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