]> Creatis software - creaMaracasVisu.git/blob - lib/maracasVisuLib/src/interface/wxWindows/widgets/pPlotter/LogicalColorBar.cxx
Support #1768 CREATIS Licence insertion
[creaMaracasVisu.git] / lib / maracasVisuLib / src / interface / wxWindows / widgets / pPlotter / LogicalColorBar.cxx
1 //------------------------------------------------------------------------------------------------------------
2 /*# ---------------------------------------------------------------------
3 #
4 # Copyright (c) CREATIS (Centre de Recherche en Acquisition et Traitement de l'Image
5 #                        pour la Sant�)
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
9 #
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.
16 #
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
21 #  liability.
22 #
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 # ------------------------------------------------------------------------ */
26
27 // Class definition include
28 //------------------------------------------------------------------------------------------------------------
29 #include "LogicalColorBar.h"
30
31
32 //------------------------------------------------------------------------------------------------------------
33 // Class implementation
34 //------------------------------------------------------------------------------------------------------------
35 /** file LogicalColorBar.cxx */
36
37
38 //------------------------------------------------------------------------------------------------------------
39 // Constructors & Destructors
40 //------------------------------------------------------------------------------------------------------------
41
42         LogicalColorBar :: LogicalColorBar () 
43         {
44                 minValue = 0;
45                 maxValue = 0;
46                 bar_orientation = true;
47         }
48
49         LogicalColorBar :: ~ LogicalColorBar () 
50         {
51                 //logicColorPoints.clear();
52         }
53
54 //------------------------------------------------------------------------------------------------------------
55 // Methods Implementation 
56 //------------------------------------------------------------------------------------------------------------
57
58
59
60 //
61         // Gets the first point
62         //
63         pColorPoint * LogicalColorBar :: getFirstPoint()
64         {
65                 return logicColorPoints.front();
66         }
67
68
69         //
70         // Gets the last point
71         //
72         pColorPoint * LogicalColorBar :: getLastPoint()
73         {
74                 return logicColorPoints.back();
75         }
76
77
78         double LogicalColorBar :: getMinValue()
79         {
80                 return minValue;
81         }
82
83
84         void  LogicalColorBar :: setMinValue(double valueMin)
85         {
86                 minValue = valueMin;
87         }
88
89
90         double LogicalColorBar :: getMaxValue()
91         {
92                 return maxValue;
93         }
94
95
96         void LogicalColorBar :: setMaxValue(double valueMax)
97         {
98                 maxValue = valueMax;
99         }
100
101
102         bool LogicalColorBar :: getOrientation()
103         {
104                 return bar_orientation;
105         }
106
107         void LogicalColorBar :: setOrientation(bool orientation)
108         {
109                 bar_orientation = orientation;
110         }
111
112         //
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.
119         ////
120         bool LogicalColorBar :: addColorPoint (double xRealValue, wxColour theColour )
121         {
122                 bool addedPoint = false;
123                 
124                 if(xRealValue>=minValue && xRealValue<=maxValue)
125                 {
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
131                         int i = 0;
132                                         
133                         std::vector <pColorPoint*>::iterator iter;
134                         std::vector <pColorPoint*>::iterator nextIter;
135                         pColorPoint * newColorPoint = new pColorPoint ( xRealValue, theColour, false );
136                         if(logicColorPoints.empty())
137                         {
138                                 logicColorPoints.push_back(newColorPoint);
139                                 addedPoint = true;
140                         }else{                          
141                                 iter = logicColorPoints.begin();
142                                 for (i=0; i<=maxIndex && !addedPoint; i++)
143                                 {
144                                         nextIter = iter;
145                                         int before = (*iter)->getRealX() ;
146                                         if(before>xRealValue && i==0)
147                                         {
148                                                 //Is the first point
149                                                 logicColorPoints.insert( iter, newColorPoint );
150                                                 addedPoint =true;
151                                                 lastAddedPoint = newColorPoint;
152                                         }
153                                         else if(before<xRealValue && i==maxIndex)
154                                         {
155                                                 //Is the last point 
156                                                 logicColorPoints.push_back(newColorPoint );     
157                                                 addedPoint =true;
158                                                 lastAddedPoint = newColorPoint;
159                                         }
160                                         else if(i<maxIndex)
161                                         {
162                                                 //
163                                                 nextIter++;                     
164                                                 int after = (*nextIter)->getRealX();                            
165                                                 if( before < xRealValue && after> xRealValue)
166                                                 {
167                                                         logicColorPoints.insert( nextIter, newColorPoint );     
168                                                         addedPoint =true;
169                                                         lastAddedPoint = newColorPoint;
170                                                 }
171                                         }               
172                                         //std::cout<<"JCPaddColorPoint iterator "<<*iter<<std::endl;
173                                         if(!addedPoint)
174                                                 ++iter;
175                                 }               
176                         }                       
177                 }
178                 return addedPoint;              
179         }
180
181         bool LogicalColorBar :: deleteColorPoint ( double  valErase )
182         {
183                 bool deletedPoint = false;              
184                 std::vector <pColorPoint*>::iterator pointIterator = logicColorPoints.begin();
185                 for(int i=0; i<logicColorPoints.size() && !deletedPoint; i++)
186                 {
187                         pColorPoint  aPoint =**pointIterator;
188                         if(aPoint.getRealX() == valErase)
189                         {
190                                 logicColorPoints.erase(pointIterator);
191                                 deletedPoint = true;
192                         }                       
193                         pointIterator++;
194                 }
195                 return deletedPoint;
196         }
197         
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 );
200         {
201                 bool foundedStart = false;
202                 bool foundedEnd = false;
203                 
204                 /*for (int i=0; i<logicColorPoints.size()&&(!foundedStart || !foundedEnd);i++)
205                 {
206                         pColorPoint colorPoint = logicColorPoints[i];
207                         double actualValue = colorPoint->getRealX();
208                         if(!foundedStart)
209                         {
210                                 if((startSearched <= actualValue) )
211                                 {
212                                         startIndex = i;
213                                         if((startSearched == actualValue) )
214                                                 foundedStart = true;
215                                 }                                       
216                         }
217                         if(!foundedEnd)
218                         {
219                                 if((actualValue <= endSearched) )
220                                 {
221                                         endIndex = i;
222                                         if((endSearched == actualValue))
223                                                 foundedEnd = true;
224                                 }                       
225                         }                                               
226                 }               */
227
228                 for (int i=0; i<logicColorPoints.size()&& !foundedEnd;i++)
229                 {
230                         pColorPoint * colorPoint = logicColorPoints[i];
231                         double actualValue = colorPoint->getRealX();
232                         if(!foundedStart)
233                         {
234                                 if((startSearched <= actualValue) )
235                                 {
236                                         startIndex = i;
237                                         //if((startSearched == actualValue) )                                   
238                                         foundedStart = true;                                                                                    
239                                 }                                       
240                         }
241                         if(!foundedEnd)
242                         {
243                                 if((actualValue <= endSearched) )
244                                 {
245                                         endIndex = i;
246                                         if((endSearched == actualValue))
247                                         {
248                                                 foundedEnd = true;                                              
249                                         }
250                                 }                       
251                         }                                               
252                         if(actualValue>=startSearched && actualValue<=endSearched)
253                         {
254                                 if(startSearched<endSearched)
255                                         theInputQueue.push_back(colorPoint);
256                         }
257                 }                       
258         }
259
260         pColorPoint * LogicalColorBar :: getLastAddedPoint()
261         {
262                 return lastAddedPoint;
263         }
264
265         pColorPoint * LogicalColorBar :: getPointAtIndex(int anIndex)
266         {
267                 if(anIndex>=0 && logicColorPoints.size()>anIndex)
268                         return logicColorPoints[anIndex];
269                 else
270                         return NULL;
271         }
272
273         
274         int LogicalColorBar :: getCount()
275         {
276                 return logicColorPoints.size();
277         }
278
279         void LogicalColorBar :: getDataAt(int index, double &x,int &red,int &green,int &blue)
280         {
281                 pColorPoint * colorPoint = logicColorPoints[index];             
282                 wxColour color = colorPoint->getColor();
283                 red = color.Red();
284                 blue = color.Blue();
285                 green = color.Green();
286                 x = colorPoint->getRealX();
287         }
288
289         void LogicalColorBar :: clearPoints()
290         {       
291                 logicColorPoints.clear();
292         }
293
294         double LogicalColorBar :: getMinAddedValue()
295         {
296                 return logicColorPoints.front()->getRealX();            
297         }
298
299         double LogicalColorBar :: getMaxAddedValue()
300         {
301                 return logicColorPoints.back()->getRealX();
302         }
303
304         void LogicalColorBar :: changeColor(double pointValue, wxColour theNewColor)
305         {
306                 bool changedCol = false;
307                 for(int i=0; i<logicColorPoints.size() && !changedCol; i++)
308                 {
309                         pColorPoint * aPoint = logicColorPoints[i];
310                         if(aPoint->getRealX() == pointValue)
311                         {
312                                 aPoint->setColor( theNewColor );
313                                 changedCol = true;
314                         }                       
315                 }
316         }
317
318         bool LogicalColorBar :: setColorPoints (std::vector<pColorPoint *> pointsVector)
319         {
320                 bool addedAll = true;
321                 for(int i=0; i<pointsVector.size() && addedAll; i++)
322                 {
323                         pColorPoint * aPoint  = pointsVector[i];
324                         addedAll &= addColorPoint(aPoint->getRealX(), aPoint->getColor());
325                 }
326                 if(addedAll)
327                 {
328                         minValue = getMinAddedValue();
329                         maxValue = getMaxAddedValue();
330                 }
331                 else
332                         logicColorPoints.clear();
333
334                 return addedAll;
335         }
336    
337