1 /*# ---------------------------------------------------------------------
3 # Copyright (c) CREATIS (Centre de Recherche en Acquisition et Traitement de l'Image
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
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.
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
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 # ------------------------------------------------------------------------ */
26 //----------------------------------------------------------------------------------------------------------------
27 // Class definition include
28 //----------------------------------------------------------------------------------------------------------------
29 #include "wxContourMainFrame.h"
33 //----------------------------------------------------------------------------------------------------------------
35 //----------------------------------------------------------------------------------------------------------------
38 #include "NameWrapper.h"
39 #include "wx/artprov.h"
40 #include "ConceptDataWrap.h"
46 //----------------------------------------------------------------------------------------------------------------
47 // Class implementation
48 //----------------------------------------------------------------------------------------------------------------
49 /** @file wxContourMainFrame.cxx */
51 //------------------------------------------------------------------------------------------------------------
52 // Constructors & Destructors
53 //------------------------------------------------------------------------------------------------------------
55 wxContourMainFrame* wxContourMainFrame:: instance = NULL;
56 char wxContourMainFrame::COPY = 'C';
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)
63 m_mgr.SetManagedWindow(this);
65 _creatingContoursActive = false;
67 // _modelManager = NULL;
69 // _buttonsBar = NULL;
71 // _drawToolsPanel = NULL;
72 // _operationsToolsPanel = NULL;
73 //_autoFormsPanel = NULL;
74 // _standardToolsPanel = NULL;
75 // _editionToolsPanel = NULL;
76 // _listViewPanel = NULL;
77 // _sceneManager = NULL;
78 //_actualInstant = NULL;
79 _numberOfVariablesStatistics= 6+1;
81 _refLineControl = NULL;
84 // _actorPresent = false;
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;
91 _contourextractdata = NULL;
92 _viewMaskImage = NULL;
93 _viewMaskImagePanel = NULL;
94 _viewThresholdImage = NULL;
95 _viewThresholdImagePanel = NULL;
96 _viewColorLayerImagePanel = NULL;
98 _frameShowResultImages = NULL;
101 wxContourMainFrame::wxContourMainFrame(wxWindow* parent, wxWindowID id,const wxString& title,const wxPoint& pos,const wxSize& size,std::vector<vtkImageData*> images, long style,std::string datadir)
102 : wxPanel(parent, id, pos, size, style)
104 m_mgr.SetManagedWindow(this);
106 _creatingContoursActive = false;
107 _theViewPanel = NULL;
108 _instantPanel = NULL;
109 _refLineControl = NULL;
110 _refLineModel = NULL;
112 // _actorPresent = false;
113 _viewMaskImage = NULL;
114 _viewMaskImagePanel = NULL;
115 _viewThresholdImage = NULL;
116 _viewThresholdImagePanel = NULL;
117 _viewColorLayerImagePanel = NULL;
118 // set up default notebook style
119 m_notebook_style = wxAUI_NB_TAB_SPLIT | wxAUI_NB_TAB_EXTERNAL_MOVE | wxNO_BORDER;
120 m_notebook_theme = 0;
121 //wxContour_ActionCommandsID a;
122 _numberOfVariablesStatistics= 7;
126 _pannew = interfMainPanel::getInstance(this,datadir+"/data/Icons");//, eventHandler);
127 _performingOperation = new PerformingOperation();
128 if(images.size() > 0)
130 this->setVectImages(images);
132 _contourextractdata = NULL;
135 void wxContourMainFrame::setVectImages(std::vector<vtkImageData*> imgs)
139 std::string str_home(getenv("USERPROFILE"));
140 #elif defined(__GNUC__)
141 std::string str_home(getenv("HOME"));
143 std::string strCreaContourDataTmp = str_home + "/.creaContourDataTemp/";
144 std::vector<std::string> conceptNameVect;
145 std::vector<int> conceptSizeVect;
146 notebook = this->createNotebook();
147 kernelManager = new KernelManagerContour( imgs , _datadir+"/data/" , strCreaContourDataTmp );
148 _instantPanel = new wxInstantChooserPanel( notebook, "Instant Chooser", true, false, "c" );
149 _theViewPanel = new wxContourViewPanel( kernelManager->getSourceImage(), notebook );
150 //-------------------------------------------------------------
151 kernelManager->getConceptsInformation(conceptNameVect, conceptSizeVect);
152 _instantPanel->addConcepts(conceptNameVect, conceptSizeVect);
153 double val = _theViewPanel->getCurrentDeep();
154 _instantPanel->setConceptValue( "Axe Depth", (int)val );
155 //JCP _instantPanel->setConceptValue("time", num de imagenes);
156 ConceptDataWrap * data = _instantPanel->getConceptDataOf( "Axe Depth" );
157 //*******************changeInstant();
158 _theViewPanel->setVerticalConcept( "Axe Depth", data->getMinValue(), data->getMaxValue(), data->getMinShowedValue(), data->getMaxShowedValue(), data->getActualValue() );
159 this->configurePanels( );
163 wxContourMainFrame* wxContourMainFrame :: getInstance(wxWindow* parent, wxWindowID id,const wxString& title,const wxPoint& pos,const wxSize& size,std::vector<vtkImageData*> images, long style,std::string datadir )
165 if(instance == NULL){
166 instance = new wxContourMainFrame(parent, id, title, pos, size, images, style,datadir);
171 std::vector<vtkImageData*> wxContourMainFrame ::getVectImages()
173 return kernelManager->getVectImages();
176 wxContourMainFrame* wxContourMainFrame :: getInstance()
181 void wxContourMainFrame :: resetInstance()
186 wxContourMainFrame :: ~wxContourMainFrame()
188 delete _contourextractdata;
191 interfMainPanel::resetInstance();
192 delete kernelManager;
194 //_pannew->Destroy();
200 //El problema al cerrar la aplicacion puede estar asociado
201 //a que wxAUINotebook esta en la aplicacion
202 //principal (wxContourGUIExample)tambien
203 //EED???? delete _theViewPanel;
204 //EED???? delete _instantPanel;
205 //EED???? delete _buttonsBar;
206 //EED???? delete _actualInstant;
207 //EED???? delete _sceneManager;
211 //------------------------------------------------------------------------------------------------------------
212 // Creational and initialization methods using WxAui
213 //------------------------------------------------------------------------------------------------------------
215 wxAuiNotebook * wxContourMainFrame :: createNotebook()
217 wxSize client_size = GetClientSize();
218 wxAuiNotebook* noteBook = new wxAuiNotebook(this, -1, wxPoint(client_size.x, client_size.y), wxSize(430,200), m_notebook_style);
219 wxBitmap page_bmp = wxArtProvider::GetBitmap(wxART_NORMAL_FILE, wxART_OTHER, wxSize(16,16));
224 //------------------------------------------------------------------------------------------------------------
225 // Creational and initialization methods
226 //------------------------------------------------------------------------------------------------------------
227 bool wxContourMainFrame :: configurePanels( )
229 bool configured = _theViewPanel!=NULL;
231 configured &= _theViewPanel!=NULL;
232 if( _theViewPanel!=NULL )
234 notebook->AddPage( _theViewPanel, wxT(" View ") );
239 notebook->AddPage( _instantPanel, wxT("Instant Page") );
242 m_mgr.AddPane(notebook, wxAuiPaneInfo().Name(wxT("notebook_content")).CenterPane().PaneBorder(false));
244 SetMinSize(wxSize(300,300));
250 bool wxContourMainFrame::addNewPanel(wxPanel* panel)
252 bool configured = panel!=NULL;
253 configured &= panel!=NULL;
257 notebook->AddPage( panel, wxT(" Viewer "), true );
263 //------------------------------------------------------------------------------------------------------------
264 // Attributes getters and setters
265 //------------------------------------------------------------------------------------------------------------
269 void wxContourMainFrame :: setInstantChooserPanel( wxInstantChooserPanel * theInstantChooserPanel )
271 _instantPanel = theInstantChooserPanel;
274 // void wxContourMainFrame :: setButtonsBar( wxContour_ButtonsBar * theButtonsBar )
276 // _buttonsBar = theButtonsBar;
279 // void wxContourMainFrame :: setGrid( wxContour_Grid * theGridPanel )
281 // _gridPanel = theGridPanel;
284 // void wxContourMainFrame :: setDrawToolsPanel( wxContour_DrawToolsPanel * theDrawToolsPanel )
286 // _drawToolsPanel = theDrawToolsPanel;
289 // void wxContourMainFrame :: setOperationsToolsPanel( wxContour_OperationsToolsPanel * theOperationsToolsPanel )
291 // _operationsToolsPanel = theOperationsToolsPanel;
294 // void wxContourMainFrame :: setAutomaticFormsPanel( wxContour_AutomaticFormsToolsPanel * theAutoFormsPanel )
296 // _autoFormsPanel = theAutoFormsPanel;
299 // void wxContourMainFrame :: setStandardToolsPanel( wxContour_StandardToolsPanel * theStandardToolsPanel )
301 // _standardToolsPanel= theStandardToolsPanel;
304 // void wxContourMainFrame :: setEditionToolsPanel( wxContour_EdtionToolsPanel * theEditionToolsPanel )
306 // _editionToolsPanel = theEditionToolsPanel;
309 // void wxContourMainFrame :: setListViewPanel( wxContour_ListViewPanel * theListViewPanel )
311 // _listViewPanel = theListViewPanel;
316 void wxContourMainFrame::onCreateContourSpline( ){
318 //JCP 20-10-08 Undo redo implementation
320 //JCP 20-10-08 Undo redo implementation
325 void wxContourMainFrame::onCreateContourRectangle( )
327 //JCP 20-10-08 Undo redo implementation
329 //JCP 20-10-08 Undo redo implementation
333 void wxContourMainFrame::onCreateContourCircle( )
335 //JCP 20-10-08 Undo redo implementation
337 //JCP 20-10-08 Undo redo implementation
341 void wxContourMainFrame::onCreateContourLine( )
343 //JCP 20-10-08 Undo redo implementation
345 //JCP 20-10-08 Undo redo implementation
349 // RaC 09-09 --------------------------------------
350 void wxContourMainFrame::onCreateContourPoints( )
352 //JCP 20-10-08 Undo redo implementation
354 //JCP 20-10-08 Undo redo implementation
357 // RaC 09-09 --------------------------------------
359 // RaC 10-09 --------------------------------------
360 void wxContourMainFrame::onCreateContourPolygon( )
362 //JCP 20-10-08 Undo redo implementation
364 //JCP 20-10-08 Undo redo implementation
367 // RaC 10-09 --------------------------------------
369 //------------------------------------------------------------------------------------------------------------
371 void wxContourMainFrame :: onCreateContourBullEye(wxPanel* panel )
373 //Creating the manualBaseModel and including in the model
374 manualBaseModel * manModelContour = factoryManualContourModel(panel );
376 std::vector<int> instantVector;
377 _instantPanel->getInstant( instantVector );
378 std::string theName = kernelManager->createOutline(manModelContour, instantVector);
380 /*std::vector<int> instantVector;
381 _instantPanel->getInstant( instantVector );
383 theName= _modelManager->createOutline( manModelContour, instantVector );*/
384 bool addedModel = theName.compare("") != 0;//??
388 double spc[3];//Si no hay imagen pero hay contornos que spacing se pone por default
389 _theViewPanel->getSpacing(spc);
390 //Adding the manualContourControler to interface objects structure
391 //Adding the manualViewContour to interface objects structure
392 //_theViewPanel->getSceneManager()->setControlActiveStateOfALL( false );//This call is being done here because if the ROI is created underneath the previously created ROIS will still be active.
393 _theViewPanel->getSceneManager()->configureViewControlTo( theName, manModelContour,spc , 4) ;
397 void wxContourMainFrame :: createContour( int typeContour )
399 //Creating the manualContourModel and including in the model
400 manualBaseModel * manModelContour = kernelManager->factoryManualContourModel(typeContour);
401 std::vector<int> instantVector;
402 _instantPanel->getInstant( instantVector );
403 std::string theName = kernelManager->createOutline(manModelContour, instantVector);
404 /*std::vector<int> instantVector;
405 _instantPanel->getInstant( instantVector );
407 theName= _modelManager->createOutline( manModelContour, instantVector );*/
408 bool addedModel = theName.compare("") != 0;//??
411 double spc[3];//Si no hay imagen pero hay contornos que spacing se pone por default
412 _theViewPanel->getSpacing(spc);
413 //Adding the manualContourControler to interface objects structure
414 //Adding the manualViewContour to interface objects structure
415 //_sceneManager->setControlActiveStateOfALL( false );//This call is being done here because if the ROI is created underneath the previously created ROIS will still be active.
416 _theViewPanel->getSceneManager()->configureViewControlTo( theName, manModelContour,spc , typeContour) ;
420 manualBaseModel * wxContourMainFrame::factoryManualContourModel(wxPanel* panel){
422 manualContourModelBullEye *manModelContourBullEye = new manualContourModelBullEye();
423 manualBaseModel *manModelContour=NULL;
424 manModelContour = manModelContourBullEye;
426 int iCrown,sizeCrowns,iSector,sizeSectors;
427 double radioA,radioB,ang,angDelta ;
428 sizeCrowns = ((PanelBullEyeOptions*)panel)->GetNumberOfCrowns();
429 for ( iCrown=0 ; iCrown<sizeCrowns ; iCrown++ )
431 sizeSectors = ((PanelBullEyeOptions*)panel)->GetNumberOfSections(iCrown);
432 radioB = ((PanelBullEyeOptions*)panel)->GetRadioOfCrown(iCrown);
433 if (iCrown==sizeCrowns-1)
437 radioA = ((PanelBullEyeOptions*)panel)->GetRadioOfCrown(iCrown+1);
441 for ( iSector=0 ; iSector<sizeSectors ; iSector++ )
443 ang = ((PanelBullEyeOptions*)panel)->GetAngOfCrownSection(iCrown,iSector);
444 angDelta= ((PanelBullEyeOptions*)panel)->GetAngDeltaOfCrownSection(iCrown);
445 manModelContourBullEye->AddSector(radioA,radioB,ang,angDelta);
448 } // if _panelBullEyeOptions
450 return manModelContour;
453 void wxContourMainFrame :: saveState()
455 std::string temp = kernelManager->saveState();
456 saveFileWithContours(temp);
459 void wxContourMainFrame::onDeleteContour()
461 //JCP 20-10-08 Undo redo implementation
463 //JCP 20-10-08 Undo redo implementation
465 std::vector<std::string> lstKeyNameToBeErase;
466 lstKeyNameToBeErase = _theViewPanel->getSceneManager()->getSelectedObjects();
467 deleteContours( lstKeyNameToBeErase );
469 int i,size=_sceneManager->getSelectedObjects().size();
472 std::string keyName = _sceneManager->getSelectedObjects()[i];
473 int ispartofstaticlist = this->_modelManager->IsPartOfStaticList( keyName );
474 if ( ispartofstaticlist>=0 )
476 std::vector<int> tempVector;
477 _instantPanel->getInstant( tempVector );
478 Instant instant(&tempVector);
479 this->_modelManager->ChangeContourOfList(keyName, &instant);
483 std::vector<std::string> lstKeyName;
484 std::vector<std::string> lstKeyNameActualSlice;
485 std::vector<std::string> lstKeyNameToBeErase;
487 lstKeyNameToBeErase = _sceneManager->getSelectedObjects();
488 lstKeyNameActualSlice = _sceneManager->GetlstContoursNameActualSlice();
489 int k,kSize=lstKeyNameToBeErase.size();
490 int j,jSize=lstKeyNameActualSlice.size();
492 for (k=0;k<kSize; k++)
495 for (j=0;j<jSize; j++)
497 if (lstKeyNameToBeErase[k]==lstKeyNameActualSlice[j])
504 lstKeyName.push_back( lstKeyNameToBeErase[k] );
508 deleteContours( lstKeyName );
512 void wxContourMainFrame :: deleteContours( std::vector<std::string> keyNamesVector )
514 int i,size=keyNamesVector.size();
517 deleteContour( keyNamesVector[i] );
521 void wxContourMainFrame :: deleteContour( std::string theKeyName )
524 manualContourModel * cModel;
525 manualViewBaseContour * cViewer;
526 manualContourBaseControler * cControler;
528 ContourWrap_ViewControl *conwrapviewControl = _theViewPanel->getSceneManager()->getContourWrap_ViewControlOf( theKeyName );
529 cControler = conwrapviewControl->getControler();*/
532 bool isedit = _theViewPanel->isEditableCControler(theKeyName);
533 bool ispartofstaticlst = kernelManager->IsPartOfStaticList(theKeyName);
535 if (isedit && ispartofstaticlst)
537 _theViewPanel->removeFromScene(theKeyName);
539 kernelManager->deleteCModel(theKeyName);
540 //_theViewPanel->getSceneManager()->removeFromScene( theKeyName );
541 //cViewer = conwrapviewControl->getViewer();
542 //_theViewPanel->getSceneManager()->removeWrap( theKeyName );
543 //cControler* conwrapviewControl->getControler();
546 // delete cControler;
551 void wxContourMainFrame::onDeleteContoursActSlice(){
552 //JCP 20-10-08 Undo redo implementation
554 //JCP 20-10-08 Undo redo implementation
555 deleteContours( (std::vector<std::string>)_theViewPanel->getSceneManager()->GetlstContoursNameActualSlice() );
557 void wxContourMainFrame::onDeleteAllContours(){
558 //JCP 20-10-08 Undo redo implementation
562 void wxContourMainFrame::deleteAllContours(){
563 //JCP 20-10-08 Undo redo implementation
566 std::vector<int> tempVector;
567 _instantPanel->getInstant( tempVector );
569 //JCP --08-09-2008 When using a diferent interface the _mbarrangeDeleteAll might not be initialize
570 // the values in GetStart and GetEnd will then not be initialize also.
571 // We use instead the values given when initializing the _deletepanel.
573 //int minZ = _mbarrangeDeleteAll->GetStart();
574 //int maxZ = _mbarrangeDeleteAll->GetEnd();
578 maxZ = _theViewPanel->getSceneManager()->GetImageDataSizeZ();
582 _theViewPanel->getSceneManager()->removeSceneContours( );
583 _theViewPanel->getSceneManager()->removeAllOutlines();
584 kernelManager->removeAllOutlines();
587 if ( (minZ==0) && (maxZ==_mbarrangeDeleteAll->GetMax() ))
589 _theViewPanel->getSceneManager()->removeSceneContours( );
590 _modelManager->removeAllOutlines();
591 _theViewPanel->getSceneManager()->removeAllOutlines();
594 for ( z=minZ ; z<=maxZ ; z++)
597 Instant instant(&tempVector);
598 std::vector<ContourThing**> lstContourThings = this->_modelManager->getOutlinesAtInstant( &instant );
600 sizeLstContourThings = lstContourThings.size();
601 for (ii=0 ; ii<sizeLstContourThings ; ii++)
603 ContourThing **contourthing = lstContourThings[ii];
604 deleteContour( (*contourthing)->getName() );
611 void wxContourMainFrame::setConceptValue( std::string name, int value )
613 _instantPanel->setConceptValue(name, value);
617 ConceptDataWrap* wxContourMainFrame::getLastConceptData()
619 return _instantPanel->getLastConceptData();
623 bool wxContourMainFrame::getIfConceptCheckedAt( std::string name, int pos )
625 return _instantPanel->getIfConceptCheckedAt( name, pos );
630 void wxContourMainFrame::ShowResultImages(int typeContourGroup, int selection, int minZ, int maxZ)
633 vtkImageData * value;
634 this->getMaskValue(&mask, &value, typeContourGroup, selection, minZ, maxZ);
636 std::vector<int> nTypeView;
637 nTypeView.push_back(5);
638 nTypeView.push_back(1);
639 nTypeView.push_back(2);
640 nTypeView.push_back(0);
642 if (_frameShowResultImages==NULL)
644 // wxFrame *_frameShowResultImages = new wxFrame(this, -1,_T("Result image extracted.."),wxDefaultPosition,wxSize(600,600), wxDEFAULT_FRAME_STYLE|wxSTAY_ON_TOP);
645 _frameShowResultImages = new wxFrame(this, -1,_T("Result image extracted.."),wxDefaultPosition,wxSize(600,600),
646 wxFRAME_TOOL_WINDOW|wxSYSTEM_MENU | wxCAPTION | wxCLIP_CHILDREN |wxFRAME_FLOAT_ON_PARENT | wxRESIZE_BORDER );
648 wxAuiManager *m_mgr_noteBookViewerResult = new wxAuiManager();
649 m_mgr_noteBookViewerResult->SetManagedWindow(_frameShowResultImages);
651 wxAuiNotebook* noteBookViewerResult = new wxAuiNotebook(_frameShowResultImages, -1, wxPoint(600, 600), wxSize(430,200), m_notebook_style);
652 m_mgr_noteBookViewerResult->AddPane(noteBookViewerResult, wxAuiPaneInfo().Name(wxT("notebook_content")).CenterPane().PaneBorder(false));
654 wxPanel *panelViewer1 = new wxMaracas_N_ViewersWidget(noteBookViewerResult, value,&nTypeView);
655 wxPanel *panelViewer2 = new wxMaracas_N_ViewersWidget(noteBookViewerResult, mask,&nTypeView);
658 noteBookViewerResult->AddPage( panelViewer1, wxT("Image result") );
659 noteBookViewerResult->AddPage( panelViewer2, wxT("Mask result") );
660 m_mgr_noteBookViewerResult->Update();
661 _frameShowResultImages->Show();
662 } // if _frameShowResultImages
668 void wxContourMainFrame::changeInstant()
670 std::vector<int> instantVect;
671 _instantPanel->getInstant( instantVect );
672 int actualSlice = instantVect[1];
673 kernelManager->setInstant(instantVect);
674 // Refresh Mask image
675 if(_viewMaskImage!=NULL)
677 _viewMaskImage->SetZ(actualSlice);
678 if (_viewMaskImagePanel->IsVisible()==true)
680 vtkImageData *mask, *value;
681 getMaskValue(&mask,&value, _contourGroup , 0, -1, -1);
682 _viewMaskImage->onThreshold();
684 } // if _viewMaskImage
685 // Refresh Threshold image
686 if(_viewThresholdImage!=NULL)
688 _viewThresholdImage->SetZ(actualSlice);
689 if (_viewThresholdImagePanel->IsVisible()==true)
691 _viewThresholdImage->onThreshold();
693 } // if _viewThresholdImage
694 updateInstantOutlines();
695 updateInstantImageData();
701 void wxContourMainFrame::updateInstantOutlines()
703 _theViewPanel->removeSceneContours();
704 _theViewPanel->addNameWrapperToScene();
706 //for( int i=0; i<size; i++)
708 // _theViewPanel->getSceneManager()->addToScene(namesWrapping[i]->getKeyName(), true, true, true, false, false );
712 int wxContourMainFrame::getNamesWrappingSize()
714 return kernelManager->getNamesWrappingSize();
717 std::string wxContourMainFrame::getNameWrapping(int i)
719 return kernelManager->getNameWrapping(i);
722 void wxContourMainFrame::updateInstantImageData()
724 std::vector<int> inst;
725 _instantPanel->getInstant(inst);
727 vtkImageData* img = kernelManager->getImageAtInstant(inst);
729 _theViewPanel->changeImage(img);
732 int z = _instantPanel->getConceptDataOf("Axe Depth")->getActualValue();
733 _theViewPanel->setImageSlice(z);
737 void wxContourMainFrame::updateInstantAxes()
742 void wxContourMainFrame::onChangeDeep(int val){
743 _instantPanel->setConceptValue( "Axe Depth", (int)val );
748 void wxContourMainFrame::onCopy(){
749 std::vector<std::string> currentSelection = _theViewPanel->getSelectedObjects();
750 std::vector<int> tempVector;
751 _instantPanel->getInstant( tempVector );
752 _performingOperation->reset();
753 _performingOperation->setStartCommand( COPY );
754 _performingOperation->setStartOperationInstantVector( tempVector );
755 _performingOperation->setKeyNamesOperationElems( currentSelection );
758 void wxContourMainFrame::onPaste()
760 char theStartCommand = _performingOperation->getStartCommand();
761 if ( theStartCommand == COPY )
763 //JCP 20-10-08 Undo redo implementation
765 //JCP 20-10-08 Undo redo implementation
766 std::vector<int> tempVector;
767 _instantPanel->getInstant( tempVector );
768 _performingOperation->setEndOperationInstantVector ( tempVector );
769 std::vector<std::string> elems = _performingOperation->getKeyNamesOperationElems();
770 int i,size = elems.size();
771 for( i=0; i<size; i++ )
773 createCopyContourOf( elems[i], tempVector, i>0 );
778 void wxContourMainFrame::onUndo()
780 std::string filename;
781 if(kernelManager->onUndoSaveFile(filename)){
782 saveFileWithContours(filename);
784 if(kernelManager->onUndo(filename)){
788 void wxContourMainFrame::onRedo(){
789 std::string filename;
790 if(kernelManager->onRedo(filename)){
795 void wxContourMainFrame :: createCopyContourOf ( std::string anExistingKName, std::vector<int> &instantNoTouchData, bool append )
797 std::string cloneName = kernelManager->createCopyContourOf( anExistingKName, instantNoTouchData );
798 manualBaseModel * manualModel = kernelManager->getOutlineByKeyName(cloneName);//_modelManager->getOutlineByKeyName( cloneName )->getModel();
799 _theViewPanel->getSceneManager()->createCopyContourOf( anExistingKName, cloneName, manualModel , append );
802 ///AD: 03-09 Copy the object and apply the given transformation
803 void wxContourMainFrame :: createMirrorContourOf ( std::string anExistingKName, std::vector<int> &instantNoTouchData, bool append )
805 std::string cloneName = kernelManager->createCopyContourOf( anExistingKName, instantNoTouchData );
806 manualBaseModel * manualModel = kernelManager->getOutlineByKeyName(cloneName);
808 manualPoint * refPoint1 = _refLineModel->GetManualPoint(0);
809 manualPoint * refPoint2 = _refLineModel->GetManualPoint(1);
811 double pnt1X = refPoint1->GetX();
812 double pnt1Y = refPoint1->GetY();
813 // double pnt1Z = refPoint1->GetZ();
814 double pnt2X = refPoint2->GetX();
815 double pnt2Y = refPoint2->GetY();
816 // double pnt2Z = refPoint2->GetZ();
818 double angle = (atan2(pnt2Y - pnt1Y, pnt2X - pnt1X) * 180 / 3.1415926535897932384626433832795)+90;
819 vtkTransform *t = vtkTransform::New();
823 t->Translate(-pnt1X, -pnt1Y, 0);
827 t->Translate(pnt1X, pnt1Y, 0);
830 int i,size=manualModel->GetSizeLstPoints();
833 manualPoint * mp = manualModel->GetManualPoint(i);
839 t->TransformPoint( vecIn, vecOut );
840 mp->SetPointX( vecOut[0] );
841 mp->SetPointY( vecOut[1] );
842 mp->SetPointZ( vecOut[2] );
845 _theViewPanel->getSceneManager()->createCopyContourOf( anExistingKName, cloneName, manualModel , append );
848 void wxContourMainFrame ::loadState(std::string filename)
851 onLoadContours(filename,false);
855 void wxContourMainFrame::onLoad()
857 std::string fileNameContourROI = GetFileLocation();
858 //CMRU 03-09-09-----------------------------------------------------------------------------------------------
859 if(GetFileLocation().empty())
861 //------------------------------------------------------------------------------------------------------------
862 //EED 2017-09-16 Migration wxWidgets 2.8 to 3.0
863 #if wxMAJOR_VERSION <= 2
864 wxFileDialog dialog(NULL, _T("Choose a file"), _T(""), _T(""), _T("*.roi"), wxOPEN );
866 wxFileDialog dialog(NULL, _T("Choose a file"), _T(""), _T(""), _T("*.roi"), wxFD_OPEN );
868 if (dialog.ShowModal() == wxID_OK)
870 fileNameContourROI = (const char *)(dialog.GetPath().mb_str());
874 onLoadContours(fileNameContourROI,true);
878 void wxContourMainFrame::SetZForAllContours(int pz)
881 std::vector< std::string > lstNameThings;
882 int i,sizeLstNameThings;
883 int ii,sizeLstPoints;
885 lstNameThings = kernelManager->GetLstNameThings();
886 sizeLstNameThings = lstNameThings.size();
887 for (i=0 ; i<sizeLstNameThings ; i++)
889 printf("EED wxContourMainFrame::SetZForAllContours contour=%d \n", i );
890 manualBaseModel * manualModel = kernelManager->getOutlineByKeyName(lstNameThings[i]);
891 sizeLstPoints = manualModel->GetSizeLstPoints();
892 for (ii=0 ; ii<sizeLstPoints ; ii++)
894 manualModel->GetManualPoint(ii)->SetPointZ(-900);
895 }// for ii list of points
896 }// for i list of Things
900 lstNameThings = kernelManager->GetLstNameThingsStatic();
901 sizeLstNameThings = lstNameThings.size();
902 for (i=0 ; i<sizeLstNameThings ; i++)
904 manualBaseModel * manualModel = kernelManager->getOutlineByKeyName(lstNameThings[i]);
905 sizeLstPoints = manualModel->GetSizeLstPoints();
906 for (ii=0 ; ii<sizeLstPoints ; ii++)
908 manualModel->GetManualPoint(ii)->SetPointZ(-900);
909 }// for ii list of points
910 }// for i list of static things
913 void wxContourMainFrame::onLoadContours(std::string fileNameContourROI, bool interactiveInterface)
917 FILE *pFile =fopen(fileNameContourROI.c_str(),"r+");
918 //CMRU 03-09-09- ----------------------------------------------------------------------------------------------
921 //------------------------------------------------------------------------------------------------------------
922 fileNameContourROI.append("data");
923 FILE *pFileData=fopen(fileNameContourROI.c_str(),"r+");
924 if(pFileData != NULL)
926 fscanf(pFileData,"%s",tmpD); // --CreaContour--
927 fscanf(pFileData,"%s",tmpD); // Version
928 fscanf(pFileData,"%s",tmpD); // 1.0.3 || 1.0.2 || 1.0.1 || 1.0.0
930 fscanf(pFileData,"%s",tmpD); // onePixelSize
931 fscanf(pFileData,"%s",tmpD); // #
932 _onePixelSize = atof(tmpD);
933 fscanf(pFileData,"%s",tmpD); // NumberOfContours
934 fscanf(pFileData,"%s",tmpD); // #
936 fscanf(pFile,"%s",tmp); // --CreaContour--
937 fscanf(pFile,"%s",tmp); // Version
938 fscanf(pFile,"%s",tmp); // 1.0.3 || 1.0.2 || 1.0.1 || 1.0.0
939 std::string version(tmp);
941 _tmpReadFileTypeOfTransformation=-1;
942 if (version=="1.0.3")
944 readDimSpc(pFile,interactiveInterface); // DimSpc interactive ON
945 openContours(pFile,pFileData,false);
946 openContours(pFile,pFileData,true); //Load StaticContours
948 if (version=="1.0.2")
951 readDimSpc(pFile,interactiveInterface); // DimSpc interactive ON
952 openContours(pFile,pFileData,false);
953 readDimSpc(pFile,false); // DimSpc interactive OFF
954 openContours(pFile,pFileData,true); // Load StaticContours
955 SetZForAllContours(-900);
958 else if (version=="1.0.1")
960 openContours(pFile,pFileData,false); //Skips ImageDimensions and ImageSpacing
961 openContours(pFile,pFileData,true); //Load StaticContours, skips ImageDimensions and ImageSpacing
965 else if (version=="1.0.0")
967 openContours(pFile,pFileData,false); //Skips ImageDimensions and ImageSpacing
972 if(pFileData != NULL)
977 _theViewPanel->getSceneManager()->removeSceneContours();
982 void wxContourMainFrame::onImport()
984 std::string filename, filenamecontours;
985 //EED 2017-09-16 Migration wxWidgets 2.8 to 3.0
986 #if wxMAJOR_VERSION <= 2
987 wxFileDialog dialog(NULL, _T("Choose a XML Osirix File"), _T(""), _T(""), _T("*.xml"), wxOPEN );
989 wxFileDialog dialog(NULL, _T("Choose a XML Osirix File"), _T(""), _T(""), _T("*.xml"), wxFD_OPEN );
991 if (dialog.ShowModal() == wxID_OK)
993 filename = dialog.GetPath().mb_str();
994 filenamecontours = kernelManager->parseOsirixFile(filename);
996 if(filenamecontours.compare("") != 0){
997 onLoadContours(filenamecontours,true);
1002 void wxContourMainFrame::onTest()
1004 std::string filename, filenamecontours;
1005 //EED 2017-09-16 Migration wxWidgets 2.8 to 3.0
1006 #if wxMAJOR_VERSION <= 2
1007 wxFileDialog dialog(NULL, _T("Choose a File"), _T(""), _T(""), _T("*.*"), wxOPEN );
1009 wxFileDialog dialog(NULL, _T("Choose a File"), _T(""), _T(""), _T("*.*"), wxFD_OPEN );
1012 if (dialog.ShowModal() == wxID_OK)
1014 filename = dialog.GetPath().mb_str();
1015 std::cout << "This is the filename: " << filename << std::endl;
1021 void wxContourMainFrame::onSave(){
1022 //CMRU 03-09-09-----------------------------------------------------------------------------------------------
1023 if(GetFileLocation().empty())
1025 //------------------------------------------------------------------------------------------------------------
1026 //EED 2017-09-16 Migration wxWidgets 2.8 to 3.0
1027 #if wxMAJOR_VERSION <= 2
1028 wxFileDialog dialog(NULL, _T("Choose a file"), _T(""), _T(""), _T("*.roi"), wxSAVE );
1030 wxFileDialog dialog(NULL, _T("Choose a file"), _T(""), _T(""), _T("*.roi"), wxFD_SAVE );
1032 if (dialog.ShowModal() == wxID_OK)
1034 std::string fileNameContourROI = (const char *)(dialog.GetPath().mb_str());
1035 kernelManager->setCurrentFileName(fileNameContourROI);
1036 saveFileWithContours( fileNameContourROI );
1039 //CMRU 03-09-09-----------------------------------------------------------------------------------------------
1042 std::cout<<"Nombre del archivo: "<<GetFileLocation()<<std::endl;
1043 std::string fileNameContourROI = GetFileLocation();
1044 std::cout<<"Nombre del archivo: "<<fileNameContourROI<<std::endl;
1045 kernelManager->setCurrentFileName(fileNameContourROI);
1046 saveFileWithContours( fileNameContourROI);
1048 //------------------------------------------------------------------------------------------------------------
1052 void wxContourMainFrame::saveFileWithContours( std::string filename )
1055 FILE *pFile=fopen(filename.c_str(),"w+");
1057 //CMRU 03-09-09-----------------------------------------------------------------------------------------------
1058 filename.append("data");
1059 std::cout<<"Nombre del archivo: "<<filename<<std::endl;
1060 FILE *pFileData=fopen(filename.c_str(),"w+");
1061 //------------------------------------------------------------------------------------------------------------
1063 std::vector< std::string > lstNameThings;
1064 int i,sizeLstNameThings;
1066 fprintf(pFile,"--CreaContour--\n");
1067 fprintf(pFile,"Version %s\n", "1.0.3" );
1069 //CMRU 03-09-09-----------------------------------------------------------------------------------------------
1070 fprintf(pFileData,"--CreaContour--\n");
1071 fprintf(pFileData,"Version %s\n", "1.0.3" );
1072 fprintf(pFileData,"OnePixelSize %f\n", _onePixelSize);
1074 //------------------------------------------------------------------------------------------------------------
1076 vtkImageData *image = _images[0];
1079 image->GetDimensions(dimRange);
1081 fprintf(pFile,"ImageDimensions %d %d %d\n", dimRange[0], dimRange[1], dimRange[2] );
1084 image->GetSpacing(spaRange);
1086 fprintf(pFile,"ImageSpacing %f %f %f\n", spaRange[0], spaRange[1], spaRange[2] );
1090 lstNameThings = kernelManager->GetLstNameThings();
1091 sizeLstNameThings = lstNameThings.size();
1092 fprintf(pFile,"NumberOfContours %d\n", sizeLstNameThings );
1094 //CMRU 03-09-09-----------------------------------------------------------------------------------------------
1095 fprintf(pFileData,"NumberOfContours %d\n", sizeLstNameThings );
1096 //------------------------------------------------------------------------------------------------------------
1105 for (i=0 ; i<sizeLstNameThings ; i++)
1107 //CMRU 03-09-09-----------------------------------------------------------------------------------------------
1108 manualBaseModel * manualModel = kernelManager->getOutlineByKeyName(lstNameThings[i]);
1111 // double sizeInPixel = manualModel ->GetPathSize( );
1112 double sizeInPixel = manualModel ->GetPathSize( spc );
1114 double realContourSize = sizeInPixel*_onePixelSize;
1115 manualModel ->SetRealSize(realContourSize);
1116 //------------------------------------------------------------------------------------------------------------
1118 //int size= kernelManager->GetLstNameThings().size();
1120 kernelManager->SaveThingName( pFile, pFileData, lstNameThings[i] );
1121 _theViewPanel->getSceneManager()->SaveThingName( pFile, lstNameThings[i] );
1124 //-- Static Contours
1126 // fprintf(pFile,"ImageDimensions %d %d %d\n", dimRange[0], dimRange[1], dimRange[2] );
1127 // fprintf(pFile,"ImageSpacing %f %f %f\n", spaRange[0], spaRange[1], spaRange[2] );
1129 lstNameThings = kernelManager->GetLstNameThingsStatic();
1130 sizeLstNameThings = lstNameThings.size();
1131 fprintf(pFile,"NumberOfContoursStatic %d\n", sizeLstNameThings );
1133 //CMRU 03-09-09-----------------------------------------------------------------------------------------------
1134 fprintf(pFileData,"NumberOfContoursStatic %d\n", sizeLstNameThings );
1135 //------------------------------------------------------------------------------------------------------------
1137 for (i=0 ; i<sizeLstNameThings ; i++)
1139 kernelManager->SaveThingName( pFile, pFileData, lstNameThings[i] );
1140 _theViewPanel->getSceneManager()->SaveThingName( pFile, lstNameThings[i] );
1148 void wxContourMainFrame::readDimSpc(FILE *pFile, bool interactiveOption)
1152 double imageSpac[3];
1153 vtkImageData *image = _images[0];
1154 image->GetDimensions(imageDim);
1155 image->GetSpacing(imageSpac);
1157 fscanf(pFile,"%s",tmp); // ImageDimensions
1158 fscanf(pFile,"%s",tmp); // X
1159 _tmpReadFileImageDim[0] = atoi(tmp);
1160 fscanf(pFile,"%s",tmp); // Y
1161 _tmpReadFileImageDim[1] = atoi(tmp);
1162 fscanf(pFile,"%s",tmp); // Z
1163 _tmpReadFileImageDim[2] = atoi(tmp);
1165 fscanf(pFile,"%s",tmp); // ImageSpacing
1166 fscanf(pFile,"%s",tmp); // X
1167 _tmpReadFileImageSpac[0] = atof(tmp);
1168 fscanf(pFile,"%s",tmp); // Y
1169 _tmpReadFileImageSpac[1] = atof(tmp);
1170 fscanf(pFile,"%s",tmp); // Z
1171 _tmpReadFileImageSpac[2] = atof(tmp);
1174 if (interactiveOption==true)
1176 //Compare Spacing and Dims in X and Y (Necessary in Z?) - Just for Version 2
1177 if (imageDim[0]!=_tmpReadFileImageDim[0] || imageDim[1]!=_tmpReadFileImageDim[1] || imageSpac[0]!=_tmpReadFileImageSpac[0] || imageSpac[1]!=_tmpReadFileImageSpac[1])
1179 wxDialog* dial = new wxDialog (this,-1,_T("Tools"),wxDefaultPosition, wxSize(460,360));
1180 wxSizer* buttonsSizer = dial->CreateSeparatedButtonSizer(wxOK|wxCANCEL);
1181 wxBoxSizer *dialSizer = new wxBoxSizer(wxVERTICAL);
1183 wxString lstOptOperation[2];
1184 lstOptOperation[0]=_T("By Dimension");
1185 lstOptOperation[1]=_T("By Spacing");
1186 wxRadioBox * radioOpts = new wxRadioBox(dial, -1, _T("Type of Transformation"), wxDefaultPosition, wxSize(270,45), 2 , lstOptOperation, 2, wxRA_SPECIFY_COLS);
1188 dialSizer->Add( new wxStaticText(dial,-1,_T("The image resolution is not compatible with the ")) , 0, wxGROW );
1189 dialSizer->Add( new wxStaticText(dial,-1,_T("selected Roi file. Do you want to tranform it?")) , 0, wxGROW );
1190 dialSizer->Add( new wxStaticText(dial,-1,_T(" ")) , 0, wxGROW );
1191 dialSizer->Add(radioOpts,0,wxGROW);
1192 dialSizer->Add( new wxStaticText(dial,-1,_T(" ")) , 0, wxGROW );
1193 dialSizer->Add(buttonsSizer,0,wxGROW);
1194 dial->SetSizer(dialSizer, true);
1198 int _tmpReadFileTypeOfTransformation = -1;
1199 //EED bool transform = false;
1201 if (dial->GetReturnCode() == wxID_OK)
1203 _tmpReadFileTypeOfTransformation = radioOpts->GetSelection();
1207 } // if interactiveOption
1214 void wxContourMainFrame::openContours( FILE *pFile, FILE *pFileData, bool staticContour )
1219 vtkImageData *image = _images[0];
1222 double imageSpac[3];
1223 image->GetDimensions(imageDim);
1224 image->GetSpacing(imageSpac);
1227 fscanf(pFile,"%s",tmp); // NumberOfContours
1228 fscanf(pFile,"%s",tmp); // ##
1229 int numberOfContours = atoi(tmp);
1231 std::vector<int> instantVector;
1232 int typeContourModel;
1233 manualBaseModel *manModelContour;
1237 if (compatible==true)
1240 for (i=0;i<numberOfContours;i++)
1242 instantVector.clear();
1243 fscanf(pFile,"%s",tmp); // Instant
1245 fscanf(pFile,"%s",tmp); // 1
1246 instantVector.push_back( atoi(tmp) );
1247 fscanf(pFile,"%s",tmp); // 2
1248 instantVector.push_back( atoi(tmp) );
1249 fscanf(pFile,"%s",tmp); // 3
1250 instantVector.push_back( atoi(tmp) );
1251 fscanf(pFile,"%s",tmp); // 4
1252 instantVector.push_back( atoi(tmp) );
1253 fscanf(pFile,"%s",tmp); // 5
1254 instantVector.push_back( atoi(tmp) );
1255 fscanf(pFile,"%s",tmp); // 6
1256 instantVector.push_back( atoi(tmp) );
1259 fscanf(pFile,"%s",tmp); // TypeContourModel
1260 fscanf(pFile,"%s",tmp); // ##
1261 typeContourModel = atoi(tmp);
1263 manModelContour = kernelManager->factoryManualContourModel(typeContourModel);
1264 manModelContour->Open(pFile);
1265 if(pFileData != NULL)
1267 manModelContour->OpenData(pFileData);
1270 fscanf(pFile,"%s",tmp); // TypeView
1271 fscanf(pFile,"%s",tmp); // ##
1272 typeView = atoi(tmp);
1274 std::string theName;
1275 theName = kernelManager->createOutline( manModelContour, instantVector );
1276 bool addedModel = theName.compare("") != 0;
1279 double spc[3];//Si no hay imagen pero hay contornos que spacing se pone por default
1280 _theViewPanel->getSpacing(spc);
1281 //Adding the manualContourControler to interface objects structure
1282 //Adding the manualViewContour to interface objects structure
1283 //_theViewPanel->getSceneManager()->setControlActiveStateOfALL( false );//This call is being done here because if the ROI is created underneath the previously created ROIS will still be active.
1284 _theViewPanel->getSceneManager()->configureViewControlTo( theName, manModelContour,spc , typeView) ;
1287 if (staticContour) //StaticContours (will appear in all slices)
1289 Instant instant(&instantVector);
1290 kernelManager->changeContourOfManager( theName , &instant );
1293 }// for numberOfContours
1296 else if (compatible==false)
1301 for (i=0;i<numberOfContours;i++)
1303 instantVector.clear();
1304 fscanf(pFile,"%s",tmp); // Instant
1306 fscanf(pFile,"%s",tmp); // 1
1307 instantVector.push_back( atoi(tmp) );
1308 fscanf(pFile,"%s",tmp); // 2
1309 instantVector.push_back( atoi(tmp) );
1310 fscanf(pFile,"%s",tmp); // 3
1311 instantVector.push_back( atoi(tmp) );
1312 fscanf(pFile,"%s",tmp); // 4
1313 instantVector.push_back( atoi(tmp) );
1314 fscanf(pFile,"%s",tmp); // 5
1315 instantVector.push_back( atoi(tmp) );
1316 fscanf(pFile,"%s",tmp); // 6
1317 instantVector.push_back( atoi(tmp) );
1319 fscanf(pFile,"%s",tmp); // TypeContourModel
1320 fscanf(pFile,"%s",tmp); // ##
1321 typeContourModel = atoi(tmp);
1323 manModelContour = kernelManager->factoryManualContourModel(typeContourModel);
1324 manModelContour->Open(pFile);
1325 if(pFileData != NULL)
1327 manModelContour->OpenData(pFileData);
1330 if (_tmpReadFileTypeOfTransformation==-1){
1332 } else if (_tmpReadFileTypeOfTransformation==0){
1333 double transX, transY;
1334 transX = (double) imageDim[0]/_tmpReadFileImageDim[0];
1335 transY = (double) imageDim[1]/_tmpReadFileImageDim[1];
1336 manModelContour->Transform_Ax_Plus_B(transX,0,transY,0);
1337 } else if (_tmpReadFileTypeOfTransformation==1) {
1338 double transX, transY;
1339 transX = (double) _tmpReadFileImageSpac[0]/imageDim[0];
1340 transY = (double) _tmpReadFileImageSpac[1]/imageDim[1];
1341 manModelContour->Transform_Ax_Plus_B(transX,0,transY,0);
1344 fscanf(pFile,"%s",tmp); // TypeView
1345 fscanf(pFile,"%s",tmp); // ##
1346 typeView = atoi(tmp);
1348 std::string theName;
1349 theName = kernelManager->createOutline( manModelContour, instantVector );
1350 bool addedModel = theName.compare("") != 0;
1353 double spc[3];//Si no hay imagen pero hay contornos que spacing se pone por default
1354 _theViewPanel->getSpacing(spc);
1355 //Adding the manualContourControler to interface objects structure
1356 //Adding the manualViewContour to interface objects structure
1357 //_theViewPanel->getSceneManager()->setControlActiveStateOfALL( false );//This call is being done here because if the ROI is created underneath the previously created ROIS will still be active.
1358 _theViewPanel->getSceneManager()->configureViewControlTo( theName, manModelContour,spc , typeView) ;
1361 if (staticContour) //StaticContours (will appear in all slices)
1363 Instant instant(&instantVector);
1364 kernelManager->changeContourOfManager( theName , &instant );
1366 }// for numberOfContours
1372 void wxContourMainFrame::RefreshInterface()
1375 _theViewPanel->RefreshInterface();
1376 //wxVtk2DBaseView *wxvtk2dbaseview = (wxVtk2DBaseView*)this->_theViewPanel->getWxVtkBaseView();
1377 //wxvtk2dbaseview->Refresh();
1380 vtkImageData* wxContourMainFrame::getImageData()
1382 return _theViewPanel->getImageData();
1385 void wxContourMainFrame::onSegmentationOneSliceITK(wxString distance, wxString sigma, wxString alfa, wxString beta, wxString propagation, wxString iterations, wxString inflation)
1387 //JCP 20-10-08 Undo redo implementation
1389 //JCP 20-10-08 Undo redo implementation
1392 int x = _theViewPanel->GetX();
1393 int y = _theViewPanel->GetY();
1394 int z = _theViewPanel->GetZ();
1395 SegmentationOneSliceITK( x,y,z,distance, sigma, alfa, beta, propagation, iterations, inflation);
1399 void wxContourMainFrame::SegmentationOneSliceITK(int x, int y, int z, wxString distanc, wxString sigm, wxString alf, wxString bet, wxString prop, wxString iter, wxString inflation)
1401 int typeofcontour = 1;
1403 vtkImageData *imagedata = getImageData();
1405 //Tipo de pixeles a utilizar internamente en ITK
1406 typedef float InternalPixelType;
1407 const unsigned int Dimension = 2;
1408 typedef itk::Image< InternalPixelType, Dimension > InternalImageType;
1410 //Tipo de pixeles de salida 1
1411 typedef unsigned char OutputPixelType;
1412 typedef itk::Image< OutputPixelType, Dimension > OutputImageType;
1414 //Tipo de pixeles de salida 2
1415 typedef unsigned short OutputPixelType2;
1416 typedef itk::Image< OutputPixelType2, Dimension > OutputImageType2;
1418 //DefiniciÛn del thresholder
1419 typedef itk::BinaryThresholdImageFilter<
1421 OutputImageType > ThresholdingFilterType;
1423 //DefiniciÛn del primer filtro de conversiÛn de pixeles
1424 typedef itk::CastImageFilter<
1425 OutputImageType, OutputImageType2 > CastFilterType;
1427 //DefiniciÛn del segundo tipo de conversiÛn de pixeles
1428 typedef itk::CastImageFilter<
1429 OutputImageType2, InternalImageType > CastFilterType2;
1431 //Tercer tipo de conversiÛn
1432 typedef itk::RescaleIntensityImageFilter<
1434 OutputImageType > CastFilterType3;
1436 //Cuarto tipo de conversiÛn
1437 typedef itk::RescaleIntensityImageFilter<
1439 OutputImageType > CastFilterType4;
1441 ThresholdingFilterType::Pointer thresholder = ThresholdingFilterType::New();
1443 thresholder->SetLowerThreshold( 0.0 );
1444 thresholder->SetUpperThreshold( 128 );
1446 thresholder->SetOutsideValue( 255 );
1447 thresholder->SetInsideValue( 0 );
1449 //DefinciÛn de conexiÛnes entre VTK e ITK y el writer
1450 typedef itk::VTKImageToImageFilter<OutputImageType2> ConnectorType;
1451 typedef itk::ImageToVTKImageFilter<OutputImageType> ConnectorType2;
1452 //EED10JUIN2011 typedef itk::ImageFileWriter< OutputImageType > WriterType;
1454 ConnectorType::Pointer connector= ConnectorType::New();
1455 ConnectorType2::Pointer connector2= ConnectorType2::New();
1458 CastFilterType::Pointer filter=CastFilterType::New();
1459 CastFilterType2::Pointer filter2=CastFilterType2::New();
1461 connector->SetInput( imagedata );
1462 filter2->SetInput(connector->GetOutput());
1464 typedef itk::CurvatureAnisotropicDiffusionImageFilter<
1466 InternalImageType > SmoothingFilterType;
1468 SmoothingFilterType::Pointer smoothing = SmoothingFilterType::New();
1470 typedef itk::GradientMagnitudeRecursiveGaussianImageFilter<
1472 InternalImageType > GradientFilterType;
1474 typedef itk::SigmoidImageFilter<
1476 InternalImageType > SigmoidFilterType;
1478 GradientFilterType::Pointer gradientMagnitude = GradientFilterType::New();
1480 SigmoidFilterType::Pointer sigmoid = SigmoidFilterType::New();
1482 sigmoid->SetOutputMinimum( 0.0 );
1483 sigmoid->SetOutputMaximum( 255.0 );
1486 typedef itk::FastMarchingImageFilter<
1488 InternalImageType > FastMarchingFilterType;
1491 FastMarchingFilterType::Pointer fastMarching = FastMarchingFilterType::New();
1493 printf("EED wxContourMainFrame::SegmentationOneSliceITK Skypping this code. Not compiling GeodesicActiveContourLevelSetImageFilter in fedora 17 with ITK 3.20.1 \n ");
1495 > - > - > - > - > - > - > - > - > - > - > - > - > - > - > - > - Not compiling GeodesicActiveContourLevelSetImageFilter in fedora 17 with ITK 3.20.1
1498 typedef itk::GeodesicActiveContourLevelSetImageFilter< InternalImageType,
1499 InternalImageType > GeodesicActiveContourFilterType;
1500 GeodesicActiveContourFilterType::Pointer geodesicActiveContour =
1501 GeodesicActiveContourFilterType::New();
1503 typedef itk::ZeroCrossingImageFilter<
1505 InternalImageType > ZeroCrossingFilterType;
1506 ZeroCrossingFilterType::Pointer zeroCrossing =
1507 ZeroCrossingFilterType::New();
1509 const double propagationScaling = atof( crea::wx2std(prop).c_str() );
1511 geodesicActiveContour->SetPropagationScaling( propagationScaling );
1512 geodesicActiveContour->SetCurvatureScaling( 1.0 );
1513 geodesicActiveContour->SetAdvectionScaling( 1.0 );
1515 geodesicActiveContour->SetMaximumRMSError( 0.02 );
1516 int it=atoi( crea::wx2std(iter).c_str() );
1517 geodesicActiveContour->SetNumberOfIterations( it );
1519 smoothing->SetInput( filter2->GetOutput() );
1520 gradientMagnitude->SetInput( smoothing->GetOutput() );
1521 sigmoid->SetInput( gradientMagnitude->GetOutput() );
1522 fastMarching->SetInput( sigmoid->GetOutput() );
1523 geodesicActiveContour->SetInput( fastMarching->GetOutput() );
1524 geodesicActiveContour->SetFeatureImage( sigmoid->GetOutput() );
1526 zeroCrossing->SetInput( geodesicActiveContour->GetOutput() );
1527 //thresholder->SetInput( zeroCrossing->GetOutput() );
1528 thresholder->SetInput( geodesicActiveContour->GetOutput() );
1529 connector2->SetInput( thresholder->GetOutput() );
1531 < - < - < - < - < - < - < - < - < - < - < - < - < - < - < - < - < - < - < - < -
1537 smoothing->SetTimeStep( 0.125 );
1538 smoothing->SetNumberOfIterations( 5 );
1539 smoothing->SetConductanceParameter( 9.0 );
1542 const double sigma = atof( crea::wx2std(sigm).c_str() );
1543 gradientMagnitude->SetSigma( sigma );
1545 const double alpha = atof( crea::wx2std(alf).c_str() );
1546 const double beta = atof( crea::wx2std(bet).c_str() );
1548 sigmoid->SetAlpha( alpha );
1549 sigmoid->SetBeta( beta );
1551 typedef FastMarchingFilterType::NodeContainer NodeContainer;
1552 typedef FastMarchingFilterType::NodeType NodeType;
1554 NodeContainer::Pointer seeds = NodeContainer::New();
1556 InternalImageType::IndexType seedPosition;
1557 seedPosition[0] = x;
1558 seedPosition[1] = y;
1560 const double initialDistance = atof( crea::wx2std(distanc).c_str() );
1564 const double seedValue = - initialDistance;
1566 node.SetValue( seedValue );
1567 node.SetIndex( seedPosition );
1569 seeds->Initialize();
1570 seeds->InsertElement( 0, node );
1572 fastMarching->SetTrialPoints( seeds );
1574 fastMarching->SetSpeedConstant( 1.0 );
1576 fastMarching->SetOutputSize(
1577 connector->GetOutput()->GetBufferedRegion().GetSize() );
1579 fastMarching->SetStoppingValue( 800 );
1583 connector2->Update();
1584 vtkImageData *idata = connector2->GetOutput();
1586 vtkMarchingContourFilter* cntVTK = vtkMarchingContourFilter::New( );
1588 cntVTK->SetNumberOfContours( 1 );
1589 cntVTK->SetValue( 0, 255 );
1590 //EED 2017-01-01 Migration VTK7
1591 #if VTK_MAJOR_VERSION <= 5
1592 cntVTK->SetInput( idata );
1594 cntVTK->UpdateInformation();
1596 cntVTK->SetInputData( idata );
1599 vtkCleanPolyData* cpd = vtkCleanPolyData::New( );
1601 //EED 2017-01-01 Migration VTK7
1602 #if VTK_MAJOR_VERSION <= 5
1603 cpd->SetInput( cntVTK->GetOutput( ) );
1605 cpd->UpdateInformation();
1607 cpd->SetInputData( cntVTK->GetOutput( ) );
1611 vtkPolyDataConnectivityFilter* conn = vtkPolyDataConnectivityFilter::New( );
1612 conn->SetExtractionModeToLargestRegion( );
1613 //EED 2017-01-01 Migration VTK7
1614 #if VTK_MAJOR_VERSION <= 5
1615 conn->SetInput( cpd->GetOutput( ) );
1617 conn->UpdateInformation();
1619 conn->SetInputData( cpd->GetOutput( ) );
1623 vtkStripper* vtkstripper = vtkStripper::New( );
1625 //EED 2017-01-01 Migration VTK7
1626 #if VTK_MAJOR_VERSION <= 5
1627 vtkstripper->SetInput( conn->GetOutput() );
1628 vtkstripper->Update();
1629 vtkstripper->UpdateInformation();
1631 vtkstripper->SetInputData( conn->GetOutput() );
1635 vtkPolyData* polyDataResult = cntVTK->GetOutput();
1636 //std::cout<<"Points "<<polyDataResult->GetNumberOfPoints()<<std::endl;
1638 //EED 2017-01-01 Migration VTK7
1639 #if VTK_MAJOR_VERSION <= 5
1640 polyDataResult->Update( );
1641 polyDataResult->UpdateInformation();
1649 myfile.open ("C:/Creatis/example.txt");
1651 polyDataResult->Print(myfile);
1652 myfile << "-------------------------------------\n";
1653 polyDataResult->GetLines()->Print(myfile);
1661 //--Calculating control points
1663 std::vector<double> vecX;
1664 std::vector<double> vecY;
1665 std::vector<double> vecXo;
1666 std::vector<double> vecYo;
1667 std::vector<double>::iterator vecXoi;
1668 std::vector<double>::iterator vecYoi;
1669 std::vector<double> vecZ;
1671 std::vector<double> vecCtrlPointX;
1672 std::vector<double> vecCtrlPointY;
1673 std::vector<double> vecCtrlPointZ;
1679 int ii,size=polyDataResult->GetNumberOfPoints();
1681 myfile.open ("C:/Creatis/example2.txt");
1683 size=polyDataResult->GetNumberOfPoints();
1684 for (ii=0;ii<size;ii++)
1691 p = polyDataResult->GetPoint(ii);
1694 /*if(fabs(yAct-y)>20)
1696 if((xAct-x)>1 || (xAct-x)<-1)
1698 vecX.push_back( p[0] );
1699 vecY.push_back( p[1] );
1700 myfile <<p[0]<<","<<p[1]<<"\n";
1701 std::cout<<" x Anterior "<<xAct<<" x actual "<<x<<std::endl;
1702 std::cout<<" y Anterior "<<yAct<<" y actual "<<y<<std::endl;
1703 std::cout<<" x "<<p[0]<<" y "<<p[1]<<std::endl;
1704 vecZ.push_back( 900 );
1710 vecXo.push_back(p[0]);
1711 vecYo.push_back(p[1]);
1715 else*/ if(fabs(xAct-x)>11)
1717 vecXo.push_back(p[0]);
1718 vecYo.push_back(p[1]);
1720 vecX.push_back( p[0] );
1721 myfile <<p[0]<<","<<p[1]<<"\n";
1722 //std::cout<<" x Anterior "<<xAct<<" x actual "<<x<<std::endl;
1723 //std::cout<<" y Anterior "<<yAct<<" y actual "<<y<<std::endl;
1724 //std::cout<<" x "<<p[0]<<" y "<<p[1]<<std::endl;
1725 vecY.push_back( p[1] );
1727 vecZ.push_back( -900 );
1735 while(!vecXo.empty())
1737 vecX.push_back(vecXo.back());
1738 //std::cout<<" x Siguiente "<<vecXo.back();
1741 vecZ.push_back( -900 );
1743 while(!vecYo.empty())
1745 vecY.push_back(vecYo.back());
1750 /*for(int l=0;l<vecX.size();l++)
1754 vecXo.push_back(p[0]);
1755 vecYo.push_back(p[1]);
1766 ExtractControlPoints2D *extractcontrolpoints2d = new ExtractControlPoints2D();
1768 extractcontrolpoints2d->SetContour( &vecX , &vecY , &vecZ );
1772 extractcontrolpoints2d->GetInitialControlPoints( &vecCtrlPointX , &vecCtrlPointY , &vecCtrlPointZ );
1774 else if (method==1){
1775 extractcontrolpoints2d->GetControlPoints( &vecCtrlPointX , &vecCtrlPointY , &vecCtrlPointZ );
1777 else if (method==2){
1778 extractcontrolpoints2d->SetSamplingControlPoints( 15 );
1779 extractcontrolpoints2d->GetSamplingControlPoints( &vecCtrlPointX , &vecCtrlPointY , &vecCtrlPointZ );
1781 //--Adding contour to the system
1783 std::vector<int> actualInstantVector;
1784 _instantPanel->getInstant( actualInstantVector );
1785 actualInstantVector[1]=z;
1787 int j,sizeCtrPt = vecCtrlPointX.size();
1789 manualBaseModel *manModelContour = kernelManager->factoryManualContourModel( typeofcontour );
1790 manModelContour->SetNumberOfPointsSpline( ((sizeCtrPt/100)+1)*100 );
1792 for (j=0 ; j<sizeCtrPt ; j++)
1794 manModelContour->AddPoint( vecCtrlPointX[j] , vecCtrlPointY[j] , vecCtrlPointZ[j] );
1796 std::string theName;
1797 //theName = _modelManager->createOutline( manModelContour, actualInstantVector );
1798 theName = kernelManager->createOutline( manModelContour, actualInstantVector );
1799 bool addedModel = theName.compare("") != 0;
1802 double spc[3];//Si no hay imagen pero hay contornos que spacing se pone por default
1803 _theViewPanel->getSpacing(spc);
1804 //Adding the manualContourControler to interface objects structure
1805 //Adding the manualViewContour to interface objects structure
1806 //_theViewPanel->getSceneManager()->setControlActiveStateOfALL( false );//This call is being done here because if the ROI is created underneath the previously created ROIS will still be active.
1807 _theViewPanel->configureViewControlTo(theName, manModelContour, spc, typeofcontour);
1808 //_theViewPanel->getSceneManager()->configureViewControlTo( theName, manModelContour,spc, typeofcontour ) ;
1815 WriterType::Pointer writer = WriterType::New();
1816 CastFilterType3::Pointer caster = CastFilterType3::New();
1818 caster->SetInput( gradientMagnitude->GetOutput() );
1819 writer->SetInput( caster->GetOutput() );
1820 writer->SetFileName("Gradient Magnitude.png");
1821 caster->SetOutputMinimum( 0 );
1822 caster->SetOutputMaximum( 255 );
1825 CastFilterType3::Pointer caster2 = CastFilterType3::New();
1826 WriterType::Pointer writer2 = WriterType::New();
1828 caster2->SetInput( sigmoid->GetOutput() );
1829 writer2->SetInput( caster2->GetOutput() );
1830 writer2->SetFileName("Sigmoid.png");
1831 caster2->SetOutputMinimum( 0 );
1832 caster2->SetOutputMaximum( 255 );
1835 CastFilterType3::Pointer caster3 = CastFilterType3::New();
1836 WriterType::Pointer writer3 = WriterType::New();
1838 caster3->SetInput( fastMarching->GetOutput() );
1839 writer3->SetInput( caster3->GetOutput() );
1840 writer3->SetFileName("FastMarching.bmp");
1841 caster3->SetOutputMinimum( 0 );
1842 caster3->SetOutputMaximum( 255 );
1845 CastFilterType3::Pointer caster4 = CastFilterType3::New();
1846 WriterType::Pointer writer4 = WriterType::New();
1848 caster4->SetInput( geodesicActiveContour->GetOutput() );
1849 writer4->SetInput( caster4->GetOutput() );
1850 writer4->SetFileName("GeodesicActiveContour.png");
1851 caster4->SetOutputMinimum( 0 );
1852 caster4->SetOutputMaximum( 255 );
1855 CastFilterType3::Pointer caster5 = CastFilterType3::New();
1856 WriterType::Pointer writer5 = WriterType::New();
1858 caster5->SetInput( zeroCrossing->GetOutput() );
1859 writer5->SetInput( caster5->GetOutput() );
1860 writer5->SetFileName("ZeroCrossing.bmp");
1861 caster5->SetOutputMinimum( 0 );
1862 caster5->SetOutputMaximum( 255 );
1866 catch( itk::ExceptionObject & excep )
1868 std::cerr << "Exception caught !" << std::endl;
1869 std::cerr << excep << std::endl;
1873 void wxContourMainFrame::onSegmentationOneSlice(int isovalue,int sampling,int method){
1875 //JCP 20-10-08 Undo redo implementation
1877 //JCP 20-10-08 Undo redo implementation
1880 int x = _theViewPanel->GetX();
1881 int y = _theViewPanel->GetY();
1882 int z = _theViewPanel->GetZ();
1883 SegmentationOneSlice( x,y,z,isovalue, sampling, method );
1888 void wxContourMainFrame::SegmentationOneSlice( int x, int y, int z, int isovalue, int sampling, int method )
1890 int typeofcontour = 1;
1891 //--Extracting Contour
1892 //vtkImageData *imagedata = _theViewPanel->getSceneManager()->GetImageData();
1893 vtkImageData *imagedata = getImageData();
1894 // double *range = imagedata->GetScalarRange();
1897 vtkImageReslice *imageReslice = vtkImageReslice::New();
1900 // imagedata->GetSpacing(spc);
1905 //EED 2017-01-01 Migration VTK7
1906 #if VTK_MAJOR_VERSION <= 5
1907 imageReslice->SetInput( imagedata );
1909 imageReslice->SetInputData( imagedata );
1911 imageReslice->SetInformationInput(imagedata);
1912 imageReslice->SetResliceAxesDirectionCosines(1,0,0, 0,1,0 ,0,0,1);
1913 imageReslice->SetResliceAxesOrigin(0,0,z);
1914 imageReslice->SetOutputDimensionality(2);
1915 imageReslice->SetInterpolationModeToLinear();
1917 //EED 2017-01-01 Migration VTK7
1918 #if VTK_MAJOR_VERSION <= 5
1921 imageReslice->Update();
1924 imagedata = imageReslice->GetOutput();
1925 //EED 2017-01-01 Migration VTK7
1926 #if VTK_MAJOR_VERSION <= 5
1927 imagedata->Update();
1928 imagedata->UpdateInformation();
1933 vtkContourFilter* cntVTK = vtkContourFilter::New( );
1934 //EED 2017-01-01 Migration VTK7
1935 #if VTK_MAJOR_VERSION <= 5
1936 cntVTK->SetInput( imagedata );
1938 cntVTK->SetInputData( imagedata );
1941 cntVTK->SetNumberOfContours( 1 );
1942 //cntVTK->SetValue( 0, vmin );
1943 // cntVTK->SetValue( 0, (range[1]*thr/100) );
1944 cntVTK->SetValue( 1, isovalue );
1945 // cntVTK->SetValue( 1, vmax );
1947 cntVTK->UpdateInformation();
1949 vtkCleanPolyData* cpd = vtkCleanPolyData::New( );
1950 //EED 2017-01-01 Migration VTK7
1951 #if VTK_MAJOR_VERSION <= 5
1952 cpd->SetInput( cntVTK->GetOutput( ) );
1954 cpd->SetInputData( cntVTK->GetOutput( ) );
1956 cpd->ConvertLinesToPointsOff( );
1958 cpd->UpdateInformation();
1960 vtkPolyDataConnectivityFilter* conn = vtkPolyDataConnectivityFilter::New( );
1961 conn->SetExtractionModeToClosestPointRegion( );
1962 //conn->SetMaxRecursionDepth( 3000 );
1964 //EED 2017-01-01 Migration VTK7
1965 #if VTK_MAJOR_VERSION <= 5
1966 conn->SetInput( cpd->GetOutput( ) );
1968 conn->SetInputData( cpd->GetOutput( ) );
1971 conn->SetClosestPoint( x, y, 0 );
1973 conn->UpdateInformation();
1975 vtkCleanPolyData* cpd2 = vtkCleanPolyData::New( );
1976 //EED 2017-01-01 Migration VTK7
1977 #if VTK_MAJOR_VERSION <= 5
1978 cpd2->SetInput( conn->GetOutput( ) );
1980 cpd2->SetInputData( conn->GetOutput( ) );
1983 cpd2->UpdateInformation();
1985 vtkStripper* vtkstripper = vtkStripper::New( );
1986 //EED 2017-01-01 Migration VTK7
1987 #if VTK_MAJOR_VERSION <= 5
1988 vtkstripper->SetInput( cpd2->GetOutput() );
1990 vtkstripper->SetInputData( cpd2->GetOutput() );
1992 vtkstripper->Update();
1993 vtkstripper->UpdateInformation();
1996 vtkPolyData* polyDataResult = vtkstripper->GetOutput();
1998 //EED 2017-01-01 Migration VTK7
1999 #if VTK_MAJOR_VERSION <= 5
2000 polyDataResult->Update( );
2001 polyDataResult->UpdateInformation();
2008 myfile.open ("c:/temp/example.txt");
2010 polyDataResult->Print(myfile);
2011 myfile << "-------------------------------------\n";
2012 polyDataResult->GetLines()->Print(myfile);
2022 //--Calculating control points
2024 std::vector<double> vecX;
2025 std::vector<double> vecY;
2026 std::vector<double> vecZ;
2028 std::vector<double> vecCtrlPointX;
2029 std::vector<double> vecCtrlPointY;
2030 std::vector<double> vecCtrlPointZ;
2034 int ii,size=polyDataResult->GetNumberOfPoints();
2036 for (ii=1;ii<=size;ii++)
2038 id = polyDataResult->GetLines()->GetData()->GetValue(ii);
2039 p = polyDataResult->GetPoint(id);
2042 vecX.push_back( p[0] );
2043 vecY.push_back( p[1] );
2045 vecZ.push_back( -900 );
2046 // vecZ.push_back( p[2] );
2050 ExtractControlPoints2D *extractcontrolpoints2d = new ExtractControlPoints2D();
2051 extractcontrolpoints2d->SetContour( &vecX , &vecY , &vecZ );
2054 /*if (methodRadiobox->GetSelection()==0){
2055 extractcontrolpoints2d->GetInitialControlPoints( &vecCtrlPointX , &vecCtrlPointY , &vecCtrlPointZ );
2057 if (methodRadiobox->GetSelection()==1){
2058 extractcontrolpoints2d->GetControlPoints( &vecCtrlPointX , &vecCtrlPointY , &vecCtrlPointZ );
2060 if (methodRadiobox->GetSelection()==2){
2061 extractcontrolpoints2d->SetSamplingControlPoints( sampling );
2062 extractcontrolpoints2d->GetSamplingControlPoints( &vecCtrlPointX , &vecCtrlPointY , &vecCtrlPointZ );
2066 extractcontrolpoints2d->GetInitialControlPoints( &vecCtrlPointX , &vecCtrlPointY , &vecCtrlPointZ );
2068 else if (method==1){
2069 extractcontrolpoints2d->GetControlPoints( &vecCtrlPointX , &vecCtrlPointY , &vecCtrlPointZ );
2071 else if (method==2){
2072 extractcontrolpoints2d->SetSamplingControlPoints( sampling );
2073 extractcontrolpoints2d->GetSamplingControlPoints( &vecCtrlPointX , &vecCtrlPointY , &vecCtrlPointZ );
2076 //--Adding contour to the system
2078 std::vector<int> actualInstantVector;
2079 _instantPanel->getInstant( actualInstantVector );
2080 actualInstantVector[1]=z;
2082 int j,sizeCtrPt = vecCtrlPointX.size();
2083 manualBaseModel *manModelContour = kernelManager->factoryManualContourModel( typeofcontour );
2084 manModelContour->SetNumberOfPointsSpline( ((sizeCtrPt/100)+1)*100 );
2086 for (j=0 ; j<sizeCtrPt ; j++)
2088 manModelContour->AddPoint( vecCtrlPointX[j] , vecCtrlPointY[j] , vecCtrlPointZ[j] );
2090 std::string theName;
2091 //theName = _modelManager->createOutline( manModelContour, actualInstantVector );
2092 theName = kernelManager->createOutline( manModelContour, actualInstantVector );
2093 bool addedModel = theName.compare("") != 0;
2096 double spc[3];//Si no hay imagen pero hay contornos que spacing se pone por default
2097 _theViewPanel->getSpacing(spc);
2098 //Adding the manualContourControler to interface objects structure
2099 //Adding the manualViewContour to interface objects structure
2100 //_theViewPanel->getSceneManager()->setControlActiveStateOfALL( false );//This call is being done here because if the ROI is created underneath the previously created ROIS will still be active.
2101 _theViewPanel->configureViewControlTo(theName, manModelContour, spc, typeofcontour);
2102 //_theViewPanel->getSceneManager()->configureViewControlTo( theName, manModelContour,spc, typeofcontour ) ;
2106 int wxContourMainFrame::GetImageDataSizeZ(){
2107 return _theViewPanel->GetImageDataSizeZ();
2110 void wxContourMainFrame::GetImageDataRange(double *range){
2111 _theViewPanel->GetImageDataRange(range);
2114 void wxContourMainFrame::onSegmentationAllSlice(int minZ,int maxZ,int isovalue,int sampling,int method){
2115 //JCP 20-10-08 Undo redo implementation
2117 //JCP 20-10-08 Undo redo implementation
2120 int x = _theViewPanel->GetX();
2121 int y = _theViewPanel->GetY();
2125 double totalZ = maxZ-minZ+1;
2126 for( z=minZ ; z<=maxZ ; z++ )
2128 porcent = 100.0* (z-minZ)/totalZ;
2129 tmpString.Printf(_T(" %d %c %d/%d %d"), (int)porcent , 37 , z-minZ+1, (int)totalZ,z );
2130 interfMainPanel::getInstance()->setLabelSegmentationPanelVTK(tmpString);
2131 //_staticTextSegmentation->SetLabel(tmpString);
2132 SegmentationOneSlice( x,y,z,isovalue, sampling,method );
2134 interfMainPanel::getInstance()->setLabelSegmentationPanelVTK(_T(" "));
2139 //Creates a reference line to be used as the axis of the mirroring
2140 void wxContourMainFrame::referenceLine()
2142 if (_refLineControl==NULL)
2147 vtkImageData *vtkimagedata = _theViewPanel->getImageData();
2148 vtkimagedata->GetSpacing(spc);
2150 wxVtkBaseView * viewer2D = _theViewPanel->getWxVtkBaseView();
2152 _refLineControl = new manualLineControler();
2153 _refLineModel = new manualContourModelLine();
2154 _refLineView = new manualViewLine();
2155 _refLineView->SetModel( _refLineModel );
2156 _refLineView->SetWxVtkBaseView( viewer2D );
2157 _refLineView->SetRange( 2 );
2158 _refLineView->SetZ( 1200 );
2160 _refLineView->SetSpacing(spc);
2162 _refLineView->SetColorNormalContour(0, 0, 1);
2163 _refLineView->SetColorEditContour(0, 0.5, 0.5);
2164 _refLineView->SetWidthLine(4);
2166 _refLineControl->SetModelView( _refLineModel , _refLineView );
2167 vtkInteractorStyleBaseView* style = (vtkInteractorStyleBaseView*)viewer2D->GetInteractorStyleBaseView();
2168 style->AddInteractorStyleMaracas( _refLineControl );
2169 _refLineModel->SetCloseContour(false);
2170 _refLineControl->CreateNewManualContour();
2172 //AD: Inicializar el mirroring con una linea ya pintada
2174 double z = _refLineControl->GetZ();
2177 image->GetDimensions(imageDim);
2178 double x = (double) imageDim[0]/2;
2179 double y1 = (double) (imageDim[1]/2)+15;
2180 double y2 = (double) (imageDim[1]/2)-15;
2182 _refLineControl->AddPoint(x,y1,z);
2183 _refLineControl->AddPoint(x,y2,z);
2184 _refLineControl->SetCompleteCreation(true);
2186 _refLineModel->AddPoint(x,y1,z);
2187 _refLineModel->AddPoint(x,y2,z);
2188 _refLineModel->UpdateSpline();
2190 _refLineView->UpdateViewPoint(0);
2191 _refLineView->UpdateViewPoint(1);
2194 _refLineControl->SetActive(true);
2195 _refLineView->RefreshContour();
2199 //Hides the referenceLine
2200 void wxContourMainFrame::refLineHide()
2202 if (_refLineControl!=NULL)
2204 if (_refLineControl->GetActive())
2206 _refLineView->RemoveCompleteContourActor();
2207 _refLineControl->SetEditable(false);
2208 _refLineControl->SetActive(false);
2215 //Shows the referenceLine
2216 void wxContourMainFrame::refLineShow()
2218 if (_refLineControl!=NULL)
2220 if (_refLineControl->GetActive()==false)
2222 wxVtkBaseView * viewer2D = _theViewPanel->getWxVtkBaseView();
2224 _refLineView->SetModel( _refLineModel );
2225 _refLineView->SetWxVtkBaseView( viewer2D );
2226 _refLineView->SetRange( 2 );
2227 _refLineView->SetZ( 1200 );
2229 _refLineControl->SetModelView( _refLineModel , _refLineView );
2230 vtkInteractorStyleBaseView* style = (vtkInteractorStyleBaseView*)viewer2D->GetInteractorStyleBaseView();
2231 style->AddInteractorStyleMaracas( _refLineControl );
2232 _refLineControl->CreateNewManualContour();
2233 _refLineControl->SetActive(true);
2234 _refLineView->RefreshContour();
2241 void wxContourMainFrame::refLineChangeWidth(int width)
2243 _refLineView->SetWidthLine(width);
2244 _refLineView->RefreshContour();
2250 void wxContourMainFrame::onMirror()
2253 std::vector<std::string> currentSelection = _theViewPanel->getSelectedObjects();
2254 std::vector<std::string> filterCurrentSelection;
2256 std::vector<int> tempVector;
2257 _instantPanel->getInstant( tempVector );
2258 _performingOperation->reset();
2259 _performingOperation->setStartCommand( COPY );
2260 _performingOperation->setStartOperationInstantVector( tempVector );
2261 _performingOperation->setKeyNamesOperationElems( currentSelection );
2263 char theStartCommand = _performingOperation->getStartCommand();
2264 if ( theStartCommand == COPY )
2266 //JCP 20-10-08 Undo redo implementation
2268 //JCP 20-10-08 Undo redo implementation
2269 std::vector<int> tempVector;
2270 _instantPanel->getInstant( tempVector );
2271 _performingOperation->setEndOperationInstantVector ( tempVector );
2272 std::vector<std::string> elems = _performingOperation->getKeyNamesOperationElems();
2273 int i,size = elems.size();
2274 for( i=0; i<size; i++ )
2276 createMirrorContourOf( elems[i], tempVector, i>0 );
2280 //deleteContour( _refName );
2285 void wxContourMainFrame::showAxis(bool show)
2287 _theViewPanel->SetVisibleAxis(show);
2288 _theViewPanel->Refresh();
2292 void wxContourMainFrame::onRigidPressed(){
2293 std::vector<std::string> currentSelection = _theViewPanel->getSelectedObjects();
2294 int elementsSelected = currentSelection.size();
2296 if ( elementsSelected >= 1 ){
2297 //JCP 20-10-08 Undo redo implementation
2299 //JCP 20-10-08 Undo redo implementation
2301 std::vector<int> tempVector;
2302 _instantPanel->getInstant( tempVector );
2303 Instant instant(&tempVector);
2305 int i , size=currentSelection.size();
2306 for ( i=0 ; i<size ; i++ )
2308 kernelManager->changeContourOfManager(currentSelection[i], &instant);
2313 void wxContourMainFrame::onWidthOfContour(double width){
2315 _theViewPanel->removeSceneContours();
2316 _theViewPanel->SetWidthContour(width);
2318 //_theViewPanel->getSceneManager()->SetWidthContour( width );
2323 int wxContourMainFrame::getColorWindow()
2327 vtkImageData * img = getImageData();
2328 img->GetScalarRange(range);
2330 std::cout<<"Val 1: "<<range[0]<<" Val 2: "<<range[1]<<std::endl;
2332 return (int)range[1];
2334 return _theViewPanel->getColorWindow();
2337 int wxContourMainFrame::getWindowLevel()
2341 vtkImageData * img = getImageData();
2342 img->GetScalarRange(range);
2344 std::cout<<"Val 1: "<<range[0]<<" Val 2: "<<range[1]<<std::endl;
2346 return (int)range[1];
2348 return _theViewPanel->getWindowLevel();
2351 void wxContourMainFrame::onBrigthnessColorWindowLevel(int colorwindow,int windowlevel)
2353 _theViewPanel->onBrigthnessColorWindowLevel(colorwindow, windowlevel);
2358 void wxContourMainFrame::onInterpolation(bool interpolate)
2360 _theViewPanel->onInterpolation(interpolate);
2364 void wxContourMainFrame::onChangeInstant(std::string name,int actual)
2366 _instantPanel->setConceptValue( name, actual );
2370 void wxContourMainFrame::resetAppend()
2372 kernelManager->resetAppend();
2376 void wxContourMainFrame::onSpreadAdd()
2378 std::vector<double> vecX;
2379 std::vector<double> vecY;
2380 std::vector<double> vecZ;
2381 _theViewPanel->GetPointsOfActualContour(&vecX , &vecY , &vecZ );
2382 std::vector<int> tempVector;
2383 _instantPanel->getInstant( tempVector );
2384 std::string val = kernelManager->onSpreadAdd(&vecX , &vecY , &vecZ, tempVector);
2385 interfMainPanel::getInstance()->appendStringSpread(val);
2389 void wxContourMainFrame::onSpreadAddAll()
2392 std::vector<int> tempVector;
2393 _instantPanel->getInstant( tempVector );
2396 maxZ = interfMainPanel::getInstance()->GetImageDataSizeZ();
2398 int sizeLstContourThings;
2399 for ( z=minZ ; z<=maxZ ; z++ )
2402 Instant instant(&tempVector);
2403 std::vector<ContourThing**> lstContourThings = kernelManager->getOutlinesAtInstant( &instant );
2404 sizeLstContourThings = lstContourThings.size();
2405 if (sizeLstContourThings>=1)
2407 std::vector<double> vecX;
2408 std::vector<double> vecY;
2409 std::vector<double> vecZ;
2410 ContourThing **contourthing = lstContourThings[0];
2411 manualBaseModel *cModel = (*contourthing)->getModel();
2412 int i,size = cModel->GetNumberOfPointsSpline();
2414 for (i=0; i<size; i++)
2416 cModel->GetSpline_i_Point(i, &x, &y, &z);
2421 std::string val = kernelManager->onSpreadAdd(&vecX , &vecY , &vecZ, tempVector);
2422 interfMainPanel::getInstance()->appendStringSpread(val);
2423 }// if sizeLstContourThings
2428 void wxContourMainFrame::onSpreadGo(int type)
2430 //JCP 20-10-08 Undo redo implementation
2432 //JCP 20-10-08 Undo redo implementation
2434 std::vector<double> vecCtrlPointX;
2435 std::vector<double> vecCtrlPointY;
2436 std::vector<double> vecCtrlPointZ;
2440 std::vector<int> tempVector;
2441 _instantPanel->getInstant( tempVector );
2444 kernelManager->getMaxMinZ(&minZ,&maxZ);
2445 //JSTG_16-07-08_----------------------------------------------------------------
2446 //_contourPropagation->setInterpolationNumber(maxZ-minZ+1);
2447 kernelManager->CalculeSplinePropagation();
2449 double totalZ = maxZ-minZ+1;
2452 //--------------------------------------------------------------------
2453 for ( z=(int)minZ ; z<=(int)maxZ ; z++ )
2455 porcent = 100.0* (z-minZ)/totalZ;
2456 int numero = (int)(z-minZ+1)/(int)totalZ;
2457 std::string stringtemp = " "+kernelManager->intToString(porcent)+"% "+kernelManager->intToString(numero)+" "+kernelManager->intToString(z);
2459 interfMainPanel::getInstance()->setStringSpread(stringtemp);
2461 int typeofcontour = 1;
2462 std::string theName;
2463 manualBaseModel* manModelContour = kernelManager->GetPoints(z, type, &vecCtrlPointX,&vecCtrlPointY,&vecCtrlPointZ, theName,typeofcontour, tempVector);
2465 if( manModelContour!=NULL ){
2466 double spc[3];//Si no hay imagen pero hay contornos que spacing se pone por default
2467 this->_theViewPanel->getSpacing(spc);
2468 //Adding the manualContourControler to interface objects structure
2469 //Adding the manualViewContour to interface objects structure
2470 //_theViewPanel->getSceneManager()->setControlActiveStateOfALL( false );//This call is being done here because if the ROI is created underneath the previously created ROIS will still be active.
2471 _theViewPanel->configureViewControlTo( theName, manModelContour,spc,typeofcontour ) ;
2476 int numero = (int)(z-minZ+1)/(int)totalZ;
2477 std::string stringtemp = " "+kernelManager->intToString(porcent)+"% "+kernelManager->intToString(numero)+" "+kernelManager->intToString(z);
2479 interfMainPanel::getInstance()->setStringSpread(stringtemp);
2481 //RefreshInterface();
2484 void wxContourMainFrame::getInstantVector(std::vector<int>& tempVector)
2488 std::vector<std::string> wxContourMainFrame::getOutlinesName(int slide)
2490 std::vector<int> tempVector;
2491 _instantPanel->getInstant(tempVector);
2492 //Asignation of slide number should be different ex by name
2493 tempVector[1]=slide;
2494 return kernelManager->getOutlinesNameAtInstant(tempVector);
2498 void wxContourMainFrame::SetScalarRange(int grayRangeMin, int grayRangeMax)
2500 _contourextractdata->SetScalarRange(grayRangeMin,grayRangeMax);
2504 void wxContourMainFrame::onInformationContourLabels(int typeContourGroup,int selection,int minimumZ,int maximumZ,int grayRangeMin, int grayRangeMax)
2507 wxString tempString;
2508 int maxContourGroup = 0;
2510 _contourextractdata ->SetTypeOperation( typeContourGroup % 3 );
2512 std::vector<manualBaseModel*> lstManConMod;
2513 std::vector<manualBaseModel*> lstManConModTmp;
2514 std::vector<manualBaseModel*> lstManConModExp;
2515 std::vector<double> pLstValue;
2516 std::vector<double> pLstValuePosX;
2517 std::vector<double> pLstValuePosY;
2518 std::vector<double> pLstValuePosZ;
2521 int resultGrayRangeCount;
2524 double resultAverage;
2525 double resultStandardeviation;
2527 std::vector<int> tempVector;
2528 _instantPanel->getInstant( tempVector );
2531 int ii,sizeLstContourThings;
2540 if (selection==0 ) // actual slice
2542 int actualSlice = tempVector[1];
2545 } else { // slice range
2551 totalZ = maxZ-minZ+1;
2553 _contourextractdata->InitVolumeStatistics();
2556 for ( z=minZ ; z<=maxZ ; z++ )
2559 porcent = 100.0* (z-minZ)/totalZ;
2560 tmpString.Printf(_T(" %d %c %d/%d %d"), (int)porcent , 37 , z-minZ+1, (int)totalZ ,z);
2562 interfMainPanel::getInstance()->setStringInfoPanel(tmpString);
2563 //_staticTextInformation->SetLabel(tmpString);
2565 //Extraction data from contours of each slice
2566 _contourextractdata->SetZtoBeAnalys(z);
2569 Instant instant(&tempVector);
2570 std::vector<ContourThing**> lstContourThings = kernelManager->getOutlinesAtInstant( &instant );
2571 sizeLstContourThings = lstContourThings.size();
2573 lstManConMod.clear();
2574 for (ii=0 ; ii<sizeLstContourThings ; ii++)
2576 ContourThing **contourthing = lstContourThings[ii];
2577 lstManConMod.push_back( (*contourthing)->getModel() );
2580 lstManConModExp = kernelManager->ExploseEachModel( lstManConMod );
2582 tempString.Printf(_T("%d - %d"),z, sizeLstContourThings);
2583 interfMainPanel::getInstance()->setRowLabelInfoPanel(z, tempString);
2584 //_grid->SetRowLabelValue(z, tempString );
2586 int iContourGroup,sizeContourGroup;
2587 if (typeContourGroup==3) // contour separete
2589 sizeContourGroup=lstManConModExp.size();
2590 if ( maxContourGroup<sizeContourGroup )
2592 maxContourGroup=sizeContourGroup;
2594 } else { // contour AND OR XOR
2601 for( iContourGroup=0 ; iContourGroup<sizeContourGroup ; iContourGroup++ ){
2602 lstManConModTmp.clear();
2606 if (typeContourGroup==3) // contour separete
2608 lstManConModTmp.push_back( lstManConModExp[iContourGroup]);
2609 } else { // contour AND OR XOR
2610 lstManConModTmp = lstManConModExp;
2613 _contourextractdata->SetLstManualContourModel( lstManConModTmp );
2614 _contourextractdata->SetScalarRange(grayRangeMin,grayRangeMax);
2617 pLstValuePosX.clear();
2618 pLstValuePosY.clear();
2619 pLstValuePosZ.clear();
2623 _contourextractdata->GetValuesInsideCrown( &numberOfPixels,
2629 resultSize=numberOfPixels;
2630 // Statistics of each slice.
2631 _contourextractdata->Statistics( &pLstValue,
2634 &resultGrayRangeCount,
2639 &resultStandardeviation);
2641 if (interfMainPanel::getInstance()->getNumberColsInformationPanel()<_numberOfVariablesStatistics*(iContourGroup+1) )
2643 interfMainPanel::getInstance()->appendColsInformationPanel(_numberOfVariablesStatistics);
2646 tmpIntA=_numberOfVariablesStatistics*iContourGroup ;
2648 tempString.Printf(_T("%d"),numberOfPixels);
2650 interfMainPanel::getInstance()->setCellValueInfoPanel(z, tmpIntA, tempString);
2652 tempString.Printf(_T("%d"),resultGrayRangeCount);
2653 interfMainPanel::getInstance()->setCellValueInfoPanel(z, tmpIntA+1, tempString);
2655 tempString.Printf(_T("%f"),resultMin);
2656 interfMainPanel::getInstance()->setCellValueInfoPanel(z, tmpIntA+2, tempString);
2658 tempString.Printf(_T("%f"),resultMax);
2659 interfMainPanel::getInstance()->setCellValueInfoPanel(z, tmpIntA+3, tempString);
2661 tempString.Printf(_T("%f"),resultAverage);
2662 interfMainPanel::getInstance()->setCellValueInfoPanel(z, tmpIntA+4, tempString);
2664 tempString.Printf(_T("%f"),resultStandardeviation);
2665 interfMainPanel::getInstance()->setCellValueInfoPanel(z, tmpIntA+5, tempString);
2668 } // for iContourGroup
2671 // Print Volume Statistics
2674 int vol_rCountRange;
2676 double vol_minValue;
2677 double vol_maxValue;
2679 double vol_standardeviation;
2681 if (selection!=0 ) // actual slice
2684 _contourextractdata->GetVolumeStatistics(&vol_rCountRange, &vol_rsize,
2685 &vol_minValue, &vol_maxValue,
2686 &vol_average, &vol_standardeviation);
2688 interfMainPanel::getInstance()->setRowLabelInfoPanel(maxZ+2, _T("Total:"));
2690 tempString.Printf(_T("%d"),vol_rsize);
2691 interfMainPanel::getInstance()->setCellValueInfoPanel(maxZ+2, 0, tempString);
2693 tempString.Printf(_T("%d"),vol_rCountRange);
2694 interfMainPanel::getInstance()->setCellValueInfoPanel(maxZ+2, 1, tempString);
2696 tempString.Printf(_T("%f"),vol_minValue);
2697 interfMainPanel::getInstance()->setCellValueInfoPanel(maxZ+2, 2, tempString);
2699 tempString.Printf(_T("%f"),vol_maxValue);
2700 interfMainPanel::getInstance()->setCellValueInfoPanel(maxZ+2, 3, tempString);
2702 tempString.Printf(_T("%f"),vol_average);
2703 interfMainPanel::getInstance()->setCellValueInfoPanel(maxZ+2, 4, tempString);
2705 tempString.Printf(_T("%f"),vol_standardeviation);
2706 interfMainPanel::getInstance()->setCellValueInfoPanel(maxZ+2, 5, tempString);
2708 //-----------------------------------------
2711 wxString tmpTitleString;
2713 for ( iTitleGroup=0 ; iTitleGroup<maxContourGroup ; iTitleGroup++ )
2715 tmpIntB =_numberOfVariablesStatistics*iTitleGroup;
2716 tmpTitleString.Printf(_T("%d-Size Data"),iTitleGroup);
2717 interfMainPanel::getInstance()->setColLableInfoPanel(tmpIntB + 0, tmpTitleString);
2719 interfMainPanel::getInstance()->setColLableInfoPanel(tmpIntB + 0, tmpTitleString );
2720 interfMainPanel::getInstance()->setColLableInfoPanel( tmpIntB + 1, _T("Size Range") );
2721 interfMainPanel::getInstance()->setColLableInfoPanel( tmpIntB + 2, _T("Min") );
2722 interfMainPanel::getInstance()->setColLableInfoPanel( tmpIntB + 3, _T("Max") );
2723 interfMainPanel::getInstance()->setColLableInfoPanel( tmpIntB + 4, _T("Average") );
2724 interfMainPanel::getInstance()->setColLableInfoPanel( tmpIntB + 5, _T("St.Dev.") );
2725 interfMainPanel::getInstance()->setColLableInfoPanel( tmpIntB + 6, _T(" ") );
2727 interfMainPanel::getInstance()->setStringInfoPanel( _T("") );
2731 void wxContourMainFrame::onSaveResults(std::string directory,std::string namefile, std::string filename,
2732 int typeContourGroup, int selection, int minZ, int maxZ, bool XYZValues, bool contourImage, bool statistics)
2736 SaveValuesXYZ( directory , namefile, typeContourGroup );
2741 vtkImageData * mask;
2742 vtkImageData * value;
2743 this->getMaskValue(&mask, &value, typeContourGroup,selection,minZ,maxZ);
2744 this->SaveImageResult( directory , namefile, mask, value);
2749 std::ostringstream name;
2750 name << filename << ".xls";
2753 FILE *pFile=fopen(name.str().c_str(),"w+");
2759 // int sizeZ = _theViewPanel->GetImageDataSizeZ();
2760 // int maxY=sizeZ+2;
2762 maxX= interfMainPanel::getInstance()->getNumberColsInformationPanel();//this->_grid->GetNumberCols();
2765 int iTitle,sizeTitle = (maxX / _numberOfVariablesStatistics);
2766 for ( iTitle=0; iTitle<sizeTitle ; iTitle++)
2768 // fprintf(pFile,"-- \t %d-Size \t SizeRange \t Min \t Max \t Ave \t StDv \t" , iTitle,tmpString.c_str() );
2769 fprintf(pFile,"slice\t %d-Size \t SizeRange \t Min \t Max \t Ave \t StDv \t" , iTitle );
2771 fprintf(pFile,"\n\n" );
2775 if (selection==0 ) // actual slice
2777 std::vector<int> tempVector;
2778 _instantPanel->getInstant( tempVector );
2779 int actualSlice = tempVector[1];
2785 for ( j=minZ; j<=maxZ ; j++)
2787 fprintf(pFile,"%d\t" , j );
2788 for (i=0 ; i<maxX ; i++){
2789 tmpString = interfMainPanel::getInstance()->getCellValue(j, i);//_grid->GetCellValue( j , i );
2790 fprintf(pFile,"%s\t" , (const char *)(tmpString.mb_str()) );
2792 fprintf(pFile,"\n" );
2796 // Total of stadistics.....
2799 fprintf(pFile,"\n Total:\t" );
2800 for (i=0 ; i<maxX ; i++){
2801 tmpString = interfMainPanel::getInstance()->getCellValue(maxZ+2, i);//_grid->GetCellValue( maxZ+2 , i );
2802 fprintf(pFile,"%s\t" , (const char *)(tmpString.mb_str()) );
2804 fprintf(pFile,"\n" );
2812 void wxContourMainFrame::SaveValuesXYZ(std::string directory,std::string namefile,int typeContourGroup)
2816 //int typeContourGroup = this->_radiolstboxContourGroup->GetSelection();
2817 _contourextractdata ->SetTypeOperation( typeContourGroup % 3 );
2819 std::vector<manualBaseModel*> lstManConMod;
2820 std::vector<manualBaseModel*> lstManConModTmp;
2821 std::vector<manualBaseModel*> lstManConModExp;
2822 std::vector<double> pLstValue;
2823 std::vector<double> pLstValuePosX;
2824 std::vector<double> pLstValuePosY;
2825 std::vector<double> pLstValuePosZ;
2827 std::vector<int> tempVector;
2828 _instantPanel->getInstant( tempVector );
2830 int sizeZ = _theViewPanel->getSceneManager()->GetImageDataSizeZ();
2832 int ii,sizeLstContourThings;
2839 minZ = 0;// _mbarrange->GetStart();
2840 maxZ = sizeZ;//_mbarrange->GetEnd();
2841 totalZ = maxZ-minZ+1;
2845 for ( z=0 ; z<sizeZ ; z++)
2848 porcent = 100.0* (z-minZ)/totalZ;
2850 tmpString.Printf(_T("Saving Values"));
2851 tmpString.Printf(_T(" %d %c %d/%d %d"), (int)porcent , 37 , z-minZ+1, (int)totalZ ,z);
2852 interfMainPanel::getInstance()->setStringInfoPanel(tmpString);
2853 //_staticTextInformation->SetLabel(tmpString);
2856 //Extraction data from contours of each slice
2857 _contourextractdata->SetZtoBeAnalys( z);
2860 Instant instant(&tempVector);
2861 std::vector<ContourThing**> lstContourThings = kernelManager->getOutlinesAtInstant(&instant);//this->_modelManager->getOutlinesAtInstant( &instant );
2862 sizeLstContourThings = lstContourThings.size();
2864 lstManConMod.clear();
2865 for (ii=0 ; ii<sizeLstContourThings ; ii++)
2867 ContourThing **contourthing = lstContourThings[ii];
2868 lstManConMod.push_back( (*contourthing)->getModel() );
2870 lstManConModExp = kernelManager->ExploseEachModel( lstManConMod );
2875 int iContourGroup,sizeContourGroup;
2876 if (typeContourGroup==3) // contour separete
2878 sizeContourGroup=lstManConModExp.size();
2879 } else { // contour AND OR XOR
2883 for( iContourGroup=0 ; iContourGroup<sizeContourGroup ; iContourGroup++ ){
2884 lstManConModTmp.clear();
2885 if (typeContourGroup==3) // contour separete
2887 lstManConModTmp.push_back( lstManConModExp[iContourGroup]);
2888 } else { // contour AND OR XOR
2889 lstManConModTmp = lstManConModExp;
2892 _contourextractdata->SetLstManualContourModel( lstManConModTmp );
2895 pLstValuePosX.clear();
2896 pLstValuePosY.clear();
2897 pLstValuePosZ.clear();
2899 _contourextractdata->GetValuesInsideCrown( &numberOfPixels,
2905 std::string temp = directory + "/" + namefile + "-slice";
2906 temp = temp + kernelManager->intToString(z) + "-cont" + kernelManager->intToString(iContourGroup);
2907 temp = temp + ".txt";
2909 // LG 14/01/09 : using crea
2910 wxString filename = crea::std2wx(temp);
2911 /*filename.Printf(_T("%s"),directory.c_str());
2912 filename.append(_T("\\"));
2913 filename.append(_T("%s"),namefile.c_str());
2914 filename.append(_T("-slice"));
2915 filename.append(_T("%d"),z);
2916 filename.append(_T("-cont"));
2917 filename.append(_T("%d"),iContourGroup);
2918 filename.append(_T(".txt"));*/
2919 // filename.Printf(temp.c_str());
2923 FILE *pFile=fopen((const char *)filename.mb_str(),"w+");
2924 fprintf(pFile,"value \t x \t y \t z\n" );
2925 int iLstValue,sizeLstValue=pLstValue.size();
2926 for (iLstValue=0 ; iLstValue<sizeLstValue ; iLstValue++ )
2928 fprintf(pFile,"%f\t %f\t %f\t %f\n", (float)pLstValue[iLstValue] , (float)pLstValuePosX[iLstValue], (float)pLstValuePosY[iLstValue], (float)z );
2931 } // for iContourGroup
2933 interfMainPanel::getInstance()->setStringInfoPanel(_T(""));
2934 //_staticTextInformation->SetLabel( _T("") );
2938 void wxContourMainFrame::getMaskValue(vtkImageData ** mask,vtkImageData ** value,int typeContourGroup, int selection, int minZ, int maxZ){
2941 //int typeContourGroup = this->_radiolstboxContourGroup->GetSelection();
2942 if (typeContourGroup==3)
2946 _contourextractdata ->SetTypeOperation( typeContourGroup % 3 );
2948 std::vector<manualBaseModel*> lstManConMod;
2949 std::vector<manualBaseModel*> lstManConModTmp;
2950 std::vector<manualBaseModel*> lstManConModExp;
2952 std::vector<int> tempVector;
2953 _instantPanel->getInstant( tempVector );
2955 vtkImageData *imagedata = _theViewPanel->getImageData();
2957 imagedata->GetExtent(ext);
2958 int sizeZimage = ext[5]-ext[4]+1;
2960 int ii,sizeLstContourThings;
2968 if (selection==0 ) // actual slice
2970 int actualSlice = tempVector[1];
2978 // cleanning image before range
2979 for (z=0; z<minZ; z++){
2980 _contourextractdata->ResetImageResult(z);
2982 // cleanning image after range
2983 for (z=maxZ+1; z<sizeZimage; z++){
2984 _contourextractdata->ResetImageResult(z);
2989 for ( z=minZ ; z<=maxZ ; z++)
2992 porcent = 100.0* (z-minZ)/totalZ;
2993 tmpString.Printf(_T("Saving Values"));
2994 tmpString.Printf(_T("%d %c %d/%d %d"), (int)porcent , 37 , z-minZ+1, (int)totalZ ,z);
2995 interfMainPanel::getInstance()->setStringInfoPanel(tmpString);
2997 //Extraction data from contours of each slice
2998 _contourextractdata->SetZtoBeAnalys( z);
3001 Instant instant(&tempVector);
3002 std::vector<ContourThing**> lstContourThings = kernelManager->getOutlinesAtInstant( &instant );
3003 sizeLstContourThings = lstContourThings.size();
3005 lstManConMod.clear();
3006 for (ii=0 ; ii<sizeLstContourThings ; ii++)
3008 ContourThing **contourthing = lstContourThings[ii];
3009 lstManConMod.push_back( (*contourthing)->getModel() );
3011 lstManConModExp = kernelManager->ExploseEachModel( lstManConMod );
3014 int iContourGroup,sizeContourGroup;
3015 if (typeContourGroup==3) // contour separete
3017 sizeContourGroup=lstManConModExp.size();
3018 } else { // contour AND OR XOR
3022 for( iContourGroup=0 ; iContourGroup<sizeContourGroup ; iContourGroup++ ){
3023 lstManConModTmp.clear();
3024 if (typeContourGroup==3) // contour separete
3026 lstManConModTmp.push_back( lstManConModExp[iContourGroup]);
3027 } else { // contour AND OR XOR
3028 lstManConModTmp = lstManConModExp;
3031 _contourextractdata->SetLstManualContourModel( lstManConModTmp );
3032 _contourextractdata->CalculateImageResult(); // with actual Z
3034 } // for iContourGroup
3037 (*value) = _contourextractdata->GetVtkImageValueResult();
3038 (*mask) = _contourextractdata->GetVtkImageMaskResult();
3042 std::string wxContourMainFrame::GetStringTypeImage( vtkImageData* image)
3044 std::string result="";
3045 if ( image->GetScalarType()==VTK_CHAR )
3048 } else if ( image->GetScalarType()==VTK_UNSIGNED_CHAR ){
3050 } else if ( image->GetScalarType()==VTK_FLOAT ){
3052 } else if ( image->GetScalarType()==VTK_DOUBLE ){
3054 } else if ( image->GetScalarType()==VTK_INT ){
3056 } else if ( image->GetScalarType()==VTK_UNSIGNED_INT ){
3058 } else if ( image->GetScalarType()==VTK_SHORT ){
3060 } else if ( image->GetScalarType()==VTK_UNSIGNED_SHORT ){
3062 } else if ( image->GetScalarType()==VTK_LONG ){
3064 } else if ( image->GetScalarType()==VTK_UNSIGNED_LONG ){
3070 void wxContourMainFrame::SaveImageResult(std::string directory,std::string namefile, vtkImageData* mask,vtkImageData* value)
3072 std::string stringType;
3074 kernelManager->GetSpacing(spc,0); // returns the spacing of the first image
3075 stringType = GetStringTypeImage(value);
3076 std::string temp = directory + "/" + namefile + "-image-Value-"+stringType+".mhd";
3078 wxString filename = crea::std2wx(temp);
3082 vtkImageChangeInformation *valueChInfo = vtkImageChangeInformation::New();
3083 //EED 2017-01-01 Migration VTK7
3084 #if VTK_MAJOR_VERSION <= 5
3085 valueChInfo->SetInput(value);
3087 valueChInfo->SetInputData(value);
3089 valueChInfo->SetSpacingScale(spc);
3090 vtkMetaImageWriter *writerValueImage = vtkMetaImageWriter::New( );
3092 //EED 2017-01-01 Migration VTK7
3093 #if VTK_MAJOR_VERSION <= 5
3094 writerValueImage->SetInput( valueChInfo->GetOutput() );
3096 writerValueImage->SetInputData( valueChInfo->GetOutput() );
3098 writerValueImage->SetFileName( (const char *)filename.mb_str() );
3099 writerValueImage->SetFileDimensionality( 3 );
3100 writerValueImage->SetCompression(false);
3101 writerValueImage->Write( );
3104 stringType = GetStringTypeImage(mask);
3105 temp = directory + "/" + namefile + "-image-Mask-"+stringType+".mhd";
3107 // LG 14/01/09 : using crea
3108 filename = crea::std2wx(temp);
3109 // filename.Printf(_T(temp.c_str()));
3112 vtkImageChangeInformation *maskChInfo = vtkImageChangeInformation::New();
3113 //EED 2017-01-01 Migration VTK7
3114 #if VTK_MAJOR_VERSION <= 5
3115 maskChInfo->SetInput(mask);
3117 maskChInfo->SetInputData(mask);
3119 maskChInfo->SetSpacingScale(spc);
3120 vtkMetaImageWriter *writerMaskImage = vtkMetaImageWriter::New( );
3122 //EED 2017-01-01 Migration VTK7
3123 #if VTK_MAJOR_VERSION <= 5
3124 writerMaskImage->SetInput( maskChInfo->GetOutput() );
3126 writerMaskImage->SetInputData( maskChInfo->GetOutput() );
3129 writerMaskImage->SetFileName( (const char *)filename.mb_str() );
3130 writerMaskImage->SetFileDimensionality( 3 );
3131 writerMaskImage->SetCompression(false);
3132 writerMaskImage->Write( );
3134 interfMainPanel::getInstance()->setStringInfoPanel( _T("") );
3140 void wxContourMainFrame::onChangeInstantInstantPanel(std::string name,int value, int minshow, int maxshow){
3141 if( name.compare( _theViewPanel->getVerticalConceptName() ) == 0){
3142 _theViewPanel->setActualVertical( value);
3144 else if( name.compare( _theViewPanel->getHorizontalConceptName() ) == 0|| _instantPanel->getIfConceptCheckedAt( name, 0 ) ) {
3145 _theViewPanel->setHorizontalConcept( name, minshow, maxshow, minshow, maxshow, value);
3151 void wxContourMainFrame::onSnakePressed(){
3152 std::vector<double> vecX;
3153 std::vector<double> vecY;
3154 std::vector<double> vecZ;
3155 _theViewPanel->GetPointsOfActualContour( &vecX , &vecY , &vecZ );
3157 if (vecX.size()!=0){
3158 std::vector<int> tempVector;
3159 _instantPanel->getInstant( tempVector );
3160 int i,size=vecZ.size();
3161 int actualSlice = tempVector[1];
3162 for ( i=0 ; i<size ; i++ )
3164 vecZ[i] = actualSlice;
3167 wxDialog* dialog = new wxDialog(this, -1, wxString(_T("Snake")));
3168 wxPanel* panel = new wxPanel(dialog,-1);
3169 // wxStaticText* sttext = new wxStaticText(panel, -1, wxString(_T("Panel para snake")));
3170 new wxStaticText(panel, -1, wxString(_T("Panel para snake")));
3171 dialog->ShowModal();
3176 void wxContourMainFrame::saveFileWithContoursAutomatique(){
3177 std::string filename = kernelManager->getCurrentFileName();
3178 if(filename.compare("")!=0){
3179 saveFileWithContours(filename);
3184 void wxContourMainFrame::ShowToolsPanel(bool show){
3185 _pannew->Show(show);
3190 void wxContourMainFrame::SetContourGroup(int contourGroup)
3192 _contourGroup = contourGroup;
3196 wxPanel *wxContourMainFrame::getMaskImageViewPanel(wxWindow *parent)
3199 if (_viewMaskImagePanel==NULL)
3201 _contourextractdata = new ContourExtractData(true);
3202 _contourextractdata->SetImage( _theViewPanel->getImageData() );
3204 // _theViewPanel->getImageData()->GetScalarRange(range);
3205 //int min = (int)floor (range[0]);
3206 //int max = (int)ceil (range[1]);
3212 _viewMaskImagePanel = new ThresholdImageViewPanel( parent, -1, -1 , -1,-1, 0);
3213 _viewMaskImage = new ThresholdImageView();
3214 _viewMaskImage->SetImage( _contourextractdata->GetVtkImageMaskResult() );
3215 _viewMaskImage->SetminMaxValue( min, max);
3216 _viewMaskImage->SetBaseColor( 0,0,1 );
3219 std::vector<int> colorbarposition;
3220 colorbarposition.push_back( -999 );
3221 colorbarposition.push_back( -999 );
3222 _viewMaskImage->SetColorBarPosition( colorbarposition );
3224 _viewMaskImage->SetSpcBase( _theViewPanel->getImageData()->GetSpacing() );
3225 _viewMaskImage->SetNewSpacingLayer( _theViewPanel->getImageData()->GetSpacing() );
3227 _viewMaskImagePanel->SetThresholdImageView( _viewMaskImage );
3228 _viewMaskImage->SetwxVtkBaseView( _theViewPanel->getWxVtkBaseView() );
3229 _viewMaskImage->onThresholdChangeOpacity( 25 );
3231 return _viewMaskImagePanel;
3235 wxPanel *wxContourMainFrame::getColorLayerImageViewPanel(wxWindow *parent)
3237 if (_viewColorLayerImagePanel==NULL)
3240 _theViewPanel->getImageData()->GetScalarRange(range);
3241 int min = (int)floor (range[0]);
3242 int max = (int)ceil (range[1]);
3243 _viewColorLayerImagePanel = new ColorLayerImageViewPanel( parent, min, max, 100, 1);
3244 _viewColorLayerImagePanel->GetColorLayerImageViewManager()->SetwxVtkBaseView( 0 , _theViewPanel->getWxVtkBaseView() );
3245 // std::vector<double> range = bbGetInputlstRangeForColorBar();
3246 // clivp->GetColorLayerImageViewManager()->SetRangeForColorBar( range );
3247 std::vector<int> colorbarposition;
3248 colorbarposition.push_back( 50 );
3249 colorbarposition.push_back( 105 );
3250 _viewColorLayerImagePanel->GetColorLayerImageViewManager()->SetColorBarPosition( colorbarposition );
3251 // std::vector<double> base_color;
3252 // _viewColorLayerImagePanel->GetColorLayerImageViewManager()->SetBaseColors( base_color );
3253 // std::vector<double> grey_level_boundaries;
3254 // clivp->GetColorLayerImageViewManager()->SetGreyLevelBoundaries( grey_level_boundaries );
3255 std::vector<double> transparence_level_boundaries;
3256 transparence_level_boundaries.push_back(0);
3257 _viewColorLayerImagePanel->GetColorLayerImageViewManager()->SetBaseTransparence( transparence_level_boundaries );
3258 _viewColorLayerImagePanel->GetColorLayerImageViewManager()->SetPlainOrGradientColor( false );
3259 // _viewColorLayerImagePanel->SetFittingMode( 3 );
3261 return _viewColorLayerImagePanel;
3265 wxPanel *wxContourMainFrame::getThresholdImageViewPanel(wxWindow *parent)
3267 if (_viewThresholdImagePanel==NULL)
3270 _theViewPanel->getImageData()->GetScalarRange(range);
3271 int min = (int)floor (range[0]);
3272 int max = (int)ceil (range[1]);
3273 int start= (max+min)/2 - (max-min)*0.25;
3274 int end= (max+min)/2 + (max-min)*0.25;
3275 _viewThresholdImagePanel = new ThresholdImageViewPanel( parent, min, max, start, end , 1);
3276 _viewThresholdImage = new ThresholdImageView();
3277 _viewThresholdImage->SetminMaxValue(start,end);
3278 _viewThresholdImage->SetImage( _theViewPanel->getImageData() );
3279 std::vector<int> colorbarposition;
3280 colorbarposition.push_back( 10 );
3281 colorbarposition.push_back( 105 );
3282 _viewThresholdImage->SetColorBarPosition( colorbarposition );
3284 _viewThresholdImage->SetSpcBase( _theViewPanel->getImageData()->GetSpacing() );
3285 _viewThresholdImage->SetNewSpacingLayer( _theViewPanel->getImageData()->GetSpacing() );
3287 _viewThresholdImage->SetBaseColor( 1,0,0 );
3288 _viewThresholdImagePanel->SetThresholdImageView( _viewThresholdImage );
3289 _viewThresholdImage->SetwxVtkBaseView( _theViewPanel->getWxVtkBaseView() );
3290 _viewThresholdImage->onThresholdChangeOpacity( 25 );
3293 return _viewThresholdImagePanel;
3296 //CMRU 17-08-09-----------------------------------------------------------------------------------------------
3297 int wxContourMainFrame::getType ()
3300 std::vector<std::string> currentSelection = _theViewPanel->getSelectedObjects();
3302 if(!currentSelection.empty())
3304 std::string cloneName = currentSelection [0];
3305 manualBaseModel * manualModel = kernelManager->getOutlineByKeyName(cloneName);
3306 tipo = manualModel-> GetTypeModel();
3311 double wxContourMainFrame::getContourSizeInPixels()
3313 double contourSize = 0;
3315 std::vector<std::string> currentSelection = _theViewPanel->getSelectedObjects(); if(!currentSelection.empty())
3316 if(!currentSelection.empty())
3318 std::string cloneName = currentSelection [0];
3320 manualBaseModel * manualModel = kernelManager->getOutlineByKeyName(cloneName);//_modelManager->getOutlineByKeyName( cloneName )->getModel();
3323 // contourSize = manualModel->GetPathSize();
3328 contourSize = manualModel->GetPathSize( spc );
3333 manualBaseModel * wxContourMainFrame::getContour ()
3335 std::vector<std::string> currentSelection = _theViewPanel->getSelectedObjects();
3337 if(!currentSelection.empty())
3339 std::string cloneName = currentSelection [0];
3340 manualBaseModel * manualModel = kernelManager->getOutlineByKeyName(cloneName);//_modelManager->getOutlineByKeyName( cloneName )->getModel();
3345 void wxContourMainFrame::onPrintLabel (wxString label, manualBaseModel* manualModel)
3347 std::string labelAscii(label.ToAscii());
3348 int pos = labelAscii.find(" ");
3352 for (j=0 ; pos != string::npos;j++)
3354 labelAscii.replace( pos, 1, "_" );
3355 pos= labelAscii.find(" ");
3358 manualModel -> SetLabel(labelAscii);
3360 void wxContourMainFrame::onInsertCalculation(manualBaseModel* manualModel)
3363 // double sizeInPixel = manualModel ->GetPathSize( );
3368 double sizeInPixel = manualModel ->GetPathSize( spc );
3370 double onePixelRealSize = interfMainPanel::getInstance()->GetPixelValue();;
3371 double realContourSize = sizeInPixel*onePixelRealSize;
3372 manualModel ->SetRealSize(realContourSize);
3375 double wxContourMainFrame::onePixelSize( double value)
3377 return _onePixelSize = value;
3380 std::string wxContourMainFrame::GetFileLocation()
3382 return _fileLocation;
3385 void wxContourMainFrame::SetFileLocation(std::string newFileLocation)
3387 _fileLocation = newFileLocation;
3388 std::cout<<"GETFILELOCATION:"<<_fileLocation<<std::endl;
3390 //------------------------------------------------------------------------------------------------------------
3399 void wxContourMainFrame::FlipSelectedContours(int flipDirection)
3402 (std::vector<std::string>)_theViewPanel->getSceneManager()->getSelectedObjects() ,
3408 void wxContourMainFrame::FlipActualSliceContours(int flipDirection)
3411 (std::vector<std::string>)_theViewPanel->getSceneManager()->GetlstContoursNameActualSlice() ,
3416 void wxContourMainFrame::FlipAllContours(int flipDirection)
3419 kernelManager->GetLstNameThings() ,
3424 void wxContourMainFrame::FlipLstOfContours(std::vector<std::string> lstNameThings, int flipDirection)
3427 getImageData()->GetExtent(ext);
3428 int sizeX = ext[1]-ext[0];
3429 int sizeY = ext[3]-ext[2];
3432 int i,sizeLstNameThings;
3433 int ii,sizeLstPoints;
3435 sizeLstNameThings = lstNameThings.size();
3436 for (i=0 ; i<sizeLstNameThings ; i++)
3438 printf("EED wxContourMainFrame::FlipAllContours contour=%d \n", i );
3439 manualBaseModel * manualModel = kernelManager->getOutlineByKeyName(lstNameThings[i]);
3440 if (flipDirection==0)
3442 manualModel->Transform_Ax_Plus_B(-1,sizeX,1,0 );
3444 manualModel->Transform_Ax_Plus_B(1,0,-1,sizeY );
3446 }// for i list of Things
3448 //-- Static Contours
3450 lstNameThings = kernelManager->GetLstNameThingsStatic();
3451 sizeLstNameThings = lstNameThings.size();
3452 for (i=0 ; i<sizeLstNameThings ; i++)
3454 manualBaseModel * manualModel = kernelManager->getOutlineByKeyName(lstNameThings[i]);
3455 if (flipDirection==0)
3457 manualModel->Transform_Ax_Plus_B(-1,sizeX,1,0 );
3459 manualModel->Transform_Ax_Plus_B(1,0,-1,sizeY );
3461 }// for i list of static things
3464 void wxContourMainFrame::FlipContours(int typeContourFlip, int flipDirection)
3466 printf("EED wxContourMainFrame::FlipContours( %d , %d ) \n",typeContourFlip, flipDirection );
3470 if (typeContourFlip==0) //
3472 FlipSelectedContours(flipDirection);
3475 if (typeContourFlip==1) //
3477 FlipActualSliceContours(flipDirection);
3480 if (typeContourFlip==2) //
3482 FlipAllContours(flipDirection);