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