]> Creatis software - creaContours.git/blob - lib/Interface_ManagerContour_NDimensions/wxContourMainFrame.cxx
#3322 creaContours Feature New Normal - Show reference contour Befor After actual...
[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 printf("EED wxContourMainFrame::SegmentationOneSlice   Start\n");
1903         int typeofcontour = 1;
1904         //--Extracting Contour
1905         //vtkImageData  *imagedata      = _theViewPanel->getSceneManager()->GetImageData();
1906         vtkImageData    *imagedata      = getImageData();
1907 //              double                  *range          = imagedata->GetScalarRange();
1908 //              double                  thr                     = 1;
1909
1910         vtkImageReslice *imageReslice = vtkImageReslice::New();
1911 //EED
1912 //              double spc[3];
1913 //              imagedata->GetSpacing(spc);
1914 //              x = x*spc[0];
1915 //              y = y*spc[1];
1916 //              z = z*spc[3];
1917
1918 //EED 2017-01-01 Migration VTK7
1919 #if VTK_MAJOR_VERSION <= 5
1920         imageReslice->SetInput( imagedata );
1921 #else
1922         imageReslice->SetInputData( imagedata );
1923 #endif
1924         imageReslice->SetInformationInput(imagedata);
1925         imageReslice->SetResliceAxesDirectionCosines(1,0,0, 0,1,0 ,0,0,1);
1926         imageReslice->SetResliceAxesOrigin(0,0,z);
1927         imageReslice->SetOutputDimensionality(2);
1928         imageReslice->SetInterpolationModeToLinear();
1929
1930 //EED 2017-01-01 Migration VTK7
1931 #if VTK_MAJOR_VERSION <= 5
1932         // ..
1933 #else
1934         imageReslice->Update();
1935 #endif
1936
1937         imagedata = imageReslice->GetOutput();
1938 //EED 2017-01-01 Migration VTK7
1939 #if VTK_MAJOR_VERSION <= 5
1940         imagedata->Update();
1941         imagedata->UpdateInformation();
1942 #else
1943         // ..
1944 #endif
1945
1946         vtkContourFilter* cntVTK = vtkContourFilter::New( );
1947 //EED 2017-01-01 Migration VTK7
1948 #if VTK_MAJOR_VERSION <= 5
1949         cntVTK->SetInput( imagedata );
1950 #else
1951         cntVTK->SetInputData( imagedata );
1952 #endif
1953
1954         cntVTK->SetNumberOfContours( 1 );
1955         //cntVTK->SetValue( 0, vmin );
1956 //              cntVTK->SetValue( 0, (range[1]*thr/100) );
1957         cntVTK->SetValue( 1, isovalue );
1958 //      cntVTK->SetValue( 1, vmax );
1959         cntVTK->Update( );
1960         cntVTK->UpdateInformation();
1961
1962         vtkCleanPolyData* cpd = vtkCleanPolyData::New( );
1963 //EED 2017-01-01 Migration VTK7
1964 #if VTK_MAJOR_VERSION <= 5
1965         cpd->SetInput( cntVTK->GetOutput( ) );
1966 #else
1967         cpd->SetInputData( cntVTK->GetOutput( ) );
1968 #endif
1969         cpd->ConvertLinesToPointsOff( );
1970         cpd->Update( );
1971         cpd->UpdateInformation();
1972
1973         vtkPolyDataConnectivityFilter* conn = vtkPolyDataConnectivityFilter::New( );
1974         conn->SetExtractionModeToClosestPointRegion( );
1975         //conn->SetMaxRecursionDepth( 3000 );
1976
1977 //EED 2017-01-01 Migration VTK7
1978 #if VTK_MAJOR_VERSION <= 5
1979         conn->SetInput( cpd->GetOutput( ) );
1980 #else
1981         conn->SetInputData( cpd->GetOutput( ) );
1982 #endif
1983
1984         conn->SetClosestPoint( x, y, 0 );
1985         conn->Update( );
1986         conn->UpdateInformation();
1987
1988         vtkCleanPolyData* cpd2 = vtkCleanPolyData::New( );
1989 //EED 2017-01-01 Migration VTK7
1990 #if VTK_MAJOR_VERSION <= 5
1991         cpd2->SetInput( conn->GetOutput( ) );
1992 #else
1993         cpd2->SetInputData( conn->GetOutput( ) );
1994 #endif
1995         cpd2->Update();
1996         cpd2->UpdateInformation();
1997
1998         vtkStripper* vtkstripper = vtkStripper::New( );
1999         vtkstripper->SetMaximumLength(20000);
2000 //EED 2017-01-01 Migration VTK7
2001 #if VTK_MAJOR_VERSION <= 5
2002         vtkstripper->SetInput( cpd2->GetOutput() );
2003 #else
2004         vtkstripper->SetInputData( cpd2->GetOutput() );
2005 #endif
2006         vtkstripper->Update();
2007         vtkstripper->UpdateInformation();
2008
2009
2010         vtkPolyData* polyDataResult =  vtkstripper->GetOutput();
2011
2012 //EED 2017-01-01 Migration VTK7
2013 #if VTK_MAJOR_VERSION <= 5
2014         polyDataResult->Update( );
2015         polyDataResult->UpdateInformation();
2016 #else
2017         //...
2018 #endif
2019
2020 /* EED
2021 ofstream myfile;
2022 myfile.open ("c:/temp/example.txt");
2023 myfile << "\n";
2024 polyDataResult->Print(myfile);
2025 myfile << "-------------------------------------\n";
2026 polyDataResult->GetLines()->Print(myfile);
2027 myfile.close();
2028 */
2029
2030         cntVTK          -> Delete();
2031         cpd2            -> Delete();
2032         cpd                     -> Delete();
2033         conn            -> Delete();
2034
2035
2036 //--Calculating control points
2037
2038         std::vector<double> vecX;
2039         std::vector<double> vecY;
2040         std::vector<double> vecZ;
2041
2042         std::vector<double> vecCtrlPointX;
2043         std::vector<double> vecCtrlPointY;
2044         std::vector<double> vecCtrlPointZ;
2045
2046
2047 printf("EED wxContourMainFrame::SegmentationOneSlice GetNumberOfLines=%d \n",polyDataResult->GetNumberOfLines() );
2048
2049 int numberOfPointsInCell;
2050 int numberOfcells=polyDataResult->GetNumberOfCells();
2051 for (int jj=0; jj<numberOfcells ; jj++)
2052 {
2053         vtkCell* vtkcell = polyDataResult->GetCell( jj );
2054         numberOfPointsInCell=vtkcell->GetNumberOfPoints();
2055         printf("EED wxContourMainFrame::SegmentationOneSlice cell=%d  points=%d \n",jj,numberOfPointsInCell );
2056 }// for jj
2057
2058 printf("EED wxContourMainFrame::SegmentationOneSlice PrintSelf \n");
2059
2060 polyDataResult->PrintSelf( std::cout, vtkIndent(0) );
2061
2062
2063
2064         double *p;
2065         int ii,size=polyDataResult->GetNumberOfPoints();
2066         int id;
2067         for (ii=1;ii<=size;ii++)
2068         {
2069                 id      = polyDataResult->GetLines()->GetData()->GetValue(ii);
2070                 p       = polyDataResult->GetPoint(id);
2071 printf("EED wxContourMainFrame::SegmentationOneSlice (%d) id=%d  px=%f py=%f\n",ii,id, p[0],p[1]);
2072 //              double x=p[0];
2073 //              double y=p[1];
2074                 vecX.push_back( p[0] );
2075                 vecY.push_back( p[1] );
2076 //EED 2017-12-16
2077                 vecZ.push_back( -900 );
2078 //                      vecZ.push_back( p[2] );
2079         }
2080
2081
2082         ExtractControlPoints2D *extractcontrolpoints2d = new ExtractControlPoints2D();
2083         extractcontrolpoints2d->SetContour( &vecX , &vecY , &vecZ );
2084
2085 //PROOFS
2086         /*if (methodRadiobox->GetSelection()==0){
2087                 extractcontrolpoints2d->GetInitialControlPoints( &vecCtrlPointX , &vecCtrlPointY , &vecCtrlPointZ );
2088         }
2089         if (methodRadiobox->GetSelection()==1){
2090                 extractcontrolpoints2d->GetControlPoints(  &vecCtrlPointX , &vecCtrlPointY , &vecCtrlPointZ );
2091         }
2092         if (methodRadiobox->GetSelection()==2){
2093                 extractcontrolpoints2d->SetSamplingControlPoints( sampling );
2094                 extractcontrolpoints2d->GetSamplingControlPoints(  &vecCtrlPointX , &vecCtrlPointY , &vecCtrlPointZ );
2095         }*/
2096
2097         if (method==0)
2098         {
2099                 extractcontrolpoints2d->GetInitialControlPoints( &vecCtrlPointX , &vecCtrlPointY , &vecCtrlPointZ );
2100         } else if (method==1){
2101                 extractcontrolpoints2d->GetControlPoints(  &vecCtrlPointX , &vecCtrlPointY , &vecCtrlPointZ );
2102         } else if (method==2){
2103                 extractcontrolpoints2d->SetSamplingControlPoints( sampling );
2104                 extractcontrolpoints2d->GetSamplingControlPoints(  &vecCtrlPointX , &vecCtrlPointY , &vecCtrlPointZ );
2105         }
2106
2107         //--Adding contour to the system
2108         std::vector<int> actualInstantVector;
2109         _instantPanel->getInstant( actualInstantVector );
2110         actualInstantVector[1]=z;
2111
2112         int j,sizeCtrPt = vecCtrlPointX.size();
2113         manualBaseModel *manModelContour =  kernelManager->factoryManualContourModel( typeofcontour );
2114 printf("EED  wxContourMainFrame::SegmentationOneSlice  sizeCtrPt=%d   %d  %d\n" , sizeCtrPt
2115                                                                                                                                                                 , ((sizeCtrPt/100)+1)*100 *2
2116                                                                                                                                                                 , manModelContour->GetNumberOfPointsSpline()
2117         );
2118         manModelContour->SetNumberOfPointsSpline( ((sizeCtrPt/100)+1)*100 *2 );
2119         if (sizeCtrPt>=3)
2120         {
2121                 for (j=0 ; j<sizeCtrPt ; j++)
2122                 {
2123                         manModelContour->AddPoint( vecCtrlPointX[j] , vecCtrlPointY[j] , vecCtrlPointZ[j]  );
2124                 } // for
2125                 std::string theName;
2126                 //theName = _modelManager->createOutline( manModelContour, actualInstantVector );
2127                 theName = kernelManager->createOutline( manModelContour, actualInstantVector );
2128                 bool addedModel = theName.compare("") != 0;
2129                 if( addedModel )
2130                 {
2131                         double spc[3];//Si no hay imagen pero hay contornos que spacing se pone por default
2132                         _theViewPanel->getSpacing(spc);
2133                         //Adding the manualContourControler to interface objects structure
2134                         //Adding the manualViewContour to interface objects structure
2135                         //_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.
2136                         _theViewPanel->configureViewControlTo(theName, manModelContour, spc, typeofcontour);
2137                         //_theViewPanel->getSceneManager()->configureViewControlTo( theName, manModelContour,spc, typeofcontour ) ;
2138                 }       // if addedModel
2139         } // if sizeCtrPt
2140 printf("EED wxContourMainFrame::SegmentationOneSlice   End\n");
2141 }
2142
2143 int wxContourMainFrame::GetImageDataSizeZ()
2144 {
2145         return _theViewPanel->GetImageDataSizeZ();
2146 }
2147
2148 void wxContourMainFrame::GetImageDataRange(double *range)
2149 {
2150         _theViewPanel->GetImageDataRange(range);
2151 }
2152
2153 void wxContourMainFrame::onSegmentationAllSlice(int minZ,int maxZ,int isovalue,int sampling,int method)
2154 {
2155         //JCP 20-10-08 Undo redo implementation
2156         saveState();
2157         //JCP 20-10-08 Undo redo implementation
2158
2159         wxBusyCursor wait;
2160         int                                     x                                       = _theViewPanel->GetX();
2161         int                                     y                                       = _theViewPanel->GetY();
2162         int z;
2163         double porcent;
2164         wxString tmpString;
2165         double totalZ = maxZ-minZ+1;
2166         for( z=minZ ; z<=maxZ ; z++ )
2167         {
2168                 porcent = 100.0* (z-minZ)/totalZ;
2169                 tmpString.Printf(_T("  %d %c            %d/%d            %d"), (int)porcent , 37 , z-minZ+1, (int)totalZ,z );
2170                 interfMainPanel::getInstance()->setLabelSegmentationPanelVTK(tmpString);
2171                 //_staticTextSegmentation->SetLabel(tmpString);
2172                 SegmentationOneSlice( x,y,z,isovalue, sampling,method );
2173         }
2174         interfMainPanel::getInstance()->setLabelSegmentationPanelVTK(_T("   "));
2175         RefreshInterface();
2176 }
2177
2178
2179 //Creates a reference line to be used as the axis of the mirroring
2180 void wxContourMainFrame::referenceLine()
2181 {
2182         if (_refLineControl==NULL)
2183         {
2184                 wxBusyCursor wait;
2185                 double spc[3];
2186
2187                 vtkImageData *vtkimagedata = _theViewPanel->getImageData();
2188                 vtkimagedata->GetSpacing(spc);
2189
2190                 wxVtkBaseView * viewer2D = _theViewPanel->getWxVtkBaseView();
2191
2192                 _refLineControl = new manualLineControler();
2193                 _refLineModel   = new manualContourModelLine();
2194                 _refLineView = new manualViewLine();
2195                 _refLineView->SetModel( _refLineModel );
2196                 _refLineView->SetWxVtkBaseView( viewer2D );
2197                 _refLineView->SetRange( 2 );
2198                 _refLineView->SetZ( 1200 );
2199
2200                 _refLineView->SetSpacing(spc);
2201
2202                 _refLineView->SetColorNormalContour(0, 0, 1);
2203                 _refLineView->SetColorEditContour(0, 0.5, 0.5);
2204                 _refLineView->SetWidthLine(4);
2205
2206                 _refLineControl->SetModelView( _refLineModel , _refLineView );
2207                 vtkInteractorStyleBaseView* style = (vtkInteractorStyleBaseView*)viewer2D->GetInteractorStyleBaseView();
2208                 style->AddInteractorStyleMaracas( _refLineControl );
2209                 _refLineModel->SetCloseContour(false);
2210                 _refLineControl->CreateNewManualContour();
2211
2212 //AD: Inicializar el mirroring con una linea ya pintada
2213         /*
2214                 double z = _refLineControl->GetZ();
2215
2216                 int imageDim[3];
2217                 image->GetDimensions(imageDim);
2218                 double x = (double) imageDim[0]/2;
2219                 double y1 = (double) (imageDim[1]/2)+15;
2220                 double y2 = (double) (imageDim[1]/2)-15;
2221
2222                 _refLineControl->AddPoint(x,y1,z);
2223                 _refLineControl->AddPoint(x,y2,z);
2224                 _refLineControl->SetCompleteCreation(true);
2225
2226                 _refLineModel->AddPoint(x,y1,z);
2227                 _refLineModel->AddPoint(x,y2,z);
2228                 _refLineModel->UpdateSpline();
2229
2230                 _refLineView->UpdateViewPoint(0);
2231                 _refLineView->UpdateViewPoint(1);
2232         */
2233
2234                 _refLineControl->SetActive(true);
2235                 _refLineView->RefreshContour();
2236         }
2237 }
2238
2239 //Hides the referenceLine
2240 void wxContourMainFrame::refLineHide()
2241 {
2242         if (_refLineControl!=NULL)
2243         {
2244                 if (_refLineControl->GetActive())
2245                 {
2246                         _refLineView->RemoveCompleteContourActor();
2247                         _refLineControl->SetEditable(false);
2248                         _refLineControl->SetActive(false);
2249
2250                         RefreshInterface();
2251                 }
2252         }
2253 }
2254
2255 //Shows the referenceLine
2256 void wxContourMainFrame::refLineShow()
2257 {
2258         if (_refLineControl!=NULL)
2259         {
2260                 if (_refLineControl->GetActive()==false)
2261                 {
2262                         wxVtkBaseView * viewer2D = _theViewPanel->getWxVtkBaseView();
2263
2264                         _refLineView->SetModel( _refLineModel );
2265                         _refLineView->SetWxVtkBaseView( viewer2D );
2266                         _refLineView->SetRange( 2 );
2267                         _refLineView->SetZ( 1200 );
2268
2269                         _refLineControl->SetModelView( _refLineModel , _refLineView );
2270                         vtkInteractorStyleBaseView* style = (vtkInteractorStyleBaseView*)viewer2D->GetInteractorStyleBaseView();
2271                         style->AddInteractorStyleMaracas( _refLineControl );
2272                         _refLineControl->CreateNewManualContour();
2273                         _refLineControl->SetActive(true);
2274                         _refLineView->RefreshContour();
2275
2276                         RefreshInterface();
2277                 }
2278         }
2279 }
2280
2281 void wxContourMainFrame::refLineChangeWidth(int width)
2282 {
2283         _refLineView->SetWidthLine(width);
2284         _refLineView->RefreshContour();
2285
2286         RefreshInterface();
2287 }
2288
2289
2290 void wxContourMainFrame::onMirror()
2291 {
2292         //AD:02-09
2293         std::vector<std::string> currentSelection = _theViewPanel->getSelectedObjects();
2294         std::vector<std::string> filterCurrentSelection;
2295
2296         std::vector<int> tempVector;
2297         _instantPanel->getInstant( tempVector );
2298     _performingOperation->reset();
2299         _performingOperation->setStartCommand( COPY );
2300         _performingOperation->setStartOperationInstantVector( tempVector );
2301         _performingOperation->setKeyNamesOperationElems( currentSelection );
2302
2303         char theStartCommand = _performingOperation->getStartCommand();
2304         if (  theStartCommand == COPY )
2305         {
2306                 //JCP 20-10-08 Undo redo implementation
2307                 saveState();
2308                 //JCP 20-10-08 Undo redo implementation
2309                 std::vector<int> tempVector;
2310                 _instantPanel->getInstant( tempVector );
2311                 _performingOperation->setEndOperationInstantVector ( tempVector );
2312                 std::vector<std::string> elems = _performingOperation->getKeyNamesOperationElems();
2313                 int i,size = elems.size();
2314                 for( i=0; i<size; i++ )
2315                 {
2316                         createMirrorContourOf( elems[i], tempVector, i>0 );
2317                 }
2318         }
2319
2320         //deleteContour( _refName );
2321         //_refName = "";
2322 }
2323
2324
2325 void wxContourMainFrame::showAxis(bool show)
2326 {
2327         _theViewPanel->SetVisibleAxis(show);
2328         _theViewPanel->Refresh();
2329 }
2330
2331
2332 void wxContourMainFrame::onRigidPressed(){
2333         std::vector<std::string> currentSelection = _theViewPanel->getSelectedObjects();
2334         int elementsSelected = currentSelection.size();
2335
2336         if ( elementsSelected >= 1 ){
2337                 //JCP 20-10-08 Undo redo implementation
2338                 saveState();
2339                 //JCP 20-10-08 Undo redo implementation
2340
2341                 std::vector<int> tempVector;
2342                 _instantPanel->getInstant( tempVector );
2343                 Instant instant(&tempVector);
2344
2345                 int i , size=currentSelection.size();
2346                 for ( i=0 ; i<size ; i++ )
2347                 {
2348                         kernelManager->changeContourOfManager(currentSelection[i], &instant);
2349                 } // i
2350         }
2351 }
2352
2353 void wxContourMainFrame::onWidthOfContour(double width){
2354
2355         _theViewPanel->removeSceneContours();
2356         _theViewPanel->SetWidthContour(width);
2357
2358         //_theViewPanel->getSceneManager()->SetWidthContour( width );
2359
2360         RefreshInterface();
2361 }
2362
2363 int wxContourMainFrame::getColorWindow()
2364 {
2365         /*
2366         double range[2];
2367         vtkImageData * img = getImageData();
2368         img->GetScalarRange(range);
2369
2370         std::cout<<"Val 1: "<<range[0]<<" Val 2: "<<range[1]<<std::endl;
2371
2372         return (int)range[1];
2373         */
2374         return _theViewPanel->getColorWindow();
2375 }
2376
2377 int wxContourMainFrame::getWindowLevel()
2378 {
2379         /*
2380         double range[2];
2381         vtkImageData * img = getImageData();
2382         img->GetScalarRange(range);
2383
2384         std::cout<<"Val 1: "<<range[0]<<" Val 2: "<<range[1]<<std::endl;
2385
2386         return (int)range[1];
2387         */
2388         return _theViewPanel->getWindowLevel();
2389 }
2390
2391 void wxContourMainFrame::onBrigthnessColorWindowLevel(int colorwindow,int windowlevel)
2392 {
2393         _theViewPanel->onBrigthnessColorWindowLevel(colorwindow, windowlevel);
2394
2395         RefreshInterface();
2396 }
2397
2398 void wxContourMainFrame::onInterpolation(bool interpolate)
2399 {
2400         _theViewPanel->onInterpolation(interpolate);
2401         RefreshInterface();
2402 }
2403
2404 void wxContourMainFrame::onBeforeAfterContour(bool before,bool after)
2405 {
2406         _theViewPanel->onBeforeAfterContour(before,after);
2407         RefreshInterface();
2408 }
2409
2410
2411 void wxContourMainFrame::onChangeInstant(std::string name,int actual)
2412 {
2413         _instantPanel->setConceptValue( name, actual );
2414 }
2415
2416
2417 void wxContourMainFrame::resetAppend()
2418 {
2419         kernelManager->resetAppend();
2420 }
2421
2422
2423 void wxContourMainFrame::onSpreadAdd()
2424 {
2425         std::vector<double> vecX;
2426         std::vector<double> vecY;
2427         std::vector<double> vecZ;
2428         _theViewPanel->GetPointsOfActualContour(&vecX , &vecY , &vecZ );
2429         std::vector<int> tempVector;
2430         _instantPanel->getInstant( tempVector );
2431         std::string val = kernelManager->onSpreadAdd(&vecX , &vecY , &vecZ, tempVector);
2432         interfMainPanel::getInstance()->appendStringSpread(val);
2433 }
2434
2435
2436 void wxContourMainFrame::onSpreadAddAll()
2437 {
2438 //EED02
2439         std::vector<int> tempVector;
2440         _instantPanel->getInstant( tempVector );
2441         int minZ,maxZ;
2442     minZ        = 0;
2443     maxZ        = interfMainPanel::getInstance()->GetImageDataSizeZ();
2444         int z;
2445         int sizeLstContourThings;
2446         for ( z=minZ ; z<=maxZ ; z++ )
2447         {
2448                 tempVector[1]=z;
2449                 Instant instant(&tempVector);
2450                 std::vector<ContourThing**> lstContourThings = kernelManager->getOutlinesAtInstant( &instant );
2451                 sizeLstContourThings = lstContourThings.size();
2452                 if (sizeLstContourThings>=1)
2453         {
2454             std::vector<double> vecX;
2455             std::vector<double> vecY;
2456             std::vector<double> vecZ;
2457             ContourThing **contourthing = lstContourThings[0];
2458                         manualBaseModel *cModel                         =  (*contourthing)->getModel();
2459                         int i,size = cModel->GetNumberOfPointsSpline();
2460                         double x,y,z;
2461                         for (i=0; i<size; i++)
2462                         {
2463                                 cModel->GetSpline_i_Point(i, &x, &y, &z);
2464                                 vecX.push_back(x);
2465                                 vecY.push_back(y);
2466                                 vecZ.push_back(z);
2467                         } // for i
2468             std::string val = kernelManager->onSpreadAdd(&vecX , &vecY , &vecZ, tempVector);
2469             interfMainPanel::getInstance()->appendStringSpread(val);
2470         }// if sizeLstContourThings
2471     } // for z
2472 }
2473
2474
2475 void wxContourMainFrame::onSpreadGo(int type)
2476 {
2477         //JCP 20-10-08 Undo redo implementation
2478         saveState();
2479         //JCP 20-10-08 Undo redo implementation
2480         wxBusyCursor wait;
2481         std::vector<double> vecCtrlPointX;
2482         std::vector<double> vecCtrlPointY;
2483         std::vector<double> vecCtrlPointZ;
2484         double  minZ,maxZ;
2485         int z;
2486
2487         std::vector<int> tempVector;
2488         _instantPanel->getInstant( tempVector );
2489 //              tempVector[1];
2490
2491         kernelManager->getMaxMinZ(&minZ,&maxZ);
2492 //JSTG_16-07-08_----------------------------------------------------------------
2493         //_contourPropagation->setInterpolationNumber(maxZ-minZ+1);
2494         kernelManager->CalculeSplinePropagation();
2495
2496         double          totalZ = maxZ-minZ+1;
2497         double          porcent;
2498         wxString        tmpString;
2499 //--------------------------------------------------------------------
2500         for ( z=(int)minZ ; z<=(int)maxZ ; z++ )
2501         {
2502                 porcent = 100.0* (z-minZ)/totalZ;
2503                 int numero = (int)(z-minZ+1)/(int)totalZ;
2504                 std::string stringtemp = "  "+kernelManager->intToString(porcent)+"%            "+kernelManager->intToString(numero)+"            "+kernelManager->intToString(z);
2505
2506                 interfMainPanel::getInstance()->setStringSpread(stringtemp);
2507
2508                 int typeofcontour = 1;
2509                 std::string theName;
2510                 manualBaseModel* manModelContour = kernelManager->GetPoints(z, type, &vecCtrlPointX,&vecCtrlPointY,&vecCtrlPointZ, theName,typeofcontour, tempVector);
2511
2512                 if( manModelContour!=NULL ){
2513                         double spc[3];//Si no hay imagen pero hay contornos que spacing se pone por default
2514                         this->_theViewPanel->getSpacing(spc);
2515                         //Adding the manualContourControler to interface objects structure
2516                         //Adding the manualViewContour to interface objects structure
2517                         //_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.
2518                         _theViewPanel->configureViewControlTo( theName, manModelContour,spc,typeofcontour ) ;
2519                 } // if addedModel
2520         }
2521         if(z > maxZ){
2522                 porcent = 100.0;
2523                 int numero = (int)(z-minZ+1)/(int)totalZ;
2524                 std::string stringtemp = "  "+kernelManager->intToString(porcent)+"%            "+kernelManager->intToString(numero)+"            "+kernelManager->intToString(z);
2525
2526                 interfMainPanel::getInstance()->setStringSpread(stringtemp);
2527         }// for z
2528         //RefreshInterface();
2529 }
2530
2531 void wxContourMainFrame::getInstantVector(std::vector<int>& tempVector)
2532 {
2533         _instantPanel->getInstant( tempVector );
2534 }
2535
2536 std::vector<std::string> wxContourMainFrame::getOutlinesName(int slide)
2537 {
2538         std::vector<int> tempVector;
2539         _instantPanel->getInstant(tempVector);
2540         //Asignation of slide number should be different ex by name
2541         tempVector[1]=slide;
2542         return kernelManager->getOutlinesNameAtInstant(tempVector);
2543 }
2544
2545
2546 void wxContourMainFrame::SetScalarRange(int grayRangeMin, int grayRangeMax)
2547 {
2548         _contourextractdata->SetScalarRange(grayRangeMin,grayRangeMax);
2549 }
2550
2551
2552 void wxContourMainFrame::onInformationContourLabels(int typeContourGroup,int selection,int minimumZ,int maximumZ,int grayRangeMin, int grayRangeMax)
2553 {
2554
2555         wxString tempString;
2556         int maxContourGroup     =       0;
2557
2558         _contourextractdata ->SetTypeOperation( typeContourGroup % 3 );
2559
2560         std::vector<manualBaseModel*> lstManConMod;
2561         std::vector<manualBaseModel*> lstManConModTmp;
2562         std::vector<manualBaseModel*> lstManConModExp;
2563         std::vector<double> pLstValue;
2564         std::vector<double> pLstValuePosX;
2565         std::vector<double> pLstValuePosY;
2566         std::vector<double> pLstValuePosZ;
2567
2568         int             resultSize;
2569         int             resultGrayRangeCount;
2570         double  resultMin;
2571         double  resultMax;
2572         double  resultAverage;
2573         double  resultStandardeviation;
2574
2575         std::vector<int> tempVector;
2576         _instantPanel->getInstant( tempVector );
2577
2578         int z;
2579         int ii,sizeLstContourThings;
2580
2581
2582         int minZ,maxZ;
2583         double totalZ;
2584         double porcent;
2585         wxString tmpString;
2586
2587
2588         if (selection==0 ) // actual slice
2589         {
2590                 int actualSlice = tempVector[1];
2591                 minZ    = actualSlice;
2592                 maxZ    = actualSlice;
2593         }       else  {  // slice range
2594                 minZ    = minimumZ;
2595                 maxZ    = maximumZ;
2596         }
2597
2598
2599         totalZ  = maxZ-minZ+1;
2600
2601         _contourextractdata->InitVolumeStatistics();
2602
2603 // For each slice..
2604         for ( z=minZ ; z<=maxZ ; z++ )
2605         {
2606
2607                 porcent = 100.0* (z-minZ)/totalZ;
2608                 tmpString.Printf(_T("  %d %c            %d/%d             %d"), (int)porcent , 37 , z-minZ+1, (int)totalZ ,z);
2609
2610                 interfMainPanel::getInstance()->setStringInfoPanel(tmpString);
2611                 //_staticTextInformation->SetLabel(tmpString);
2612
2613                 //Extraction data from contours of each slice
2614                 _contourextractdata->SetZtoBeAnalys(z);
2615
2616                 tempVector[1]=z;
2617                 Instant instant(&tempVector);
2618                 std::vector<ContourThing**> lstContourThings = kernelManager->getOutlinesAtInstant( &instant );
2619                 sizeLstContourThings = lstContourThings.size();
2620
2621                 lstManConMod.clear();
2622                 for (ii=0 ; ii<sizeLstContourThings ; ii++)
2623                 {
2624                         ContourThing **contourthing = lstContourThings[ii];
2625                         lstManConMod.push_back( (*contourthing)->getModel() );
2626                 }
2627
2628                 lstManConModExp =  kernelManager->ExploseEachModel( lstManConMod );
2629
2630                 tempString.Printf(_T("%d - %d"),z, sizeLstContourThings);
2631                 interfMainPanel::getInstance()->setRowLabelInfoPanel(z, tempString);
2632                 //_grid->SetRowLabelValue(z, tempString );
2633 //EED004
2634                 int iContourGroup,sizeContourGroup;
2635                 if (typeContourGroup==3) // contour separete
2636                 {
2637                         sizeContourGroup=lstManConModExp.size();
2638                         if ( maxContourGroup<sizeContourGroup )
2639                         {
2640                                 maxContourGroup=sizeContourGroup;
2641                         }
2642                 } else {  // contour AND OR XOR
2643                         sizeContourGroup=1;
2644                         maxContourGroup=1;
2645                 }
2646
2647                 int tmpIntA;
2648
2649                 for( iContourGroup=0 ; iContourGroup<sizeContourGroup ; iContourGroup++ ){
2650                         lstManConModTmp.clear();
2651
2652
2653
2654                         if (typeContourGroup==3) // contour separete
2655                         {
2656                                 lstManConModTmp.push_back( lstManConModExp[iContourGroup]);
2657                         } else {  // contour AND OR XOR
2658                                 lstManConModTmp = lstManConModExp;
2659                         }
2660
2661                         _contourextractdata->SetLstManualContourModel( lstManConModTmp );
2662                         _contourextractdata->SetScalarRange(grayRangeMin,grayRangeMax);
2663
2664                         pLstValue.clear();
2665                         pLstValuePosX.clear();
2666                         pLstValuePosY.clear();
2667                         pLstValuePosZ.clear();
2668
2669
2670                         int numberOfPixels;
2671                         _contourextractdata->GetValuesInsideCrown(  &numberOfPixels,
2672                                                                                                                 &pLstValue,
2673                                                                                                                 &pLstValuePosX,
2674                                                                                                                 &pLstValuePosY,
2675                                                                                                                 &pLstValuePosZ);
2676
2677                         resultSize=numberOfPixels;
2678                         // Statistics of each slice.
2679                         _contourextractdata->Statistics( &pLstValue,
2680                                                                                         grayRangeMin,
2681                                                                                         grayRangeMax,
2682                                                                                         &resultGrayRangeCount,
2683                                                                                         &resultSize,
2684                                                                                         &resultMin,
2685                                                                                         &resultMax,
2686                                                                                         &resultAverage,
2687                                                                                         &resultStandardeviation);
2688
2689                         if (interfMainPanel::getInstance()->getNumberColsInformationPanel()<_numberOfVariablesStatistics*(iContourGroup+1)  )
2690                         {
2691                                 interfMainPanel::getInstance()->appendColsInformationPanel(_numberOfVariablesStatistics);
2692                         }
2693
2694                         tmpIntA=_numberOfVariablesStatistics*iContourGroup ;
2695
2696                         tempString.Printf(_T("%d"),numberOfPixels);
2697
2698                         interfMainPanel::getInstance()->setCellValueInfoPanel(z, tmpIntA, tempString);
2699
2700                         tempString.Printf(_T("%d"),resultGrayRangeCount);
2701                         interfMainPanel::getInstance()->setCellValueInfoPanel(z, tmpIntA+1, tempString);
2702
2703                         tempString.Printf(_T("%f"),resultMin);
2704                         interfMainPanel::getInstance()->setCellValueInfoPanel(z, tmpIntA+2, tempString);
2705
2706                         tempString.Printf(_T("%f"),resultMax);
2707                         interfMainPanel::getInstance()->setCellValueInfoPanel(z, tmpIntA+3, tempString);
2708
2709                         tempString.Printf(_T("%f"),resultAverage);
2710                         interfMainPanel::getInstance()->setCellValueInfoPanel(z, tmpIntA+4, tempString);
2711
2712                         tempString.Printf(_T("%f"),resultStandardeviation);
2713                         interfMainPanel::getInstance()->setCellValueInfoPanel(z, tmpIntA+5, tempString);
2714
2715
2716                 } // for iContourGroup
2717         } // for z
2718
2719         // Print Volume Statistics
2720
2721
2722         int             vol_rCountRange;
2723         int             vol_rsize;
2724         double  vol_minValue;
2725         double  vol_maxValue;
2726         double  vol_average;
2727         double  vol_standardeviation;
2728
2729         if (selection!=0 ) // actual slice
2730         {
2731
2732                 _contourextractdata->GetVolumeStatistics(&vol_rCountRange, &vol_rsize,
2733                                                                                                  &vol_minValue, &vol_maxValue,
2734                                                                                                  &vol_average, &vol_standardeviation);
2735
2736                 interfMainPanel::getInstance()->setRowLabelInfoPanel(maxZ+2, _T("Total:"));
2737
2738                 tempString.Printf(_T("%d"),vol_rsize);
2739                 interfMainPanel::getInstance()->setCellValueInfoPanel(maxZ+2, 0, tempString);
2740
2741                 tempString.Printf(_T("%d"),vol_rCountRange);
2742                 interfMainPanel::getInstance()->setCellValueInfoPanel(maxZ+2, 1, tempString);
2743
2744                 tempString.Printf(_T("%f"),vol_minValue);
2745                 interfMainPanel::getInstance()->setCellValueInfoPanel(maxZ+2, 2, tempString);
2746
2747                 tempString.Printf(_T("%f"),vol_maxValue);
2748                 interfMainPanel::getInstance()->setCellValueInfoPanel(maxZ+2, 3, tempString);
2749
2750                 tempString.Printf(_T("%f"),vol_average);
2751                 interfMainPanel::getInstance()->setCellValueInfoPanel(maxZ+2, 4, tempString);
2752
2753                 tempString.Printf(_T("%f"),vol_standardeviation);
2754                 interfMainPanel::getInstance()->setCellValueInfoPanel(maxZ+2, 5, tempString);
2755         }
2756         //-----------------------------------------
2757
2758         int iTitleGroup;
2759         wxString tmpTitleString;
2760         int tmpIntB;
2761         for ( iTitleGroup=0 ; iTitleGroup<maxContourGroup ; iTitleGroup++ )
2762         {
2763                 tmpIntB =_numberOfVariablesStatistics*iTitleGroup;
2764                 tmpTitleString.Printf(_T("%d-Size Data"),iTitleGroup);
2765                 interfMainPanel::getInstance()->setColLableInfoPanel(tmpIntB + 0, tmpTitleString);
2766
2767                 interfMainPanel::getInstance()->setColLableInfoPanel(tmpIntB + 0, tmpTitleString );
2768                 interfMainPanel::getInstance()->setColLableInfoPanel( tmpIntB + 1, _T("Size Range") );
2769                 interfMainPanel::getInstance()->setColLableInfoPanel( tmpIntB + 2, _T("Min") );
2770                 interfMainPanel::getInstance()->setColLableInfoPanel( tmpIntB + 3, _T("Max") );
2771                 interfMainPanel::getInstance()->setColLableInfoPanel( tmpIntB + 4, _T("Average") );
2772                 interfMainPanel::getInstance()->setColLableInfoPanel( tmpIntB + 5, _T("St.Dev.") );
2773                 interfMainPanel::getInstance()->setColLableInfoPanel( tmpIntB + 6, _T(" ") );
2774         }// for title
2775         interfMainPanel::getInstance()->setStringInfoPanel( _T("") );
2776 }
2777
2778 //AD: 29-05-09
2779 void wxContourMainFrame::onSaveResults(std::string directory,std::string namefile, std::string filename,
2780         int typeContourGroup, int selection, int minZ, int maxZ, bool XYZValues, bool contourImage, bool statistics)
2781 {
2782         if (XYZValues)
2783         {
2784                 SaveValuesXYZ( directory , namefile, typeContourGroup );
2785         }
2786
2787         if (contourImage)
2788         {
2789                 vtkImageData * mask;
2790                 vtkImageData * value;
2791                 this->getMaskValue(&mask, &value, typeContourGroup,selection,minZ,maxZ);
2792                 this->SaveImageResult( directory , namefile, mask, value);
2793         }
2794
2795         if (statistics)
2796         {
2797                 std::ostringstream name;
2798                 name << filename << ".xls";
2799
2800
2801                 FILE *pFile=fopen(name.str().c_str(),"w+");
2802
2803
2804                 wxString tmpString;
2805                 int i,j,maxX;
2806
2807 //              int sizeZ = _theViewPanel->GetImageDataSizeZ();
2808 //              int maxY=sizeZ+2;
2809
2810                 maxX= interfMainPanel::getInstance()->getNumberColsInformationPanel();//this->_grid->GetNumberCols();
2811
2812                 // -- Title --
2813                 int iTitle,sizeTitle = (maxX / _numberOfVariablesStatistics);
2814                 for ( iTitle=0; iTitle<sizeTitle ; iTitle++)
2815                 {
2816                                 // fprintf(pFile,"-- \t %d-Size \t SizeRange \t Min \t Max \t Ave \t StDv \t" , iTitle,tmpString.c_str() );
2817                                 fprintf(pFile,"slice\t %d-Size \t SizeRange \t Min \t Max \t Ave \t StDv \t" , iTitle );
2818                 }
2819                 fprintf(pFile,"\n\n" );
2820
2821
2822
2823                 if (selection==0 ) // actual slice
2824                 {
2825                         std::vector<int> tempVector;
2826                         _instantPanel->getInstant( tempVector );
2827                         int actualSlice = tempVector[1];
2828                         minZ    = actualSlice;
2829                         maxZ    = actualSlice;
2830                 }
2831
2832                 // Stadistics...
2833                 for ( j=minZ; j<=maxZ ; j++)
2834                 {
2835                         fprintf(pFile,"%d\t" , j );
2836                         for (i=0 ; i<maxX ; i++){
2837                                 tmpString = interfMainPanel::getInstance()->getCellValue(j, i);//_grid->GetCellValue( j , i );
2838                                 fprintf(pFile,"%s\t" , (const char *)(tmpString.mb_str()) );
2839                         } // for i
2840                         fprintf(pFile,"\n"  );
2841                 } // for j
2842
2843
2844                 // Total of stadistics.....
2845                 if (selection!=0)
2846                 {
2847                         fprintf(pFile,"\n Total:\t"  );
2848                         for (i=0 ; i<maxX ; i++){
2849                                 tmpString = interfMainPanel::getInstance()->getCellValue(maxZ+2, i);//_grid->GetCellValue( maxZ+2 , i );
2850                                 fprintf(pFile,"%s\t" , (const char *)(tmpString.mb_str()) );
2851                         } // for i
2852                         fprintf(pFile,"\n"  );
2853                 }
2854
2855                 fclose(pFile);
2856         }
2857 }
2858
2859 //AD: 29-05-09
2860 void wxContourMainFrame::SaveValuesXYZ(std::string directory,std::string namefile,int typeContourGroup)
2861 {
2862         wxBusyCursor wait;
2863
2864         //int typeContourGroup = this->_radiolstboxContourGroup->GetSelection();
2865         _contourextractdata ->SetTypeOperation( typeContourGroup % 3 );
2866
2867         std::vector<manualBaseModel*> lstManConMod;
2868         std::vector<manualBaseModel*> lstManConModTmp;
2869         std::vector<manualBaseModel*> lstManConModExp;
2870         std::vector<double> pLstValue;
2871         std::vector<double> pLstValuePosX;
2872         std::vector<double> pLstValuePosY;
2873         std::vector<double> pLstValuePosZ;
2874
2875         std::vector<int> tempVector;
2876         _instantPanel->getInstant( tempVector );
2877
2878         int sizeZ = _theViewPanel->getSceneManager()->GetImageDataSizeZ();
2879         int z;
2880         int ii,sizeLstContourThings;
2881
2882
2883         int minZ,maxZ;
2884         double totalZ;
2885         double porcent;
2886         wxString tmpString;
2887         minZ    = 0;// _mbarrange->GetStart();
2888         maxZ    = sizeZ;//_mbarrange->GetEnd();
2889         totalZ  = maxZ-minZ+1;
2890
2891
2892 // For each slice..
2893         for ( z=0 ; z<sizeZ ; z++)
2894         {
2895
2896                 porcent = 100.0* (z-minZ)/totalZ;
2897
2898                 tmpString.Printf(_T("Saving Values"));
2899                 tmpString.Printf(_T("  %d %c            %d/%d             %d"), (int)porcent , 37 , z-minZ+1, (int)totalZ ,z);
2900                 interfMainPanel::getInstance()->setStringInfoPanel(tmpString);
2901                 //_staticTextInformation->SetLabel(tmpString);
2902
2903
2904                 //Extraction data from contours of each slice
2905                 _contourextractdata->SetZtoBeAnalys( z);
2906
2907                 tempVector[1]=z;
2908                 Instant instant(&tempVector);
2909                 std::vector<ContourThing**> lstContourThings = kernelManager->getOutlinesAtInstant(&instant);//this->_modelManager->getOutlinesAtInstant( &instant );
2910                 sizeLstContourThings = lstContourThings.size();
2911
2912                 lstManConMod.clear();
2913                 for (ii=0 ; ii<sizeLstContourThings ; ii++)
2914                 {
2915                         ContourThing **contourthing = lstContourThings[ii];
2916                         lstManConMod.push_back( (*contourthing)->getModel() );
2917                 }
2918                 lstManConModExp =  kernelManager->ExploseEachModel( lstManConMod );
2919
2920
2921 //EED004
2922
2923                 int iContourGroup,sizeContourGroup;
2924                 if (typeContourGroup==3) // contour separete
2925                 {
2926                         sizeContourGroup=lstManConModExp.size();
2927                 } else {  // contour AND OR XOR
2928                         sizeContourGroup=1;
2929                 }
2930
2931                 for( iContourGroup=0 ; iContourGroup<sizeContourGroup ; iContourGroup++ ){
2932                         lstManConModTmp.clear();
2933                         if (typeContourGroup==3) // contour separete
2934                         {
2935                                 lstManConModTmp.push_back( lstManConModExp[iContourGroup]);
2936                         } else {  // contour AND OR XOR
2937                                 lstManConModTmp = lstManConModExp;
2938                         }
2939
2940                         _contourextractdata->SetLstManualContourModel( lstManConModTmp );
2941
2942                         pLstValue.clear();
2943                         pLstValuePosX.clear();
2944                         pLstValuePosY.clear();
2945                         pLstValuePosZ.clear();
2946                         int numberOfPixels;
2947                         _contourextractdata->GetValuesInsideCrown(      &numberOfPixels,
2948                                                                                                                 &pLstValue,
2949                                                                                                                 &pLstValuePosX,
2950                                                                                                                 &pLstValuePosY,
2951                                                                                                                 &pLstValuePosZ);
2952
2953                         std::string temp = directory + "/" + namefile + "-slice";
2954                         temp = temp + kernelManager->intToString(z) + "-cont" + kernelManager->intToString(iContourGroup);
2955                         temp = temp + ".txt";
2956
2957                         // LG 14/01/09 : using crea
2958                         wxString filename = crea::std2wx(temp);
2959                         /*filename.Printf(_T("%s"),directory.c_str());
2960                         filename.append(_T("\\"));
2961                         filename.append(_T("%s"),namefile.c_str());
2962                         filename.append(_T("-slice"));
2963                         filename.append(_T("%d"),z);
2964                         filename.append(_T("-cont"));
2965                         filename.append(_T("%d"),iContourGroup);
2966                         filename.append(_T(".txt"));*/
2967                         //                      filename.Printf(temp.c_str());
2968
2969
2970
2971                         FILE *pFile=fopen((const char *)filename.mb_str(),"w+");
2972                         fprintf(pFile,"value \t x \t y \t z\n"  );
2973                         int iLstValue,sizeLstValue=pLstValue.size();
2974                         for (iLstValue=0 ; iLstValue<sizeLstValue ; iLstValue++ )
2975                         {
2976                                 fprintf(pFile,"%f\t %f\t %f\t %f\n", (float)pLstValue[iLstValue] , (float)pLstValuePosX[iLstValue], (float)pLstValuePosY[iLstValue], (float)z );
2977                         }
2978                         fclose(pFile);
2979                 } // for  iContourGroup
2980         } // for z
2981         interfMainPanel::getInstance()->setStringInfoPanel(_T(""));
2982         //_staticTextInformation->SetLabel( _T("") );
2983
2984 }
2985
2986 void wxContourMainFrame::getMaskValue(vtkImageData ** mask,vtkImageData ** value,int typeContourGroup, int selection, int minZ, int maxZ){
2987         wxBusyCursor wait;
2988
2989         //int typeContourGroup = this->_radiolstboxContourGroup->GetSelection();
2990         if (typeContourGroup==3)
2991         {
2992                 typeContourGroup=1;
2993         }
2994         _contourextractdata ->SetTypeOperation( typeContourGroup % 3 );
2995
2996         std::vector<manualBaseModel*> lstManConMod;
2997         std::vector<manualBaseModel*> lstManConModTmp;
2998         std::vector<manualBaseModel*> lstManConModExp;
2999
3000         std::vector<int> tempVector;
3001         _instantPanel->getInstant( tempVector );
3002
3003     vtkImageData *imagedata = _theViewPanel->getImageData();
3004         int ext[6];
3005         imagedata->GetExtent(ext);
3006         int sizeZimage = ext[5]-ext[4]+1;
3007         int z;
3008         int ii,sizeLstContourThings;
3009
3010         double totalZ;
3011         double porcent;
3012
3013         wxString tmpString;
3014
3015
3016         if (selection==0 ) // actual slice
3017         {
3018                 int actualSlice = tempVector[1];
3019                 minZ    = actualSlice;
3020                 maxZ    = actualSlice;
3021         }
3022
3023         totalZ  = maxZ-minZ;
3024
3025
3026         // cleanning image before range
3027         for (z=0; z<minZ; z++){
3028                 _contourextractdata->ResetImageResult(z);
3029         }
3030         // cleanning image after range
3031         for (z=maxZ+1; z<sizeZimage; z++){
3032                 _contourextractdata->ResetImageResult(z);
3033         }
3034
3035
3036 // For each slice..
3037         for ( z=minZ ; z<=maxZ ; z++)
3038         {
3039
3040                 porcent = 100.0* (z-minZ)/totalZ;
3041                 tmpString.Printf(_T("Saving Values"));
3042                 tmpString.Printf(_T("%d %c            %d/%d             %d"), (int)porcent , 37 , z-minZ+1, (int)totalZ ,z);
3043                 interfMainPanel::getInstance()->setStringInfoPanel(tmpString);
3044
3045                 //Extraction data from contours of each slice
3046                 _contourextractdata->SetZtoBeAnalys( z);
3047
3048                 tempVector[1]=z;
3049                 Instant instant(&tempVector);
3050                 std::vector<ContourThing**> lstContourThings = kernelManager->getOutlinesAtInstant( &instant );
3051                 sizeLstContourThings = lstContourThings.size();
3052
3053                 lstManConMod.clear();
3054                 for (ii=0 ; ii<sizeLstContourThings ; ii++)
3055                 {
3056                         ContourThing **contourthing = lstContourThings[ii];
3057                         lstManConMod.push_back( (*contourthing)->getModel() );
3058                 }
3059                 lstManConModExp =  kernelManager->ExploseEachModel( lstManConMod );
3060
3061
3062                 int iContourGroup,sizeContourGroup;
3063                 if (typeContourGroup==3) // contour separete
3064                 {
3065                         sizeContourGroup=lstManConModExp.size();
3066                 } else {  // contour AND OR XOR
3067                         sizeContourGroup=1;
3068                 }
3069
3070                 for( iContourGroup=0 ; iContourGroup<sizeContourGroup ; iContourGroup++ ){
3071                         lstManConModTmp.clear();
3072                         if (typeContourGroup==3) // contour separete
3073                         {
3074                                 lstManConModTmp.push_back( lstManConModExp[iContourGroup]);
3075                         } else {  // contour AND OR XOR
3076                                 lstManConModTmp = lstManConModExp;
3077                         }
3078
3079                         _contourextractdata->SetLstManualContourModel( lstManConModTmp );
3080                         _contourextractdata->CalculateImageResult(); // with actual Z
3081
3082                 } // for  iContourGroup
3083         } // for z
3084
3085         (*value) = _contourextractdata->GetVtkImageValueResult();
3086         (*mask)  = _contourextractdata->GetVtkImageMaskResult();
3087
3088 }
3089
3090 std::string wxContourMainFrame::GetStringTypeImage( vtkImageData* image)
3091 {
3092         std::string result="";
3093         if ( image->GetScalarType()==VTK_CHAR )
3094         {
3095                 result="CHAR";
3096         } else if ( image->GetScalarType()==VTK_UNSIGNED_CHAR ){
3097                 result="UCHAR";
3098         } else if ( image->GetScalarType()==VTK_FLOAT ){
3099                 result="FLOAT";
3100         } else if ( image->GetScalarType()==VTK_DOUBLE ){
3101                 result="DOUBLE";
3102         } else if ( image->GetScalarType()==VTK_INT ){
3103                 result="INT";
3104         } else if ( image->GetScalarType()==VTK_UNSIGNED_INT ){
3105                 result="UINT";
3106         } else if ( image->GetScalarType()==VTK_SHORT ){
3107                 result="SHORT";
3108         } else if ( image->GetScalarType()==VTK_UNSIGNED_SHORT ){
3109                 result="USHORT";
3110         } else if ( image->GetScalarType()==VTK_LONG ){
3111                 result="LONG";
3112         } else if ( image->GetScalarType()==VTK_UNSIGNED_LONG ){
3113                 result="ULONG";
3114         }
3115         return result;
3116 }
3117
3118 void wxContourMainFrame::SaveImageResult(std::string directory,std::string namefile, vtkImageData* mask,vtkImageData* value)
3119 {
3120         std::string stringType;
3121         double spc[3];
3122         kernelManager->GetSpacing(spc,0);   // returns the spacing of the first image
3123         stringType              = GetStringTypeImage(value);
3124         std::string temp = directory + "/" + namefile + "-image-Value-"+stringType+".mhd";
3125
3126         wxString filename = crea::std2wx(temp);
3127
3128 // Image Value
3129         
3130         vtkImageChangeInformation *valueChInfo = vtkImageChangeInformation::New();
3131 //EED 2017-01-01 Migration VTK7
3132 #if VTK_MAJOR_VERSION <= 5
3133         valueChInfo->SetInput(value);
3134 #else
3135         valueChInfo->SetInputData(value);
3136 #endif
3137         valueChInfo->SetSpacingScale(spc);      
3138         valueChInfo->Update();  
3139         vtkMetaImageWriter *writerValueImage = vtkMetaImageWriter::New( );
3140
3141 //EED 2017-01-01 Migration VTK7
3142 #if VTK_MAJOR_VERSION <= 5
3143         writerValueImage->SetInput( valueChInfo->GetOutput() );
3144 #else
3145         writerValueImage->SetInputData( valueChInfo->GetOutput() );
3146 #endif
3147         writerValueImage->SetFileName( (const char *)filename.mb_str() );
3148         writerValueImage->SetFileDimensionality( 3 );
3149         writerValueImage->SetCompression(false);
3150         writerValueImage->Write( );
3151
3152 // Image Mask
3153         stringType              = GetStringTypeImage(mask);
3154         temp = directory + "/" + namefile + "-image-Mask-"+stringType+".mhd";
3155
3156         // LG 14/01/09 : using crea
3157         filename = crea::std2wx(temp);
3158         //      filename.Printf(_T(temp.c_str()));
3159
3160
3161         vtkImageChangeInformation *maskChInfo = vtkImageChangeInformation::New();
3162 //EED 2017-01-01 Migration VTK7
3163 #if VTK_MAJOR_VERSION <= 5
3164         maskChInfo->SetInput(mask);
3165 #else
3166         maskChInfo->SetInputData(mask);
3167 #endif
3168         maskChInfo->SetSpacingScale(spc);       
3169         maskChInfo->Update();   
3170         vtkMetaImageWriter *writerMaskImage = vtkMetaImageWriter::New( );
3171
3172 //EED 2017-01-01 Migration VTK7
3173 #if VTK_MAJOR_VERSION <= 5
3174         writerMaskImage->SetInput( maskChInfo->GetOutput() );
3175 #else
3176         writerMaskImage->SetInputData( maskChInfo->GetOutput() );
3177 #endif
3178
3179         writerMaskImage->SetFileName( (const char *)filename.mb_str() );
3180         writerMaskImage->SetFileDimensionality( 3 );
3181         writerMaskImage->SetCompression(false);
3182         writerMaskImage->Write( );
3183
3184         interfMainPanel::getInstance()->setStringInfoPanel( _T("") );
3185
3186 }
3187
3188
3189
3190 void wxContourMainFrame::onChangeInstantInstantPanel(std::string name,int value, int minshow, int maxshow){
3191         if( name.compare( _theViewPanel->getVerticalConceptName() ) == 0){
3192                 _theViewPanel->setActualVertical( value);
3193         }
3194         else if( name.compare( _theViewPanel->getHorizontalConceptName() ) == 0|| _instantPanel->getIfConceptCheckedAt( name, 0 ) )     {
3195                 _theViewPanel->setHorizontalConcept( name, minshow, maxshow, minshow, maxshow, value);
3196         }
3197
3198         changeInstant();
3199 }
3200
3201 void wxContourMainFrame::onSnakePressed(){
3202         std::vector<double> vecX;
3203         std::vector<double> vecY;
3204         std::vector<double> vecZ;
3205         _theViewPanel->GetPointsOfActualContour( &vecX , &vecY , &vecZ );
3206
3207         if (vecX.size()!=0){
3208                 std::vector<int> tempVector;
3209                 _instantPanel->getInstant( tempVector );
3210                 int i,size=vecZ.size();
3211                 int actualSlice = tempVector[1];
3212                 for ( i=0 ; i<size ; i++ )
3213                 {
3214                         vecZ[i] = actualSlice;
3215                 } // for
3216
3217                 wxDialog* dialog = new wxDialog(this, -1, wxString(_T("Snake")));
3218                 wxPanel* panel = new wxPanel(dialog,-1);
3219                 //              wxStaticText* sttext = new wxStaticText(panel, -1, wxString(_T("Panel para snake")));
3220          new wxStaticText(panel, -1, wxString(_T("Panel para snake")));
3221                 dialog->ShowModal();
3222         } // if
3223
3224 }
3225
3226 void wxContourMainFrame::saveFileWithContoursAutomatique(){
3227         std::string filename = kernelManager->getCurrentFileName();
3228         if(filename.compare("")!=0){
3229                 saveFileWithContours(filename);
3230         }else{
3231                 onSave();
3232         }
3233 }
3234 void wxContourMainFrame::ShowToolsPanel(bool show){
3235         _pannew->Show(show);
3236 }
3237
3238
3239
3240 void wxContourMainFrame::SetContourGroup(int contourGroup)
3241 {
3242         _contourGroup = contourGroup;
3243 }
3244
3245
3246 wxPanel *wxContourMainFrame::getMaskImageViewPanel(wxWindow *parent)
3247 {
3248  
3249         if      (_viewMaskImagePanel==NULL)
3250         {
3251                 _contourextractdata = new ContourExtractData(true);
3252                 _contourextractdata->SetImage( _theViewPanel->getImageData() );
3253 //              double range[2];
3254 //              _theViewPanel->getImageData()->GetScalarRange(range);
3255                 //int min = (int)floor (range[0]);
3256                 //int max = (int)ceil (range[1]);
3257
3258 //EED 2017-12-17
3259                 int min = 254;
3260                 int max = 256;
3261
3262                 _viewMaskImagePanel = new ThresholdImageViewPanel( parent, -1, -1 , -1,-1,  0);
3263                 _viewMaskImage = new ThresholdImageView();
3264                 _viewMaskImage->SetImage( _contourextractdata->GetVtkImageMaskResult() );
3265                 _viewMaskImage->SetminMaxValue( min, max);
3266                 _viewMaskImage->SetBaseColor( 0,0,1 );
3267
3268
3269                 std::vector<int> colorbarposition;
3270                 colorbarposition.push_back( -999 );
3271                 colorbarposition.push_back( -999 );
3272                 _viewMaskImage->SetColorBarPosition( colorbarposition );
3273                 double spc[3];
3274                 _viewMaskImage->SetSpcBase( _theViewPanel->getImageData()->GetSpacing() );
3275                 _viewMaskImage->SetNewSpacingLayer( _theViewPanel->getImageData()->GetSpacing() );
3276
3277                 _viewMaskImagePanel->SetThresholdImageView( _viewMaskImage );
3278                 _viewMaskImage->SetwxVtkBaseView( _theViewPanel->getWxVtkBaseView() );
3279                 _viewMaskImage->onThresholdChangeOpacity( 25 );
3280         }
3281         return _viewMaskImagePanel;
3282 }
3283
3284
3285 wxPanel *wxContourMainFrame::getColorLayerImageViewPanel(wxWindow *parent)
3286 {
3287         if      (_viewColorLayerImagePanel==NULL)
3288         {
3289                 double range[2];
3290                 _theViewPanel->getImageData()->GetScalarRange(range);
3291                 int min = (int)floor (range[0]);
3292                 int max = (int)ceil (range[1]);
3293                 _viewColorLayerImagePanel = new ColorLayerImageViewPanel( parent, min, max, 100, 1);
3294                 _viewColorLayerImagePanel->GetColorLayerImageViewManager()->SetwxVtkBaseView( 0 , _theViewPanel->getWxVtkBaseView() );
3295         //    std::vector<double> range = bbGetInputlstRangeForColorBar();
3296         //    clivp->GetColorLayerImageViewManager()->SetRangeForColorBar( range );
3297                 std::vector<int> colorbarposition;
3298                 colorbarposition.push_back( 50 );
3299                 colorbarposition.push_back( 105 );
3300                 _viewColorLayerImagePanel->GetColorLayerImageViewManager()->SetColorBarPosition( colorbarposition );
3301         //    std::vector<double> base_color;
3302         //    _viewColorLayerImagePanel->GetColorLayerImageViewManager()->SetBaseColors( base_color );
3303         //    std::vector<double> grey_level_boundaries;
3304         //    clivp->GetColorLayerImageViewManager()->SetGreyLevelBoundaries( grey_level_boundaries );
3305                 std::vector<double> transparence_level_boundaries;
3306                 transparence_level_boundaries.push_back(0);
3307                 _viewColorLayerImagePanel->GetColorLayerImageViewManager()->SetBaseTransparence( transparence_level_boundaries );
3308                 _viewColorLayerImagePanel->GetColorLayerImageViewManager()->SetPlainOrGradientColor( false );
3309 //              _viewColorLayerImagePanel->SetFittingMode( 3 );
3310         }
3311         return _viewColorLayerImagePanel;
3312 }
3313
3314
3315 wxPanel *wxContourMainFrame::getThresholdImageViewPanel(wxWindow *parent)
3316 {
3317         if      (_viewThresholdImagePanel==NULL)
3318         {
3319                 double range[2];
3320                 _theViewPanel->getImageData()->GetScalarRange(range);
3321                 int min = (int)floor (range[0]);
3322                 int max = (int)ceil (range[1]);
3323                 int start= (max+min)/2 - (max-min)*0.25; 
3324                 int end= (max+min)/2 + (max-min)*0.25; 
3325                 _viewThresholdImagePanel = new ThresholdImageViewPanel( parent, min, max, start, end , 1);
3326                 _viewThresholdImage = new ThresholdImageView();
3327                 _viewThresholdImage->SetminMaxValue(start,end);
3328                 _viewThresholdImage->SetImage( _theViewPanel->getImageData() );
3329                 std::vector<int> colorbarposition;
3330                 colorbarposition.push_back( 10 );
3331                 colorbarposition.push_back( 105 );
3332                 _viewThresholdImage->SetColorBarPosition( colorbarposition );
3333                 double spc[3];
3334                 _viewThresholdImage->SetSpcBase( _theViewPanel->getImageData()->GetSpacing() );
3335                 _viewThresholdImage->SetNewSpacingLayer( _theViewPanel->getImageData()->GetSpacing() );
3336
3337                 _viewThresholdImage->SetBaseColor( 1,0,0 );
3338                 _viewThresholdImagePanel->SetThresholdImageView( _viewThresholdImage );
3339                 _viewThresholdImage->SetwxVtkBaseView( _theViewPanel->getWxVtkBaseView() );
3340                 _viewThresholdImage->onThresholdChangeOpacity( 25 );
3341                 RefreshInterface();
3342         }
3343         return _viewThresholdImagePanel;
3344 }
3345
3346 //CMRU 17-08-09-----------------------------------------------------------------------------------------------
3347 int wxContourMainFrame::getType ()
3348 {
3349         int tipo = 0;
3350         std::vector<std::string> currentSelection = _theViewPanel->getSelectedObjects();
3351
3352         if(!currentSelection.empty())
3353         {
3354                 std::string cloneName = currentSelection [0];
3355                 manualBaseModel * manualModel = kernelManager->getOutlineByKeyName(cloneName);
3356                 tipo = manualModel-> GetTypeModel();
3357         }
3358         return tipo;
3359 }
3360
3361 double wxContourMainFrame::getContourSizeInPixels()
3362 {
3363         double contourSize = 0;
3364
3365         std::vector<std::string> currentSelection = _theViewPanel->getSelectedObjects();        if(!currentSelection.empty())
3366         if(!currentSelection.empty())
3367         {
3368                 std::string cloneName = currentSelection [0];
3369
3370                 manualBaseModel * manualModel = kernelManager->getOutlineByKeyName(cloneName);//_modelManager->getOutlineByKeyName( cloneName )->getModel();
3371
3372 // EED 2017-05-30
3373 //              contourSize = manualModel->GetPathSize();
3374                 double spc[3];
3375                 spc[0]=1; 
3376                 spc[1]=1; 
3377                 spc[2]=1; 
3378                 contourSize = manualModel->GetPathSize( spc );
3379         }
3380         return contourSize;
3381 }
3382
3383 manualBaseModel * wxContourMainFrame::getContour ()
3384 {
3385         std::vector<std::string> currentSelection = _theViewPanel->getSelectedObjects();
3386
3387         if(!currentSelection.empty())
3388         {
3389                 std::string cloneName = currentSelection [0];
3390                 manualBaseModel * manualModel = kernelManager->getOutlineByKeyName(cloneName);//_modelManager->getOutlineByKeyName( cloneName )->getModel();
3391                 return manualModel;
3392         }
3393         return NULL;
3394 }
3395 void wxContourMainFrame::onPrintLabel (wxString label, manualBaseModel* manualModel)
3396 {
3397         std::string labelAscii(label.ToAscii());
3398         int pos = labelAscii.find(" ");
3399
3400         int j;
3401
3402         for (j=0 ; pos != string::npos;j++)
3403         {
3404                 labelAscii.replace( pos, 1, "_" );
3405                 pos= labelAscii.find(" ");
3406         }
3407
3408         manualModel -> SetLabel(labelAscii);
3409 }
3410 void wxContourMainFrame::onInsertCalculation(manualBaseModel* manualModel)
3411 {
3412 // EED 2017-05-30
3413 //      double sizeInPixel      = manualModel ->GetPathSize(  );
3414         double spc[3];
3415         spc[0]=1; // ????
3416         spc[1]=1; // ????
3417         spc[2]=1; // ????
3418         double sizeInPixel      = manualModel ->GetPathSize( spc );
3419
3420         double onePixelRealSize = interfMainPanel::getInstance()->GetPixelValue();;
3421         double realContourSize  = sizeInPixel*onePixelRealSize;
3422         manualModel ->SetRealSize(realContourSize);
3423 }
3424
3425 double wxContourMainFrame::onePixelSize( double value)
3426 {
3427         return _onePixelSize = value;
3428 }
3429
3430 std::string wxContourMainFrame::GetFileLocation()
3431 {
3432         return _fileLocation;
3433 }
3434
3435 void wxContourMainFrame::SetFileLocation(std::string newFileLocation)
3436 {
3437         _fileLocation = newFileLocation;
3438         std::cout<<"GETFILELOCATION:"<<_fileLocation<<std::endl;
3439 }
3440 //------------------------------------------------------------------------------------------------------------
3441
3442
3443
3444
3445
3446
3447
3448
3449 void wxContourMainFrame::FlipSelectedContours(int flipDirection)
3450 {
3451         FlipLstOfContours( 
3452                             (std::vector<std::string>)_theViewPanel->getSceneManager()->getSelectedObjects() , 
3453                             flipDirection
3454                           );    
3455                 
3456 }
3457
3458 void wxContourMainFrame::FlipActualSliceContours(int flipDirection)
3459 {
3460         FlipLstOfContours( 
3461                             (std::vector<std::string>)_theViewPanel->getSceneManager()->GetlstContoursNameActualSlice() , 
3462                             flipDirection
3463                           );    
3464 }
3465
3466 void wxContourMainFrame::FlipAllContours(int flipDirection)
3467 {
3468         FlipLstOfContours( 
3469                             kernelManager->GetLstNameThings() , 
3470                             flipDirection
3471                           );
3472 }
3473
3474 void wxContourMainFrame::FlipLstOfContours(std::vector<std::string> lstNameThings, int flipDirection)
3475 {
3476         int ext[6];
3477         getImageData()->GetExtent(ext);         
3478         int sizeX = ext[1]-ext[0];
3479         int sizeY = ext[3]-ext[2];
3480
3481         
3482         int i,sizeLstNameThings;
3483         int ii,sizeLstPoints;
3484         
3485         sizeLstNameThings       = lstNameThings.size(); 
3486         for (i=0 ; i<sizeLstNameThings ; i++)
3487         {
3488                 printf("EED wxContourMainFrame::FlipAllContours contour=%d \n", i );
3489                 manualBaseModel * manualModel = kernelManager->getOutlineByKeyName(lstNameThings[i]);
3490                 if (flipDirection==0)
3491                 {
3492                         manualModel->Transform_Ax_Plus_B(-1,sizeX,1,0 );
3493                 } else {
3494                         manualModel->Transform_Ax_Plus_B(1,0,-1,sizeY );
3495                 }
3496         }// for i  list of Things
3497
3498         //-- Static Contours
3499
3500         lstNameThings           = kernelManager->GetLstNameThingsStatic();
3501         sizeLstNameThings       = lstNameThings.size();
3502         for (i=0 ; i<sizeLstNameThings ; i++)
3503         {
3504                 manualBaseModel * manualModel = kernelManager->getOutlineByKeyName(lstNameThings[i]);
3505                 if (flipDirection==0)
3506                 {
3507                         manualModel->Transform_Ax_Plus_B(-1,sizeX,1,0 );
3508                 } else {
3509                         manualModel->Transform_Ax_Plus_B(1,0,-1,sizeY );
3510                 }
3511         }// for i  list of static things        
3512 }
3513
3514 void wxContourMainFrame::FlipContours(int typeContourFlip, int flipDirection)
3515 {
3516         printf("EED wxContourMainFrame::FlipContours( %d , %d ) \n",typeContourFlip,  flipDirection );
3517
3518         saveState();
3519         
3520         if (typeContourFlip==0) // 
3521         {
3522                 FlipSelectedContours(flipDirection);
3523         }
3524
3525         if (typeContourFlip==1) // 
3526         {
3527                 FlipActualSliceContours(flipDirection);
3528         }
3529         
3530         if (typeContourFlip==2) // 
3531         {
3532                 FlipAllContours(flipDirection);
3533         }
3534         RefreshInterface();
3535 }
3536
3537
3538 void wxContourMainFrame::SetXY(int x, int y)
3539 {
3540         _theViewPanel->SetXY(x,y);
3541 }
3542
3543
3544
3545