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