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