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