]> Creatis software - creaMaracasVisu.git/blob - lib/maracasVisuLib/src/interface/wxWindows/widgets/pPlotter/pGraphicalFunction.h
Support #1768 CREATIS Licence insertion
[creaMaracasVisu.git] / lib / maracasVisuLib / src / interface / wxWindows / widgets / pPlotter / pGraphicalFunction.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
28 #ifndef __pGraphicalFunction_h__
29 #define __pGraphicalFunction_h__
30
31 // ----------------------------------------------------------------------------
32 // WX headers inclusion.
33 // For compilers that support precompilation, includes <wx/wx.h>.
34 // ----------------------------------------------------------------------------
35
36 #include <wx/wxprec.h>
37 #ifdef __BORLANDC__
38 #pragma hdrstop
39 #endif
40 #ifndef WX_PRECOMP
41 #include <wx/wx.h>
42 #endif
43
44
45 //----------------------------------------------------------------------------
46 // Includes
47 //----------------------------------------------------------------------------
48
49
50 #include "pPlotterLayer.h"
51 #include "pFunctionPoint.h"
52 #include "pLogicalFunction.h"
53 #include "pColorPoint.h"
54 #include "vtkKochanekSpline.h"
55 #include <vector>
56 #include <iostream>
57 #include <fstream>
58
59 /**
60  this scale, scales each function with its maximum x, and maximum y
61  in its points
62 */
63 #define DEFECT_SCALE 1
64 /**
65  this scale with the maximun x  and y of all the functions defined
66 */
67 #define MAX_SCALE 2
68 /**
69  this scales with the scale giving by the user of the widget
70 */
71 #define USER_SCALE 3
72
73 /*
74  Types of Plotter
75 */
76 /*
77  Lets to the user to plot any number of the
78  functions
79 */
80 #define DEFAULT 1
81 /*
82  Dont let draw on the plotter, but lets to edit
83  the functions that are editables in the plotter
84 */
85 #define HISTOGRAM 2
86
87 class pGraphicalFunction;
88 //----------------------------------------------------------------------------
89 // Class definition
90 //----------------------------------------------------------------------------
91
92
93 class pGraphicalFunction: public pPlotterLayer
94 {
95 public:
96
97         //constructor 
98         pGraphicalFunction(wxString name= wxEmptyString, int flags= mpALIGN_RIGHT);
99
100         ~pGraphicalFunction( );
101         
102         //---------------------------
103         //Virtual Mehods
104         //---------------------------
105
106         /**
107          Get the value of the traslation
108         in the x-axis
109         */
110         virtual int getXTraslation()
111         {
112                 return xTraslation;
113         }
114
115
116
117
118         /**
119          Get the type of the curve
120          1=normal function
121          2=Histogram
122         */
123         virtual int getmType()
124         {
125                 return mType;
126         }
127
128         /**
129          Get the type of the curve
130          1=piecewise functio
131          2= smooth
132         */
133         virtual int vGetType()
134         {
135                 return _type;
136         }
137
138         /**
139          Get _offsetX and _offsetY
140         */
141
142         virtual void getOffsets(int &offsetX,int &offSetY )
143         {
144                 offsetX=(int)_offsetX;
145                 offsetY=(int)_offsetY;
146         }
147         
148         /*
149         * Get the factor zoom
150         */
151         virtual void getFactorZoom(float & fz)
152         {
153                 fz=factorZoom;
154         }
155
156
157         /*
158         * Get the value of fromWindow
159         */
160         virtual void getFromWindowV(bool &fw)
161         {
162                 fw=fromWindow;
163         }
164
165
166         /**
167         * if the function that is drawing is the actual
168         */
169         virtual void getIfActual(bool &actual)
170         {
171                 actual=ifActual;
172         }
173
174         /**
175         * get the max of the function in x and y
176         */
177         virtual void getMax(int & maxX, int &maxY)
178         {
179                 maxX=(int)getMaxX();
180             maxY=(int)getMaxY();
181         }
182         /**
183         * get the maxShowed of the function in x and y
184         */
185         virtual void getMaxShowed(int & maxX, int &maxY)
186         {
187                 maxX=(int)getMaxXShowed();
188                 maxY=(int)getMaxYShowed();
189         }
190         /**
191         * get the minShowed of the function in x and y
192         */
193         virtual void getMinShowed(int & minX, int &minY)
194         {
195                 minX=(int)getMinXShowed();
196                 minY=(int)getMinYShowed();
197         }
198
199         /**
200         * Get screens of the function
201         */
202         virtual void getScreens(int & scrX, int & scrY)
203         {
204       scrX=screenX;
205           scrY=screenY;
206         }
207
208         /**
209         * Set screens value
210         */
211         virtual void setScreens(int scrX,int scrY)
212         {
213                 screenX=scrX;
214                 screenY=scrY;                   
215         }
216         
217         /**
218         * Let us know the scale of the function
219         */
220         virtual void getScales(double & scaleX,double & scaleY)
221         {
222                 scaleX=_scaleX;
223                 scaleY=_scaleY;
224         }
225         
226         
227         /**
228         * Let us Know if the user has finished the drawing
229         * that starts before.
230         */
231
232         virtual void getDrawing(bool &draw)
233         {
234                 draw = drawing;
235         }
236
237         /**
238         Let us Know if the user want to see the points of the function
239         of other color than the color of the lines
240         */
241         virtual void ifShowPoints(bool & show)
242         {
243                 show = showPointsF;
244         }
245
246         /**
247         *Rewind 
248         */
249         virtual void Rewind()
250         {
251                                 
252                 node = logicFunction->GetPointAt(0);
253                 
254         }
255
256         /** Get locus value for next N.
257         Override this function in your implementation.
258         @param x Returns X value
259         @param y Returns Y value
260         */
261         virtual bool GetNextXY(double & x, double & y) 
262         {
263                 if(node)
264                 {
265                         pFunctionPoint* p=(pFunctionPoint*)node->GetData();
266                         x=p->getRealX();
267                         y=p->getRealY();
268                         node=node->GetNext();
269                         return true;
270                 }
271                 return false;
272         }
273         /**
274         Get Point list of the funcion
275         @param return points
276         */
277         virtual void GetPoints(wxList &points)
278         {
279                 logicFunction->GetPoints(points);
280                 //points = realPoints;
281         }  
282
283         /**
284         Get the point where the user
285         made a click
286         */
287
288         virtual void getMousePoint(int &x,int &y)
289         {
290                 x=mousePoint.x;
291                 y=mousePoint.y;
292         }
293
294         /**
295         * Get the number of points of the function
296         */
297         virtual void getSize(int &size)
298         {
299                 size=getSizePoints();
300         }
301
302         /**
303         * this method gets the direction of the drawing
304         */
305         virtual void getDirection(bool &dir)
306         {               
307                 logicFunction -> getDirection (dir);
308         }
309
310         //---------------------------
311         // Methods
312         //---------------------------
313         /*
314         * 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  
315         * x1-validPointRange<x<x1+validPointRange y1-validPointRange<y<y1+validPointRange
316         */
317         int validPointOnFunction(wxPoint realPoint);
318
319         //returns the index in the list of the point  
320         int getIndexOf(wxPoint realpoint);
321
322         /*
323         * This metohd returns the node of the point that is the movingPointIndex position in the list of points.
324         * @param: int movingPointIndex, Is the index value of the searched node.
325         * @return: Return a pointer to the node corresponding to the index value by parameter.
326         */
327         wxNode* GetPointAt( int movingPointIndex);
328
329         /*
330         * Includes a point between two existing points of the this function. The new point (x,y) was not defined when the function was created.
331         *@ return Returns true is the point was succcesfully added to the funcion.
332         */
333         bool AddNewPoint(int x,int y);
334
335         /**
336         * this method add a new logical point to the function, this point is one of those used to draw the function
337         */
338         bool AddPoint(int aX, int aY,bool order=true);
339
340         /**
341         * deletes the point given by the  user  from the collection of logical points of the function
342         */
343         bool DeletePoint(int aX, int aY);
344
345         /**
346         * 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.
347         */
348         bool changePoint(wxPoint newCoords, int movingIndexPoint);
349
350         /**
351         * Evaluates if the given point belongs to the function.
352         */
353         //bool hasPoint(wxPoint aAPoint);
354
355         /**
356         * Returns the real x values of the control points of the function. It dont includes the points calculated by interpolation.
357         */
358         double * getX_RealValues();
359
360         /**
361         * Returns the real y values of the control points of the function. It dont includes the points calculated by interpolation.
362         */
363         double* getY_RealValues();
364         /*
365         * This method orders the list of points taking into account that the last appended node in the list (realPoint) is the only one disordered.
366         * @return Returns true if the last point included has a valid value for x and was ordered, according to the definition of function.
367         */
368         bool orderPoints();
369
370         /**
371         * This method get a pointer to the node in the real points list that is inmediately previous to the searched by parameter.
372         * @pre The seached point (realX, realY) is not the first point of the list.
373         * @param realX
374         * @param realY 
375         */
376         //wxNode * findPreviousNodeTo( int realX, int realY );
377
378         /**
379         * Deletes a point of the function given its index 
380         */
381         bool deletePointAt(int index);
382         /*
383         * Returns the number of points that the function
384         * has
385         */
386         int getSizePoints();
387         /*
388         * Set the scales of the function in x and y
389         */
390         void setScales();
391
392         //----------------------------------
393         // Asking if it has a point (x,y)
394         //----------------------------------
395
396         /*
397         * returns true if the point is along the function
398         * false otherway
399         */
400         bool isInFunction(int x, int y);
401         /*
402         * give us the point that is in the function and is exactly before
403         * the point we are giving
404         */
405         wxNode* getBefore(pFunctionPoint* point);
406         /*
407         * Returns true if the point is in the line
408         */
409         bool isInLine(pFunctionPoint* before,pFunctionPoint* next, pFunctionPoint* point);
410         /**
411         * give us the value of y in the line define by the arguments
412         */
413         double interpolateY(double m, int x1,int y1,int x);
414         /*
415          * Set Up startPoint, endPoint, maxY,maxX points        
416         */
417         void setUp();
418         //----------------------------
419         // Spline Methods
420         //----------------------------
421         /*
422         * clear the spline vectors
423         */
424         void clearSplineVectors();
425
426
427         /*
428         Initiliaze xSpline and ySpline vectors
429         */
430         void initializeSplines();
431         
432         /*
433         Add the (x,y) points of the function to the 
434         spline
435         */
436         void addSplinesPoints();
437         
438         /*
439          This Method adds the point calculated by
440          the splines to the vectors
441         */
442         void initializeSplineVectors();
443         
444         /*
445          get the spline point for t, in xKSpline and yKSpline
446         */
447         void GetSplinePoint(double t, double &x, double &y); 
448         /*
449          returns the xSpline to plotter
450         */
451         virtual std::vector<double> getXSpline()
452         {
453                 return xSpline;
454         }
455         /*
456          returns the ySpline to plotter
457         */
458         virtual std::vector<double> getYSpline()
459         {
460                 return ySpline;
461         }
462
463
464         /**
465         Gets the x-offset of the zoom
466         in pixels
467         */
468         virtual int getOffsetPixelsXv()
469         {
470                 return offsetPixelX;
471         }       
472         
473         /**
474         Gets the offset of the zoom
475         in pixels
476         */
477         virtual int getOffsetPixelsYv()
478         {
479                 return offsetPixelY;
480         }
481
482         //-----------------------
483         // Persistence
484         //-----------------------
485
486         /*
487          Save the points of the function
488         */
489         void save(wxString fileName);
490         /*
491          Load the points of a function 
492         */
493         void load(wxString fileName);
494
495     //------------------------------
496         // Getters and Setters
497         //------------------------------
498
499         //set if the function has to draw the points  
500         void SetShowPoints(bool showPoints);
501
502         //get the paramater showPointsF
503         bool getShowPoints();
504
505         void setScreenX(int scrX);
506
507         int getScreenX();
508
509         void setScreenY(int scrY);
510
511         int getScreenY();
512         
513         void setStartX(double aStartX);
514
515         double getStartX();
516
517         void setStartY(double aStartY);
518
519         double getStartY();
520
521         void setEndX(double aEndX);
522
523         double getEndX();
524
525         void setEndY(double aEndY);
526
527         double getEndY();
528
529         void setScaleX(double aScaleX);
530
531         double getScaleX();
532
533         void setScaleY(double aScaleY);
534
535         double getScaleY();
536
537         void setMinX(double aMinX);
538
539         double getMinX();
540
541         void setMinY(double aMinY);
542
543         double getMinY();
544         
545         void setMaxX(double aMaxX);
546
547         double getMaxX();
548
549         void setMaxY(double aMaxY);
550
551         double getMaxY();
552
553         void setOffsetX(double aOffsetX);
554
555         double getOffsetX();
556
557         void setOffsetY(double aOffsetY);
558
559         double getOffsetY();
560
561         void setType(int aType);
562
563         int getType();
564
565         int getValidPointRange();
566
567         void setValidPointRange(int theRange);
568
569         void SetDrawing(bool d)
570         {
571                 drawing = d;
572         }
573         //get if the function is being drawed
574         bool GetDrawing()
575         {
576                 return drawing;
577         }
578
579         //set the mouse point
580         void SetMousePoint(wxPoint p)
581         { 
582                 mousePoint = p;
583         }
584         //get the mousePoint
585         wxPoint getMousePoint()
586         {
587                 return mousePoint;
588         }
589         /**
590         * actual
591         */
592         void setActual(bool act);
593
594         bool getActual();
595
596         /**
597         * SCALE WAY
598         * DEFECT_SCALE 1
599         * MAX_SCALE 2
600         * USER_SCALE 3
601         */
602         void setScaleWay(int typeS);
603
604         int  getScaleWay();
605         
606         /**
607         * set fromWindow: it is set to true if the
608         * function was created interactively
609         */
610         void setFromWindow(bool w)
611         {
612                 fromWindow=w;
613         }
614         
615         /*
616         * Get the value of fromWindow
617         */
618         bool getFromWindow()
619         {
620                 return fromWindow;
621         }
622         /*
623         *  Set factor zoom
624         */
625         void setFactorZoom(float factor)
626         {
627                 factorZoom=factor;
628         }
629         /*
630         * Set editable
631         */
632         void setEditable(bool edit)
633         {
634                 editable=edit;
635         }
636         /**
637         * Get editable
638         */
639         bool getEditable()
640         {
641                 return editable;
642         }
643
644         //----------------------------
645         // Zoom
646         //----------------------------
647
648         /* 
649          * Get boolean zoom
650          */
651         bool getZoomB()
652         {
653                 return zoomIn;
654         }
655         /* *
656          * Set boolean zoom
657          * @param z: the new value
658          */
659         void setZoomIn(bool z)
660         {
661                 zoomIn=z;
662         }
663         /**
664         * Set the initial drawing point
665         * @param pFunctionPoint* initialPoint
666         */
667         void setInitialDrawPoint(pFunctionPoint* initialPoint)
668         {
669                 initialDrawingPoint=initialPoint;       
670         }
671         /**
672         * Get the initial drawing point
673         * @return initialDrawingPoint
674         */
675         pFunctionPoint* getInitialDrawPoint()
676         {
677                 return initialDrawingPoint;     
678         }
679         /**
680         * Set the final drawing point
681         * @param pFunctionPoint* finalPoint
682         */
683         void setFinalDrawPoint(pFunctionPoint* finalPoint)
684         {
685                 finalDrawingPoint=finalPoint;   
686         }
687         /**
688         * Get the final drawing point
689         * @return finalDrawingPoint
690         */
691         pFunctionPoint* getFinallDrawPoint()
692         {
693                 return finalDrawingPoint;       
694         }
695         /**
696         This method set the initial point and the final point of drawing
697         according with the width of the square around the point clicked
698         @param clickedX
699         @param clickedY
700         @param width: width of the square
701         */
702         
703         void zooming(int clickedX,int clickedY,int width);
704         
705         /*
706         * This method sets the offset 
707         */
708         void setOffsets(int offx,int offy);
709         
710         /*
711         *  This method sets the minShowedX 
712         *  and the minShowedY, accordig to the offset in
713         *  x-axis and y-axis respectively
714         *  pre: _offsetX>=0,_offsetY>=0
715         */
716         void setMinShowed();
717
718         /**
719         Get the minX Showed
720         */
721         int getMinXShowed()
722         {
723                 return minShowedX;
724         }
725         /**
726         Get the minY Showed
727         */
728         int getMinYShowed()
729         {
730                 return minShowedY;
731         }
732         /**
733         Get the maxX Showed
734         */
735         int getMaxXShowed()
736         {
737                 return maxShowedX;
738         }
739         /**
740         Get the maxY Showed
741         */
742         int getMaxYShowed()
743         {
744                 return maxShowedY;
745         }
746         /**
747          Set the minShowedX
748         */
749         void setMinShowedX(int msx)
750         {
751                 minShowedX=msx;
752         }
753         /**
754          Set the minShowedY
755         */
756         void setMinShowedY(int msy)
757         {
758                 minShowedY=msy;
759         }
760         /**
761          Set the maxShowedX
762         */
763         void setMaxShowedX(int msx)
764         {
765                 maxShowedX=msx;
766         }
767         /**
768          Set the minShowedY
769         */
770         void setMaxShowedY(int msy)
771         {
772                 maxShowedY=msy;
773         }
774
775         //------------------------
776         // Offsets in pixels 
777         //------------------------
778         
779         /**
780         Gets the x-offset of the zoom
781         in pixels
782         */
783         int getOffsetPixelsX()
784         {
785                 return offsetPixelX;
786         }       
787         
788         /**
789         Gets the offset of the zoom
790         in pixels
791         */
792         int getOffsetPixelsY()
793         {
794                 return offsetPixelY;
795         }
796         /**
797          Set the x-offset of the zoom
798         */
799         void setOffsetPixelX(int offX)
800         {
801                 offsetPixelX=offX;
802         }
803         /**
804          Set the y-offset of the zoom
805         */
806         void setOffsetPixelY(int offY)
807         {
808                 offsetPixelY=offY;
809         }       
810
811         
812
813         /*
814         * Sets the color points of the function by teh given parameter
815         * @param colorVector Is the color points vector to set
816         */
817         void setColorPoints(std::vector<pColorPoint *> &colorVector);
818
819         /*
820         * Gets the color points of the function in the given parameter
821         * @param colorVector Is the color points list to get the points
822         */
823         void getColorPoints(std::vector<pColorPoint *> &colorVector);
824         /*
825          Setter the mType
826         */
827         void setmType(int mt)
828         {
829                 mType=mt;
830         }
831         //-----------------------
832         //TRASLATION
833         //-----------------------
834         /**
835          Set the value of the traslation
836          in the x-axis
837          @param xT value in pixels of the traslation in x-axis
838         */
839         void setXTraslation(int xT)
840         {
841                  xTraslation=xT;
842         }
843         
844
845
846 private:
847
848         /**
849         * Represents the logical function asociated to this graphical function.
850         */
851         pLogicalFunction* logicFunction;
852         /**
853         * If the function has to showpoints
854         */
855         bool showPointsF;
856
857         /**
858         * Is the initial discrete point on x axis of the drawed function.
859         */
860         double _startX;
861         /**
862         * Is the initial discrete point on y axis of the drawed function.
863         */
864         double _startY;
865         /**
866         * Is the last discrete point on x axis of the drawed function.
867         */
868         double _endX;
869         /**
870         * Is the last discrete point on y axis of the drawed function.
871         */
872         double _endY;
873         /**
874         * Is the x-scale percentage according to the context device.
875         */
876         double _scaleX;
877         /**
878         * Is the y-scale percentage according to the context device.
879         */
880         double _scaleY;
881         /**
882         * Is the minimun x-real value reacheable by the function.
883         */
884         double _minX;
885         /**
886         * Is the minimun y-real value reacheable by the function.
887         */
888         double _minY;
889         /**
890         * Is the maximun x-real value reacheable by the function.
891         */
892         double _maxX;
893         /**
894         * Is the maximun y-real value reacheable by the function.
895         */
896         double _maxY;
897         /**
898         * Is the logical x-offset of the drawed function.
899         */
900         double _offsetX;
901         /**
902         * Is the logical y-offset of the drawed function.
903         */
904         double _offsetY;
905         /**
906         * Is the way of how points are going to be connected. It could be smooth, line.
907         */
908         int _type;
909         /**
910         * The list of the function points
911         */
912         wxList realPoints;
913         /*
914         * The list of the color points of the function associated to the color bar
915         */
916         std::vector<pColorPoint *> f_colorPoints;
917
918         /**
919         *  node of the realPoints where are we
920         */
921         wxNode* node;
922         /**
923         * Number that determines the radius range for the valid area the point (sensible radius). Default value 5.
924         */
925         int validPointRange;
926
927         /**
928         * Indicates if the user is drawing the function
929         */
930         bool drawing; 
931
932         /**
933         * this is for the graphical function
934         * Mouse Point
935         */
936         wxPoint mousePoint;
937
938         /**
939         * The size of the screen in X
940         */
941         int screenX;
942         
943         /**
944         * The size of the screen in Y
945         */
946         int screenY;
947         /**
948           if is the actual
949         */
950         bool ifActual;
951         
952         /**
953          the way we scale
954          DEFECT_SCALE 1
955          MAX_SCALE 2
956          USER_SCALE 3
957         */
958         
959         int scaleWay;
960
961         /**
962          if the function comes from window
963         */
964     bool fromWindow;
965         /**
966         * factorZoom
967         */
968         float factorZoom;
969         /**
970         * The function is editable
971         */
972         bool editable;
973          /**
974          * if the user did a zoom in/out
975          */
976         bool zoomIn;
977         /**
978         * initial drawing point
979         */
980         pFunctionPoint* initialDrawingPoint;
981         /**
982         * final drawing point
983         */
984         pFunctionPoint* finalDrawingPoint;
985         /**
986          Minimum point showed to the user
987          (zoom)X
988         */
989         int minShowedX;
990         /**
991          Maximum point showed to the user
992          (zoom)X
993         */
994         int maxShowedX;
995         /**
996          Minimum point showed to the user
997          (zoom)Y
998         */
999         int minShowedY;
1000         /**
1001          Maximum point showed to the user
1002          (zoom)X
1003         */
1004         int maxShowedY;
1005         
1006         
1007         /*
1008          Vectors where the spline is stored
1009         */
1010         std::vector<double> xSpline;
1011         
1012         std::vector<double>     ySpline;
1013         
1014         /*
1015           Kochanek splines
1016         */
1017         vtkKochanekSpline* xKSpline;
1018
1019         vtkKochanekSpline* yKSpline;
1020         
1021         
1022         /**
1023          offset in pixels where the user has clicked
1024          before changing the scale
1025         */
1026         int offsetPixelX;
1027         int offsetPixelY;
1028         /*
1029          type of the meaning of the function
1030          DEFAULT=1; the  function  has no meaning
1031          HISTOGRAM=2. The function represents an histogram
1032         */
1033
1034         int mType;
1035
1036         /*
1037          is use for lets the user move the function
1038         */
1039         int xTraslation;
1040
1041         DECLARE_CLASS (pGraphicalFunction)
1042 };
1043
1044 #endif
1045
1046