]> Creatis software - creaMaracasVisu.git/blob - lib/maracasVisuLib/src/interface/wxWindows/widgets/pPlotter/pLogicalFunction.h
#3472 TDx
[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 //EED 2017-09-16 Migration wxWidgets 2.8 to 3.0
106 #if wxMAJOR_VERSION <= 2
107         /**
108         Get Point list of the funcion
109         @param return points
110         */
111         /*virtual*/
112         void GetPoints(wxList &points)
113         {
114                 points = realPoints;
115         }  
116 #else
117         /**
118         Get Point list of the funcion
119         @param return pointsPtr
120         */
121         /*virtual*/
122         wxList* GetPointsPtr()
123         {
124                 return &realPoints;
125         }  
126 #endif
127
128
129         /*
130         * 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  
131         * x1-validPointRange<x<x1+validPointRange y1-validPointRange<y<y1+validPointRange
132         */
133         int validPointOnFunction(wxPoint realPoint);
134
135         //returns the index in the list of the point  
136         int getIndexOf(wxPoint realpoint);
137
138         /*
139         * This metohd returns the node of the point that is the movingPointIndex position in the list of points.
140         * @param: int movingPointIndex, Is the index value of the searched node.
141         * @return: Return a pointer to the node corresponding to the index value by parameter.
142         */
143         wxNode* GetPointAt( int movingPointIndex);
144
145         /*
146         * Includes a point between two existing points of the this function. The new point (x,y) was not defined when the function was created.
147         *@ return Returns true is the point was succcesfully added to the funcion.
148         */
149         bool AddNewPoint(int x,int y);
150
151         /**
152         * this method add a new logical point to the function, this point is one of those used to draw the function
153         */
154         bool AddPoint(int aX, int aY,bool order=true);
155
156         /**
157         * deletes the point given by the  user  from the collection of logical points of the function
158         */
159         bool DeletePoint(int aX, int aY);
160
161         /**
162         * 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.
163         */
164         bool changePoint(wxPoint newCoords, int movingIndexPoint);
165
166         /**
167         * Evaluates if the given point belongs to the function.
168         * IS NO USED
169         */
170         //bool hasPoint(wxPoint aAPoint);
171
172         /**
173         * Returns the real x values of the control points of the function. It dont includes the points calculated by interpolation.
174         */
175         double * getX_RealValues();
176
177         /**
178         * Returns the real y values of the control points of the function. It dont includes the points calculated by interpolation.
179         */
180         double* getY_RealValues();
181         /*
182         * This method orders the list of points taking into account that the last appended node in the list (realPoint) is the only one disordered.
183         * @return Returns true if the last point included has a valid value for x and was ordered, according to the definition of function.
184         */
185         bool orderPoints();
186
187         /**
188         * This method get a pointer to the node in the real points list that is inmediately previous to the searched by parameter.
189         * @pre The seached point (realX, realY) is not the first point of the list.
190         * @param realX
191         * @param realY
192         * IS NOT USED
193         */
194         //wxNode * findPreviousNodeTo( int realX, int realY );
195
196         /*
197          * sets the start point of the function
198          */
199         void  setStartPoints();
200
201         /*
202          * sets the end point of the function
203          */
204         void setEndPoints();
205
206         /*
207          * set the max value in x and y between all the points of the function
208          */
209         void setMaxPoints();
210
211
212         /*
213          * set the min value in x and y between all the points of the function
214          */
215         void setMinPoints();
216         /*
217          * Set Up startPoint, endPoint, maxY,maxX points        
218         */
219         void setUp();
220
221
222         //set if the function has to draw the points  
223         //void SetShowPoints(bool showPoints);
224
225         //get the paramater showPointsF
226         //bool getShowPoints();
227
228         //-----------------------
229         // Persistence
230         //-----------------------
231
232         /*
233          Save the points of the function
234         */
235         void save(wxString fileName);
236         /*
237          Load the points of a function 
238         */
239         void load(wxString fileName);
240
241         //----------------------------
242         //Getters and Setters
243         //----------------------------
244
245         void setStartX(double aStartX);
246
247         double getStartX();
248
249         void setStartY(double aStartY);
250
251         double getStartY();
252
253         void setEndX(double aEndX);
254
255         double getEndX();
256
257         void setEndY(double aEndY);
258
259         double getEndY();
260
261         void setScaleX(double aScaleX);
262
263         double getScaleX();
264
265         void setScaleY(double aScaleY);
266
267         double getScaleY();
268
269         void setMinX(double aMinX);
270
271         double getMinX();
272
273         void setMinY(double aMinY);
274
275         double getMinY();
276
277         void setMaxX(double aMaxX);
278
279         double getMaxX();
280
281         void setMaxY(double aMaxY);
282
283         double getMaxY();
284
285         void setOffsetX(double aOffsetX);
286
287         double getOffsetX();
288
289         void setOffsetY(double aOffsetY);
290
291         double getOffsetY();
292
293         void setType(int aType);
294
295         int getType();
296
297         int getValidPointRange();
298
299         void setValidPointRange(int theRange);
300
301         /**
302         * Deletes a point of the function given its index 
303         */
304         bool deletePointAt(int index);
305         /*
306         * Returns the number of points that the function
307         * has
308         */
309         int getSizePoints();
310
311         void getDirection(bool &dir);
312
313
314
315 private:
316
317         /**
318         * Is the initial discrete point on x axis of the drawed function.
319         */
320         double _startX;
321         /**
322         * Is the initial discrete point on y axis of the drawed function.
323         */
324         double _startY;
325         /**
326         * Is the last discrete point on x axis of the drawed function.
327         */
328         double _endX;
329         /**
330         * Is the last discrete point on y axis of the drawed function.
331         */
332         double _endY;
333         /**
334         * Is the x-scale percentage according to the context device.
335         */
336         double _scaleX;
337         /**
338         * Is the y-scale percentage according to the context device.
339         */
340         double _scaleY;
341         /**
342         * Is the minimun x-real value reacheable by the function.
343         */
344         double _minX;
345         /**
346         * Is the minimun y-real value reacheable by the function.
347         */
348         double _minY;
349         /**
350         * Is the maximun y-real value reacheable by the function.
351         */
352         double _maxX;
353
354         /**
355         * Is the maximun y-real value reacheable by the function.
356         */
357         double _maxY;
358
359         /**
360         * Is the logical x-offset of the drawed function.
361         */
362         double _offsetX;
363         /**
364         * Is the logical y-offset of the drawed function.
365         */
366         double _offsetY;
367         /**
368         * Is the way of how points are going to be connected. It could be smooth, line.
369         */
370         int _type;
371         /**
372         * The list of the function points
373         */
374         wxList realPoints;
375
376         /**
377         *  x-values
378         */
379         double x_Values[MAX_POINTS];
380         /**
381         *  y-values
382         */
383         double y_Values[MAX_POINTS];
384         /**
385         *  node of the realPoints where are we
386         */
387         //wxNode* node;
388         
389         /**
390         * Number that determines the radius range for the valid area the point (sensible radius). Default value 5.
391         */
392         int validPointRange;
393
394         /**
395         * 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.
396         * It is initialized when the second point is included in the funcion.
397         */
398         bool leftToRigthDef;
399
400         /**
401         * Indicates if the user is drawing the function
402         */
403         //bool drawing;
404
405
406         DECLARE_CLASS (pLogicalFunction)
407 };
408
409 #endif
410
411