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