]> Creatis software - creaMaracasVisu.git/blob - bbtk/src/bbmaracasvisuPlotterView.cxx
e3e61bad11061a5e80f15e47956e139715a7aa01
[creaMaracasVisu.git] / bbtk / src / bbmaracasvisuPlotterView.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 #include "bbmaracasvisuPlotterView.h"
27 #include "bbcreaMaracasVisuPackage.h"
28
29 #include "pPlotterScaleX.h"
30 #include "pPlotterScaleY.h"
31
32
33 namespace bbcreaMaracasVisu
34 {
35
36 BBTK_ADD_BLACK_BOX_TO_PACKAGE(creaMaracasVisu,PlotterView)
37 BBTK_BLACK_BOX_IMPLEMENTATION(PlotterView,bbtk::WxBlackBox);
38
39 //---------------------------------------------------
40 void PlotterView::Process()
41 {
42         if (bbGetInputInX().size()==bbGetInputInY().size() ) 
43     {
44                 pGraphicalFunction *pGF  = mwxwidget->getFunction(0);
45                 pGraphicalFunction *pGF2 = mwxwidget->getFunction(1);
46         // EED 2020-01-22
47                 if (pGF!=NULL)  
48                 { 
49                         // -Erasing  points-
50                         int i,sizePoints                = pGF->getSizePoints();
51                         for (i=1; i<sizePoints;i++)
52                         {
53         //EED 2017-09-16 Migration wxWidgets 2.8 to 3.0
54         #if wxMAJOR_VERSION <= 2
55                                 pGF->deletePointAt(1);   //  EED here NOT 0 is 1
56         #else
57                                 pGF->deletePointAt(0);   //  EED here NOT 0 is 1
58         #endif
59                         } // for i
60                         mwxwidget->deleteFunction(pGF);  
61                         pGF=NULL;  
62                 }
63         // EED 2020-01-22
64                 if (pGF2!=NULL) 
65                 { 
66                         // -Erasing  points-
67                         int i,sizePoints                = pGF2->getSizePoints();
68                         for (i=0; i<sizePoints;i++)
69                         {
70         //EED 2017-09-16 Migration wxWidgets 2.8 to 3.0
71         #if wxMAJOR_VERSION <= 2
72                                 pGF2->deletePointAt(1);   //  EED here NOT 0 is 1
73         #else
74                                 pGF2->deletePointAt(0);   //  EED here NOT 0 is 1
75         #endif
76                         } // for i
77                         mwxwidget->deleteFunction(pGF2); 
78                         pGF2=NULL; 
79                 }
80         
81                         if ( (bbGetInputInY().size()!=0) && (pGF==NULL) )               
82                         {
83                                 // avoid 'taking address of temporary '
84                                 //pGraphicalFunction *pGF = mwxwidget->getFunctionForVectors( &(bbGetInputInX()), &(bbGetInputInY()) ); // taking address of temporary ! JPRx
85                                 std::vector<double> inX;
86                                 if (bbGetInputInX().size()==0)
87                                 {
88                                         int i,size=bbGetInputInY().size();
89                                         for(i=0;i<size;i++)
90                                         {
91                                                 inX.push_back((double)i);
92                                         } // for
93                                 } else {
94                                         inX = bbGetInputInX();
95                                 } // if bbGetInputInX
96                                 std::vector<double> inY = bbGetInputInY();
97
98                                 bool ok=false;
99                                 int i, size = inY.size();
100                                 for ( i=0 ; i<size ; i++ )
101                                 {       
102                                         if (inY[i]!=0) {ok=true;}
103                                 }// for
104                                 if (ok==true) 
105                                 {
106                                         pGF = mwxwidget->getFunctionForVectors( &inX, &inY ); 
107                                         mwxwidget->addFunction(pGF);            
108                                 } // if ok
109
110                         } // if bbGetInputInY
111
112                         if ((bbGetInputInY2().size()!=0)&& (pGF2==NULL) )
113                         {
114                                 // avoid 'taking address of temporary '
115                                 //pGraphicalFunction *pGF = mwxwidget->getFunctionForVectors( &(bbGetInputInX()), &(bbGetInputInY()) ); // taking address of temporary ! JPRx
116                                 std::vector<double> inX2;
117                                 if (bbGetInputInX().size()==0)
118                                 {
119                                         int i,size=bbGetInputInY2().size();
120                                         for(i=0;i<size;i++)
121                                         {
122                                                 inX2.push_back((double)i);
123                                         } // for
124                                 } else {
125                                         inX2 = bbGetInputInX();
126                                 } // if bbGetInputInX
127                                 std::vector<double> inY2 = bbGetInputInY2();
128
129                                 bool ok2=false;
130                                 int i, size = inY2.size();
131                                 for ( i=0 ; i<size ; i++ )
132                                 {       
133                                         if (inY2[i]!=0) {ok2=true;}
134                                 }// for
135                                 if (ok2==true) 
136                                 {
137                                         pGF2 = mwxwidget->getFunctionForVectors( &inX2, &inY2 ); 
138                                         mwxwidget->addFunction(pGF2);           
139                                 } // if ok
140
141
142                         } // if bbGetInputInY
143                 
144         /* EED 2020-01-22
145
146                 if (pGF!=NULL)  
147                 {
148                         // -Erasing  points-
149                         int i,sizePoints                = pGF->getSizePoints();
150                         for (i=1; i<sizePoints;i++)
151                         {
152                                 pGF->deletePointAt(1);  //  EED here NOT 0 is 1
153                         } // for i
154                         // -Add Points-
155                         double px;
156                         sizePoints=bbGetInputInY().size();
157                         for (i=0; i<sizePoints;i++)
158                         {
159                                 if (i<bbGetInputInX().size())
160                                 {
161                                         px = bbGetInputInX()[i]; 
162                                 } else {
163                                         px = i;
164                                 }       
165                                 pGF->AddNewPoint( px, bbGetInputInY()[i] );
166                         }               
167                 }// if pGF
168
169                 if (pGF2!=NULL) 
170                 {
171                         // -Erasing  points-
172                         int i,sizePoints                = pGF2->getSizePoints();
173                         for (i=0; i<sizePoints;i++)
174                         {
175         //EED 2017-09-16 Migration wxWidgets 2.8 to 3.0
176         #if wxMAJOR_VERSION <= 2
177                                 pGF2->deletePointAt(1);   //  EED here NOT 0 is 1
178         #else
179                                 pGF2->deletePointAt(0);   //  EED here NOT 0 is 1
180         #endif
181                         } // for i
182                         // -Add Points-
183                         double px;
184                         sizePoints=bbGetInputInY2().size();
185                         for (i=0; i<sizePoints;i++)
186                         {
187                                 if (i<bbGetInputInX().size())
188                                 {
189                                         px = bbGetInputInX()[i]; 
190                                 } else {
191                                         px = i;
192                                 }       
193                                 pGF2->AddNewPoint( px, bbGetInputInY2()[i] );
194                         }  // for       
195                 }// if pGF
196         */
197                 mwxwidget->UpdateAll();
198         } else {
199                 printf("EED Warnning... PlotterView::Process()   Size of vecto X and Y is not coherent.\n");
200         } // InX.size InY.size
201
202 }
203
204         
205 //---------------------------------------------------
206 void PlotterView::CreateWidget(wxWindow* parent)
207 {
208         bbtkDebugMessageInc("Core",9,"PlotterView::CreateWxWindow()"<<std::endl);
209         mwxwidget = new pPlotterWindow( parent , -1,wxDefaultPosition,  wxDefaultSize,  0 );
210         mwxwidget->AddLayer(new pPlotterScaleX());
211         mwxwidget->AddLayer(new pPlotterScaleY());
212         mwxwidget->setMinScrY(0);
213         mwxwidget->setMaxScrY(5000);
214         bbtkDebugDecTab("Core",9);
215         bbSetOutputWidget( mwxwidget );
216 }
217
218 //---------------------------------------------------
219 void PlotterView::bbUserSetDefaultValues()
220 {
221         mwxwidget = NULL;
222 }
223         
224         //-----------------------------------------------------------------     
225         void PlotterView::bbUserInitializeProcessing()
226         {
227         }
228         
229         //-----------------------------------------------------------------     
230         void PlotterView::bbUserFinalizeProcessing()
231         {
232         }
233         
234         //-----------------------------------------------------------------     
235
236 }
237 // EO namespace bbcreaMaracasVisu
238
239