]> Creatis software - creaContours.git/blob - lib/Interface_Icons_NDimensions/interfSegmentationPanels.cxx
OK
[creaContours.git] / lib / Interface_Icons_NDimensions / interfSegmentationPanels.cxx
1 #include "interfSegmentationPanels.h"
2 #include "interfMainPanel.h"
3
4 interfSegmentationPanelVTK::interfSegmentationPanelVTK(wxWindow * parent)
5 : wxPanel(parent, -1, wxDefaultPosition, wxDefaultSize, wxBORDER_SUNKEN)
6 {
7         int sizeZ = interfMainPanel::getInstance()->GetImageDataSizeZ();
8         //int sizeZ = _theViewPanel->getSceneManager()->GetImageDataSizeZ();
9         double range[2];
10         //_theViewPanel->getSceneManager()->GetImageDataRange(range);
11         interfMainPanel::getInstance()->GetImageDataRange(range);
12
13         wxButton *segmentationOneSliceBtn   = new wxButton(this,-1,_T("Current slice"), wxDefaultPosition, wxSize(200,35) );
14         wxButton *segmentationAllSliceBtn   = new wxButton(this,-1,_T("All slices") ,wxDefaultPosition, wxSize(200,35) );
15         _isovalue                           = new wxSlider(this, -1, 40 , (int)(range[0]), (int)(range[1]), wxDefaultPosition, wxSize(200,35), wxSL_HORIZONTAL|wxSL_LABELS, wxDefaultValidator);
16         _sampling                           = new wxSlider(this, -1, 20 , 4, 50, wxDefaultPosition, wxSize(200,35), wxSL_HORIZONTAL|wxSL_LABELS, wxDefaultValidator);
17         wxString lstOptions[3];
18         lstOptions[0]=_T("A");
19         lstOptions[1]=_T("B");
20         lstOptions[2]=_T("C");
21         methodRadiobox                      = new wxRadioBox(this, -1, _T("Method (find ctrl. Points)"), wxDefaultPosition, wxSize(200,45), 3 , lstOptions,  3, wxRA_SPECIFY_COLS);
22         methodRadiobox->SetSelection(2);
23         _staticTextSegmentation             = new wxStaticText(this,-1,_T("    "));
24
25         _mbarrange                          = new mBarRange(this,70, 65);
26         _mbarrange->SetMin(0);
27         _mbarrange->SetStart(0);
28
29         _mbarrange->SetOrientation( true );
30         _mbarrange->setActiveStateTo(true);
31         _mbarrange->setVisibleLabels( true );
32         _mbarrange->setDeviceEndMargin(10);
33         _mbarrange->setRepresentedValues( 0 , sizeZ );
34         _mbarrange->setDeviceBlitStart(10,10); 
35         _mbarrange->setIfWithActualDrawed( false );
36         _mbarrange->SetStart( 0 );
37         _mbarrange->SetEnd( sizeZ );  
38
39         wxFlexGridSizer * sizer             = new wxFlexGridSizer(1);
40         sizer->Add( new wxStaticText(this, -1, _T("Isovalue (Gray level)")), 1, wxGROW );
41         sizer->Add( _isovalue, 1, wxGROW );
42         sizer->Add( methodRadiobox , 1, wxGROW );
43         sizer->Add( new wxStaticText(this, -1 ,_T("Sampling (%)")), 1, wxGROW );
44         sizer->Add( _sampling, 1, wxGROW );
45         sizer->Add( segmentationOneSliceBtn, 1, wxGROW );
46         sizer->Add( new wxStaticText(this, -1, _T(" ")), 1, wxGROW );
47         sizer->Add( _staticTextSegmentation, 1, wxGROW );
48         sizer->Add( segmentationAllSliceBtn, 1, wxGROW );
49         sizer->Add( _mbarrange, 1, wxGROW );
50
51         this->SetSizer( sizer );
52 //              panel->SetSize( sizePanel );
53         this->SetSize( wxDefaultSize );
54         this->SetAutoLayout( true );
55         this->Layout();
56         
57 //_segmentationFrame->SetEventHandler( this );
58         //segmentationOneSliceBtn->SetEventHandler( this );
59         //segmentationAllSliceBtn->SetEventHandler( this );
60         //panel->SetEventHandler(this);
61         Connect( segmentationOneSliceBtn->GetId(), wxEVT_COMMAND_BUTTON_CLICKED, (wxObjectEventFunction) &interfSegmentationPanelVTK::onSegmentationOneSlice); 
62         Connect( segmentationAllSliceBtn->GetId(), wxEVT_COMMAND_BUTTON_CLICKED, (wxObjectEventFunction) &interfSegmentationPanelVTK::onSegmentationAllSlice); 
63 }
64
65
66 interfSegmentationPanelVTK::~interfSegmentationPanelVTK()
67 {
68 }
69
70 /**
71         **      Responds to the events of the buttons, when the same panel is responsible for it. It gets the name
72         **      of the button corresponding to the method that has to be executed,
73         **      it uses attribute eventHandler to call the methods define by the application.
74         **      see setEventHandler(wxEventHandler*)
75         **/
76
77 void  interfSegmentationPanelVTK::onSegmentationPressedITK(wxCommandEvent& event){
78    if(segmentPanelITK == NULL) {
79                 segmentPanelITK = new wxPanel(interfMainPanel::getInstance()->getInfoPanel(), -1, wxDefaultPosition, wxDefaultSize, wxBORDER_STATIC, wxString(_T("")));                 
80
81                 wxFlexGridSizer* flexsizer = new wxFlexGridSizer(1);    
82                 segmentPanelITK->SetSizer(flexsizer, true);
83                 segmentPanelITK->SetAutoLayout( true ); 
84                                 
85                 wxPanel* panel = new wxPanel(this, -1);//contourevent->getSegmentationPanelITK(segmentPanelITK);
86         
87                 wxStaticText* stattext = new wxStaticText(segmentPanelITK, -1, wxString(_T("   Automatic ITK Segmentation   ")), wxDefaultPosition,
88                         wxDefaultSize, wxALIGN_CENTRE|wxBORDER_SIMPLE|wxFULL_REPAINT_ON_RESIZE, wxString(_T("")));
89
90                 flexsizer->Add(stattext, wxALIGN_CENTER | wxALIGN_CENTRE);
91                 flexsizer->Add(panel, wxEXPAND);
92                 segmentPanelITK->Layout();
93    }
94         interfMainPanel::getInstance()->showPanel(segmentPanelITK);
95         //contourevent->showAxis(true);
96         //axisshown = true;
97 }
98
99 void interfSegmentationPanelVTK::onSegmentationOneSlice( wxCommandEvent& event )
100 {
101         int isovalue = _isovalue->GetValue();
102         int sampling = _sampling->GetValue();
103         int method = methodRadiobox->GetSelection();
104         interfMainPanel::getInstance()->onSegmentationOneSlice(isovalue, sampling, method);
105         
106 }
107 void interfSegmentationPanelVTK::onSegmentationAllSlice( wxCommandEvent& event )
108 {
109         int minZ=_mbarrange->GetStart();
110         int maxZ=_mbarrange->GetEnd();
111
112         int isovalue = _isovalue->GetValue();
113         int sampling = _sampling->GetValue();
114         int method   = methodRadiobox->GetSelection();
115
116         interfMainPanel::getInstance()->onSegmentationAllSlice(minZ, maxZ, isovalue, sampling, method); 
117 }
118
119 void interfSegmentationPanelVTK::setLabel(wxString tmpString){
120         _staticTextSegmentation->SetLabel(tmpString);
121 }
122 /**
123 ** start of new implementation
124 **      interfSegmentationPanelITK
125 **/
126 interfSegmentationPanelITK::interfSegmentationPanelITK(wxWindow * parent)
127 : wxPanel(parent, -1, wxDefaultPosition, wxDefaultSize, wxBORDER_SUNKEN)
128 {
129 //      int sizeZ = interfMainPanel::getInstance()->GetImageDataSizeZ();
130         //int sizeZ = _theViewPanel->getSceneManager()->GetImageDataSizeZ();
131         double range[2];
132         //_theViewPanel->getSceneManager()->GetImageDataRange(range);
133         interfMainPanel::getInstance()->GetImageDataRange(range);
134         
135         //The labels
136         //wxStaticText * distance =    
137         new wxStaticText(this, wxID_ANY, wxT("Initial Distance"),   wxPoint(5, 5));
138         //wxStaticText * sigma =       
139         new wxStaticText(this, wxID_ANY, wxT("Sigma"),              wxPoint(5, 30));
140         //wxStaticText * alfa =        
141         new wxStaticText(this, wxID_ANY, wxT("Sigmoid Alfa"),       wxPoint(5, 55));
142         //wxStaticText * beta =        
143         new wxStaticText(this, wxID_ANY, wxT("Sigmoid Beta"),       wxPoint(5, 80));
144         //wxStaticText * propagation = 
145         new wxStaticText(this, wxID_ANY, wxT("Propagation Scaling"),wxPoint(5, 105));
146         //wxStaticText * iterations =  
147         new wxStaticText(this, wxID_ANY, wxT("Iterations"),         wxPoint(5, 130));
148         //wxStaticText * infStrength = 
149         new wxStaticText(this, wxID_ANY, wxT("Inflation Strength"), wxPoint(5, 155));
150
151         //Text Controls
152
153         _distance =      new wxTextCtrl(this, wxID_ANY, wxT("5.0"),  wxPoint(98,5),   wxSize(80, 20), 0, wxDefaultValidator, wxTextCtrlNameStr);
154         _sigma =         new wxTextCtrl(this, wxID_ANY, wxT("1.2"),  wxPoint(98,30),  wxSize(80, 20), 0, wxDefaultValidator, wxTextCtrlNameStr);
155         _alfa =          new wxTextCtrl(this, wxID_ANY, wxT("-1.0"), wxPoint(98,55),  wxSize(80, 20), 0, wxDefaultValidator, wxTextCtrlNameStr);        
156         _beta =          new wxTextCtrl(this, wxID_ANY, wxT("5.0"),  wxPoint(98,80),  wxSize(80, 20), 0, wxDefaultValidator, wxTextCtrlNameStr);        
157         _propagation =   new wxTextCtrl(this, wxID_ANY, wxT("6.0"),  wxPoint(98,105), wxSize(80, 20), 0, wxDefaultValidator, wxTextCtrlNameStr);        
158         _iterations =    new wxTextCtrl(this, wxID_ANY, wxT("800"),  wxPoint(98,130), wxSize(80, 20), 0, wxDefaultValidator, wxTextCtrlNameStr);        
159         _infStrength =   new wxTextCtrl(this, wxID_ANY, wxT("3.0"),  wxPoint(98,155), wxSize(80, 20), 0, wxDefaultValidator, wxTextCtrlNameStr);
160         
161         //El boton
162         //wxButton * bot = 
163         new wxButton(this, 6, wxT("One Slice"), wxPoint(98, 180), wxSize(70, 25), 0, wxDefaultValidator, wxT("button"));
164
165         //Conexion del boton con su respectivo manejador
166         Connect(6, wxEVT_COMMAND_BUTTON_CLICKED,(wxObjectEventFunction) &interfSegmentationPanelITK::onSegmentationOneSlice);
167         
168         
169 }
170 interfSegmentationPanelITK::~interfSegmentationPanelITK(){
171
172 }
173
174 void interfSegmentationPanelITK::onSegmentationOneSlice( wxCommandEvent& event )
175 {
176         wxString distanc=_distance->GetValue();
177         wxString sigm=_sigma->GetValue();
178         wxString alf=_alfa->GetValue();
179         wxString bet=_beta->GetValue();
180         wxString prop=_propagation->GetValue();
181         wxString iter=_iterations->GetValue();
182         wxString infS=_infStrength->GetValue();
183         
184         interfMainPanel::getInstance()->onSegmentationOneSliceITK(distanc, sigm, alf, bet, prop, iter, infS);
185         
186 }
187 void interfSegmentationPanelITK::onSegmentationAllSlice( wxCommandEvent& event )
188 {
189
190         /*int minZ=_mbarrange->GetStart();
191         int maxZ=_mbarrange->GetEnd();
192
193         int                             isovalue        = _isovalue->GetValue();
194         int                             sampling        = _sampling->GetValue();
195         int method = methodRadiobox->GetSelection();
196
197
198         interfMainPanel::getInstance()->onSegmentationAllSlice(minZ, maxZ, isovalue, sampling, method);*/
199         
200 }
201
202 //------------------------------------------------------------------------------------------------------------
203
204
205 /**
206 ** Begin of the mirror panel
207 **/
208
209 interfMirrorPanel::interfMirrorPanel(wxWindow* parent)
210 : wxPanel(parent, -1, wxDefaultPosition, wxDefaultSize, wxBORDER_SUNKEN)
211 {
212         wxButton *axisShowBtn = new wxButton(this,wxID_ANY,_T("Show Axis"), wxDefaultPosition, wxSize(200,35) );
213         wxButton *axisHideBtn = new wxButton(this,wxID_ANY,_T("Hide Axis"), wxDefaultPosition, wxSize(200,35) );
214         wxButton *mirrorGoBtn = new wxButton(this,wxID_ANY,_T("Mirror Contour"), wxDefaultPosition, wxSize(200,35) );
215         _thickness = new wxSlider(this, -1, 4, 1, 10, wxDefaultPosition, wxDefaultSize, wxSL_HORIZONTAL|wxSL_LABELS, wxDefaultValidator);
216         
217         Connect( axisShowBtn->GetId(), wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &interfMirrorPanel::onAxisShow );
218         Connect( axisHideBtn->GetId(), wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &interfMirrorPanel::onAxisHide ); 
219         Connect( mirrorGoBtn->GetId(), wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &interfMirrorPanel::onMirrorGo ); 
220
221         wxFlexGridSizer * sizer         = new wxFlexGridSizer(1);
222         sizer -> Add( axisShowBtn, 1, wxGROW );
223         sizer -> Add( axisHideBtn, 1, wxGROW );
224         sizer -> Add( new wxStaticText(this,-1,_T(" "))  , 1, wxGROW );
225         sizer -> Add( new wxStaticText(this,-1,_T("Thickness"))  , 1, wxGROW );
226         sizer -> Add( _thickness, 1, wxGROW );
227         sizer -> Add( mirrorGoBtn, 1, wxGROW );
228
229         this->SetSizer( sizer );
230         this->SetAutoLayout( true );
231         this->Layout();
232 }
233
234 interfMirrorPanel::~interfMirrorPanel(){
235 }
236
237 void interfMirrorPanel::onAxisShow(wxCommandEvent& event)
238 {
239         interfMainPanel::getInstance()->onMirrorAxisShow();
240 }
241
242 void interfMirrorPanel::onAxisHide(wxCommandEvent& event)
243 {
244         interfMainPanel::getInstance()->onMirrorAxisHide();
245 }
246
247 void interfMirrorPanel::onMirrorGo(wxCommandEvent& event)
248 {
249         interfMainPanel::getInstance()->onMirror();
250 }
251
252 void interfMirrorPanel::onChangeWidth(wxScrollEvent& event)
253 {
254         int width = _thickness->GetValue();
255         interfMainPanel::getInstance()->onMirrorChangeWidth(width);
256 }
257
258
259
260 /**
261 ** Begin of the threshold panel
262 **/
263 interfThresholdPanel::interfThresholdPanel(wxWindow* parent)
264 : wxPanel(parent, -1, wxDefaultPosition, wxDefaultSize, wxBORDER_SUNKEN)
265 {
266         wxButton *thresholdGoBtn = new wxButton(this,wxID_ANY,_T("Add Fake Color"), wxDefaultPosition, wxSize(200,30) );
267         wxButton *thresholdRemoveBtn = new wxButton(this,wxID_ANY,_T("Remove Fake Color"), wxDefaultPosition, wxSize(200,30) );
268         _interpolationCheckBox = new wxCheckBox(this, -1, _T("Image interpolation") );
269         _interpolationCheckBox->SetValue(true); 
270         _opacity = new wxSlider(this, wxID_ANY, 6, 1, 10, wxDefaultPosition, wxDefaultSize, wxSL_HORIZONTAL|wxSL_LABELS, wxDefaultValidator);
271         _thresholdGo = false;
272
273         double range[2];
274         interfMainPanel::getInstance()->getImageRange(range);
275         
276         int min = (int)floor (range[0]);
277         int max = (int)ceil (range[1]);
278
279         _mBarThreshold  =  new mBarRange(this,70,65);
280         _mBarThreshold->SetMin(0);
281         _mBarThreshold->SetStart(0);
282         _mBarThreshold-> SetOrientation( true );
283         _mBarThreshold-> setActiveStateTo(true);
284         _mBarThreshold-> setVisibleLabels( true );
285         _mBarThreshold-> setDeviceEndMargin(10);
286         _mBarThreshold-> setRepresentedValues( min , max );
287         _mBarThreshold-> setDeviceBlitStart(10,10); 
288         _mBarThreshold-> setIfWithActualDrawed( false );
289         _mBarThreshold-> SetStart( min );
290         _mBarThreshold-> SetEnd( max );  
291         
292         Connect( thresholdGoBtn->GetId(), wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &interfThresholdPanel::onThresholdGo ); 
293         Connect( thresholdRemoveBtn->GetId(), wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &interfThresholdPanel::onThresholdRemove );
294         Connect( _interpolationCheckBox->GetId(), wxEVT_COMMAND_CHECKBOX_CLICKED, (wxObjectEventFunction) &interfThresholdPanel::onThresholdInterpolation );
295
296         wxFlexGridSizer * sizer         = new wxFlexGridSizer(1);
297         sizer -> Add( new wxStaticText(this,-1,_T("Image Threshold"))  , 1, wxGROW );
298         sizer -> Add( _mBarThreshold, 1, wxGROW );
299         sizer -> Add( new wxStaticText(this,-1,_T(" "))  , 1, wxGROW );
300         sizer -> Add( new wxStaticText(this,-1,_T("Opacity Level"))  , 1, wxGROW );
301         sizer -> Add( _opacity, 1, wxGROW );
302         sizer -> Add( new wxStaticText(this,-1,_T(" "))  , 1, wxGROW );
303         sizer -> Add( thresholdGoBtn, 1, wxGROW );
304         sizer -> Add( thresholdRemoveBtn, 1, wxGROW );
305         sizer -> Add( new wxStaticText(this,-1,_T(" "))  , 1, wxGROW );
306         sizer -> Add( _interpolationCheckBox, 1, wxGROW );
307
308         this->SetSizer( sizer );
309         this->SetAutoLayout( true );
310         this->Layout();
311 }
312
313 interfThresholdPanel::~interfThresholdPanel(){
314 }
315
316
317
318 void interfThresholdPanel::onThresholdChange(wxCommandEvent& event)
319 {
320         if (_thresholdGo)
321         {
322                 int minVal = _mBarThreshold->GetStart();
323                 int maxVal = _mBarThreshold->GetEnd();
324
325                 interfMainPanel::getInstance()->onThresholdChange(minVal, maxVal);
326
327                 //std::cout<< "Valor Min: " << minVal << " & Valor Max: " << maxVal  << std::endl;
328         }
329 }
330
331 void interfThresholdPanel::onThresholdGo(wxCommandEvent& event)
332 {
333         if (!_thresholdGo)
334         {
335                 int minVal = _mBarThreshold->GetStart();
336                 int maxVal = _mBarThreshold->GetEnd();
337
338                 interfMainPanel::getInstance()->onThreshold(minVal, maxVal);
339                 _thresholdGo=true;
340         }
341 }
342
343 void interfThresholdPanel::onThresholdRemove(wxCommandEvent& event)
344 {
345         interfMainPanel::getInstance()->onThresholdRemove( );
346         _thresholdGo=false;
347 }
348
349 void interfThresholdPanel::onThresholdStop()
350 {
351         interfMainPanel::getInstance()->onThresholdRemove( );
352         _thresholdGo=false;
353 }
354
355 void interfThresholdPanel::onThresholdInstantChange(int range[])
356 {
357         range[0] = _mBarThreshold->GetStart();
358         range[1] = _mBarThreshold->GetEnd();
359 }
360
361 void interfThresholdPanel::onThresholdInterpolation(wxCommandEvent& event)
362 {
363         interfMainPanel::getInstance()->onThresholdInterpolation(_interpolationCheckBox->GetValue());
364 }
365
366 void interfThresholdPanel::onChangeOpacity(wxScrollEvent& event)
367 {
368         int opacity = _opacity->GetValue();
369         interfMainPanel::getInstance()->onThresholdChangeOpacity(opacity);
370 }
371
372
373 BEGIN_EVENT_TABLE(interfMirrorPanel, wxPanel)
374         EVT_SCROLL(interfMirrorPanel :: onChangeWidth)
375 END_EVENT_TABLE()
376
377 BEGIN_EVENT_TABLE(interfThresholdPanel, wxPanel)
378         EVT_COMMAND(wxID_ANY, wxEVT_TSBAR_START, interfThresholdPanel :: onThresholdChange)
379         EVT_COMMAND(wxID_ANY, wxEVT_TSBAR_END, interfThresholdPanel :: onThresholdChange)
380         EVT_COMMAND(wxID_ANY, wxEVT_TSBAR_MOVED, interfThresholdPanel :: onThresholdChange)     
381         EVT_SCROLL(interfThresholdPanel :: onChangeOpacity)
382 END_EVENT_TABLE()
383
384