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