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