]> Creatis software - creaContours.git/blob - lib/Interface_Icons_NDimensions/interfMainPanel.cxx
TOTO : fix deprecated
[creaContours.git] / lib / Interface_Icons_NDimensions / interfMainPanel.cxx
1 #include "interfMainPanel.h"
2
3
4 interfMainPanel* interfMainPanel::interfmainpanel=NULL;
5 wxFrame* interfMainPanel::_newframe=NULL;
6
7 interfMainPanel::interfMainPanel(wxWindow * parent, int sizex, int sizey, wxEvtHandler * evtHandler, std::string datadir)
8 : wxPanel(parent, -1, wxDefaultPosition, wxSize(sizex, sizey), wxBORDER_SUNKEN)
9 {
10
11         PANEL                                   = "New Contour";
12         PANEL1                                  = "I/O";
13         PANEL2                                  = "Edit";
14         PANEL3                                  = "Delete";
15         PANEL4                                  = "Contour Tools";
16         PANEL5                                  = "Segmentation";
17 //EED 07/07/2010
18         PANEL6                                  = "Image Tools";
19
20         segmentPanel                    = NULL;
21         segmentPanelITK                 = NULL;
22         configPanel                             = NULL;
23         spreadPanel                             = NULL;
24         infoWin                                 = NULL;
25         infoPanel                               = NULL;
26         infoPanelMask                   = NULL;
27         informationPanel                = NULL;
28         mirrorPanel                             = NULL;
29         thresholdPanel                  = NULL;
30         colorImageLayerPanel    = NULL;
31         currentWindow                   = NULL;
32         testPanel                               = NULL;
33
34 //CMRU 17-08-09 ------------------------------------------------------------------
35         infoPanelCalibration = NULL;
36         panelAux = NULL;
37 //--------------------------------------------------------------------------------
38         splitterwindow = new wxSplitterWindow(this,-1, wxDefaultPosition, wxSize(sizex, sizey), wxSP_3DSASH, wxString(_T("")));
39
40         splitterwindow->SetMinimumPaneSize( 10 );
41         sizey = sizey/8;
42
43         wxPanel* toolpanel = new wxPanel(splitterwindow, -1, wxDefaultPosition, wxDefaultSize, wxBORDER_DOUBLE, wxString(_T("")));
44
45         wxFlexGridSizer* flexsizer = new wxFlexGridSizer(6,2,1,1);
46         toolpanel->SetSizer(flexsizer, true);
47         toolpanel->SetAutoLayout( true );
48
49         wxButton* b = getButton(toolpanel);
50         b->SetClientData(&PANEL);
51         wxButton* b1 = getButton(toolpanel);
52         b1->SetClientData(&PANEL1);
53         wxButton* b2 = getButton(toolpanel);
54         b2->SetClientData(&PANEL2);
55         wxButton* b3 = getButton(toolpanel);
56         b3->SetClientData(&PANEL3);
57         wxButton* b4 = getButton(toolpanel);
58         b4->SetClientData(&PANEL4);
59         wxButton* b5 = getButton(toolpanel);
60         b5->SetClientData(&PANEL5);
61 //EED 07/07/2010
62         wxButton* b6 = getButton(toolpanel);
63         b6->SetClientData(&PANEL6);
64
65
66         wxPanel* mentex  = new wxPanel(toolpanel, -1, wxDefaultPosition, wxDefaultSize, wxBORDER_NONE, wxString(_T("")));
67         wxPanel* mentex1 = new wxPanel(toolpanel, -1, wxDefaultPosition, wxDefaultSize, wxBORDER_NONE, wxString(_T("")));
68         wxPanel* mentex2 = new wxPanel(toolpanel, -1, wxDefaultPosition, wxDefaultSize, wxBORDER_NONE, wxString(_T("")));
69         wxPanel* mentex3 = new wxPanel(toolpanel, -1, wxDefaultPosition, wxDefaultSize, wxBORDER_NONE, wxString(_T("")));
70         wxPanel* mentex4 = new wxPanel(toolpanel, -1, wxDefaultPosition, wxDefaultSize, wxBORDER_NONE, wxString(_T("")));
71         wxPanel* mentex5 = new wxPanel(toolpanel, -1, wxDefaultPosition, wxDefaultSize, wxBORDER_NONE, wxString(_T("")));
72 //EED 07/07/2010
73         wxPanel* mentex6 = new wxPanel(toolpanel, -1, wxDefaultPosition, wxDefaultSize, wxBORDER_NONE, wxString(_T("")));
74
75         menubar  = new interfNewContourMenu  (mentex,  sizex, sizey, evtHandler, datadir);
76         menubar1 = new interfIOMenu          (mentex1, sizex, sizey, evtHandler, datadir);
77         menubar2 = new interfEditMenu        (mentex2, sizex, sizey, evtHandler, datadir);
78         menubar3 = new interfDeleteMenu      (mentex3, sizex, sizey, evtHandler, datadir);
79         menubar4 = new interfToolsMenu       (mentex4, sizex ,sizey, evtHandler, datadir);
80         menubar5 = new interfSegmentationMenu(mentex5, sizex, sizey, evtHandler, datadir);
81         menubar6 = new interfImageToolsMenu(mentex6, sizex, sizey, evtHandler, datadir);
82
83         statictext  = getText(mentex,  PANEL);
84         statictext1 = getText(mentex1, PANEL1);
85         statictext2 = getText(mentex2, PANEL2);
86         statictext3 = getText(mentex3, PANEL3);
87         statictext4 = getText(mentex4, PANEL4);
88         statictext5 = getText(mentex5, PANEL5);
89         statictext6 = getText(mentex6, PANEL6);
90
91         flexsizer->Add(b, wxFIXED_MINSIZE);
92         flexsizer->Add(setMenuTextSizer(mentex, menubar,statictext), wxFIXED_MINSIZE);
93
94         flexsizer->Add(b1, wxFIXED_MINSIZE);
95         flexsizer->Add(setMenuTextSizer(mentex1, menubar1,statictext1), wxFIXED_MINSIZE);
96
97         flexsizer->Add(b2, wxFIXED_MINSIZE);
98         flexsizer->Add(setMenuTextSizer(mentex2, menubar2,statictext2), wxFIXED_MINSIZE);
99
100         flexsizer->Add(b3, wxFIXED_MINSIZE);
101         flexsizer->Add(setMenuTextSizer(mentex3, menubar3,statictext3), wxFIXED_MINSIZE);
102
103         flexsizer->Add(b4, wxFIXED_MINSIZE);
104         flexsizer->Add(setMenuTextSizer(mentex4, menubar4,statictext4), wxFIXED_MINSIZE);
105
106         flexsizer->Add(b5, wxFIXED_MINSIZE);
107         flexsizer->Add(setMenuTextSizer(mentex5, menubar5,statictext5), wxFIXED_MINSIZE);
108         flexsizer->Add(b6, wxFIXED_MINSIZE);
109         flexsizer->Add(setMenuTextSizer(mentex6, menubar6,statictext6), wxFIXED_MINSIZE);
110
111         toolpanel->Update();
112         toolpanel->Layout();
113
114         infoPanel = new wxPanel(splitterwindow, -1, wxDefaultPosition, wxDefaultSize, wxBORDER_DOUBLE, wxString(_T("")));
115         wxFlexGridSizer* infosizer = new wxFlexGridSizer(1,1,2,2);
116         infoPanel->SetSizer(infosizer, true);
117         infoPanel->SetAutoLayout( true );
118
119         splitterwindow->Initialize(toolpanel);
120         splitterwindow->SetSashGravity(1);
121 //EED   splitterwindow->SetSashPosition(600);
122         splitterwindow->SetSashSize(5);
123         splitterwindow->SplitHorizontally(toolpanel, infoPanel,8*73);
124
125         Connect(b->GetId(),  wxEVT_COMMAND_BUTTON_CLICKED, (wxObjectEventFunction)&interfMainPanel::onActionButtonPressed1);
126         Connect(b1->GetId(), wxEVT_COMMAND_BUTTON_CLICKED, (wxObjectEventFunction)&interfMainPanel::onActionButtonPressed1);
127         Connect(b2->GetId(), wxEVT_COMMAND_BUTTON_CLICKED, (wxObjectEventFunction)&interfMainPanel::onActionButtonPressed1);
128         Connect(b3->GetId(), wxEVT_COMMAND_BUTTON_CLICKED, (wxObjectEventFunction)&interfMainPanel::onActionButtonPressed1);
129         Connect(b4->GetId(), wxEVT_COMMAND_BUTTON_CLICKED, (wxObjectEventFunction)&interfMainPanel::onActionButtonPressed1);
130         Connect(b5->GetId(), wxEVT_COMMAND_BUTTON_CLICKED, (wxObjectEventFunction)&interfMainPanel::onActionButtonPressed1);
131         Connect(b6->GetId(), wxEVT_COMMAND_BUTTON_CLICKED, (wxObjectEventFunction)&interfMainPanel::onActionButtonPressed1);
132
133         this->Layout();
134 }
135
136 interfMainPanel::~interfMainPanel(void)
137 {
138
139 }
140
141 interfMainPanel* interfMainPanel::getInstance(wxWindow* parent, std::string datadir, wxEvtHandler * evtHandler)
142 {
143         _newframe = new wxFrame(parent, -1, wxT(" Contour Tools "), wxPoint(25,50), wxSize(350,900),wxFRAME_TOOL_WINDOW|wxSYSTEM_MENU | wxCAPTION |  wxCLIP_CHILDREN |wxFRAME_FLOAT_ON_PARENT);
144
145         if(interfmainpanel == NULL){
146                 interfmainpanel = new interfMainPanel(_newframe, 350, 900, evtHandler, datadir);
147         }
148         _newframe->Show(TRUE);
149         return interfmainpanel;
150 }
151
152 interfMainPanel* interfMainPanel::getInstance(wxWindow* parent, wxEvtHandler * evtHandler)
153 {
154
155         _newframe = new wxFrame(parent, -1, wxT(" Contour Tools "), wxPoint(25,50), wxSize(350,900),wxFRAME_TOOL_WINDOW|wxSYSTEM_MENU | wxCAPTION |  wxCLIP_CHILDREN |wxFRAME_FLOAT_ON_PARENT );
156
157         if(interfmainpanel == NULL){
158                 interfmainpanel = new interfMainPanel(_newframe, 350, 900, evtHandler);
159         }
160         _newframe->Show(TRUE);
161         return interfmainpanel;
162 }
163
164 bool interfMainPanel::Show(bool show)
165 {
166         return _newframe->Show(show);
167 }
168
169 interfMainPanel* interfMainPanel::getInstance()
170 {
171         return interfmainpanel;
172 }
173
174 void interfMainPanel :: resetInstance()
175 {
176         //delete interfmainpanel;
177         delete _newframe;
178         interfmainpanel = NULL;
179 }
180
181 wxPanel* interfMainPanel::initializeToolsPanel(wxWindow* parent, int sizex, int sizey, wxEvtHandler * evtHandler)
182 {
183         wxPanel* panel = new wxPanel(parent, -1, wxDefaultPosition, wxSize(sizex, sizey), wxBORDER_SUNKEN, wxString(_T("Spread")));
184
185         wxFlexGridSizer* flexsizer = new wxFlexGridSizer(2,1,2,2)       ;
186         panel->SetSizer(flexsizer, true);
187         panel->SetAutoLayout( true );
188
189         interfToolsMenu* menu = new interfToolsMenu(panel, sizex, sizey, evtHandler);
190         toolspread = new interfToolsSpreadPanel(panel, sizex, 300, evtHandler);
191
192         flexsizer->Add(menu, wxFIXED_MINSIZE);
193         flexsizer->Add(toolspread, wxFIXED_MINSIZE);
194
195         panel->Layout();
196
197         return panel;
198 }
199
200 /**
201 **      Adds a new checkbox to the scrolledwindow using the checkboxsizer
202 **      @Params id of contour
203 **
204 **/
205 void interfMainPanel::addContourCheckBox(std::string id)
206 {
207         toolspread->addContourCheckBox(id);
208 }
209
210 /**
211 **      Removes a checkbox from the list of checkboxes in the flexsizer (checkboxsizer)
212 **      @Params id of contour
213 **
214 **/
215 void interfMainPanel::removeContourCheckBox(std::string id)
216 {
217         toolspread->removeContourCheckBox(id);
218 }
219
220 void interfMainPanel::onActionButtonPressed1( wxCommandEvent& event )
221 {
222         //((interfToolsMenu*)menubar4)->hideAxis();
223         wxButton* b = (wxButton*)event.GetEventObject();
224         wxPanel* dmenu;
225         wxStaticText* text;
226         std::string dstring = *((std::string*) b->GetClientData());
227         int sizechange=0;
228
229         if(dstring.compare(PANEL)==0){
230                 dmenu = menubar;
231                 text = statictext;
232         }else if(dstring.compare(PANEL1)==0 ){
233                 dmenu = menubar1;
234                 text = statictext1;
235         }else if(dstring.compare(PANEL2)==0){
236                 dmenu = menubar2;
237                 text = statictext2;
238         }else if(dstring.compare(PANEL3)==0){
239                 dmenu = menubar3;
240                 text = statictext3;
241         }else if(dstring.compare(PANEL4)==0){
242                 dmenu = menubar4;
243                 text = statictext4;
244         }else if(dstring.compare(PANEL5)==0){
245                 dmenu = menubar5;
246                 text = statictext5;
247         }else if(dstring.compare(PANEL6)==0){
248                 dmenu = menubar6;
249                 text = statictext6;
250         }
251
252         if(wxStrcmp(b->GetLabel(),_T("+"))==0 ){
253                 dmenu->Show(true);
254                 sizechange = 1;
255                 b->SetLabel(_T("-"));
256         }else{
257                 dmenu->Show(false);
258                 sizechange = -1;
259                 b->SetLabel(_T("+"));
260         }
261
262         sizechange *= (dmenu->GetSize().GetHeight()-10);
263         splitterwindow->SetSashPosition(splitterwindow->GetSashPosition()+sizechange);
264
265         this->Layout();
266         this->Refresh();
267 }
268
269 wxStaticText* interfMainPanel::getText(wxWindow* parent, std::string nom)
270 {
271         return new wxStaticText(parent, -1, wxString(nom.c_str(),wxConvUTF8), wxDefaultPosition,
272                                         wxDefaultSize, wxALIGN_CENTRE, wxString(nom.c_str(),wxConvUTF8));
273 }
274
275 wxButton* interfMainPanel::getButton(wxWindow* parent)
276 {
277         wxButton* b = new wxButton(parent, -1, wxString(_T("-")), wxDefaultPosition, wxDefaultSize, wxBU_EXACTFIT,
278                                         wxDefaultValidator, wxString(_T("-")));
279         return b;
280 }
281
282 wxPanel* interfMainPanel::setMenuTextSizer(wxWindow* parent, wxPanel* panel, wxStaticText* text)
283 {
284
285         wxFlexGridSizer* flexsizer = new wxFlexGridSizer(2,1,2,2);
286         parent->SetSizer(flexsizer, true);
287         parent->SetAutoLayout( true );
288
289         flexsizer->Add(text, wxFLEX_GROWMODE_ALL);
290         flexsizer->Add(panel, wxFLEX_GROWMODE_ALL);
291
292         parent->Layout();
293         return (wxPanel*)parent;
294 }
295
296 /**
297 **      Shows the panel in the
298 **/
299 void interfMainPanel::showPanel(wxWindow* panel)
300 {
301         wxContourMainFrame::getInstance()->showAxis(false);
302         wxSizer* sizer = infoPanel->GetSizer();
303
304         if(currentWindow != NULL){
305                 currentWindow->Hide();
306                 /// \TODO fix warning: virtual bool wxSizer::Remove(wxWindow*) is deprecated 
307                 sizer->Remove(currentWindow);
308         }
309         sizer->Add(panel);
310         currentWindow = panel;
311         currentWindow->Show(true);
312
313         splitterwindow->SetSashPosition(splitterwindow->GetSashPosition()+1);
314         splitterwindow->SetSashPosition(splitterwindow->GetSashPosition()-1);
315
316         infoPanel->Layout();
317         infoPanel->Refresh();
318         this->Layout();
319         this->Refresh();
320 }
321
322 /**
323 **      Hide the panel in the lower box
324 **/
325 void interfMainPanel::hidePanel( )
326 {
327         wxContourMainFrame::getInstance()->showAxis(false);
328         wxSizer* sizer = infoPanel->GetSizer();
329
330         if(currentWindow != NULL){
331                 currentWindow->Hide();
332                 /// \TODO fix warning: virtual bool wxSizer::Remove(wxWindow*) is deprecated 
333                 sizer->Remove(currentWindow);
334         }
335         wxPanel * emptyPanel = new wxPanel(interfMainPanel::getInstance()->getInfoPanel(), -1, wxDefaultPosition, wxDefaultSize, wxBORDER_STATIC, wxString(_T("")));
336         sizer->Add(emptyPanel);
337         currentWindow = emptyPanel;
338         currentWindow->Show(true);
339
340         splitterwindow->SetSashPosition(splitterwindow->GetSashPosition()+1);
341         splitterwindow->SetSashPosition(splitterwindow->GetSashPosition()-1);
342
343         infoPanel->Layout();
344         infoPanel->Refresh();
345         this->Layout();
346         this->Refresh();
347 }
348
349 /**
350 **      Gets the Information panel
351 **/
352 wxPanel* interfMainPanel::getInfoPanel()
353 {
354         return infoPanel;
355 }
356
357 void interfMainPanel::onCreateContourSpline( )
358 {
359         wxContourMainFrame::getInstance()->showAxis(false);
360         wxContourMainFrame::getInstance()->onCreateContourSpline();
361 }
362
363 void interfMainPanel::onCreateContourRectangle( )
364 {
365         wxContourMainFrame::getInstance()->showAxis(false);
366     wxContourMainFrame::getInstance()->onCreateContourRectangle();
367 }
368 void interfMainPanel::onCreateContourCircle( )
369 {
370         wxContourMainFrame::getInstance()->showAxis(false);
371     wxContourMainFrame::getInstance()->onCreateContourCircle();
372 }
373
374 void interfMainPanel::onCreateContourLine( )
375 {
376         wxContourMainFrame::getInstance()->showAxis(false);
377     wxContourMainFrame::getInstance()->onCreateContourLine();
378 }
379
380 // RaC 09-09 ---------------------
381 void interfMainPanel::onCreateContourPoints( )
382 {
383         wxContourMainFrame::getInstance()->showAxis(false);
384     wxContourMainFrame::getInstance()->onCreateContourPoints();
385 }
386 // RaC 09-09 ---------------------
387
388 // RaC 10-09 ---------------------
389 void interfMainPanel::onCreateContourPolygon( )
390 {
391         wxContourMainFrame::getInstance()->showAxis(false);
392     wxContourMainFrame::getInstance()->onCreateContourPolygon();
393 }
394 // RaC 10-09 ---------------------
395
396 void interfMainPanel::onCreateContoursBullEye(wxPanel* panBull)
397 {
398         wxContourMainFrame::getInstance()->showAxis(false);
399         wxContourMainFrame::getInstance()->onCreateContourBullEye(panBull);
400 }
401
402 void interfMainPanel::onDeleteContour()
403 {
404         wxContourMainFrame::getInstance()->showAxis(false);
405         wxContourMainFrame::getInstance()->onDeleteContour();
406 }
407
408 void interfMainPanel::onDeleteContoursActSlice()
409 {
410         wxContourMainFrame::getInstance()->showAxis(false);
411         wxContourMainFrame::getInstance()->onDeleteContoursActSlice();
412 }
413
414 void interfMainPanel::onDeleteAllContours()
415 {
416         wxContourMainFrame::getInstance()->showAxis(false);
417         wxContourMainFrame::getInstance()->onDeleteAllContours();
418 }
419
420 void interfMainPanel::onCopy()
421 {
422         wxContourMainFrame::getInstance()->onCopy();
423 }
424
425 void interfMainPanel::onPaste()
426 {
427         wxContourMainFrame::getInstance()->onPaste();
428 }
429
430 void interfMainPanel::onUndo()
431 {
432         wxContourMainFrame::getInstance()->onUndo();
433 }
434
435 void interfMainPanel::onRedo()
436 {
437         wxContourMainFrame::getInstance()->onRedo();
438 }
439
440 void interfMainPanel::onLoad()
441 {
442         wxContourMainFrame::getInstance()->onLoad();
443 }
444
445 void interfMainPanel::onSave()
446 {
447         wxContourMainFrame::getInstance()->onSave();
448 }
449
450 void interfMainPanel::onImport(){
451         wxContourMainFrame::getInstance()->onImport();
452 }
453
454 void interfMainPanel::onTest(){
455         if(testPanel==NULL)
456         {
457                 testPanel = new wxPanel(interfMainPanel::getInstance()->getInfoPanel(), -1, wxDefaultPosition,
458                         wxDefaultSize, wxBORDER_STATIC, wxString(_T("")));
459                 wxFlexGridSizer* flexsizer = new wxFlexGridSizer(1);
460                 testPanel->SetSizer(flexsizer, true);
461                 testPanel->SetAutoLayout( true );
462                 panelTest = new interfTestPanel(testPanel);
463
464                 wxStaticText* stattext = new wxStaticText(mirrorPanel,  -1,
465                         wxString(_T("   Test Panel   ")),
466                         wxDefaultPosition, wxDefaultSize,
467                         wxALIGN_CENTRE|wxBORDER_SIMPLE|wxFULL_REPAINT_ON_RESIZE, wxString(_T("")));
468
469                 flexsizer->Add(stattext,wxALIGN_CENTER | wxALIGN_CENTRE);
470                 flexsizer->Add(panelTest, wxEXPAND);
471                 testPanel->Layout();
472                 showPanel(testPanel);
473         }
474 }
475
476 void interfMainPanel::RefreshInterface()
477 {
478         wxContourMainFrame::getInstance()->RefreshInterface();
479 }
480
481 vtkImageData* interfMainPanel::getImageData()
482 {
483         return wxContourMainFrame::getInstance()->getImageData();
484 }
485
486 void interfMainPanel::getImageRange(double  range[2] )
487 {
488         vtkImageData * img = getImageData();
489         img->GetScalarRange(range);
490 }
491
492 void interfMainPanel::onSegmentationOneSlice(int isovalue,int sampling,int method)
493 {
494         wxContourMainFrame::getInstance()->onSegmentationOneSlice(isovalue, sampling, method);
495 }
496
497 void interfMainPanel::onSegmentationOneSliceITK(wxString distance, wxString sigma, wxString alfa, wxString beta, wxString propagation, wxString iterations, wxString inflation)
498 {
499         wxContourMainFrame::getInstance()->onSegmentationOneSliceITK(distance, sigma, alfa, beta, propagation, iterations, inflation);
500 }
501
502 int interfMainPanel::GetImageDataSizeZ()
503 {
504         return wxContourMainFrame::getInstance()->GetImageDataSizeZ();
505 }
506
507 void interfMainPanel::onSegmentationAllSlice(int minZ,int maxZ,int isovalue,int sampling,int method)
508 {
509         wxContourMainFrame::getInstance()->onSegmentationAllSlice(minZ, maxZ,isovalue,sampling,method);
510 }
511
512 void interfMainPanel::setLabelSegmentationPanelVTK(wxString tmpString)
513 {
514     ((interfSegmentationPanelVTK*)segmentationPanel)->setLabel(tmpString);
515 }
516 void interfMainPanel::onSegmentationPressed()
517 {
518         if(segmentPanel == NULL){
519                 segmentPanel = new wxPanel(getInfoPanel(), -1, wxDefaultPosition, wxDefaultSize, wxBORDER_STATIC, wxString(_T("")));
520                 wxFlexGridSizer* flexsizer = new wxFlexGridSizer(1);
521                 segmentPanel->SetSizer(flexsizer, true);
522                 segmentPanel->SetAutoLayout(true);
523                 segmentPanel->SetEventHandler(this);
524
525                 //wxPanel* panel = contourevent->getSegmentationPanel(segmentPanel);
526                 segmentationPanel = new interfSegmentationPanelVTK(segmentPanel);
527
528
529                 wxStaticText* stattext = new wxStaticText(segmentPanel, -1, wxString(_T("   Automatic Segmentation   ")), wxDefaultPosition,
530                         wxDefaultSize, wxALIGN_CENTRE|wxBORDER_SIMPLE|wxFULL_REPAINT_ON_RESIZE, wxString(_T("")));
531
532                 flexsizer->Add(stattext,wxALIGN_CENTER | wxALIGN_CENTRE);
533                 flexsizer->Add(segmentationPanel, wxEXPAND);
534                 segmentPanel->Layout();
535         }
536         showPanel(segmentPanel);
537         wxContourMainFrame::getInstance()->showAxis(true);
538         axisshown = true;
539 }
540
541 void interfMainPanel::onSegmentationPressedITK()
542 {
543     if(segmentPanelITK == NULL){
544                 segmentPanelITK = new wxPanel(interfMainPanel::getInstance()->getInfoPanel(), -1, wxDefaultPosition, wxDefaultSize, wxBORDER_STATIC, wxString(_T("")));
545
546
547                 wxFlexGridSizer* flexsizer = new wxFlexGridSizer(1);
548                 segmentPanelITK->SetSizer(flexsizer, true);
549                 segmentPanelITK->SetAutoLayout( true );
550                 //segmentPanelITK->SetEventHandler(this->contourevent);
551
552                 //wxPanel* panel = contourevent->getSegmentationPanelITK(segmentPanelITK);
553                 wxPanel* panel = new interfSegmentationPanelITK(segmentPanelITK);
554
555                 wxStaticText* stattext = new wxStaticText(segmentPanelITK, -1, wxString(_T("   Automatic ITK Segmentation   ")), wxDefaultPosition,
556                         wxDefaultSize, wxALIGN_CENTRE|wxBORDER_SIMPLE|wxFULL_REPAINT_ON_RESIZE, wxString(_T("")));
557
558                 flexsizer->Add(stattext,wxALIGN_CENTER | wxALIGN_CENTRE);
559                 flexsizer->Add(panel, wxEXPAND);
560                 segmentPanelITK->Layout();
561         }
562         showPanel(segmentPanelITK);
563         wxContourMainFrame::getInstance()->showAxis(true);
564         axisshown = true;
565 }
566
567 void interfMainPanel::onRigidPressed()
568 {
569         wxContourMainFrame::getInstance()->onRigidPressed();
570 }
571
572 void interfMainPanel::onWidthOfContour(double width)
573 {
574         wxContourMainFrame::getInstance()->onWidthOfContour(width);
575 }
576
577 int interfMainPanel::getColorWindow()
578 {
579         return wxContourMainFrame::getInstance()->getColorWindow();
580 }
581 int interfMainPanel::getWindowLevel()
582 {
583         return wxContourMainFrame::getInstance()->getWindowLevel();
584 }
585 void interfMainPanel::onBrigthnessColorWindowLevel(int colorwindow,int windowlevel)
586 {
587         wxContourMainFrame::getInstance()->onBrigthnessColorWindowLevel(colorwindow, windowlevel);
588 }
589
590 void interfMainPanel::onInterpolation(bool interpolate)
591 {
592         wxContourMainFrame::getInstance()->onInterpolation(interpolate);
593 }
594
595
596 void interfMainPanel::onConfigurationPressed()
597 {
598         if(configPanel == NULL){
599                 configPanel = new wxPanel(interfMainPanel::getInstance()->getInfoPanel(), -1, wxDefaultPosition, wxDefaultSize, wxNO_BORDER, wxString(_T("")));
600                 wxFlexGridSizer* flexsizer = new wxFlexGridSizer(1);
601                 configPanel->SetSizer(flexsizer, true);
602                 configPanel->SetAutoLayout( true );
603                 //configPanel->SetEventHandler(this->contourevent);
604                 wxPanel* panel = new interfConfigurationPanel(configPanel);
605                 wxStaticText* stattext = new wxStaticText(configPanel, -1, wxString(_T("   Interface Configuration   ")), wxDefaultPosition,
606                         wxDefaultSize, wxALIGN_CENTRE|wxBORDER_SIMPLE|wxFULL_REPAINT_ON_RESIZE, wxString(_T("")));
607                 flexsizer->Add(stattext,wxALIGN_CENTER | wxALIGN_CENTRE);
608                 flexsizer->Add(panel, wxEXPAND);
609                 configPanel->Layout();
610         }
611         showPanel(configPanel);
612 }
613
614 void interfMainPanel::onSpreadPressed()
615 {
616     if(spreadPanel==NULL){
617
618                 spreadPanel = new wxPanel(interfMainPanel::getInstance()->getInfoPanel(), -1, wxDefaultPosition, wxDefaultSize, wxBORDER_STATIC, wxString(_T("")));
619                 wxFlexGridSizer* flexsizer = new wxFlexGridSizer(1);
620                 spreadPanel->SetSizer(flexsizer, true);
621                 spreadPanel->SetAutoLayout( true );
622                 //spreadPanel->SetEventHandler(this->contourevent);
623
624                 //wxPanel* panel = contourevent->getSpreadPanel(spreadPanel);
625                 panelSpread = new interfSpreadPanel(spreadPanel);
626
627
628                 wxStaticText* stattext = new wxStaticText(spreadPanel, -1, wxString(_T("   Automatic Spread   ")), wxDefaultPosition,
629                         wxDefaultSize, wxALIGN_CENTRE|wxBORDER_SIMPLE|wxFULL_REPAINT_ON_RESIZE, wxString(_T("")));
630
631                 flexsizer->Add(stattext,wxALIGN_CENTER | wxALIGN_CENTRE);
632                 flexsizer->Add(panelSpread, wxEXPAND);
633                 spreadPanel->Layout();
634         }
635         showPanel(spreadPanel);
636         //hideAxis();
637 }
638
639 void interfMainPanel::resetAppend()
640 {
641         wxContourMainFrame::getInstance()->resetAppend();
642 }
643
644 void interfMainPanel::onSpreadAdd()
645 {
646         wxContourMainFrame::getInstance()->onSpreadAdd();
647 }
648
649 void interfMainPanel::onSpreadAddAll()
650 {
651         wxContourMainFrame::getInstance()->onSpreadAddAll();
652 }
653
654
655 void interfMainPanel::appendStringSpread(std::string val)
656 {
657     panelSpread->appendStringSpread(val);
658 }
659
660 void interfMainPanel::onSpreadGo(int type)
661 {
662         wxContourMainFrame::getInstance()->onSpreadGo(type);
663 }
664
665 void interfMainPanel::setStringSpread(std::string stringtemp)
666 {
667         panelSpread->setStringSpread(stringtemp);
668 }
669
670 void interfMainPanel::onInformationPressed()
671 {
672
673         // Statistics frame
674         if(infoWin ==NULL){
675                 infoWin                 = new wxFrame (this, -1,_T("  Statistics  "), wxDefaultPosition, wxDefaultSize, wxFRAME_TOOL_WINDOW|wxSYSTEM_MENU | wxCAPTION |  wxCLIP_CHILDREN |wxFRAME_FLOAT_ON_PARENT | wxRESIZE_BORDER  );
676                 infoWin->SetSize( wxSize(825,650) );
677
678                 wxSize sizepanel(825,675);
679                 informationPanel        = new interfInformationPanel(infoWin);//contourevent->getInformationPanel(infoWin);
680
681                 wxBoxSizer * sizerPanel = new wxBoxSizer(wxHORIZONTAL);
682                 sizerPanel -> Add( informationPanel, 1, wxEXPAND ,0);
683
684                 infoWin->SetSizer( sizerPanel );
685                 infoWin->SetAutoLayout( true );
686                 infoWin->Layout();
687                 infoWin->Show();
688         }else {
689
690                 if (infoWin->IsShown()==true)
691                 {
692                         infoWin->Show(false);
693                 } else  {
694                         //contourevent->FillGridWithContoursInformation();
695                         infoWin->Show(true);
696                 }
697         }
698
699 //CMRU 29-08-09-----------------------------------------------------------------------------------------------
700         if(panelAux == NULL)
701         {
702                 panelAux = new wxPanel(interfMainPanel::getInstance()->getInfoPanel(), -1, wxDefaultPosition, wxDefaultSize, wxNO_BORDER, wxString(_T("")));
703         }
704 //------------------------------------------------------------------------------------------------------------
705
706         // mask view control panel
707         if(infoPanelMask == NULL){
708                 infoPanelMask = new wxPanel(panelAux, -1, wxDefaultPosition, wxDefaultSize, wxNO_BORDER, wxString(_T("")));
709                 wxFlexGridSizer* flexsizer = new wxFlexGridSizer(1);
710                 infoPanelMask->SetSizer(flexsizer, true);
711                 infoPanelMask->SetAutoLayout( true );
712                 //configPanel->SetEventHandler(this->contourevent);
713                 wxPanel *panel = wxContourMainFrame::getInstance()->getMaskImageViewPanel( infoPanelMask );
714                 wxStaticText* stattext = new wxStaticText(infoPanelMask, -1, wxString(_T("   Mask segmentation    ")), wxDefaultPosition,
715                                                                                                   wxDefaultSize, wxALIGN_CENTRE|wxBORDER_SIMPLE|wxFULL_REPAINT_ON_RESIZE, wxString(_T("")));
716
717                 flexsizer->Add(stattext,wxALIGN_CENTER | wxALIGN_CENTRE);
718
719                 flexsizer->Add(panel, wxEXPAND);
720                 infoPanelMask->Layout();
721
722         }
723
724 //CMRU 29-08-09-----------------------------------------------------------------------------------------------
725         //Calibration panel
726         if(infoPanelCalibration == NULL)
727         {
728                 infoPanelCalibration = new wxPanel(panelAux, -1, wxDefaultPosition, wxDefaultSize, wxNO_BORDER , wxString(_T("")));
729                 wxFlexGridSizer* flexsizer = new wxFlexGridSizer(1);
730                 infoPanelCalibration->SetSizer(flexsizer, true);
731                 infoPanelCalibration->SetAutoLayout( true );
732
733                 wxPanel *panel = new interfCalibrationPanel(infoPanelCalibration);
734                 wxStaticText* stattext = new wxStaticText(infoPanelCalibration, -1, wxString(_T("              Calibration               ")), wxDefaultPosition,
735                                                                                                   wxDefaultSize, wxALIGN_CENTRE|wxBORDER_SIMPLE|wxFULL_REPAINT_ON_RESIZE, wxString(_T("")));
736
737                 flexsizer->Add(stattext,wxALIGN_CENTER | wxALIGN_CENTRE);
738
739                 flexsizer->Add(panel, wxEXPAND);
740                 infoPanelCalibration->Layout();
741         }
742
743         wxFlexGridSizer* sizer = new wxFlexGridSizer(1);
744         panelAux->SetSizer(sizer, true);
745         panelAux->SetAutoLayout( true );
746         sizer->Add(infoPanelMask);
747         sizer->Add(infoPanelCalibration);
748
749         showPanel(panelAux);
750
751 //------------------------------------------------------------------
752
753         wxContourMainFrame::getInstance()->changeInstant();
754 }
755
756 void interfMainPanel::getInstantVector(std::vector<int>& tempVector)
757 {
758         wxContourMainFrame::getInstance()->getInstantVector(tempVector);
759 }
760
761 std::vector<std::string> interfMainPanel::getOutlinesName(int slide)
762 {
763         return wxContourMainFrame::getInstance()->getOutlinesName(slide);
764 }
765
766 void interfMainPanel::onInformationContourLabels(int typeContourGroup,int selection,int minZ,int maxZ,int grayRangeMin,int grayRangeMax){
767         wxContourMainFrame::getInstance()->onInformationContourLabels(typeContourGroup, selection, minZ, maxZ,grayRangeMin,grayRangeMax);
768 }
769
770 void interfMainPanel::setStringInfoPanel(wxString tmpString)
771 {
772         if(informationPanel!=NULL){
773                 ((interfInformationPanel*)informationPanel)->setStringInfoPanel(tmpString);
774         }
775 }
776
777 void interfMainPanel::setRowLabelInfoPanel(int z, wxString tempString)
778 {
779         ((interfInformationPanel*)informationPanel)->setRowLabelInfoPanel(z, tempString);
780 }
781
782 int interfMainPanel::getNumberColsInformationPanel()
783 {
784         return ((interfInformationPanel*)informationPanel)->getNumberCols();
785 }
786
787 void interfMainPanel::appendColsInformationPanel(int _numberOfVariablesStatistics)
788 {
789         ((interfInformationPanel*)informationPanel)->appendCols(_numberOfVariablesStatistics);
790 }
791
792 void interfMainPanel::setCellValueInfoPanel(int z,int tmpIntA,wxString tempString)
793 {
794         ((interfInformationPanel*)informationPanel)->setCellValue(z, tmpIntA, tempString);
795 }
796
797 void interfMainPanel::setColLableInfoPanel(int tmpIntB,wxString tmpTitleString)
798 {
799         ((interfInformationPanel*)informationPanel)->setColLabel(tmpIntB, tmpTitleString);
800
801 }
802
803 void interfMainPanel::SetScalarRange(int grayRangeMin,int grayRangeMax)
804 {
805         wxContourMainFrame::getInstance()->SetScalarRange(grayRangeMin, grayRangeMax);
806 }
807
808 void interfMainPanel::onSaveResults(std::string directory,std::string namefile, std::string filename,
809                                                                         int typeContourGroup, int selection, int minZ, int maxZ ,bool XYZValues, bool contourImage, bool statistics)
810 {
811         wxContourMainFrame::getInstance()->onSaveResults(directory, namefile, filename,
812                 typeContourGroup, selection, minZ,maxZ, XYZValues, contourImage, statistics);
813 }
814
815 wxString interfMainPanel::getCellValue(int j,int i){
816         return ((interfInformationPanel*)informationPanel)->getCellValue(j, i );
817 }
818
819 void interfMainPanel::onSnakePressed()
820 {
821         axisshown=false;
822         wxContourMainFrame::getInstance()->showAxis(axisshown);
823         wxContourMainFrame::getInstance()->onSnakePressed();
824 }
825
826 void interfMainPanel::onMirrorPressed(){
827     if(mirrorPanel==NULL)
828         {
829
830                 mirrorPanel = new wxPanel(interfMainPanel::getInstance()->getInfoPanel(), -1, wxDefaultPosition, wxDefaultSize, wxBORDER_STATIC, wxString(_T("")));
831                 wxFlexGridSizer* flexsizer = new wxFlexGridSizer(1);
832                 mirrorPanel->SetSizer(flexsizer, true);
833                 mirrorPanel->SetAutoLayout( true );
834                 panelMirror = new interfMirrorPanel(mirrorPanel);
835
836                 wxStaticText* stattext = new wxStaticText(mirrorPanel, -1, wxString(_T("   Mirroring Tool   ")), wxDefaultPosition,
837                         wxDefaultSize, wxALIGN_CENTRE|wxBORDER_SIMPLE|wxFULL_REPAINT_ON_RESIZE, wxString(_T("")));
838
839                 flexsizer->Add(stattext,wxALIGN_CENTER | wxALIGN_CENTRE);
840                 flexsizer->Add(panelMirror, wxEXPAND);
841                 mirrorPanel->Layout();
842
843                 refLineShown=true;
844                 wxContourMainFrame::getInstance()->referenceLine();
845         }
846
847         else
848         {
849
850                 if (!refLineShown)
851                 {
852                         wxContourMainFrame::getInstance()->refLineShow();
853                         refLineShown=true;
854                 }
855         }
856
857         showPanel(mirrorPanel);
858 }
859
860 void interfMainPanel::onMirror()
861 {
862         wxContourMainFrame::getInstance()->onMirror();
863 }
864
865 void interfMainPanel::onMirrorAxisShow()
866 {
867         if (!refLineShown)
868         {
869                 wxContourMainFrame::getInstance()->refLineShow();
870                 refLineShown=true;
871         }
872 }
873
874 void interfMainPanel::onMirrorAxisHide()
875 {
876         if (refLineShown)
877         {
878                 wxContourMainFrame::getInstance()->refLineHide();
879                 refLineShown=false;
880         }
881 }
882
883 void interfMainPanel::onMirrorChangeWidth(int width)
884 {
885         wxContourMainFrame::getInstance()->refLineChangeWidth(width);
886 }
887
888 //EED 07/07/2010
889 void interfMainPanel::onColorLayerImagePressed()
890 {
891         // Color Image Layer  view control panel
892         if(colorImageLayerPanel == NULL){
893                 colorImageLayerPanel = new wxPanel(interfMainPanel::getInstance()->getInfoPanel(), -1, wxDefaultPosition, wxDefaultSize, wxNO_BORDER, wxString(_T("")));
894                 wxFlexGridSizer* flexsizer = new wxFlexGridSizer(1);
895                 colorImageLayerPanel->SetSizer(flexsizer, true);
896                 colorImageLayerPanel->SetAutoLayout( true );
897                 //configPanel->SetEventHandler(this->contourevent);
898                 wxPanel *panel = wxContourMainFrame::getInstance()->getColorLayerImageViewPanel( colorImageLayerPanel );
899                 wxStaticText* stattext = new wxStaticText(colorImageLayerPanel, -1, wxString(_T("   Color Image Layer     ")), wxDefaultPosition,
900                                                                                                   wxDefaultSize, wxALIGN_CENTRE|wxBORDER_SIMPLE|wxFULL_REPAINT_ON_RESIZE, wxString(_T("")));
901                 flexsizer->Add(stattext,wxALIGN_CENTER | wxALIGN_CENTRE);
902                 flexsizer->Add(panel, wxEXPAND);
903                 colorImageLayerPanel->Layout();
904         }
905         showPanel(colorImageLayerPanel);
906         wxContourMainFrame::getInstance()->changeInstant();
907 }
908
909 //EED01
910 void interfMainPanel::onThresholdPressed()
911 {
912         // Threshold view control panel
913         if(thresholdPanel == NULL){
914                 thresholdPanel = new wxPanel(interfMainPanel::getInstance()->getInfoPanel(), -1, wxDefaultPosition, wxDefaultSize, wxNO_BORDER, wxString(_T("")));
915                 wxFlexGridSizer* flexsizer = new wxFlexGridSizer(1);
916                 thresholdPanel->SetSizer(flexsizer, true);
917                 thresholdPanel->SetAutoLayout( true );
918                 //configPanel->SetEventHandler(this->contourevent);
919                 wxPanel *panel = wxContourMainFrame::getInstance()->getThresholdImageViewPanel( thresholdPanel );
920                 wxStaticText* stattext = new wxStaticText(thresholdPanel, -1, wxString(_T("   Threshold segmentation    ")), wxDefaultPosition,
921                                                                                                   wxDefaultSize, wxALIGN_CENTRE|wxBORDER_SIMPLE|wxFULL_REPAINT_ON_RESIZE, wxString(_T("")));
922                 flexsizer->Add(stattext,wxALIGN_CENTER | wxALIGN_CENTRE);
923                 flexsizer->Add(panel, wxEXPAND);
924                 thresholdPanel->Layout();
925         }
926         showPanel(thresholdPanel);
927         wxContourMainFrame::getInstance()->changeInstant();
928 }
929
930
931 void interfMainPanel::ShowResultImages(int typeContourGroup, int selection, int minZ, int maxZ)
932 {
933         wxContourMainFrame::getInstance()->ShowResultImages(typeContourGroup, selection, minZ, maxZ);
934 }
935
936
937 void interfMainPanel::SetContourGroup(int contourGroup)
938 {
939         wxContourMainFrame::getInstance()->SetContourGroup( contourGroup);
940 }
941
942 //CMRU 17-08-09 ---------------------------------------------
943 void interfMainPanel::onPrintLabel ()
944 {
945         wxString label;
946         manualBaseModel* manualModel = wxContourMainFrame::getInstance()->getContour();
947
948         if(manualModel==NULL)
949         {
950         wxMessageDialog *dial = new wxMessageDialog(NULL, wxT("Please select a Contour"), wxT("Warning"), wxOK | wxICON_EXCLAMATION);
951                 dial->ShowModal();
952                 return;
953         }
954
955         wxTextEntryDialog* dialog = new wxTextEntryDialog(this,_T("Enter a tag name: ")) ;
956
957         if (dialog->ShowModal() == wxID_OK)
958         {
959                 label = dialog->GetValue();
960
961                 if(label.Len()!=0)
962                 {
963                         wxContourMainFrame::getInstance()->onPrintLabel(label,manualModel);
964                         wxMessageDialog *dial = new wxMessageDialog(NULL, wxT("The tag name was updated"), wxT("Information"), wxOK | wxICON_INFORMATION);
965                         dial->ShowModal();
966                 }
967                 else
968                 {
969                         wxMessageDialog *dial = new wxMessageDialog(NULL, wxT("Please enter a valid tag"), wxT("Warning"), wxOK | wxICON_EXCLAMATION);
970                         dial->ShowModal();
971                 }
972         }
973 }
974
975 void interfMainPanel::onCalibration(wxString size, int unit)
976 {
977         int type = 0;
978         double contourSize = 0.0;
979         double realSizeDouble = 0.0;
980
981         type = wxContourMainFrame::getInstance()->getType();
982         contourSize = wxContourMainFrame::getInstance()->getContourSizeInPixels();
983
984         std::cout<<"Cata->TamaƱo del contorno en pixeles:"<<contourSize<<endl;
985
986         if ( type == 6 )
987         {
988                 if (size.ToDouble(&realSizeDouble))
989                 {
990                         if(unit==1)
991                         {
992                                 realSizeDouble = realSizeDouble * 10;
993                         }
994                         if(unit==2)
995                         {
996                                 realSizeDouble = realSizeDouble * 25.4;
997                         }
998                         std::cout<< "Valor del usuario" << realSizeDouble<< endl ;
999                         onePixelSize (realSizeDouble,contourSize);
1000                  }
1001                  else
1002                  {
1003                         wxMessageDialog *dial = new wxMessageDialog(NULL, wxT("Please enter a numeric value"), wxT("Warning"), wxOK | wxICON_EXCLAMATION);
1004                         dial->ShowModal();
1005                  }
1006         }
1007         else
1008         {
1009                 wxMessageDialog *dial = new wxMessageDialog(NULL, wxT("Please select a line contour"), wxT("Warning"), wxOK | wxICON_EXCLAMATION);
1010                 dial->ShowModal();
1011         }
1012
1013         wxMessageDialog *dial = new wxMessageDialog(NULL, wxT("The calibration was made"), wxT("Information"), wxOK | wxICON_INFORMATION);
1014         dial->ShowModal();
1015         std::cout<< "Cata-> Se ha realizado la calibracion" << endl ;
1016 }
1017
1018 double interfMainPanel::onePixelSize (double realSize,double sizePixel)
1019 {
1020         _pixelValue = realSize/sizePixel;
1021         std::cout<< "Valor del un pixel = " << _pixelValue<< endl ;
1022         wxContourMainFrame::getInstance()->onePixelSize (_pixelValue);
1023         return _pixelValue ;
1024 }
1025
1026 double interfMainPanel::GetPixelValue()
1027 {
1028         return _pixelValue;
1029 }
1030 //------------------------------------------------------------------------------------------------------------