]> Creatis software - creaMaracasVisu.git/blob - bbtk/src/bbmaracasvisuContourVOI.cxx
#
[creaMaracasVisu.git] / bbtk / src / bbmaracasvisuContourVOI.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 //HOLA!!!
27 //HOLA!!!
28
29 #include "bbmaracasvisuContourVOI.h"
30 #include "bbcreaMaracasVisuPackage.h"
31
32
33
34 namespace bbcreaMaracasVisu
35 {
36
37   //--------------------------------------------------------------------------
38   // wxWidgetMPR
39   //--------------------------------------------------------------------------
40 BEGIN_EVENT_TABLE( wxWidgetVOI, wxPanel )
41         EVT_MENU( 12121, wxWidgetVOI::OnRefreshView )
42         EVT_MENU( 12122, wxWidgetVOI::OnDClickLeft  )
43 END_EVENT_TABLE( );
44
45   //-----------
46   //Constructor
47   //-----------
48   wxWidgetVOI::wxWidgetVOI(wxWindow* parent,  wxVtkBaseView *wxvtkbaseview, vtkImageData *imagedata)
49           : wxPanel( parent, -1 )
50   {
51 //              wxPanel *panel  = this;
52
53                 wxFlexGridSizer *sizer=new wxFlexGridSizer(1);          
54                 sizer   -> AddGrowableCol(0);
55                 this    -> SetSizer(sizer);
56                 this    -> SetAutoLayout(true);
57                 this->wxvtkbaseview = NULL;
58                 mcontourvoiwidget=NULL;
59
60                 if(wxvtkbaseview!=NULL&&imagedata!=NULL){
61
62                         setBaseView(wxvtkbaseview);
63                         setImageData(imagedata);
64                         initializeVOIWidget();
65                 }                       
66   }
67
68    void wxWidgetVOI::initializeVOIWidget()
69         {
70            wxSizer* sizer = this->GetSizer();
71
72
73 /// \TODO fix deprecated warning: virtual bool wxSizer::Remove(wxWindow*) is deprecated (declared at /usr/include/wx-2.8/wx/sizer.h:513)                
74                 if(mcontourvoiwidget!=NULL)
75                 {
76 //EED 2017-09-16 Migration wxWidgets 2.8 to 3.0
77 #if wxMAJOR_VERSION <= 2
78                         sizer->Remove( mcontourvoiwidget );     
79 #else
80                         sizer->Detach( mcontourvoiwidget );     
81 #endif
82                         mcontourvoiwidget->Destroy();
83                 }
84
85                 mcontourvoiwidget = new ContourVOIWidget( this, wxvtkbaseview, imagedata );
86                 mcontourvoiwidget->ConfigureVTK();
87
88                 sizer   -> Add( mcontourvoiwidget,1,wxGROW ); 
89 //              wxwidget = new wxMPRWidget2( panel, marimagedata , 1 ); 
90 //              wxwidget->ConfigureVTK();       
91                 
92                 this->Refresh();
93   }
94
95   void wxWidgetVOI::setBaseView(wxVtkBaseView * wxvtkbaseview)
96         {
97           this->wxvtkbaseview = wxvtkbaseview;
98   }
99
100   void wxWidgetVOI::setImageData(vtkImageData * imagedata)
101         {
102           this->imagedata = imagedata;
103   }
104
105  
106 //--------------------------------------------------------------------------
107   wxWidgetVOI::~wxWidgetVOI()
108   {
109   }
110         
111 //--------------------------------------------------------------------------
112   void wxWidgetVOI::Refresh()
113   { 
114 //        wxwidget->RefreshView();
115   }
116
117 //--------------------------------------------------------------------------
118   //---------------
119   //Handling events
120   //---------------
121   void wxWidgetVOI::OnRefreshView(wxCommandEvent &event)
122   {
123 /*
124           if((wxwidget!=NULL) && (mbbViewerMPR!=NULL))
125           {
126             point.clear();
127                 point.push_back((int)wxwidget->GetVtkMPRBaseData()->GetX());
128                 point.push_back((int)wxwidget->GetVtkMPRBaseData()->GetY());
129                 point.push_back((int)wxwidget->GetVtkMPRBaseData()->GetZ());
130                 mbbViewerMPR->bbSetOutputPoint(point);
131                 mbbViewerMPR->bbSetModifiedStatus();
132                 wxwidget->RefreshView();
133           }
134 */
135   }
136
137 //--------------------------------------------------------------------------
138   void wxWidgetVOI::OnDClickLeft(wxCommandEvent & event) 
139   {
140 //      wxwidget->RefreshView();
141   }
142
143 //------------------------------------------------------
144 ContourVOIWidget* wxWidgetVOI::GetContourVOIWidget()
145 {
146         return mcontourvoiwidget;
147 }
148
149 //--------------------------------------------------------------------------------------------------------------------------------
150
151 //------------------------------------------------------
152 //------------------------------------------------------
153 //------------------------------------------------------
154
155
156 BBTK_ADD_BLACK_BOX_TO_PACKAGE(creaMaracasVisu,ContourVOI)
157 BBTK_BLACK_BOX_IMPLEMENTATION(ContourVOI,bbtk::WxBlackBox);
158
159 //------------------------------------------------------
160 void ContourVOI::Process()
161 {  
162
163         /*if (bbGetInputwxVtkBaseView()==NULL) 
164     {
165       wxMessageDialog(NULL,  bbtk::std2wx("(ContourVOI) Input 'wxVtkBaseView' is not set"),  bbtk::std2wx(bbGetFullName()) ).ShowModal();         
166     }
167         if (bbGetInputIn()==NULL) 
168     {
169       wxMessageDialog(NULL,  bbtk::std2wx("(ContourVOI) Input 'In' is not set"),  bbtk::std2wx(bbGetFullName()) ).ShowModal();
170     }*/
171
172         vtkImageData* img = bbGetInputIn();
173         wxVtkBaseView* base = bbGetInputwxVtkBaseView();
174
175         wxWidgetVOI* wxwidgetvoi = (wxWidgetVOI*)bbGetOutputWidget();
176
177         if(base !=NULL && img != NULL && _img != img){
178
179                 _img = img;
180                 _base = base;
181                 
182                 wxwidgetvoi->setBaseView(base);
183                 wxwidgetvoi->setImageData(img);
184                 wxwidgetvoi->initializeVOIWidget();             
185         }
186
187         if (wxwidgetvoi!=NULL && _img!=NULL && _base != NULL){
188                 ContourVOIWidget* contourvoiwidget = wxwidgetvoi->GetContourVOIWidget();
189                 
190                 int voi[6];
191                 contourvoiwidget->GetVOI(voi);
192                 char buffer[40];
193                 sprintf(buffer,"%d %d %d ", voi[0], voi[2], voi[4] );
194                 std::string Index(buffer);
195                 sprintf(buffer,"%d %d %d ", voi[1]-voi[0]+1, voi[3]-voi[2]+1, voi[5]-voi[4]+1 );
196                 std::string Size(buffer);
197
198                 std::cout<<"ContourVOI index "<<Index<<" size "<<Size<<std::endl;
199
200         /*EED 20 Juin 2011      
201           This go out of the box ... see ExtractVtkImageFilter ...
202          
203                 //JCP
204                 if(_extract!=NULL){             
205                         _extract->Delete();
206                 }
207                 _extract = vtkExtractVOI::New();
208                 _extract->RemoveAllInputs();
209                 _extract->SetInput(img);
210                 _extract->SetVOI(voi);  
211                 _extract->UpdateWholeExtent();
212                 _extract->Update();
213                 bbSetOutputVOI(_extract->GetOutput());
214                 //JCP
215   */
216         
217                 bbSetOutputIndex( Index );
218                 bbSetOutputSize( Size );
219         } 
220 }
221
222 //------------------------------------------------------
223 void ContourVOI::CreateWidget(wxWindow*  parent)
224 {  
225         bbtkDebugMessageInc("Core",9,"ContourVOI::CreateWidget()"<<std::endl);
226         wxWidgetVOI *mwxwidget = new wxWidgetVOI( parent );
227         bbSetOutputWidget(mwxwidget);
228         bbtkDebugDecTab("Core",9);
229         this->bbSignalOutputModification();
230
231         //Process();
232 }
233
234 //------------------------------------------------------
235 void ContourVOI::bbUserSetDefaultValues()
236 {
237         _img = NULL;
238         _base = NULL;
239 //EED 20Juin2011        _extract =NULL;
240         bbSetInputwxVtkBaseView(NULL);
241         bbSetInputIn(NULL);
242         bbSetOutputWidget(NULL);
243         bbSetOutputVOI(NULL);
244
245         bbSetInputIn(NULL);
246         bbSetInputwxVtkBaseView(NULL);
247
248 }
249
250 //-----------------------------------------------------------------     
251 void ContourVOI::bbUserInitializeProcessing()
252 {
253 }
254         
255 //-----------------------------------------------------------------     
256 void ContourVOI::bbUserFinalizeProcessing()
257 {
258 }
259         
260 //-----------------------------------------------------------------     
261         
262 }
263 // EO namespace bbcreaMaracasVisu