]> Creatis software - creaContours.git/blob - lib/Interface_ManagerContour_NDimensions/wxContourMainFrame.cxx
0e7bff41f9cd3939a1ef3ab49906833ce1c6ac99
[creaContours.git] / lib / Interface_ManagerContour_NDimensions / wxContourMainFrame.cxx
1 /*# ---------------------------------------------------------------------
2 #
3 # Copyright (c) CREATIS (Centre de Recherche en Acquisition et Traitement de l'Image
4 #                        pour la Sant�)
5 # Authors : Eduardo Davila, Frederic Cervenansky, Claire Mouton
6 # Previous Authors : Laurent Guigues, Jean-Pierre Roux
7 # CreaTools website : www.creatis.insa-lyon.fr/site/fr/creatools_accueil
8 #
9 #  This software is governed by the CeCILL-B license under French law and
10 #  abiding by the rules of distribution of free software. You can  use,
11 #  modify and/ or redistribute the software under the terms of the CeCILL-B
12 #  license as circulated by CEA, CNRS and INRIA at the following URL
13 #  http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
14 #  or in the file LICENSE.txt.
15 #
16 #  As a counterpart to the access to the source code and  rights to copy,
17 #  modify and redistribute granted by the license, users are provided only
18 #  with a limited warranty  and the software's author,  the holder of the
19 #  economic rights,  and the successive licensors  have only  limited
20 #  liability.
21 #
22 #  The fact that you are presently reading this means that you have had
23 #  knowledge of the CeCILL-B license and that you accept its terms.
24 # ------------------------------------------------------------------------ */
25
26 //----------------------------------------------------------------------------------------------------------------
27 // Class definition include
28 //----------------------------------------------------------------------------------------------------------------
29 #include "wxContourMainFrame.h"
30
31
32
33 //----------------------------------------------------------------------------------------------------------------
34 // Includes
35 //----------------------------------------------------------------------------------------------------------------
36
37
38 #include "NameWrapper.h"
39 #include "wx/artprov.h"
40 #include "ConceptDataWrap.h"
41 #include <creaWx.h>
42
43 #include <string>
44 using namespace std;
45
46 //----------------------------------------------------------------------------------------------------------------
47 // Class implementation
48 //----------------------------------------------------------------------------------------------------------------
49 /** @file wxContourMainFrame.cxx */
50
51         //------------------------------------------------------------------------------------------------------------
52         // Constructors & Destructors
53         //------------------------------------------------------------------------------------------------------------
54
55 wxContourMainFrame* wxContourMainFrame:: instance = NULL;
56 char wxContourMainFrame::COPY = 'C';
57
58         wxContourMainFrame :: wxContourMainFrame(wxWindow* parent, wxWindowID id,const wxString& title,const wxPoint& pos,const wxSize& size,long style)
59                 //: wxPanel(parent, id, title, pos, size, style)
60                 //: wxWindow(parent, id, pos, size, style)
61                 : wxPanel(parent, id, pos, size, style)
62         {
63                 m_mgr.SetManagedWindow(this);
64                 _contourGroup                           = 1;
65                 _creatingContoursActive         = false;
66                 _theViewPanel                           = NULL;
67 //              _modelManager                           = NULL;
68                 _instantPanel                           = NULL;
69 //              _buttonsBar                                     = NULL;
70 //              _gridPanel                                      = NULL;
71 //              _drawToolsPanel                         = NULL;
72 //              _operationsToolsPanel           = NULL;
73                 //_autoFormsPanel                       = NULL;
74 //              _standardToolsPanel                     = NULL;
75 //              _editionToolsPanel                      = NULL;
76 //              _listViewPanel                          = NULL;
77 //              _sceneManager                           = NULL;
78                 //_actualInstant                        = NULL;
79                 _numberOfVariablesStatistics= 6+1;
80
81                 _refLineControl                         = NULL;
82                 _refLineModel                           = NULL;
83                 _refLineView                            = NULL;
84 //              _actorPresent                           = false;
85
86                 // set up default notebook style
87 //              m_notebook_style =wxAUI_NB_TAB_SPLIT | wxAUI_NB_TAB_EXTERNAL_MOVE | wxNO_BORDER;
88 //              m_notebook_theme = 0;
89                 //wxContour_ActionCommandsID a;
90
91                 _contourextractdata                     = NULL;
92                 _viewMaskImage                          = NULL;
93                 _viewMaskImagePanel                     = NULL;
94                 _viewThresholdImage                     = NULL;
95                 _viewThresholdImagePanel        = NULL;
96                 _viewColorLayerImagePanel       = NULL;
97
98                 _frameShowResultImages          = NULL;
99         }
100
101         wxContourMainFrame::wxContourMainFrame(wxWindow* parent, wxWindowID id,const wxString& title,const wxPoint& pos,const wxSize& size,std::vector<vtkImageData*> images, long style,std::string datadir)
102                 : wxPanel(parent, id, pos, size, style)
103         {
104                 m_mgr.SetManagedWindow(this);
105                 _contourGroup                           = 1;
106                 _creatingContoursActive         = false;
107                 _theViewPanel                           = NULL;
108                 _instantPanel                           = NULL;
109                 _refLineControl                         = NULL;
110                 _refLineModel                           = NULL;
111                 _refLineView                            = NULL;
112 //              _actorPresent                           = false;
113                 _viewMaskImage                          = NULL;
114                 _viewMaskImagePanel                     = NULL;
115                 _viewThresholdImage                     = NULL;
116                 _viewThresholdImagePanel        = NULL;
117                 _viewColorLayerImagePanel       = NULL;
118                 // set up default notebook style
119                 m_notebook_style                        = wxAUI_NB_TAB_SPLIT | wxAUI_NB_TAB_EXTERNAL_MOVE | wxNO_BORDER;
120                 m_notebook_theme                        = 0;
121                 //wxContour_ActionCommandsID a;
122                 _numberOfVariablesStatistics= 7;
123                 _datadir                                        = datadir;
124                 inredo                                          = 0;
125                 inundo                                          = 0;
126                 _pannew = interfMainPanel::getInstance(this,datadir+"/data/Icons");//, eventHandler);
127                 _performingOperation        = new PerformingOperation();
128                 if(images.size() > 0)
129                 {
130                         this->setVectImages(images);
131                 }
132                 _contourextractdata                     = NULL;
133 }
134
135 void wxContourMainFrame::setVectImages(std::vector<vtkImageData*> imgs)
136 {
137         _images = imgs;
138         #if defined(_WIN32)
139                 std::string str_home(getenv("USERPROFILE"));
140         #elif defined(__GNUC__)
141                 std::string str_home(getenv("HOME"));
142         #endif
143         std::string                             strCreaContourDataTmp = str_home + "/.creaContourDataTemp/";
144         std::vector<std::string>        conceptNameVect;
145         std::vector<int>                        conceptSizeVect;
146         notebook                = this->createNotebook();
147         kernelManager   = new KernelManagerContour( imgs , _datadir+"/data/" , strCreaContourDataTmp );
148         _instantPanel   = new wxInstantChooserPanel( notebook, "Instant Chooser", true, false, "c" );
149         _theViewPanel   = new wxContourViewPanel( kernelManager->getSourceImage(), notebook );
150 //-------------------------------------------------------------
151         kernelManager->getConceptsInformation(conceptNameVect, conceptSizeVect);
152         _instantPanel->addConcepts(conceptNameVect, conceptSizeVect);
153         double val = _theViewPanel->getCurrentDeep();
154         _instantPanel->setConceptValue( "Axe Depth", (int)val );
155         //JCP _instantPanel->setConceptValue("time", num de imagenes);
156         ConceptDataWrap * data = _instantPanel->getConceptDataOf( "Axe Depth" );
157         //*******************changeInstant();
158         _theViewPanel->setVerticalConcept( "Axe Depth", data->getMinValue(), data->getMaxValue(), data->getMinShowedValue(),  data->getMaxShowedValue(), data->getActualValue() );
159         this->configurePanels( );
160 }
161
162
163         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 )
164         {
165                 if(instance == NULL){
166                         instance = new wxContourMainFrame(parent, id, title, pos, size, images, style,datadir);
167                 }
168                 return instance;
169         }
170
171         std::vector<vtkImageData*> wxContourMainFrame ::getVectImages()
172         {
173                 return kernelManager->getVectImages();
174         }
175
176         wxContourMainFrame* wxContourMainFrame :: getInstance()
177         {
178                 return instance;
179         }
180
181         void wxContourMainFrame :: resetInstance()
182         {
183                 instance->Destroy();
184         }
185
186         wxContourMainFrame :: ~wxContourMainFrame()
187         {
188                 delete _contourextractdata;
189                 deleteAllContours();
190                 _pannew->Close();
191                 interfMainPanel::resetInstance();
192                 delete kernelManager;
193                 instance = NULL;
194                 //_pannew->Destroy();
195                 //delete _pannew;
196
197                 m_mgr.UnInit();
198                 //delete m_mgr;
199
200                 //El problema al cerrar la aplicacion puede estar asociado
201                 //a que  wxAUINotebook esta en la aplicacion
202                 //principal (wxContourGUIExample)tambien
203                 //EED????               delete _theViewPanel;
204                 //EED????               delete _instantPanel;
205                 //EED????               delete _buttonsBar;
206                 //EED????               delete _actualInstant;
207                 //EED????               delete _sceneManager;
208         }
209
210
211         //------------------------------------------------------------------------------------------------------------
212         // Creational and initialization methods using WxAui
213         //------------------------------------------------------------------------------------------------------------
214         //
215         wxAuiNotebook * wxContourMainFrame :: createNotebook()
216         {
217                 wxSize client_size = GetClientSize();
218                 wxAuiNotebook* noteBook = new wxAuiNotebook(this, -1, wxPoint(client_size.x, client_size.y), wxSize(430,200), m_notebook_style);
219                 wxBitmap page_bmp = wxArtProvider::GetBitmap(wxART_NORMAL_FILE, wxART_OTHER, wxSize(16,16));
220                 return noteBook;
221         }
222
223
224         //------------------------------------------------------------------------------------------------------------
225         // Creational and initialization methods
226         //------------------------------------------------------------------------------------------------------------
227         bool wxContourMainFrame :: configurePanels( )
228         {
229                 bool configured = _theViewPanel!=NULL;
230
231                 configured &= _theViewPanel!=NULL;
232                 if( _theViewPanel!=NULL )
233                 {
234                         notebook->AddPage( _theViewPanel, wxT("       View       ") );
235                         m_mgr.Update();
236                 }
237                 if( configured )
238                 {
239                         notebook->AddPage( _instantPanel, wxT("Instant Page") );
240                         m_mgr.Update();
241                 }
242                 m_mgr.AddPane(notebook, wxAuiPaneInfo().Name(wxT("notebook_content")).CenterPane().PaneBorder(false));
243                 m_mgr.Update();
244                 SetMinSize(wxSize(300,300));
245                 m_mgr.Update();
246                 return configured;
247         }
248
249
250         bool wxContourMainFrame::addNewPanel(wxPanel* panel)
251                 {
252                 bool configured = panel!=NULL;
253                 configured &= panel!=NULL;
254
255                 if( configured )
256                 {
257                         notebook->AddPage( panel, wxT("       Viewer       "), true );
258                         m_mgr.Update();
259                 }
260                 return configured;
261         }
262
263         //------------------------------------------------------------------------------------------------------------
264         //  Attributes getters and setters
265         //------------------------------------------------------------------------------------------------------------
266
267
268
269         void wxContourMainFrame :: setInstantChooserPanel(  wxInstantChooserPanel * theInstantChooserPanel )
270         {
271                 _instantPanel = theInstantChooserPanel;
272         }
273
274 //      void wxContourMainFrame :: setButtonsBar(  wxContour_ButtonsBar * theButtonsBar )
275 //      {
276 //              _buttonsBar = theButtonsBar;
277 //      }
278
279 //      void wxContourMainFrame :: setGrid(  wxContour_Grid * theGridPanel )
280 //      {
281 //              _gridPanel = theGridPanel;
282 //      }
283
284 //      void wxContourMainFrame :: setDrawToolsPanel(  wxContour_DrawToolsPanel * theDrawToolsPanel )
285 //      {
286 //              _drawToolsPanel = theDrawToolsPanel;
287 //      }
288
289 //      void wxContourMainFrame :: setOperationsToolsPanel(  wxContour_OperationsToolsPanel * theOperationsToolsPanel )
290 //      {
291 //              _operationsToolsPanel = theOperationsToolsPanel;
292 //      }
293
294 //      void wxContourMainFrame :: setAutomaticFormsPanel(  wxContour_AutomaticFormsToolsPanel * theAutoFormsPanel )
295 //      {
296 //              _autoFormsPanel = theAutoFormsPanel;
297 //      }
298
299 //      void wxContourMainFrame :: setStandardToolsPanel(  wxContour_StandardToolsPanel * theStandardToolsPanel )
300 //      {
301 //              _standardToolsPanel= theStandardToolsPanel;
302 //      }
303
304 //      void wxContourMainFrame :: setEditionToolsPanel(  wxContour_EdtionToolsPanel * theEditionToolsPanel )
305 //      {
306 //              _editionToolsPanel =  theEditionToolsPanel;
307 //      }
308
309 //      void wxContourMainFrame :: setListViewPanel(  wxContour_ListViewPanel * theListViewPanel )
310 //      {
311 //              _listViewPanel = theListViewPanel;
312 //      }
313
314
315
316 void wxContourMainFrame::onCreateContourSpline( ){
317
318         //JCP 20-10-08 Undo redo implementation
319         saveState();
320         //JCP 20-10-08 Undo redo implementation
321         createContour( 1 );
322
323 }
324
325 void wxContourMainFrame::onCreateContourRectangle( )
326 {
327     //JCP 20-10-08 Undo redo implementation
328         saveState();
329         //JCP 20-10-08 Undo redo implementation
330         createContour( 2 );
331 }
332
333 void wxContourMainFrame::onCreateContourCircle( )
334 {
335     //JCP 20-10-08 Undo redo implementation
336         saveState();
337         //JCP 20-10-08 Undo redo implementation
338         createContour( 3 );
339 }
340
341 void wxContourMainFrame::onCreateContourLine( )
342 {
343     //JCP 20-10-08 Undo redo implementation
344         saveState();
345         //JCP 20-10-08 Undo redo implementation
346         createContour( 6 );
347 }
348
349 // RaC 09-09 --------------------------------------
350 void wxContourMainFrame::onCreateContourPoints( )
351 {
352     //JCP 20-10-08 Undo redo implementation
353         saveState();
354         //JCP 20-10-08 Undo redo implementation
355         createContour( 7 );
356 }
357 // RaC 09-09 --------------------------------------
358
359 // RaC 10-09 --------------------------------------
360 void wxContourMainFrame::onCreateContourPolygon( )
361 {
362     //JCP 20-10-08 Undo redo implementation
363         saveState();
364         //JCP 20-10-08 Undo redo implementation
365         createContour( 10 );
366 }
367 // RaC 10-09 --------------------------------------
368
369 //------------------------------------------------------------------------------------------------------------
370
371 void wxContourMainFrame :: onCreateContourBullEye(wxPanel* panel )
372 {
373         //Creating the manualBaseModel and including in the model
374         manualBaseModel * manModelContour = factoryManualContourModel(panel );
375
376         std::vector<int> instantVector;
377         _instantPanel->getInstant( instantVector );
378         std::string theName = kernelManager->createOutline(manModelContour, instantVector);
379
380         /*std::vector<int> instantVector;
381         _instantPanel->getInstant( instantVector );
382         std::string theName;
383         theName= _modelManager->createOutline( manModelContour, instantVector );*/
384         bool addedModel = theName.compare("") != 0;//??
385
386         if( addedModel )
387         {
388                 double spc[3];//Si no hay imagen pero hay contornos que spacing se pone por default
389                 _theViewPanel->getSpacing(spc);
390                 //Adding the manualContourControler to interface objects structure
391                 //Adding the manualViewContour to interface objects structure
392                 //_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.
393                 _theViewPanel->getSceneManager()->configureViewControlTo( theName, manModelContour,spc , 4) ;
394         }
395 }
396
397 void wxContourMainFrame::createContour( int typeContour )
398 {
399         //Creating the manualContourModel and including in the model
400         manualBaseModel * manModelContour = kernelManager->factoryManualContourModel(typeContour);
401         std::vector<int> instantVector;
402         _instantPanel->getInstant( instantVector );
403
404         std::vector<int> tempVector;
405         getInstantVector( tempVector );
406         manModelContour->SetLabel2( std::to_string(tempVector[1]) );
407
408         std::string theName = kernelManager->createOutline(manModelContour, instantVector);
409         /*std::vector<int> instantVector;
410         _instantPanel->getInstant( instantVector );
411         std::string theName;
412         theName= _modelManager->createOutline( manModelContour, instantVector );*/
413         bool addedModel = theName.compare("") != 0;//??
414         if( addedModel )
415         {
416                 double spc[3];//Si no hay imagen pero hay contornos que spacing se pone por default
417                 _theViewPanel->getSpacing(spc);
418                 //Adding the manualContourControler to interface objects structure
419                 //Adding the manualViewContour to interface objects structure
420                 //_sceneManager->setControlActiveStateOfALL( false );//This call is being done here because if the ROI is created underneath the previously created ROIS will still be active.
421                 _theViewPanel->getSceneManager()->configureViewControlTo( theName, manModelContour,spc , typeContour) ;
422         } // if addedModel
423 }
424
425 manualBaseModel * wxContourMainFrame::factoryManualContourModel(wxPanel* panel){
426
427         manualContourModelBullEye *manModelContourBullEye = new manualContourModelBullEye();
428         manualBaseModel *manModelContour=NULL;
429         manModelContour = manModelContourBullEye;
430         if (panel!=NULL){
431                 int iCrown,sizeCrowns,iSector,sizeSectors;
432                 double radioA,radioB,ang,angDelta ;
433                 sizeCrowns = ((PanelBullEyeOptions*)panel)->GetNumberOfCrowns();
434                 for ( iCrown=0 ; iCrown<sizeCrowns ; iCrown++ )
435                 {
436                         sizeSectors = ((PanelBullEyeOptions*)panel)->GetNumberOfSections(iCrown);
437                         radioB  = ((PanelBullEyeOptions*)panel)->GetRadioOfCrown(iCrown);
438                         if (iCrown==sizeCrowns-1)
439                         {
440                                 radioA  = 0;
441                         } else {
442                                 radioA  = ((PanelBullEyeOptions*)panel)->GetRadioOfCrown(iCrown+1);
443                         }
444                         radioA=radioA/100.0;
445                         radioB=radioB/100.0;
446                         for ( iSector=0 ; iSector<sizeSectors  ; iSector++ )
447                         {
448                                 ang             = ((PanelBullEyeOptions*)panel)->GetAngOfCrownSection(iCrown,iSector);
449                                 angDelta= ((PanelBullEyeOptions*)panel)->GetAngDeltaOfCrownSection(iCrown);
450                                 manModelContourBullEye->AddSector(radioA,radioB,ang,angDelta);
451                         } // for iSector
452                 } // for iCrown
453         } // if _panelBullEyeOptions
454
455         return manModelContour;
456 }
457
458 void wxContourMainFrame :: saveState()
459 {
460         std::string temp = kernelManager->saveState();
461         saveFileWithContours(temp);
462 }
463
464 void wxContourMainFrame::onDeleteContour()
465 {
466         //JCP 20-10-08 Undo redo implementation
467                 saveState();
468                 //JCP 20-10-08 Undo redo implementation
469
470                 std::vector<std::string> lstKeyNameToBeErase;
471                 lstKeyNameToBeErase             = _theViewPanel->getSceneManager()->getSelectedObjects();
472                 deleteContours( lstKeyNameToBeErase );
473 /*JCP 19 - 11 - 08
474                 int i,size=_sceneManager->getSelectedObjects().size();
475                 for(i=0;i<size;i++)
476                 {
477                         std::string keyName             = _sceneManager->getSelectedObjects()[i];
478                         int ispartofstaticlist  = this->_modelManager->IsPartOfStaticList( keyName );
479                         if ( ispartofstaticlist>=0 )
480                         {
481                                 std::vector<int> tempVector;
482                                 _instantPanel->getInstant( tempVector );
483                                 Instant instant(&tempVector);
484                                 this->_modelManager->ChangeContourOfList(keyName, &instant);
485                         }
486                 }
487
488                 std::vector<std::string> lstKeyName;
489                 std::vector<std::string> lstKeyNameActualSlice;
490                 std::vector<std::string> lstKeyNameToBeErase;
491
492                 lstKeyNameToBeErase             = _sceneManager->getSelectedObjects();
493                 lstKeyNameActualSlice   = _sceneManager->GetlstContoursNameActualSlice();
494                 int k,kSize=lstKeyNameToBeErase.size();
495                 int j,jSize=lstKeyNameActualSlice.size();
496                 bool ok;
497                 for (k=0;k<kSize; k++)
498                 {
499                         ok=false;
500                         for (j=0;j<jSize; j++)
501                         {
502                                 if (lstKeyNameToBeErase[k]==lstKeyNameActualSlice[j])
503                                 {
504                                         ok=true;
505                                 }
506                         } // for j
507                         if (ok==true)
508                         {
509                                 lstKeyName.push_back( lstKeyNameToBeErase[k] );
510                         } // if ok
511                 } // for k
512
513                 deleteContours( lstKeyName );
514 JCP 19 - 11 - 08*/
515 }
516
517 void wxContourMainFrame :: deleteContours( std::vector<std::string>  keyNamesVector )
518 {
519         int i,size=keyNamesVector.size();
520         for (i=0;i<size;i++)
521         {
522                 deleteContour( keyNamesVector[i] );
523         }
524 }
525
526 void wxContourMainFrame :: deleteContour( std::string theKeyName )
527 {
528         /*
529         manualContourModel                      * cModel;
530         manualViewBaseContour           * cViewer;
531         manualContourBaseControler      * cControler;
532
533         ContourWrap_ViewControl *conwrapviewControl =  _theViewPanel->getSceneManager()->getContourWrap_ViewControlOf( theKeyName );
534         cControler      = conwrapviewControl->getControler();*/
535
536         //JCP 21 - 11 - 2008
537         bool isedit = _theViewPanel->isEditableCControler(theKeyName);
538         bool ispartofstaticlst = kernelManager->IsPartOfStaticList(theKeyName);
539
540         if (isedit  && ispartofstaticlst)
541         {
542                 _theViewPanel->removeFromScene(theKeyName);
543
544                 kernelManager->deleteCModel(theKeyName);
545                 //_theViewPanel->getSceneManager()->removeFromScene( theKeyName );
546                 //cViewer               = conwrapviewControl->getViewer();
547                 //_theViewPanel->getSceneManager()->removeWrap( theKeyName );
548                 //cControler* conwrapviewControl->getControler();
549         //      delete cModel;
550         //      delete cViewer;
551         //      delete cControler;
552         } // if editable
553 //JCP 21 - 11 - 08
554 }
555
556 void wxContourMainFrame::onDeleteContoursActSlice()
557 {
558         //JCP 20-10-08 Undo redo implementation
559         saveState();
560         //JCP 20-10-08 Undo redo implementation
561
562         std::vector<int> tempVector;
563         getInstantVector( tempVector );
564         deleteContours( getOutlinesName( tempVector[1] ) );
565 //      deleteContours( (std::vector<std::string>)_theViewPanel->getSceneManager()->GetlstContoursNameActualSlice() );
566
567 }
568 void wxContourMainFrame::onDeleteAllContours(){
569         //JCP 20-10-08 Undo redo implementation
570         saveState();
571         deleteAllContours();
572 }
573 void wxContourMainFrame::deleteAllContours(){
574         //JCP 20-10-08 Undo redo implementation
575
576         wxBusyCursor wait;
577         std::vector<int> tempVector;
578         _instantPanel->getInstant( tempVector );
579
580 //JCP --08-09-2008 When using a diferent interface the _mbarrangeDeleteAll might not be initialize
581 //              the values in GetStart and GetEnd will then not be initialize also.
582 //              We use instead the values given when initializing the _deletepanel.
583
584         //int minZ = _mbarrangeDeleteAll->GetStart();
585         //int maxZ = _mbarrangeDeleteAll->GetEnd();
586         int minZ, maxZ;
587
588         minZ = 0;
589         maxZ = _theViewPanel->getSceneManager()->GetImageDataSizeZ();
590
591 //JCP --08-09-2008
592
593         _theViewPanel->getSceneManager()->removeSceneContours( );
594         _theViewPanel->getSceneManager()->removeAllOutlines();
595         kernelManager->removeAllOutlines();
596 //JCP --08-09-2008
597         /*
598         if ( (minZ==0) && (maxZ==_mbarrangeDeleteAll->GetMax() ))
599         {
600                 _theViewPanel->getSceneManager()->removeSceneContours( );
601                 _modelManager->removeAllOutlines();
602                 _theViewPanel->getSceneManager()->removeAllOutlines();
603
604         } else {
605                 for ( z=minZ ; z<=maxZ ; z++)
606                 {
607                         tempVector[1]=z;
608                         Instant instant(&tempVector);
609                         std::vector<ContourThing**> lstContourThings = this->_modelManager->getOutlinesAtInstant( &instant );
610
611                         sizeLstContourThings = lstContourThings.size();
612                         for (ii=0 ; ii<sizeLstContourThings ; ii++)
613                         {
614                                 ContourThing **contourthing = lstContourThings[ii];
615                                 deleteContour( (*contourthing)->getName() );
616                         } //for ii
617                 }// for z
618         } // if
619 JCP --08-09-2008 */
620 }
621
622 void wxContourMainFrame::setConceptValue( std::string name, int value )
623 {
624         _instantPanel->setConceptValue(name, value);
625 }
626
627
628 ConceptDataWrap* wxContourMainFrame::getLastConceptData()
629 {
630         return _instantPanel->getLastConceptData();
631 }
632
633
634 bool wxContourMainFrame::getIfConceptCheckedAt( std::string name, int pos )
635 {
636         return _instantPanel->getIfConceptCheckedAt( name, pos );
637 }
638
639
640
641 void wxContourMainFrame::ShowResultImages(int typeContourGroup, int selection, int minZ, int maxZ)
642 {
643         vtkImageData * mask;
644         vtkImageData * value;
645         this->getMaskValue(&mask, &value, typeContourGroup, selection, minZ, maxZ);
646
647         std::vector<int> nTypeView;
648         nTypeView.push_back(5);
649         nTypeView.push_back(1);
650         nTypeView.push_back(2);
651         nTypeView.push_back(0);
652
653         if (_frameShowResultImages==NULL)
654         {
655 //              wxFrame *_frameShowResultImages = new wxFrame(this, -1,_T("Result image extracted.."),wxDefaultPosition,wxSize(600,600), wxDEFAULT_FRAME_STYLE|wxSTAY_ON_TOP);
656                 _frameShowResultImages = new wxFrame(this, -1,_T("Result image extracted.."),wxDefaultPosition,wxSize(600,600), 
657                      wxFRAME_TOOL_WINDOW|wxSYSTEM_MENU | wxCAPTION |  wxCLIP_CHILDREN |wxFRAME_FLOAT_ON_PARENT | wxRESIZE_BORDER  );
658
659                 wxAuiManager *m_mgr_noteBookViewerResult = new wxAuiManager();
660                 m_mgr_noteBookViewerResult->SetManagedWindow(_frameShowResultImages);
661
662                 wxAuiNotebook* noteBookViewerResult = new wxAuiNotebook(_frameShowResultImages, -1, wxPoint(600, 600), wxSize(430,200), m_notebook_style);
663                 m_mgr_noteBookViewerResult->AddPane(noteBookViewerResult, wxAuiPaneInfo().Name(wxT("notebook_content")).CenterPane().PaneBorder(false));
664
665                 wxPanel *panelViewer1 = new wxMaracas_N_ViewersWidget(noteBookViewerResult, value,&nTypeView);
666                 wxPanel *panelViewer2 = new wxMaracas_N_ViewersWidget(noteBookViewerResult, mask,&nTypeView);
667
668
669                 noteBookViewerResult->AddPage( panelViewer1, wxT("Image result") );
670                 noteBookViewerResult->AddPage( panelViewer2, wxT("Mask result") );
671                 m_mgr_noteBookViewerResult->Update();
672                 _frameShowResultImages->Show();
673         } // if _frameShowResultImages
674 }
675
676
677
678
679 void wxContourMainFrame::changeInstant()
680 {
681                 std::vector<int> instantVect;
682                 _instantPanel->getInstant( instantVect );
683                 int actualSlice = instantVect[1];
684                 kernelManager->setInstant(instantVect);
685             // Refresh Mask image
686                 if(_viewMaskImage!=NULL)
687                 {
688                         _viewMaskImage->SetZ(actualSlice);
689                         if (_viewMaskImagePanel->IsVisible()==true)
690                         {
691                                 vtkImageData *mask, *value;
692                                 getMaskValue(&mask,&value, _contourGroup , 0, -1, -1);
693                                 _viewMaskImage->onThreshold();
694                         }
695                 } // if _viewMaskImage
696         // Refresh Threshold image
697                 if(_viewThresholdImage!=NULL)
698                 {
699                         _viewThresholdImage->SetZ(actualSlice);
700                         if (_viewThresholdImagePanel->IsVisible()==true)
701                         {
702                                 _viewThresholdImage->onThreshold();
703                         }
704                 } // if _viewThresholdImage
705                 updateInstantOutlines();
706                 updateInstantImageData();
707                 updateInstantAxes();
708 }
709
710
711
712 void wxContourMainFrame::updateInstantOutlines()
713 {
714         _theViewPanel->removeSceneContours();
715         _theViewPanel->addNameWrapperToScene();
716
717         //for( int i=0; i<size; i++)
718         //{
719         //      _theViewPanel->getSceneManager()->addToScene(namesWrapping[i]->getKeyName(), true, true, true, false, false );
720         //}
721 }
722
723 int wxContourMainFrame::getNamesWrappingSize()
724 {
725         return kernelManager->getNamesWrappingSize();
726 }
727
728 std::string wxContourMainFrame::getNameWrapping(int i)
729 {
730         return kernelManager->getNameWrapping(i);
731 }
732
733 void wxContourMainFrame::updateInstantImageData()
734 {
735         std::vector<int> inst;
736         _instantPanel->getInstant(inst);
737
738         vtkImageData* img = kernelManager->getImageAtInstant(inst);
739         if(img!=NULL)
740         {
741                 _theViewPanel->changeImage(img);
742                 showAxis(false);
743         }else{
744                 int z = _instantPanel->getConceptDataOf("Axe Depth")->getActualValue();
745                 _theViewPanel->setImageSlice(z);
746         } // if img
747 }
748
749 void wxContourMainFrame::updateInstantAxes()
750 {
751 }
752
753
754 void wxContourMainFrame::onChangeDeep(int val){
755         _instantPanel->setConceptValue( "Axe Depth", (int)val );
756         changeInstant();
757 }
758
759
760 void wxContourMainFrame::onCopy(){
761         std::vector<std::string> currentSelection = _theViewPanel->getSelectedObjects();
762         std::vector<int> tempVector;
763         _instantPanel->getInstant( tempVector );
764     _performingOperation->reset();
765         _performingOperation->setStartCommand( COPY );
766         _performingOperation->setStartOperationInstantVector( tempVector );
767         _performingOperation->setKeyNamesOperationElems( currentSelection );
768 }
769
770 void wxContourMainFrame::onPaste()
771 {
772         char theStartCommand = _performingOperation->getStartCommand();
773         if (  theStartCommand == COPY )
774         {
775                 //JCP 20-10-08 Undo redo implementation
776                 saveState();
777                 //JCP 20-10-08 Undo redo implementation
778                 std::vector<int> tempVector;
779                 _instantPanel->getInstant( tempVector );
780                 _performingOperation->setEndOperationInstantVector ( tempVector );
781                 std::vector<std::string> elems = _performingOperation->getKeyNamesOperationElems();
782                 int i,size = elems.size();
783                 for( i=0; i<size; i++ )
784                 {
785                         createCopyContourOf( elems[i], tempVector, i>0 );
786                 }
787         }
788 }
789
790 void wxContourMainFrame::onUndo()
791 {
792         std::string filename;
793         if(kernelManager->onUndoSaveFile(filename)){
794                 saveFileWithContours(filename);
795         }
796         if(kernelManager->onUndo(filename)){
797                 loadState(filename);
798         }
799 }
800 void wxContourMainFrame::onRedo(){
801         std::string filename;
802         if(kernelManager->onRedo(filename)){
803                 loadState(filename);
804         }
805
806 }
807 void wxContourMainFrame :: createCopyContourOf ( std::string anExistingKName, std::vector<int> &instantNoTouchData, bool append )
808 {
809         std::string cloneName = kernelManager->createCopyContourOf( anExistingKName, instantNoTouchData );
810         manualBaseModel * manualModel = kernelManager->getOutlineByKeyName(cloneName);//_modelManager->getOutlineByKeyName( cloneName )->getModel();
811         _theViewPanel->getSceneManager()->createCopyContourOf( anExistingKName, cloneName, manualModel , append );
812 }
813
814 ///AD: 03-09    Copy the object and apply the given transformation
815 void wxContourMainFrame :: createMirrorContourOf ( std::string anExistingKName, std::vector<int> &instantNoTouchData, bool append )
816 {
817         std::string cloneName = kernelManager->createCopyContourOf( anExistingKName, instantNoTouchData );
818         manualBaseModel * manualModel = kernelManager->getOutlineByKeyName(cloneName);
819
820         manualPoint * refPoint1 = _refLineModel->GetManualPoint(0);
821         manualPoint * refPoint2 = _refLineModel->GetManualPoint(1);
822
823         double pnt1X = refPoint1->GetX();
824         double pnt1Y = refPoint1->GetY();
825 //      double pnt1Z = refPoint1->GetZ();
826         double pnt2X = refPoint2->GetX();
827         double pnt2Y = refPoint2->GetY();
828 //      double pnt2Z = refPoint2->GetZ();
829
830         double angle = (atan2(pnt2Y - pnt1Y, pnt2X - pnt1X) * 180 / 3.1415926535897932384626433832795)+90;
831         vtkTransform *t = vtkTransform::New();
832
833         t->PostMultiply();
834         t->Identity();
835         t->Translate(-pnt1X, -pnt1Y, 0);
836         t->RotateZ(-angle);
837         t->Scale(-1,1,1);
838         t->RotateZ(angle);
839         t->Translate(pnt1X, pnt1Y, 0);
840         t->Update();
841
842         int i,size=manualModel->GetSizeLstPoints();
843         for (i=0;i<size;i++)
844         {
845                 manualPoint * mp = manualModel->GetManualPoint(i);
846                 float vecIn[3];
847                 float vecOut[3];
848                 vecIn[0]=mp->GetX();
849                 vecIn[1]=mp->GetY();
850                 vecIn[2]=mp->GetZ();
851                 t->TransformPoint( vecIn, vecOut );
852                 mp->SetPointX( vecOut[0] );
853                 mp->SetPointY( vecOut[1] );
854                 mp->SetPointZ( vecOut[2] );
855         }
856
857         _theViewPanel->getSceneManager()->createCopyContourOf( anExistingKName, cloneName, manualModel , append );
858 }
859
860 void wxContourMainFrame ::loadState(std::string filename)
861 {
862         deleteAllContours();
863         onLoadContours(filename,false);
864 }
865
866
867 void wxContourMainFrame::onLoad()
868 {
869         std::string fileNameContourROI = GetFileLocation();
870 //CMRU 03-09-09-----------------------------------------------------------------------------------------------
871         if(GetFileLocation().empty())
872         {
873 //------------------------------------------------------------------------------------------------------------
874 //EED 2017-09-16 Migration wxWidgets 2.8 to 3.0
875 #if wxMAJOR_VERSION <= 2
876                 wxFileDialog dialog(NULL, _T("Choose a file"), _T(""), _T(""), _T("*.roi"), wxOPEN );
877 #else
878                 wxFileDialog dialog(NULL, _T("Choose a file"), _T(""), _T(""), _T("*.roi"), wxFD_OPEN );
879 #endif
880                 if (dialog.ShowModal() == wxID_OK)
881                 {
882                         fileNameContourROI = (const char *)(dialog.GetPath().mb_str());
883                 }
884         }
885
886         onLoadContours(fileNameContourROI,true);
887 }
888
889
890 void  wxContourMainFrame::SetZForAllContours(int pz)
891 {
892         //-- Normal Contours
893         std::vector< std::string > lstNameThings;       
894         int i,sizeLstNameThings;
895         int ii,sizeLstPoints;
896         
897         lstNameThings           = kernelManager->GetLstNameThings();
898         sizeLstNameThings       = lstNameThings.size(); 
899         for (i=0 ; i<sizeLstNameThings ; i++)
900         {
901 printf("EED wxContourMainFrame::SetZForAllContours contour=%d \n", i );
902                 manualBaseModel * manualModel = kernelManager->getOutlineByKeyName(lstNameThings[i]);
903                 sizeLstPoints = manualModel->GetSizeLstPoints();
904                 for (ii=0 ; ii<sizeLstPoints ; ii++)
905                 {
906                          manualModel->GetManualPoint(ii)->SetPointZ(-900);
907                 }// for ii  list of points
908         }// for i  list of Things
909
910         //-- Static Contours
911
912         lstNameThings           = kernelManager->GetLstNameThingsStatic();
913         sizeLstNameThings       = lstNameThings.size();
914         for (i=0 ; i<sizeLstNameThings ; i++)
915         {
916                 manualBaseModel * manualModel = kernelManager->getOutlineByKeyName(lstNameThings[i]);
917                 sizeLstPoints = manualModel->GetSizeLstPoints();
918                 for (ii=0 ; ii<sizeLstPoints ; ii++)
919                 {
920                          manualModel->GetManualPoint(ii)->SetPointZ(-900);
921                 }// for ii  list of points
922         }// for i  list of static things
923 }
924
925 void wxContourMainFrame::onLoadContours(std::string fileNameContourROI, bool interactiveInterface)
926 {
927         char tmp[255];
928         char tmpD[255];
929         FILE *pFile =fopen(fileNameContourROI.c_str(),"r+");
930 //CMRU 03-09-09- ----------------------------------------------------------------------------------------------
931         if(pFile != NULL)
932         {
933 //------------------------------------------------------------------------------------------------------------
934         fileNameContourROI.append("data");
935                 FILE *pFileData=fopen(fileNameContourROI.c_str(),"r+");
936                 if(pFileData != NULL)
937                 {
938                         fscanf(pFileData,"%s",tmpD); // --CreaContour--
939                         fscanf(pFileData,"%s",tmpD); // Version
940                         fscanf(pFileData,"%s",tmpD); // 1.0.3 || 1.0.2 || 1.0.1 || 1.0.0
941
942                         fscanf(pFileData,"%s",tmpD); // onePixelSize
943                         fscanf(pFileData,"%s",tmpD); // #
944                         _onePixelSize = atof(tmpD);
945                         fscanf(pFileData,"%s",tmpD); // NumberOfContours
946                         fscanf(pFileData,"%s",tmpD); // #
947                 }
948                 fscanf(pFile,"%s",tmp); // --CreaContour--
949                 fscanf(pFile,"%s",tmp); // Version
950                 fscanf(pFile,"%s",tmp); // 1.0.3 || 1.0.2 || 1.0.1 || 1.0.0
951                 std::string version(tmp);
952                 //AD:02-06-09
953         _tmpReadFileTypeOfTransformation=-1;
954                 if (version=="1.0.3")
955                 {
956                     readDimSpc(pFile,interactiveInterface);   // DimSpc interactive ON
957                         openContours(pFile,pFileData,false);
958                         openContours(pFile,pFileData,true);     //Load StaticContours
959                 }       
960                 if (version=="1.0.2")
961                 {
962 //EED001
963                         readDimSpc(pFile,interactiveInterface); // DimSpc interactive ON
964                         openContours(pFile,pFileData,false);
965                         readDimSpc(pFile,false);                // DimSpc interactive OFF
966                         openContours(pFile,pFileData,true);     // Load StaticContours
967                         SetZForAllContours(-900);
968                 }
969                 //AD:02-06-09
970                 else if (version=="1.0.1")
971                 {
972                         openContours(pFile,pFileData,false); //Skips ImageDimensions and ImageSpacing
973                         openContours(pFile,pFileData,true); //Load StaticContours, skips ImageDimensions and ImageSpacing
974                 }
975
976                 //AD:02-06-09
977                 else if (version=="1.0.0")
978                 {
979                         openContours(pFile,pFileData,false); //Skips ImageDimensions and ImageSpacing
980                 }
981
982                 fclose(pFile);
983
984                 if(pFileData != NULL)
985                 {
986                         fclose(pFileData);
987                 } // if
988         }
989         _theViewPanel->getSceneManager()->removeSceneContours();
990         changeInstant();
991 }
992
993
994 void wxContourMainFrame::onImport()
995 {
996         std::string filename, filenamecontours;
997 //EED 2017-09-16 Migration wxWidgets 2.8 to 3.0
998 #if wxMAJOR_VERSION <= 2
999         wxFileDialog dialog(NULL, _T("Choose a XML Osirix File"), _T(""), _T(""), _T("*.xml"), wxOPEN );
1000 #else
1001         wxFileDialog dialog(NULL, _T("Choose a XML Osirix File"), _T(""), _T(""), _T("*.xml"), wxFD_OPEN );
1002 #endif
1003         if (dialog.ShowModal() == wxID_OK)
1004         {
1005                 filename = dialog.GetPath().mb_str();
1006                 filenamecontours = kernelManager->parseOsirixFile(filename);
1007
1008                 if(filenamecontours.compare("") != 0){
1009                         onLoadContours(filenamecontours,true);
1010                 } // if
1011         } // if
1012 }
1013
1014 void wxContourMainFrame::onTest()
1015 {
1016         std::string filename, filenamecontours;
1017 //EED 2017-09-16 Migration wxWidgets 2.8 to 3.0
1018 #if wxMAJOR_VERSION <= 2
1019         wxFileDialog dialog(NULL, _T("Choose a File"), _T(""), _T(""), _T("*.*"), wxOPEN );
1020 #else
1021         wxFileDialog dialog(NULL, _T("Choose a File"), _T(""), _T(""), _T("*.*"), wxFD_OPEN );
1022 #endif
1023
1024         if (dialog.ShowModal() == wxID_OK)
1025         {
1026                 filename = dialog.GetPath().mb_str();
1027                 std::cout << "This is the filename: " << filename << std::endl;
1028         } // if
1029 }
1030
1031
1032 //AD: 29-05-09
1033 void wxContourMainFrame::onSave(){
1034 //CMRU 03-09-09-----------------------------------------------------------------------------------------------
1035         if(GetFileLocation().empty())
1036         {
1037 //------------------------------------------------------------------------------------------------------------
1038 //EED 2017-09-16 Migration wxWidgets 2.8 to 3.0
1039 #if wxMAJOR_VERSION <= 2
1040                 wxFileDialog dialog(NULL, _T("Choose a file"), _T(""), _T(""), _T("*.roi"), wxSAVE );
1041 #else
1042                 wxFileDialog dialog(NULL, _T("Choose a file"), _T(""), _T(""), _T("*.roi"), wxFD_SAVE );
1043 #endif
1044                 if (dialog.ShowModal() == wxID_OK)
1045                 {
1046                         std::string fileNameContourROI = (const char *)(dialog.GetPath().mb_str());
1047                         kernelManager->setCurrentFileName(fileNameContourROI);
1048                         saveFileWithContours( fileNameContourROI );
1049                 }
1050         }
1051 //CMRU 03-09-09-----------------------------------------------------------------------------------------------
1052         else
1053         {
1054                 std::cout<<"Nombre del archivo: "<<GetFileLocation()<<std::endl;
1055                 std::string fileNameContourROI = GetFileLocation();
1056                 std::cout<<"Nombre del archivo: "<<fileNameContourROI<<std::endl;
1057                 kernelManager->setCurrentFileName(fileNameContourROI);
1058                 saveFileWithContours( fileNameContourROI);
1059         }
1060 //------------------------------------------------------------------------------------------------------------
1061 }
1062
1063 //AD: 29-05-09
1064 void wxContourMainFrame::saveFileWithContours( std::string filename )
1065 {
1066
1067         FILE *pFile=fopen(filename.c_str(),"w+");
1068
1069 //CMRU 03-09-09-----------------------------------------------------------------------------------------------
1070         filename.append("data");
1071         std::cout<<"Nombre del archivo: "<<filename<<std::endl;
1072         FILE *pFileData=fopen(filename.c_str(),"w+");
1073 //------------------------------------------------------------------------------------------------------------
1074
1075         std::vector< std::string > lstNameThings;
1076         int i,sizeLstNameThings;
1077
1078         fprintf(pFile,"--CreaContour--\n");
1079         fprintf(pFile,"Version %s\n", "1.0.3" );
1080
1081 //CMRU 03-09-09-----------------------------------------------------------------------------------------------
1082         fprintf(pFileData,"--CreaContour--\n");
1083         fprintf(pFileData,"Version %s\n", "1.0.3" );
1084         fprintf(pFileData,"OnePixelSize %f\n", _onePixelSize);
1085
1086 //------------------------------------------------------------------------------------------------------------
1087
1088         vtkImageData *image = _images[0];
1089
1090         int dimRange[3];
1091         image->GetDimensions(dimRange);
1092
1093         fprintf(pFile,"ImageDimensions %d %d %d\n", dimRange[0], dimRange[1], dimRange[2] );
1094
1095         double spaRange[3];
1096         image->GetSpacing(spaRange);
1097
1098         fprintf(pFile,"ImageSpacing %f %f %f\n", spaRange[0], spaRange[1], spaRange[2] );
1099
1100         // Normal Contours
1101
1102         lstNameThings           = kernelManager->GetLstNameThings();
1103         sizeLstNameThings       = lstNameThings.size();
1104         fprintf(pFile,"NumberOfContours %d\n", sizeLstNameThings );
1105
1106 //CMRU 03-09-09-----------------------------------------------------------------------------------------------
1107         fprintf(pFileData,"NumberOfContours %d\n", sizeLstNameThings );
1108 //------------------------------------------------------------------------------------------------------------
1109
1110
1111 // EED 2017-05-30
1112         double spc[3];
1113         spc[0]=1; 
1114         spc[1]=1; 
1115         spc[2]=1; 
1116
1117         for (i=0 ; i<sizeLstNameThings ; i++)
1118         {
1119 //CMRU 03-09-09-----------------------------------------------------------------------------------------------
1120                 manualBaseModel * manualModel = kernelManager->getOutlineByKeyName(lstNameThings[i]);
1121
1122 // EED 2017-05-30
1123 //              double sizeInPixel = manualModel ->GetPathSize(  );
1124                 double sizeInPixel = manualModel ->GetPathSize( spc );
1125
1126                 double realContourSize = sizeInPixel*_onePixelSize;
1127                 manualModel ->SetRealSize(realContourSize);
1128 //------------------------------------------------------------------------------------------------------------
1129
1130         //int size= kernelManager->GetLstNameThings().size();
1131
1132                 kernelManager->SaveThingName( pFile, pFileData, lstNameThings[i] );
1133                 _theViewPanel->getSceneManager()->SaveThingName( pFile, lstNameThings[i] );
1134         }// for i
1135
1136         //-- Static Contours
1137
1138 //      fprintf(pFile,"ImageDimensions %d %d %d\n", dimRange[0], dimRange[1], dimRange[2] );
1139 //      fprintf(pFile,"ImageSpacing %f %f %f\n", spaRange[0], spaRange[1], spaRange[2] );
1140
1141         lstNameThings           = kernelManager->GetLstNameThingsStatic();
1142         sizeLstNameThings       = lstNameThings.size();
1143         fprintf(pFile,"NumberOfContoursStatic %d\n", sizeLstNameThings );
1144
1145 //CMRU 03-09-09-----------------------------------------------------------------------------------------------
1146         fprintf(pFileData,"NumberOfContoursStatic %d\n", sizeLstNameThings );
1147 //------------------------------------------------------------------------------------------------------------
1148
1149         for (i=0 ; i<sizeLstNameThings ; i++)
1150         {
1151                 kernelManager->SaveThingName( pFile, pFileData, lstNameThings[i] );
1152                 _theViewPanel->getSceneManager()->SaveThingName( pFile, lstNameThings[i] );
1153         }// for i
1154         fclose(pFile);
1155         fclose(pFileData);
1156 }
1157
1158
1159 //EED02
1160 void wxContourMainFrame::readDimSpc(FILE *pFile, bool interactiveOption)
1161 {
1162         char tmp[255];
1163         int             imageDim[3];
1164         double          imageSpac[3];
1165         vtkImageData    *image          = _images[0];
1166     image->GetDimensions(imageDim);
1167     image->GetSpacing(imageSpac);
1168
1169     fscanf(pFile,"%s",tmp); // ImageDimensions
1170     fscanf(pFile,"%s",tmp); // X
1171     _tmpReadFileImageDim[0] = atoi(tmp);
1172     fscanf(pFile,"%s",tmp); // Y
1173     _tmpReadFileImageDim[1] = atoi(tmp);
1174     fscanf(pFile,"%s",tmp); // Z
1175     _tmpReadFileImageDim[2] = atoi(tmp);
1176
1177     fscanf(pFile,"%s",tmp); // ImageSpacing
1178     fscanf(pFile,"%s",tmp); // X
1179     _tmpReadFileImageSpac[0] = atof(tmp);
1180     fscanf(pFile,"%s",tmp); // Y
1181     _tmpReadFileImageSpac[1] = atof(tmp);
1182     fscanf(pFile,"%s",tmp); // Z
1183     _tmpReadFileImageSpac[2] = atof(tmp);
1184
1185
1186         if (interactiveOption==true)
1187     {
1188                 //Compare Spacing and Dims in X and Y (Necessary in Z?) - Just for Version 2
1189                 if (imageDim[0]!=_tmpReadFileImageDim[0] || imageDim[1]!=_tmpReadFileImageDim[1] || imageSpac[0]!=_tmpReadFileImageSpac[0] || imageSpac[1]!=_tmpReadFileImageSpac[1])
1190                 {
1191                         wxDialog* dial = new wxDialog (this,-1,_T("Tools"),wxDefaultPosition, wxSize(460,360));
1192                         wxSizer* buttonsSizer = dial->CreateSeparatedButtonSizer(wxOK|wxCANCEL);
1193                         wxBoxSizer *dialSizer = new wxBoxSizer(wxVERTICAL);
1194
1195                         wxString lstOptOperation[2];
1196                         lstOptOperation[0]=_T("By Dimension");
1197                         lstOptOperation[1]=_T("By Spacing");
1198                         wxRadioBox * radioOpts = new wxRadioBox(dial, -1, _T("Type of Transformation"), wxDefaultPosition, wxSize(270,45), 2 , lstOptOperation,  2, wxRA_SPECIFY_COLS);
1199
1200                         dialSizer->Add( new wxStaticText(dial,-1,_T("The image resolution is not compatible with the "))  , 0, wxGROW );
1201                         dialSizer->Add( new wxStaticText(dial,-1,_T("selected Roi file. Do you want to tranform it?"))  , 0, wxGROW );
1202                         dialSizer->Add( new wxStaticText(dial,-1,_T(" "))  , 0, wxGROW );
1203                         dialSizer->Add(radioOpts,0,wxGROW);
1204                         dialSizer->Add( new wxStaticText(dial,-1,_T(" "))  , 0, wxGROW );
1205                         dialSizer->Add(buttonsSizer,0,wxGROW);
1206                         dial->SetSizer(dialSizer, true);
1207                         dial->Layout();
1208                         dial->ShowModal();
1209
1210                         int _tmpReadFileTypeOfTransformation = -1;
1211 //EED                   bool transform = false;
1212
1213                         if (dial->GetReturnCode() == wxID_OK)
1214                         {
1215                                 _tmpReadFileTypeOfTransformation    = radioOpts->GetSelection();
1216                         }// if wxOK
1217
1218                 } // if dim spc
1219     } // if interactiveOption
1220 }
1221
1222
1223
1224
1225 //AD:04-06-09
1226 void wxContourMainFrame::openContours( FILE *pFile, FILE *pFileData, bool staticContour )
1227 {
1228
1229         char tmp[255];
1230
1231         vtkImageData    *image = _images[0];
1232
1233         int             imageDim[3];
1234         double          imageSpac[3];
1235     image->GetDimensions(imageDim);
1236     image->GetSpacing(imageSpac);
1237
1238
1239         fscanf(pFile,"%s",tmp); // NumberOfContours
1240         fscanf(pFile,"%s",tmp); // ##
1241         int numberOfContours = atoi(tmp);
1242
1243         std::vector<int> instantVector;
1244         int typeContourModel;
1245         manualBaseModel *manModelContour;
1246         int typeView;
1247
1248 /*
1249         if (compatible==true)
1250         {
1251                 int i;
1252                 for (i=0;i<numberOfContours;i++)
1253                 {
1254                         instantVector.clear();
1255                         fscanf(pFile,"%s",tmp); // Instant
1256
1257                         fscanf(pFile,"%s",tmp); // 1
1258                         instantVector.push_back( atoi(tmp) );
1259                         fscanf(pFile,"%s",tmp); // 2
1260                         instantVector.push_back( atoi(tmp) );
1261                         fscanf(pFile,"%s",tmp); // 3
1262                         instantVector.push_back( atoi(tmp) );
1263                         fscanf(pFile,"%s",tmp); // 4
1264                         instantVector.push_back( atoi(tmp) );
1265                         fscanf(pFile,"%s",tmp); // 5
1266                         instantVector.push_back( atoi(tmp) );
1267                         fscanf(pFile,"%s",tmp); // 6
1268                         instantVector.push_back( atoi(tmp) );
1269
1270
1271                         fscanf(pFile,"%s",tmp); // TypeContourModel
1272                         fscanf(pFile,"%s",tmp); // ##
1273                         typeContourModel = atoi(tmp);
1274
1275                         manModelContour =  kernelManager->factoryManualContourModel(typeContourModel);
1276                         manModelContour->Open(pFile);
1277                         if(pFileData != NULL)
1278                         {
1279                                 manModelContour->OpenData(pFileData);
1280                         }
1281
1282                         fscanf(pFile,"%s",tmp); // TypeView
1283                         fscanf(pFile,"%s",tmp); // ##
1284                         typeView = atoi(tmp);
1285
1286                         std::string theName;
1287                         theName = kernelManager->createOutline( manModelContour, instantVector );
1288                         bool addedModel = theName.compare("") != 0;
1289                         if( addedModel )
1290                         {
1291                                 double spc[3];//Si no hay imagen pero hay contornos que spacing se pone por default
1292                                 _theViewPanel->getSpacing(spc);
1293                                 //Adding the manualContourControler to interface objects structure
1294                                 //Adding the manualViewContour to interface objects structure
1295                                 //_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.
1296                                 _theViewPanel->getSceneManager()->configureViewControlTo( theName, manModelContour,spc , typeView) ;
1297                         }
1298
1299                         if (staticContour) //StaticContours (will appear in all slices)
1300                         {
1301                                 Instant instant(&instantVector);
1302                                 kernelManager->changeContourOfManager( theName , &instant );
1303                         }
1304
1305                 }// for  numberOfContours
1306         }
1307
1308         else if (compatible==false)
1309         {
1310 */
1311
1312                 int i;
1313                 for (i=0;i<numberOfContours;i++)
1314                 {
1315                         instantVector.clear();
1316                         fscanf(pFile,"%s",tmp); // Instant
1317
1318                         fscanf(pFile,"%s",tmp); // 1
1319                         instantVector.push_back( atoi(tmp) );
1320                         fscanf(pFile,"%s",tmp); // 2
1321                         instantVector.push_back( atoi(tmp) );
1322                         fscanf(pFile,"%s",tmp); // 3
1323                         instantVector.push_back( atoi(tmp) );
1324                         fscanf(pFile,"%s",tmp); // 4
1325                         instantVector.push_back( atoi(tmp) );
1326                         fscanf(pFile,"%s",tmp); // 5
1327                         instantVector.push_back( atoi(tmp) );
1328                         fscanf(pFile,"%s",tmp); // 6
1329                         instantVector.push_back( atoi(tmp) );
1330
1331                         fscanf(pFile,"%s",tmp); // TypeContourModel
1332                         fscanf(pFile,"%s",tmp); // ##
1333                         typeContourModel = atoi(tmp);
1334
1335                         manModelContour =  kernelManager->factoryManualContourModel(typeContourModel);
1336                         manModelContour->Open(pFile);
1337                         if(pFileData != NULL)
1338                         {
1339                                 manModelContour->OpenData(pFileData);
1340                         }
1341
1342             if (_tmpReadFileTypeOfTransformation==-1){
1343                 //nothing to do..
1344             } else if (_tmpReadFileTypeOfTransformation==0){
1345                 double transX, transY;
1346                 transX = (double) imageDim[0]/_tmpReadFileImageDim[0];
1347                 transY = (double) imageDim[1]/_tmpReadFileImageDim[1];
1348                 manModelContour->Transform_Ax_Plus_B(transX,0,transY,0);
1349             } else if (_tmpReadFileTypeOfTransformation==1) {
1350                 double transX, transY;
1351                 transX = (double) _tmpReadFileImageSpac[0]/imageDim[0];
1352                 transY = (double) _tmpReadFileImageSpac[1]/imageDim[1];
1353                 manModelContour->Transform_Ax_Plus_B(transX,0,transY,0);
1354             }
1355
1356                         fscanf(pFile,"%s",tmp); // TypeView
1357                         fscanf(pFile,"%s",tmp); // ##
1358                         typeView = atoi(tmp);
1359
1360                         std::string theName;
1361                         theName = kernelManager->createOutline( manModelContour, instantVector );
1362                         bool addedModel = theName.compare("") != 0;
1363                         if( addedModel )
1364                         {
1365                                 double spc[3];//Si no hay imagen pero hay contornos que spacing se pone por default
1366                                 _theViewPanel->getSpacing(spc);
1367                                 //Adding the manualContourControler to interface objects structure
1368                                 //Adding the manualViewContour to interface objects structure
1369                                 //_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.
1370                                 _theViewPanel->getSceneManager()->configureViewControlTo( theName, manModelContour,spc , typeView) ;
1371                         }
1372
1373                         if (staticContour) //StaticContours (will appear in all slices)
1374                         {
1375                                 Instant instant(&instantVector);
1376                                 kernelManager->changeContourOfManager( theName , &instant );
1377                         }
1378                 }// for  numberOfContours
1379
1380 /*      }    */
1381
1382 }
1383
1384 void wxContourMainFrame::RefreshInterface()
1385 {
1386         changeInstant();
1387         _theViewPanel->RefreshInterface();
1388         //wxVtk2DBaseView *wxvtk2dbaseview = (wxVtk2DBaseView*)this->_theViewPanel->getWxVtkBaseView();
1389         //wxvtk2dbaseview->Refresh();
1390 }
1391
1392 vtkImageData* wxContourMainFrame::getImageData()
1393 {
1394         return _theViewPanel->getImageData();
1395 }
1396
1397 void wxContourMainFrame::onSegmentationOneSliceITK(wxString distance, wxString sigma, wxString alfa, wxString beta, wxString propagation, wxString iterations, wxString inflation)
1398 {
1399         //JCP 20-10-08 Undo redo implementation
1400         saveState();
1401         //JCP 20-10-08 Undo redo implementation
1402
1403         wxBusyCursor wait;
1404         int                                     x                                       = _theViewPanel->GetX();
1405         int                                     y                                       = _theViewPanel->GetY();
1406         int                                     z                                       = _theViewPanel->GetZ();
1407         SegmentationOneSliceITK( x,y,z,distance, sigma, alfa, beta, propagation, iterations, inflation);
1408         RefreshInterface();
1409 }
1410
1411 void wxContourMainFrame::SegmentationOneSliceITK(int x, int y, int z, wxString distanc, wxString sigm, wxString alf, wxString bet, wxString prop, wxString iter, wxString inflation)
1412 {
1413         int typeofcontour = 1;
1414         //Image Data
1415         vtkImageData    *imagedata      = getImageData();
1416
1417         //Tipo de pixeles a utilizar internamente en ITK
1418         typedef   float  InternalPixelType;
1419         const     unsigned int    Dimension = 2;
1420         typedef itk::Image< InternalPixelType, Dimension >  InternalImageType;
1421
1422         //Tipo de pixeles de salida 1
1423         typedef unsigned char OutputPixelType;
1424         typedef itk::Image< OutputPixelType, Dimension > OutputImageType;
1425
1426         //Tipo de pixeles de salida 2
1427         typedef unsigned short OutputPixelType2;
1428         typedef itk::Image< OutputPixelType2, Dimension > OutputImageType2;
1429
1430         //DefiniciÛn del thresholder
1431         typedef itk::BinaryThresholdImageFilter<
1432                                                         InternalImageType,
1433                                                         OutputImageType    >    ThresholdingFilterType;
1434
1435         //DefiniciÛn del primer filtro de conversiÛn de pixeles
1436         typedef itk::CastImageFilter<
1437                                 OutputImageType, OutputImageType2 >  CastFilterType;
1438
1439         //DefiniciÛn del segundo tipo de conversiÛn de pixeles
1440         typedef itk::CastImageFilter<
1441                                 OutputImageType2, InternalImageType >  CastFilterType2;
1442
1443         //Tercer tipo de conversiÛn
1444         typedef itk::RescaleIntensityImageFilter<
1445                                                                 InternalImageType,
1446                                                                 OutputImageType >   CastFilterType3;
1447
1448         //Cuarto tipo de conversiÛn
1449         typedef itk::RescaleIntensityImageFilter<
1450                                                                 OutputImageType,
1451                                                                 OutputImageType >   CastFilterType4;
1452
1453         ThresholdingFilterType::Pointer thresholder = ThresholdingFilterType::New();
1454
1455         thresholder->SetLowerThreshold( 0.0 );
1456         thresholder->SetUpperThreshold( 128 );
1457
1458         thresholder->SetOutsideValue(  255  );
1459         thresholder->SetInsideValue(  0 );
1460
1461         //DefinciÛn de conexiÛnes entre VTK e ITK y el writer
1462         typedef itk::VTKImageToImageFilter<OutputImageType2> ConnectorType;
1463         typedef itk::ImageToVTKImageFilter<OutputImageType> ConnectorType2;
1464 //EED10JUIN2011 typedef  itk::ImageFileWriter<  OutputImageType  > WriterType;
1465
1466         ConnectorType::Pointer connector= ConnectorType::New();
1467         ConnectorType2::Pointer connector2= ConnectorType2::New();
1468
1469
1470         CastFilterType::Pointer filter=CastFilterType::New();
1471         CastFilterType2::Pointer filter2=CastFilterType2::New();
1472
1473         connector->SetInput( imagedata );
1474         filter2->SetInput(connector->GetOutput());
1475
1476         typedef   itk::CurvatureAnisotropicDiffusionImageFilter<
1477                                                                 InternalImageType,
1478                                                                 InternalImageType >  SmoothingFilterType;
1479
1480         SmoothingFilterType::Pointer smoothing = SmoothingFilterType::New();
1481
1482         typedef   itk::GradientMagnitudeRecursiveGaussianImageFilter<
1483                                                                 InternalImageType,
1484                                                                 InternalImageType >  GradientFilterType;
1485
1486         typedef   itk::SigmoidImageFilter<
1487                                                                 InternalImageType,
1488                                                                 InternalImageType >  SigmoidFilterType;
1489
1490         GradientFilterType::Pointer  gradientMagnitude = GradientFilterType::New();
1491
1492         SigmoidFilterType::Pointer sigmoid = SigmoidFilterType::New();
1493
1494         sigmoid->SetOutputMinimum(  0.0  );
1495         sigmoid->SetOutputMaximum(  255.0  );
1496
1497
1498         typedef  itk::FastMarchingImageFilter<
1499                                                                 InternalImageType,
1500                                                                 InternalImageType >    FastMarchingFilterType;
1501
1502
1503         FastMarchingFilterType::Pointer  fastMarching = FastMarchingFilterType::New();
1504         
1505 printf("EED wxContourMainFrame::SegmentationOneSliceITK  Skypping this code.  Not compiling   GeodesicActiveContourLevelSetImageFilter     in fedora 17 with ITK 3.20.1 \n ");
1506 /*EED 17 sept 2010
1507  > - > - > - > - > - > - > - > - > - > - > - > - > - > - > - > -   Not compiling   GeodesicActiveContourLevelSetImageFilter     in fedora 17 with ITK 3.20.1
1508  
1509  
1510         typedef  itk::GeodesicActiveContourLevelSetImageFilter< InternalImageType,
1511                                         InternalImageType >    GeodesicActiveContourFilterType;
1512         GeodesicActiveContourFilterType::Pointer geodesicActiveContour =
1513                                                                                 GeodesicActiveContourFilterType::New();
1514
1515         typedef  itk::ZeroCrossingImageFilter<
1516                                                                 InternalImageType,
1517                                                                 InternalImageType >    ZeroCrossingFilterType;
1518         ZeroCrossingFilterType::Pointer zeroCrossing =
1519                                                         ZeroCrossingFilterType::New();
1520
1521         const double propagationScaling = atof( crea::wx2std(prop).c_str() );
1522
1523         geodesicActiveContour->SetPropagationScaling( propagationScaling );
1524         geodesicActiveContour->SetCurvatureScaling( 1.0 );
1525         geodesicActiveContour->SetAdvectionScaling( 1.0 );
1526
1527         geodesicActiveContour->SetMaximumRMSError( 0.02 );
1528         int it=atoi(  crea::wx2std(iter).c_str() );
1529         geodesicActiveContour->SetNumberOfIterations( it );
1530
1531         smoothing->SetInput( filter2->GetOutput() );
1532         gradientMagnitude->SetInput( smoothing->GetOutput() );
1533         sigmoid->SetInput( gradientMagnitude->GetOutput() );
1534         fastMarching->SetInput( sigmoid->GetOutput() );
1535         geodesicActiveContour->SetInput( fastMarching->GetOutput() );
1536         geodesicActiveContour->SetFeatureImage( sigmoid->GetOutput() );
1537
1538         zeroCrossing->SetInput( geodesicActiveContour->GetOutput() );
1539         //thresholder->SetInput( zeroCrossing->GetOutput() );
1540         thresholder->SetInput( geodesicActiveContour->GetOutput() );
1541         connector2->SetInput( thresholder->GetOutput()  );
1542  
1543 < - < - < - < - < - < - < - < - < - < - < - < - < - < - < - < - < - < - < - < - 
1544 */
1545         
1546         
1547         
1548
1549         smoothing->SetTimeStep( 0.125 );
1550         smoothing->SetNumberOfIterations(  5 );
1551         smoothing->SetConductanceParameter( 9.0 );
1552
1553
1554         const double sigma = atof(  crea::wx2std(sigm).c_str() );
1555         gradientMagnitude->SetSigma(  sigma  );
1556
1557         const double alpha =  atof(  crea::wx2std(alf).c_str() );
1558         const double beta  =  atof(  crea::wx2std(bet).c_str() );
1559
1560         sigmoid->SetAlpha( alpha );
1561         sigmoid->SetBeta(  beta  );
1562
1563         typedef FastMarchingFilterType::NodeContainer  NodeContainer;
1564         typedef FastMarchingFilterType::NodeType       NodeType;
1565
1566         NodeContainer::Pointer seeds = NodeContainer::New();
1567
1568         InternalImageType::IndexType  seedPosition;
1569         seedPosition[0] = x;
1570         seedPosition[1] = y;
1571
1572         const double initialDistance = atof( crea::wx2std(distanc).c_str() );
1573
1574         NodeType node;
1575
1576         const double seedValue = - initialDistance;
1577
1578         node.SetValue( seedValue );
1579         node.SetIndex( seedPosition );
1580
1581         seeds->Initialize();
1582         seeds->InsertElement( 0, node );
1583
1584         fastMarching->SetTrialPoints( seeds );
1585
1586         fastMarching->SetSpeedConstant( 1.0 );
1587
1588         fastMarching->SetOutputSize(
1589                         connector->GetOutput()->GetBufferedRegion().GetSize() );
1590
1591         fastMarching->SetStoppingValue( 800 );
1592         try
1593     {
1594
1595         connector2->Update();
1596         vtkImageData *idata = connector2->GetOutput();
1597
1598         vtkMarchingContourFilter* cntVTK = vtkMarchingContourFilter::New( );
1599
1600         cntVTK->SetNumberOfContours( 1 );
1601         cntVTK->SetValue( 0, 255 );
1602 //EED 2017-01-01 Migration VTK7
1603 #if VTK_MAJOR_VERSION <= 5
1604         cntVTK->SetInput( idata );
1605         cntVTK->Update( );
1606         cntVTK->UpdateInformation();
1607 #else
1608         cntVTK->SetInputData( idata );
1609 #endif
1610
1611         vtkCleanPolyData* cpd = vtkCleanPolyData::New( );
1612
1613 //EED 2017-01-01 Migration VTK7
1614 #if VTK_MAJOR_VERSION <= 5
1615         cpd->SetInput( cntVTK->GetOutput( ) );
1616         cpd->Update( );
1617         cpd->UpdateInformation();
1618 #else
1619         cpd->SetInputData( cntVTK->GetOutput( ) );
1620 #endif
1621
1622
1623         vtkPolyDataConnectivityFilter* conn = vtkPolyDataConnectivityFilter::New( );
1624         conn->SetExtractionModeToLargestRegion( );
1625 //EED 2017-01-01 Migration VTK7
1626 #if VTK_MAJOR_VERSION <= 5
1627         conn->SetInput( cpd->GetOutput( ) );
1628         conn->Update( );
1629         conn->UpdateInformation();
1630 #else
1631         conn->SetInputData( cpd->GetOutput( ) );
1632 #endif
1633
1634
1635         vtkStripper* vtkstripper = vtkStripper::New( );
1636
1637 //EED 2017-01-01 Migration VTK7
1638 #if VTK_MAJOR_VERSION <= 5
1639         vtkstripper->SetInput( conn->GetOutput() );
1640         vtkstripper->Update();
1641         vtkstripper->UpdateInformation();
1642 #else
1643         vtkstripper->SetInputData( conn->GetOutput() );
1644         cntVTK->Update();
1645 #endif
1646
1647         vtkPolyData* polyDataResult =  cntVTK->GetOutput();
1648         //std::cout<<"Points "<<polyDataResult->GetNumberOfPoints()<<std::endl;
1649
1650 //EED 2017-01-01 Migration VTK7
1651 #if VTK_MAJOR_VERSION <= 5
1652         polyDataResult->Update( );
1653         polyDataResult->UpdateInformation();
1654 #else
1655         // ..
1656 #endif
1657
1658         //EED
1659                 /*
1660         ofstream myfile;
1661         myfile.open ("C:/Creatis/example.txt");
1662         myfile << "\n";
1663         polyDataResult->Print(myfile);
1664         myfile << "-------------------------------------\n";
1665         polyDataResult->GetLines()->Print(myfile);
1666         myfile.close();*/
1667
1668         cntVTK          -> Delete();
1669         cpd                     -> Delete();
1670         conn            -> Delete();
1671
1672
1673         //--Calculating control points
1674
1675         std::vector<double> vecX;
1676         std::vector<double> vecY;
1677         std::vector<double> vecXo;
1678         std::vector<double> vecYo;
1679         std::vector<double>::iterator vecXoi;
1680         std::vector<double>::iterator vecYoi;
1681         std::vector<double> vecZ;
1682
1683         std::vector<double> vecCtrlPointX;
1684         std::vector<double> vecCtrlPointY;
1685         std::vector<double> vecCtrlPointZ;
1686
1687
1688         double *p;
1689         double xAct=0;
1690         double yAct=0;
1691         int ii,size=polyDataResult->GetNumberOfPoints();
1692         ofstream myfile;
1693         myfile.open ("C:/Creatis/example2.txt");
1694
1695         size=polyDataResult->GetNumberOfPoints();
1696         for (ii=0;ii<size;ii++)
1697         {
1698                 if(ii==0)
1699                 {
1700                         xAct=x;
1701                         yAct=y;
1702                 }
1703                 p       = polyDataResult->GetPoint(ii);
1704                 double x=p[0];
1705                 double y=p[1];
1706                 /*if(fabs(yAct-y)>20)
1707                 {
1708                         if((xAct-x)>1 || (xAct-x)<-1)
1709                         {
1710                         vecX.push_back( p[0] );
1711                         vecY.push_back( p[1] );
1712                         myfile <<p[0]<<","<<p[1]<<"\n";
1713                         std::cout<<" x Anterior "<<xAct<<" x actual "<<x<<std::endl;
1714                 std::cout<<" y Anterior "<<yAct<<" y actual "<<y<<std::endl;
1715                 std::cout<<" x "<<p[0]<<" y "<<p[1]<<std::endl;
1716                         vecZ.push_back( 900 );
1717                         xAct=x;
1718                         yAct=y;
1719                         }
1720                         else
1721                         {
1722                                 vecXo.push_back(p[0]);
1723                                 vecYo.push_back(p[1]);
1724                         }
1725
1726                 }
1727                 else*/ if(fabs(xAct-x)>11)
1728                 {
1729                         vecXo.push_back(p[0]);
1730                         vecYo.push_back(p[1]);
1731                 } else {
1732                         vecX.push_back( p[0] );
1733                         myfile <<p[0]<<","<<p[1]<<"\n";
1734                         //std::cout<<" x Anterior "<<xAct<<" x actual "<<x<<std::endl;
1735                         //std::cout<<" y Anterior "<<yAct<<" y actual "<<y<<std::endl;
1736                         //std::cout<<" x "<<p[0]<<" y "<<p[1]<<std::endl;
1737                         vecY.push_back( p[1] );
1738 //EED 2017-12-16
1739                         vecZ.push_back( -900 );
1740                         xAct = x;
1741                         yAct = y;
1742                 } // if xAct
1743
1744
1745         }
1746
1747         while(!vecXo.empty())
1748         {
1749                 vecX.push_back(vecXo.back());
1750                 //std::cout<<" x Siguiente "<<vecXo.back();
1751                 vecXo.pop_back();
1752 //EED 2017-12-16
1753                 vecZ.push_back( -900 );
1754         }
1755         while(!vecYo.empty())
1756         {
1757                 vecY.push_back(vecYo.back());
1758                         vecYo.pop_back();
1759         }
1760         myfile.close();
1761
1762         /*for(int l=0;l<vecX.size();l++)
1763         {
1764                 if(l==0)
1765                 {
1766             vecXo.push_back(p[0]);
1767                         vecYo.push_back(p[1]);
1768                 }
1769                 else
1770                 {
1771                         if(vecXoi[l-1]==)
1772                         {
1773                         }
1774                 }
1775
1776         }*/
1777
1778         ExtractControlPoints2D *extractcontrolpoints2d = new ExtractControlPoints2D();
1779
1780         extractcontrolpoints2d->SetContour( &vecX , &vecY , &vecZ );
1781
1782         int method=2;
1783         if (method==0){
1784                 extractcontrolpoints2d->GetInitialControlPoints( &vecCtrlPointX , &vecCtrlPointY , &vecCtrlPointZ );
1785         }
1786         else if (method==1){
1787                 extractcontrolpoints2d->GetControlPoints(  &vecCtrlPointX , &vecCtrlPointY , &vecCtrlPointZ );
1788         }
1789         else if (method==2){
1790                 extractcontrolpoints2d->SetSamplingControlPoints( 15 );
1791                 extractcontrolpoints2d->GetSamplingControlPoints(  &vecCtrlPointX , &vecCtrlPointY , &vecCtrlPointZ );
1792         }
1793         //--Adding contour to the system
1794
1795         std::vector<int> actualInstantVector;
1796         _instantPanel->getInstant( actualInstantVector );
1797         actualInstantVector[1]=z;
1798
1799         int j,sizeCtrPt = vecCtrlPointX.size();
1800
1801         manualBaseModel *manModelContour =  kernelManager->factoryManualContourModel( typeofcontour );
1802         manModelContour->SetNumberOfPointsSpline( ((sizeCtrPt/100)+1)*100 );
1803         if (sizeCtrPt>=3){
1804                 for (j=0 ; j<sizeCtrPt ; j++)
1805                 {
1806                         manModelContour->AddPoint( vecCtrlPointX[j] , vecCtrlPointY[j] , vecCtrlPointZ[j]  );
1807                 } // for
1808                 std::string theName;
1809                 //theName = _modelManager->createOutline( manModelContour, actualInstantVector );
1810                 theName = kernelManager->createOutline( manModelContour, actualInstantVector );
1811                 bool addedModel = theName.compare("") != 0;
1812                 if( addedModel )
1813                 {
1814                         double spc[3];//Si no hay imagen pero hay contornos que spacing se pone por default
1815                         _theViewPanel->getSpacing(spc);
1816                         //Adding the manualContourControler to interface objects structure
1817                         //Adding the manualViewContour to interface objects structure
1818                         //_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.
1819                         _theViewPanel->configureViewControlTo(theName, manModelContour, spc, typeofcontour);
1820                         //_theViewPanel->getSceneManager()->configureViewControlTo( theName, manModelContour,spc, typeofcontour ) ;
1821                 }       // if addedModel
1822         } // if sizeCtrPt
1823
1824
1825 /*
1826 //EED10JUIN2011
1827                  WriterType::Pointer writer = WriterType::New();
1828          CastFilterType3::Pointer caster = CastFilterType3::New();
1829
1830                  caster->SetInput( gradientMagnitude->GetOutput() );
1831                  writer->SetInput( caster->GetOutput() );
1832                  writer->SetFileName("Gradient Magnitude.png");
1833                  caster->SetOutputMinimum(   0 );
1834                  caster->SetOutputMaximum( 255 );
1835                  writer->Update();
1836
1837                  CastFilterType3::Pointer caster2 = CastFilterType3::New();
1838                  WriterType::Pointer writer2 = WriterType::New();
1839
1840                  caster2->SetInput( sigmoid->GetOutput() );
1841                  writer2->SetInput( caster2->GetOutput() );
1842                  writer2->SetFileName("Sigmoid.png");
1843                  caster2->SetOutputMinimum(   0 );
1844                  caster2->SetOutputMaximum( 255 );
1845                  writer2->Update();
1846
1847                  CastFilterType3::Pointer caster3 = CastFilterType3::New();
1848                  WriterType::Pointer writer3 = WriterType::New();
1849
1850                  caster3->SetInput( fastMarching->GetOutput() );
1851                  writer3->SetInput( caster3->GetOutput() );
1852                  writer3->SetFileName("FastMarching.bmp");
1853                  caster3->SetOutputMinimum(   0 );
1854                  caster3->SetOutputMaximum( 255 );
1855                  writer3->Update();
1856
1857                  CastFilterType3::Pointer caster4 = CastFilterType3::New();
1858                  WriterType::Pointer writer4 = WriterType::New();
1859
1860                  caster4->SetInput( geodesicActiveContour->GetOutput() );
1861                  writer4->SetInput( caster4->GetOutput() );
1862                  writer4->SetFileName("GeodesicActiveContour.png");
1863                  caster4->SetOutputMinimum(   0 );
1864                  caster4->SetOutputMaximum( 255 );
1865                  writer4->Update();
1866
1867                  CastFilterType3::Pointer caster5 = CastFilterType3::New();
1868                  WriterType::Pointer writer5 = WriterType::New();
1869
1870                  caster5->SetInput( zeroCrossing->GetOutput() );
1871                  writer5->SetInput( caster5->GetOutput() );
1872                  writer5->SetFileName("ZeroCrossing.bmp");
1873                  caster5->SetOutputMinimum(   0 );
1874                  caster5->SetOutputMaximum( 255 );
1875                  writer5->Update();
1876 */
1877     }
1878   catch( itk::ExceptionObject & excep )
1879     {
1880     std::cerr << "Exception caught !" << std::endl;
1881     std::cerr << excep << std::endl;
1882     }
1883 }
1884
1885 void wxContourMainFrame::onSegmentationOneSlice(int isovalue,int sampling,int method){
1886
1887         //JCP 20-10-08 Undo redo implementation
1888         saveState();
1889         //JCP 20-10-08 Undo redo implementation
1890
1891         wxBusyCursor wait;
1892         int                                     x                                       = _theViewPanel->GetX();
1893         int                                     y                                       = _theViewPanel->GetY();
1894         int                                     z                                       = _theViewPanel->GetZ();
1895         SegmentationOneSlice( x,y,z,isovalue, sampling, method );
1896         RefreshInterface();
1897 }
1898
1899
1900 void wxContourMainFrame::SegmentationOneSlice( int x, int y, int z, int isovalue, int sampling, int method )
1901 {
1902         int typeofcontour = 1;
1903         //--Extracting Contour
1904         vtkImageData    *imagedata      = getImageData();
1905
1906         vtkImageReslice *imageReslice = vtkImageReslice::New();
1907 //EED
1908                 double spc[3];
1909                 imagedata->GetSpacing(spc);
1910                 x = x*spc[0];
1911                 y = y*spc[1];
1912                 z = z;
1913
1914 //EED 2017-01-01 Migration VTK7
1915 #if VTK_MAJOR_VERSION <= 5
1916         imageReslice->SetInput( imagedata );
1917 #else
1918         imageReslice->SetInputData( imagedata );
1919 #endif
1920         imageReslice->SetInformationInput(imagedata);
1921         imageReslice->SetResliceAxesDirectionCosines(1,0,0, 0,1,0 ,0,0,1);
1922         imageReslice->SetResliceAxesOrigin(0,0,z*spc[2]);
1923         imageReslice->SetOutputDimensionality(2);
1924         imageReslice->SetInterpolationModeToLinear();
1925
1926 //EED 2017-01-01 Migration VTK7
1927 #if VTK_MAJOR_VERSION <= 5
1928         // ..
1929 #else
1930         imageReslice->Update();
1931 #endif
1932
1933         imagedata = imageReslice->GetOutput();
1934 //EED 2017-01-01 Migration VTK7
1935 #if VTK_MAJOR_VERSION <= 5
1936         imagedata->Update();
1937         imagedata->UpdateInformation();
1938 #else
1939         // ..
1940 #endif
1941
1942         vtkContourFilter* cntVTK = vtkContourFilter::New( );
1943 //EED 2017-01-01 Migration VTK7
1944 #if VTK_MAJOR_VERSION <= 5
1945         cntVTK->SetInput( imagedata );
1946 #else
1947         cntVTK->SetInputData( imagedata );
1948 #endif
1949
1950         cntVTK->SetNumberOfContours( 1 );
1951         //cntVTK->SetValue( 0, vmin );
1952 //              cntVTK->SetValue( 0, (range[1]*thr/100) );
1953         cntVTK->SetValue( 1, isovalue );
1954 //      cntVTK->SetValue( 1, vmax );
1955         cntVTK->Update( );
1956         cntVTK->UpdateInformation();
1957
1958         vtkCleanPolyData* cpd = vtkCleanPolyData::New( );
1959 //EED 2017-01-01 Migration VTK7
1960 #if VTK_MAJOR_VERSION <= 5
1961         cpd->SetInput( cntVTK->GetOutput( ) );
1962 #else
1963         cpd->SetInputData( cntVTK->GetOutput( ) );
1964 #endif
1965         cpd->ConvertLinesToPointsOff( );
1966         cpd->Update( );
1967         cpd->UpdateInformation();
1968
1969         vtkPolyDataConnectivityFilter* conn = vtkPolyDataConnectivityFilter::New( );
1970
1971 //      conn->SetExtractionModeToPointSeededRegions();
1972 //      conn->SetExtractionModeToCellSeededRegions();
1973 //      conn->SetExtractionModeToSpecifiedRegions();
1974 //      conn->SetExtractionModeToLargestRegion();
1975 //      conn->SetExtractionModeToAllRegions();
1976
1977         conn->SetExtractionModeToClosestPointRegion();
1978
1979         //conn->SetMaxRecursionDepth( 3000 );
1980
1981 //EED 2017-01-01 Migration VTK7
1982 #if VTK_MAJOR_VERSION <= 5
1983         conn->SetInput( cpd->GetOutput( ) );
1984 #else
1985         conn->SetInputData( cpd->GetOutput( ) );
1986 #endif
1987
1988         conn->SetClosestPoint( x, y, 0 );
1989         conn->Update( );
1990         conn->UpdateInformation();
1991
1992         vtkCleanPolyData* cpd2 = vtkCleanPolyData::New( );
1993 //EED 2017-01-01 Migration VTK7
1994 #if VTK_MAJOR_VERSION <= 5
1995         cpd2->SetInput( conn->GetOutput( ) );
1996 #else
1997         cpd2->SetInputData( conn->GetOutput( ) );
1998 #endif
1999         cpd2->Update();
2000         cpd2->UpdateInformation();
2001
2002         vtkStripper* vtkstripper = vtkStripper::New( );
2003 vtkstripper->SetJoinContiguousSegments(true);
2004         vtkstripper->SetMaximumLength(20000);
2005 //EED 2017-01-01 Migration VTK7
2006 #if VTK_MAJOR_VERSION <= 5
2007         vtkstripper->SetInput( cpd2->GetOutput() );
2008 #else
2009         vtkstripper->SetInputData( cpd2->GetOutput() );
2010 //      vtkstripper->SetInputData( cntVTK->GetOutput() );
2011
2012 #endif
2013         vtkstripper->Update();
2014         vtkstripper->UpdateInformation();
2015
2016
2017         vtkPolyData* polyDataResult =  vtkstripper->GetOutput();
2018
2019 //EED 2017-01-01 Migration VTK7
2020 #if VTK_MAJOR_VERSION <= 5
2021         polyDataResult->Update( );
2022         polyDataResult->UpdateInformation();
2023 #else
2024         //...
2025 #endif
2026
2027 /* EED
2028 ofstream myfile;
2029 myfile.open ("c:/temp/example.txt");
2030 myfile << "\n";
2031 polyDataResult->Print(myfile);
2032 myfile << "-------------------------------------\n";
2033 polyDataResult->GetLines()->Print(myfile);
2034 myfile.close();
2035 */
2036         cntVTK  -> Delete();
2037         cpd2    -> Delete();
2038         cpd             -> Delete();
2039         conn    -> Delete();
2040
2041 //--Calculating control points
2042         std::vector<double> vecX;
2043         std::vector<double> vecY;
2044         std::vector<double> vecZ;
2045         std::vector<double> vecCtrlPointX;
2046         std::vector<double> vecCtrlPointY;
2047         std::vector<double> vecCtrlPointZ;
2048
2049 printf("EED wxContourMainFrame::SegmentationOneSlice GetNumberOfLines=%d \n",polyDataResult->GetNumberOfLines() );
2050
2051 int numberOfPointsInCell;
2052 int numberOfcells=polyDataResult->GetNumberOfCells();
2053 for (int jj=0; jj<numberOfcells ; jj++)
2054 {
2055         vtkCell* vtkcell = polyDataResult->GetCell( jj );
2056         numberOfPointsInCell=vtkcell->GetNumberOfPoints();
2057         printf("EED wxContourMainFrame::SegmentationOneSlice cell=%d  points=%d \n",jj,numberOfPointsInCell );
2058 }// for jj
2059
2060 printf("EED wxContourMainFrame::SegmentationOneSlice PrintSelf \n");
2061
2062 polyDataResult->PrintSelf( std::cout, vtkIndent(0) );
2063
2064
2065         if (polyDataResult->GetNumberOfCells()>0)
2066         {
2067                 double *p;
2068         printf("EED wxContourMainFrame::SegmentationOneSlice A \n");
2069                 vtkCell* vtkcell = polyDataResult->GetCell( 0 );
2070         printf("EED wxContourMainFrame::SegmentationOneSlice B \n");
2071         //      int ii,size=polyDataResult->GetNumberOfPoints();
2072                 int ii,size=vtkcell->GetNumberOfPoints();
2073         printf("EED wxContourMainFrame::SegmentationOneSlice C \n");
2074                 int id;
2075                 for (ii=1;ii<=size;ii++)
2076                 {
2077         //              id      = polyDataResult->GetLines()->GetData()->GetValue(ii);
2078         //              p       = polyDataResult->GetPoint(id);
2079                         p       = vtkcell->GetPoints()->GetPoint(ii);
2080
2081         printf("EED wxContourMainFrame::SegmentationOneSlice (%d) id=%d  px=%f py=%f\n",ii,id, p[0],p[1]);
2082         //              double x=p[0];
2083         //              double y=p[1];
2084                         vecX.push_back( p[0] );
2085                         vecY.push_back( p[1] );
2086         //EED 2017-12-16
2087                         vecZ.push_back( -900 );
2088         //                      vecZ.push_back( p[2] );
2089                 }
2090
2091                 ExtractControlPoints2D *extractcontrolpoints2d = new ExtractControlPoints2D();
2092                 extractcontrolpoints2d->SetContour( &vecX , &vecY , &vecZ );
2093
2094         //PROOFS
2095                 /*if (methodRadiobox->GetSelection()==0){
2096                         extractcontrolpoints2d->GetInitialControlPoints( &vecCtrlPointX , &vecCtrlPointY , &vecCtrlPointZ );
2097                 }
2098                 if (methodRadiobox->GetSelection()==1){
2099                         extractcontrolpoints2d->GetControlPoints(  &vecCtrlPointX , &vecCtrlPointY , &vecCtrlPointZ );
2100                 }
2101                 if (methodRadiobox->GetSelection()==2){
2102                         extractcontrolpoints2d->SetSamplingControlPoints( sampling );
2103                         extractcontrolpoints2d->GetSamplingControlPoints(  &vecCtrlPointX , &vecCtrlPointY , &vecCtrlPointZ );
2104                 }*/
2105
2106                 if (method==0)
2107                 {
2108                         extractcontrolpoints2d->GetInitialControlPoints( &vecCtrlPointX , &vecCtrlPointY , &vecCtrlPointZ );
2109                 } else if (method==1){
2110                         extractcontrolpoints2d->GetControlPoints(  &vecCtrlPointX , &vecCtrlPointY , &vecCtrlPointZ );
2111                 } else if (method==2){
2112                         extractcontrolpoints2d->SetSamplingControlPoints( sampling );
2113                         extractcontrolpoints2d->GetSamplingControlPoints(  &vecCtrlPointX , &vecCtrlPointY , &vecCtrlPointZ );
2114                 }
2115
2116                 //--Adding contour to the system
2117                 std::vector<int> actualInstantVector;
2118                 _instantPanel->getInstant( actualInstantVector );
2119                 actualInstantVector[1]=z;
2120
2121                 int j,sizeCtrPt = vecCtrlPointX.size();
2122                 manualBaseModel *manModelContour =  kernelManager->factoryManualContourModel( typeofcontour );
2123                 manModelContour->SetNumberOfPointsSpline( ((sizeCtrPt/100)+1)*100 *2 );
2124                 manModelContour->SetLabel2( std::to_string(z) );
2125                 if (sizeCtrPt>=3)
2126                 {
2127                         for (j=0 ; j<sizeCtrPt ; j++)
2128                         {
2129                                 manModelContour->AddPoint( vecCtrlPointX[j] / spc[0], vecCtrlPointY[j] / spc[1], vecCtrlPointZ[j] );
2130                         } // for
2131                         std::string theName;
2132                         //theName = _modelManager->createOutline( manModelContour, actualInstantVector );
2133                         theName = kernelManager->createOutline( manModelContour, actualInstantVector );
2134                         bool addedModel = theName.compare("") != 0;
2135                         if( addedModel )
2136                         {
2137                                 double spc[3];//Si no hay imagen pero hay contornos que spacing se pone por default
2138                                 _theViewPanel->getSpacing(spc);
2139                                 //Adding the manualContourControler to interface objects structure
2140                                 //Adding the manualViewContour to interface objects structure
2141                                 //_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.
2142                                 _theViewPanel->configureViewControlTo(theName, manModelContour, spc, typeofcontour);
2143                                 //_theViewPanel->getSceneManager()->configureViewControlTo( theName, manModelContour,spc, typeofcontour ) ;
2144                         }       // if addedModel
2145                 } // if sizeCtrPt
2146         } // if NumberOfCells > 0
2147
2148 printf("EED wxContourMainFrame::SegmentationOneSlice  End\n");
2149 }
2150
2151 int wxContourMainFrame::GetImageDataSizeZ()
2152 {
2153         return _theViewPanel->GetImageDataSizeZ();
2154 }
2155
2156 void wxContourMainFrame::GetImageDataRange(double *range)
2157 {
2158         _theViewPanel->GetImageDataRange(range);
2159 }
2160
2161 void wxContourMainFrame::onSegmentationAllSlice(int minZ,int maxZ,int isovalue,int sampling,int method)
2162 {
2163         //JCP 20-10-08 Undo redo implementation
2164         saveState();
2165         //JCP 20-10-08 Undo redo implementation
2166
2167         wxBusyCursor wait;
2168         int                                     x = _theViewPanel->GetX();
2169         int                                     y = _theViewPanel->GetY();
2170         int                             z;
2171         double                          porcent;
2172         wxString                        tmpString;
2173         double                          totalZ = maxZ-minZ+1;
2174         for( z=minZ ; z<=maxZ ; z++ )
2175         {
2176                 porcent = 100.0* (z-minZ)/totalZ;
2177                 tmpString.Printf(_T("  %d %c            %d/%d            %d"), (int)porcent , 37 , z-minZ+1, (int)totalZ,z );
2178                 interfMainPanel::getInstance()->setLabelSegmentationPanelVTK(tmpString);
2179                 //_staticTextSegmentation->SetLabel(tmpString);
2180                 SegmentationOneSlice( x,y,z,isovalue, sampling,method );
2181         }
2182         interfMainPanel::getInstance()->setLabelSegmentationPanelVTK(_T("   "));
2183         RefreshInterface();
2184 }
2185
2186
2187 //Creates a reference line to be used as the axis of the mirroring
2188 void wxContourMainFrame::referenceLine()
2189 {
2190         if (_refLineControl==NULL)
2191         {
2192                 wxBusyCursor wait;
2193                 double spc[3];
2194
2195                 vtkImageData *vtkimagedata = _theViewPanel->getImageData();
2196                 vtkimagedata->GetSpacing(spc);
2197
2198                 wxVtkBaseView * viewer2D = _theViewPanel->getWxVtkBaseView();
2199
2200                 _refLineControl = new manualLineControler();
2201                 _refLineModel   = new manualContourModelLine();
2202                 _refLineView = new manualViewLine();
2203                 _refLineView->SetModel( _refLineModel );
2204                 _refLineView->SetWxVtkBaseView( viewer2D );
2205                 _refLineView->SetRange( 2 );
2206                 _refLineView->SetZ( 1200 );
2207
2208                 _refLineView->SetSpacing(spc);
2209
2210                 _refLineView->SetColorNormalContour(0, 0, 1);
2211                 _refLineView->SetColorEditContour(0, 0.5, 0.5);
2212                 _refLineView->SetWidthLine(4);
2213
2214                 _refLineControl->SetModelView( _refLineModel , _refLineView );
2215                 vtkInteractorStyleBaseView* style = (vtkInteractorStyleBaseView*)viewer2D->GetInteractorStyleBaseView();
2216                 style->AddInteractorStyleMaracas( _refLineControl );
2217                 _refLineModel->SetCloseContour(false);
2218                 _refLineControl->CreateNewManualContour();
2219
2220 //AD: Inicializar el mirroring con una linea ya pintada
2221         /*
2222                 double z = _refLineControl->GetZ();
2223
2224                 int imageDim[3];
2225                 image->GetDimensions(imageDim);
2226                 double x = (double) imageDim[0]/2;
2227                 double y1 = (double) (imageDim[1]/2)+15;
2228                 double y2 = (double) (imageDim[1]/2)-15;
2229
2230                 _refLineControl->AddPoint(x,y1,z);
2231                 _refLineControl->AddPoint(x,y2,z);
2232                 _refLineControl->SetCompleteCreation(true);
2233
2234                 _refLineModel->AddPoint(x,y1,z);
2235                 _refLineModel->AddPoint(x,y2,z);
2236                 _refLineModel->UpdateSpline();
2237
2238                 _refLineView->UpdateViewPoint(0);
2239                 _refLineView->UpdateViewPoint(1);
2240         */
2241
2242                 _refLineControl->SetActive(true);
2243                 _refLineView->RefreshContour();
2244         }
2245 }
2246
2247 //Hides the referenceLine
2248 void wxContourMainFrame::refLineHide()
2249 {
2250         if (_refLineControl!=NULL)
2251         {
2252                 if (_refLineControl->GetActive())
2253                 {
2254                         _refLineView->RemoveCompleteContourActor();
2255                         _refLineControl->SetEditable(false);
2256                         _refLineControl->SetActive(false);
2257
2258                         RefreshInterface();
2259                 }
2260         }
2261 }
2262
2263 //Shows the referenceLine
2264 void wxContourMainFrame::refLineShow()
2265 {
2266         if (_refLineControl!=NULL)
2267         {
2268                 if (_refLineControl->GetActive()==false)
2269                 {
2270                         wxVtkBaseView * viewer2D = _theViewPanel->getWxVtkBaseView();
2271
2272                         _refLineView->SetModel( _refLineModel );
2273                         _refLineView->SetWxVtkBaseView( viewer2D );
2274                         _refLineView->SetRange( 2 );
2275                         _refLineView->SetZ( 1200 );
2276
2277                         _refLineControl->SetModelView( _refLineModel , _refLineView );
2278                         vtkInteractorStyleBaseView* style = (vtkInteractorStyleBaseView*)viewer2D->GetInteractorStyleBaseView();
2279                         style->AddInteractorStyleMaracas( _refLineControl );
2280                         _refLineControl->CreateNewManualContour();
2281                         _refLineControl->SetActive(true);
2282                         _refLineView->RefreshContour();
2283
2284                         RefreshInterface();
2285                 }
2286         }
2287 }
2288
2289 void wxContourMainFrame::refLineChangeWidth(int width)
2290 {
2291         _refLineView->SetWidthLine(width);
2292         _refLineView->RefreshContour();
2293
2294         RefreshInterface();
2295 }
2296
2297
2298 void wxContourMainFrame::onMirror()
2299 {
2300         //AD:02-09
2301         std::vector<std::string> currentSelection = _theViewPanel->getSelectedObjects();
2302         std::vector<std::string> filterCurrentSelection;
2303
2304         std::vector<int> tempVector;
2305         _instantPanel->getInstant( tempVector );
2306     _performingOperation->reset();
2307         _performingOperation->setStartCommand( COPY );
2308         _performingOperation->setStartOperationInstantVector( tempVector );
2309         _performingOperation->setKeyNamesOperationElems( currentSelection );
2310
2311         char theStartCommand = _performingOperation->getStartCommand();
2312         if (  theStartCommand == COPY )
2313         {
2314                 //JCP 20-10-08 Undo redo implementation
2315                 saveState();
2316                 //JCP 20-10-08 Undo redo implementation
2317                 std::vector<int> tempVector;
2318                 _instantPanel->getInstant( tempVector );
2319                 _performingOperation->setEndOperationInstantVector ( tempVector );
2320                 std::vector<std::string> elems = _performingOperation->getKeyNamesOperationElems();
2321                 int i,size = elems.size();
2322                 for( i=0; i<size; i++ )
2323                 {
2324                         createMirrorContourOf( elems[i], tempVector, i>0 );
2325                 }
2326         }
2327
2328         //deleteContour( _refName );
2329         //_refName = "";
2330 }
2331
2332
2333 void wxContourMainFrame::showAxis(bool show)
2334 {
2335         _theViewPanel->SetVisibleAxis(show);
2336         _theViewPanel->Refresh();
2337 }
2338
2339
2340 void wxContourMainFrame::onRigidPressed(){
2341         std::vector<std::string> currentSelection = _theViewPanel->getSelectedObjects();
2342         int elementsSelected = currentSelection.size();
2343
2344         if ( elementsSelected >= 1 ){
2345                 //JCP 20-10-08 Undo redo implementation
2346                 saveState();
2347                 //JCP 20-10-08 Undo redo implementation
2348
2349                 std::vector<int> tempVector;
2350                 _instantPanel->getInstant( tempVector );
2351                 Instant instant(&tempVector);
2352
2353                 int i , size=currentSelection.size();
2354                 for ( i=0 ; i<size ; i++ )
2355                 {
2356                         kernelManager->changeContourOfManager(currentSelection[i], &instant);
2357                 } // i
2358         }
2359 }
2360
2361 void wxContourMainFrame::onWidthOfContour(double width){
2362
2363         _theViewPanel->removeSceneContours();
2364         _theViewPanel->SetWidthContour(width);
2365
2366         //_theViewPanel->getSceneManager()->SetWidthContour( width );
2367
2368         RefreshInterface();
2369 }
2370
2371 int wxContourMainFrame::getColorWindow()
2372 {
2373         /*
2374         double range[2];
2375         vtkImageData * img = getImageData();
2376         img->GetScalarRange(range);
2377
2378         std::cout<<"Val 1: "<<range[0]<<" Val 2: "<<range[1]<<std::endl;
2379
2380         return (int)range[1];
2381         */
2382         return _theViewPanel->getColorWindow();
2383 }
2384
2385 int wxContourMainFrame::getWindowLevel()
2386 {
2387         /*
2388         double range[2];
2389         vtkImageData * img = getImageData();
2390         img->GetScalarRange(range);
2391
2392         std::cout<<"Val 1: "<<range[0]<<" Val 2: "<<range[1]<<std::endl;
2393
2394         return (int)range[1];
2395         */
2396         return _theViewPanel->getWindowLevel();
2397 }
2398
2399 void wxContourMainFrame::onBrigthnessColorWindowLevel(int colorwindow,int windowlevel)
2400 {
2401         _theViewPanel->onBrigthnessColorWindowLevel(colorwindow, windowlevel);
2402
2403         RefreshInterface();
2404 }
2405
2406 void wxContourMainFrame::onInterpolation(bool interpolate)
2407 {
2408         _theViewPanel->onInterpolation(interpolate);
2409         RefreshInterface();
2410 }
2411
2412 void wxContourMainFrame::onBeforeAfterContour(bool before,bool after)
2413 {
2414         _theViewPanel->onBeforeAfterContour(before,after);
2415         RefreshInterface();
2416 }
2417
2418 void wxContourMainFrame::onShowTextContour(bool show)
2419 {
2420         _theViewPanel->onShowTextContour(show);
2421         RefreshInterface();
2422 }
2423
2424 void wxContourMainFrame::onChangeInstant(std::string name,int actual)
2425 {
2426         _instantPanel->setConceptValue( name, actual );
2427 }
2428
2429 void wxContourMainFrame::resetAppend()
2430 {
2431         kernelManager->resetAppend();
2432 }
2433
2434 void wxContourMainFrame::onSpreadAdd()
2435 {
2436         std::vector<double> vecX;
2437         std::vector<double> vecY;
2438         std::vector<double> vecZ;
2439         _theViewPanel->GetPointsOfActualContour(&vecX , &vecY , &vecZ );
2440         std::vector<int> tempVector;
2441         _instantPanel->getInstant( tempVector );
2442         std::string val = kernelManager->onSpreadAdd(&vecX , &vecY , &vecZ, tempVector);
2443         interfMainPanel::getInstance()->appendStringSpread(val);
2444 }
2445
2446
2447 void wxContourMainFrame::onSpreadAddAll()
2448 {
2449 //EED02
2450         std::vector<int> tempVector;
2451         _instantPanel->getInstant( tempVector );
2452         int minZ,maxZ;
2453     minZ        = 0;
2454     maxZ        = interfMainPanel::getInstance()->GetImageDataSizeZ();
2455         int z;
2456         int sizeLstContourThings;
2457         for ( z=minZ ; z<=maxZ ; z++ )
2458         {
2459                 tempVector[1]=z;
2460                 Instant instant(&tempVector);
2461                 std::vector<ContourThing**> lstContourThings = kernelManager->getOutlinesAtInstant( &instant );
2462                 sizeLstContourThings = lstContourThings.size();
2463                 if (sizeLstContourThings>=1)
2464         {
2465             std::vector<double> vecX;
2466             std::vector<double> vecY;
2467             std::vector<double> vecZ;
2468             ContourThing **contourthing = lstContourThings[0];
2469                         manualBaseModel *cModel                         =  (*contourthing)->getModel();
2470                         int i,size = cModel->GetNumberOfPointsSpline();
2471                         double x,y,z;
2472                         for (i=0; i<size; i++)
2473                         {
2474                                 cModel->GetSpline_i_Point(i, &x, &y, &z);
2475                                 vecX.push_back(x);
2476                                 vecY.push_back(y);
2477                                 vecZ.push_back(z);
2478                         } // for i
2479             std::string val = kernelManager->onSpreadAdd(&vecX , &vecY , &vecZ, tempVector);
2480             interfMainPanel::getInstance()->appendStringSpread(val);
2481         }// if sizeLstContourThings
2482     } // for z
2483 }
2484
2485
2486 void wxContourMainFrame::onSpreadGo(int type)
2487 {
2488         //JCP 20-10-08 Undo redo implementation
2489         saveState();
2490         //JCP 20-10-08 Undo redo implementation
2491         wxBusyCursor wait;
2492         std::vector<double> vecCtrlPointX;
2493         std::vector<double> vecCtrlPointY;
2494         std::vector<double> vecCtrlPointZ;
2495         double  minZ,maxZ;
2496         int z;
2497
2498         std::vector<int> tempVector;
2499         _instantPanel->getInstant( tempVector );
2500 //              tempVector[1];
2501
2502         kernelManager->getMaxMinZ(&minZ,&maxZ);
2503 //JSTG_16-07-08_----------------------------------------------------------------
2504         //_contourPropagation->setInterpolationNumber(maxZ-minZ+1);
2505         kernelManager->CalculeSplinePropagation();
2506
2507         double          totalZ = maxZ-minZ+1;
2508         double          porcent;
2509         wxString        tmpString;
2510 //--------------------------------------------------------------------
2511         for ( z=(int)minZ ; z<=(int)maxZ ; z++ )
2512         {
2513                 porcent = 100.0* (z-minZ)/totalZ;
2514                 int numero = (int)(z-minZ+1)/(int)totalZ;
2515                 std::string stringtemp = "  "+kernelManager->intToString(porcent)+"%            "+kernelManager->intToString(numero)+"            "+kernelManager->intToString(z);
2516
2517                 interfMainPanel::getInstance()->setStringSpread(stringtemp);
2518
2519                 int typeofcontour = 1;
2520                 std::string theName;
2521                 manualBaseModel* manModelContour = kernelManager->GetPoints(z, type, &vecCtrlPointX,&vecCtrlPointY,&vecCtrlPointZ, theName,typeofcontour, tempVector);
2522
2523                 if( manModelContour!=NULL ){
2524                         double spc[3];//Si no hay imagen pero hay contornos que spacing se pone por default
2525                         this->_theViewPanel->getSpacing(spc);
2526                         //Adding the manualContourControler to interface objects structure
2527                         //Adding the manualViewContour to interface objects structure
2528                         //_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.
2529                         _theViewPanel->configureViewControlTo( theName, manModelContour,spc,typeofcontour ) ;
2530                 } // if addedModel
2531         }
2532         if(z > maxZ){
2533                 porcent = 100.0;
2534                 int numero = (int)(z-minZ+1)/(int)totalZ;
2535                 std::string stringtemp = "  "+kernelManager->intToString(porcent)+"%            "+kernelManager->intToString(numero)+"            "+kernelManager->intToString(z);
2536
2537                 interfMainPanel::getInstance()->setStringSpread(stringtemp);
2538         }// for z
2539         //RefreshInterface();
2540 }
2541
2542 void wxContourMainFrame::getInstantVector(std::vector<int>& tempVector)
2543 {
2544         _instantPanel->getInstant( tempVector );
2545 }
2546
2547 std::vector<std::string> wxContourMainFrame::getOutlinesName(int slide)
2548 {
2549         std::vector<int> tempVector;
2550         _instantPanel->getInstant(tempVector);
2551         //Asignation of slide number should be different ex by name
2552         tempVector[1]=slide;
2553         return kernelManager->getOutlinesNameAtInstant(tempVector);
2554 }
2555
2556
2557 void wxContourMainFrame::SetScalarRange(int grayRangeMin, int grayRangeMax)
2558 {
2559         _contourextractdata->SetScalarRange(grayRangeMin,grayRangeMax);
2560 }
2561
2562
2563 void wxContourMainFrame::onInformationContourLabels(int typeContourGroup,int selection,int minimumZ,int maximumZ,int grayRangeMin, int grayRangeMax)
2564 {
2565
2566         wxString tempString;
2567         int maxContourGroup     =       0;
2568
2569         _contourextractdata ->SetTypeOperation( typeContourGroup % 3 );
2570
2571         std::vector<manualBaseModel*> lstManConMod;
2572         std::vector<manualBaseModel*> lstManConModTmp;
2573         std::vector<manualBaseModel*> lstManConModExp;
2574         std::vector<double> pLstValue;
2575         std::vector<double> pLstValuePosX;
2576         std::vector<double> pLstValuePosY;
2577         std::vector<double> pLstValuePosZ;
2578
2579         int             resultSize;
2580         int             resultGrayRangeCount;
2581         double  resultMin;
2582         double  resultMax;
2583         double  resultAverage;
2584         double  resultStandardeviation;
2585
2586         std::vector<int> tempVector;
2587         _instantPanel->getInstant( tempVector );
2588
2589         int z;
2590         int ii,sizeLstContourThings;
2591
2592
2593         int minZ,maxZ;
2594         double totalZ;
2595         double porcent;
2596         wxString tmpString;
2597
2598
2599         if (selection==0 ) // actual slice
2600         {
2601                 int actualSlice = tempVector[1];
2602                 minZ    = actualSlice;
2603                 maxZ    = actualSlice;
2604         }       else  {  // slice range
2605                 minZ    = minimumZ;
2606                 maxZ    = maximumZ;
2607         }
2608
2609
2610         totalZ  = maxZ-minZ+1;
2611
2612         _contourextractdata->InitVolumeStatistics();
2613
2614 // For each slice..
2615         for ( z=minZ ; z<=maxZ ; z++ )
2616         {
2617
2618                 porcent = 100.0* (z-minZ)/totalZ;
2619                 tmpString.Printf(_T("  %d %c            %d/%d             %d"), (int)porcent , 37 , z-minZ+1, (int)totalZ ,z);
2620
2621                 interfMainPanel::getInstance()->setStringInfoPanel(tmpString);
2622                 //_staticTextInformation->SetLabel(tmpString);
2623
2624                 //Extraction data from contours of each slice
2625                 _contourextractdata->SetZtoBeAnalys(z);
2626
2627                 tempVector[1]=z;
2628                 Instant instant(&tempVector);
2629                 std::vector<ContourThing**> lstContourThings = kernelManager->getOutlinesAtInstant( &instant );
2630                 sizeLstContourThings = lstContourThings.size();
2631
2632                 lstManConMod.clear();
2633                 for (ii=0 ; ii<sizeLstContourThings ; ii++)
2634                 {
2635                         ContourThing **contourthing = lstContourThings[ii];
2636                         lstManConMod.push_back( (*contourthing)->getModel() );
2637                 }
2638
2639                 lstManConModExp =  kernelManager->ExploseEachModel( lstManConMod );
2640
2641                 tempString.Printf(_T("%d - %d"),z, sizeLstContourThings);
2642                 interfMainPanel::getInstance()->setRowLabelInfoPanel(z, tempString);
2643                 //_grid->SetRowLabelValue(z, tempString );
2644 //EED004
2645                 int iContourGroup,sizeContourGroup;
2646                 if (typeContourGroup==3) // contour separete
2647                 {
2648                         sizeContourGroup=lstManConModExp.size();
2649                         if ( maxContourGroup<sizeContourGroup )
2650                         {
2651                                 maxContourGroup=sizeContourGroup;
2652                         }
2653                 } else {  // contour AND OR XOR
2654                         sizeContourGroup=1;
2655                         maxContourGroup=1;
2656                 }
2657
2658                 int tmpIntA;
2659
2660                 for( iContourGroup=0 ; iContourGroup<sizeContourGroup ; iContourGroup++ ){
2661                         lstManConModTmp.clear();
2662
2663
2664
2665                         if (typeContourGroup==3) // contour separete
2666                         {
2667                                 lstManConModTmp.push_back( lstManConModExp[iContourGroup]);
2668                         } else {  // contour AND OR XOR
2669                                 lstManConModTmp = lstManConModExp;
2670                         }
2671
2672                         _contourextractdata->SetLstManualContourModel( lstManConModTmp );
2673                         _contourextractdata->SetScalarRange(grayRangeMin,grayRangeMax);
2674
2675                         pLstValue.clear();
2676                         pLstValuePosX.clear();
2677                         pLstValuePosY.clear();
2678                         pLstValuePosZ.clear();
2679
2680
2681                         int numberOfPixels;
2682                         _contourextractdata->GetValuesInsideCrown(  &numberOfPixels,
2683                                                                                                                 &pLstValue,
2684                                                                                                                 &pLstValuePosX,
2685                                                                                                                 &pLstValuePosY,
2686                                                                                                                 &pLstValuePosZ);
2687
2688                         resultSize=numberOfPixels;
2689                         // Statistics of each slice.
2690                         _contourextractdata->Statistics( &pLstValue,
2691                                                                                         grayRangeMin,
2692                                                                                         grayRangeMax,
2693                                                                                         &resultGrayRangeCount,
2694                                                                                         &resultSize,
2695                                                                                         &resultMin,
2696                                                                                         &resultMax,
2697                                                                                         &resultAverage,
2698                                                                                         &resultStandardeviation);
2699
2700                         if (interfMainPanel::getInstance()->getNumberColsInformationPanel()<_numberOfVariablesStatistics*(iContourGroup+1)  )
2701                         {
2702                                 interfMainPanel::getInstance()->appendColsInformationPanel(_numberOfVariablesStatistics);
2703                         }
2704
2705                         tmpIntA=_numberOfVariablesStatistics*iContourGroup ;
2706
2707                         tempString.Printf(_T("%d"),numberOfPixels);
2708
2709                         interfMainPanel::getInstance()->setCellValueInfoPanel(z, tmpIntA, tempString);
2710
2711                         tempString.Printf(_T("%d"),resultGrayRangeCount);
2712                         interfMainPanel::getInstance()->setCellValueInfoPanel(z, tmpIntA+1, tempString);
2713
2714                         tempString.Printf(_T("%f"),resultMin);
2715                         interfMainPanel::getInstance()->setCellValueInfoPanel(z, tmpIntA+2, tempString);
2716
2717                         tempString.Printf(_T("%f"),resultMax);
2718                         interfMainPanel::getInstance()->setCellValueInfoPanel(z, tmpIntA+3, tempString);
2719
2720                         tempString.Printf(_T("%f"),resultAverage);
2721                         interfMainPanel::getInstance()->setCellValueInfoPanel(z, tmpIntA+4, tempString);
2722
2723                         tempString.Printf(_T("%f"),resultStandardeviation);
2724                         interfMainPanel::getInstance()->setCellValueInfoPanel(z, tmpIntA+5, tempString);
2725
2726
2727                 } // for iContourGroup
2728         } // for z
2729
2730         // Print Volume Statistics
2731
2732
2733         int             vol_rCountRange;
2734         int             vol_rsize;
2735         double  vol_minValue;
2736         double  vol_maxValue;
2737         double  vol_average;
2738         double  vol_standardeviation;
2739
2740         if (selection!=0 ) // actual slice
2741         {
2742
2743                 _contourextractdata->GetVolumeStatistics(&vol_rCountRange, &vol_rsize,
2744                                                                                                  &vol_minValue, &vol_maxValue,
2745                                                                                                  &vol_average, &vol_standardeviation);
2746
2747                 interfMainPanel::getInstance()->setRowLabelInfoPanel(maxZ+2, _T("Total:"));
2748
2749                 tempString.Printf(_T("%d"),vol_rsize);
2750                 interfMainPanel::getInstance()->setCellValueInfoPanel(maxZ+2, 0, tempString);
2751
2752                 tempString.Printf(_T("%d"),vol_rCountRange);
2753                 interfMainPanel::getInstance()->setCellValueInfoPanel(maxZ+2, 1, tempString);
2754
2755                 tempString.Printf(_T("%f"),vol_minValue);
2756                 interfMainPanel::getInstance()->setCellValueInfoPanel(maxZ+2, 2, tempString);
2757
2758                 tempString.Printf(_T("%f"),vol_maxValue);
2759                 interfMainPanel::getInstance()->setCellValueInfoPanel(maxZ+2, 3, tempString);
2760
2761                 tempString.Printf(_T("%f"),vol_average);
2762                 interfMainPanel::getInstance()->setCellValueInfoPanel(maxZ+2, 4, tempString);
2763
2764                 tempString.Printf(_T("%f"),vol_standardeviation);
2765                 interfMainPanel::getInstance()->setCellValueInfoPanel(maxZ+2, 5, tempString);
2766         }
2767         //-----------------------------------------
2768
2769         int iTitleGroup;
2770         wxString tmpTitleString;
2771         int tmpIntB;
2772         for ( iTitleGroup=0 ; iTitleGroup<maxContourGroup ; iTitleGroup++ )
2773         {
2774                 tmpIntB =_numberOfVariablesStatistics*iTitleGroup;
2775                 tmpTitleString.Printf(_T("%d-Size Data"),iTitleGroup);
2776                 interfMainPanel::getInstance()->setColLableInfoPanel(tmpIntB + 0, tmpTitleString);
2777
2778                 interfMainPanel::getInstance()->setColLableInfoPanel(tmpIntB + 0, tmpTitleString );
2779                 interfMainPanel::getInstance()->setColLableInfoPanel( tmpIntB + 1, _T("Size Range") );
2780                 interfMainPanel::getInstance()->setColLableInfoPanel( tmpIntB + 2, _T("Min") );
2781                 interfMainPanel::getInstance()->setColLableInfoPanel( tmpIntB + 3, _T("Max") );
2782                 interfMainPanel::getInstance()->setColLableInfoPanel( tmpIntB + 4, _T("Average") );
2783                 interfMainPanel::getInstance()->setColLableInfoPanel( tmpIntB + 5, _T("St.Dev.") );
2784                 interfMainPanel::getInstance()->setColLableInfoPanel( tmpIntB + 6, _T(" ") );
2785         }// for title
2786         interfMainPanel::getInstance()->setStringInfoPanel( _T("") );
2787 }
2788
2789 //AD: 29-05-09
2790 void wxContourMainFrame::onSaveResults(std::string directory,std::string namefile, std::string filename,
2791         int typeContourGroup, int selection, int minZ, int maxZ, bool XYZValues, bool contourImage, bool statistics)
2792 {
2793         if (XYZValues)
2794         {
2795                 SaveValuesXYZ( directory , namefile, typeContourGroup );
2796         }
2797
2798         if (contourImage)
2799         {
2800                 vtkImageData * mask;
2801                 vtkImageData * value;
2802                 this->getMaskValue(&mask, &value, typeContourGroup,selection,minZ,maxZ);
2803                 this->SaveImageResult( directory , namefile, mask, value);
2804         }
2805
2806         if (statistics)
2807         {
2808                 std::ostringstream name;
2809                 name << filename << ".xls";
2810
2811
2812                 FILE *pFile=fopen(name.str().c_str(),"w+");
2813
2814
2815                 wxString tmpString;
2816                 int i,j,maxX;
2817
2818 //              int sizeZ = _theViewPanel->GetImageDataSizeZ();
2819 //              int maxY=sizeZ+2;
2820
2821                 maxX= interfMainPanel::getInstance()->getNumberColsInformationPanel();//this->_grid->GetNumberCols();
2822
2823                 // -- Title --
2824                 int iTitle,sizeTitle = (maxX / _numberOfVariablesStatistics);
2825                 for ( iTitle=0; iTitle<sizeTitle ; iTitle++)
2826                 {
2827                                 // fprintf(pFile,"-- \t %d-Size \t SizeRange \t Min \t Max \t Ave \t StDv \t" , iTitle,tmpString.c_str() );
2828                                 fprintf(pFile,"slice\t %d-Size \t SizeRange \t Min \t Max \t Ave \t StDv \t" , iTitle );
2829                 }
2830                 fprintf(pFile,"\n\n" );
2831
2832
2833
2834                 if (selection==0 ) // actual slice
2835                 {
2836                         std::vector<int> tempVector;
2837                         _instantPanel->getInstant( tempVector );
2838                         int actualSlice = tempVector[1];
2839                         minZ    = actualSlice;
2840                         maxZ    = actualSlice;
2841                 }
2842
2843                 // Stadistics...
2844                 for ( j=minZ; j<=maxZ ; j++)
2845                 {
2846                         fprintf(pFile,"%d\t" , j );
2847                         for (i=0 ; i<maxX ; i++){
2848                                 tmpString = interfMainPanel::getInstance()->getCellValue(j, i);//_grid->GetCellValue( j , i );
2849                                 fprintf(pFile,"%s\t" , (const char *)(tmpString.mb_str()) );
2850                         } // for i
2851                         fprintf(pFile,"\n"  );
2852                 } // for j
2853
2854
2855                 // Total of stadistics.....
2856                 if (selection!=0)
2857                 {
2858                         fprintf(pFile,"\n Total:\t"  );
2859                         for (i=0 ; i<maxX ; i++){
2860                                 tmpString = interfMainPanel::getInstance()->getCellValue(maxZ+2, i);//_grid->GetCellValue( maxZ+2 , i );
2861                                 fprintf(pFile,"%s\t" , (const char *)(tmpString.mb_str()) );
2862                         } // for i
2863                         fprintf(pFile,"\n"  );
2864                 }
2865
2866                 fclose(pFile);
2867         }
2868 }
2869
2870 //AD: 29-05-09
2871 void wxContourMainFrame::SaveValuesXYZ(std::string directory,std::string namefile,int typeContourGroup)
2872 {
2873         wxBusyCursor wait;
2874
2875         //int typeContourGroup = this->_radiolstboxContourGroup->GetSelection();
2876         _contourextractdata ->SetTypeOperation( typeContourGroup % 3 );
2877
2878         std::vector<manualBaseModel*> lstManConMod;
2879         std::vector<manualBaseModel*> lstManConModTmp;
2880         std::vector<manualBaseModel*> lstManConModExp;
2881         std::vector<double> pLstValue;
2882         std::vector<double> pLstValuePosX;
2883         std::vector<double> pLstValuePosY;
2884         std::vector<double> pLstValuePosZ;
2885
2886         std::vector<int> tempVector;
2887         _instantPanel->getInstant( tempVector );
2888
2889         int sizeZ = _theViewPanel->getSceneManager()->GetImageDataSizeZ();
2890         int z;
2891         int ii,sizeLstContourThings;
2892
2893
2894         int minZ,maxZ;
2895         double totalZ;
2896         double porcent;
2897         wxString tmpString;
2898         minZ    = 0;// _mbarrange->GetStart();
2899         maxZ    = sizeZ;//_mbarrange->GetEnd();
2900         totalZ  = maxZ-minZ+1;
2901
2902
2903 // For each slice..
2904         for ( z=0 ; z<sizeZ ; z++)
2905         {
2906
2907                 porcent = 100.0* (z-minZ)/totalZ;
2908
2909                 tmpString.Printf(_T("Saving Values"));
2910                 tmpString.Printf(_T("  %d %c            %d/%d             %d"), (int)porcent , 37 , z-minZ+1, (int)totalZ ,z);
2911                 interfMainPanel::getInstance()->setStringInfoPanel(tmpString);
2912                 //_staticTextInformation->SetLabel(tmpString);
2913
2914
2915                 //Extraction data from contours of each slice
2916                 _contourextractdata->SetZtoBeAnalys( z);
2917
2918                 tempVector[1]=z;
2919                 Instant instant(&tempVector);
2920                 std::vector<ContourThing**> lstContourThings = kernelManager->getOutlinesAtInstant(&instant);//this->_modelManager->getOutlinesAtInstant( &instant );
2921                 sizeLstContourThings = lstContourThings.size();
2922
2923                 lstManConMod.clear();
2924                 for (ii=0 ; ii<sizeLstContourThings ; ii++)
2925                 {
2926                         ContourThing **contourthing = lstContourThings[ii];
2927                         lstManConMod.push_back( (*contourthing)->getModel() );
2928                 }
2929                 lstManConModExp =  kernelManager->ExploseEachModel( lstManConMod );
2930
2931
2932 //EED004
2933
2934                 int iContourGroup,sizeContourGroup;
2935                 if (typeContourGroup==3) // contour separete
2936                 {
2937                         sizeContourGroup=lstManConModExp.size();
2938                 } else {  // contour AND OR XOR
2939                         sizeContourGroup=1;
2940                 }
2941
2942                 for( iContourGroup=0 ; iContourGroup<sizeContourGroup ; iContourGroup++ ){
2943                         lstManConModTmp.clear();
2944                         if (typeContourGroup==3) // contour separete
2945                         {
2946                                 lstManConModTmp.push_back( lstManConModExp[iContourGroup]);
2947                         } else {  // contour AND OR XOR
2948                                 lstManConModTmp = lstManConModExp;
2949                         }
2950
2951                         _contourextractdata->SetLstManualContourModel( lstManConModTmp );
2952
2953                         pLstValue.clear();
2954                         pLstValuePosX.clear();
2955                         pLstValuePosY.clear();
2956                         pLstValuePosZ.clear();
2957                         int numberOfPixels;
2958                         _contourextractdata->GetValuesInsideCrown(      &numberOfPixels,
2959                                                                                                                 &pLstValue,
2960                                                                                                                 &pLstValuePosX,
2961                                                                                                                 &pLstValuePosY,
2962                                                                                                                 &pLstValuePosZ);
2963
2964                         std::string temp = directory + "/" + namefile + "-slice";
2965                         temp = temp + kernelManager->intToString(z) + "-cont" + kernelManager->intToString(iContourGroup);
2966                         temp = temp + ".txt";
2967
2968                         // LG 14/01/09 : using crea
2969                         wxString filename = crea::std2wx(temp);
2970                         /*filename.Printf(_T("%s"),directory.c_str());
2971                         filename.append(_T("\\"));
2972                         filename.append(_T("%s"),namefile.c_str());
2973                         filename.append(_T("-slice"));
2974                         filename.append(_T("%d"),z);
2975                         filename.append(_T("-cont"));
2976                         filename.append(_T("%d"),iContourGroup);
2977                         filename.append(_T(".txt"));*/
2978                         //                      filename.Printf(temp.c_str());
2979
2980
2981
2982                         FILE *pFile=fopen((const char *)filename.mb_str(),"w+");
2983                         fprintf(pFile,"value \t x \t y \t z\n"  );
2984                         int iLstValue,sizeLstValue=pLstValue.size();
2985                         for (iLstValue=0 ; iLstValue<sizeLstValue ; iLstValue++ )
2986                         {
2987                                 fprintf(pFile,"%f\t %f\t %f\t %f\n", (float)pLstValue[iLstValue] , (float)pLstValuePosX[iLstValue], (float)pLstValuePosY[iLstValue], (float)z );
2988                         }
2989                         fclose(pFile);
2990                 } // for  iContourGroup
2991         } // for z
2992         interfMainPanel::getInstance()->setStringInfoPanel(_T(""));
2993         //_staticTextInformation->SetLabel( _T("") );
2994
2995 }
2996
2997 void wxContourMainFrame::getMaskValue(vtkImageData ** mask,vtkImageData ** value,int typeContourGroup, int selection, int minZ, int maxZ){
2998         wxBusyCursor wait;
2999
3000         //int typeContourGroup = this->_radiolstboxContourGroup->GetSelection();
3001         if (typeContourGroup==3)
3002         {
3003                 typeContourGroup=1;
3004         }
3005         _contourextractdata ->SetTypeOperation( typeContourGroup % 3 );
3006
3007         std::vector<manualBaseModel*> lstManConMod;
3008         std::vector<manualBaseModel*> lstManConModTmp;
3009         std::vector<manualBaseModel*> lstManConModExp;
3010
3011         std::vector<int> tempVector;
3012         _instantPanel->getInstant( tempVector );
3013
3014     vtkImageData *imagedata = _theViewPanel->getImageData();
3015         int ext[6];
3016         imagedata->GetExtent(ext);
3017         int sizeZimage = ext[5]-ext[4]+1;
3018         int z;
3019         int ii,sizeLstContourThings;
3020
3021         double totalZ;
3022         double porcent;
3023
3024         wxString tmpString;
3025
3026
3027         if (selection==0 ) // actual slice
3028         {
3029                 int actualSlice = tempVector[1];
3030                 minZ    = actualSlice;
3031                 maxZ    = actualSlice;
3032         }
3033
3034         totalZ  = maxZ-minZ;
3035
3036
3037         // cleanning image before range
3038         for (z=0; z<minZ; z++){
3039                 _contourextractdata->ResetImageResult(z);
3040         }
3041         // cleanning image after range
3042         for (z=maxZ+1; z<sizeZimage; z++){
3043                 _contourextractdata->ResetImageResult(z);
3044         }
3045
3046
3047 // For each slice..
3048         for ( z=minZ ; z<=maxZ ; z++)
3049         {
3050
3051                 porcent = 100.0* (z-minZ)/totalZ;
3052                 tmpString.Printf(_T("Saving Values"));
3053                 tmpString.Printf(_T("%d %c            %d/%d             %d"), (int)porcent , 37 , z-minZ+1, (int)totalZ ,z);
3054                 interfMainPanel::getInstance()->setStringInfoPanel(tmpString);
3055
3056                 //Extraction data from contours of each slice
3057                 _contourextractdata->SetZtoBeAnalys( z);
3058
3059                 tempVector[1]=z;
3060                 Instant instant(&tempVector);
3061                 std::vector<ContourThing**> lstContourThings = kernelManager->getOutlinesAtInstant( &instant );
3062                 sizeLstContourThings = lstContourThings.size();
3063
3064                 lstManConMod.clear();
3065                 for (ii=0 ; ii<sizeLstContourThings ; ii++)
3066                 {
3067                         ContourThing **contourthing = lstContourThings[ii];
3068                         lstManConMod.push_back( (*contourthing)->getModel() );
3069                 }
3070                 lstManConModExp =  kernelManager->ExploseEachModel( lstManConMod );
3071
3072
3073                 int iContourGroup,sizeContourGroup;
3074                 if (typeContourGroup==3) // contour separete
3075                 {
3076                         sizeContourGroup=lstManConModExp.size();
3077                 } else {  // contour AND OR XOR
3078                         sizeContourGroup=1;
3079                 }
3080
3081                 for( iContourGroup=0 ; iContourGroup<sizeContourGroup ; iContourGroup++ ){
3082                         lstManConModTmp.clear();
3083                         if (typeContourGroup==3) // contour separete
3084                         {
3085                                 lstManConModTmp.push_back( lstManConModExp[iContourGroup]);
3086                         } else {  // contour AND OR XOR
3087                                 lstManConModTmp = lstManConModExp;
3088                         }
3089
3090                         _contourextractdata->SetLstManualContourModel( lstManConModTmp );
3091                         _contourextractdata->CalculateImageResult(); // with actual Z
3092
3093                 } // for  iContourGroup
3094         } // for z
3095
3096         (*value) = _contourextractdata->GetVtkImageValueResult();
3097         (*mask)  = _contourextractdata->GetVtkImageMaskResult();
3098
3099 }
3100
3101 std::string wxContourMainFrame::GetStringTypeImage( vtkImageData* image)
3102 {
3103         std::string result="";
3104         if ( image->GetScalarType()==VTK_CHAR )
3105         {
3106                 result="CHAR";
3107         } else if ( image->GetScalarType()==VTK_UNSIGNED_CHAR ){
3108                 result="UCHAR";
3109         } else if ( image->GetScalarType()==VTK_FLOAT ){
3110                 result="FLOAT";
3111         } else if ( image->GetScalarType()==VTK_DOUBLE ){
3112                 result="DOUBLE";
3113         } else if ( image->GetScalarType()==VTK_INT ){
3114                 result="INT";
3115         } else if ( image->GetScalarType()==VTK_UNSIGNED_INT ){
3116                 result="UINT";
3117         } else if ( image->GetScalarType()==VTK_SHORT ){
3118                 result="SHORT";
3119         } else if ( image->GetScalarType()==VTK_UNSIGNED_SHORT ){
3120                 result="USHORT";
3121         } else if ( image->GetScalarType()==VTK_LONG ){
3122                 result="LONG";
3123         } else if ( image->GetScalarType()==VTK_UNSIGNED_LONG ){
3124                 result="ULONG";
3125         }
3126         return result;
3127 }
3128
3129 void wxContourMainFrame::SaveImageResult(std::string directory,std::string namefile, vtkImageData* mask,vtkImageData* value)
3130 {
3131         std::string stringType;
3132         double spc[3];
3133         kernelManager->GetSpacing(spc,0);   // returns the spacing of the first image
3134         stringType              = GetStringTypeImage(value);
3135         std::string temp = directory + "/" + namefile + "-image-Value-"+stringType+".mhd";
3136
3137         wxString filename = crea::std2wx(temp);
3138
3139 // Image Value
3140         
3141         vtkImageChangeInformation *valueChInfo = vtkImageChangeInformation::New();
3142 //EED 2017-01-01 Migration VTK7
3143 #if VTK_MAJOR_VERSION <= 5
3144         valueChInfo->SetInput(value);
3145 #else
3146         valueChInfo->SetInputData(value);
3147 #endif
3148         valueChInfo->SetSpacingScale(spc);      
3149         valueChInfo->Update();  
3150         vtkMetaImageWriter *writerValueImage = vtkMetaImageWriter::New( );
3151
3152 //EED 2017-01-01 Migration VTK7
3153 #if VTK_MAJOR_VERSION <= 5
3154         writerValueImage->SetInput( valueChInfo->GetOutput() );
3155 #else
3156         writerValueImage->SetInputData( valueChInfo->GetOutput() );
3157 #endif
3158         writerValueImage->SetFileName( (const char *)filename.mb_str() );
3159         writerValueImage->SetFileDimensionality( 3 );
3160         writerValueImage->SetCompression(false);
3161         writerValueImage->Write( );
3162
3163 // Image Mask
3164         stringType              = GetStringTypeImage(mask);
3165         temp = directory + "/" + namefile + "-image-Mask-"+stringType+".mhd";
3166
3167         // LG 14/01/09 : using crea
3168         filename = crea::std2wx(temp);
3169         //      filename.Printf(_T(temp.c_str()));
3170
3171
3172         vtkImageChangeInformation *maskChInfo = vtkImageChangeInformation::New();
3173 //EED 2017-01-01 Migration VTK7
3174 #if VTK_MAJOR_VERSION <= 5
3175         maskChInfo->SetInput(mask);
3176 #else
3177         maskChInfo->SetInputData(mask);
3178 #endif
3179         maskChInfo->SetSpacingScale(spc);       
3180         maskChInfo->Update();   
3181         vtkMetaImageWriter *writerMaskImage = vtkMetaImageWriter::New( );
3182
3183 //EED 2017-01-01 Migration VTK7
3184 #if VTK_MAJOR_VERSION <= 5
3185         writerMaskImage->SetInput( maskChInfo->GetOutput() );
3186 #else
3187         writerMaskImage->SetInputData( maskChInfo->GetOutput() );
3188 #endif
3189
3190         writerMaskImage->SetFileName( (const char *)filename.mb_str() );
3191         writerMaskImage->SetFileDimensionality( 3 );
3192         writerMaskImage->SetCompression(false);
3193         writerMaskImage->Write( );
3194
3195         interfMainPanel::getInstance()->setStringInfoPanel( _T("") );
3196
3197 }
3198
3199
3200
3201 void wxContourMainFrame::onChangeInstantInstantPanel(std::string name,int value, int minshow, int maxshow){
3202         if( name.compare( _theViewPanel->getVerticalConceptName() ) == 0){
3203                 _theViewPanel->setActualVertical( value);
3204         }
3205         else if( name.compare( _theViewPanel->getHorizontalConceptName() ) == 0|| _instantPanel->getIfConceptCheckedAt( name, 0 ) )     {
3206                 _theViewPanel->setHorizontalConcept( name, minshow, maxshow, minshow, maxshow, value);
3207         }
3208
3209         changeInstant();
3210 }
3211
3212 void wxContourMainFrame::onSnakePressed(){
3213         std::vector<double> vecX;
3214         std::vector<double> vecY;
3215         std::vector<double> vecZ;
3216         _theViewPanel->GetPointsOfActualContour( &vecX , &vecY , &vecZ );
3217
3218         if (vecX.size()!=0){
3219                 std::vector<int> tempVector;
3220                 _instantPanel->getInstant( tempVector );
3221                 int i,size=vecZ.size();
3222                 int actualSlice = tempVector[1];
3223                 for ( i=0 ; i<size ; i++ )
3224                 {
3225                         vecZ[i] = actualSlice;
3226                 } // for
3227
3228                 wxDialog* dialog = new wxDialog(this, -1, wxString(_T("Snake")));
3229                 wxPanel* panel = new wxPanel(dialog,-1);
3230                 //              wxStaticText* sttext = new wxStaticText(panel, -1, wxString(_T("Panel para snake")));
3231          new wxStaticText(panel, -1, wxString(_T("Panel para snake")));
3232                 dialog->ShowModal();
3233         } // if
3234
3235 }
3236
3237 void wxContourMainFrame::saveFileWithContoursAutomatique(){
3238         std::string filename = kernelManager->getCurrentFileName();
3239         if(filename.compare("")!=0){
3240                 saveFileWithContours(filename);
3241         }else{
3242                 onSave();
3243         }
3244 }
3245 void wxContourMainFrame::ShowToolsPanel(bool show){
3246         _pannew->Show(show);
3247 }
3248
3249
3250
3251 void wxContourMainFrame::SetContourGroup(int contourGroup)
3252 {
3253         _contourGroup = contourGroup;
3254 }
3255
3256
3257 wxPanel *wxContourMainFrame::getMaskImageViewPanel(wxWindow *parent)
3258 {
3259  
3260         if      (_viewMaskImagePanel==NULL)
3261         {
3262                 _contourextractdata = new ContourExtractData(true);
3263                 _contourextractdata->SetImage( _theViewPanel->getImageData() );
3264 //              double range[2];
3265 //              _theViewPanel->getImageData()->GetScalarRange(range);
3266                 //int min = (int)floor (range[0]);
3267                 //int max = (int)ceil (range[1]);
3268
3269 //EED 2017-12-17
3270                 int min = 254;
3271                 int max = 256;
3272
3273                 _viewMaskImagePanel = new ThresholdImageViewPanel( parent, -1, -1 , -1,-1,  0);
3274                 _viewMaskImage = new ThresholdImageView();
3275                 _viewMaskImage->SetImage( _contourextractdata->GetVtkImageMaskResult() );
3276                 _viewMaskImage->SetminMaxValue( min, max);
3277                 _viewMaskImage->SetBaseColor( 0,0,1 );
3278
3279
3280                 std::vector<int> colorbarposition;
3281                 colorbarposition.push_back( -999 );
3282                 colorbarposition.push_back( -999 );
3283                 _viewMaskImage->SetColorBarPosition( colorbarposition );
3284                 double spc[3];
3285                 _viewMaskImage->SetSpcBase( _theViewPanel->getImageData()->GetSpacing() );
3286                 _viewMaskImage->SetNewSpacingLayer( _theViewPanel->getImageData()->GetSpacing() );
3287
3288                 _viewMaskImagePanel->SetThresholdImageView( _viewMaskImage );
3289                 _viewMaskImage->SetwxVtkBaseView( _theViewPanel->getWxVtkBaseView() );
3290                 _viewMaskImage->onThresholdChangeOpacity( 25 );
3291         }
3292         return _viewMaskImagePanel;
3293 }
3294
3295
3296 wxPanel *wxContourMainFrame::getColorLayerImageViewPanel(wxWindow *parent)
3297 {
3298         if      (_viewColorLayerImagePanel==NULL)
3299         {
3300                 double range[2];
3301                 _theViewPanel->getImageData()->GetScalarRange(range);
3302                 int min = (int)floor (range[0]);
3303                 int max = (int)ceil (range[1]);
3304                 _viewColorLayerImagePanel = new ColorLayerImageViewPanel( parent, min, max, 100, 1);
3305                 _viewColorLayerImagePanel->GetColorLayerImageViewManager()->SetwxVtkBaseView( 0 , _theViewPanel->getWxVtkBaseView() );
3306         //    std::vector<double> range = bbGetInputlstRangeForColorBar();
3307         //    clivp->GetColorLayerImageViewManager()->SetRangeForColorBar( range );
3308                 std::vector<int> colorbarposition;
3309                 colorbarposition.push_back( 50 );
3310                 colorbarposition.push_back( 105 );
3311                 _viewColorLayerImagePanel->GetColorLayerImageViewManager()->SetColorBarPosition( colorbarposition );
3312         //    std::vector<double> base_color;
3313         //    _viewColorLayerImagePanel->GetColorLayerImageViewManager()->SetBaseColors( base_color );
3314         //    std::vector<double> grey_level_boundaries;
3315         //    clivp->GetColorLayerImageViewManager()->SetGreyLevelBoundaries( grey_level_boundaries );
3316                 std::vector<double> transparence_level_boundaries;
3317                 transparence_level_boundaries.push_back(0);
3318                 _viewColorLayerImagePanel->GetColorLayerImageViewManager()->SetBaseTransparence( transparence_level_boundaries );
3319                 _viewColorLayerImagePanel->GetColorLayerImageViewManager()->SetPlainOrGradientColor( false );
3320 //              _viewColorLayerImagePanel->SetFittingMode( 3 );
3321         }
3322         return _viewColorLayerImagePanel;
3323 }
3324
3325
3326 wxPanel *wxContourMainFrame::getThresholdImageViewPanel(wxWindow *parent)
3327 {
3328         if      (_viewThresholdImagePanel==NULL)
3329         {
3330                 double range[2];
3331                 _theViewPanel->getImageData()->GetScalarRange(range);
3332                 int min = (int)floor (range[0]);
3333                 int max = (int)ceil (range[1]);
3334                 int start= (max+min)/2 - (max-min)*0.25; 
3335                 int end= (max+min)/2 + (max-min)*0.25; 
3336                 _viewThresholdImagePanel = new ThresholdImageViewPanel( parent, min, max, start, end , 1);
3337                 _viewThresholdImage = new ThresholdImageView();
3338                 _viewThresholdImage->SetminMaxValue(start,end);
3339                 _viewThresholdImage->SetImage( _theViewPanel->getImageData() );
3340                 std::vector<int> colorbarposition;
3341                 colorbarposition.push_back( 10 );
3342                 colorbarposition.push_back( 105 );
3343                 _viewThresholdImage->SetColorBarPosition( colorbarposition );
3344                 double spc[3];
3345                 _viewThresholdImage->SetSpcBase( _theViewPanel->getImageData()->GetSpacing() );
3346                 _viewThresholdImage->SetNewSpacingLayer( _theViewPanel->getImageData()->GetSpacing() );
3347
3348                 _viewThresholdImage->SetBaseColor( 1,0,0 );
3349                 _viewThresholdImagePanel->SetThresholdImageView( _viewThresholdImage );
3350                 _viewThresholdImage->SetwxVtkBaseView( _theViewPanel->getWxVtkBaseView() );
3351                 _viewThresholdImage->onThresholdChangeOpacity( 25 );
3352                 RefreshInterface();
3353         }
3354         return _viewThresholdImagePanel;
3355 }
3356
3357 //CMRU 17-08-09-----------------------------------------------------------------------------------------------
3358 int wxContourMainFrame::getType ()
3359 {
3360         int tipo = 0;
3361         std::vector<std::string> currentSelection = _theViewPanel->getSelectedObjects();
3362
3363         if(!currentSelection.empty())
3364         {
3365                 std::string cloneName = currentSelection [0];
3366                 manualBaseModel * manualModel = kernelManager->getOutlineByKeyName(cloneName);
3367                 tipo = manualModel-> GetTypeModel();
3368         }
3369         return tipo;
3370 }
3371
3372 double wxContourMainFrame::getContourSizeInPixels()
3373 {
3374         double contourSize = 0;
3375
3376         std::vector<std::string> currentSelection = _theViewPanel->getSelectedObjects();        if(!currentSelection.empty())
3377         if(!currentSelection.empty())
3378         {
3379                 std::string cloneName = currentSelection [0];
3380
3381                 manualBaseModel * manualModel = kernelManager->getOutlineByKeyName(cloneName);//_modelManager->getOutlineByKeyName( cloneName )->getModel();
3382
3383 // EED 2017-05-30
3384 //              contourSize = manualModel->GetPathSize();
3385                 double spc[3];
3386                 spc[0]=1; 
3387                 spc[1]=1; 
3388                 spc[2]=1; 
3389                 contourSize = manualModel->GetPathSize( spc );
3390         }
3391         return contourSize;
3392 }
3393
3394 manualBaseModel * wxContourMainFrame::getContour ()
3395 {
3396         std::vector<std::string> currentSelection = _theViewPanel->getSelectedObjects();
3397
3398         if(!currentSelection.empty())
3399         {
3400                 std::string cloneName = currentSelection [0];
3401                 manualBaseModel * manualModel = kernelManager->getOutlineByKeyName(cloneName);//_modelManager->getOutlineByKeyName( cloneName )->getModel();
3402                 return manualModel;
3403         }
3404         return NULL;
3405 }
3406 void wxContourMainFrame::onPrintLabel (wxString label, manualBaseModel* manualModel)
3407 {
3408         std::string labelAscii(label.ToAscii());
3409         int pos = labelAscii.find(" ");
3410
3411         int j;
3412
3413         for (j=0 ; pos != string::npos;j++)
3414         {
3415                 labelAscii.replace( pos, 1, "_" );
3416                 pos= labelAscii.find(" ");
3417         }
3418
3419         manualModel -> SetLabel(labelAscii);
3420 }
3421 void wxContourMainFrame::onInsertCalculation(manualBaseModel* manualModel)
3422 {
3423 // EED 2017-05-30
3424 //      double sizeInPixel      = manualModel ->GetPathSize(  );
3425         double spc[3];
3426         spc[0]=1; // ????
3427         spc[1]=1; // ????
3428         spc[2]=1; // ????
3429         double sizeInPixel      = manualModel ->GetPathSize( spc );
3430
3431         double onePixelRealSize = interfMainPanel::getInstance()->GetPixelValue();;
3432         double realContourSize  = sizeInPixel*onePixelRealSize;
3433         manualModel ->SetRealSize(realContourSize);
3434 }
3435
3436 double wxContourMainFrame::onePixelSize( double value)
3437 {
3438         return _onePixelSize = value;
3439 }
3440
3441 std::string wxContourMainFrame::GetFileLocation()
3442 {
3443         return _fileLocation;
3444 }
3445
3446 void wxContourMainFrame::SetFileLocation(std::string newFileLocation)
3447 {
3448         _fileLocation = newFileLocation;
3449         std::cout<<"GETFILELOCATION:"<<_fileLocation<<std::endl;
3450 }
3451 //------------------------------------------------------------------------------------------------------------
3452
3453
3454
3455
3456
3457
3458
3459
3460 void wxContourMainFrame::FlipSelectedContours(int flipDirection)
3461 {
3462         FlipLstOfContours( 
3463                             (std::vector<std::string>)_theViewPanel->getSceneManager()->getSelectedObjects() , 
3464                             flipDirection
3465                           );    
3466                 
3467 }
3468
3469 void wxContourMainFrame::FlipActualSliceContours(int flipDirection)
3470 {
3471         FlipLstOfContours( 
3472                             (std::vector<std::string>)_theViewPanel->getSceneManager()->GetlstContoursNameActualSlice() , 
3473                             flipDirection
3474                           );    
3475 }
3476
3477 void wxContourMainFrame::FlipAllContours(int flipDirection)
3478 {
3479         FlipLstOfContours( 
3480                             kernelManager->GetLstNameThings() , 
3481                             flipDirection
3482                           );
3483 }
3484
3485 void wxContourMainFrame::FlipLstOfContours(std::vector<std::string> lstNameThings, int flipDirection)
3486 {
3487         int ext[6];
3488         getImageData()->GetExtent(ext);         
3489         int sizeX = ext[1]-ext[0];
3490         int sizeY = ext[3]-ext[2];
3491
3492         
3493         int i,sizeLstNameThings;
3494         int ii,sizeLstPoints;
3495         
3496         sizeLstNameThings       = lstNameThings.size(); 
3497         for (i=0 ; i<sizeLstNameThings ; i++)
3498         {
3499                 printf("EED wxContourMainFrame::FlipAllContours contour=%d \n", i );
3500                 manualBaseModel * manualModel = kernelManager->getOutlineByKeyName(lstNameThings[i]);
3501                 if (flipDirection==0)
3502                 {
3503                         manualModel->Transform_Ax_Plus_B(-1,sizeX,1,0 );
3504                 } else {
3505                         manualModel->Transform_Ax_Plus_B(1,0,-1,sizeY );
3506                 }
3507         }// for i  list of Things
3508
3509         //-- Static Contours
3510
3511         lstNameThings           = kernelManager->GetLstNameThingsStatic();
3512         sizeLstNameThings       = lstNameThings.size();
3513         for (i=0 ; i<sizeLstNameThings ; i++)
3514         {
3515                 manualBaseModel * manualModel = kernelManager->getOutlineByKeyName(lstNameThings[i]);
3516                 if (flipDirection==0)
3517                 {
3518                         manualModel->Transform_Ax_Plus_B(-1,sizeX,1,0 );
3519                 } else {
3520                         manualModel->Transform_Ax_Plus_B(1,0,-1,sizeY );
3521                 }
3522         }// for i  list of static things        
3523 }
3524
3525 void wxContourMainFrame::FlipContours(int typeContourFlip, int flipDirection)
3526 {
3527         printf("EED wxContourMainFrame::FlipContours( %d , %d ) \n",typeContourFlip,  flipDirection );
3528
3529         saveState();
3530         
3531         if (typeContourFlip==0) // 
3532         {
3533                 FlipSelectedContours(flipDirection);
3534         }
3535
3536         if (typeContourFlip==1) // 
3537         {
3538                 FlipActualSliceContours(flipDirection);
3539         }
3540         
3541         if (typeContourFlip==2) // 
3542         {
3543                 FlipAllContours(flipDirection);
3544         }
3545         RefreshInterface();
3546 }
3547
3548
3549 void wxContourMainFrame::SetXY(int x, int y)
3550 {
3551         _theViewPanel->SetXY(x,y);
3552 }
3553
3554
3555
3556