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