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();
274 Get Point list of the funcion
277 virtual void GetPoints(wxList &points)
279 logicFunction->GetPoints(points);
280 //points = realPoints;
284 Get the point where the user
288 virtual void getMousePoint(int &x,int &y)
295 * Get the number of points of the function
297 virtual void getSize(int &size)
299 size=getSizePoints();
303 * this method gets the direction of the drawing
305 virtual void getDirection(bool &dir)
307 logicFunction -> getDirection (dir);
310 //---------------------------
312 //---------------------------
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
317 int validPointOnFunction(wxPoint realPoint);
319 //returns the index in the list of the point
320 int getIndexOf(wxPoint realpoint);
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.
327 wxNode* GetPointAt( int movingPointIndex);
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.
333 bool AddNewPoint(int x,int y);
336 * this method add a new logical point to the function, this point is one of those used to draw the function
338 bool AddPoint(int aX, int aY,bool order=true);
341 * deletes the point given by the user from the collection of logical points of the function
343 bool DeletePoint(int aX, int aY);
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.
348 bool changePoint(wxPoint newCoords, int movingIndexPoint);
351 * Evaluates if the given point belongs to the function.
353 //bool hasPoint(wxPoint aAPoint);
356 * Returns the real x values of the control points of the function. It dont includes the points calculated by interpolation.
358 double * getX_RealValues();
361 * Returns the real y values of the control points of the function. It dont includes the points calculated by interpolation.
363 double* getY_RealValues();
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.
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.
376 //wxNode * findPreviousNodeTo( int realX, int realY );
379 * Deletes a point of the function given its index
381 bool deletePointAt(int index);
383 * Returns the number of points that the function
388 * Set the scales of the function in x and y
392 //----------------------------------
393 // Asking if it has a point (x,y)
394 //----------------------------------
397 * returns true if the point is along the function
400 bool isInFunction(int x, int y);
402 * give us the point that is in the function and is exactly before
403 * the point we are giving
405 wxNode* getBefore(pFunctionPoint* point);
407 * Returns true if the point is in the line
409 bool isInLine(pFunctionPoint* before,pFunctionPoint* next, pFunctionPoint* point);
411 * give us the value of y in the line define by the arguments
413 double interpolateY(double m, int x1,int y1,int x);
415 * Set Up startPoint, endPoint, maxY,maxX points
418 //----------------------------
420 //----------------------------
422 * clear the spline vectors
424 void clearSplineVectors();
428 Initiliaze xSpline and ySpline vectors
430 void initializeSplines();
433 Add the (x,y) points of the function to the
436 void addSplinesPoints();
439 This Method adds the point calculated by
440 the splines to the vectors
442 void initializeSplineVectors();
445 get the spline point for t, in xKSpline and yKSpline
447 void GetSplinePoint(double t, double &x, double &y);
449 returns the xSpline to plotter
451 virtual std::vector<double> getXSpline()
456 returns the ySpline to plotter
458 virtual std::vector<double> getYSpline()
465 Gets the x-offset of the zoom
468 virtual int getOffsetPixelsXv()
474 Gets the offset of the zoom
477 virtual int getOffsetPixelsYv()
482 //-----------------------
484 //-----------------------
487 Save the points of the function
489 void save(wxString fileName);
491 Load the points of a function
493 void load(wxString fileName);
495 //------------------------------
496 // Getters and Setters
497 //------------------------------
499 //set if the function has to draw the points
500 void SetShowPoints(bool showPoints);
502 //get the paramater showPointsF
503 bool getShowPoints();
505 void setScreenX(int scrX);
509 void setScreenY(int scrY);
513 void setStartX(double aStartX);
517 void setStartY(double aStartY);
521 void setEndX(double aEndX);
525 void setEndY(double aEndY);
529 void setScaleX(double aScaleX);
533 void setScaleY(double aScaleY);
537 void setMinX(double aMinX);
541 void setMinY(double aMinY);
545 void setMaxX(double aMaxX);
549 void setMaxY(double aMaxY);
553 void setOffsetX(double aOffsetX);
557 void setOffsetY(double aOffsetY);
561 void setType(int aType);
565 int getValidPointRange();
567 void setValidPointRange(int theRange);
569 void SetDrawing(bool d)
573 //get if the function is being drawed
579 //set the mouse point
580 void SetMousePoint(wxPoint p)
585 wxPoint getMousePoint()
592 void setActual(bool act);
602 void setScaleWay(int typeS);
607 * set fromWindow: it is set to true if the
608 * function was created interactively
610 void setFromWindow(bool w)
616 * Get the value of fromWindow
625 void setFactorZoom(float factor)
632 void setEditable(bool edit)
644 //----------------------------
646 //----------------------------
657 * @param z: the new value
659 void setZoomIn(bool z)
664 * Set the initial drawing point
665 * @param pFunctionPoint* initialPoint
667 void setInitialDrawPoint(pFunctionPoint* initialPoint)
669 initialDrawingPoint=initialPoint;
672 * Get the initial drawing point
673 * @return initialDrawingPoint
675 pFunctionPoint* getInitialDrawPoint()
677 return initialDrawingPoint;
680 * Set the final drawing point
681 * @param pFunctionPoint* finalPoint
683 void setFinalDrawPoint(pFunctionPoint* finalPoint)
685 finalDrawingPoint=finalPoint;
688 * Get the final drawing point
689 * @return finalDrawingPoint
691 pFunctionPoint* getFinallDrawPoint()
693 return finalDrawingPoint;
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
700 @param width: width of the square
703 void zooming(int clickedX,int clickedY,int width);
706 * This method sets the offset
708 void setOffsets(int offx,int offy);
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
749 void setMinShowedX(int msx)
756 void setMinShowedY(int msy)
763 void setMaxShowedX(int msx)
770 void setMaxShowedY(int msy)
775 //------------------------
777 //------------------------
780 Gets the x-offset of the zoom
783 int getOffsetPixelsX()
789 Gets the offset of the zoom
792 int getOffsetPixelsY()
797 Set the x-offset of the zoom
799 void setOffsetPixelX(int offX)
804 Set the y-offset of the zoom
806 void setOffsetPixelY(int offY)
814 * Sets the color points of the function by teh given parameter
815 * @param colorVector Is the color points vector to set
817 void setColorPoints(std::vector<pColorPoint *> &colorVector);
820 * Gets the color points of the function in the given parameter
821 * @param colorVector Is the color points list to get the points
823 void getColorPoints(std::vector<pColorPoint *> &colorVector);
827 void setmType(int mt)
831 //-----------------------
833 //-----------------------
835 Set the value of the traslation
837 @param xT value in pixels of the traslation in x-axis
839 void setXTraslation(int xT)
849 * Represents the logical function asociated to this graphical function.
851 pLogicalFunction* logicFunction;
853 * If the function has to showpoints
858 * Is the initial discrete point on x axis of the drawed function.
862 * Is the initial discrete point on y axis of the drawed function.
866 * Is the last discrete point on x axis of the drawed function.
870 * Is the last discrete point on y axis of the drawed function.
874 * Is the x-scale percentage according to the context device.
878 * Is the y-scale percentage according to the context device.
882 * Is the minimun x-real value reacheable by the function.
886 * Is the minimun y-real value reacheable by the function.
890 * Is the maximun x-real value reacheable by the function.
894 * Is the maximun y-real value reacheable by the function.
898 * Is the logical x-offset of the drawed function.
902 * Is the logical y-offset of the drawed function.
906 * Is the way of how points are going to be connected. It could be smooth, line.
910 * The list of the function points
914 * The list of the color points of the function associated to the color bar
916 std::vector<pColorPoint *> f_colorPoints;
919 * node of the realPoints where are we
923 * Number that determines the radius range for the valid area the point (sensible radius). Default value 5.
928 * Indicates if the user is drawing the function
933 * this is for the graphical function
939 * The size of the screen in X
944 * The size of the screen in Y
962 if the function comes from window
970 * The function is editable
974 * if the user did a zoom in/out
978 * initial drawing point
980 pFunctionPoint* initialDrawingPoint;
982 * final drawing point
984 pFunctionPoint* finalDrawingPoint;
986 Minimum point showed to the user
991 Maximum point showed to the user
996 Minimum point showed to the user
1001 Maximum point showed to the user
1008 Vectors where the spline is stored
1010 std::vector<double> xSpline;
1012 std::vector<double> ySpline;
1017 vtkKochanekSpline* xKSpline;
1019 vtkKochanekSpline* yKSpline;
1023 offset in pixels where the user has clicked
1024 before changing the scale
1029 type of the meaning of the function
1030 DEFAULT=1; the function has no meaning
1031 HISTOGRAM=2. The function represents an histogram
1037 is use for lets the user move the function
1041 DECLARE_CLASS (pGraphicalFunction)