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 # ------------------------------------------------------------------------ */
26 //----------------------------------------------------------------------------
27 // Class definition include
28 //----------------------------------------------------------------------------
29 #include "pPlotterLayer.h"
31 // ----------------------------------------------------------------------------
32 // WX headers inclusion.
33 // For compilers that support precompilation, includes <wx/wx.h>.
34 // ----------------------------------------------------------------------------
43 //----------------------------------------------------------------------------
44 // Class implementation
45 //----------------------------------------------------------------------------
47 IMPLEMENT_ABSTRACT_CLASS(pPlotterLayer, mpLayer)
48 //----------------------------------------------------------------------------
50 //----------------------------------------------------------------------------
54 *@param flags Label alignment, pass one of #mpALIGN_NE, #mpALIGN_NW, #mpALIGN_SW, #mpALIGN_SE.
56 pPlotterLayer:: pPlotterLayer(wxString name , int flags )
60 points.DeleteContents(TRUE);
66 Draw the line from (x1,y1) to (x2,y2) only passing by the
67 positive points in the line
69 void pPlotterLayer::draw(wxDC & dc,mpWindow & w,double x1,double y1,double x2,double y2, int orgy)
73 float m=((float)(y2-y1))/(x2-x1);
77 double sizedc = dc.GetSize().GetHeight()-orgy;
84 dc.DrawLine(0,GetYTranslated(sizedc,y0), x2,GetYTranslated(sizedc,y2));
86 else if(y2<=0 && y1>=0)
89 dc.DrawLine(0,GetYTranslated(sizedc,y0),x0,GetYTranslated(sizedc,0) );
91 else if(y2>=0 && y1<=0)
94 dc.DrawLine(0,GetYTranslated(sizedc,y0),x2,GetYTranslated(sizedc,y2) );
102 dc.DrawLine(x1,GetYTranslated(sizedc,y1), x2,GetYTranslated(sizedc,y2));
103 else if(y1>=0 && y2<=0)
104 dc.DrawLine(x1,GetYTranslated(sizedc,y1),x0,GetYTranslated(sizedc,0) );
105 else if(y1<=0 && y2>=0)
106 dc.DrawLine(x0,GetYTranslated(sizedc,0),x2,GetYTranslated(sizedc,y2));
113 * Draw the function with th spline points
116 void pPlotterLayer::drawSplineCurve(wxDC & dc,mpWindow & w, int orgy)
118 std::vector<double> vx=getXSpline();
119 std::vector<double> vy=getYSpline();
122 int /*counter=0,*/ minX,maxX,minY,maxY; // JPRx
124 This is the offset of every point scale to the window
127 int offsetpx=getOffsetPixelsXv();
128 int offsetpy=getOffsetPixelsYv();
135 getMaxShowed(maxX,maxY);
136 getMinShowed(minX,minY);
143 Fill the function if it represented an histogram
145 ppoints=(wxPoint*)malloc(sizeof(int)*2*(vx.size()+2));
156 for(int i=0;(i+1)< size;i++)
160 double cxi=(vx.at(i)-minX-offsetX)*scaleX+offsetpx;
161 double cyi=(vy.at(i)-minY-offsetY)*scaleY+offsetpy;
163 double cxj=(vx.at(i+1)-minX-offsetX)*scaleX+offsetpx;
164 double cyj=(vy.at(i+1)-minY-offsetY)*scaleY+offsetpy;
168 draw(dc,w,cxi,cyi,cxj,cyj,orgy);
171 if(!initializePolygon(ppoints,cxi,cyi,cxj,cyj) && ((cxi<=0 && cxj>=0)||(cxi>=0 && cxj>=0)))
184 //point.x=vx.at(size-1)* scaleX + offsetpx;
185 point.x=ppoints[j-1].x;
187 //ppoints[vx.size()]=point;
190 Fill the function if it represented an histogram
192 //ppoints=(wxPoint*)malloc(sizeof(int)*2*(vx.size()+1));
194 //point.x=vx.at(0)*scaleX + offsetpx;
195 point.x=ppoints[0].x;
197 //ppoints[vx.size()+1]=point;
200 dc.SetBrush(wxBrush( wxColour(239,238,242) ,wxSOLID ));
201 dc.SetPen(wxPen( wxColour(0,0,0) ,1,wxSOLID ));
202 //dc.DrawPolygon(vx.size()+2,ppoints,0,0);
203 for(int i = 0; i <= j + 1; i++){
204 int sizedc = dc.GetSize().GetHeight()-orgy;
205 ppoints[i].y = GetYTranslated(sizedc, ppoints[i].y);
207 dc.DrawPolygon(j+2,ppoints,0,0);
214 it define the first point of the polygon for be drawing
215 returns true if the first and second point of the polygon are set
217 bool pPlotterLayer::initializePolygon(wxPoint* points,double x1, double y1,double x2, double y2)
222 float m=((float)(y2-y1))/(x2-x1);
226 if(points[0].x<=0&& points[1].x<=0 && points[0].y<=0&& points[1].y<=0)
229 //int offsetpx=getOffsetPixelsXv(); //JPRx
231 //analyzing the curve
237 //dc.DrawLine(0,y0, x2,y2);
245 else if(y2<=0 && y1>=0)
249 //dc.DrawLine(0,y0,x0,0 );
259 else if(y2>=0 && y1<=0)
263 //dc.DrawLine(0,y0,x2,y2 );
278 //dc.DrawLine(x1,y1, x2,y2);
285 else if(y1>=0 && y2<=0)
287 //dc.DrawLine(x1,y1,x0,0 );
294 else if(y1<=0 && y2>=0)
296 //dc.DrawLine(x0,0,x2,y2);
313 * Draw the lines between the points of the function
315 void pPlotterLayer::drawFunction(wxDC & dc,mpWindow & w, int orgy)
319 int scrwX,scrwY,offsetpx,offsetpy,maxX,minX,maxY,minY;
320 wxPoint* ppoints=NULL;
323 This is the offset of every point scale to the window
326 offsetpx=getOffsetPixelsXv();
327 offsetpy=getOffsetPixelsYv();
331 dc.GetSize(&scrwX, &scrwY);
333 //Lines between the points
335 int sizedc = dc.GetSize().GetHeight()-orgy;
342 getMaxShowed(maxX,maxY);
343 getMinShowed(minX,minY);
347 //int xTraslation=getXTraslation(); //JPRx
348 wxNode* node= points.GetFirst();
349 // int i=1;//points.GetCount()+1; //JPRx
352 Fill it if it is an histogram
355 // pFunctionPoint* pointk; //JPRx
359 Fill the function if it represented an histogram
361 ppoints=(wxPoint*)malloc(sizeof(int)*2*(points.GetCount()+2));
364 point.y=GetYTranslated(sizedc,-5000);
371 while (node!=NULL && node->GetNext()!=NULL)
373 pFunctionPoint* pointi=(pFunctionPoint*)node->GetData();
374 wxNode* nextNode=node->GetNext();
375 pFunctionPoint* pointj=(pFunctionPoint*)nextNode->GetData();
378 int pxi=(pointi->getRealX()-minX)-offsetX;
379 int pyi=(pointi->getRealY()-minY)-offsetY;
380 int pxj=(pointj->getRealX()-minX)-offsetX;
381 int pyj=(pointj->getRealY()-minY)-offsetY;
384 int cxi=pxi* scaleX + offsetpx; //+ xTraslation;
385 int cxj=pxj* scaleX + offsetpx; //+ xTraslation;
386 int cyi=pyi* scaleY+ offsetpy ;
387 int cyj=pyj* scaleY+ offsetpy ;
388 //dc.DrawLine(pxi* scaleX + offsetpx,pyi* scaleY+ offsetpy, pxj* scaleX + offsetpx,pyj* scaleY+ offsetpy );
390 draw(dc,w,pxi* scaleX + offsetpx,pyi* scaleY+ offsetpy, pxj* scaleX + offsetpx,pyj* scaleY+ offsetpy,orgy );
391 //dc.DrawLine(pxi* scaleX + offsetpx,pyi* scaleY+ offsetpy, pxj* scaleX + offsetpx,pyj* scaleY+ offsetpy );
394 if(!initializePolygon(ppoints,cxi,cyi,cxj,cyj) && ((cxi<=0 && cxj>=0)||(cxi>=0 && cxj>=0)))
397 point.y=GetYTranslated(sizedc,cyj);
404 node=node->GetNext();
409 //point.x=vx.at(size-1)* scaleX + offsetpx;
410 point.x=ppoints[j-1].x;
411 point.y=GetYTranslated(sizedc,0);
412 //ppoints[vx.size()]=point;
415 Fill the function if it represented an histogram
417 //ppoints=(wxPoint*)malloc(sizeof(int)*2*(vx.size()+1));
419 //point.x=vx.at(0)*scaleX + offsetpx;
420 point.x=ppoints[0].x;
421 point.y=GetYTranslated(sizedc,0);
422 //ppoints[vx.size()+1]=point;
425 dc.SetBrush(wxBrush( wxColour(239,238,242) ,wxSOLID ));
426 dc.SetPen(wxPen( wxColour(0,0,0) ,1,wxSOLID ));
427 //dc.DrawPolygon(vx.size()+2,ppoints,0,0);
428 dc.DrawPolygon(j+2,ppoints,0,0);
435 * Draw the points of the function
437 void pPlotterLayer::drawPoints(wxDC & dc,mpWindow & w, int orgy)
442 int minX,maxX,minY,maxY;
444 double sizedc = dc.GetSize().GetHeight()-orgy;
447 This is the offset of every point scale to the window
450 int offsetpx=getOffsetPixelsXv();
451 int offsetpy=getOffsetPixelsYv();
453 // int xTraslation=getXTraslation(); //EED
454 /*wxPen mypen(*wxBLACK, 5, wxSOLID);
457 getMaxShowed(maxX,maxY);
458 getMinShowed(minX,minY);
460 //we have to draw the points
462 while (GetNextXY(x, y))
465 //set the points of the polygons
467 dc.SetBrush(wxBrush( wxColour(255,0,0),wxSOLID ));
468 //dc.SetPen(wxPen(wxColour(0,0,0),1,wxSOLID) );
469 points[0].x=((x-minX-offsetX)*scaleX + offsetpx-MOVE);
470 points[0].y=GetYTranslated(sizedc,((y-minY-offsetY)*scaleY+ offsetpy-MOVE));
471 points[1].x=((x-minX-offsetX)*scaleX+ offsetpx+MOVE);
472 points[1].y=GetYTranslated(sizedc,((y-minY-offsetY)*scaleY+ offsetpy-MOVE));
473 points[2].x=((x-minX-offsetX)*scaleX+ offsetpx+MOVE);
474 points[2].y=GetYTranslated(sizedc,((y-minY-offsetY)*scaleY+ offsetpy+MOVE));
475 points[3].x=((x-minX-offsetX)*scaleX+ offsetpx-MOVE);
476 points[3].y=GetYTranslated(sizedc,((y-minY-offsetY)*scaleY+ offsetpy+MOVE));
477 if((x-minX-offsetX)*scaleX >=0 && (y-minY-offsetY/*w.getMinScrY()*/)*scaleY>=0)
478 dc.DrawPolygon(4,points,0,0);
483 * Draw the line between the last point of the function
484 * and the position of the mouse
486 void pPlotterLayer::drawLineToMousePoint(wxDC & dc,mpWindow & w, int orgy)
488 int x,y,sizeP,maxX,maxY,minX,minY;
494 getDirection(direction);
496 //Lines betwen the points
499 wxNode *node=points.GetLast();
500 wxNode *node1=points.GetFirst();
504 This is the offset of every point scale to the window
507 int offsetpx = getOffsetPixelsXv();
508 int offsetpy = getOffsetPixelsYv();
510 getMaxShowed(maxX,maxY);
511 getMinShowed(minX,minY);
514 // int xTraslation=getXTraslation(); //EED
518 pFunctionPoint* lastPoint=(pFunctionPoint*)node->GetData();
519 pFunctionPoint* firstPoint=(pFunctionPoint*)node1->GetData();
522 if(lastPoint->getRealX()<x && direction && sizeP >=2)
524 dc.DrawLine((lastPoint->getRealX()-minX-offsetX)*scaleX + offsetpx,(lastPoint->getRealY()-minY-offsetY)*scaleY+ offsetpy, (x-minX)*scaleX + offsetpx, (y-minY)*scaleY + offsetpy);
527 else if(firstPoint->getRealX()>x && !direction && sizeP >=2 )
529 dc.DrawLine((firstPoint->getRealX()-minX-offsetX)*scaleX+ offsetpx,(firstPoint->getRealY()-minY-offsetY)*scaleY+ offsetpy,(x-minX)*scaleX+ offsetpx, (y-minY)*scaleY+ offsetpy);
534 dc.DrawLine((lastPoint->getRealX()-minX-offsetX)*scaleX + offsetpx,(lastPoint->getRealY()-minY-offsetY)*scaleY+ offsetpy, (x-minX)*scaleX+ offsetpx, (y-minY)*scaleY+ offsetpy);
538 if( w.drawGuideLines() )
540 dc.SetPen(wxPen( wxColour(255,0,0),1,wxDOT ));
541 // Drawing the horizontal guide line
542 dc.DrawLine( 0, (y-minY)*scaleY + offsetpy, (x-minX)*scaleX + offsetpx, (y-minY)*scaleY + offsetpy);
543 // Drawing the vertical guide line
544 dc.DrawLine( (x-minX)*scaleX + offsetpx,0, (x-minX)*scaleX + offsetpx, (y-minY)*scaleY + offsetpy);
551 This implementation will plot the locus in the visible area and
552 put a label according to the aligment specified.
554 void pPlotterLayer::Plot(wxDC & dc, mpWindow & w)
556 bool show,drawing,actual;
557 int scrwX,scrwY,maxX,maxY,minX,minY,type;
567 * Managing the scale and zoom
570 dc.GetSize(&scrwX, &scrwY);
573 //getMax(maxX, maxY);
575 getMaxShowed(maxX,maxY);
576 getMinShowed(minX,minY);
578 getFactorZoom(factorZoom);
579 getOffsets(offsetX,offsetY);
586 if((maxX-minX)!=0 && (maxY-minY)!=0)
589 scaleX=(((double)scrwX-100)/(maxX-minX))*factorZoom;
590 scaleY=(((double)scrwY-50)/(maxY-minY))*factorZoom;
596 //w.setMinScrX(offsetX);
597 //w.setMinScrY(offsetY);
608 // int orgy=w.GetScrY()-40;
609 // dc.SetDeviceOrigin( orgx ,orgy);
610 // dc.SetAxisOrientation(true,true);
613 //dc.SetDeviceOrigin( orgx ,orgy);
614 dc.SetDeviceOrigin( orgx ,0);
615 int sizedc = dc.GetSize().GetHeight()-orgy;
616 //dc.SetAxisOrientation(true,false);
620 //if the user dont want to see the points of the function and if he stops drawing
621 //we have to draw the function
622 if(!show && !drawing && type==1)
623 drawFunction(dc,w,orgy);
624 else if(!show && !drawing && type==2)
625 drawSplineCurve(dc,w,orgy);
626 //we just draw the point that the user just clicked
627 else if(drawing && type==1)
629 drawFunction(dc,w,orgy);
630 drawLineToMousePoint(dc,w,orgy);
631 drawPoints(dc,w,orgy);
633 else if(drawing && type==1)
635 drawSplineCurve(dc,w,orgy);
636 drawLineToMousePoint(dc,w,orgy);
637 drawPoints(dc,w,orgy);
639 else if(show && type==1)
641 drawFunction(dc,w,orgy);
642 drawPoints(dc,w,orgy);
644 else if(show && type==2)
646 drawSplineCurve(dc,w,orgy);
647 drawPoints(dc,w,orgy);
650 // Drawing the guides according to real values entered according to the integrated interaction (IS NOT WORKING!!!)
653 dc.SetPen(wxPen( wxColour(255,0,0),1,wxDOT ));
654 int offsetpx = getOffsetPixelsXv();
655 // int offsetpy = getOffsetPixelsYv(); //EED
657 int realX_guide = w.getRealGuideX();
658 if( realX_guide!=-1 )
660 dc.DrawLine( (realX_guide/*-w.getMinScrX()*/-offsetX)*scaleX + offsetpx,
661 GetYTranslated(sizedc,0),
662 (realX_guide/*-w.getMinScrX()*/-offsetX)*scaleX + offsetpx,
663 GetYTranslated(sizedc,scrwY));
666 int realY_guide = w.getRealGuideY();
667 if( realY_guide!=-1 )
670 GetYTranslated(sizedc,(realY_guide/*-w.getMinScrY()*/-offsetX)*scaleX + offsetpx),
672 GetYTranslated(sizedc,(realY_guide/*-w.getMinScrY()*/-offsetX)*scaleX + offsetpx));