~ubuntu-branches/debian/sid/3depict/sid

« back to all changes in this revision

Viewing changes to src/plot.cpp

  • Committer: Bazaar Package Importer
  • Author(s): D Haley, Sylvestre Ledru
  • Date: 2011-04-12 17:44:06 UTC
  • mfrom: (1.2.1 upstream) (3.1.2 experimental)
  • Revision ID: james.westby@ubuntu.com-20110412174406-zz06iu3xmardt43s
Tags: 0.0.5-1
[ Sylvestre Ledru ]
* watch file added
* Switch to dpkg-source 3.0 (quilt) format

* New upstream version 

Show diffs side-by-side

added added

removed removed

Lines of Context:
149
149
                                        stddev+=(y[idx]-mean)*(y[idx]-mean);
150
150
                                }
151
151
 
152
 
                                stddev=sqrt(stddev/(float)errMode.movingAverageNum);
 
152
                                stddev=sqrtf(stddev/(float)errMode.movingAverageNum);
153
153
                                errBars[ui]=stddev;
154
154
                        }
155
155
                        break;
182
182
 
183
183
        plottingData.clear();
184
184
        regions.clear();
185
 
        uniqueIDHandler.clear();
 
185
        plotIDHandler.clear();
 
186
        regionIDHandler.clear();
186
187
        plotChanged=true;
187
188
}
188
189
 
189
190
void Multiplot::setStrings(unsigned int plotID, const std::string &x, 
190
191
                                const std::string &y, const std::string &t)
191
192
{
192
 
        unsigned int plotPos=uniqueIDHandler.getPos(plotID);
 
193
        unsigned int plotPos=plotIDHandler.getPos(plotID);
193
194
        plottingData[plotPos].xLabel = strToWStr(x);
194
195
        plottingData[plotPos].yLabel = strToWStr(y);
195
196
        
199
200
 
200
201
void Multiplot::setParentData(unsigned int plotID, const void *parentObj, unsigned int idx)
201
202
{
202
 
        unsigned int plotPos=uniqueIDHandler.getPos(plotID);
 
203
        unsigned int plotPos=plotIDHandler.getPos(plotID);
203
204
        plottingData[plotPos].parentObject= parentObj;
204
205
        plottingData[plotPos].parentPlotIndex=idx;
205
206
        
256
257
        newDataRef.r=(0);newDataRef.g=(0);newDataRef.b=(1);
257
258
 
258
259
        //assign a unique identifier to this plot, by which it can be referenced
259
 
        unsigned int uniqueID = uniqueIDHandler.genId(plottingData.size()-1);
 
260
        unsigned int uniqueID = plotIDHandler.genId(plottingData.size()-1);
260
261
        plotChanged=true;
261
262
        return uniqueID;
262
263
}
297
298
        
298
299
        maxThis=-std::numeric_limits<float>::max();
299
300
        minThis=std::numeric_limits<float>::max();
300
 
        for(unsigned int ui=0;ui<v.size();ui++)
301
 
        {
302
 
                minThis=std::min(minThis,v[ui].second);
303
 
                maxThis=std::max(maxThis,v[ui].second);
 
301
        if(newDataRef.errBars.size())
 
302
        {
 
303
                ASSERT(newDataRef.errBars.size() == v.size());
 
304
                for(unsigned int ui=0;ui<v.size();ui++)
 
305
                {
 
306
                        minThis=std::min(minThis,v[ui].second-newDataRef.errBars[ui]);
 
307
                        maxThis=std::max(maxThis,v[ui].second+newDataRef.errBars[ui]);
 
308
                }
 
309
        }
 
310
        else
 
311
        {
 
312
                for(unsigned int ui=0;ui<v.size();ui++)
 
313
                {
 
314
                        minThis=std::min(minThis,v[ui].second);
 
315
                        maxThis=std::max(maxThis,v[ui].second);
 
316
                }
 
317
 
304
318
        }
305
319
        newDataRef.minY=minThis;
306
320
        newDataRef.maxY=1.10f*maxThis; //The 1.10 is because mathgl chops off data
315
329
        newDataRef.r=(0);newDataRef.g=(0);newDataRef.b=(1);
316
330
 
317
331
        //assign a unique identifier to this plot, by which it can be referenced
318
 
        unsigned int uniqueID = uniqueIDHandler.genId(plottingData.size()-1);
 
332
        unsigned int uniqueID = plotIDHandler.genId(plottingData.size()-1);
319
333
        plotChanged=true;
320
334
        return uniqueID;
321
335
}
326
340
{
327
341
 
328
342
        ASSERT(mode<PLOT_TYPE_ENDOFENUM);
329
 
        plottingData[uniqueIDHandler.getPos(plotUniqueID)].plotType=mode;
 
343
        plottingData[plotIDHandler.getPos(plotUniqueID)].plotType=mode;
330
344
        plotChanged=true;
331
345
}
332
346
 
333
347
void Multiplot::setColours(unsigned int plotUniqueID, float rN,float gN,float bN) 
334
348
{
335
 
        unsigned int plotPos=uniqueIDHandler.getPos(plotUniqueID);
 
349
        unsigned int plotPos=plotIDHandler.getPos(plotUniqueID);
336
350
        plottingData[plotPos].r=rN;
337
351
        plottingData[plotPos].g=gN;
338
352
        plottingData[plotPos].b=bN;
343
357
void Multiplot::setBounds(float xMin, float xMax,
344
358
                        float yMin,float yMax)
345
359
{
 
360
        ASSERT(xMin < xMax);
 
361
        ASSERT(yMin< yMax);
346
362
        xUserMin=xMin;
347
363
        yUserMin=std::max(0.0f,yMin);
348
364
        xUserMax=xMax;
352
368
        plotChanged=true;
353
369
}
354
370
 
 
371
 
 
372
void Multiplot::disableUserAxisBounds(bool xBound)
 
373
{
 
374
        float xMin,xMax,yMin,yMax;
 
375
        scanBounds(xMin,xMax,yMin,yMax);
 
376
 
 
377
        if(xBound)
 
378
        {
 
379
                xUserMin=xMin;
 
380
                xUserMax=xMax;
 
381
        }
 
382
        else
 
383
        {
 
384
                yUserMin=std::max(0.0f,yMin);
 
385
                yUserMax=yMax;
 
386
        }
 
387
 
 
388
 
 
389
        //Check to see if we have zoomed all the bounds out anyway
 
390
        if(fabs(xUserMin -xMin)<=std::numeric_limits<float>::epsilon() &&
 
391
                fabs(yUserMin -yMin)<=std::numeric_limits<float>::epsilon())
 
392
        {
 
393
                applyUserBounds=false;
 
394
        }
 
395
 
 
396
        plotChanged=true;
 
397
}
355
398
void Multiplot::getBounds(float &xMin, float &xMax,
356
399
                        float &yMin,float &yMax) const
357
400
{
359
402
        {
360
403
                xMin=xUserMin;
361
404
                yMin=yUserMin;
362
 
                xMin=xUserMax;
363
 
                yMin=yUserMax;
 
405
                xMax=xUserMax;
 
406
                yMax=yUserMax;
364
407
        }
365
408
        else
366
409
        {
367
 
                //OK, we are going to have to scan for max/min
368
 
                xMin=std::numeric_limits<float>::max();
369
 
                xMax=-std::numeric_limits<float>::max();
370
 
                yMin=std::numeric_limits<float>::max();
371
 
                yMax=-std::numeric_limits<float>::max();
372
 
 
373
 
                for(unsigned int ui=0;ui<plottingData.size();ui++)
 
410
                scanBounds(xMin,xMax,yMin,yMax);
 
411
        }
 
412
 
 
413
        ASSERT(xMin < xMax && yMin < yMax);
 
414
}
 
415
 
 
416
void Multiplot::scanBounds(float &xMin,float &xMax,float &yMin,float &yMax) const
 
417
{
 
418
        //OK, we are going to have to scan for max/min
 
419
        xMin=std::numeric_limits<float>::max();
 
420
        xMax=-std::numeric_limits<float>::max();
 
421
        yMin=std::numeric_limits<float>::max();
 
422
        yMax=-std::numeric_limits<float>::max();
 
423
 
 
424
        for(unsigned int ui=0;ui<plottingData.size();ui++)
 
425
        {
 
426
                if(plottingData[ui].visible)
374
427
                {
375
428
                        xMin=std::min(plottingData[ui].minX,xMin);
376
429
                        xMax=std::max(plottingData[ui].maxX,xMax);
378
431
                        yMin=std::min(plottingData[ui].minY,yMin);
379
432
                        yMax=std::max(plottingData[ui].maxY,yMax);
380
433
                }
 
434
        }
381
435
 
 
436
        //If we are in log mode, then we need to set the
 
437
        //log of that bound before emitting it.
 
438
        if(isLogarithmic())
 
439
        {
 
440
                yMin=log10(std::max(yMin,1.0f));
 
441
                yMax=log10(yMax);
382
442
        }
383
443
}
384
444
 
408
468
        plotChanged=true;
409
469
}
410
470
 
 
471
//Is the plot being displayed in lgo mode?
 
472
bool Multiplot::isLogarithmic() const
 
473
{
 
474
        for(unsigned int ui=0;ui<plottingData.size(); ui++)
 
475
        {
 
476
                if(plottingData[ui].visible)
 
477
                {
 
478
                        if(plottingData[ui].logarithmic) 
 
479
                                return true;
 
480
                }
 
481
        }
 
482
 
 
483
        return false;
 
484
}
 
485
 
411
486
void Multiplot::drawPlot(mglGraph *gr) const
412
487
{
413
488
        if(!plottingData.size())
536
611
                for(unsigned int uj=0;uj<regions.size();uj++)
537
612
                {
538
613
                        //Do not plot regions that do not belong to current plot
539
 
                        if(regions[uj].ownerPlot!= uniqueIDHandler.getId(ui))
 
614
                        if(regions[uj].ownerPlot!= plotIDHandler.getId(ui))
540
615
                                continue;
541
616
                        //Compute region bounds, such that it will not exceed the axis
542
617
                        float rMinX, rMaxX, rMinY,rMaxY;
686
761
        string sY;
687
762
        sY.assign(yLabel.begin(), yLabel.end()); //unicode conversion
688
763
        if(logarithmic && !notLog)
689
 
                sY = string("\\log(") + sY + ")";
 
764
                sY = string("\\log_{10}(") + sY + ")";
690
765
        else if (logarithmic && notLog)
691
766
        {
692
767
                sY = string("Mixed log/non-log:") + sY ;
721
796
 
722
797
void Multiplot::setVisible(unsigned int uniqueID, bool setVis)
723
798
{
724
 
        unsigned int plotPos = uniqueIDHandler.getPos(uniqueID);
 
799
        unsigned int plotPos = plotIDHandler.getPos(uniqueID);
725
800
 
726
801
        plottingData[plotPos].visible=setVis;
727
802
        plotChanged=true;
728
803
}
729
804
 
730
 
void Multiplot::addRegion(unsigned int parentPlot,float start, float end, 
731
 
                        float rNew, float gNew, float bNew)
 
805
void Multiplot::addRegion(unsigned int parentPlot,unsigned int regionID,float start, float end, 
 
806
                        float rNew, float gNew, float bNew, Filter *parentFilter)
732
807
{
733
808
        ASSERT(start <end);
734
809
        ASSERT( rNew>=0.0 && rNew <= 1.0);
738
813
        PlotRegion region;
739
814
        region.ownerPlot=parentPlot;
740
815
        region.bounds=std::make_pair(start,end);
 
816
        region.parentFilter = parentFilter;
 
817
        region.id = regionID;
 
818
        region.uniqueID = regionIDHandler.genId(regions.size());
741
819
 
742
820
        region.r=rNew;
743
821
        region.g=gNew;
762
840
 
763
841
bool Multiplot::isPlotVisible(unsigned int plotID) const
764
842
{
765
 
        return plottingData[uniqueIDHandler.getPos(plotID)].visible;
 
843
        return plottingData[plotIDHandler.getPos(plotID)].visible;
766
844
}
767
845
 
768
846
void Multiplot::getRawData(std::vector<std::vector<std::vector< float> > > &rawData,
810
888
        }
811
889
}
812
890
 
 
891
void Multiplot::getRegions(std::vector<PlotRegion> &copyRegions) const
 
892
{
 
893
        
 
894
        copyRegions.reserve(regions.size());
 
895
 
 
896
        for(unsigned int ui=0;ui<regions.size();ui++)
 
897
        {
 
898
                if(isPlotVisible(regions[ui].ownerPlot))
 
899
                        copyRegions.push_back(regions[ui]); 
 
900
        }
 
901
}
 
902
 
813
903
 
814
904
char Multiplot::getNearestMathglColour(float r, float g, float b) const
815
905
{
863
953
 
864
954
        return val;
865
955
}
 
956
 
 
957
 
 
958
float Multiplot::moveRegionTest(unsigned int regionID, 
 
959
                        unsigned int method, float newPos)  const
 
960
{
 
961
        unsigned int region=(unsigned int)-1;
 
962
        for(unsigned int ui=0;ui<regions.size();ui++)
 
963
        {
 
964
                if(regionID== regions[ui].uniqueID)
 
965
                        region=ui;
 
966
        }
 
967
 
 
968
        ASSERT(region<regions.size());
 
969
        ASSERT(isPlotVisible(regions[region].ownerPlot));
 
970
 
 
971
        //Check that moving this range will not cause any overlaps with 
 
972
        //other regions
 
973
        float mean;
 
974
        mean=(regions[region].bounds.first + regions[region].bounds.second)/2.0f;
 
975
 
 
976
        //Who is the owner of the current plot -- we only want to interact with our colleagues
 
977
        unsigned int curOwnerPlot= regions[region].ownerPlot;
 
978
        float xMin,xMax,yMin,yMax;
 
979
        getBounds(xMin,xMax,yMin,yMax);
 
980
 
 
981
        switch(method)
 
982
        {
 
983
                //Left extend
 
984
                case REGION_LEFT_EXTEND:
 
985
                        //Check that the upper bound does not intersect any RHS of 
 
986
                        //region bounds
 
987
                        for(unsigned int ui=0; ui<regions.size(); ui++)
 
988
                        {
 
989
                                if(regions[ui].ownerPlot == curOwnerPlot &&
 
990
                                        (regions[ui].bounds.second < mean && ui !=region) )
 
991
                                                newPos=std::max(newPos,regions[ui].bounds.second);
 
992
                        }
 
993
                        //Dont allow past self right
 
994
                        newPos=std::min(newPos,regions[region].bounds.second);
 
995
                        //Dont extend outside plot
 
996
                        newPos=std::max(newPos,xMin);
 
997
                        break;
 
998
                //shift
 
999
                case REGION_MOVE:
 
1000
                        //Check that the upper bound does not intersect any RHS or LHS of 
 
1001
                        //region bounds
 
1002
                        if(newPos > mean) 
 
1003
                                
 
1004
                        {
 
1005
                                //Disallow hitting other bounds
 
1006
                                for(unsigned int ui=0; ui<regions.size(); ui++)
 
1007
                                {
 
1008
                                        if(regions[ui].ownerPlot == curOwnerPlot &&
 
1009
                                                (regions[ui].bounds.first > mean && ui != region) )
 
1010
                                                newPos=std::min(newPos,regions[ui].bounds.first);
 
1011
                                }
 
1012
                                newPos=std::max(newPos,xMin);
 
1013
                        }
 
1014
                        else
 
1015
                        {
 
1016
                                //Disallow hitting other bounds
 
1017
                                for(unsigned int ui=0; ui<regions.size(); ui++)
 
1018
                                {
 
1019
                                        if(regions[ui].ownerPlot == curOwnerPlot &&
 
1020
                                                (regions[ui].bounds.second < mean && ui != region))
 
1021
                                                newPos=std::max(newPos,regions[ui].bounds.second);
 
1022
                                }
 
1023
                                //Dont extend outside plot
 
1024
                                newPos=std::min(newPos,xMax);
 
1025
                        }
 
1026
                        break;
 
1027
                //Right extend
 
1028
                case REGION_RIGHT_EXTEND:
 
1029
                        //Disallow hitting other bounds
 
1030
 
 
1031
                        for(unsigned int ui=0; ui<regions.size(); ui++)
 
1032
                        {
 
1033
                                if(regions[ui].ownerPlot == curOwnerPlot &&
 
1034
                                        (regions[ui].bounds.second > mean && ui != region))
 
1035
                                        newPos=std::min(newPos,regions[ui].bounds.first);
 
1036
                        }
 
1037
                        //Dont allow past self left
 
1038
                        newPos=std::max(newPos,regions[region].bounds.first);
 
1039
                        //Dont extend outside plot
 
1040
                        newPos=std::min(newPos,xMax);
 
1041
                        break;
 
1042
                default:
 
1043
                        ASSERT(false);
 
1044
        }
 
1045
 
 
1046
 
 
1047
 
 
1048
        return newPos;
 
1049
}
 
1050
 
 
1051
 
 
1052
void Multiplot::moveRegion(unsigned int regionID, unsigned int method, float newPos)
 
1053
{
 
1054
 
 
1055
        //Well, we should have called this externally to determine location
 
1056
        //let us confirm that this is the case 
 
1057
        moveRegionTest(regionID,method,newPos);
 
1058
 
 
1059
        unsigned int region=(unsigned int)-1;
 
1060
        for(unsigned int ui=0;ui<regions.size();ui++)
 
1061
        {
 
1062
                if(regionID== regions[ui].uniqueID)
 
1063
                        region=ui;
 
1064
        }
 
1065
 
 
1066
        ASSERT(region<regions.size());
 
1067
        ASSERT(regions[region].parentFilter);
 
1068
        regions[region].parentFilter->setPropFromRegion(method,regions[region].id,newPos);      
 
1069
 
 
1070
 
 
1071
 
 
1072
}