]> Creatis software - creaContours.git/blob - lib/Interface_ManagerContour_NDimensions/wxContourMainFrame.cxx
c50fa9b4f3356b0f3c2aa4548369f7e37b9754de
[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                 _frameShowResultImages          = NULL;
98         }
99
100         wxContourMainFrame::wxContourMainFrame(wxWindow* parent, wxWindowID id,const wxString& title,const wxPoint& pos,const wxSize& size,std::vector<vtkImageData*> images, long style,std::string datadir)
101                 : wxPanel(parent, id, pos, size, style)
102         {
103                 m_mgr.SetManagedWindow(this);
104                 _contourGroup                           = 1;
105                 _creatingContoursActive         = false;
106                 _theViewPanel                           = NULL;
107                 _instantPanel                           = NULL;
108                 _refLineControl                         = NULL;
109                 _refLineModel                           = NULL;
110                 _refLineView                            = NULL;
111 //              _actorPresent                           = false;
112                 _viewMaskImage                          = NULL;
113                 _viewMaskImagePanel                     = NULL;
114                 _viewThresholdImage                     = NULL;
115                 _viewThresholdImagePanel        = NULL;
116                 _viewColorLayerImagePanel       = NULL;
117                 // set up default notebook style
118                 m_notebook_style                        = wxAUI_NB_TAB_SPLIT | wxAUI_NB_TAB_EXTERNAL_MOVE | wxNO_BORDER;
119                 m_notebook_theme                        = 0;
120                 //wxContour_ActionCommandsID a;
121                 _numberOfVariablesStatistics= 7;
122                 _datadir                                        = datadir;
123                 inredo                                          = 0;
124                 inundo                                          = 0;
125                 _pannew = interfMainPanel::getInstance(this,datadir+"/data/Icons");//, eventHandler);
126                 _performingOperation        = new PerformingOperation();
127                 if(images.size() > 0)
128                 {
129                         this->configure(images);
130                 }
131                 _contourextractdata                     = NULL;
132 }
133
134 void wxContourMainFrame::configure(std::vector<vtkImageData*> imgs)
135 {
136         _images = imgs;
137         #if defined(_WIN32)
138                 std::string str_home(getenv("USERPROFILE"));
139         #elif defined(__GNUC__)
140                 std::string str_home(getenv("HOME"));
141         #endif
142         std::string                             strCreaContourDataTmp = str_home + "/.creaContourDataTemp/";
143         std::vector<std::string>        conceptNameVect;
144         std::vector<int>                        conceptSizeVect;
145         notebook                = this->createNotebook();
146         kernelManager   = new KernelManagerContour( imgs , _datadir+"/data/" , strCreaContourDataTmp );
147         _instantPanel   = new wxInstantChooserPanel( notebook, "Instant Chooser", true, false, "c" );
148         _theViewPanel   = new wxContourViewPanel( kernelManager->getSourceImage(), notebook );
149 //-------------------------------------------------------------
150         kernelManager->getConceptsInformation(conceptNameVect, conceptSizeVect);
151         _instantPanel->addConcepts(conceptNameVect, conceptSizeVect);
152         double val = _theViewPanel->getCurrentDeep();
153         _instantPanel->setConceptValue( "Axe Depth", (int)val );
154         //JCP _instantPanel->setConceptValue("time", num de imagenes);
155         ConceptDataWrap * data = _instantPanel->getConceptDataOf( "Axe Depth" );
156         //*******************changeInstant();
157         _theViewPanel->setVerticalConcept( "Axe Depth", data->getMinValue(), data->getMaxValue(), data->getMinShowedValue(),  data->getMaxShowedValue(), data->getActualValue() );
158         this->configurePanels( );
159 }
160
161
162         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 )
163         {
164                 if(instance == NULL)
165                 {
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         } // for i
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 void wxContourMainFrame::onLoad()
867 {
868         std::string fileNameContourROI = GetFileLocation();
869 //CMRU 03-09-09-----------------------------------------------------------------------------------------------
870         if(GetFileLocation().empty())
871         {
872 //------------------------------------------------------------------------------------------------------------
873 //EED 2017-09-16 Migration wxWidgets 2.8 to 3.0
874 #if wxMAJOR_VERSION <= 2
875                 wxFileDialog dialog(NULL, _T("Choose a file"), _T(""), _T(""), _T("*.roi"), wxOPEN );
876 #else
877                 wxFileDialog dialog(NULL, _T("Choose a file"), _T(""), _T(""), _T("*.roi"), wxFD_OPEN );
878 #endif
879                 if (dialog.ShowModal() == wxID_OK)
880                 {
881                         fileNameContourROI = (const char *)(dialog.GetPath().mb_str());
882                 } // if dialog
883         } // if FileLocation
884         onLoadContours(fileNameContourROI,true);
885 }
886
887 void  wxContourMainFrame::SetZForAllContours(int pz)
888 {
889         //-- Normal Contours
890         std::vector< std::string > lstNameThings;       
891         int i,sizeLstNameThings;
892         int ii,sizeLstPoints;   
893         lstNameThings           = kernelManager->GetLstNameThings();
894         sizeLstNameThings       = lstNameThings.size(); 
895         for (i=0 ; i<sizeLstNameThings ; i++)
896         {
897 printf("EED wxContourMainFrame::SetZForAllContours contour=%d \n", i );
898                 manualBaseModel * manualModel = kernelManager->getOutlineByKeyName(lstNameThings[i]);
899                 sizeLstPoints = manualModel->GetSizeLstPoints();
900                 for (ii=0 ; ii<sizeLstPoints ; ii++)
901                 {
902                          manualModel->GetManualPoint(ii)->SetPointZ(-900);
903                 }// for ii  list of points
904         }// for i  list of Things
905
906         //-- Static Contours
907
908         lstNameThings           = kernelManager->GetLstNameThingsStatic();
909         sizeLstNameThings       = lstNameThings.size();
910         for (i=0 ; i<sizeLstNameThings ; i++)
911         {
912                 manualBaseModel * manualModel = kernelManager->getOutlineByKeyName(lstNameThings[i]);
913                 sizeLstPoints = manualModel->GetSizeLstPoints();
914                 for (ii=0 ; ii<sizeLstPoints ; ii++)
915                 {
916                          manualModel->GetManualPoint(ii)->SetPointZ(-900);
917                 }// for ii  list of points
918         }// for i  list of static things
919 }
920
921 void wxContourMainFrame::onLoadContours(std::string fileNameContourROI, bool interactiveInterface)
922 {
923         char tmp[255];
924         char tmpD[255];
925         FILE *pFile =fopen(fileNameContourROI.c_str(),"r+");
926 //CMRU 03-09-09- ----------------------------------------------------------------------------------------------
927         if(pFile != NULL)
928         {
929 //------------------------------------------------------------------------------------------------------------
930         fileNameContourROI.append("data");
931                 FILE *pFileData=fopen(fileNameContourROI.c_str(),"r+");
932                 if(pFileData != NULL)
933                 {
934                         fscanf(pFileData,"%s",tmpD); // --CreaContour--
935                         fscanf(pFileData,"%s",tmpD); // Version
936                         fscanf(pFileData,"%s",tmpD); // 1.0.3 || 1.0.2 || 1.0.1 || 1.0.0
937
938                         fscanf(pFileData,"%s",tmpD); // onePixelSize
939                         fscanf(pFileData,"%s",tmpD); // #
940                         _onePixelSize = atof(tmpD);
941                         fscanf(pFileData,"%s",tmpD); // NumberOfContours
942                         fscanf(pFileData,"%s",tmpD); // #
943                 }
944                 fscanf(pFile,"%s",tmp); // --CreaContour--
945                 fscanf(pFile,"%s",tmp); // Version
946                 fscanf(pFile,"%s",tmp); // 1.0.3 || 1.0.2 || 1.0.1 || 1.0.0
947                 std::string version(tmp);
948                 //AD:02-06-09
949         _tmpReadFileTypeOfTransformation=-1;
950                 if (version=="1.0.3")
951                 {
952                     readDimSpc(pFile,interactiveInterface);   // DimSpc interactive ON
953                         openContours(pFile,pFileData,false);
954                         openContours(pFile,pFileData,true);     //Load StaticContours
955                 }       
956                 if (version=="1.0.2")
957                 {
958 //EED001
959                         readDimSpc(pFile,interactiveInterface); // DimSpc interactive ON
960                         openContours(pFile,pFileData,false);
961                         readDimSpc(pFile,false);                // DimSpc interactive OFF
962                         openContours(pFile,pFileData,true);     // Load StaticContours
963                         SetZForAllContours(-900);
964                 } else if (version=="1.0.1") { //AD:02-06-09
965                         openContours(pFile,pFileData,false); //Skips ImageDimensions and ImageSpacing
966                         openContours(pFile,pFileData,true); //Load StaticContours, skips ImageDimensions and ImageSpacing
967                 } else if (version=="1.0.0") { //AD:02-06-09
968                         openContours(pFile,pFileData,false); //Skips ImageDimensions and ImageSpacing
969                 }
970                 fclose(pFile);
971                 if(pFileData != NULL)
972                 {
973                         fclose(pFileData);
974                 } // if
975         } // pFile
976         _theViewPanel->getSceneManager()->removeSceneContours();
977         changeInstant();
978 }
979
980
981 void wxContourMainFrame::onImport()
982 {
983         std::string filename, filenamecontours;
984 //EED 2017-09-16 Migration wxWidgets 2.8 to 3.0
985 #if wxMAJOR_VERSION <= 2
986         wxFileDialog dialog(NULL, _T("Choose a XML Osirix File"), _T(""), _T(""), _T("*.xml"), wxOPEN );
987 #else
988         wxFileDialog dialog(NULL, _T("Choose a XML Osirix File"), _T(""), _T(""), _T("*.xml"), wxFD_OPEN );
989 #endif
990         if (dialog.ShowModal() == wxID_OK)
991         {
992                 filename = dialog.GetPath().mb_str();
993                 filenamecontours = kernelManager->parseOsirixFile(filename);
994
995                 if(filenamecontours.compare("") != 0)
996                 {
997                         onLoadContours(filenamecontours,true);
998                 } // if
999         } // if
1000 }
1001
1002 void wxContourMainFrame::onTest()
1003 {
1004         std::string filename, filenamecontours;
1005 //EED 2017-09-16 Migration wxWidgets 2.8 to 3.0
1006 #if wxMAJOR_VERSION <= 2
1007         wxFileDialog dialog(NULL, _T("Choose a File"), _T(""), _T(""), _T("*.*"), wxOPEN );
1008 #else
1009         wxFileDialog dialog(NULL, _T("Choose a File"), _T(""), _T(""), _T("*.*"), wxFD_OPEN );
1010 #endif
1011         if (dialog.ShowModal() == wxID_OK)
1012         {
1013                 filename = dialog.GetPath().mb_str();
1014                 std::cout << "This is the filename: " << filename << std::endl;
1015         } // if
1016 }
1017
1018 //AD: 29-05-09
1019 void wxContourMainFrame::onSave()
1020 {
1021 //CMRU 03-09-09-----------------------------------------------------------------------------------------------
1022         if(GetFileLocation().empty())
1023         {
1024 //------------------------------------------------------------------------------------------------------------
1025 //EED 2017-09-16 Migration wxWidgets 2.8 to 3.0
1026 #if wxMAJOR_VERSION <= 2
1027                 wxFileDialog dialog(NULL, _T("Choose a file"), _T(""), _T(""), _T("*.roi"), wxSAVE );
1028 #else
1029                 wxFileDialog dialog(NULL, _T("Choose a file"), _T(""), _T(""), _T("*.roi"), wxFD_SAVE );
1030 #endif
1031                 if (dialog.ShowModal() == wxID_OK)
1032                 {
1033                         std::string fileNameContourROI = (const char *)(dialog.GetPath().mb_str());
1034                         kernelManager->setCurrentFileName(fileNameContourROI);
1035                         saveFileWithContours( fileNameContourROI );
1036                 }
1037         } else {//CMRU 03-09-09-----------------------------------------------------------------------------------------------
1038                 std::cout<<"Nombre del archivo: "<<GetFileLocation()<<std::endl;
1039                 std::string fileNameContourROI = GetFileLocation();
1040                 std::cout<<"Nombre del archivo: "<<fileNameContourROI<<std::endl;
1041                 kernelManager->setCurrentFileName(fileNameContourROI);
1042                 saveFileWithContours( fileNameContourROI);
1043         }
1044 //------------------------------------------------------------------------------------------------------------
1045 }
1046
1047 //AD: 29-05-09
1048 void wxContourMainFrame::saveFileWithContours( std::string filename )
1049 {
1050
1051         FILE *pFile=fopen(filename.c_str(),"w+");
1052
1053 //CMRU 03-09-09-----------------------------------------------------------------------------------------------
1054         filename.append("data");
1055         std::cout<<"Nombre del archivo: "<<filename<<std::endl;
1056         FILE *pFileData=fopen(filename.c_str(),"w+");
1057 //------------------------------------------------------------------------------------------------------------
1058
1059         std::vector< std::string > lstNameThings;
1060         int i,sizeLstNameThings;
1061
1062         fprintf(pFile,"--CreaContour--\n");
1063         fprintf(pFile,"Version %s\n", "1.0.3" );
1064
1065 //CMRU 03-09-09-----------------------------------------------------------------------------------------------
1066         fprintf(pFileData,"--CreaContour--\n");
1067         fprintf(pFileData,"Version %s\n", "1.0.3" );
1068         fprintf(pFileData,"OnePixelSize %f\n", _onePixelSize);
1069
1070 //------------------------------------------------------------------------------------------------------------
1071
1072         vtkImageData *image = _images[0];
1073
1074         int dimRange[3];
1075         image->GetDimensions(dimRange);
1076
1077         fprintf(pFile,"ImageDimensions %d %d %d\n", dimRange[0], dimRange[1], dimRange[2] );
1078
1079         double spaRange[3];
1080         image->GetSpacing(spaRange);
1081
1082         fprintf(pFile,"ImageSpacing %f %f %f\n", spaRange[0], spaRange[1], spaRange[2] );
1083
1084         // Normal Contours
1085
1086         lstNameThings           = kernelManager->GetLstNameThings();
1087         sizeLstNameThings       = lstNameThings.size();
1088         fprintf(pFile,"NumberOfContours %d\n", sizeLstNameThings );
1089
1090 //CMRU 03-09-09-----------------------------------------------------------------------------------------------
1091         fprintf(pFileData,"NumberOfContours %d\n", sizeLstNameThings );
1092 //------------------------------------------------------------------------------------------------------------
1093
1094
1095 // EED 2017-05-30
1096         double spc[3];
1097         spc[0]=1; 
1098         spc[1]=1; 
1099         spc[2]=1; 
1100
1101         for (i=0 ; i<sizeLstNameThings ; i++)
1102         {
1103 //CMRU 03-09-09-----------------------------------------------------------------------------------------------
1104                 manualBaseModel * manualModel = kernelManager->getOutlineByKeyName(lstNameThings[i]);
1105
1106 // EED 2017-05-30
1107 //              double sizeInPixel = manualModel ->GetPathSize(  );
1108                 double sizeInPixel = manualModel ->GetPathSize( spc );
1109
1110                 double realContourSize = sizeInPixel*_onePixelSize;
1111                 manualModel ->SetRealSize(realContourSize);
1112 //------------------------------------------------------------------------------------------------------------
1113
1114         //int size= kernelManager->GetLstNameThings().size();
1115
1116                 kernelManager->SaveThingName( pFile, pFileData, lstNameThings[i] );
1117                 _theViewPanel->getSceneManager()->SaveThingName( pFile, lstNameThings[i] );
1118         }// for i
1119
1120         //-- Static Contours
1121
1122 //      fprintf(pFile,"ImageDimensions %d %d %d\n", dimRange[0], dimRange[1], dimRange[2] );
1123 //      fprintf(pFile,"ImageSpacing %f %f %f\n", spaRange[0], spaRange[1], spaRange[2] );
1124
1125         lstNameThings           = kernelManager->GetLstNameThingsStatic();
1126         sizeLstNameThings       = lstNameThings.size();
1127         fprintf(pFile,"NumberOfContoursStatic %d\n", sizeLstNameThings );
1128
1129 //CMRU 03-09-09-----------------------------------------------------------------------------------------------
1130         fprintf(pFileData,"NumberOfContoursStatic %d\n", sizeLstNameThings );
1131 //------------------------------------------------------------------------------------------------------------
1132
1133         for (i=0 ; i<sizeLstNameThings ; i++)
1134         {
1135                 kernelManager->SaveThingName( pFile, pFileData, lstNameThings[i] );
1136                 _theViewPanel->getSceneManager()->SaveThingName( pFile, lstNameThings[i] );
1137         }// for i
1138         fclose(pFile);
1139         fclose(pFileData);
1140 }
1141
1142
1143 //EED02
1144 void wxContourMainFrame::readDimSpc(FILE *pFile, bool interactiveOption)
1145 {
1146         char tmp[255];
1147         int             imageDim[3];
1148         double          imageSpac[3];
1149         vtkImageData    *image          = _images[0];
1150     image->GetDimensions(imageDim);
1151     image->GetSpacing(imageSpac);
1152
1153     fscanf(pFile,"%s",tmp); // ImageDimensions
1154     fscanf(pFile,"%s",tmp); // X
1155     _tmpReadFileImageDim[0] = atoi(tmp);
1156     fscanf(pFile,"%s",tmp); // Y
1157     _tmpReadFileImageDim[1] = atoi(tmp);
1158     fscanf(pFile,"%s",tmp); // Z
1159     _tmpReadFileImageDim[2] = atoi(tmp);
1160
1161     fscanf(pFile,"%s",tmp); // ImageSpacing
1162     fscanf(pFile,"%s",tmp); // X
1163     _tmpReadFileImageSpac[0] = atof(tmp);
1164     fscanf(pFile,"%s",tmp); // Y
1165     _tmpReadFileImageSpac[1] = atof(tmp);
1166     fscanf(pFile,"%s",tmp); // Z
1167     _tmpReadFileImageSpac[2] = atof(tmp);
1168
1169
1170         if (interactiveOption==true)
1171     {
1172                 //Compare Spacing and Dims in X and Y (Necessary in Z?) - Just for Version 2
1173                 if (imageDim[0]!=_tmpReadFileImageDim[0] || imageDim[1]!=_tmpReadFileImageDim[1] || imageSpac[0]!=_tmpReadFileImageSpac[0] || imageSpac[1]!=_tmpReadFileImageSpac[1])
1174                 {
1175                         wxDialog* dial = new wxDialog (this,-1,_T("Tools"),wxDefaultPosition, wxSize(460,360));
1176                         wxSizer* buttonsSizer = dial->CreateSeparatedButtonSizer(wxOK|wxCANCEL);
1177 //                      wxBoxSizer              *dialSizer = new wxBoxSizer(wxVERTICAL);
1178                         wxFlexGridSizer *dialSizer = new wxFlexGridSizer(1);
1179
1180                         wxString lstOptOperation[3];
1181                         lstOptOperation[0]=_T("By Dimension (XY)");
1182                         lstOptOperation[1]=_T("By Spacing   (XY)");
1183                         lstOptOperation[2]=_T("By Spacing   (XYZ)");
1184                         wxRadioBox * radioOpts = new wxRadioBox(dial, -1, _T("Type of Transformation"), wxDefaultPosition, wxSize(370,200), 3 , lstOptOperation,  3, wxRA_SPECIFY_ROWS);
1185
1186                         dialSizer->Add( new wxStaticText(dial,-1,_T("The image resolution is not compatible with the "))  , 0, wxGROW );
1187                         dialSizer->Add( new wxStaticText(dial,-1,_T("selected Roi file. Do you want to tranform it?"))  , 0, wxGROW );
1188                         dialSizer->Add( new wxStaticText(dial,-1,_T(" "))  , 0, wxGROW );
1189                         dialSizer->Add(radioOpts,0,wxGROW);
1190                         dialSizer->Add( new wxStaticText(dial,-1,_T(" "))  , 0, wxGROW );
1191                         dialSizer->Add(buttonsSizer,0,wxGROW);
1192                         dial->SetSizer(dialSizer, true);
1193                         dial->Layout();
1194                         dial->ShowModal();
1195
1196                         _tmpReadFileTypeOfTransformation = -1;
1197 //EED                   bool transform = false;
1198
1199                         if (dial->GetReturnCode() == wxID_OK)
1200                         {
1201                                 _tmpReadFileTypeOfTransformation    = radioOpts->GetSelection();
1202                         }// if wxOK
1203
1204                 } // if dim spc
1205     } // if interactiveOption
1206 }
1207
1208
1209
1210
1211 //AD:04-06-09
1212 void wxContourMainFrame::openContours( FILE *pFile, FILE *pFileData, bool staticContour )
1213 {
1214         char tmp[255];
1215
1216         vtkImageData    *image = _images[0];
1217
1218         int             imageDim[3];
1219         double          imageSpac[3];
1220     image->GetDimensions(imageDim);
1221     image->GetSpacing(imageSpac);
1222
1223
1224         fscanf(pFile,"%s",tmp); // NumberOfContours
1225         fscanf(pFile,"%s",tmp); // ##
1226         int numberOfContours = atoi(tmp);
1227
1228         std::vector<int> instantVector;
1229         int typeContourModel;
1230         manualBaseModel *manModelContour;
1231         int typeView;
1232
1233 /*
1234         if (compatible==true)
1235         {
1236                 int i;
1237                 for (i=0;i<numberOfContours;i++)
1238                 {
1239                         instantVector.clear();
1240                         fscanf(pFile,"%s",tmp); // Instant
1241
1242                         fscanf(pFile,"%s",tmp); // 1
1243                         instantVector.push_back( atoi(tmp) );
1244                         fscanf(pFile,"%s",tmp); // 2
1245                         instantVector.push_back( atoi(tmp) );
1246                         fscanf(pFile,"%s",tmp); // 3
1247                         instantVector.push_back( atoi(tmp) );
1248                         fscanf(pFile,"%s",tmp); // 4
1249                         instantVector.push_back( atoi(tmp) );
1250                         fscanf(pFile,"%s",tmp); // 5
1251                         instantVector.push_back( atoi(tmp) );
1252                         fscanf(pFile,"%s",tmp); // 6
1253                         instantVector.push_back( atoi(tmp) );
1254
1255
1256                         fscanf(pFile,"%s",tmp); // TypeContourModel
1257                         fscanf(pFile,"%s",tmp); // ##
1258                         typeContourModel = atoi(tmp);
1259
1260                         manModelContour =  kernelManager->factoryManualContourModel(typeContourModel);
1261                         manModelContour->Open(pFile);
1262                         if(pFileData != NULL)
1263                         {
1264                                 manModelContour->OpenData(pFileData);
1265                         }
1266
1267                         fscanf(pFile,"%s",tmp); // TypeView
1268                         fscanf(pFile,"%s",tmp); // ##
1269                         typeView = atoi(tmp);
1270
1271                         std::string theName;
1272                         theName = kernelManager->createOutline( manModelContour, instantVector );
1273                         bool addedModel = theName.compare("") != 0;
1274                         if( addedModel )
1275                         {
1276                                 double spc[3];//Si no hay imagen pero hay contornos que spacing se pone por default
1277                                 _theViewPanel->getSpacing(spc);
1278                                 //Adding the manualContourControler to interface objects structure
1279                                 //Adding the manualViewContour to interface objects structure
1280                                 //_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.
1281                                 _theViewPanel->getSceneManager()->configureViewControlTo( theName, manModelContour,spc , typeView) ;
1282                         }
1283
1284                         if (staticContour) //StaticContours (will appear in all slices)
1285                         {
1286                                 Instant instant(&instantVector);
1287                                 kernelManager->changeContourOfManager( theName , &instant );
1288                         }
1289
1290                 }// for  numberOfContours
1291         }
1292
1293         else if (compatible==false)
1294         {
1295 */
1296
1297                 int i;
1298                 for (i=0;i<numberOfContours;i++)
1299                 {
1300                         instantVector.clear();
1301                         fscanf(pFile,"%s",tmp); // Instant
1302
1303                         fscanf(pFile,"%s",tmp); // 1
1304                         instantVector.push_back( atoi(tmp) );
1305                         fscanf(pFile,"%s",tmp); // 2
1306                         instantVector.push_back( atoi(tmp) );
1307                         fscanf(pFile,"%s",tmp); // 3
1308                         instantVector.push_back( atoi(tmp) );
1309                         fscanf(pFile,"%s",tmp); // 4
1310                         instantVector.push_back( atoi(tmp) );
1311                         fscanf(pFile,"%s",tmp); // 5
1312                         instantVector.push_back( atoi(tmp) );
1313                         fscanf(pFile,"%s",tmp); // 6
1314                         instantVector.push_back( atoi(tmp) );
1315
1316                         fscanf(pFile,"%s",tmp); // TypeContourModel
1317                         fscanf(pFile,"%s",tmp); // ##
1318                         typeContourModel = atoi(tmp);
1319
1320                         manModelContour =  kernelManager->factoryManualContourModel(typeContourModel);
1321                         manModelContour->Open(pFile);
1322                         if(pFileData != NULL)
1323                         {
1324                                 manModelContour->OpenData(pFileData);
1325                         }
1326
1327             if (_tmpReadFileTypeOfTransformation==-1){
1328                 //nothing to do..
1329             } else if (_tmpReadFileTypeOfTransformation==0){
1330                 double transX, transY;
1331                 transX = (double) imageDim[0]/_tmpReadFileImageDim[0];                    // X
1332                 transY = (double) imageDim[1]/_tmpReadFileImageDim[1];                    // Y
1333                 manModelContour->Transform_Ax_Plus_B(transX,0,transY,0);                
1334             } else if (_tmpReadFileTypeOfTransformation==1) {
1335                 double transX, transY;
1336                 transX = (double) _tmpReadFileImageSpac[0]/imageSpac[0];                  // X
1337                 transY = (double) _tmpReadFileImageSpac[1]/imageSpac[1];                  // Y
1338                 manModelContour->Transform_Ax_Plus_B(transX,0,transY,0); 
1339             } else if (_tmpReadFileTypeOfTransformation==2) {  // with Z include
1340                 double transX, transY;
1341                 transX = (double) _tmpReadFileImageSpac[0]/imageSpac[0];                   // X
1342                 transY = (double) _tmpReadFileImageSpac[1]/imageSpac[1];                   // Y 
1343                 instantVector[1]=instantVector[1]*_tmpReadFileImageSpac[2]/imageSpac[2];   // Z
1344                 manModelContour->Transform_Ax_Plus_B(transX,0,transY,0);
1345             }else {
1346                     printf ("EED Warnning! wxContourMainFrame::openContours _tmpReadFileTypeOfTransformation not set. \n");
1347             }
1348
1349                         fscanf(pFile,"%s",tmp); // TypeView
1350                         fscanf(pFile,"%s",tmp); // ##
1351                         typeView = atoi(tmp);
1352
1353                         std::string theName;
1354                         theName = kernelManager->createOutline( manModelContour, instantVector );
1355                         bool addedModel = theName.compare("") != 0;
1356                         if( addedModel )
1357                         {
1358                                 double spc[3];//Si no hay imagen pero hay contornos que spacing se pone por default
1359                                 _theViewPanel->getSpacing(spc);
1360                                 //Adding the manualContourControler to interface objects structure
1361                                 //Adding the manualViewContour to interface objects structure
1362                                 //_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.
1363                                 _theViewPanel->getSceneManager()->configureViewControlTo( theName, manModelContour,spc , typeView) ;
1364                         }
1365
1366                         if (staticContour) //StaticContours (will appear in all slices)
1367                         {
1368                                 Instant instant(&instantVector);
1369                                 kernelManager->changeContourOfManager( theName , &instant );
1370                         }
1371                 }// for  numberOfContours
1372
1373 /*      }    */
1374
1375 }
1376
1377 void wxContourMainFrame::RefreshInterface()
1378 {
1379         changeInstant();
1380         _theViewPanel->RefreshInterface();
1381         //wxVtk2DBaseView *wxvtk2dbaseview = (wxVtk2DBaseView*)this->_theViewPanel->getWxVtkBaseView();
1382         //wxvtk2dbaseview->Refresh();
1383 }
1384
1385 vtkImageData* wxContourMainFrame::getImageData()
1386 {
1387         return _theViewPanel->getImageData();
1388 }
1389
1390 void wxContourMainFrame::onSegmentationOneSliceITK(wxString distance, wxString sigma, wxString alfa, wxString beta, wxString propagation, wxString iterations, wxString inflation)
1391 {
1392         //JCP 20-10-08 Undo redo implementation
1393         saveState();
1394         //JCP 20-10-08 Undo redo implementation
1395
1396         wxBusyCursor wait;
1397         int                                     x                                       = _theViewPanel->GetX();
1398         int                                     y                                       = _theViewPanel->GetY();
1399         int                                     z                                       = _theViewPanel->GetZ();
1400         SegmentationOneSliceITK( x,y,z,distance, sigma, alfa, beta, propagation, iterations, inflation);
1401         RefreshInterface();
1402 }
1403
1404 void wxContourMainFrame::SegmentationOneSliceITK(int x, int y, int z, wxString distanc, wxString sigm, wxString alf, wxString bet, wxString prop, wxString iter, wxString inflation)
1405 {
1406         int typeofcontour = 1;
1407         //Image Data
1408         vtkImageData    *imagedata      = getImageData();
1409         //Tipo de pixeles a utilizar internamente en ITK
1410         typedef   float  InternalPixelType;
1411         const     unsigned int    Dimension = 2;
1412         typedef itk::Image< InternalPixelType, Dimension >  InternalImageType;
1413         //Tipo de pixeles de salida 1
1414         typedef unsigned char OutputPixelType;
1415         typedef itk::Image< OutputPixelType, Dimension > OutputImageType;
1416         //Tipo de pixeles de salida 2
1417         typedef unsigned short OutputPixelType2;
1418         typedef itk::Image< OutputPixelType2, Dimension > OutputImageType2;
1419         //DefiniciÛn del thresholder
1420         typedef itk::BinaryThresholdImageFilter<
1421                                                         InternalImageType,
1422                                                         OutputImageType    >    ThresholdingFilterType;
1423         //DefiniciÛn del primer filtro de conversiÛn de pixeles
1424         typedef itk::CastImageFilter<
1425                                 OutputImageType, OutputImageType2 >  CastFilterType;
1426         //DefiniciÛn del segundo tipo de conversiÛn de pixeles
1427         typedef itk::CastImageFilter<
1428                                 OutputImageType2, InternalImageType >  CastFilterType2;
1429         //Tercer tipo de conversiÛn
1430         typedef itk::RescaleIntensityImageFilter<
1431                                                                 InternalImageType,
1432                                                                 OutputImageType >   CastFilterType3;
1433         //Cuarto tipo de conversiÛn
1434         typedef itk::RescaleIntensityImageFilter<
1435                                                                 OutputImageType,
1436                                                                 OutputImageType >   CastFilterType4;
1437         ThresholdingFilterType::Pointer thresholder = ThresholdingFilterType::New();
1438         thresholder->SetLowerThreshold( 0.0 );
1439         thresholder->SetUpperThreshold( 128 );
1440         thresholder->SetOutsideValue(  255  );
1441         thresholder->SetInsideValue(  0 );
1442         //DefinciÛn de conexiÛnes entre VTK e ITK y el writer
1443         typedef itk::VTKImageToImageFilter<OutputImageType2> ConnectorType;
1444         typedef itk::ImageToVTKImageFilter<OutputImageType> ConnectorType2;
1445 //EED10JUIN2011 typedef  itk::ImageFileWriter<  OutputImageType  > WriterType;
1446         ConnectorType::Pointer connector        = ConnectorType::New();
1447         ConnectorType2::Pointer connector2      = ConnectorType2::New();
1448         CastFilterType::Pointer filter   = CastFilterType::New();
1449         CastFilterType2::Pointer filter2 = CastFilterType2::New();
1450         connector->SetInput( imagedata );
1451         filter2->SetInput(connector->GetOutput());
1452         typedef   itk::CurvatureAnisotropicDiffusionImageFilter<
1453                                                                 InternalImageType,
1454                                                                 InternalImageType >  SmoothingFilterType;
1455         SmoothingFilterType::Pointer smoothing = SmoothingFilterType::New();
1456         typedef   itk::GradientMagnitudeRecursiveGaussianImageFilter<
1457                                                                 InternalImageType,
1458                                                                 InternalImageType >  GradientFilterType;
1459         typedef   itk::SigmoidImageFilter<
1460                                                                 InternalImageType,
1461                                                                 InternalImageType >  SigmoidFilterType;
1462         GradientFilterType::Pointer  gradientMagnitude = GradientFilterType::New();
1463         SigmoidFilterType::Pointer sigmoid = SigmoidFilterType::New();
1464         sigmoid->SetOutputMinimum(  0.0  );
1465         sigmoid->SetOutputMaximum(  255.0  );
1466         typedef  itk::FastMarchingImageFilter<
1467                                                                 InternalImageType,
1468                                                                 InternalImageType >    FastMarchingFilterType;
1469         FastMarchingFilterType::Pointer  fastMarching = FastMarchingFilterType::New();
1470         typedef  itk::GeodesicActiveContourLevelSetImageFilter< InternalImageType,
1471                                         InternalImageType >    GeodesicActiveContourFilterType;
1472         GeodesicActiveContourFilterType::Pointer geodesicActiveContour =
1473                                                                                 GeodesicActiveContourFilterType::New();
1474         typedef  itk::ZeroCrossingImageFilter<
1475                                                                 InternalImageType,
1476                                                                 InternalImageType >    ZeroCrossingFilterType;
1477         ZeroCrossingFilterType::Pointer zeroCrossing =
1478                                                         ZeroCrossingFilterType::New();
1479         const double propagationScaling = atof( crea::wx2std(prop).c_str() );
1480         geodesicActiveContour->SetPropagationScaling( propagationScaling );
1481         geodesicActiveContour->SetCurvatureScaling( 1.0 );
1482         geodesicActiveContour->SetAdvectionScaling( 1.0 );
1483         geodesicActiveContour->SetMaximumRMSError( 0.02 );
1484         int it=atoi(  crea::wx2std(iter).c_str() );
1485         geodesicActiveContour->SetNumberOfIterations( it );
1486         smoothing->SetInput( filter2->GetOutput() );
1487         gradientMagnitude->SetInput( smoothing->GetOutput() );
1488         sigmoid->SetInput( gradientMagnitude->GetOutput() );
1489         fastMarching->SetInput( sigmoid->GetOutput() );
1490         geodesicActiveContour->SetInput( fastMarching->GetOutput() );
1491         geodesicActiveContour->SetFeatureImage( sigmoid->GetOutput() );
1492         zeroCrossing->SetInput( geodesicActiveContour->GetOutput() );
1493         //thresholder->SetInput( zeroCrossing->GetOutput() );
1494         thresholder->SetInput( geodesicActiveContour->GetOutput() );
1495         connector2->SetInput( thresholder->GetOutput()  );
1496         smoothing->SetTimeStep( 0.125 );
1497         smoothing->SetNumberOfIterations(  5 );
1498         smoothing->SetConductanceParameter( 9.0 );
1499         const double sigma      = atof(  crea::wx2std(sigm).c_str() );
1500         gradientMagnitude->SetSigma(  sigma  );
1501         const double alpha      =  atof(  crea::wx2std(alf).c_str() );
1502         const double beta       =  atof(  crea::wx2std(bet).c_str() );
1503         sigmoid->SetAlpha( alpha );
1504         sigmoid->SetBeta(  beta  );
1505         typedef FastMarchingFilterType::NodeContainer  NodeContainer;
1506         typedef FastMarchingFilterType::NodeType       NodeType;
1507         NodeContainer::Pointer seeds = NodeContainer::New();
1508         InternalImageType::IndexType  seedPosition;
1509         seedPosition[0]         = x;
1510         seedPosition[1]         = y;
1511         const double initialDistance = atof( crea::wx2std(distanc).c_str() );
1512         NodeType node;
1513         const double seedValue = - initialDistance;
1514         node.SetValue( seedValue );
1515         node.SetIndex( seedPosition );
1516         seeds->Initialize();
1517         seeds->InsertElement( 0, node );
1518         fastMarching->SetTrialPoints( seeds );
1519         fastMarching->SetSpeedConstant( 1.0 );
1520         fastMarching->SetOutputSize( connector->GetOutput()->GetBufferedRegion().GetSize() );
1521         fastMarching->SetStoppingValue( 800 );
1522         try
1523     {
1524 //              connector2->Update();
1525                 vtkImageData *idata = NULL;
1526                 idata                           = connector2->GetOutput();
1527                 vtkMarchingContourFilter* cntVTK = vtkMarchingContourFilter::New( );
1528                 cntVTK->SetNumberOfContours( 1 );
1529                 cntVTK->SetValue( 0, 255 );
1530 //EED 2017-01-01 Migration VTK7
1531 #if VTK_MAJOR_VERSION <= 5
1532                 cntVTK->SetInput( idata );
1533                 cntVTK->Update( );
1534                 cntVTK->UpdateInformation();
1535 #else
1536                 cntVTK->SetInputData( idata );
1537 #endif
1538                 vtkCleanPolyData* cpd = vtkCleanPolyData::New( );
1539 //EED 2017-01-01 Migration VTK7
1540 #if VTK_MAJOR_VERSION <= 5
1541                 cpd->SetInput( cntVTK->GetOutput( ) );
1542                 cpd->Update( );
1543                 cpd->UpdateInformation();
1544 #else
1545                 cpd->SetInputData( cntVTK->GetOutput( ) );
1546 #endif
1547                 vtkPolyDataConnectivityFilter* conn = vtkPolyDataConnectivityFilter::New( );
1548                 conn->SetExtractionModeToLargestRegion( );
1549 //EED 2017-01-01 Migration VTK7
1550 #if VTK_MAJOR_VERSION <= 5
1551                 conn->SetInput( cpd->GetOutput( ) );
1552                 conn->Update( );
1553                 conn->UpdateInformation();
1554 #else
1555                 conn->SetInputData( cpd->GetOutput( ) );
1556 #endif
1557                 vtkStripper* vtkstripper = vtkStripper::New( );
1558 //EED 2017-01-01 Migration VTK7
1559 #if VTK_MAJOR_VERSION <= 5
1560                 vtkstripper->SetInput( conn->GetOutput() );
1561                 vtkstripper->Update();
1562                 vtkstripper->UpdateInformation();
1563 #else
1564                 vtkstripper->SetInputData( conn->GetOutput() );
1565                 cntVTK->Update();
1566 #endif
1567                 vtkPolyData* polyDataResult =  cntVTK->GetOutput();
1568                 //std::cout<<"Points "<<polyDataResult->GetNumberOfPoints()<<std::endl;
1569
1570 //EED 2017-01-01 Migration VTK7
1571 #if VTK_MAJOR_VERSION <= 5
1572                 polyDataResult->Update( );
1573                 polyDataResult->UpdateInformation();
1574 #else
1575         // ..
1576 #endif
1577                 cntVTK          -> Delete();
1578                 cpd                     -> Delete();
1579                 conn            -> Delete();
1580                 //--Calculating control points
1581                 std::vector<double> vecX;
1582                 std::vector<double> vecY;
1583                 std::vector<double> vecXo;
1584                 std::vector<double> vecYo;
1585                 std::vector<double>::iterator vecXoi;
1586                 std::vector<double>::iterator vecYoi;
1587                 std::vector<double> vecZ;
1588                 std::vector<double> vecCtrlPointX;
1589                 std::vector<double> vecCtrlPointY;
1590                 std::vector<double> vecCtrlPointZ;
1591                 double *p;
1592                 double xAct=0;
1593                 double yAct=0;
1594                 int ii,size=polyDataResult->GetNumberOfPoints();
1595                 ofstream myfile;
1596                 myfile.open ("C:/Creatis/example2.txt");
1597                 size=polyDataResult->GetNumberOfPoints();
1598                 for (ii=0;ii<size;ii++)
1599                 {
1600                         if(ii==0)
1601                         {
1602                                 xAct=x;
1603                                 yAct=y;
1604                         }
1605                         p       = polyDataResult->GetPoint(ii);
1606                         double x=p[0];
1607                         double y=p[1];
1608 //                      if(fabs(yAct-y)>20)
1609 //                      {
1610 //                              if((xAct-x)>1 || (xAct-x)<-1)
1611 //                              {
1612 //                                      vecX.push_back( p[0] );
1613 //                                      vecY.push_back( p[1] );
1614 //                                      myfile <<p[0]<<","<<p[1]<<"\n";
1615 //                                      std::cout<<" x Anterior "<<xAct<<" x actual "<<x<<std::endl;
1616 //                                      std::cout<<" y Anterior "<<yAct<<" y actual "<<y<<std::endl;
1617 //                                      std::cout<<" x "<<p[0]<<" y "<<p[1]<<std::endl;
1618 //                                      vecZ.push_back( 900 );
1619 //                                      xAct=x;
1620 //                                      yAct=y;
1621 //                              } else {
1622 //                                      vecXo.push_back(p[0]);
1623 //                                      vecYo.push_back(p[1]);
1624 //                              }
1625 //                      } else
1626
1627                         if(fabs(xAct-x)>11)
1628                         {
1629                                 vecXo.push_back(p[0]);
1630                                 vecYo.push_back(p[1]);
1631                         } else {
1632                                 vecX.push_back( p[0] );
1633                                 myfile <<p[0]<<","<<p[1]<<"\n";
1634                                 //std::cout<<" x Anterior "<<xAct<<" x actual "<<x<<std::endl;
1635                                 //std::cout<<" y Anterior "<<yAct<<" y actual "<<y<<std::endl;
1636                                 //std::cout<<" x "<<p[0]<<" y "<<p[1]<<std::endl;
1637                                 vecY.push_back( p[1] );
1638 //EED 2017-12-16
1639                                 vecZ.push_back( -900 );
1640                                 xAct = x;
1641                                 yAct = y;
1642                         } // if xAct
1643
1644
1645                 } // for
1646
1647                 while(!vecXo.empty())
1648                 {
1649                         vecX.push_back(vecXo.back());
1650                         //std::cout<<" x Siguiente "<<vecXo.back();
1651                         vecXo.pop_back();
1652         //EED 2017-12-16
1653                         vecZ.push_back( -900 );
1654                 }
1655                 while(!vecYo.empty())
1656                 {
1657                         vecY.push_back(vecYo.back());
1658                                 vecYo.pop_back();
1659                 }
1660                 myfile.close();
1661
1662 //              for(int l=0;l<vecX.size();l++)
1663 //              {
1664 //                      if(l==0)
1665 //                      {
1666 //                vecXo.push_back(p[0]);
1667 //                              vecYo.push_back(p[1]);
1668 //                      } else {
1669 //                              if(vecXoi[l-1]==)
1670 //                              {
1671 //                              }
1672 //                      } // if
1673 //              } // for
1674
1675                 ExtractControlPoints2D *extractcontrolpoints2d = new ExtractControlPoints2D();
1676                 extractcontrolpoints2d->SetContour( &vecX , &vecY , &vecZ );
1677
1678                 int method=2;
1679                 if (method==0)
1680                 {
1681                         extractcontrolpoints2d->GetInitialControlPoints( &vecCtrlPointX , &vecCtrlPointY , &vecCtrlPointZ );
1682                 } else if (method==1){
1683                         extractcontrolpoints2d->GetControlPoints(  &vecCtrlPointX , &vecCtrlPointY , &vecCtrlPointZ );
1684                 } else if (method==2){
1685                         extractcontrolpoints2d->SetSamplingControlPoints( 15 );
1686                         extractcontrolpoints2d->GetSamplingControlPoints(  &vecCtrlPointX , &vecCtrlPointY , &vecCtrlPointZ );
1687                 }
1688                 //--Adding contour to the system
1689
1690                 std::vector<int> actualInstantVector;
1691                 _instantPanel->getInstant( actualInstantVector );
1692                 actualInstantVector[1]=z;
1693
1694                 int j,sizeCtrPt = vecCtrlPointX.size();
1695
1696                 manualBaseModel *manModelContour =  kernelManager->factoryManualContourModel( typeofcontour );
1697                 manModelContour->SetNumberOfPointsSpline( ((sizeCtrPt/100)+1)*100 );
1698                 if (sizeCtrPt>=3){
1699                         for (j=0 ; j<sizeCtrPt ; j++)
1700                         {
1701                                 manModelContour->AddPoint( vecCtrlPointX[j] , vecCtrlPointY[j] , vecCtrlPointZ[j]  );
1702                         } // for
1703                         std::string theName;
1704                         //theName = _modelManager->createOutline( manModelContour, actualInstantVector );
1705                         theName = kernelManager->createOutline( manModelContour, actualInstantVector );
1706                         bool addedModel = theName.compare("") != 0;
1707                         if( addedModel )
1708                         {
1709                                 double spc[3];//Si no hay imagen pero hay contornos que spacing se pone por default
1710                                 _theViewPanel->getSpacing(spc);
1711                                 //Adding the manualContourControler to interface objects structure
1712                                 //Adding the manualViewContour to interface objects structure
1713                                 //_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.
1714                                 _theViewPanel->configureViewControlTo(theName, manModelContour, spc, typeofcontour);
1715                                 //_theViewPanel->getSceneManager()->configureViewControlTo( theName, manModelContour,spc, typeofcontour ) ;
1716                         }       // if addedModel
1717                 } // if sizeCtrPt
1718
1719     }   catch( itk::ExceptionObject & excep ) {
1720                 std::cerr << "Exception caught !" << std::endl;
1721                 std::cerr << excep << std::endl;
1722     } // try
1723
1724 }
1725
1726 void wxContourMainFrame::onSegmentationOneSlice(int isovalue,int sampling,int method){
1727
1728         //JCP 20-10-08 Undo redo implementation
1729         saveState();
1730         //JCP 20-10-08 Undo redo implementation
1731
1732         wxBusyCursor wait;
1733         int                                     x                                       = _theViewPanel->GetX();
1734         int                                     y                                       = _theViewPanel->GetY();
1735         int                                     z                                       = _theViewPanel->GetZ();
1736         SegmentationOneSlice( x,y,z,isovalue, sampling, method );
1737         RefreshInterface();
1738 }
1739
1740
1741 void wxContourMainFrame::SegmentationOneSlice( int x, int y, int z, int isovalue, int sampling, int method )
1742 {
1743
1744 //printf("EED wxContourMainFrame::SegmentationOneSlice Start=%d  %d\n",sampling,method );
1745 //printf("EED wxContourMainFrame::SegmentationOneSlice %d %d %d  \n",x,y,z );
1746
1747         int typeofcontour = 1;
1748         //--Extracting Contour
1749         vtkImageData    *imagedata      = getImageData();
1750
1751         vtkImageReslice *imageReslice = vtkImageReslice::New();
1752 //EED
1753                 double spc[3];
1754                 imagedata->GetSpacing(spc);
1755                 x = x*spc[0];
1756                 y = y*spc[1];
1757                 z = z;
1758
1759 //EED 2017-01-01 Migration VTK7
1760 #if VTK_MAJOR_VERSION <= 5
1761         imageReslice->SetInput( imagedata );
1762 #else
1763         imageReslice->SetInputData( imagedata );
1764 #endif
1765         imageReslice->SetInformationInput(imagedata);
1766         imageReslice->SetResliceAxesDirectionCosines(1,0,0, 0,1,0 ,0,0,1);
1767         imageReslice->SetResliceAxesOrigin(0,0,z*spc[2]);
1768         imageReslice->SetOutputDimensionality(2);
1769         imageReslice->SetInterpolationModeToLinear();
1770
1771 //EED 2017-01-01 Migration VTK7
1772 #if VTK_MAJOR_VERSION <= 5
1773         // ..
1774 #else
1775         imageReslice->Update();
1776 #endif
1777
1778         imagedata = imageReslice->GetOutput();
1779 //EED 2017-01-01 Migration VTK7
1780 #if VTK_MAJOR_VERSION <= 5
1781         imagedata->Update();
1782         imagedata->UpdateInformation();
1783 #else
1784         // ..
1785 #endif
1786
1787         vtkContourFilter* cntVTK = vtkContourFilter::New( );
1788 //EED 2017-01-01 Migration VTK7
1789 #if VTK_MAJOR_VERSION <= 5
1790         cntVTK->SetInput( imagedata );
1791 #else
1792         cntVTK->SetInputData( imagedata );
1793 #endif
1794
1795         cntVTK->SetNumberOfContours( 1 );
1796         //cntVTK->SetValue( 0, vmin );
1797 //              cntVTK->SetValue( 0, (range[1]*thr/100) );
1798         cntVTK->SetValue( 1, isovalue );
1799 //      cntVTK->SetValue( 1, vmax );
1800         cntVTK->Update( );
1801         cntVTK->UpdateInformation();
1802
1803         vtkCleanPolyData* cpd = vtkCleanPolyData::New( );
1804 //EED 2017-01-01 Migration VTK7
1805 #if VTK_MAJOR_VERSION <= 5
1806         cpd->SetInput( cntVTK->GetOutput( ) );
1807 #else
1808         cpd->SetInputData( cntVTK->GetOutput( ) );
1809 #endif
1810         cpd->ConvertLinesToPointsOff( );
1811         cpd->Update( );
1812         cpd->UpdateInformation();
1813
1814         vtkPolyDataConnectivityFilter* conn = vtkPolyDataConnectivityFilter::New( );
1815
1816 //      conn->SetExtractionModeToPointSeededRegions();
1817 //      conn->SetExtractionModeToCellSeededRegions();
1818 //      conn->SetExtractionModeToSpecifiedRegions();
1819 //      conn->SetExtractionModeToLargestRegion();
1820 //      conn->SetExtractionModeToAllRegions();
1821
1822         conn->SetExtractionModeToClosestPointRegion();
1823
1824         //conn->SetMaxRecursionDepth( 3000 );
1825
1826 //EED 2017-01-01 Migration VTK7
1827 #if VTK_MAJOR_VERSION <= 5
1828         conn->SetInput( cpd->GetOutput( ) );
1829 #else
1830         conn->SetInputData( cpd->GetOutput( ) );
1831 #endif
1832
1833         conn->SetClosestPoint( x, y, 0 );
1834         conn->Update( );
1835         conn->UpdateInformation();
1836
1837         vtkCleanPolyData* cpd2 = vtkCleanPolyData::New( );
1838 //EED 2017-01-01 Migration VTK7
1839 #if VTK_MAJOR_VERSION <= 5
1840         cpd2->SetInput( conn->GetOutput( ) );
1841 #else
1842         cpd2->SetInputData( conn->GetOutput( ) );
1843 #endif
1844         cpd2->Update();
1845         cpd2->UpdateInformation();
1846
1847         vtkStripper* vtkstripper = vtkStripper::New( );
1848 vtkstripper->SetJoinContiguousSegments(true);
1849         vtkstripper->SetMaximumLength(20000);
1850 //EED 2017-01-01 Migration VTK7
1851 #if VTK_MAJOR_VERSION <= 5
1852         vtkstripper->SetInput( cpd2->GetOutput() );
1853 #else
1854         vtkstripper->SetInputData( cpd2->GetOutput() );
1855 //      vtkstripper->SetInputData( cntVTK->GetOutput() );
1856
1857 #endif
1858         vtkstripper->Update();
1859         vtkstripper->UpdateInformation();
1860
1861
1862         vtkPolyData* polyDataResult =  vtkstripper->GetOutput();
1863
1864 //EED 2017-01-01 Migration VTK7
1865 #if VTK_MAJOR_VERSION <= 5
1866         polyDataResult->Update( );
1867         polyDataResult->UpdateInformation();
1868 #else
1869         //...
1870 #endif
1871
1872 /* EED
1873 ofstream myfile;
1874 myfile.open ("c:/temp/example.txt");
1875 myfile << "\n";
1876 polyDataResult->Print(myfile);
1877 myfile << "-------------------------------------\n";
1878 polyDataResult->GetLines()->Print(myfile);
1879 myfile.close();
1880 */
1881         cntVTK  -> Delete();
1882         cpd2    -> Delete();
1883         cpd             -> Delete();
1884         conn    -> Delete();
1885
1886 //--Calculating control points
1887         std::vector<double> vecX;
1888         std::vector<double> vecY;
1889         std::vector<double> vecZ;
1890         std::vector<double> vecCtrlPointX;
1891         std::vector<double> vecCtrlPointY;
1892         std::vector<double> vecCtrlPointZ;
1893
1894 //printf("EED wxContourMainFrame::SegmentationOneSlice GetNumberOfLines=%d \n",polyDataResult->GetNumberOfLines() );
1895 //int numberOfPointsInCell;
1896 //int numberOfcells=polyDataResult->GetNumberOfCells();
1897 //for (int jj=0; jj<numberOfcells ; jj++)
1898 //{
1899 //      vtkCell* vtkcell = polyDataResult->GetCell( jj );
1900 //      numberOfPointsInCell=vtkcell->GetNumberOfPoints();
1901 //      printf("EED wxContourMainFrame::SegmentationOneSlice cell=%d  points=%d \n",jj,numberOfPointsInCell );
1902 //}// for jj
1903 // printf("EED wxContourMainFrame::SegmentationOneSlice PrintSelf \n");
1904 // polyDataResult->PrintSelf( std::cout, vtkIndent(0) );
1905
1906
1907         if (polyDataResult->GetNumberOfCells()>0)
1908         {
1909                 double *p;
1910                 vtkCell* vtkcell = polyDataResult->GetCell( 0 );
1911         //      int ii,size=polyDataResult->GetNumberOfPoints();
1912                 int ii,size=vtkcell->GetNumberOfPoints();
1913                 int id;
1914                 for (ii=0;ii<size;ii++)
1915                 {
1916         //              id      = polyDataResult->GetLines()->GetData()->GetValue(ii);
1917         //              p       = polyDataResult->GetPoint(id);
1918                         p       = vtkcell->GetPoints()->GetPoint(ii);
1919 //      printf("EED wxContourMainFrame::SegmentationOneSlice (%d) id=%d  px=%f py=%f\n",ii,id, p[0],p[1]);
1920         //              double x=p[0];
1921         //              double y=p[1];
1922                         vecX.push_back( p[0] );
1923                         vecY.push_back( p[1] );
1924         //EED 2017-12-16
1925                         vecZ.push_back( -900 );
1926         //                      vecZ.push_back( p[2] );
1927                 }
1928                 ExtractControlPoints2D *extractcontrolpoints2d = new ExtractControlPoints2D();
1929                 extractcontrolpoints2d->SetContour( &vecX , &vecY , &vecZ );
1930         //PROOFS
1931                 /*if (methodRadiobox->GetSelection()==0){
1932                         extractcontrolpoints2d->GetInitialControlPoints( &vecCtrlPointX , &vecCtrlPointY , &vecCtrlPointZ );
1933                 }
1934                 if (methodRadiobox->GetSelection()==1){
1935                         extractcontrolpoints2d->GetControlPoints(  &vecCtrlPointX , &vecCtrlPointY , &vecCtrlPointZ );
1936                 }
1937                 if (methodRadiobox->GetSelection()==2){
1938                         extractcontrolpoints2d->SetSamplingControlPoints( sampling );
1939                         extractcontrolpoints2d->GetSamplingControlPoints(  &vecCtrlPointX , &vecCtrlPointY , &vecCtrlPointZ );
1940                 }*/
1941
1942                 if (method==0)
1943                 {
1944                         extractcontrolpoints2d->GetInitialControlPoints( &vecCtrlPointX , &vecCtrlPointY , &vecCtrlPointZ );
1945                 } else if (method==1){
1946                         extractcontrolpoints2d->GetControlPoints(  &vecCtrlPointX , &vecCtrlPointY , &vecCtrlPointZ );
1947                 } else if (method==2){
1948                         extractcontrolpoints2d->SetSamplingControlPoints( sampling );
1949                         extractcontrolpoints2d->GetSamplingControlPoints(  &vecCtrlPointX , &vecCtrlPointY , &vecCtrlPointZ );
1950                 }
1951
1952                 //--Adding contour to the system
1953                 std::vector<int> actualInstantVector;
1954                 _instantPanel->getInstant( actualInstantVector );
1955                 actualInstantVector[1]=z;
1956
1957                 int j,sizeCtrPt = vecCtrlPointX.size();
1958                 manualBaseModel *manModelContour =  kernelManager->factoryManualContourModel( typeofcontour );
1959                 manModelContour->SetNumberOfPointsSpline( ((sizeCtrPt/100)+1)*100 *2 );
1960                 manModelContour->SetLabel2( std::to_string(z) );
1961                 if (sizeCtrPt>=3)
1962                 {
1963                         for (j=0 ; j<sizeCtrPt ; j++)
1964                         {
1965                                 manModelContour->AddPoint( vecCtrlPointX[j] / spc[0], vecCtrlPointY[j] / spc[1], vecCtrlPointZ[j] );
1966                         } // for
1967                         std::string theName;
1968                         //theName = _modelManager->createOutline( manModelContour, actualInstantVector );
1969                         theName = kernelManager->createOutline( manModelContour, actualInstantVector );
1970                         bool addedModel = theName.compare("") != 0;
1971                         if( addedModel )
1972                         {
1973                                 double spc[3];//Si no hay imagen pero hay contornos que spacing se pone por default
1974                                 _theViewPanel->getSpacing(spc);
1975                                 //Adding the manualContourControler to interface objects structure
1976                                 //Adding the manualViewContour to interface objects structure
1977                                 //_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.
1978                                 _theViewPanel->configureViewControlTo(theName, manModelContour, spc, typeofcontour);
1979                                 //_theViewPanel->getSceneManager()->configureViewControlTo( theName, manModelContour,spc, typeofcontour ) ;
1980                         }       // if addedModel
1981                 } // if sizeCtrPt
1982         } // if NumberOfCells > 0
1983 //printf("EED wxContourMainFrame::SegmentationOneSlice  End\n");
1984 }
1985
1986 int wxContourMainFrame::GetImageDataSizeZ()
1987 {
1988         return _theViewPanel->GetImageDataSizeZ();
1989 }
1990
1991 void wxContourMainFrame::GetImageDataRange(double *range)
1992 {
1993         _theViewPanel->GetImageDataRange(range);
1994 }
1995
1996 void wxContourMainFrame::onSegmentationAllSlice(int minZ,int maxZ,int isovalue,int sampling,int method)
1997 {
1998         //JCP 20-10-08 Undo redo implementation
1999         saveState();
2000         //JCP 20-10-08 Undo redo implementation
2001
2002         wxBusyCursor wait;
2003         int                                     x = _theViewPanel->GetX();
2004         int                                     y = _theViewPanel->GetY();
2005         int                             z;
2006         double                          porcent;
2007         wxString                        tmpString;
2008         double                          totalZ = maxZ-minZ+1;
2009         for( z=minZ ; z<=maxZ ; z++ )
2010         {
2011                 porcent = 100.0* (z-minZ)/totalZ;
2012                 tmpString.Printf(_T("  %d %c            %d/%d            %d"), (int)porcent , 37 , z-minZ+1, (int)totalZ,z );
2013                 interfMainPanel::getInstance()->setLabelSegmentationPanelVTK(tmpString);
2014                 //_staticTextSegmentation->SetLabel(tmpString);
2015                 SegmentationOneSlice( x,y,z,isovalue, sampling,method );
2016         }
2017         interfMainPanel::getInstance()->setLabelSegmentationPanelVTK(_T("   "));
2018         RefreshInterface();
2019 }
2020
2021
2022 //Creates a reference line to be used as the axis of the mirroring
2023 void wxContourMainFrame::referenceLine()
2024 {
2025         if (_refLineControl==NULL)
2026         {
2027                 wxBusyCursor wait;
2028                 double spc[3];
2029
2030                 vtkImageData *vtkimagedata = _theViewPanel->getImageData();
2031                 vtkimagedata->GetSpacing(spc);
2032
2033                 wxVtkBaseView * viewer2D = _theViewPanel->getWxVtkBaseView();
2034
2035                 _refLineControl = new manualLineControler();
2036                 _refLineModel   = new manualContourModelLine();
2037                 _refLineView = new manualViewLine();
2038                 _refLineView->SetModel( _refLineModel );
2039                 _refLineView->SetWxVtkBaseView( viewer2D );
2040                 _refLineView->SetRange( 2 );
2041                 _refLineView->SetZ( 1200 );
2042
2043                 _refLineView->SetSpacing(spc);
2044
2045                 _refLineView->SetColorNormalContour(0, 0, 1);
2046                 _refLineView->SetColorEditContour(0, 0.5, 0.5);
2047                 _refLineView->SetWidthLine(4);
2048
2049                 _refLineControl->SetModelView( _refLineModel , _refLineView );
2050                 vtkInteractorStyleBaseView* style = (vtkInteractorStyleBaseView*)viewer2D->GetInteractorStyleBaseView();
2051                 style->AddInteractorStyleMaracas( _refLineControl );
2052                 _refLineModel->SetCloseContour(false);
2053                 _refLineControl->CreateNewManualContour();
2054
2055 //AD: Inicializar el mirroring con una linea ya pintada
2056         /*
2057                 double z = _refLineControl->GetZ();
2058
2059                 int imageDim[3];
2060                 image->GetDimensions(imageDim);
2061                 double x = (double) imageDim[0]/2;
2062                 double y1 = (double) (imageDim[1]/2)+15;
2063                 double y2 = (double) (imageDim[1]/2)-15;
2064
2065                 _refLineControl->AddPoint(x,y1,z);
2066                 _refLineControl->AddPoint(x,y2,z);
2067                 _refLineControl->SetCompleteCreation(true);
2068
2069                 _refLineModel->AddPoint(x,y1,z);
2070                 _refLineModel->AddPoint(x,y2,z);
2071                 _refLineModel->UpdateSpline();
2072
2073                 _refLineView->UpdateViewPoint(0);
2074                 _refLineView->UpdateViewPoint(1);
2075         */
2076
2077                 _refLineControl->SetActive(true);
2078                 _refLineView->RefreshContour();
2079         }
2080 }
2081
2082 //Hides the referenceLine
2083 void wxContourMainFrame::refLineHide()
2084 {
2085         if (_refLineControl!=NULL)
2086         {
2087                 if (_refLineControl->GetActive())
2088                 {
2089                         _refLineView->RemoveCompleteContourActor();
2090                         _refLineControl->SetEditable(false);
2091                         _refLineControl->SetActive(false);
2092
2093                         RefreshInterface();
2094                 }
2095         }
2096 }
2097
2098 //Shows the referenceLine
2099 void wxContourMainFrame::refLineShow()
2100 {
2101         if (_refLineControl!=NULL)
2102         {
2103                 if (_refLineControl->GetActive()==false)
2104                 {
2105                         wxVtkBaseView * viewer2D = _theViewPanel->getWxVtkBaseView();
2106
2107                         _refLineView->SetModel( _refLineModel );
2108                         _refLineView->SetWxVtkBaseView( viewer2D );
2109                         _refLineView->SetRange( 2 );
2110                         _refLineView->SetZ( 1200 );
2111
2112                         _refLineControl->SetModelView( _refLineModel , _refLineView );
2113                         vtkInteractorStyleBaseView* style = (vtkInteractorStyleBaseView*)viewer2D->GetInteractorStyleBaseView();
2114                         style->AddInteractorStyleMaracas( _refLineControl );
2115                         _refLineControl->CreateNewManualContour();
2116                         _refLineControl->SetActive(true);
2117                         _refLineView->RefreshContour();
2118
2119                         RefreshInterface();
2120                 }
2121         }
2122 }
2123
2124 void wxContourMainFrame::refLineChangeWidth(int width)
2125 {
2126         _refLineView->SetWidthLine(width);
2127         _refLineView->RefreshContour();
2128
2129         RefreshInterface();
2130 }
2131
2132
2133 void wxContourMainFrame::onMirror()
2134 {
2135         //AD:02-09
2136         std::vector<std::string> currentSelection = _theViewPanel->getSelectedObjects();
2137         std::vector<std::string> filterCurrentSelection;
2138
2139         std::vector<int> tempVector;
2140         _instantPanel->getInstant( tempVector );
2141     _performingOperation->reset();
2142         _performingOperation->setStartCommand( COPY );
2143         _performingOperation->setStartOperationInstantVector( tempVector );
2144         _performingOperation->setKeyNamesOperationElems( currentSelection );
2145
2146         char theStartCommand = _performingOperation->getStartCommand();
2147         if (  theStartCommand == COPY )
2148         {
2149                 //JCP 20-10-08 Undo redo implementation
2150                 saveState();
2151                 //JCP 20-10-08 Undo redo implementation
2152                 std::vector<int> tempVector;
2153                 _instantPanel->getInstant( tempVector );
2154                 _performingOperation->setEndOperationInstantVector ( tempVector );
2155                 std::vector<std::string> elems = _performingOperation->getKeyNamesOperationElems();
2156                 int i,size = elems.size();
2157                 for( i=0; i<size; i++ )
2158                 {
2159                         createMirrorContourOf( elems[i], tempVector, i>0 );
2160                 }
2161         }
2162
2163         //deleteContour( _refName );
2164         //_refName = "";
2165 }
2166
2167
2168 void wxContourMainFrame::showAxis(bool show)
2169 {
2170         _theViewPanel->SetVisibleAxis(show);
2171         _theViewPanel->Refresh();
2172 }
2173
2174
2175 void wxContourMainFrame::onRigidPressed(){
2176         std::vector<std::string> currentSelection = _theViewPanel->getSelectedObjects();
2177         int elementsSelected = currentSelection.size();
2178
2179         if ( elementsSelected >= 1 ){
2180                 //JCP 20-10-08 Undo redo implementation
2181                 saveState();
2182                 //JCP 20-10-08 Undo redo implementation
2183
2184                 std::vector<int> tempVector;
2185                 _instantPanel->getInstant( tempVector );
2186                 Instant instant(&tempVector);
2187
2188                 int i , size=currentSelection.size();
2189                 for ( i=0 ; i<size ; i++ )
2190                 {
2191                         kernelManager->changeContourOfManager(currentSelection[i], &instant);
2192                 } // i
2193         }
2194 }
2195
2196 void wxContourMainFrame::onWidthOfContour(double width){
2197
2198         _theViewPanel->removeSceneContours();
2199         _theViewPanel->SetWidthContour(width);
2200
2201         //_theViewPanel->getSceneManager()->SetWidthContour( width );
2202
2203         RefreshInterface();
2204 }
2205
2206 int wxContourMainFrame::getColorWindow()
2207 {
2208         /*
2209         double range[2];
2210         vtkImageData * img = getImageData();
2211         img->GetScalarRange(range);
2212
2213         std::cout<<"Val 1: "<<range[0]<<" Val 2: "<<range[1]<<std::endl;
2214
2215         return (int)range[1];
2216         */
2217         return _theViewPanel->getColorWindow();
2218 }
2219
2220 int wxContourMainFrame::getWindowLevel()
2221 {
2222         /*
2223         double range[2];
2224         vtkImageData * img = getImageData();
2225         img->GetScalarRange(range);
2226
2227         std::cout<<"Val 1: "<<range[0]<<" Val 2: "<<range[1]<<std::endl;
2228
2229         return (int)range[1];
2230         */
2231         return _theViewPanel->getWindowLevel();
2232 }
2233
2234 void wxContourMainFrame::onBrigthnessColorWindowLevel(int colorwindow,int windowlevel)
2235 {
2236         _theViewPanel->onBrigthnessColorWindowLevel(colorwindow, windowlevel);
2237
2238         RefreshInterface();
2239 }
2240
2241 void wxContourMainFrame::onInterpolation(bool interpolate)
2242 {
2243         _theViewPanel->onInterpolation(interpolate);
2244         RefreshInterface();
2245 }
2246
2247 void wxContourMainFrame::onBeforeAfterContour(bool before,bool after)
2248 {
2249         _theViewPanel->onBeforeAfterContour(before,after);
2250         RefreshInterface();
2251 }
2252
2253 void wxContourMainFrame::onJumpSlice(int step, int shift)
2254 {
2255         std::vector<int> tempVector;
2256         _instantPanel->getInstant( tempVector );
2257         int ss  = abs(step);
2258         int pos         = tempVector[1];
2259         int maxZ        = interfMainPanel::getInstance()->GetImageDataSizeZ();
2260         pos=(pos/ss)*ss+step+shift;
2261         if ((pos>=0) && (pos<maxZ)) 
2262         {
2263                 tempVector[1]=pos;
2264                 _instantPanel->setInstant( tempVector );
2265                 RefreshInterface();
2266         } // if pos     
2267 }
2268
2269 void wxContourMainFrame::onShowTextContour(bool show)
2270 {
2271         _theViewPanel->onShowTextContour(show);
2272         RefreshInterface();
2273 }
2274
2275 void wxContourMainFrame::onChangeInstant(std::string name,int actual)
2276 {
2277         _instantPanel->setConceptValue( name, actual );
2278 }
2279
2280 void wxContourMainFrame::resetAppend()
2281 {
2282         kernelManager->resetAppend();
2283 }
2284
2285 void wxContourMainFrame::onSpreadAdd()
2286 {
2287         std::vector<double> vecX;
2288         std::vector<double> vecY;
2289         std::vector<double> vecZ;
2290         _theViewPanel->GetPointsOfActualContour(&vecX , &vecY , &vecZ );
2291         std::vector<int> tempVector;
2292         _instantPanel->getInstant( tempVector );
2293         std::string val = kernelManager->onSpreadAdd(&vecX , &vecY , &vecZ, tempVector);
2294         interfMainPanel::getInstance()->appendStringSpread(val);
2295 }
2296
2297
2298 void wxContourMainFrame::onSpreadAddAll()
2299 {
2300 //EED02
2301         std::vector<int> tempVector;
2302         _instantPanel->getInstant( tempVector );
2303         int minZ,maxZ;
2304     minZ        = 0;
2305     maxZ        = interfMainPanel::getInstance()->GetImageDataSizeZ();
2306         int z;
2307         int sizeLstContourThings;
2308         for ( z=minZ ; z<=maxZ ; z++ )
2309         {
2310                 tempVector[1]=z;
2311                 Instant instant(&tempVector);
2312                 std::vector<ContourThing**> lstContourThings = kernelManager->getOutlinesAtInstant( &instant );
2313                 sizeLstContourThings = lstContourThings.size();
2314                 if (sizeLstContourThings>=1)
2315         {
2316             std::vector<double> vecX;
2317             std::vector<double> vecY;
2318             std::vector<double> vecZ;
2319             ContourThing **contourthing = lstContourThings[0];
2320                         manualBaseModel *cModel                         =  (*contourthing)->getModel();
2321                         int i,size = cModel->GetNumberOfPointsSpline();
2322                         double x,y,z;
2323                         for (i=0; i<size; i++)
2324                         {
2325                                 cModel->GetSpline_i_Point(i, &x, &y, &z);
2326                                 vecX.push_back(x);
2327                                 vecY.push_back(y);
2328                                 vecZ.push_back(z);
2329                         } // for i
2330             std::string val = kernelManager->onSpreadAdd(&vecX , &vecY , &vecZ, tempVector);
2331             interfMainPanel::getInstance()->appendStringSpread(val);
2332         }// if sizeLstContourThings
2333     } // for z
2334 }
2335
2336
2337 void wxContourMainFrame::onSpreadGo(int type)
2338 {
2339         //JCP 20-10-08 Undo redo implementation
2340         saveState();
2341         //JCP 20-10-08 Undo redo implementation
2342         wxBusyCursor wait;
2343         std::vector<double> vecCtrlPointX;
2344         std::vector<double> vecCtrlPointY;
2345         std::vector<double> vecCtrlPointZ;
2346         double  minZ,maxZ;
2347         int z;
2348
2349         std::vector<int> tempVector;
2350         _instantPanel->getInstant( tempVector );
2351 //              tempVector[1];
2352
2353         kernelManager->getMaxMinZ(&minZ,&maxZ);
2354 //JSTG_16-07-08_----------------------------------------------------------------
2355         //_contourPropagation->setInterpolationNumber(maxZ-minZ+1);
2356         kernelManager->CalculeSplinePropagation();
2357
2358         double          totalZ = maxZ-minZ+1;
2359         double          porcent;
2360         wxString        tmpString;
2361 //--------------------------------------------------------------------
2362         for ( z=(int)minZ ; z<=(int)maxZ ; z++ )
2363         {
2364                 porcent = 100.0* (z-minZ)/totalZ;
2365                 int numero = (int)(z-minZ+1)/(int)totalZ;
2366                 std::string stringtemp = "  "+kernelManager->intToString(porcent)+"%            "+kernelManager->intToString(numero)+"            "+kernelManager->intToString(z);
2367
2368                 interfMainPanel::getInstance()->setStringSpread(stringtemp);
2369
2370                 int typeofcontour = 1;
2371                 std::string theName;
2372                 manualBaseModel* manModelContour = kernelManager->GetPoints(z, type, &vecCtrlPointX,&vecCtrlPointY,&vecCtrlPointZ, theName,typeofcontour, tempVector);
2373
2374                 if( manModelContour!=NULL ){
2375                         double spc[3];//Si no hay imagen pero hay contornos que spacing se pone por default
2376                         this->_theViewPanel->getSpacing(spc);
2377                         //Adding the manualContourControler to interface objects structure
2378                         //Adding the manualViewContour to interface objects structure
2379                         //_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.
2380                         _theViewPanel->configureViewControlTo( theName, manModelContour,spc,typeofcontour ) ;
2381                 } // if addedModel
2382         }
2383         if(z > maxZ){
2384                 porcent = 100.0;
2385                 int numero = (int)(z-minZ+1)/(int)totalZ;
2386                 std::string stringtemp = "  "+kernelManager->intToString(porcent)+"%            "+kernelManager->intToString(numero)+"            "+kernelManager->intToString(z);
2387
2388                 interfMainPanel::getInstance()->setStringSpread(stringtemp);
2389         }// for z
2390         //RefreshInterface();
2391 }
2392
2393 void wxContourMainFrame::getInstantVector(std::vector<int>& tempVector)
2394 {
2395         _instantPanel->getInstant( tempVector );
2396 }
2397
2398 std::vector<std::string> wxContourMainFrame::getOutlinesName(int slide)
2399 {
2400         std::vector<int> tempVector;
2401         _instantPanel->getInstant(tempVector);
2402         //Asignation of slide number should be different ex by name
2403         tempVector[1]=slide;
2404         return kernelManager->getOutlinesNameAtInstant(tempVector);
2405 }
2406
2407
2408 void wxContourMainFrame::SetScalarRange(int grayRangeMin, int grayRangeMax)
2409 {
2410         _contourextractdata->SetScalarRange(grayRangeMin,grayRangeMax);
2411 }
2412
2413
2414 void wxContourMainFrame::onInformationContourLabels(int typeContourGroup,int selection,int minimumZ,int maximumZ,int grayRangeMin, int grayRangeMax)
2415 {
2416
2417         wxString tempString;
2418         int maxContourGroup     =       0;
2419
2420         _contourextractdata ->SetTypeOperation( typeContourGroup % 3 );
2421
2422         std::vector<manualBaseModel*> lstManConMod;
2423         std::vector<manualBaseModel*> lstManConModTmp;
2424         std::vector<manualBaseModel*> lstManConModExp;
2425         std::vector<double> pLstValue;
2426         std::vector<double> pLstValuePosX;
2427         std::vector<double> pLstValuePosY;
2428         std::vector<double> pLstValuePosZ;
2429
2430         int             resultSize;
2431         int             resultGrayRangeCount;
2432         double  resultMin;
2433         double  resultMax;
2434         double  resultAverage;
2435         double  resultStandardeviation;
2436
2437         std::vector<int> tempVector;
2438         _instantPanel->getInstant( tempVector );
2439
2440         int z;
2441         int ii,sizeLstContourThings;
2442
2443
2444         int minZ,maxZ;
2445         double totalZ;
2446         double porcent;
2447         wxString tmpString;
2448
2449
2450         if (selection==0 ) // actual slice
2451         {
2452                 int actualSlice = tempVector[1];
2453                 minZ    = actualSlice;
2454                 maxZ    = actualSlice;
2455         }       else  {  // slice range
2456                 minZ    = minimumZ;
2457                 maxZ    = maximumZ;
2458         }
2459
2460
2461         totalZ  = maxZ-minZ+1;
2462
2463         _contourextractdata->InitVolumeStatistics();
2464
2465 // For each slice..
2466         for ( z=minZ ; z<=maxZ ; z++ )
2467         {
2468
2469                 porcent = 100.0* (z-minZ)/totalZ;
2470                 tmpString.Printf(_T("  %d %c            %d/%d             %d"), (int)porcent , 37 , z-minZ+1, (int)totalZ ,z);
2471
2472                 interfMainPanel::getInstance()->setStringInfoPanel(tmpString);
2473                 //_staticTextInformation->SetLabel(tmpString);
2474
2475                 //Extraction data from contours of each slice
2476                 _contourextractdata->SetZtoBeAnalys(z);
2477
2478                 tempVector[1]=z;
2479                 Instant instant(&tempVector);
2480                 std::vector<ContourThing**> lstContourThings = kernelManager->getOutlinesAtInstant( &instant );
2481                 sizeLstContourThings = lstContourThings.size();
2482
2483                 lstManConMod.clear();
2484                 for (ii=0 ; ii<sizeLstContourThings ; ii++)
2485                 {
2486                         ContourThing **contourthing = lstContourThings[ii];
2487                         lstManConMod.push_back( (*contourthing)->getModel() );
2488                 }
2489
2490                 lstManConModExp =  kernelManager->ExploseEachModel( lstManConMod );
2491
2492                 tempString.Printf(_T("%d - %d"),z, sizeLstContourThings);
2493                 interfMainPanel::getInstance()->setRowLabelInfoPanel(z, tempString);
2494                 //_grid->SetRowLabelValue(z, tempString );
2495 //EED004
2496                 int iContourGroup,sizeContourGroup;
2497                 if (typeContourGroup==3) // contour separete
2498                 {
2499                         sizeContourGroup=lstManConModExp.size();
2500                         if ( maxContourGroup<sizeContourGroup )
2501                         {
2502                                 maxContourGroup=sizeContourGroup;
2503                         }
2504                 } else {  // contour AND OR XOR
2505                         sizeContourGroup=1;
2506                         maxContourGroup=1;
2507                 }
2508
2509                 int tmpIntA;
2510
2511                 for( iContourGroup=0 ; iContourGroup<sizeContourGroup ; iContourGroup++ ){
2512                         lstManConModTmp.clear();
2513
2514
2515
2516                         if (typeContourGroup==3) // contour separete
2517                         {
2518                                 lstManConModTmp.push_back( lstManConModExp[iContourGroup]);
2519                         } else {  // contour AND OR XOR
2520                                 lstManConModTmp = lstManConModExp;
2521                         }
2522
2523                         _contourextractdata->SetLstManualContourModel( lstManConModTmp );
2524                         _contourextractdata->SetScalarRange(grayRangeMin,grayRangeMax);
2525
2526                         pLstValue.clear();
2527                         pLstValuePosX.clear();
2528                         pLstValuePosY.clear();
2529                         pLstValuePosZ.clear();
2530
2531
2532                         int numberOfPixels;
2533                         _contourextractdata->GetValuesInsideCrown(  &numberOfPixels,
2534                                                                                                                 &pLstValue,
2535                                                                                                                 &pLstValuePosX,
2536                                                                                                                 &pLstValuePosY,
2537                                                                                                                 &pLstValuePosZ);
2538
2539                         resultSize=numberOfPixels;
2540                         // Statistics of each slice.
2541                         _contourextractdata->Statistics( &pLstValue,
2542                                                                                         grayRangeMin,
2543                                                                                         grayRangeMax,
2544                                                                                         &resultGrayRangeCount,
2545                                                                                         &resultSize,
2546                                                                                         &resultMin,
2547                                                                                         &resultMax,
2548                                                                                         &resultAverage,
2549                                                                                         &resultStandardeviation);
2550
2551                         if (interfMainPanel::getInstance()->getNumberColsInformationPanel()<_numberOfVariablesStatistics*(iContourGroup+1)  )
2552                         {
2553                                 interfMainPanel::getInstance()->appendColsInformationPanel(_numberOfVariablesStatistics);
2554                         }
2555
2556                         tmpIntA=_numberOfVariablesStatistics*iContourGroup ;
2557
2558                         tempString.Printf(_T("%d"),numberOfPixels);
2559
2560                         interfMainPanel::getInstance()->setCellValueInfoPanel(z, tmpIntA, tempString);
2561
2562                         tempString.Printf(_T("%d"),resultGrayRangeCount);
2563                         interfMainPanel::getInstance()->setCellValueInfoPanel(z, tmpIntA+1, tempString);
2564
2565                         tempString.Printf(_T("%f"),resultMin);
2566                         interfMainPanel::getInstance()->setCellValueInfoPanel(z, tmpIntA+2, tempString);
2567
2568                         tempString.Printf(_T("%f"),resultMax);
2569                         interfMainPanel::getInstance()->setCellValueInfoPanel(z, tmpIntA+3, tempString);
2570
2571                         tempString.Printf(_T("%f"),resultAverage);
2572                         interfMainPanel::getInstance()->setCellValueInfoPanel(z, tmpIntA+4, tempString);
2573
2574                         tempString.Printf(_T("%f"),resultStandardeviation);
2575                         interfMainPanel::getInstance()->setCellValueInfoPanel(z, tmpIntA+5, tempString);
2576
2577
2578                 } // for iContourGroup
2579         } // for z
2580
2581         // Print Volume Statistics
2582
2583
2584         int             vol_rCountRange;
2585         int             vol_rsize;
2586         double  vol_minValue;
2587         double  vol_maxValue;
2588         double  vol_average;
2589         double  vol_standardeviation;
2590
2591         if (selection!=0 ) // actual slice
2592         {
2593
2594                 _contourextractdata->GetVolumeStatistics(&vol_rCountRange, &vol_rsize,
2595                                                                                                  &vol_minValue, &vol_maxValue,
2596                                                                                                  &vol_average, &vol_standardeviation);
2597
2598                 interfMainPanel::getInstance()->setRowLabelInfoPanel(maxZ+2, _T("Total:"));
2599
2600                 tempString.Printf(_T("%d"),vol_rsize);
2601                 interfMainPanel::getInstance()->setCellValueInfoPanel(maxZ+2, 0, tempString);
2602
2603                 tempString.Printf(_T("%d"),vol_rCountRange);
2604                 interfMainPanel::getInstance()->setCellValueInfoPanel(maxZ+2, 1, tempString);
2605
2606                 tempString.Printf(_T("%f"),vol_minValue);
2607                 interfMainPanel::getInstance()->setCellValueInfoPanel(maxZ+2, 2, tempString);
2608
2609                 tempString.Printf(_T("%f"),vol_maxValue);
2610                 interfMainPanel::getInstance()->setCellValueInfoPanel(maxZ+2, 3, tempString);
2611
2612                 tempString.Printf(_T("%f"),vol_average);
2613                 interfMainPanel::getInstance()->setCellValueInfoPanel(maxZ+2, 4, tempString);
2614
2615                 tempString.Printf(_T("%f"),vol_standardeviation);
2616                 interfMainPanel::getInstance()->setCellValueInfoPanel(maxZ+2, 5, tempString);
2617         }
2618         //-----------------------------------------
2619
2620         int iTitleGroup;
2621         wxString tmpTitleString;
2622         int tmpIntB;
2623         for ( iTitleGroup=0 ; iTitleGroup<maxContourGroup ; iTitleGroup++ )
2624         {
2625                 tmpIntB =_numberOfVariablesStatistics*iTitleGroup;
2626                 tmpTitleString.Printf(_T("%d-Size Data"),iTitleGroup);
2627                 interfMainPanel::getInstance()->setColLableInfoPanel(tmpIntB + 0, tmpTitleString);
2628
2629                 interfMainPanel::getInstance()->setColLableInfoPanel(tmpIntB + 0, tmpTitleString );
2630                 interfMainPanel::getInstance()->setColLableInfoPanel( tmpIntB + 1, _T("Size Range") );
2631                 interfMainPanel::getInstance()->setColLableInfoPanel( tmpIntB + 2, _T("Min") );
2632                 interfMainPanel::getInstance()->setColLableInfoPanel( tmpIntB + 3, _T("Max") );
2633                 interfMainPanel::getInstance()->setColLableInfoPanel( tmpIntB + 4, _T("Average") );
2634                 interfMainPanel::getInstance()->setColLableInfoPanel( tmpIntB + 5, _T("St.Dev.") );
2635                 interfMainPanel::getInstance()->setColLableInfoPanel( tmpIntB + 6, _T(" ") );
2636         }// for title
2637         interfMainPanel::getInstance()->setStringInfoPanel( _T("") );
2638 }
2639
2640 //AD: 29-05-09
2641 void wxContourMainFrame::onSaveResults(std::string directory,std::string namefile, std::string filename,
2642         int typeContourGroup, int selection, int minZ, int maxZ, bool XYZValues, bool contourImage, bool statistics)
2643 {
2644         if (XYZValues)
2645         {
2646                 SaveValuesXYZ( directory , namefile, typeContourGroup );
2647         }
2648
2649         if (contourImage)
2650         {
2651                 vtkImageData * mask;
2652                 vtkImageData * value;
2653                 this->getMaskValue(&mask, &value, typeContourGroup,selection,minZ,maxZ);
2654                 this->SaveImageResult( directory , namefile, mask, value);
2655         }
2656
2657         if (statistics)
2658         {
2659                 std::ostringstream name;
2660                 name << filename << ".xls";
2661
2662
2663                 FILE *pFile=fopen(name.str().c_str(),"w+");
2664
2665
2666                 wxString tmpString;
2667                 int i,j,maxX;
2668
2669 //              int sizeZ = _theViewPanel->GetImageDataSizeZ();
2670 //              int maxY=sizeZ+2;
2671
2672                 maxX= interfMainPanel::getInstance()->getNumberColsInformationPanel();//this->_grid->GetNumberCols();
2673
2674                 // -- Title --
2675                 int iTitle,sizeTitle = (maxX / _numberOfVariablesStatistics);
2676                 for ( iTitle=0; iTitle<sizeTitle ; iTitle++)
2677                 {
2678                                 // fprintf(pFile,"-- \t %d-Size \t SizeRange \t Min \t Max \t Ave \t StDv \t" , iTitle,tmpString.c_str() );
2679                                 fprintf(pFile,"slice\t %d-Size \t SizeRange \t Min \t Max \t Ave \t StDv \t" , iTitle );
2680                 }
2681                 fprintf(pFile,"\n\n" );
2682
2683
2684
2685                 if (selection==0 ) // actual slice
2686                 {
2687                         std::vector<int> tempVector;
2688                         _instantPanel->getInstant( tempVector );
2689                         int actualSlice = tempVector[1];
2690                         minZ    = actualSlice;
2691                         maxZ    = actualSlice;
2692                 }
2693
2694                 // Stadistics...
2695                 for ( j=minZ; j<=maxZ ; j++)
2696                 {
2697                         fprintf(pFile,"%d\t" , j );
2698                         for (i=0 ; i<maxX ; i++){
2699                                 tmpString = interfMainPanel::getInstance()->getCellValue(j, i);//_grid->GetCellValue( j , i );
2700                                 fprintf(pFile,"%s\t" , (const char *)(tmpString.mb_str()) );
2701                         } // for i
2702                         fprintf(pFile,"\n"  );
2703                 } // for j
2704
2705
2706                 // Total of stadistics.....
2707                 if (selection!=0)
2708                 {
2709                         fprintf(pFile,"\n Total:\t"  );
2710                         for (i=0 ; i<maxX ; i++){
2711                                 tmpString = interfMainPanel::getInstance()->getCellValue(maxZ+2, i);//_grid->GetCellValue( maxZ+2 , i );
2712                                 fprintf(pFile,"%s\t" , (const char *)(tmpString.mb_str()) );
2713                         } // for i
2714                         fprintf(pFile,"\n"  );
2715                 }
2716
2717                 fclose(pFile);
2718         }
2719 }
2720
2721 //AD: 29-05-09
2722 void wxContourMainFrame::SaveValuesXYZ(std::string directory,std::string namefile,int typeContourGroup)
2723 {
2724         wxBusyCursor wait;
2725
2726         //int typeContourGroup = this->_radiolstboxContourGroup->GetSelection();
2727         _contourextractdata ->SetTypeOperation( typeContourGroup % 3 );
2728
2729         std::vector<manualBaseModel*> lstManConMod;
2730         std::vector<manualBaseModel*> lstManConModTmp;
2731         std::vector<manualBaseModel*> lstManConModExp;
2732         std::vector<double> pLstValue;
2733         std::vector<double> pLstValuePosX;
2734         std::vector<double> pLstValuePosY;
2735         std::vector<double> pLstValuePosZ;
2736
2737         std::vector<int> tempVector;
2738         _instantPanel->getInstant( tempVector );
2739
2740         int sizeZ = _theViewPanel->getSceneManager()->GetImageDataSizeZ();
2741         int z;
2742         int ii,sizeLstContourThings;
2743
2744
2745         int minZ,maxZ;
2746         double totalZ;
2747         double porcent;
2748         wxString tmpString;
2749         minZ    = 0;// _mbarrange->GetStart();
2750         maxZ    = sizeZ;//_mbarrange->GetEnd();
2751         totalZ  = maxZ-minZ+1;
2752
2753
2754 // For each slice..
2755         for ( z=0 ; z<sizeZ ; z++)
2756         {
2757
2758                 porcent = 100.0* (z-minZ)/totalZ;
2759
2760                 tmpString.Printf(_T("Saving Values"));
2761                 tmpString.Printf(_T("  %d %c            %d/%d             %d"), (int)porcent , 37 , z-minZ+1, (int)totalZ ,z);
2762                 interfMainPanel::getInstance()->setStringInfoPanel(tmpString);
2763                 //_staticTextInformation->SetLabel(tmpString);
2764
2765
2766                 //Extraction data from contours of each slice
2767                 _contourextractdata->SetZtoBeAnalys( z);
2768
2769                 tempVector[1]=z;
2770                 Instant instant(&tempVector);
2771                 std::vector<ContourThing**> lstContourThings = kernelManager->getOutlinesAtInstant(&instant);//this->_modelManager->getOutlinesAtInstant( &instant );
2772                 sizeLstContourThings = lstContourThings.size();
2773
2774                 lstManConMod.clear();
2775                 for (ii=0 ; ii<sizeLstContourThings ; ii++)
2776                 {
2777                         ContourThing **contourthing = lstContourThings[ii];
2778                         lstManConMod.push_back( (*contourthing)->getModel() );
2779                 }
2780                 lstManConModExp =  kernelManager->ExploseEachModel( lstManConMod );
2781
2782
2783 //EED004
2784
2785                 int iContourGroup,sizeContourGroup;
2786                 if (typeContourGroup==3) // contour separete
2787                 {
2788                         sizeContourGroup=lstManConModExp.size();
2789                 } else {  // contour AND OR XOR
2790                         sizeContourGroup=1;
2791                 }
2792
2793                 for( iContourGroup=0 ; iContourGroup<sizeContourGroup ; iContourGroup++ ){
2794                         lstManConModTmp.clear();
2795                         if (typeContourGroup==3) // contour separete
2796                         {
2797                                 lstManConModTmp.push_back( lstManConModExp[iContourGroup]);
2798                         } else {  // contour AND OR XOR
2799                                 lstManConModTmp = lstManConModExp;
2800                         }
2801
2802                         _contourextractdata->SetLstManualContourModel( lstManConModTmp );
2803
2804                         pLstValue.clear();
2805                         pLstValuePosX.clear();
2806                         pLstValuePosY.clear();
2807                         pLstValuePosZ.clear();
2808                         int numberOfPixels;
2809                         _contourextractdata->GetValuesInsideCrown(      &numberOfPixels,
2810                                                                                                                 &pLstValue,
2811                                                                                                                 &pLstValuePosX,
2812                                                                                                                 &pLstValuePosY,
2813                                                                                                                 &pLstValuePosZ);
2814
2815                         std::string temp = directory + "/" + namefile + "-slice";
2816                         temp = temp + kernelManager->intToString(z) + "-cont" + kernelManager->intToString(iContourGroup);
2817                         temp = temp + ".txt";
2818
2819                         // LG 14/01/09 : using crea
2820                         wxString filename = crea::std2wx(temp);
2821                         /*filename.Printf(_T("%s"),directory.c_str());
2822                         filename.append(_T("\\"));
2823                         filename.append(_T("%s"),namefile.c_str());
2824                         filename.append(_T("-slice"));
2825                         filename.append(_T("%d"),z);
2826                         filename.append(_T("-cont"));
2827                         filename.append(_T("%d"),iContourGroup);
2828                         filename.append(_T(".txt"));*/
2829                         //                      filename.Printf(temp.c_str());
2830
2831
2832
2833                         FILE *pFile=fopen((const char *)filename.mb_str(),"w+");
2834                         fprintf(pFile,"value \t x \t y \t z\n"  );
2835                         int iLstValue,sizeLstValue=pLstValue.size();
2836                         for (iLstValue=0 ; iLstValue<sizeLstValue ; iLstValue++ )
2837                         {
2838                                 fprintf(pFile,"%f\t %f\t %f\t %f\n", (float)pLstValue[iLstValue] , (float)pLstValuePosX[iLstValue], (float)pLstValuePosY[iLstValue], (float)z );
2839                         }
2840                         fclose(pFile);
2841                 } // for  iContourGroup
2842         } // for z
2843         interfMainPanel::getInstance()->setStringInfoPanel(_T(""));
2844         //_staticTextInformation->SetLabel( _T("") );
2845
2846 }
2847
2848 void wxContourMainFrame::getMaskValue(vtkImageData ** mask,vtkImageData ** value,int typeContourGroup, int selection, int minZ, int maxZ){
2849         wxBusyCursor wait;
2850
2851         //int typeContourGroup = this->_radiolstboxContourGroup->GetSelection();
2852         if (typeContourGroup==3)
2853         {
2854                 typeContourGroup=1;
2855         }
2856         _contourextractdata ->SetTypeOperation( typeContourGroup % 3 );
2857
2858         std::vector<manualBaseModel*> lstManConMod;
2859         std::vector<manualBaseModel*> lstManConModTmp;
2860         std::vector<manualBaseModel*> lstManConModExp;
2861
2862         std::vector<int> tempVector;
2863         _instantPanel->getInstant( tempVector );
2864
2865     vtkImageData *imagedata = _theViewPanel->getImageData();
2866         int ext[6];
2867         imagedata->GetExtent(ext);
2868         int sizeZimage = ext[5]-ext[4]+1;
2869         int z;
2870         int ii,sizeLstContourThings;
2871
2872         double totalZ;
2873         double porcent;
2874
2875         wxString tmpString;
2876
2877
2878         if (selection==0 ) // actual slice
2879         {
2880                 int actualSlice = tempVector[1];
2881                 minZ    = actualSlice;
2882                 maxZ    = actualSlice;
2883         }
2884
2885         totalZ  = maxZ-minZ;
2886
2887
2888         // cleanning image before range
2889         for (z=0; z<minZ; z++){
2890                 _contourextractdata->ResetImageResult(z);
2891         }
2892         // cleanning image after range
2893         for (z=maxZ+1; z<sizeZimage; z++){
2894                 _contourextractdata->ResetImageResult(z);
2895         }
2896
2897
2898 // For each slice..
2899         for ( z=minZ ; z<=maxZ ; z++)
2900         {
2901
2902                 porcent = 100.0* (z-minZ)/totalZ;
2903                 tmpString.Printf(_T("Saving Values"));
2904                 tmpString.Printf(_T("%d %c            %d/%d             %d"), (int)porcent , 37 , z-minZ+1, (int)totalZ ,z);
2905                 interfMainPanel::getInstance()->setStringInfoPanel(tmpString);
2906
2907                 //Extraction data from contours of each slice
2908                 _contourextractdata->SetZtoBeAnalys( z);
2909
2910                 tempVector[1]=z;
2911                 Instant instant(&tempVector);
2912                 std::vector<ContourThing**> lstContourThings = kernelManager->getOutlinesAtInstant( &instant );
2913                 sizeLstContourThings = lstContourThings.size();
2914
2915                 lstManConMod.clear();
2916                 for (ii=0 ; ii<sizeLstContourThings ; ii++)
2917                 {
2918                         ContourThing **contourthing = lstContourThings[ii];
2919                         lstManConMod.push_back( (*contourthing)->getModel() );
2920                 }
2921                 lstManConModExp =  kernelManager->ExploseEachModel( lstManConMod );
2922
2923
2924                 int iContourGroup,sizeContourGroup;
2925                 if (typeContourGroup==3) // contour separete
2926                 {
2927                         sizeContourGroup=lstManConModExp.size();
2928                 } else {  // contour AND OR XOR
2929                         sizeContourGroup=1;
2930                 }
2931
2932                 for( iContourGroup=0 ; iContourGroup<sizeContourGroup ; iContourGroup++ ){
2933                         lstManConModTmp.clear();
2934                         if (typeContourGroup==3) // contour separete
2935                         {
2936                                 lstManConModTmp.push_back( lstManConModExp[iContourGroup]);
2937                         } else {  // contour AND OR XOR
2938                                 lstManConModTmp = lstManConModExp;
2939                         }
2940
2941                         _contourextractdata->SetLstManualContourModel( lstManConModTmp );
2942                         _contourextractdata->CalculateImageResult(); // with actual Z
2943
2944                 } // for  iContourGroup
2945         } // for z
2946
2947         (*value) = _contourextractdata->GetVtkImageValueResult();
2948         (*mask)  = _contourextractdata->GetVtkImageMaskResult();
2949
2950 }
2951
2952 std::string wxContourMainFrame::GetStringTypeImage( vtkImageData* image)
2953 {
2954         std::string result="";
2955         if ( image->GetScalarType()==VTK_CHAR )
2956         {
2957                 result="CHAR";
2958         } else if ( image->GetScalarType()==VTK_UNSIGNED_CHAR ){
2959                 result="UCHAR";
2960         } else if ( image->GetScalarType()==VTK_FLOAT ){
2961                 result="FLOAT";
2962         } else if ( image->GetScalarType()==VTK_DOUBLE ){
2963                 result="DOUBLE";
2964         } else if ( image->GetScalarType()==VTK_INT ){
2965                 result="INT";
2966         } else if ( image->GetScalarType()==VTK_UNSIGNED_INT ){
2967                 result="UINT";
2968         } else if ( image->GetScalarType()==VTK_SHORT ){
2969                 result="SHORT";
2970         } else if ( image->GetScalarType()==VTK_UNSIGNED_SHORT ){
2971                 result="USHORT";
2972         } else if ( image->GetScalarType()==VTK_LONG ){
2973                 result="LONG";
2974         } else if ( image->GetScalarType()==VTK_UNSIGNED_LONG ){
2975                 result="ULONG";
2976         }
2977         return result;
2978 }
2979
2980 void wxContourMainFrame::SaveImageResult(std::string directory,std::string namefile, vtkImageData* mask,vtkImageData* value)
2981 {
2982         std::string stringType;
2983         double spc[3];
2984         kernelManager->GetSpacing(spc,0);   // returns the spacing of the first image
2985         stringType              = GetStringTypeImage(value);
2986         std::string temp = directory + "/" + namefile + "-image-Value-"+stringType+".mhd";
2987
2988         wxString filename = crea::std2wx(temp);
2989
2990 // Image Value
2991         
2992         vtkImageChangeInformation *valueChInfo = vtkImageChangeInformation::New();
2993 //EED 2017-01-01 Migration VTK7
2994 #if VTK_MAJOR_VERSION <= 5
2995         valueChInfo->SetInput(value);
2996 #else
2997         valueChInfo->SetInputData(value);
2998 #endif
2999         valueChInfo->SetSpacingScale(spc);      
3000         valueChInfo->Update();  
3001         vtkMetaImageWriter *writerValueImage = vtkMetaImageWriter::New( );
3002
3003 //EED 2017-01-01 Migration VTK7
3004 #if VTK_MAJOR_VERSION <= 5
3005         writerValueImage->SetInput( valueChInfo->GetOutput() );
3006 #else
3007         writerValueImage->SetInputData( valueChInfo->GetOutput() );
3008 #endif
3009         writerValueImage->SetFileName( (const char *)filename.mb_str() );
3010         writerValueImage->SetFileDimensionality( 3 );
3011         writerValueImage->SetCompression(false);
3012         writerValueImage->Write( );
3013
3014 // Image Mask
3015         stringType              = GetStringTypeImage(mask);
3016         temp = directory + "/" + namefile + "-image-Mask-"+stringType+".mhd";
3017
3018         // LG 14/01/09 : using crea
3019         filename = crea::std2wx(temp);
3020         //      filename.Printf(_T(temp.c_str()));
3021
3022
3023         vtkImageChangeInformation *maskChInfo = vtkImageChangeInformation::New();
3024 //EED 2017-01-01 Migration VTK7
3025 #if VTK_MAJOR_VERSION <= 5
3026         maskChInfo->SetInput(mask);
3027 #else
3028         maskChInfo->SetInputData(mask);
3029 #endif
3030         maskChInfo->SetSpacingScale(spc);       
3031         maskChInfo->Update();   
3032         vtkMetaImageWriter *writerMaskImage = vtkMetaImageWriter::New( );
3033
3034 //EED 2017-01-01 Migration VTK7
3035 #if VTK_MAJOR_VERSION <= 5
3036         writerMaskImage->SetInput( maskChInfo->GetOutput() );
3037 #else
3038         writerMaskImage->SetInputData( maskChInfo->GetOutput() );
3039 #endif
3040
3041         writerMaskImage->SetFileName( (const char *)filename.mb_str() );
3042         writerMaskImage->SetFileDimensionality( 3 );
3043         writerMaskImage->SetCompression(false);
3044         writerMaskImage->Write( );
3045
3046         interfMainPanel::getInstance()->setStringInfoPanel( _T("") );
3047
3048 }
3049
3050
3051
3052 void wxContourMainFrame::onChangeInstantInstantPanel(std::string name,int value, int minshow, int maxshow){
3053         if( name.compare( _theViewPanel->getVerticalConceptName() ) == 0){
3054                 _theViewPanel->setActualVertical( value);
3055         }
3056         else if( name.compare( _theViewPanel->getHorizontalConceptName() ) == 0|| _instantPanel->getIfConceptCheckedAt( name, 0 ) )     {
3057                 _theViewPanel->setHorizontalConcept( name, minshow, maxshow, minshow, maxshow, value);
3058         }
3059
3060         changeInstant();
3061 }
3062
3063 void wxContourMainFrame::onSnakePressed(){
3064         std::vector<double> vecX;
3065         std::vector<double> vecY;
3066         std::vector<double> vecZ;
3067         _theViewPanel->GetPointsOfActualContour( &vecX , &vecY , &vecZ );
3068
3069         if (vecX.size()!=0){
3070                 std::vector<int> tempVector;
3071                 _instantPanel->getInstant( tempVector );
3072                 int i,size=vecZ.size();
3073                 int actualSlice = tempVector[1];
3074                 for ( i=0 ; i<size ; i++ )
3075                 {
3076                         vecZ[i] = actualSlice;
3077                 } // for
3078
3079                 wxDialog* dialog = new wxDialog(this, -1, wxString(_T("Snake")));
3080                 wxPanel* panel = new wxPanel(dialog,-1);
3081                 //              wxStaticText* sttext = new wxStaticText(panel, -1, wxString(_T("Panel para snake")));
3082          new wxStaticText(panel, -1, wxString(_T("Panel para snake")));
3083                 dialog->ShowModal();
3084         } // if
3085
3086 }
3087
3088 void wxContourMainFrame::saveFileWithContoursAutomatique()
3089 {
3090 printf("EED wxContourMainFrame::saveFileWithContoursAutomatique \n");
3091         std::string filename = kernelManager->getCurrentFileName();
3092         if(filename.compare("")!=0){
3093                 saveFileWithContours(filename);
3094         }else{
3095                 onSave();
3096         }
3097 }
3098 void wxContourMainFrame::ShowToolsPanel(bool show)
3099 {
3100         _pannew->Show(show);
3101 }
3102
3103
3104
3105 void wxContourMainFrame::SetContourGroup(int contourGroup)
3106 {
3107         _contourGroup = contourGroup;
3108 }
3109
3110
3111 wxPanel *wxContourMainFrame::getMaskImageViewPanel(wxWindow *parent)
3112 {
3113  
3114         if      (_viewMaskImagePanel==NULL)
3115         {
3116                 _contourextractdata = new ContourExtractData(true);
3117                 _contourextractdata->SetImage( _theViewPanel->getImageData() );
3118 //              double range[2];
3119 //              _theViewPanel->getImageData()->GetScalarRange(range);
3120                 //int min = (int)floor (range[0]);
3121                 //int max = (int)ceil (range[1]);
3122
3123 //EED 2017-12-17
3124                 int min = 254;
3125                 int max = 256;
3126
3127                 _viewMaskImagePanel = new ThresholdImageViewPanel( parent, -1, -1 , -1,-1,  0);
3128                 _viewMaskImage = new ThresholdImageView();
3129                 _viewMaskImage->SetImage( _contourextractdata->GetVtkImageMaskResult() );
3130                 _viewMaskImage->SetminMaxValue( min, max);
3131                 _viewMaskImage->SetBaseColor( 0,0,1 );
3132
3133
3134                 std::vector<int> colorbarposition;
3135                 colorbarposition.push_back( -999 );
3136                 colorbarposition.push_back( -999 );
3137                 _viewMaskImage->SetColorBarPosition( colorbarposition );
3138                 double spc[3];
3139                 _viewMaskImage->SetSpcBase( _theViewPanel->getImageData()->GetSpacing() );
3140                 _viewMaskImage->SetNewSpacingLayer( _theViewPanel->getImageData()->GetSpacing() );
3141
3142                 _viewMaskImagePanel->SetThresholdImageView( _viewMaskImage );
3143                 _viewMaskImage->SetwxVtkBaseView( _theViewPanel->getWxVtkBaseView() );
3144                 _viewMaskImage->onThresholdChangeOpacity( 25 );
3145         }
3146         return _viewMaskImagePanel;
3147 }
3148
3149
3150 wxPanel *wxContourMainFrame::getColorLayerImageViewPanel(wxWindow *parent)
3151 {
3152         if      (_viewColorLayerImagePanel==NULL)
3153         {
3154                 double range[2];
3155                 _theViewPanel->getImageData()->GetScalarRange(range);
3156                 int min = (int)floor (range[0]);
3157                 int max = (int)ceil (range[1]);
3158                 _viewColorLayerImagePanel = new ColorLayerImageViewPanel( parent, min, max, 100, 1);
3159                 _viewColorLayerImagePanel->GetColorLayerImageViewManager()->SetwxVtkBaseView( 0 , _theViewPanel->getWxVtkBaseView() );
3160         //    std::vector<double> range = bbGetInputlstRangeForColorBar();
3161         //    clivp->GetColorLayerImageViewManager()->SetRangeForColorBar( range );
3162                 std::vector<int> colorbarposition;
3163                 colorbarposition.push_back( 50 );
3164                 colorbarposition.push_back( 105 );
3165                 _viewColorLayerImagePanel->GetColorLayerImageViewManager()->SetColorBarPosition( colorbarposition );
3166         //    std::vector<double> base_color;
3167         //    _viewColorLayerImagePanel->GetColorLayerImageViewManager()->SetBaseColors( base_color );
3168         //    std::vector<double> grey_level_boundaries;
3169         //    clivp->GetColorLayerImageViewManager()->SetGreyLevelBoundaries( grey_level_boundaries );
3170                 std::vector<double> transparence_level_boundaries;
3171                 transparence_level_boundaries.push_back(0);
3172                 _viewColorLayerImagePanel->GetColorLayerImageViewManager()->SetBaseTransparence( transparence_level_boundaries );
3173                 _viewColorLayerImagePanel->GetColorLayerImageViewManager()->SetPlainOrGradientColor( false );
3174 //              _viewColorLayerImagePanel->SetFittingMode( 3 );
3175         }
3176         return _viewColorLayerImagePanel;
3177 }
3178
3179 void wxContourMainFrame::SetColorLayerImage(vtkImageData* img)
3180 {
3181         if (_viewColorLayerImagePanel!=NULL) 
3182         {
3183                 if (img!=NULL)
3184                 {
3185                         _viewColorLayerImagePanel->SetActive(true);
3186                         _viewColorLayerImagePanel->SetImage( img );
3187 //                      RefreshInterface();
3188                 } // img
3189         } // _viewColorLayerImagePanel
3190 }
3191
3192 wxPanel *wxContourMainFrame::getThresholdImageViewPanel(wxWindow *parent)
3193 {
3194         if      (_viewThresholdImagePanel==NULL)
3195         {
3196                 double range[2];
3197                 _theViewPanel->getImageData()->GetScalarRange(range);
3198                 int min                                         = (int)floor (range[0]);
3199                 int max                                         = (int)ceil (range[1]);
3200                 int start                                       = (max+min)/2 - (max-min)*0.25; 
3201                 int end                                         = (max+min)/2 + (max-min)*0.25; 
3202                 _viewThresholdImagePanel        = new ThresholdImageViewPanel( parent, min, max, start, end , 1);
3203                 _viewThresholdImage             = new ThresholdImageView();
3204                 _viewThresholdImage->SetminMaxValue(start,end);
3205 //              _viewThresholdImage->SetminMaxValue(range[0],range[1]);
3206                 _viewThresholdImage->SetImage( _theViewPanel->getImageData() );
3207                 std::vector<int> colorbarposition;
3208                 colorbarposition.push_back( 10 );
3209                 colorbarposition.push_back( 105 );
3210                 _viewThresholdImage->SetColorBarPosition( colorbarposition );
3211                 double spc[3];
3212                 _viewThresholdImage->SetSpcBase( _theViewPanel->getImageData()->GetSpacing() );
3213                 _viewThresholdImage->SetNewSpacingLayer( _theViewPanel->getImageData()->GetSpacing() );
3214
3215                 _viewThresholdImage->SetBaseColor( 1,0,0 );
3216                 _viewThresholdImagePanel->SetThresholdImageView( _viewThresholdImage );
3217                 _viewThresholdImage->SetwxVtkBaseView( _theViewPanel->getWxVtkBaseView() );
3218                 _viewThresholdImage->onThresholdChangeOpacity( 25 );
3219                 RefreshInterface();
3220         }
3221         return _viewThresholdImagePanel;
3222 }
3223
3224 //CMRU 17-08-09-----------------------------------------------------------------------------------------------
3225 int wxContourMainFrame::getType ()
3226 {
3227         int tipo = 0;
3228         std::vector<std::string> currentSelection = _theViewPanel->getSelectedObjects();
3229
3230         if(!currentSelection.empty())
3231         {
3232                 std::string cloneName = currentSelection [0];
3233                 manualBaseModel * manualModel = kernelManager->getOutlineByKeyName(cloneName);
3234                 tipo = manualModel-> GetTypeModel();
3235         }
3236         return tipo;
3237 }
3238
3239 double wxContourMainFrame::getContourSizeInPixels()
3240 {
3241         double contourSize = 0;
3242
3243         std::vector<std::string> currentSelection = _theViewPanel->getSelectedObjects();        if(!currentSelection.empty())
3244         if(!currentSelection.empty())
3245         {
3246                 std::string cloneName = currentSelection [0];
3247
3248                 manualBaseModel * manualModel = kernelManager->getOutlineByKeyName(cloneName);//_modelManager->getOutlineByKeyName( cloneName )->getModel();
3249
3250 // EED 2017-05-30
3251 //              contourSize = manualModel->GetPathSize();
3252                 double spc[3];
3253                 spc[0]=1; 
3254                 spc[1]=1; 
3255                 spc[2]=1; 
3256                 contourSize = manualModel->GetPathSize( spc );
3257         }
3258         return contourSize;
3259 }
3260
3261 manualBaseModel * wxContourMainFrame::getContour ()
3262 {
3263         std::vector<std::string> currentSelection = _theViewPanel->getSelectedObjects();
3264
3265         if(!currentSelection.empty())
3266         {
3267                 std::string cloneName = currentSelection [0];
3268                 manualBaseModel * manualModel = kernelManager->getOutlineByKeyName(cloneName);//_modelManager->getOutlineByKeyName( cloneName )->getModel();
3269                 return manualModel;
3270         }
3271         return NULL;
3272 }
3273 void wxContourMainFrame::onPrintLabel (wxString label, manualBaseModel* manualModel)
3274 {
3275         std::string labelAscii(label.ToAscii());
3276         int pos = labelAscii.find(" ");
3277
3278         int j;
3279
3280         for (j=0 ; pos != string::npos;j++)
3281         {
3282                 labelAscii.replace( pos, 1, "_" );
3283                 pos= labelAscii.find(" ");
3284         }
3285
3286         manualModel -> SetLabel(labelAscii);
3287 }
3288 void wxContourMainFrame::onInsertCalculation(manualBaseModel* manualModel)
3289 {
3290 // EED 2017-05-30
3291 //      double sizeInPixel      = manualModel ->GetPathSize(  );
3292         double spc[3];
3293         spc[0]=1; // ????
3294         spc[1]=1; // ????
3295         spc[2]=1; // ????
3296         double sizeInPixel      = manualModel ->GetPathSize( spc );
3297
3298         double onePixelRealSize = interfMainPanel::getInstance()->GetPixelValue();;
3299         double realContourSize  = sizeInPixel*onePixelRealSize;
3300         manualModel ->SetRealSize(realContourSize);
3301 }
3302
3303 double wxContourMainFrame::onePixelSize( double value)
3304 {
3305         return _onePixelSize = value;
3306 }
3307
3308 std::string wxContourMainFrame::GetFileLocation()
3309 {
3310         return _fileLocation;
3311 }
3312
3313 void wxContourMainFrame::SetFileLocation(std::string newFileLocation)
3314 {
3315         _fileLocation = newFileLocation;
3316         std::cout<<"GETFILELOCATION:"<<_fileLocation<<std::endl;
3317
3318 //EED 2019-12-17
3319         kernelManager->setCurrentFileName(_fileLocation);
3320 }
3321 //------------------------------------------------------------------------------------------------------------
3322
3323
3324
3325
3326
3327
3328
3329
3330 void wxContourMainFrame::FlipSelectedContours(int flipDirection)
3331 {
3332         FlipLstOfContours( 
3333                             (std::vector<std::string>)_theViewPanel->getSceneManager()->getSelectedObjects() , 
3334                             flipDirection
3335                           );    
3336                 
3337 }
3338
3339 void wxContourMainFrame::FlipActualSliceContours(int flipDirection)
3340 {
3341         FlipLstOfContours( 
3342                             (std::vector<std::string>)_theViewPanel->getSceneManager()->GetlstContoursNameActualSlice() , 
3343                             flipDirection
3344                           );    
3345 }
3346
3347 void wxContourMainFrame::FlipAllContours(int flipDirection)
3348 {
3349         FlipLstOfContours( 
3350                             kernelManager->GetLstNameThings() , 
3351                             flipDirection
3352                           );
3353 }
3354
3355 void wxContourMainFrame::FlipLstOfContours(std::vector<std::string> lstNameThings, int flipDirection)
3356 {
3357         int ext[6];
3358         getImageData()->GetExtent(ext);         
3359         int sizeX = ext[1]-ext[0];
3360         int sizeY = ext[3]-ext[2];
3361
3362         
3363         int i,sizeLstNameThings;
3364         int ii,sizeLstPoints;
3365         
3366         sizeLstNameThings       = lstNameThings.size(); 
3367         for (i=0 ; i<sizeLstNameThings ; i++)
3368         {
3369                 manualBaseModel * manualModel = kernelManager->getOutlineByKeyName(lstNameThings[i]);
3370                 if (flipDirection==0)
3371                 {
3372                         manualModel->Transform_Ax_Plus_B(-1,sizeX,1,0 );
3373                 } else {
3374                         manualModel->Transform_Ax_Plus_B(1,0,-1,sizeY );
3375                 }
3376         }// for i  list of Things
3377
3378         //-- Static Contours
3379
3380         lstNameThings           = kernelManager->GetLstNameThingsStatic();
3381         sizeLstNameThings       = lstNameThings.size();
3382         for (i=0 ; i<sizeLstNameThings ; i++)
3383         {
3384                 manualBaseModel * manualModel = kernelManager->getOutlineByKeyName(lstNameThings[i]);
3385                 if (flipDirection==0)
3386                 {
3387                         manualModel->Transform_Ax_Plus_B(-1,sizeX,1,0 );
3388                 } else {
3389                         manualModel->Transform_Ax_Plus_B(1,0,-1,sizeY );
3390                 }
3391         }// for i  list of static things        
3392 }
3393
3394 void wxContourMainFrame::FlipContours(int typeContourFlip, int flipDirection)
3395 {
3396         saveState();
3397         
3398         if (typeContourFlip==0) // 
3399         {
3400                 FlipSelectedContours(flipDirection);
3401         }
3402
3403         if (typeContourFlip==1) // 
3404         {
3405                 FlipActualSliceContours(flipDirection);
3406         }
3407         
3408         if (typeContourFlip==2) // 
3409         {
3410                 FlipAllContours(flipDirection);
3411         }
3412         RefreshInterface();
3413 }
3414
3415 void wxContourMainFrame::SetXY(int x, int y)
3416 {
3417         _theViewPanel->SetXY(x,y);
3418 }
3419
3420 wxVtkBaseView* wxContourMainFrame::GetWxVtkBaseView()
3421 {
3422         if (_theViewPanel!=NULL)
3423         {
3424                 return _theViewPanel->getWxVtkBaseView();;
3425         } else {
3426                 return NULL;
3427         }
3428 }
3429
3430
3431