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