X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=lib%2FmaracasVisuLib%2Fsrc%2Finterface%2FwxWindows%2Fwidgets%2FpPlotter%2FpGraphicalFunction.cxx;h=63b3cc9ed2a27dfb796d24b2c8a75c8e0166684a;hb=659bcd2c2a608cfb8c5854ffe84e9248871df9a1;hp=0eed1ed66fa2c6317cfc4e3f626cac72e757a2fe;hpb=1bf58cfa1758464b422d1d0cca808e528043e691;p=creaMaracasVisu.git diff --git a/lib/maracasVisuLib/src/interface/wxWindows/widgets/pPlotter/pGraphicalFunction.cxx b/lib/maracasVisuLib/src/interface/wxWindows/widgets/pPlotter/pGraphicalFunction.cxx index 0eed1ed..63b3cc9 100644 --- a/lib/maracasVisuLib/src/interface/wxWindows/widgets/pPlotter/pGraphicalFunction.cxx +++ b/lib/maracasVisuLib/src/interface/wxWindows/widgets/pPlotter/pGraphicalFunction.cxx @@ -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,14 +181,13 @@ bool pGraphicalFunction:: AddNewPoint(int x,int y) */ bool pGraphicalFunction::AddPoint(int aX, int aY,bool order) { - printf("EED %p pGraphicalFunction::AddPoint %p (%d %d) \n", this, logicFunction, aX, aY); bool added=false; if (logicFunction!=NULL){ added=logicFunction -> AddPoint( aX, aY,order ); - if(!fromWindow) - setUp(); - else + if(!fromWindow) { + setUp(); + } else { logicFunction->setEndPoints(); logicFunction->setStartPoints(); } // if fromWindow @@ -183,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(); } @@ -199,9 +220,9 @@ bool pGraphicalFunction::deletePointAt(int index) { bool added=logicFunction -> deletePointAt( index ); if(!fromWindow) - setUp(); - else { + setUp(); + } else { logicFunction->setEndPoints(); logicFunction->setStartPoints(); } @@ -215,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(); } @@ -266,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; } /* @@ -286,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(); @@ -318,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)); @@ -396,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++ ) { @@ -441,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 @@ -477,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; + } } }