]> Creatis software - creaMaracasVisu.git/blobdiff - lib/maracasVisuLib/src/interface/wxWindows/widgets/pPlotter/pGraphicalFunction.cxx
#3472 TDx
[creaMaracasVisu.git] / lib / maracasVisuLib / src / interface / wxWindows / widgets / pPlotter / pGraphicalFunction.cxx
index b04e17c81bacb5a648d8dacb8c735f85b3a7691d..63b3cc9ed2a27dfb796d24b2c8a75c8e0166684a 100644 (file)
@@ -1,3 +1,28 @@
+/*# ---------------------------------------------------------------------
+#
+# Copyright (c) CREATIS (Centre de Recherche en Acquisition et Traitement de l'Image
+#                        pour la Sant�)
+# Authors : Eduardo Davila, Frederic Cervenansky, Claire Mouton
+# Previous Authors : Laurent Guigues, Jean-Pierre Roux
+# CreaTools website : www.creatis.insa-lyon.fr/site/fr/creatools_accueil
+#
+#  This software is governed by the CeCILL-B license under French law and
+#  abiding by the rules of distribution of free software. You can  use,
+#  modify and/ or redistribute the software under the terms of the CeCILL-B
+#  license as circulated by CEA, CNRS and INRIA at the following URL
+#  http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
+#  or in the file LICENSE.txt.
+#
+#  As a counterpart to the access to the source code and  rights to copy,
+#  modify and redistribute granted by the license, users are provided only
+#  with a limited warranty  and the software's author,  the holder of the
+#  economic rights,  and the successive licensors  have only  limited
+#  liability.
+#
+#  The fact that you are presently reading this means that you have had
+#  knowledge of the CeCILL-B license and that you accept its terms.
+# ------------------------------------------------------------------------ */
+
 
 //----------------------------------------------------------------------------
 // Class definition include
@@ -27,27 +52,28 @@ IMPLEMENT_CLASS(pGraphicalFunction, pPlotterLayer)
 pGraphicalFunction:: pGraphicalFunction(wxString name, int flags)
 {
        SetName(name);
-       showPointsF = false;
-       validPointRange = 5;
-       logicFunction = new pLogicalFunction ();
-       fromWindow=false;
-       factorZoom=1;
-       drawing=false;
-       editable=true;
-       ifActual=false;
-       zoomIn=false;
+       showPointsF             = false;
+       validPointRange         = 5;
+       logicFunction           = new pLogicalFunction ();
+       fromWindow                      = false;
+       factorZoom                      = 1;
+       drawing                         = false;
+       editable                        = true;
+       ifActual                        = false;
+       zoomIn                          = false;
        setOffsetX(0);
        setOffsetY(0);
-       initialDrawingPoint=NULL;
-       finalDrawingPoint=NULL;
+       initialDrawingPoint     = NULL;
+       finalDrawingPoint       = NULL;
        //type=1 means that is going to be a piecewise function
-       _type=1;
-       xKSpline=NULL;
-       yKSpline=NULL;
-       offsetPixelX=0;
-       offsetPixelY=0;
-       xTraslation=0;
-       mType=DEFAULT;
+       _type                           = 1;
+       xKSpline                        = NULL;
+       yKSpline                        = NULL;
+       offsetPixelX            = 0;
+       offsetPixelY            = 0;
+       xTraslation                     = 0;
+       mType                           = DEFAULT;
+       
 }
 
 /**
@@ -82,7 +108,6 @@ void pGraphicalFunction::setUp()
        setEndX(logicFunction->getEndX());
        setStartY(logicFunction->getStartY());
        setEndY(logicFunction->getEndY());
-       
 }
 
 /*
@@ -120,8 +145,6 @@ void pGraphicalFunction::setScales()
        //int dy= logicFunction->getMaxY()-logicFunction->getMinY();
        int dx= maxShowedX-minShowedX;
        int dy= maxShowedY-minShowedY;
-       
-       
        if(dx!=0 && dy!=0)
        {
                double scaleX=(((float)(screenX-100))/dx)*factorZoom;
@@ -130,8 +153,7 @@ void pGraphicalFunction::setScales()
                setScaleY(scaleY);
                logicFunction->setScaleX(scaleX);
                logicFunction->setScaleY(scaleY);
-
-       }
+       }// if dx dy
 }
 /*
 * Includes a point between two existing points of this function. The new point (x,y) was not defined when the function was created.
@@ -140,10 +162,10 @@ void pGraphicalFunction::setScales()
 bool pGraphicalFunction:: AddNewPoint(int x,int y)
 {
        bool added= logicFunction -> AddNewPoint ( x, y );
-       if(!fromWindow)
-        setUp();
-       else
+       if(!fromWindow) 
        {
+        setUp();
+       } else {
                logicFunction->setEndPoints();
                logicFunction->setStartPoints();
        }
@@ -159,15 +181,17 @@ bool pGraphicalFunction:: AddNewPoint(int x,int y)
 */
 bool pGraphicalFunction::AddPoint(int aX, int aY,bool order) 
 {      
-       
-       bool added=logicFunction -> AddPoint( aX, aY,order );
-       if(!fromWindow)
-        setUp();
-       else
-       {
-               logicFunction->setEndPoints();
-               logicFunction->setStartPoints();
-       }
+       bool added=false;
+       if (logicFunction!=NULL){
+               added=logicFunction -> AddPoint( aX, aY,order );
+               if(!fromWindow) 
+               {
+                       setUp();
+               } else {
+                       logicFunction->setEndPoints();
+                       logicFunction->setStartPoints();
+               } // if fromWindow
+       } // if logicFunction
        return added;
 }
 
@@ -180,9 +204,9 @@ bool pGraphicalFunction::DeletePoint(int aX, int aY)
 {
        bool added= logicFunction -> DeletePoint( aX, aY );     
        if(!fromWindow)
-        setUp();
-       else
        {
+        setUp();
+       } else {
                logicFunction->setEndPoints();
                logicFunction->setStartPoints();
        }
@@ -196,9 +220,9 @@ bool pGraphicalFunction::deletePointAt(int index)
 {
        bool added=logicFunction -> deletePointAt( index );
        if(!fromWindow)
-        setUp();
-       else
        {
+               setUp();
+       } else {
                logicFunction->setEndPoints();
                logicFunction->setStartPoints();
        }
@@ -212,10 +236,10 @@ bool pGraphicalFunction::deletePointAt(int index)
 bool pGraphicalFunction::changePoint(wxPoint newCoords, int movingIndexPoint) 
 {
        bool added= (logicFunction -> changePoint( newCoords, movingIndexPoint ));
-       if(!fromWindow)
-        setUp();
-       else
+       if(!fromWindow) 
        {
+               setUp();
+       } else {
                logicFunction->setEndPoints();
                logicFunction->setStartPoints();
        }
@@ -263,15 +287,14 @@ bool pGraphicalFunction:: isInFunction(int x, int y)
        pFunctionPoint* point= new pFunctionPoint(x,y);
        bool inLine;
        before=getBefore(point);
-
        if(before && before->GetNext())
        {
                next = before->GetNext();
                //next = (before->GetNext())->GetNext();
                inLine= isInLine((pFunctionPoint*)before->GetData(),(pFunctionPoint*)next->GetData(),point);
-       }
-       else 
+       } else { 
                inLine=false;
+       }
        return inLine;
 }
 /*
@@ -283,6 +306,7 @@ wxNode* pGraphicalFunction:: getBefore(pFunctionPoint* point)
        int minDiference=10000000;
        wxNode* node=logicFunction->GetPointAt(0);
        wxNode* before=NULL;
+
        while(node)
        {
                pFunctionPoint* before1=(pFunctionPoint*)node->GetData();
@@ -315,7 +339,6 @@ bool pGraphicalFunction::isInLine(pFunctionPoint* before,pFunctionPoint* next, p
        x=(float)point->getRealX();
        y=(float)point->getRealY();
 
-       
        float d1= (float)sqrt(pow(float(x1-x),2)+ pow(float(y1-y),2));
        float d2= (float)sqrt(pow(float(x2-x),2)+ pow(float(y2-y),2));
        float d=(float)sqrt(pow(float(x2-x1),2)+ pow(float(y2-y1),2));
@@ -393,7 +416,7 @@ double pGraphicalFunction::interpolateY(double m, int x1,int y1,int x)
                //realPoints.DeleteC  
 
                np = logicFunction->getSizePoints();
-               nps = 100;
+               nps = 200;
                delta=( double ) ( np ) / ( double ) ( nps );
                for( i = 0; i < nps; i++ )
                {
@@ -438,17 +461,17 @@ void pGraphicalFunction::zooming(int clickedX,int clickedY,int width)
 {
        int xS,yS,x1,x2,y1,y2;
        setScales();
-       xS=clickedX/_scaleX+_offsetX;
-       yS=clickedY/_scaleY+_offsetY;
+       xS = clickedX/_scaleX+_offsetX;
+       yS = clickedY/_scaleY+_offsetY;
        //square
-       x1=(clickedX-width)/_scaleX+_offsetX;
-       x2=(clickedX+width)/_scaleX+_offsetX;
-       y1=(clickedY-width)/_scaleY+_offsetY;
-       y2=(clickedY+width)/_scaleY+_offsetY;
-
-       int numberPoints=getSizePoints();
-       pFunctionPoint* point;
-       wxNode* p;
+       x1 = (clickedX-width)/_scaleX+_offsetX;
+       x2 = (clickedX+width)/_scaleX+_offsetX;
+       y1 = (clickedY-width)/_scaleY+_offsetY;
+       y2 = (clickedY+width)/_scaleY+_offsetY;
+
+       int numberPoints = getSizePoints();
+       pFunctionPoint* point;
+       wxNode*                 p;
        bool inSquare=false,first=false;
        
        //if the user made a zoom
@@ -474,22 +497,20 @@ void pGraphicalFunction::zooming(int clickedX,int clickedY,int width)
                                finalDrawingPoint=point;
                        }
                }
-       }       
-       else
-       {
+       } else {
                //We extend the range of vision in x and y,20 and 10 respectively
                if((_offsetX-20)>=0)
                {
                        _offsetX=_offsetX-20;
-               }
-               else
+               } else {
                        _offsetX=0;
+               }
                if((_offsetY-10)>=0)
                {
                        _offsetY=_offsetY-10;
-               }
-               else
+               } else {
                        _offsetY=0;
+               }
        }
 }
 
@@ -822,7 +843,7 @@ void pGraphicalFunction :: setColorPoints(std::vector<pColorPoint *> &colorVecto
 {
        f_colorPoints.clear();
        int i = 0;      
-       while(i<colorVector.size())
+       while(i<(int)(colorVector.size()))
        {
                f_colorPoints.push_back(colorVector[i]);                
                i++;
@@ -836,7 +857,7 @@ void pGraphicalFunction :: setColorPoints(std::vector<pColorPoint *> &colorVecto
 void pGraphicalFunction :: getColorPoints(std::vector<pColorPoint *> &colorVector)
 {
        int i = 0;      
-       while(i<f_colorPoints.size())
+       while(i<(int)(f_colorPoints.size()))
        {
                pColorPoint * originaslPoint = f_colorPoints[i];
                pColorPoint * copyPoint = new pColorPoint(originaslPoint->getRealX(), originaslPoint->getColor(), originaslPoint->isTemporalColor());