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