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;
99 wxContourMainFrame::wxContourMainFrame(wxWindow* parent, wxWindowID id,const wxString& title,const wxPoint& pos,const wxSize& size,std::vector<vtkImageData*> images, long style,std::string datadir)
100 : wxPanel(parent, id, pos, size, style)
102 m_mgr.SetManagedWindow(this);
104 _creatingContoursActive = false;
105 _theViewPanel = NULL;
107 _instantPanel = NULL;
108 _refLineControl = NULL;
109 _refLineModel = NULL;
111 // _actorPresent = false;
112 _viewMaskImage = NULL;
113 _viewMaskImagePanel = NULL;
114 _viewThresholdImage = NULL;
115 _viewThresholdImagePanel = NULL;
116 _viewColorLayerImagePanel = NULL;
117 // set up default notebook style
118 m_notebook_style = wxAUI_NB_TAB_SPLIT | wxAUI_NB_TAB_EXTERNAL_MOVE | wxNO_BORDER;
119 m_notebook_theme = 0;
120 //wxContour_ActionCommandsID a;
121 _numberOfVariablesStatistics= 7;
125 _pannew = interfMainPanel::getInstance(this,datadir+"/data/Icons");//, eventHandler);
126 _performingOperation = new PerformingOperation();
127 if(images.size() > 0)
129 this->setVectImages(images);
131 _contourextractdata = NULL;
134 void wxContourMainFrame::setVectImages(std::vector<vtkImageData*> imgs)
137 #if defined(__GNUC__)
138 std::string str_home(getenv("HOME"));
139 #elif defined(_WIN32)
140 std::string str_home(getenv("USERPROFILE"));
142 std::string strCreaContourDataTmp = str_home + "/.creaContourDataTemp/";
143 std::vector<std::string> conceptNameVect;
144 std::vector<int> conceptSizeVect;
145 notebook = this->createNotebook();
146 kernelManager = new KernelManagerContour( imgs , _datadir+"/data/" , strCreaContourDataTmp );
147 _instantPanel = new wxInstantChooserPanel( notebook, "Instant Chooser", true, false, "c" );
148 _theViewPanel = new wxContourViewPanel( kernelManager->getSourceImage(), notebook );
149 //-------------------------------------------------------------
150 kernelManager->getConceptsInformation(conceptNameVect, conceptSizeVect);
151 _instantPanel->addConcepts(conceptNameVect, conceptSizeVect);
152 double val = _theViewPanel->getCurrentDeep();
153 _instantPanel->setConceptValue( "Axe Depth", (int)val );
154 //JCP _instantPanel->setConceptValue("time", num de imagenes);
155 ConceptDataWrap * data = _instantPanel->getConceptDataOf( "Axe Depth" );
156 //*******************changeInstant();
157 _theViewPanel->setVerticalConcept( "Axe Depth", data->getMinValue(), data->getMaxValue(), data->getMinShowedValue(), data->getMaxShowedValue(), data->getActualValue() );
158 this->configurePanels( );
162 wxContourMainFrame* wxContourMainFrame :: getInstance(wxWindow* parent, wxWindowID id,const wxString& title,const wxPoint& pos,const wxSize& size,std::vector<vtkImageData*> images, long style,std::string datadir )
164 if(instance == NULL){
165 instance = new wxContourMainFrame(parent, id, title, pos, size, images, style,datadir);
170 std::vector<vtkImageData*> wxContourMainFrame ::getVectImages()
172 return kernelManager->getVectImages();
175 wxContourMainFrame* wxContourMainFrame :: getInstance()
180 void wxContourMainFrame :: resetInstance()
185 wxContourMainFrame :: ~wxContourMainFrame()
187 delete _contourextractdata;
190 interfMainPanel::resetInstance();
191 delete kernelManager;
193 //_pannew->Destroy();
199 //El problema al cerrar la aplicacion puede estar asociado
200 //a que wxAUINotebook esta en la aplicacion
201 //principal (wxContourGUIExample)tambien
202 //EED???? delete _theViewPanel;
203 //EED???? delete _instantPanel;
204 //EED???? delete _buttonsBar;
205 //EED???? delete _actualInstant;
206 //EED???? delete _sceneManager;
210 //------------------------------------------------------------------------------------------------------------
211 // Creational and initialization methods using WxAui
212 //------------------------------------------------------------------------------------------------------------
214 wxAuiNotebook * wxContourMainFrame :: createNotebook()
216 wxSize client_size = GetClientSize();
217 wxAuiNotebook* noteBook = new wxAuiNotebook(this, -1, wxPoint(client_size.x, client_size.y), wxSize(430,200), m_notebook_style);
218 wxBitmap page_bmp = wxArtProvider::GetBitmap(wxART_NORMAL_FILE, wxART_OTHER, wxSize(16,16));
223 //------------------------------------------------------------------------------------------------------------
224 // Creational and initialization methods
225 //------------------------------------------------------------------------------------------------------------
226 bool wxContourMainFrame :: configurePanels( )
228 bool configured = _theViewPanel!=NULL;
230 configured &= _theViewPanel!=NULL;
231 if( _theViewPanel!=NULL )
233 notebook->AddPage( _theViewPanel, wxT(" View ") );
238 notebook->AddPage( _instantPanel, wxT("Instant Page") );
241 m_mgr.AddPane(notebook, wxAuiPaneInfo().Name(wxT("notebook_content")).CenterPane().PaneBorder(false));
243 SetMinSize(wxSize(300,300));
249 bool wxContourMainFrame::addNewPanel(wxPanel* panel)
251 bool configured = panel!=NULL;
252 configured &= panel!=NULL;
256 notebook->AddPage( panel, wxT(" Viewer "), true );
262 //------------------------------------------------------------------------------------------------------------
263 // Attributes getters and setters
264 //------------------------------------------------------------------------------------------------------------
268 void wxContourMainFrame :: setInstantChooserPanel( wxInstantChooserPanel * theInstantChooserPanel )
270 _instantPanel = theInstantChooserPanel;
273 // void wxContourMainFrame :: setButtonsBar( wxContour_ButtonsBar * theButtonsBar )
275 // _buttonsBar = theButtonsBar;
278 // void wxContourMainFrame :: setGrid( wxContour_Grid * theGridPanel )
280 // _gridPanel = theGridPanel;
283 // void wxContourMainFrame :: setDrawToolsPanel( wxContour_DrawToolsPanel * theDrawToolsPanel )
285 // _drawToolsPanel = theDrawToolsPanel;
288 // void wxContourMainFrame :: setOperationsToolsPanel( wxContour_OperationsToolsPanel * theOperationsToolsPanel )
290 // _operationsToolsPanel = theOperationsToolsPanel;
293 // void wxContourMainFrame :: setAutomaticFormsPanel( wxContour_AutomaticFormsToolsPanel * theAutoFormsPanel )
295 // _autoFormsPanel = theAutoFormsPanel;
298 // void wxContourMainFrame :: setStandardToolsPanel( wxContour_StandardToolsPanel * theStandardToolsPanel )
300 // _standardToolsPanel= theStandardToolsPanel;
303 // void wxContourMainFrame :: setEditionToolsPanel( wxContour_EdtionToolsPanel * theEditionToolsPanel )
305 // _editionToolsPanel = theEditionToolsPanel;
308 // void wxContourMainFrame :: setListViewPanel( wxContour_ListViewPanel * theListViewPanel )
310 // _listViewPanel = theListViewPanel;
315 void wxContourMainFrame::onCreateContourSpline( ){
317 //JCP 20-10-08 Undo redo implementation
319 //JCP 20-10-08 Undo redo implementation
323 void wxContourMainFrame::onCreateContourRectangle( ){
324 //JCP 20-10-08 Undo redo implementation
326 //JCP 20-10-08 Undo redo implementation
329 void wxContourMainFrame::onCreateContourCircle( ){
330 //JCP 20-10-08 Undo redo implementation
332 //JCP 20-10-08 Undo redo implementation
336 void wxContourMainFrame::onCreateContourLine( ){
337 //JCP 20-10-08 Undo redo implementation
339 //JCP 20-10-08 Undo redo implementation
343 // RaC 09-09 --------------------------------------
344 void wxContourMainFrame::onCreateContourPoints( ){
345 //JCP 20-10-08 Undo redo implementation
347 //JCP 20-10-08 Undo redo implementation
350 // RaC 09-09 --------------------------------------
352 // RaC 10-09 --------------------------------------
353 void wxContourMainFrame::onCreateContourPolygon( ){
354 //JCP 20-10-08 Undo redo implementation
356 //JCP 20-10-08 Undo redo implementation
359 // RaC 10-09 --------------------------------------
361 //------------------------------------------------------------------------------------------------------------
363 void wxContourMainFrame :: onCreateContourBullEye(wxPanel* panel )
365 //Creating the manualBaseModel and including in the model
366 manualBaseModel * manModelContour = factoryManualContourModel(panel );
368 std::vector<int> instantVector;
369 _instantPanel->getInstant( instantVector );
370 std::string theName = kernelManager->createOutline(manModelContour, instantVector);
372 /*std::vector<int> instantVector;
373 _instantPanel->getInstant( instantVector );
375 theName= _modelManager->createOutline( manModelContour, instantVector );*/
376 bool addedModel = theName.compare("") != 0;//??
380 double spc[3];//Si no hay imagen pero hay contornos que spacing se pone por default
381 _theViewPanel->getSpacing(spc);
382 //Adding the manualContourControler to interface objects structure
383 //Adding the manualViewContour to interface objects structure
384 //_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.
385 _theViewPanel->getSceneManager()->configureViewControlTo( theName, manModelContour,spc , 4) ;
388 void wxContourMainFrame :: createContour( int typeContour )
390 //Creating the manualContourModel and including in the model
391 manualBaseModel * manModelContour = kernelManager->factoryManualContourModel(typeContour);
393 std::vector<int> instantVector;
394 _instantPanel->getInstant( instantVector );
395 std::string theName = kernelManager->createOutline(manModelContour, instantVector);
397 /*std::vector<int> instantVector;
398 _instantPanel->getInstant( instantVector );
400 theName= _modelManager->createOutline( manModelContour, instantVector );*/
401 bool addedModel = theName.compare("") != 0;//??
404 double spc[3];//Si no hay imagen pero hay contornos que spacing se pone por default
405 _theViewPanel->getSpacing(spc);
406 //Adding the manualContourControler to interface objects structure
407 //Adding the manualViewContour to interface objects structure
408 //_sceneManager->setControlActiveStateOfALL( false );//This call is being done here because if the ROI is created underneath the previously created ROIS will still be active.
409 _theViewPanel->getSceneManager()->configureViewControlTo( theName, manModelContour,spc , typeContour) ;
413 manualBaseModel * wxContourMainFrame::factoryManualContourModel(wxPanel* panel){
415 manualContourModelBullEye *manModelContourBullEye = new manualContourModelBullEye();
416 manualBaseModel *manModelContour=NULL;
417 manModelContour = manModelContourBullEye;
419 int iCrown,sizeCrowns,iSector,sizeSectors;
420 double radioA,radioB,ang,angDelta ;
421 sizeCrowns = ((PanelBullEyeOptions*)panel)->GetNumberOfCrowns();
422 for ( iCrown=0 ; iCrown<sizeCrowns ; iCrown++ )
424 sizeSectors = ((PanelBullEyeOptions*)panel)->GetNumberOfSections(iCrown);
425 radioB = ((PanelBullEyeOptions*)panel)->GetRadioOfCrown(iCrown);
426 if (iCrown==sizeCrowns-1)
430 radioA = ((PanelBullEyeOptions*)panel)->GetRadioOfCrown(iCrown+1);
434 for ( iSector=0 ; iSector<sizeSectors ; iSector++ )
436 ang = ((PanelBullEyeOptions*)panel)->GetAngOfCrownSection(iCrown,iSector);
437 angDelta= ((PanelBullEyeOptions*)panel)->GetAngDeltaOfCrownSection(iCrown);
438 manModelContourBullEye->AddSector(radioA,radioB,ang,angDelta);
441 } // if _panelBullEyeOptions
443 return manModelContour;
446 void wxContourMainFrame :: saveState()
448 std::string temp = kernelManager->saveState();
449 saveFileWithContours(temp);
452 void wxContourMainFrame::onDeleteContour()
454 //JCP 20-10-08 Undo redo implementation
456 //JCP 20-10-08 Undo redo implementation
458 std::vector<std::string> lstKeyNameToBeErase;
459 lstKeyNameToBeErase = _theViewPanel->getSceneManager()->getSelectedObjects();
460 deleteContours( lstKeyNameToBeErase );
462 int i,size=_sceneManager->getSelectedObjects().size();
465 std::string keyName = _sceneManager->getSelectedObjects()[i];
466 int ispartofstaticlist = this->_modelManager->IsPartOfStaticList( keyName );
467 if ( ispartofstaticlist>=0 )
469 std::vector<int> tempVector;
470 _instantPanel->getInstant( tempVector );
471 Instant instant(&tempVector);
472 this->_modelManager->ChangeContourOfList(keyName, &instant);
476 std::vector<std::string> lstKeyName;
477 std::vector<std::string> lstKeyNameActualSlice;
478 std::vector<std::string> lstKeyNameToBeErase;
480 lstKeyNameToBeErase = _sceneManager->getSelectedObjects();
481 lstKeyNameActualSlice = _sceneManager->GetlstContoursNameActualSlice();
482 int k,kSize=lstKeyNameToBeErase.size();
483 int j,jSize=lstKeyNameActualSlice.size();
485 for (k=0;k<kSize; k++)
488 for (j=0;j<jSize; j++)
490 if (lstKeyNameToBeErase[k]==lstKeyNameActualSlice[j])
497 lstKeyName.push_back( lstKeyNameToBeErase[k] );
501 deleteContours( lstKeyName );
505 void wxContourMainFrame :: deleteContours( std::vector<std::string> keyNamesVector )
507 int i,size=keyNamesVector.size();
510 deleteContour( keyNamesVector[i] );
514 void wxContourMainFrame :: deleteContour( std::string theKeyName )
517 manualContourModel * cModel;
518 manualViewBaseContour * cViewer;
519 manualContourBaseControler * cControler;
521 ContourWrap_ViewControl *conwrapviewControl = _theViewPanel->getSceneManager()->getContourWrap_ViewControlOf( theKeyName );
522 cControler = conwrapviewControl->getControler();*/
525 bool isedit = _theViewPanel->isEditableCControler(theKeyName);
526 bool ispartofstaticlst = kernelManager->IsPartOfStaticList(theKeyName);
528 if (isedit && ispartofstaticlst)
530 _theViewPanel->removeFromScene(theKeyName);
532 kernelManager->deleteCModel(theKeyName);
533 //_theViewPanel->getSceneManager()->removeFromScene( theKeyName );
534 //cViewer = conwrapviewControl->getViewer();
535 //_theViewPanel->getSceneManager()->removeWrap( theKeyName );
536 //cControler* conwrapviewControl->getControler();
539 // delete cControler;
544 void wxContourMainFrame::onDeleteContoursActSlice(){
545 //JCP 20-10-08 Undo redo implementation
547 //JCP 20-10-08 Undo redo implementation
548 deleteContours( (std::vector<std::string>)_theViewPanel->getSceneManager()->GetlstContoursNameActualSlice() );
550 void wxContourMainFrame::onDeleteAllContours(){
551 //JCP 20-10-08 Undo redo implementation
555 void wxContourMainFrame::deleteAllContours(){
556 //JCP 20-10-08 Undo redo implementation
559 std::vector<int> tempVector;
560 _instantPanel->getInstant( tempVector );
562 //JCP --08-09-2008 When using a diferent interface the _mbarrangeDeleteAll might not be initialize
563 // the values in GetStart and GetEnd will then not be initialize also.
564 // We use instead the values given when initializing the _deletepanel.
566 //int minZ = _mbarrangeDeleteAll->GetStart();
567 //int maxZ = _mbarrangeDeleteAll->GetEnd();
571 maxZ = _theViewPanel->getSceneManager()->GetImageDataSizeZ();
575 _theViewPanel->getSceneManager()->removeSceneContours( );
576 _theViewPanel->getSceneManager()->removeAllOutlines();
577 kernelManager->removeAllOutlines();
580 if ( (minZ==0) && (maxZ==_mbarrangeDeleteAll->GetMax() ))
582 _theViewPanel->getSceneManager()->removeSceneContours( );
583 _modelManager->removeAllOutlines();
584 _theViewPanel->getSceneManager()->removeAllOutlines();
587 for ( z=minZ ; z<=maxZ ; z++)
590 Instant instant(&tempVector);
591 std::vector<ContourThing**> lstContourThings = this->_modelManager->getOutlinesAtInstant( &instant );
593 sizeLstContourThings = lstContourThings.size();
594 for (ii=0 ; ii<sizeLstContourThings ; ii++)
596 ContourThing **contourthing = lstContourThings[ii];
597 deleteContour( (*contourthing)->getName() );
604 void wxContourMainFrame::setConceptValue( std::string name, int value )
606 _instantPanel->setConceptValue(name, value);
610 ConceptDataWrap* wxContourMainFrame::getLastConceptData()
612 return _instantPanel->getLastConceptData();
616 bool wxContourMainFrame::getIfConceptCheckedAt( std::string name, int pos )
618 return _instantPanel->getIfConceptCheckedAt( name, pos );
623 void wxContourMainFrame::ShowResultImages(int typeContourGroup, int selection, int minZ, int maxZ)
626 vtkImageData * value;
627 this->getMaskValue(&mask, &value, typeContourGroup, selection, minZ, maxZ);
629 std::vector<int> nTypeView;
630 nTypeView.push_back(5);
631 nTypeView.push_back(1);
632 nTypeView.push_back(2);
633 nTypeView.push_back(0);
635 wxFrame *frame = new wxFrame(this, -1,_T("Result image extracted.."),wxDefaultPosition,wxSize(600,600), wxDEFAULT_FRAME_STYLE|wxSTAY_ON_TOP);
636 wxAuiManager *m_mgr_noteBookViewerResult = new wxAuiManager();
637 m_mgr_noteBookViewerResult->SetManagedWindow(frame);
639 wxAuiNotebook* noteBookViewerResult = new wxAuiNotebook(frame, -1, wxPoint(600, 600), wxSize(430,200), m_notebook_style);
640 m_mgr_noteBookViewerResult->AddPane(noteBookViewerResult, wxAuiPaneInfo().Name(wxT("notebook_content")).CenterPane().PaneBorder(false));
642 wxPanel *panelViewer1 = new wxMaracas_N_ViewersWidget(noteBookViewerResult, value,&nTypeView);
643 wxPanel *panelViewer2 = new wxMaracas_N_ViewersWidget(noteBookViewerResult, mask,&nTypeView);
646 noteBookViewerResult->AddPage( panelViewer1, wxT("Image result") );
647 noteBookViewerResult->AddPage( panelViewer2, wxT("Mask result") );
648 m_mgr_noteBookViewerResult->Update();
655 void wxContourMainFrame::changeInstant()
657 std::vector<int> instantVect;
658 _instantPanel->getInstant( instantVect );
659 int actualSlice = instantVect[1];
660 kernelManager->setInstant(instantVect);
661 // Refresh Mask image
662 if(_viewMaskImage!=NULL)
664 _viewMaskImage->SetZ(actualSlice);
665 if (_viewMaskImagePanel->IsVisible()==true)
667 vtkImageData *mask, *value;
668 getMaskValue(&mask,&value, _contourGroup , 0, -1, -1);
669 _viewMaskImage->onThreshold();
671 } // if _viewMaskImage
672 // Refresh Threshold image
673 if(_viewThresholdImage!=NULL)
675 _viewThresholdImage->SetZ(actualSlice);
676 if (_viewThresholdImagePanel->IsVisible()==true)
678 _viewThresholdImage->onThreshold();
680 } // if _viewThresholdImage
681 updateInstantOutlines();
682 updateInstantImageData();
688 void wxContourMainFrame::updateInstantOutlines()
690 _theViewPanel->removeSceneContours();
691 _theViewPanel->addNameWrapperToScene();
693 //for( int i=0; i<size; i++)
695 // _theViewPanel->getSceneManager()->addToScene(namesWrapping[i]->getKeyName(), true, true, true, false, false );
699 int wxContourMainFrame::getNamesWrappingSize()
701 return kernelManager->getNamesWrappingSize();
704 std::string wxContourMainFrame::getNameWrapping(int i)
706 return kernelManager->getNameWrapping(i);
709 void wxContourMainFrame::updateInstantImageData()
711 std::vector<int> inst;
712 _instantPanel->getInstant(inst);
714 vtkImageData* img = kernelManager->getImageAtInstant(inst);
716 _theViewPanel->changeImage(img);
719 int z = _instantPanel->getConceptDataOf("Axe Depth")->getActualValue();
720 _theViewPanel->setImageSlice(z);
724 void wxContourMainFrame::updateInstantAxes()
729 void wxContourMainFrame::onChangeDeep(int val){
730 _instantPanel->setConceptValue( "Axe Depth", (int)val );
735 void wxContourMainFrame::onCopy(){
736 std::vector<std::string> currentSelection = _theViewPanel->getSelectedObjects();
737 std::vector<int> tempVector;
738 _instantPanel->getInstant( tempVector );
739 _performingOperation->reset();
740 _performingOperation->setStartCommand( COPY );
741 _performingOperation->setStartOperationInstantVector( tempVector );
742 _performingOperation->setKeyNamesOperationElems( currentSelection );
745 void wxContourMainFrame::onPaste()
747 char theStartCommand = _performingOperation->getStartCommand();
748 if ( theStartCommand == COPY )
750 //JCP 20-10-08 Undo redo implementation
752 //JCP 20-10-08 Undo redo implementation
753 std::vector<int> tempVector;
754 _instantPanel->getInstant( tempVector );
755 _performingOperation->setEndOperationInstantVector ( tempVector );
756 std::vector<std::string> elems = _performingOperation->getKeyNamesOperationElems();
757 int i,size = elems.size();
758 for( i=0; i<size; i++ )
760 createCopyContourOf( elems[i], tempVector, i>0 );
765 void wxContourMainFrame::onUndo()
767 std::string filename;
768 if(kernelManager->onUndoSaveFile(filename)){
769 saveFileWithContours(filename);
771 if(kernelManager->onUndo(filename)){
775 void wxContourMainFrame::onRedo(){
776 std::string filename;
777 if(kernelManager->onRedo(filename)){
782 void wxContourMainFrame :: createCopyContourOf ( std::string anExistingKName, std::vector<int> &instantNoTouchData, bool append )
784 std::string cloneName = kernelManager->createCopyContourOf( anExistingKName, instantNoTouchData );
785 manualBaseModel * manualModel = kernelManager->getOutlineByKeyName(cloneName);//_modelManager->getOutlineByKeyName( cloneName )->getModel();
786 _theViewPanel->getSceneManager()->createCopyContourOf( anExistingKName, cloneName, manualModel , append );
789 ///AD: 03-09 Copy the object and apply the given transformation
790 void wxContourMainFrame :: createMirrorContourOf ( std::string anExistingKName, std::vector<int> &instantNoTouchData, bool append )
792 std::string cloneName = kernelManager->createCopyContourOf( anExistingKName, instantNoTouchData );
793 manualBaseModel * manualModel = kernelManager->getOutlineByKeyName(cloneName);
795 manualPoint * refPoint1 = _refLineModel->GetManualPoint(0);
796 manualPoint * refPoint2 = _refLineModel->GetManualPoint(1);
798 double pnt1X = refPoint1->GetX();
799 double pnt1Y = refPoint1->GetY();
800 // double pnt1Z = refPoint1->GetZ();
801 double pnt2X = refPoint2->GetX();
802 double pnt2Y = refPoint2->GetY();
803 // double pnt2Z = refPoint2->GetZ();
805 double angle = (atan2(pnt2Y - pnt1Y, pnt2X - pnt1X) * 180 / 3.1415926535897932384626433832795)+90;
806 vtkTransform *t = vtkTransform::New();
810 t->Translate(-pnt1X, -pnt1Y, 0);
814 t->Translate(pnt1X, pnt1Y, 0);
817 int i,size=manualModel->GetSizeLstPoints();
820 manualPoint * mp = manualModel->GetManualPoint(i);
826 t->TransformPoint( vecIn, vecOut );
827 mp->SetPointX( vecOut[0] );
828 mp->SetPointY( vecOut[1] );
829 mp->SetPointZ( vecOut[2] );
832 _theViewPanel->getSceneManager()->createCopyContourOf( anExistingKName, cloneName, manualModel , append );
835 void wxContourMainFrame ::loadState(std::string filename)
838 onLoadContours(filename,false);
842 void wxContourMainFrame::onLoad()
844 std::string fileNameContourROI = GetFileLocation();
845 //CMRU 03-09-09-----------------------------------------------------------------------------------------------
846 if(GetFileLocation().empty())
848 //------------------------------------------------------------------------------------------------------------
849 //EED 2017-09-16 Migration wxWidgets 2.8 to 3.0
850 #if wxMAJOR_VERSION <= 2
851 wxFileDialog dialog(NULL, _T("Choose a file"), _T(""), _T(""), _T("*.roi"), wxOPEN );
853 wxFileDialog dialog(NULL, _T("Choose a file"), _T(""), _T(""), _T("*.roi"), wxFD_OPEN );
855 if (dialog.ShowModal() == wxID_OK)
857 fileNameContourROI = (const char *)(dialog.GetPath().mb_str());
861 onLoadContours(fileNameContourROI,true);
865 void wxContourMainFrame::SetZForAllContours(int pz)
868 std::vector< std::string > lstNameThings;
869 int i,sizeLstNameThings;
870 int ii,sizeLstPoints;
872 lstNameThings = kernelManager->GetLstNameThings();
873 sizeLstNameThings = lstNameThings.size();
874 for (i=0 ; i<sizeLstNameThings ; i++)
876 printf("EED wxContourMainFrame::SetZForAllContours contour=%d \n", i );
877 manualBaseModel * manualModel = kernelManager->getOutlineByKeyName(lstNameThings[i]);
878 sizeLstPoints = manualModel->GetSizeLstPoints();
879 for (ii=0 ; ii<sizeLstPoints ; ii++)
881 manualModel->GetManualPoint(ii)->SetPointZ(-900);
882 }// for ii list of points
883 }// for i list of Things
887 lstNameThings = kernelManager->GetLstNameThingsStatic();
888 sizeLstNameThings = lstNameThings.size();
889 for (i=0 ; i<sizeLstNameThings ; 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 static things
900 void wxContourMainFrame::onLoadContours(std::string fileNameContourROI, bool interactiveInterface)
904 FILE *pFile =fopen(fileNameContourROI.c_str(),"r+");
905 //CMRU 03-09-09- ----------------------------------------------------------------------------------------------
908 //------------------------------------------------------------------------------------------------------------
909 fileNameContourROI.append("data");
910 FILE *pFileData=fopen(fileNameContourROI.c_str(),"r+");
911 if(pFileData != NULL)
913 fscanf(pFileData,"%s",tmpD); // --CreaContour--
914 fscanf(pFileData,"%s",tmpD); // Version
915 fscanf(pFileData,"%s",tmpD); // 1.0.3 || 1.0.2 || 1.0.1 || 1.0.0
917 fscanf(pFileData,"%s",tmpD); // onePixelSize
918 fscanf(pFileData,"%s",tmpD); // #
919 _onePixelSize = atof(tmpD);
920 fscanf(pFileData,"%s",tmpD); // NumberOfContours
921 fscanf(pFileData,"%s",tmpD); // #
923 fscanf(pFile,"%s",tmp); // --CreaContour--
924 fscanf(pFile,"%s",tmp); // Version
925 fscanf(pFile,"%s",tmp); // 1.0.3 || 1.0.2 || 1.0.1 || 1.0.0
926 std::string version(tmp);
928 _tmpReadFileTypeOfTransformation=-1;
929 if (version=="1.0.3")
931 readDimSpc(pFile,interactiveInterface); // DimSpc interactive ON
932 openContours(pFile,pFileData,false);
933 openContours(pFile,pFileData,true); //Load StaticContours
935 if (version=="1.0.2")
938 readDimSpc(pFile,interactiveInterface); // DimSpc interactive ON
939 openContours(pFile,pFileData,false);
940 readDimSpc(pFile,false); // DimSpc interactive OFF
941 openContours(pFile,pFileData,true); // Load StaticContours
942 SetZForAllContours(-900);
945 else if (version=="1.0.1")
947 openContours(pFile,pFileData,false); //Skips ImageDimensions and ImageSpacing
948 openContours(pFile,pFileData,true); //Load StaticContours, skips ImageDimensions and ImageSpacing
952 else if (version=="1.0.0")
954 openContours(pFile,pFileData,false); //Skips ImageDimensions and ImageSpacing
959 if(pFileData != NULL)
964 _theViewPanel->getSceneManager()->removeSceneContours();
969 void wxContourMainFrame::onImport()
971 std::string filename, filenamecontours;
972 //EED 2017-09-16 Migration wxWidgets 2.8 to 3.0
973 #if wxMAJOR_VERSION <= 2
974 wxFileDialog dialog(NULL, _T("Choose a XML Osirix File"), _T(""), _T(""), _T("*.xml"), wxOPEN );
976 wxFileDialog dialog(NULL, _T("Choose a XML Osirix File"), _T(""), _T(""), _T("*.xml"), wxFD_OPEN );
978 if (dialog.ShowModal() == wxID_OK)
980 filename = dialog.GetPath().mb_str();
981 filenamecontours = kernelManager->parseOsirixFile(filename);
983 if(filenamecontours.compare("") != 0){
984 onLoadContours(filenamecontours,true);
989 void wxContourMainFrame::onTest()
991 std::string filename, filenamecontours;
992 //EED 2017-09-16 Migration wxWidgets 2.8 to 3.0
993 #if wxMAJOR_VERSION <= 2
994 wxFileDialog dialog(NULL, _T("Choose a File"), _T(""), _T(""), _T("*.*"), wxOPEN );
996 wxFileDialog dialog(NULL, _T("Choose a File"), _T(""), _T(""), _T("*.*"), wxFD_OPEN );
999 if (dialog.ShowModal() == wxID_OK)
1001 filename = dialog.GetPath().mb_str();
1002 std::cout << "This is the filename: " << filename << std::endl;
1008 void wxContourMainFrame::onSave(){
1009 //CMRU 03-09-09-----------------------------------------------------------------------------------------------
1010 if(GetFileLocation().empty())
1012 //------------------------------------------------------------------------------------------------------------
1013 //EED 2017-09-16 Migration wxWidgets 2.8 to 3.0
1014 #if wxMAJOR_VERSION <= 2
1015 wxFileDialog dialog(NULL, _T("Choose a file"), _T(""), _T(""), _T("*.roi"), wxSAVE );
1017 wxFileDialog dialog(NULL, _T("Choose a file"), _T(""), _T(""), _T("*.roi"), wxFD_SAVE );
1019 if (dialog.ShowModal() == wxID_OK)
1021 std::string fileNameContourROI = (const char *)(dialog.GetPath().mb_str());
1022 kernelManager->setCurrentFileName(fileNameContourROI);
1023 saveFileWithContours( fileNameContourROI );
1026 //CMRU 03-09-09-----------------------------------------------------------------------------------------------
1029 std::cout<<"Nombre del archivo: "<<GetFileLocation()<<std::endl;
1030 std::string fileNameContourROI = GetFileLocation();
1031 std::cout<<"Nombre del archivo: "<<fileNameContourROI<<std::endl;
1032 kernelManager->setCurrentFileName(fileNameContourROI);
1033 saveFileWithContours( fileNameContourROI);
1035 //------------------------------------------------------------------------------------------------------------
1039 void wxContourMainFrame::saveFileWithContours( std::string filename )
1042 FILE *pFile=fopen(filename.c_str(),"w+");
1044 //CMRU 03-09-09-----------------------------------------------------------------------------------------------
1045 filename.append("data");
1046 std::cout<<"Nombre del archivo: "<<filename<<std::endl;
1047 FILE *pFileData=fopen(filename.c_str(),"w+");
1048 //------------------------------------------------------------------------------------------------------------
1050 std::vector< std::string > lstNameThings;
1051 int i,sizeLstNameThings;
1053 fprintf(pFile,"--CreaContour--\n");
1054 fprintf(pFile,"Version %s\n", "1.0.3" );
1056 //CMRU 03-09-09-----------------------------------------------------------------------------------------------
1057 fprintf(pFileData,"--CreaContour--\n");
1058 fprintf(pFileData,"Version %s\n", "1.0.3" );
1059 fprintf(pFileData,"OnePixelSize %f\n", _onePixelSize);
1061 //------------------------------------------------------------------------------------------------------------
1063 vtkImageData *image = _images[0];
1066 image->GetDimensions(dimRange);
1068 fprintf(pFile,"ImageDimensions %d %d %d\n", dimRange[0], dimRange[1], dimRange[2] );
1071 image->GetSpacing(spaRange);
1073 fprintf(pFile,"ImageSpacing %f %f %f\n", spaRange[0], spaRange[1], spaRange[2] );
1077 lstNameThings = kernelManager->GetLstNameThings();
1078 sizeLstNameThings = lstNameThings.size();
1079 fprintf(pFile,"NumberOfContours %d\n", sizeLstNameThings );
1081 //CMRU 03-09-09-----------------------------------------------------------------------------------------------
1082 fprintf(pFileData,"NumberOfContours %d\n", sizeLstNameThings );
1083 //------------------------------------------------------------------------------------------------------------
1092 for (i=0 ; i<sizeLstNameThings ; i++)
1094 //CMRU 03-09-09-----------------------------------------------------------------------------------------------
1095 manualBaseModel * manualModel = kernelManager->getOutlineByKeyName(lstNameThings[i]);
1098 // double sizeInPixel = manualModel ->GetPathSize( );
1099 double sizeInPixel = manualModel ->GetPathSize( spc );
1101 double realContourSize = sizeInPixel*_onePixelSize;
1102 manualModel ->SetRealSize(realContourSize);
1103 //------------------------------------------------------------------------------------------------------------
1105 //int size= kernelManager->GetLstNameThings().size();
1107 kernelManager->SaveThingName( pFile, pFileData, lstNameThings[i] );
1108 _theViewPanel->getSceneManager()->SaveThingName( pFile, lstNameThings[i] );
1111 //-- Static Contours
1113 // fprintf(pFile,"ImageDimensions %d %d %d\n", dimRange[0], dimRange[1], dimRange[2] );
1114 // fprintf(pFile,"ImageSpacing %f %f %f\n", spaRange[0], spaRange[1], spaRange[2] );
1116 lstNameThings = kernelManager->GetLstNameThingsStatic();
1117 sizeLstNameThings = lstNameThings.size();
1118 fprintf(pFile,"NumberOfContoursStatic %d\n", sizeLstNameThings );
1120 //CMRU 03-09-09-----------------------------------------------------------------------------------------------
1121 fprintf(pFileData,"NumberOfContoursStatic %d\n", sizeLstNameThings );
1122 //------------------------------------------------------------------------------------------------------------
1124 for (i=0 ; i<sizeLstNameThings ; i++)
1126 kernelManager->SaveThingName( pFile, pFileData, lstNameThings[i] );
1127 _theViewPanel->getSceneManager()->SaveThingName( pFile, lstNameThings[i] );
1135 void wxContourMainFrame::readDimSpc(FILE *pFile, bool interactiveOption)
1139 double imageSpac[3];
1140 vtkImageData *image = _images[0];
1141 image->GetDimensions(imageDim);
1142 image->GetSpacing(imageSpac);
1144 fscanf(pFile,"%s",tmp); // ImageDimensions
1145 fscanf(pFile,"%s",tmp); // X
1146 _tmpReadFileImageDim[0] = atoi(tmp);
1147 fscanf(pFile,"%s",tmp); // Y
1148 _tmpReadFileImageDim[1] = atoi(tmp);
1149 fscanf(pFile,"%s",tmp); // Z
1150 _tmpReadFileImageDim[2] = atoi(tmp);
1152 fscanf(pFile,"%s",tmp); // ImageSpacing
1153 fscanf(pFile,"%s",tmp); // X
1154 _tmpReadFileImageSpac[0] = atof(tmp);
1155 fscanf(pFile,"%s",tmp); // Y
1156 _tmpReadFileImageSpac[1] = atof(tmp);
1157 fscanf(pFile,"%s",tmp); // Z
1158 _tmpReadFileImageSpac[2] = atof(tmp);
1161 if (interactiveOption==true)
1163 //Compare Spacing and Dims in X and Y (Necessary in Z?) - Just for Version 2
1164 if (imageDim[0]!=_tmpReadFileImageDim[0] || imageDim[1]!=_tmpReadFileImageDim[1] || imageSpac[0]!=_tmpReadFileImageSpac[0] || imageSpac[1]!=_tmpReadFileImageSpac[1])
1166 wxDialog* dial = new wxDialog (this,-1,_T("Tools"),wxDefaultPosition, wxSize(460,360));
1167 wxSizer* buttonsSizer = dial->CreateSeparatedButtonSizer(wxOK|wxCANCEL);
1168 wxBoxSizer *dialSizer = new wxBoxSizer(wxVERTICAL);
1170 wxString lstOptOperation[2];
1171 lstOptOperation[0]=_T("By Dimension");
1172 lstOptOperation[1]=_T("By Spacing");
1173 wxRadioBox * radioOpts = new wxRadioBox(dial, -1, _T("Type of Transformation"), wxDefaultPosition, wxSize(270,45), 2 , lstOptOperation, 2, wxRA_SPECIFY_COLS);
1175 dialSizer->Add( new wxStaticText(dial,-1,_T("The image resolution is not compatible with the ")) , 0, wxGROW );
1176 dialSizer->Add( new wxStaticText(dial,-1,_T("selected Roi file. Do you want to tranform it?")) , 0, wxGROW );
1177 dialSizer->Add( new wxStaticText(dial,-1,_T(" ")) , 0, wxGROW );
1178 dialSizer->Add(radioOpts,0,wxGROW);
1179 dialSizer->Add( new wxStaticText(dial,-1,_T(" ")) , 0, wxGROW );
1180 dialSizer->Add(buttonsSizer,0,wxGROW);
1181 dial->SetSizer(dialSizer, true);
1185 int _tmpReadFileTypeOfTransformation = -1;
1186 //EED bool transform = false;
1188 if (dial->GetReturnCode() == wxID_OK)
1190 _tmpReadFileTypeOfTransformation = radioOpts->GetSelection();
1194 } // if interactiveOption
1201 void wxContourMainFrame::openContours( FILE *pFile, FILE *pFileData, bool staticContour )
1206 vtkImageData *image = _images[0];
1209 double imageSpac[3];
1210 image->GetDimensions(imageDim);
1211 image->GetSpacing(imageSpac);
1214 fscanf(pFile,"%s",tmp); // NumberOfContours
1215 fscanf(pFile,"%s",tmp); // ##
1216 int numberOfContours = atoi(tmp);
1218 std::vector<int> instantVector;
1219 int typeContourModel;
1220 manualBaseModel *manModelContour;
1224 if (compatible==true)
1227 for (i=0;i<numberOfContours;i++)
1229 instantVector.clear();
1230 fscanf(pFile,"%s",tmp); // Instant
1232 fscanf(pFile,"%s",tmp); // 1
1233 instantVector.push_back( atoi(tmp) );
1234 fscanf(pFile,"%s",tmp); // 2
1235 instantVector.push_back( atoi(tmp) );
1236 fscanf(pFile,"%s",tmp); // 3
1237 instantVector.push_back( atoi(tmp) );
1238 fscanf(pFile,"%s",tmp); // 4
1239 instantVector.push_back( atoi(tmp) );
1240 fscanf(pFile,"%s",tmp); // 5
1241 instantVector.push_back( atoi(tmp) );
1242 fscanf(pFile,"%s",tmp); // 6
1243 instantVector.push_back( atoi(tmp) );
1246 fscanf(pFile,"%s",tmp); // TypeContourModel
1247 fscanf(pFile,"%s",tmp); // ##
1248 typeContourModel = atoi(tmp);
1250 manModelContour = kernelManager->factoryManualContourModel(typeContourModel);
1251 manModelContour->Open(pFile);
1252 if(pFileData != NULL)
1254 manModelContour->OpenData(pFileData);
1257 fscanf(pFile,"%s",tmp); // TypeView
1258 fscanf(pFile,"%s",tmp); // ##
1259 typeView = atoi(tmp);
1261 std::string theName;
1262 theName = kernelManager->createOutline( manModelContour, instantVector );
1263 bool addedModel = theName.compare("") != 0;
1266 double spc[3];//Si no hay imagen pero hay contornos que spacing se pone por default
1267 _theViewPanel->getSpacing(spc);
1268 //Adding the manualContourControler to interface objects structure
1269 //Adding the manualViewContour to interface objects structure
1270 //_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.
1271 _theViewPanel->getSceneManager()->configureViewControlTo( theName, manModelContour,spc , typeView) ;
1274 if (staticContour) //StaticContours (will appear in all slices)
1276 Instant instant(&instantVector);
1277 kernelManager->changeContourOfManager( theName , &instant );
1280 }// for numberOfContours
1283 else if (compatible==false)
1288 for (i=0;i<numberOfContours;i++)
1290 instantVector.clear();
1291 fscanf(pFile,"%s",tmp); // Instant
1293 fscanf(pFile,"%s",tmp); // 1
1294 instantVector.push_back( atoi(tmp) );
1295 fscanf(pFile,"%s",tmp); // 2
1296 instantVector.push_back( atoi(tmp) );
1297 fscanf(pFile,"%s",tmp); // 3
1298 instantVector.push_back( atoi(tmp) );
1299 fscanf(pFile,"%s",tmp); // 4
1300 instantVector.push_back( atoi(tmp) );
1301 fscanf(pFile,"%s",tmp); // 5
1302 instantVector.push_back( atoi(tmp) );
1303 fscanf(pFile,"%s",tmp); // 6
1304 instantVector.push_back( atoi(tmp) );
1306 fscanf(pFile,"%s",tmp); // TypeContourModel
1307 fscanf(pFile,"%s",tmp); // ##
1308 typeContourModel = atoi(tmp);
1310 manModelContour = kernelManager->factoryManualContourModel(typeContourModel);
1311 manModelContour->Open(pFile);
1312 if(pFileData != NULL)
1314 manModelContour->OpenData(pFileData);
1317 if (_tmpReadFileTypeOfTransformation==-1){
1319 } else if (_tmpReadFileTypeOfTransformation==0){
1320 double transX, transY;
1321 transX = (double) imageDim[0]/_tmpReadFileImageDim[0];
1322 transY = (double) imageDim[1]/_tmpReadFileImageDim[1];
1323 manModelContour->Transform_Ax_Plus_B(transX,0,transY,0);
1324 } else if (_tmpReadFileTypeOfTransformation==1) {
1325 double transX, transY;
1326 transX = (double) _tmpReadFileImageSpac[0]/imageDim[0];
1327 transY = (double) _tmpReadFileImageSpac[1]/imageDim[1];
1328 manModelContour->Transform_Ax_Plus_B(transX,0,transY,0);
1331 fscanf(pFile,"%s",tmp); // TypeView
1332 fscanf(pFile,"%s",tmp); // ##
1333 typeView = atoi(tmp);
1335 std::string theName;
1336 theName = kernelManager->createOutline( manModelContour, instantVector );
1337 bool addedModel = theName.compare("") != 0;
1340 double spc[3];//Si no hay imagen pero hay contornos que spacing se pone por default
1341 _theViewPanel->getSpacing(spc);
1342 //Adding the manualContourControler to interface objects structure
1343 //Adding the manualViewContour to interface objects structure
1344 //_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.
1345 _theViewPanel->getSceneManager()->configureViewControlTo( theName, manModelContour,spc , typeView) ;
1348 if (staticContour) //StaticContours (will appear in all slices)
1350 Instant instant(&instantVector);
1351 kernelManager->changeContourOfManager( theName , &instant );
1353 }// for numberOfContours
1359 void wxContourMainFrame::RefreshInterface()
1362 _theViewPanel->RefreshInterface();
1363 //wxVtk2DBaseView *wxvtk2dbaseview = (wxVtk2DBaseView*)this->_theViewPanel->getWxVtkBaseView();
1364 //wxvtk2dbaseview->Refresh();
1367 vtkImageData* wxContourMainFrame::getImageData()
1369 return _theViewPanel->getImageData();
1372 void wxContourMainFrame::onSegmentationOneSliceITK(wxString distance, wxString sigma, wxString alfa, wxString beta, wxString propagation, wxString iterations, wxString inflation)
1374 //JCP 20-10-08 Undo redo implementation
1376 //JCP 20-10-08 Undo redo implementation
1379 int x = _theViewPanel->GetX();
1380 int y = _theViewPanel->GetY();
1381 int z = _theViewPanel->GetZ();
1382 SegmentationOneSliceITK( x,y,z,distance, sigma, alfa, beta, propagation, iterations, inflation);
1386 void wxContourMainFrame::SegmentationOneSliceITK(int x, int y, int z, wxString distanc, wxString sigm, wxString alf, wxString bet, wxString prop, wxString iter, wxString inflation)
1388 int typeofcontour = 1;
1390 vtkImageData *imagedata = getImageData();
1392 //Tipo de pixeles a utilizar internamente en ITK
1393 typedef float InternalPixelType;
1394 const unsigned int Dimension = 2;
1395 typedef itk::Image< InternalPixelType, Dimension > InternalImageType;
1397 //Tipo de pixeles de salida 1
1398 typedef unsigned char OutputPixelType;
1399 typedef itk::Image< OutputPixelType, Dimension > OutputImageType;
1401 //Tipo de pixeles de salida 2
1402 typedef unsigned short OutputPixelType2;
1403 typedef itk::Image< OutputPixelType2, Dimension > OutputImageType2;
1405 //DefiniciÛn del thresholder
1406 typedef itk::BinaryThresholdImageFilter<
1408 OutputImageType > ThresholdingFilterType;
1410 //DefiniciÛn del primer filtro de conversiÛn de pixeles
1411 typedef itk::CastImageFilter<
1412 OutputImageType, OutputImageType2 > CastFilterType;
1414 //DefiniciÛn del segundo tipo de conversiÛn de pixeles
1415 typedef itk::CastImageFilter<
1416 OutputImageType2, InternalImageType > CastFilterType2;
1418 //Tercer tipo de conversiÛn
1419 typedef itk::RescaleIntensityImageFilter<
1421 OutputImageType > CastFilterType3;
1423 //Cuarto tipo de conversiÛn
1424 typedef itk::RescaleIntensityImageFilter<
1426 OutputImageType > CastFilterType4;
1428 ThresholdingFilterType::Pointer thresholder = ThresholdingFilterType::New();
1430 thresholder->SetLowerThreshold( 0.0 );
1431 thresholder->SetUpperThreshold( 128 );
1433 thresholder->SetOutsideValue( 255 );
1434 thresholder->SetInsideValue( 0 );
1436 //DefinciÛn de conexiÛnes entre VTK e ITK y el writer
1437 typedef itk::VTKImageToImageFilter<OutputImageType2> ConnectorType;
1438 typedef itk::ImageToVTKImageFilter<OutputImageType> ConnectorType2;
1439 //EED10JUIN2011 typedef itk::ImageFileWriter< OutputImageType > WriterType;
1441 ConnectorType::Pointer connector= ConnectorType::New();
1442 ConnectorType2::Pointer connector2= ConnectorType2::New();
1445 CastFilterType::Pointer filter=CastFilterType::New();
1446 CastFilterType2::Pointer filter2=CastFilterType2::New();
1448 connector->SetInput( imagedata );
1449 filter2->SetInput(connector->GetOutput());
1451 typedef itk::CurvatureAnisotropicDiffusionImageFilter<
1453 InternalImageType > SmoothingFilterType;
1455 SmoothingFilterType::Pointer smoothing = SmoothingFilterType::New();
1457 typedef itk::GradientMagnitudeRecursiveGaussianImageFilter<
1459 InternalImageType > GradientFilterType;
1461 typedef itk::SigmoidImageFilter<
1463 InternalImageType > SigmoidFilterType;
1465 GradientFilterType::Pointer gradientMagnitude = GradientFilterType::New();
1467 SigmoidFilterType::Pointer sigmoid = SigmoidFilterType::New();
1469 sigmoid->SetOutputMinimum( 0.0 );
1470 sigmoid->SetOutputMaximum( 255.0 );
1473 typedef itk::FastMarchingImageFilter<
1475 InternalImageType > FastMarchingFilterType;
1478 FastMarchingFilterType::Pointer fastMarching = FastMarchingFilterType::New();
1480 printf("EED wxContourMainFrame::SegmentationOneSliceITK Skypping this code. Not compiling GeodesicActiveContourLevelSetImageFilter in fedora 17 with ITK 3.20.1 \n ");
1482 > - > - > - > - > - > - > - > - > - > - > - > - > - > - > - > - Not compiling GeodesicActiveContourLevelSetImageFilter in fedora 17 with ITK 3.20.1
1485 typedef itk::GeodesicActiveContourLevelSetImageFilter< InternalImageType,
1486 InternalImageType > GeodesicActiveContourFilterType;
1487 GeodesicActiveContourFilterType::Pointer geodesicActiveContour =
1488 GeodesicActiveContourFilterType::New();
1490 typedef itk::ZeroCrossingImageFilter<
1492 InternalImageType > ZeroCrossingFilterType;
1493 ZeroCrossingFilterType::Pointer zeroCrossing =
1494 ZeroCrossingFilterType::New();
1496 const double propagationScaling = atof( crea::wx2std(prop).c_str() );
1498 geodesicActiveContour->SetPropagationScaling( propagationScaling );
1499 geodesicActiveContour->SetCurvatureScaling( 1.0 );
1500 geodesicActiveContour->SetAdvectionScaling( 1.0 );
1502 geodesicActiveContour->SetMaximumRMSError( 0.02 );
1503 int it=atoi( crea::wx2std(iter).c_str() );
1504 geodesicActiveContour->SetNumberOfIterations( it );
1506 smoothing->SetInput( filter2->GetOutput() );
1507 gradientMagnitude->SetInput( smoothing->GetOutput() );
1508 sigmoid->SetInput( gradientMagnitude->GetOutput() );
1509 fastMarching->SetInput( sigmoid->GetOutput() );
1510 geodesicActiveContour->SetInput( fastMarching->GetOutput() );
1511 geodesicActiveContour->SetFeatureImage( sigmoid->GetOutput() );
1513 zeroCrossing->SetInput( geodesicActiveContour->GetOutput() );
1514 //thresholder->SetInput( zeroCrossing->GetOutput() );
1515 thresholder->SetInput( geodesicActiveContour->GetOutput() );
1516 connector2->SetInput( thresholder->GetOutput() );
1518 < - < - < - < - < - < - < - < - < - < - < - < - < - < - < - < - < - < - < - < -
1524 smoothing->SetTimeStep( 0.125 );
1525 smoothing->SetNumberOfIterations( 5 );
1526 smoothing->SetConductanceParameter( 9.0 );
1529 const double sigma = atof( crea::wx2std(sigm).c_str() );
1530 gradientMagnitude->SetSigma( sigma );
1532 const double alpha = atof( crea::wx2std(alf).c_str() );
1533 const double beta = atof( crea::wx2std(bet).c_str() );
1535 sigmoid->SetAlpha( alpha );
1536 sigmoid->SetBeta( beta );
1538 typedef FastMarchingFilterType::NodeContainer NodeContainer;
1539 typedef FastMarchingFilterType::NodeType NodeType;
1541 NodeContainer::Pointer seeds = NodeContainer::New();
1543 InternalImageType::IndexType seedPosition;
1544 seedPosition[0] = x;
1545 seedPosition[1] = y;
1547 const double initialDistance = atof( crea::wx2std(distanc).c_str() );
1551 const double seedValue = - initialDistance;
1553 node.SetValue( seedValue );
1554 node.SetIndex( seedPosition );
1556 seeds->Initialize();
1557 seeds->InsertElement( 0, node );
1559 fastMarching->SetTrialPoints( seeds );
1561 fastMarching->SetSpeedConstant( 1.0 );
1563 fastMarching->SetOutputSize(
1564 connector->GetOutput()->GetBufferedRegion().GetSize() );
1566 fastMarching->SetStoppingValue( 800 );
1570 connector2->Update();
1571 vtkImageData *idata = connector2->GetOutput();
1573 vtkMarchingContourFilter* cntVTK = vtkMarchingContourFilter::New( );
1575 cntVTK->SetNumberOfContours( 1 );
1576 cntVTK->SetValue( 0, 255 );
1577 //EED 2017-01-01 Migration VTK7
1578 #if VTK_MAJOR_VERSION <= 5
1579 cntVTK->SetInput( idata );
1581 cntVTK->UpdateInformation();
1583 cntVTK->SetInputData( idata );
1586 vtkCleanPolyData* cpd = vtkCleanPolyData::New( );
1588 //EED 2017-01-01 Migration VTK7
1589 #if VTK_MAJOR_VERSION <= 5
1590 cpd->SetInput( cntVTK->GetOutput( ) );
1592 cpd->UpdateInformation();
1594 cpd->SetInputData( cntVTK->GetOutput( ) );
1598 vtkPolyDataConnectivityFilter* conn = vtkPolyDataConnectivityFilter::New( );
1599 conn->SetExtractionModeToLargestRegion( );
1600 //EED 2017-01-01 Migration VTK7
1601 #if VTK_MAJOR_VERSION <= 5
1602 conn->SetInput( cpd->GetOutput( ) );
1604 conn->UpdateInformation();
1606 conn->SetInputData( cpd->GetOutput( ) );
1610 vtkStripper* vtkstripper = vtkStripper::New( );
1612 //EED 2017-01-01 Migration VTK7
1613 #if VTK_MAJOR_VERSION <= 5
1614 vtkstripper->SetInput( conn->GetOutput() );
1615 vtkstripper->Update();
1616 vtkstripper->UpdateInformation();
1618 vtkstripper->SetInputData( conn->GetOutput() );
1622 vtkPolyData* polyDataResult = cntVTK->GetOutput();
1623 //std::cout<<"Points "<<polyDataResult->GetNumberOfPoints()<<std::endl;
1625 //EED 2017-01-01 Migration VTK7
1626 #if VTK_MAJOR_VERSION <= 5
1627 polyDataResult->Update( );
1628 polyDataResult->UpdateInformation();
1636 myfile.open ("C:/Creatis/example.txt");
1638 polyDataResult->Print(myfile);
1639 myfile << "-------------------------------------\n";
1640 polyDataResult->GetLines()->Print(myfile);
1648 //--Calculating control points
1650 std::vector<double> vecX;
1651 std::vector<double> vecY;
1652 std::vector<double> vecXo;
1653 std::vector<double> vecYo;
1654 std::vector<double>::iterator vecXoi;
1655 std::vector<double>::iterator vecYoi;
1656 std::vector<double> vecZ;
1658 std::vector<double> vecCtrlPointX;
1659 std::vector<double> vecCtrlPointY;
1660 std::vector<double> vecCtrlPointZ;
1666 int ii,size=polyDataResult->GetNumberOfPoints();
1668 myfile.open ("C:/Creatis/example2.txt");
1670 size=polyDataResult->GetNumberOfPoints();
1671 for (ii=0;ii<size;ii++)
1678 p = polyDataResult->GetPoint(ii);
1681 /*if(fabs(yAct-y)>20)
1683 if((xAct-x)>1 || (xAct-x)<-1)
1685 vecX.push_back( p[0] );
1686 vecY.push_back( p[1] );
1687 myfile <<p[0]<<","<<p[1]<<"\n";
1688 std::cout<<" x Anterior "<<xAct<<" x actual "<<x<<std::endl;
1689 std::cout<<" y Anterior "<<yAct<<" y actual "<<y<<std::endl;
1690 std::cout<<" x "<<p[0]<<" y "<<p[1]<<std::endl;
1691 vecZ.push_back( 900 );
1697 vecXo.push_back(p[0]);
1698 vecYo.push_back(p[1]);
1702 else*/ if(fabs(xAct-x)>11)
1704 vecXo.push_back(p[0]);
1705 vecYo.push_back(p[1]);
1709 vecX.push_back( p[0] );
1710 myfile <<p[0]<<","<<p[1]<<"\n";
1711 //std::cout<<" x Anterior "<<xAct<<" x actual "<<x<<std::endl;
1712 //std::cout<<" y Anterior "<<yAct<<" y actual "<<y<<std::endl;
1713 //std::cout<<" x "<<p[0]<<" y "<<p[1]<<std::endl;
1714 vecY.push_back( p[1] );
1715 vecZ.push_back( 900 );
1723 while(!vecXo.empty())
1725 vecX.push_back(vecXo.back());
1726 //std::cout<<" x Siguiente "<<vecXo.back();
1728 vecZ.push_back( 900 );
1730 while(!vecYo.empty())
1732 vecY.push_back(vecYo.back());
1737 /*for(int l=0;l<vecX.size();l++)
1741 vecXo.push_back(p[0]);
1742 vecYo.push_back(p[1]);
1753 ExtractControlPoints2D *extractcontrolpoints2d = new ExtractControlPoints2D();
1755 extractcontrolpoints2d->SetContour( &vecX , &vecY , &vecZ );
1759 extractcontrolpoints2d->GetInitialControlPoints( &vecCtrlPointX , &vecCtrlPointY , &vecCtrlPointZ );
1761 else if (method==1){
1762 extractcontrolpoints2d->GetControlPoints( &vecCtrlPointX , &vecCtrlPointY , &vecCtrlPointZ );
1764 else if (method==2){
1765 extractcontrolpoints2d->SetSamplingControlPoints( 15 );
1766 extractcontrolpoints2d->GetSamplingControlPoints( &vecCtrlPointX , &vecCtrlPointY , &vecCtrlPointZ );
1768 //--Adding contour to the system
1770 std::vector<int> actualInstantVector;
1771 _instantPanel->getInstant( actualInstantVector );
1772 actualInstantVector[1]=z;
1774 int j,sizeCtrPt = vecCtrlPointX.size();
1776 manualBaseModel *manModelContour = kernelManager->factoryManualContourModel( typeofcontour );
1777 manModelContour->SetNumberOfPointsSpline( ((sizeCtrPt/100)+1)*100 );
1779 for (j=0 ; j<sizeCtrPt ; j++)
1781 manModelContour->AddPoint( vecCtrlPointX[j] , vecCtrlPointY[j] , vecCtrlPointZ[j] );
1783 std::string theName;
1784 //theName = _modelManager->createOutline( manModelContour, actualInstantVector );
1785 theName = kernelManager->createOutline( manModelContour, actualInstantVector );
1786 bool addedModel = theName.compare("") != 0;
1789 double spc[3];//Si no hay imagen pero hay contornos que spacing se pone por default
1790 _theViewPanel->getSpacing(spc);
1791 //Adding the manualContourControler to interface objects structure
1792 //Adding the manualViewContour to interface objects structure
1793 //_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.
1794 _theViewPanel->configureViewControlTo(theName, manModelContour, spc, typeofcontour);
1795 //_theViewPanel->getSceneManager()->configureViewControlTo( theName, manModelContour,spc, typeofcontour ) ;
1802 WriterType::Pointer writer = WriterType::New();
1803 CastFilterType3::Pointer caster = CastFilterType3::New();
1805 caster->SetInput( gradientMagnitude->GetOutput() );
1806 writer->SetInput( caster->GetOutput() );
1807 writer->SetFileName("Gradient Magnitude.png");
1808 caster->SetOutputMinimum( 0 );
1809 caster->SetOutputMaximum( 255 );
1812 CastFilterType3::Pointer caster2 = CastFilterType3::New();
1813 WriterType::Pointer writer2 = WriterType::New();
1815 caster2->SetInput( sigmoid->GetOutput() );
1816 writer2->SetInput( caster2->GetOutput() );
1817 writer2->SetFileName("Sigmoid.png");
1818 caster2->SetOutputMinimum( 0 );
1819 caster2->SetOutputMaximum( 255 );
1822 CastFilterType3::Pointer caster3 = CastFilterType3::New();
1823 WriterType::Pointer writer3 = WriterType::New();
1825 caster3->SetInput( fastMarching->GetOutput() );
1826 writer3->SetInput( caster3->GetOutput() );
1827 writer3->SetFileName("FastMarching.bmp");
1828 caster3->SetOutputMinimum( 0 );
1829 caster3->SetOutputMaximum( 255 );
1832 CastFilterType3::Pointer caster4 = CastFilterType3::New();
1833 WriterType::Pointer writer4 = WriterType::New();
1835 caster4->SetInput( geodesicActiveContour->GetOutput() );
1836 writer4->SetInput( caster4->GetOutput() );
1837 writer4->SetFileName("GeodesicActiveContour.png");
1838 caster4->SetOutputMinimum( 0 );
1839 caster4->SetOutputMaximum( 255 );
1842 CastFilterType3::Pointer caster5 = CastFilterType3::New();
1843 WriterType::Pointer writer5 = WriterType::New();
1845 caster5->SetInput( zeroCrossing->GetOutput() );
1846 writer5->SetInput( caster5->GetOutput() );
1847 writer5->SetFileName("ZeroCrossing.bmp");
1848 caster5->SetOutputMinimum( 0 );
1849 caster5->SetOutputMaximum( 255 );
1853 catch( itk::ExceptionObject & excep )
1855 std::cerr << "Exception caught !" << std::endl;
1856 std::cerr << excep << std::endl;
1860 void wxContourMainFrame::onSegmentationOneSlice(int isovalue,int sampling,int method){
1862 //JCP 20-10-08 Undo redo implementation
1864 //JCP 20-10-08 Undo redo implementation
1867 int x = _theViewPanel->GetX();
1868 int y = _theViewPanel->GetY();
1869 int z = _theViewPanel->GetZ();
1870 SegmentationOneSlice( x,y,z,isovalue, sampling, method );
1875 void wxContourMainFrame::SegmentationOneSlice( int x, int y, int z, int isovalue, int sampling, int method )
1877 int typeofcontour = 1;
1878 //--Extracting Contour
1879 //vtkImageData *imagedata = _theViewPanel->getSceneManager()->GetImageData();
1880 vtkImageData *imagedata = getImageData();
1881 // double *range = imagedata->GetScalarRange();
1884 vtkImageReslice *imageReslice = vtkImageReslice::New();
1887 // imagedata->GetSpacing(spc);
1892 //EED 2017-01-01 Migration VTK7
1893 #if VTK_MAJOR_VERSION <= 5
1894 imageReslice->SetInput( imagedata );
1896 imageReslice->SetInputData( imagedata );
1898 imageReslice->SetInformationInput(imagedata);
1899 imageReslice->SetResliceAxesDirectionCosines(1,0,0, 0,1,0 ,0,0,1);
1900 imageReslice->SetResliceAxesOrigin(0,0,z);
1901 imageReslice->SetOutputDimensionality(2);
1902 imageReslice->SetInterpolationModeToLinear();
1904 //EED 2017-01-01 Migration VTK7
1905 #if VTK_MAJOR_VERSION <= 5
1908 imageReslice->Update();
1911 imagedata = imageReslice->GetOutput();
1912 //EED 2017-01-01 Migration VTK7
1913 #if VTK_MAJOR_VERSION <= 5
1914 imagedata->Update();
1915 imagedata->UpdateInformation();
1920 vtkContourFilter* cntVTK = vtkContourFilter::New( );
1921 //EED 2017-01-01 Migration VTK7
1922 #if VTK_MAJOR_VERSION <= 5
1923 cntVTK->SetInput( imagedata );
1925 cntVTK->SetInputData( imagedata );
1928 cntVTK->SetNumberOfContours( 1 );
1929 //cntVTK->SetValue( 0, vmin );
1930 // cntVTK->SetValue( 0, (range[1]*thr/100) );
1931 cntVTK->SetValue( 1, isovalue );
1932 // cntVTK->SetValue( 1, vmax );
1934 cntVTK->UpdateInformation();
1936 vtkCleanPolyData* cpd = vtkCleanPolyData::New( );
1937 //EED 2017-01-01 Migration VTK7
1938 #if VTK_MAJOR_VERSION <= 5
1939 cpd->SetInput( cntVTK->GetOutput( ) );
1941 cpd->SetInputData( cntVTK->GetOutput( ) );
1943 cpd->ConvertLinesToPointsOff( );
1945 cpd->UpdateInformation();
1947 vtkPolyDataConnectivityFilter* conn = vtkPolyDataConnectivityFilter::New( );
1948 conn->SetExtractionModeToClosestPointRegion( );
1949 //conn->SetMaxRecursionDepth( 3000 );
1951 //EED 2017-01-01 Migration VTK7
1952 #if VTK_MAJOR_VERSION <= 5
1953 conn->SetInput( cpd->GetOutput( ) );
1955 conn->SetInputData( cpd->GetOutput( ) );
1958 conn->SetClosestPoint( x, y, 0 );
1960 conn->UpdateInformation();
1962 vtkCleanPolyData* cpd2 = vtkCleanPolyData::New( );
1963 //EED 2017-01-01 Migration VTK7
1964 #if VTK_MAJOR_VERSION <= 5
1965 cpd2->SetInput( conn->GetOutput( ) );
1967 cpd2->SetInputData( conn->GetOutput( ) );
1970 cpd2->UpdateInformation();
1972 vtkStripper* vtkstripper = vtkStripper::New( );
1973 //EED 2017-01-01 Migration VTK7
1974 #if VTK_MAJOR_VERSION <= 5
1975 vtkstripper->SetInput( cpd2->GetOutput() );
1977 vtkstripper->SetInputData( cpd2->GetOutput() );
1979 vtkstripper->Update();
1980 vtkstripper->UpdateInformation();
1983 vtkPolyData* polyDataResult = vtkstripper->GetOutput();
1985 //EED 2017-01-01 Migration VTK7
1986 #if VTK_MAJOR_VERSION <= 5
1987 polyDataResult->Update( );
1988 polyDataResult->UpdateInformation();
1995 myfile.open ("c:/temp/example.txt");
1997 polyDataResult->Print(myfile);
1998 myfile << "-------------------------------------\n";
1999 polyDataResult->GetLines()->Print(myfile);
2009 //--Calculating control points
2011 std::vector<double> vecX;
2012 std::vector<double> vecY;
2013 std::vector<double> vecZ;
2015 std::vector<double> vecCtrlPointX;
2016 std::vector<double> vecCtrlPointY;
2017 std::vector<double> vecCtrlPointZ;
2021 int ii,size=polyDataResult->GetNumberOfPoints();
2023 for (ii=1;ii<=size;ii++)
2025 id = polyDataResult->GetLines()->GetData()->GetValue(ii);
2026 p = polyDataResult->GetPoint(id);
2029 vecX.push_back( p[0] );
2030 vecY.push_back( p[1] );
2031 vecZ.push_back( 900 );
2032 // vecZ.push_back( p[2] );
2036 ExtractControlPoints2D *extractcontrolpoints2d = new ExtractControlPoints2D();
2037 extractcontrolpoints2d->SetContour( &vecX , &vecY , &vecZ );
2040 /*if (methodRadiobox->GetSelection()==0){
2041 extractcontrolpoints2d->GetInitialControlPoints( &vecCtrlPointX , &vecCtrlPointY , &vecCtrlPointZ );
2043 if (methodRadiobox->GetSelection()==1){
2044 extractcontrolpoints2d->GetControlPoints( &vecCtrlPointX , &vecCtrlPointY , &vecCtrlPointZ );
2046 if (methodRadiobox->GetSelection()==2){
2047 extractcontrolpoints2d->SetSamplingControlPoints( sampling );
2048 extractcontrolpoints2d->GetSamplingControlPoints( &vecCtrlPointX , &vecCtrlPointY , &vecCtrlPointZ );
2052 extractcontrolpoints2d->GetInitialControlPoints( &vecCtrlPointX , &vecCtrlPointY , &vecCtrlPointZ );
2054 else if (method==1){
2055 extractcontrolpoints2d->GetControlPoints( &vecCtrlPointX , &vecCtrlPointY , &vecCtrlPointZ );
2057 else if (method==2){
2058 extractcontrolpoints2d->SetSamplingControlPoints( sampling );
2059 extractcontrolpoints2d->GetSamplingControlPoints( &vecCtrlPointX , &vecCtrlPointY , &vecCtrlPointZ );
2062 //--Adding contour to the system
2064 std::vector<int> actualInstantVector;
2065 _instantPanel->getInstant( actualInstantVector );
2066 actualInstantVector[1]=z;
2068 int j,sizeCtrPt = vecCtrlPointX.size();
2069 manualBaseModel *manModelContour = kernelManager->factoryManualContourModel( typeofcontour );
2070 manModelContour->SetNumberOfPointsSpline( ((sizeCtrPt/100)+1)*100 );
2072 for (j=0 ; j<sizeCtrPt ; j++)
2074 manModelContour->AddPoint( vecCtrlPointX[j] , vecCtrlPointY[j] , vecCtrlPointZ[j] );
2076 std::string theName;
2077 //theName = _modelManager->createOutline( manModelContour, actualInstantVector );
2078 theName = kernelManager->createOutline( manModelContour, actualInstantVector );
2079 bool addedModel = theName.compare("") != 0;
2082 double spc[3];//Si no hay imagen pero hay contornos que spacing se pone por default
2083 _theViewPanel->getSpacing(spc);
2084 //Adding the manualContourControler to interface objects structure
2085 //Adding the manualViewContour to interface objects structure
2086 //_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.
2087 _theViewPanel->configureViewControlTo(theName, manModelContour, spc, typeofcontour);
2088 //_theViewPanel->getSceneManager()->configureViewControlTo( theName, manModelContour,spc, typeofcontour ) ;
2092 int wxContourMainFrame::GetImageDataSizeZ(){
2093 return _theViewPanel->GetImageDataSizeZ();
2096 void wxContourMainFrame::GetImageDataRange(double *range){
2097 _theViewPanel->GetImageDataRange(range);
2100 void wxContourMainFrame::onSegmentationAllSlice(int minZ,int maxZ,int isovalue,int sampling,int method){
2101 //JCP 20-10-08 Undo redo implementation
2103 //JCP 20-10-08 Undo redo implementation
2106 int x = _theViewPanel->GetX();
2107 int y = _theViewPanel->GetY();
2111 double totalZ = maxZ-minZ+1;
2112 for( z=minZ ; z<=maxZ ; z++ )
2114 porcent = 100.0* (z-minZ)/totalZ;
2115 tmpString.Printf(_T(" %d %c %d/%d %d"), (int)porcent , 37 , z-minZ+1, (int)totalZ,z );
2116 interfMainPanel::getInstance()->setLabelSegmentationPanelVTK(tmpString);
2117 //_staticTextSegmentation->SetLabel(tmpString);
2118 SegmentationOneSlice( x,y,z,isovalue, sampling,method );
2120 interfMainPanel::getInstance()->setLabelSegmentationPanelVTK(_T(" "));
2125 //Creates a reference line to be used as the axis of the mirroring
2126 void wxContourMainFrame::referenceLine()
2128 if (_refLineControl==NULL)
2133 vtkImageData *vtkimagedata = _theViewPanel->getImageData();
2134 vtkimagedata->GetSpacing(spc);
2136 wxVtkBaseView * viewer2D = _theViewPanel->getWxVtkBaseView();
2138 _refLineControl = new manualLineControler();
2139 _refLineModel = new manualContourModelLine();
2140 _refLineView = new manualViewLine();
2141 _refLineView->SetModel( _refLineModel );
2142 _refLineView->SetWxVtkBaseView( viewer2D );
2143 _refLineView->SetRange( 2 );
2144 _refLineView->SetZ( 1200 );
2146 _refLineView->SetSpacing(spc);
2148 _refLineView->SetColorNormalContour(0, 0, 1);
2149 _refLineView->SetColorEditContour(0, 0.5, 0.5);
2150 _refLineView->SetWidthLine(4);
2152 _refLineControl->SetModelView( _refLineModel , _refLineView );
2153 vtkInteractorStyleBaseView* style = (vtkInteractorStyleBaseView*)viewer2D->GetInteractorStyleBaseView();
2154 style->AddInteractorStyleMaracas( _refLineControl );
2155 _refLineModel->SetCloseContour(false);
2156 _refLineControl->CreateNewManualContour();
2158 //AD: Inicializar el mirroring con una linea ya pintada
2160 double z = _refLineControl->GetZ();
2163 image->GetDimensions(imageDim);
2164 double x = (double) imageDim[0]/2;
2165 double y1 = (double) (imageDim[1]/2)+15;
2166 double y2 = (double) (imageDim[1]/2)-15;
2168 _refLineControl->AddPoint(x,y1,z);
2169 _refLineControl->AddPoint(x,y2,z);
2170 _refLineControl->SetCompleteCreation(true);
2172 _refLineModel->AddPoint(x,y1,z);
2173 _refLineModel->AddPoint(x,y2,z);
2174 _refLineModel->UpdateSpline();
2176 _refLineView->UpdateViewPoint(0);
2177 _refLineView->UpdateViewPoint(1);
2180 _refLineControl->SetActive(true);
2181 _refLineView->RefreshContour();
2185 //Hides the referenceLine
2186 void wxContourMainFrame::refLineHide()
2188 if (_refLineControl!=NULL)
2190 if (_refLineControl->GetActive())
2192 _refLineView->RemoveCompleteContourActor();
2193 _refLineControl->SetEditable(false);
2194 _refLineControl->SetActive(false);
2201 //Shows the referenceLine
2202 void wxContourMainFrame::refLineShow()
2204 if (_refLineControl!=NULL)
2206 if (_refLineControl->GetActive()==false)
2208 wxVtkBaseView * viewer2D = _theViewPanel->getWxVtkBaseView();
2210 _refLineView->SetModel( _refLineModel );
2211 _refLineView->SetWxVtkBaseView( viewer2D );
2212 _refLineView->SetRange( 2 );
2213 _refLineView->SetZ( 1200 );
2215 _refLineControl->SetModelView( _refLineModel , _refLineView );
2216 vtkInteractorStyleBaseView* style = (vtkInteractorStyleBaseView*)viewer2D->GetInteractorStyleBaseView();
2217 style->AddInteractorStyleMaracas( _refLineControl );
2218 _refLineControl->CreateNewManualContour();
2219 _refLineControl->SetActive(true);
2220 _refLineView->RefreshContour();
2227 void wxContourMainFrame::refLineChangeWidth(int width)
2229 _refLineView->SetWidthLine(width);
2230 _refLineView->RefreshContour();
2236 void wxContourMainFrame::onMirror()
2239 std::vector<std::string> currentSelection = _theViewPanel->getSelectedObjects();
2240 std::vector<std::string> filterCurrentSelection;
2242 std::vector<int> tempVector;
2243 _instantPanel->getInstant( tempVector );
2244 _performingOperation->reset();
2245 _performingOperation->setStartCommand( COPY );
2246 _performingOperation->setStartOperationInstantVector( tempVector );
2247 _performingOperation->setKeyNamesOperationElems( currentSelection );
2249 char theStartCommand = _performingOperation->getStartCommand();
2250 if ( theStartCommand == COPY )
2252 //JCP 20-10-08 Undo redo implementation
2254 //JCP 20-10-08 Undo redo implementation
2255 std::vector<int> tempVector;
2256 _instantPanel->getInstant( tempVector );
2257 _performingOperation->setEndOperationInstantVector ( tempVector );
2258 std::vector<std::string> elems = _performingOperation->getKeyNamesOperationElems();
2259 int i,size = elems.size();
2260 for( i=0; i<size; i++ )
2262 createMirrorContourOf( elems[i], tempVector, i>0 );
2266 //deleteContour( _refName );
2271 void wxContourMainFrame::showAxis(bool show)
2273 _theViewPanel->SetVisibleAxis(show);
2274 _theViewPanel->Refresh();
2278 void wxContourMainFrame::onRigidPressed(){
2279 std::vector<std::string> currentSelection = _theViewPanel->getSelectedObjects();
2280 int elementsSelected = currentSelection.size();
2282 if ( elementsSelected >= 1 ){
2283 //JCP 20-10-08 Undo redo implementation
2285 //JCP 20-10-08 Undo redo implementation
2287 std::vector<int> tempVector;
2288 _instantPanel->getInstant( tempVector );
2289 Instant instant(&tempVector);
2291 int i , size=currentSelection.size();
2292 for ( i=0 ; i<size ; i++ )
2294 kernelManager->changeContourOfManager(currentSelection[i], &instant);
2299 void wxContourMainFrame::onWidthOfContour(double width){
2301 _theViewPanel->removeSceneContours();
2302 _theViewPanel->SetWidthContour(width);
2304 //_theViewPanel->getSceneManager()->SetWidthContour( width );
2309 int wxContourMainFrame::getColorWindow()
2313 vtkImageData * img = getImageData();
2314 img->GetScalarRange(range);
2316 std::cout<<"Val 1: "<<range[0]<<" Val 2: "<<range[1]<<std::endl;
2318 return (int)range[1];
2320 return _theViewPanel->getColorWindow();
2323 int wxContourMainFrame::getWindowLevel()
2327 vtkImageData * img = getImageData();
2328 img->GetScalarRange(range);
2330 std::cout<<"Val 1: "<<range[0]<<" Val 2: "<<range[1]<<std::endl;
2332 return (int)range[1];
2334 return _theViewPanel->getWindowLevel();
2337 void wxContourMainFrame::onBrigthnessColorWindowLevel(int colorwindow,int windowlevel)
2339 _theViewPanel->onBrigthnessColorWindowLevel(colorwindow, windowlevel);
2344 void wxContourMainFrame::onInterpolation(bool interpolate)
2346 _theViewPanel->onInterpolation(interpolate);
2350 void wxContourMainFrame::onChangeInstant(std::string name,int actual)
2352 _instantPanel->setConceptValue( name, actual );
2356 void wxContourMainFrame::resetAppend()
2358 kernelManager->resetAppend();
2362 void wxContourMainFrame::onSpreadAdd()
2364 std::vector<double> vecX;
2365 std::vector<double> vecY;
2366 std::vector<double> vecZ;
2367 _theViewPanel->GetPointsOfActualContour(&vecX , &vecY , &vecZ );
2368 std::vector<int> tempVector;
2369 _instantPanel->getInstant( tempVector );
2370 std::string val = kernelManager->onSpreadAdd(&vecX , &vecY , &vecZ, tempVector);
2371 interfMainPanel::getInstance()->appendStringSpread(val);
2375 void wxContourMainFrame::onSpreadAddAll()
2378 std::vector<int> tempVector;
2379 _instantPanel->getInstant( tempVector );
2382 maxZ = interfMainPanel::getInstance()->GetImageDataSizeZ();
2384 int sizeLstContourThings;
2385 for ( z=minZ ; z<=maxZ ; z++ )
2388 Instant instant(&tempVector);
2389 std::vector<ContourThing**> lstContourThings = kernelManager->getOutlinesAtInstant( &instant );
2390 sizeLstContourThings = lstContourThings.size();
2391 if (sizeLstContourThings>=1)
2393 std::vector<double> vecX;
2394 std::vector<double> vecY;
2395 std::vector<double> vecZ;
2396 ContourThing **contourthing = lstContourThings[0];
2397 manualBaseModel *cModel = (*contourthing)->getModel();
2398 int i,size = cModel->GetNumberOfPointsSpline();
2400 for (i=0; i<size; i++)
2402 cModel->GetSpline_i_Point(i, &x, &y, &z);
2407 std::string val = kernelManager->onSpreadAdd(&vecX , &vecY , &vecZ, tempVector);
2408 interfMainPanel::getInstance()->appendStringSpread(val);
2409 }// if sizeLstContourThings
2414 void wxContourMainFrame::onSpreadGo(int type)
2416 //JCP 20-10-08 Undo redo implementation
2418 //JCP 20-10-08 Undo redo implementation
2420 std::vector<double> vecCtrlPointX;
2421 std::vector<double> vecCtrlPointY;
2422 std::vector<double> vecCtrlPointZ;
2426 std::vector<int> tempVector;
2427 _instantPanel->getInstant( tempVector );
2430 kernelManager->getMaxMinZ(&minZ,&maxZ);
2431 //JSTG_16-07-08_----------------------------------------------------------------
2432 //_contourPropagation->setInterpolationNumber(maxZ-minZ+1);
2433 kernelManager->CalculeSplinePropagation();
2435 double totalZ = maxZ-minZ+1;
2438 //--------------------------------------------------------------------
2439 for ( z=(int)minZ ; z<=(int)maxZ ; z++ )
2441 porcent = 100.0* (z-minZ)/totalZ;
2442 int numero = (int)(z-minZ+1)/(int)totalZ;
2443 std::string stringtemp = " "+kernelManager->intToString(porcent)+"% "+kernelManager->intToString(numero)+" "+kernelManager->intToString(z);
2445 interfMainPanel::getInstance()->setStringSpread(stringtemp);
2447 int typeofcontour = 1;
2448 std::string theName;
2449 manualBaseModel* manModelContour = kernelManager->GetPoints(z, type, &vecCtrlPointX,&vecCtrlPointY,&vecCtrlPointZ, theName,typeofcontour, tempVector);
2451 if( manModelContour!=NULL ){
2452 double spc[3];//Si no hay imagen pero hay contornos que spacing se pone por default
2453 this->_theViewPanel->getSpacing(spc);
2454 //Adding the manualContourControler to interface objects structure
2455 //Adding the manualViewContour to interface objects structure
2456 //_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.
2457 _theViewPanel->configureViewControlTo( theName, manModelContour,spc,typeofcontour ) ;
2462 int numero = (int)(z-minZ+1)/(int)totalZ;
2463 std::string stringtemp = " "+kernelManager->intToString(porcent)+"% "+kernelManager->intToString(numero)+" "+kernelManager->intToString(z);
2465 interfMainPanel::getInstance()->setStringSpread(stringtemp);
2467 //RefreshInterface();
2470 void wxContourMainFrame::getInstantVector(std::vector<int>& tempVector)
2474 std::vector<std::string> wxContourMainFrame::getOutlinesName(int slide)
2476 std::vector<int> tempVector;
2477 _instantPanel->getInstant(tempVector);
2478 //Asignation of slide number should be different ex by name
2479 tempVector[1]=slide;
2480 return kernelManager->getOutlinesNameAtInstant(tempVector);
2484 void wxContourMainFrame::SetScalarRange(int grayRangeMin, int grayRangeMax)
2486 _contourextractdata->SetScalarRange(grayRangeMin,grayRangeMax);
2490 void wxContourMainFrame::onInformationContourLabels(int typeContourGroup,int selection,int minimumZ,int maximumZ,int grayRangeMin, int grayRangeMax)
2493 wxString tempString;
2494 int maxContourGroup = 0;
2496 _contourextractdata ->SetTypeOperation( typeContourGroup % 3 );
2498 std::vector<manualBaseModel*> lstManConMod;
2499 std::vector<manualBaseModel*> lstManConModTmp;
2500 std::vector<manualBaseModel*> lstManConModExp;
2501 std::vector<double> pLstValue;
2502 std::vector<double> pLstValuePosX;
2503 std::vector<double> pLstValuePosY;
2504 std::vector<double> pLstValuePosZ;
2507 int resultGrayRangeCount;
2510 double resultAverage;
2511 double resultStandardeviation;
2513 std::vector<int> tempVector;
2514 _instantPanel->getInstant( tempVector );
2517 int ii,sizeLstContourThings;
2526 if (selection==0 ) // actual slice
2528 int actualSlice = tempVector[1];
2531 } else { // slice range
2537 totalZ = maxZ-minZ+1;
2539 _contourextractdata->InitVolumeStatistics();
2542 for ( z=minZ ; z<=maxZ ; z++ )
2545 porcent = 100.0* (z-minZ)/totalZ;
2546 tmpString.Printf(_T(" %d %c %d/%d %d"), (int)porcent , 37 , z-minZ+1, (int)totalZ ,z);
2548 interfMainPanel::getInstance()->setStringInfoPanel(tmpString);
2549 //_staticTextInformation->SetLabel(tmpString);
2551 //Extraction data from contours of each slice
2552 _contourextractdata->SetZtoBeAnalys(z);
2555 Instant instant(&tempVector);
2556 std::vector<ContourThing**> lstContourThings = kernelManager->getOutlinesAtInstant( &instant );
2557 sizeLstContourThings = lstContourThings.size();
2559 lstManConMod.clear();
2560 for (ii=0 ; ii<sizeLstContourThings ; ii++)
2562 ContourThing **contourthing = lstContourThings[ii];
2563 lstManConMod.push_back( (*contourthing)->getModel() );
2566 lstManConModExp = kernelManager->ExploseEachModel( lstManConMod );
2568 tempString.Printf(_T("%d - %d"),z, sizeLstContourThings);
2569 interfMainPanel::getInstance()->setRowLabelInfoPanel(z, tempString);
2570 //_grid->SetRowLabelValue(z, tempString );
2572 int iContourGroup,sizeContourGroup;
2573 if (typeContourGroup==3) // contour separete
2575 sizeContourGroup=lstManConModExp.size();
2576 if ( maxContourGroup<sizeContourGroup )
2578 maxContourGroup=sizeContourGroup;
2580 } else { // contour AND OR XOR
2587 for( iContourGroup=0 ; iContourGroup<sizeContourGroup ; iContourGroup++ ){
2588 lstManConModTmp.clear();
2592 if (typeContourGroup==3) // contour separete
2594 lstManConModTmp.push_back( lstManConModExp[iContourGroup]);
2595 } else { // contour AND OR XOR
2596 lstManConModTmp = lstManConModExp;
2599 _contourextractdata->SetLstManualContourModel( lstManConModTmp );
2600 _contourextractdata->SetScalarRange(grayRangeMin,grayRangeMax);
2603 pLstValuePosX.clear();
2604 pLstValuePosY.clear();
2605 pLstValuePosZ.clear();
2609 _contourextractdata->GetValuesInsideCrown( &numberOfPixels,
2615 resultSize=numberOfPixels;
2616 // Statistics of each slice.
2617 _contourextractdata->Statistics( &pLstValue,
2620 &resultGrayRangeCount,
2625 &resultStandardeviation);
2627 if (interfMainPanel::getInstance()->getNumberColsInformationPanel()<_numberOfVariablesStatistics*(iContourGroup+1) )
2629 interfMainPanel::getInstance()->appendColsInformationPanel(_numberOfVariablesStatistics);
2632 tmpIntA=_numberOfVariablesStatistics*iContourGroup ;
2634 tempString.Printf(_T("%d"),numberOfPixels);
2636 interfMainPanel::getInstance()->setCellValueInfoPanel(z, tmpIntA, tempString);
2638 tempString.Printf(_T("%d"),resultGrayRangeCount);
2639 interfMainPanel::getInstance()->setCellValueInfoPanel(z, tmpIntA+1, tempString);
2641 tempString.Printf(_T("%f"),resultMin);
2642 interfMainPanel::getInstance()->setCellValueInfoPanel(z, tmpIntA+2, tempString);
2644 tempString.Printf(_T("%f"),resultMax);
2645 interfMainPanel::getInstance()->setCellValueInfoPanel(z, tmpIntA+3, tempString);
2647 tempString.Printf(_T("%f"),resultAverage);
2648 interfMainPanel::getInstance()->setCellValueInfoPanel(z, tmpIntA+4, tempString);
2650 tempString.Printf(_T("%f"),resultStandardeviation);
2651 interfMainPanel::getInstance()->setCellValueInfoPanel(z, tmpIntA+5, tempString);
2654 } // for iContourGroup
2657 // Print Volume Statistics
2660 int vol_rCountRange;
2662 double vol_minValue;
2663 double vol_maxValue;
2665 double vol_standardeviation;
2667 if (selection!=0 ) // actual slice
2670 _contourextractdata->GetVolumeStatistics(&vol_rCountRange, &vol_rsize,
2671 &vol_minValue, &vol_maxValue,
2672 &vol_average, &vol_standardeviation);
2674 interfMainPanel::getInstance()->setRowLabelInfoPanel(maxZ+2, _T("Total:"));
2676 tempString.Printf(_T("%d"),vol_rsize);
2677 interfMainPanel::getInstance()->setCellValueInfoPanel(maxZ+2, 0, tempString);
2679 tempString.Printf(_T("%d"),vol_rCountRange);
2680 interfMainPanel::getInstance()->setCellValueInfoPanel(maxZ+2, 1, tempString);
2682 tempString.Printf(_T("%f"),vol_minValue);
2683 interfMainPanel::getInstance()->setCellValueInfoPanel(maxZ+2, 2, tempString);
2685 tempString.Printf(_T("%f"),vol_maxValue);
2686 interfMainPanel::getInstance()->setCellValueInfoPanel(maxZ+2, 3, tempString);
2688 tempString.Printf(_T("%f"),vol_average);
2689 interfMainPanel::getInstance()->setCellValueInfoPanel(maxZ+2, 4, tempString);
2691 tempString.Printf(_T("%f"),vol_standardeviation);
2692 interfMainPanel::getInstance()->setCellValueInfoPanel(maxZ+2, 5, tempString);
2694 //-----------------------------------------
2697 wxString tmpTitleString;
2699 for ( iTitleGroup=0 ; iTitleGroup<maxContourGroup ; iTitleGroup++ )
2701 tmpIntB =_numberOfVariablesStatistics*iTitleGroup;
2702 tmpTitleString.Printf(_T("%d-Size Data"),iTitleGroup);
2703 interfMainPanel::getInstance()->setColLableInfoPanel(tmpIntB + 0, tmpTitleString);
2705 interfMainPanel::getInstance()->setColLableInfoPanel(tmpIntB + 0, tmpTitleString );
2706 interfMainPanel::getInstance()->setColLableInfoPanel( tmpIntB + 1, _T("Size Range") );
2707 interfMainPanel::getInstance()->setColLableInfoPanel( tmpIntB + 2, _T("Min") );
2708 interfMainPanel::getInstance()->setColLableInfoPanel( tmpIntB + 3, _T("Max") );
2709 interfMainPanel::getInstance()->setColLableInfoPanel( tmpIntB + 4, _T("Average") );
2710 interfMainPanel::getInstance()->setColLableInfoPanel( tmpIntB + 5, _T("St.Dev.") );
2711 interfMainPanel::getInstance()->setColLableInfoPanel( tmpIntB + 6, _T(" ") );
2713 interfMainPanel::getInstance()->setStringInfoPanel( _T("") );
2717 void wxContourMainFrame::onSaveResults(std::string directory,std::string namefile, std::string filename,
2718 int typeContourGroup, int selection, int minZ, int maxZ, bool XYZValues, bool contourImage, bool statistics)
2722 SaveValuesXYZ( directory , namefile, typeContourGroup );
2727 vtkImageData * mask;
2728 vtkImageData * value;
2729 this->getMaskValue(&mask, &value, typeContourGroup,selection,minZ,maxZ);
2730 this->SaveImageResult( directory , namefile, mask, value);
2735 std::ostringstream name;
2736 name << filename << ".xls";
2739 FILE *pFile=fopen(name.str().c_str(),"w+");
2745 // int sizeZ = _theViewPanel->GetImageDataSizeZ();
2746 // int maxY=sizeZ+2;
2748 maxX= interfMainPanel::getInstance()->getNumberColsInformationPanel();//this->_grid->GetNumberCols();
2751 int iTitle,sizeTitle = (maxX / _numberOfVariablesStatistics);
2752 for ( iTitle=0; iTitle<sizeTitle ; iTitle++)
2754 // fprintf(pFile,"-- \t %d-Size \t SizeRange \t Min \t Max \t Ave \t StDv \t" , iTitle,tmpString.c_str() );
2755 fprintf(pFile,"slice\t %d-Size \t SizeRange \t Min \t Max \t Ave \t StDv \t" , iTitle );
2757 fprintf(pFile,"\n\n" );
2761 if (selection==0 ) // actual slice
2763 std::vector<int> tempVector;
2764 _instantPanel->getInstant( tempVector );
2765 int actualSlice = tempVector[1];
2771 for ( j=minZ; j<=maxZ ; j++)
2773 fprintf(pFile,"%d\t" , j );
2774 for (i=0 ; i<maxX ; i++){
2775 tmpString = interfMainPanel::getInstance()->getCellValue(j, i);//_grid->GetCellValue( j , i );
2776 fprintf(pFile,"%s\t" , (const char *)(tmpString.mb_str()) );
2778 fprintf(pFile,"\n" );
2782 // Total of stadistics.....
2785 fprintf(pFile,"\n Total:\t" );
2786 for (i=0 ; i<maxX ; i++){
2787 tmpString = interfMainPanel::getInstance()->getCellValue(maxZ+2, i);//_grid->GetCellValue( maxZ+2 , i );
2788 fprintf(pFile,"%s\t" , (const char *)(tmpString.mb_str()) );
2790 fprintf(pFile,"\n" );
2798 void wxContourMainFrame::SaveValuesXYZ(std::string directory,std::string namefile,int typeContourGroup)
2802 //int typeContourGroup = this->_radiolstboxContourGroup->GetSelection();
2803 _contourextractdata ->SetTypeOperation( typeContourGroup % 3 );
2805 std::vector<manualBaseModel*> lstManConMod;
2806 std::vector<manualBaseModel*> lstManConModTmp;
2807 std::vector<manualBaseModel*> lstManConModExp;
2808 std::vector<double> pLstValue;
2809 std::vector<double> pLstValuePosX;
2810 std::vector<double> pLstValuePosY;
2811 std::vector<double> pLstValuePosZ;
2813 std::vector<int> tempVector;
2814 _instantPanel->getInstant( tempVector );
2816 int sizeZ = _theViewPanel->getSceneManager()->GetImageDataSizeZ();
2818 int ii,sizeLstContourThings;
2825 minZ = 0;// _mbarrange->GetStart();
2826 maxZ = sizeZ;//_mbarrange->GetEnd();
2827 totalZ = maxZ-minZ+1;
2831 for ( z=0 ; z<sizeZ ; z++)
2834 porcent = 100.0* (z-minZ)/totalZ;
2836 tmpString.Printf(_T("Saving Values"));
2837 tmpString.Printf(_T(" %d %c %d/%d %d"), (int)porcent , 37 , z-minZ+1, (int)totalZ ,z);
2838 interfMainPanel::getInstance()->setStringInfoPanel(tmpString);
2839 //_staticTextInformation->SetLabel(tmpString);
2842 //Extraction data from contours of each slice
2843 _contourextractdata->SetZtoBeAnalys( z);
2846 Instant instant(&tempVector);
2847 std::vector<ContourThing**> lstContourThings = kernelManager->getOutlinesAtInstant(&instant);//this->_modelManager->getOutlinesAtInstant( &instant );
2848 sizeLstContourThings = lstContourThings.size();
2850 lstManConMod.clear();
2851 for (ii=0 ; ii<sizeLstContourThings ; ii++)
2853 ContourThing **contourthing = lstContourThings[ii];
2854 lstManConMod.push_back( (*contourthing)->getModel() );
2856 lstManConModExp = kernelManager->ExploseEachModel( lstManConMod );
2861 int iContourGroup,sizeContourGroup;
2862 if (typeContourGroup==3) // contour separete
2864 sizeContourGroup=lstManConModExp.size();
2865 } else { // contour AND OR XOR
2869 for( iContourGroup=0 ; iContourGroup<sizeContourGroup ; iContourGroup++ ){
2870 lstManConModTmp.clear();
2871 if (typeContourGroup==3) // contour separete
2873 lstManConModTmp.push_back( lstManConModExp[iContourGroup]);
2874 } else { // contour AND OR XOR
2875 lstManConModTmp = lstManConModExp;
2878 _contourextractdata->SetLstManualContourModel( lstManConModTmp );
2881 pLstValuePosX.clear();
2882 pLstValuePosY.clear();
2883 pLstValuePosZ.clear();
2885 _contourextractdata->GetValuesInsideCrown( &numberOfPixels,
2891 std::string temp = directory + "/" + namefile + "-slice";
2892 temp = temp + kernelManager->intToString(z) + "-cont" + kernelManager->intToString(iContourGroup);
2893 temp = temp + ".txt";
2895 // LG 14/01/09 : using crea
2896 wxString filename = crea::std2wx(temp);
2897 /*filename.Printf(_T("%s"),directory.c_str());
2898 filename.append(_T("\\"));
2899 filename.append(_T("%s"),namefile.c_str());
2900 filename.append(_T("-slice"));
2901 filename.append(_T("%d"),z);
2902 filename.append(_T("-cont"));
2903 filename.append(_T("%d"),iContourGroup);
2904 filename.append(_T(".txt"));*/
2905 // filename.Printf(temp.c_str());
2909 FILE *pFile=fopen((const char *)filename.mb_str(),"w+");
2910 fprintf(pFile,"value \t x \t y \t z\n" );
2911 int iLstValue,sizeLstValue=pLstValue.size();
2912 for (iLstValue=0 ; iLstValue<sizeLstValue ; iLstValue++ )
2914 fprintf(pFile,"%f\t %f\t %f\t %f\n", (float)pLstValue[iLstValue] , (float)pLstValuePosX[iLstValue], (float)pLstValuePosY[iLstValue], (float)z );
2917 } // for iContourGroup
2919 interfMainPanel::getInstance()->setStringInfoPanel(_T(""));
2920 //_staticTextInformation->SetLabel( _T("") );
2924 void wxContourMainFrame::getMaskValue(vtkImageData ** mask,vtkImageData ** value,int typeContourGroup, int selection, int minZ, int maxZ){
2927 //int typeContourGroup = this->_radiolstboxContourGroup->GetSelection();
2928 if (typeContourGroup==3)
2932 _contourextractdata ->SetTypeOperation( typeContourGroup % 3 );
2934 std::vector<manualBaseModel*> lstManConMod;
2935 std::vector<manualBaseModel*> lstManConModTmp;
2936 std::vector<manualBaseModel*> lstManConModExp;
2938 std::vector<int> tempVector;
2939 _instantPanel->getInstant( tempVector );
2941 vtkImageData *imagedata = _theViewPanel->getImageData();
2943 imagedata->GetExtent(ext);
2944 int sizeZimage = ext[5]-ext[4]+1;
2946 int ii,sizeLstContourThings;
2955 if (selection==0 ) // actual slice
2957 int actualSlice = tempVector[1];
2965 // cleanning image before range
2966 for (z=0; z<minZ; z++){
2967 _contourextractdata->ResetImageResult(z);
2969 // cleanning image after range
2970 for (z=maxZ+1; z<sizeZimage; z++){
2971 _contourextractdata->ResetImageResult(z);
2976 for ( z=minZ ; z<=maxZ ; z++)
2979 porcent = 100.0* (z-minZ)/totalZ;
2980 tmpString.Printf(_T("Saving Values"));
2981 tmpString.Printf(_T("%d %c %d/%d %d"), (int)porcent , 37 , z-minZ+1, (int)totalZ ,z);
2982 interfMainPanel::getInstance()->setStringInfoPanel(tmpString);
2984 //Extraction data from contours of each slice
2985 _contourextractdata->SetZtoBeAnalys( z);
2988 Instant instant(&tempVector);
2989 std::vector<ContourThing**> lstContourThings = kernelManager->getOutlinesAtInstant( &instant );
2990 sizeLstContourThings = lstContourThings.size();
2992 lstManConMod.clear();
2993 for (ii=0 ; ii<sizeLstContourThings ; ii++)
2995 ContourThing **contourthing = lstContourThings[ii];
2996 lstManConMod.push_back( (*contourthing)->getModel() );
2998 lstManConModExp = kernelManager->ExploseEachModel( lstManConMod );
3001 int iContourGroup,sizeContourGroup;
3002 if (typeContourGroup==3) // contour separete
3004 sizeContourGroup=lstManConModExp.size();
3005 } else { // contour AND OR XOR
3009 for( iContourGroup=0 ; iContourGroup<sizeContourGroup ; iContourGroup++ ){
3010 lstManConModTmp.clear();
3011 if (typeContourGroup==3) // contour separete
3013 lstManConModTmp.push_back( lstManConModExp[iContourGroup]);
3014 } else { // contour AND OR XOR
3015 lstManConModTmp = lstManConModExp;
3018 _contourextractdata->SetLstManualContourModel( lstManConModTmp );
3019 _contourextractdata->CalculateImageResult(); // with actual Z
3021 } // for iContourGroup
3024 (*value) = _contourextractdata->GetVtkImageValueResult();
3025 (*mask) = _contourextractdata->GetVtkImageMaskResult();
3029 void wxContourMainFrame::SaveImageResult(std::string directory,std::string namefile, vtkImageData* mask,vtkImageData* value)
3033 kernelManager->GetSpacing(spc,0); // returns the spacing of the first image
3035 std::string temp = directory + "/" + namefile + "-image-Value.mhd";
3037 wxString filename = crea::std2wx(temp);
3041 vtkImageChangeInformation *valueChInfo = vtkImageChangeInformation::New();
3042 //EED 2017-01-01 Migration VTK7
3043 #if VTK_MAJOR_VERSION <= 5
3044 valueChInfo->SetInput(value);
3046 valueChInfo->SetInputData(value);
3048 valueChInfo->SetSpacingScale(spc);
3049 vtkMetaImageWriter *writerValueImage = vtkMetaImageWriter::New( );
3051 //EED 2017-01-01 Migration VTK7
3052 #if VTK_MAJOR_VERSION <= 5
3053 writerValueImage->SetInput( valueChInfo->GetOutput() );
3055 writerValueImage->SetInputData( valueChInfo->GetOutput() );
3057 writerValueImage->SetFileName( (const char *)filename.mb_str() );
3058 writerValueImage->SetFileDimensionality( 3 );
3059 writerValueImage->SetCompression(false);
3060 writerValueImage->Write( );
3063 temp = directory + "/" + namefile + "-image-Mask.mhd";
3065 // LG 14/01/09 : using crea
3066 filename = crea::std2wx(temp);
3067 // filename.Printf(_T(temp.c_str()));
3070 vtkImageChangeInformation *maskChInfo = vtkImageChangeInformation::New();
3071 //EED 2017-01-01 Migration VTK7
3072 #if VTK_MAJOR_VERSION <= 5
3073 maskChInfo->SetInput(mask);
3075 maskChInfo->SetInputData(mask);
3077 maskChInfo->SetSpacingScale(spc);
3078 vtkMetaImageWriter *writerMaskImage = vtkMetaImageWriter::New( );
3080 //EED 2017-01-01 Migration VTK7
3081 #if VTK_MAJOR_VERSION <= 5
3082 writerMaskImage->SetInput( maskChInfo->GetOutput() );
3084 writerMaskImage->SetInputData( maskChInfo->GetOutput() );
3087 writerMaskImage->SetFileName( (const char *)filename.mb_str() );
3088 writerMaskImage->SetFileDimensionality( 3 );
3089 writerMaskImage->SetCompression(false);
3090 writerMaskImage->Write( );
3092 interfMainPanel::getInstance()->setStringInfoPanel( _T("") );
3098 void wxContourMainFrame::onChangeInstantInstantPanel(std::string name,int value, int minshow, int maxshow){
3099 if( name.compare( _theViewPanel->getVerticalConceptName() ) == 0){
3100 _theViewPanel->setActualVertical( value);
3102 else if( name.compare( _theViewPanel->getHorizontalConceptName() ) == 0|| _instantPanel->getIfConceptCheckedAt( name, 0 ) ) {
3103 _theViewPanel->setHorizontalConcept( name, minshow, maxshow, minshow, maxshow, value);
3109 void wxContourMainFrame::onSnakePressed(){
3110 std::vector<double> vecX;
3111 std::vector<double> vecY;
3112 std::vector<double> vecZ;
3113 _theViewPanel->GetPointsOfActualContour( &vecX , &vecY , &vecZ );
3115 if (vecX.size()!=0){
3116 std::vector<int> tempVector;
3117 _instantPanel->getInstant( tempVector );
3118 int i,size=vecZ.size();
3119 int actualSlice = tempVector[1];
3120 for ( i=0 ; i<size ; i++ )
3122 vecZ[i] = actualSlice;
3125 wxDialog* dialog = new wxDialog(this, -1, wxString(_T("Snake")));
3126 wxPanel* panel = new wxPanel(dialog,-1);
3127 // wxStaticText* sttext = new wxStaticText(panel, -1, wxString(_T("Panel para snake")));
3128 new wxStaticText(panel, -1, wxString(_T("Panel para snake")));
3129 dialog->ShowModal();
3134 void wxContourMainFrame::saveFileWithContoursAutomatique(){
3135 std::string filename = kernelManager->getCurrentFileName();
3136 if(filename.compare("")!=0){
3137 saveFileWithContours(filename);
3142 void wxContourMainFrame::ShowToolsPanel(bool show){
3143 _pannew->Show(show);
3148 void wxContourMainFrame::SetContourGroup(int contourGroup)
3150 _contourGroup = contourGroup;
3154 wxPanel *wxContourMainFrame::getMaskImageViewPanel(wxWindow *parent)
3157 if (_viewMaskImagePanel==NULL)
3159 _contourextractdata = new ContourExtractData(true);
3160 _contourextractdata->SetImage( _theViewPanel->getImageData() );
3162 // _theViewPanel->getImageData()->GetScalarRange(range);
3163 //int min = (int)floor (range[0]);
3164 //int max = (int)ceil (range[1]);
3167 _viewMaskImagePanel = new ThresholdImageViewPanel( parent, -1, -1 , 0);
3168 _viewMaskImage = new ThresholdImageView();
3169 _viewMaskImage->SetImage(_contourextractdata->GetVtkImageMaskResult() );
3170 _viewMaskImage->SetminMaxValue( min, max);
3171 _viewMaskImage->SetBaseColor( 0,0,1 );
3172 _viewMaskImagePanel->SetThresholdImageView( _viewMaskImage );
3173 _viewMaskImage->SetwxVtkBaseView( _theViewPanel->getWxVtkBaseView() );
3175 return _viewMaskImagePanel;
3179 wxPanel *wxContourMainFrame::getColorLayerImageViewPanel(wxWindow *parent)
3181 if (_viewColorLayerImagePanel==NULL)
3184 _theViewPanel->getImageData()->GetScalarRange(range);
3185 int min = (int)floor (range[0]);
3186 int max = (int)ceil (range[1]);
3187 _viewColorLayerImagePanel = new ColorLayerImageViewPanel( parent, min, max, 100, 1);
3188 _viewColorLayerImagePanel->GetColorLayerImageViewManager()->SetwxVtkBaseView( 0 , _theViewPanel->getWxVtkBaseView() );
3190 return _viewColorLayerImagePanel;
3194 wxPanel *wxContourMainFrame::getThresholdImageViewPanel(wxWindow *parent)
3196 if (_viewThresholdImagePanel==NULL)
3199 _theViewPanel->getImageData()->GetScalarRange(range);
3200 int min = (int)floor (range[0]);
3201 int max = (int)ceil (range[1]);
3202 _viewThresholdImagePanel = new ThresholdImageViewPanel( parent, min, max , 1);
3203 _viewThresholdImage = new ThresholdImageView();
3204 _viewThresholdImage->SetImage( _theViewPanel->getImageData() );
3205 _viewThresholdImage->SetminMaxValue( min, max);
3206 _viewThresholdImage->SetBaseColor( 1,0,0 );
3207 _viewThresholdImagePanel->SetThresholdImageView( _viewThresholdImage );
3208 _viewThresholdImage->SetwxVtkBaseView( _theViewPanel->getWxVtkBaseView() );
3210 return _viewThresholdImagePanel;
3213 //CMRU 17-08-09-----------------------------------------------------------------------------------------------
3214 int wxContourMainFrame::getType ()
3217 std::vector<std::string> currentSelection = _theViewPanel->getSelectedObjects();
3219 if(!currentSelection.empty())
3221 std::string cloneName = currentSelection [0];
3222 manualBaseModel * manualModel = kernelManager->getOutlineByKeyName(cloneName);
3223 tipo = manualModel-> GetTypeModel();
3228 double wxContourMainFrame::getContourSizeInPixels()
3230 double contourSize = 0;
3232 std::vector<std::string> currentSelection = _theViewPanel->getSelectedObjects(); if(!currentSelection.empty())
3233 if(!currentSelection.empty())
3235 std::string cloneName = currentSelection [0];
3237 manualBaseModel * manualModel = kernelManager->getOutlineByKeyName(cloneName);//_modelManager->getOutlineByKeyName( cloneName )->getModel();
3240 // contourSize = manualModel->GetPathSize();
3245 contourSize = manualModel->GetPathSize( spc );
3250 manualBaseModel * wxContourMainFrame::getContour ()
3252 std::vector<std::string> currentSelection = _theViewPanel->getSelectedObjects();
3254 if(!currentSelection.empty())
3256 std::string cloneName = currentSelection [0];
3257 manualBaseModel * manualModel = kernelManager->getOutlineByKeyName(cloneName);//_modelManager->getOutlineByKeyName( cloneName )->getModel();
3262 void wxContourMainFrame::onPrintLabel (wxString label, manualBaseModel* manualModel)
3264 std::string labelAscii(label.ToAscii());
3265 int pos = labelAscii.find(" ");
3269 for (j=0 ; pos != string::npos;j++)
3271 labelAscii.replace( pos, 1, "_" );
3272 pos= labelAscii.find(" ");
3275 manualModel -> SetLabel(labelAscii);
3277 void wxContourMainFrame::onInsertCalculation(manualBaseModel* manualModel)
3280 // double sizeInPixel = manualModel ->GetPathSize( );
3285 double sizeInPixel = manualModel ->GetPathSize( spc );
3287 double onePixelRealSize = interfMainPanel::getInstance()->GetPixelValue();;
3288 double realContourSize = sizeInPixel*onePixelRealSize;
3289 manualModel ->SetRealSize(realContourSize);
3292 double wxContourMainFrame::onePixelSize( double value)
3294 return _onePixelSize = value;
3297 std::string wxContourMainFrame::GetFileLocation()
3299 return _fileLocation;
3302 void wxContourMainFrame::SetFileLocation(std::string newFileLocation)
3304 _fileLocation = newFileLocation;
3305 std::cout<<"GETFILELOCATION:"<<_fileLocation<<std::endl;
3307 //------------------------------------------------------------------------------------------------------------
3316 void wxContourMainFrame::FlipSelectedContours(int flipDirection)
3318 printf("EED wxContourMainFrame::FlipSelectedContours flipDirection=%d \n", flipDirection );
3320 (std::vector<std::string>)_theViewPanel->getSceneManager()->getSelectedObjects() ,
3326 void wxContourMainFrame::FlipActualSliceContours(int flipDirection)
3328 printf("EED wxContourMainFrame::FlipActualSliceContours flipDirection=%d \n", flipDirection );
3330 (std::vector<std::string>)_theViewPanel->getSceneManager()->GetlstContoursNameActualSlice() ,
3335 void wxContourMainFrame::FlipAllContours(int flipDirection)
3337 printf("EED wxContourMainFrame::FlipAllContours flipDirection=%d \n", flipDirection );
3339 kernelManager->GetLstNameThings() ,
3344 void wxContourMainFrame::FlipLstOfContours(std::vector<std::string> lstNameThings, int flipDirection)
3347 getImageData()->GetExtent(ext);
3348 int sizeX = ext[1]-ext[0];
3349 int sizeY = ext[3]-ext[2];
3352 int i,sizeLstNameThings;
3353 int ii,sizeLstPoints;
3355 sizeLstNameThings = lstNameThings.size();
3356 for (i=0 ; i<sizeLstNameThings ; i++)
3358 printf("EED wxContourMainFrame::FlipAllContours contour=%d \n", i );
3359 manualBaseModel * manualModel = kernelManager->getOutlineByKeyName(lstNameThings[i]);
3360 if (flipDirection==0)
3362 manualModel->Transform_Ax_Plus_B(-1,sizeX,1,0 );
3364 manualModel->Transform_Ax_Plus_B(1,0,-1,sizeY );
3366 }// for i list of Things
3368 //-- Static Contours
3370 lstNameThings = kernelManager->GetLstNameThingsStatic();
3371 sizeLstNameThings = lstNameThings.size();
3372 for (i=0 ; i<sizeLstNameThings ; i++)
3374 manualBaseModel * manualModel = kernelManager->getOutlineByKeyName(lstNameThings[i]);
3375 if (flipDirection==0)
3377 manualModel->Transform_Ax_Plus_B(-1,sizeX,1,0 );
3379 manualModel->Transform_Ax_Plus_B(1,0,-1,sizeY );
3381 }// for i list of static things
3384 void wxContourMainFrame::FlipContours(int typeContourFlip, int flipDirection)
3386 printf("EED wxContourMainFrame::FlipContours( %d , %d ) \n",typeContourFlip, flipDirection );
3390 if (typeContourFlip==0) //
3392 FlipSelectedContours(flipDirection);
3395 if (typeContourFlip==1) //
3397 FlipActualSliceContours(flipDirection);
3400 if (typeContourFlip==2) //
3402 FlipAllContours(flipDirection);