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