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 //---------------------------------------------------------------------------------------------
31 // --------------------------------------------------------------------------------------------
32 // WX headers inclusion.
33 // For compilers that support precompilation, includes <wx/wx.h>.
34 // --------------------------------------------------------------------------------------------
40 //---------------------------------------------------------------------------------------------
41 // Class implementation
42 //---------------------------------------------------------------------------------------------
44 IMPLEMENT_CLASS(pPlotter, wxPanel)
46 //------------------------------------------------------------------------------------------------------------
47 // Generated events declaration and definition
48 //------------------------------------------------------------------------------------------------------------
49 BEGIN_DECLARE_EVENT_TYPES()
50 DECLARE_EVENT_TYPE( wxEVT_NW_TEXT_MESAGGE, -1 )
51 END_DECLARE_EVENT_TYPES()
53 DEFINE_EVENT_TYPE( wxEVT_NW_TEXT_MESAGGE )
55 // ----------------------------------------------------------------------------------------------------
56 // Handdled events from pColorBar
57 // ----------------------------------------------------------------------------------------------------
58 DECLARE_EVENT_TYPE(wxEVT_ADDED_POINT, -1)
59 DECLARE_EVENT_TYPE(wxEVT_REMOVED_POINT, -1)
60 DECLARE_EVENT_TYPE(wxEVT_MOVED_POINT, -1)
61 DECLARE_EVENT_TYPE(wxEVT_CHANGED_POINT, -1)
62 DECLARE_EVENT_TYPE(wxEVT_ON_COLOR_BAR, -1)
64 // ----------------------------------------------------------------------------------------------------
65 // Handdled events from plotter
66 // ----------------------------------------------------------------------------------------------------
67 DECLARE_EVENT_TYPE(wxEVT_PPLOTTER_CHANGED_FUNCTION, -1)
68 DECLARE_EVENT_TYPE(wxEVT_PPLOTTER_POINT_MOVE, -1)
69 DECLARE_EVENT_TYPE(wxEVT_PPLOTTER_POINT_ADD, -1)
70 DECLARE_EVENT_TYPE(wxEVT_PPLOTTER_POINT_DELETE, -1)
71 DECLARE_EVENT_TYPE(wxEVT_PPLOTTER_GUIDELINES, -1)
73 // ----------------------------------------------------------------------------------------------------
74 // Handdled events from max-min barrange
75 // ----------------------------------------------------------------------------------------------------
76 DECLARE_EVENT_TYPE(wxEVT_TSBAR, -1)
77 DECLARE_EVENT_TYPE(wxEVT_TSBAR_ACTUAL, -1)
78 DECLARE_EVENT_TYPE(wxEVT_TSBAR_START, -1)
79 DECLARE_EVENT_TYPE(wxEVT_TSBAR_END, -1)
80 DECLARE_EVENT_TYPE(wxEVT_TSBAR_MOVED, -1)
81 DECLARE_EVENT_TYPE(wxEVT_SELECTION_END, -1)
84 // ----------------------------------------------------------------------------------------------------
85 // EVENT TABLE (->Connect: analogous)
86 //-----------------------------------------------------------------------------------------------------
87 BEGIN_EVENT_TABLE(pPlotter, wxPanel)
89 //EVT_SIZE (pPlotter::OnSize)
91 // Connectting the handled envents for the plotter to the corresponding methods
92 EVT_COMMAND (-1,wxEVT_PPLOTTER_CHANGED_FUNCTION, pPlotter::onChangeFunction)
93 EVT_COMMAND (-1,wxEVT_PPLOTTER_POINT_MOVE, pPlotter::onMovePoint_Plotter)
94 EVT_COMMAND (-1,wxEVT_PPLOTTER_POINT_ADD, pPlotter::onAddedPoint_Plotter)
95 EVT_COMMAND (-1,wxEVT_PPLOTTER_POINT_DELETE, pPlotter::onRemovedPoint_Plotter)
96 EVT_COMMAND (-1,wxEVT_PPLOTTER_GUIDELINES, pPlotter::onGuideLines)
98 // Connectting the handled envents for the color bar to the corresponding methods
99 EVT_COMMAND (-1,wxEVT_ADDED_POINT, pPlotter :: onAdded_ColorPoint )
100 EVT_COMMAND (-1,wxEVT_REMOVED_POINT, pPlotter :: onRemoved_ColorPoint )
101 EVT_COMMAND (-1,wxEVT_MOVED_POINT, pPlotter :: onMoved_ColorPoint )
102 EVT_COMMAND (-1,wxEVT_CHANGED_POINT, pPlotter :: onChanged_ColorPoint )
103 EVT_COMMAND (-1,wxEVT_ON_COLOR_BAR, pPlotter :: onColorBar )
105 // Connectting the handled envents from the max-min barrange to the corresponding methods
106 EVT_COMMAND (-1,wxEVT_TSBAR, pPlotter::onBarrange)
107 EVT_COMMAND (-1,wxEVT_SELECTION_END, pPlotter::onSelectionEnd)
108 EVT_COMMAND (-1,wxEVT_TSBAR_MOVED, pPlotter::onMovedBar)
109 EVT_COMMAND (-1,wxEVT_TSBAR_ACTUAL, pPlotter:: onActualChange_Bar)
110 EVT_COMMAND (-1,wxEVT_TSBAR_START, pPlotter::onStartChange_Bar)
111 EVT_COMMAND (-1,wxEVT_TSBAR_END, pPlotter::onEndChange_Bar)
116 //---------------------------------------------------------------------------------------------
117 // Constructors & Destructors
118 //---------------------------------------------------------------------------------------------
120 * Creates an integrated plotter instance
121 * @param *parent Container window
123 pPlotter :: pPlotter (wxWindow *parent,int nWidth, int nHeight)
124 :wxPanel(parent,-1,wxDefaultPosition,wxDefaultSize,wxTAB_TRAVERSAL)
126 SetBackgroundColour(wxColour(255,255,255));
127 m_plot = new pPlotterWindow( this, -1, wxPoint(0,0), wxSize(nWidth,nHeight), wxSUNKEN_BORDER );
128 actualFunction =NULL;
129 // Adding the axis layers to the plotter
130 m_plot->AddLayer( new pPlotterScaleX() );
131 m_plot->AddLayer( new pPlotterScaleY() );
133 // Creating the log window
136 m_log = new wxTextCtrl( panel, -1, wxT("This is the log window.\n"), wxPoint(0,0), wxSize(400,100), wxTE_MULTILINE );
137 // Sharing the log window of the application with the plotter widget
138 m_plot->setmLog(m_log);
143 // Creating a function for the plotter with given points x-vector and y-vector
146 double vectX_F1 [] = { 0, 20, 50, 80, 100, 115, 120, 210, 220,250 };
149 // double vectX_F1 [] = { 0, 20, 50, 80, 100, 115, 120, 210, 220,250 };
151 double vectY_F1 [] = { 0, 40, 70, 100, 200, 100, 40, 170, 0, 50 };
152 pGraphicalFunction * f1 = m_plot ->getFunctionForVectors( vectX_F1, 10, vectY_F1, 10 );
153 // Including and drawing the created function in the plotter
156 m_plot->addFunction( f1 );
157 m_plot->addFunctionToMove(f1);
158 //m_plot->addFunctionToMove(f1);
159 wxPen mypen1(*wxBLUE, 2, wxDOT_DASH );
161 f1->SetPen( mypen1 );
165 //=================== lines to sychronyze the bars width with the drawed plotter--------------------------
167 mpWindow* mplotWindow = ((mpWindow*)m_plot);
168 float minReal_X = 0; //(float)mplotWindow->getMinScrX();
169 float maxReal_X =(float)mplotWindow->getMaxScrX();
170 //float scrX=(float)mplotWindow->GetScrX()-100; // JPRx
171 //double scaleX=(scrX/(maxReal_X))* (mplotWindow->getZoomFactor()); // JPRx
173 // Creating the color bar with values according to the plotter added widget
174 color_bar = new pColorBar(this, (m_plot->GetSize()).GetWidth(),40, true);
175 color_bar -> setRepresentedValues ((int)minReal_X, (int)maxReal_X);
176 color_bar -> setDeviceBlitStart (70,0);
177 color_bar -> setVisibleRange ((int)minReal_X,(int) maxReal_X);
178 color_bar -> setDeviceEndMargin (50);
181 // Creating the min-max barrange bar with values according to the plotter added widget
182 barrange = new mBarRange(this, (m_plot->GetSize()).GetWidth(),30);
183 barrange -> setVisibleLabels (false);
184 barrange -> setRepresentedValues (minReal_X, maxReal_X);
185 barrange -> setDeviceBlitStart (70,0);
186 barrange -> setDeviceEndMargin (50);
188 // Adding the components to the sizer
190 if(m_plot->getActualFunction())
193 wxBoxSizer *sizer = new wxBoxSizer(wxVERTICAL);
194 sizer->Add( m_plot, 4, wxEXPAND);
195 sizer->Add( color_bar,0, wxEXPAND );
196 sizer->Add( barrange, 0, wxEXPAND );
198 // sizer->Add( m_log, 0, wxEXPAND);
200 // Stablishing the layout and sizer of the panel
201 /*panel->*/SetAutoLayout(true);
202 /*panel->*/SetSizer(sizer);
205 /*panel->*/Refresh();
209 pPlotter :: ~pPlotter ()
215 //---------------------------------------------------------------------------------------------
217 //---------------------------------------------------------------------------------------------
219 Set the bars according to the actual function
222 void pPlotter::setAll()
224 actualFunction = m_plot->getActualFunction();
226 if (actualFunction != NULL)
228 barrange -> setActiveStateTo(true);
229 color_bar -> setActiveStateTo(true);
233 double realMin_X = actualFunction->getMinX();
234 text = text + realMin_X;
235 text = text + _T(" maxX=");
236 double realMax_X = actualFunction->getMaxX();
237 text = text + realMax_X;
239 int minShowed = actualFunction->getMinXShowed();
240 int maxShowed = actualFunction->getMaxXShowed();
242 barrange -> setRepresentedValues (realMin_X, realMax_X);
243 barrange->SetStart( minShowed );
244 barrange->SetEnd( maxShowed );
247 std::vector<pColorPoint *> actualColorPoints;
248 actualFunction -> getColorPoints(actualColorPoints);
249 if(actualColorPoints.empty())
250 color_bar ->reinitiateColorBar (realMin_X, realMax_X);
252 color_bar ->reinitiateColorBarTo(actualColorPoints);
254 color_bar -> setVisibleRange (minShowed, maxShowed);
257 color_bar -> RefreshForce();
258 barrange -> RefreshForce();
265 //*****************************************************************************************************
266 // Color bar control methods
267 //*****************************************************************************************************
269 //-----------------------------------------------------------------------------------------------------
270 // Updating methods for occured events in the color bar
271 //-----------------------------------------------------------------------------------------------------
272 void pPlotter :: onAdded_ColorPoint(wxCommandEvent& event)
275 text = _T( "Last event was on color bar: Color point added, total#");
277 actualFunction = m_plot->getActualFunction();
278 if(actualFunction!=NULL)
280 std::vector<pColorPoint *> actualColorPoints;
281 color_bar ->getAddedColorsPointsList(actualColorPoints);
282 actualFunction -> setColorPoints(actualColorPoints);
283 text << actualColorPoints.size();
288 void pPlotter :: onRemoved_ColorPoint(wxCommandEvent& event)
291 text = _T( "Last event on color bar: Color point removed total#");
293 actualFunction = m_plot->getActualFunction();
294 std::vector<pColorPoint *> actualColorPoints;
295 color_bar ->getAddedColorsPointsList(actualColorPoints);
296 actualFunction -> setColorPoints(actualColorPoints);
297 text << actualColorPoints.size();
301 void pPlotter :: onMoved_ColorPoint(wxCommandEvent& event)
304 text = _T( "Last event was on color bar: Color point moved to: ");
305 int lastReal_X = (int)(color_bar->getLastMovedColorPoint())->getRealX();
308 barrange ->setRealX_vertical_line (lastReal_X);
309 barrange -> RefreshForce();
311 m_plot->setRealGuideX (lastReal_X);
316 void pPlotter:: onChanged_ColorPoint(wxCommandEvent& event)
319 sendTMessage(_T("Last event was on color bar: Color point changed color"));
322 void pPlotter :: onColorBar( wxCommandEvent& event )
324 if( (barrange->getRealX_vertical_line())!=-1)
326 barrange ->setRealX_vertical_line (-1);
327 m_plot->setRealGuideX (-1);
329 barrange -> RefreshForce();
334 //*****************************************************************************************************
335 // Plotter control methods
336 //*****************************************************************************************************
340 * Method called when actual function is changed
342 void pPlotter :: onChangeFunction (wxCommandEvent& event)
344 actualFunction = m_plot->getActualFunction();
346 if (actualFunction != NULL)
348 if( !barrange->isActive() )
350 barrange -> setActiveStateTo(true);
351 color_bar -> setActiveStateTo(true);
355 text = _T("Last event was on plotter: function changed, minX=");
356 double realMin_X = actualFunction->getMinX();
358 text << _T(" maxX=");
359 double realMax_X = actualFunction->getMaxX();
362 int minShowed = actualFunction->getMinXShowed();
363 int maxShowed = actualFunction->getMaxXShowed();
365 barrange -> setRepresentedValues (realMin_X, realMax_X);
366 barrange->SetStart( minShowed );
367 barrange->SetEnd( maxShowed );
369 std::vector<pColorPoint *> actualColorPoints;
370 actualFunction -> getColorPoints(actualColorPoints);
371 if(actualColorPoints.empty())
372 color_bar ->reinitiateColorBar (realMin_X, realMax_X);
374 color_bar ->reinitiateColorBarTo(actualColorPoints);
376 color_bar -> setVisibleRange ((int)realMin_X, maxShowed);
379 color_bar -> RefreshForce();
380 barrange -> RefreshForce();
388 * Method called when a point is added to the actual function on the plotter
391 void pPlotter :: onAddedPoint_Plotter (wxCommandEvent& event)
394 m_plot->writeInText(text);
399 * Method called when a point is removed to the actual function on the plotter
401 void pPlotter :: onRemovedPoint_Plotter (wxCommandEvent& event)
404 m_plot->writeInText(text);
409 * Method called when a point is moved from the actual function on the plotter
411 void pPlotter :: onMovePoint_Plotter (wxCommandEvent& event)
414 m_plot->writeInText(text);
418 * Method called when turn off the guide line from the actual function on the plotter
420 void pPlotter::onGuideLines(wxCommandEvent& event)
427 //*****************************************************************************************************
428 // Max-Min Barrange control methods
429 //*****************************************************************************************************
433 void pPlotter::onBarrange(wxCommandEvent& event)
440 void pPlotter::onActualChange_Bar(wxCommandEvent& event)
443 text = _T( "Last event was on min-max bar: Actual triangle moved to: " );
444 int lastActual_X = barrange->GetActual();
446 text << lastActual_X;
448 color_bar ->setRealX_vertical_line (lastActual_X);
449 m_plot->setRealGuideX (lastActual_X);
451 color_bar -> RefreshForce();
458 * Method called when the start triangle is moved. Adjusts the plotter and color bar view-range.
460 void pPlotter::onStartChange_Bar(wxCommandEvent& event)
464 text = _T( "Last event was on min-max bar: Start triangle moved to: ");
465 int realMin_X = barrange->GetStart();
466 text += wxString::Format(_T("%d"), realMin_X);
467 double realMax_X = m_plot->getMaxScrX();
469 color_bar -> setVisibleRange (realMin_X, (int)realMax_X);
471 m_plot->actualizeViewRange(realMin_X, (int)realMax_X);
473 //setting the plotter for draw the functions that
476 float startP=(float)barrange->getStartShowPorcentage();
477 float endP=(float)barrange->getEndShowPorcentage();
478 m_plot->moveFunctions(startP,endP);
481 color_bar -> RefreshForce();
482 m_plot -> UpdateAll();
486 void pPlotter::onEndChange_Bar(wxCommandEvent& event)
489 text += _T("Last event was on min-max bar: End triangle moved to: ");
490 int realMax_X = barrange->GetEnd();
491 text += wxString::Format(_T("%d"),realMax_X);
492 double realMin_X = m_plot->getMinScrX();
493 color_bar -> setVisibleRange ((int)realMin_X, realMax_X);
494 m_plot->actualizeViewRange((int)realMin_X,realMax_X);
496 float startP=(float)barrange->getStartShowPorcentage();
497 float endP=(float)barrange->getEndShowPorcentage();
498 m_plot->moveFunctions(startP,endP);
500 color_bar -> RefreshForce();
501 m_plot -> UpdateAll();
506 void pPlotter :: onSelectionEnd(wxCommandEvent& event)
508 if( (color_bar->getRealX_vertical_line())!=-1)
510 color_bar ->setRealX_vertical_line (-1);
511 m_plot->setRealGuideX (-1);
513 color_bar -> RefreshForce();
517 void pPlotter :: onMovedBar(wxCommandEvent& event)
520 text = _T( "Last event was on min-max bar: Moved bar to min:" );
522 int realMin_X = barrange->GetStart();
523 text += wxString::Format(_T("%d"),realMin_X);
526 int realMax_X = barrange->GetEnd();
527 text += wxString::Format(_T("%d"),realMax_X);
529 color_bar -> setVisibleRange (realMin_X, realMax_X);
531 float startP=(float)barrange->getStartShowPorcentage();
532 float endP=(float)barrange->getEndShowPorcentage();
533 m_plot->moveFunctions(startP,endP);
535 color_bar -> RefreshForce();
536 m_plot -> UpdateAll();
542 * Method for sending a text message to the container window
543 * @param theText Is the text of the message
545 void pPlotter :: sendTMessage(wxString theText)
547 //Creating a message event
548 wxCommandEvent puntualMSG_Event( wxEVT_NW_TEXT_MESAGGE, GetId() );
549 puntualMSG_Event.SetEventObject(this);
551 GetEventHandler()->ProcessEvent( puntualMSG_Event );
555 * Sets the text message
556 * @param nMessage Is the text message to set
558 void pPlotter :: setTextMessage(wxString nMessage)
564 * Gets the text message
565 * @param text Is the actual text message
567 wxString pPlotter :: getTextMessage()
572 * Add a function to the plotter
573 * when the function doesnt come from window
575 int pPlotter:: addFunction(pGraphicalFunction * function)
577 return m_plot->addFunction(function);
580 * Creates and returns a graphical funcion according to the indicated vectors.
582 pGraphicalFunction* pPlotter::getFunctionForVectors( double* vectorX, int sizeX,double * vectorY, int sizeY )
584 return m_plot->getFunctionForVectors(vectorX,sizeX, vectorY, sizeY );
589 void pPlotter::setType(int t)
594 Get a function in the plotter given the index
596 pGraphicalFunction* pPlotter:: getFunction(int index)
598 return m_plot->getFunction(index);
601 Adds function to move with the bar min max
603 int pPlotter::addFunctionToMove(pGraphicalFunction * function)
605 return m_plot->addFunctionToMove(function);
609 move the functions that the user wants to move
610 and that were setted in functionsToMove
611 @param porcentageMinX:the porcentage that the minShowed
612 of the funcntions have to be move
613 @param porcentageMaxX:the porcentage that the maxShowed
614 of the funcntions have to be move
617 void pPlotter:: moveFunctions(float porcentageMinX,float porcentageMaxX)
619 m_plot->moveFunctions(porcentageMinX,porcentageMaxX);
622 * deletes the function from the plotter
625 bool pPlotter::deleteFunction(pGraphicalFunction * function);
627 return m_plot->deleteFunction(function);
632 //--------------------
634 //---------------------
636 Returns the number of points that the bar color has
638 int pPlotter::getColorPointsSize()
640 return color_bar->getColorPointsSize();
643 Get the RGB values of the color point that is in the
646 void pPlotter::getBarColorDataAt(int index,double& x, int& red,int& green,int& blue)
648 color_bar->getDataAt(index,x,red,green,blue);
652 returns true if the point was succesfully added
653 PRE: 0<=red<=255 0<=green<=255 0<=blue<=255
655 bool pPlotter::addColorPoint(int x,int red,int green, int blue)
657 wxColour color= wxColour(red,green,blue);
658 return color_bar->addColorPoint((double)x, color);
660 void pPlotter::eraseColorPoints()
662 int min=(int)color_bar->getMinValue();
663 int max=(int)color_bar->getMaxValue();
664 color_bar->reinitiateColorBar(min,max);
667 //--------------------
669 //---------------------
670 float pPlotter::getMaxShowedPorcentage()
672 return barrange->getEndShowPorcentage();
674 float pPlotter::getMinShowedPorcentage()
676 return barrange->getStartShowPorcentage();
678 float pPlotter::getActualShowedPorcentage()
680 return barrange->getActualShowPorcentage();
683 //--------------------
684 // plotter Information
685 //---------------------
686 void pPlotter::setActual(pGraphicalFunction* nActual)
688 m_plot->setActualFunction(nActual);
690 void pPlotter::update()
692 //if it is a plotter of histograms
693 if(m_plot->getType()==2)
695 pGraphicalFunction* tf= m_plot->getActualFunction();
698 tf->clearSplineVectors();
699 tf->addSplinesPoints();
700 tf->initializeSplineVectors();
706 //----------------------------
707 //Handling Options Menu
708 //----------------------------
710 void pPlotter::setPopUpMenu(bool startD,bool stopD,bool smooth,bool line, bool zoomIn,
711 bool zoomOut,bool showPoints,bool noShowPoints,bool changeColor, bool addP,
712 bool delPoint,bool load,bool save)
714 m_plot->setPopUpMenu(startD, stopD, smooth, line, zoomIn,
715 zoomOut, showPoints, noShowPoints, changeColor, addP,
716 delPoint, load, save);
721 if the user resize the window
727 void pPlotter::OnSize( wxSizeEvent &WXUNUSED(event) )
730 GetClientSize(&scrX,&scrY);
731 m_plot->SetSize(scrX,scrY);
734 pGraphicalFunction* actual=m_plot->getActualFunction();
737 actual->setScreens(scrX,scrY);
747 ** Returns two vectors, the grey level of the point and its value, the value is between [0,1]
749 void pPlotter::GetValuesPointsFunction(std::vector<double>& greylevel,std::vector<double>& value, int histogramsize)
751 if(actualFunction != NULL){
752 double* xval = actualFunction->getX_RealValues();
753 double* yval = actualFunction->getY_RealValues();
755 actualFunction->getScaleY();
756 for(int i = 0; i < actualFunction->getSizePoints();i++){
757 greylevel.push_back(xval[i]);
758 value.push_back(yval[i]/histogramsize);
764 ** Returns two vectors, the grey level of the point and its value, the red, green
765 ** and blue value is between [0,1]
767 void pPlotter::GetValuesColorPointsFunction(std::vector<double>& greylevel,
768 std::vector<double>& red,
769 std::vector<double>& green,
770 std::vector<double>& blue)
773 if(color_bar != NULL){
775 std::vector<pColorPoint*> colors;
776 color_bar->getAddedColorsPointsList(colors);
778 for(int i = 0; i < colors.size();i++){
779 pColorPoint* pcolor = colors[i];
781 greylevel.push_back(pcolor->getRealX());
782 wxColour colour = pcolor->getColor();
784 double _red = (double)(colour.Red())/255.0;
785 double _green = (double)(colour.Green())/255.0;
786 double _blue = (double)(colour.Blue())/255.0;
789 green.push_back(_green);
790 blue.push_back(_blue);