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