]> Creatis software - creaMaracasVisu.git/blob - lib/maracasVisuLib/src/interface/wxWindows/widgets/pPlotter/pLogicalFunction.h
Support #1768 CREATIS Licence insertion
[creaMaracasVisu.git] / lib / maracasVisuLib / src / interface / wxWindows / widgets / pPlotter / pLogicalFunction.h
1 /*# ---------------------------------------------------------------------
2 #
3 # Copyright (c) CREATIS (Centre de Recherche en Acquisition et Traitement de l'Image
4 #                        pour la Sant�)
5 # Authors : Eduardo Davila, Frederic Cervenansky, Claire Mouton
6 # Previous Authors : Laurent Guigues, Jean-Pierre Roux
7 # CreaTools website : www.creatis.insa-lyon.fr/site/fr/creatools_accueil
8 #
9 #  This software is governed by the CeCILL-B license under French law and
10 #  abiding by the rules of distribution of free software. You can  use,
11 #  modify and/ or redistribute the software under the terms of the CeCILL-B
12 #  license as circulated by CEA, CNRS and INRIA at the following URL
13 #  http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
14 #  or in the file LICENSE.txt.
15 #
16 #  As a counterpart to the access to the source code and  rights to copy,
17 #  modify and redistribute granted by the license, users are provided only
18 #  with a limited warranty  and the software's author,  the holder of the
19 #  economic rights,  and the successive licensors  have only  limited
20 #  liability.
21 #
22 #  The fact that you are presently reading this means that you have had
23 #  knowledge of the CeCILL-B license and that you accept its terms.
24 # ------------------------------------------------------------------------ */
25
26
27 #ifndef __pLogicalFunction_h__
28 #define __pLogicalFunction_h__
29
30 // ----------------------------------------------------------------------------
31 // WX headers inclusion.
32 // For compilers that support precompilation, includes <wx/wx.h>.
33 // ----------------------------------------------------------------------------
34
35 #include <wx/wxprec.h>
36 #ifdef __BORLANDC__
37 #pragma hdrstop
38 #endif
39 #ifndef WX_PRECOMP
40 #include <wx/wx.h>
41 #endif
42
43
44 //----------------------------------------------------------------------------
45 // Includes
46 //----------------------------------------------------------------------------
47
48 #include "pFunctionPoint.h"
49 #include <iostream>
50 #include <fstream>
51 #include <string>
52
53
54
55 class pLogicalFunction;
56 //----------------------------------------------------------------------------
57 // Class definition
58 //----------------------------------------------------------------------------
59 #define MAX_POINTS 50
60
61 //if your are going to change se sensible region  you have to change MOVE in pPlotterLayer
62 #define SENSIBLE_REGION 5
63
64
65 class pLogicalFunction: public wxObject
66 {
67 public:
68
69         //----------------------------------------------------------------------------
70         // Constructors
71         //----------------------------------------------------------------------------
72         pLogicalFunction( );
73
74         ~pLogicalFunction( );
75         
76         /**
77         *Rewind 
78         */
79         /*virtual void Rewind()
80         {
81                 node = realPoints.GetFirst();
82         }
83         */
84         
85         /** Get locus value for next N.
86         Override this function in your implementation.
87         @param x Returns X value
88         @param y Returns Y value
89         */
90         /*virtual bool GetNextXY(double & x, double & y) 
91         {
92                 if(node)
93                 {
94                         pFunctionPoint* p=(pFunctionPoint*)node->GetData();
95                         x=p->getRealX();
96                         y=p->getRealY();
97                         node=node->GetNext();
98                         return true;
99                 }
100                 return false;
101         }
102         */
103
104         /**
105         Get Point list of the funcion
106         @param return points
107         */
108         /*virtual*/
109         void GetPoints(wxList &points)
110         {
111                 points = realPoints;
112         }  
113         /*
114         * validate if the function has that point in a sensible area returning the index where the point was found or -1 if is in not part of the function: define the sensible area is  
115         * x1-validPointRange<x<x1+validPointRange y1-validPointRange<y<y1+validPointRange
116         */
117         int validPointOnFunction(wxPoint realPoint);
118
119         //returns the index in the list of the point  
120         int getIndexOf(wxPoint realpoint);
121
122         /*
123         * This metohd returns the node of the point that is the movingPointIndex position in the list of points.
124         * @param: int movingPointIndex, Is the index value of the searched node.
125         * @return: Return a pointer to the node corresponding to the index value by parameter.
126         */
127         wxNode* GetPointAt( int movingPointIndex);
128
129         /*
130         * Includes a point between two existing points of the this function. The new point (x,y) was not defined when the function was created.
131         *@ return Returns true is the point was succcesfully added to the funcion.
132         */
133         bool AddNewPoint(int x,int y);
134
135         /**
136         * this method add a new logical point to the function, this point is one of those used to draw the function
137         */
138         bool AddPoint(int aX, int aY,bool order=true);
139
140         /**
141         * deletes the point given by the  user  from the collection of logical points of the function
142         */
143         bool DeletePoint(int aX, int aY);
144
145         /**
146         * Change de coordinates of the given point if it is possible and return the result of the invoked action. True if it was possible to do the change.
147         */
148         bool changePoint(wxPoint newCoords, int movingIndexPoint);
149
150         /**
151         * Evaluates if the given point belongs to the function.
152         * IS NO USED
153         */
154         //bool hasPoint(wxPoint aAPoint);
155
156         /**
157         * Returns the real x values of the control points of the function. It dont includes the points calculated by interpolation.
158         */
159         double * getX_RealValues();
160
161         /**
162         * Returns the real y values of the control points of the function. It dont includes the points calculated by interpolation.
163         */
164         double* getY_RealValues();
165         /*
166         * This method orders the list of points taking into account that the last appended node in the list (realPoint) is the only one disordered.
167         * @return Returns true if the last point included has a valid value for x and was ordered, according to the definition of function.
168         */
169         bool orderPoints();
170
171         /**
172         * This method get a pointer to the node in the real points list that is inmediately previous to the searched by parameter.
173         * @pre The seached point (realX, realY) is not the first point of the list.
174         * @param realX
175         * @param realY
176         * IS NOT USED
177         */
178         //wxNode * findPreviousNodeTo( int realX, int realY );
179
180         /*
181          * sets the start point of the function
182          */
183         void  setStartPoints();
184
185         /*
186          * sets the end point of the function
187          */
188         void setEndPoints();
189
190         /*
191          * set the max value in x and y between all the points of the function
192          */
193         void setMaxPoints();
194
195
196         /*
197          * set the min value in x and y between all the points of the function
198          */
199         void setMinPoints();
200         /*
201          * Set Up startPoint, endPoint, maxY,maxX points        
202         */
203         void setUp();
204
205
206         //set if the function has to draw the points  
207         //void SetShowPoints(bool showPoints);
208
209         //get the paramater showPointsF
210         //bool getShowPoints();
211
212         //-----------------------
213         // Persistence
214         //-----------------------
215
216         /*
217          Save the points of the function
218         */
219         void save(wxString fileName);
220         /*
221          Load the points of a function 
222         */
223         void load(wxString fileName);
224
225         //----------------------------
226         //Getters and Setters
227         //----------------------------
228
229         void setStartX(double aStartX);
230
231         double getStartX();
232
233         void setStartY(double aStartY);
234
235         double getStartY();
236
237         void setEndX(double aEndX);
238
239         double getEndX();
240
241         void setEndY(double aEndY);
242
243         double getEndY();
244
245         void setScaleX(double aScaleX);
246
247         double getScaleX();
248
249         void setScaleY(double aScaleY);
250
251         double getScaleY();
252
253         void setMinX(double aMinX);
254
255         double getMinX();
256
257         void setMinY(double aMinY);
258
259         double getMinY();
260
261         void setMaxX(double aMaxX);
262
263         double getMaxX();
264
265         void setMaxY(double aMaxY);
266
267         double getMaxY();
268
269         void setOffsetX(double aOffsetX);
270
271         double getOffsetX();
272
273         void setOffsetY(double aOffsetY);
274
275         double getOffsetY();
276
277         void setType(int aType);
278
279         int getType();
280
281         int getValidPointRange();
282
283         void setValidPointRange(int theRange);
284
285         /**
286         * Deletes a point of the function given its index 
287         */
288         bool deletePointAt(int index);
289         /*
290         * Returns the number of points that the function
291         * has
292         */
293         int getSizePoints();
294
295         void getDirection(bool &dir);
296
297
298
299 private:
300
301         /**
302         * Is the initial discrete point on x axis of the drawed function.
303         */
304         double _startX;
305         /**
306         * Is the initial discrete point on y axis of the drawed function.
307         */
308         double _startY;
309         /**
310         * Is the last discrete point on x axis of the drawed function.
311         */
312         double _endX;
313         /**
314         * Is the last discrete point on y axis of the drawed function.
315         */
316         double _endY;
317         /**
318         * Is the x-scale percentage according to the context device.
319         */
320         double _scaleX;
321         /**
322         * Is the y-scale percentage according to the context device.
323         */
324         double _scaleY;
325         /**
326         * Is the minimun x-real value reacheable by the function.
327         */
328         double _minX;
329         /**
330         * Is the minimun y-real value reacheable by the function.
331         */
332         double _minY;
333         /**
334         * Is the maximun y-real value reacheable by the function.
335         */
336         double _maxX;
337
338         /**
339         * Is the maximun y-real value reacheable by the function.
340         */
341         double _maxY;
342
343         /**
344         * Is the logical x-offset of the drawed function.
345         */
346         double _offsetX;
347         /**
348         * Is the logical y-offset of the drawed function.
349         */
350         double _offsetY;
351         /**
352         * Is the way of how points are going to be connected. It could be smooth, line.
353         */
354         int _type;
355         /**
356         * The list of the function points
357         */
358         wxList realPoints;
359
360         /**
361         *  x-values
362         */
363         double x_Values[MAX_POINTS];
364         /**
365         *  y-values
366         */
367         double y_Values[MAX_POINTS];
368         /**
369         *  node of the realPoints where are we
370         */
371         //wxNode* node;
372         
373         /**
374         * Number that determines the radius range for the valid area the point (sensible radius). Default value 5.
375         */
376         int validPointRange;
377
378         /**
379         * Indicates the way the function is being drawed when defining it. So that it is true if the direction is from left-to-right, and false if it is from right-to-left.
380         * It is initialized when the second point is included in the funcion.
381         */
382         bool leftToRigthDef;
383
384         /**
385         * Indicates if the user is drawing the function
386         */
387         //bool drawing;
388
389
390         DECLARE_CLASS (pLogicalFunction)
391 };
392
393 #endif
394
395