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);
730 _theViewPanel->changeImage(img);
733 int z = _instantPanel->getConceptDataOf("Axe Depth")->getActualValue();
734 _theViewPanel->setImageSlice(z);
738 void wxContourMainFrame::updateInstantAxes()
743 void wxContourMainFrame::onChangeDeep(int val){
744 _instantPanel->setConceptValue( "Axe Depth", (int)val );
749 void wxContourMainFrame::onCopy(){
750 std::vector<std::string> currentSelection = _theViewPanel->getSelectedObjects();
751 std::vector<int> tempVector;
752 _instantPanel->getInstant( tempVector );
753 _performingOperation->reset();
754 _performingOperation->setStartCommand( COPY );
755 _performingOperation->setStartOperationInstantVector( tempVector );
756 _performingOperation->setKeyNamesOperationElems( currentSelection );
759 void wxContourMainFrame::onPaste()
761 char theStartCommand = _performingOperation->getStartCommand();
762 if ( theStartCommand == COPY )
764 //JCP 20-10-08 Undo redo implementation
766 //JCP 20-10-08 Undo redo implementation
767 std::vector<int> tempVector;
768 _instantPanel->getInstant( tempVector );
769 _performingOperation->setEndOperationInstantVector ( tempVector );
770 std::vector<std::string> elems = _performingOperation->getKeyNamesOperationElems();
771 int i,size = elems.size();
772 for( i=0; i<size; i++ )
774 createCopyContourOf( elems[i], tempVector, i>0 );
779 void wxContourMainFrame::onUndo()
781 std::string filename;
782 if(kernelManager->onUndoSaveFile(filename)){
783 saveFileWithContours(filename);
785 if(kernelManager->onUndo(filename)){
789 void wxContourMainFrame::onRedo(){
790 std::string filename;
791 if(kernelManager->onRedo(filename)){
796 void wxContourMainFrame :: createCopyContourOf ( std::string anExistingKName, std::vector<int> &instantNoTouchData, bool append )
798 std::string cloneName = kernelManager->createCopyContourOf( anExistingKName, instantNoTouchData );
799 manualBaseModel * manualModel = kernelManager->getOutlineByKeyName(cloneName);//_modelManager->getOutlineByKeyName( cloneName )->getModel();
800 _theViewPanel->getSceneManager()->createCopyContourOf( anExistingKName, cloneName, manualModel , append );
803 ///AD: 03-09 Copy the object and apply the given transformation
804 void wxContourMainFrame :: createMirrorContourOf ( std::string anExistingKName, std::vector<int> &instantNoTouchData, bool append )
806 std::string cloneName = kernelManager->createCopyContourOf( anExistingKName, instantNoTouchData );
807 manualBaseModel * manualModel = kernelManager->getOutlineByKeyName(cloneName);
809 manualPoint * refPoint1 = _refLineModel->GetManualPoint(0);
810 manualPoint * refPoint2 = _refLineModel->GetManualPoint(1);
812 double pnt1X = refPoint1->GetX();
813 double pnt1Y = refPoint1->GetY();
814 // double pnt1Z = refPoint1->GetZ();
815 double pnt2X = refPoint2->GetX();
816 double pnt2Y = refPoint2->GetY();
817 // double pnt2Z = refPoint2->GetZ();
819 double angle = (atan2(pnt2Y - pnt1Y, pnt2X - pnt1X) * 180 / 3.1415926535897932384626433832795)+90;
820 vtkTransform *t = vtkTransform::New();
824 t->Translate(-pnt1X, -pnt1Y, 0);
828 t->Translate(pnt1X, pnt1Y, 0);
831 int i,size=manualModel->GetSizeLstPoints();
834 manualPoint * mp = manualModel->GetManualPoint(i);
840 t->TransformPoint( vecIn, vecOut );
841 mp->SetPointX( vecOut[0] );
842 mp->SetPointY( vecOut[1] );
843 mp->SetPointZ( vecOut[2] );
846 _theViewPanel->getSceneManager()->createCopyContourOf( anExistingKName, cloneName, manualModel , append );
849 void wxContourMainFrame ::loadState(std::string filename)
852 onLoadContours(filename,false);
856 void wxContourMainFrame::onLoad()
858 std::string fileNameContourROI = GetFileLocation();
859 //CMRU 03-09-09-----------------------------------------------------------------------------------------------
860 if(GetFileLocation().empty())
862 //------------------------------------------------------------------------------------------------------------
863 //EED 2017-09-16 Migration wxWidgets 2.8 to 3.0
864 #if wxMAJOR_VERSION <= 2
865 wxFileDialog dialog(NULL, _T("Choose a file"), _T(""), _T(""), _T("*.roi"), wxOPEN );
867 wxFileDialog dialog(NULL, _T("Choose a file"), _T(""), _T(""), _T("*.roi"), wxFD_OPEN );
869 if (dialog.ShowModal() == wxID_OK)
871 fileNameContourROI = (const char *)(dialog.GetPath().mb_str());
875 onLoadContours(fileNameContourROI,true);
879 void wxContourMainFrame::SetZForAllContours(int pz)
882 std::vector< std::string > lstNameThings;
883 int i,sizeLstNameThings;
884 int ii,sizeLstPoints;
886 lstNameThings = kernelManager->GetLstNameThings();
887 sizeLstNameThings = lstNameThings.size();
888 for (i=0 ; i<sizeLstNameThings ; i++)
890 printf("EED wxContourMainFrame::SetZForAllContours contour=%d \n", i );
891 manualBaseModel * manualModel = kernelManager->getOutlineByKeyName(lstNameThings[i]);
892 sizeLstPoints = manualModel->GetSizeLstPoints();
893 for (ii=0 ; ii<sizeLstPoints ; ii++)
895 manualModel->GetManualPoint(ii)->SetPointZ(-900);
896 }// for ii list of points
897 }// for i list of Things
901 lstNameThings = kernelManager->GetLstNameThingsStatic();
902 sizeLstNameThings = lstNameThings.size();
903 for (i=0 ; i<sizeLstNameThings ; i++)
905 manualBaseModel * manualModel = kernelManager->getOutlineByKeyName(lstNameThings[i]);
906 sizeLstPoints = manualModel->GetSizeLstPoints();
907 for (ii=0 ; ii<sizeLstPoints ; ii++)
909 manualModel->GetManualPoint(ii)->SetPointZ(-900);
910 }// for ii list of points
911 }// for i list of static things
914 void wxContourMainFrame::onLoadContours(std::string fileNameContourROI, bool interactiveInterface)
918 FILE *pFile =fopen(fileNameContourROI.c_str(),"r+");
919 //CMRU 03-09-09- ----------------------------------------------------------------------------------------------
922 //------------------------------------------------------------------------------------------------------------
923 fileNameContourROI.append("data");
924 FILE *pFileData=fopen(fileNameContourROI.c_str(),"r+");
925 if(pFileData != NULL)
927 fscanf(pFileData,"%s",tmpD); // --CreaContour--
928 fscanf(pFileData,"%s",tmpD); // Version
929 fscanf(pFileData,"%s",tmpD); // 1.0.3 || 1.0.2 || 1.0.1 || 1.0.0
931 fscanf(pFileData,"%s",tmpD); // onePixelSize
932 fscanf(pFileData,"%s",tmpD); // #
933 _onePixelSize = atof(tmpD);
934 fscanf(pFileData,"%s",tmpD); // NumberOfContours
935 fscanf(pFileData,"%s",tmpD); // #
937 fscanf(pFile,"%s",tmp); // --CreaContour--
938 fscanf(pFile,"%s",tmp); // Version
939 fscanf(pFile,"%s",tmp); // 1.0.3 || 1.0.2 || 1.0.1 || 1.0.0
940 std::string version(tmp);
942 _tmpReadFileTypeOfTransformation=-1;
943 if (version=="1.0.3")
945 readDimSpc(pFile,interactiveInterface); // DimSpc interactive ON
946 openContours(pFile,pFileData,false);
947 openContours(pFile,pFileData,true); //Load StaticContours
949 if (version=="1.0.2")
952 readDimSpc(pFile,interactiveInterface); // DimSpc interactive ON
953 openContours(pFile,pFileData,false);
954 readDimSpc(pFile,false); // DimSpc interactive OFF
955 openContours(pFile,pFileData,true); // Load StaticContours
956 SetZForAllContours(-900);
959 else if (version=="1.0.1")
961 openContours(pFile,pFileData,false); //Skips ImageDimensions and ImageSpacing
962 openContours(pFile,pFileData,true); //Load StaticContours, skips ImageDimensions and ImageSpacing
966 else if (version=="1.0.0")
968 openContours(pFile,pFileData,false); //Skips ImageDimensions and ImageSpacing
973 if(pFileData != NULL)
978 _theViewPanel->getSceneManager()->removeSceneContours();
983 void wxContourMainFrame::onImport()
985 std::string filename, filenamecontours;
986 //EED 2017-09-16 Migration wxWidgets 2.8 to 3.0
987 #if wxMAJOR_VERSION <= 2
988 wxFileDialog dialog(NULL, _T("Choose a XML Osirix File"), _T(""), _T(""), _T("*.xml"), wxOPEN );
990 wxFileDialog dialog(NULL, _T("Choose a XML Osirix File"), _T(""), _T(""), _T("*.xml"), wxFD_OPEN );
992 if (dialog.ShowModal() == wxID_OK)
994 filename = dialog.GetPath().mb_str();
995 filenamecontours = kernelManager->parseOsirixFile(filename);
997 if(filenamecontours.compare("") != 0){
998 onLoadContours(filenamecontours,true);
1003 void wxContourMainFrame::onTest()
1005 std::string filename, filenamecontours;
1006 //EED 2017-09-16 Migration wxWidgets 2.8 to 3.0
1007 #if wxMAJOR_VERSION <= 2
1008 wxFileDialog dialog(NULL, _T("Choose a File"), _T(""), _T(""), _T("*.*"), wxOPEN );
1010 wxFileDialog dialog(NULL, _T("Choose a File"), _T(""), _T(""), _T("*.*"), wxFD_OPEN );
1013 if (dialog.ShowModal() == wxID_OK)
1015 filename = dialog.GetPath().mb_str();
1016 std::cout << "This is the filename: " << filename << std::endl;
1022 void wxContourMainFrame::onSave(){
1023 //CMRU 03-09-09-----------------------------------------------------------------------------------------------
1024 if(GetFileLocation().empty())
1026 //------------------------------------------------------------------------------------------------------------
1027 //EED 2017-09-16 Migration wxWidgets 2.8 to 3.0
1028 #if wxMAJOR_VERSION <= 2
1029 wxFileDialog dialog(NULL, _T("Choose a file"), _T(""), _T(""), _T("*.roi"), wxSAVE );
1031 wxFileDialog dialog(NULL, _T("Choose a file"), _T(""), _T(""), _T("*.roi"), wxFD_SAVE );
1033 if (dialog.ShowModal() == wxID_OK)
1035 std::string fileNameContourROI = (const char *)(dialog.GetPath().mb_str());
1036 kernelManager->setCurrentFileName(fileNameContourROI);
1037 saveFileWithContours( fileNameContourROI );
1040 //CMRU 03-09-09-----------------------------------------------------------------------------------------------
1043 std::cout<<"Nombre del archivo: "<<GetFileLocation()<<std::endl;
1044 std::string fileNameContourROI = GetFileLocation();
1045 std::cout<<"Nombre del archivo: "<<fileNameContourROI<<std::endl;
1046 kernelManager->setCurrentFileName(fileNameContourROI);
1047 saveFileWithContours( fileNameContourROI);
1049 //------------------------------------------------------------------------------------------------------------
1053 void wxContourMainFrame::saveFileWithContours( std::string filename )
1056 FILE *pFile=fopen(filename.c_str(),"w+");
1058 //CMRU 03-09-09-----------------------------------------------------------------------------------------------
1059 filename.append("data");
1060 std::cout<<"Nombre del archivo: "<<filename<<std::endl;
1061 FILE *pFileData=fopen(filename.c_str(),"w+");
1062 //------------------------------------------------------------------------------------------------------------
1064 std::vector< std::string > lstNameThings;
1065 int i,sizeLstNameThings;
1067 fprintf(pFile,"--CreaContour--\n");
1068 fprintf(pFile,"Version %s\n", "1.0.3" );
1070 //CMRU 03-09-09-----------------------------------------------------------------------------------------------
1071 fprintf(pFileData,"--CreaContour--\n");
1072 fprintf(pFileData,"Version %s\n", "1.0.3" );
1073 fprintf(pFileData,"OnePixelSize %f\n", _onePixelSize);
1075 //------------------------------------------------------------------------------------------------------------
1077 vtkImageData *image = _images[0];
1080 image->GetDimensions(dimRange);
1082 fprintf(pFile,"ImageDimensions %d %d %d\n", dimRange[0], dimRange[1], dimRange[2] );
1085 image->GetSpacing(spaRange);
1087 fprintf(pFile,"ImageSpacing %f %f %f\n", spaRange[0], spaRange[1], spaRange[2] );
1091 lstNameThings = kernelManager->GetLstNameThings();
1092 sizeLstNameThings = lstNameThings.size();
1093 fprintf(pFile,"NumberOfContours %d\n", sizeLstNameThings );
1095 //CMRU 03-09-09-----------------------------------------------------------------------------------------------
1096 fprintf(pFileData,"NumberOfContours %d\n", sizeLstNameThings );
1097 //------------------------------------------------------------------------------------------------------------
1106 for (i=0 ; i<sizeLstNameThings ; i++)
1108 //CMRU 03-09-09-----------------------------------------------------------------------------------------------
1109 manualBaseModel * manualModel = kernelManager->getOutlineByKeyName(lstNameThings[i]);
1112 // double sizeInPixel = manualModel ->GetPathSize( );
1113 double sizeInPixel = manualModel ->GetPathSize( spc );
1115 double realContourSize = sizeInPixel*_onePixelSize;
1116 manualModel ->SetRealSize(realContourSize);
1117 //------------------------------------------------------------------------------------------------------------
1119 //int size= kernelManager->GetLstNameThings().size();
1121 kernelManager->SaveThingName( pFile, pFileData, lstNameThings[i] );
1122 _theViewPanel->getSceneManager()->SaveThingName( pFile, lstNameThings[i] );
1125 //-- Static Contours
1127 // fprintf(pFile,"ImageDimensions %d %d %d\n", dimRange[0], dimRange[1], dimRange[2] );
1128 // fprintf(pFile,"ImageSpacing %f %f %f\n", spaRange[0], spaRange[1], spaRange[2] );
1130 lstNameThings = kernelManager->GetLstNameThingsStatic();
1131 sizeLstNameThings = lstNameThings.size();
1132 fprintf(pFile,"NumberOfContoursStatic %d\n", sizeLstNameThings );
1134 //CMRU 03-09-09-----------------------------------------------------------------------------------------------
1135 fprintf(pFileData,"NumberOfContoursStatic %d\n", sizeLstNameThings );
1136 //------------------------------------------------------------------------------------------------------------
1138 for (i=0 ; i<sizeLstNameThings ; i++)
1140 kernelManager->SaveThingName( pFile, pFileData, lstNameThings[i] );
1141 _theViewPanel->getSceneManager()->SaveThingName( pFile, lstNameThings[i] );
1149 void wxContourMainFrame::readDimSpc(FILE *pFile, bool interactiveOption)
1153 double imageSpac[3];
1154 vtkImageData *image = _images[0];
1155 image->GetDimensions(imageDim);
1156 image->GetSpacing(imageSpac);
1158 fscanf(pFile,"%s",tmp); // ImageDimensions
1159 fscanf(pFile,"%s",tmp); // X
1160 _tmpReadFileImageDim[0] = atoi(tmp);
1161 fscanf(pFile,"%s",tmp); // Y
1162 _tmpReadFileImageDim[1] = atoi(tmp);
1163 fscanf(pFile,"%s",tmp); // Z
1164 _tmpReadFileImageDim[2] = atoi(tmp);
1166 fscanf(pFile,"%s",tmp); // ImageSpacing
1167 fscanf(pFile,"%s",tmp); // X
1168 _tmpReadFileImageSpac[0] = atof(tmp);
1169 fscanf(pFile,"%s",tmp); // Y
1170 _tmpReadFileImageSpac[1] = atof(tmp);
1171 fscanf(pFile,"%s",tmp); // Z
1172 _tmpReadFileImageSpac[2] = atof(tmp);
1175 if (interactiveOption==true)
1177 //Compare Spacing and Dims in X and Y (Necessary in Z?) - Just for Version 2
1178 if (imageDim[0]!=_tmpReadFileImageDim[0] || imageDim[1]!=_tmpReadFileImageDim[1] || imageSpac[0]!=_tmpReadFileImageSpac[0] || imageSpac[1]!=_tmpReadFileImageSpac[1])
1180 wxDialog* dial = new wxDialog (this,-1,_T("Tools"),wxDefaultPosition, wxSize(460,360));
1181 wxSizer* buttonsSizer = dial->CreateSeparatedButtonSizer(wxOK|wxCANCEL);
1182 wxBoxSizer *dialSizer = new wxBoxSizer(wxVERTICAL);
1184 wxString lstOptOperation[2];
1185 lstOptOperation[0]=_T("By Dimension");
1186 lstOptOperation[1]=_T("By Spacing");
1187 wxRadioBox * radioOpts = new wxRadioBox(dial, -1, _T("Type of Transformation"), wxDefaultPosition, wxSize(270,45), 2 , lstOptOperation, 2, wxRA_SPECIFY_COLS);
1189 dialSizer->Add( new wxStaticText(dial,-1,_T("The image resolution is not compatible with the ")) , 0, wxGROW );
1190 dialSizer->Add( new wxStaticText(dial,-1,_T("selected Roi file. Do you want to tranform it?")) , 0, wxGROW );
1191 dialSizer->Add( new wxStaticText(dial,-1,_T(" ")) , 0, wxGROW );
1192 dialSizer->Add(radioOpts,0,wxGROW);
1193 dialSizer->Add( new wxStaticText(dial,-1,_T(" ")) , 0, wxGROW );
1194 dialSizer->Add(buttonsSizer,0,wxGROW);
1195 dial->SetSizer(dialSizer, true);
1199 int _tmpReadFileTypeOfTransformation = -1;
1200 //EED bool transform = false;
1202 if (dial->GetReturnCode() == wxID_OK)
1204 _tmpReadFileTypeOfTransformation = radioOpts->GetSelection();
1208 } // if interactiveOption
1215 void wxContourMainFrame::openContours( FILE *pFile, FILE *pFileData, bool staticContour )
1220 vtkImageData *image = _images[0];
1223 double imageSpac[3];
1224 image->GetDimensions(imageDim);
1225 image->GetSpacing(imageSpac);
1228 fscanf(pFile,"%s",tmp); // NumberOfContours
1229 fscanf(pFile,"%s",tmp); // ##
1230 int numberOfContours = atoi(tmp);
1232 std::vector<int> instantVector;
1233 int typeContourModel;
1234 manualBaseModel *manModelContour;
1238 if (compatible==true)
1241 for (i=0;i<numberOfContours;i++)
1243 instantVector.clear();
1244 fscanf(pFile,"%s",tmp); // Instant
1246 fscanf(pFile,"%s",tmp); // 1
1247 instantVector.push_back( atoi(tmp) );
1248 fscanf(pFile,"%s",tmp); // 2
1249 instantVector.push_back( atoi(tmp) );
1250 fscanf(pFile,"%s",tmp); // 3
1251 instantVector.push_back( atoi(tmp) );
1252 fscanf(pFile,"%s",tmp); // 4
1253 instantVector.push_back( atoi(tmp) );
1254 fscanf(pFile,"%s",tmp); // 5
1255 instantVector.push_back( atoi(tmp) );
1256 fscanf(pFile,"%s",tmp); // 6
1257 instantVector.push_back( atoi(tmp) );
1260 fscanf(pFile,"%s",tmp); // TypeContourModel
1261 fscanf(pFile,"%s",tmp); // ##
1262 typeContourModel = atoi(tmp);
1264 manModelContour = kernelManager->factoryManualContourModel(typeContourModel);
1265 manModelContour->Open(pFile);
1266 if(pFileData != NULL)
1268 manModelContour->OpenData(pFileData);
1271 fscanf(pFile,"%s",tmp); // TypeView
1272 fscanf(pFile,"%s",tmp); // ##
1273 typeView = atoi(tmp);
1275 std::string theName;
1276 theName = kernelManager->createOutline( manModelContour, instantVector );
1277 bool addedModel = theName.compare("") != 0;
1280 double spc[3];//Si no hay imagen pero hay contornos que spacing se pone por default
1281 _theViewPanel->getSpacing(spc);
1282 //Adding the manualContourControler to interface objects structure
1283 //Adding the manualViewContour to interface objects structure
1284 //_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.
1285 _theViewPanel->getSceneManager()->configureViewControlTo( theName, manModelContour,spc , typeView) ;
1288 if (staticContour) //StaticContours (will appear in all slices)
1290 Instant instant(&instantVector);
1291 kernelManager->changeContourOfManager( theName , &instant );
1294 }// for numberOfContours
1297 else if (compatible==false)
1302 for (i=0;i<numberOfContours;i++)
1304 instantVector.clear();
1305 fscanf(pFile,"%s",tmp); // Instant
1307 fscanf(pFile,"%s",tmp); // 1
1308 instantVector.push_back( atoi(tmp) );
1309 fscanf(pFile,"%s",tmp); // 2
1310 instantVector.push_back( atoi(tmp) );
1311 fscanf(pFile,"%s",tmp); // 3
1312 instantVector.push_back( atoi(tmp) );
1313 fscanf(pFile,"%s",tmp); // 4
1314 instantVector.push_back( atoi(tmp) );
1315 fscanf(pFile,"%s",tmp); // 5
1316 instantVector.push_back( atoi(tmp) );
1317 fscanf(pFile,"%s",tmp); // 6
1318 instantVector.push_back( atoi(tmp) );
1320 fscanf(pFile,"%s",tmp); // TypeContourModel
1321 fscanf(pFile,"%s",tmp); // ##
1322 typeContourModel = atoi(tmp);
1324 manModelContour = kernelManager->factoryManualContourModel(typeContourModel);
1325 manModelContour->Open(pFile);
1326 if(pFileData != NULL)
1328 manModelContour->OpenData(pFileData);
1331 if (_tmpReadFileTypeOfTransformation==-1){
1333 } else if (_tmpReadFileTypeOfTransformation==0){
1334 double transX, transY;
1335 transX = (double) imageDim[0]/_tmpReadFileImageDim[0];
1336 transY = (double) imageDim[1]/_tmpReadFileImageDim[1];
1337 manModelContour->Transform_Ax_Plus_B(transX,0,transY,0);
1338 } else if (_tmpReadFileTypeOfTransformation==1) {
1339 double transX, transY;
1340 transX = (double) _tmpReadFileImageSpac[0]/imageDim[0];
1341 transY = (double) _tmpReadFileImageSpac[1]/imageDim[1];
1342 manModelContour->Transform_Ax_Plus_B(transX,0,transY,0);
1345 fscanf(pFile,"%s",tmp); // TypeView
1346 fscanf(pFile,"%s",tmp); // ##
1347 typeView = atoi(tmp);
1349 std::string theName;
1350 theName = kernelManager->createOutline( manModelContour, instantVector );
1351 bool addedModel = theName.compare("") != 0;
1354 double spc[3];//Si no hay imagen pero hay contornos que spacing se pone por default
1355 _theViewPanel->getSpacing(spc);
1356 //Adding the manualContourControler to interface objects structure
1357 //Adding the manualViewContour to interface objects structure
1358 //_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.
1359 _theViewPanel->getSceneManager()->configureViewControlTo( theName, manModelContour,spc , typeView) ;
1362 if (staticContour) //StaticContours (will appear in all slices)
1364 Instant instant(&instantVector);
1365 kernelManager->changeContourOfManager( theName , &instant );
1367 }// for numberOfContours
1373 void wxContourMainFrame::RefreshInterface()
1376 _theViewPanel->RefreshInterface();
1377 //wxVtk2DBaseView *wxvtk2dbaseview = (wxVtk2DBaseView*)this->_theViewPanel->getWxVtkBaseView();
1378 //wxvtk2dbaseview->Refresh();
1381 vtkImageData* wxContourMainFrame::getImageData()
1383 return _theViewPanel->getImageData();
1386 void wxContourMainFrame::onSegmentationOneSliceITK(wxString distance, wxString sigma, wxString alfa, wxString beta, wxString propagation, wxString iterations, wxString inflation)
1388 //JCP 20-10-08 Undo redo implementation
1390 //JCP 20-10-08 Undo redo implementation
1393 int x = _theViewPanel->GetX();
1394 int y = _theViewPanel->GetY();
1395 int z = _theViewPanel->GetZ();
1396 SegmentationOneSliceITK( x,y,z,distance, sigma, alfa, beta, propagation, iterations, inflation);
1400 void wxContourMainFrame::SegmentationOneSliceITK(int x, int y, int z, wxString distanc, wxString sigm, wxString alf, wxString bet, wxString prop, wxString iter, wxString inflation)
1402 int typeofcontour = 1;
1404 vtkImageData *imagedata = getImageData();
1406 //Tipo de pixeles a utilizar internamente en ITK
1407 typedef float InternalPixelType;
1408 const unsigned int Dimension = 2;
1409 typedef itk::Image< InternalPixelType, Dimension > InternalImageType;
1411 //Tipo de pixeles de salida 1
1412 typedef unsigned char OutputPixelType;
1413 typedef itk::Image< OutputPixelType, Dimension > OutputImageType;
1415 //Tipo de pixeles de salida 2
1416 typedef unsigned short OutputPixelType2;
1417 typedef itk::Image< OutputPixelType2, Dimension > OutputImageType2;
1419 //DefiniciÛn del thresholder
1420 typedef itk::BinaryThresholdImageFilter<
1422 OutputImageType > ThresholdingFilterType;
1424 //DefiniciÛn del primer filtro de conversiÛn de pixeles
1425 typedef itk::CastImageFilter<
1426 OutputImageType, OutputImageType2 > CastFilterType;
1428 //DefiniciÛn del segundo tipo de conversiÛn de pixeles
1429 typedef itk::CastImageFilter<
1430 OutputImageType2, InternalImageType > CastFilterType2;
1432 //Tercer tipo de conversiÛn
1433 typedef itk::RescaleIntensityImageFilter<
1435 OutputImageType > CastFilterType3;
1437 //Cuarto tipo de conversiÛn
1438 typedef itk::RescaleIntensityImageFilter<
1440 OutputImageType > CastFilterType4;
1442 ThresholdingFilterType::Pointer thresholder = ThresholdingFilterType::New();
1444 thresholder->SetLowerThreshold( 0.0 );
1445 thresholder->SetUpperThreshold( 128 );
1447 thresholder->SetOutsideValue( 255 );
1448 thresholder->SetInsideValue( 0 );
1450 //DefinciÛn de conexiÛnes entre VTK e ITK y el writer
1451 typedef itk::VTKImageToImageFilter<OutputImageType2> ConnectorType;
1452 typedef itk::ImageToVTKImageFilter<OutputImageType> ConnectorType2;
1453 //EED10JUIN2011 typedef itk::ImageFileWriter< OutputImageType > WriterType;
1455 ConnectorType::Pointer connector= ConnectorType::New();
1456 ConnectorType2::Pointer connector2= ConnectorType2::New();
1459 CastFilterType::Pointer filter=CastFilterType::New();
1460 CastFilterType2::Pointer filter2=CastFilterType2::New();
1462 connector->SetInput( imagedata );
1463 filter2->SetInput(connector->GetOutput());
1465 typedef itk::CurvatureAnisotropicDiffusionImageFilter<
1467 InternalImageType > SmoothingFilterType;
1469 SmoothingFilterType::Pointer smoothing = SmoothingFilterType::New();
1471 typedef itk::GradientMagnitudeRecursiveGaussianImageFilter<
1473 InternalImageType > GradientFilterType;
1475 typedef itk::SigmoidImageFilter<
1477 InternalImageType > SigmoidFilterType;
1479 GradientFilterType::Pointer gradientMagnitude = GradientFilterType::New();
1481 SigmoidFilterType::Pointer sigmoid = SigmoidFilterType::New();
1483 sigmoid->SetOutputMinimum( 0.0 );
1484 sigmoid->SetOutputMaximum( 255.0 );
1487 typedef itk::FastMarchingImageFilter<
1489 InternalImageType > FastMarchingFilterType;
1492 FastMarchingFilterType::Pointer fastMarching = FastMarchingFilterType::New();
1494 printf("EED wxContourMainFrame::SegmentationOneSliceITK Skypping this code. Not compiling GeodesicActiveContourLevelSetImageFilter in fedora 17 with ITK 3.20.1 \n ");
1496 > - > - > - > - > - > - > - > - > - > - > - > - > - > - > - > - Not compiling GeodesicActiveContourLevelSetImageFilter in fedora 17 with ITK 3.20.1
1499 typedef itk::GeodesicActiveContourLevelSetImageFilter< InternalImageType,
1500 InternalImageType > GeodesicActiveContourFilterType;
1501 GeodesicActiveContourFilterType::Pointer geodesicActiveContour =
1502 GeodesicActiveContourFilterType::New();
1504 typedef itk::ZeroCrossingImageFilter<
1506 InternalImageType > ZeroCrossingFilterType;
1507 ZeroCrossingFilterType::Pointer zeroCrossing =
1508 ZeroCrossingFilterType::New();
1510 const double propagationScaling = atof( crea::wx2std(prop).c_str() );
1512 geodesicActiveContour->SetPropagationScaling( propagationScaling );
1513 geodesicActiveContour->SetCurvatureScaling( 1.0 );
1514 geodesicActiveContour->SetAdvectionScaling( 1.0 );
1516 geodesicActiveContour->SetMaximumRMSError( 0.02 );
1517 int it=atoi( crea::wx2std(iter).c_str() );
1518 geodesicActiveContour->SetNumberOfIterations( it );
1520 smoothing->SetInput( filter2->GetOutput() );
1521 gradientMagnitude->SetInput( smoothing->GetOutput() );
1522 sigmoid->SetInput( gradientMagnitude->GetOutput() );
1523 fastMarching->SetInput( sigmoid->GetOutput() );
1524 geodesicActiveContour->SetInput( fastMarching->GetOutput() );
1525 geodesicActiveContour->SetFeatureImage( sigmoid->GetOutput() );
1527 zeroCrossing->SetInput( geodesicActiveContour->GetOutput() );
1528 //thresholder->SetInput( zeroCrossing->GetOutput() );
1529 thresholder->SetInput( geodesicActiveContour->GetOutput() );
1530 connector2->SetInput( thresholder->GetOutput() );
1532 < - < - < - < - < - < - < - < - < - < - < - < - < - < - < - < - < - < - < - < -
1538 smoothing->SetTimeStep( 0.125 );
1539 smoothing->SetNumberOfIterations( 5 );
1540 smoothing->SetConductanceParameter( 9.0 );
1543 const double sigma = atof( crea::wx2std(sigm).c_str() );
1544 gradientMagnitude->SetSigma( sigma );
1546 const double alpha = atof( crea::wx2std(alf).c_str() );
1547 const double beta = atof( crea::wx2std(bet).c_str() );
1549 sigmoid->SetAlpha( alpha );
1550 sigmoid->SetBeta( beta );
1552 typedef FastMarchingFilterType::NodeContainer NodeContainer;
1553 typedef FastMarchingFilterType::NodeType NodeType;
1555 NodeContainer::Pointer seeds = NodeContainer::New();
1557 InternalImageType::IndexType seedPosition;
1558 seedPosition[0] = x;
1559 seedPosition[1] = y;
1561 const double initialDistance = atof( crea::wx2std(distanc).c_str() );
1565 const double seedValue = - initialDistance;
1567 node.SetValue( seedValue );
1568 node.SetIndex( seedPosition );
1570 seeds->Initialize();
1571 seeds->InsertElement( 0, node );
1573 fastMarching->SetTrialPoints( seeds );
1575 fastMarching->SetSpeedConstant( 1.0 );
1577 fastMarching->SetOutputSize(
1578 connector->GetOutput()->GetBufferedRegion().GetSize() );
1580 fastMarching->SetStoppingValue( 800 );
1584 connector2->Update();
1585 vtkImageData *idata = connector2->GetOutput();
1587 vtkMarchingContourFilter* cntVTK = vtkMarchingContourFilter::New( );
1589 cntVTK->SetNumberOfContours( 1 );
1590 cntVTK->SetValue( 0, 255 );
1591 //EED 2017-01-01 Migration VTK7
1592 #if VTK_MAJOR_VERSION <= 5
1593 cntVTK->SetInput( idata );
1595 cntVTK->UpdateInformation();
1597 cntVTK->SetInputData( idata );
1600 vtkCleanPolyData* cpd = vtkCleanPolyData::New( );
1602 //EED 2017-01-01 Migration VTK7
1603 #if VTK_MAJOR_VERSION <= 5
1604 cpd->SetInput( cntVTK->GetOutput( ) );
1606 cpd->UpdateInformation();
1608 cpd->SetInputData( cntVTK->GetOutput( ) );
1612 vtkPolyDataConnectivityFilter* conn = vtkPolyDataConnectivityFilter::New( );
1613 conn->SetExtractionModeToLargestRegion( );
1614 //EED 2017-01-01 Migration VTK7
1615 #if VTK_MAJOR_VERSION <= 5
1616 conn->SetInput( cpd->GetOutput( ) );
1618 conn->UpdateInformation();
1620 conn->SetInputData( cpd->GetOutput( ) );
1624 vtkStripper* vtkstripper = vtkStripper::New( );
1626 //EED 2017-01-01 Migration VTK7
1627 #if VTK_MAJOR_VERSION <= 5
1628 vtkstripper->SetInput( conn->GetOutput() );
1629 vtkstripper->Update();
1630 vtkstripper->UpdateInformation();
1632 vtkstripper->SetInputData( conn->GetOutput() );
1636 vtkPolyData* polyDataResult = cntVTK->GetOutput();
1637 //std::cout<<"Points "<<polyDataResult->GetNumberOfPoints()<<std::endl;
1639 //EED 2017-01-01 Migration VTK7
1640 #if VTK_MAJOR_VERSION <= 5
1641 polyDataResult->Update( );
1642 polyDataResult->UpdateInformation();
1650 myfile.open ("C:/Creatis/example.txt");
1652 polyDataResult->Print(myfile);
1653 myfile << "-------------------------------------\n";
1654 polyDataResult->GetLines()->Print(myfile);
1662 //--Calculating control points
1664 std::vector<double> vecX;
1665 std::vector<double> vecY;
1666 std::vector<double> vecXo;
1667 std::vector<double> vecYo;
1668 std::vector<double>::iterator vecXoi;
1669 std::vector<double>::iterator vecYoi;
1670 std::vector<double> vecZ;
1672 std::vector<double> vecCtrlPointX;
1673 std::vector<double> vecCtrlPointY;
1674 std::vector<double> vecCtrlPointZ;
1680 int ii,size=polyDataResult->GetNumberOfPoints();
1682 myfile.open ("C:/Creatis/example2.txt");
1684 size=polyDataResult->GetNumberOfPoints();
1685 for (ii=0;ii<size;ii++)
1692 p = polyDataResult->GetPoint(ii);
1695 /*if(fabs(yAct-y)>20)
1697 if((xAct-x)>1 || (xAct-x)<-1)
1699 vecX.push_back( p[0] );
1700 vecY.push_back( p[1] );
1701 myfile <<p[0]<<","<<p[1]<<"\n";
1702 std::cout<<" x Anterior "<<xAct<<" x actual "<<x<<std::endl;
1703 std::cout<<" y Anterior "<<yAct<<" y actual "<<y<<std::endl;
1704 std::cout<<" x "<<p[0]<<" y "<<p[1]<<std::endl;
1705 vecZ.push_back( 900 );
1711 vecXo.push_back(p[0]);
1712 vecYo.push_back(p[1]);
1716 else*/ if(fabs(xAct-x)>11)
1718 vecXo.push_back(p[0]);
1719 vecYo.push_back(p[1]);
1721 vecX.push_back( p[0] );
1722 myfile <<p[0]<<","<<p[1]<<"\n";
1723 //std::cout<<" x Anterior "<<xAct<<" x actual "<<x<<std::endl;
1724 //std::cout<<" y Anterior "<<yAct<<" y actual "<<y<<std::endl;
1725 //std::cout<<" x "<<p[0]<<" y "<<p[1]<<std::endl;
1726 vecY.push_back( p[1] );
1728 vecZ.push_back( -900 );
1736 while(!vecXo.empty())
1738 vecX.push_back(vecXo.back());
1739 //std::cout<<" x Siguiente "<<vecXo.back();
1742 vecZ.push_back( -900 );
1744 while(!vecYo.empty())
1746 vecY.push_back(vecYo.back());
1751 /*for(int l=0;l<vecX.size();l++)
1755 vecXo.push_back(p[0]);
1756 vecYo.push_back(p[1]);
1767 ExtractControlPoints2D *extractcontrolpoints2d = new ExtractControlPoints2D();
1769 extractcontrolpoints2d->SetContour( &vecX , &vecY , &vecZ );
1773 extractcontrolpoints2d->GetInitialControlPoints( &vecCtrlPointX , &vecCtrlPointY , &vecCtrlPointZ );
1775 else if (method==1){
1776 extractcontrolpoints2d->GetControlPoints( &vecCtrlPointX , &vecCtrlPointY , &vecCtrlPointZ );
1778 else if (method==2){
1779 extractcontrolpoints2d->SetSamplingControlPoints( 15 );
1780 extractcontrolpoints2d->GetSamplingControlPoints( &vecCtrlPointX , &vecCtrlPointY , &vecCtrlPointZ );
1782 //--Adding contour to the system
1784 std::vector<int> actualInstantVector;
1785 _instantPanel->getInstant( actualInstantVector );
1786 actualInstantVector[1]=z;
1788 int j,sizeCtrPt = vecCtrlPointX.size();
1790 manualBaseModel *manModelContour = kernelManager->factoryManualContourModel( typeofcontour );
1791 manModelContour->SetNumberOfPointsSpline( ((sizeCtrPt/100)+1)*100 );
1793 for (j=0 ; j<sizeCtrPt ; j++)
1795 manModelContour->AddPoint( vecCtrlPointX[j] , vecCtrlPointY[j] , vecCtrlPointZ[j] );
1797 std::string theName;
1798 //theName = _modelManager->createOutline( manModelContour, actualInstantVector );
1799 theName = kernelManager->createOutline( manModelContour, actualInstantVector );
1800 bool addedModel = theName.compare("") != 0;
1803 double spc[3];//Si no hay imagen pero hay contornos que spacing se pone por default
1804 _theViewPanel->getSpacing(spc);
1805 //Adding the manualContourControler to interface objects structure
1806 //Adding the manualViewContour to interface objects structure
1807 //_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.
1808 _theViewPanel->configureViewControlTo(theName, manModelContour, spc, typeofcontour);
1809 //_theViewPanel->getSceneManager()->configureViewControlTo( theName, manModelContour,spc, typeofcontour ) ;
1816 WriterType::Pointer writer = WriterType::New();
1817 CastFilterType3::Pointer caster = CastFilterType3::New();
1819 caster->SetInput( gradientMagnitude->GetOutput() );
1820 writer->SetInput( caster->GetOutput() );
1821 writer->SetFileName("Gradient Magnitude.png");
1822 caster->SetOutputMinimum( 0 );
1823 caster->SetOutputMaximum( 255 );
1826 CastFilterType3::Pointer caster2 = CastFilterType3::New();
1827 WriterType::Pointer writer2 = WriterType::New();
1829 caster2->SetInput( sigmoid->GetOutput() );
1830 writer2->SetInput( caster2->GetOutput() );
1831 writer2->SetFileName("Sigmoid.png");
1832 caster2->SetOutputMinimum( 0 );
1833 caster2->SetOutputMaximum( 255 );
1836 CastFilterType3::Pointer caster3 = CastFilterType3::New();
1837 WriterType::Pointer writer3 = WriterType::New();
1839 caster3->SetInput( fastMarching->GetOutput() );
1840 writer3->SetInput( caster3->GetOutput() );
1841 writer3->SetFileName("FastMarching.bmp");
1842 caster3->SetOutputMinimum( 0 );
1843 caster3->SetOutputMaximum( 255 );
1846 CastFilterType3::Pointer caster4 = CastFilterType3::New();
1847 WriterType::Pointer writer4 = WriterType::New();
1849 caster4->SetInput( geodesicActiveContour->GetOutput() );
1850 writer4->SetInput( caster4->GetOutput() );
1851 writer4->SetFileName("GeodesicActiveContour.png");
1852 caster4->SetOutputMinimum( 0 );
1853 caster4->SetOutputMaximum( 255 );
1856 CastFilterType3::Pointer caster5 = CastFilterType3::New();
1857 WriterType::Pointer writer5 = WriterType::New();
1859 caster5->SetInput( zeroCrossing->GetOutput() );
1860 writer5->SetInput( caster5->GetOutput() );
1861 writer5->SetFileName("ZeroCrossing.bmp");
1862 caster5->SetOutputMinimum( 0 );
1863 caster5->SetOutputMaximum( 255 );
1867 catch( itk::ExceptionObject & excep )
1869 std::cerr << "Exception caught !" << std::endl;
1870 std::cerr << excep << std::endl;
1874 void wxContourMainFrame::onSegmentationOneSlice(int isovalue,int sampling,int method){
1876 //JCP 20-10-08 Undo redo implementation
1878 //JCP 20-10-08 Undo redo implementation
1881 int x = _theViewPanel->GetX();
1882 int y = _theViewPanel->GetY();
1883 int z = _theViewPanel->GetZ();
1884 SegmentationOneSlice( x,y,z,isovalue, sampling, method );
1889 void wxContourMainFrame::SegmentationOneSlice( int x, int y, int z, int isovalue, int sampling, int method )
1891 printf("EED wxContourMainFrame::SegmentationOneSlice Start\n");
1892 int typeofcontour = 1;
1893 //--Extracting Contour
1894 //vtkImageData *imagedata = _theViewPanel->getSceneManager()->GetImageData();
1895 vtkImageData *imagedata = getImageData();
1896 // double *range = imagedata->GetScalarRange();
1899 vtkImageReslice *imageReslice = vtkImageReslice::New();
1902 // imagedata->GetSpacing(spc);
1907 //EED 2017-01-01 Migration VTK7
1908 #if VTK_MAJOR_VERSION <= 5
1909 imageReslice->SetInput( imagedata );
1911 imageReslice->SetInputData( imagedata );
1913 imageReslice->SetInformationInput(imagedata);
1914 imageReslice->SetResliceAxesDirectionCosines(1,0,0, 0,1,0 ,0,0,1);
1915 imageReslice->SetResliceAxesOrigin(0,0,z);
1916 imageReslice->SetOutputDimensionality(2);
1917 imageReslice->SetInterpolationModeToLinear();
1919 //EED 2017-01-01 Migration VTK7
1920 #if VTK_MAJOR_VERSION <= 5
1923 imageReslice->Update();
1926 imagedata = imageReslice->GetOutput();
1927 //EED 2017-01-01 Migration VTK7
1928 #if VTK_MAJOR_VERSION <= 5
1929 imagedata->Update();
1930 imagedata->UpdateInformation();
1935 vtkContourFilter* cntVTK = vtkContourFilter::New( );
1936 //EED 2017-01-01 Migration VTK7
1937 #if VTK_MAJOR_VERSION <= 5
1938 cntVTK->SetInput( imagedata );
1940 cntVTK->SetInputData( imagedata );
1943 cntVTK->SetNumberOfContours( 1 );
1944 //cntVTK->SetValue( 0, vmin );
1945 // cntVTK->SetValue( 0, (range[1]*thr/100) );
1946 cntVTK->SetValue( 1, isovalue );
1947 // cntVTK->SetValue( 1, vmax );
1949 cntVTK->UpdateInformation();
1951 vtkCleanPolyData* cpd = vtkCleanPolyData::New( );
1952 //EED 2017-01-01 Migration VTK7
1953 #if VTK_MAJOR_VERSION <= 5
1954 cpd->SetInput( cntVTK->GetOutput( ) );
1956 cpd->SetInputData( cntVTK->GetOutput( ) );
1958 cpd->ConvertLinesToPointsOff( );
1960 cpd->UpdateInformation();
1962 vtkPolyDataConnectivityFilter* conn = vtkPolyDataConnectivityFilter::New( );
1963 conn->SetExtractionModeToClosestPointRegion( );
1964 //conn->SetMaxRecursionDepth( 3000 );
1966 //EED 2017-01-01 Migration VTK7
1967 #if VTK_MAJOR_VERSION <= 5
1968 conn->SetInput( cpd->GetOutput( ) );
1970 conn->SetInputData( cpd->GetOutput( ) );
1973 conn->SetClosestPoint( x, y, 0 );
1975 conn->UpdateInformation();
1977 vtkCleanPolyData* cpd2 = vtkCleanPolyData::New( );
1978 //EED 2017-01-01 Migration VTK7
1979 #if VTK_MAJOR_VERSION <= 5
1980 cpd2->SetInput( conn->GetOutput( ) );
1982 cpd2->SetInputData( conn->GetOutput( ) );
1985 cpd2->UpdateInformation();
1987 vtkStripper* vtkstripper = vtkStripper::New( );
1988 vtkstripper->SetMaximumLength(20000);
1989 //EED 2017-01-01 Migration VTK7
1990 #if VTK_MAJOR_VERSION <= 5
1991 vtkstripper->SetInput( cpd2->GetOutput() );
1993 vtkstripper->SetInputData( cpd2->GetOutput() );
1995 vtkstripper->Update();
1996 vtkstripper->UpdateInformation();
1999 vtkPolyData* polyDataResult = vtkstripper->GetOutput();
2001 //EED 2017-01-01 Migration VTK7
2002 #if VTK_MAJOR_VERSION <= 5
2003 polyDataResult->Update( );
2004 polyDataResult->UpdateInformation();
2011 myfile.open ("c:/temp/example.txt");
2013 polyDataResult->Print(myfile);
2014 myfile << "-------------------------------------\n";
2015 polyDataResult->GetLines()->Print(myfile);
2025 //--Calculating control points
2027 std::vector<double> vecX;
2028 std::vector<double> vecY;
2029 std::vector<double> vecZ;
2031 std::vector<double> vecCtrlPointX;
2032 std::vector<double> vecCtrlPointY;
2033 std::vector<double> vecCtrlPointZ;
2036 printf("EED wxContourMainFrame::SegmentationOneSlice GetNumberOfLines=%d \n",polyDataResult->GetNumberOfLines() );
2038 int numberOfPointsInCell;
2039 int numberOfcells=polyDataResult->GetNumberOfCells();
2040 for (int jj=0; jj<numberOfcells ; jj++)
2042 vtkCell* vtkcell = polyDataResult->GetCell( jj );
2043 numberOfPointsInCell=vtkcell->GetNumberOfPoints();
2044 printf("EED wxContourMainFrame::SegmentationOneSlice cell=%d points=%d \n",jj,numberOfPointsInCell );
2047 printf("EED wxContourMainFrame::SegmentationOneSlice PrintSelf \n");
2049 polyDataResult->PrintSelf( std::cout, vtkIndent(0) );
2054 int ii,size=polyDataResult->GetNumberOfPoints();
2056 for (ii=1;ii<=size;ii++)
2058 id = polyDataResult->GetLines()->GetData()->GetValue(ii);
2059 p = polyDataResult->GetPoint(id);
2060 printf("EED wxContourMainFrame::SegmentationOneSlice (%d) id=%d px=%f py=%f\n",ii,id, p[0],p[1]);
2063 vecX.push_back( p[0] );
2064 vecY.push_back( p[1] );
2066 vecZ.push_back( -900 );
2067 // vecZ.push_back( p[2] );
2071 ExtractControlPoints2D *extractcontrolpoints2d = new ExtractControlPoints2D();
2072 extractcontrolpoints2d->SetContour( &vecX , &vecY , &vecZ );
2075 /*if (methodRadiobox->GetSelection()==0){
2076 extractcontrolpoints2d->GetInitialControlPoints( &vecCtrlPointX , &vecCtrlPointY , &vecCtrlPointZ );
2078 if (methodRadiobox->GetSelection()==1){
2079 extractcontrolpoints2d->GetControlPoints( &vecCtrlPointX , &vecCtrlPointY , &vecCtrlPointZ );
2081 if (methodRadiobox->GetSelection()==2){
2082 extractcontrolpoints2d->SetSamplingControlPoints( sampling );
2083 extractcontrolpoints2d->GetSamplingControlPoints( &vecCtrlPointX , &vecCtrlPointY , &vecCtrlPointZ );
2088 extractcontrolpoints2d->GetInitialControlPoints( &vecCtrlPointX , &vecCtrlPointY , &vecCtrlPointZ );
2089 } else if (method==1){
2090 extractcontrolpoints2d->GetControlPoints( &vecCtrlPointX , &vecCtrlPointY , &vecCtrlPointZ );
2091 } else if (method==2){
2092 extractcontrolpoints2d->SetSamplingControlPoints( sampling );
2093 extractcontrolpoints2d->GetSamplingControlPoints( &vecCtrlPointX , &vecCtrlPointY , &vecCtrlPointZ );
2096 //--Adding contour to the system
2097 std::vector<int> actualInstantVector;
2098 _instantPanel->getInstant( actualInstantVector );
2099 actualInstantVector[1]=z;
2101 int j,sizeCtrPt = vecCtrlPointX.size();
2102 manualBaseModel *manModelContour = kernelManager->factoryManualContourModel( typeofcontour );
2103 printf("EED wxContourMainFrame::SegmentationOneSlice sizeCtrPt=%d %d %d\n" , sizeCtrPt
2104 , ((sizeCtrPt/100)+1)*100 *2
2105 , manModelContour->GetNumberOfPointsSpline()
2107 manModelContour->SetNumberOfPointsSpline( ((sizeCtrPt/100)+1)*100 *2 );
2110 for (j=0 ; j<sizeCtrPt ; j++)
2112 manModelContour->AddPoint( vecCtrlPointX[j] , vecCtrlPointY[j] , vecCtrlPointZ[j] );
2114 std::string theName;
2115 //theName = _modelManager->createOutline( manModelContour, actualInstantVector );
2116 theName = kernelManager->createOutline( manModelContour, actualInstantVector );
2117 bool addedModel = theName.compare("") != 0;
2120 double spc[3];//Si no hay imagen pero hay contornos que spacing se pone por default
2121 _theViewPanel->getSpacing(spc);
2122 //Adding the manualContourControler to interface objects structure
2123 //Adding the manualViewContour to interface objects structure
2124 //_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.
2125 _theViewPanel->configureViewControlTo(theName, manModelContour, spc, typeofcontour);
2126 //_theViewPanel->getSceneManager()->configureViewControlTo( theName, manModelContour,spc, typeofcontour ) ;
2129 printf("EED wxContourMainFrame::SegmentationOneSlice End\n");
2132 int wxContourMainFrame::GetImageDataSizeZ()
2134 return _theViewPanel->GetImageDataSizeZ();
2137 void wxContourMainFrame::GetImageDataRange(double *range)
2139 _theViewPanel->GetImageDataRange(range);
2142 void wxContourMainFrame::onSegmentationAllSlice(int minZ,int maxZ,int isovalue,int sampling,int method)
2144 //JCP 20-10-08 Undo redo implementation
2146 //JCP 20-10-08 Undo redo implementation
2149 int x = _theViewPanel->GetX();
2150 int y = _theViewPanel->GetY();
2154 double totalZ = maxZ-minZ+1;
2155 for( z=minZ ; z<=maxZ ; z++ )
2157 porcent = 100.0* (z-minZ)/totalZ;
2158 tmpString.Printf(_T(" %d %c %d/%d %d"), (int)porcent , 37 , z-minZ+1, (int)totalZ,z );
2159 interfMainPanel::getInstance()->setLabelSegmentationPanelVTK(tmpString);
2160 //_staticTextSegmentation->SetLabel(tmpString);
2161 SegmentationOneSlice( x,y,z,isovalue, sampling,method );
2163 interfMainPanel::getInstance()->setLabelSegmentationPanelVTK(_T(" "));
2168 //Creates a reference line to be used as the axis of the mirroring
2169 void wxContourMainFrame::referenceLine()
2171 if (_refLineControl==NULL)
2176 vtkImageData *vtkimagedata = _theViewPanel->getImageData();
2177 vtkimagedata->GetSpacing(spc);
2179 wxVtkBaseView * viewer2D = _theViewPanel->getWxVtkBaseView();
2181 _refLineControl = new manualLineControler();
2182 _refLineModel = new manualContourModelLine();
2183 _refLineView = new manualViewLine();
2184 _refLineView->SetModel( _refLineModel );
2185 _refLineView->SetWxVtkBaseView( viewer2D );
2186 _refLineView->SetRange( 2 );
2187 _refLineView->SetZ( 1200 );
2189 _refLineView->SetSpacing(spc);
2191 _refLineView->SetColorNormalContour(0, 0, 1);
2192 _refLineView->SetColorEditContour(0, 0.5, 0.5);
2193 _refLineView->SetWidthLine(4);
2195 _refLineControl->SetModelView( _refLineModel , _refLineView );
2196 vtkInteractorStyleBaseView* style = (vtkInteractorStyleBaseView*)viewer2D->GetInteractorStyleBaseView();
2197 style->AddInteractorStyleMaracas( _refLineControl );
2198 _refLineModel->SetCloseContour(false);
2199 _refLineControl->CreateNewManualContour();
2201 //AD: Inicializar el mirroring con una linea ya pintada
2203 double z = _refLineControl->GetZ();
2206 image->GetDimensions(imageDim);
2207 double x = (double) imageDim[0]/2;
2208 double y1 = (double) (imageDim[1]/2)+15;
2209 double y2 = (double) (imageDim[1]/2)-15;
2211 _refLineControl->AddPoint(x,y1,z);
2212 _refLineControl->AddPoint(x,y2,z);
2213 _refLineControl->SetCompleteCreation(true);
2215 _refLineModel->AddPoint(x,y1,z);
2216 _refLineModel->AddPoint(x,y2,z);
2217 _refLineModel->UpdateSpline();
2219 _refLineView->UpdateViewPoint(0);
2220 _refLineView->UpdateViewPoint(1);
2223 _refLineControl->SetActive(true);
2224 _refLineView->RefreshContour();
2228 //Hides the referenceLine
2229 void wxContourMainFrame::refLineHide()
2231 if (_refLineControl!=NULL)
2233 if (_refLineControl->GetActive())
2235 _refLineView->RemoveCompleteContourActor();
2236 _refLineControl->SetEditable(false);
2237 _refLineControl->SetActive(false);
2244 //Shows the referenceLine
2245 void wxContourMainFrame::refLineShow()
2247 if (_refLineControl!=NULL)
2249 if (_refLineControl->GetActive()==false)
2251 wxVtkBaseView * viewer2D = _theViewPanel->getWxVtkBaseView();
2253 _refLineView->SetModel( _refLineModel );
2254 _refLineView->SetWxVtkBaseView( viewer2D );
2255 _refLineView->SetRange( 2 );
2256 _refLineView->SetZ( 1200 );
2258 _refLineControl->SetModelView( _refLineModel , _refLineView );
2259 vtkInteractorStyleBaseView* style = (vtkInteractorStyleBaseView*)viewer2D->GetInteractorStyleBaseView();
2260 style->AddInteractorStyleMaracas( _refLineControl );
2261 _refLineControl->CreateNewManualContour();
2262 _refLineControl->SetActive(true);
2263 _refLineView->RefreshContour();
2270 void wxContourMainFrame::refLineChangeWidth(int width)
2272 _refLineView->SetWidthLine(width);
2273 _refLineView->RefreshContour();
2279 void wxContourMainFrame::onMirror()
2282 std::vector<std::string> currentSelection = _theViewPanel->getSelectedObjects();
2283 std::vector<std::string> filterCurrentSelection;
2285 std::vector<int> tempVector;
2286 _instantPanel->getInstant( tempVector );
2287 _performingOperation->reset();
2288 _performingOperation->setStartCommand( COPY );
2289 _performingOperation->setStartOperationInstantVector( tempVector );
2290 _performingOperation->setKeyNamesOperationElems( currentSelection );
2292 char theStartCommand = _performingOperation->getStartCommand();
2293 if ( theStartCommand == COPY )
2295 //JCP 20-10-08 Undo redo implementation
2297 //JCP 20-10-08 Undo redo implementation
2298 std::vector<int> tempVector;
2299 _instantPanel->getInstant( tempVector );
2300 _performingOperation->setEndOperationInstantVector ( tempVector );
2301 std::vector<std::string> elems = _performingOperation->getKeyNamesOperationElems();
2302 int i,size = elems.size();
2303 for( i=0; i<size; i++ )
2305 createMirrorContourOf( elems[i], tempVector, i>0 );
2309 //deleteContour( _refName );
2314 void wxContourMainFrame::showAxis(bool show)
2316 _theViewPanel->SetVisibleAxis(show);
2317 _theViewPanel->Refresh();
2321 void wxContourMainFrame::onRigidPressed(){
2322 std::vector<std::string> currentSelection = _theViewPanel->getSelectedObjects();
2323 int elementsSelected = currentSelection.size();
2325 if ( elementsSelected >= 1 ){
2326 //JCP 20-10-08 Undo redo implementation
2328 //JCP 20-10-08 Undo redo implementation
2330 std::vector<int> tempVector;
2331 _instantPanel->getInstant( tempVector );
2332 Instant instant(&tempVector);
2334 int i , size=currentSelection.size();
2335 for ( i=0 ; i<size ; i++ )
2337 kernelManager->changeContourOfManager(currentSelection[i], &instant);
2342 void wxContourMainFrame::onWidthOfContour(double width){
2344 _theViewPanel->removeSceneContours();
2345 _theViewPanel->SetWidthContour(width);
2347 //_theViewPanel->getSceneManager()->SetWidthContour( width );
2352 int wxContourMainFrame::getColorWindow()
2356 vtkImageData * img = getImageData();
2357 img->GetScalarRange(range);
2359 std::cout<<"Val 1: "<<range[0]<<" Val 2: "<<range[1]<<std::endl;
2361 return (int)range[1];
2363 return _theViewPanel->getColorWindow();
2366 int wxContourMainFrame::getWindowLevel()
2370 vtkImageData * img = getImageData();
2371 img->GetScalarRange(range);
2373 std::cout<<"Val 1: "<<range[0]<<" Val 2: "<<range[1]<<std::endl;
2375 return (int)range[1];
2377 return _theViewPanel->getWindowLevel();
2380 void wxContourMainFrame::onBrigthnessColorWindowLevel(int colorwindow,int windowlevel)
2382 _theViewPanel->onBrigthnessColorWindowLevel(colorwindow, windowlevel);
2387 void wxContourMainFrame::onInterpolation(bool interpolate)
2389 _theViewPanel->onInterpolation(interpolate);
2393 void wxContourMainFrame::onChangeInstant(std::string name,int actual)
2395 _instantPanel->setConceptValue( name, actual );
2399 void wxContourMainFrame::resetAppend()
2401 kernelManager->resetAppend();
2405 void wxContourMainFrame::onSpreadAdd()
2407 std::vector<double> vecX;
2408 std::vector<double> vecY;
2409 std::vector<double> vecZ;
2410 _theViewPanel->GetPointsOfActualContour(&vecX , &vecY , &vecZ );
2411 std::vector<int> tempVector;
2412 _instantPanel->getInstant( tempVector );
2413 std::string val = kernelManager->onSpreadAdd(&vecX , &vecY , &vecZ, tempVector);
2414 interfMainPanel::getInstance()->appendStringSpread(val);
2418 void wxContourMainFrame::onSpreadAddAll()
2421 std::vector<int> tempVector;
2422 _instantPanel->getInstant( tempVector );
2425 maxZ = interfMainPanel::getInstance()->GetImageDataSizeZ();
2427 int sizeLstContourThings;
2428 for ( z=minZ ; z<=maxZ ; z++ )
2431 Instant instant(&tempVector);
2432 std::vector<ContourThing**> lstContourThings = kernelManager->getOutlinesAtInstant( &instant );
2433 sizeLstContourThings = lstContourThings.size();
2434 if (sizeLstContourThings>=1)
2436 std::vector<double> vecX;
2437 std::vector<double> vecY;
2438 std::vector<double> vecZ;
2439 ContourThing **contourthing = lstContourThings[0];
2440 manualBaseModel *cModel = (*contourthing)->getModel();
2441 int i,size = cModel->GetNumberOfPointsSpline();
2443 for (i=0; i<size; i++)
2445 cModel->GetSpline_i_Point(i, &x, &y, &z);
2450 std::string val = kernelManager->onSpreadAdd(&vecX , &vecY , &vecZ, tempVector);
2451 interfMainPanel::getInstance()->appendStringSpread(val);
2452 }// if sizeLstContourThings
2457 void wxContourMainFrame::onSpreadGo(int type)
2459 //JCP 20-10-08 Undo redo implementation
2461 //JCP 20-10-08 Undo redo implementation
2463 std::vector<double> vecCtrlPointX;
2464 std::vector<double> vecCtrlPointY;
2465 std::vector<double> vecCtrlPointZ;
2469 std::vector<int> tempVector;
2470 _instantPanel->getInstant( tempVector );
2473 kernelManager->getMaxMinZ(&minZ,&maxZ);
2474 //JSTG_16-07-08_----------------------------------------------------------------
2475 //_contourPropagation->setInterpolationNumber(maxZ-minZ+1);
2476 kernelManager->CalculeSplinePropagation();
2478 double totalZ = maxZ-minZ+1;
2481 //--------------------------------------------------------------------
2482 for ( z=(int)minZ ; z<=(int)maxZ ; z++ )
2484 porcent = 100.0* (z-minZ)/totalZ;
2485 int numero = (int)(z-minZ+1)/(int)totalZ;
2486 std::string stringtemp = " "+kernelManager->intToString(porcent)+"% "+kernelManager->intToString(numero)+" "+kernelManager->intToString(z);
2488 interfMainPanel::getInstance()->setStringSpread(stringtemp);
2490 int typeofcontour = 1;
2491 std::string theName;
2492 manualBaseModel* manModelContour = kernelManager->GetPoints(z, type, &vecCtrlPointX,&vecCtrlPointY,&vecCtrlPointZ, theName,typeofcontour, tempVector);
2494 if( manModelContour!=NULL ){
2495 double spc[3];//Si no hay imagen pero hay contornos que spacing se pone por default
2496 this->_theViewPanel->getSpacing(spc);
2497 //Adding the manualContourControler to interface objects structure
2498 //Adding the manualViewContour to interface objects structure
2499 //_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.
2500 _theViewPanel->configureViewControlTo( theName, manModelContour,spc,typeofcontour ) ;
2505 int numero = (int)(z-minZ+1)/(int)totalZ;
2506 std::string stringtemp = " "+kernelManager->intToString(porcent)+"% "+kernelManager->intToString(numero)+" "+kernelManager->intToString(z);
2508 interfMainPanel::getInstance()->setStringSpread(stringtemp);
2510 //RefreshInterface();
2513 void wxContourMainFrame::getInstantVector(std::vector<int>& tempVector)
2517 std::vector<std::string> wxContourMainFrame::getOutlinesName(int slide)
2519 std::vector<int> tempVector;
2520 _instantPanel->getInstant(tempVector);
2521 //Asignation of slide number should be different ex by name
2522 tempVector[1]=slide;
2523 return kernelManager->getOutlinesNameAtInstant(tempVector);
2527 void wxContourMainFrame::SetScalarRange(int grayRangeMin, int grayRangeMax)
2529 _contourextractdata->SetScalarRange(grayRangeMin,grayRangeMax);
2533 void wxContourMainFrame::onInformationContourLabels(int typeContourGroup,int selection,int minimumZ,int maximumZ,int grayRangeMin, int grayRangeMax)
2536 wxString tempString;
2537 int maxContourGroup = 0;
2539 _contourextractdata ->SetTypeOperation( typeContourGroup % 3 );
2541 std::vector<manualBaseModel*> lstManConMod;
2542 std::vector<manualBaseModel*> lstManConModTmp;
2543 std::vector<manualBaseModel*> lstManConModExp;
2544 std::vector<double> pLstValue;
2545 std::vector<double> pLstValuePosX;
2546 std::vector<double> pLstValuePosY;
2547 std::vector<double> pLstValuePosZ;
2550 int resultGrayRangeCount;
2553 double resultAverage;
2554 double resultStandardeviation;
2556 std::vector<int> tempVector;
2557 _instantPanel->getInstant( tempVector );
2560 int ii,sizeLstContourThings;
2569 if (selection==0 ) // actual slice
2571 int actualSlice = tempVector[1];
2574 } else { // slice range
2580 totalZ = maxZ-minZ+1;
2582 _contourextractdata->InitVolumeStatistics();
2585 for ( z=minZ ; z<=maxZ ; z++ )
2588 porcent = 100.0* (z-minZ)/totalZ;
2589 tmpString.Printf(_T(" %d %c %d/%d %d"), (int)porcent , 37 , z-minZ+1, (int)totalZ ,z);
2591 interfMainPanel::getInstance()->setStringInfoPanel(tmpString);
2592 //_staticTextInformation->SetLabel(tmpString);
2594 //Extraction data from contours of each slice
2595 _contourextractdata->SetZtoBeAnalys(z);
2598 Instant instant(&tempVector);
2599 std::vector<ContourThing**> lstContourThings = kernelManager->getOutlinesAtInstant( &instant );
2600 sizeLstContourThings = lstContourThings.size();
2602 lstManConMod.clear();
2603 for (ii=0 ; ii<sizeLstContourThings ; ii++)
2605 ContourThing **contourthing = lstContourThings[ii];
2606 lstManConMod.push_back( (*contourthing)->getModel() );
2609 lstManConModExp = kernelManager->ExploseEachModel( lstManConMod );
2611 tempString.Printf(_T("%d - %d"),z, sizeLstContourThings);
2612 interfMainPanel::getInstance()->setRowLabelInfoPanel(z, tempString);
2613 //_grid->SetRowLabelValue(z, tempString );
2615 int iContourGroup,sizeContourGroup;
2616 if (typeContourGroup==3) // contour separete
2618 sizeContourGroup=lstManConModExp.size();
2619 if ( maxContourGroup<sizeContourGroup )
2621 maxContourGroup=sizeContourGroup;
2623 } else { // contour AND OR XOR
2630 for( iContourGroup=0 ; iContourGroup<sizeContourGroup ; iContourGroup++ ){
2631 lstManConModTmp.clear();
2635 if (typeContourGroup==3) // contour separete
2637 lstManConModTmp.push_back( lstManConModExp[iContourGroup]);
2638 } else { // contour AND OR XOR
2639 lstManConModTmp = lstManConModExp;
2642 _contourextractdata->SetLstManualContourModel( lstManConModTmp );
2643 _contourextractdata->SetScalarRange(grayRangeMin,grayRangeMax);
2646 pLstValuePosX.clear();
2647 pLstValuePosY.clear();
2648 pLstValuePosZ.clear();
2652 _contourextractdata->GetValuesInsideCrown( &numberOfPixels,
2658 resultSize=numberOfPixels;
2659 // Statistics of each slice.
2660 _contourextractdata->Statistics( &pLstValue,
2663 &resultGrayRangeCount,
2668 &resultStandardeviation);
2670 if (interfMainPanel::getInstance()->getNumberColsInformationPanel()<_numberOfVariablesStatistics*(iContourGroup+1) )
2672 interfMainPanel::getInstance()->appendColsInformationPanel(_numberOfVariablesStatistics);
2675 tmpIntA=_numberOfVariablesStatistics*iContourGroup ;
2677 tempString.Printf(_T("%d"),numberOfPixels);
2679 interfMainPanel::getInstance()->setCellValueInfoPanel(z, tmpIntA, tempString);
2681 tempString.Printf(_T("%d"),resultGrayRangeCount);
2682 interfMainPanel::getInstance()->setCellValueInfoPanel(z, tmpIntA+1, tempString);
2684 tempString.Printf(_T("%f"),resultMin);
2685 interfMainPanel::getInstance()->setCellValueInfoPanel(z, tmpIntA+2, tempString);
2687 tempString.Printf(_T("%f"),resultMax);
2688 interfMainPanel::getInstance()->setCellValueInfoPanel(z, tmpIntA+3, tempString);
2690 tempString.Printf(_T("%f"),resultAverage);
2691 interfMainPanel::getInstance()->setCellValueInfoPanel(z, tmpIntA+4, tempString);
2693 tempString.Printf(_T("%f"),resultStandardeviation);
2694 interfMainPanel::getInstance()->setCellValueInfoPanel(z, tmpIntA+5, tempString);
2697 } // for iContourGroup
2700 // Print Volume Statistics
2703 int vol_rCountRange;
2705 double vol_minValue;
2706 double vol_maxValue;
2708 double vol_standardeviation;
2710 if (selection!=0 ) // actual slice
2713 _contourextractdata->GetVolumeStatistics(&vol_rCountRange, &vol_rsize,
2714 &vol_minValue, &vol_maxValue,
2715 &vol_average, &vol_standardeviation);
2717 interfMainPanel::getInstance()->setRowLabelInfoPanel(maxZ+2, _T("Total:"));
2719 tempString.Printf(_T("%d"),vol_rsize);
2720 interfMainPanel::getInstance()->setCellValueInfoPanel(maxZ+2, 0, tempString);
2722 tempString.Printf(_T("%d"),vol_rCountRange);
2723 interfMainPanel::getInstance()->setCellValueInfoPanel(maxZ+2, 1, tempString);
2725 tempString.Printf(_T("%f"),vol_minValue);
2726 interfMainPanel::getInstance()->setCellValueInfoPanel(maxZ+2, 2, tempString);
2728 tempString.Printf(_T("%f"),vol_maxValue);
2729 interfMainPanel::getInstance()->setCellValueInfoPanel(maxZ+2, 3, tempString);
2731 tempString.Printf(_T("%f"),vol_average);
2732 interfMainPanel::getInstance()->setCellValueInfoPanel(maxZ+2, 4, tempString);
2734 tempString.Printf(_T("%f"),vol_standardeviation);
2735 interfMainPanel::getInstance()->setCellValueInfoPanel(maxZ+2, 5, tempString);
2737 //-----------------------------------------
2740 wxString tmpTitleString;
2742 for ( iTitleGroup=0 ; iTitleGroup<maxContourGroup ; iTitleGroup++ )
2744 tmpIntB =_numberOfVariablesStatistics*iTitleGroup;
2745 tmpTitleString.Printf(_T("%d-Size Data"),iTitleGroup);
2746 interfMainPanel::getInstance()->setColLableInfoPanel(tmpIntB + 0, tmpTitleString);
2748 interfMainPanel::getInstance()->setColLableInfoPanel(tmpIntB + 0, tmpTitleString );
2749 interfMainPanel::getInstance()->setColLableInfoPanel( tmpIntB + 1, _T("Size Range") );
2750 interfMainPanel::getInstance()->setColLableInfoPanel( tmpIntB + 2, _T("Min") );
2751 interfMainPanel::getInstance()->setColLableInfoPanel( tmpIntB + 3, _T("Max") );
2752 interfMainPanel::getInstance()->setColLableInfoPanel( tmpIntB + 4, _T("Average") );
2753 interfMainPanel::getInstance()->setColLableInfoPanel( tmpIntB + 5, _T("St.Dev.") );
2754 interfMainPanel::getInstance()->setColLableInfoPanel( tmpIntB + 6, _T(" ") );
2756 interfMainPanel::getInstance()->setStringInfoPanel( _T("") );
2760 void wxContourMainFrame::onSaveResults(std::string directory,std::string namefile, std::string filename,
2761 int typeContourGroup, int selection, int minZ, int maxZ, bool XYZValues, bool contourImage, bool statistics)
2765 SaveValuesXYZ( directory , namefile, typeContourGroup );
2770 vtkImageData * mask;
2771 vtkImageData * value;
2772 this->getMaskValue(&mask, &value, typeContourGroup,selection,minZ,maxZ);
2773 this->SaveImageResult( directory , namefile, mask, value);
2778 std::ostringstream name;
2779 name << filename << ".xls";
2782 FILE *pFile=fopen(name.str().c_str(),"w+");
2788 // int sizeZ = _theViewPanel->GetImageDataSizeZ();
2789 // int maxY=sizeZ+2;
2791 maxX= interfMainPanel::getInstance()->getNumberColsInformationPanel();//this->_grid->GetNumberCols();
2794 int iTitle,sizeTitle = (maxX / _numberOfVariablesStatistics);
2795 for ( iTitle=0; iTitle<sizeTitle ; iTitle++)
2797 // fprintf(pFile,"-- \t %d-Size \t SizeRange \t Min \t Max \t Ave \t StDv \t" , iTitle,tmpString.c_str() );
2798 fprintf(pFile,"slice\t %d-Size \t SizeRange \t Min \t Max \t Ave \t StDv \t" , iTitle );
2800 fprintf(pFile,"\n\n" );
2804 if (selection==0 ) // actual slice
2806 std::vector<int> tempVector;
2807 _instantPanel->getInstant( tempVector );
2808 int actualSlice = tempVector[1];
2814 for ( j=minZ; j<=maxZ ; j++)
2816 fprintf(pFile,"%d\t" , j );
2817 for (i=0 ; i<maxX ; i++){
2818 tmpString = interfMainPanel::getInstance()->getCellValue(j, i);//_grid->GetCellValue( j , i );
2819 fprintf(pFile,"%s\t" , (const char *)(tmpString.mb_str()) );
2821 fprintf(pFile,"\n" );
2825 // Total of stadistics.....
2828 fprintf(pFile,"\n Total:\t" );
2829 for (i=0 ; i<maxX ; i++){
2830 tmpString = interfMainPanel::getInstance()->getCellValue(maxZ+2, i);//_grid->GetCellValue( maxZ+2 , i );
2831 fprintf(pFile,"%s\t" , (const char *)(tmpString.mb_str()) );
2833 fprintf(pFile,"\n" );
2841 void wxContourMainFrame::SaveValuesXYZ(std::string directory,std::string namefile,int typeContourGroup)
2845 //int typeContourGroup = this->_radiolstboxContourGroup->GetSelection();
2846 _contourextractdata ->SetTypeOperation( typeContourGroup % 3 );
2848 std::vector<manualBaseModel*> lstManConMod;
2849 std::vector<manualBaseModel*> lstManConModTmp;
2850 std::vector<manualBaseModel*> lstManConModExp;
2851 std::vector<double> pLstValue;
2852 std::vector<double> pLstValuePosX;
2853 std::vector<double> pLstValuePosY;
2854 std::vector<double> pLstValuePosZ;
2856 std::vector<int> tempVector;
2857 _instantPanel->getInstant( tempVector );
2859 int sizeZ = _theViewPanel->getSceneManager()->GetImageDataSizeZ();
2861 int ii,sizeLstContourThings;
2868 minZ = 0;// _mbarrange->GetStart();
2869 maxZ = sizeZ;//_mbarrange->GetEnd();
2870 totalZ = maxZ-minZ+1;
2874 for ( z=0 ; z<sizeZ ; z++)
2877 porcent = 100.0* (z-minZ)/totalZ;
2879 tmpString.Printf(_T("Saving Values"));
2880 tmpString.Printf(_T(" %d %c %d/%d %d"), (int)porcent , 37 , z-minZ+1, (int)totalZ ,z);
2881 interfMainPanel::getInstance()->setStringInfoPanel(tmpString);
2882 //_staticTextInformation->SetLabel(tmpString);
2885 //Extraction data from contours of each slice
2886 _contourextractdata->SetZtoBeAnalys( z);
2889 Instant instant(&tempVector);
2890 std::vector<ContourThing**> lstContourThings = kernelManager->getOutlinesAtInstant(&instant);//this->_modelManager->getOutlinesAtInstant( &instant );
2891 sizeLstContourThings = lstContourThings.size();
2893 lstManConMod.clear();
2894 for (ii=0 ; ii<sizeLstContourThings ; ii++)
2896 ContourThing **contourthing = lstContourThings[ii];
2897 lstManConMod.push_back( (*contourthing)->getModel() );
2899 lstManConModExp = kernelManager->ExploseEachModel( lstManConMod );
2904 int iContourGroup,sizeContourGroup;
2905 if (typeContourGroup==3) // contour separete
2907 sizeContourGroup=lstManConModExp.size();
2908 } else { // contour AND OR XOR
2912 for( iContourGroup=0 ; iContourGroup<sizeContourGroup ; iContourGroup++ ){
2913 lstManConModTmp.clear();
2914 if (typeContourGroup==3) // contour separete
2916 lstManConModTmp.push_back( lstManConModExp[iContourGroup]);
2917 } else { // contour AND OR XOR
2918 lstManConModTmp = lstManConModExp;
2921 _contourextractdata->SetLstManualContourModel( lstManConModTmp );
2924 pLstValuePosX.clear();
2925 pLstValuePosY.clear();
2926 pLstValuePosZ.clear();
2928 _contourextractdata->GetValuesInsideCrown( &numberOfPixels,
2934 std::string temp = directory + "/" + namefile + "-slice";
2935 temp = temp + kernelManager->intToString(z) + "-cont" + kernelManager->intToString(iContourGroup);
2936 temp = temp + ".txt";
2938 // LG 14/01/09 : using crea
2939 wxString filename = crea::std2wx(temp);
2940 /*filename.Printf(_T("%s"),directory.c_str());
2941 filename.append(_T("\\"));
2942 filename.append(_T("%s"),namefile.c_str());
2943 filename.append(_T("-slice"));
2944 filename.append(_T("%d"),z);
2945 filename.append(_T("-cont"));
2946 filename.append(_T("%d"),iContourGroup);
2947 filename.append(_T(".txt"));*/
2948 // filename.Printf(temp.c_str());
2952 FILE *pFile=fopen((const char *)filename.mb_str(),"w+");
2953 fprintf(pFile,"value \t x \t y \t z\n" );
2954 int iLstValue,sizeLstValue=pLstValue.size();
2955 for (iLstValue=0 ; iLstValue<sizeLstValue ; iLstValue++ )
2957 fprintf(pFile,"%f\t %f\t %f\t %f\n", (float)pLstValue[iLstValue] , (float)pLstValuePosX[iLstValue], (float)pLstValuePosY[iLstValue], (float)z );
2960 } // for iContourGroup
2962 interfMainPanel::getInstance()->setStringInfoPanel(_T(""));
2963 //_staticTextInformation->SetLabel( _T("") );
2967 void wxContourMainFrame::getMaskValue(vtkImageData ** mask,vtkImageData ** value,int typeContourGroup, int selection, int minZ, int maxZ){
2970 //int typeContourGroup = this->_radiolstboxContourGroup->GetSelection();
2971 if (typeContourGroup==3)
2975 _contourextractdata ->SetTypeOperation( typeContourGroup % 3 );
2977 std::vector<manualBaseModel*> lstManConMod;
2978 std::vector<manualBaseModel*> lstManConModTmp;
2979 std::vector<manualBaseModel*> lstManConModExp;
2981 std::vector<int> tempVector;
2982 _instantPanel->getInstant( tempVector );
2984 vtkImageData *imagedata = _theViewPanel->getImageData();
2986 imagedata->GetExtent(ext);
2987 int sizeZimage = ext[5]-ext[4]+1;
2989 int ii,sizeLstContourThings;
2997 if (selection==0 ) // actual slice
2999 int actualSlice = tempVector[1];
3007 // cleanning image before range
3008 for (z=0; z<minZ; z++){
3009 _contourextractdata->ResetImageResult(z);
3011 // cleanning image after range
3012 for (z=maxZ+1; z<sizeZimage; z++){
3013 _contourextractdata->ResetImageResult(z);
3018 for ( z=minZ ; z<=maxZ ; z++)
3021 porcent = 100.0* (z-minZ)/totalZ;
3022 tmpString.Printf(_T("Saving Values"));
3023 tmpString.Printf(_T("%d %c %d/%d %d"), (int)porcent , 37 , z-minZ+1, (int)totalZ ,z);
3024 interfMainPanel::getInstance()->setStringInfoPanel(tmpString);
3026 //Extraction data from contours of each slice
3027 _contourextractdata->SetZtoBeAnalys( z);
3030 Instant instant(&tempVector);
3031 std::vector<ContourThing**> lstContourThings = kernelManager->getOutlinesAtInstant( &instant );
3032 sizeLstContourThings = lstContourThings.size();
3034 lstManConMod.clear();
3035 for (ii=0 ; ii<sizeLstContourThings ; ii++)
3037 ContourThing **contourthing = lstContourThings[ii];
3038 lstManConMod.push_back( (*contourthing)->getModel() );
3040 lstManConModExp = kernelManager->ExploseEachModel( lstManConMod );
3043 int iContourGroup,sizeContourGroup;
3044 if (typeContourGroup==3) // contour separete
3046 sizeContourGroup=lstManConModExp.size();
3047 } else { // contour AND OR XOR
3051 for( iContourGroup=0 ; iContourGroup<sizeContourGroup ; iContourGroup++ ){
3052 lstManConModTmp.clear();
3053 if (typeContourGroup==3) // contour separete
3055 lstManConModTmp.push_back( lstManConModExp[iContourGroup]);
3056 } else { // contour AND OR XOR
3057 lstManConModTmp = lstManConModExp;
3060 _contourextractdata->SetLstManualContourModel( lstManConModTmp );
3061 _contourextractdata->CalculateImageResult(); // with actual Z
3063 } // for iContourGroup
3066 (*value) = _contourextractdata->GetVtkImageValueResult();
3067 (*mask) = _contourextractdata->GetVtkImageMaskResult();
3071 std::string wxContourMainFrame::GetStringTypeImage( vtkImageData* image)
3073 std::string result="";
3074 if ( image->GetScalarType()==VTK_CHAR )
3077 } else if ( image->GetScalarType()==VTK_UNSIGNED_CHAR ){
3079 } else if ( image->GetScalarType()==VTK_FLOAT ){
3081 } else if ( image->GetScalarType()==VTK_DOUBLE ){
3083 } else if ( image->GetScalarType()==VTK_INT ){
3085 } else if ( image->GetScalarType()==VTK_UNSIGNED_INT ){
3087 } else if ( image->GetScalarType()==VTK_SHORT ){
3089 } else if ( image->GetScalarType()==VTK_UNSIGNED_SHORT ){
3091 } else if ( image->GetScalarType()==VTK_LONG ){
3093 } else if ( image->GetScalarType()==VTK_UNSIGNED_LONG ){
3099 void wxContourMainFrame::SaveImageResult(std::string directory,std::string namefile, vtkImageData* mask,vtkImageData* value)
3101 std::string stringType;
3103 kernelManager->GetSpacing(spc,0); // returns the spacing of the first image
3104 stringType = GetStringTypeImage(value);
3105 std::string temp = directory + "/" + namefile + "-image-Value-"+stringType+".mhd";
3107 wxString filename = crea::std2wx(temp);
3111 vtkImageChangeInformation *valueChInfo = vtkImageChangeInformation::New();
3112 //EED 2017-01-01 Migration VTK7
3113 #if VTK_MAJOR_VERSION <= 5
3114 valueChInfo->SetInput(value);
3116 valueChInfo->SetInputData(value);
3118 valueChInfo->SetSpacingScale(spc);
3119 vtkMetaImageWriter *writerValueImage = vtkMetaImageWriter::New( );
3121 //EED 2017-01-01 Migration VTK7
3122 #if VTK_MAJOR_VERSION <= 5
3123 writerValueImage->SetInput( valueChInfo->GetOutput() );
3125 writerValueImage->SetInputData( valueChInfo->GetOutput() );
3127 writerValueImage->SetFileName( (const char *)filename.mb_str() );
3128 writerValueImage->SetFileDimensionality( 3 );
3129 writerValueImage->SetCompression(false);
3130 writerValueImage->Write( );
3133 stringType = GetStringTypeImage(mask);
3134 temp = directory + "/" + namefile + "-image-Mask-"+stringType+".mhd";
3136 // LG 14/01/09 : using crea
3137 filename = crea::std2wx(temp);
3138 // filename.Printf(_T(temp.c_str()));
3141 vtkImageChangeInformation *maskChInfo = vtkImageChangeInformation::New();
3142 //EED 2017-01-01 Migration VTK7
3143 #if VTK_MAJOR_VERSION <= 5
3144 maskChInfo->SetInput(mask);
3146 maskChInfo->SetInputData(mask);
3148 maskChInfo->SetSpacingScale(spc);
3149 vtkMetaImageWriter *writerMaskImage = vtkMetaImageWriter::New( );
3151 //EED 2017-01-01 Migration VTK7
3152 #if VTK_MAJOR_VERSION <= 5
3153 writerMaskImage->SetInput( maskChInfo->GetOutput() );
3155 writerMaskImage->SetInputData( maskChInfo->GetOutput() );
3158 writerMaskImage->SetFileName( (const char *)filename.mb_str() );
3159 writerMaskImage->SetFileDimensionality( 3 );
3160 writerMaskImage->SetCompression(false);
3161 writerMaskImage->Write( );
3163 interfMainPanel::getInstance()->setStringInfoPanel( _T("") );
3169 void wxContourMainFrame::onChangeInstantInstantPanel(std::string name,int value, int minshow, int maxshow){
3170 if( name.compare( _theViewPanel->getVerticalConceptName() ) == 0){
3171 _theViewPanel->setActualVertical( value);
3173 else if( name.compare( _theViewPanel->getHorizontalConceptName() ) == 0|| _instantPanel->getIfConceptCheckedAt( name, 0 ) ) {
3174 _theViewPanel->setHorizontalConcept( name, minshow, maxshow, minshow, maxshow, value);
3180 void wxContourMainFrame::onSnakePressed(){
3181 std::vector<double> vecX;
3182 std::vector<double> vecY;
3183 std::vector<double> vecZ;
3184 _theViewPanel->GetPointsOfActualContour( &vecX , &vecY , &vecZ );
3186 if (vecX.size()!=0){
3187 std::vector<int> tempVector;
3188 _instantPanel->getInstant( tempVector );
3189 int i,size=vecZ.size();
3190 int actualSlice = tempVector[1];
3191 for ( i=0 ; i<size ; i++ )
3193 vecZ[i] = actualSlice;
3196 wxDialog* dialog = new wxDialog(this, -1, wxString(_T("Snake")));
3197 wxPanel* panel = new wxPanel(dialog,-1);
3198 // wxStaticText* sttext = new wxStaticText(panel, -1, wxString(_T("Panel para snake")));
3199 new wxStaticText(panel, -1, wxString(_T("Panel para snake")));
3200 dialog->ShowModal();
3205 void wxContourMainFrame::saveFileWithContoursAutomatique(){
3206 std::string filename = kernelManager->getCurrentFileName();
3207 if(filename.compare("")!=0){
3208 saveFileWithContours(filename);
3213 void wxContourMainFrame::ShowToolsPanel(bool show){
3214 _pannew->Show(show);
3219 void wxContourMainFrame::SetContourGroup(int contourGroup)
3221 _contourGroup = contourGroup;
3225 wxPanel *wxContourMainFrame::getMaskImageViewPanel(wxWindow *parent)
3228 if (_viewMaskImagePanel==NULL)
3230 _contourextractdata = new ContourExtractData(true);
3231 _contourextractdata->SetImage( _theViewPanel->getImageData() );
3233 // _theViewPanel->getImageData()->GetScalarRange(range);
3234 //int min = (int)floor (range[0]);
3235 //int max = (int)ceil (range[1]);
3241 _viewMaskImagePanel = new ThresholdImageViewPanel( parent, -1, -1 , -1,-1, 0);
3242 _viewMaskImage = new ThresholdImageView();
3243 _viewMaskImage->SetImage( _contourextractdata->GetVtkImageMaskResult() );
3244 _viewMaskImage->SetminMaxValue( min, max);
3245 _viewMaskImage->SetBaseColor( 0,0,1 );
3248 std::vector<int> colorbarposition;
3249 colorbarposition.push_back( -999 );
3250 colorbarposition.push_back( -999 );
3251 _viewMaskImage->SetColorBarPosition( colorbarposition );
3253 _viewMaskImage->SetSpcBase( _theViewPanel->getImageData()->GetSpacing() );
3254 _viewMaskImage->SetNewSpacingLayer( _theViewPanel->getImageData()->GetSpacing() );
3256 _viewMaskImagePanel->SetThresholdImageView( _viewMaskImage );
3257 _viewMaskImage->SetwxVtkBaseView( _theViewPanel->getWxVtkBaseView() );
3258 _viewMaskImage->onThresholdChangeOpacity( 25 );
3260 return _viewMaskImagePanel;
3264 wxPanel *wxContourMainFrame::getColorLayerImageViewPanel(wxWindow *parent)
3266 if (_viewColorLayerImagePanel==NULL)
3269 _theViewPanel->getImageData()->GetScalarRange(range);
3270 int min = (int)floor (range[0]);
3271 int max = (int)ceil (range[1]);
3272 _viewColorLayerImagePanel = new ColorLayerImageViewPanel( parent, min, max, 100, 1);
3273 _viewColorLayerImagePanel->GetColorLayerImageViewManager()->SetwxVtkBaseView( 0 , _theViewPanel->getWxVtkBaseView() );
3274 // std::vector<double> range = bbGetInputlstRangeForColorBar();
3275 // clivp->GetColorLayerImageViewManager()->SetRangeForColorBar( range );
3276 std::vector<int> colorbarposition;
3277 colorbarposition.push_back( 50 );
3278 colorbarposition.push_back( 105 );
3279 _viewColorLayerImagePanel->GetColorLayerImageViewManager()->SetColorBarPosition( colorbarposition );
3280 // std::vector<double> base_color;
3281 // _viewColorLayerImagePanel->GetColorLayerImageViewManager()->SetBaseColors( base_color );
3282 // std::vector<double> grey_level_boundaries;
3283 // clivp->GetColorLayerImageViewManager()->SetGreyLevelBoundaries( grey_level_boundaries );
3284 std::vector<double> transparence_level_boundaries;
3285 transparence_level_boundaries.push_back(0);
3286 _viewColorLayerImagePanel->GetColorLayerImageViewManager()->SetBaseTransparence( transparence_level_boundaries );
3287 _viewColorLayerImagePanel->GetColorLayerImageViewManager()->SetPlainOrGradientColor( false );
3288 // _viewColorLayerImagePanel->SetFittingMode( 3 );
3290 return _viewColorLayerImagePanel;
3294 wxPanel *wxContourMainFrame::getThresholdImageViewPanel(wxWindow *parent)
3296 if (_viewThresholdImagePanel==NULL)
3299 _theViewPanel->getImageData()->GetScalarRange(range);
3300 int min = (int)floor (range[0]);
3301 int max = (int)ceil (range[1]);
3302 int start= (max+min)/2 - (max-min)*0.25;
3303 int end= (max+min)/2 + (max-min)*0.25;
3304 _viewThresholdImagePanel = new ThresholdImageViewPanel( parent, min, max, start, end , 1);
3305 _viewThresholdImage = new ThresholdImageView();
3306 _viewThresholdImage->SetminMaxValue(start,end);
3307 _viewThresholdImage->SetImage( _theViewPanel->getImageData() );
3308 std::vector<int> colorbarposition;
3309 colorbarposition.push_back( 10 );
3310 colorbarposition.push_back( 105 );
3311 _viewThresholdImage->SetColorBarPosition( colorbarposition );
3313 _viewThresholdImage->SetSpcBase( _theViewPanel->getImageData()->GetSpacing() );
3314 _viewThresholdImage->SetNewSpacingLayer( _theViewPanel->getImageData()->GetSpacing() );
3316 _viewThresholdImage->SetBaseColor( 1,0,0 );
3317 _viewThresholdImagePanel->SetThresholdImageView( _viewThresholdImage );
3318 _viewThresholdImage->SetwxVtkBaseView( _theViewPanel->getWxVtkBaseView() );
3319 _viewThresholdImage->onThresholdChangeOpacity( 25 );
3322 return _viewThresholdImagePanel;
3325 //CMRU 17-08-09-----------------------------------------------------------------------------------------------
3326 int wxContourMainFrame::getType ()
3329 std::vector<std::string> currentSelection = _theViewPanel->getSelectedObjects();
3331 if(!currentSelection.empty())
3333 std::string cloneName = currentSelection [0];
3334 manualBaseModel * manualModel = kernelManager->getOutlineByKeyName(cloneName);
3335 tipo = manualModel-> GetTypeModel();
3340 double wxContourMainFrame::getContourSizeInPixels()
3342 double contourSize = 0;
3344 std::vector<std::string> currentSelection = _theViewPanel->getSelectedObjects(); if(!currentSelection.empty())
3345 if(!currentSelection.empty())
3347 std::string cloneName = currentSelection [0];
3349 manualBaseModel * manualModel = kernelManager->getOutlineByKeyName(cloneName);//_modelManager->getOutlineByKeyName( cloneName )->getModel();
3352 // contourSize = manualModel->GetPathSize();
3357 contourSize = manualModel->GetPathSize( spc );
3362 manualBaseModel * wxContourMainFrame::getContour ()
3364 std::vector<std::string> currentSelection = _theViewPanel->getSelectedObjects();
3366 if(!currentSelection.empty())
3368 std::string cloneName = currentSelection [0];
3369 manualBaseModel * manualModel = kernelManager->getOutlineByKeyName(cloneName);//_modelManager->getOutlineByKeyName( cloneName )->getModel();
3374 void wxContourMainFrame::onPrintLabel (wxString label, manualBaseModel* manualModel)
3376 std::string labelAscii(label.ToAscii());
3377 int pos = labelAscii.find(" ");
3381 for (j=0 ; pos != string::npos;j++)
3383 labelAscii.replace( pos, 1, "_" );
3384 pos= labelAscii.find(" ");
3387 manualModel -> SetLabel(labelAscii);
3389 void wxContourMainFrame::onInsertCalculation(manualBaseModel* manualModel)
3392 // double sizeInPixel = manualModel ->GetPathSize( );
3397 double sizeInPixel = manualModel ->GetPathSize( spc );
3399 double onePixelRealSize = interfMainPanel::getInstance()->GetPixelValue();;
3400 double realContourSize = sizeInPixel*onePixelRealSize;
3401 manualModel ->SetRealSize(realContourSize);
3404 double wxContourMainFrame::onePixelSize( double value)
3406 return _onePixelSize = value;
3409 std::string wxContourMainFrame::GetFileLocation()
3411 return _fileLocation;
3414 void wxContourMainFrame::SetFileLocation(std::string newFileLocation)
3416 _fileLocation = newFileLocation;
3417 std::cout<<"GETFILELOCATION:"<<_fileLocation<<std::endl;
3419 //------------------------------------------------------------------------------------------------------------
3428 void wxContourMainFrame::FlipSelectedContours(int flipDirection)
3431 (std::vector<std::string>)_theViewPanel->getSceneManager()->getSelectedObjects() ,
3437 void wxContourMainFrame::FlipActualSliceContours(int flipDirection)
3440 (std::vector<std::string>)_theViewPanel->getSceneManager()->GetlstContoursNameActualSlice() ,
3445 void wxContourMainFrame::FlipAllContours(int flipDirection)
3448 kernelManager->GetLstNameThings() ,
3453 void wxContourMainFrame::FlipLstOfContours(std::vector<std::string> lstNameThings, int flipDirection)
3456 getImageData()->GetExtent(ext);
3457 int sizeX = ext[1]-ext[0];
3458 int sizeY = ext[3]-ext[2];
3461 int i,sizeLstNameThings;
3462 int ii,sizeLstPoints;
3464 sizeLstNameThings = lstNameThings.size();
3465 for (i=0 ; i<sizeLstNameThings ; i++)
3467 printf("EED wxContourMainFrame::FlipAllContours contour=%d \n", i );
3468 manualBaseModel * manualModel = kernelManager->getOutlineByKeyName(lstNameThings[i]);
3469 if (flipDirection==0)
3471 manualModel->Transform_Ax_Plus_B(-1,sizeX,1,0 );
3473 manualModel->Transform_Ax_Plus_B(1,0,-1,sizeY );
3475 }// for i list of Things
3477 //-- Static Contours
3479 lstNameThings = kernelManager->GetLstNameThingsStatic();
3480 sizeLstNameThings = lstNameThings.size();
3481 for (i=0 ; i<sizeLstNameThings ; i++)
3483 manualBaseModel * manualModel = kernelManager->getOutlineByKeyName(lstNameThings[i]);
3484 if (flipDirection==0)
3486 manualModel->Transform_Ax_Plus_B(-1,sizeX,1,0 );
3488 manualModel->Transform_Ax_Plus_B(1,0,-1,sizeY );
3490 }// for i list of static things
3493 void wxContourMainFrame::FlipContours(int typeContourFlip, int flipDirection)
3495 printf("EED wxContourMainFrame::FlipContours( %d , %d ) \n",typeContourFlip, flipDirection );
3499 if (typeContourFlip==0) //
3501 FlipSelectedContours(flipDirection);
3504 if (typeContourFlip==1) //
3506 FlipActualSliceContours(flipDirection);
3509 if (typeContourFlip==2) //
3511 FlipAllContours(flipDirection);
3517 void wxContourMainFrame::SetXY(int x, int y)
3519 _theViewPanel->SetXY(x,y);