1 //------------------------------------------------------------------------------------------------------------
2 /*# ---------------------------------------------------------------------
4 # Copyright (c) CREATIS (Centre de Recherche en Acquisition et Traitement de l'Image
6 # Authors : Eduardo Davila, Frederic Cervenansky, Claire Mouton
7 # Previous Authors : Laurent Guigues, Jean-Pierre Roux
8 # CreaTools website : www.creatis.insa-lyon.fr/site/fr/creatools_accueil
10 # This software is governed by the CeCILL-B license under French law and
11 # abiding by the rules of distribution of free software. You can use,
12 # modify and/ or redistribute the software under the terms of the CeCILL-B
13 # license as circulated by CEA, CNRS and INRIA at the following URL
14 # http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
15 # or in the file LICENSE.txt.
17 # As a counterpart to the access to the source code and rights to copy,
18 # modify and redistribute granted by the license, users are provided only
19 # with a limited warranty and the software's author, the holder of the
20 # economic rights, and the successive licensors have only limited
23 # The fact that you are presently reading this means that you have had
24 # knowledge of the CeCILL-B license and that you accept its terms.
25 # ------------------------------------------------------------------------ */
27 // Class definition include
28 //------------------------------------------------------------------------------------------------------------
29 #include "LogicalColorBar.h"
32 //------------------------------------------------------------------------------------------------------------
33 // Class implementation
34 //------------------------------------------------------------------------------------------------------------
35 /** file LogicalColorBar.cxx */
38 //------------------------------------------------------------------------------------------------------------
39 // Constructors & Destructors
40 //------------------------------------------------------------------------------------------------------------
42 LogicalColorBar :: LogicalColorBar ()
46 bar_orientation = true;
49 LogicalColorBar :: ~ LogicalColorBar ()
51 //logicColorPoints.clear();
54 //------------------------------------------------------------------------------------------------------------
55 // Methods Implementation
56 //------------------------------------------------------------------------------------------------------------
61 // Gets the first point
63 pColorPoint * LogicalColorBar :: getFirstPoint()
65 return logicColorPoints.front();
70 // Gets the last point
72 pColorPoint * LogicalColorBar :: getLastPoint()
74 return logicColorPoints.back();
78 double LogicalColorBar :: getMinValue()
84 void LogicalColorBar :: setMinValue(double valueMin)
90 double LogicalColorBar :: getMaxValue()
96 void LogicalColorBar :: setMaxValue(double valueMax)
102 bool LogicalColorBar :: getOrientation()
104 return bar_orientation;
107 void LogicalColorBar :: setOrientation(bool orientation)
109 bar_orientation = orientation;
113 // Adds a color degrade point to the color bar.
114 // param xRealValue The real xValue of the point
115 // param theColour The assigned color for the point
116 // param temporalStart Indicates if the inserted point is the temporal startShowing point
117 // param temporalEnd Indicates if the inserted point is the temporal startShowing point
118 // return Returns true if the point was succesfully inserted.
120 bool LogicalColorBar :: addColorPoint (double xRealValue, wxColour theColour )
122 bool addedPoint = false;
124 if(xRealValue>=minValue && xRealValue<=maxValue)
126 // bool ifContinue = true; // JPRx
127 //pColorPoint * colorPoint, nextColorPoint;
128 int maxIndex= logicColorPoints.size()-1;
129 // int nextIndex = 0; // JPRx
130 //int nextX = 0; // JPRx
133 std::vector <pColorPoint*>::iterator iter;
134 std::vector <pColorPoint*>::iterator nextIter;
135 pColorPoint * newColorPoint = new pColorPoint ( xRealValue, theColour, false );
136 if(logicColorPoints.empty())
138 logicColorPoints.push_back(newColorPoint);
141 iter = logicColorPoints.begin();
142 for (i=0; i<=maxIndex && !addedPoint; i++)
145 int before = (*iter)->getRealX() ;
146 if(before>xRealValue && i==0)
149 logicColorPoints.insert( iter, newColorPoint );
151 lastAddedPoint = newColorPoint;
153 else if(before<xRealValue && i==maxIndex)
156 logicColorPoints.push_back(newColorPoint );
158 lastAddedPoint = newColorPoint;
164 int after = (*nextIter)->getRealX();
165 if( before < xRealValue && after> xRealValue)
167 logicColorPoints.insert( nextIter, newColorPoint );
169 lastAddedPoint = newColorPoint;
172 //std::cout<<"JCPaddColorPoint iterator "<<*iter<<std::endl;
181 bool LogicalColorBar :: deleteColorPoint ( double valErase )
183 bool deletedPoint = false;
184 std::vector <pColorPoint*>::iterator pointIterator = logicColorPoints.begin();
185 for(int i=0; i<logicColorPoints.size() && !deletedPoint; i++)
187 pColorPoint aPoint =**pointIterator;
188 if(aPoint.getRealX() == valErase)
190 logicColorPoints.erase(pointIterator);
198 void LogicalColorBar :: getPointersToRangeLimits( std::deque<pColorPoint *> &theInputQueue, int &startIndex, int &endIndex, int startSearched, int endSearched )
199 //void LogicalColorBar :: getListIndexRangeLimits( std::vector<pColorPoint *> &theVector, bool &startFOUND, bool &endFOUND, int startSearched, int endSearched );
201 bool foundedStart = false;
202 bool foundedEnd = false;
204 /*for (int i=0; i<logicColorPoints.size()&&(!foundedStart || !foundedEnd);i++)
206 pColorPoint colorPoint = logicColorPoints[i];
207 double actualValue = colorPoint->getRealX();
210 if((startSearched <= actualValue) )
213 if((startSearched == actualValue) )
219 if((actualValue <= endSearched) )
222 if((endSearched == actualValue))
228 for (int i=0; i<logicColorPoints.size()&& !foundedEnd;i++)
230 pColorPoint * colorPoint = logicColorPoints[i];
231 double actualValue = colorPoint->getRealX();
234 if((startSearched <= actualValue) )
237 //if((startSearched == actualValue) )
243 if((actualValue <= endSearched) )
246 if((endSearched == actualValue))
252 if(actualValue>=startSearched && actualValue<=endSearched)
254 if(startSearched<endSearched)
255 theInputQueue.push_back(colorPoint);
260 pColorPoint * LogicalColorBar :: getLastAddedPoint()
262 return lastAddedPoint;
265 pColorPoint * LogicalColorBar :: getPointAtIndex(int anIndex)
267 if(anIndex>=0 && logicColorPoints.size()>anIndex)
268 return logicColorPoints[anIndex];
274 int LogicalColorBar :: getCount()
276 return logicColorPoints.size();
279 void LogicalColorBar :: getDataAt(int index, double &x,int &red,int &green,int &blue)
281 pColorPoint * colorPoint = logicColorPoints[index];
282 wxColour color = colorPoint->getColor();
285 green = color.Green();
286 x = colorPoint->getRealX();
289 void LogicalColorBar :: clearPoints()
291 logicColorPoints.clear();
294 double LogicalColorBar :: getMinAddedValue()
296 return logicColorPoints.front()->getRealX();
299 double LogicalColorBar :: getMaxAddedValue()
301 return logicColorPoints.back()->getRealX();
304 void LogicalColorBar :: changeColor(double pointValue, wxColour theNewColor)
306 bool changedCol = false;
307 for(int i=0; i<logicColorPoints.size() && !changedCol; i++)
309 pColorPoint * aPoint = logicColorPoints[i];
310 if(aPoint->getRealX() == pointValue)
312 aPoint->setColor( theNewColor );
318 bool LogicalColorBar :: setColorPoints (std::vector<pColorPoint *> pointsVector)
320 bool addedAll = true;
321 for(int i=0; i<pointsVector.size() && addedAll; i++)
323 pColorPoint * aPoint = pointsVector[i];
324 addedAll &= addColorPoint(aPoint->getRealX(), aPoint->getColor());
328 minValue = getMinAddedValue();
329 maxValue = getMaxAddedValue();
332 logicColorPoints.clear();