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