~ubuntu-branches/ubuntu/trusty/3depict/trusty

« back to all changes in this revision

Viewing changes to .pc/patch-caching-bug/src/backend/filters/ionColour.cpp

  • Committer: Package Import Robot
  • Author(s): D Haley
  • Date: 2014-01-20 06:25:38 UTC
  • mfrom: (10.1.2 sid)
  • Revision ID: package-import@ubuntu.com-20140120062538-66167npw2uayux1r
Tags: 0.0.15-2
* Really remove unit tests (Closes: #730100)
* Adjust ac_header for mgl detection
* Apply upstream patch for cache bug
* Add missing files to debian/copyright

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 *      ionColour.cpp - Filter to create coloured batches of ions based upon value
 
3
 *      Copyright (C) 2013, D Haley 
 
4
 
 
5
 *      This program is free software: you can redistribute it and/or modify
 
6
 *      it under the terms of the GNU General Public License as published by
 
7
 *      the Free Software Foundation, either version 3 of the License, or
 
8
 *      (at your option) any later version.
 
9
 
 
10
 *      This program is distributed in the hope that it will be useful,
 
11
 *      but WITHOUT ANY WARRANTY; without even the implied warranty of
 
12
 *      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
13
 *      GNU General Public License for more details.
 
14
 
 
15
 *      You should have received a copy of the GNU General Public License
 
16
 *      along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
17
*/
 
18
#include "ionColour.h"
 
19
 
 
20
#include "filterCommon.h"
 
21
 
 
22
#include "common/colourmap.h"
 
23
 
 
24
 
 
25
 
 
26
const unsigned int MAX_NUM_COLOURS=256;
 
27
enum
 
28
{
 
29
        KEY_IONCOLOURFILTER_COLOURMAP,
 
30
        KEY_IONCOLOURFILTER_MAPSTART,
 
31
        KEY_IONCOLOURFILTER_MAPEND,
 
32
        KEY_IONCOLOURFILTER_NCOLOURS,
 
33
        KEY_IONCOLOURFILTER_REVERSE,
 
34
        KEY_IONCOLOURFILTER_SHOWBAR,
 
35
};
 
36
 
 
37
enum
 
38
{
 
39
        IONCOLOUR_ABORT_ERR
 
40
};
 
41
 
 
42
IonColourFilter::IonColourFilter() : colourMap(0),reverseMap(false), 
 
43
                nColours(MAX_NUM_COLOURS),showColourBar(true)
 
44
{
 
45
        mapBounds[0] = 0.0f;
 
46
        mapBounds[1] = 100.0f;
 
47
 
 
48
        cacheOK=false;
 
49
        cache=true; //By default, we should cache, but decision is made higher up
 
50
 
 
51
}
 
52
 
 
53
Filter *IonColourFilter::cloneUncached() const
 
54
{
 
55
        IonColourFilter *p=new IonColourFilter();
 
56
        p->colourMap = colourMap;
 
57
        p->mapBounds[0]=mapBounds[0];
 
58
        p->mapBounds[1]=mapBounds[1];
 
59
        p->nColours =nColours;  
 
60
        p->showColourBar =showColourBar;        
 
61
        p->reverseMap=reverseMap;       
 
62
        
 
63
        //We are copying wether to cache or not,
 
64
        //not the cache itself
 
65
        p->cache=cache;
 
66
        p->cacheOK=false;
 
67
        p->userString=userString;
 
68
        return p;
 
69
}
 
70
 
 
71
size_t IonColourFilter::numBytesForCache(size_t nObjects) const
 
72
{
 
73
                return (size_t)((float)(nObjects*IONDATA_SIZE));
 
74
}
 
75
 
 
76
 
 
77
 
 
78
unsigned int IonColourFilter::refresh(const std::vector<const FilterStreamData *> &dataIn,
 
79
        std::vector<const FilterStreamData *> &getOut, ProgressData &progress, bool (*callback)(bool))
 
80
{
 
81
        //use the cached copy if we have it.
 
82
        if(cacheOK)
 
83
        {
 
84
                ASSERT(filterOutputs.size());
 
85
                propagateStreams(dataIn,getOut,STREAM_TYPE_IONS,false);
 
86
 
 
87
                propagateCache(getOut);
 
88
 
 
89
                if(filterOutputs.size() && showColourBar)
 
90
                {
 
91
                        DrawStreamData *d = new DrawStreamData;
 
92
                        d->parent=this;
 
93
                        d->drawables.push_back(makeColourBar(mapBounds[0],
 
94
                                        mapBounds[1],nColours,colourMap));
 
95
                        d->cached=0;
 
96
                        getOut.push_back(d);
 
97
                }
 
98
                return 0;
 
99
        }
 
100
 
 
101
 
 
102
        ASSERT(nColours >0 && nColours<=MAX_NUM_COLOURS);
 
103
        IonStreamData *d[nColours];
 
104
        unsigned char rgb[3]; //RGB array
 
105
        //Build the colourmap values, each as a unique filter output
 
106
        for(unsigned int ui=0;ui<nColours; ui++)
 
107
        {
 
108
                d[ui]=new IonStreamData;
 
109
                d[ui]->parent=this;
 
110
                float value;
 
111
                value = (float)ui*(mapBounds[1]-mapBounds[0])/(float)nColours + mapBounds[0];
 
112
                //Pick the desired colour map
 
113
                colourMapWrap(colourMap,rgb,value,mapBounds[0],mapBounds[1],reverseMap);
 
114
        
 
115
                d[ui]->r=rgb[0]/255.0f;
 
116
                d[ui]->g=rgb[1]/255.0f;
 
117
                d[ui]->b=rgb[2]/255.0f;
 
118
                d[ui]->a=1.0f;
 
119
        }
 
120
 
 
121
 
 
122
 
 
123
        //Try to maintain ion size if possible
 
124
        bool haveIonSize,sameSize; // have we set the ionSize?
 
125
        float ionSize;
 
126
        haveIonSize=false;
 
127
        sameSize=true;
 
128
 
 
129
        //Did we find any ions in this pass?
 
130
        bool foundIons=false;   
 
131
        unsigned int totalSize=numElements(dataIn);
 
132
        unsigned int curProg=NUM_CALLBACK;
 
133
        size_t n=0;
 
134
        for(unsigned int ui=0;ui<dataIn.size() ;ui++)
 
135
        {
 
136
                switch(dataIn[ui]->getStreamType())
 
137
                {
 
138
                        case STREAM_TYPE_IONS: 
 
139
                        {
 
140
                                foundIons=true;
 
141
 
 
142
                                //Check for ion size consistency        
 
143
                                if(haveIonSize)
 
144
                                {
 
145
                                        sameSize &= (fabs(ionSize-((const IonStreamData *)dataIn[ui])->ionSize) 
 
146
                                                                        < std::numeric_limits<float>::epsilon());
 
147
                                }
 
148
                                else
 
149
                                {
 
150
                                        ionSize=((const IonStreamData *)dataIn[ui])->ionSize;
 
151
                                        haveIonSize=true;
 
152
                                }
 
153
                                for(vector<IonHit>::const_iterator it=((const IonStreamData *)dataIn[ui])->data.begin();
 
154
                                               it!=((const IonStreamData *)dataIn[ui])->data.end(); ++it)
 
155
                                {
 
156
                                        unsigned int colour;
 
157
 
 
158
                                        float tmp;      
 
159
                                        tmp= (it->getMassToCharge()-mapBounds[0])/(mapBounds[1]-mapBounds[0]);
 
160
                                        tmp = std::max(0.0f,tmp);
 
161
                                        tmp = std::min(tmp,1.0f);
 
162
                                        
 
163
                                        colour=(unsigned int)(tmp*(float)(nColours-1)); 
 
164
                                        d[colour]->data.push_back(*it);
 
165
                                
 
166
                                        //update progress every CALLBACK ions
 
167
                                        if(!curProg--)
 
168
                                        {
 
169
                                                n+=NUM_CALLBACK;
 
170
                                                progress.filterProgress= (unsigned int)((float)(n)/((float)totalSize)*100.0f);
 
171
                                                curProg=NUM_CALLBACK;
 
172
                                                if(!(*callback)(false))
 
173
                                                {
 
174
                                                        for(unsigned int ui=0;ui<nColours;ui++)
 
175
                                                                delete d[ui];
 
176
                                                        return IONCOLOUR_ABORT_ERR;
 
177
                                                }
 
178
                                        }
 
179
                                }
 
180
 
 
181
                                
 
182
                                break;
 
183
                        }
 
184
                        default:
 
185
                                getOut.push_back(dataIn[ui]);
 
186
 
 
187
                }
 
188
        }
 
189
 
 
190
        //create the colour bar as needed
 
191
        if(foundIons && showColourBar)
 
192
        {
 
193
                DrawStreamData *d = new DrawStreamData;
 
194
                d->drawables.push_back(makeColourBar(mapBounds[0],mapBounds[1],nColours,colourMap,reverseMap));
 
195
                d->parent=this;
 
196
                d->cached=0;
 
197
                getOut.push_back(d);
 
198
        }
 
199
 
 
200
 
 
201
        //If all the ions are the same size, then propagate
 
202
        if(haveIonSize && sameSize)
 
203
        {
 
204
                for(unsigned int ui=0;ui<nColours;ui++)
 
205
                        d[ui]->ionSize=ionSize;
 
206
        }
 
207
        //merge the results as needed
 
208
        if(cache)
 
209
        {
 
210
                for(unsigned int ui=0;ui<nColours;ui++)
 
211
                {
 
212
                        if(d[ui]->data.size())
 
213
                                d[ui]->cached=1;
 
214
                        else
 
215
                                d[ui]->cached=0;
 
216
                        if(d[ui]->data.size())
 
217
                                filterOutputs.push_back(d[ui]);
 
218
                }
 
219
                cacheOK=filterOutputs.size();
 
220
        }
 
221
        else
 
222
        {
 
223
                for(unsigned int ui=0;ui<nColours;ui++)
 
224
                {
 
225
                        //NOTE: MUST set cached BEFORE push_back!
 
226
                        d[ui]->cached=0;
 
227
                }
 
228
                cacheOK=false;
 
229
        }
 
230
 
 
231
        //push the colours onto the output. cached or not (their status is set above).
 
232
        for(unsigned int ui=0;ui<nColours;ui++)
 
233
        {
 
234
                if(d[ui]->data.size())
 
235
                        getOut.push_back(d[ui]);
 
236
                else
 
237
                        delete d[ui];
 
238
        }
 
239
        
 
240
        return 0;
 
241
}
 
242
 
 
243
 
 
244
void IonColourFilter::getProperties(FilterPropGroup &propertyList) const
 
245
{
 
246
 
 
247
        FilterProperty p;
 
248
        string tmpStr;
 
249
        vector<pair<unsigned int, string> > choices;
 
250
 
 
251
        size_t curGroup=0;
 
252
 
 
253
        for(unsigned int ui=0;ui<NUM_COLOURMAPS; ui++)
 
254
                choices.push_back(make_pair(ui,getColourMapName(ui)));
 
255
 
 
256
        tmpStr=choiceString(choices,colourMap);
 
257
        
 
258
        p.name=TRANS("Colour Map"); 
 
259
        p.data=tmpStr;
 
260
        p.key=KEY_IONCOLOURFILTER_COLOURMAP;
 
261
        p.type=PROPERTY_TYPE_CHOICE;
 
262
        p.helpText=TRANS("Colour scheme used to assign points colours by value");
 
263
        propertyList.addProperty(p,curGroup);
 
264
 
 
265
        
 
266
        p.name=TRANS("Reverse map");
 
267
        p.helpText=TRANS("Reverse the colour scale");
 
268
        p.data= boolStrEnc(reverseMap);
 
269
        p.key=KEY_IONCOLOURFILTER_REVERSE;
 
270
        p.type=PROPERTY_TYPE_BOOL;
 
271
        propertyList.addProperty(p,curGroup);
 
272
        
 
273
 
 
274
        p.name=TRANS("Show Bar");
 
275
        p.key=KEY_IONCOLOURFILTER_SHOWBAR;
 
276
        p.data=boolStrEnc(showColourBar);
 
277
        p.type=PROPERTY_TYPE_BOOL;
 
278
        propertyList.addProperty(p,curGroup);
 
279
 
 
280
        stream_cast(tmpStr,nColours);
 
281
        p.name=TRANS("Num Colours");
 
282
        p.data=tmpStr;
 
283
        p.helpText=TRANS("Number of unique colours to use in colour map"); 
 
284
        p.key=KEY_IONCOLOURFILTER_NCOLOURS;
 
285
        p.type=PROPERTY_TYPE_INTEGER;
 
286
        propertyList.addProperty(p,curGroup);
 
287
 
 
288
        stream_cast(tmpStr,mapBounds[0]);
 
289
        p.name=TRANS("Map start");
 
290
        p.helpText=TRANS("Assign points with this value to the first colour in map"); 
 
291
        p.data= tmpStr;
 
292
        p.key=KEY_IONCOLOURFILTER_MAPSTART;
 
293
        p.type=PROPERTY_TYPE_REAL;
 
294
        propertyList.addProperty(p,curGroup);
 
295
 
 
296
        stream_cast(tmpStr,mapBounds[1]);
 
297
        p.name=TRANS("Map end");
 
298
        p.helpText=TRANS("Assign points with this value to the last colour in map"); 
 
299
        p.data= tmpStr;
 
300
        p.key=KEY_IONCOLOURFILTER_MAPEND;
 
301
        p.type=PROPERTY_TYPE_REAL;
 
302
        propertyList.addProperty(p,curGroup);
 
303
        
 
304
 
 
305
}
 
306
 
 
307
bool IonColourFilter::setProperty(  unsigned int key,
 
308
                                        const std::string &value, bool &needUpdate)
 
309
{
 
310
 
 
311
        needUpdate=false;
 
312
        switch(key)
 
313
        {
 
314
                case KEY_IONCOLOURFILTER_COLOURMAP:
 
315
                {
 
316
                        unsigned int tmpMap;
 
317
                        tmpMap=(unsigned int)-1;
 
318
                        for(unsigned int ui=0;ui<NUM_COLOURMAPS;ui++)
 
319
                        {
 
320
                                if(value== getColourMapName(ui))
 
321
                                {
 
322
                                        tmpMap=ui;
 
323
                                        break;
 
324
                                }
 
325
                        }
 
326
 
 
327
                        if(tmpMap >=NUM_COLOURMAPS || tmpMap ==colourMap)
 
328
                                return false;
 
329
 
 
330
                        clearCache();
 
331
                        needUpdate=true;
 
332
                        colourMap=tmpMap;
 
333
                        break;
 
334
                }
 
335
                case KEY_IONCOLOURFILTER_REVERSE:
 
336
                {
 
337
                        bool newVal;
 
338
                        if(!boolStrDec(value,newVal))
 
339
                                return false;
 
340
 
 
341
                        //Only need update if changed
 
342
                        if(newVal!=reverseMap)
 
343
                        {
 
344
                                clearCache();
 
345
                                needUpdate=true;
 
346
                        }
 
347
 
 
348
                        reverseMap=newVal;
 
349
                        break;
 
350
                }       
 
351
                case KEY_IONCOLOURFILTER_MAPSTART:
 
352
                {
 
353
                        float tmpBound;
 
354
                        stream_cast(tmpBound,value);
 
355
                        if(tmpBound >=mapBounds[1])
 
356
                                return false;
 
357
 
 
358
                        clearCache();
 
359
                        needUpdate=true;
 
360
                        mapBounds[0]=tmpBound;
 
361
                        break;
 
362
                }
 
363
                case KEY_IONCOLOURFILTER_MAPEND:
 
364
                {
 
365
                        float tmpBound;
 
366
                        stream_cast(tmpBound,value);
 
367
                        if(tmpBound <=mapBounds[0])
 
368
                                return false;
 
369
 
 
370
                        clearCache();
 
371
                        needUpdate=true;
 
372
                        mapBounds[1]=tmpBound;
 
373
                        break;
 
374
                }
 
375
                case KEY_IONCOLOURFILTER_NCOLOURS:
 
376
                {
 
377
                        unsigned int numColours;
 
378
                        if(stream_cast(numColours,value))
 
379
                                return false;
 
380
 
 
381
                        clearCache();
 
382
                        needUpdate=true;
 
383
                        //enforce 1->MAX_NUM_COLOURS range
 
384
                        nColours=std::min(numColours,MAX_NUM_COLOURS);
 
385
                        if(!nColours)
 
386
                                nColours=1;
 
387
                        break;
 
388
                }
 
389
                case KEY_IONCOLOURFILTER_SHOWBAR:
 
390
                {
 
391
                        bool newVal;
 
392
                        if(!boolStrDec(value,newVal))
 
393
                                return false;
 
394
                        //Only need update if changed
 
395
                        if(newVal!=showColourBar)
 
396
                        {
 
397
                                needUpdate=true;
 
398
                                clearCache();
 
399
                        }
 
400
                        showColourBar=newVal;
 
401
                        break;
 
402
                }       
 
403
 
 
404
                default:
 
405
                        ASSERT(false);
 
406
        }       
 
407
        return true;
 
408
}
 
409
 
 
410
 
 
411
std::string  IonColourFilter::getErrString(unsigned int code) const
 
412
{
 
413
        //Currently the only error is aborting
 
414
        return std::string(TRANS("Aborted"));
 
415
}
 
416
 
 
417
void IonColourFilter::setPropFromBinding(const SelectionBinding &b)
 
418
{
 
419
        ASSERT(false); 
 
420
}
 
421
 
 
422
bool IonColourFilter::writeState(std::ostream &f,unsigned int format, unsigned int depth) const
 
423
{
 
424
        using std::endl;
 
425
        switch(format)
 
426
        {
 
427
                case STATE_FORMAT_XML:
 
428
                {       
 
429
                        f << tabs(depth) << "<" << trueName() << ">" << endl;
 
430
                        f << tabs(depth+1) << "<userstring value=\""<< escapeXML(userString) << "\"/>"  << endl;
 
431
 
 
432
                        f << tabs(depth+1) << "<colourmap value=\"" << colourMap << "\"/>" << endl;
 
433
                        f << tabs(depth+1) << "<extrema min=\"" << mapBounds[0] << "\" max=\"" 
 
434
                                << mapBounds[1] << "\"/>" << endl;
 
435
                        f << tabs(depth+1) << "<ncolours value=\"" << nColours << "\"/>" << endl;
 
436
 
 
437
                        f << tabs(depth+1) << "<showcolourbar value=\"" << boolStrEnc(showColourBar)<< "\"/>" << endl;
 
438
                        f << tabs(depth+1) << "<reversemap value=\"" << boolStrEnc(reverseMap)<< "\"/>" << endl;
 
439
                        
 
440
                        f << tabs(depth) << "</" << trueName() << ">" << endl;
 
441
                        break;
 
442
                }
 
443
                default:
 
444
                        ASSERT(false);
 
445
                        return false;
 
446
        }
 
447
 
 
448
        return true;
 
449
}
 
450
 
 
451
bool IonColourFilter::readState(xmlNodePtr &nodePtr, const std::string &stateFileDir)
 
452
{
 
453
        //Retrieve user string
 
454
        //===
 
455
        if(XMLHelpFwdToElem(nodePtr,"userstring"))
 
456
                return false;
 
457
 
 
458
        xmlChar *xmlString=xmlGetProp(nodePtr,(const xmlChar *)"value");
 
459
        if(!xmlString)
 
460
                return false;
 
461
        userString=(char *)xmlString;
 
462
        xmlFree(xmlString);
 
463
        //===
 
464
 
 
465
        std::string tmpStr;     
 
466
        //Retrieve colourmap
 
467
        //====
 
468
        if(XMLHelpFwdToElem(nodePtr,"colourmap"))
 
469
                return false;
 
470
 
 
471
        xmlString=xmlGetProp(nodePtr,(const xmlChar *)"value");
 
472
        if(!xmlString)
 
473
                return false;
 
474
        tmpStr=(char *)xmlString;
 
475
 
 
476
        //convert from string to digit
 
477
        if(stream_cast(colourMap,tmpStr))
 
478
                return false;
 
479
 
 
480
        if(colourMap>= NUM_COLOURMAPS)
 
481
               return false;    
 
482
        xmlFree(xmlString);
 
483
        //====
 
484
        
 
485
        //Retrieve Extrema 
 
486
        //===
 
487
        float tmpMin,tmpMax;
 
488
        if(XMLHelpFwdToElem(nodePtr,"extrema"))
 
489
                return false;
 
490
 
 
491
        xmlString=xmlGetProp(nodePtr,(const xmlChar *)"min");
 
492
        if(!xmlString)
 
493
                return false;
 
494
        tmpStr=(char *)xmlString;
 
495
 
 
496
        //convert from string to digit
 
497
        if(stream_cast(tmpMin,tmpStr))
 
498
                return false;
 
499
 
 
500
        xmlString=xmlGetProp(nodePtr,(const xmlChar *)"max");
 
501
        if(!xmlString)
 
502
                return false;
 
503
        tmpStr=(char *)xmlString;
 
504
 
 
505
        //convert from string to digit
 
506
        if(stream_cast(tmpMax,tmpStr))
 
507
                return false;
 
508
 
 
509
        xmlFree(xmlString);
 
510
 
 
511
        if(tmpMin > tmpMax)
 
512
                return false;
 
513
 
 
514
        mapBounds[0]=tmpMin;
 
515
        mapBounds[1]=tmpMax;
 
516
 
 
517
        //===
 
518
        
 
519
        //Retrieve num colours 
 
520
        //====
 
521
        if(XMLHelpFwdToElem(nodePtr,"ncolours"))
 
522
                return false;
 
523
 
 
524
        xmlString=xmlGetProp(nodePtr,(const xmlChar *)"value");
 
525
        if(!xmlString)
 
526
                return false;
 
527
        tmpStr=(char *)xmlString;
 
528
 
 
529
        //convert from string to digit
 
530
        if(stream_cast(nColours,tmpStr))
 
531
                return false;
 
532
 
 
533
        xmlFree(xmlString);
 
534
        //====
 
535
        
 
536
        //Retrieve num colours 
 
537
        //====
 
538
        if(XMLHelpFwdToElem(nodePtr,"showcolourbar"))
 
539
                return false;
 
540
 
 
541
        xmlString=xmlGetProp(nodePtr,(const xmlChar *)"value");
 
542
        if(!xmlString)
 
543
                return false;
 
544
        tmpStr=(char *)xmlString;
 
545
 
 
546
        //convert from string to digit
 
547
        if(stream_cast(showColourBar,tmpStr))
 
548
                return false;
 
549
 
 
550
        xmlFree(xmlString);
 
551
        //====
 
552
        
 
553
        //Check for colour map reversal
 
554
        //=====
 
555
        if(XMLHelpFwdToElem(nodePtr,"reversemap"))
 
556
        {
 
557
                //Didn't exist prior to 0.0.15, assume off
 
558
                reverseMap=false;
 
559
        }
 
560
        else
 
561
        {
 
562
                xmlString=xmlGetProp(nodePtr,(const xmlChar *)"value");
 
563
                if(!xmlString)
 
564
                        return false;
 
565
                tmpStr=(char *)xmlString;
 
566
 
 
567
                //convert from string to bool 
 
568
                if(!boolStrDec(tmpStr,reverseMap))
 
569
                        return false;
 
570
        }
 
571
 
 
572
        xmlFree(xmlString);
 
573
        //====
 
574
        return true;
 
575
}
 
576
 
 
577
unsigned int IonColourFilter::getRefreshBlockMask() const
 
578
{
 
579
        //Anything but ions can go through this filter.
 
580
        return STREAM_TYPE_IONS;
 
581
}
 
582
 
 
583
unsigned int IonColourFilter::getRefreshEmitMask() const
 
584
{
 
585
        return  STREAM_TYPE_DRAW | STREAM_TYPE_IONS;
 
586
}
 
587
 
 
588
unsigned int IonColourFilter::getRefreshUseMask() const
 
589
{
 
590
        return  STREAM_TYPE_IONS;
 
591
}
 
592
#ifdef DEBUG
 
593
 
 
594
IonStreamData *sythIonCountData(unsigned int numPts, float mStart, float mEnd)
 
595
{
 
596
        IonStreamData *d = new IonStreamData;
 
597
        d->data.resize(numPts);
 
598
        for(unsigned int ui=0; ui<numPts;ui++)
 
599
        {
 
600
                IonHit h;
 
601
 
 
602
                h.setPos(Point3D(ui,ui,ui));
 
603
                h.setMassToCharge( (mEnd-mStart)*(float)ui/(float)numPts + mStart);
 
604
                d->data[ui] =h;
 
605
        }
 
606
 
 
607
        return d;
 
608
}
 
609
 
 
610
 
 
611
bool ionCountTest()
 
612
{
 
613
        const int NUM_PTS=1000;
 
614
        vector<const FilterStreamData*> streamIn,streamOut;
 
615
        IonStreamData *d=sythIonCountData(NUM_PTS,0,100);
 
616
        streamIn.push_back(d);
 
617
 
 
618
 
 
619
        IonColourFilter *f = new IonColourFilter;
 
620
        f->setCaching(false);
 
621
 
 
622
        bool needUpdate;
 
623
        TEST(f->setProperty(KEY_IONCOLOURFILTER_NCOLOURS,"100",needUpdate),"Set prop");
 
624
        TEST(f->setProperty(KEY_IONCOLOURFILTER_MAPSTART,"0",needUpdate),"Set prop");
 
625
        TEST(f->setProperty(KEY_IONCOLOURFILTER_MAPEND,"100",needUpdate),"Set prop");
 
626
        TEST(f->setProperty(KEY_IONCOLOURFILTER_SHOWBAR,"0",needUpdate),"Set prop");
 
627
        
 
628
        ProgressData p;
 
629
        TEST(!f->refresh(streamIn,streamOut,p,dummyCallback),"refresh error code");
 
630
        delete f;
 
631
        delete d;
 
632
        
 
633
        TEST(streamOut.size() == 99,"stream count");
 
634
 
 
635
        for(unsigned int ui=0;ui<streamOut.size();ui++)
 
636
        {
 
637
                TEST(streamOut[ui]->getStreamType() == STREAM_TYPE_IONS,"stream type");
 
638
        }
 
639
 
 
640
        for(unsigned int ui=0;ui<streamOut.size();ui++)
 
641
                delete streamOut[ui];
 
642
 
 
643
        return true;
 
644
}
 
645
 
 
646
 
 
647
bool IonColourFilter::runUnitTests()
 
648
{
 
649
        if(!ionCountTest())
 
650
                return false;
 
651
 
 
652
        return true;
 
653
}
 
654
 
 
655
 
 
656
#endif
 
657