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