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