1 /*# ---------------------------------------------------------------------
3 # Copyright (c) CREATIS (Centre de Recherche en Acquisition et Traitement de l'Image
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
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.
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
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 # ------------------------------------------------------------------------ */
28 #ifndef __pGraphicalFunction_h__
29 #define __pGraphicalFunction_h__
31 // ----------------------------------------------------------------------------
32 // WX headers inclusion.
33 // For compilers that support precompilation, includes <wx/wx.h>.
34 // ----------------------------------------------------------------------------
36 #include <wx/wxprec.h>
45 //----------------------------------------------------------------------------
47 //----------------------------------------------------------------------------
50 #include "pPlotterLayer.h"
51 #include "pFunctionPoint.h"
52 #include "pLogicalFunction.h"
53 #include "pColorPoint.h"
54 #include "vtkKochanekSpline.h"
60 this scale, scales each function with its maximum x, and maximum y
63 #define DEFECT_SCALE 1
65 this scale with the maximun x and y of all the functions defined
69 this scales with the scale giving by the user of the widget
77 Lets to the user to plot any number of the
82 Dont let draw on the plotter, but lets to edit
83 the functions that are editables in the plotter
87 class pGraphicalFunction;
88 //----------------------------------------------------------------------------
90 //----------------------------------------------------------------------------
93 class pGraphicalFunction: public pPlotterLayer
98 pGraphicalFunction(wxString name= wxEmptyString, int flags= mpALIGN_RIGHT);
100 ~pGraphicalFunction( );
102 //---------------------------
104 //---------------------------
107 Get the value of the traslation
110 virtual int getXTraslation()
119 Get the type of the curve
123 virtual int getmType()
129 Get the type of the curve
133 virtual int vGetType()
139 Get _offsetX and _offsetY
142 virtual void getOffsets(int &offsetX,int &offSetY )
144 offsetX=(int)_offsetX;
145 offsetY=(int)_offsetY;
149 * Get the factor zoom
151 virtual void getFactorZoom(float & fz)
158 * Get the value of fromWindow
160 virtual void getFromWindowV(bool &fw)
167 * if the function that is drawing is the actual
169 virtual void getIfActual(bool &actual)
175 * get the max of the function in x and y
177 virtual void getMax(int & maxX, int &maxY)
183 * get the maxShowed of the function in x and y
185 virtual void getMaxShowed(int & maxX, int &maxY)
187 maxX=(int)getMaxXShowed();
188 maxY=(int)getMaxYShowed();
191 * get the minShowed of the function in x and y
193 virtual void getMinShowed(int & minX, int &minY)
195 minX=(int)getMinXShowed();
196 minY=(int)getMinYShowed();
200 * Get screens of the function
202 virtual void getScreens(int & scrX, int & scrY)
211 virtual void setScreens(int scrX,int scrY)
218 * Let us know the scale of the function
220 virtual void getScales(double & scaleX,double & scaleY)
228 * Let us Know if the user has finished the drawing
229 * that starts before.
232 virtual void getDrawing(bool &draw)
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
241 virtual void ifShowPoints(bool & show)
249 virtual void Rewind()
252 node = logicFunction->GetPointAt(0);
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
261 virtual bool GetNextXY(double & x, double & y)
265 pFunctionPoint* p=(pFunctionPoint*)node->GetData();
268 node=node->GetNext();
276 //EED 2017-09-16 Migration wxWidgets 2.8 to 3.0
277 #if wxMAJOR_VERSION <= 2
279 Get Point list of the funcion
282 virtual void GetPoints(wxList &points)
284 logicFunction->GetPoints(points);
285 //points = realPoints;
289 Get Point list of the funcion
290 @param return pointsPtr
292 virtual wxList* GetPointsPtr()
294 return logicFunction->GetPointsPtr();
301 Get the point where the user
304 virtual void getMousePoint(int &x,int &y)
311 * Get the number of points of the function
313 virtual void getSize(int &size)
315 size=getSizePoints();
319 * this method gets the direction of the drawing
321 virtual void getDirection(bool &dir)
323 logicFunction -> getDirection (dir);
326 //---------------------------
328 //---------------------------
330 * 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
331 * x1-validPointRange<x<x1+validPointRange y1-validPointRange<y<y1+validPointRange
333 int validPointOnFunction(wxPoint realPoint);
335 //returns the index in the list of the point
336 int getIndexOf(wxPoint realpoint);
339 * This metohd returns the node of the point that is the movingPointIndex position in the list of points.
340 * @param: int movingPointIndex, Is the index value of the searched node.
341 * @return: Return a pointer to the node corresponding to the index value by parameter.
343 wxNode* GetPointAt( int movingPointIndex);
346 * Includes a point between two existing points of the this function. The new point (x,y) was not defined when the function was created.
347 *@ return Returns true is the point was succcesfully added to the funcion.
349 bool AddNewPoint(int x,int y);
352 * this method add a new logical point to the function, this point is one of those used to draw the function
354 bool AddPoint(int aX, int aY,bool order=true);
357 * deletes the point given by the user from the collection of logical points of the function
359 bool DeletePoint(int aX, int aY);
362 * 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.
364 bool changePoint(wxPoint newCoords, int movingIndexPoint);
367 * Evaluates if the given point belongs to the function.
369 //bool hasPoint(wxPoint aAPoint);
372 * Returns the real x values of the control points of the function. It dont includes the points calculated by interpolation.
374 double * getX_RealValues();
377 * Returns the real y values of the control points of the function. It dont includes the points calculated by interpolation.
379 double* getY_RealValues();
381 * This method orders the list of points taking into account that the last appended node in the list (realPoint) is the only one disordered.
382 * @return Returns true if the last point included has a valid value for x and was ordered, according to the definition of function.
387 * This method get a pointer to the node in the real points list that is inmediately previous to the searched by parameter.
388 * @pre The seached point (realX, realY) is not the first point of the list.
392 //wxNode * findPreviousNodeTo( int realX, int realY );
395 * Deletes a point of the function given its index
397 bool deletePointAt(int index);
399 * Returns the number of points that the function
404 * Set the scales of the function in x and y
408 //----------------------------------
409 // Asking if it has a point (x,y)
410 //----------------------------------
413 * returns true if the point is along the function
416 bool isInFunction(int x, int y);
418 * give us the point that is in the function and is exactly before
419 * the point we are giving
421 wxNode* getBefore(pFunctionPoint* point);
423 * Returns true if the point is in the line
425 bool isInLine(pFunctionPoint* before,pFunctionPoint* next, pFunctionPoint* point);
427 * give us the value of y in the line define by the arguments
429 double interpolateY(double m, int x1,int y1,int x);
431 * Set Up startPoint, endPoint, maxY,maxX points
434 //----------------------------
436 //----------------------------
438 * clear the spline vectors
440 void clearSplineVectors();
444 Initiliaze xSpline and ySpline vectors
446 void initializeSplines();
449 Add the (x,y) points of the function to the
452 void addSplinesPoints();
455 This Method adds the point calculated by
456 the splines to the vectors
458 void initializeSplineVectors();
461 get the spline point for t, in xKSpline and yKSpline
463 void GetSplinePoint(double t, double &x, double &y);
465 returns the xSpline to plotter
467 virtual std::vector<double> getXSpline()
472 returns the ySpline to plotter
474 virtual std::vector<double> getYSpline()
481 Gets the x-offset of the zoom
484 virtual int getOffsetPixelsXv()
490 Gets the offset of the zoom
493 virtual int getOffsetPixelsYv()
498 //-----------------------
500 //-----------------------
503 Save the points of the function
505 void save(wxString fileName);
507 Load the points of a function
509 void load(wxString fileName);
511 //------------------------------
512 // Getters and Setters
513 //------------------------------
515 //set if the function has to draw the points
516 void SetShowPoints(bool showPoints);
518 //get the paramater showPointsF
519 bool getShowPoints();
521 void setScreenX(int scrX);
525 void setScreenY(int scrY);
529 void setStartX(double aStartX);
533 void setStartY(double aStartY);
537 void setEndX(double aEndX);
541 void setEndY(double aEndY);
545 void setScaleX(double aScaleX);
549 void setScaleY(double aScaleY);
553 void setMinX(double aMinX);
557 void setMinY(double aMinY);
561 void setMaxX(double aMaxX);
565 void setMaxY(double aMaxY);
569 void setOffsetX(double aOffsetX);
573 void setOffsetY(double aOffsetY);
577 void setType(int aType);
581 int getValidPointRange();
583 void setValidPointRange(int theRange);
585 void SetDrawing(bool d)
589 //get if the function is being drawed
595 //set the mouse point
596 void SetMousePoint(wxPoint p)
601 wxPoint getMousePoint()
608 void setActual(bool act);
618 void setScaleWay(int typeS);
623 * set fromWindow: it is set to true if the
624 * function was created interactively
626 void setFromWindow(bool w)
632 * Get the value of fromWindow
641 void setFactorZoom(float factor)
648 void setEditable(bool edit)
660 //----------------------------
662 //----------------------------
673 * @param z: the new value
675 void setZoomIn(bool z)
680 * Set the initial drawing point
681 * @param pFunctionPoint* initialPoint
683 void setInitialDrawPoint(pFunctionPoint* initialPoint)
685 initialDrawingPoint=initialPoint;
688 * Get the initial drawing point
689 * @return initialDrawingPoint
691 pFunctionPoint* getInitialDrawPoint()
693 return initialDrawingPoint;
696 * Set the final drawing point
697 * @param pFunctionPoint* finalPoint
699 void setFinalDrawPoint(pFunctionPoint* finalPoint)
701 finalDrawingPoint=finalPoint;
704 * Get the final drawing point
705 * @return finalDrawingPoint
707 pFunctionPoint* getFinallDrawPoint()
709 return finalDrawingPoint;
712 This method set the initial point and the final point of drawing
713 according with the width of the square around the point clicked
716 @param width: width of the square
719 void zooming(int clickedX,int clickedY,int width);
722 * This method sets the offset
724 void setOffsets(int offx,int offy);
727 * This method sets the minShowedX
728 * and the minShowedY, accordig to the offset in
729 * x-axis and y-axis respectively
730 * pre: _offsetX>=0,_offsetY>=0
765 void setMinShowedX(int msx)
772 void setMinShowedY(int msy)
779 void setMaxShowedX(int msx)
786 void setMaxShowedY(int msy)
791 //------------------------
793 //------------------------
796 Gets the x-offset of the zoom
799 int getOffsetPixelsX()
805 Gets the offset of the zoom
808 int getOffsetPixelsY()
813 Set the x-offset of the zoom
815 void setOffsetPixelX(int offX)
820 Set the y-offset of the zoom
822 void setOffsetPixelY(int offY)
830 * Sets the color points of the function by teh given parameter
831 * @param colorVector Is the color points vector to set
833 void setColorPoints(std::vector<pColorPoint *> &colorVector);
836 * Gets the color points of the function in the given parameter
837 * @param colorVector Is the color points list to get the points
839 void getColorPoints(std::vector<pColorPoint *> &colorVector);
843 void setmType(int mt)
847 //-----------------------
849 //-----------------------
851 Set the value of the traslation
853 @param xT value in pixels of the traslation in x-axis
855 void setXTraslation(int xT)
865 * Represents the logical function asociated to this graphical function.
867 pLogicalFunction* logicFunction;
869 * If the function has to showpoints
874 * Is the initial discrete point on x axis of the drawed function.
878 * Is the initial discrete point on y axis of the drawed function.
882 * Is the last discrete point on x axis of the drawed function.
886 * Is the last discrete point on y axis of the drawed function.
890 * Is the x-scale percentage according to the context device.
894 * Is the y-scale percentage according to the context device.
898 * Is the minimun x-real value reacheable by the function.
902 * Is the minimun y-real value reacheable by the function.
906 * Is the maximun x-real value reacheable by the function.
910 * Is the maximun y-real value reacheable by the function.
914 * Is the logical x-offset of the drawed function.
918 * Is the logical y-offset of the drawed function.
922 * Is the way of how points are going to be connected. It could be smooth, line.
926 * The list of the function points
930 * The list of the color points of the function associated to the color bar
932 std::vector<pColorPoint *> f_colorPoints;
935 * node of the realPoints where are we
939 * Number that determines the radius range for the valid area the point (sensible radius). Default value 5.
944 * Indicates if the user is drawing the function
949 * this is for the graphical function
955 * The size of the screen in X
960 * The size of the screen in Y
978 if the function comes from window
986 * The function is editable
990 * if the user did a zoom in/out
994 * initial drawing point
996 pFunctionPoint* initialDrawingPoint;
998 * final drawing point
1000 pFunctionPoint* finalDrawingPoint;
1002 Minimum point showed to the user
1007 Maximum point showed to the user
1012 Minimum point showed to the user
1017 Maximum point showed to the user
1024 Vectors where the spline is stored
1026 std::vector<double> xSpline;
1028 std::vector<double> ySpline;
1033 vtkKochanekSpline* xKSpline;
1035 vtkKochanekSpline* yKSpline;
1039 offset in pixels where the user has clicked
1040 before changing the scale
1045 type of the meaning of the function
1046 DEFAULT=1; the function has no meaning
1047 HISTOGRAM=2. The function represents an histogram
1053 is use for lets the user move the function
1057 DECLARE_CLASS (pGraphicalFunction)