]> Creatis software - creaContours.git/blob - lib/Interface_Icons_NDimensions/interfMainPanel.cxx
*** empty log message ***
[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         splitterwindow->SetSashPosition(500);
122         splitterwindow->SetSashSize(5);
123         splitterwindow->SplitHorizontally(toolpanel, infoPanel);        
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();
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                 sizer->Remove(currentWindow);
307         }       
308         sizer->Add(panel);
309         currentWindow = panel;
310         currentWindow->Show(true);
311
312         splitterwindow->SetSashPosition(splitterwindow->GetSashPosition()+1);
313         splitterwindow->SetSashPosition(splitterwindow->GetSashPosition()-1);
314
315         infoPanel->Layout();
316         infoPanel->Refresh();
317         this->Layout();
318         this->Refresh();
319 }
320
321 /**
322 **      Hide the panel in the lower box
323 **/
324 void interfMainPanel::hidePanel( )
325 {
326         wxContourMainFrame::getInstance()->showAxis(false);
327         wxSizer* sizer = infoPanel->GetSizer();
328
329         if(currentWindow != NULL){
330                 currentWindow->Hide();
331                 sizer->Remove(currentWindow);
332         }
333         wxPanel * emptyPanel = new wxPanel(interfMainPanel::getInstance()->getInfoPanel(), -1, wxDefaultPosition, wxDefaultSize, wxBORDER_STATIC, wxString(_T("")));
334         sizer->Add(emptyPanel);
335         currentWindow = emptyPanel;
336         currentWindow->Show(true);
337
338         splitterwindow->SetSashPosition(splitterwindow->GetSashPosition()+1);
339         splitterwindow->SetSashPosition(splitterwindow->GetSashPosition()-1);
340
341         infoPanel->Layout();
342         infoPanel->Refresh();
343         this->Layout();
344         this->Refresh();
345 }
346
347 /**
348 **      Gets the Information panel
349 **/
350 wxPanel* interfMainPanel::getInfoPanel()
351 {
352         return infoPanel;
353 }
354
355 void interfMainPanel::onCreateContourSpline( )
356 {
357         wxContourMainFrame::getInstance()->showAxis(false);
358         wxContourMainFrame::getInstance()->onCreateContourSpline();
359 }
360
361 void interfMainPanel::onCreateContourRectangle( )
362 {
363         wxContourMainFrame::getInstance()->showAxis(false);
364     wxContourMainFrame::getInstance()->onCreateContourRectangle();
365 }
366 void interfMainPanel::onCreateContourCircle( )
367 {
368         wxContourMainFrame::getInstance()->showAxis(false);
369     wxContourMainFrame::getInstance()->onCreateContourCircle();
370 }
371
372 void interfMainPanel::onCreateContourLine( )
373 {
374         wxContourMainFrame::getInstance()->showAxis(false);
375     wxContourMainFrame::getInstance()->onCreateContourLine();
376 }
377
378 // RaC 09-09 ---------------------
379 void interfMainPanel::onCreateContourPoints( )
380 {
381         wxContourMainFrame::getInstance()->showAxis(false);
382     wxContourMainFrame::getInstance()->onCreateContourPoints();
383 }
384 // RaC 09-09 ---------------------
385
386 // RaC 10-09 ---------------------
387 void interfMainPanel::onCreateContourPolygon( )
388 {
389         wxContourMainFrame::getInstance()->showAxis(false);
390     wxContourMainFrame::getInstance()->onCreateContourPolygon();
391 }
392 // RaC 10-09 ---------------------
393
394 void interfMainPanel::onCreateContoursBullEye(wxPanel* panBull)
395 {
396         wxContourMainFrame::getInstance()->showAxis(false);
397         wxContourMainFrame::getInstance()->onCreateContourBullEye(panBull);
398 }
399
400 void interfMainPanel::onDeleteContour()
401 {
402         wxContourMainFrame::getInstance()->showAxis(false);
403         wxContourMainFrame::getInstance()->onDeleteContour();
404 }
405
406 void interfMainPanel::onDeleteContoursActSlice()
407 {
408         wxContourMainFrame::getInstance()->showAxis(false);
409         wxContourMainFrame::getInstance()->onDeleteContoursActSlice();
410 }
411
412 void interfMainPanel::onDeleteAllContours()
413 {
414         wxContourMainFrame::getInstance()->showAxis(false);
415         wxContourMainFrame::getInstance()->onDeleteAllContours();
416 }
417
418 void interfMainPanel::onCopy()
419 {
420         wxContourMainFrame::getInstance()->onCopy();
421 }
422
423 void interfMainPanel::onPaste()
424 {
425         wxContourMainFrame::getInstance()->onPaste();
426 }
427
428 void interfMainPanel::onUndo()
429 {
430         wxContourMainFrame::getInstance()->onUndo();
431 }
432
433 void interfMainPanel::onRedo()
434 {
435         wxContourMainFrame::getInstance()->onRedo();
436 }
437
438 void interfMainPanel::onLoad()
439 {
440         wxContourMainFrame::getInstance()->onLoad();
441 }
442
443 void interfMainPanel::onSave()
444 {
445         wxContourMainFrame::getInstance()->onSave();
446 }
447
448 void interfMainPanel::onImport(){
449         wxContourMainFrame::getInstance()->onImport();
450 }
451
452 void interfMainPanel::onTest(){
453         if(testPanel==NULL)
454         {
455                 testPanel = new wxPanel(interfMainPanel::getInstance()->getInfoPanel(), -1, wxDefaultPosition, 
456                         wxDefaultSize, wxBORDER_STATIC, wxString(_T("")));
457                 wxFlexGridSizer* flexsizer = new wxFlexGridSizer(1);    
458                 testPanel->SetSizer(flexsizer, true);
459                 testPanel->SetAutoLayout( true );       
460                 panelTest = new interfTestPanel(testPanel);
461
462                 wxStaticText* stattext = new wxStaticText(mirrorPanel,  -1, 
463                         wxString(_T("   Test Panel   ")), 
464                         wxDefaultPosition, wxDefaultSize, 
465                         wxALIGN_CENTRE|wxBORDER_SIMPLE|wxFULL_REPAINT_ON_RESIZE, wxString(_T("")));
466
467                 flexsizer->Add(stattext,wxALIGN_CENTER | wxALIGN_CENTRE);
468                 flexsizer->Add(panelTest, wxEXPAND);
469                 testPanel->Layout();
470                 showPanel(testPanel);
471         }       
472 }
473
474 void interfMainPanel::RefreshInterface()
475 {
476         wxContourMainFrame::getInstance()->RefreshInterface();
477 }
478
479 vtkImageData* interfMainPanel::getImageData()
480 {
481         return wxContourMainFrame::getInstance()->getImageData();
482 }
483
484 void interfMainPanel::getImageRange(double  range[2] )
485 {
486         vtkImageData * img = getImageData();
487         img->GetScalarRange(range);
488 }
489
490 void interfMainPanel::onSegmentationOneSlice(int isovalue,int sampling,int method)
491 {
492         wxContourMainFrame::getInstance()->onSegmentationOneSlice(isovalue, sampling, method);
493 }
494
495 void interfMainPanel::onSegmentationOneSliceITK(wxString distance, wxString sigma, wxString alfa, wxString beta, wxString propagation, wxString iterations, wxString inflation)
496 {
497         wxContourMainFrame::getInstance()->onSegmentationOneSliceITK(distance, sigma, alfa, beta, propagation, iterations, inflation);
498 }
499
500 int interfMainPanel::GetImageDataSizeZ()
501 {
502         return wxContourMainFrame::getInstance()->GetImageDataSizeZ();
503 }
504
505 void interfMainPanel::onSegmentationAllSlice(int minZ,int maxZ,int isovalue,int sampling,int method)
506 {
507         wxContourMainFrame::getInstance()->onSegmentationAllSlice(minZ, maxZ,isovalue,sampling,method);
508 }
509
510 void interfMainPanel::setLabelSegmentationPanelVTK(wxString tmpString)
511 {       
512     ((interfSegmentationPanelVTK*)segmentationPanel)->setLabel(tmpString);
513 }
514 void interfMainPanel::onSegmentationPressed()
515 {
516         if(segmentPanel == NULL){
517                 segmentPanel = new wxPanel(getInfoPanel(), -1, wxDefaultPosition, wxDefaultSize, wxBORDER_STATIC, wxString(_T("")));
518                 wxFlexGridSizer* flexsizer = new wxFlexGridSizer(1);    
519                 segmentPanel->SetSizer(flexsizer, true);
520                 segmentPanel->SetAutoLayout(true);      
521                 segmentPanel->SetEventHandler(this);
522                 
523                 //wxPanel* panel = contourevent->getSegmentationPanel(segmentPanel);
524                 segmentationPanel = new interfSegmentationPanelVTK(segmentPanel);
525         
526
527                 wxStaticText* stattext = new wxStaticText(segmentPanel, -1, wxString(_T("   Automatic Segmentation   ")), wxDefaultPosition,
528                         wxDefaultSize, wxALIGN_CENTRE|wxBORDER_SIMPLE|wxFULL_REPAINT_ON_RESIZE, wxString(_T("")));
529
530                 flexsizer->Add(stattext,wxALIGN_CENTER | wxALIGN_CENTRE);
531                 flexsizer->Add(segmentationPanel, wxEXPAND);
532                 segmentPanel->Layout();
533         }
534         showPanel(segmentPanel);
535         wxContourMainFrame::getInstance()->showAxis(true);
536         axisshown = true;
537 }
538
539 void interfMainPanel::onSegmentationPressedITK()
540 {
541     if(segmentPanelITK == NULL){
542                 segmentPanelITK = new wxPanel(interfMainPanel::getInstance()->getInfoPanel(), -1, wxDefaultPosition, wxDefaultSize, wxBORDER_STATIC, wxString(_T("")));
543                         
544
545                 wxFlexGridSizer* flexsizer = new wxFlexGridSizer(1);    
546                 segmentPanelITK->SetSizer(flexsizer, true);
547                 segmentPanelITK->SetAutoLayout( true ); 
548                 //segmentPanelITK->SetEventHandler(this->contourevent);
549                 
550                 //wxPanel* panel = contourevent->getSegmentationPanelITK(segmentPanelITK);
551                 wxPanel* panel = new interfSegmentationPanelITK(segmentPanelITK);
552         
553                 wxStaticText* stattext = new wxStaticText(segmentPanelITK, -1, wxString(_T("   Automatic ITK Segmentation   ")), wxDefaultPosition,
554                         wxDefaultSize, wxALIGN_CENTRE|wxBORDER_SIMPLE|wxFULL_REPAINT_ON_RESIZE, wxString(_T("")));
555
556                 flexsizer->Add(stattext,wxALIGN_CENTER | wxALIGN_CENTRE);
557                 flexsizer->Add(panel, wxEXPAND);
558                 segmentPanelITK->Layout();
559         }
560         showPanel(segmentPanelITK);
561         wxContourMainFrame::getInstance()->showAxis(true);
562         axisshown = true;
563 }
564
565 void interfMainPanel::onRigidPressed()
566 {
567         wxContourMainFrame::getInstance()->onRigidPressed();
568 }
569
570 void interfMainPanel::onWidthOfContour(double width)
571 {    
572         wxContourMainFrame::getInstance()->onWidthOfContour(width);
573 }
574
575 int interfMainPanel::getColorWindow()
576 {
577         return wxContourMainFrame::getInstance()->getColorWindow();
578 }
579 int interfMainPanel::getWindowLevel()
580 {
581         return wxContourMainFrame::getInstance()->getWindowLevel();
582 }
583 void interfMainPanel::onBrigthnessColorWindowLevel(int colorwindow,int windowlevel)
584 {
585         wxContourMainFrame::getInstance()->onBrigthnessColorWindowLevel(colorwindow, windowlevel);
586 }
587
588 void interfMainPanel::onInterpolation(bool interpolate)
589 {
590         wxContourMainFrame::getInstance()->onInterpolation(interpolate);
591 }
592
593
594 void interfMainPanel::onConfigurationPressed()
595 {
596         if(configPanel == NULL){
597                 configPanel = new wxPanel(interfMainPanel::getInstance()->getInfoPanel(), -1, wxDefaultPosition, wxDefaultSize, wxNO_BORDER, wxString(_T("")));
598                 wxFlexGridSizer* flexsizer = new wxFlexGridSizer(1);    
599                 configPanel->SetSizer(flexsizer, true);
600                 configPanel->SetAutoLayout( true );     
601                 //configPanel->SetEventHandler(this->contourevent);
602                 wxPanel* panel = new interfConfigurationPanel(configPanel);
603                 wxStaticText* stattext = new wxStaticText(configPanel, -1, wxString(_T("   Interface Configuration   ")), wxDefaultPosition,
604                         wxDefaultSize, wxALIGN_CENTRE|wxBORDER_SIMPLE|wxFULL_REPAINT_ON_RESIZE, wxString(_T("")));
605                 flexsizer->Add(stattext,wxALIGN_CENTER | wxALIGN_CENTRE);
606                 flexsizer->Add(panel, wxEXPAND);
607                 configPanel->Layout();
608         }
609         showPanel(configPanel);
610 }
611
612 void interfMainPanel::onSpreadPressed()
613 {
614     if(spreadPanel==NULL){
615
616                 spreadPanel = new wxPanel(interfMainPanel::getInstance()->getInfoPanel(), -1, wxDefaultPosition, wxDefaultSize, wxBORDER_STATIC, wxString(_T("")));
617                 wxFlexGridSizer* flexsizer = new wxFlexGridSizer(1);    
618                 spreadPanel->SetSizer(flexsizer, true);
619                 spreadPanel->SetAutoLayout( true );     
620                 //spreadPanel->SetEventHandler(this->contourevent);
621                 
622                 //wxPanel* panel = contourevent->getSpreadPanel(spreadPanel);
623                 panelSpread = new interfSpreadPanel(spreadPanel);
624         
625
626                 wxStaticText* stattext = new wxStaticText(spreadPanel, -1, wxString(_T("   Automatic Spread   ")), wxDefaultPosition,
627                         wxDefaultSize, wxALIGN_CENTRE|wxBORDER_SIMPLE|wxFULL_REPAINT_ON_RESIZE, wxString(_T("")));
628
629                 flexsizer->Add(stattext,wxALIGN_CENTER | wxALIGN_CENTRE);
630                 flexsizer->Add(panelSpread, wxEXPAND);
631                 spreadPanel->Layout();
632         }       
633         showPanel(spreadPanel);
634         //hideAxis();
635 }
636
637 void interfMainPanel::resetAppend()
638 {
639         wxContourMainFrame::getInstance()->resetAppend();
640 }
641
642 void interfMainPanel::onSpreadAdd()
643 {
644         wxContourMainFrame::getInstance()->onSpreadAdd();
645 }
646
647 void interfMainPanel::appendStringSpread(std::string val)
648 {
649     panelSpread->appendStringSpread(val);
650 }
651
652 void interfMainPanel::onSpreadGo(int type)
653 {
654         wxContourMainFrame::getInstance()->onSpreadGo(type);
655 }
656
657 void interfMainPanel::setStringSpread(std::string stringtemp)
658 {
659         panelSpread->setStringSpread(stringtemp);
660 }
661
662 void interfMainPanel::onInformationPressed()
663 {
664         
665         // Statistics frame
666         if(infoWin ==NULL){
667                 infoWin                 = new wxFrame (this, -1,_T("  Statistics  "), wxDefaultPosition, wxDefaultSize, wxFRAME_TOOL_WINDOW|wxSYSTEM_MENU | wxCAPTION |  wxCLIP_CHILDREN |wxFRAME_FLOAT_ON_PARENT | wxRESIZE_BORDER  );
668                 infoWin->SetSize( wxSize(825,650) );
669                 
670                 wxSize sizepanel(825,675);
671                 informationPanel        = new interfInformationPanel(infoWin);//contourevent->getInformationPanel(infoWin);
672
673                 wxBoxSizer * sizerPanel = new wxBoxSizer(wxHORIZONTAL);
674                 sizerPanel -> Add( informationPanel, 1, wxEXPAND ,0);
675
676                 infoWin->SetSizer( sizerPanel );
677                 infoWin->SetAutoLayout( true );
678                 infoWin->Layout();
679                 infoWin->Show();
680         }else {
681
682                 if (infoWin->IsShown()==true)
683                 {
684                         infoWin->Show(false);
685                 } else  {
686                         //contourevent->FillGridWithContoursInformation();
687                         infoWin->Show(true);
688                 }
689         }
690                 
691 //CMRU 29-08-09-----------------------------------------------------------------------------------------------  
692         if(panelAux == NULL)
693         {
694                 panelAux = new wxPanel(interfMainPanel::getInstance()->getInfoPanel(), -1, wxDefaultPosition, wxDefaultSize, wxNO_BORDER, wxString(_T("")));
695         }       
696 //------------------------------------------------------------------------------------------------------------
697
698         // mask view control panel
699         if(infoPanelMask == NULL){
700                 infoPanelMask = new wxPanel(panelAux, -1, wxDefaultPosition, wxDefaultSize, wxNO_BORDER, wxString(_T("")));
701                 wxFlexGridSizer* flexsizer = new wxFlexGridSizer(1);    
702                 infoPanelMask->SetSizer(flexsizer, true);
703                 infoPanelMask->SetAutoLayout( true );   
704                 //configPanel->SetEventHandler(this->contourevent);
705                 wxPanel *panel = wxContourMainFrame::getInstance()->getMaskImageViewPanel( infoPanelMask );                             
706                 wxStaticText* stattext = new wxStaticText(infoPanelMask, -1, wxString(_T("   Mask segmentation    ")), wxDefaultPosition,
707                                                                                                   wxDefaultSize, wxALIGN_CENTRE|wxBORDER_SIMPLE|wxFULL_REPAINT_ON_RESIZE, wxString(_T("")));
708                 
709                 flexsizer->Add(stattext,wxALIGN_CENTER | wxALIGN_CENTRE);
710                 
711                 flexsizer->Add(panel, wxEXPAND);
712                 infoPanelMask->Layout();
713                 
714         }
715         
716 //CMRU 29-08-09-----------------------------------------------------------------------------------------------
717         //Calibration panel
718         if(infoPanelCalibration == NULL)
719         {
720                 infoPanelCalibration = new wxPanel(panelAux, -1, wxDefaultPosition, wxDefaultSize, wxNO_BORDER , wxString(_T("")));
721                 wxFlexGridSizer* flexsizer = new wxFlexGridSizer(1);    
722                 infoPanelCalibration->SetSizer(flexsizer, true);
723                 infoPanelCalibration->SetAutoLayout( true );    
724
725                 wxPanel *panel = new interfCalibrationPanel(infoPanelCalibration);
726                 wxStaticText* stattext = new wxStaticText(infoPanelCalibration, -1, wxString(_T("              Calibration               ")), wxDefaultPosition,
727                                                                                                   wxDefaultSize, wxALIGN_CENTRE|wxBORDER_SIMPLE|wxFULL_REPAINT_ON_RESIZE, wxString(_T("")));
728                 
729                 flexsizer->Add(stattext,wxALIGN_CENTER | wxALIGN_CENTRE);
730                 
731                 flexsizer->Add(panel, wxEXPAND);
732                 infoPanelCalibration->Layout();
733         }
734
735         wxFlexGridSizer* sizer = new wxFlexGridSizer(1);
736         panelAux->SetSizer(sizer, true);
737         panelAux->SetAutoLayout( true );        
738         sizer->Add(infoPanelMask);
739         sizer->Add(infoPanelCalibration);
740         
741         showPanel(panelAux);
742
743 //------------------------------------------------------------------
744
745         wxContourMainFrame::getInstance()->changeInstant();
746 }
747
748 void interfMainPanel::getInstantVector(std::vector<int>& tempVector)
749 {
750         wxContourMainFrame::getInstance()->getInstantVector(tempVector);
751 }
752
753 std::vector<std::string> interfMainPanel::getOutlinesName(int slide)
754 {
755         return wxContourMainFrame::getInstance()->getOutlinesName(slide);
756 }
757
758 void interfMainPanel::onInformationContourLabels(int typeContourGroup,int selection,int minZ,int maxZ,int grayRangeMin,int grayRangeMax){
759         wxContourMainFrame::getInstance()->onInformationContourLabels(typeContourGroup, selection, minZ, maxZ,grayRangeMin,grayRangeMax);
760 }
761
762 void interfMainPanel::setStringInfoPanel(wxString tmpString)
763 {
764         if(informationPanel!=NULL){
765                 ((interfInformationPanel*)informationPanel)->setStringInfoPanel(tmpString);
766         }
767 }
768
769 void interfMainPanel::setRowLabelInfoPanel(int z, wxString tempString)
770 {
771         ((interfInformationPanel*)informationPanel)->setRowLabelInfoPanel(z, tempString);
772 }
773
774 int interfMainPanel::getNumberColsInformationPanel()
775 {
776         return ((interfInformationPanel*)informationPanel)->getNumberCols();
777 }
778
779 void interfMainPanel::appendColsInformationPanel(int _numberOfVariablesStatistics)
780 {
781         ((interfInformationPanel*)informationPanel)->appendCols(_numberOfVariablesStatistics);
782 }
783
784 void interfMainPanel::setCellValueInfoPanel(int z,int tmpIntA,wxString tempString)
785 {
786         ((interfInformationPanel*)informationPanel)->setCellValue(z, tmpIntA, tempString);
787 }
788
789 void interfMainPanel::setColLableInfoPanel(int tmpIntB,wxString tmpTitleString)
790 {
791         ((interfInformationPanel*)informationPanel)->setColLabel(tmpIntB, tmpTitleString);
792
793 }
794
795 void interfMainPanel::SetScalarRange(int grayRangeMin,int grayRangeMax)
796 {
797         wxContourMainFrame::getInstance()->SetScalarRange(grayRangeMin, grayRangeMax); 
798 }
799
800 void interfMainPanel::onSaveResults(std::string directory,std::string namefile, std::string filename, 
801                                                                         int typeContourGroup, int selection, int minZ, int maxZ ,bool XYZValues, bool contourImage, bool statistics)
802 {
803         wxContourMainFrame::getInstance()->onSaveResults(directory, namefile, filename, 
804                 typeContourGroup, selection, minZ,maxZ, XYZValues, contourImage, statistics);
805 }
806
807 wxString interfMainPanel::getCellValue(int j,int i){
808         return ((interfInformationPanel*)informationPanel)->getCellValue(j, i );
809 }
810
811 void interfMainPanel::onSnakePressed()
812 {
813         axisshown=false;
814         wxContourMainFrame::getInstance()->showAxis(axisshown);
815         wxContourMainFrame::getInstance()->onSnakePressed();
816 }
817
818 void interfMainPanel::onMirrorPressed(){
819     if(mirrorPanel==NULL)
820         {
821
822                 mirrorPanel = new wxPanel(interfMainPanel::getInstance()->getInfoPanel(), -1, wxDefaultPosition, wxDefaultSize, wxBORDER_STATIC, wxString(_T("")));
823                 wxFlexGridSizer* flexsizer = new wxFlexGridSizer(1);    
824                 mirrorPanel->SetSizer(flexsizer, true);
825                 mirrorPanel->SetAutoLayout( true );     
826                 panelMirror = new interfMirrorPanel(mirrorPanel);
827         
828                 wxStaticText* stattext = new wxStaticText(mirrorPanel, -1, wxString(_T("   Mirroring Tool   ")), wxDefaultPosition,
829                         wxDefaultSize, wxALIGN_CENTRE|wxBORDER_SIMPLE|wxFULL_REPAINT_ON_RESIZE, wxString(_T("")));
830
831                 flexsizer->Add(stattext,wxALIGN_CENTER | wxALIGN_CENTRE);
832                 flexsizer->Add(panelMirror, wxEXPAND);
833                 mirrorPanel->Layout();
834
835                 refLineShown=true;
836                 wxContourMainFrame::getInstance()->referenceLine();
837         }       
838
839         else
840         {
841
842                 if (!refLineShown)
843                 {
844                         wxContourMainFrame::getInstance()->refLineShow();
845                         refLineShown=true;
846                 }
847         }
848
849         showPanel(mirrorPanel);
850 }
851
852 void interfMainPanel::onMirror()
853 {
854         wxContourMainFrame::getInstance()->onMirror();
855 }
856
857 void interfMainPanel::onMirrorAxisShow()
858 {
859         if (!refLineShown)
860         {
861                 wxContourMainFrame::getInstance()->refLineShow();
862                 refLineShown=true;
863         }
864 }
865
866 void interfMainPanel::onMirrorAxisHide()
867 {
868         if (refLineShown)
869         {
870                 wxContourMainFrame::getInstance()->refLineHide();
871                 refLineShown=false;
872         }
873 }
874
875 void interfMainPanel::onMirrorChangeWidth(int width)
876 {
877         wxContourMainFrame::getInstance()->refLineChangeWidth(width);
878 }
879
880 //EED 07/07/2010
881 void interfMainPanel::onColorLayerImagePressed()
882 {
883         // Color Image Layer  view control panel
884         if(colorImageLayerPanel == NULL){
885                 colorImageLayerPanel = new wxPanel(interfMainPanel::getInstance()->getInfoPanel(), -1, wxDefaultPosition, wxDefaultSize, wxNO_BORDER, wxString(_T("")));
886                 wxFlexGridSizer* flexsizer = new wxFlexGridSizer(1);    
887                 colorImageLayerPanel->SetSizer(flexsizer, true);
888                 colorImageLayerPanel->SetAutoLayout( true );    
889                 //configPanel->SetEventHandler(this->contourevent);
890                 wxPanel *panel = wxContourMainFrame::getInstance()->getThresholdImageViewPanel( colorImageLayerPanel );                         
891                 wxStaticText* stattext = new wxStaticText(colorImageLayerPanel, -1, wxString(_T("   Color Image Layer     ")), wxDefaultPosition,
892                                                                                                   wxDefaultSize, wxALIGN_CENTRE|wxBORDER_SIMPLE|wxFULL_REPAINT_ON_RESIZE, wxString(_T("")));
893                 flexsizer->Add(stattext,wxALIGN_CENTER | wxALIGN_CENTRE);
894                 flexsizer->Add(panel, wxEXPAND);
895                 colorImageLayerPanel->Layout();
896         }
897         showPanel(colorImageLayerPanel);
898         wxContourMainFrame::getInstance()->changeInstant();
899 }
900
901 //EED01
902 void interfMainPanel::onThresholdPressed()
903 {       
904         // Threshold view control panel
905         if(thresholdPanel == NULL){
906                 thresholdPanel = new wxPanel(interfMainPanel::getInstance()->getInfoPanel(), -1, wxDefaultPosition, wxDefaultSize, wxNO_BORDER, wxString(_T("")));
907                 wxFlexGridSizer* flexsizer = new wxFlexGridSizer(1);    
908                 thresholdPanel->SetSizer(flexsizer, true);
909                 thresholdPanel->SetAutoLayout( true );  
910                 //configPanel->SetEventHandler(this->contourevent);
911                 wxPanel *panel = wxContourMainFrame::getInstance()->getColorLayerImageViewPanel( thresholdPanel );                              
912                 wxStaticText* stattext = new wxStaticText(thresholdPanel, -1, wxString(_T("   Threshold segmentation    ")), wxDefaultPosition,
913                                                                                                   wxDefaultSize, wxALIGN_CENTRE|wxBORDER_SIMPLE|wxFULL_REPAINT_ON_RESIZE, wxString(_T("")));
914                 flexsizer->Add(stattext,wxALIGN_CENTER | wxALIGN_CENTRE);
915                 flexsizer->Add(panel, wxEXPAND);
916                 thresholdPanel->Layout();               
917         }
918         showPanel(thresholdPanel);
919         wxContourMainFrame::getInstance()->changeInstant();
920 }
921
922
923 void interfMainPanel::ShowResultImages(int typeContourGroup, int selection, int minZ, int maxZ)
924 {
925         wxContourMainFrame::getInstance()->ShowResultImages(typeContourGroup, selection, minZ, maxZ);
926 }
927
928
929 void interfMainPanel::SetContourGroup(int contourGroup)
930 {
931         wxContourMainFrame::getInstance()->SetContourGroup( contourGroup);
932 }
933
934 //CMRU 17-08-09 ---------------------------------------------
935 void interfMainPanel::onPrintLabel () 
936 {
937         wxString label;
938         manualBaseModel* manualModel = wxContourMainFrame::getInstance()->getContour();
939
940         if(manualModel==NULL)
941         {
942         wxMessageDialog *dial = new wxMessageDialog(NULL, wxT("Please select a Contour"), wxT("Warning"), wxOK | wxICON_EXCLAMATION);
943                 dial->ShowModal();
944                 return;
945         }
946
947         wxTextEntryDialog* dialog = new wxTextEntryDialog(this,_T("Enter a tag name: ")) ;
948         
949         if (dialog->ShowModal() == wxID_OK)
950         {
951                 label = dialog->GetValue(); 
952
953                 if(label.Len()!=0)
954                 {
955                         wxContourMainFrame::getInstance()->onPrintLabel(label,manualModel);
956                         wxMessageDialog *dial = new wxMessageDialog(NULL, wxT("The tag name was updated"), wxT("Information"), wxOK | wxICON_INFORMATION);
957                         dial->ShowModal();
958                 }
959                 else
960                 {
961                         wxMessageDialog *dial = new wxMessageDialog(NULL, wxT("Please enter a valid tag"), wxT("Warning"), wxOK | wxICON_EXCLAMATION);
962                         dial->ShowModal();
963                 }
964         }
965 }
966
967 void interfMainPanel::onCalibration(wxString size, int unit)
968 {
969         int type = 0;
970         double contourSize = 0.0; 
971         double realSizeDouble = 0.0;
972
973         type = wxContourMainFrame::getInstance()->getType(); 
974         contourSize = wxContourMainFrame::getInstance()->getContourSizeInPixels();
975
976         std::cout<<"Cata->TamaƱo del contorno en pixeles:"<<contourSize<<endl;
977         
978         if ( type == 6 ) 
979         {
980                 if (size.ToDouble(&realSizeDouble))
981                 {
982                         if(unit==1)
983                         {
984                                 realSizeDouble = realSizeDouble * 10;
985                         }
986                         if(unit==2)
987                         {
988                                 realSizeDouble = realSizeDouble * 25.4;
989                         }
990                         std::cout<< "Valor del usuario" << realSizeDouble<< endl ; 
991                         onePixelSize (realSizeDouble,contourSize);
992                  }
993                  else
994                  {
995                         wxMessageDialog *dial = new wxMessageDialog(NULL, wxT("Please enter a numeric value"), wxT("Warning"), wxOK | wxICON_EXCLAMATION);
996                         dial->ShowModal();
997                  }              
998         }
999         else 
1000         {
1001                 wxMessageDialog *dial = new wxMessageDialog(NULL, wxT("Please select a line contour"), wxT("Warning"), wxOK | wxICON_EXCLAMATION);
1002                 dial->ShowModal();
1003         }
1004         
1005         wxMessageDialog *dial = new wxMessageDialog(NULL, wxT("The calibration was made"), wxT("Information"), wxOK | wxICON_INFORMATION);
1006         dial->ShowModal();
1007         std::cout<< "Cata-> Se ha realizado la calibracion" << endl ;
1008 }
1009
1010 double interfMainPanel::onePixelSize (double realSize,double sizePixel) 
1011 {
1012         _pixelValue = realSize/sizePixel;
1013         std::cout<< "Valor del un pixel = " << _pixelValue<< endl ;
1014         wxContourMainFrame::getInstance()->onePixelSize (_pixelValue);
1015         return _pixelValue ;
1016 }
1017
1018 double interfMainPanel::GetPixelValue()
1019 {
1020         return _pixelValue;
1021 }
1022 //------------------------------------------------------------------------------------------------------------