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;
97 _frameShowResultImages = NULL;
100 wxContourMainFrame::wxContourMainFrame(wxWindow* parent, wxWindowID id,const wxString& title,const wxPoint& pos,const wxSize& size,std::vector<vtkImageData*> images, long style,std::string datadir)
101 : wxPanel(parent, id, pos, size, style)
103 m_mgr.SetManagedWindow(this);
105 _creatingContoursActive = false;
106 _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)
138 std::string str_home(getenv("USERPROFILE"));
139 #elif defined(__GNUC__)
140 std::string str_home(getenv("HOME"));
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 )
166 instance=new wxContourMainFrame(parent, id, title, pos, size, images, style,datadir);
171 std::vector<vtkImageData*> wxContourMainFrame::getVectImages()
173 return kernelManager->getVectImages();
176 wxContourMainFrame* wxContourMainFrame::getInstance()
181 void wxContourMainFrame::resetInstance()
186 wxContourMainFrame::~wxContourMainFrame()
188 delete _contourextractdata;
191 interfMainPanel::resetInstance();
192 delete kernelManager;
194 //_pannew->Destroy();
200 //El problema al cerrar la aplicacion puede estar asociado
201 //a que wxAUINotebook esta en la aplicacion
202 //principal (wxContourGUIExample)tambien
203 //EED???? delete _theViewPanel;
204 //EED???? delete _instantPanel;
205 //EED???? delete _buttonsBar;
206 //EED???? delete _actualInstant;
207 //EED???? delete _sceneManager;
211 //------------------------------------------------------------------------------------------------------------
212 // Creational and initialization methods using WxAui
213 //------------------------------------------------------------------------------------------------------------
215 wxAuiNotebook * wxContourMainFrame::createNotebook()
217 wxSize client_size = GetClientSize();
218 wxAuiNotebook* noteBook = new wxAuiNotebook(this, -1, wxPoint(client_size.x, client_size.y), wxSize(430,200), m_notebook_style);
219 wxBitmap page_bmp = wxArtProvider::GetBitmap(wxART_NORMAL_FILE, wxART_OTHER, wxSize(16,16));
224 //------------------------------------------------------------------------------------------------------------
225 // Creational and initialization methods
226 //------------------------------------------------------------------------------------------------------------
227 bool wxContourMainFrame::configurePanels( )
229 bool configured = _theViewPanel!=NULL;
231 configured &= _theViewPanel!=NULL;
232 if( _theViewPanel!=NULL )
234 notebook->AddPage( _theViewPanel, wxT(" View ") );
239 notebook->AddPage( _instantPanel, wxT("Instant Page") );
242 m_mgr.AddPane(notebook, wxAuiPaneInfo().Name(wxT("notebook_content")).CenterPane().PaneBorder(false));
244 SetMinSize(wxSize(300,300));
250 bool wxContourMainFrame::addNewPanel(wxPanel* panel)
252 bool configured = panel!=NULL;
253 configured &= panel!=NULL;
257 notebook->AddPage( panel, wxT(" Viewer "), true );
263 //------------------------------------------------------------------------------------------------------------
264 // Attributes getters and setters
265 //------------------------------------------------------------------------------------------------------------
269 void wxContourMainFrame :: setInstantChooserPanel( wxInstantChooserPanel * theInstantChooserPanel )
271 _instantPanel = theInstantChooserPanel;
274 // void wxContourMainFrame :: setButtonsBar( wxContour_ButtonsBar * theButtonsBar )
276 // _buttonsBar = theButtonsBar;
279 // void wxContourMainFrame :: setGrid( wxContour_Grid * theGridPanel )
281 // _gridPanel = theGridPanel;
284 // void wxContourMainFrame :: setDrawToolsPanel( wxContour_DrawToolsPanel * theDrawToolsPanel )
286 // _drawToolsPanel = theDrawToolsPanel;
289 // void wxContourMainFrame :: setOperationsToolsPanel( wxContour_OperationsToolsPanel * theOperationsToolsPanel )
291 // _operationsToolsPanel = theOperationsToolsPanel;
294 // void wxContourMainFrame :: setAutomaticFormsPanel( wxContour_AutomaticFormsToolsPanel * theAutoFormsPanel )
296 // _autoFormsPanel = theAutoFormsPanel;
299 // void wxContourMainFrame :: setStandardToolsPanel( wxContour_StandardToolsPanel * theStandardToolsPanel )
301 // _standardToolsPanel= theStandardToolsPanel;
304 // void wxContourMainFrame :: setEditionToolsPanel( wxContour_EdtionToolsPanel * theEditionToolsPanel )
306 // _editionToolsPanel = theEditionToolsPanel;
309 // void wxContourMainFrame :: setListViewPanel( wxContour_ListViewPanel * theListViewPanel )
311 // _listViewPanel = theListViewPanel;
316 void wxContourMainFrame::onCreateContourSpline( ){
318 //JCP 20-10-08 Undo redo implementation
320 //JCP 20-10-08 Undo redo implementation
325 void wxContourMainFrame::onCreateContourRectangle( )
327 //JCP 20-10-08 Undo redo implementation
329 //JCP 20-10-08 Undo redo implementation
333 void wxContourMainFrame::onCreateContourCircle( )
335 //JCP 20-10-08 Undo redo implementation
337 //JCP 20-10-08 Undo redo implementation
341 void wxContourMainFrame::onCreateContourLine( )
343 //JCP 20-10-08 Undo redo implementation
345 //JCP 20-10-08 Undo redo implementation
349 // RaC 09-09 --------------------------------------
350 void wxContourMainFrame::onCreateContourPoints( )
352 //JCP 20-10-08 Undo redo implementation
354 //JCP 20-10-08 Undo redo implementation
357 // RaC 09-09 --------------------------------------
359 // RaC 10-09 --------------------------------------
360 void wxContourMainFrame::onCreateContourPolygon( )
362 //JCP 20-10-08 Undo redo implementation
364 //JCP 20-10-08 Undo redo implementation
367 // RaC 10-09 --------------------------------------
369 //------------------------------------------------------------------------------------------------------------
371 void wxContourMainFrame :: onCreateContourBullEye(wxPanel* panel )
373 //Creating the manualBaseModel and including in the model
374 manualBaseModel * manModelContour = factoryManualContourModel(panel );
376 std::vector<int> instantVector;
377 _instantPanel->getInstant( instantVector );
378 std::string theName = kernelManager->createOutline(manModelContour, instantVector);
380 /*std::vector<int> instantVector;
381 _instantPanel->getInstant( instantVector );
383 theName= _modelManager->createOutline( manModelContour, instantVector );*/
384 bool addedModel = theName.compare("") != 0;//??
388 double spc[3];//Si no hay imagen pero hay contornos que spacing se pone por default
389 _theViewPanel->getSpacing(spc);
390 //Adding the manualContourControler to interface objects structure
391 //Adding the manualViewContour to interface objects structure
392 //_theViewPanel->getSceneManager()->setControlActiveStateOfALL( false );//This call is being done here because if the ROI is created underneath the previously created ROIS will still be active.
393 _theViewPanel->getSceneManager()->configureViewControlTo( theName, manModelContour,spc , 4) ;
397 void wxContourMainFrame::createContour( int typeContour )
399 //Creating the manualContourModel and including in the model
400 manualBaseModel * manModelContour = kernelManager->factoryManualContourModel(typeContour);
401 std::vector<int> instantVector;
402 _instantPanel->getInstant( instantVector );
404 std::vector<int> tempVector;
405 getInstantVector( tempVector );
406 manModelContour->SetLabel2( std::to_string(tempVector[1]) );
408 std::string theName = kernelManager->createOutline(manModelContour, instantVector);
409 /*std::vector<int> instantVector;
410 _instantPanel->getInstant( instantVector );
412 theName= _modelManager->createOutline( manModelContour, instantVector );*/
413 bool addedModel = theName.compare("") != 0;//??
416 double spc[3];//Si no hay imagen pero hay contornos que spacing se pone por default
417 _theViewPanel->getSpacing(spc);
418 //Adding the manualContourControler to interface objects structure
419 //Adding the manualViewContour to interface objects structure
420 //_sceneManager->setControlActiveStateOfALL( false );//This call is being done here because if the ROI is created underneath the previously created ROIS will still be active.
421 _theViewPanel->getSceneManager()->configureViewControlTo( theName, manModelContour,spc , typeContour) ;
425 manualBaseModel * wxContourMainFrame::factoryManualContourModel(wxPanel* panel){
427 manualContourModelBullEye *manModelContourBullEye = new manualContourModelBullEye();
428 manualBaseModel *manModelContour=NULL;
429 manModelContour = manModelContourBullEye;
431 int iCrown,sizeCrowns,iSector,sizeSectors;
432 double radioA,radioB,ang,angDelta ;
433 sizeCrowns = ((PanelBullEyeOptions*)panel)->GetNumberOfCrowns();
434 for ( iCrown=0 ; iCrown<sizeCrowns ; iCrown++ )
436 sizeSectors = ((PanelBullEyeOptions*)panel)->GetNumberOfSections(iCrown);
437 radioB = ((PanelBullEyeOptions*)panel)->GetRadioOfCrown(iCrown);
438 if (iCrown==sizeCrowns-1)
442 radioA = ((PanelBullEyeOptions*)panel)->GetRadioOfCrown(iCrown+1);
446 for ( iSector=0 ; iSector<sizeSectors ; iSector++ )
448 ang = ((PanelBullEyeOptions*)panel)->GetAngOfCrownSection(iCrown,iSector);
449 angDelta= ((PanelBullEyeOptions*)panel)->GetAngDeltaOfCrownSection(iCrown);
450 manModelContourBullEye->AddSector(radioA,radioB,ang,angDelta);
453 } // if _panelBullEyeOptions
455 return manModelContour;
458 void wxContourMainFrame :: saveState()
460 std::string temp = kernelManager->saveState();
461 saveFileWithContours(temp);
464 void wxContourMainFrame::onDeleteContour()
466 //JCP 20-10-08 Undo redo implementation
468 //JCP 20-10-08 Undo redo implementation
470 std::vector<std::string> lstKeyNameToBeErase;
471 lstKeyNameToBeErase = _theViewPanel->getSceneManager()->getSelectedObjects();
472 deleteContours( lstKeyNameToBeErase );
474 int i,size=_sceneManager->getSelectedObjects().size();
477 std::string keyName = _sceneManager->getSelectedObjects()[i];
478 int ispartofstaticlist = this->_modelManager->IsPartOfStaticList( keyName );
479 if ( ispartofstaticlist>=0 )
481 std::vector<int> tempVector;
482 _instantPanel->getInstant( tempVector );
483 Instant instant(&tempVector);
484 this->_modelManager->ChangeContourOfList(keyName, &instant);
488 std::vector<std::string> lstKeyName;
489 std::vector<std::string> lstKeyNameActualSlice;
490 std::vector<std::string> lstKeyNameToBeErase;
492 lstKeyNameToBeErase = _sceneManager->getSelectedObjects();
493 lstKeyNameActualSlice = _sceneManager->GetlstContoursNameActualSlice();
494 int k,kSize=lstKeyNameToBeErase.size();
495 int j,jSize=lstKeyNameActualSlice.size();
497 for (k=0;k<kSize; k++)
500 for (j=0;j<jSize; j++)
502 if (lstKeyNameToBeErase[k]==lstKeyNameActualSlice[j])
509 lstKeyName.push_back( lstKeyNameToBeErase[k] );
513 deleteContours( lstKeyName );
517 void wxContourMainFrame :: deleteContours( std::vector<std::string> keyNamesVector )
519 int i,size=keyNamesVector.size();
522 deleteContour( keyNamesVector[i] );
526 void wxContourMainFrame :: deleteContour( std::string theKeyName )
529 manualContourModel * cModel;
530 manualViewBaseContour * cViewer;
531 manualContourBaseControler * cControler;
533 ContourWrap_ViewControl *conwrapviewControl = _theViewPanel->getSceneManager()->getContourWrap_ViewControlOf( theKeyName );
534 cControler = conwrapviewControl->getControler();*/
537 bool isedit = _theViewPanel->isEditableCControler(theKeyName);
538 bool ispartofstaticlst = kernelManager->IsPartOfStaticList(theKeyName);
540 if (isedit && ispartofstaticlst)
542 _theViewPanel->removeFromScene(theKeyName);
544 kernelManager->deleteCModel(theKeyName);
545 //_theViewPanel->getSceneManager()->removeFromScene( theKeyName );
546 //cViewer = conwrapviewControl->getViewer();
547 //_theViewPanel->getSceneManager()->removeWrap( theKeyName );
548 //cControler* conwrapviewControl->getControler();
551 // delete cControler;
556 void wxContourMainFrame::onDeleteContoursActSlice()
558 //JCP 20-10-08 Undo redo implementation
560 //JCP 20-10-08 Undo redo implementation
562 std::vector<int> tempVector;
563 getInstantVector( tempVector );
564 deleteContours( getOutlinesName( tempVector[1] ) );
565 // deleteContours( (std::vector<std::string>)_theViewPanel->getSceneManager()->GetlstContoursNameActualSlice() );
568 void wxContourMainFrame::onDeleteAllContours(){
569 //JCP 20-10-08 Undo redo implementation
573 void wxContourMainFrame::deleteAllContours(){
574 //JCP 20-10-08 Undo redo implementation
577 std::vector<int> tempVector;
578 _instantPanel->getInstant( tempVector );
580 //JCP --08-09-2008 When using a diferent interface the _mbarrangeDeleteAll might not be initialize
581 // the values in GetStart and GetEnd will then not be initialize also.
582 // We use instead the values given when initializing the _deletepanel.
584 //int minZ = _mbarrangeDeleteAll->GetStart();
585 //int maxZ = _mbarrangeDeleteAll->GetEnd();
589 maxZ = _theViewPanel->getSceneManager()->GetImageDataSizeZ();
593 _theViewPanel->getSceneManager()->removeSceneContours( );
594 _theViewPanel->getSceneManager()->removeAllOutlines();
595 kernelManager->removeAllOutlines();
598 if ( (minZ==0) && (maxZ==_mbarrangeDeleteAll->GetMax() ))
600 _theViewPanel->getSceneManager()->removeSceneContours( );
601 _modelManager->removeAllOutlines();
602 _theViewPanel->getSceneManager()->removeAllOutlines();
605 for ( z=minZ ; z<=maxZ ; z++)
608 Instant instant(&tempVector);
609 std::vector<ContourThing**> lstContourThings = this->_modelManager->getOutlinesAtInstant( &instant );
611 sizeLstContourThings = lstContourThings.size();
612 for (ii=0 ; ii<sizeLstContourThings ; ii++)
614 ContourThing **contourthing = lstContourThings[ii];
615 deleteContour( (*contourthing)->getName() );
622 void wxContourMainFrame::setConceptValue( std::string name, int value )
624 _instantPanel->setConceptValue(name, value);
628 ConceptDataWrap* wxContourMainFrame::getLastConceptData()
630 return _instantPanel->getLastConceptData();
634 bool wxContourMainFrame::getIfConceptCheckedAt( std::string name, int pos )
636 return _instantPanel->getIfConceptCheckedAt( name, pos );
641 void wxContourMainFrame::ShowResultImages(int typeContourGroup, int selection, int minZ, int maxZ)
644 vtkImageData * value;
645 this->getMaskValue(&mask, &value, typeContourGroup, selection, minZ, maxZ);
647 std::vector<int> nTypeView;
648 nTypeView.push_back(5);
649 nTypeView.push_back(1);
650 nTypeView.push_back(2);
651 nTypeView.push_back(0);
653 if (_frameShowResultImages==NULL)
655 // wxFrame *_frameShowResultImages = new wxFrame(this, -1,_T("Result image extracted.."),wxDefaultPosition,wxSize(600,600), wxDEFAULT_FRAME_STYLE|wxSTAY_ON_TOP);
656 _frameShowResultImages = new wxFrame(this, -1,_T("Result image extracted.."),wxDefaultPosition,wxSize(600,600),
657 wxFRAME_TOOL_WINDOW|wxSYSTEM_MENU | wxCAPTION | wxCLIP_CHILDREN |wxFRAME_FLOAT_ON_PARENT | wxRESIZE_BORDER );
659 wxAuiManager *m_mgr_noteBookViewerResult = new wxAuiManager();
660 m_mgr_noteBookViewerResult->SetManagedWindow(_frameShowResultImages);
662 wxAuiNotebook* noteBookViewerResult = new wxAuiNotebook(_frameShowResultImages, -1, wxPoint(600, 600), wxSize(430,200), m_notebook_style);
663 m_mgr_noteBookViewerResult->AddPane(noteBookViewerResult, wxAuiPaneInfo().Name(wxT("notebook_content")).CenterPane().PaneBorder(false));
665 wxPanel *panelViewer1 = new wxMaracas_N_ViewersWidget(noteBookViewerResult, value,&nTypeView);
666 wxPanel *panelViewer2 = new wxMaracas_N_ViewersWidget(noteBookViewerResult, mask,&nTypeView);
669 noteBookViewerResult->AddPage( panelViewer1, wxT("Image result") );
670 noteBookViewerResult->AddPage( panelViewer2, wxT("Mask result") );
671 m_mgr_noteBookViewerResult->Update();
672 _frameShowResultImages->Show();
673 } // if _frameShowResultImages
679 void wxContourMainFrame::changeInstant()
681 std::vector<int> instantVect;
682 _instantPanel->getInstant( instantVect );
683 int actualSlice = instantVect[1];
684 kernelManager->setInstant(instantVect);
685 // Refresh Mask image
686 if(_viewMaskImage!=NULL)
688 _viewMaskImage->SetZ(actualSlice);
689 if (_viewMaskImagePanel->IsVisible()==true)
691 vtkImageData *mask, *value;
692 getMaskValue(&mask,&value, _contourGroup , 0, -1, -1);
693 _viewMaskImage->onThreshold();
695 } // if _viewMaskImage
696 // Refresh Threshold image
697 if(_viewThresholdImage!=NULL)
699 _viewThresholdImage->SetZ(actualSlice);
700 if (_viewThresholdImagePanel->IsVisible()==true)
702 _viewThresholdImage->onThreshold();
704 } // if _viewThresholdImage
705 updateInstantOutlines();
706 updateInstantImageData();
712 void wxContourMainFrame::updateInstantOutlines()
714 _theViewPanel->removeSceneContours();
715 _theViewPanel->addNameWrapperToScene();
717 //for( int i=0; i<size; i++)
719 // _theViewPanel->getSceneManager()->addToScene(namesWrapping[i]->getKeyName(), true, true, true, false, false );
723 int wxContourMainFrame::getNamesWrappingSize()
725 return kernelManager->getNamesWrappingSize();
728 std::string wxContourMainFrame::getNameWrapping(int i)
730 return kernelManager->getNameWrapping(i);
733 void wxContourMainFrame::updateInstantImageData()
735 std::vector<int> inst;
736 _instantPanel->getInstant(inst);
738 vtkImageData* img = kernelManager->getImageAtInstant(inst);
741 _theViewPanel->changeImage(img);
744 int z = _instantPanel->getConceptDataOf("Axe Depth")->getActualValue();
745 _theViewPanel->setImageSlice(z);
749 void wxContourMainFrame::updateInstantAxes()
754 void wxContourMainFrame::onChangeDeep(int val){
755 _instantPanel->setConceptValue( "Axe Depth", (int)val );
760 void wxContourMainFrame::onCopy(){
761 std::vector<std::string> currentSelection = _theViewPanel->getSelectedObjects();
762 std::vector<int> tempVector;
763 _instantPanel->getInstant( tempVector );
764 _performingOperation->reset();
765 _performingOperation->setStartCommand( COPY );
766 _performingOperation->setStartOperationInstantVector( tempVector );
767 _performingOperation->setKeyNamesOperationElems( currentSelection );
770 void wxContourMainFrame::onPaste()
772 char theStartCommand = _performingOperation->getStartCommand();
773 if ( theStartCommand == COPY )
775 //JCP 20-10-08 Undo redo implementation
777 //JCP 20-10-08 Undo redo implementation
778 std::vector<int> tempVector;
779 _instantPanel->getInstant( tempVector );
780 _performingOperation->setEndOperationInstantVector ( tempVector );
781 std::vector<std::string> elems = _performingOperation->getKeyNamesOperationElems();
782 int i,size = elems.size();
783 for( i=0; i<size; i++ )
785 createCopyContourOf( elems[i], tempVector, i>0 );
790 void wxContourMainFrame::onUndo()
792 std::string filename;
793 if(kernelManager->onUndoSaveFile(filename)){
794 saveFileWithContours(filename);
796 if(kernelManager->onUndo(filename)){
800 void wxContourMainFrame::onRedo(){
801 std::string filename;
802 if(kernelManager->onRedo(filename)){
807 void wxContourMainFrame :: createCopyContourOf ( std::string anExistingKName, std::vector<int> &instantNoTouchData, bool append )
809 std::string cloneName = kernelManager->createCopyContourOf( anExistingKName, instantNoTouchData );
810 manualBaseModel * manualModel = kernelManager->getOutlineByKeyName(cloneName);//_modelManager->getOutlineByKeyName( cloneName )->getModel();
811 _theViewPanel->getSceneManager()->createCopyContourOf( anExistingKName, cloneName, manualModel , append );
814 ///AD: 03-09 Copy the object and apply the given transformation
815 void wxContourMainFrame :: createMirrorContourOf ( std::string anExistingKName, std::vector<int> &instantNoTouchData, bool append )
817 std::string cloneName = kernelManager->createCopyContourOf( anExistingKName, instantNoTouchData );
818 manualBaseModel * manualModel = kernelManager->getOutlineByKeyName(cloneName);
820 manualPoint * refPoint1 = _refLineModel->GetManualPoint(0);
821 manualPoint * refPoint2 = _refLineModel->GetManualPoint(1);
823 double pnt1X = refPoint1->GetX();
824 double pnt1Y = refPoint1->GetY();
825 // double pnt1Z = refPoint1->GetZ();
826 double pnt2X = refPoint2->GetX();
827 double pnt2Y = refPoint2->GetY();
828 // double pnt2Z = refPoint2->GetZ();
830 double angle = (atan2(pnt2Y - pnt1Y, pnt2X - pnt1X) * 180 / 3.1415926535897932384626433832795)+90;
831 vtkTransform *t = vtkTransform::New();
835 t->Translate(-pnt1X, -pnt1Y, 0);
839 t->Translate(pnt1X, pnt1Y, 0);
842 int i,size=manualModel->GetSizeLstPoints();
845 manualPoint * mp = manualModel->GetManualPoint(i);
851 t->TransformPoint( vecIn, vecOut );
852 mp->SetPointX( vecOut[0] );
853 mp->SetPointY( vecOut[1] );
854 mp->SetPointZ( vecOut[2] );
857 _theViewPanel->getSceneManager()->createCopyContourOf( anExistingKName, cloneName, manualModel , append );
860 void wxContourMainFrame ::loadState(std::string filename)
863 onLoadContours(filename,false);
866 void wxContourMainFrame::onLoad()
868 std::string fileNameContourROI = GetFileLocation();
869 //CMRU 03-09-09-----------------------------------------------------------------------------------------------
870 if(GetFileLocation().empty())
872 //------------------------------------------------------------------------------------------------------------
873 //EED 2017-09-16 Migration wxWidgets 2.8 to 3.0
874 #if wxMAJOR_VERSION <= 2
875 wxFileDialog dialog(NULL, _T("Choose a file"), _T(""), _T(""), _T("*.roi"), wxOPEN );
877 wxFileDialog dialog(NULL, _T("Choose a file"), _T(""), _T(""), _T("*.roi"), wxFD_OPEN );
879 if (dialog.ShowModal() == wxID_OK)
881 fileNameContourROI = (const char *)(dialog.GetPath().mb_str());
884 onLoadContours(fileNameContourROI,true);
887 void wxContourMainFrame::SetZForAllContours(int pz)
890 std::vector< std::string > lstNameThings;
891 int i,sizeLstNameThings;
892 int ii,sizeLstPoints;
893 lstNameThings = kernelManager->GetLstNameThings();
894 sizeLstNameThings = lstNameThings.size();
895 for (i=0 ; i<sizeLstNameThings ; i++)
897 printf("EED wxContourMainFrame::SetZForAllContours contour=%d \n", i );
898 manualBaseModel * manualModel = kernelManager->getOutlineByKeyName(lstNameThings[i]);
899 sizeLstPoints = manualModel->GetSizeLstPoints();
900 for (ii=0 ; ii<sizeLstPoints ; ii++)
902 manualModel->GetManualPoint(ii)->SetPointZ(-900);
903 }// for ii list of points
904 }// for i list of Things
908 lstNameThings = kernelManager->GetLstNameThingsStatic();
909 sizeLstNameThings = lstNameThings.size();
910 for (i=0 ; i<sizeLstNameThings ; i++)
912 manualBaseModel * manualModel = kernelManager->getOutlineByKeyName(lstNameThings[i]);
913 sizeLstPoints = manualModel->GetSizeLstPoints();
914 for (ii=0 ; ii<sizeLstPoints ; ii++)
916 manualModel->GetManualPoint(ii)->SetPointZ(-900);
917 }// for ii list of points
918 }// for i list of static things
921 void wxContourMainFrame::onLoadContours(std::string fileNameContourROI, bool interactiveInterface)
925 FILE *pFile =fopen(fileNameContourROI.c_str(),"r+");
926 //CMRU 03-09-09- ----------------------------------------------------------------------------------------------
929 //------------------------------------------------------------------------------------------------------------
930 fileNameContourROI.append("data");
931 FILE *pFileData=fopen(fileNameContourROI.c_str(),"r+");
932 if(pFileData != NULL)
934 fscanf(pFileData,"%s",tmpD); // --CreaContour--
935 fscanf(pFileData,"%s",tmpD); // Version
936 fscanf(pFileData,"%s",tmpD); // 1.0.3 || 1.0.2 || 1.0.1 || 1.0.0
938 fscanf(pFileData,"%s",tmpD); // onePixelSize
939 fscanf(pFileData,"%s",tmpD); // #
940 _onePixelSize = atof(tmpD);
941 fscanf(pFileData,"%s",tmpD); // NumberOfContours
942 fscanf(pFileData,"%s",tmpD); // #
944 fscanf(pFile,"%s",tmp); // --CreaContour--
945 fscanf(pFile,"%s",tmp); // Version
946 fscanf(pFile,"%s",tmp); // 1.0.3 || 1.0.2 || 1.0.1 || 1.0.0
947 std::string version(tmp);
949 _tmpReadFileTypeOfTransformation=-1;
950 if (version=="1.0.3")
952 readDimSpc(pFile,interactiveInterface); // DimSpc interactive ON
953 openContours(pFile,pFileData,false);
954 openContours(pFile,pFileData,true); //Load StaticContours
956 if (version=="1.0.2")
959 readDimSpc(pFile,interactiveInterface); // DimSpc interactive ON
960 openContours(pFile,pFileData,false);
961 readDimSpc(pFile,false); // DimSpc interactive OFF
962 openContours(pFile,pFileData,true); // Load StaticContours
963 SetZForAllContours(-900);
964 } else if (version=="1.0.1") { //AD:02-06-09
965 openContours(pFile,pFileData,false); //Skips ImageDimensions and ImageSpacing
966 openContours(pFile,pFileData,true); //Load StaticContours, skips ImageDimensions and ImageSpacing
967 } else if (version=="1.0.0") { //AD:02-06-09
968 openContours(pFile,pFileData,false); //Skips ImageDimensions and ImageSpacing
971 if(pFileData != NULL)
976 _theViewPanel->getSceneManager()->removeSceneContours();
981 void wxContourMainFrame::onImport()
983 std::string filename, filenamecontours;
984 //EED 2017-09-16 Migration wxWidgets 2.8 to 3.0
985 #if wxMAJOR_VERSION <= 2
986 wxFileDialog dialog(NULL, _T("Choose a XML Osirix File"), _T(""), _T(""), _T("*.xml"), wxOPEN );
988 wxFileDialog dialog(NULL, _T("Choose a XML Osirix File"), _T(""), _T(""), _T("*.xml"), wxFD_OPEN );
990 if (dialog.ShowModal() == wxID_OK)
992 filename = dialog.GetPath().mb_str();
993 filenamecontours = kernelManager->parseOsirixFile(filename);
995 if(filenamecontours.compare("") != 0)
997 onLoadContours(filenamecontours,true);
1002 void wxContourMainFrame::onTest()
1004 std::string filename, filenamecontours;
1005 //EED 2017-09-16 Migration wxWidgets 2.8 to 3.0
1006 #if wxMAJOR_VERSION <= 2
1007 wxFileDialog dialog(NULL, _T("Choose a File"), _T(""), _T(""), _T("*.*"), wxOPEN );
1009 wxFileDialog dialog(NULL, _T("Choose a File"), _T(""), _T(""), _T("*.*"), wxFD_OPEN );
1011 if (dialog.ShowModal() == wxID_OK)
1013 filename = dialog.GetPath().mb_str();
1014 std::cout << "This is the filename: " << filename << std::endl;
1019 void wxContourMainFrame::onSave()
1021 //CMRU 03-09-09-----------------------------------------------------------------------------------------------
1022 if(GetFileLocation().empty())
1024 //------------------------------------------------------------------------------------------------------------
1025 //EED 2017-09-16 Migration wxWidgets 2.8 to 3.0
1026 #if wxMAJOR_VERSION <= 2
1027 wxFileDialog dialog(NULL, _T("Choose a file"), _T(""), _T(""), _T("*.roi"), wxSAVE );
1029 wxFileDialog dialog(NULL, _T("Choose a file"), _T(""), _T(""), _T("*.roi"), wxFD_SAVE );
1031 if (dialog.ShowModal() == wxID_OK)
1033 std::string fileNameContourROI = (const char *)(dialog.GetPath().mb_str());
1034 kernelManager->setCurrentFileName(fileNameContourROI);
1035 saveFileWithContours( fileNameContourROI );
1037 } else {//CMRU 03-09-09-----------------------------------------------------------------------------------------------
1038 std::cout<<"Nombre del archivo: "<<GetFileLocation()<<std::endl;
1039 std::string fileNameContourROI = GetFileLocation();
1040 std::cout<<"Nombre del archivo: "<<fileNameContourROI<<std::endl;
1041 kernelManager->setCurrentFileName(fileNameContourROI);
1042 saveFileWithContours( fileNameContourROI);
1044 //------------------------------------------------------------------------------------------------------------
1048 void wxContourMainFrame::saveFileWithContours( std::string filename )
1051 FILE *pFile=fopen(filename.c_str(),"w+");
1053 //CMRU 03-09-09-----------------------------------------------------------------------------------------------
1054 filename.append("data");
1055 std::cout<<"Nombre del archivo: "<<filename<<std::endl;
1056 FILE *pFileData=fopen(filename.c_str(),"w+");
1057 //------------------------------------------------------------------------------------------------------------
1059 std::vector< std::string > lstNameThings;
1060 int i,sizeLstNameThings;
1062 fprintf(pFile,"--CreaContour--\n");
1063 fprintf(pFile,"Version %s\n", "1.0.3" );
1065 //CMRU 03-09-09-----------------------------------------------------------------------------------------------
1066 fprintf(pFileData,"--CreaContour--\n");
1067 fprintf(pFileData,"Version %s\n", "1.0.3" );
1068 fprintf(pFileData,"OnePixelSize %f\n", _onePixelSize);
1070 //------------------------------------------------------------------------------------------------------------
1072 vtkImageData *image = _images[0];
1075 image->GetDimensions(dimRange);
1077 fprintf(pFile,"ImageDimensions %d %d %d\n", dimRange[0], dimRange[1], dimRange[2] );
1080 image->GetSpacing(spaRange);
1082 fprintf(pFile,"ImageSpacing %f %f %f\n", spaRange[0], spaRange[1], spaRange[2] );
1086 lstNameThings = kernelManager->GetLstNameThings();
1087 sizeLstNameThings = lstNameThings.size();
1088 fprintf(pFile,"NumberOfContours %d\n", sizeLstNameThings );
1090 //CMRU 03-09-09-----------------------------------------------------------------------------------------------
1091 fprintf(pFileData,"NumberOfContours %d\n", sizeLstNameThings );
1092 //------------------------------------------------------------------------------------------------------------
1101 for (i=0 ; i<sizeLstNameThings ; i++)
1103 //CMRU 03-09-09-----------------------------------------------------------------------------------------------
1104 manualBaseModel * manualModel = kernelManager->getOutlineByKeyName(lstNameThings[i]);
1107 // double sizeInPixel = manualModel ->GetPathSize( );
1108 double sizeInPixel = manualModel ->GetPathSize( spc );
1110 double realContourSize = sizeInPixel*_onePixelSize;
1111 manualModel ->SetRealSize(realContourSize);
1112 //------------------------------------------------------------------------------------------------------------
1114 //int size= kernelManager->GetLstNameThings().size();
1116 kernelManager->SaveThingName( pFile, pFileData, lstNameThings[i] );
1117 _theViewPanel->getSceneManager()->SaveThingName( pFile, lstNameThings[i] );
1120 //-- Static Contours
1122 // fprintf(pFile,"ImageDimensions %d %d %d\n", dimRange[0], dimRange[1], dimRange[2] );
1123 // fprintf(pFile,"ImageSpacing %f %f %f\n", spaRange[0], spaRange[1], spaRange[2] );
1125 lstNameThings = kernelManager->GetLstNameThingsStatic();
1126 sizeLstNameThings = lstNameThings.size();
1127 fprintf(pFile,"NumberOfContoursStatic %d\n", sizeLstNameThings );
1129 //CMRU 03-09-09-----------------------------------------------------------------------------------------------
1130 fprintf(pFileData,"NumberOfContoursStatic %d\n", sizeLstNameThings );
1131 //------------------------------------------------------------------------------------------------------------
1133 for (i=0 ; i<sizeLstNameThings ; i++)
1135 kernelManager->SaveThingName( pFile, pFileData, lstNameThings[i] );
1136 _theViewPanel->getSceneManager()->SaveThingName( pFile, lstNameThings[i] );
1144 void wxContourMainFrame::readDimSpc(FILE *pFile, bool interactiveOption)
1148 double imageSpac[3];
1149 vtkImageData *image = _images[0];
1150 image->GetDimensions(imageDim);
1151 image->GetSpacing(imageSpac);
1153 fscanf(pFile,"%s",tmp); // ImageDimensions
1154 fscanf(pFile,"%s",tmp); // X
1155 _tmpReadFileImageDim[0] = atoi(tmp);
1156 fscanf(pFile,"%s",tmp); // Y
1157 _tmpReadFileImageDim[1] = atoi(tmp);
1158 fscanf(pFile,"%s",tmp); // Z
1159 _tmpReadFileImageDim[2] = atoi(tmp);
1161 fscanf(pFile,"%s",tmp); // ImageSpacing
1162 fscanf(pFile,"%s",tmp); // X
1163 _tmpReadFileImageSpac[0] = atof(tmp);
1164 fscanf(pFile,"%s",tmp); // Y
1165 _tmpReadFileImageSpac[1] = atof(tmp);
1166 fscanf(pFile,"%s",tmp); // Z
1167 _tmpReadFileImageSpac[2] = atof(tmp);
1170 if (interactiveOption==true)
1172 //Compare Spacing and Dims in X and Y (Necessary in Z?) - Just for Version 2
1173 if (imageDim[0]!=_tmpReadFileImageDim[0] || imageDim[1]!=_tmpReadFileImageDim[1] || imageSpac[0]!=_tmpReadFileImageSpac[0] || imageSpac[1]!=_tmpReadFileImageSpac[1])
1175 wxDialog* dial = new wxDialog (this,-1,_T("Tools"),wxDefaultPosition, wxSize(460,360));
1176 wxSizer* buttonsSizer = dial->CreateSeparatedButtonSizer(wxOK|wxCANCEL);
1177 // wxBoxSizer *dialSizer = new wxBoxSizer(wxVERTICAL);
1178 wxFlexGridSizer *dialSizer = new wxFlexGridSizer(1);
1180 wxString lstOptOperation[3];
1181 lstOptOperation[0]=_T("By Dimension (XY)");
1182 lstOptOperation[1]=_T("By Spacing (XY)");
1183 lstOptOperation[2]=_T("By Spacing (XYZ)");
1184 wxRadioBox * radioOpts = new wxRadioBox(dial, -1, _T("Type of Transformation"), wxDefaultPosition, wxSize(370,200), 3 , lstOptOperation, 3, wxRA_SPECIFY_ROWS);
1186 dialSizer->Add( new wxStaticText(dial,-1,_T("The image resolution is not compatible with the ")) , 0, wxGROW );
1187 dialSizer->Add( new wxStaticText(dial,-1,_T("selected Roi file. Do you want to tranform it?")) , 0, wxGROW );
1188 dialSizer->Add( new wxStaticText(dial,-1,_T(" ")) , 0, wxGROW );
1189 dialSizer->Add(radioOpts,0,wxGROW);
1190 dialSizer->Add( new wxStaticText(dial,-1,_T(" ")) , 0, wxGROW );
1191 dialSizer->Add(buttonsSizer,0,wxGROW);
1192 dial->SetSizer(dialSizer, true);
1196 _tmpReadFileTypeOfTransformation = -1;
1197 //EED bool transform = false;
1199 if (dial->GetReturnCode() == wxID_OK)
1201 _tmpReadFileTypeOfTransformation = radioOpts->GetSelection();
1205 } // if interactiveOption
1212 void wxContourMainFrame::openContours( FILE *pFile, FILE *pFileData, bool staticContour )
1214 printf ("EED wxContourMainFrame::openContours Start \n");
1217 vtkImageData *image = _images[0];
1220 double imageSpac[3];
1221 image->GetDimensions(imageDim);
1222 image->GetSpacing(imageSpac);
1225 fscanf(pFile,"%s",tmp); // NumberOfContours
1226 fscanf(pFile,"%s",tmp); // ##
1227 int numberOfContours = atoi(tmp);
1229 std::vector<int> instantVector;
1230 int typeContourModel;
1231 manualBaseModel *manModelContour;
1235 if (compatible==true)
1238 for (i=0;i<numberOfContours;i++)
1240 instantVector.clear();
1241 fscanf(pFile,"%s",tmp); // Instant
1243 fscanf(pFile,"%s",tmp); // 1
1244 instantVector.push_back( atoi(tmp) );
1245 fscanf(pFile,"%s",tmp); // 2
1246 instantVector.push_back( atoi(tmp) );
1247 fscanf(pFile,"%s",tmp); // 3
1248 instantVector.push_back( atoi(tmp) );
1249 fscanf(pFile,"%s",tmp); // 4
1250 instantVector.push_back( atoi(tmp) );
1251 fscanf(pFile,"%s",tmp); // 5
1252 instantVector.push_back( atoi(tmp) );
1253 fscanf(pFile,"%s",tmp); // 6
1254 instantVector.push_back( atoi(tmp) );
1257 fscanf(pFile,"%s",tmp); // TypeContourModel
1258 fscanf(pFile,"%s",tmp); // ##
1259 typeContourModel = atoi(tmp);
1261 manModelContour = kernelManager->factoryManualContourModel(typeContourModel);
1262 manModelContour->Open(pFile);
1263 if(pFileData != NULL)
1265 manModelContour->OpenData(pFileData);
1268 fscanf(pFile,"%s",tmp); // TypeView
1269 fscanf(pFile,"%s",tmp); // ##
1270 typeView = atoi(tmp);
1272 std::string theName;
1273 theName = kernelManager->createOutline( manModelContour, instantVector );
1274 bool addedModel = theName.compare("") != 0;
1277 double spc[3];//Si no hay imagen pero hay contornos que spacing se pone por default
1278 _theViewPanel->getSpacing(spc);
1279 //Adding the manualContourControler to interface objects structure
1280 //Adding the manualViewContour to interface objects structure
1281 //_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.
1282 _theViewPanel->getSceneManager()->configureViewControlTo( theName, manModelContour,spc , typeView) ;
1285 if (staticContour) //StaticContours (will appear in all slices)
1287 Instant instant(&instantVector);
1288 kernelManager->changeContourOfManager( theName , &instant );
1291 }// for numberOfContours
1294 else if (compatible==false)
1299 for (i=0;i<numberOfContours;i++)
1301 instantVector.clear();
1302 fscanf(pFile,"%s",tmp); // Instant
1304 fscanf(pFile,"%s",tmp); // 1
1305 instantVector.push_back( atoi(tmp) );
1306 fscanf(pFile,"%s",tmp); // 2
1307 instantVector.push_back( atoi(tmp) );
1308 fscanf(pFile,"%s",tmp); // 3
1309 instantVector.push_back( atoi(tmp) );
1310 fscanf(pFile,"%s",tmp); // 4
1311 instantVector.push_back( atoi(tmp) );
1312 fscanf(pFile,"%s",tmp); // 5
1313 instantVector.push_back( atoi(tmp) );
1314 fscanf(pFile,"%s",tmp); // 6
1315 instantVector.push_back( atoi(tmp) );
1317 fscanf(pFile,"%s",tmp); // TypeContourModel
1318 fscanf(pFile,"%s",tmp); // ##
1319 typeContourModel = atoi(tmp);
1321 manModelContour = kernelManager->factoryManualContourModel(typeContourModel);
1322 manModelContour->Open(pFile);
1323 if(pFileData != NULL)
1325 manModelContour->OpenData(pFileData);
1328 if (_tmpReadFileTypeOfTransformation==-1){
1330 } else if (_tmpReadFileTypeOfTransformation==0){
1331 double transX, transY;
1332 transX = (double) imageDim[0]/_tmpReadFileImageDim[0]; // X
1333 transY = (double) imageDim[1]/_tmpReadFileImageDim[1]; // Y
1334 manModelContour->Transform_Ax_Plus_B(transX,0,transY,0);
1335 } else if (_tmpReadFileTypeOfTransformation==1) {
1336 double transX, transY;
1337 transX = (double) _tmpReadFileImageSpac[0]/imageSpac[0]; // X
1338 transY = (double) _tmpReadFileImageSpac[1]/imageSpac[1]; // Y
1339 manModelContour->Transform_Ax_Plus_B(transX,0,transY,0);
1340 } else if (_tmpReadFileTypeOfTransformation==2) { // with Z include
1341 double transX, transY;
1342 transX = (double) _tmpReadFileImageSpac[0]/imageSpac[0]; // X
1343 transY = (double) _tmpReadFileImageSpac[1]/imageSpac[1]; // Y
1344 instantVector[1]=instantVector[1]*_tmpReadFileImageSpac[2]/imageSpac[2]; // Z
1345 manModelContour->Transform_Ax_Plus_B(transX,0,transY,0);
1347 printf ("EED Warnning! wxContourMainFrame::openContours _tmpReadFileTypeOfTransformation not set. \n");
1350 fscanf(pFile,"%s",tmp); // TypeView
1351 fscanf(pFile,"%s",tmp); // ##
1352 typeView = atoi(tmp);
1354 std::string theName;
1355 theName = kernelManager->createOutline( manModelContour, instantVector );
1356 bool addedModel = theName.compare("") != 0;
1359 double spc[3];//Si no hay imagen pero hay contornos que spacing se pone por default
1360 _theViewPanel->getSpacing(spc);
1361 //Adding the manualContourControler to interface objects structure
1362 //Adding the manualViewContour to interface objects structure
1363 //_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.
1364 _theViewPanel->getSceneManager()->configureViewControlTo( theName, manModelContour,spc , typeView) ;
1367 if (staticContour) //StaticContours (will appear in all slices)
1369 Instant instant(&instantVector);
1370 kernelManager->changeContourOfManager( theName , &instant );
1372 }// for numberOfContours
1376 printf ("EED wxContourMainFrame::openContours END \n");
1380 void wxContourMainFrame::RefreshInterface()
1383 _theViewPanel->RefreshInterface();
1384 //wxVtk2DBaseView *wxvtk2dbaseview = (wxVtk2DBaseView*)this->_theViewPanel->getWxVtkBaseView();
1385 //wxvtk2dbaseview->Refresh();
1388 vtkImageData* wxContourMainFrame::getImageData()
1390 return _theViewPanel->getImageData();
1393 void wxContourMainFrame::onSegmentationOneSliceITK(wxString distance, wxString sigma, wxString alfa, wxString beta, wxString propagation, wxString iterations, wxString inflation)
1395 //JCP 20-10-08 Undo redo implementation
1397 //JCP 20-10-08 Undo redo implementation
1400 int x = _theViewPanel->GetX();
1401 int y = _theViewPanel->GetY();
1402 int z = _theViewPanel->GetZ();
1403 SegmentationOneSliceITK( x,y,z,distance, sigma, alfa, beta, propagation, iterations, inflation);
1407 void wxContourMainFrame::SegmentationOneSliceITK(int x, int y, int z, wxString distanc, wxString sigm, wxString alf, wxString bet, wxString prop, wxString iter, wxString inflation)
1409 int typeofcontour = 1;
1411 vtkImageData *imagedata = getImageData();
1412 //Tipo de pixeles a utilizar internamente en ITK
1413 typedef float InternalPixelType;
1414 const unsigned int Dimension = 2;
1415 typedef itk::Image< InternalPixelType, Dimension > InternalImageType;
1416 //Tipo de pixeles de salida 1
1417 typedef unsigned char OutputPixelType;
1418 typedef itk::Image< OutputPixelType, Dimension > OutputImageType;
1419 //Tipo de pixeles de salida 2
1420 typedef unsigned short OutputPixelType2;
1421 typedef itk::Image< OutputPixelType2, Dimension > OutputImageType2;
1422 //DefiniciÛn del thresholder
1423 typedef itk::BinaryThresholdImageFilter<
1425 OutputImageType > ThresholdingFilterType;
1426 //DefiniciÛn del primer filtro de conversiÛn de pixeles
1427 typedef itk::CastImageFilter<
1428 OutputImageType, OutputImageType2 > CastFilterType;
1429 //DefiniciÛn del segundo tipo de conversiÛn de pixeles
1430 typedef itk::CastImageFilter<
1431 OutputImageType2, InternalImageType > CastFilterType2;
1432 //Tercer tipo de conversiÛn
1433 typedef itk::RescaleIntensityImageFilter<
1435 OutputImageType > CastFilterType3;
1436 //Cuarto tipo de conversiÛn
1437 typedef itk::RescaleIntensityImageFilter<
1439 OutputImageType > CastFilterType4;
1440 ThresholdingFilterType::Pointer thresholder = ThresholdingFilterType::New();
1441 thresholder->SetLowerThreshold( 0.0 );
1442 thresholder->SetUpperThreshold( 128 );
1443 thresholder->SetOutsideValue( 255 );
1444 thresholder->SetInsideValue( 0 );
1445 //DefinciÛn de conexiÛnes entre VTK e ITK y el writer
1446 typedef itk::VTKImageToImageFilter<OutputImageType2> ConnectorType;
1447 typedef itk::ImageToVTKImageFilter<OutputImageType> ConnectorType2;
1448 //EED10JUIN2011 typedef itk::ImageFileWriter< OutputImageType > WriterType;
1449 ConnectorType::Pointer connector = ConnectorType::New();
1450 ConnectorType2::Pointer connector2 = ConnectorType2::New();
1451 CastFilterType::Pointer filter = CastFilterType::New();
1452 CastFilterType2::Pointer filter2 = CastFilterType2::New();
1453 connector->SetInput( imagedata );
1454 filter2->SetInput(connector->GetOutput());
1455 typedef itk::CurvatureAnisotropicDiffusionImageFilter<
1457 InternalImageType > SmoothingFilterType;
1458 SmoothingFilterType::Pointer smoothing = SmoothingFilterType::New();
1459 typedef itk::GradientMagnitudeRecursiveGaussianImageFilter<
1461 InternalImageType > GradientFilterType;
1462 typedef itk::SigmoidImageFilter<
1464 InternalImageType > SigmoidFilterType;
1465 GradientFilterType::Pointer gradientMagnitude = GradientFilterType::New();
1466 SigmoidFilterType::Pointer sigmoid = SigmoidFilterType::New();
1467 sigmoid->SetOutputMinimum( 0.0 );
1468 sigmoid->SetOutputMaximum( 255.0 );
1469 typedef itk::FastMarchingImageFilter<
1471 InternalImageType > FastMarchingFilterType;
1472 FastMarchingFilterType::Pointer fastMarching = FastMarchingFilterType::New();
1473 typedef itk::GeodesicActiveContourLevelSetImageFilter< InternalImageType,
1474 InternalImageType > GeodesicActiveContourFilterType;
1475 GeodesicActiveContourFilterType::Pointer geodesicActiveContour =
1476 GeodesicActiveContourFilterType::New();
1477 typedef itk::ZeroCrossingImageFilter<
1479 InternalImageType > ZeroCrossingFilterType;
1480 ZeroCrossingFilterType::Pointer zeroCrossing =
1481 ZeroCrossingFilterType::New();
1482 const double propagationScaling = atof( crea::wx2std(prop).c_str() );
1483 geodesicActiveContour->SetPropagationScaling( propagationScaling );
1484 geodesicActiveContour->SetCurvatureScaling( 1.0 );
1485 geodesicActiveContour->SetAdvectionScaling( 1.0 );
1486 geodesicActiveContour->SetMaximumRMSError( 0.02 );
1487 int it=atoi( crea::wx2std(iter).c_str() );
1488 geodesicActiveContour->SetNumberOfIterations( it );
1489 smoothing->SetInput( filter2->GetOutput() );
1490 gradientMagnitude->SetInput( smoothing->GetOutput() );
1491 sigmoid->SetInput( gradientMagnitude->GetOutput() );
1492 fastMarching->SetInput( sigmoid->GetOutput() );
1493 geodesicActiveContour->SetInput( fastMarching->GetOutput() );
1494 geodesicActiveContour->SetFeatureImage( sigmoid->GetOutput() );
1495 zeroCrossing->SetInput( geodesicActiveContour->GetOutput() );
1496 //thresholder->SetInput( zeroCrossing->GetOutput() );
1497 thresholder->SetInput( geodesicActiveContour->GetOutput() );
1498 connector2->SetInput( thresholder->GetOutput() );
1499 smoothing->SetTimeStep( 0.125 );
1500 smoothing->SetNumberOfIterations( 5 );
1501 smoothing->SetConductanceParameter( 9.0 );
1502 const double sigma = atof( crea::wx2std(sigm).c_str() );
1503 gradientMagnitude->SetSigma( sigma );
1504 const double alpha = atof( crea::wx2std(alf).c_str() );
1505 const double beta = atof( crea::wx2std(bet).c_str() );
1506 sigmoid->SetAlpha( alpha );
1507 sigmoid->SetBeta( beta );
1508 typedef FastMarchingFilterType::NodeContainer NodeContainer;
1509 typedef FastMarchingFilterType::NodeType NodeType;
1510 NodeContainer::Pointer seeds = NodeContainer::New();
1511 InternalImageType::IndexType seedPosition;
1512 seedPosition[0] = x;
1513 seedPosition[1] = y;
1514 const double initialDistance = atof( crea::wx2std(distanc).c_str() );
1516 const double seedValue = - initialDistance;
1517 node.SetValue( seedValue );
1518 node.SetIndex( seedPosition );
1519 seeds->Initialize();
1520 seeds->InsertElement( 0, node );
1521 fastMarching->SetTrialPoints( seeds );
1522 fastMarching->SetSpeedConstant( 1.0 );
1523 fastMarching->SetOutputSize( connector->GetOutput()->GetBufferedRegion().GetSize() );
1524 fastMarching->SetStoppingValue( 800 );
1527 // connector2->Update();
1528 vtkImageData *idata = NULL;
1529 idata = connector2->GetOutput();
1530 vtkMarchingContourFilter* cntVTK = vtkMarchingContourFilter::New( );
1531 cntVTK->SetNumberOfContours( 1 );
1532 cntVTK->SetValue( 0, 255 );
1533 //EED 2017-01-01 Migration VTK7
1534 #if VTK_MAJOR_VERSION <= 5
1535 cntVTK->SetInput( idata );
1537 cntVTK->UpdateInformation();
1539 cntVTK->SetInputData( idata );
1541 vtkCleanPolyData* cpd = vtkCleanPolyData::New( );
1542 //EED 2017-01-01 Migration VTK7
1543 #if VTK_MAJOR_VERSION <= 5
1544 cpd->SetInput( cntVTK->GetOutput( ) );
1546 cpd->UpdateInformation();
1548 cpd->SetInputData( cntVTK->GetOutput( ) );
1550 vtkPolyDataConnectivityFilter* conn = vtkPolyDataConnectivityFilter::New( );
1551 conn->SetExtractionModeToLargestRegion( );
1552 //EED 2017-01-01 Migration VTK7
1553 #if VTK_MAJOR_VERSION <= 5
1554 conn->SetInput( cpd->GetOutput( ) );
1556 conn->UpdateInformation();
1558 conn->SetInputData( cpd->GetOutput( ) );
1560 vtkStripper* vtkstripper = vtkStripper::New( );
1561 //EED 2017-01-01 Migration VTK7
1562 #if VTK_MAJOR_VERSION <= 5
1563 vtkstripper->SetInput( conn->GetOutput() );
1564 vtkstripper->Update();
1565 vtkstripper->UpdateInformation();
1567 vtkstripper->SetInputData( conn->GetOutput() );
1570 vtkPolyData* polyDataResult = cntVTK->GetOutput();
1571 //std::cout<<"Points "<<polyDataResult->GetNumberOfPoints()<<std::endl;
1573 //EED 2017-01-01 Migration VTK7
1574 #if VTK_MAJOR_VERSION <= 5
1575 polyDataResult->Update( );
1576 polyDataResult->UpdateInformation();
1583 //--Calculating control points
1584 std::vector<double> vecX;
1585 std::vector<double> vecY;
1586 std::vector<double> vecXo;
1587 std::vector<double> vecYo;
1588 std::vector<double>::iterator vecXoi;
1589 std::vector<double>::iterator vecYoi;
1590 std::vector<double> vecZ;
1591 std::vector<double> vecCtrlPointX;
1592 std::vector<double> vecCtrlPointY;
1593 std::vector<double> vecCtrlPointZ;
1597 int ii,size=polyDataResult->GetNumberOfPoints();
1599 myfile.open ("C:/Creatis/example2.txt");
1600 size=polyDataResult->GetNumberOfPoints();
1601 for (ii=0;ii<size;ii++)
1608 p = polyDataResult->GetPoint(ii);
1611 // if(fabs(yAct-y)>20)
1613 // if((xAct-x)>1 || (xAct-x)<-1)
1615 // vecX.push_back( p[0] );
1616 // vecY.push_back( p[1] );
1617 // myfile <<p[0]<<","<<p[1]<<"\n";
1618 // std::cout<<" x Anterior "<<xAct<<" x actual "<<x<<std::endl;
1619 // std::cout<<" y Anterior "<<yAct<<" y actual "<<y<<std::endl;
1620 // std::cout<<" x "<<p[0]<<" y "<<p[1]<<std::endl;
1621 // vecZ.push_back( 900 );
1625 // vecXo.push_back(p[0]);
1626 // vecYo.push_back(p[1]);
1632 vecXo.push_back(p[0]);
1633 vecYo.push_back(p[1]);
1635 vecX.push_back( p[0] );
1636 myfile <<p[0]<<","<<p[1]<<"\n";
1637 //std::cout<<" x Anterior "<<xAct<<" x actual "<<x<<std::endl;
1638 //std::cout<<" y Anterior "<<yAct<<" y actual "<<y<<std::endl;
1639 //std::cout<<" x "<<p[0]<<" y "<<p[1]<<std::endl;
1640 vecY.push_back( p[1] );
1642 vecZ.push_back( -900 );
1650 while(!vecXo.empty())
1652 vecX.push_back(vecXo.back());
1653 //std::cout<<" x Siguiente "<<vecXo.back();
1656 vecZ.push_back( -900 );
1658 while(!vecYo.empty())
1660 vecY.push_back(vecYo.back());
1665 // for(int l=0;l<vecX.size();l++)
1669 // vecXo.push_back(p[0]);
1670 // vecYo.push_back(p[1]);
1672 // if(vecXoi[l-1]==)
1678 ExtractControlPoints2D *extractcontrolpoints2d = new ExtractControlPoints2D();
1679 extractcontrolpoints2d->SetContour( &vecX , &vecY , &vecZ );
1684 extractcontrolpoints2d->GetInitialControlPoints( &vecCtrlPointX , &vecCtrlPointY , &vecCtrlPointZ );
1685 } else if (method==1){
1686 extractcontrolpoints2d->GetControlPoints( &vecCtrlPointX , &vecCtrlPointY , &vecCtrlPointZ );
1687 } else if (method==2){
1688 extractcontrolpoints2d->SetSamplingControlPoints( 15 );
1689 extractcontrolpoints2d->GetSamplingControlPoints( &vecCtrlPointX , &vecCtrlPointY , &vecCtrlPointZ );
1691 //--Adding contour to the system
1693 std::vector<int> actualInstantVector;
1694 _instantPanel->getInstant( actualInstantVector );
1695 actualInstantVector[1]=z;
1697 int j,sizeCtrPt = vecCtrlPointX.size();
1699 manualBaseModel *manModelContour = kernelManager->factoryManualContourModel( typeofcontour );
1700 manModelContour->SetNumberOfPointsSpline( ((sizeCtrPt/100)+1)*100 );
1702 for (j=0 ; j<sizeCtrPt ; j++)
1704 manModelContour->AddPoint( vecCtrlPointX[j] , vecCtrlPointY[j] , vecCtrlPointZ[j] );
1706 std::string theName;
1707 //theName = _modelManager->createOutline( manModelContour, actualInstantVector );
1708 theName = kernelManager->createOutline( manModelContour, actualInstantVector );
1709 bool addedModel = theName.compare("") != 0;
1712 double spc[3];//Si no hay imagen pero hay contornos que spacing se pone por default
1713 _theViewPanel->getSpacing(spc);
1714 //Adding the manualContourControler to interface objects structure
1715 //Adding the manualViewContour to interface objects structure
1716 //_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.
1717 _theViewPanel->configureViewControlTo(theName, manModelContour, spc, typeofcontour);
1718 //_theViewPanel->getSceneManager()->configureViewControlTo( theName, manModelContour,spc, typeofcontour ) ;
1722 } catch( itk::ExceptionObject & excep ) {
1723 std::cerr << "Exception caught !" << std::endl;
1724 std::cerr << excep << std::endl;
1729 void wxContourMainFrame::onSegmentationOneSlice(int isovalue,int sampling,int method){
1731 //JCP 20-10-08 Undo redo implementation
1733 //JCP 20-10-08 Undo redo implementation
1736 int x = _theViewPanel->GetX();
1737 int y = _theViewPanel->GetY();
1738 int z = _theViewPanel->GetZ();
1739 SegmentationOneSlice( x,y,z,isovalue, sampling, method );
1744 void wxContourMainFrame::SegmentationOneSlice( int x, int y, int z, int isovalue, int sampling, int method )
1747 //printf("EED wxContourMainFrame::SegmentationOneSlice Start=%d %d\n",sampling,method );
1748 //printf("EED wxContourMainFrame::SegmentationOneSlice %d %d %d \n",x,y,z );
1750 int typeofcontour = 1;
1751 //--Extracting Contour
1752 vtkImageData *imagedata = getImageData();
1754 vtkImageReslice *imageReslice = vtkImageReslice::New();
1757 imagedata->GetSpacing(spc);
1762 //EED 2017-01-01 Migration VTK7
1763 #if VTK_MAJOR_VERSION <= 5
1764 imageReslice->SetInput( imagedata );
1766 imageReslice->SetInputData( imagedata );
1768 imageReslice->SetInformationInput(imagedata);
1769 imageReslice->SetResliceAxesDirectionCosines(1,0,0, 0,1,0 ,0,0,1);
1770 imageReslice->SetResliceAxesOrigin(0,0,z*spc[2]);
1771 imageReslice->SetOutputDimensionality(2);
1772 imageReslice->SetInterpolationModeToLinear();
1774 //EED 2017-01-01 Migration VTK7
1775 #if VTK_MAJOR_VERSION <= 5
1778 imageReslice->Update();
1781 imagedata = imageReslice->GetOutput();
1782 //EED 2017-01-01 Migration VTK7
1783 #if VTK_MAJOR_VERSION <= 5
1784 imagedata->Update();
1785 imagedata->UpdateInformation();
1790 vtkContourFilter* cntVTK = vtkContourFilter::New( );
1791 //EED 2017-01-01 Migration VTK7
1792 #if VTK_MAJOR_VERSION <= 5
1793 cntVTK->SetInput( imagedata );
1795 cntVTK->SetInputData( imagedata );
1798 cntVTK->SetNumberOfContours( 1 );
1799 //cntVTK->SetValue( 0, vmin );
1800 // cntVTK->SetValue( 0, (range[1]*thr/100) );
1801 cntVTK->SetValue( 1, isovalue );
1802 // cntVTK->SetValue( 1, vmax );
1804 cntVTK->UpdateInformation();
1806 vtkCleanPolyData* cpd = vtkCleanPolyData::New( );
1807 //EED 2017-01-01 Migration VTK7
1808 #if VTK_MAJOR_VERSION <= 5
1809 cpd->SetInput( cntVTK->GetOutput( ) );
1811 cpd->SetInputData( cntVTK->GetOutput( ) );
1813 cpd->ConvertLinesToPointsOff( );
1815 cpd->UpdateInformation();
1817 vtkPolyDataConnectivityFilter* conn = vtkPolyDataConnectivityFilter::New( );
1819 // conn->SetExtractionModeToPointSeededRegions();
1820 // conn->SetExtractionModeToCellSeededRegions();
1821 // conn->SetExtractionModeToSpecifiedRegions();
1822 // conn->SetExtractionModeToLargestRegion();
1823 // conn->SetExtractionModeToAllRegions();
1825 conn->SetExtractionModeToClosestPointRegion();
1827 //conn->SetMaxRecursionDepth( 3000 );
1829 //EED 2017-01-01 Migration VTK7
1830 #if VTK_MAJOR_VERSION <= 5
1831 conn->SetInput( cpd->GetOutput( ) );
1833 conn->SetInputData( cpd->GetOutput( ) );
1836 conn->SetClosestPoint( x, y, 0 );
1838 conn->UpdateInformation();
1840 vtkCleanPolyData* cpd2 = vtkCleanPolyData::New( );
1841 //EED 2017-01-01 Migration VTK7
1842 #if VTK_MAJOR_VERSION <= 5
1843 cpd2->SetInput( conn->GetOutput( ) );
1845 cpd2->SetInputData( conn->GetOutput( ) );
1848 cpd2->UpdateInformation();
1850 vtkStripper* vtkstripper = vtkStripper::New( );
1851 vtkstripper->SetJoinContiguousSegments(true);
1852 vtkstripper->SetMaximumLength(20000);
1853 //EED 2017-01-01 Migration VTK7
1854 #if VTK_MAJOR_VERSION <= 5
1855 vtkstripper->SetInput( cpd2->GetOutput() );
1857 vtkstripper->SetInputData( cpd2->GetOutput() );
1858 // vtkstripper->SetInputData( cntVTK->GetOutput() );
1861 vtkstripper->Update();
1862 vtkstripper->UpdateInformation();
1865 vtkPolyData* polyDataResult = vtkstripper->GetOutput();
1867 //EED 2017-01-01 Migration VTK7
1868 #if VTK_MAJOR_VERSION <= 5
1869 polyDataResult->Update( );
1870 polyDataResult->UpdateInformation();
1877 myfile.open ("c:/temp/example.txt");
1879 polyDataResult->Print(myfile);
1880 myfile << "-------------------------------------\n";
1881 polyDataResult->GetLines()->Print(myfile);
1889 //--Calculating control points
1890 std::vector<double> vecX;
1891 std::vector<double> vecY;
1892 std::vector<double> vecZ;
1893 std::vector<double> vecCtrlPointX;
1894 std::vector<double> vecCtrlPointY;
1895 std::vector<double> vecCtrlPointZ;
1897 //printf("EED wxContourMainFrame::SegmentationOneSlice GetNumberOfLines=%d \n",polyDataResult->GetNumberOfLines() );
1898 //int numberOfPointsInCell;
1899 //int numberOfcells=polyDataResult->GetNumberOfCells();
1900 //for (int jj=0; jj<numberOfcells ; jj++)
1902 // vtkCell* vtkcell = polyDataResult->GetCell( jj );
1903 // numberOfPointsInCell=vtkcell->GetNumberOfPoints();
1904 // printf("EED wxContourMainFrame::SegmentationOneSlice cell=%d points=%d \n",jj,numberOfPointsInCell );
1906 // printf("EED wxContourMainFrame::SegmentationOneSlice PrintSelf \n");
1907 // polyDataResult->PrintSelf( std::cout, vtkIndent(0) );
1910 if (polyDataResult->GetNumberOfCells()>0)
1913 vtkCell* vtkcell = polyDataResult->GetCell( 0 );
1914 // int ii,size=polyDataResult->GetNumberOfPoints();
1915 int ii,size=vtkcell->GetNumberOfPoints();
1917 for (ii=0;ii<size;ii++)
1919 // id = polyDataResult->GetLines()->GetData()->GetValue(ii);
1920 // p = polyDataResult->GetPoint(id);
1921 p = vtkcell->GetPoints()->GetPoint(ii);
1922 // printf("EED wxContourMainFrame::SegmentationOneSlice (%d) id=%d px=%f py=%f\n",ii,id, p[0],p[1]);
1925 vecX.push_back( p[0] );
1926 vecY.push_back( p[1] );
1928 vecZ.push_back( -900 );
1929 // vecZ.push_back( p[2] );
1931 ExtractControlPoints2D *extractcontrolpoints2d = new ExtractControlPoints2D();
1932 extractcontrolpoints2d->SetContour( &vecX , &vecY , &vecZ );
1934 /*if (methodRadiobox->GetSelection()==0){
1935 extractcontrolpoints2d->GetInitialControlPoints( &vecCtrlPointX , &vecCtrlPointY , &vecCtrlPointZ );
1937 if (methodRadiobox->GetSelection()==1){
1938 extractcontrolpoints2d->GetControlPoints( &vecCtrlPointX , &vecCtrlPointY , &vecCtrlPointZ );
1940 if (methodRadiobox->GetSelection()==2){
1941 extractcontrolpoints2d->SetSamplingControlPoints( sampling );
1942 extractcontrolpoints2d->GetSamplingControlPoints( &vecCtrlPointX , &vecCtrlPointY , &vecCtrlPointZ );
1947 extractcontrolpoints2d->GetInitialControlPoints( &vecCtrlPointX , &vecCtrlPointY , &vecCtrlPointZ );
1948 } else if (method==1){
1949 extractcontrolpoints2d->GetControlPoints( &vecCtrlPointX , &vecCtrlPointY , &vecCtrlPointZ );
1950 } else if (method==2){
1951 extractcontrolpoints2d->SetSamplingControlPoints( sampling );
1952 extractcontrolpoints2d->GetSamplingControlPoints( &vecCtrlPointX , &vecCtrlPointY , &vecCtrlPointZ );
1955 //--Adding contour to the system
1956 std::vector<int> actualInstantVector;
1957 _instantPanel->getInstant( actualInstantVector );
1958 actualInstantVector[1]=z;
1960 int j,sizeCtrPt = vecCtrlPointX.size();
1961 manualBaseModel *manModelContour = kernelManager->factoryManualContourModel( typeofcontour );
1962 manModelContour->SetNumberOfPointsSpline( ((sizeCtrPt/100)+1)*100 *2 );
1963 manModelContour->SetLabel2( std::to_string(z) );
1966 for (j=0 ; j<sizeCtrPt ; j++)
1968 manModelContour->AddPoint( vecCtrlPointX[j] / spc[0], vecCtrlPointY[j] / spc[1], vecCtrlPointZ[j] );
1970 std::string theName;
1971 //theName = _modelManager->createOutline( manModelContour, actualInstantVector );
1972 theName = kernelManager->createOutline( manModelContour, actualInstantVector );
1973 bool addedModel = theName.compare("") != 0;
1976 double spc[3];//Si no hay imagen pero hay contornos que spacing se pone por default
1977 _theViewPanel->getSpacing(spc);
1978 //Adding the manualContourControler to interface objects structure
1979 //Adding the manualViewContour to interface objects structure
1980 //_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.
1981 _theViewPanel->configureViewControlTo(theName, manModelContour, spc, typeofcontour);
1982 //_theViewPanel->getSceneManager()->configureViewControlTo( theName, manModelContour,spc, typeofcontour ) ;
1985 } // if NumberOfCells > 0
1986 //printf("EED wxContourMainFrame::SegmentationOneSlice End\n");
1989 int wxContourMainFrame::GetImageDataSizeZ()
1991 return _theViewPanel->GetImageDataSizeZ();
1994 void wxContourMainFrame::GetImageDataRange(double *range)
1996 _theViewPanel->GetImageDataRange(range);
1999 void wxContourMainFrame::onSegmentationAllSlice(int minZ,int maxZ,int isovalue,int sampling,int method)
2001 //JCP 20-10-08 Undo redo implementation
2003 //JCP 20-10-08 Undo redo implementation
2006 int x = _theViewPanel->GetX();
2007 int y = _theViewPanel->GetY();
2011 double totalZ = maxZ-minZ+1;
2012 for( z=minZ ; z<=maxZ ; z++ )
2014 porcent = 100.0* (z-minZ)/totalZ;
2015 tmpString.Printf(_T(" %d %c %d/%d %d"), (int)porcent , 37 , z-minZ+1, (int)totalZ,z );
2016 interfMainPanel::getInstance()->setLabelSegmentationPanelVTK(tmpString);
2017 //_staticTextSegmentation->SetLabel(tmpString);
2018 SegmentationOneSlice( x,y,z,isovalue, sampling,method );
2020 interfMainPanel::getInstance()->setLabelSegmentationPanelVTK(_T(" "));
2025 //Creates a reference line to be used as the axis of the mirroring
2026 void wxContourMainFrame::referenceLine()
2028 if (_refLineControl==NULL)
2033 vtkImageData *vtkimagedata = _theViewPanel->getImageData();
2034 vtkimagedata->GetSpacing(spc);
2036 wxVtkBaseView * viewer2D = _theViewPanel->getWxVtkBaseView();
2038 _refLineControl = new manualLineControler();
2039 _refLineModel = new manualContourModelLine();
2040 _refLineView = new manualViewLine();
2041 _refLineView->SetModel( _refLineModel );
2042 _refLineView->SetWxVtkBaseView( viewer2D );
2043 _refLineView->SetRange( 2 );
2044 _refLineView->SetZ( 1200 );
2046 _refLineView->SetSpacing(spc);
2048 _refLineView->SetColorNormalContour(0, 0, 1);
2049 _refLineView->SetColorEditContour(0, 0.5, 0.5);
2050 _refLineView->SetWidthLine(4);
2052 _refLineControl->SetModelView( _refLineModel , _refLineView );
2053 vtkInteractorStyleBaseView* style = (vtkInteractorStyleBaseView*)viewer2D->GetInteractorStyleBaseView();
2054 style->AddInteractorStyleMaracas( _refLineControl );
2055 _refLineModel->SetCloseContour(false);
2056 _refLineControl->CreateNewManualContour();
2058 //AD: Inicializar el mirroring con una linea ya pintada
2060 double z = _refLineControl->GetZ();
2063 image->GetDimensions(imageDim);
2064 double x = (double) imageDim[0]/2;
2065 double y1 = (double) (imageDim[1]/2)+15;
2066 double y2 = (double) (imageDim[1]/2)-15;
2068 _refLineControl->AddPoint(x,y1,z);
2069 _refLineControl->AddPoint(x,y2,z);
2070 _refLineControl->SetCompleteCreation(true);
2072 _refLineModel->AddPoint(x,y1,z);
2073 _refLineModel->AddPoint(x,y2,z);
2074 _refLineModel->UpdateSpline();
2076 _refLineView->UpdateViewPoint(0);
2077 _refLineView->UpdateViewPoint(1);
2080 _refLineControl->SetActive(true);
2081 _refLineView->RefreshContour();
2085 //Hides the referenceLine
2086 void wxContourMainFrame::refLineHide()
2088 if (_refLineControl!=NULL)
2090 if (_refLineControl->GetActive())
2092 _refLineView->RemoveCompleteContourActor();
2093 _refLineControl->SetEditable(false);
2094 _refLineControl->SetActive(false);
2101 //Shows the referenceLine
2102 void wxContourMainFrame::refLineShow()
2104 if (_refLineControl!=NULL)
2106 if (_refLineControl->GetActive()==false)
2108 wxVtkBaseView * viewer2D = _theViewPanel->getWxVtkBaseView();
2110 _refLineView->SetModel( _refLineModel );
2111 _refLineView->SetWxVtkBaseView( viewer2D );
2112 _refLineView->SetRange( 2 );
2113 _refLineView->SetZ( 1200 );
2115 _refLineControl->SetModelView( _refLineModel , _refLineView );
2116 vtkInteractorStyleBaseView* style = (vtkInteractorStyleBaseView*)viewer2D->GetInteractorStyleBaseView();
2117 style->AddInteractorStyleMaracas( _refLineControl );
2118 _refLineControl->CreateNewManualContour();
2119 _refLineControl->SetActive(true);
2120 _refLineView->RefreshContour();
2127 void wxContourMainFrame::refLineChangeWidth(int width)
2129 _refLineView->SetWidthLine(width);
2130 _refLineView->RefreshContour();
2136 void wxContourMainFrame::onMirror()
2139 std::vector<std::string> currentSelection = _theViewPanel->getSelectedObjects();
2140 std::vector<std::string> filterCurrentSelection;
2142 std::vector<int> tempVector;
2143 _instantPanel->getInstant( tempVector );
2144 _performingOperation->reset();
2145 _performingOperation->setStartCommand( COPY );
2146 _performingOperation->setStartOperationInstantVector( tempVector );
2147 _performingOperation->setKeyNamesOperationElems( currentSelection );
2149 char theStartCommand = _performingOperation->getStartCommand();
2150 if ( theStartCommand == COPY )
2152 //JCP 20-10-08 Undo redo implementation
2154 //JCP 20-10-08 Undo redo implementation
2155 std::vector<int> tempVector;
2156 _instantPanel->getInstant( tempVector );
2157 _performingOperation->setEndOperationInstantVector ( tempVector );
2158 std::vector<std::string> elems = _performingOperation->getKeyNamesOperationElems();
2159 int i,size = elems.size();
2160 for( i=0; i<size; i++ )
2162 createMirrorContourOf( elems[i], tempVector, i>0 );
2166 //deleteContour( _refName );
2171 void wxContourMainFrame::showAxis(bool show)
2173 _theViewPanel->SetVisibleAxis(show);
2174 _theViewPanel->Refresh();
2178 void wxContourMainFrame::onRigidPressed(){
2179 std::vector<std::string> currentSelection = _theViewPanel->getSelectedObjects();
2180 int elementsSelected = currentSelection.size();
2182 if ( elementsSelected >= 1 ){
2183 //JCP 20-10-08 Undo redo implementation
2185 //JCP 20-10-08 Undo redo implementation
2187 std::vector<int> tempVector;
2188 _instantPanel->getInstant( tempVector );
2189 Instant instant(&tempVector);
2191 int i , size=currentSelection.size();
2192 for ( i=0 ; i<size ; i++ )
2194 kernelManager->changeContourOfManager(currentSelection[i], &instant);
2199 void wxContourMainFrame::onWidthOfContour(double width){
2201 _theViewPanel->removeSceneContours();
2202 _theViewPanel->SetWidthContour(width);
2204 //_theViewPanel->getSceneManager()->SetWidthContour( width );
2209 int wxContourMainFrame::getColorWindow()
2213 vtkImageData * img = getImageData();
2214 img->GetScalarRange(range);
2216 std::cout<<"Val 1: "<<range[0]<<" Val 2: "<<range[1]<<std::endl;
2218 return (int)range[1];
2220 return _theViewPanel->getColorWindow();
2223 int wxContourMainFrame::getWindowLevel()
2227 vtkImageData * img = getImageData();
2228 img->GetScalarRange(range);
2230 std::cout<<"Val 1: "<<range[0]<<" Val 2: "<<range[1]<<std::endl;
2232 return (int)range[1];
2234 return _theViewPanel->getWindowLevel();
2237 void wxContourMainFrame::onBrigthnessColorWindowLevel(int colorwindow,int windowlevel)
2239 _theViewPanel->onBrigthnessColorWindowLevel(colorwindow, windowlevel);
2244 void wxContourMainFrame::onInterpolation(bool interpolate)
2246 _theViewPanel->onInterpolation(interpolate);
2250 void wxContourMainFrame::onBeforeAfterContour(bool before,bool after)
2252 _theViewPanel->onBeforeAfterContour(before,after);
2256 void wxContourMainFrame::onJumpSlice(int step, int shift)
2258 std::vector<int> tempVector;
2259 _instantPanel->getInstant( tempVector );
2261 int pos = tempVector[1];
2262 int maxZ = interfMainPanel::getInstance()->GetImageDataSizeZ();
2263 pos=(pos/ss)*ss+step+shift;
2264 if ((pos>=0) && (pos<maxZ))
2267 _instantPanel->setInstant( tempVector );
2272 void wxContourMainFrame::onShowTextContour(bool show)
2274 _theViewPanel->onShowTextContour(show);
2278 void wxContourMainFrame::onChangeInstant(std::string name,int actual)
2280 _instantPanel->setConceptValue( name, actual );
2283 void wxContourMainFrame::resetAppend()
2285 kernelManager->resetAppend();
2288 void wxContourMainFrame::onSpreadAdd()
2290 std::vector<double> vecX;
2291 std::vector<double> vecY;
2292 std::vector<double> vecZ;
2293 _theViewPanel->GetPointsOfActualContour(&vecX , &vecY , &vecZ );
2294 std::vector<int> tempVector;
2295 _instantPanel->getInstant( tempVector );
2296 std::string val = kernelManager->onSpreadAdd(&vecX , &vecY , &vecZ, tempVector);
2297 interfMainPanel::getInstance()->appendStringSpread(val);
2301 void wxContourMainFrame::onSpreadAddAll()
2304 std::vector<int> tempVector;
2305 _instantPanel->getInstant( tempVector );
2308 maxZ = interfMainPanel::getInstance()->GetImageDataSizeZ();
2310 int sizeLstContourThings;
2311 for ( z=minZ ; z<=maxZ ; z++ )
2314 Instant instant(&tempVector);
2315 std::vector<ContourThing**> lstContourThings = kernelManager->getOutlinesAtInstant( &instant );
2316 sizeLstContourThings = lstContourThings.size();
2317 if (sizeLstContourThings>=1)
2319 std::vector<double> vecX;
2320 std::vector<double> vecY;
2321 std::vector<double> vecZ;
2322 ContourThing **contourthing = lstContourThings[0];
2323 manualBaseModel *cModel = (*contourthing)->getModel();
2324 int i,size = cModel->GetNumberOfPointsSpline();
2326 for (i=0; i<size; i++)
2328 cModel->GetSpline_i_Point(i, &x, &y, &z);
2333 std::string val = kernelManager->onSpreadAdd(&vecX , &vecY , &vecZ, tempVector);
2334 interfMainPanel::getInstance()->appendStringSpread(val);
2335 }// if sizeLstContourThings
2340 void wxContourMainFrame::onSpreadGo(int type)
2342 //JCP 20-10-08 Undo redo implementation
2344 //JCP 20-10-08 Undo redo implementation
2346 std::vector<double> vecCtrlPointX;
2347 std::vector<double> vecCtrlPointY;
2348 std::vector<double> vecCtrlPointZ;
2352 std::vector<int> tempVector;
2353 _instantPanel->getInstant( tempVector );
2356 kernelManager->getMaxMinZ(&minZ,&maxZ);
2357 //JSTG_16-07-08_----------------------------------------------------------------
2358 //_contourPropagation->setInterpolationNumber(maxZ-minZ+1);
2359 kernelManager->CalculeSplinePropagation();
2361 double totalZ = maxZ-minZ+1;
2364 //--------------------------------------------------------------------
2365 for ( z=(int)minZ ; z<=(int)maxZ ; z++ )
2367 porcent = 100.0* (z-minZ)/totalZ;
2368 int numero = (int)(z-minZ+1)/(int)totalZ;
2369 std::string stringtemp = " "+kernelManager->intToString(porcent)+"% "+kernelManager->intToString(numero)+" "+kernelManager->intToString(z);
2371 interfMainPanel::getInstance()->setStringSpread(stringtemp);
2373 int typeofcontour = 1;
2374 std::string theName;
2375 manualBaseModel* manModelContour = kernelManager->GetPoints(z, type, &vecCtrlPointX,&vecCtrlPointY,&vecCtrlPointZ, theName,typeofcontour, tempVector);
2377 if( manModelContour!=NULL ){
2378 double spc[3];//Si no hay imagen pero hay contornos que spacing se pone por default
2379 this->_theViewPanel->getSpacing(spc);
2380 //Adding the manualContourControler to interface objects structure
2381 //Adding the manualViewContour to interface objects structure
2382 //_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.
2383 _theViewPanel->configureViewControlTo( theName, manModelContour,spc,typeofcontour ) ;
2388 int numero = (int)(z-minZ+1)/(int)totalZ;
2389 std::string stringtemp = " "+kernelManager->intToString(porcent)+"% "+kernelManager->intToString(numero)+" "+kernelManager->intToString(z);
2391 interfMainPanel::getInstance()->setStringSpread(stringtemp);
2393 //RefreshInterface();
2396 void wxContourMainFrame::getInstantVector(std::vector<int>& tempVector)
2398 _instantPanel->getInstant( tempVector );
2401 std::vector<std::string> wxContourMainFrame::getOutlinesName(int slide)
2403 std::vector<int> tempVector;
2404 _instantPanel->getInstant(tempVector);
2405 //Asignation of slide number should be different ex by name
2406 tempVector[1]=slide;
2407 return kernelManager->getOutlinesNameAtInstant(tempVector);
2411 void wxContourMainFrame::SetScalarRange(int grayRangeMin, int grayRangeMax)
2413 _contourextractdata->SetScalarRange(grayRangeMin,grayRangeMax);
2417 void wxContourMainFrame::onInformationContourLabels(int typeContourGroup,int selection,int minimumZ,int maximumZ,int grayRangeMin, int grayRangeMax)
2420 wxString tempString;
2421 int maxContourGroup = 0;
2423 _contourextractdata ->SetTypeOperation( typeContourGroup % 3 );
2425 std::vector<manualBaseModel*> lstManConMod;
2426 std::vector<manualBaseModel*> lstManConModTmp;
2427 std::vector<manualBaseModel*> lstManConModExp;
2428 std::vector<double> pLstValue;
2429 std::vector<double> pLstValuePosX;
2430 std::vector<double> pLstValuePosY;
2431 std::vector<double> pLstValuePosZ;
2434 int resultGrayRangeCount;
2437 double resultAverage;
2438 double resultStandardeviation;
2440 std::vector<int> tempVector;
2441 _instantPanel->getInstant( tempVector );
2444 int ii,sizeLstContourThings;
2453 if (selection==0 ) // actual slice
2455 int actualSlice = tempVector[1];
2458 } else { // slice range
2464 totalZ = maxZ-minZ+1;
2466 _contourextractdata->InitVolumeStatistics();
2469 for ( z=minZ ; z<=maxZ ; z++ )
2472 porcent = 100.0* (z-minZ)/totalZ;
2473 tmpString.Printf(_T(" %d %c %d/%d %d"), (int)porcent , 37 , z-minZ+1, (int)totalZ ,z);
2475 interfMainPanel::getInstance()->setStringInfoPanel(tmpString);
2476 //_staticTextInformation->SetLabel(tmpString);
2478 //Extraction data from contours of each slice
2479 _contourextractdata->SetZtoBeAnalys(z);
2482 Instant instant(&tempVector);
2483 std::vector<ContourThing**> lstContourThings = kernelManager->getOutlinesAtInstant( &instant );
2484 sizeLstContourThings = lstContourThings.size();
2486 lstManConMod.clear();
2487 for (ii=0 ; ii<sizeLstContourThings ; ii++)
2489 ContourThing **contourthing = lstContourThings[ii];
2490 lstManConMod.push_back( (*contourthing)->getModel() );
2493 lstManConModExp = kernelManager->ExploseEachModel( lstManConMod );
2495 tempString.Printf(_T("%d - %d"),z, sizeLstContourThings);
2496 interfMainPanel::getInstance()->setRowLabelInfoPanel(z, tempString);
2497 //_grid->SetRowLabelValue(z, tempString );
2499 int iContourGroup,sizeContourGroup;
2500 if (typeContourGroup==3) // contour separete
2502 sizeContourGroup=lstManConModExp.size();
2503 if ( maxContourGroup<sizeContourGroup )
2505 maxContourGroup=sizeContourGroup;
2507 } else { // contour AND OR XOR
2514 for( iContourGroup=0 ; iContourGroup<sizeContourGroup ; iContourGroup++ ){
2515 lstManConModTmp.clear();
2519 if (typeContourGroup==3) // contour separete
2521 lstManConModTmp.push_back( lstManConModExp[iContourGroup]);
2522 } else { // contour AND OR XOR
2523 lstManConModTmp = lstManConModExp;
2526 _contourextractdata->SetLstManualContourModel( lstManConModTmp );
2527 _contourextractdata->SetScalarRange(grayRangeMin,grayRangeMax);
2530 pLstValuePosX.clear();
2531 pLstValuePosY.clear();
2532 pLstValuePosZ.clear();
2536 _contourextractdata->GetValuesInsideCrown( &numberOfPixels,
2542 resultSize=numberOfPixels;
2543 // Statistics of each slice.
2544 _contourextractdata->Statistics( &pLstValue,
2547 &resultGrayRangeCount,
2552 &resultStandardeviation);
2554 if (interfMainPanel::getInstance()->getNumberColsInformationPanel()<_numberOfVariablesStatistics*(iContourGroup+1) )
2556 interfMainPanel::getInstance()->appendColsInformationPanel(_numberOfVariablesStatistics);
2559 tmpIntA=_numberOfVariablesStatistics*iContourGroup ;
2561 tempString.Printf(_T("%d"),numberOfPixels);
2563 interfMainPanel::getInstance()->setCellValueInfoPanel(z, tmpIntA, tempString);
2565 tempString.Printf(_T("%d"),resultGrayRangeCount);
2566 interfMainPanel::getInstance()->setCellValueInfoPanel(z, tmpIntA+1, tempString);
2568 tempString.Printf(_T("%f"),resultMin);
2569 interfMainPanel::getInstance()->setCellValueInfoPanel(z, tmpIntA+2, tempString);
2571 tempString.Printf(_T("%f"),resultMax);
2572 interfMainPanel::getInstance()->setCellValueInfoPanel(z, tmpIntA+3, tempString);
2574 tempString.Printf(_T("%f"),resultAverage);
2575 interfMainPanel::getInstance()->setCellValueInfoPanel(z, tmpIntA+4, tempString);
2577 tempString.Printf(_T("%f"),resultStandardeviation);
2578 interfMainPanel::getInstance()->setCellValueInfoPanel(z, tmpIntA+5, tempString);
2581 } // for iContourGroup
2584 // Print Volume Statistics
2587 int vol_rCountRange;
2589 double vol_minValue;
2590 double vol_maxValue;
2592 double vol_standardeviation;
2594 if (selection!=0 ) // actual slice
2597 _contourextractdata->GetVolumeStatistics(&vol_rCountRange, &vol_rsize,
2598 &vol_minValue, &vol_maxValue,
2599 &vol_average, &vol_standardeviation);
2601 interfMainPanel::getInstance()->setRowLabelInfoPanel(maxZ+2, _T("Total:"));
2603 tempString.Printf(_T("%d"),vol_rsize);
2604 interfMainPanel::getInstance()->setCellValueInfoPanel(maxZ+2, 0, tempString);
2606 tempString.Printf(_T("%d"),vol_rCountRange);
2607 interfMainPanel::getInstance()->setCellValueInfoPanel(maxZ+2, 1, tempString);
2609 tempString.Printf(_T("%f"),vol_minValue);
2610 interfMainPanel::getInstance()->setCellValueInfoPanel(maxZ+2, 2, tempString);
2612 tempString.Printf(_T("%f"),vol_maxValue);
2613 interfMainPanel::getInstance()->setCellValueInfoPanel(maxZ+2, 3, tempString);
2615 tempString.Printf(_T("%f"),vol_average);
2616 interfMainPanel::getInstance()->setCellValueInfoPanel(maxZ+2, 4, tempString);
2618 tempString.Printf(_T("%f"),vol_standardeviation);
2619 interfMainPanel::getInstance()->setCellValueInfoPanel(maxZ+2, 5, tempString);
2621 //-----------------------------------------
2624 wxString tmpTitleString;
2626 for ( iTitleGroup=0 ; iTitleGroup<maxContourGroup ; iTitleGroup++ )
2628 tmpIntB =_numberOfVariablesStatistics*iTitleGroup;
2629 tmpTitleString.Printf(_T("%d-Size Data"),iTitleGroup);
2630 interfMainPanel::getInstance()->setColLableInfoPanel(tmpIntB + 0, tmpTitleString);
2632 interfMainPanel::getInstance()->setColLableInfoPanel(tmpIntB + 0, tmpTitleString );
2633 interfMainPanel::getInstance()->setColLableInfoPanel( tmpIntB + 1, _T("Size Range") );
2634 interfMainPanel::getInstance()->setColLableInfoPanel( tmpIntB + 2, _T("Min") );
2635 interfMainPanel::getInstance()->setColLableInfoPanel( tmpIntB + 3, _T("Max") );
2636 interfMainPanel::getInstance()->setColLableInfoPanel( tmpIntB + 4, _T("Average") );
2637 interfMainPanel::getInstance()->setColLableInfoPanel( tmpIntB + 5, _T("St.Dev.") );
2638 interfMainPanel::getInstance()->setColLableInfoPanel( tmpIntB + 6, _T(" ") );
2640 interfMainPanel::getInstance()->setStringInfoPanel( _T("") );
2644 void wxContourMainFrame::onSaveResults(std::string directory,std::string namefile, std::string filename,
2645 int typeContourGroup, int selection, int minZ, int maxZ, bool XYZValues, bool contourImage, bool statistics)
2649 SaveValuesXYZ( directory , namefile, typeContourGroup );
2654 vtkImageData * mask;
2655 vtkImageData * value;
2656 this->getMaskValue(&mask, &value, typeContourGroup,selection,minZ,maxZ);
2657 this->SaveImageResult( directory , namefile, mask, value);
2662 std::ostringstream name;
2663 name << filename << ".xls";
2666 FILE *pFile=fopen(name.str().c_str(),"w+");
2672 // int sizeZ = _theViewPanel->GetImageDataSizeZ();
2673 // int maxY=sizeZ+2;
2675 maxX= interfMainPanel::getInstance()->getNumberColsInformationPanel();//this->_grid->GetNumberCols();
2678 int iTitle,sizeTitle = (maxX / _numberOfVariablesStatistics);
2679 for ( iTitle=0; iTitle<sizeTitle ; iTitle++)
2681 // fprintf(pFile,"-- \t %d-Size \t SizeRange \t Min \t Max \t Ave \t StDv \t" , iTitle,tmpString.c_str() );
2682 fprintf(pFile,"slice\t %d-Size \t SizeRange \t Min \t Max \t Ave \t StDv \t" , iTitle );
2684 fprintf(pFile,"\n\n" );
2688 if (selection==0 ) // actual slice
2690 std::vector<int> tempVector;
2691 _instantPanel->getInstant( tempVector );
2692 int actualSlice = tempVector[1];
2698 for ( j=minZ; j<=maxZ ; j++)
2700 fprintf(pFile,"%d\t" , j );
2701 for (i=0 ; i<maxX ; i++){
2702 tmpString = interfMainPanel::getInstance()->getCellValue(j, i);//_grid->GetCellValue( j , i );
2703 fprintf(pFile,"%s\t" , (const char *)(tmpString.mb_str()) );
2705 fprintf(pFile,"\n" );
2709 // Total of stadistics.....
2712 fprintf(pFile,"\n Total:\t" );
2713 for (i=0 ; i<maxX ; i++){
2714 tmpString = interfMainPanel::getInstance()->getCellValue(maxZ+2, i);//_grid->GetCellValue( maxZ+2 , i );
2715 fprintf(pFile,"%s\t" , (const char *)(tmpString.mb_str()) );
2717 fprintf(pFile,"\n" );
2725 void wxContourMainFrame::SaveValuesXYZ(std::string directory,std::string namefile,int typeContourGroup)
2729 //int typeContourGroup = this->_radiolstboxContourGroup->GetSelection();
2730 _contourextractdata ->SetTypeOperation( typeContourGroup % 3 );
2732 std::vector<manualBaseModel*> lstManConMod;
2733 std::vector<manualBaseModel*> lstManConModTmp;
2734 std::vector<manualBaseModel*> lstManConModExp;
2735 std::vector<double> pLstValue;
2736 std::vector<double> pLstValuePosX;
2737 std::vector<double> pLstValuePosY;
2738 std::vector<double> pLstValuePosZ;
2740 std::vector<int> tempVector;
2741 _instantPanel->getInstant( tempVector );
2743 int sizeZ = _theViewPanel->getSceneManager()->GetImageDataSizeZ();
2745 int ii,sizeLstContourThings;
2752 minZ = 0;// _mbarrange->GetStart();
2753 maxZ = sizeZ;//_mbarrange->GetEnd();
2754 totalZ = maxZ-minZ+1;
2758 for ( z=0 ; z<sizeZ ; z++)
2761 porcent = 100.0* (z-minZ)/totalZ;
2763 tmpString.Printf(_T("Saving Values"));
2764 tmpString.Printf(_T(" %d %c %d/%d %d"), (int)porcent , 37 , z-minZ+1, (int)totalZ ,z);
2765 interfMainPanel::getInstance()->setStringInfoPanel(tmpString);
2766 //_staticTextInformation->SetLabel(tmpString);
2769 //Extraction data from contours of each slice
2770 _contourextractdata->SetZtoBeAnalys( z);
2773 Instant instant(&tempVector);
2774 std::vector<ContourThing**> lstContourThings = kernelManager->getOutlinesAtInstant(&instant);//this->_modelManager->getOutlinesAtInstant( &instant );
2775 sizeLstContourThings = lstContourThings.size();
2777 lstManConMod.clear();
2778 for (ii=0 ; ii<sizeLstContourThings ; ii++)
2780 ContourThing **contourthing = lstContourThings[ii];
2781 lstManConMod.push_back( (*contourthing)->getModel() );
2783 lstManConModExp = kernelManager->ExploseEachModel( lstManConMod );
2788 int iContourGroup,sizeContourGroup;
2789 if (typeContourGroup==3) // contour separete
2791 sizeContourGroup=lstManConModExp.size();
2792 } else { // contour AND OR XOR
2796 for( iContourGroup=0 ; iContourGroup<sizeContourGroup ; iContourGroup++ ){
2797 lstManConModTmp.clear();
2798 if (typeContourGroup==3) // contour separete
2800 lstManConModTmp.push_back( lstManConModExp[iContourGroup]);
2801 } else { // contour AND OR XOR
2802 lstManConModTmp = lstManConModExp;
2805 _contourextractdata->SetLstManualContourModel( lstManConModTmp );
2808 pLstValuePosX.clear();
2809 pLstValuePosY.clear();
2810 pLstValuePosZ.clear();
2812 _contourextractdata->GetValuesInsideCrown( &numberOfPixels,
2818 std::string temp = directory + "/" + namefile + "-slice";
2819 temp = temp + kernelManager->intToString(z) + "-cont" + kernelManager->intToString(iContourGroup);
2820 temp = temp + ".txt";
2822 // LG 14/01/09 : using crea
2823 wxString filename = crea::std2wx(temp);
2824 /*filename.Printf(_T("%s"),directory.c_str());
2825 filename.append(_T("\\"));
2826 filename.append(_T("%s"),namefile.c_str());
2827 filename.append(_T("-slice"));
2828 filename.append(_T("%d"),z);
2829 filename.append(_T("-cont"));
2830 filename.append(_T("%d"),iContourGroup);
2831 filename.append(_T(".txt"));*/
2832 // filename.Printf(temp.c_str());
2836 FILE *pFile=fopen((const char *)filename.mb_str(),"w+");
2837 fprintf(pFile,"value \t x \t y \t z\n" );
2838 int iLstValue,sizeLstValue=pLstValue.size();
2839 for (iLstValue=0 ; iLstValue<sizeLstValue ; iLstValue++ )
2841 fprintf(pFile,"%f\t %f\t %f\t %f\n", (float)pLstValue[iLstValue] , (float)pLstValuePosX[iLstValue], (float)pLstValuePosY[iLstValue], (float)z );
2844 } // for iContourGroup
2846 interfMainPanel::getInstance()->setStringInfoPanel(_T(""));
2847 //_staticTextInformation->SetLabel( _T("") );
2851 void wxContourMainFrame::getMaskValue(vtkImageData ** mask,vtkImageData ** value,int typeContourGroup, int selection, int minZ, int maxZ){
2854 //int typeContourGroup = this->_radiolstboxContourGroup->GetSelection();
2855 if (typeContourGroup==3)
2859 _contourextractdata ->SetTypeOperation( typeContourGroup % 3 );
2861 std::vector<manualBaseModel*> lstManConMod;
2862 std::vector<manualBaseModel*> lstManConModTmp;
2863 std::vector<manualBaseModel*> lstManConModExp;
2865 std::vector<int> tempVector;
2866 _instantPanel->getInstant( tempVector );
2868 vtkImageData *imagedata = _theViewPanel->getImageData();
2870 imagedata->GetExtent(ext);
2871 int sizeZimage = ext[5]-ext[4]+1;
2873 int ii,sizeLstContourThings;
2881 if (selection==0 ) // actual slice
2883 int actualSlice = tempVector[1];
2891 // cleanning image before range
2892 for (z=0; z<minZ; z++){
2893 _contourextractdata->ResetImageResult(z);
2895 // cleanning image after range
2896 for (z=maxZ+1; z<sizeZimage; z++){
2897 _contourextractdata->ResetImageResult(z);
2902 for ( z=minZ ; z<=maxZ ; z++)
2905 porcent = 100.0* (z-minZ)/totalZ;
2906 tmpString.Printf(_T("Saving Values"));
2907 tmpString.Printf(_T("%d %c %d/%d %d"), (int)porcent , 37 , z-minZ+1, (int)totalZ ,z);
2908 interfMainPanel::getInstance()->setStringInfoPanel(tmpString);
2910 //Extraction data from contours of each slice
2911 _contourextractdata->SetZtoBeAnalys( z);
2914 Instant instant(&tempVector);
2915 std::vector<ContourThing**> lstContourThings = kernelManager->getOutlinesAtInstant( &instant );
2916 sizeLstContourThings = lstContourThings.size();
2918 lstManConMod.clear();
2919 for (ii=0 ; ii<sizeLstContourThings ; ii++)
2921 ContourThing **contourthing = lstContourThings[ii];
2922 lstManConMod.push_back( (*contourthing)->getModel() );
2924 lstManConModExp = kernelManager->ExploseEachModel( lstManConMod );
2927 int iContourGroup,sizeContourGroup;
2928 if (typeContourGroup==3) // contour separete
2930 sizeContourGroup=lstManConModExp.size();
2931 } else { // contour AND OR XOR
2935 for( iContourGroup=0 ; iContourGroup<sizeContourGroup ; iContourGroup++ ){
2936 lstManConModTmp.clear();
2937 if (typeContourGroup==3) // contour separete
2939 lstManConModTmp.push_back( lstManConModExp[iContourGroup]);
2940 } else { // contour AND OR XOR
2941 lstManConModTmp = lstManConModExp;
2944 _contourextractdata->SetLstManualContourModel( lstManConModTmp );
2945 _contourextractdata->CalculateImageResult(); // with actual Z
2947 } // for iContourGroup
2950 (*value) = _contourextractdata->GetVtkImageValueResult();
2951 (*mask) = _contourextractdata->GetVtkImageMaskResult();
2955 std::string wxContourMainFrame::GetStringTypeImage( vtkImageData* image)
2957 std::string result="";
2958 if ( image->GetScalarType()==VTK_CHAR )
2961 } else if ( image->GetScalarType()==VTK_UNSIGNED_CHAR ){
2963 } else if ( image->GetScalarType()==VTK_FLOAT ){
2965 } else if ( image->GetScalarType()==VTK_DOUBLE ){
2967 } else if ( image->GetScalarType()==VTK_INT ){
2969 } else if ( image->GetScalarType()==VTK_UNSIGNED_INT ){
2971 } else if ( image->GetScalarType()==VTK_SHORT ){
2973 } else if ( image->GetScalarType()==VTK_UNSIGNED_SHORT ){
2975 } else if ( image->GetScalarType()==VTK_LONG ){
2977 } else if ( image->GetScalarType()==VTK_UNSIGNED_LONG ){
2983 void wxContourMainFrame::SaveImageResult(std::string directory,std::string namefile, vtkImageData* mask,vtkImageData* value)
2985 std::string stringType;
2987 kernelManager->GetSpacing(spc,0); // returns the spacing of the first image
2988 stringType = GetStringTypeImage(value);
2989 std::string temp = directory + "/" + namefile + "-image-Value-"+stringType+".mhd";
2991 wxString filename = crea::std2wx(temp);
2995 vtkImageChangeInformation *valueChInfo = vtkImageChangeInformation::New();
2996 //EED 2017-01-01 Migration VTK7
2997 #if VTK_MAJOR_VERSION <= 5
2998 valueChInfo->SetInput(value);
3000 valueChInfo->SetInputData(value);
3002 valueChInfo->SetSpacingScale(spc);
3003 valueChInfo->Update();
3004 vtkMetaImageWriter *writerValueImage = vtkMetaImageWriter::New( );
3006 //EED 2017-01-01 Migration VTK7
3007 #if VTK_MAJOR_VERSION <= 5
3008 writerValueImage->SetInput( valueChInfo->GetOutput() );
3010 writerValueImage->SetInputData( valueChInfo->GetOutput() );
3012 writerValueImage->SetFileName( (const char *)filename.mb_str() );
3013 writerValueImage->SetFileDimensionality( 3 );
3014 writerValueImage->SetCompression(false);
3015 writerValueImage->Write( );
3018 stringType = GetStringTypeImage(mask);
3019 temp = directory + "/" + namefile + "-image-Mask-"+stringType+".mhd";
3021 // LG 14/01/09 : using crea
3022 filename = crea::std2wx(temp);
3023 // filename.Printf(_T(temp.c_str()));
3026 vtkImageChangeInformation *maskChInfo = vtkImageChangeInformation::New();
3027 //EED 2017-01-01 Migration VTK7
3028 #if VTK_MAJOR_VERSION <= 5
3029 maskChInfo->SetInput(mask);
3031 maskChInfo->SetInputData(mask);
3033 maskChInfo->SetSpacingScale(spc);
3034 maskChInfo->Update();
3035 vtkMetaImageWriter *writerMaskImage = vtkMetaImageWriter::New( );
3037 //EED 2017-01-01 Migration VTK7
3038 #if VTK_MAJOR_VERSION <= 5
3039 writerMaskImage->SetInput( maskChInfo->GetOutput() );
3041 writerMaskImage->SetInputData( maskChInfo->GetOutput() );
3044 writerMaskImage->SetFileName( (const char *)filename.mb_str() );
3045 writerMaskImage->SetFileDimensionality( 3 );
3046 writerMaskImage->SetCompression(false);
3047 writerMaskImage->Write( );
3049 interfMainPanel::getInstance()->setStringInfoPanel( _T("") );
3055 void wxContourMainFrame::onChangeInstantInstantPanel(std::string name,int value, int minshow, int maxshow){
3056 if( name.compare( _theViewPanel->getVerticalConceptName() ) == 0){
3057 _theViewPanel->setActualVertical( value);
3059 else if( name.compare( _theViewPanel->getHorizontalConceptName() ) == 0|| _instantPanel->getIfConceptCheckedAt( name, 0 ) ) {
3060 _theViewPanel->setHorizontalConcept( name, minshow, maxshow, minshow, maxshow, value);
3066 void wxContourMainFrame::onSnakePressed(){
3067 std::vector<double> vecX;
3068 std::vector<double> vecY;
3069 std::vector<double> vecZ;
3070 _theViewPanel->GetPointsOfActualContour( &vecX , &vecY , &vecZ );
3072 if (vecX.size()!=0){
3073 std::vector<int> tempVector;
3074 _instantPanel->getInstant( tempVector );
3075 int i,size=vecZ.size();
3076 int actualSlice = tempVector[1];
3077 for ( i=0 ; i<size ; i++ )
3079 vecZ[i] = actualSlice;
3082 wxDialog* dialog = new wxDialog(this, -1, wxString(_T("Snake")));
3083 wxPanel* panel = new wxPanel(dialog,-1);
3084 // wxStaticText* sttext = new wxStaticText(panel, -1, wxString(_T("Panel para snake")));
3085 new wxStaticText(panel, -1, wxString(_T("Panel para snake")));
3086 dialog->ShowModal();
3091 void wxContourMainFrame::saveFileWithContoursAutomatique()
3093 printf("EED wxContourMainFrame::saveFileWithContoursAutomatique \n");
3094 std::string filename = kernelManager->getCurrentFileName();
3095 if(filename.compare("")!=0){
3096 saveFileWithContours(filename);
3101 void wxContourMainFrame::ShowToolsPanel(bool show)
3103 _pannew->Show(show);
3108 void wxContourMainFrame::SetContourGroup(int contourGroup)
3110 _contourGroup = contourGroup;
3114 wxPanel *wxContourMainFrame::getMaskImageViewPanel(wxWindow *parent)
3117 if (_viewMaskImagePanel==NULL)
3119 _contourextractdata = new ContourExtractData(true);
3120 _contourextractdata->SetImage( _theViewPanel->getImageData() );
3122 // _theViewPanel->getImageData()->GetScalarRange(range);
3123 //int min = (int)floor (range[0]);
3124 //int max = (int)ceil (range[1]);
3130 _viewMaskImagePanel = new ThresholdImageViewPanel( parent, -1, -1 , -1,-1, 0);
3131 _viewMaskImage = new ThresholdImageView();
3132 _viewMaskImage->SetImage( _contourextractdata->GetVtkImageMaskResult() );
3133 _viewMaskImage->SetminMaxValue( min, max);
3134 _viewMaskImage->SetBaseColor( 0,0,1 );
3137 std::vector<int> colorbarposition;
3138 colorbarposition.push_back( -999 );
3139 colorbarposition.push_back( -999 );
3140 _viewMaskImage->SetColorBarPosition( colorbarposition );
3142 _viewMaskImage->SetSpcBase( _theViewPanel->getImageData()->GetSpacing() );
3143 _viewMaskImage->SetNewSpacingLayer( _theViewPanel->getImageData()->GetSpacing() );
3145 _viewMaskImagePanel->SetThresholdImageView( _viewMaskImage );
3146 _viewMaskImage->SetwxVtkBaseView( _theViewPanel->getWxVtkBaseView() );
3147 _viewMaskImage->onThresholdChangeOpacity( 25 );
3149 return _viewMaskImagePanel;
3153 wxPanel *wxContourMainFrame::getColorLayerImageViewPanel(wxWindow *parent)
3155 if (_viewColorLayerImagePanel==NULL)
3158 _theViewPanel->getImageData()->GetScalarRange(range);
3159 int min = (int)floor (range[0]);
3160 int max = (int)ceil (range[1]);
3161 _viewColorLayerImagePanel = new ColorLayerImageViewPanel( parent, min, max, 100, 1);
3162 _viewColorLayerImagePanel->GetColorLayerImageViewManager()->SetwxVtkBaseView( 0 , _theViewPanel->getWxVtkBaseView() );
3163 // std::vector<double> range = bbGetInputlstRangeForColorBar();
3164 // clivp->GetColorLayerImageViewManager()->SetRangeForColorBar( range );
3165 std::vector<int> colorbarposition;
3166 colorbarposition.push_back( 50 );
3167 colorbarposition.push_back( 105 );
3168 _viewColorLayerImagePanel->GetColorLayerImageViewManager()->SetColorBarPosition( colorbarposition );
3169 // std::vector<double> base_color;
3170 // _viewColorLayerImagePanel->GetColorLayerImageViewManager()->SetBaseColors( base_color );
3171 // std::vector<double> grey_level_boundaries;
3172 // clivp->GetColorLayerImageViewManager()->SetGreyLevelBoundaries( grey_level_boundaries );
3173 std::vector<double> transparence_level_boundaries;
3174 transparence_level_boundaries.push_back(0);
3175 _viewColorLayerImagePanel->GetColorLayerImageViewManager()->SetBaseTransparence( transparence_level_boundaries );
3176 _viewColorLayerImagePanel->GetColorLayerImageViewManager()->SetPlainOrGradientColor( false );
3177 // _viewColorLayerImagePanel->SetFittingMode( 3 );
3179 return _viewColorLayerImagePanel;
3182 void wxContourMainFrame::SetColorLayerImage(vtkImageData* img)
3184 if (_viewColorLayerImagePanel!=NULL)
3188 _viewColorLayerImagePanel->SetActive(true);
3189 _viewColorLayerImagePanel->SetImage( img );
3190 // RefreshInterface();
3192 } // _viewColorLayerImagePanel
3195 wxPanel *wxContourMainFrame::getThresholdImageViewPanel(wxWindow *parent)
3197 if (_viewThresholdImagePanel==NULL)
3200 _theViewPanel->getImageData()->GetScalarRange(range);
3201 int min = (int)floor (range[0]);
3202 int max = (int)ceil (range[1]);
3203 int start = (max+min)/2 - (max-min)*0.25;
3204 int end = (max+min)/2 + (max-min)*0.25;
3205 _viewThresholdImagePanel = new ThresholdImageViewPanel( parent, min, max, start, end , 1);
3206 _viewThresholdImage = new ThresholdImageView();
3207 _viewThresholdImage->SetminMaxValue(start,end);
3208 // _viewThresholdImage->SetminMaxValue(range[0],range[1]);
3209 _viewThresholdImage->SetImage( _theViewPanel->getImageData() );
3210 std::vector<int> colorbarposition;
3211 colorbarposition.push_back( 10 );
3212 colorbarposition.push_back( 105 );
3213 _viewThresholdImage->SetColorBarPosition( colorbarposition );
3215 _viewThresholdImage->SetSpcBase( _theViewPanel->getImageData()->GetSpacing() );
3216 _viewThresholdImage->SetNewSpacingLayer( _theViewPanel->getImageData()->GetSpacing() );
3218 _viewThresholdImage->SetBaseColor( 1,0,0 );
3219 _viewThresholdImagePanel->SetThresholdImageView( _viewThresholdImage );
3220 _viewThresholdImage->SetwxVtkBaseView( _theViewPanel->getWxVtkBaseView() );
3221 _viewThresholdImage->onThresholdChangeOpacity( 25 );
3224 return _viewThresholdImagePanel;
3227 //CMRU 17-08-09-----------------------------------------------------------------------------------------------
3228 int wxContourMainFrame::getType ()
3231 std::vector<std::string> currentSelection = _theViewPanel->getSelectedObjects();
3233 if(!currentSelection.empty())
3235 std::string cloneName = currentSelection [0];
3236 manualBaseModel * manualModel = kernelManager->getOutlineByKeyName(cloneName);
3237 tipo = manualModel-> GetTypeModel();
3242 double wxContourMainFrame::getContourSizeInPixels()
3244 double contourSize = 0;
3246 std::vector<std::string> currentSelection = _theViewPanel->getSelectedObjects(); if(!currentSelection.empty())
3247 if(!currentSelection.empty())
3249 std::string cloneName = currentSelection [0];
3251 manualBaseModel * manualModel = kernelManager->getOutlineByKeyName(cloneName);//_modelManager->getOutlineByKeyName( cloneName )->getModel();
3254 // contourSize = manualModel->GetPathSize();
3259 contourSize = manualModel->GetPathSize( spc );
3264 manualBaseModel * wxContourMainFrame::getContour ()
3266 std::vector<std::string> currentSelection = _theViewPanel->getSelectedObjects();
3268 if(!currentSelection.empty())
3270 std::string cloneName = currentSelection [0];
3271 manualBaseModel * manualModel = kernelManager->getOutlineByKeyName(cloneName);//_modelManager->getOutlineByKeyName( cloneName )->getModel();
3276 void wxContourMainFrame::onPrintLabel (wxString label, manualBaseModel* manualModel)
3278 std::string labelAscii(label.ToAscii());
3279 int pos = labelAscii.find(" ");
3283 for (j=0 ; pos != string::npos;j++)
3285 labelAscii.replace( pos, 1, "_" );
3286 pos= labelAscii.find(" ");
3289 manualModel -> SetLabel(labelAscii);
3291 void wxContourMainFrame::onInsertCalculation(manualBaseModel* manualModel)
3294 // double sizeInPixel = manualModel ->GetPathSize( );
3299 double sizeInPixel = manualModel ->GetPathSize( spc );
3301 double onePixelRealSize = interfMainPanel::getInstance()->GetPixelValue();;
3302 double realContourSize = sizeInPixel*onePixelRealSize;
3303 manualModel ->SetRealSize(realContourSize);
3306 double wxContourMainFrame::onePixelSize( double value)
3308 return _onePixelSize = value;
3311 std::string wxContourMainFrame::GetFileLocation()
3313 return _fileLocation;
3316 void wxContourMainFrame::SetFileLocation(std::string newFileLocation)
3318 _fileLocation = newFileLocation;
3319 std::cout<<"GETFILELOCATION:"<<_fileLocation<<std::endl;
3322 kernelManager->setCurrentFileName(_fileLocation);
3324 //------------------------------------------------------------------------------------------------------------
3333 void wxContourMainFrame::FlipSelectedContours(int flipDirection)
3336 (std::vector<std::string>)_theViewPanel->getSceneManager()->getSelectedObjects() ,
3342 void wxContourMainFrame::FlipActualSliceContours(int flipDirection)
3345 (std::vector<std::string>)_theViewPanel->getSceneManager()->GetlstContoursNameActualSlice() ,
3350 void wxContourMainFrame::FlipAllContours(int flipDirection)
3353 kernelManager->GetLstNameThings() ,
3358 void wxContourMainFrame::FlipLstOfContours(std::vector<std::string> lstNameThings, int flipDirection)
3361 getImageData()->GetExtent(ext);
3362 int sizeX = ext[1]-ext[0];
3363 int sizeY = ext[3]-ext[2];
3366 int i,sizeLstNameThings;
3367 int ii,sizeLstPoints;
3369 sizeLstNameThings = lstNameThings.size();
3370 for (i=0 ; i<sizeLstNameThings ; i++)
3372 manualBaseModel * manualModel = kernelManager->getOutlineByKeyName(lstNameThings[i]);
3373 if (flipDirection==0)
3375 manualModel->Transform_Ax_Plus_B(-1,sizeX,1,0 );
3377 manualModel->Transform_Ax_Plus_B(1,0,-1,sizeY );
3379 }// for i list of Things
3381 //-- Static Contours
3383 lstNameThings = kernelManager->GetLstNameThingsStatic();
3384 sizeLstNameThings = lstNameThings.size();
3385 for (i=0 ; i<sizeLstNameThings ; i++)
3387 manualBaseModel * manualModel = kernelManager->getOutlineByKeyName(lstNameThings[i]);
3388 if (flipDirection==0)
3390 manualModel->Transform_Ax_Plus_B(-1,sizeX,1,0 );
3392 manualModel->Transform_Ax_Plus_B(1,0,-1,sizeY );
3394 }// for i list of static things
3397 void wxContourMainFrame::FlipContours(int typeContourFlip, int flipDirection)
3401 if (typeContourFlip==0) //
3403 FlipSelectedContours(flipDirection);
3406 if (typeContourFlip==1) //
3408 FlipActualSliceContours(flipDirection);
3411 if (typeContourFlip==2) //
3413 FlipAllContours(flipDirection);
3418 void wxContourMainFrame::SetXY(int x, int y)
3420 _theViewPanel->SetXY(x,y);
3423 wxVtkBaseView* wxContourMainFrame::GetWxVtkBaseView()
3425 if (_theViewPanel!=NULL)
3427 return _theViewPanel->getWxVtkBaseView();;