]> Creatis software - creaMaracasVisu.git/blob - lib/maracasVisuLib/src/interface/wxWindows/widgets/pPlotter/pPlotter.cxx
#2490 creaMaracasVisu Feature New High - Histogram Interaction
[creaMaracasVisu.git] / lib / maracasVisuLib / src / interface / wxWindows / widgets / pPlotter / pPlotter.cxx
1 /*# ---------------------------------------------------------------------
2 #
3 # Copyright (c) CREATIS (Centre de Recherche en Acquisition et Traitement de l'Image
4 #                        pour la Sant�)
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
8 #
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.
15 #
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
20 #  liability.
21 #
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 # ------------------------------------------------------------------------ */
25
26 //---------------------------------------------------------------------------------------------
27 // Class definition include
28 //---------------------------------------------------------------------------------------------
29 #include "pPlotter.h"
30
31 // --------------------------------------------------------------------------------------------
32 // WX headers inclusion.
33 // For compilers that support precompilation, includes <wx/wx.h>.
34 // --------------------------------------------------------------------------------------------
35
36 #ifndef WX_PRECOMP
37 #include <wx/wx.h>
38 #endif
39
40 //---------------------------------------------------------------------------------------------
41 // Class implementation
42 //---------------------------------------------------------------------------------------------
43
44 IMPLEMENT_CLASS(pPlotter, wxPanel)
45
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()
52
53 DEFINE_EVENT_TYPE( wxEVT_NW_TEXT_MESAGGE )
54
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)
63
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)
72
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)
82
83
84 // ----------------------------------------------------------------------------------------------------
85 // EVENT TABLE (->Connect: analogous)
86 //-----------------------------------------------------------------------------------------------------
87 BEGIN_EVENT_TABLE(pPlotter, wxPanel)
88         //OnSize
89         //EVT_SIZE  (pPlotter::OnSize)
90         
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)
97
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 )
104
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)
112
113 END_EVENT_TABLE()
114
115
116 //---------------------------------------------------------------------------------------------
117 // Constructors & Destructors
118 //---------------------------------------------------------------------------------------------
119         /*
120         * Creates an integrated plotter instance 
121         * @param *parent Container window
122         */
123         pPlotter :: pPlotter  (wxWindow *parent,int nWidth, int nHeight)
124         :wxPanel(parent,-1,wxDefaultPosition,wxDefaultSize,wxTAB_TRAVERSAL)
125         {
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() );  
132
133                 // Creating the log window
134         /*
135            
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);
139                 
140                 */
141
142
143                 // Creating a function for the plotter with given points x-vector and y-vector
144
145                 /*
146                 double vectX_F1 [] = { 0, 20, 50, 80, 100, 115, 120, 210, 220,250 };
147
148                 
149 //              double vectX_F1 [] = { 0, 20, 50, 80, 100, 115, 120, 210, 220,250 };
150
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
154                 if (f1)
155                 {
156                         m_plot->addFunction( f1 );
157                         m_plot->addFunctionToMove(f1);
158                         //m_plot->addFunctionToMove(f1);
159                         wxPen mypen1(*wxBLUE, 2, wxDOT_DASH );
160                         mypen1.SetWidth(2);
161                         f1->SetPen( mypen1 );
162                 }
163                 */
164                 
165                 //=================== lines to sychronyze the bars width with the drawed plotter--------------------------
166
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
172                         
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);
179                 
180                 
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);
187
188                 // Adding the components to the sizer 
189                 /*
190                 if(m_plot->getActualFunction())
191                         setAll();
192                 */      
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 );
197
198                 // sizer->Add( m_log, 0, wxEXPAND);
199                 
200                 // Stablishing the layout and sizer of the panel
201                 /*panel->*/SetAutoLayout(true);
202                 /*panel->*/SetSizer(sizer);
203                 /*panel->*/Layout();
204
205                 /*panel->*/Refresh();
206         }
207
208
209         pPlotter :: ~pPlotter ()
210         {       
211                 
212                 
213         }
214
215 //---------------------------------------------------------------------------------------------
216 // Methods
217 //---------------------------------------------------------------------------------------------
218 /*
219 Set the bars according to the actual function 
220 */
221
222 void pPlotter::setAll()
223 {
224         actualFunction = m_plot->getActualFunction();
225         if (actualFunction != NULL)
226         {
227                 barrange -> setActiveStateTo(true);
228                 color_bar -> setActiveStateTo(true);
229                 text.Clear();
230                 text = _T("minX=");
231                 double realMin_X = actualFunction->getMinX();
232                 text = text + realMin_X;        
233                 text = text + _T(" maxX=");
234                 double realMax_X = actualFunction->getMaxX();
235                 text = text + realMax_X;
236                 int minShowed = actualFunction->getMinXShowed();
237                 int maxShowed = actualFunction->getMaxXShowed();
238                 barrange -> setRepresentedValues (realMin_X, realMax_X);
239                 barrange->SetStart( minShowed );
240                 barrange->SetEnd( maxShowed );
241                 std::vector<pColorPoint *> actualColorPoints;
242                 actualFunction->getColorPoints(actualColorPoints);
243                 if(actualColorPoints.empty())
244                 {
245                         color_bar->reinitiateColorBar (realMin_X, realMax_X);
246                 } else {
247                         color_bar->reinitiateColorBarTo(actualColorPoints);
248                 }
249                 color_bar->setVisibleRange (minShowed, maxShowed);
250                 // Refresh
251                 color_bar->RefreshForce();
252                 barrange->RefreshForce();       
253                 sendTMessage(text);
254         } // if actualFunction
255 }
256
257         
258 //*****************************************************************************************************
259 // Color bar control methods
260 //*****************************************************************************************************
261
262 //-----------------------------------------------------------------------------------------------------
263 // Updating methods for occured events in the color bar
264 //-----------------------------------------------------------------------------------------------------
265 void  pPlotter::onAdded_ColorPoint(wxCommandEvent& event)
266 {
267         text.Clear();
268         text = _T( "Last event was on color bar: Color point added, total#");
269         actualFunction = m_plot->getActualFunction();
270         if(actualFunction!=NULL)
271         {               
272                 std::vector<pColorPoint *> actualColorPoints;
273                 color_bar ->getAddedColorsPointsList(actualColorPoints);
274                 actualFunction -> setColorPoints(actualColorPoints);
275                 text << actualColorPoints.size();
276                 sendTMessage(text);
277         }
278 }
279
280 void  pPlotter :: onRemoved_ColorPoint(wxCommandEvent& event)
281 {       
282         text.Clear();
283         text = _T( "Last event on color bar: Color point removed total#");
284         actualFunction = m_plot->getActualFunction();
285         std::vector<pColorPoint *> actualColorPoints;
286         color_bar ->getAddedColorsPointsList(actualColorPoints);
287         actualFunction -> setColorPoints(actualColorPoints);
288         text << actualColorPoints.size();
289         sendTMessage(text);
290 }
291
292 void  pPlotter :: onMoved_ColorPoint(wxCommandEvent& event)
293 {
294         text.Clear();
295         text = _T( "Last event was on color bar: Color point moved to: ");
296         int lastReal_X = (int)(color_bar->getLastMovedColorPoint())->getRealX();
297         text << lastReal_X;
298         barrange ->setRealX_vertical_line (lastReal_X);
299         barrange -> RefreshForce();
300         m_plot->setRealGuideX (lastReal_X);
301         m_plot->UpdateAll();
302         sendTMessage(text);
303 }
304
305 void  pPlotter:: onChanged_ColorPoint(wxCommandEvent& event)
306 {
307         text.Clear();
308         sendTMessage(_T("Last event was on color bar: Color point changed color"));
309 }
310
311 void pPlotter :: onColorBar( wxCommandEvent& event )
312 {
313         if( (barrange->getRealX_vertical_line())!=-1)
314         {
315                 barrange ->setRealX_vertical_line (-1); 
316                 m_plot->setRealGuideX (-1);
317
318                 barrange -> RefreshForce();
319                 m_plot->UpdateAll();
320         }
321 }
322
323 //*****************************************************************************************************
324 // Plotter control methods
325 //*****************************************************************************************************
326
327
328 /*
329 * Method called when actual function is changed
330 */
331 void pPlotter :: onChangeFunction (wxCommandEvent& event)
332 {
333         actualFunction = m_plot->getActualFunction();
334         
335         if (actualFunction != NULL)
336         {
337                 if( !barrange->isActive() )
338                 {
339                         barrange -> setActiveStateTo(true);
340                         color_bar -> setActiveStateTo(true);
341                 }
342
343                 text.Clear();
344                 text = _T("Last event was on plotter: function changed, minX=");
345                 double realMin_X = actualFunction->getMinX();
346                 text << realMin_X;      
347                 text << _T(" maxX=");
348                 double realMax_X = actualFunction->getMaxX();
349                 text << realMax_X;
350
351                 int minShowed = actualFunction->getMinXShowed();
352                 int maxShowed = actualFunction->getMaxXShowed();
353
354                 barrange -> setRepresentedValues (realMin_X, realMax_X);
355                 barrange->SetStart( minShowed );
356                 barrange->SetEnd( maxShowed );
357                 
358                 std::vector<pColorPoint *> actualColorPoints;
359                 actualFunction->getColorPoints(actualColorPoints);
360                 if(actualColorPoints.empty())
361                 {
362                         color_bar->reinitiateColorBar (realMin_X, realMax_X);
363                 } else {
364                         color_bar->reinitiateColorBarTo(actualColorPoints);
365                 }
366                 color_bar->setVisibleRange ((int)realMin_X, maxShowed);
367                 
368                 // Refresh
369                 color_bar->RefreshForce();
370                 barrange->RefreshForce();       
371                 
372                 sendTMessage(text);
373         } // if actualFunction
374 }
375
376
377 /*
378 * Method called when a point is added to the actual function on the plotter
379 */
380
381 void pPlotter :: onAddedPoint_Plotter (wxCommandEvent& event)
382 {
383         text.Clear();
384         m_plot->writeInText(text);
385         sendTMessage(text);
386 }
387
388 /*
389 * Method called when a point is removed to the actual function on the plotter
390 */
391 void pPlotter :: onRemovedPoint_Plotter (wxCommandEvent& event)
392 {
393         text.Clear();
394         m_plot->writeInText(text);
395         sendTMessage(text);     
396 }
397
398 /*
399 * Method called when a point is moved from the actual function on the plotter
400 */
401 void pPlotter :: onMovePoint_Plotter (wxCommandEvent& event)
402 {
403         text.Clear();
404         m_plot->writeInText(text);
405         sendTMessage(text);
406 }
407 /*
408 * Method called when turn off the guide line from the actual function on the plotter
409 */
410 void pPlotter::onGuideLines(wxCommandEvent& event)
411 {
412                 
413 }
414
415
416
417 //*****************************************************************************************************
418 // Max-Min Barrange control methods
419 //*****************************************************************************************************
420 /*
421 *
422 */
423 void  pPlotter::onBarrange(wxCommandEvent& event)
424 {
425                 
426 }
427 /*
428 *
429 */
430 void  pPlotter::onActualChange_Bar(wxCommandEvent& event)
431 {
432         int lastActual_X = barrange->GetActual();
433         
434         color_bar ->setRealX_vertical_line (lastActual_X);
435         color_bar -> RefreshForce();    
436
437         m_plot->setRealGuideX(lastActual_X);
438         m_plot->UpdateAll();
439
440         text.Clear();
441         text = _T( "Last event was on min-max bar: Actual triangle moved to: " );
442         text << lastActual_X;
443         sendTMessage(text);
444 }
445
446 /*
447 * Method called when the start triangle is moved. Adjusts the plotter and color bar view-range.
448 */
449 void  pPlotter::onStartChange_Bar(wxCommandEvent& event)
450 {
451         text.Clear();
452     
453         text = _T( "Last event was on min-max bar: Start triangle moved to: ");
454         int realMin_X = barrange->GetStart();
455         text += wxString::Format(_T("%d"), realMin_X);  
456         double realMax_X = m_plot->getMaxScrX();
457         
458         color_bar -> setVisibleRange (realMin_X, (int)realMax_X);
459         
460         m_plot->actualizeViewRange(realMin_X, (int)realMax_X);
461         
462         //setting the plotter for draw the functions that
463         //it has to move.
464         
465         float startP    =       (float)barrange->getStartShowPorcentage();
466         float endP              =       (float)barrange->getEndShowPorcentage();
467         m_plot->moveFunctions(startP,endP);
468         
469         //Updating
470         color_bar -> RefreshForce();
471         m_plot -> UpdateAll();
472         sendTMessage(text);
473 }
474
475 void  pPlotter::onEndChange_Bar(wxCommandEvent& event)
476 {
477         text.Clear();
478         text += _T("Last event was on min-max bar: End  triangle moved to: ");
479         int realMax_X           = barrange->GetEnd();
480         text += wxString::Format(_T("%d"),realMax_X);   
481         double realMin_X        = m_plot->getMinScrX();
482         color_bar -> setVisibleRange ((int)realMin_X, realMax_X);
483         m_plot->actualizeViewRange((int)realMin_X,realMax_X);
484         float startP            = (float)barrange->getStartShowPorcentage();
485         float endP                      = (float)barrange->getEndShowPorcentage();
486         m_plot->moveFunctions(startP,endP);
487         color_bar -> RefreshForce();
488         m_plot -> UpdateAll();
489         sendTMessage(text);
490 }
491
492 void pPlotter :: onSelectionEnd(wxCommandEvent& event)
493 {
494         if( (color_bar->getRealX_vertical_line())!=-1)
495         {
496                 color_bar ->setRealX_vertical_line (-1);        
497                 m_plot->setRealGuideX (-1);
498
499                 color_bar -> RefreshForce();
500                 m_plot->UpdateAll();    
501         }
502 }
503 void  pPlotter :: onMovedBar(wxCommandEvent& event)
504 {
505         text.Clear();
506         text = _T( "Last event was on min-max bar: Moved bar to min:" );
507         
508         int realMin_X = barrange->GetStart();
509         text +=  wxString::Format(_T("%d"),realMin_X);  
510         text +=  _T(" max:");
511
512         int realMax_X = barrange->GetEnd();
513         text +=  wxString::Format(_T("%d"),realMax_X);
514
515         color_bar -> setVisibleRange (realMin_X, realMax_X);
516         
517         float startP=(float)barrange->getStartShowPorcentage();
518         float endP=(float)barrange->getEndShowPorcentage();
519         m_plot->moveFunctions(startP,endP);
520         
521         color_bar -> RefreshForce();
522         m_plot -> UpdateAll();
523
524         sendTMessage(text);
525 }
526
527 /*
528         * Method for sending a text message to the container window
529         * @param theText Is the text of the message
530         */
531 void pPlotter :: sendTMessage(wxString theText)
532 {
533         //Creating a message event 
534         wxCommandEvent puntualMSG_Event( wxEVT_NW_TEXT_MESAGGE, GetId() );
535         puntualMSG_Event.SetEventObject(this);
536         //Sending the event
537         GetEventHandler()->ProcessEvent( puntualMSG_Event );
538 }
539
540 /*
541         * Sets the text message
542         * @param nMessage Is the text message to set
543         */
544         void pPlotter :: setTextMessage(wxString nMessage)
545         {
546                 text = nMessage;
547         }
548
549         /*
550         * Gets the text message
551         * @param text Is the actual text message 
552         */
553         wxString pPlotter :: getTextMessage()
554         {
555                 return text;
556         }
557         /**
558         * Add a function to the plotter
559         * when the function doesnt come from window
560         */
561         int pPlotter:: addFunction(pGraphicalFunction * function)
562         {
563                 return m_plot->addFunction(function);  
564         }
565         /**
566         * Creates and returns a graphical funcion according to the indicated vectors.
567         */
568         pGraphicalFunction* pPlotter::getFunctionForVectors( double* vectorX, int sizeX,double * vectorY, int sizeY )
569         {
570                 return m_plot->getFunctionForVectors(vectorX,sizeX, vectorY, sizeY );
571         }
572                 /*
573          Set Type
574         */
575         void pPlotter::setType(int t)
576         {
577                 m_plot->setType(t);
578         }
579         /*
580          Get a function in the plotter given the index
581         */
582         pGraphicalFunction* pPlotter:: getFunction(int index)
583         {
584                 return m_plot->getFunction(index);
585         }
586         /*
587          Adds  function to move with the bar min max
588         */
589         int pPlotter::addFunctionToMove(pGraphicalFunction * function)
590         {
591                 return m_plot->addFunctionToMove(function);
592         }
593         
594         /*
595           move the functions that the user wants to move
596           and that were setted in functionsToMove
597           @param porcentageMinX:the porcentage that the minShowed
598           of the funcntions have to be move
599           @param porcentageMaxX:the porcentage that the maxShowed
600           of the funcntions have to be move
601
602         */
603         void pPlotter:: moveFunctions(float porcentageMinX,float porcentageMaxX)
604         {
605                 m_plot->moveFunctions(porcentageMinX,porcentageMaxX);
606         }
607         /*
608         * deletes the function from the plotter
609         */
610         /*
611         bool pPlotter::deleteFunction(pGraphicalFunction * function);
612                 {
613                         return m_plot->deleteFunction(function);
614
615                 }
616
617         */
618         //--------------------
619         // Color information
620         //---------------------
621         /**
622                 Returns the number of points that the bar color has
623         */
624         int pPlotter::getColorPointsSize()
625         {
626                 return color_bar->getColorPointsSize();
627         }
628         /*
629          Get the RGB values of the color point that is in the
630          index given
631         */
632         void pPlotter::getBarColorDataAt(int index,double& x, int& red,int& green,int& blue)
633         {
634                 color_bar->getDataAt(index,x,red,green,blue);
635         }
636         /*
637          add a color Point 
638          returns true if the point was succesfully added
639          PRE: 0<=red<=255 0<=green<=255 0<=blue<=255
640         */
641         bool pPlotter::addColorPoint(int x,int red,int green, int blue)
642         {
643                 wxColour color= wxColour(red,green,blue);
644                 return color_bar->addColorPoint((double)x, color);
645         }
646         void pPlotter::eraseColorPoints()
647         {
648                 int min=(int)color_bar->getMinValue();
649                 int max=(int)color_bar->getMaxValue();
650                 color_bar->reinitiateColorBar(min,max);
651         }
652
653         //--------------------
654         // bar Information
655         //---------------------
656         float pPlotter::getMaxShowedPorcentage()
657         {
658                 return barrange->getEndShowPorcentage();
659         }
660
661         float pPlotter::getMinShowedPorcentage()
662         {
663                 return barrange->getStartShowPorcentage();
664         }
665
666         float pPlotter::getActualShowedPorcentage()
667         {
668                 return barrange->getActualShowPorcentage();
669         }
670         
671         //--------------------
672         // plotter Information
673         //---------------------
674         void pPlotter::setActual(pGraphicalFunction* nActual)
675         {
676                 m_plot->setActualFunction(nActual);
677         }
678         void pPlotter::update()
679         {
680                 //if it is a plotter of histograms
681                 if(m_plot->getType()==2)
682                 {
683                         pGraphicalFunction* tf= m_plot->getActualFunction();
684                         if(tf->getType()==2)
685                         {
686                                 tf->clearSplineVectors();
687                                 tf->addSplinesPoints();
688                                 tf->initializeSplineVectors();
689                         }
690                 }
691
692                 m_plot->UpdateAll();
693         }
694         //----------------------------
695         //Handling Options Menu
696         //----------------------------
697         
698         void pPlotter::setPopUpMenu(bool startD,bool stopD,bool smooth,bool line, bool zoomIn,
699                                           bool zoomOut,bool showPoints,bool noShowPoints,bool changeColor, bool addP,
700                                           bool delPoint,bool load,bool save)
701         {
702                 m_plot->setPopUpMenu(startD, stopD, smooth, line,  zoomIn,
703                                            zoomOut, showPoints, noShowPoints, changeColor,  addP,
704                                            delPoint, load, save);
705         }
706
707
708         /*
709                 if the user resize the window   
710         */
711         
712         
713         
714         /*
715         void pPlotter::OnSize( wxSizeEvent &WXUNUSED(event) )
716         {
717                 int scrX,scrY;
718                 GetClientSize(&scrX,&scrY);
719                 m_plot->SetSize(scrX,scrY);
720                 
721                 
722                 pGraphicalFunction* actual=m_plot->getActualFunction();
723                 if(actual!=NULL)
724                 {               
725                         actual->setScreens(scrX,scrY);
726                         actual->setScales();
727                 }
728                 
729                 
730         }
731         */
732         
733
734 /**
735 **      Returns two vectors, the grey level of the point and its value, the value is between [0,1]
736 **/
737 void pPlotter::GetValuesPointsFunction(std::vector<double>& greylevel,std::vector<double>& value, int histogramsize)
738 {
739         if(actualFunction != NULL)
740         {
741                 double* xval = actualFunction->getX_RealValues();
742                 double* yval = actualFunction->getY_RealValues();
743                 actualFunction->getScaleY();
744                 for(int i = 0; i < actualFunction->getSizePoints();i++)
745                 {
746                         greylevel.push_back(xval[i]);
747                         value.push_back(yval[i]/histogramsize);
748                 } // for
749         } // if
750 }
751
752 /**
753 **      Returns two vectors, the grey level of the point and its value, the red, green
754 **      and blue value is between [0,1]
755 **/
756 void pPlotter::GetValuesColorPointsFunction(std::vector<double>& greylevel,
757                                                                 std::vector<double>& red,
758                                                                 std::vector<double>& green,
759                                                                 std::vector<double>& blue)
760 {
761         if(color_bar != NULL)
762         {
763                 std::vector<pColorPoint*> colors;
764       color_bar->getAddedColorsPointsList(colors);
765                 for(int i = 0; i < colors.size();i++)
766                 {
767                         pColorPoint* pcolor     = colors[i];
768                         greylevel.push_back(pcolor->getRealX());
769                         wxColour colour                 = pcolor->getColor();
770                         double _red                     = (double)(colour.Red())/255.0;
771                         double _green                   = (double)(colour.Green())/255.0;
772                         double _blue                    = (double)(colour.Blue())/255.0;
773                         red.push_back(_red);
774                         green.push_back(_green);
775                         blue.push_back(_blue);
776                 } // for
777         } // if
778 }
779
780
781
782