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