]> Creatis software - creaContours.git/blob - lib/Interface_ManagerContour_NDimensions/wxContourMainFrame.cxx
*** empty log message ***
[creaContours.git] / lib / Interface_ManagerContour_NDimensions / wxContourMainFrame.cxx
1 //----------------------------------------------------------------------------------------------------------------
2 // Class definition include
3 //----------------------------------------------------------------------------------------------------------------
4 #include "wxContourMainFrame.h"
5
6
7
8 //----------------------------------------------------------------------------------------------------------------
9 // Includes
10 //----------------------------------------------------------------------------------------------------------------
11
12
13 #include "NameWrapper.h"
14 #include "wx/artprov.h"
15 #include "ConceptDataWrap.h"
16
17 #include <manualContour.h>
18 //#include "ImageSourceThing.h"
19 //#include "wxContour_ActionCommandsID.h"
20 //#include "OutlineModelBuilder.h"
21 //#include "wxContourEventHandler.h"
22 #include <creaWx.h>
23
24 //----------------------------------------------------------------------------------------------------------------
25 // Class implementation
26 //----------------------------------------------------------------------------------------------------------------
27 /** @file wxContourMainFrame.cxx */
28
29         //------------------------------------------------------------------------------------------------------------
30         // Constructors & Destructors
31         //------------------------------------------------------------------------------------------------------------
32
33 wxContourMainFrame* wxContourMainFrame:: instance = NULL;
34 char wxContourMainFrame::COPY = 'C';
35                 
36         wxContourMainFrame :: wxContourMainFrame(wxWindow* parent, wxWindowID id,const wxString& title,const wxPoint& pos,const wxSize& size,long style)
37                 //: wxPanel(parent, id, title, pos, size, style)
38                 //: wxWindow(parent, id, pos, size, style)
39                 : wxPanel(parent, id, pos, size, style)
40         {
41                 m_mgr.SetManagedWindow(this);
42                 _creatingContoursActive         = false;
43                 _theViewPanel                           = NULL;
44 //              _modelManager                           = NULL;
45                 _instantPanel                           = NULL;
46 //              _buttonsBar                                     = NULL;
47 //              _gridPanel                                      = NULL; 
48 //              _drawToolsPanel                         = NULL;
49 //              _operationsToolsPanel           = NULL;
50                 //_autoFormsPanel                               = NULL; 
51 //              _standardToolsPanel                     = NULL;
52 //              _editionToolsPanel                      = NULL;
53 //              _listViewPanel                          = NULL;
54 //              _sceneManager                           = NULL;
55                 //_actualInstant                                = NULL;
56                 _numberOfVariablesStatistics = 6+1;
57
58                 // set up default notebook style
59 //              m_notebook_style =wxAUI_NB_TAB_SPLIT | wxAUI_NB_TAB_EXTERNAL_MOVE | wxNO_BORDER;
60 //              m_notebook_theme = 0;   
61                 //wxContour_ActionCommandsID a;
62
63         }
64
65         wxContourMainFrame :: wxContourMainFrame(wxWindow* parent, wxWindowID id,const wxString& title,const wxPoint& pos,const wxSize& size,std::vector<vtkImageData*> images, long style,std::string datadir)         
66                 : wxPanel(parent, id, pos, size, style)
67         {
68                 m_mgr.SetManagedWindow(this);
69                 _creatingContoursActive         = false;
70                 _theViewPanel                           = NULL;
71 //              _modelManager                           = NULL;
72                 _instantPanel                           = NULL;
73 //              _buttonsBar                                     = NULL;
74 //              _gridPanel                                      = NULL; 
75 //              _drawToolsPanel                         = NULL;
76 //              _operationsToolsPanel           = NULL;
77 //              _autoFormsPanel                         = NULL; 
78 //              _standardToolsPanel                     = NULL;
79 //              _editionToolsPanel                      = NULL;
80 //              _listViewPanel                          = NULL;
81 //              _sceneManager                           = NULL;
82                 //_actualInstant                                = NULL;
83
84                 // set up default notebook style
85                 m_notebook_style =wxAUI_NB_TAB_SPLIT | wxAUI_NB_TAB_EXTERNAL_MOVE | wxNO_BORDER;
86                 m_notebook_theme = 0;   
87                 //wxContour_ActionCommandsID a;
88                 _numberOfVariablesStatistics = 6+1;
89
90
91                 _performingOperation                    = new PerformingOperation();
92 //JCP 17 - 10 - 2008
93
94         inredo = 0;
95         inundo = 0;
96
97         kernelManager = new KernelManagerContour(images,datadir+"/data/");
98         //kernelManager->setVectImages(images);
99         //kernelManager->initializeEnvironment();
100                         
101         //vtkImageData* selectedimage = kernelManager->getVectImages()[0];
102         
103 //-------------------------------------------------------------
104
105         /*frame = new wxContourMainFrame(_builder->getImSourceEnv(), _builder->getImSectionEnv(), _builder->getAxesEnv(),  _builder->getContourEnv(),NULL, wxID_ANY, wxT("ROI Application Sample"), wxPoint(50,50), wxSize(800, 600)); 
106         frame->Show(TRUE);*/
107
108         //Creating the evtHandler of the panels
109         //wxContourEventHandler * eventHandler = new wxContourEventHandler();
110
111         //Creating the window that will show the panels
112
113         //Getting the parent for the panels ( using aui )
114         wxAuiNotebook * notebook = this->createNotebook();
115
116         //JCP 17 - 11 - 08
117         //wxInstantChooserPanel * instantPanel                          = new wxInstantChooserPanel( notebook, "Instant Chooser", true);
118         //JCP 17 - 11 - 08
119         std::vector<std::string> conceptNameVect;
120         std::vector<int> conceptSizeVect;
121         
122
123
124         _instantPanel                           = new wxInstantChooserPanel( notebook, "Instant Chooser", true, false, "c" );
125         _theViewPanel                           = new wxContourViewPanel( kernelManager->getSourceImage(), notebook );  
126
127
128
129     kernelManager->getConceptsInformation(conceptNameVect, conceptSizeVect);
130         _instantPanel->addConcepts(conceptNameVect, conceptSizeVect);
131                 
132
133         double val = _theViewPanel->getCurrentDeep();
134         _instantPanel->setConceptValue( "Axe Depth", (int)val );
135         //JCP _instantPanel->setConceptValue("time", num de imagenes);
136         ConceptDataWrap * data = _instantPanel->getConceptDataOf( "Axe Depth" );
137         //*******************changeInstant();
138         _theViewPanel->setVerticalConcept( "Axe Depth", data->getMinValue(), data->getMaxValue(), data->getMinShowedValue(),  data->getMaxShowedValue(), data->getActualValue() );
139
140         //eventHandler->setModelManager( kernelManager->getOutlineModelManager() );
141         //eventHandler->setViewPanel( _theViewPanel );
142         //_theViewPanel->initializeScenceManager();
143         //eventHandler->setInstantChooserPanel( _instantPanel );
144         
145         //bool successConfiuration = eventHandler->configureEventsHandling();
146
147         //successConfiuration &= this->configurePanels( notebook );
148         this->configurePanels( notebook );
149
150         interfMainPanel* pannew = interfMainPanel::getInstance(parent,datadir+"/data/Icons");//, eventHandler);
151
152 //JCP 17 -10 - 2008
153
154
155         }
156
157
158         wxContourMainFrame* wxContourMainFrame :: getInstance(wxWindow* parent, wxWindowID id,const wxString& title,const wxPoint& pos,const wxSize& size,std::vector<vtkImageData*> images, long style,std::string datadir ){
159                 if(instance == NULL){
160                         instance = new wxContourMainFrame(parent, id, title, pos, size, images, style,datadir);
161                 }
162                 return instance;
163         }
164
165         std::vector<vtkImageData*> wxContourMainFrame ::getVectImages(){
166                 return kernelManager->getVectImages();
167         }
168         wxContourMainFrame* wxContourMainFrame :: getInstance(){
169                 return instance;
170                 
171         }
172
173         wxContourMainFrame :: ~wxContourMainFrame()
174         {
175                   m_mgr.UnInit();
176                   //El problema al cerrar la aplicacion puede estar asociado 
177                   //a que  wxAUINotebook esta en la aplicacion 
178                   //principal (wxContourGUIExample)tambien
179 //EED????               delete _theViewPanel;             
180 //EED????               delete _instantPanel;
181 //EED????               delete _buttonsBar;
182 //EED????               delete _actualInstant;           
183 //EED????               delete _sceneManager;
184         }
185
186
187         //------------------------------------------------------------------------------------------------------------
188         // Creational and initialization methods using WxAui
189         //------------------------------------------------------------------------------------------------------------
190         //
191         wxAuiNotebook * wxContourMainFrame :: createNotebook()
192         {
193                 wxSize client_size = GetClientSize();
194                 wxAuiNotebook* noteBook = new wxAuiNotebook(this, -1, wxPoint(client_size.x, client_size.y), wxSize(430,200), m_notebook_style);
195                 wxBitmap page_bmp = wxArtProvider::GetBitmap(wxART_NORMAL_FILE, wxART_OTHER, wxSize(16,16));
196                 return noteBook;
197         }
198         
199
200         //------------------------------------------------------------------------------------------------------------
201         // Creational and initialization methods 
202         //------------------------------------------------------------------------------------------------------------
203         bool wxContourMainFrame :: configurePanels(wxAuiNotebook* theNoteBook)
204         {
205                 bool configured = _theViewPanel!=NULL;
206                                         
207                 configured &= _theViewPanel!=NULL;
208                 if( _theViewPanel!=NULL )
209                 {
210                         theNoteBook->AddPage( _theViewPanel, wxT("       View       ") );               
211                         m_mgr.Update();
212                 }
213
214
215                 if( configured )
216                 {
217                         theNoteBook->AddPage( _instantPanel, wxT("Instant Page") );
218                         m_mgr.Update();
219                 }
220
221                 m_mgr.AddPane(theNoteBook, wxAuiPaneInfo().Name(wxT("notebook_content")).CenterPane().PaneBorder(false));
222                 m_mgr.Update();
223 /*              configured &= _buttonsBar!=NULL;
224                 if( _buttonsBar!=NULL )
225                 {                       
226                         m_mgr.AddPane(_buttonsBar, wxAuiPaneInfo().
227                                         Name(wxT("TB")).Caption(wxT("Buttons Bar")).
228                                         ToolbarPane().Top().
229                                         LeftDockable(  ).RightDockable( false ).CloseButton(false));
230                         m_mgr.Update();
231                 }*/
232                 //CreateStatusBar();
233                          
234                 SetMinSize(wxSize(300,300));
235                 m_mgr.Update();
236                 return configured;
237         }
238
239         void wxContourMainFrame :: setNotebook( wxAuiNotebook * noteBook )
240         {
241
242         }
243
244         //------------------------------------------------------------------------------------------------------------
245         //  Attributes getters and setters
246         //------------------------------------------------------------------------------------------------------------
247         
248
249         
250         void wxContourMainFrame :: setInstantChooserPanel(  wxInstantChooserPanel * theInstantChooserPanel )
251         {
252                 _instantPanel = theInstantChooserPanel; 
253         }
254
255 //      void wxContourMainFrame :: setButtonsBar(  wxContour_ButtonsBar * theButtonsBar )
256 //      {
257 //              _buttonsBar = theButtonsBar;
258 //      }
259
260 //      void wxContourMainFrame :: setGrid(  wxContour_Grid * theGridPanel )
261 //      {
262 //              _gridPanel = theGridPanel;
263 //      }
264
265 //      void wxContourMainFrame :: setDrawToolsPanel(  wxContour_DrawToolsPanel * theDrawToolsPanel )
266 //      {
267 //              _drawToolsPanel = theDrawToolsPanel;
268 //      }
269
270 //      void wxContourMainFrame :: setOperationsToolsPanel(  wxContour_OperationsToolsPanel * theOperationsToolsPanel )
271 //      {       
272 //              _operationsToolsPanel = theOperationsToolsPanel;
273 //      }
274
275 //      void wxContourMainFrame :: setAutomaticFormsPanel(  wxContour_AutomaticFormsToolsPanel * theAutoFormsPanel )
276 //      {
277 //              _autoFormsPanel = theAutoFormsPanel;
278 //      }
279
280 //      void wxContourMainFrame :: setStandardToolsPanel(  wxContour_StandardToolsPanel * theStandardToolsPanel )
281 //      {
282 //              _standardToolsPanel= theStandardToolsPanel;
283 //      }
284
285 //      void wxContourMainFrame :: setEditionToolsPanel(  wxContour_EdtionToolsPanel * theEditionToolsPanel )
286 //      {
287 //              _editionToolsPanel =  theEditionToolsPanel;
288 //      }
289
290 //      void wxContourMainFrame :: setListViewPanel(  wxContour_ListViewPanel * theListViewPanel )
291 //      {
292 //              _listViewPanel = theListViewPanel;
293 //      }
294
295
296
297 void wxContourMainFrame::onCreateContourSpline( ){
298         
299         //JCP 20-10-08 Undo redo implementation
300         saveState();
301         //JCP 20-10-08 Undo redo implementation
302         createContour( 1 );
303         
304 }
305 void wxContourMainFrame::onCreateContourRectangle( ){
306     //JCP 20-10-08 Undo redo implementation
307         saveState();
308         //JCP 20-10-08 Undo redo implementation 
309         createContour( 2 );
310 }
311 void wxContourMainFrame::onCreateContourCircle( ){
312     //JCP 20-10-08 Undo redo implementation
313         saveState();
314         //JCP 20-10-08 Undo redo implementation 
315         createContour( 3 );
316 }
317
318 void wxContourMainFrame::onCreateContourLine( ){
319     //JCP 20-10-08 Undo redo implementation
320         saveState();
321         //JCP 20-10-08 Undo redo implementation 
322         createContour( 6 );
323 }
324
325 //------------------------------------------------------------------------------------------------------------
326
327 void wxContourMainFrame :: onCreateContourBullEye(wxPanel* panel )
328 {
329         //Creating the manualContourModel and including in the model
330         manualContourModel * manModelContour = factoryManualContourModel(panel );
331
332         std::vector<int> instantVector;
333         _instantPanel->getInstant( instantVector );
334         std::string theName = kernelManager->createOutline(manModelContour, instantVector);
335         
336         /*std::vector<int> instantVector;
337         _instantPanel->getInstant( instantVector );
338         std::string theName;
339         theName= _modelManager->createOutline( manModelContour, instantVector );*/
340         bool addedModel = theName.compare("") != 0;//??
341
342         if( addedModel )
343         {
344                 double spc[3];//Si no hay imagen pero hay contornos que spacing se pone por default
345                 _theViewPanel->getSpacing(spc);                                 
346                 //Adding the manualContourControler to interface objects structure
347                 //Adding the manualViewContour to interface objects structure           
348                 //_theViewPanel->getSceneManager()->setControlActiveStateOfALL( false );//This call is being done here because if the ROI is created underneath the previously created ROIS will still be active.
349                 _theViewPanel->getSceneManager()->configureViewControlTo( theName, manModelContour,spc , 4) ;
350         }
351 }
352 void wxContourMainFrame :: createContour( int typeContour )
353 {
354         //Creating the manualContourModel and including in the model
355         manualContourModel * manModelContour = kernelManager->factoryManualContourModel(typeContour);
356
357
358         std::vector<int> instantVector;
359         _instantPanel->getInstant( instantVector );
360         std::string theName = kernelManager->createOutline(manModelContour, instantVector);
361         
362         /*std::vector<int> instantVector;
363         _instantPanel->getInstant( instantVector );
364         std::string theName;
365         theName= _modelManager->createOutline( manModelContour, instantVector );*/
366         bool addedModel = theName.compare("") != 0;//??
367         if( addedModel )
368         {
369                 double spc[3];//Si no hay imagen pero hay contornos que spacing se pone por default
370                 _theViewPanel->getSpacing(spc);                                 
371                 //Adding the manualContourControler to interface objects structure
372                 //Adding the manualViewContour to interface objects structure           
373                 //_sceneManager->setControlActiveStateOfALL( false );//This call is being done here because if the ROI is created underneath the previously created ROIS will still be active.
374                 _theViewPanel->getSceneManager()->configureViewControlTo( theName, manModelContour,spc , typeContour) ;
375         }       
376
377 }
378 manualContourModel * wxContourMainFrame::factoryManualContourModel(wxPanel* panel){
379
380         manualContourModelBullEye *manModelContourBullEye = new manualContourModelBullEye();
381         manualContourModel *manModelContour=NULL;
382         manModelContour = manModelContourBullEye;
383         if (panel!=NULL){
384                 int iCrown,sizeCrowns,iSector,sizeSectors;
385                 double radioA,radioB,ang,angDelta ;
386                 sizeCrowns = ((PanelBullEyeOptions*)panel)->GetNumberOfCrowns();
387                 for ( iCrown=0 ; iCrown<sizeCrowns ; iCrown++ )
388                 {
389                         sizeSectors = ((PanelBullEyeOptions*)panel)->GetNumberOfSections(iCrown);
390                         radioB  = ((PanelBullEyeOptions*)panel)->GetRadioOfCrown(iCrown);
391                         if (iCrown==sizeCrowns-1)
392                         {
393                                 radioA  = 0;
394                         } else {
395                                 radioA  = ((PanelBullEyeOptions*)panel)->GetRadioOfCrown(iCrown+1);
396                         }
397                         radioA=radioA/100.0;
398                         radioB=radioB/100.0;
399                         for ( iSector=0 ; iSector<sizeSectors  ; iSector++ )
400                         {
401                                 ang             = ((PanelBullEyeOptions*)panel)->GetAngOfCrownSection(iCrown,iSector);
402                                 angDelta= ((PanelBullEyeOptions*)panel)->GetAngDeltaOfCrownSection(iCrown);                                     
403                                 manModelContourBullEye->AddSector(radioA,radioB,ang,angDelta);
404                         } // for iSector
405                 } // for iCrown
406         } // if _panelBullEyeOptions
407         
408         return manModelContour;
409 }
410 void wxContourMainFrame :: saveState(){ 
411                 
412         std::string temp = kernelManager->saveState();
413         saveFileWithContours(temp);     
414 }
415
416 void wxContourMainFrame::onDeleteContour(){
417         //JCP 20-10-08 Undo redo implementation
418                 saveState();
419                 //JCP 20-10-08 Undo redo implementation
420
421                 std::vector<std::string> lstKeyNameToBeErase;
422                 lstKeyNameToBeErase             = _theViewPanel->getSceneManager()->getSelectedObjects();
423                 deleteContours( lstKeyNameToBeErase );
424 /*JCP 19 - 11 - 08
425                 int i,size=_sceneManager->getSelectedObjects().size();
426                 for(i=0;i<size;i++)
427                 {
428                         std::string keyName             = _sceneManager->getSelectedObjects()[i];
429                         int ispartofstaticlist  = this->_modelManager->IsPartOfStaticList( keyName );
430                         if ( ispartofstaticlist>=0 )
431                         {
432                                 std::vector<int> tempVector;
433                                 _instantPanel->getInstant( tempVector );
434                                 Instant instant(&tempVector);
435                                 this->_modelManager->ChangeContourOfList(keyName, &instant);
436                         }
437                 }
438
439                 std::vector<std::string> lstKeyName;
440                 std::vector<std::string> lstKeyNameActualSlice;
441                 std::vector<std::string> lstKeyNameToBeErase;
442
443                 lstKeyNameToBeErase             = _sceneManager->getSelectedObjects();
444                 lstKeyNameActualSlice   = _sceneManager->GetlstContoursNameActualSlice();
445                 int k,kSize=lstKeyNameToBeErase.size();
446                 int j,jSize=lstKeyNameActualSlice.size();
447                 bool ok;
448                 for (k=0;k<kSize; k++)
449                 {
450                         ok=false;
451                         for (j=0;j<jSize; j++)
452                         {
453                                 if (lstKeyNameToBeErase[k]==lstKeyNameActualSlice[j])
454                                 { 
455                                         ok=true;
456                                 }
457                         } // for j
458                         if (ok==true)
459                         {
460                                 lstKeyName.push_back( lstKeyNameToBeErase[k] );
461                         } // if ok
462                 } // for k
463
464                 deleteContours( lstKeyName );
465 JCP 19 - 11 - 08*/
466 }
467
468 void wxContourMainFrame :: deleteContours( std::vector<std::string>  keyNamesVector )
469 {
470         int i,size=keyNamesVector.size();
471         for (i=0;i<size;i++)
472         {
473                 deleteContour( keyNamesVector[i] );
474         }
475 }
476
477 void wxContourMainFrame :: deleteContour( std::string theKeyName ){
478         /*manualContourModel                    * cModel;
479         manualViewBaseContour           * cViewer;
480         manualContourBaseControler      * cControler;
481
482         ContourWrap_ViewControl *conwrapviewControl =  _theViewPanel->getSceneManager()->getContourWrap_ViewControlOf( theKeyName );
483         cControler      = conwrapviewControl->getControler();*/
484
485         //JCP 21 - 11 - 2008
486         bool isedit = _theViewPanel->isEditableCControler(theKeyName);
487         bool ispartofstaticlst = kernelManager->IsPartOfStaticList(theKeyName);
488
489         if (isedit  && ispartofstaticlst)
490         {
491                 _theViewPanel->removeFromScene(theKeyName);
492
493                 kernelManager->deleteCModel(theKeyName);
494                 //_theViewPanel->getSceneManager()->removeFromScene( theKeyName );                      
495                 //cViewer               = conwrapviewControl->getViewer();
496                 //_theViewPanel->getSceneManager()->removeWrap( theKeyName );
497                 //cControler* conwrapviewControl->getControler();                       
498 //EED Borrame
499 //FILE *ff = fopen("c:/temp/wxVtkBaseView_SceneManagerStadistics.txt","a+");
500 //fprintf(ff,"EED wxContourEventHandler::deleteContours() \n" );
501 //fprintf(ff,"    %s %p\n",keyNamesVector[i].c_str(),  cControler );
502 //fclose(ff);
503         //      delete cModel;
504         //      delete cViewer;
505         //      delete cControler;
506         } // if editable
507 //JCP 21 - 11 - 08
508 }
509
510 void wxContourMainFrame::onDeleteContoursActSlice(){
511         //JCP 20-10-08 Undo redo implementation
512         saveState();
513         //JCP 20-10-08 Undo redo implementation
514         deleteContours( (std::vector<std::string>)_theViewPanel->getSceneManager()->GetlstContoursNameActualSlice() );
515 }
516 void wxContourMainFrame::onDeleteAllContours(){
517         //JCP 20-10-08 Undo redo implementation
518         saveState();
519         deleteAllContours();
520 }
521 void wxContourMainFrame::deleteAllContours(){
522         //JCP 20-10-08 Undo redo implementation
523
524         wxBusyCursor wait;
525         std::vector<int> tempVector;
526         _instantPanel->getInstant( tempVector );
527
528 //JCP --08-09-2008 When using a diferent interface the _mbarrangeDeleteAll might not be initialize
529 //              the values in GetStart and GetEnd will then not be initialize also.
530 //              We use instead the values given when initializing the _deletepanel.
531
532         //int minZ = _mbarrangeDeleteAll->GetStart();
533         //int maxZ = _mbarrangeDeleteAll->GetEnd();
534         int minZ, maxZ;
535         
536         minZ = 0;
537         maxZ = _theViewPanel->getSceneManager()->GetImageDataSizeZ();
538         
539 //JCP --08-09-2008
540         
541         _theViewPanel->getSceneManager()->removeSceneContours( );       
542         _theViewPanel->getSceneManager()->removeAllOutlines();
543         kernelManager->removeAllOutlines();     
544 //JCP --08-09-2008
545         /*
546         if ( (minZ==0) && (maxZ==_mbarrangeDeleteAll->GetMax() ))
547         {
548                 _theViewPanel->getSceneManager()->removeSceneContours( );
549                 _modelManager->removeAllOutlines();
550                 _theViewPanel->getSceneManager()->removeAllOutlines();
551
552         } else {
553                 for ( z=minZ ; z<=maxZ ; z++)
554                 {
555                         tempVector[1]=z;
556                         Instant instant(&tempVector);
557                         std::vector<ContourThing**> lstContourThings = this->_modelManager->getOutlinesAtInstant( &instant );
558
559                         sizeLstContourThings = lstContourThings.size();
560                         for (ii=0 ; ii<sizeLstContourThings ; ii++)
561                         {
562                                 ContourThing **contourthing = lstContourThings[ii];
563                                 deleteContour( (*contourthing)->getName() );
564                         } //for ii
565                 }// for z
566         } // if 
567 JCP --08-09-2008 */
568 }
569
570 void wxContourMainFrame::setConceptValue( std::string name, int value ){
571         _instantPanel->setConceptValue(name, value);
572 }
573
574 ConceptDataWrap* wxContourMainFrame::getLastConceptData(){
575         return _instantPanel->getLastConceptData();
576 }
577 bool wxContourMainFrame::getIfConceptCheckedAt( std::string name, int pos ){
578         return _instantPanel->getIfConceptCheckedAt( name, pos );
579 }
580
581 void wxContourMainFrame::changeInstant(){
582                 std::vector<int> instantVect;
583                 _instantPanel->getInstant( instantVect );
584 //              Instant * theInstant = new Instant ( &instantVect );
585                 
586                 //Setting the actual instant
587                 //_actualInstant = theInstant;
588
589                 kernelManager->setInstant(instantVect);
590                 //_modelManager->setInstant( _actualInstant );
591                 
592                 updateInstantOutlines();
593                 updateInstantImageData();
594                 updateInstantAxes();
595
596                 
597 }
598 void wxContourMainFrame :: updateInstantOutlines(){
599         
600         _theViewPanel->removeSceneContours();
601         _theViewPanel->addNameWrapperToScene();
602
603         //for( int i=0; i<size; i++)
604         //{                     
605         //      _theViewPanel->getSceneManager()->addToScene(namesWrapping[i]->getKeyName(), true, true, true, false, false );
606         //}
607 }
608
609 int wxContourMainFrame::getNamesWrappingSize(){
610         return kernelManager->getNamesWrappingSize();
611 }
612 std::string wxContourMainFrame::getNameWrapping(int i){
613         return kernelManager->getNameWrapping(i);
614 }
615
616 void wxContourMainFrame::updateInstantImageData(){
617         std::vector<int> inst;
618         _instantPanel->getInstant(inst);
619
620         vtkImageData* img = kernelManager->getImageAtInstant(inst);
621         if(img!=NULL){
622                 _theViewPanel->changeImage(img);
623                 showAxis(false);
624         }else{
625                 int z = _instantPanel->getConceptDataOf("Axe Depth")->getActualValue();
626                 _theViewPanel->setImageSlice(z);
627         }
628 }
629 void wxContourMainFrame::updateInstantAxes(){
630 }
631
632 void wxContourMainFrame::onChangeDeep(int val){
633         _instantPanel->setConceptValue( "Axe Depth", (int)val );        
634         changeInstant();
635 }
636
637
638 void wxContourMainFrame::onCopy(){
639         std::vector<std::string> currentSelection = _theViewPanel->getSelectedObjects();
640
641         std::vector<int> tempVector;
642         _instantPanel->getInstant( tempVector );
643     _performingOperation->reset();
644         _performingOperation->setStartCommand( COPY );
645         _performingOperation->setStartOperationInstantVector( tempVector );
646         _performingOperation->setKeyNamesOperationElems( currentSelection );
647 }
648
649 void wxContourMainFrame::onPaste(){
650
651
652         char theStartCommand = _performingOperation->getStartCommand();
653         if (  theStartCommand == COPY )
654         {
655                 //JCP 20-10-08 Undo redo implementation
656                 saveState();
657                 //JCP 20-10-08 Undo redo implementation
658                 std::vector<int> tempVector;
659                 _instantPanel->getInstant( tempVector );
660                 _performingOperation->setEndOperationInstantVector ( tempVector );
661                 std::vector<std::string> elems = _performingOperation->getKeyNamesOperationElems();
662                 int i,size = elems.size();                      
663                 for( i=0; i<size; i++ )
664                 {                               
665                         createCopyContourOf( elems[i], tempVector, i>0 );
666                 }               
667         }
668 }
669 void wxContourMainFrame::onUndo(){
670         std::string filename;
671         if(kernelManager->onUndoSaveFile(filename)){
672                 saveFileWithContours(filename);
673         }
674         if(kernelManager->onUndo(filename)){
675                 loadState(filename);
676         }
677 }
678 void wxContourMainFrame::onRedo(){
679         std::string filename;
680         if(kernelManager->onRedo(filename)){
681                 loadState(filename);
682         }
683         
684 }
685 void wxContourMainFrame :: createCopyContourOf ( std::string anExistingKName, std::vector<int> &instantNoTouchData, bool append ){
686         std::string cloneName = kernelManager->createCopyContourOf( anExistingKName, instantNoTouchData );
687         manualContourModel * manualModel = kernelManager->getOutlineByKeyName(cloneName);//_modelManager->getOutlineByKeyName( cloneName )->getModel();
688         _theViewPanel->getSceneManager()->createCopyContourOf( anExistingKName, cloneName, manualModel , append );
689 }
690
691 void wxContourMainFrame ::loadState(std::string filename){
692         char tmp[255];
693         FILE *pFile=fopen(filename.c_str(),"r+");
694
695         fscanf(pFile,"%s",tmp); // --CreaContour--
696
697         fscanf(pFile,"%s",tmp); // Version
698         fscanf(pFile,"%s",tmp); // 1.0.1
699         std::string version(tmp);
700
701         deleteAllContours();
702
703         openContours(pFile,false);
704         if (version!="1.0.0"){
705                 openContours(pFile,true);
706         }
707
708         fclose(pFile);
709         
710         //_theViewPanel->getSceneManager()->removeSceneContours();
711         //changeInstant();
712
713 }
714
715 void wxContourMainFrame::onLoad(){
716         char tmp[255];
717         wxFileDialog dialog(NULL, _T("Choose a file"), _T(""), _T(""), _T("*.roi"), wxOPEN );
718         if (dialog.ShowModal() == wxID_OK)
719         {
720                 std::string fileNameContourROI = (const char *)(dialog.GetPath().mb_str());
721                 FILE *pFile=fopen(fileNameContourROI.c_str(),"r+");
722
723                 fscanf(pFile,"%s",tmp); // --CreaContour--
724
725                 fscanf(pFile,"%s",tmp); // Version
726                 fscanf(pFile,"%s",tmp); // 1.0.1
727                 std::string version(tmp);
728
729                 openContours(pFile,false);
730                 if (version!="1.0.0"){
731                         openContours(pFile,true);
732                 }
733 //                        _theViewPanel->getSceneManager()->openFileWithContours(ff);
734
735                 fclose(pFile);
736         }
737         _theViewPanel->getSceneManager()->removeSceneContours();
738         changeInstant();
739 }
740 void wxContourMainFrame::onSave(){
741         wxFileDialog dialog(NULL, _T("Choose a file"), _T(""), _T(""), _T("*.roi"), wxSAVE );
742         if (dialog.ShowModal() == wxID_OK)
743         {
744                 std::string fileNameContourROI = (const char *)(dialog.GetPath().mb_str());
745                 kernelManager->setCurrentFileName(fileNameContourROI);
746                 saveFileWithContours( fileNameContourROI );
747         }
748 }
749 void wxContourMainFrame::saveFileWithContours( std::string filename ){
750
751         FILE *pFile=fopen(filename.c_str(),"w+");
752         std::vector< std::string > lstNameThings;
753         int i,sizeLstNameThings; 
754
755         fprintf(pFile,"--CreaContour--\n");
756         fprintf(pFile,"Version %s\n", "1.0.1" );
757
758         // Normal Contours
759         lstNameThings           = kernelManager->GetLstNameThings();
760         sizeLstNameThings       = lstNameThings.size(); 
761         fprintf(pFile,"NumberOfContours %d\n", sizeLstNameThings );
762         for (i=0 ; i<sizeLstNameThings ; i++) 
763         {
764                 kernelManager->SaveThingName( pFile, lstNameThings[i] );
765                 _theViewPanel->getSceneManager()->SaveThingName( pFile, lstNameThings[i] );
766         }// for i
767
768         //-- Contours Statics 
769         lstNameThings           = kernelManager->GetLstNameThingsStatic();
770         sizeLstNameThings       = lstNameThings.size(); 
771         fprintf(pFile,"NumberOfContoursStatic %d\n", sizeLstNameThings );
772         for (i=0 ; i<sizeLstNameThings ; i++) 
773         {
774                 kernelManager->SaveThingName( pFile, lstNameThings[i] );
775                 _theViewPanel->getSceneManager()->SaveThingName( pFile, lstNameThings[i] );
776         }// for i
777         fclose(pFile);
778 }
779
780 void wxContourMainFrame::openContours( FILE *pFile, bool staticContour ){
781         char tmp[255];
782         fscanf(pFile,"%s",tmp); // NumberOfContours 
783         fscanf(pFile,"%s",tmp); // ##
784         int numberOfContours = atoi(tmp);  
785
786         std::vector<int> instantVector;
787         int typeContourModel;
788         manualContourModel *manModelContour;
789         int typeView;
790
791         int i;
792         for (i=0;i<numberOfContours;i++)
793         {
794                 instantVector.clear();
795                 fscanf(pFile,"%s",tmp); // Instant
796
797                 fscanf(pFile,"%s",tmp); // 1
798                 instantVector.push_back( atoi(tmp) );
799                 fscanf(pFile,"%s",tmp); // 2
800                 instantVector.push_back( atoi(tmp) );
801                 fscanf(pFile,"%s",tmp); // 3
802                 instantVector.push_back( atoi(tmp) );
803                 fscanf(pFile,"%s",tmp); // 4
804                 instantVector.push_back( atoi(tmp) );
805                 fscanf(pFile,"%s",tmp); // 5
806                 instantVector.push_back( atoi(tmp) );
807                 fscanf(pFile,"%s",tmp); // 6
808                 instantVector.push_back( atoi(tmp) );
809
810
811                 fscanf(pFile,"%s",tmp); // TypeContourModel
812                 fscanf(pFile,"%s",tmp); // ##
813                 typeContourModel = atoi(tmp);
814
815                 manModelContour =  kernelManager->factoryManualContourModel(typeContourModel);
816                 manModelContour->Open(pFile);
817
818                 fscanf(pFile,"%s",tmp); // TypeView
819                 fscanf(pFile,"%s",tmp); // ##
820                 typeView = atoi(tmp);  
821
822
823 //                      if (typeView==1) 
824 //                      {
825 //                      }
826
827
828                 std::string theName;
829                 theName = kernelManager->createOutline( manModelContour, instantVector );
830                 bool addedModel = theName.compare("") != 0;
831                 if( addedModel )
832                 {
833                         double spc[3];//Si no hay imagen pero hay contornos que spacing se pone por default
834                         _theViewPanel->getSpacing(spc);                                 
835                         //Adding the manualContourControler to interface objects structure
836                         //Adding the manualViewContour to interface objects structure           
837                         //_theViewPanel->getSceneManager()->setControlActiveStateOfALL( false );//This call is being done here because if the ROI is created underneath the previously created ROIS will still be active.
838                         _theViewPanel->getSceneManager()->configureViewControlTo( theName, manModelContour,spc , typeView) ;
839                 }       
840
841                 if (staticContour==true)
842                 {
843                         Instant instant(&instantVector);
844                         kernelManager->changeContourOfManager( theName , &instant );
845                 }
846
847         }// for  numberOfContours
848
849 }
850
851 void wxContourMainFrame::RefreshInterface(){
852         changeInstant();
853         _theViewPanel->RefreshInterface();
854         //wxVtk2DBaseView *wxvtk2dbaseview = (wxVtk2DBaseView*)this->_theViewPanel->getWxVtkBaseView();
855         //wxvtk2dbaseview->Refresh();
856 }
857
858 vtkImageData* wxContourMainFrame::getImageData(){
859         return _theViewPanel->getImageData();
860 }
861
862 void wxContourMainFrame::onSegmentationOneSlice(int isovalue,int sampling,int method){
863         
864         //JCP 20-10-08 Undo redo implementation
865         saveState();
866         //JCP 20-10-08 Undo redo implementation
867         
868         wxBusyCursor wait;
869         int                                     x                                       = _theViewPanel->GetX();
870         int                                     y                                       = _theViewPanel->GetY();
871         int                                     z                                       = _theViewPanel->GetZ();
872         SegmentationOneSlice( x,y,z,isovalue, sampling, method );
873         RefreshInterface();
874 }
875
876
877 void wxContourMainFrame::SegmentationOneSlice( int x, int y, int z, int isovalue, int sampling, int method )
878 {               
879         int typeofcontour = 1;
880         //--Extracting Contour
881         //vtkImageData  *imagedata      = _theViewPanel->getSceneManager()->GetImageData();
882         vtkImageData    *imagedata      = getImageData();
883 //              double                  *range          = imagedata->GetScalarRange();  
884 //              double                  thr                     = 1;
885
886         vtkImageReslice *imageReslice = vtkImageReslice::New();
887 //EED
888 //              double spc[3];
889 //              imagedata->GetSpacing(spc);
890 //              x = x*spc[0];
891 //              y = y*spc[1];
892 //              z = z*spc[3];
893
894         imageReslice->SetInput( imagedata );
895         imageReslice->SetInformationInput(imagedata);
896         imageReslice->SetResliceAxesDirectionCosines(1,0,0, 0,1,0 ,0,0,1);
897         imageReslice->SetResliceAxesOrigin(0,0,z);
898         imageReslice->SetOutputDimensionality(2);
899         imageReslice->SetInterpolationModeToLinear();
900
901         imagedata = imageReslice->GetOutput();
902         imagedata->Update();
903         imagedata->UpdateInformation();
904
905         vtkContourFilter* cntVTK = vtkContourFilter::New( );
906         cntVTK->SetInput( imagedata );
907
908         cntVTK->SetNumberOfContours( 1 );
909         //cntVTK->SetValue( 0, vmin );
910 //              cntVTK->SetValue( 0, (range[1]*thr/100) );
911         cntVTK->SetValue( 1, isovalue );
912 //      cntVTK->SetValue( 1, vmax );
913         cntVTK->Update( );
914         cntVTK->UpdateInformation();
915                 
916         vtkCleanPolyData* cpd = vtkCleanPolyData::New( );
917         cpd->SetInput( cntVTK->GetOutput( ) );
918         cpd->ConvertLinesToPointsOff( );
919         cpd->Update( );
920         cpd->UpdateInformation();
921
922         vtkPolyDataConnectivityFilter* conn = vtkPolyDataConnectivityFilter::New( );
923         conn->SetExtractionModeToClosestPointRegion( );
924         //conn->SetMaxRecursionDepth( 3000 );
925                 
926         conn->SetInput( cpd->GetOutput( ) );
927                 
928         conn->SetClosestPoint( x, y, 0 );
929         conn->Update( );
930         conn->UpdateInformation();
931                 
932         vtkCleanPolyData* cpd2 = vtkCleanPolyData::New( );
933         cpd2->SetInput( conn->GetOutput( ) );
934         cpd2->Update();
935         cpd2->UpdateInformation();
936
937         vtkStripper* vtkstripper = vtkStripper::New( );
938         vtkstripper->SetInput( cpd2->GetOutput() );
939         vtkstripper->Update();
940         vtkstripper->UpdateInformation();
941
942
943         vtkPolyData* polyDataResult =  vtkstripper->GetOutput();
944
945         polyDataResult->Update( );
946         polyDataResult->UpdateInformation();
947
948 /* EED
949 ofstream myfile;
950 myfile.open ("c:/temp/example.txt");
951 myfile << "\n";
952 polyDataResult->Print(myfile);
953 myfile << "-------------------------------------\n";
954 polyDataResult->GetLines()->Print(myfile);
955 myfile.close();
956 */
957
958         cntVTK          -> Delete();
959         cpd2            -> Delete();
960         cpd                     -> Delete();
961         conn            -> Delete();
962
963
964 //--Calculating control points
965
966         std::vector<double> vecX;
967         std::vector<double> vecY;
968         std::vector<double> vecZ;
969
970         std::vector<double> vecCtrlPointX;
971         std::vector<double> vecCtrlPointY;
972         std::vector<double> vecCtrlPointZ;
973
974
975         double *p;
976         int ii,size=polyDataResult->GetNumberOfPoints();
977         int id;
978         for (ii=1;ii<=size;ii++)
979         {
980                 id      = polyDataResult->GetLines()->GetData()->GetValue(ii);
981                 p       = polyDataResult->GetPoint(id);
982                 double x=p[0];
983                 double y=p[1];
984                 vecX.push_back( p[0] );
985                 vecY.push_back( p[1] );
986                 vecZ.push_back( -900 );
987 //                      vecZ.push_back( p[2] );
988         }
989
990
991         ExtractControlPoints2D *extractcontrolpoints2d = new ExtractControlPoints2D();
992         extractcontrolpoints2d->SetContour( &vecX , &vecY , &vecZ );
993
994 //PROOFS
995         /*if (methodRadiobox->GetSelection()==0){
996                 extractcontrolpoints2d->GetInitialControlPoints( &vecCtrlPointX , &vecCtrlPointY , &vecCtrlPointZ );
997         }
998         if (methodRadiobox->GetSelection()==1){
999                 extractcontrolpoints2d->GetControlPoints(  &vecCtrlPointX , &vecCtrlPointY , &vecCtrlPointZ );
1000         }
1001         if (methodRadiobox->GetSelection()==2){
1002                 extractcontrolpoints2d->SetSamplingControlPoints( sampling );
1003                 extractcontrolpoints2d->GetSamplingControlPoints(  &vecCtrlPointX , &vecCtrlPointY , &vecCtrlPointZ );
1004         }*/
1005
1006         if (method==0){
1007                 extractcontrolpoints2d->GetInitialControlPoints( &vecCtrlPointX , &vecCtrlPointY , &vecCtrlPointZ );
1008         }
1009         else if (method==1){
1010                 extractcontrolpoints2d->GetControlPoints(  &vecCtrlPointX , &vecCtrlPointY , &vecCtrlPointZ );
1011         }
1012         else if (method==2){
1013                 extractcontrolpoints2d->SetSamplingControlPoints( sampling );
1014                 extractcontrolpoints2d->GetSamplingControlPoints(  &vecCtrlPointX , &vecCtrlPointY , &vecCtrlPointZ );
1015         }
1016
1017         //--Adding contour to the system
1018
1019         std::vector<int> actualInstantVector;
1020         _instantPanel->getInstant( actualInstantVector );
1021         actualInstantVector[1]=z;
1022
1023         int j,sizeCtrPt = vecCtrlPointX.size();
1024         manualContourModel *manModelContour =  kernelManager->factoryManualContourModel( typeofcontour );
1025         manModelContour->SetNumberOfPointsSpline( ((sizeCtrPt/100)+1)*100 );
1026         if (sizeCtrPt>=3){
1027                 for (j=0 ; j<sizeCtrPt ; j++)
1028                 {
1029                         manModelContour->AddPoint( vecCtrlPointX[j] , vecCtrlPointY[j] , vecCtrlPointZ[j]  );
1030                 } // for
1031                 std::string theName;
1032                 //theName = _modelManager->createOutline( manModelContour, actualInstantVector );
1033                 theName = kernelManager->createOutline( manModelContour, actualInstantVector );
1034                 bool addedModel = theName.compare("") != 0;
1035                 if( addedModel )
1036                 {
1037                         double spc[3];//Si no hay imagen pero hay contornos que spacing se pone por default
1038                         _theViewPanel->getSpacing(spc);                                 
1039                         //Adding the manualContourControler to interface objects structure
1040                         //Adding the manualViewContour to interface objects structure           
1041                         //_theViewPanel->getSceneManager()->setControlActiveStateOfALL( false );//This call is being done here because if the ROI is created underneath the previously created ROIS will still be active.
1042                         _theViewPanel->configureViewControlTo(theName, manModelContour, spc, typeofcontour);
1043                         //_theViewPanel->getSceneManager()->configureViewControlTo( theName, manModelContour,spc, typeofcontour ) ;
1044                 }       // if addedModel
1045         } // if sizeCtrPt
1046 }
1047
1048 int wxContourMainFrame::GetImageDataSizeZ(){
1049         return _theViewPanel->GetImageDataSizeZ();
1050 }
1051
1052 void wxContourMainFrame::GetImageDataRange(double *range){
1053         _theViewPanel->GetImageDataRange(range);
1054 }
1055
1056 void wxContourMainFrame::onSegmentationAllSlice(int minZ,int maxZ,int isovalue,int sampling,int method){
1057         //JCP 20-10-08 Undo redo implementation
1058         saveState();
1059         //JCP 20-10-08 Undo redo implementation
1060         
1061         wxBusyCursor wait;
1062         int                                     x                                       = _theViewPanel->GetX();
1063         int                                     y                                       = _theViewPanel->GetY();
1064         int z;
1065         double porcent; 
1066         wxString tmpString;     
1067         double totalZ = maxZ-minZ+1;
1068         for( z=minZ ; z<=maxZ ; z++ )
1069         {
1070                 porcent = 100.0* (z-minZ)/totalZ;
1071                 tmpString.Printf(_T("  %d %c            %d/%d            %d"), (int)porcent , 37 , z-minZ+1, (int)totalZ,z );
1072                 interfMainPanel::getInstance()->setLabelSegmentationPanelVTK(tmpString);
1073                 //_staticTextSegmentation->SetLabel(tmpString);
1074                 SegmentationOneSlice( x,y,z,isovalue, sampling,method );
1075         }
1076         interfMainPanel::getInstance()->setLabelSegmentationPanelVTK(_T("   "));
1077         RefreshInterface();
1078 }
1079
1080 void wxContourMainFrame::onMirror()
1081 {
1082         //AD:02-09
1083         std::vector<std::string> currentSelection = _theViewPanel->getSelectedObjects();
1084
1085         std::vector<int> tempVector;
1086         _instantPanel->getInstant( tempVector );
1087     _performingOperation->reset();
1088         _performingOperation->setStartCommand( COPY );
1089         _performingOperation->setStartOperationInstantVector( tempVector );
1090         _performingOperation->setKeyNamesOperationElems( currentSelection );
1091
1092         //AD:02-09
1093         char theStartCommand = _performingOperation->getStartCommand();
1094         if (  theStartCommand == COPY )
1095         {
1096                 //JCP 20-10-08 Undo redo implementation
1097                 saveState();
1098                 //JCP 20-10-08 Undo redo implementation
1099                 std::vector<int> tempVector;
1100                 _instantPanel->getInstant( tempVector );
1101                 _performingOperation->setEndOperationInstantVector ( tempVector );
1102                 std::vector<std::string> elems = _performingOperation->getKeyNamesOperationElems();
1103                 int i,size = elems.size();                      
1104                 for( i=0; i<size; i++ )
1105                 {                               
1106                         createCopyContourOf( elems[i], tempVector, i>0 );
1107                 }               
1108         }
1109 }
1110
1111 void wxContourMainFrame::showAxis(bool show){
1112         _theViewPanel->SetVisibleAxis(show);
1113         _theViewPanel->Refresh();
1114 }
1115
1116
1117 void wxContourMainFrame::onRigidPressed(){
1118         std::vector<std::string> currentSelection = _theViewPanel->getSelectedObjects();
1119         int elementsSelected = currentSelection.size();
1120
1121         if ( elementsSelected >= 1 ){
1122                 //JCP 20-10-08 Undo redo implementation
1123                 saveState();
1124                 //JCP 20-10-08 Undo redo implementation
1125
1126                 std::vector<int> tempVector;
1127                 _instantPanel->getInstant( tempVector );
1128                 Instant instant(&tempVector);
1129
1130                 int i , size=currentSelection.size();
1131                 for ( i=0 ; i<size ; i++ )
1132                 {
1133                         kernelManager->changeContourOfManager(currentSelection[i], &instant);
1134                 } // i
1135         }
1136 }
1137
1138 void wxContourMainFrame::onWidthOfContour(double width){
1139
1140         _theViewPanel->removeSceneContours();
1141         _theViewPanel->SetWidthContour(width);
1142         
1143         //_theViewPanel->getSceneManager()->SetWidthContour( width );
1144
1145         RefreshInterface();
1146 }
1147 int wxContourMainFrame::getColorWindow(){
1148         return _theViewPanel->getColorWindow();
1149 }
1150 int wxContourMainFrame::getWindowLevel(){
1151         return _theViewPanel->getWindowLevel();
1152 }
1153
1154 void wxContourMainFrame::onBrigthnessColorWindowLevel(int colorwindow,int windowlevel){
1155         _theViewPanel->onBrigthnessColorWindowLevel(colorwindow, windowlevel);
1156
1157         
1158         RefreshInterface();
1159 }
1160
1161 void wxContourMainFrame::onInterpolation(bool interpolate){
1162         _theViewPanel->onInterpolation(interpolate);    
1163         RefreshInterface();
1164 }
1165
1166 void wxContourMainFrame::onChangeInstant(std::string name,int actual){
1167         _instantPanel->setConceptValue( name, actual );
1168 }
1169
1170 void wxContourMainFrame::resetAppend(){
1171         kernelManager->resetAppend();
1172         
1173 }
1174
1175 void wxContourMainFrame::onSpreadAdd(){
1176         std::vector<double> vecX; 
1177         std::vector<double> vecY; 
1178         std::vector<double> vecZ; 
1179         _theViewPanel->GetPointsOfActualContour(&vecX , &vecY , &vecZ );
1180         
1181         std::vector<int> tempVector;
1182         _instantPanel->getInstant( tempVector );
1183
1184         std::string val = kernelManager->onSpreadAdd(&vecX , &vecY , &vecZ, tempVector);
1185
1186         interfMainPanel::getInstance()->appendStringSpread(val);
1187         
1188 }
1189
1190 void wxContourMainFrame::onSpreadGo(int type){
1191
1192         //JCP 20-10-08 Undo redo implementation
1193         saveState();
1194         //JCP 20-10-08 Undo redo implementation
1195
1196         wxBusyCursor wait;      
1197         std::vector<double> vecCtrlPointX;
1198         std::vector<double> vecCtrlPointY;
1199         std::vector<double> vecCtrlPointZ;
1200         double  minZ,maxZ;
1201         int z;
1202
1203         std::vector<int> tempVector;
1204         _instantPanel->getInstant( tempVector );
1205 //              tempVector[1];
1206
1207         kernelManager->getMaxMinZ(&minZ,&maxZ);
1208 //JSTG_16-07-08_----------------------------------------------------------------
1209         //_contourPropagation->setInterpolationNumber(maxZ-minZ+1);
1210         kernelManager->CalculeSplinePropagation();
1211
1212         double          totalZ = maxZ-minZ+1;
1213         double          porcent;
1214         wxString        tmpString;
1215 //--------------------------------------------------------------------
1216         for ( z=(int)minZ ; z<=(int)maxZ ; z++ )
1217         {
1218                 porcent = 100.0* (z-minZ)/totalZ;
1219                 int numero = (int)(z-minZ+1)/(int)totalZ;
1220                 std::string stringtemp = "  "+kernelManager->intToString(porcent)+"%            "+kernelManager->intToString(numero)+"            "+kernelManager->intToString(z);
1221                 
1222                 interfMainPanel::getInstance()->setStringSpread(stringtemp);    
1223
1224                 int typeofcontour = 1;
1225                 std::string theName;
1226                 manualContourModel* manModelContour = kernelManager->GetPoints(z, type, &vecCtrlPointX,&vecCtrlPointY,&vecCtrlPointZ, theName,typeofcontour, tempVector);
1227
1228                 if( manModelContour!=NULL ){
1229                         double spc[3];//Si no hay imagen pero hay contornos que spacing se pone por default
1230                         this->_theViewPanel->getSpacing(spc);                                   
1231                         //Adding the manualContourControler to interface objects structure
1232                         //Adding the manualViewContour to interface objects structure           
1233                         //_theViewPanel->getSceneManager()->setControlActiveStateOfALL( false );//This call is being done here because if the ROI is created underneath the previously created ROIS will still be active.
1234                         _theViewPanel->configureViewControlTo( theName, manModelContour,spc,typeofcontour ) ;
1235                 } // if addedModel
1236         } 
1237         if(z > maxZ){
1238                 porcent = 100.0;
1239                 int numero = (int)(z-minZ+1)/(int)totalZ;
1240                 std::string stringtemp = "  "+kernelManager->intToString(porcent)+"%            "+kernelManager->intToString(numero)+"            "+kernelManager->intToString(z);
1241                 
1242                 interfMainPanel::getInstance()->setStringSpread(stringtemp);
1243         }// for z
1244         //RefreshInterface();
1245 }
1246
1247 void wxContourMainFrame::getInstantVector(std::vector<int>& tempVector){
1248         
1249 }
1250
1251 std::vector<std::string> wxContourMainFrame::getOutlinesName(int slide){
1252         std::vector<int> tempVector;
1253         _instantPanel->getInstant(tempVector);
1254         //Asignation of slide number should be different ex by name
1255         tempVector[1]=slide;
1256         return kernelManager->getOutlinesNameAtInstant(tempVector);
1257 }
1258
1259 void wxContourMainFrame::onInformationContourLabels(int typeContourGroup,int selection,int minimumZ,int maximumZ){
1260         int maxContourGroup     =       0;
1261
1262         ContourExtractData      *contourextractdata = new ContourExtractData();
1263         
1264         contourextractdata ->SetTypeOperation( typeContourGroup % 3 );
1265
1266         std::vector<manualContourModel*> lstManConMod;
1267         std::vector<manualContourModel*> lstManConModTmp;
1268         std::vector<manualContourModel*> lstManConModExp;
1269         std::vector<double> pLstValue;
1270         std::vector<double> pLstValuePosX;
1271         std::vector<double> pLstValuePosY;
1272         std::vector<double> pLstValuePosZ;
1273
1274         int             resultSize; 
1275         int             resultGrayRangeCount;
1276         double  resultMin; 
1277         double  resultMax;
1278         double  resultAverage;
1279         double  resultStandardeviation;
1280
1281         std::vector<int> tempVector;
1282         _instantPanel->getInstant( tempVector );
1283
1284         vtkImageData *imagedata = _theViewPanel->getImageData();
1285         int sizeZ = _theViewPanel->GetImageDataSizeZ();
1286         int z;
1287         int ii,sizeLstContourThings;
1288
1289
1290         int minZ,maxZ;
1291         double totalZ;
1292         double porcent; 
1293         wxString tmpString;
1294
1295         
1296
1297         if (selection==0 ) // actual slice
1298         {
1299                 std::vector<int> tempVector;
1300                 _instantPanel->getInstant( tempVector );
1301                 int actualSlice = tempVector[1];
1302                 minZ    = actualSlice;
1303                 maxZ    = actualSlice;
1304         }
1305         else if (selection==2 ) // All slices
1306         {
1307                 minZ    = 0;
1308                 maxZ    = sizeZ-1;
1309         }
1310         else if (selection==1 ) // slice range
1311         {
1312                 minZ    = minimumZ;
1313                 maxZ    = maximumZ;
1314         }
1315         
1316
1317         totalZ  = maxZ-minZ+1;
1318         contourextractdata->SetImage( imagedata);
1319
1320 // For each slice..
1321         for ( z=minZ ; z<=maxZ ; z++ )
1322         {
1323                 
1324                 porcent = 100.0* (z-minZ)/totalZ;
1325                 tmpString.Printf(_T("  %d %c            %d/%d             %d"), (int)porcent , 37 , z-minZ+1, (int)totalZ ,z);
1326
1327                 interfMainPanel::getInstance()->setStringInfoPanel(tmpString);          
1328                 //_staticTextInformation->SetLabel(tmpString);
1329
1330                 //Extraction data from contours of each slice
1331                 contourextractdata->SetZtoBeAnalys( z);
1332
1333                 tempVector[1]=z;
1334                 Instant instant(&tempVector);
1335                 std::vector<ContourThing**> lstContourThings = kernelManager->getOutlinesAtInstant( &instant );
1336                 sizeLstContourThings = lstContourThings.size();
1337
1338                 lstManConMod.clear();
1339                 for (ii=0 ; ii<sizeLstContourThings ; ii++)
1340                 {
1341                         ContourThing **contourthing = lstContourThings[ii];
1342                         lstManConMod.push_back( (*contourthing)->getModel() );
1343                 }
1344                 lstManConModExp =  kernelManager->ExploseEachModel( lstManConMod );
1345
1346
1347                 wxString tempString;
1348                 tempString.Printf(_T("%d - %d"),z, sizeLstContourThings);
1349                 interfMainPanel::getInstance()->setRowLabelInfoPanel(z, tempString);
1350                 //_grid->SetRowLabelValue(z, tempString );
1351 //EED004
1352                 int iContourGroup,sizeContourGroup;
1353                 if (typeContourGroup==3) // contour separete
1354                 {
1355                         sizeContourGroup=lstManConModExp.size();
1356                         if ( maxContourGroup<sizeContourGroup ) 
1357                         {
1358                                 maxContourGroup=sizeContourGroup;
1359                         }
1360                 } else {  // contour AND OR XOR
1361                         sizeContourGroup=1;
1362                         maxContourGroup=1;
1363                 }
1364
1365                 int tmpIntA;
1366
1367
1368
1369                 for( iContourGroup=0 ; iContourGroup<sizeContourGroup ; iContourGroup++ ){
1370                         lstManConModTmp.clear();
1371                         if (typeContourGroup==3) // contour separete
1372                         {
1373                                 lstManConModTmp.push_back( lstManConModExp[iContourGroup]);
1374                         } else {  // contour AND OR XOR
1375                                 lstManConModTmp = lstManConModExp;
1376                         }
1377
1378                         contourextractdata->SetLstManualContourModel( lstManConModTmp );
1379
1380                         pLstValue.clear();
1381                         pLstValuePosX.clear();
1382                         pLstValuePosY.clear();
1383                         pLstValuePosZ.clear();
1384                         contourextractdata->GetValuesInsideCrown(       &pLstValue,
1385                                                                                                                 &pLstValuePosX,
1386                                                                                                                 &pLstValuePosY,
1387                                                                                                                 &pLstValuePosZ);
1388                         // Statistics of each slice.
1389                         contourextractdata->Statistics( &pLstValue,
1390                                                                                         minimumZ,
1391                                                                                         maximumZ,
1392                                                                                         &resultGrayRangeCount, 
1393                                                                                         &resultSize, 
1394                                                                                         &resultMin, 
1395                                                                                         &resultMax,
1396                                                                                         &resultAverage,
1397                                                                                         &resultStandardeviation);
1398                         
1399                         if (interfMainPanel::getInstance()->getNumberColsInformationPanel()<_numberOfVariablesStatistics*(iContourGroup+1)  )
1400                         {
1401                                 interfMainPanel::getInstance()->appendColsInformationPanel(_numberOfVariablesStatistics);
1402                         }
1403
1404                         tmpIntA=_numberOfVariablesStatistics*iContourGroup ;
1405
1406                         tempString.Printf(_T("%d"),resultSize);
1407                         interfMainPanel::getInstance()->setCellValueInfoPanel(z, tmpIntA, tempString);  
1408
1409                         tempString.Printf(_T("%d"),resultGrayRangeCount);
1410                         interfMainPanel::getInstance()->setCellValueInfoPanel(z, tmpIntA+1, tempString);
1411                         
1412                         tempString.Printf(_T("%f"),resultMin);
1413                         interfMainPanel::getInstance()->setCellValueInfoPanel(z, tmpIntA+2, tempString);
1414                         
1415                         tempString.Printf(_T("%f"),resultMax);
1416                         interfMainPanel::getInstance()->setCellValueInfoPanel(z, tmpIntA+3, tempString);
1417                         
1418                         tempString.Printf(_T("%f"),resultAverage);
1419                         interfMainPanel::getInstance()->setCellValueInfoPanel(z, tmpIntA+4, tempString);
1420                         
1421                         tempString.Printf(_T("%f"),resultStandardeviation);
1422                         interfMainPanel::getInstance()->setCellValueInfoPanel(z, tmpIntA+5, tempString);
1423                         
1424
1425                 } // for iContourGroup
1426         } // for z
1427
1428         int iTitleGroup;
1429         wxString tmpTitleString;
1430         int tmpIntB;
1431         for ( iTitleGroup=0 ; iTitleGroup<maxContourGroup ; iTitleGroup++ )
1432         {
1433                 tmpIntB =_numberOfVariablesStatistics*iTitleGroup;
1434                 tmpTitleString.Printf(_T("%d-Size Data"),iTitleGroup);
1435                 interfMainPanel::getInstance()->setColLableInfoPanel(tmpIntB + 0, tmpTitleString);
1436
1437                 interfMainPanel::getInstance()->setColLableInfoPanel(tmpIntB + 0, tmpTitleString );
1438                 interfMainPanel::getInstance()->setColLableInfoPanel( tmpIntB + 1, _T("Size Range") );
1439                 interfMainPanel::getInstance()->setColLableInfoPanel( tmpIntB + 2, _T("Min") );
1440                 interfMainPanel::getInstance()->setColLableInfoPanel( tmpIntB + 3, _T("Max") );
1441                 interfMainPanel::getInstance()->setColLableInfoPanel( tmpIntB + 4, _T("Average") );
1442                 interfMainPanel::getInstance()->setColLableInfoPanel( tmpIntB + 5, _T("St.Dev.") );
1443                 interfMainPanel::getInstance()->setColLableInfoPanel( tmpIntB + 6, _T(" ") );
1444         }
1445
1446         interfMainPanel::getInstance()->setStringInfoPanel( _T("") );
1447         delete contourextractdata;
1448 }
1449
1450 void wxContourMainFrame::onSaveResults(std::string directory,std::string namefile, std::string filename, int typeContourGroup){
1451     SaveValuesXYZ( directory , namefile, typeContourGroup );
1452         SaveImageResult( directory , namefile, typeContourGroup);
1453
1454         
1455         FILE *pFile=fopen(filename.c_str(),"w+");
1456
1457         int sizeZ = _theViewPanel->GetImageDataSizeZ();
1458
1459         wxString tmpString;
1460         int i,j,maxX,maxY=sizeZ;
1461         maxX= interfMainPanel::getInstance()->getNumberColsInformationPanel();//this->_grid->GetNumberCols();
1462
1463         int iTitle,sizeTitle = (maxX / _numberOfVariablesStatistics);
1464         for ( iTitle=0; iTitle<sizeTitle ; iTitle++)
1465         {
1466                 fprintf(pFile,"-- \t %d-Size \t SizeRange \t Min \t Max \t Ave \t StDv \t" , iTitle,tmpString.c_str() );
1467         }
1468         fprintf(pFile,"\n" );
1469
1470
1471
1472         for ( j=0; j<maxY ; j++)
1473         {
1474                 fprintf(pFile,"%d\t" , j );
1475                 for (i=0 ; i<maxX ; i++){
1476                         tmpString = interfMainPanel::getInstance()->getCellValue(j, i);//_grid->GetCellValue( j , i );
1477                         fprintf(pFile,"%s\t" , (const char *)(tmpString.mb_str()) );
1478                 } // for i
1479                 fprintf(pFile,"\n"  );
1480         } // for j
1481
1482         fclose(pFile);
1483 }
1484
1485 void wxContourMainFrame::SaveValuesXYZ(std::string directory,std::string namefile,int typeContourGroup)
1486 {
1487         wxBusyCursor wait;
1488         ContourExtractData      *contourextractdata = new ContourExtractData();
1489         //int typeContourGroup = this->_radiolstboxContourGroup->GetSelection();
1490         contourextractdata ->SetTypeOperation( typeContourGroup % 3 );
1491
1492         std::vector<manualContourModel*> lstManConMod;
1493         std::vector<manualContourModel*> lstManConModTmp;
1494         std::vector<manualContourModel*> lstManConModExp;
1495         std::vector<double> pLstValue;
1496         std::vector<double> pLstValuePosX;
1497         std::vector<double> pLstValuePosY;
1498         std::vector<double> pLstValuePosZ;
1499
1500         std::vector<int> tempVector;
1501         _instantPanel->getInstant( tempVector );
1502
1503         vtkImageData *imagedata = _theViewPanel->getSceneManager()->GetImageData();
1504         int sizeZ = _theViewPanel->getSceneManager()->GetImageDataSizeZ();
1505         int z;
1506         int ii,sizeLstContourThings;
1507
1508
1509         int minZ,maxZ;
1510         double totalZ;
1511         double porcent; 
1512         wxString tmpString;
1513         minZ    = 0;// _mbarrange->GetStart();
1514         maxZ    = sizeZ;//_mbarrange->GetEnd();
1515         totalZ  = maxZ-minZ+1;
1516
1517         contourextractdata->SetImage( imagedata);
1518
1519 // For each slice..
1520         for ( z=0 ; z<sizeZ ; z++)
1521         {
1522
1523                 porcent = 100.0* (z-minZ)/totalZ;
1524                 
1525                 tmpString.Printf(_T("Saving Values"));
1526                 tmpString.Printf(_T("  %d %c            %d/%d             %d"), (int)porcent , 37 , z-minZ+1, (int)totalZ ,z);
1527                 interfMainPanel::getInstance()->setStringInfoPanel(tmpString);
1528                 //_staticTextInformation->SetLabel(tmpString);
1529
1530
1531                 //Extraction data from contours of each slice
1532                 contourextractdata->SetZtoBeAnalys( z);
1533
1534                 tempVector[1]=z;
1535                 Instant instant(&tempVector);
1536                 std::vector<ContourThing**> lstContourThings = kernelManager->getOutlinesAtInstant(&instant);//this->_modelManager->getOutlinesAtInstant( &instant );
1537                 sizeLstContourThings = lstContourThings.size();
1538
1539                 lstManConMod.clear();
1540                 for (ii=0 ; ii<sizeLstContourThings ; ii++)
1541                 {
1542                         ContourThing **contourthing = lstContourThings[ii];
1543                         lstManConMod.push_back( (*contourthing)->getModel() );
1544                 }
1545                 lstManConModExp =  kernelManager->ExploseEachModel( lstManConMod );
1546
1547
1548 //EED004
1549
1550                 int iContourGroup,sizeContourGroup;
1551                 if (typeContourGroup==3) // contour separete
1552                 {
1553                         sizeContourGroup=lstManConModExp.size();
1554                 } else {  // contour AND OR XOR
1555                         sizeContourGroup=1;
1556                 }
1557
1558                 for( iContourGroup=0 ; iContourGroup<sizeContourGroup ; iContourGroup++ ){
1559                         lstManConModTmp.clear();
1560                         if (typeContourGroup==3) // contour separete
1561                         {
1562                                 lstManConModTmp.push_back( lstManConModExp[iContourGroup]);
1563                         } else {  // contour AND OR XOR
1564                                 lstManConModTmp = lstManConModExp;
1565                         }
1566
1567                         contourextractdata->SetLstManualContourModel( lstManConModTmp );
1568
1569                         pLstValue.clear();
1570                         pLstValuePosX.clear();
1571                         pLstValuePosY.clear();
1572                         pLstValuePosZ.clear();
1573                         contourextractdata->GetValuesInsideCrown(       &pLstValue,
1574                                                                                                                 &pLstValuePosX,
1575                                                                                                                 &pLstValuePosY,
1576                                                                                                                 &pLstValuePosZ);
1577
1578                         std::string temp = directory + "/" + namefile + "-slice";
1579                         temp = temp + kernelManager->intToString(z) + "-cont" + kernelManager->intToString(iContourGroup);
1580                         temp = temp + ".txt";
1581
1582                         // LG 14/01/09 : using crea
1583                         wxString filename = crea::std2wx(temp);
1584                         /*filename.Printf(_T("%s"),directory.c_str());
1585                         filename.append(_T("\\"));
1586                         filename.append(_T("%s"),namefile.c_str());
1587                         filename.append(_T("-slice"));
1588                         filename.append(_T("%d"),z);
1589                         filename.append(_T("-cont"));
1590                         filename.append(_T("%d"),iContourGroup);
1591                         filename.append(_T(".txt"));*/
1592                         //                      filename.Printf(temp.c_str());
1593
1594                         
1595
1596                         FILE *pFile=fopen((const char *)filename.mb_str(),"w+");
1597                         fprintf(pFile,"value \t x \t y \t z\n"  );
1598                         int iLstValue,sizeLstValue=pLstValue.size();
1599                         for (iLstValue=0 ; iLstValue<sizeLstValue ; iLstValue++ )
1600                         {
1601                                 fprintf(pFile,"%f\t %f\t %f\t %f\n", (float)pLstValue[iLstValue] , (float)pLstValuePosX[iLstValue], (float)pLstValuePosY[iLstValue], (float)z );
1602                         }
1603                         fclose(pFile);
1604                 } // for  iContourGroup
1605         } // for z
1606         interfMainPanel::getInstance()->setStringInfoPanel(_T(""));
1607         //_staticTextInformation->SetLabel( _T("") );
1608         delete contourextractdata;
1609 }
1610
1611 void wxContourMainFrame::SaveImageResult(std::string directory,std::string namefile, int typeContourGroup)
1612 {
1613         wxBusyCursor wait;
1614         ContourExtractData      *contourextractdata = new ContourExtractData( true );
1615         //int typeContourGroup = this->_radiolstboxContourGroup->GetSelection();
1616         if (typeContourGroup==3)
1617         {
1618                 typeContourGroup=1;
1619         }
1620         contourextractdata ->SetTypeOperation( typeContourGroup % 3 );
1621
1622         std::vector<manualContourModel*> lstManConMod;
1623         std::vector<manualContourModel*> lstManConModTmp;
1624         std::vector<manualContourModel*> lstManConModExp;
1625
1626         std::vector<int> tempVector;
1627         _instantPanel->getInstant( tempVector );
1628
1629         vtkImageData *imagedata = _theViewPanel->getImageData();
1630         int sizeZ = _theViewPanel->GetImageDataSizeZ();
1631         int z;
1632         int ii,sizeLstContourThings;
1633
1634
1635         int minZ,maxZ;
1636         double totalZ;
1637         double porcent; 
1638
1639         wxString tmpString;
1640
1641         minZ    = 0;// _mbarrange->GetStart();
1642         maxZ    = sizeZ;//_mbarrange->GetEnd();
1643         totalZ  = maxZ-minZ+1;
1644
1645         contourextractdata->SetImage( imagedata);
1646
1647 // For each slice..
1648         for ( z=0 ; z<sizeZ ; z++)
1649         {
1650
1651                 porcent = 100.0* (z-minZ)/totalZ;
1652                 tmpString.Printf(_T("Saving Values"));
1653                 tmpString.Printf(_T("%d %c            %d/%d             %d"), (int)porcent , 37 , z-minZ+1, (int)totalZ ,z);
1654                 interfMainPanel::getInstance()->setStringInfoPanel(tmpString);
1655
1656                 //Extraction data from contours of each slice
1657                 contourextractdata->SetZtoBeAnalys( z);
1658
1659                 tempVector[1]=z;
1660                 Instant instant(&tempVector);
1661                 std::vector<ContourThing**> lstContourThings = kernelManager->getOutlinesAtInstant( &instant );
1662                 sizeLstContourThings = lstContourThings.size();
1663
1664                 lstManConMod.clear();
1665                 for (ii=0 ; ii<sizeLstContourThings ; ii++)
1666                 {
1667                         ContourThing **contourthing = lstContourThings[ii];
1668                         lstManConMod.push_back( (*contourthing)->getModel() );
1669                 }
1670                 lstManConModExp =  kernelManager->ExploseEachModel( lstManConMod );
1671
1672
1673                 int iContourGroup,sizeContourGroup;
1674                 if (typeContourGroup==3) // contour separete
1675                 {
1676                         sizeContourGroup=lstManConModExp.size();
1677                 } else {  // contour AND OR XOR
1678                         sizeContourGroup=1;
1679                 }
1680
1681                 for( iContourGroup=0 ; iContourGroup<sizeContourGroup ; iContourGroup++ ){
1682                         lstManConModTmp.clear();
1683                         if (typeContourGroup==3) // contour separete
1684                         {
1685                                 lstManConModTmp.push_back( lstManConModExp[iContourGroup]);
1686                         } else {  // contour AND OR XOR
1687                                 lstManConModTmp = lstManConModExp;
1688                         }
1689
1690                         contourextractdata->SetLstManualContourModel( lstManConModTmp );
1691
1692
1693 //                              for (ii=0 ; ii<sizeLstContourThings ; ii++)
1694 //                              {
1695 //                                      ContourThing **contourthing = lstContourThings[ii];
1696 //                                      lstManConMod.push_back( (*contourthing)->getModel() );
1697 //                              }
1698 //                              contourextractdata->SetLstManualContourModel( lstManConMod );
1699
1700                         contourextractdata->CalculateImageResult(); // with actual Z
1701
1702                 } // for  iContourGroup
1703         } // for z
1704
1705         std::string temp = directory + "/" + namefile + "-Value.mhd";
1706
1707         wxString filename = crea::std2wx(temp);
1708         // LG 
1709         //      filename.Printf(_T(temp.c_str()));
1710         //filename.Printf(_T("%s\\%s-Value.mhd",directory.c_str(),namefile.c_str(),z);
1711         /*filename.Printf(_T("%s"),directory.c_str());
1712         filename.append(_T("\\"));
1713         filename.append(_T("%s"),namefile.c_str());
1714         filename.append(_T("-Value.mhd"));*/
1715
1716 // Image Value
1717         vtkMetaImageWriter *writerValueImage = vtkMetaImageWriter::New( );
1718         writerValueImage->SetInput( contourextractdata->GetVtkImageValueResult() );
1719         writerValueImage->SetFileName( (const char *)filename.mb_str() );
1720         writerValueImage->SetFileDimensionality( 3 );
1721         writerValueImage->Write( );
1722
1723 // Image Mask
1724         //              filename.Printf("%s\\%s-Mask.mhd",directory.c_str(),namefile.c_str(),z);
1725         temp = directory + "/" + namefile + "-Mask.mhd";
1726
1727         // LG 14/01/09 : using crea
1728         filename = crea::std2wx(temp);
1729         //      filename.Printf(_T(temp.c_str()));
1730
1731         /*filename.Printf(_T("%s"),directory.c_str());
1732         filename.append(_T("\\"));
1733         filename.append(_T("%s"),namefile.c_str());
1734         filename.append(_T("-Mask.mhd"));*/
1735
1736         vtkMetaImageWriter *writerMaskImage = vtkMetaImageWriter::New( );
1737         writerMaskImage->SetInput( contourextractdata->GetVtkImageMaskResult() );
1738         writerMaskImage->SetFileName( (const char *)filename.mb_str() );
1739         writerMaskImage->SetFileDimensionality( 3 );
1740         writerMaskImage->Write( );
1741
1742         interfMainPanel::getInstance()->setStringInfoPanel( _T("") );
1743         delete contourextractdata;
1744 }
1745
1746 void wxContourMainFrame::onChangeInstantInstantPanel(std::string name,int value, int minshow, int maxshow){
1747         if( name.compare( _theViewPanel->getVerticalConceptName() ) == 0){
1748                 _theViewPanel->setActualVertical( value);
1749         }
1750         else if( name.compare( _theViewPanel->getHorizontalConceptName() ) == 0|| _instantPanel->getIfConceptCheckedAt( name, 0 ) )     {
1751                 _theViewPanel->setHorizontalConcept( name, minshow, maxshow, minshow, maxshow, value);
1752         }
1753
1754         changeInstant();
1755 }
1756
1757 void wxContourMainFrame::onSnakePressed(){
1758         std::vector<double> vecX; 
1759         std::vector<double> vecY; 
1760         std::vector<double> vecZ; 
1761         _theViewPanel->GetPointsOfActualContour( &vecX , &vecY , &vecZ );       
1762
1763         if (vecX.size()!=0){
1764                 std::vector<int> tempVector;
1765                 _instantPanel->getInstant( tempVector );
1766                 int i,size=vecZ.size();
1767                 int actualSlice = tempVector[1];
1768                 for ( i=0 ; i<size ; i++ )
1769                 {
1770                         vecZ[i] = actualSlice;
1771                 } // for
1772
1773                 wxDialog* dialog = new wxDialog(this, -1, wxString(_T("Snake")));
1774                 wxPanel* panel = new wxPanel(dialog,-1); 
1775                 wxStaticText* sttext = new wxStaticText(panel, -1, wxString(_T("Panel para snake")));
1776                 dialog->ShowModal();
1777         } // if 
1778
1779 }
1780
1781 void wxContourMainFrame::saveFileWithContoursAutomatique(){
1782         std::string filename = kernelManager->getCurrentFileName();
1783         if(filename.compare("")!=0){
1784                 saveFileWithContours(filename);
1785         }else{
1786                 onSave();
1787         }
1788 }