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