]> Creatis software - creaContours.git/blob - lib/Interface_Icons_NDimensions/interfSegmentationPanels.cxx
46fb279043e0fdc75f50db7f168d8eabe252f071
[creaContours.git] / lib / Interface_Icons_NDimensions / interfSegmentationPanels.cxx
1 /*# ---------------------------------------------------------------------
2 #
3 # Copyright (c) CREATIS (Centre de Recherche en Acquisition et Traitement de l'Image
4 #                        pour la Sant�)
5 # Authors : Eduardo Davila, Frederic Cervenansky, Claire Mouton
6 # Previous Authors : Laurent Guigues, Jean-Pierre Roux
7 # CreaTools website : www.creatis.insa-lyon.fr/site/fr/creatools_accueil
8 #
9 #  This software is governed by the CeCILL-B license under French law and
10 #  abiding by the rules of distribution of free software. You can  use,
11 #  modify and/ or redistribute the software under the terms of the CeCILL-B
12 #  license as circulated by CEA, CNRS and INRIA at the following URL
13 #  http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
14 #  or in the file LICENSE.txt.
15 #
16 #  As a counterpart to the access to the source code and  rights to copy,
17 #  modify and redistribute granted by the license, users are provided only
18 #  with a limited warranty  and the software's author,  the holder of the
19 #  economic rights,  and the successive licensors  have only  limited
20 #  liability.
21 #
22 #  The fact that you are presently reading this means that you have had
23 #  knowledge of the CeCILL-B license and that you accept its terms.
24 # ------------------------------------------------------------------------ */
25
26 #include "interfSegmentationPanels.h"
27 #include "interfMainPanel.h"
28
29 interfSegmentationPanelVTK::interfSegmentationPanelVTK(wxWindow * parent)
30 : wxPanel(parent, -1, wxDefaultPosition, wxDefaultSize, wxBORDER_SUNKEN)
31 {
32         int sizeZ = interfMainPanel::getInstance()->GetImageDataSizeZ();
33         double range[2];
34         interfMainPanel::getInstance()->getImageRange(range);
35         int min = (int)floor (range[0]);
36         int max = (int)ceil (range[1]);
37
38         wxButton *segmentationOneSliceBtn   = new wxButton(this,-1,_T("Current slice"), wxDefaultPosition, wxSize(200,35) );
39         wxButton *segmentationAllSliceBtn   = new wxButton(this,-1,_T("All slices") ,wxDefaultPosition, wxSize(200,35) );
40         _isovalue                           = new wxSlider(this, -1, 40 , min, max, wxDefaultPosition, wxDefaultSize, wxSL_HORIZONTAL|wxSL_LABELS, wxDefaultValidator);
41         _sampling                           = new wxSlider(this, -1, 20 , 4, 50, wxDefaultPosition,  wxDefaultSize, wxSL_HORIZONTAL|wxSL_LABELS, wxDefaultValidator);
42         wxString lstOptions[3];
43         lstOptions[0]=_T("A");
44         lstOptions[1]=_T("B");
45         lstOptions[2]=_T("C");
46         methodRadiobox                      = new wxRadioBox(this, -1, _T("Method (find ctrl. Points)"), wxDefaultPosition, wxSize(200,45), 3 , lstOptions,  3, wxRA_SPECIFY_COLS);
47         methodRadiobox->SetSelection(2);
48         _staticTextSegmentation             = new wxStaticText(this,-1,_T("    "));
49         _mbarrange                          = new mBarRange(this,70, 65);
50         _mbarrange->SetMin(0);
51         _mbarrange->SetStart(0);
52         _mbarrange->SetOrientation( true );
53         _mbarrange->setActiveStateTo(true);
54         _mbarrange->setVisibleLabels( true );
55         _mbarrange->setDeviceEndMargin(10);
56         _mbarrange->setRepresentedValues( 0 , sizeZ );
57         _mbarrange->setDeviceBlitStart(10,10); 
58         _mbarrange->setIfWithActualDrawed( false );
59         _mbarrange->SetStart( 0 );
60         _mbarrange->SetEnd( sizeZ );  
61         wxFlexGridSizer * sizer             = new wxFlexGridSizer(20,1,0,0);
62         sizer->Add( new wxStaticText(this, -1, _T("Isovalue (Gray level)")), 1, wxGROW );
63         sizer->Add( _isovalue, 1, wxGROW );
64         sizer->Add( methodRadiobox , 1, wxGROW );
65         sizer->Add( new wxStaticText(this, -1 ,_T("Sampling (%)")), 1, wxGROW );
66         sizer->Add( _sampling, 1, wxGROW );
67         sizer->Add( segmentationOneSliceBtn, 1, wxGROW );
68         sizer->Add( new wxStaticText(this, -1, _T(" ")), 1, wxGROW );
69         sizer->Add( _staticTextSegmentation, 1, wxGROW );
70         sizer->Add( segmentationAllSliceBtn, 1, wxGROW );
71         sizer->Add( _mbarrange, 1, wxGROW );
72         this->SetSizer( sizer );
73         this->SetAutoLayout( true );
74         this->Layout();
75 //_segmentationFrame->SetEventHandler( this );
76         //segmentationOneSliceBtn->SetEventHandler( this );
77         //segmentationAllSliceBtn->SetEventHandler( this );
78         //panel->SetEventHandler(this);
79         Connect( segmentationOneSliceBtn->GetId(), wxEVT_COMMAND_BUTTON_CLICKED, (wxObjectEventFunction) &interfSegmentationPanelVTK::onSegmentationOneSlice); 
80         Connect( segmentationAllSliceBtn->GetId(), wxEVT_COMMAND_BUTTON_CLICKED, (wxObjectEventFunction) &interfSegmentationPanelVTK::onSegmentationAllSlice); 
81 }
82
83 interfSegmentationPanelVTK::~interfSegmentationPanelVTK()
84 {
85 }
86
87 /**
88         **      Responds to the events of the buttons, when the same panel is responsible for it. It gets the name
89         **      of the button corresponding to the method that has to be executed,
90         **      it uses attribute eventHandler to call the methods define by the application.
91         **      see setEventHandler(wxEventHandler*)
92         **/
93
94 void  interfSegmentationPanelVTK::onSegmentationPressedITK(wxCommandEvent& event){
95    if(segmentPanelITK == NULL) {
96                 segmentPanelITK = new wxPanel(interfMainPanel::getInstance()->getInfoPanel(), -1, wxDefaultPosition, wxDefaultSize, wxBORDER_STATIC, wxString(_T("")));                 
97
98                 wxFlexGridSizer* flexsizer = new wxFlexGridSizer(1);    
99                 segmentPanelITK->SetSizer(flexsizer, true);
100                 segmentPanelITK->SetAutoLayout( true ); 
101                 wxPanel* panel = new wxPanel(this, -1);//contourevent->getSegmentationPanelITK(segmentPanelITK);
102                 wxStaticText* stattext = new wxStaticText(segmentPanelITK, -1, wxString(_T("   Automatic ITK Segmentation   ")), wxDefaultPosition,
103                         wxDefaultSize, wxALIGN_CENTRE|wxBORDER_SIMPLE|wxFULL_REPAINT_ON_RESIZE, wxString(_T("")));
104
105                 flexsizer->Add(stattext, wxALIGN_CENTER | wxALIGN_CENTRE);
106                 flexsizer->Add(panel, wxEXPAND);
107                 segmentPanelITK->Layout();
108    }
109         interfMainPanel::getInstance()->showPanel(segmentPanelITK);
110         //contourevent->showAxis(true);
111         //axisshown = true;
112 }
113
114 void interfSegmentationPanelVTK::onSegmentationOneSlice( wxCommandEvent& event )
115 {
116         int isovalue = _isovalue->GetValue();
117         int sampling = _sampling->GetValue();
118         int method = methodRadiobox->GetSelection();
119         interfMainPanel::getInstance()->onSegmentationOneSlice(isovalue, sampling, method);
120 }
121
122 void interfSegmentationPanelVTK::onSegmentationAllSlice( wxCommandEvent& event )
123 {
124         int minZ=_mbarrange->GetStart();
125         int maxZ=_mbarrange->GetEnd();
126         int isovalue = _isovalue->GetValue();
127         int sampling = _sampling->GetValue();
128         int method   = methodRadiobox->GetSelection();
129         interfMainPanel::getInstance()->onSegmentationAllSlice(minZ, maxZ, isovalue, sampling, method); 
130 }
131
132 void interfSegmentationPanelVTK::setLabel(wxString tmpString)
133 {
134         _staticTextSegmentation->SetLabel(tmpString);
135 }
136
137 /**
138 ** start of new implementation
139 **      interfSegmentationPanelITK
140 **/
141 interfSegmentationPanelITK::interfSegmentationPanelITK(wxWindow * parent)
142 : wxPanel(parent, -1, wxDefaultPosition, wxDefaultSize, wxBORDER_SUNKEN)
143 {
144         double range[2];
145         interfMainPanel::getInstance()->getImageRange(range);
146 //      int min = (int)floor (range[0]);
147 //      int max = (int)ceil (range[1]);
148         //The labels
149         //wxStaticText * distance =    
150         new wxStaticText(this, wxID_ANY, wxT("Initial Distance"),   wxPoint(5, 5));
151         //wxStaticText * sigma =       
152         new wxStaticText(this, wxID_ANY, wxT("Sigma"),              wxPoint(5, 30));
153         //wxStaticText * alfa =        
154         new wxStaticText(this, wxID_ANY, wxT("Sigmoid Alfa"),       wxPoint(5, 55));
155         //wxStaticText * beta =        
156         new wxStaticText(this, wxID_ANY, wxT("Sigmoid Beta"),       wxPoint(5, 80));
157         //wxStaticText * propagation = 
158         new wxStaticText(this, wxID_ANY, wxT("Propagation Scaling"),wxPoint(5, 105));
159         //wxStaticText * iterations =  
160         new wxStaticText(this, wxID_ANY, wxT("Iterations"),         wxPoint(5, 130));
161         //wxStaticText * infStrength = 
162         new wxStaticText(this, wxID_ANY, wxT("Inflation Strength"), wxPoint(5, 155));
163         //Text Controls
164         _distance =      new wxTextCtrl(this, wxID_ANY, wxT("5.0"),  wxPoint(98,5),   wxSize(80, 20), 0, wxDefaultValidator, wxTextCtrlNameStr);
165         _sigma =         new wxTextCtrl(this, wxID_ANY, wxT("1.2"),  wxPoint(98,30),  wxSize(80, 20), 0, wxDefaultValidator, wxTextCtrlNameStr);
166         _alfa =          new wxTextCtrl(this, wxID_ANY, wxT("-1.0"), wxPoint(98,55),  wxSize(80, 20), 0, wxDefaultValidator, wxTextCtrlNameStr);        
167         _beta =          new wxTextCtrl(this, wxID_ANY, wxT("5.0"),  wxPoint(98,80),  wxSize(80, 20), 0, wxDefaultValidator, wxTextCtrlNameStr);        
168         _propagation =   new wxTextCtrl(this, wxID_ANY, wxT("6.0"),  wxPoint(98,105), wxSize(80, 20), 0, wxDefaultValidator, wxTextCtrlNameStr);        
169         _iterations =    new wxTextCtrl(this, wxID_ANY, wxT("800"),  wxPoint(98,130), wxSize(80, 20), 0, wxDefaultValidator, wxTextCtrlNameStr);        
170         _infStrength =   new wxTextCtrl(this, wxID_ANY, wxT("3.0"),  wxPoint(98,155), wxSize(80, 20), 0, wxDefaultValidator, wxTextCtrlNameStr);
171         //El boton
172         //wxButton * bot = 
173         new wxButton(this, 6, wxT("One Slice"), wxPoint(98, 180), wxSize(70, 25), 0, wxDefaultValidator, wxT("button"));
174         //Conexion del boton con su respectivo manejador
175         Connect(6, wxEVT_COMMAND_BUTTON_CLICKED,(wxObjectEventFunction) &interfSegmentationPanelITK::onSegmentationOneSlice);
176 }
177
178 interfSegmentationPanelITK::~interfSegmentationPanelITK()
179 {
180 }
181
182 void interfSegmentationPanelITK::onSegmentationOneSlice( wxCommandEvent& event )
183 {
184         wxString distanc        = _distance->GetValue();
185         wxString sigm           = _sigma->GetValue();
186         wxString alf            = _alfa->GetValue();
187         wxString bet            = _beta->GetValue();
188         wxString prop           = _propagation->GetValue();
189         wxString iter           = _iterations->GetValue();
190         wxString infS           = _infStrength->GetValue();     
191         interfMainPanel::getInstance()->onSegmentationOneSliceITK(distanc, sigm, alf, bet, prop, iter, infS);
192 }
193
194 void interfSegmentationPanelITK::onSegmentationAllSlice( wxCommandEvent& event )
195 {
196         /*int minZ=_mbarrange->GetStart();
197         int maxZ=_mbarrange->GetEnd();
198         int                             isovalue        = _isovalue->GetValue();
199         int                             sampling        = _sampling->GetValue();
200         int method = methodRadiobox->GetSelection();
201         interfMainPanel::getInstance()->onSegmentationAllSlice(minZ, maxZ, isovalue, sampling, method);*/
202 }
203
204 //------------------------------------------------------------------------------------------------------------
205
206
207 /**
208 ** Begin of the mirror panel
209 **/
210
211 interfMirrorPanel::interfMirrorPanel(wxWindow* parent)
212 : wxPanel(parent, -1, wxDefaultPosition, wxDefaultSize, wxBORDER_SUNKEN)
213 {
214         _axisStatus = true;
215         wxButton *axisShowBtn = new wxButton(this,wxID_ANY,_T("Show/Hide Axis"), wxDefaultPosition, wxSize(200,35) );
216         wxButton *mirrorGoBtn = new wxButton(this,wxID_ANY,_T("Mirror Contour"), wxDefaultPosition, wxSize(200,35) );
217         _thickness = new wxSlider(this, -1, 4, 1, 10, wxDefaultPosition, wxDefaultSize, wxSL_HORIZONTAL|wxSL_LABELS, wxDefaultValidator);
218         Connect( axisShowBtn->GetId(), wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &interfMirrorPanel::onAxisShow );
219         Connect( mirrorGoBtn->GetId(), wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &interfMirrorPanel::onMirrorGo ); 
220         wxFlexGridSizer * sizer         = new wxFlexGridSizer(20,1,0,0);
221         sizer -> Add( axisShowBtn, 1, wxGROW );
222         sizer -> Add( new wxStaticText(this,-1,_T(" "))  , 1, wxGROW );
223         sizer -> Add( new wxStaticText(this,-1,_T("Thickness"))  , 1, wxGROW );
224         sizer -> Add( _thickness, 1, wxGROW );
225         sizer -> Add( mirrorGoBtn, 1, wxGROW );
226         this->SetSizer( sizer );
227         this->SetAutoLayout( true );
228         this->Layout();
229 }
230
231 interfMirrorPanel::~interfMirrorPanel()
232 {
233 }
234
235 void interfMirrorPanel::onAxisShow(wxCommandEvent& event)
236 {
237         if (!_axisStatus)
238         {
239                 interfMainPanel::getInstance()->onMirrorAxisShow();
240                 _axisStatus=true;
241         } else {        
242                 interfMainPanel::getInstance()->onMirrorAxisHide();
243                 _axisStatus=false;              
244         }
245 }
246
247 void interfMirrorPanel::onMirrorGo(wxCommandEvent& event)
248 {
249         if (_axisStatus)
250         {
251                 interfMainPanel::getInstance()->onMirror();
252         }
253 }
254
255 void interfMirrorPanel::onChangeWidth(wxScrollEvent& event)
256 {
257         int width = _thickness->GetValue();
258         interfMainPanel::getInstance()->onMirrorChangeWidth(width);
259 }
260
261
262 BEGIN_EVENT_TABLE(interfMirrorPanel, wxPanel)
263 EVT_SCROLL(interfMirrorPanel :: onChangeWidth)
264 END_EVENT_TABLE()
265
266
267 //////////////////////////////////////////////////////////////
268
269 interfTestPanel::interfTestPanel(wxWindow* parent)
270 : wxPanel(parent, -1, wxDefaultPosition, wxDefaultSize, wxBORDER_SUNKEN)
271 {
272         wxButton *button1 = new wxButton(this,wxID_ANY,_T("Button 1"), wxDefaultPosition, wxSize(200,35) );
273         wxButton *button2 = new wxButton(this,wxID_ANY,_T("Button 2"), wxDefaultPosition, wxSize(200,35) );     
274         Connect( button1->GetId(), wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &interfTestPanel::onButton1Pressed );
275         Connect( button2->GetId(), wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &interfTestPanel::onButton2Pressed ); 
276         wxFlexGridSizer * sizer         = new wxFlexGridSizer(20);
277         sizer -> Add( button1, 1, wxGROW );
278         sizer -> Add( button2, 1, wxGROW );
279         this->SetSizer( sizer );
280         this->SetAutoLayout( true );
281         this->Layout();
282 }
283
284 interfTestPanel::~interfTestPanel(){
285 }
286
287 void interfTestPanel::onButton1Pressed(wxCommandEvent& event)
288 {
289         std::cout << "Button 1 has been pressed" << std::endl;
290 }
291
292 void interfTestPanel::onButton2Pressed(wxCommandEvent& event)
293 {
294         std::cout << "Button 2 has been pressed" << std::endl;
295 }
296
297
298
299