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