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