]> Creatis software - creaContours.git/blob - lib/Interface_Icons_NDimensions/interfSegmentationPanels.cxx
edb257c80ca7721ea6f89964ee2d298c387d9482
[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 =    new wxStaticText(this, wxID_ANY, wxT("Initial Distance"),   wxPoint(5, 5));
137         wxStaticText * sigma =       new wxStaticText(this, wxID_ANY, wxT("Sigma"),              wxPoint(5, 30));
138         wxStaticText * alfa =        new wxStaticText(this, wxID_ANY, wxT("Sigmoid Alfa"),       wxPoint(5, 55));
139         wxStaticText * beta =        new wxStaticText(this, wxID_ANY, wxT("Sigmoid Beta"),       wxPoint(5, 80));
140         wxStaticText * propagation = new wxStaticText(this, wxID_ANY, wxT("Propagation Scaling"),wxPoint(5, 105));
141         wxStaticText * iterations =  new wxStaticText(this, wxID_ANY, wxT("Iterations"),         wxPoint(5, 130));
142         wxStaticText * infStrength = new wxStaticText(this, wxID_ANY, wxT("Inflation Strength"), wxPoint(5, 155));
143
144         //Text Controls
145
146         _distance =      new wxTextCtrl(this, wxID_ANY, wxT("5.0"),  wxPoint(98,5),   wxSize(80, 20), 0, wxDefaultValidator, wxTextCtrlNameStr);
147         _sigma =         new wxTextCtrl(this, wxID_ANY, wxT("1.2"),  wxPoint(98,30),  wxSize(80, 20), 0, wxDefaultValidator, wxTextCtrlNameStr);
148         _alfa =          new wxTextCtrl(this, wxID_ANY, wxT("-1.0"), wxPoint(98,55),  wxSize(80, 20), 0, wxDefaultValidator, wxTextCtrlNameStr);        
149         _beta =          new wxTextCtrl(this, wxID_ANY, wxT("5.0"),  wxPoint(98,80),  wxSize(80, 20), 0, wxDefaultValidator, wxTextCtrlNameStr);        
150         _propagation =   new wxTextCtrl(this, wxID_ANY, wxT("6.0"),  wxPoint(98,105), wxSize(80, 20), 0, wxDefaultValidator, wxTextCtrlNameStr);        
151         _iterations =    new wxTextCtrl(this, wxID_ANY, wxT("800"),  wxPoint(98,130), wxSize(80, 20), 0, wxDefaultValidator, wxTextCtrlNameStr);        
152         _infStrength =   new wxTextCtrl(this, wxID_ANY, wxT("3.0"),  wxPoint(98,155), wxSize(80, 20), 0, wxDefaultValidator, wxTextCtrlNameStr);
153         
154         //El boton
155         wxButton * bot = new wxButton(this, 6, wxT("One Slice"), wxPoint(98, 180), wxSize(70, 25), 0, wxDefaultValidator, wxT("button"));
156
157         //Conexion del boton con su respectivo manejador
158         Connect(6, wxEVT_COMMAND_BUTTON_CLICKED,(wxObjectEventFunction) &interfSegmentationPanelITK::onSegmentationOneSlice);
159         
160         
161 }
162 interfSegmentationPanelITK::~interfSegmentationPanelITK(){
163
164 }
165
166 void interfSegmentationPanelITK::onSegmentationOneSlice( wxCommandEvent& event )
167 {
168         wxString distanc=_distance->GetValue();
169         wxString sigm=_sigma->GetValue();
170         wxString alf=_alfa->GetValue();
171         wxString bet=_beta->GetValue();
172         wxString prop=_propagation->GetValue();
173         wxString iter=_iterations->GetValue();
174         wxString infS=_infStrength->GetValue();
175         
176         interfMainPanel::getInstance()->onSegmentationOneSliceITK(distanc, sigm, alf, bet, prop, iter, infS);
177         
178 }
179 void interfSegmentationPanelITK::onSegmentationAllSlice( wxCommandEvent& event )
180 {
181
182         /*int minZ=_mbarrange->GetStart();
183         int maxZ=_mbarrange->GetEnd();
184
185         int                             isovalue        = _isovalue->GetValue();
186         int                             sampling        = _sampling->GetValue();
187         int method = methodRadiobox->GetSelection();
188
189
190         interfMainPanel::getInstance()->onSegmentationAllSlice(minZ, maxZ, isovalue, sampling, method);*/
191         
192 }
193
194 //------------------------------------------------------------------------------------------------------------
195
196
197 /**
198 ** Begin of the mirror panel
199 **/
200
201 interfMirrorPanel::interfMirrorPanel(wxWindow* parent)
202 : wxPanel(parent, -1, wxDefaultPosition, wxDefaultSize, wxBORDER_SUNKEN)
203 {
204         wxButton *axisShowBtn = new wxButton(this,wxID_ANY,_T("Show Axis"), wxDefaultPosition, wxSize(200,35) );
205         wxButton *axisHideBtn = new wxButton(this,wxID_ANY,_T("Hide Axis"), wxDefaultPosition, wxSize(200,35) );
206         wxButton *mirrorGoBtn = new wxButton(this,wxID_ANY,_T("Mirror Contour"), wxDefaultPosition, wxSize(200,35) );
207         _thickness = new wxSlider(this, -1, 4, 1, 10, wxDefaultPosition, wxDefaultSize, wxSL_HORIZONTAL|wxSL_LABELS, wxDefaultValidator);
208         
209         Connect( axisShowBtn->GetId(), wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &interfMirrorPanel::onAxisShow );
210         Connect( axisHideBtn->GetId(), wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &interfMirrorPanel::onAxisHide ); 
211         Connect( mirrorGoBtn->GetId(), wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &interfMirrorPanel::onMirrorGo ); 
212
213         wxFlexGridSizer * sizer         = new wxFlexGridSizer(1);
214         sizer -> Add( axisShowBtn, 1, wxGROW );
215         sizer -> Add( axisHideBtn, 1, wxGROW );
216         sizer -> Add( new wxStaticText(this,-1,_T(" "))  , 1, wxGROW );
217         sizer -> Add( new wxStaticText(this,-1,_T("Thickness"))  , 1, wxGROW );
218         sizer -> Add( _thickness, 1, wxGROW );
219         sizer -> Add( mirrorGoBtn, 1, wxGROW );
220
221         this->SetSizer( sizer );
222         this->SetAutoLayout( true );
223         this->Layout();
224 }
225
226 interfMirrorPanel::~interfMirrorPanel(){
227 }
228
229 void interfMirrorPanel::onAxisShow(wxCommandEvent& event)
230 {
231         interfMainPanel::getInstance()->onMirrorAxisShow();
232 }
233
234 void interfMirrorPanel::onAxisHide(wxCommandEvent& event)
235 {
236         interfMainPanel::getInstance()->onMirrorAxisHide();
237 }
238
239 void interfMirrorPanel::onMirrorGo(wxCommandEvent& event)
240 {
241         interfMainPanel::getInstance()->onMirror();
242 }
243
244 void interfMirrorPanel::onChangeWidth(wxScrollEvent& event)
245 {
246         int width = _thickness->GetValue();
247         interfMainPanel::getInstance()->onMirrorChangeWidth(width);
248 }
249
250
251
252 /**
253 ** Begin of the threshold panel
254 **/
255 interfThresholdPanel::interfThresholdPanel(wxWindow* parent)
256 : wxPanel(parent, -1, wxDefaultPosition, wxDefaultSize, wxBORDER_SUNKEN)
257 {
258         wxButton *thresholdGoBtn = new wxButton(this,wxID_ANY,_T("Add Fake Color"), wxDefaultPosition, wxSize(200,30) );
259         wxButton *thresholdRemoveBtn = new wxButton(this,wxID_ANY,_T("Remove Fake Color"), wxDefaultPosition, wxSize(200,30) );
260         _interpolationCheckBox = new wxCheckBox(this, -1, _T("Image interpolation") );
261         _interpolationCheckBox->SetValue(true); 
262         _opacity = new wxSlider(this, wxID_ANY, 6, 1, 10, wxDefaultPosition, wxDefaultSize, wxSL_HORIZONTAL|wxSL_LABELS, wxDefaultValidator);
263         _thresholdGo = false;
264
265         double range[2];
266         interfMainPanel::getInstance()->getImageRange(range);
267         
268         int min = floor (range[0]);
269         int max = ceil (range[1]);
270
271         _mBarThreshold  =  new mBarRange(this,70,65);
272         _mBarThreshold->SetMin(0);
273         _mBarThreshold->SetStart(0);
274         _mBarThreshold-> SetOrientation( true );
275         _mBarThreshold-> setActiveStateTo(true);
276         _mBarThreshold-> setVisibleLabels( true );
277         _mBarThreshold-> setDeviceEndMargin(10);
278         _mBarThreshold-> setRepresentedValues( min , max );
279         _mBarThreshold-> setDeviceBlitStart(10,10); 
280         _mBarThreshold-> setIfWithActualDrawed( false );
281         _mBarThreshold-> SetStart( min );
282         _mBarThreshold-> SetEnd( max );  
283         
284         Connect( thresholdGoBtn->GetId(), wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &interfThresholdPanel::onThresholdGo ); 
285         Connect( thresholdRemoveBtn->GetId(), wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &interfThresholdPanel::onThresholdRemove );
286         Connect( _interpolationCheckBox->GetId(), wxEVT_COMMAND_CHECKBOX_CLICKED, (wxObjectEventFunction) &interfThresholdPanel::onThresholdInterpolation );
287
288         wxFlexGridSizer * sizer         = new wxFlexGridSizer(1);
289         sizer -> Add( new wxStaticText(this,-1,_T("Image Threshold"))  , 1, wxGROW );
290         sizer -> Add( _mBarThreshold, 1, wxGROW );
291         sizer -> Add( new wxStaticText(this,-1,_T(" "))  , 1, wxGROW );
292         sizer -> Add( new wxStaticText(this,-1,_T("Opacity Level"))  , 1, wxGROW );
293         sizer -> Add( _opacity, 1, wxGROW );
294         sizer -> Add( new wxStaticText(this,-1,_T(" "))  , 1, wxGROW );
295         sizer -> Add( thresholdGoBtn, 1, wxGROW );
296         sizer -> Add( thresholdRemoveBtn, 1, wxGROW );
297         sizer -> Add( new wxStaticText(this,-1,_T(" "))  , 1, wxGROW );
298         sizer -> Add( _interpolationCheckBox, 1, wxGROW );
299
300         this->SetSizer( sizer );
301         this->SetAutoLayout( true );
302         this->Layout();
303 }
304
305 interfThresholdPanel::~interfThresholdPanel(){
306 }
307
308
309
310 void interfThresholdPanel::onThresholdChange(wxCommandEvent& event)
311 {
312         if (_thresholdGo)
313         {
314                 int minVal = _mBarThreshold->GetStart();
315                 int maxVal = _mBarThreshold->GetEnd();
316
317                 interfMainPanel::getInstance()->onThresholdChange(minVal, maxVal);
318
319                 //std::cout<< "Valor Min: " << minVal << " & Valor Max: " << maxVal  << std::endl;
320         }
321 }
322
323 void interfThresholdPanel::onThresholdGo(wxCommandEvent& event)
324 {
325         if (!_thresholdGo)
326         {
327                 int minVal = _mBarThreshold->GetStart();
328                 int maxVal = _mBarThreshold->GetEnd();
329
330                 interfMainPanel::getInstance()->onThreshold(minVal, maxVal);
331                 _thresholdGo=true;
332         }
333 }
334
335 void interfThresholdPanel::onThresholdRemove(wxCommandEvent& event)
336 {
337         interfMainPanel::getInstance()->onThresholdRemove( );
338         _thresholdGo=false;
339 }
340
341 void interfThresholdPanel::onThresholdStop()
342 {
343         interfMainPanel::getInstance()->onThresholdRemove( );
344         _thresholdGo=false;
345 }
346
347 void interfThresholdPanel::onThresholdInstantChange(int range[])
348 {
349         range[0] = _mBarThreshold->GetStart();
350         range[1] = _mBarThreshold->GetEnd();
351 }
352
353 void interfThresholdPanel::onThresholdInterpolation(wxCommandEvent& event)
354 {
355         interfMainPanel::getInstance()->onThresholdInterpolation(_interpolationCheckBox->GetValue());
356 }
357
358 void interfThresholdPanel::onChangeOpacity(wxScrollEvent& event)
359 {
360         int opacity = _opacity->GetValue();
361         interfMainPanel::getInstance()->onThresholdChangeOpacity(opacity);
362 }
363
364
365 BEGIN_EVENT_TABLE(interfMirrorPanel, wxPanel)
366         EVT_SCROLL(interfMirrorPanel :: onChangeWidth)
367 END_EVENT_TABLE()
368
369 BEGIN_EVENT_TABLE(interfThresholdPanel, wxPanel)
370         EVT_COMMAND(wxID_ANY, wxEVT_TSBAR_START, interfThresholdPanel :: onThresholdChange)
371         EVT_COMMAND(wxID_ANY, wxEVT_TSBAR_END, interfThresholdPanel :: onThresholdChange)
372         EVT_COMMAND(wxID_ANY, wxEVT_TSBAR_MOVED, interfThresholdPanel :: onThresholdChange)     
373         EVT_SCROLL(interfThresholdPanel :: onChangeOpacity)
374 END_EVENT_TABLE()
375
376