]> Creatis software - creaContours.git/blob - lib/Interface_ManagerContour_NDimensions/wxContourMainFrame.cxx
*** empty log message ***
[creaContours.git] / lib / Interface_ManagerContour_NDimensions / wxContourMainFrame.cxx
1 //----------------------------------------------------------------------------------------------------------------
2 // Class definition include
3 //----------------------------------------------------------------------------------------------------------------
4 #include "wxContourMainFrame.h"
5
6
7
8 //----------------------------------------------------------------------------------------------------------------
9 // Includes
10 //----------------------------------------------------------------------------------------------------------------
11
12
13 #include "NameWrapper.h"
14 #include "wx/artprov.h"
15 #include "ConceptDataWrap.h"
16
17 #include <manualContour.h>
18 //#include "ImageSourceThing.h"
19 //#include "wxContour_ActionCommandsID.h"
20 //#include "OutlineModelBuilder.h"
21 //#include "wxContourEventHandler.h"
22 #include <creaWx.h>
23
24 //----------------------------------------------------------------------------------------------------------------
25 // Class implementation
26 //----------------------------------------------------------------------------------------------------------------
27 /** @file wxContourMainFrame.cxx */
28
29         //------------------------------------------------------------------------------------------------------------
30         // Constructors & Destructors
31         //------------------------------------------------------------------------------------------------------------
32
33 wxContourMainFrame* wxContourMainFrame:: instance = NULL;
34 char wxContourMainFrame::COPY = 'C';
35                 
36         wxContourMainFrame :: wxContourMainFrame(wxWindow* parent, wxWindowID id,const wxString& title,const wxPoint& pos,const wxSize& size,long style)
37                 //: wxPanel(parent, id, title, pos, size, style)
38                 //: wxWindow(parent, id, pos, size, style)
39                 : wxPanel(parent, id, pos, size, style)
40         {
41                 m_mgr.SetManagedWindow(this);
42                 _creatingContoursActive         = false;
43                 _theViewPanel                           = NULL;
44 //              _modelManager                           = NULL;
45                 _instantPanel                           = NULL;
46 //              _buttonsBar                                     = NULL;
47 //              _gridPanel                                      = NULL; 
48 //              _drawToolsPanel                         = NULL;
49 //              _operationsToolsPanel           = NULL;
50                 //_autoFormsPanel                               = NULL; 
51 //              _standardToolsPanel                     = NULL;
52 //              _editionToolsPanel                      = NULL;
53 //              _listViewPanel                          = NULL;
54 //              _sceneManager                           = NULL;
55                 //_actualInstant                                = NULL;
56                 _numberOfVariablesStatistics = 6+1;
57
58                 _refLineControl                         = NULL;
59                 _refLineModel                           = NULL;
60                 _refLineView                            = NULL;
61
62                 // set up default notebook style
63 //              m_notebook_style =wxAUI_NB_TAB_SPLIT | wxAUI_NB_TAB_EXTERNAL_MOVE | wxNO_BORDER;
64 //              m_notebook_theme = 0;   
65                 //wxContour_ActionCommandsID a;
66
67         }
68
69         wxContourMainFrame :: wxContourMainFrame(wxWindow* parent, wxWindowID id,const wxString& title,const wxPoint& pos,const wxSize& size,std::vector<vtkImageData*> images, long style,std::string datadir)         
70                 : wxPanel(parent, id, pos, size, style)
71         {
72                 m_mgr.SetManagedWindow(this);
73                 _creatingContoursActive         = false;
74                 _theViewPanel                           = NULL;
75 //              _modelManager                           = NULL;
76                 _instantPanel                           = NULL;
77 //              _buttonsBar                                     = NULL;
78 //              _gridPanel                                      = NULL; 
79 //              _drawToolsPanel                         = NULL;
80 //              _operationsToolsPanel           = NULL;
81 //              _autoFormsPanel                         = NULL; 
82 //              _standardToolsPanel                     = NULL;
83 //              _editionToolsPanel                      = NULL;
84 //              _listViewPanel                          = NULL;
85 //              _sceneManager                           = NULL;
86 //              _actualInstant                          = NULL;
87
88                 _refLineControl                         = NULL;
89                 _refLineModel                           = NULL;
90                 _refLineView                            = NULL;
91
92                 // set up default notebook style
93                 m_notebook_style =wxAUI_NB_TAB_SPLIT | wxAUI_NB_TAB_EXTERNAL_MOVE | wxNO_BORDER;
94                 m_notebook_theme = 0;   
95                 //wxContour_ActionCommandsID a;
96                 _numberOfVariablesStatistics = 6+1;
97
98
99                 _performingOperation                    = new PerformingOperation();
100 //JCP 17 - 10 - 2008
101
102         inredo = 0;
103         inundo = 0;
104
105         kernelManager = new KernelManagerContour(images,datadir+"/data/");
106         //kernelManager->setVectImages(images);
107         //kernelManager->initializeEnvironment();
108                         
109         //vtkImageData* selectedimage = kernelManager->getVectImages()[0];
110         
111 //-------------------------------------------------------------
112
113         /*frame = new wxContourMainFrame(_builder->getImSourceEnv(), _builder->getImSectionEnv(), _builder->getAxesEnv(),  _builder->getContourEnv(),NULL, wxID_ANY, wxT("ROI Application Sample"), wxPoint(50,50), wxSize(800, 600)); 
114         frame->Show(TRUE);*/
115
116         //Creating the evtHandler of the panels
117         //wxContourEventHandler * eventHandler = new wxContourEventHandler();
118
119         //Creating the window that will show the panels
120
121         //Getting the parent for the panels ( using aui )
122         wxAuiNotebook * notebook = this->createNotebook();
123
124         //JCP 17 - 11 - 08
125         //wxInstantChooserPanel * instantPanel                          = new wxInstantChooserPanel( notebook, "Instant Chooser", true);
126         //JCP 17 - 11 - 08
127         std::vector<std::string> conceptNameVect;
128         std::vector<int> conceptSizeVect;
129         
130
131
132         _instantPanel                           = new wxInstantChooserPanel( notebook, "Instant Chooser", true, false, "c" );
133         _theViewPanel                           = new wxContourViewPanel( kernelManager->getSourceImage(), notebook );  
134
135
136
137     kernelManager->getConceptsInformation(conceptNameVect, conceptSizeVect);
138         _instantPanel->addConcepts(conceptNameVect, conceptSizeVect);
139                 
140
141         double val = _theViewPanel->getCurrentDeep();
142         _instantPanel->setConceptValue( "Axe Depth", (int)val );
143         //JCP _instantPanel->setConceptValue("time", num de imagenes);
144         ConceptDataWrap * data = _instantPanel->getConceptDataOf( "Axe Depth" );
145         //*******************changeInstant();
146         _theViewPanel->setVerticalConcept( "Axe Depth", data->getMinValue(), data->getMaxValue(), data->getMinShowedValue(),  data->getMaxShowedValue(), data->getActualValue() );
147
148         //eventHandler->setModelManager( kernelManager->getOutlineModelManager() );
149         //eventHandler->setViewPanel( _theViewPanel );
150         //_theViewPanel->initializeScenceManager();
151         //eventHandler->setInstantChooserPanel( _instantPanel );
152         
153         //bool successConfiuration = eventHandler->configureEventsHandling();
154
155         //successConfiuration &= this->configurePanels( notebook );
156         this->configurePanels( notebook );
157
158         interfMainPanel* pannew = interfMainPanel::getInstance(parent,datadir+"/data/Icons");//, eventHandler);
159
160 //JCP 17 -10 - 2008
161
162
163         }
164
165
166         wxContourMainFrame* wxContourMainFrame :: getInstance(wxWindow* parent, wxWindowID id,const wxString& title,const wxPoint& pos,const wxSize& size,std::vector<vtkImageData*> images, long style,std::string datadir ){
167                 if(instance == NULL){
168                         instance = new wxContourMainFrame(parent, id, title, pos, size, images, style,datadir);
169                 }
170                 return instance;
171         }
172
173         std::vector<vtkImageData*> wxContourMainFrame ::getVectImages(){
174                 return kernelManager->getVectImages();
175         }
176         wxContourMainFrame* wxContourMainFrame :: getInstance(){
177                 return instance;
178                 
179         }
180
181         wxContourMainFrame :: ~wxContourMainFrame()
182         {
183                   m_mgr.UnInit();
184                   //El problema al cerrar la aplicacion puede estar asociado 
185                   //a que  wxAUINotebook esta en la aplicacion 
186                   //principal (wxContourGUIExample)tambien
187 //EED????               delete _theViewPanel;             
188 //EED????               delete _instantPanel;
189 //EED????               delete _buttonsBar;
190 //EED????               delete _actualInstant;           
191 //EED????               delete _sceneManager;
192         }
193
194
195         //------------------------------------------------------------------------------------------------------------
196         // Creational and initialization methods using WxAui
197         //------------------------------------------------------------------------------------------------------------
198         //
199         wxAuiNotebook * wxContourMainFrame :: createNotebook()
200         {
201                 wxSize client_size = GetClientSize();
202                 wxAuiNotebook* noteBook = new wxAuiNotebook(this, -1, wxPoint(client_size.x, client_size.y), wxSize(430,200), m_notebook_style);
203                 wxBitmap page_bmp = wxArtProvider::GetBitmap(wxART_NORMAL_FILE, wxART_OTHER, wxSize(16,16));
204                 return noteBook;
205         }
206         
207
208         //------------------------------------------------------------------------------------------------------------
209         // Creational and initialization methods 
210         //------------------------------------------------------------------------------------------------------------
211         bool wxContourMainFrame :: configurePanels(wxAuiNotebook* theNoteBook)
212         {
213                 bool configured = _theViewPanel!=NULL;
214                                         
215                 configured &= _theViewPanel!=NULL;
216                 if( _theViewPanel!=NULL )
217                 {
218                         theNoteBook->AddPage( _theViewPanel, wxT("       View       ") );               
219                         m_mgr.Update();
220                 }
221
222
223                 if( configured )
224                 {
225                         theNoteBook->AddPage( _instantPanel, wxT("Instant Page") );
226                         m_mgr.Update();
227                 }
228
229                 m_mgr.AddPane(theNoteBook, wxAuiPaneInfo().Name(wxT("notebook_content")).CenterPane().PaneBorder(false));
230                 m_mgr.Update();
231 /*              configured &= _buttonsBar!=NULL;
232                 if( _buttonsBar!=NULL )
233                 {                       
234                         m_mgr.AddPane(_buttonsBar, wxAuiPaneInfo().
235                                         Name(wxT("TB")).Caption(wxT("Buttons Bar")).
236                                         ToolbarPane().Top().
237                                         LeftDockable(  ).RightDockable( false ).CloseButton(false));
238                         m_mgr.Update();
239                 }*/
240                 //CreateStatusBar();
241                          
242                 SetMinSize(wxSize(300,300));
243                 m_mgr.Update();
244                 return configured;
245         }
246
247         void wxContourMainFrame :: setNotebook( wxAuiNotebook * noteBook )
248         {
249
250         }
251
252         //------------------------------------------------------------------------------------------------------------
253         //  Attributes getters and setters
254         //------------------------------------------------------------------------------------------------------------
255         
256
257         
258         void wxContourMainFrame :: setInstantChooserPanel(  wxInstantChooserPanel * theInstantChooserPanel )
259         {
260                 _instantPanel = theInstantChooserPanel; 
261         }
262
263 //      void wxContourMainFrame :: setButtonsBar(  wxContour_ButtonsBar * theButtonsBar )
264 //      {
265 //              _buttonsBar = theButtonsBar;
266 //      }
267
268 //      void wxContourMainFrame :: setGrid(  wxContour_Grid * theGridPanel )
269 //      {
270 //              _gridPanel = theGridPanel;
271 //      }
272
273 //      void wxContourMainFrame :: setDrawToolsPanel(  wxContour_DrawToolsPanel * theDrawToolsPanel )
274 //      {
275 //              _drawToolsPanel = theDrawToolsPanel;
276 //      }
277
278 //      void wxContourMainFrame :: setOperationsToolsPanel(  wxContour_OperationsToolsPanel * theOperationsToolsPanel )
279 //      {       
280 //              _operationsToolsPanel = theOperationsToolsPanel;
281 //      }
282
283 //      void wxContourMainFrame :: setAutomaticFormsPanel(  wxContour_AutomaticFormsToolsPanel * theAutoFormsPanel )
284 //      {
285 //              _autoFormsPanel = theAutoFormsPanel;
286 //      }
287
288 //      void wxContourMainFrame :: setStandardToolsPanel(  wxContour_StandardToolsPanel * theStandardToolsPanel )
289 //      {
290 //              _standardToolsPanel= theStandardToolsPanel;
291 //      }
292
293 //      void wxContourMainFrame :: setEditionToolsPanel(  wxContour_EdtionToolsPanel * theEditionToolsPanel )
294 //      {
295 //              _editionToolsPanel =  theEditionToolsPanel;
296 //      }
297
298 //      void wxContourMainFrame :: setListViewPanel(  wxContour_ListViewPanel * theListViewPanel )
299 //      {
300 //              _listViewPanel = theListViewPanel;
301 //      }
302
303
304
305 void wxContourMainFrame::onCreateContourSpline( ){
306         
307         //JCP 20-10-08 Undo redo implementation
308         saveState();
309         //JCP 20-10-08 Undo redo implementation
310         createContour( 1 );
311         
312 }
313 void wxContourMainFrame::onCreateContourRectangle( ){
314     //JCP 20-10-08 Undo redo implementation
315         saveState();
316         //JCP 20-10-08 Undo redo implementation 
317         createContour( 2 );
318 }
319 void wxContourMainFrame::onCreateContourCircle( ){
320     //JCP 20-10-08 Undo redo implementation
321         saveState();
322         //JCP 20-10-08 Undo redo implementation 
323         createContour( 3 );
324 }
325
326 void wxContourMainFrame::onCreateContourLine( ){
327     //JCP 20-10-08 Undo redo implementation
328         saveState();
329         //JCP 20-10-08 Undo redo implementation 
330         createContour( 6 );
331 }
332
333 //------------------------------------------------------------------------------------------------------------
334
335 void wxContourMainFrame :: onCreateContourBullEye(wxPanel* panel )
336 {
337         //Creating the manualContourModel and including in the model
338         manualContourModel * manModelContour = factoryManualContourModel(panel );
339
340         std::vector<int> instantVector;
341         _instantPanel->getInstant( instantVector );
342         std::string theName = kernelManager->createOutline(manModelContour, instantVector);
343         
344         /*std::vector<int> instantVector;
345         _instantPanel->getInstant( instantVector );
346         std::string theName;
347         theName= _modelManager->createOutline( manModelContour, instantVector );*/
348         bool addedModel = theName.compare("") != 0;//??
349
350         if( addedModel )
351         {
352                 double spc[3];//Si no hay imagen pero hay contornos que spacing se pone por default
353                 _theViewPanel->getSpacing(spc);                                 
354                 //Adding the manualContourControler to interface objects structure
355                 //Adding the manualViewContour to interface objects structure           
356                 //_theViewPanel->getSceneManager()->setControlActiveStateOfALL( false );//This call is being done here because if the ROI is created underneath the previously created ROIS will still be active.
357                 _theViewPanel->getSceneManager()->configureViewControlTo( theName, manModelContour,spc , 4) ;
358         }
359 }
360 void wxContourMainFrame :: createContour( int typeContour )
361 {
362         //Creating the manualContourModel and including in the model
363         manualContourModel * manModelContour = kernelManager->factoryManualContourModel(typeContour);
364
365
366         std::vector<int> instantVector;
367         _instantPanel->getInstant( instantVector );
368         std::string theName = kernelManager->createOutline(manModelContour, instantVector);
369         
370         /*std::vector<int> instantVector;
371         _instantPanel->getInstant( instantVector );
372         std::string theName;
373         theName= _modelManager->createOutline( manModelContour, instantVector );*/
374         bool addedModel = theName.compare("") != 0;//??
375         if( addedModel )
376         {
377                 double spc[3];//Si no hay imagen pero hay contornos que spacing se pone por default
378                 _theViewPanel->getSpacing(spc);                                 
379                 //Adding the manualContourControler to interface objects structure
380                 //Adding the manualViewContour to interface objects structure           
381                 //_sceneManager->setControlActiveStateOfALL( false );//This call is being done here because if the ROI is created underneath the previously created ROIS will still be active.
382                 _theViewPanel->getSceneManager()->configureViewControlTo( theName, manModelContour,spc , typeContour) ;
383         }       
384
385 }
386 manualContourModel * wxContourMainFrame::factoryManualContourModel(wxPanel* panel){
387
388         manualContourModelBullEye *manModelContourBullEye = new manualContourModelBullEye();
389         manualContourModel *manModelContour=NULL;
390         manModelContour = manModelContourBullEye;
391         if (panel!=NULL){
392                 int iCrown,sizeCrowns,iSector,sizeSectors;
393                 double radioA,radioB,ang,angDelta ;
394                 sizeCrowns = ((PanelBullEyeOptions*)panel)->GetNumberOfCrowns();
395                 for ( iCrown=0 ; iCrown<sizeCrowns ; iCrown++ )
396                 {
397                         sizeSectors = ((PanelBullEyeOptions*)panel)->GetNumberOfSections(iCrown);
398                         radioB  = ((PanelBullEyeOptions*)panel)->GetRadioOfCrown(iCrown);
399                         if (iCrown==sizeCrowns-1)
400                         {
401                                 radioA  = 0;
402                         } else {
403                                 radioA  = ((PanelBullEyeOptions*)panel)->GetRadioOfCrown(iCrown+1);
404                         }
405                         radioA=radioA/100.0;
406                         radioB=radioB/100.0;
407                         for ( iSector=0 ; iSector<sizeSectors  ; iSector++ )
408                         {
409                                 ang             = ((PanelBullEyeOptions*)panel)->GetAngOfCrownSection(iCrown,iSector);
410                                 angDelta= ((PanelBullEyeOptions*)panel)->GetAngDeltaOfCrownSection(iCrown);                                     
411                                 manModelContourBullEye->AddSector(radioA,radioB,ang,angDelta);
412                         } // for iSector
413                 } // for iCrown
414         } // if _panelBullEyeOptions
415         
416         return manModelContour;
417 }
418 void wxContourMainFrame :: saveState(){ 
419                 
420         std::string temp = kernelManager->saveState();
421         saveFileWithContours(temp);     
422 }
423
424 void wxContourMainFrame::onDeleteContour(){
425         //JCP 20-10-08 Undo redo implementation
426                 saveState();
427                 //JCP 20-10-08 Undo redo implementation
428
429                 std::vector<std::string> lstKeyNameToBeErase;
430                 lstKeyNameToBeErase             = _theViewPanel->getSceneManager()->getSelectedObjects();
431                 deleteContours( lstKeyNameToBeErase );
432 /*JCP 19 - 11 - 08
433                 int i,size=_sceneManager->getSelectedObjects().size();
434                 for(i=0;i<size;i++)
435                 {
436                         std::string keyName             = _sceneManager->getSelectedObjects()[i];
437                         int ispartofstaticlist  = this->_modelManager->IsPartOfStaticList( keyName );
438                         if ( ispartofstaticlist>=0 )
439                         {
440                                 std::vector<int> tempVector;
441                                 _instantPanel->getInstant( tempVector );
442                                 Instant instant(&tempVector);
443                                 this->_modelManager->ChangeContourOfList(keyName, &instant);
444                         }
445                 }
446
447                 std::vector<std::string> lstKeyName;
448                 std::vector<std::string> lstKeyNameActualSlice;
449                 std::vector<std::string> lstKeyNameToBeErase;
450
451                 lstKeyNameToBeErase             = _sceneManager->getSelectedObjects();
452                 lstKeyNameActualSlice   = _sceneManager->GetlstContoursNameActualSlice();
453                 int k,kSize=lstKeyNameToBeErase.size();
454                 int j,jSize=lstKeyNameActualSlice.size();
455                 bool ok;
456                 for (k=0;k<kSize; k++)
457                 {
458                         ok=false;
459                         for (j=0;j<jSize; j++)
460                         {
461                                 if (lstKeyNameToBeErase[k]==lstKeyNameActualSlice[j])
462                                 { 
463                                         ok=true;
464                                 }
465                         } // for j
466                         if (ok==true)
467                         {
468                                 lstKeyName.push_back( lstKeyNameToBeErase[k] );
469                         } // if ok
470                 } // for k
471
472                 deleteContours( lstKeyName );
473 JCP 19 - 11 - 08*/
474 }
475
476 void wxContourMainFrame :: deleteContours( std::vector<std::string>  keyNamesVector )
477 {
478         int i,size=keyNamesVector.size();
479         for (i=0;i<size;i++)
480         {
481                 deleteContour( keyNamesVector[i] );
482         }
483 }
484
485 void wxContourMainFrame :: deleteContour( std::string theKeyName ){
486         /*
487         manualContourModel                      * cModel;
488         manualViewBaseContour           * cViewer;
489         manualContourBaseControler      * cControler;
490
491         ContourWrap_ViewControl *conwrapviewControl =  _theViewPanel->getSceneManager()->getContourWrap_ViewControlOf( theKeyName );
492         cControler      = conwrapviewControl->getControler();*/
493
494         //JCP 21 - 11 - 2008
495         bool isedit = _theViewPanel->isEditableCControler(theKeyName);
496         bool ispartofstaticlst = kernelManager->IsPartOfStaticList(theKeyName);
497
498         if (isedit  && ispartofstaticlst)
499         {
500                 _theViewPanel->removeFromScene(theKeyName);
501
502                 kernelManager->deleteCModel(theKeyName);
503                 //_theViewPanel->getSceneManager()->removeFromScene( theKeyName );                      
504                 //cViewer               = conwrapviewControl->getViewer();
505                 //_theViewPanel->getSceneManager()->removeWrap( theKeyName );
506                 //cControler* conwrapviewControl->getControler();                       
507 //EED Borrame
508 //FILE *ff = fopen("c:/temp/wxVtkBaseView_SceneManagerStadistics.txt","a+");
509 //fprintf(ff,"EED wxContourEventHandler::deleteContours() \n" );
510 //fprintf(ff,"    %s %p\n",keyNamesVector[i].c_str(),  cControler );
511 //fclose(ff);
512         //      delete cModel;
513         //      delete cViewer;
514         //      delete cControler;
515         } // if editable
516 //JCP 21 - 11 - 08
517 }
518
519 void wxContourMainFrame::onDeleteContoursActSlice(){
520         //JCP 20-10-08 Undo redo implementation
521         saveState();
522         //JCP 20-10-08 Undo redo implementation
523         deleteContours( (std::vector<std::string>)_theViewPanel->getSceneManager()->GetlstContoursNameActualSlice() );
524 }
525 void wxContourMainFrame::onDeleteAllContours(){
526         //JCP 20-10-08 Undo redo implementation
527         saveState();
528         deleteAllContours();
529 }
530 void wxContourMainFrame::deleteAllContours(){
531         //JCP 20-10-08 Undo redo implementation
532
533         wxBusyCursor wait;
534         std::vector<int> tempVector;
535         _instantPanel->getInstant( tempVector );
536
537 //JCP --08-09-2008 When using a diferent interface the _mbarrangeDeleteAll might not be initialize
538 //              the values in GetStart and GetEnd will then not be initialize also.
539 //              We use instead the values given when initializing the _deletepanel.
540
541         //int minZ = _mbarrangeDeleteAll->GetStart();
542         //int maxZ = _mbarrangeDeleteAll->GetEnd();
543         int minZ, maxZ;
544         
545         minZ = 0;
546         maxZ = _theViewPanel->getSceneManager()->GetImageDataSizeZ();
547         
548 //JCP --08-09-2008
549         
550         _theViewPanel->getSceneManager()->removeSceneContours( );       
551         _theViewPanel->getSceneManager()->removeAllOutlines();
552         kernelManager->removeAllOutlines();     
553 //JCP --08-09-2008
554         /*
555         if ( (minZ==0) && (maxZ==_mbarrangeDeleteAll->GetMax() ))
556         {
557                 _theViewPanel->getSceneManager()->removeSceneContours( );
558                 _modelManager->removeAllOutlines();
559                 _theViewPanel->getSceneManager()->removeAllOutlines();
560
561         } else {
562                 for ( z=minZ ; z<=maxZ ; z++)
563                 {
564                         tempVector[1]=z;
565                         Instant instant(&tempVector);
566                         std::vector<ContourThing**> lstContourThings = this->_modelManager->getOutlinesAtInstant( &instant );
567
568                         sizeLstContourThings = lstContourThings.size();
569                         for (ii=0 ; ii<sizeLstContourThings ; ii++)
570                         {
571                                 ContourThing **contourthing = lstContourThings[ii];
572                                 deleteContour( (*contourthing)->getName() );
573                         } //for ii
574                 }// for z
575         } // if 
576 JCP --08-09-2008 */
577 }
578
579 void wxContourMainFrame::setConceptValue( std::string name, int value ){
580         _instantPanel->setConceptValue(name, value);
581 }
582
583 ConceptDataWrap* wxContourMainFrame::getLastConceptData(){
584         return _instantPanel->getLastConceptData();
585 }
586 bool wxContourMainFrame::getIfConceptCheckedAt( std::string name, int pos ){
587         return _instantPanel->getIfConceptCheckedAt( name, pos );
588 }
589
590 void wxContourMainFrame::changeInstant(){
591                 std::vector<int> instantVect;
592                 _instantPanel->getInstant( instantVect );
593 //              Instant * theInstant = new Instant ( &instantVect );
594                 
595                 //Setting the actual instant
596                 //_actualInstant = theInstant;
597
598                 kernelManager->setInstant(instantVect);
599                 //_modelManager->setInstant( _actualInstant );
600                 
601                 updateInstantOutlines();
602                 updateInstantImageData();
603                 updateInstantAxes();
604
605                 
606 }
607 void wxContourMainFrame :: updateInstantOutlines(){
608         
609         _theViewPanel->removeSceneContours();
610         _theViewPanel->addNameWrapperToScene();
611
612         //for( int i=0; i<size; i++)
613         //{                     
614         //      _theViewPanel->getSceneManager()->addToScene(namesWrapping[i]->getKeyName(), true, true, true, false, false );
615         //}
616 }
617
618 int wxContourMainFrame::getNamesWrappingSize(){
619         return kernelManager->getNamesWrappingSize();
620 }
621 std::string wxContourMainFrame::getNameWrapping(int i){
622         return kernelManager->getNameWrapping(i);
623 }
624
625 void wxContourMainFrame::updateInstantImageData(){
626         std::vector<int> inst;
627         _instantPanel->getInstant(inst);
628
629         vtkImageData* img = kernelManager->getImageAtInstant(inst);
630         if(img!=NULL){
631                 _theViewPanel->changeImage(img);
632                 showAxis(false);
633         }else{
634                 int z = _instantPanel->getConceptDataOf("Axe Depth")->getActualValue();
635                 _theViewPanel->setImageSlice(z);
636         }
637 }
638 void wxContourMainFrame::updateInstantAxes(){
639 }
640
641 void wxContourMainFrame::onChangeDeep(int val){
642         _instantPanel->setConceptValue( "Axe Depth", (int)val );        
643         changeInstant();
644 }
645
646
647 void wxContourMainFrame::onCopy(){
648         std::vector<std::string> currentSelection = _theViewPanel->getSelectedObjects();
649
650         std::vector<int> tempVector;
651         _instantPanel->getInstant( tempVector );
652     _performingOperation->reset();
653         _performingOperation->setStartCommand( COPY );
654         _performingOperation->setStartOperationInstantVector( tempVector );
655         _performingOperation->setKeyNamesOperationElems( currentSelection );
656 }
657
658 void wxContourMainFrame::onPaste(){
659
660
661         char theStartCommand = _performingOperation->getStartCommand();
662         if (  theStartCommand == COPY )
663         {
664                 //JCP 20-10-08 Undo redo implementation
665                 saveState();
666                 //JCP 20-10-08 Undo redo implementation
667                 std::vector<int> tempVector;
668                 _instantPanel->getInstant( tempVector );
669                 _performingOperation->setEndOperationInstantVector ( tempVector );
670                 std::vector<std::string> elems = _performingOperation->getKeyNamesOperationElems();
671                 int i,size = elems.size();                      
672                 for( i=0; i<size; i++ )
673                 {                               
674                         createCopyContourOf( elems[i], tempVector, i>0 );
675                 }               
676         }
677 }
678 void wxContourMainFrame::onUndo(){
679         std::string filename;
680         if(kernelManager->onUndoSaveFile(filename)){
681                 saveFileWithContours(filename);
682         }
683         if(kernelManager->onUndo(filename)){
684                 loadState(filename);
685         }
686 }
687 void wxContourMainFrame::onRedo(){
688         std::string filename;
689         if(kernelManager->onRedo(filename)){
690                 loadState(filename);
691         }
692         
693 }
694 void wxContourMainFrame :: createCopyContourOf ( std::string anExistingKName, std::vector<int> &instantNoTouchData, bool append )
695 {
696         std::string cloneName = kernelManager->createCopyContourOf( anExistingKName, instantNoTouchData );
697         manualContourModel * manualModel = kernelManager->getOutlineByKeyName(cloneName);//_modelManager->getOutlineByKeyName( cloneName )->getModel();
698         _theViewPanel->getSceneManager()->createCopyContourOf( anExistingKName, cloneName, manualModel , append );
699 }
700
701 ///AD: 03-09    Copy the object and apply the given transformation
702 void wxContourMainFrame :: createMirrorContourOf ( std::string anExistingKName, std::vector<int> &instantNoTouchData, bool append )
703 {
704         std::string cloneName = kernelManager->createCopyContourOf( anExistingKName, instantNoTouchData );
705         manualContourModel * manualModel = kernelManager->getOutlineByKeyName(cloneName);
706
707         manualPoint * refPoint1 = _refLineModel->GetManualPoint(0);
708         manualPoint * refPoint2 = _refLineModel->GetManualPoint(1);
709
710         double pnt1X = refPoint1->GetX();
711         double pnt1Y = refPoint1->GetY();
712         double pnt1Z = refPoint1->GetZ();
713         double pnt2X = refPoint2->GetX();
714         double pnt2Y = refPoint2->GetY();
715         double pnt2Z = refPoint2->GetZ();
716
717         double angle = (atan2(pnt2Y - pnt1Y, pnt2X - pnt1X) * 180 / 3.1415926535897932384626433832795)+90;
718         vtkTransform *t = vtkTransform::New();
719
720         t->PostMultiply();
721         t->Identity();
722         t->Translate(-pnt1X, -pnt1Y, 0);
723         t->RotateZ(-angle);
724         t->Scale(-1,1,1);
725         t->RotateZ(angle);
726         t->Translate(pnt1X, pnt1Y, 0);
727         t->Update();
728
729         int i,size=manualModel->GetSizeLstPoints();
730         for (i=0;i<size;i++)
731         {
732                 manualPoint * mp = manualModel->GetManualPoint(i);
733                 float vecIn[3];
734                 float vecOut[3];
735                 vecIn[0]=mp->GetX();
736                 vecIn[1]=mp->GetY();
737                 vecIn[2]=mp->GetZ();
738                 t->TransformPoint( vecIn, vecOut );
739                 mp->SetPointX( vecOut[0] );
740                 mp->SetPointY( vecOut[1] );
741                 mp->SetPointZ( vecOut[2] );
742         }
743
744         _theViewPanel->getSceneManager()->createCopyContourOf( anExistingKName, cloneName, manualModel , append );
745 }
746
747 void wxContourMainFrame ::loadState(std::string filename){
748         char tmp[255];
749         FILE *pFile=fopen(filename.c_str(),"r+");
750
751         fscanf(pFile,"%s",tmp); // --CreaContour--
752
753         fscanf(pFile,"%s",tmp); // Version
754         fscanf(pFile,"%s",tmp); // 1.0.1
755         std::string version(tmp);
756
757         deleteAllContours();
758
759         openContours(pFile,false);
760         if (version!="1.0.0"){
761                 openContours(pFile,true);
762         }
763
764         fclose(pFile);
765         
766         //_theViewPanel->getSceneManager()->removeSceneContours();
767         //changeInstant();
768
769 }
770
771 void wxContourMainFrame::onLoad(){
772         char tmp[255];
773         wxFileDialog dialog(NULL, _T("Choose a file"), _T(""), _T(""), _T("*.roi"), wxOPEN );
774         if (dialog.ShowModal() == wxID_OK)
775         {
776                 std::string fileNameContourROI = (const char *)(dialog.GetPath().mb_str());
777                 FILE *pFile=fopen(fileNameContourROI.c_str(),"r+");
778
779                 fscanf(pFile,"%s",tmp); // --CreaContour--
780
781                 fscanf(pFile,"%s",tmp); // Version
782                 fscanf(pFile,"%s",tmp); // 1.0.1
783                 std::string version(tmp);
784
785                 openContours(pFile,false);
786                 if (version!="1.0.0"){
787                         openContours(pFile,true);
788                 }
789 //                        _theViewPanel->getSceneManager()->openFileWithContours(ff);
790
791                 fclose(pFile);
792         }
793         _theViewPanel->getSceneManager()->removeSceneContours();
794         changeInstant();
795 }
796 void wxContourMainFrame::onSave(){
797         wxFileDialog dialog(NULL, _T("Choose a file"), _T(""), _T(""), _T("*.roi"), wxSAVE );
798         if (dialog.ShowModal() == wxID_OK)
799         {
800                 std::string fileNameContourROI = (const char *)(dialog.GetPath().mb_str());
801                 kernelManager->setCurrentFileName(fileNameContourROI);
802                 saveFileWithContours( fileNameContourROI );
803         }
804 }
805 void wxContourMainFrame::saveFileWithContours( std::string filename ){
806
807         FILE *pFile=fopen(filename.c_str(),"w+");
808         std::vector< std::string > lstNameThings;
809         int i,sizeLstNameThings; 
810
811         fprintf(pFile,"--CreaContour--\n");
812         fprintf(pFile,"Version %s\n", "1.0.1" );
813
814         // Normal Contours
815         lstNameThings           = kernelManager->GetLstNameThings();
816         sizeLstNameThings       = lstNameThings.size(); 
817         fprintf(pFile,"NumberOfContours %d\n", sizeLstNameThings );
818         for (i=0 ; i<sizeLstNameThings ; i++) 
819         {
820                 kernelManager->SaveThingName( pFile, lstNameThings[i] );
821                 _theViewPanel->getSceneManager()->SaveThingName( pFile, lstNameThings[i] );
822         }// for i
823
824         //-- Contours Statics 
825         lstNameThings           = kernelManager->GetLstNameThingsStatic();
826         sizeLstNameThings       = lstNameThings.size(); 
827         fprintf(pFile,"NumberOfContoursStatic %d\n", sizeLstNameThings );
828         for (i=0 ; i<sizeLstNameThings ; i++) 
829         {
830                 kernelManager->SaveThingName( pFile, lstNameThings[i] );
831                 _theViewPanel->getSceneManager()->SaveThingName( pFile, lstNameThings[i] );
832         }// for i
833         fclose(pFile);
834 }
835
836 void wxContourMainFrame::openContours( FILE *pFile, bool staticContour ){
837         char tmp[255];
838         fscanf(pFile,"%s",tmp); // NumberOfContours 
839         fscanf(pFile,"%s",tmp); // ##
840         int numberOfContours = atoi(tmp);  
841
842         std::vector<int> instantVector;
843         int typeContourModel;
844         manualContourModel *manModelContour;
845         int typeView;
846
847         int i;
848         for (i=0;i<numberOfContours;i++)
849         {
850                 instantVector.clear();
851                 fscanf(pFile,"%s",tmp); // Instant
852
853                 fscanf(pFile,"%s",tmp); // 1
854                 instantVector.push_back( atoi(tmp) );
855                 fscanf(pFile,"%s",tmp); // 2
856                 instantVector.push_back( atoi(tmp) );
857                 fscanf(pFile,"%s",tmp); // 3
858                 instantVector.push_back( atoi(tmp) );
859                 fscanf(pFile,"%s",tmp); // 4
860                 instantVector.push_back( atoi(tmp) );
861                 fscanf(pFile,"%s",tmp); // 5
862                 instantVector.push_back( atoi(tmp) );
863                 fscanf(pFile,"%s",tmp); // 6
864                 instantVector.push_back( atoi(tmp) );
865
866
867                 fscanf(pFile,"%s",tmp); // TypeContourModel
868                 fscanf(pFile,"%s",tmp); // ##
869                 typeContourModel = atoi(tmp);
870
871                 manModelContour =  kernelManager->factoryManualContourModel(typeContourModel);
872                 manModelContour->Open(pFile);
873
874                 fscanf(pFile,"%s",tmp); // TypeView
875                 fscanf(pFile,"%s",tmp); // ##
876                 typeView = atoi(tmp);  
877
878
879 //                      if (typeView==1) 
880 //                      {
881 //                      }
882
883
884                 std::string theName;
885                 theName = kernelManager->createOutline( manModelContour, instantVector );
886                 bool addedModel = theName.compare("") != 0;
887                 if( addedModel )
888                 {
889                         double spc[3];//Si no hay imagen pero hay contornos que spacing se pone por default
890                         _theViewPanel->getSpacing(spc);                                 
891                         //Adding the manualContourControler to interface objects structure
892                         //Adding the manualViewContour to interface objects structure           
893                         //_theViewPanel->getSceneManager()->setControlActiveStateOfALL( false );//This call is being done here because if the ROI is created underneath the previously created ROIS will still be active.
894                         _theViewPanel->getSceneManager()->configureViewControlTo( theName, manModelContour,spc , typeView) ;
895                 }       
896
897                 if (staticContour==true)
898                 {
899                         Instant instant(&instantVector);
900                         kernelManager->changeContourOfManager( theName , &instant );
901                 }
902
903         }// for  numberOfContours
904
905 }
906
907 void wxContourMainFrame::RefreshInterface(){
908         changeInstant();
909         _theViewPanel->RefreshInterface();
910         //wxVtk2DBaseView *wxvtk2dbaseview = (wxVtk2DBaseView*)this->_theViewPanel->getWxVtkBaseView();
911         //wxvtk2dbaseview->Refresh();
912 }
913
914 vtkImageData* wxContourMainFrame::getImageData(){
915         return _theViewPanel->getImageData();
916 }
917
918 void wxContourMainFrame::onSegmentationOneSlice(int isovalue,int sampling,int method){
919         
920         //JCP 20-10-08 Undo redo implementation
921         saveState();
922         //JCP 20-10-08 Undo redo implementation
923         
924         wxBusyCursor wait;
925         int                                     x                                       = _theViewPanel->GetX();
926         int                                     y                                       = _theViewPanel->GetY();
927         int                                     z                                       = _theViewPanel->GetZ();
928         SegmentationOneSlice( x,y,z,isovalue, sampling, method );
929         RefreshInterface();
930 }
931
932
933 void wxContourMainFrame::SegmentationOneSlice( int x, int y, int z, int isovalue, int sampling, int method )
934 {               
935         int typeofcontour = 1;
936         //--Extracting Contour
937         //vtkImageData  *imagedata      = _theViewPanel->getSceneManager()->GetImageData();
938         vtkImageData    *imagedata      = getImageData();
939 //              double                  *range          = imagedata->GetScalarRange();  
940 //              double                  thr                     = 1;
941
942         vtkImageReslice *imageReslice = vtkImageReslice::New();
943 //EED
944 //              double spc[3];
945 //              imagedata->GetSpacing(spc);
946 //              x = x*spc[0];
947 //              y = y*spc[1];
948 //              z = z*spc[3];
949
950         imageReslice->SetInput( imagedata );
951         imageReslice->SetInformationInput(imagedata);
952         imageReslice->SetResliceAxesDirectionCosines(1,0,0, 0,1,0 ,0,0,1);
953         imageReslice->SetResliceAxesOrigin(0,0,z);
954         imageReslice->SetOutputDimensionality(2);
955         imageReslice->SetInterpolationModeToLinear();
956
957         imagedata = imageReslice->GetOutput();
958         imagedata->Update();
959         imagedata->UpdateInformation();
960
961         vtkContourFilter* cntVTK = vtkContourFilter::New( );
962         cntVTK->SetInput( imagedata );
963
964         cntVTK->SetNumberOfContours( 1 );
965         //cntVTK->SetValue( 0, vmin );
966 //              cntVTK->SetValue( 0, (range[1]*thr/100) );
967         cntVTK->SetValue( 1, isovalue );
968 //      cntVTK->SetValue( 1, vmax );
969         cntVTK->Update( );
970         cntVTK->UpdateInformation();
971                 
972         vtkCleanPolyData* cpd = vtkCleanPolyData::New( );
973         cpd->SetInput( cntVTK->GetOutput( ) );
974         cpd->ConvertLinesToPointsOff( );
975         cpd->Update( );
976         cpd->UpdateInformation();
977
978         vtkPolyDataConnectivityFilter* conn = vtkPolyDataConnectivityFilter::New( );
979         conn->SetExtractionModeToClosestPointRegion( );
980         //conn->SetMaxRecursionDepth( 3000 );
981                 
982         conn->SetInput( cpd->GetOutput( ) );
983                 
984         conn->SetClosestPoint( x, y, 0 );
985         conn->Update( );
986         conn->UpdateInformation();
987                 
988         vtkCleanPolyData* cpd2 = vtkCleanPolyData::New( );
989         cpd2->SetInput( conn->GetOutput( ) );
990         cpd2->Update();
991         cpd2->UpdateInformation();
992
993         vtkStripper* vtkstripper = vtkStripper::New( );
994         vtkstripper->SetInput( cpd2->GetOutput() );
995         vtkstripper->Update();
996         vtkstripper->UpdateInformation();
997
998
999         vtkPolyData* polyDataResult =  vtkstripper->GetOutput();
1000
1001         polyDataResult->Update( );
1002         polyDataResult->UpdateInformation();
1003
1004 /* EED
1005 ofstream myfile;
1006 myfile.open ("c:/temp/example.txt");
1007 myfile << "\n";
1008 polyDataResult->Print(myfile);
1009 myfile << "-------------------------------------\n";
1010 polyDataResult->GetLines()->Print(myfile);
1011 myfile.close();
1012 */
1013
1014         cntVTK          -> Delete();
1015         cpd2            -> Delete();
1016         cpd                     -> Delete();
1017         conn            -> Delete();
1018
1019
1020 //--Calculating control points
1021
1022         std::vector<double> vecX;
1023         std::vector<double> vecY;
1024         std::vector<double> vecZ;
1025
1026         std::vector<double> vecCtrlPointX;
1027         std::vector<double> vecCtrlPointY;
1028         std::vector<double> vecCtrlPointZ;
1029
1030
1031         double *p;
1032         int ii,size=polyDataResult->GetNumberOfPoints();
1033         int id;
1034         for (ii=1;ii<=size;ii++)
1035         {
1036                 id      = polyDataResult->GetLines()->GetData()->GetValue(ii);
1037                 p       = polyDataResult->GetPoint(id);
1038                 double x=p[0];
1039                 double y=p[1];
1040                 vecX.push_back( p[0] );
1041                 vecY.push_back( p[1] );
1042                 vecZ.push_back( -900 );
1043 //                      vecZ.push_back( p[2] );
1044         }
1045
1046
1047         ExtractControlPoints2D *extractcontrolpoints2d = new ExtractControlPoints2D();
1048         extractcontrolpoints2d->SetContour( &vecX , &vecY , &vecZ );
1049
1050 //PROOFS
1051         /*if (methodRadiobox->GetSelection()==0){
1052                 extractcontrolpoints2d->GetInitialControlPoints( &vecCtrlPointX , &vecCtrlPointY , &vecCtrlPointZ );
1053         }
1054         if (methodRadiobox->GetSelection()==1){
1055                 extractcontrolpoints2d->GetControlPoints(  &vecCtrlPointX , &vecCtrlPointY , &vecCtrlPointZ );
1056         }
1057         if (methodRadiobox->GetSelection()==2){
1058                 extractcontrolpoints2d->SetSamplingControlPoints( sampling );
1059                 extractcontrolpoints2d->GetSamplingControlPoints(  &vecCtrlPointX , &vecCtrlPointY , &vecCtrlPointZ );
1060         }*/
1061
1062         if (method==0){
1063                 extractcontrolpoints2d->GetInitialControlPoints( &vecCtrlPointX , &vecCtrlPointY , &vecCtrlPointZ );
1064         }
1065         else if (method==1){
1066                 extractcontrolpoints2d->GetControlPoints(  &vecCtrlPointX , &vecCtrlPointY , &vecCtrlPointZ );
1067         }
1068         else if (method==2){
1069                 extractcontrolpoints2d->SetSamplingControlPoints( sampling );
1070                 extractcontrolpoints2d->GetSamplingControlPoints(  &vecCtrlPointX , &vecCtrlPointY , &vecCtrlPointZ );
1071         }
1072
1073         //--Adding contour to the system
1074
1075         std::vector<int> actualInstantVector;
1076         _instantPanel->getInstant( actualInstantVector );
1077         actualInstantVector[1]=z;
1078
1079         int j,sizeCtrPt = vecCtrlPointX.size();
1080         manualContourModel *manModelContour =  kernelManager->factoryManualContourModel( typeofcontour );
1081         manModelContour->SetNumberOfPointsSpline( ((sizeCtrPt/100)+1)*100 );
1082         if (sizeCtrPt>=3){
1083                 for (j=0 ; j<sizeCtrPt ; j++)
1084                 {
1085                         manModelContour->AddPoint( vecCtrlPointX[j] , vecCtrlPointY[j] , vecCtrlPointZ[j]  );
1086                 } // for
1087                 std::string theName;
1088                 //theName = _modelManager->createOutline( manModelContour, actualInstantVector );
1089                 theName = kernelManager->createOutline( manModelContour, actualInstantVector );
1090                 bool addedModel = theName.compare("") != 0;
1091                 if( addedModel )
1092                 {
1093                         double spc[3];//Si no hay imagen pero hay contornos que spacing se pone por default
1094                         _theViewPanel->getSpacing(spc);                                 
1095                         //Adding the manualContourControler to interface objects structure
1096                         //Adding the manualViewContour to interface objects structure           
1097                         //_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.
1098                         _theViewPanel->configureViewControlTo(theName, manModelContour, spc, typeofcontour);
1099                         //_theViewPanel->getSceneManager()->configureViewControlTo( theName, manModelContour,spc, typeofcontour ) ;
1100                 }       // if addedModel
1101         } // if sizeCtrPt
1102 }
1103
1104 int wxContourMainFrame::GetImageDataSizeZ(){
1105         return _theViewPanel->GetImageDataSizeZ();
1106 }
1107
1108 void wxContourMainFrame::GetImageDataRange(double *range){
1109         _theViewPanel->GetImageDataRange(range);
1110 }
1111
1112 void wxContourMainFrame::onSegmentationAllSlice(int minZ,int maxZ,int isovalue,int sampling,int method){
1113         //JCP 20-10-08 Undo redo implementation
1114         saveState();
1115         //JCP 20-10-08 Undo redo implementation
1116         
1117         wxBusyCursor wait;
1118         int                                     x                                       = _theViewPanel->GetX();
1119         int                                     y                                       = _theViewPanel->GetY();
1120         int z;
1121         double porcent; 
1122         wxString tmpString;     
1123         double totalZ = maxZ-minZ+1;
1124         for( z=minZ ; z<=maxZ ; z++ )
1125         {
1126                 porcent = 100.0* (z-minZ)/totalZ;
1127                 tmpString.Printf(_T("  %d %c            %d/%d            %d"), (int)porcent , 37 , z-minZ+1, (int)totalZ,z );
1128                 interfMainPanel::getInstance()->setLabelSegmentationPanelVTK(tmpString);
1129                 //_staticTextSegmentation->SetLabel(tmpString);
1130                 SegmentationOneSlice( x,y,z,isovalue, sampling,method );
1131         }
1132         interfMainPanel::getInstance()->setLabelSegmentationPanelVTK(_T("   "));
1133         RefreshInterface();
1134 }
1135
1136
1137 //Creates a reference line to be used as the axis of the mirroring
1138 void wxContourMainFrame::referenceLine()
1139 {
1140     wxBusyCursor wait;
1141         double spc[3];
1142
1143         vtkImageData *vtkimagedata = _theViewPanel->getImageData();
1144         vtkimagedata->GetSpacing(spc);
1145
1146         wxVtkBaseView * viewer2D = _theViewPanel->getWxVtkBaseView();
1147
1148         _refLineControl = new manualLineControler();
1149         _refLineModel   = new manualContourModelLine();
1150         _refLineView = new manualViewLine();
1151         _refLineView->SetModel( _refLineModel );
1152         _refLineView->SetWxVtkBaseView( viewer2D );
1153         _refLineView->SetRange( 2 );
1154         _refLineView->SetZ( 1200 );
1155
1156         _refLineView->SetSpacing(spc);
1157
1158         _refLineView->SetColorNormalContour(0, 0, 1);
1159         _refLineView->SetColorEditContour(0, 0.5, 0.5);
1160         _refLineView->SetWidthLine(4);
1161
1162         _refLineControl->SetModelView( _refLineModel , _refLineView );
1163         viewer2D->GetInteractorStyleBaseView()->AddInteractorStyleMaracas( _refLineControl );
1164         _refLineModel->SetCloseContour(false);
1165         _refLineControl->CreateNewManualContour();
1166 /*
1167         double z = _refLineControl->GetZ();
1168
1169         _refLineModel->AddPoint(50,100,z);
1170         _refLineModel->AddPoint(80,40,z);
1171
1172         _refLineControl->AddPoint(50,100,z);
1173         _refLineControl->AddPoint(80,40,z);
1174
1175         _refLineView->UpdateViewPoint(0);
1176         _refLineView->UpdateViewPoint(1);
1177
1178         _refLineControl->SetCompleteCreation(true);
1179         _refLineControl->SetEditable(true);
1180 */
1181         _refLineControl->SetActive(true);
1182         _refLineView->RefreshContour();
1183 }
1184
1185 //Hides the referenceLine
1186 void wxContourMainFrame::refLineHide()
1187 {
1188         if (_refLineControl!=NULL)
1189         {
1190                 _refLineView->RemoveCompleteContourActor();     
1191         }
1192 }
1193
1194 //Shows the referenceLine
1195 void wxContourMainFrame::refLineShow()
1196 {
1197         if (_refLineControl!=NULL)
1198         {
1199                 wxVtkBaseView * viewer2D = _theViewPanel->getWxVtkBaseView();
1200
1201                 _refLineView->SetModel( _refLineModel );
1202                 _refLineView->SetWxVtkBaseView( viewer2D );
1203                 _refLineView->SetRange( 2 );
1204                 _refLineView->SetZ( 1200 );
1205
1206                 _refLineControl->SetModelView( _refLineModel , _refLineView );
1207                 viewer2D->GetInteractorStyleBaseView()->AddInteractorStyleMaracas( _refLineControl );
1208                 _refLineControl->CreateNewManualContour();
1209                 //_refLineControl->SetActive(true);
1210                 //_refLineControl->SetEditable(true);
1211                 _refLineView->RefreshContour();
1212         }
1213 }
1214
1215 void wxContourMainFrame::onMirror()
1216 {
1217         //AD:02-09
1218         std::vector<std::string> currentSelection = _theViewPanel->getSelectedObjects();
1219         std::vector<std::string> filterCurrentSelection;
1220
1221         std::vector<int> tempVector;
1222         _instantPanel->getInstant( tempVector );
1223     _performingOperation->reset();
1224         _performingOperation->setStartCommand( COPY );
1225         _performingOperation->setStartOperationInstantVector( tempVector );
1226         _performingOperation->setKeyNamesOperationElems( currentSelection );
1227
1228         char theStartCommand = _performingOperation->getStartCommand();
1229         if (  theStartCommand == COPY )
1230         {
1231                 //JCP 20-10-08 Undo redo implementation
1232                 saveState();
1233                 //JCP 20-10-08 Undo redo implementation
1234                 std::vector<int> tempVector;
1235                 _instantPanel->getInstant( tempVector );
1236                 _performingOperation->setEndOperationInstantVector ( tempVector );
1237                 std::vector<std::string> elems = _performingOperation->getKeyNamesOperationElems();
1238                 int i,size = elems.size();                      
1239                 for( i=0; i<size; i++ )
1240                 {                               
1241                         createMirrorContourOf( elems[i], tempVector, i>0 );
1242                 }               
1243         }
1244
1245         //deleteContour( _refName );
1246         //_refName = "";
1247 }
1248
1249 void wxContourMainFrame::showAxis(bool show){
1250         _theViewPanel->SetVisibleAxis(show);
1251         _theViewPanel->Refresh();
1252 }
1253
1254
1255 void wxContourMainFrame::onRigidPressed(){
1256         std::vector<std::string> currentSelection = _theViewPanel->getSelectedObjects();
1257         int elementsSelected = currentSelection.size();
1258
1259         if ( elementsSelected >= 1 ){
1260                 //JCP 20-10-08 Undo redo implementation
1261                 saveState();
1262                 //JCP 20-10-08 Undo redo implementation
1263
1264                 std::vector<int> tempVector;
1265                 _instantPanel->getInstant( tempVector );
1266                 Instant instant(&tempVector);
1267
1268                 int i , size=currentSelection.size();
1269                 for ( i=0 ; i<size ; i++ )
1270                 {
1271                         kernelManager->changeContourOfManager(currentSelection[i], &instant);
1272                 } // i
1273         }
1274 }
1275
1276 void wxContourMainFrame::onWidthOfContour(double width){
1277
1278         _theViewPanel->removeSceneContours();
1279         _theViewPanel->SetWidthContour(width);
1280         
1281         //_theViewPanel->getSceneManager()->SetWidthContour( width );
1282
1283         RefreshInterface();
1284 }
1285 int wxContourMainFrame::getColorWindow(){
1286         return _theViewPanel->getColorWindow();
1287 }
1288 int wxContourMainFrame::getWindowLevel(){
1289         return _theViewPanel->getWindowLevel();
1290 }
1291
1292 void wxContourMainFrame::onBrigthnessColorWindowLevel(int colorwindow,int windowlevel){
1293         _theViewPanel->onBrigthnessColorWindowLevel(colorwindow, windowlevel);
1294
1295         
1296         RefreshInterface();
1297 }
1298
1299 void wxContourMainFrame::onInterpolation(bool interpolate){
1300         _theViewPanel->onInterpolation(interpolate);    
1301         RefreshInterface();
1302 }
1303
1304 void wxContourMainFrame::onChangeInstant(std::string name,int actual){
1305         _instantPanel->setConceptValue( name, actual );
1306 }
1307
1308 void wxContourMainFrame::resetAppend(){
1309         kernelManager->resetAppend();
1310         
1311 }
1312
1313 void wxContourMainFrame::onSpreadAdd(){
1314         std::vector<double> vecX; 
1315         std::vector<double> vecY; 
1316         std::vector<double> vecZ; 
1317         _theViewPanel->GetPointsOfActualContour(&vecX , &vecY , &vecZ );
1318         
1319         std::vector<int> tempVector;
1320         _instantPanel->getInstant( tempVector );
1321
1322         std::string val = kernelManager->onSpreadAdd(&vecX , &vecY , &vecZ, tempVector);
1323
1324         interfMainPanel::getInstance()->appendStringSpread(val);
1325         
1326 }
1327
1328 void wxContourMainFrame::onSpreadGo(int type){
1329
1330         //JCP 20-10-08 Undo redo implementation
1331         saveState();
1332         //JCP 20-10-08 Undo redo implementation
1333
1334         wxBusyCursor wait;      
1335         std::vector<double> vecCtrlPointX;
1336         std::vector<double> vecCtrlPointY;
1337         std::vector<double> vecCtrlPointZ;
1338         double  minZ,maxZ;
1339         int z;
1340
1341         std::vector<int> tempVector;
1342         _instantPanel->getInstant( tempVector );
1343 //              tempVector[1];
1344
1345         kernelManager->getMaxMinZ(&minZ,&maxZ);
1346 //JSTG_16-07-08_----------------------------------------------------------------
1347         //_contourPropagation->setInterpolationNumber(maxZ-minZ+1);
1348         kernelManager->CalculeSplinePropagation();
1349
1350         double          totalZ = maxZ-minZ+1;
1351         double          porcent;
1352         wxString        tmpString;
1353 //--------------------------------------------------------------------
1354         for ( z=(int)minZ ; z<=(int)maxZ ; z++ )
1355         {
1356                 porcent = 100.0* (z-minZ)/totalZ;
1357                 int numero = (int)(z-minZ+1)/(int)totalZ;
1358                 std::string stringtemp = "  "+kernelManager->intToString(porcent)+"%            "+kernelManager->intToString(numero)+"            "+kernelManager->intToString(z);
1359                 
1360                 interfMainPanel::getInstance()->setStringSpread(stringtemp);    
1361
1362                 int typeofcontour = 1;
1363                 std::string theName;
1364                 manualContourModel* manModelContour = kernelManager->GetPoints(z, type, &vecCtrlPointX,&vecCtrlPointY,&vecCtrlPointZ, theName,typeofcontour, tempVector);
1365
1366                 if( manModelContour!=NULL ){
1367                         double spc[3];//Si no hay imagen pero hay contornos que spacing se pone por default
1368                         this->_theViewPanel->getSpacing(spc);                                   
1369                         //Adding the manualContourControler to interface objects structure
1370                         //Adding the manualViewContour to interface objects structure           
1371                         //_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.
1372                         _theViewPanel->configureViewControlTo( theName, manModelContour,spc,typeofcontour ) ;
1373                 } // if addedModel
1374         } 
1375         if(z > maxZ){
1376                 porcent = 100.0;
1377                 int numero = (int)(z-minZ+1)/(int)totalZ;
1378                 std::string stringtemp = "  "+kernelManager->intToString(porcent)+"%            "+kernelManager->intToString(numero)+"            "+kernelManager->intToString(z);
1379                 
1380                 interfMainPanel::getInstance()->setStringSpread(stringtemp);
1381         }// for z
1382         //RefreshInterface();
1383 }
1384
1385 void wxContourMainFrame::getInstantVector(std::vector<int>& tempVector){
1386         
1387 }
1388
1389 std::vector<std::string> wxContourMainFrame::getOutlinesName(int slide){
1390         std::vector<int> tempVector;
1391         _instantPanel->getInstant(tempVector);
1392         //Asignation of slide number should be different ex by name
1393         tempVector[1]=slide;
1394         return kernelManager->getOutlinesNameAtInstant(tempVector);
1395 }
1396
1397 void wxContourMainFrame::onInformationContourLabels(int typeContourGroup,int selection,int minimumZ,int maximumZ){
1398         int maxContourGroup     =       0;
1399
1400         ContourExtractData      *contourextractdata = new ContourExtractData();
1401         
1402         contourextractdata ->SetTypeOperation( typeContourGroup % 3 );
1403
1404         std::vector<manualContourModel*> lstManConMod;
1405         std::vector<manualContourModel*> lstManConModTmp;
1406         std::vector<manualContourModel*> lstManConModExp;
1407         std::vector<double> pLstValue;
1408         std::vector<double> pLstValuePosX;
1409         std::vector<double> pLstValuePosY;
1410         std::vector<double> pLstValuePosZ;
1411
1412         int             resultSize; 
1413         int             resultGrayRangeCount;
1414         double  resultMin; 
1415         double  resultMax;
1416         double  resultAverage;
1417         double  resultStandardeviation;
1418
1419         std::vector<int> tempVector;
1420         _instantPanel->getInstant( tempVector );
1421
1422         vtkImageData *imagedata = _theViewPanel->getImageData();
1423         int sizeZ = _theViewPanel->GetImageDataSizeZ();
1424         int z;
1425         int ii,sizeLstContourThings;
1426
1427
1428         int minZ,maxZ;
1429         double totalZ;
1430         double porcent; 
1431         wxString tmpString;
1432
1433         
1434
1435         if (selection==0 ) // actual slice
1436         {
1437                 std::vector<int> tempVector;
1438                 _instantPanel->getInstant( tempVector );
1439                 int actualSlice = tempVector[1];
1440                 minZ    = actualSlice;
1441                 maxZ    = actualSlice;
1442         }
1443         else if (selection==2 ) // All slices
1444         {
1445                 minZ    = 0;
1446                 maxZ    = sizeZ-1;
1447         }
1448         else if (selection==1 ) // slice range
1449         {
1450                 minZ    = minimumZ;
1451                 maxZ    = maximumZ;
1452         }
1453         
1454
1455         totalZ  = maxZ-minZ+1;
1456         contourextractdata->SetImage( imagedata);
1457
1458 // For each slice..
1459         for ( z=minZ ; z<=maxZ ; z++ )
1460         {
1461                 
1462                 porcent = 100.0* (z-minZ)/totalZ;
1463                 tmpString.Printf(_T("  %d %c            %d/%d             %d"), (int)porcent , 37 , z-minZ+1, (int)totalZ ,z);
1464
1465                 interfMainPanel::getInstance()->setStringInfoPanel(tmpString);          
1466                 //_staticTextInformation->SetLabel(tmpString);
1467
1468                 //Extraction data from contours of each slice
1469                 contourextractdata->SetZtoBeAnalys( z);
1470
1471                 tempVector[1]=z;
1472                 Instant instant(&tempVector);
1473                 std::vector<ContourThing**> lstContourThings = kernelManager->getOutlinesAtInstant( &instant );
1474                 sizeLstContourThings = lstContourThings.size();
1475
1476                 lstManConMod.clear();
1477                 for (ii=0 ; ii<sizeLstContourThings ; ii++)
1478                 {
1479                         ContourThing **contourthing = lstContourThings[ii];
1480                         lstManConMod.push_back( (*contourthing)->getModel() );
1481                 }
1482                 lstManConModExp =  kernelManager->ExploseEachModel( lstManConMod );
1483
1484
1485                 wxString tempString;
1486                 tempString.Printf(_T("%d - %d"),z, sizeLstContourThings);
1487                 interfMainPanel::getInstance()->setRowLabelInfoPanel(z, tempString);
1488                 //_grid->SetRowLabelValue(z, tempString );
1489 //EED004
1490                 int iContourGroup,sizeContourGroup;
1491                 if (typeContourGroup==3) // contour separete
1492                 {
1493                         sizeContourGroup=lstManConModExp.size();
1494                         if ( maxContourGroup<sizeContourGroup ) 
1495                         {
1496                                 maxContourGroup=sizeContourGroup;
1497                         }
1498                 } else {  // contour AND OR XOR
1499                         sizeContourGroup=1;
1500                         maxContourGroup=1;
1501                 }
1502
1503                 int tmpIntA;
1504
1505
1506
1507                 for( iContourGroup=0 ; iContourGroup<sizeContourGroup ; iContourGroup++ ){
1508                         lstManConModTmp.clear();
1509                         if (typeContourGroup==3) // contour separete
1510                         {
1511                                 lstManConModTmp.push_back( lstManConModExp[iContourGroup]);
1512                         } else {  // contour AND OR XOR
1513                                 lstManConModTmp = lstManConModExp;
1514                         }
1515
1516                         contourextractdata->SetLstManualContourModel( lstManConModTmp );
1517
1518                         pLstValue.clear();
1519                         pLstValuePosX.clear();
1520                         pLstValuePosY.clear();
1521                         pLstValuePosZ.clear();
1522                         contourextractdata->GetValuesInsideCrown(       &pLstValue,
1523                                                                                                                 &pLstValuePosX,
1524                                                                                                                 &pLstValuePosY,
1525                                                                                                                 &pLstValuePosZ);
1526                         // Statistics of each slice.
1527                         contourextractdata->Statistics( &pLstValue,
1528                                                                                         minimumZ,
1529                                                                                         maximumZ,
1530                                                                                         &resultGrayRangeCount, 
1531                                                                                         &resultSize, 
1532                                                                                         &resultMin, 
1533                                                                                         &resultMax,
1534                                                                                         &resultAverage,
1535                                                                                         &resultStandardeviation);
1536                         
1537                         if (interfMainPanel::getInstance()->getNumberColsInformationPanel()<_numberOfVariablesStatistics*(iContourGroup+1)  )
1538                         {
1539                                 interfMainPanel::getInstance()->appendColsInformationPanel(_numberOfVariablesStatistics);
1540                         }
1541
1542                         tmpIntA=_numberOfVariablesStatistics*iContourGroup ;
1543
1544                         tempString.Printf(_T("%d"),resultSize);
1545                         interfMainPanel::getInstance()->setCellValueInfoPanel(z, tmpIntA, tempString);  
1546
1547                         tempString.Printf(_T("%d"),resultGrayRangeCount);
1548                         interfMainPanel::getInstance()->setCellValueInfoPanel(z, tmpIntA+1, tempString);
1549                         
1550                         tempString.Printf(_T("%f"),resultMin);
1551                         interfMainPanel::getInstance()->setCellValueInfoPanel(z, tmpIntA+2, tempString);
1552                         
1553                         tempString.Printf(_T("%f"),resultMax);
1554                         interfMainPanel::getInstance()->setCellValueInfoPanel(z, tmpIntA+3, tempString);
1555                         
1556                         tempString.Printf(_T("%f"),resultAverage);
1557                         interfMainPanel::getInstance()->setCellValueInfoPanel(z, tmpIntA+4, tempString);
1558                         
1559                         tempString.Printf(_T("%f"),resultStandardeviation);
1560                         interfMainPanel::getInstance()->setCellValueInfoPanel(z, tmpIntA+5, tempString);
1561                         
1562
1563                 } // for iContourGroup
1564         } // for z
1565
1566         int iTitleGroup;
1567         wxString tmpTitleString;
1568         int tmpIntB;
1569         for ( iTitleGroup=0 ; iTitleGroup<maxContourGroup ; iTitleGroup++ )
1570         {
1571                 tmpIntB =_numberOfVariablesStatistics*iTitleGroup;
1572                 tmpTitleString.Printf(_T("%d-Size Data"),iTitleGroup);
1573                 interfMainPanel::getInstance()->setColLableInfoPanel(tmpIntB + 0, tmpTitleString);
1574
1575                 interfMainPanel::getInstance()->setColLableInfoPanel(tmpIntB + 0, tmpTitleString );
1576                 interfMainPanel::getInstance()->setColLableInfoPanel( tmpIntB + 1, _T("Size Range") );
1577                 interfMainPanel::getInstance()->setColLableInfoPanel( tmpIntB + 2, _T("Min") );
1578                 interfMainPanel::getInstance()->setColLableInfoPanel( tmpIntB + 3, _T("Max") );
1579                 interfMainPanel::getInstance()->setColLableInfoPanel( tmpIntB + 4, _T("Average") );
1580                 interfMainPanel::getInstance()->setColLableInfoPanel( tmpIntB + 5, _T("St.Dev.") );
1581                 interfMainPanel::getInstance()->setColLableInfoPanel( tmpIntB + 6, _T(" ") );
1582         }
1583
1584         interfMainPanel::getInstance()->setStringInfoPanel( _T("") );
1585         delete contourextractdata;
1586 }
1587
1588 void wxContourMainFrame::onSaveResults(std::string directory,std::string namefile, std::string filename, int typeContourGroup){
1589     SaveValuesXYZ( directory , namefile, typeContourGroup );
1590         SaveImageResult( directory , namefile, typeContourGroup);
1591
1592         
1593         FILE *pFile=fopen(filename.c_str(),"w+");
1594
1595         int sizeZ = _theViewPanel->GetImageDataSizeZ();
1596
1597         wxString tmpString;
1598         int i,j,maxX,maxY=sizeZ;
1599         maxX= interfMainPanel::getInstance()->getNumberColsInformationPanel();//this->_grid->GetNumberCols();
1600
1601         int iTitle,sizeTitle = (maxX / _numberOfVariablesStatistics);
1602         for ( iTitle=0; iTitle<sizeTitle ; iTitle++)
1603         {
1604                 fprintf(pFile,"-- \t %d-Size \t SizeRange \t Min \t Max \t Ave \t StDv \t" , iTitle,tmpString.c_str() );
1605         }
1606         fprintf(pFile,"\n" );
1607
1608
1609
1610         for ( j=0; j<maxY ; j++)
1611         {
1612                 fprintf(pFile,"%d\t" , j );
1613                 for (i=0 ; i<maxX ; i++){
1614                         tmpString = interfMainPanel::getInstance()->getCellValue(j, i);//_grid->GetCellValue( j , i );
1615                         fprintf(pFile,"%s\t" , (const char *)(tmpString.mb_str()) );
1616                 } // for i
1617                 fprintf(pFile,"\n"  );
1618         } // for j
1619
1620         fclose(pFile);
1621 }
1622
1623 void wxContourMainFrame::SaveValuesXYZ(std::string directory,std::string namefile,int typeContourGroup)
1624 {
1625         wxBusyCursor wait;
1626         ContourExtractData      *contourextractdata = new ContourExtractData();
1627         //int typeContourGroup = this->_radiolstboxContourGroup->GetSelection();
1628         contourextractdata ->SetTypeOperation( typeContourGroup % 3 );
1629
1630         std::vector<manualContourModel*> lstManConMod;
1631         std::vector<manualContourModel*> lstManConModTmp;
1632         std::vector<manualContourModel*> lstManConModExp;
1633         std::vector<double> pLstValue;
1634         std::vector<double> pLstValuePosX;
1635         std::vector<double> pLstValuePosY;
1636         std::vector<double> pLstValuePosZ;
1637
1638         std::vector<int> tempVector;
1639         _instantPanel->getInstant( tempVector );
1640
1641         vtkImageData *imagedata = _theViewPanel->getSceneManager()->GetImageData();
1642         int sizeZ = _theViewPanel->getSceneManager()->GetImageDataSizeZ();
1643         int z;
1644         int ii,sizeLstContourThings;
1645
1646
1647         int minZ,maxZ;
1648         double totalZ;
1649         double porcent; 
1650         wxString tmpString;
1651         minZ    = 0;// _mbarrange->GetStart();
1652         maxZ    = sizeZ;//_mbarrange->GetEnd();
1653         totalZ  = maxZ-minZ+1;
1654
1655         contourextractdata->SetImage( imagedata);
1656
1657 // For each slice..
1658         for ( z=0 ; z<sizeZ ; z++)
1659         {
1660
1661                 porcent = 100.0* (z-minZ)/totalZ;
1662                 
1663                 tmpString.Printf(_T("Saving Values"));
1664                 tmpString.Printf(_T("  %d %c            %d/%d             %d"), (int)porcent , 37 , z-minZ+1, (int)totalZ ,z);
1665                 interfMainPanel::getInstance()->setStringInfoPanel(tmpString);
1666                 //_staticTextInformation->SetLabel(tmpString);
1667
1668
1669                 //Extraction data from contours of each slice
1670                 contourextractdata->SetZtoBeAnalys( z);
1671
1672                 tempVector[1]=z;
1673                 Instant instant(&tempVector);
1674                 std::vector<ContourThing**> lstContourThings = kernelManager->getOutlinesAtInstant(&instant);//this->_modelManager->getOutlinesAtInstant( &instant );
1675                 sizeLstContourThings = lstContourThings.size();
1676
1677                 lstManConMod.clear();
1678                 for (ii=0 ; ii<sizeLstContourThings ; ii++)
1679                 {
1680                         ContourThing **contourthing = lstContourThings[ii];
1681                         lstManConMod.push_back( (*contourthing)->getModel() );
1682                 }
1683                 lstManConModExp =  kernelManager->ExploseEachModel( lstManConMod );
1684
1685
1686 //EED004
1687
1688                 int iContourGroup,sizeContourGroup;
1689                 if (typeContourGroup==3) // contour separete
1690                 {
1691                         sizeContourGroup=lstManConModExp.size();
1692                 } else {  // contour AND OR XOR
1693                         sizeContourGroup=1;
1694                 }
1695
1696                 for( iContourGroup=0 ; iContourGroup<sizeContourGroup ; iContourGroup++ ){
1697                         lstManConModTmp.clear();
1698                         if (typeContourGroup==3) // contour separete
1699                         {
1700                                 lstManConModTmp.push_back( lstManConModExp[iContourGroup]);
1701                         } else {  // contour AND OR XOR
1702                                 lstManConModTmp = lstManConModExp;
1703                         }
1704
1705                         contourextractdata->SetLstManualContourModel( lstManConModTmp );
1706
1707                         pLstValue.clear();
1708                         pLstValuePosX.clear();
1709                         pLstValuePosY.clear();
1710                         pLstValuePosZ.clear();
1711                         contourextractdata->GetValuesInsideCrown(       &pLstValue,
1712                                                                                                                 &pLstValuePosX,
1713                                                                                                                 &pLstValuePosY,
1714                                                                                                                 &pLstValuePosZ);
1715
1716                         std::string temp = directory + "/" + namefile + "-slice";
1717                         temp = temp + kernelManager->intToString(z) + "-cont" + kernelManager->intToString(iContourGroup);
1718                         temp = temp + ".txt";
1719
1720                         // LG 14/01/09 : using crea
1721                         wxString filename = crea::std2wx(temp);
1722                         /*filename.Printf(_T("%s"),directory.c_str());
1723                         filename.append(_T("\\"));
1724                         filename.append(_T("%s"),namefile.c_str());
1725                         filename.append(_T("-slice"));
1726                         filename.append(_T("%d"),z);
1727                         filename.append(_T("-cont"));
1728                         filename.append(_T("%d"),iContourGroup);
1729                         filename.append(_T(".txt"));*/
1730                         //                      filename.Printf(temp.c_str());
1731
1732                         
1733
1734                         FILE *pFile=fopen((const char *)filename.mb_str(),"w+");
1735                         fprintf(pFile,"value \t x \t y \t z\n"  );
1736                         int iLstValue,sizeLstValue=pLstValue.size();
1737                         for (iLstValue=0 ; iLstValue<sizeLstValue ; iLstValue++ )
1738                         {
1739                                 fprintf(pFile,"%f\t %f\t %f\t %f\n", (float)pLstValue[iLstValue] , (float)pLstValuePosX[iLstValue], (float)pLstValuePosY[iLstValue], (float)z );
1740                         }
1741                         fclose(pFile);
1742                 } // for  iContourGroup
1743         } // for z
1744         interfMainPanel::getInstance()->setStringInfoPanel(_T(""));
1745         //_staticTextInformation->SetLabel( _T("") );
1746         delete contourextractdata;
1747 }
1748
1749 void wxContourMainFrame::SaveImageResult(std::string directory,std::string namefile, int typeContourGroup)
1750 {
1751         wxBusyCursor wait;
1752         ContourExtractData      *contourextractdata = new ContourExtractData( true );
1753         //int typeContourGroup = this->_radiolstboxContourGroup->GetSelection();
1754         if (typeContourGroup==3)
1755         {
1756                 typeContourGroup=1;
1757         }
1758         contourextractdata ->SetTypeOperation( typeContourGroup % 3 );
1759
1760         std::vector<manualContourModel*> lstManConMod;
1761         std::vector<manualContourModel*> lstManConModTmp;
1762         std::vector<manualContourModel*> lstManConModExp;
1763
1764         std::vector<int> tempVector;
1765         _instantPanel->getInstant( tempVector );
1766
1767         vtkImageData *imagedata = _theViewPanel->getImageData();
1768         int sizeZ = _theViewPanel->GetImageDataSizeZ();
1769         int z;
1770         int ii,sizeLstContourThings;
1771
1772
1773         int minZ,maxZ;
1774         double totalZ;
1775         double porcent; 
1776
1777         wxString tmpString;
1778
1779         minZ    = 0;// _mbarrange->GetStart();
1780         maxZ    = sizeZ;//_mbarrange->GetEnd();
1781         totalZ  = maxZ-minZ+1;
1782
1783         contourextractdata->SetImage( imagedata);
1784
1785 // For each slice..
1786         for ( z=0 ; z<sizeZ ; z++)
1787         {
1788
1789                 porcent = 100.0* (z-minZ)/totalZ;
1790                 tmpString.Printf(_T("Saving Values"));
1791                 tmpString.Printf(_T("%d %c            %d/%d             %d"), (int)porcent , 37 , z-minZ+1, (int)totalZ ,z);
1792                 interfMainPanel::getInstance()->setStringInfoPanel(tmpString);
1793
1794                 //Extraction data from contours of each slice
1795                 contourextractdata->SetZtoBeAnalys( z);
1796
1797                 tempVector[1]=z;
1798                 Instant instant(&tempVector);
1799                 std::vector<ContourThing**> lstContourThings = kernelManager->getOutlinesAtInstant( &instant );
1800                 sizeLstContourThings = lstContourThings.size();
1801
1802                 lstManConMod.clear();
1803                 for (ii=0 ; ii<sizeLstContourThings ; ii++)
1804                 {
1805                         ContourThing **contourthing = lstContourThings[ii];
1806                         lstManConMod.push_back( (*contourthing)->getModel() );
1807                 }
1808                 lstManConModExp =  kernelManager->ExploseEachModel( lstManConMod );
1809
1810
1811                 int iContourGroup,sizeContourGroup;
1812                 if (typeContourGroup==3) // contour separete
1813                 {
1814                         sizeContourGroup=lstManConModExp.size();
1815                 } else {  // contour AND OR XOR
1816                         sizeContourGroup=1;
1817                 }
1818
1819                 for( iContourGroup=0 ; iContourGroup<sizeContourGroup ; iContourGroup++ ){
1820                         lstManConModTmp.clear();
1821                         if (typeContourGroup==3) // contour separete
1822                         {
1823                                 lstManConModTmp.push_back( lstManConModExp[iContourGroup]);
1824                         } else {  // contour AND OR XOR
1825                                 lstManConModTmp = lstManConModExp;
1826                         }
1827
1828                         contourextractdata->SetLstManualContourModel( lstManConModTmp );
1829
1830
1831 //                              for (ii=0 ; ii<sizeLstContourThings ; ii++)
1832 //                              {
1833 //                                      ContourThing **contourthing = lstContourThings[ii];
1834 //                                      lstManConMod.push_back( (*contourthing)->getModel() );
1835 //                              }
1836 //                              contourextractdata->SetLstManualContourModel( lstManConMod );
1837
1838                         contourextractdata->CalculateImageResult(); // with actual Z
1839
1840                 } // for  iContourGroup
1841         } // for z
1842
1843         std::string temp = directory + "/" + namefile + "-Value.mhd";
1844
1845         wxString filename = crea::std2wx(temp);
1846         // LG 
1847         //      filename.Printf(_T(temp.c_str()));
1848         //filename.Printf(_T("%s\\%s-Value.mhd",directory.c_str(),namefile.c_str(),z);
1849         /*filename.Printf(_T("%s"),directory.c_str());
1850         filename.append(_T("\\"));
1851         filename.append(_T("%s"),namefile.c_str());
1852         filename.append(_T("-Value.mhd"));*/
1853
1854 // Image Value
1855         vtkMetaImageWriter *writerValueImage = vtkMetaImageWriter::New( );
1856         writerValueImage->SetInput( contourextractdata->GetVtkImageValueResult() );
1857         writerValueImage->SetFileName( (const char *)filename.mb_str() );
1858         writerValueImage->SetFileDimensionality( 3 );
1859         writerValueImage->Write( );
1860
1861 // Image Mask
1862         //              filename.Printf("%s\\%s-Mask.mhd",directory.c_str(),namefile.c_str(),z);
1863         temp = directory + "/" + namefile + "-Mask.mhd";
1864
1865         // LG 14/01/09 : using crea
1866         filename = crea::std2wx(temp);
1867         //      filename.Printf(_T(temp.c_str()));
1868
1869         /*filename.Printf(_T("%s"),directory.c_str());
1870         filename.append(_T("\\"));
1871         filename.append(_T("%s"),namefile.c_str());
1872         filename.append(_T("-Mask.mhd"));*/
1873
1874         vtkMetaImageWriter *writerMaskImage = vtkMetaImageWriter::New( );
1875         writerMaskImage->SetInput( contourextractdata->GetVtkImageMaskResult() );
1876         writerMaskImage->SetFileName( (const char *)filename.mb_str() );
1877         writerMaskImage->SetFileDimensionality( 3 );
1878         writerMaskImage->Write( );
1879
1880         interfMainPanel::getInstance()->setStringInfoPanel( _T("") );
1881         delete contourextractdata;
1882 }
1883
1884 void wxContourMainFrame::onChangeInstantInstantPanel(std::string name,int value, int minshow, int maxshow){
1885         if( name.compare( _theViewPanel->getVerticalConceptName() ) == 0){
1886                 _theViewPanel->setActualVertical( value);
1887         }
1888         else if( name.compare( _theViewPanel->getHorizontalConceptName() ) == 0|| _instantPanel->getIfConceptCheckedAt( name, 0 ) )     {
1889                 _theViewPanel->setHorizontalConcept( name, minshow, maxshow, minshow, maxshow, value);
1890         }
1891
1892         changeInstant();
1893 }
1894
1895 void wxContourMainFrame::onSnakePressed(){
1896         std::vector<double> vecX; 
1897         std::vector<double> vecY; 
1898         std::vector<double> vecZ; 
1899         _theViewPanel->GetPointsOfActualContour( &vecX , &vecY , &vecZ );       
1900
1901         if (vecX.size()!=0){
1902                 std::vector<int> tempVector;
1903                 _instantPanel->getInstant( tempVector );
1904                 int i,size=vecZ.size();
1905                 int actualSlice = tempVector[1];
1906                 for ( i=0 ; i<size ; i++ )
1907                 {
1908                         vecZ[i] = actualSlice;
1909                 } // for
1910
1911                 wxDialog* dialog = new wxDialog(this, -1, wxString(_T("Snake")));
1912                 wxPanel* panel = new wxPanel(dialog,-1); 
1913                 wxStaticText* sttext = new wxStaticText(panel, -1, wxString(_T("Panel para snake")));
1914                 dialog->ShowModal();
1915         } // if 
1916
1917 }
1918
1919 void wxContourMainFrame::saveFileWithContoursAutomatique(){
1920         std::string filename = kernelManager->getCurrentFileName();
1921         if(filename.compare("")!=0){
1922                 saveFileWithContours(filename);
1923         }else{
1924                 onSave();
1925         }
1926 }