]> Creatis software - creaContours.git/blob - lib/Interface_ManagerContour_NDimensions/wxContourMainFrame.cxx
4cfa08134be989b9946325c498bb01b7ab4ca905
[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                 _refLineControl                         = NULL;
59                 _refLineModel                           = NULL;
60                 _refLineView                            = NULL;
61
62                 // set up default notebook style
63 //              m_notebook_style =wxAUI_NB_TAB_SPLIT | wxAUI_NB_TAB_EXTERNAL_MOVE | wxNO_BORDER;
64 //              m_notebook_theme = 0;   
65                 //wxContour_ActionCommandsID a;
66
67         }
68
69         wxContourMainFrame :: wxContourMainFrame(wxWindow* parent, wxWindowID id,const wxString& title,const wxPoint& pos,const wxSize& size,std::vector<vtkImageData*> images, long style,std::string datadir)         
70                 : wxPanel(parent, id, pos, size, style)
71         {
72                 m_mgr.SetManagedWindow(this);
73                 _creatingContoursActive         = false;
74                 _theViewPanel                           = NULL;
75
76                 _instantPanel                           = NULL;
77                 _refLineControl                         = NULL;
78                 _refLineModel                           = NULL;
79                 _refLineView                            = NULL;
80
81                 // set up default notebook style
82                 m_notebook_style =wxAUI_NB_TAB_SPLIT | wxAUI_NB_TAB_EXTERNAL_MOVE | wxNO_BORDER;
83                 m_notebook_theme = 0;   
84                 //wxContour_ActionCommandsID a;
85                 _numberOfVariablesStatistics = 7;
86
87                 _datadir = datadir;
88
89         
90         inredo = 0;
91         inundo = 0;
92
93         interfMainPanel* pannew = interfMainPanel::getInstance(parent,datadir+"/data/Icons");//, eventHandler);
94         _performingOperation                    = new PerformingOperation();
95
96
97
98         if(images.size() > 0){
99                 this->setVectImages(images);
100         }
101
102 }
103
104 void wxContourMainFrame::setVectImages( std::vector<vtkImageData*> images ){
105
106         #if defined(__GNUC__)
107                 std::string str_home(getenv("HOME"));
108         #elif defined(_WIN32)
109                         std::string str_home(getenv("USERPROFILE"));
110         #endif
111                 std::string strCreaContourDataTmp = str_home + "/.creaContourDataTemp/";
112
113         std::vector<std::string> conceptNameVect;
114         std::vector<int> conceptSizeVect;
115
116         wxAuiNotebook * notebook = this->createNotebook();              
117
118
119         kernelManager = new KernelManagerContour( images , _datadir+"/data/" , strCreaContourDataTmp );
120
121
122         _instantPanel                           = new wxInstantChooserPanel( notebook, "Instant Chooser", true, false, "c" );
123         _theViewPanel                           = new wxContourViewPanel( kernelManager->getSourceImage(), notebook );  
124                 
125 //-------------------------------------------------------------
126         kernelManager->getConceptsInformation(conceptNameVect, conceptSizeVect);
127         _instantPanel->addConcepts(conceptNameVect, conceptSizeVect);
128                 
129
130         double val = _theViewPanel->getCurrentDeep();
131         _instantPanel->setConceptValue( "Axe Depth", (int)val );
132         //JCP _instantPanel->setConceptValue("time", num de imagenes);
133         ConceptDataWrap * data = _instantPanel->getConceptDataOf( "Axe Depth" );
134         //*******************changeInstant();
135         _theViewPanel->setVerticalConcept( "Axe Depth", data->getMinValue(), data->getMaxValue(), data->getMinShowedValue(),  data->getMaxShowedValue(), data->getActualValue() );
136
137         this->configurePanels( notebook );
138
139 }
140
141
142         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 ){
143                 if(instance == NULL){
144                         instance = new wxContourMainFrame(parent, id, title, pos, size, images, style,datadir);
145                 }
146                 return instance;
147         }
148
149         std::vector<vtkImageData*> wxContourMainFrame ::getVectImages(){
150                 return kernelManager->getVectImages();
151         }
152         wxContourMainFrame* wxContourMainFrame :: getInstance(){
153                 return instance;
154                 
155         }
156
157         wxContourMainFrame :: ~wxContourMainFrame()
158         {
159                   m_mgr.UnInit();
160                   //El problema al cerrar la aplicacion puede estar asociado 
161                   //a que  wxAUINotebook esta en la aplicacion 
162                   //principal (wxContourGUIExample)tambien
163 //EED????               delete _theViewPanel;             
164 //EED????               delete _instantPanel;
165 //EED????               delete _buttonsBar;
166 //EED????               delete _actualInstant;           
167 //EED????               delete _sceneManager;
168         }
169
170
171         //------------------------------------------------------------------------------------------------------------
172         // Creational and initialization methods using WxAui
173         //------------------------------------------------------------------------------------------------------------
174         //
175         wxAuiNotebook * wxContourMainFrame :: createNotebook()
176         {
177                 wxSize client_size = GetClientSize();
178                 wxAuiNotebook* noteBook = new wxAuiNotebook(this, -1, wxPoint(client_size.x, client_size.y), wxSize(430,200), m_notebook_style);
179                 wxBitmap page_bmp = wxArtProvider::GetBitmap(wxART_NORMAL_FILE, wxART_OTHER, wxSize(16,16));
180                 return noteBook;
181         }
182         
183
184         //------------------------------------------------------------------------------------------------------------
185         // Creational and initialization methods 
186         //------------------------------------------------------------------------------------------------------------
187         bool wxContourMainFrame :: configurePanels(wxAuiNotebook* theNoteBook)
188         {
189                 bool configured = _theViewPanel!=NULL;
190                                         
191                 configured &= _theViewPanel!=NULL;
192                 if( _theViewPanel!=NULL )
193                 {
194                         theNoteBook->AddPage( _theViewPanel, wxT("       View       ") );               
195                         m_mgr.Update();
196                 }
197
198
199                 if( configured )
200                 {
201                         theNoteBook->AddPage( _instantPanel, wxT("Instant Page") );
202                         m_mgr.Update();
203                 }
204
205                 m_mgr.AddPane(theNoteBook, wxAuiPaneInfo().Name(wxT("notebook_content")).CenterPane().PaneBorder(false));
206                 m_mgr.Update();
207 /*              configured &= _buttonsBar!=NULL;
208                 if( _buttonsBar!=NULL )
209                 {                       
210                         m_mgr.AddPane(_buttonsBar, wxAuiPaneInfo().
211                                         Name(wxT("TB")).Caption(wxT("Buttons Bar")).
212                                         ToolbarPane().Top().
213                                         LeftDockable(  ).RightDockable( false ).CloseButton(false));
214                         m_mgr.Update();
215                 }*/
216                 //CreateStatusBar();
217                          
218                 SetMinSize(wxSize(300,300));
219                 m_mgr.Update();
220                 return configured;
221         }
222
223         void wxContourMainFrame :: setNotebook( wxAuiNotebook * noteBook )
224         {
225
226         }
227
228         //------------------------------------------------------------------------------------------------------------
229         //  Attributes getters and setters
230         //------------------------------------------------------------------------------------------------------------
231         
232
233         
234         void wxContourMainFrame :: setInstantChooserPanel(  wxInstantChooserPanel * theInstantChooserPanel )
235         {
236                 _instantPanel = theInstantChooserPanel; 
237         }
238
239 //      void wxContourMainFrame :: setButtonsBar(  wxContour_ButtonsBar * theButtonsBar )
240 //      {
241 //              _buttonsBar = theButtonsBar;
242 //      }
243
244 //      void wxContourMainFrame :: setGrid(  wxContour_Grid * theGridPanel )
245 //      {
246 //              _gridPanel = theGridPanel;
247 //      }
248
249 //      void wxContourMainFrame :: setDrawToolsPanel(  wxContour_DrawToolsPanel * theDrawToolsPanel )
250 //      {
251 //              _drawToolsPanel = theDrawToolsPanel;
252 //      }
253
254 //      void wxContourMainFrame :: setOperationsToolsPanel(  wxContour_OperationsToolsPanel * theOperationsToolsPanel )
255 //      {       
256 //              _operationsToolsPanel = theOperationsToolsPanel;
257 //      }
258
259 //      void wxContourMainFrame :: setAutomaticFormsPanel(  wxContour_AutomaticFormsToolsPanel * theAutoFormsPanel )
260 //      {
261 //              _autoFormsPanel = theAutoFormsPanel;
262 //      }
263
264 //      void wxContourMainFrame :: setStandardToolsPanel(  wxContour_StandardToolsPanel * theStandardToolsPanel )
265 //      {
266 //              _standardToolsPanel= theStandardToolsPanel;
267 //      }
268
269 //      void wxContourMainFrame :: setEditionToolsPanel(  wxContour_EdtionToolsPanel * theEditionToolsPanel )
270 //      {
271 //              _editionToolsPanel =  theEditionToolsPanel;
272 //      }
273
274 //      void wxContourMainFrame :: setListViewPanel(  wxContour_ListViewPanel * theListViewPanel )
275 //      {
276 //              _listViewPanel = theListViewPanel;
277 //      }
278
279
280
281 void wxContourMainFrame::onCreateContourSpline( ){
282         
283         //JCP 20-10-08 Undo redo implementation
284         saveState();
285         //JCP 20-10-08 Undo redo implementation
286         createContour( 1 );
287         
288 }
289 void wxContourMainFrame::onCreateContourRectangle( ){
290     //JCP 20-10-08 Undo redo implementation
291         saveState();
292         //JCP 20-10-08 Undo redo implementation 
293         createContour( 2 );
294 }
295 void wxContourMainFrame::onCreateContourCircle( ){
296     //JCP 20-10-08 Undo redo implementation
297         saveState();
298         //JCP 20-10-08 Undo redo implementation 
299         createContour( 3 );
300 }
301
302 void wxContourMainFrame::onCreateContourLine( ){
303     //JCP 20-10-08 Undo redo implementation
304         saveState();
305         //JCP 20-10-08 Undo redo implementation 
306         createContour( 6 );
307 }
308
309 //------------------------------------------------------------------------------------------------------------
310
311 void wxContourMainFrame :: onCreateContourBullEye(wxPanel* panel )
312 {
313         //Creating the manualContourModel and including in the model
314         manualContourModel * manModelContour = factoryManualContourModel(panel );
315
316         std::vector<int> instantVector;
317         _instantPanel->getInstant( instantVector );
318         std::string theName = kernelManager->createOutline(manModelContour, instantVector);
319         
320         /*std::vector<int> instantVector;
321         _instantPanel->getInstant( instantVector );
322         std::string theName;
323         theName= _modelManager->createOutline( manModelContour, instantVector );*/
324         bool addedModel = theName.compare("") != 0;//??
325
326         if( addedModel )
327         {
328                 double spc[3];//Si no hay imagen pero hay contornos que spacing se pone por default
329                 _theViewPanel->getSpacing(spc);                                 
330                 //Adding the manualContourControler to interface objects structure
331                 //Adding the manualViewContour to interface objects structure           
332                 //_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.
333                 _theViewPanel->getSceneManager()->configureViewControlTo( theName, manModelContour,spc , 4) ;
334         }
335 }
336 void wxContourMainFrame :: createContour( int typeContour )
337 {
338         //Creating the manualContourModel and including in the model
339         manualContourModel * manModelContour = kernelManager->factoryManualContourModel(typeContour);
340
341
342         std::vector<int> instantVector;
343         _instantPanel->getInstant( instantVector );
344         std::string theName = kernelManager->createOutline(manModelContour, instantVector);
345         
346         /*std::vector<int> instantVector;
347         _instantPanel->getInstant( instantVector );
348         std::string theName;
349         theName= _modelManager->createOutline( manModelContour, instantVector );*/
350         bool addedModel = theName.compare("") != 0;//??
351         if( addedModel )
352         {
353                 double spc[3];//Si no hay imagen pero hay contornos que spacing se pone por default
354                 _theViewPanel->getSpacing(spc);                                 
355                 //Adding the manualContourControler to interface objects structure
356                 //Adding the manualViewContour to interface objects structure           
357                 //_sceneManager->setControlActiveStateOfALL( false );//This call is being done here because if the ROI is created underneath the previously created ROIS will still be active.
358                 _theViewPanel->getSceneManager()->configureViewControlTo( theName, manModelContour,spc , typeContour) ;
359         }       
360
361 }
362 manualContourModel * wxContourMainFrame::factoryManualContourModel(wxPanel* panel){
363
364         manualContourModelBullEye *manModelContourBullEye = new manualContourModelBullEye();
365         manualContourModel *manModelContour=NULL;
366         manModelContour = manModelContourBullEye;
367         if (panel!=NULL){
368                 int iCrown,sizeCrowns,iSector,sizeSectors;
369                 double radioA,radioB,ang,angDelta ;
370                 sizeCrowns = ((PanelBullEyeOptions*)panel)->GetNumberOfCrowns();
371                 for ( iCrown=0 ; iCrown<sizeCrowns ; iCrown++ )
372                 {
373                         sizeSectors = ((PanelBullEyeOptions*)panel)->GetNumberOfSections(iCrown);
374                         radioB  = ((PanelBullEyeOptions*)panel)->GetRadioOfCrown(iCrown);
375                         if (iCrown==sizeCrowns-1)
376                         {
377                                 radioA  = 0;
378                         } else {
379                                 radioA  = ((PanelBullEyeOptions*)panel)->GetRadioOfCrown(iCrown+1);
380                         }
381                         radioA=radioA/100.0;
382                         radioB=radioB/100.0;
383                         for ( iSector=0 ; iSector<sizeSectors  ; iSector++ )
384                         {
385                                 ang             = ((PanelBullEyeOptions*)panel)->GetAngOfCrownSection(iCrown,iSector);
386                                 angDelta= ((PanelBullEyeOptions*)panel)->GetAngDeltaOfCrownSection(iCrown);                                     
387                                 manModelContourBullEye->AddSector(radioA,radioB,ang,angDelta);
388                         } // for iSector
389                 } // for iCrown
390         } // if _panelBullEyeOptions
391         
392         return manModelContour;
393 }
394 void wxContourMainFrame :: saveState(){ 
395                 
396         std::string temp = kernelManager->saveState();
397         saveFileWithContours(temp);     
398 }
399
400 void wxContourMainFrame::onDeleteContour(){
401         //JCP 20-10-08 Undo redo implementation
402                 saveState();
403                 //JCP 20-10-08 Undo redo implementation
404
405                 std::vector<std::string> lstKeyNameToBeErase;
406                 lstKeyNameToBeErase             = _theViewPanel->getSceneManager()->getSelectedObjects();
407                 deleteContours( lstKeyNameToBeErase );
408 /*JCP 19 - 11 - 08
409                 int i,size=_sceneManager->getSelectedObjects().size();
410                 for(i=0;i<size;i++)
411                 {
412                         std::string keyName             = _sceneManager->getSelectedObjects()[i];
413                         int ispartofstaticlist  = this->_modelManager->IsPartOfStaticList( keyName );
414                         if ( ispartofstaticlist>=0 )
415                         {
416                                 std::vector<int> tempVector;
417                                 _instantPanel->getInstant( tempVector );
418                                 Instant instant(&tempVector);
419                                 this->_modelManager->ChangeContourOfList(keyName, &instant);
420                         }
421                 }
422
423                 std::vector<std::string> lstKeyName;
424                 std::vector<std::string> lstKeyNameActualSlice;
425                 std::vector<std::string> lstKeyNameToBeErase;
426
427                 lstKeyNameToBeErase             = _sceneManager->getSelectedObjects();
428                 lstKeyNameActualSlice   = _sceneManager->GetlstContoursNameActualSlice();
429                 int k,kSize=lstKeyNameToBeErase.size();
430                 int j,jSize=lstKeyNameActualSlice.size();
431                 bool ok;
432                 for (k=0;k<kSize; k++)
433                 {
434                         ok=false;
435                         for (j=0;j<jSize; j++)
436                         {
437                                 if (lstKeyNameToBeErase[k]==lstKeyNameActualSlice[j])
438                                 { 
439                                         ok=true;
440                                 }
441                         } // for j
442                         if (ok==true)
443                         {
444                                 lstKeyName.push_back( lstKeyNameToBeErase[k] );
445                         } // if ok
446                 } // for k
447
448                 deleteContours( lstKeyName );
449 JCP 19 - 11 - 08*/
450 }
451
452 void wxContourMainFrame :: deleteContours( std::vector<std::string>  keyNamesVector )
453 {
454         int i,size=keyNamesVector.size();
455         for (i=0;i<size;i++)
456         {
457                 deleteContour( keyNamesVector[i] );
458         }
459 }
460
461 void wxContourMainFrame :: deleteContour( std::string theKeyName ){
462         /*
463         manualContourModel                      * cModel;
464         manualViewBaseContour           * cViewer;
465         manualContourBaseControler      * cControler;
466
467         ContourWrap_ViewControl *conwrapviewControl =  _theViewPanel->getSceneManager()->getContourWrap_ViewControlOf( theKeyName );
468         cControler      = conwrapviewControl->getControler();*/
469
470         //JCP 21 - 11 - 2008
471         bool isedit = _theViewPanel->isEditableCControler(theKeyName);
472         bool ispartofstaticlst = kernelManager->IsPartOfStaticList(theKeyName);
473
474         if (isedit  && ispartofstaticlst)
475         {
476                 _theViewPanel->removeFromScene(theKeyName);
477
478                 kernelManager->deleteCModel(theKeyName);
479                 //_theViewPanel->getSceneManager()->removeFromScene( theKeyName );                      
480                 //cViewer               = conwrapviewControl->getViewer();
481                 //_theViewPanel->getSceneManager()->removeWrap( theKeyName );
482                 //cControler* conwrapviewControl->getControler();                       
483 //EED Borrame
484 //FILE *ff = fopen("c:/temp/wxVtkBaseView_SceneManagerStadistics.txt","a+");
485 //fprintf(ff,"EED wxContourEventHandler::deleteContours() \n" );
486 //fprintf(ff,"    %s %p\n",keyNamesVector[i].c_str(),  cControler );
487 //fclose(ff);
488         //      delete cModel;
489         //      delete cViewer;
490         //      delete cControler;
491         } // if editable
492 //JCP 21 - 11 - 08
493 }
494
495 void wxContourMainFrame::onDeleteContoursActSlice(){
496         //JCP 20-10-08 Undo redo implementation
497         saveState();
498         //JCP 20-10-08 Undo redo implementation
499         deleteContours( (std::vector<std::string>)_theViewPanel->getSceneManager()->GetlstContoursNameActualSlice() );
500 }
501 void wxContourMainFrame::onDeleteAllContours(){
502         //JCP 20-10-08 Undo redo implementation
503         saveState();
504         deleteAllContours();
505 }
506 void wxContourMainFrame::deleteAllContours(){
507         //JCP 20-10-08 Undo redo implementation
508
509         wxBusyCursor wait;
510         std::vector<int> tempVector;
511         _instantPanel->getInstant( tempVector );
512
513 //JCP --08-09-2008 When using a diferent interface the _mbarrangeDeleteAll might not be initialize
514 //              the values in GetStart and GetEnd will then not be initialize also.
515 //              We use instead the values given when initializing the _deletepanel.
516
517         //int minZ = _mbarrangeDeleteAll->GetStart();
518         //int maxZ = _mbarrangeDeleteAll->GetEnd();
519         int minZ, maxZ;
520         
521         minZ = 0;
522         maxZ = _theViewPanel->getSceneManager()->GetImageDataSizeZ();
523         
524 //JCP --08-09-2008
525         
526         _theViewPanel->getSceneManager()->removeSceneContours( );       
527         _theViewPanel->getSceneManager()->removeAllOutlines();
528         kernelManager->removeAllOutlines();     
529 //JCP --08-09-2008
530         /*
531         if ( (minZ==0) && (maxZ==_mbarrangeDeleteAll->GetMax() ))
532         {
533                 _theViewPanel->getSceneManager()->removeSceneContours( );
534                 _modelManager->removeAllOutlines();
535                 _theViewPanel->getSceneManager()->removeAllOutlines();
536
537         } else {
538                 for ( z=minZ ; z<=maxZ ; z++)
539                 {
540                         tempVector[1]=z;
541                         Instant instant(&tempVector);
542                         std::vector<ContourThing**> lstContourThings = this->_modelManager->getOutlinesAtInstant( &instant );
543
544                         sizeLstContourThings = lstContourThings.size();
545                         for (ii=0 ; ii<sizeLstContourThings ; ii++)
546                         {
547                                 ContourThing **contourthing = lstContourThings[ii];
548                                 deleteContour( (*contourthing)->getName() );
549                         } //for ii
550                 }// for z
551         } // if 
552 JCP --08-09-2008 */
553 }
554
555 void wxContourMainFrame::setConceptValue( std::string name, int value ){
556         _instantPanel->setConceptValue(name, value);
557 }
558
559 ConceptDataWrap* wxContourMainFrame::getLastConceptData(){
560         return _instantPanel->getLastConceptData();
561 }
562 bool wxContourMainFrame::getIfConceptCheckedAt( std::string name, int pos ){
563         return _instantPanel->getIfConceptCheckedAt( name, pos );
564 }
565
566 void wxContourMainFrame::changeInstant(){
567                 std::vector<int> instantVect;
568                 _instantPanel->getInstant( instantVect );
569 //              Instant * theInstant = new Instant ( &instantVect );
570                 
571                 //Setting the actual instant
572                 //_actualInstant = theInstant;
573
574                 kernelManager->setInstant(instantVect);
575                 //_modelManager->setInstant( _actualInstant );
576                 
577                 updateInstantOutlines();
578                 updateInstantImageData();
579                 updateInstantAxes();
580
581                 
582 }
583 void wxContourMainFrame :: updateInstantOutlines(){
584         
585         _theViewPanel->removeSceneContours();
586         _theViewPanel->addNameWrapperToScene();
587
588         //for( int i=0; i<size; i++)
589         //{                     
590         //      _theViewPanel->getSceneManager()->addToScene(namesWrapping[i]->getKeyName(), true, true, true, false, false );
591         //}
592 }
593
594 int wxContourMainFrame::getNamesWrappingSize(){
595         return kernelManager->getNamesWrappingSize();
596 }
597 std::string wxContourMainFrame::getNameWrapping(int i){
598         return kernelManager->getNameWrapping(i);
599 }
600
601 void wxContourMainFrame::updateInstantImageData(){
602         std::vector<int> inst;
603         _instantPanel->getInstant(inst);
604
605         vtkImageData* img = kernelManager->getImageAtInstant(inst);
606         if(img!=NULL){
607                 _theViewPanel->changeImage(img);
608                 showAxis(false);
609         }else{
610                 int z = _instantPanel->getConceptDataOf("Axe Depth")->getActualValue();
611                 _theViewPanel->setImageSlice(z);
612         }
613 }
614 void wxContourMainFrame::updateInstantAxes(){
615 }
616
617 void wxContourMainFrame::onChangeDeep(int val){
618         _instantPanel->setConceptValue( "Axe Depth", (int)val );        
619         changeInstant();
620 }
621
622
623 void wxContourMainFrame::onCopy(){
624         std::vector<std::string> currentSelection = _theViewPanel->getSelectedObjects();
625
626         std::vector<int> tempVector;
627         _instantPanel->getInstant( tempVector );
628     _performingOperation->reset();
629         _performingOperation->setStartCommand( COPY );
630         _performingOperation->setStartOperationInstantVector( tempVector );
631         _performingOperation->setKeyNamesOperationElems( currentSelection );
632 }
633
634 void wxContourMainFrame::onPaste(){
635
636
637         char theStartCommand = _performingOperation->getStartCommand();
638         if (  theStartCommand == COPY )
639         {
640                 //JCP 20-10-08 Undo redo implementation
641                 saveState();
642                 //JCP 20-10-08 Undo redo implementation
643                 std::vector<int> tempVector;
644                 _instantPanel->getInstant( tempVector );
645                 _performingOperation->setEndOperationInstantVector ( tempVector );
646                 std::vector<std::string> elems = _performingOperation->getKeyNamesOperationElems();
647                 int i,size = elems.size();                      
648                 for( i=0; i<size; i++ )
649                 {                               
650                         createCopyContourOf( elems[i], tempVector, i>0 );
651                 }               
652         }
653 }
654 void wxContourMainFrame::onUndo(){
655         std::string filename;
656         if(kernelManager->onUndoSaveFile(filename)){
657                 saveFileWithContours(filename);
658         }
659         if(kernelManager->onUndo(filename)){
660                 loadState(filename);
661         }
662 }
663 void wxContourMainFrame::onRedo(){
664         std::string filename;
665         if(kernelManager->onRedo(filename)){
666                 loadState(filename);
667         }
668         
669 }
670 void wxContourMainFrame :: createCopyContourOf ( std::string anExistingKName, std::vector<int> &instantNoTouchData, bool append )
671 {
672         std::string cloneName = kernelManager->createCopyContourOf( anExistingKName, instantNoTouchData );
673         manualContourModel * manualModel = kernelManager->getOutlineByKeyName(cloneName);//_modelManager->getOutlineByKeyName( cloneName )->getModel();
674         _theViewPanel->getSceneManager()->createCopyContourOf( anExistingKName, cloneName, manualModel , append );
675 }
676
677 ///AD: 03-09    Copy the object and apply the given transformation
678 void wxContourMainFrame :: createMirrorContourOf ( std::string anExistingKName, std::vector<int> &instantNoTouchData, bool append )
679 {
680         std::string cloneName = kernelManager->createCopyContourOf( anExistingKName, instantNoTouchData );
681         manualContourModel * manualModel = kernelManager->getOutlineByKeyName(cloneName);
682
683         manualPoint * refPoint1 = _refLineModel->GetManualPoint(0);
684         manualPoint * refPoint2 = _refLineModel->GetManualPoint(1);
685
686         double pnt1X = refPoint1->GetX();
687         double pnt1Y = refPoint1->GetY();
688 //      double pnt1Z = refPoint1->GetZ();
689         double pnt2X = refPoint2->GetX();
690         double pnt2Y = refPoint2->GetY();
691 //      double pnt2Z = refPoint2->GetZ();
692
693         double angle = (atan2(pnt2Y - pnt1Y, pnt2X - pnt1X) * 180 / 3.1415926535897932384626433832795)+90;
694         vtkTransform *t = vtkTransform::New();
695
696         t->PostMultiply();
697         t->Identity();
698         t->Translate(-pnt1X, -pnt1Y, 0);
699         t->RotateZ(-angle);
700         t->Scale(-1,1,1);
701         t->RotateZ(angle);
702         t->Translate(pnt1X, pnt1Y, 0);
703         t->Update();
704
705         int i,size=manualModel->GetSizeLstPoints();
706         for (i=0;i<size;i++)
707         {
708                 manualPoint * mp = manualModel->GetManualPoint(i);
709                 float vecIn[3];
710                 float vecOut[3];
711                 vecIn[0]=mp->GetX();
712                 vecIn[1]=mp->GetY();
713                 vecIn[2]=mp->GetZ();
714                 t->TransformPoint( vecIn, vecOut );
715                 mp->SetPointX( vecOut[0] );
716                 mp->SetPointY( vecOut[1] );
717                 mp->SetPointZ( vecOut[2] );
718         }
719
720         _theViewPanel->getSceneManager()->createCopyContourOf( anExistingKName, cloneName, manualModel , append );
721 }
722
723 void wxContourMainFrame ::loadState(std::string filename){
724         char tmp[255];
725         FILE *pFile=fopen(filename.c_str(),"r+");
726
727         fscanf(pFile,"%s",tmp); // --CreaContour--
728
729         fscanf(pFile,"%s",tmp); // Version
730         fscanf(pFile,"%s",tmp); // 1.0.1
731         std::string version(tmp);
732
733         deleteAllContours();
734
735         openContours(pFile,false);
736         if (version!="1.0.0"){
737                 openContours(pFile,true);
738         }
739
740         fclose(pFile);
741         
742         //_theViewPanel->getSceneManager()->removeSceneContours();
743         //changeInstant();
744
745 }
746
747 void wxContourMainFrame::onLoad(){
748         char tmp[255];
749         wxFileDialog dialog(NULL, _T("Choose a file"), _T(""), _T(""), _T("*.roi"), wxOPEN );
750         if (dialog.ShowModal() == wxID_OK)
751         {
752                 std::string fileNameContourROI = (const char *)(dialog.GetPath().mb_str());
753                 FILE *pFile=fopen(fileNameContourROI.c_str(),"r+");
754
755                 fscanf(pFile,"%s",tmp); // --CreaContour--
756
757                 fscanf(pFile,"%s",tmp); // Version
758                 fscanf(pFile,"%s",tmp); // 1.0.1
759                 std::string version(tmp);
760
761                 openContours(pFile,false);
762                 if (version!="1.0.0"){
763                         openContours(pFile,true);
764                 }
765 //                        _theViewPanel->getSceneManager()->openFileWithContours(ff);
766
767                 fclose(pFile);
768         }
769         _theViewPanel->getSceneManager()->removeSceneContours();
770         changeInstant();
771 }
772 void wxContourMainFrame::onSave(){
773         wxFileDialog dialog(NULL, _T("Choose a file"), _T(""), _T(""), _T("*.roi"), wxSAVE );
774         if (dialog.ShowModal() == wxID_OK)
775         {
776                 std::string fileNameContourROI = (const char *)(dialog.GetPath().mb_str());
777                 kernelManager->setCurrentFileName(fileNameContourROI);
778                 saveFileWithContours( fileNameContourROI );
779         }
780 }
781 void wxContourMainFrame::saveFileWithContours( std::string filename ){
782
783         FILE *pFile=fopen(filename.c_str(),"w+");
784         std::vector< std::string > lstNameThings;
785         int i,sizeLstNameThings; 
786
787         fprintf(pFile,"--CreaContour--\n");
788         fprintf(pFile,"Version %s\n", "1.0.1" );
789
790         // Normal Contours
791         lstNameThings           = kernelManager->GetLstNameThings();
792         sizeLstNameThings       = lstNameThings.size(); 
793         fprintf(pFile,"NumberOfContours %d\n", sizeLstNameThings );
794         for (i=0 ; i<sizeLstNameThings ; i++) 
795         {
796                 kernelManager->SaveThingName( pFile, lstNameThings[i] );
797                 _theViewPanel->getSceneManager()->SaveThingName( pFile, lstNameThings[i] );
798         }// for i
799
800         //-- Contours Statics 
801         lstNameThings           = kernelManager->GetLstNameThingsStatic();
802         sizeLstNameThings       = lstNameThings.size(); 
803         fprintf(pFile,"NumberOfContoursStatic %d\n", sizeLstNameThings );
804         for (i=0 ; i<sizeLstNameThings ; i++) 
805         {
806                 kernelManager->SaveThingName( pFile, lstNameThings[i] );
807                 _theViewPanel->getSceneManager()->SaveThingName( pFile, lstNameThings[i] );
808         }// for i
809         fclose(pFile);
810 }
811
812 void wxContourMainFrame::openContours( FILE *pFile, bool staticContour ){
813         char tmp[255];
814         fscanf(pFile,"%s",tmp); // NumberOfContours 
815         fscanf(pFile,"%s",tmp); // ##
816         int numberOfContours = atoi(tmp);  
817
818         std::vector<int> instantVector;
819         int typeContourModel;
820         manualContourModel *manModelContour;
821         int typeView;
822
823         int i;
824         for (i=0;i<numberOfContours;i++)
825         {
826                 instantVector.clear();
827                 fscanf(pFile,"%s",tmp); // Instant
828
829                 fscanf(pFile,"%s",tmp); // 1
830                 instantVector.push_back( atoi(tmp) );
831                 fscanf(pFile,"%s",tmp); // 2
832                 instantVector.push_back( atoi(tmp) );
833                 fscanf(pFile,"%s",tmp); // 3
834                 instantVector.push_back( atoi(tmp) );
835                 fscanf(pFile,"%s",tmp); // 4
836                 instantVector.push_back( atoi(tmp) );
837                 fscanf(pFile,"%s",tmp); // 5
838                 instantVector.push_back( atoi(tmp) );
839                 fscanf(pFile,"%s",tmp); // 6
840                 instantVector.push_back( atoi(tmp) );
841
842
843                 fscanf(pFile,"%s",tmp); // TypeContourModel
844                 fscanf(pFile,"%s",tmp); // ##
845                 typeContourModel = atoi(tmp);
846
847                 manModelContour =  kernelManager->factoryManualContourModel(typeContourModel);
848                 manModelContour->Open(pFile);
849
850                 fscanf(pFile,"%s",tmp); // TypeView
851                 fscanf(pFile,"%s",tmp); // ##
852                 typeView = atoi(tmp);  
853
854
855 //                      if (typeView==1) 
856 //                      {
857 //                      }
858
859
860                 std::string theName;
861                 theName = kernelManager->createOutline( manModelContour, instantVector );
862                 bool addedModel = theName.compare("") != 0;
863                 if( addedModel )
864                 {
865                         double spc[3];//Si no hay imagen pero hay contornos que spacing se pone por default
866                         _theViewPanel->getSpacing(spc);                                 
867                         //Adding the manualContourControler to interface objects structure
868                         //Adding the manualViewContour to interface objects structure           
869                         //_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.
870                         _theViewPanel->getSceneManager()->configureViewControlTo( theName, manModelContour,spc , typeView) ;
871                 }       
872
873                 if (staticContour==true)
874                 {
875                         Instant instant(&instantVector);
876                         kernelManager->changeContourOfManager( theName , &instant );
877                 }
878
879         }// for  numberOfContours
880
881 }
882
883 void wxContourMainFrame::RefreshInterface(){
884         changeInstant();
885         _theViewPanel->RefreshInterface();
886         //wxVtk2DBaseView *wxvtk2dbaseview = (wxVtk2DBaseView*)this->_theViewPanel->getWxVtkBaseView();
887         //wxvtk2dbaseview->Refresh();
888 }
889
890 vtkImageData* wxContourMainFrame::getImageData(){
891         return _theViewPanel->getImageData();
892 }
893
894 void wxContourMainFrame::onSegmentationOneSliceITK(wxString distance, wxString sigma, wxString alfa, wxString beta, wxString propagation, wxString iterations, wxString inflation)
895 {
896         //JCP 20-10-08 Undo redo implementation
897         saveState();
898         //JCP 20-10-08 Undo redo implementation
899         
900         wxBusyCursor wait;
901         int                                     x                                       = _theViewPanel->GetX();
902         int                                     y                                       = _theViewPanel->GetY();
903         int                                     z                                       = _theViewPanel->GetZ();
904         SegmentationOneSliceITK( x,y,z,distance, sigma, alfa, beta, propagation, iterations, inflation);
905         RefreshInterface();
906 }
907
908 void wxContourMainFrame::SegmentationOneSliceITK(int x, int y, int z, wxString distanc, wxString sigm, wxString alf, wxString bet, wxString prop, wxString iter, wxString inflation)
909 {
910         
911         int typeofcontour = 1;
912         //Image Data
913         vtkImageData    *imagedata      = getImageData();
914         
915         //Tipo de pixeles a utilizar internamente en ITK
916   typedef   float  InternalPixelType;
917   const     unsigned int    Dimension = 2;
918   typedef itk::Image< InternalPixelType, Dimension >  InternalImageType;
919
920   //Tipo de pixeles de salida 1
921   typedef unsigned char OutputPixelType;
922   typedef itk::Image< OutputPixelType, Dimension > OutputImageType;
923
924   //Tipo de pixeles de salida 2
925   typedef unsigned short OutputPixelType2;
926   typedef itk::Image< OutputPixelType2, Dimension > OutputImageType2;
927
928   //Definición del thresholder
929   typedef itk::BinaryThresholdImageFilter< 
930                         InternalImageType, 
931                         OutputImageType    >    ThresholdingFilterType;
932   
933   //Definición del primer filtro de conversión de pixeles
934   typedef itk::CastImageFilter<
935                OutputImageType, OutputImageType2 >  CastFilterType;
936
937   //Definición del segundo tipo de conversión de pixeles
938   typedef itk::CastImageFilter<
939                OutputImageType2, InternalImageType >  CastFilterType2;
940
941   //Tercer tipo de conversión
942   typedef itk::RescaleIntensityImageFilter< 
943                                InternalImageType, 
944                                OutputImageType >   CastFilterType3;
945
946   //Cuarto tipo de conversión
947   typedef itk::RescaleIntensityImageFilter< 
948                                OutputImageType, 
949                                OutputImageType >   CastFilterType4;
950
951   ThresholdingFilterType::Pointer thresholder = ThresholdingFilterType::New();
952                         
953   thresholder->SetLowerThreshold( 0.0 );
954   thresholder->SetUpperThreshold( 128 );
955
956   thresholder->SetOutsideValue(  255  );
957   thresholder->SetInsideValue(  0 );
958
959   //Definción de conexiónes entre VTK e ITK y el writer
960   typedef itk::VTKImageToImageFilter<OutputImageType2> ConnectorType;
961   typedef itk::ImageToVTKImageFilter<OutputImageType> ConnectorType2;
962   typedef  itk::ImageFileWriter<  OutputImageType  > WriterType;
963
964   ConnectorType::Pointer connector= ConnectorType::New();
965   ConnectorType2::Pointer connector2= ConnectorType2::New();
966   
967
968   CastFilterType::Pointer filter=CastFilterType::New();
969   CastFilterType2::Pointer filter2=CastFilterType2::New();
970
971   connector->SetInput( imagedata );
972   filter2->SetInput(connector->GetOutput());
973
974   typedef   itk::CurvatureAnisotropicDiffusionImageFilter< 
975                                InternalImageType, 
976                                InternalImageType >  SmoothingFilterType;
977
978   SmoothingFilterType::Pointer smoothing = SmoothingFilterType::New();
979
980   typedef   itk::GradientMagnitudeRecursiveGaussianImageFilter< 
981                                InternalImageType, 
982                                InternalImageType >  GradientFilterType;
983
984   typedef   itk::SigmoidImageFilter<                               
985                                InternalImageType, 
986                                InternalImageType >  SigmoidFilterType;
987
988   GradientFilterType::Pointer  gradientMagnitude = GradientFilterType::New();
989
990   SigmoidFilterType::Pointer sigmoid = SigmoidFilterType::New();
991
992   sigmoid->SetOutputMinimum(  0.0  );
993   sigmoid->SetOutputMaximum(  255.0  );
994
995
996   typedef  itk::FastMarchingImageFilter< 
997                               InternalImageType, 
998                               InternalImageType >    FastMarchingFilterType;
999
1000
1001   FastMarchingFilterType::Pointer  fastMarching = FastMarchingFilterType::New();
1002
1003   typedef  itk::GeodesicActiveContourLevelSetImageFilter< InternalImageType, 
1004                 InternalImageType >    GeodesicActiveContourFilterType;
1005   GeodesicActiveContourFilterType::Pointer geodesicActiveContour = 
1006                                      GeodesicActiveContourFilterType::New();
1007
1008   typedef  itk::ZeroCrossingImageFilter< 
1009                               InternalImageType, 
1010                               InternalImageType >    ZeroCrossingFilterType;
1011 ZeroCrossingFilterType::Pointer zeroCrossing =
1012                                                                         ZeroCrossingFilterType::New();
1013
1014 const double propagationScaling = atof( prop );
1015
1016   geodesicActiveContour->SetPropagationScaling( propagationScaling );
1017   geodesicActiveContour->SetCurvatureScaling( 1.0 );
1018   geodesicActiveContour->SetAdvectionScaling( 1.0 );
1019
1020   geodesicActiveContour->SetMaximumRMSError( 0.02 );
1021   int it=atoi( iter );
1022   geodesicActiveContour->SetNumberOfIterations( it );
1023
1024   smoothing->SetInput( filter2->GetOutput() );
1025   gradientMagnitude->SetInput( smoothing->GetOutput() );
1026   sigmoid->SetInput( gradientMagnitude->GetOutput() );
1027   fastMarching->SetInput( sigmoid->GetOutput() );
1028   geodesicActiveContour->SetInput(  fastMarching->GetOutput() );
1029   geodesicActiveContour->SetFeatureImage( sigmoid->GetOutput() );
1030   
1031   zeroCrossing->SetInput( geodesicActiveContour->GetOutput() );
1032   //thresholder->SetInput( zeroCrossing->GetOutput() );
1033   thresholder->SetInput( geodesicActiveContour->GetOutput() );
1034   connector2->SetInput( thresholder->GetOutput()  );
1035   
1036
1037   smoothing->SetTimeStep( 0.125 );
1038   smoothing->SetNumberOfIterations(  5 );
1039   smoothing->SetConductanceParameter( 9.0 );
1040
1041
1042   const double sigma = atof( sigm );
1043   gradientMagnitude->SetSigma(  sigma  );
1044
1045   const double alpha =  atof( alf );
1046   const double beta  =  atof( bet );
1047
1048   sigmoid->SetAlpha( alpha );
1049   sigmoid->SetBeta(  beta  );
1050   
1051   typedef FastMarchingFilterType::NodeContainer  NodeContainer;
1052   typedef FastMarchingFilterType::NodeType       NodeType;
1053
1054   NodeContainer::Pointer seeds = NodeContainer::New();
1055
1056   InternalImageType::IndexType  seedPosition;
1057   seedPosition[0] = x;
1058   seedPosition[1] = y;
1059
1060   const double initialDistance = atof( distanc );
1061
1062   NodeType node;
1063
1064   const double seedValue = - initialDistance;
1065
1066   node.SetValue( seedValue );
1067   node.SetIndex( seedPosition );
1068         
1069   seeds->Initialize();
1070   seeds->InsertElement( 0, node );
1071
1072   fastMarching->SetTrialPoints(  seeds  );
1073
1074   fastMarching->SetSpeedConstant( 1.0 );
1075   
1076   fastMarching->SetOutputSize( 
1077            connector->GetOutput()->GetBufferedRegion().GetSize() );
1078   
1079   fastMarching->SetStoppingValue( 800 );
1080   try
1081     {
1082                 
1083         connector2->Update();
1084         vtkImageData *idata = connector2->GetOutput();
1085
1086         vtkMarchingContourFilter* cntVTK = vtkMarchingContourFilter::New( );
1087         
1088         cntVTK->SetInput( idata );
1089         
1090         cntVTK->SetNumberOfContours( 1 );
1091         cntVTK->SetValue( 0, 255 );
1092         cntVTK->Update( );
1093         cntVTK->UpdateInformation();
1094                 
1095         vtkCleanPolyData* cpd = vtkCleanPolyData::New( );
1096         cpd->SetInput( cntVTK->GetOutput( ) );
1097         cpd->Update( );
1098         cpd->UpdateInformation();
1099
1100         vtkPolyDataConnectivityFilter* conn = vtkPolyDataConnectivityFilter::New( );
1101         conn->SetExtractionModeToLargestRegion( );
1102         conn->SetInput( cpd->GetOutput( ) );
1103         conn->Update( );
1104         conn->UpdateInformation();
1105
1106         vtkStripper* vtkstripper = vtkStripper::New( );
1107         vtkstripper->SetInput( conn->GetOutput() );
1108         vtkstripper->Update();
1109         vtkstripper->UpdateInformation();
1110
1111
1112         vtkPolyData* polyDataResult =  cntVTK->GetOutput();
1113         std::cout<<"Points "<<polyDataResult->GetNumberOfPoints()<<std::endl;
1114         polyDataResult->Update( );
1115         polyDataResult->UpdateInformation();
1116
1117 //EED
1118         /*
1119 ofstream myfile;
1120 myfile.open ("C:/Creatis/example.txt");
1121 myfile << "\n";
1122 polyDataResult->Print(myfile);
1123 myfile << "-------------------------------------\n";
1124 polyDataResult->GetLines()->Print(myfile);
1125 myfile.close();*/
1126
1127         cntVTK          -> Delete();
1128         cpd                     -> Delete();
1129         conn            -> Delete();
1130
1131
1132 //--Calculating control points
1133
1134         std::vector<double> vecX;
1135         std::vector<double> vecY;
1136         std::vector<double> vecXo;
1137         std::vector<double> vecYo;
1138         std::vector<double>::iterator vecXoi;
1139         std::vector<double>::iterator vecYoi;
1140         std::vector<double> vecZ;
1141
1142         std::vector<double> vecCtrlPointX;
1143         std::vector<double> vecCtrlPointY;
1144         std::vector<double> vecCtrlPointZ;
1145
1146
1147         double *p;
1148         double xAct=0;
1149         double yAct=0;
1150         int ii,size=polyDataResult->GetNumberOfPoints();
1151 ofstream myfile;
1152 myfile.open ("C:/Creatis/example2.txt");
1153
1154         size=polyDataResult->GetNumberOfPoints();
1155         for (ii=0;ii<size;ii++)
1156         {
1157                 if(ii==0)
1158                 {
1159                         xAct=x;
1160                         yAct=y;
1161                 }
1162                 p       = polyDataResult->GetPoint(ii);
1163                 double x=p[0];
1164                 double y=p[1];
1165                 /*if(fabs(yAct-y)>20)
1166                 {
1167                         if((xAct-x)>1 || (xAct-x)<-1)
1168                         {
1169                         vecX.push_back( p[0] );
1170                         vecY.push_back( p[1] );
1171                         myfile <<p[0]<<","<<p[1]<<"\n";
1172                         std::cout<<" x Anterior "<<xAct<<" x actual "<<x<<std::endl;
1173                 std::cout<<" y Anterior "<<yAct<<" y actual "<<y<<std::endl;
1174                 std::cout<<" x "<<p[0]<<" y "<<p[1]<<std::endl;
1175                         vecZ.push_back( -900 );
1176                         xAct=x;
1177                         yAct=y;
1178                         }
1179                         else
1180                         {
1181                                 vecXo.push_back(p[0]);
1182                                 vecYo.push_back(p[1]);
1183                         }
1184                         
1185                 }
1186                 else*/ if(fabs(xAct-x)>11)
1187                 {
1188                         vecXo.push_back(p[0]);
1189                         vecYo.push_back(p[1]);
1190                 }
1191                 else
1192                 {
1193                 vecX.push_back( p[0] );
1194                 myfile <<p[0]<<","<<p[1]<<"\n";
1195                 std::cout<<" x Anterior "<<xAct<<" x actual "<<x<<std::endl;
1196                 std::cout<<" y Anterior "<<yAct<<" y actual "<<y<<std::endl;
1197                 std::cout<<" x "<<p[0]<<" y "<<p[1]<<std::endl;
1198                 vecY.push_back( p[1] );
1199                 vecZ.push_back( -900 );
1200                 xAct=x;
1201                 yAct=y;
1202                 }
1203                 
1204                 
1205         }
1206
1207         while(!vecXo.empty())
1208         {
1209                 vecX.push_back(vecXo.back());
1210                 std::cout<<" x Siguiente "<<vecXo.back();
1211                 vecXo.pop_back();
1212                 vecZ.push_back( -900 );
1213         }
1214         while(!vecYo.empty())
1215         {
1216                 vecY.push_back(vecYo.back());
1217                         vecYo.pop_back();
1218         }
1219         myfile.close();
1220
1221         /*for(int l=0;l<vecX.size();l++)
1222         {
1223                 if(l==0)
1224                 {
1225             vecXo.push_back(p[0]);
1226                         vecYo.push_back(p[1]);
1227                 }
1228                 else
1229                 {
1230                         if(vecXoi[l-1]==)
1231                         {
1232                         }
1233                 }
1234
1235         }*/
1236
1237         ExtractControlPoints2D *extractcontrolpoints2d = new ExtractControlPoints2D();
1238
1239         extractcontrolpoints2d->SetContour( &vecX , &vecY , &vecZ );
1240         
1241 int method=2;
1242         if (method==0){
1243                 extractcontrolpoints2d->GetInitialControlPoints( &vecCtrlPointX , &vecCtrlPointY , &vecCtrlPointZ );
1244         }
1245         else if (method==1){
1246                 extractcontrolpoints2d->GetControlPoints(  &vecCtrlPointX , &vecCtrlPointY , &vecCtrlPointZ );
1247         }
1248         else if (method==2){
1249                 extractcontrolpoints2d->SetSamplingControlPoints( 15 );
1250                 extractcontrolpoints2d->GetSamplingControlPoints(  &vecCtrlPointX , &vecCtrlPointY , &vecCtrlPointZ );
1251         }
1252         //--Adding contour to the system
1253
1254         std::vector<int> actualInstantVector;
1255         _instantPanel->getInstant( actualInstantVector );
1256         actualInstantVector[1]=z;
1257
1258         int j,sizeCtrPt = vecCtrlPointX.size();
1259         
1260         manualContourModel *manModelContour =  kernelManager->factoryManualContourModel( typeofcontour );
1261         manModelContour->SetNumberOfPointsSpline( ((sizeCtrPt/100)+1)*100 );
1262         if (sizeCtrPt>=3){
1263                 for (j=0 ; j<sizeCtrPt ; j++)
1264                 {
1265                         manModelContour->AddPoint( vecCtrlPointX[j] , vecCtrlPointY[j] , vecCtrlPointZ[j]  );
1266                 } // for
1267                 std::string theName;
1268                 //theName = _modelManager->createOutline( manModelContour, actualInstantVector );
1269                 theName = kernelManager->createOutline( manModelContour, actualInstantVector );
1270                 bool addedModel = theName.compare("") != 0;
1271                 if( addedModel )
1272                 {
1273                         double spc[3];//Si no hay imagen pero hay contornos que spacing se pone por default
1274                         _theViewPanel->getSpacing(spc); 
1275                         //Adding the manualContourControler to interface objects structure
1276                         //Adding the manualViewContour to interface objects structure           
1277                         //_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.
1278                         _theViewPanel->configureViewControlTo(theName, manModelContour, spc, typeofcontour);
1279                         //_theViewPanel->getSceneManager()->configureViewControlTo( theName, manModelContour,spc, typeofcontour ) ;
1280                 }       // if addedModel
1281         } // if sizeCtrPt
1282
1283                 
1284                  
1285                  WriterType::Pointer writer = WriterType::New();
1286          CastFilterType3::Pointer caster = CastFilterType3::New();
1287                  
1288                  caster->SetInput( gradientMagnitude->GetOutput() );
1289                  writer->SetInput( caster->GetOutput() );
1290                  writer->SetFileName("Gradient Magnitude.png");
1291                  caster->SetOutputMinimum(   0 );
1292                  caster->SetOutputMaximum( 255 );
1293                  writer->Update();
1294                 
1295                  CastFilterType3::Pointer caster2 = CastFilterType3::New();
1296                  WriterType::Pointer writer2 = WriterType::New();
1297
1298                  caster2->SetInput( sigmoid->GetOutput() );
1299                  writer2->SetInput( caster2->GetOutput() );
1300                  writer2->SetFileName("Sigmoid.png");
1301                  caster2->SetOutputMinimum(   0 );
1302                  caster2->SetOutputMaximum( 255 );
1303                  writer2->Update();
1304
1305                  CastFilterType3::Pointer caster3 = CastFilterType3::New();
1306                  WriterType::Pointer writer3 = WriterType::New();
1307
1308                  caster3->SetInput( fastMarching->GetOutput() );
1309                  writer3->SetInput( caster3->GetOutput() );
1310                  writer3->SetFileName("FastMarching.bmp");
1311                  caster3->SetOutputMinimum(   0 );
1312                  caster3->SetOutputMaximum( 255 );
1313                  writer3->Update();
1314
1315                  CastFilterType3::Pointer caster4 = CastFilterType3::New();
1316                  WriterType::Pointer writer4 = WriterType::New();
1317
1318                  caster4->SetInput( geodesicActiveContour->GetOutput() );
1319                  writer4->SetInput( caster4->GetOutput() );
1320                  writer4->SetFileName("GeodesicActiveContour.png");
1321                  caster4->SetOutputMinimum(   0 );
1322                  caster4->SetOutputMaximum( 255 );
1323                  writer4->Update();
1324
1325                  CastFilterType3::Pointer caster5 = CastFilterType3::New();
1326                  WriterType::Pointer writer5 = WriterType::New();
1327
1328                  caster5->SetInput( zeroCrossing->GetOutput() );
1329                  writer5->SetInput( caster5->GetOutput() );
1330                  writer5->SetFileName("ZeroCrossing.bmp");
1331                  caster5->SetOutputMinimum(   0 );
1332                  caster5->SetOutputMaximum( 255 );
1333                  writer5->Update();
1334     }
1335   catch( itk::ExceptionObject & excep )
1336     {
1337     std::cerr << "Exception caught !" << std::endl;
1338     std::cerr << excep << std::endl;
1339     }
1340 }
1341
1342 void wxContourMainFrame::onSegmentationOneSlice(int isovalue,int sampling,int method){
1343         
1344         //JCP 20-10-08 Undo redo implementation
1345         saveState();
1346         //JCP 20-10-08 Undo redo implementation
1347         
1348         wxBusyCursor wait;
1349         int                                     x                                       = _theViewPanel->GetX();
1350         int                                     y                                       = _theViewPanel->GetY();
1351         int                                     z                                       = _theViewPanel->GetZ();
1352         SegmentationOneSlice( x,y,z,isovalue, sampling, method );
1353         RefreshInterface();
1354 }
1355
1356
1357 void wxContourMainFrame::SegmentationOneSlice( int x, int y, int z, int isovalue, int sampling, int method )
1358 {               
1359         int typeofcontour = 1;
1360         //--Extracting Contour
1361         //vtkImageData  *imagedata      = _theViewPanel->getSceneManager()->GetImageData();
1362         vtkImageData    *imagedata      = getImageData();
1363 //              double                  *range          = imagedata->GetScalarRange();  
1364 //              double                  thr                     = 1;
1365
1366         vtkImageReslice *imageReslice = vtkImageReslice::New();
1367 //EED
1368 //              double spc[3];
1369 //              imagedata->GetSpacing(spc);
1370 //              x = x*spc[0];
1371 //              y = y*spc[1];
1372 //              z = z*spc[3];
1373
1374         imageReslice->SetInput( imagedata );
1375         imageReslice->SetInformationInput(imagedata);
1376         imageReslice->SetResliceAxesDirectionCosines(1,0,0, 0,1,0 ,0,0,1);
1377         imageReslice->SetResliceAxesOrigin(0,0,z);
1378         imageReslice->SetOutputDimensionality(2);
1379         imageReslice->SetInterpolationModeToLinear();
1380
1381         imagedata = imageReslice->GetOutput();
1382         imagedata->Update();
1383         imagedata->UpdateInformation();
1384
1385         vtkContourFilter* cntVTK = vtkContourFilter::New( );
1386         cntVTK->SetInput( imagedata );
1387
1388         cntVTK->SetNumberOfContours( 1 );
1389         //cntVTK->SetValue( 0, vmin );
1390 //              cntVTK->SetValue( 0, (range[1]*thr/100) );
1391         cntVTK->SetValue( 1, isovalue );
1392 //      cntVTK->SetValue( 1, vmax );
1393         cntVTK->Update( );
1394         cntVTK->UpdateInformation();
1395                 
1396         vtkCleanPolyData* cpd = vtkCleanPolyData::New( );
1397         cpd->SetInput( cntVTK->GetOutput( ) );
1398         cpd->ConvertLinesToPointsOff( );
1399         cpd->Update( );
1400         cpd->UpdateInformation();
1401
1402         vtkPolyDataConnectivityFilter* conn = vtkPolyDataConnectivityFilter::New( );
1403         conn->SetExtractionModeToClosestPointRegion( );
1404         //conn->SetMaxRecursionDepth( 3000 );
1405                 
1406         conn->SetInput( cpd->GetOutput( ) );
1407                 
1408         conn->SetClosestPoint( x, y, 0 );
1409         conn->Update( );
1410         conn->UpdateInformation();
1411                 
1412         vtkCleanPolyData* cpd2 = vtkCleanPolyData::New( );
1413         cpd2->SetInput( conn->GetOutput( ) );
1414         cpd2->Update();
1415         cpd2->UpdateInformation();
1416
1417         vtkStripper* vtkstripper = vtkStripper::New( );
1418         vtkstripper->SetInput( cpd2->GetOutput() );
1419         vtkstripper->Update();
1420         vtkstripper->UpdateInformation();
1421
1422
1423         vtkPolyData* polyDataResult =  vtkstripper->GetOutput();
1424
1425         polyDataResult->Update( );
1426         polyDataResult->UpdateInformation();
1427
1428 /* EED
1429 ofstream myfile;
1430 myfile.open ("c:/temp/example.txt");
1431 myfile << "\n";
1432 polyDataResult->Print(myfile);
1433 myfile << "-------------------------------------\n";
1434 polyDataResult->GetLines()->Print(myfile);
1435 myfile.close();
1436 */
1437
1438         cntVTK          -> Delete();
1439         cpd2            -> Delete();
1440         cpd                     -> Delete();
1441         conn            -> Delete();
1442
1443
1444 //--Calculating control points
1445
1446         std::vector<double> vecX;
1447         std::vector<double> vecY;
1448         std::vector<double> vecZ;
1449
1450         std::vector<double> vecCtrlPointX;
1451         std::vector<double> vecCtrlPointY;
1452         std::vector<double> vecCtrlPointZ;
1453
1454
1455         double *p;
1456         int ii,size=polyDataResult->GetNumberOfPoints();
1457         int id;
1458         for (ii=1;ii<=size;ii++)
1459         {
1460                 id      = polyDataResult->GetLines()->GetData()->GetValue(ii);
1461                 p       = polyDataResult->GetPoint(id);
1462 //              double x=p[0];
1463 //              double y=p[1];
1464                 vecX.push_back( p[0] );
1465                 vecY.push_back( p[1] );
1466                 vecZ.push_back( -900 );
1467 //                      vecZ.push_back( p[2] );
1468         }
1469
1470
1471         ExtractControlPoints2D *extractcontrolpoints2d = new ExtractControlPoints2D();
1472         extractcontrolpoints2d->SetContour( &vecX , &vecY , &vecZ );
1473
1474 //PROOFS
1475         /*if (methodRadiobox->GetSelection()==0){
1476                 extractcontrolpoints2d->GetInitialControlPoints( &vecCtrlPointX , &vecCtrlPointY , &vecCtrlPointZ );
1477         }
1478         if (methodRadiobox->GetSelection()==1){
1479                 extractcontrolpoints2d->GetControlPoints(  &vecCtrlPointX , &vecCtrlPointY , &vecCtrlPointZ );
1480         }
1481         if (methodRadiobox->GetSelection()==2){
1482                 extractcontrolpoints2d->SetSamplingControlPoints( sampling );
1483                 extractcontrolpoints2d->GetSamplingControlPoints(  &vecCtrlPointX , &vecCtrlPointY , &vecCtrlPointZ );
1484         }*/
1485
1486         if (method==0){
1487                 extractcontrolpoints2d->GetInitialControlPoints( &vecCtrlPointX , &vecCtrlPointY , &vecCtrlPointZ );
1488         }
1489         else if (method==1){
1490                 extractcontrolpoints2d->GetControlPoints(  &vecCtrlPointX , &vecCtrlPointY , &vecCtrlPointZ );
1491         }
1492         else if (method==2){
1493                 extractcontrolpoints2d->SetSamplingControlPoints( sampling );
1494                 extractcontrolpoints2d->GetSamplingControlPoints(  &vecCtrlPointX , &vecCtrlPointY , &vecCtrlPointZ );
1495         }
1496
1497         //--Adding contour to the system
1498
1499         std::vector<int> actualInstantVector;
1500         _instantPanel->getInstant( actualInstantVector );
1501         actualInstantVector[1]=z;
1502
1503         int j,sizeCtrPt = vecCtrlPointX.size();
1504         manualContourModel *manModelContour =  kernelManager->factoryManualContourModel( typeofcontour );
1505         manModelContour->SetNumberOfPointsSpline( ((sizeCtrPt/100)+1)*100 );
1506         if (sizeCtrPt>=3){
1507                 for (j=0 ; j<sizeCtrPt ; j++)
1508                 {
1509                         manModelContour->AddPoint( vecCtrlPointX[j] , vecCtrlPointY[j] , vecCtrlPointZ[j]  );
1510                 } // for
1511                 std::string theName;
1512                 //theName = _modelManager->createOutline( manModelContour, actualInstantVector );
1513                 theName = kernelManager->createOutline( manModelContour, actualInstantVector );
1514                 bool addedModel = theName.compare("") != 0;
1515                 if( addedModel )
1516                 {
1517                         double spc[3];//Si no hay imagen pero hay contornos que spacing se pone por default
1518                         _theViewPanel->getSpacing(spc);                                 
1519                         //Adding the manualContourControler to interface objects structure
1520                         //Adding the manualViewContour to interface objects structure           
1521                         //_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.
1522                         _theViewPanel->configureViewControlTo(theName, manModelContour, spc, typeofcontour);
1523                         //_theViewPanel->getSceneManager()->configureViewControlTo( theName, manModelContour,spc, typeofcontour ) ;
1524                 }       // if addedModel
1525         } // if sizeCtrPt
1526 }
1527
1528 int wxContourMainFrame::GetImageDataSizeZ(){
1529         return _theViewPanel->GetImageDataSizeZ();
1530 }
1531
1532 void wxContourMainFrame::GetImageDataRange(double *range){
1533         _theViewPanel->GetImageDataRange(range);
1534 }
1535
1536 void wxContourMainFrame::onSegmentationAllSlice(int minZ,int maxZ,int isovalue,int sampling,int method){
1537         //JCP 20-10-08 Undo redo implementation
1538         saveState();
1539         //JCP 20-10-08 Undo redo implementation
1540         
1541         wxBusyCursor wait;
1542         int                                     x                                       = _theViewPanel->GetX();
1543         int                                     y                                       = _theViewPanel->GetY();
1544         int z;
1545         double porcent; 
1546         wxString tmpString;     
1547         double totalZ = maxZ-minZ+1;
1548         for( z=minZ ; z<=maxZ ; z++ )
1549         {
1550                 porcent = 100.0* (z-minZ)/totalZ;
1551                 tmpString.Printf(_T("  %d %c            %d/%d            %d"), (int)porcent , 37 , z-minZ+1, (int)totalZ,z );
1552                 interfMainPanel::getInstance()->setLabelSegmentationPanelVTK(tmpString);
1553                 //_staticTextSegmentation->SetLabel(tmpString);
1554                 SegmentationOneSlice( x,y,z,isovalue, sampling,method );
1555         }
1556         interfMainPanel::getInstance()->setLabelSegmentationPanelVTK(_T("   "));
1557         RefreshInterface();
1558 }
1559
1560
1561 //Creates a reference line to be used as the axis of the mirroring
1562 void wxContourMainFrame::referenceLine()
1563 {
1564     wxBusyCursor wait;
1565         double spc[3];
1566
1567         vtkImageData *vtkimagedata = _theViewPanel->getImageData();
1568         vtkimagedata->GetSpacing(spc);
1569
1570         wxVtkBaseView * viewer2D = _theViewPanel->getWxVtkBaseView();
1571
1572         _refLineControl = new manualLineControler();
1573         _refLineModel   = new manualContourModelLine();
1574         _refLineView = new manualViewLine();
1575         _refLineView->SetModel( _refLineModel );
1576         _refLineView->SetWxVtkBaseView( viewer2D );
1577         _refLineView->SetRange( 2 );
1578         _refLineView->SetZ( 1200 );
1579
1580         _refLineView->SetSpacing(spc);
1581
1582         _refLineView->SetColorNormalContour(0, 0, 1);
1583         _refLineView->SetColorEditContour(0, 0.5, 0.5);
1584         _refLineView->SetWidthLine(4);
1585
1586         _refLineControl->SetModelView( _refLineModel , _refLineView );
1587         viewer2D->GetInteractorStyleBaseView()->AddInteractorStyleMaracas( _refLineControl );
1588         _refLineModel->SetCloseContour(false);
1589         _refLineControl->CreateNewManualContour();
1590
1591         double z = _refLineControl->GetZ();
1592 /*
1593         _refLineControl->AddPoint(50,100,z);
1594         _refLineControl->AddPoint(80,40,z);
1595         _refLineControl->SetCompleteCreation(true);
1596
1597         _refLineModel->AddPoint(50,100,z);
1598         _refLineModel->AddPoint(80,40,z);
1599         _refLineModel->UpdateSpline();
1600
1601         _refLineView->UpdateViewPoint(0);
1602         _refLineView->UpdateViewPoint(1);
1603 */
1604
1605         _refLineControl->SetActive(true);
1606         _refLineView->RefreshContour();
1607 }
1608
1609 //Hides the referenceLine
1610 void wxContourMainFrame::refLineHide()
1611 {
1612         if (_refLineControl!=NULL)
1613         {
1614                 _refLineView->RemoveCompleteContourActor();
1615                 _refLineControl->SetEditable(false);
1616                 _refLineControl->SetActive(false);
1617         }
1618 }
1619
1620 //Shows the referenceLine
1621 void wxContourMainFrame::refLineShow()
1622 {
1623         if (_refLineControl!=NULL)
1624         {
1625                 wxVtkBaseView * viewer2D = _theViewPanel->getWxVtkBaseView();
1626
1627                 _refLineView->SetModel( _refLineModel );
1628                 _refLineView->SetWxVtkBaseView( viewer2D );
1629                 _refLineView->SetRange( 2 );
1630                 _refLineView->SetZ( 1200 );
1631
1632                 _refLineControl->SetModelView( _refLineModel , _refLineView );
1633                 viewer2D->GetInteractorStyleBaseView()->AddInteractorStyleMaracas( _refLineControl );
1634                 _refLineControl->CreateNewManualContour();
1635                 _refLineControl->SetActive(true);
1636                 _refLineView->RefreshContour();
1637         }
1638 }
1639
1640 void wxContourMainFrame::onMirror()
1641 {
1642         //AD:02-09
1643         std::vector<std::string> currentSelection = _theViewPanel->getSelectedObjects();
1644         std::vector<std::string> filterCurrentSelection;
1645
1646         std::vector<int> tempVector;
1647         _instantPanel->getInstant( tempVector );
1648     _performingOperation->reset();
1649         _performingOperation->setStartCommand( COPY );
1650         _performingOperation->setStartOperationInstantVector( tempVector );
1651         _performingOperation->setKeyNamesOperationElems( currentSelection );
1652
1653         char theStartCommand = _performingOperation->getStartCommand();
1654         if (  theStartCommand == COPY )
1655         {
1656                 //JCP 20-10-08 Undo redo implementation
1657                 saveState();
1658                 //JCP 20-10-08 Undo redo implementation
1659                 std::vector<int> tempVector;
1660                 _instantPanel->getInstant( tempVector );
1661                 _performingOperation->setEndOperationInstantVector ( tempVector );
1662                 std::vector<std::string> elems = _performingOperation->getKeyNamesOperationElems();
1663                 int i,size = elems.size();                      
1664                 for( i=0; i<size; i++ )
1665                 {                               
1666                         createMirrorContourOf( elems[i], tempVector, i>0 );
1667                 }               
1668         }
1669
1670         //deleteContour( _refName );
1671         //_refName = "";
1672 }
1673
1674 void wxContourMainFrame::showAxis(bool show){
1675         _theViewPanel->SetVisibleAxis(show);
1676         _theViewPanel->Refresh();
1677 }
1678
1679
1680 void wxContourMainFrame::onRigidPressed(){
1681         std::vector<std::string> currentSelection = _theViewPanel->getSelectedObjects();
1682         int elementsSelected = currentSelection.size();
1683
1684         if ( elementsSelected >= 1 ){
1685                 //JCP 20-10-08 Undo redo implementation
1686                 saveState();
1687                 //JCP 20-10-08 Undo redo implementation
1688
1689                 std::vector<int> tempVector;
1690                 _instantPanel->getInstant( tempVector );
1691                 Instant instant(&tempVector);
1692
1693                 int i , size=currentSelection.size();
1694                 for ( i=0 ; i<size ; i++ )
1695                 {
1696                         kernelManager->changeContourOfManager(currentSelection[i], &instant);
1697                 } // i
1698         }
1699 }
1700
1701 void wxContourMainFrame::onWidthOfContour(double width){
1702
1703         _theViewPanel->removeSceneContours();
1704         _theViewPanel->SetWidthContour(width);
1705         
1706         //_theViewPanel->getSceneManager()->SetWidthContour( width );
1707
1708         RefreshInterface();
1709 }
1710 int wxContourMainFrame::getColorWindow(){
1711         return _theViewPanel->getColorWindow();
1712 }
1713 int wxContourMainFrame::getWindowLevel(){
1714         return _theViewPanel->getWindowLevel();
1715 }
1716
1717 void wxContourMainFrame::onBrigthnessColorWindowLevel(int colorwindow,int windowlevel){
1718         _theViewPanel->onBrigthnessColorWindowLevel(colorwindow, windowlevel);
1719
1720         
1721         RefreshInterface();
1722 }
1723
1724 void wxContourMainFrame::onInterpolation(bool interpolate){
1725         _theViewPanel->onInterpolation(interpolate);    
1726         RefreshInterface();
1727 }
1728
1729 void wxContourMainFrame::onChangeInstant(std::string name,int actual){
1730         _instantPanel->setConceptValue( name, actual );
1731 }
1732
1733 void wxContourMainFrame::resetAppend(){
1734         kernelManager->resetAppend();
1735         
1736 }
1737
1738 void wxContourMainFrame::onSpreadAdd(){
1739         std::vector<double> vecX; 
1740         std::vector<double> vecY; 
1741         std::vector<double> vecZ; 
1742         _theViewPanel->GetPointsOfActualContour(&vecX , &vecY , &vecZ );
1743         
1744         std::vector<int> tempVector;
1745         _instantPanel->getInstant( tempVector );
1746
1747         std::string val = kernelManager->onSpreadAdd(&vecX , &vecY , &vecZ, tempVector);
1748
1749         interfMainPanel::getInstance()->appendStringSpread(val);
1750         
1751 }
1752
1753 void wxContourMainFrame::onSpreadGo(int type){
1754
1755         //JCP 20-10-08 Undo redo implementation
1756         saveState();
1757         //JCP 20-10-08 Undo redo implementation
1758
1759         wxBusyCursor wait;      
1760         std::vector<double> vecCtrlPointX;
1761         std::vector<double> vecCtrlPointY;
1762         std::vector<double> vecCtrlPointZ;
1763         double  minZ,maxZ;
1764         int z;
1765
1766         std::vector<int> tempVector;
1767         _instantPanel->getInstant( tempVector );
1768 //              tempVector[1];
1769
1770         kernelManager->getMaxMinZ(&minZ,&maxZ);
1771 //JSTG_16-07-08_----------------------------------------------------------------
1772         //_contourPropagation->setInterpolationNumber(maxZ-minZ+1);
1773         kernelManager->CalculeSplinePropagation();
1774
1775         double          totalZ = maxZ-minZ+1;
1776         double          porcent;
1777         wxString        tmpString;
1778 //--------------------------------------------------------------------
1779         for ( z=(int)minZ ; z<=(int)maxZ ; z++ )
1780         {
1781                 porcent = 100.0* (z-minZ)/totalZ;
1782                 int numero = (int)(z-minZ+1)/(int)totalZ;
1783                 std::string stringtemp = "  "+kernelManager->intToString(porcent)+"%            "+kernelManager->intToString(numero)+"            "+kernelManager->intToString(z);
1784                 
1785                 interfMainPanel::getInstance()->setStringSpread(stringtemp);    
1786
1787                 int typeofcontour = 1;
1788                 std::string theName;
1789                 manualContourModel* manModelContour = kernelManager->GetPoints(z, type, &vecCtrlPointX,&vecCtrlPointY,&vecCtrlPointZ, theName,typeofcontour, tempVector);
1790
1791                 if( manModelContour!=NULL ){
1792                         double spc[3];//Si no hay imagen pero hay contornos que spacing se pone por default
1793                         this->_theViewPanel->getSpacing(spc);                                   
1794                         //Adding the manualContourControler to interface objects structure
1795                         //Adding the manualViewContour to interface objects structure           
1796                         //_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.
1797                         _theViewPanel->configureViewControlTo( theName, manModelContour,spc,typeofcontour ) ;
1798                 } // if addedModel
1799         } 
1800         if(z > maxZ){
1801                 porcent = 100.0;
1802                 int numero = (int)(z-minZ+1)/(int)totalZ;
1803                 std::string stringtemp = "  "+kernelManager->intToString(porcent)+"%            "+kernelManager->intToString(numero)+"            "+kernelManager->intToString(z);
1804                 
1805                 interfMainPanel::getInstance()->setStringSpread(stringtemp);
1806         }// for z
1807         //RefreshInterface();
1808 }
1809
1810 void wxContourMainFrame::getInstantVector(std::vector<int>& tempVector){
1811         
1812 }
1813
1814 std::vector<std::string> wxContourMainFrame::getOutlinesName(int slide){
1815         std::vector<int> tempVector;
1816         _instantPanel->getInstant(tempVector);
1817         //Asignation of slide number should be different ex by name
1818         tempVector[1]=slide;
1819         return kernelManager->getOutlinesNameAtInstant(tempVector);
1820 }
1821
1822 void wxContourMainFrame::onInformationContourLabels(int typeContourGroup,int selection,int minimumZ,int maximumZ){
1823         int maxContourGroup     =       0;
1824
1825         ContourExtractData      *contourextractdata = new ContourExtractData();
1826         
1827         contourextractdata ->SetTypeOperation( typeContourGroup % 3 );
1828
1829         std::vector<manualContourModel*> lstManConMod;
1830         std::vector<manualContourModel*> lstManConModTmp;
1831         std::vector<manualContourModel*> lstManConModExp;
1832         std::vector<double> pLstValue;
1833         std::vector<double> pLstValuePosX;
1834         std::vector<double> pLstValuePosY;
1835         std::vector<double> pLstValuePosZ;
1836
1837         int             resultSize; 
1838         int             resultGrayRangeCount;
1839         double  resultMin; 
1840         double  resultMax;
1841         double  resultAverage;
1842         double  resultStandardeviation;
1843
1844         std::vector<int> tempVector;
1845         _instantPanel->getInstant( tempVector );
1846
1847         vtkImageData *imagedata = _theViewPanel->getImageData();
1848         int sizeZ = _theViewPanel->GetImageDataSizeZ();
1849         int z;
1850         int ii,sizeLstContourThings;
1851
1852
1853         int minZ,maxZ;
1854         double totalZ;
1855         double porcent; 
1856         wxString tmpString;
1857
1858         
1859
1860         if (selection==0 ) // actual slice
1861         {
1862                 std::vector<int> tempVector;
1863                 _instantPanel->getInstant( tempVector );
1864                 int actualSlice = tempVector[1];
1865                 minZ    = actualSlice;
1866                 maxZ    = actualSlice;
1867         }
1868         else if (selection==2 ) // All slices
1869         {
1870                 minZ    = 0;
1871                 maxZ    = sizeZ-1;
1872         }
1873         else if (selection==1 ) // slice range
1874         {
1875                 minZ    = minimumZ;
1876                 maxZ    = maximumZ;
1877         }
1878         
1879
1880         totalZ  = maxZ-minZ+1;
1881         contourextractdata->SetImage( imagedata);
1882
1883 // For each slice..
1884         for ( z=minZ ; z<=maxZ ; z++ )
1885         {
1886                 
1887                 porcent = 100.0* (z-minZ)/totalZ;
1888                 tmpString.Printf(_T("  %d %c            %d/%d             %d"), (int)porcent , 37 , z-minZ+1, (int)totalZ ,z);
1889
1890                 interfMainPanel::getInstance()->setStringInfoPanel(tmpString);          
1891                 //_staticTextInformation->SetLabel(tmpString);
1892
1893                 //Extraction data from contours of each slice
1894                 contourextractdata->SetZtoBeAnalys( z);
1895
1896                 tempVector[1]=z;
1897                 Instant instant(&tempVector);
1898                 std::vector<ContourThing**> lstContourThings = kernelManager->getOutlinesAtInstant( &instant );
1899                 sizeLstContourThings = lstContourThings.size();
1900
1901                 lstManConMod.clear();
1902                 for (ii=0 ; ii<sizeLstContourThings ; ii++)
1903                 {
1904                         ContourThing **contourthing = lstContourThings[ii];
1905                         lstManConMod.push_back( (*contourthing)->getModel() );
1906                 }
1907                 lstManConModExp =  kernelManager->ExploseEachModel( lstManConMod );
1908
1909
1910                 wxString tempString;
1911                 tempString.Printf(_T("%d - %d"),z, sizeLstContourThings);
1912                 interfMainPanel::getInstance()->setRowLabelInfoPanel(z, tempString);
1913                 //_grid->SetRowLabelValue(z, tempString );
1914 //EED004
1915                 int iContourGroup,sizeContourGroup;
1916                 if (typeContourGroup==3) // contour separete
1917                 {
1918                         sizeContourGroup=lstManConModExp.size();
1919                         if ( maxContourGroup<sizeContourGroup ) 
1920                         {
1921                                 maxContourGroup=sizeContourGroup;
1922                         }
1923                 } else {  // contour AND OR XOR
1924                         sizeContourGroup=1;
1925                         maxContourGroup=1;
1926                 }
1927
1928                 int tmpIntA;
1929
1930
1931
1932                 for( iContourGroup=0 ; iContourGroup<sizeContourGroup ; iContourGroup++ ){
1933                         lstManConModTmp.clear();
1934                         if (typeContourGroup==3) // contour separete
1935                         {
1936                                 lstManConModTmp.push_back( lstManConModExp[iContourGroup]);
1937                         } else {  // contour AND OR XOR
1938                                 lstManConModTmp = lstManConModExp;
1939                         }
1940
1941                         contourextractdata->SetLstManualContourModel( lstManConModTmp );
1942
1943                         pLstValue.clear();
1944                         pLstValuePosX.clear();
1945                         pLstValuePosY.clear();
1946                         pLstValuePosZ.clear();
1947                         contourextractdata->GetValuesInsideCrown(       &pLstValue,
1948                                                                                                                 &pLstValuePosX,
1949                                                                                                                 &pLstValuePosY,
1950                                                                                                                 &pLstValuePosZ);
1951                         // Statistics of each slice.
1952                         contourextractdata->Statistics( &pLstValue,
1953                                                                                         minimumZ,
1954                                                                                         maximumZ,
1955                                                                                         &resultGrayRangeCount, 
1956                                                                                         &resultSize, 
1957                                                                                         &resultMin, 
1958                                                                                         &resultMax,
1959                                                                                         &resultAverage,
1960                                                                                         &resultStandardeviation);
1961                         
1962                         if (interfMainPanel::getInstance()->getNumberColsInformationPanel()<_numberOfVariablesStatistics*(iContourGroup+1)  )
1963                         {
1964                                 interfMainPanel::getInstance()->appendColsInformationPanel(_numberOfVariablesStatistics);
1965                         }
1966
1967                         tmpIntA=_numberOfVariablesStatistics*iContourGroup ;
1968
1969                         tempString.Printf(_T("%d"),resultSize);
1970                         interfMainPanel::getInstance()->setCellValueInfoPanel(z, tmpIntA, tempString);  
1971
1972                         tempString.Printf(_T("%d"),resultGrayRangeCount);
1973                         interfMainPanel::getInstance()->setCellValueInfoPanel(z, tmpIntA+1, tempString);
1974                         
1975                         tempString.Printf(_T("%f"),resultMin);
1976                         interfMainPanel::getInstance()->setCellValueInfoPanel(z, tmpIntA+2, tempString);
1977                         
1978                         tempString.Printf(_T("%f"),resultMax);
1979                         interfMainPanel::getInstance()->setCellValueInfoPanel(z, tmpIntA+3, tempString);
1980                         
1981                         tempString.Printf(_T("%f"),resultAverage);
1982                         interfMainPanel::getInstance()->setCellValueInfoPanel(z, tmpIntA+4, tempString);
1983                         
1984                         tempString.Printf(_T("%f"),resultStandardeviation);
1985                         interfMainPanel::getInstance()->setCellValueInfoPanel(z, tmpIntA+5, tempString);
1986                         
1987
1988                 } // for iContourGroup
1989         } // for z
1990
1991         int iTitleGroup;
1992         wxString tmpTitleString;
1993         int tmpIntB;
1994         for ( iTitleGroup=0 ; iTitleGroup<maxContourGroup ; iTitleGroup++ )
1995         {
1996                 tmpIntB =_numberOfVariablesStatistics*iTitleGroup;
1997                 tmpTitleString.Printf(_T("%d-Size Data"),iTitleGroup);
1998                 interfMainPanel::getInstance()->setColLableInfoPanel(tmpIntB + 0, tmpTitleString);
1999
2000                 interfMainPanel::getInstance()->setColLableInfoPanel(tmpIntB + 0, tmpTitleString );
2001                 interfMainPanel::getInstance()->setColLableInfoPanel( tmpIntB + 1, _T("Size Range") );
2002                 interfMainPanel::getInstance()->setColLableInfoPanel( tmpIntB + 2, _T("Min") );
2003                 interfMainPanel::getInstance()->setColLableInfoPanel( tmpIntB + 3, _T("Max") );
2004                 interfMainPanel::getInstance()->setColLableInfoPanel( tmpIntB + 4, _T("Average") );
2005                 interfMainPanel::getInstance()->setColLableInfoPanel( tmpIntB + 5, _T("St.Dev.") );
2006                 interfMainPanel::getInstance()->setColLableInfoPanel( tmpIntB + 6, _T(" ") );
2007         }
2008
2009         interfMainPanel::getInstance()->setStringInfoPanel( _T("") );
2010         delete contourextractdata;
2011 }
2012
2013 void wxContourMainFrame::onSaveResults(std::string directory,std::string namefile, std::string filename, int typeContourGroup){
2014     SaveValuesXYZ( directory , namefile, typeContourGroup );
2015         SaveImageResult( directory , namefile, typeContourGroup);
2016
2017         
2018         FILE *pFile=fopen(filename.c_str(),"w+");
2019
2020         int sizeZ = _theViewPanel->GetImageDataSizeZ();
2021
2022         wxString tmpString;
2023         int i,j,maxX,maxY=sizeZ;
2024         maxX= interfMainPanel::getInstance()->getNumberColsInformationPanel();//this->_grid->GetNumberCols();
2025
2026         int iTitle,sizeTitle = (maxX / _numberOfVariablesStatistics);
2027         for ( iTitle=0; iTitle<sizeTitle ; iTitle++)
2028         {
2029                 //              fprintf(pFile,"-- \t %d-Size \t SizeRange \t Min \t Max \t Ave \t StDv \t" , iTitle,tmpString.c_str() );
2030                 fprintf(pFile,"-- \t %d-Size \t SizeRange \t Min \t Max \t Ave \t StDv \t" , iTitle );
2031         }
2032         fprintf(pFile,"\n" );
2033
2034
2035
2036         for ( j=0; j<maxY ; j++)
2037         {
2038                 fprintf(pFile,"%d\t" , j );
2039                 for (i=0 ; i<maxX ; i++){
2040                         tmpString = interfMainPanel::getInstance()->getCellValue(j, i);//_grid->GetCellValue( j , i );
2041                         fprintf(pFile,"%s\t" , (const char *)(tmpString.mb_str()) );
2042                 } // for i
2043                 fprintf(pFile,"\n"  );
2044         } // for j
2045
2046         fclose(pFile);
2047 }
2048
2049 void wxContourMainFrame::SaveValuesXYZ(std::string directory,std::string namefile,int typeContourGroup)
2050 {
2051         wxBusyCursor wait;
2052         ContourExtractData      *contourextractdata = new ContourExtractData();
2053         //int typeContourGroup = this->_radiolstboxContourGroup->GetSelection();
2054         contourextractdata ->SetTypeOperation( typeContourGroup % 3 );
2055
2056         std::vector<manualContourModel*> lstManConMod;
2057         std::vector<manualContourModel*> lstManConModTmp;
2058         std::vector<manualContourModel*> lstManConModExp;
2059         std::vector<double> pLstValue;
2060         std::vector<double> pLstValuePosX;
2061         std::vector<double> pLstValuePosY;
2062         std::vector<double> pLstValuePosZ;
2063
2064         std::vector<int> tempVector;
2065         _instantPanel->getInstant( tempVector );
2066
2067         vtkImageData *imagedata = _theViewPanel->getSceneManager()->GetImageData();
2068         int sizeZ = _theViewPanel->getSceneManager()->GetImageDataSizeZ();
2069         int z;
2070         int ii,sizeLstContourThings;
2071
2072
2073         int minZ,maxZ;
2074         double totalZ;
2075         double porcent; 
2076         wxString tmpString;
2077         minZ    = 0;// _mbarrange->GetStart();
2078         maxZ    = sizeZ;//_mbarrange->GetEnd();
2079         totalZ  = maxZ-minZ+1;
2080
2081         contourextractdata->SetImage( imagedata);
2082
2083 // For each slice..
2084         for ( z=0 ; z<sizeZ ; z++)
2085         {
2086
2087                 porcent = 100.0* (z-minZ)/totalZ;
2088                 
2089                 tmpString.Printf(_T("Saving Values"));
2090                 tmpString.Printf(_T("  %d %c            %d/%d             %d"), (int)porcent , 37 , z-minZ+1, (int)totalZ ,z);
2091                 interfMainPanel::getInstance()->setStringInfoPanel(tmpString);
2092                 //_staticTextInformation->SetLabel(tmpString);
2093
2094
2095                 //Extraction data from contours of each slice
2096                 contourextractdata->SetZtoBeAnalys( z);
2097
2098                 tempVector[1]=z;
2099                 Instant instant(&tempVector);
2100                 std::vector<ContourThing**> lstContourThings = kernelManager->getOutlinesAtInstant(&instant);//this->_modelManager->getOutlinesAtInstant( &instant );
2101                 sizeLstContourThings = lstContourThings.size();
2102
2103                 lstManConMod.clear();
2104                 for (ii=0 ; ii<sizeLstContourThings ; ii++)
2105                 {
2106                         ContourThing **contourthing = lstContourThings[ii];
2107                         lstManConMod.push_back( (*contourthing)->getModel() );
2108                 }
2109                 lstManConModExp =  kernelManager->ExploseEachModel( lstManConMod );
2110
2111
2112 //EED004
2113
2114                 int iContourGroup,sizeContourGroup;
2115                 if (typeContourGroup==3) // contour separete
2116                 {
2117                         sizeContourGroup=lstManConModExp.size();
2118                 } else {  // contour AND OR XOR
2119                         sizeContourGroup=1;
2120                 }
2121
2122                 for( iContourGroup=0 ; iContourGroup<sizeContourGroup ; iContourGroup++ ){
2123                         lstManConModTmp.clear();
2124                         if (typeContourGroup==3) // contour separete
2125                         {
2126                                 lstManConModTmp.push_back( lstManConModExp[iContourGroup]);
2127                         } else {  // contour AND OR XOR
2128                                 lstManConModTmp = lstManConModExp;
2129                         }
2130
2131                         contourextractdata->SetLstManualContourModel( lstManConModTmp );
2132
2133                         pLstValue.clear();
2134                         pLstValuePosX.clear();
2135                         pLstValuePosY.clear();
2136                         pLstValuePosZ.clear();
2137                         contourextractdata->GetValuesInsideCrown(       &pLstValue,
2138                                                                                                                 &pLstValuePosX,
2139                                                                                                                 &pLstValuePosY,
2140                                                                                                                 &pLstValuePosZ);
2141
2142                         std::string temp = directory + "/" + namefile + "-slice";
2143                         temp = temp + kernelManager->intToString(z) + "-cont" + kernelManager->intToString(iContourGroup);
2144                         temp = temp + ".txt";
2145
2146                         // LG 14/01/09 : using crea
2147                         wxString filename = crea::std2wx(temp);
2148                         /*filename.Printf(_T("%s"),directory.c_str());
2149                         filename.append(_T("\\"));
2150                         filename.append(_T("%s"),namefile.c_str());
2151                         filename.append(_T("-slice"));
2152                         filename.append(_T("%d"),z);
2153                         filename.append(_T("-cont"));
2154                         filename.append(_T("%d"),iContourGroup);
2155                         filename.append(_T(".txt"));*/
2156                         //                      filename.Printf(temp.c_str());
2157
2158                         
2159
2160                         FILE *pFile=fopen((const char *)filename.mb_str(),"w+");
2161                         fprintf(pFile,"value \t x \t y \t z\n"  );
2162                         int iLstValue,sizeLstValue=pLstValue.size();
2163                         for (iLstValue=0 ; iLstValue<sizeLstValue ; iLstValue++ )
2164                         {
2165                                 fprintf(pFile,"%f\t %f\t %f\t %f\n", (float)pLstValue[iLstValue] , (float)pLstValuePosX[iLstValue], (float)pLstValuePosY[iLstValue], (float)z );
2166                         }
2167                         fclose(pFile);
2168                 } // for  iContourGroup
2169         } // for z
2170         interfMainPanel::getInstance()->setStringInfoPanel(_T(""));
2171         //_staticTextInformation->SetLabel( _T("") );
2172         delete contourextractdata;
2173 }
2174
2175 void wxContourMainFrame::SaveImageResult(std::string directory,std::string namefile, int typeContourGroup)
2176 {
2177         wxBusyCursor wait;
2178         ContourExtractData      *contourextractdata = new ContourExtractData( true );
2179         //int typeContourGroup = this->_radiolstboxContourGroup->GetSelection();
2180         if (typeContourGroup==3)
2181         {
2182                 typeContourGroup=1;
2183         }
2184         contourextractdata ->SetTypeOperation( typeContourGroup % 3 );
2185
2186         std::vector<manualContourModel*> lstManConMod;
2187         std::vector<manualContourModel*> lstManConModTmp;
2188         std::vector<manualContourModel*> lstManConModExp;
2189
2190         std::vector<int> tempVector;
2191         _instantPanel->getInstant( tempVector );
2192
2193         vtkImageData *imagedata = _theViewPanel->getImageData();
2194         int sizeZ = _theViewPanel->GetImageDataSizeZ();
2195         int z;
2196         int ii,sizeLstContourThings;
2197
2198
2199         int minZ,maxZ;
2200         double totalZ;
2201         double porcent; 
2202
2203         wxString tmpString;
2204
2205         minZ    = 0;// _mbarrange->GetStart();
2206         maxZ    = sizeZ;//_mbarrange->GetEnd();
2207         totalZ  = maxZ-minZ+1;
2208
2209         contourextractdata->SetImage( imagedata);
2210
2211 // For each slice..
2212         for ( z=0 ; z<sizeZ ; z++)
2213         {
2214
2215                 porcent = 100.0* (z-minZ)/totalZ;
2216                 tmpString.Printf(_T("Saving Values"));
2217                 tmpString.Printf(_T("%d %c            %d/%d             %d"), (int)porcent , 37 , z-minZ+1, (int)totalZ ,z);
2218                 interfMainPanel::getInstance()->setStringInfoPanel(tmpString);
2219
2220                 //Extraction data from contours of each slice
2221                 contourextractdata->SetZtoBeAnalys( z);
2222
2223                 tempVector[1]=z;
2224                 Instant instant(&tempVector);
2225                 std::vector<ContourThing**> lstContourThings = kernelManager->getOutlinesAtInstant( &instant );
2226                 sizeLstContourThings = lstContourThings.size();
2227
2228                 lstManConMod.clear();
2229                 for (ii=0 ; ii<sizeLstContourThings ; ii++)
2230                 {
2231                         ContourThing **contourthing = lstContourThings[ii];
2232                         lstManConMod.push_back( (*contourthing)->getModel() );
2233                 }
2234                 lstManConModExp =  kernelManager->ExploseEachModel( lstManConMod );
2235
2236
2237                 int iContourGroup,sizeContourGroup;
2238                 if (typeContourGroup==3) // contour separete
2239                 {
2240                         sizeContourGroup=lstManConModExp.size();
2241                 } else {  // contour AND OR XOR
2242                         sizeContourGroup=1;
2243                 }
2244
2245                 for( iContourGroup=0 ; iContourGroup<sizeContourGroup ; iContourGroup++ ){
2246                         lstManConModTmp.clear();
2247                         if (typeContourGroup==3) // contour separete
2248                         {
2249                                 lstManConModTmp.push_back( lstManConModExp[iContourGroup]);
2250                         } else {  // contour AND OR XOR
2251                                 lstManConModTmp = lstManConModExp;
2252                         }
2253
2254                         contourextractdata->SetLstManualContourModel( lstManConModTmp );
2255
2256
2257 //                              for (ii=0 ; ii<sizeLstContourThings ; ii++)
2258 //                              {
2259 //                                      ContourThing **contourthing = lstContourThings[ii];
2260 //                                      lstManConMod.push_back( (*contourthing)->getModel() );
2261 //                              }
2262 //                              contourextractdata->SetLstManualContourModel( lstManConMod );
2263
2264                         contourextractdata->CalculateImageResult(); // with actual Z
2265
2266                 } // for  iContourGroup
2267         } // for z
2268
2269         std::string temp = directory + "/" + namefile + "-Value.mhd";
2270
2271         wxString filename = crea::std2wx(temp);
2272         // LG 
2273         //      filename.Printf(_T(temp.c_str()));
2274         //filename.Printf(_T("%s\\%s-Value.mhd",directory.c_str(),namefile.c_str(),z);
2275         /*filename.Printf(_T("%s"),directory.c_str());
2276         filename.append(_T("\\"));
2277         filename.append(_T("%s"),namefile.c_str());
2278         filename.append(_T("-Value.mhd"));*/
2279
2280 // Image Value
2281         vtkMetaImageWriter *writerValueImage = vtkMetaImageWriter::New( );
2282         writerValueImage->SetInput( contourextractdata->GetVtkImageValueResult() );
2283         writerValueImage->SetFileName( (const char *)filename.mb_str() );
2284         writerValueImage->SetFileDimensionality( 3 );
2285         writerValueImage->Write( );
2286
2287 // Image Mask
2288         //              filename.Printf("%s\\%s-Mask.mhd",directory.c_str(),namefile.c_str(),z);
2289         temp = directory + "/" + namefile + "-Mask.mhd";
2290
2291         // LG 14/01/09 : using crea
2292         filename = crea::std2wx(temp);
2293         //      filename.Printf(_T(temp.c_str()));
2294
2295         /*filename.Printf(_T("%s"),directory.c_str());
2296         filename.append(_T("\\"));
2297         filename.append(_T("%s"),namefile.c_str());
2298         filename.append(_T("-Mask.mhd"));*/
2299
2300         vtkMetaImageWriter *writerMaskImage = vtkMetaImageWriter::New( );
2301         writerMaskImage->SetInput( contourextractdata->GetVtkImageMaskResult() );
2302         writerMaskImage->SetFileName( (const char *)filename.mb_str() );
2303         writerMaskImage->SetFileDimensionality( 3 );
2304         writerMaskImage->Write( );
2305
2306         interfMainPanel::getInstance()->setStringInfoPanel( _T("") );
2307         delete contourextractdata;
2308 }
2309
2310 void wxContourMainFrame::onChangeInstantInstantPanel(std::string name,int value, int minshow, int maxshow){
2311         if( name.compare( _theViewPanel->getVerticalConceptName() ) == 0){
2312                 _theViewPanel->setActualVertical( value);
2313         }
2314         else if( name.compare( _theViewPanel->getHorizontalConceptName() ) == 0|| _instantPanel->getIfConceptCheckedAt( name, 0 ) )     {
2315                 _theViewPanel->setHorizontalConcept( name, minshow, maxshow, minshow, maxshow, value);
2316         }
2317
2318         changeInstant();
2319 }
2320
2321 void wxContourMainFrame::onSnakePressed(){
2322         std::vector<double> vecX; 
2323         std::vector<double> vecY; 
2324         std::vector<double> vecZ; 
2325         _theViewPanel->GetPointsOfActualContour( &vecX , &vecY , &vecZ );       
2326
2327         if (vecX.size()!=0){
2328                 std::vector<int> tempVector;
2329                 _instantPanel->getInstant( tempVector );
2330                 int i,size=vecZ.size();
2331                 int actualSlice = tempVector[1];
2332                 for ( i=0 ; i<size ; i++ )
2333                 {
2334                         vecZ[i] = actualSlice;
2335                 } // for
2336
2337                 wxDialog* dialog = new wxDialog(this, -1, wxString(_T("Snake")));
2338                 wxPanel* panel = new wxPanel(dialog,-1); 
2339                 //              wxStaticText* sttext = new wxStaticText(panel, -1, wxString(_T("Panel para snake")));
2340          new wxStaticText(panel, -1, wxString(_T("Panel para snake")));
2341                 dialog->ShowModal();
2342         } // if 
2343
2344 }
2345
2346 void wxContourMainFrame::saveFileWithContoursAutomatique(){
2347         std::string filename = kernelManager->getCurrentFileName();
2348         if(filename.compare("")!=0){
2349                 saveFileWithContours(filename);
2350         }else{
2351                 onSave();
2352         }
2353 }