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 printf("EED wxContourMainFrame :: wxContourMainFrame Start 1\n");
64 m_mgr.SetManagedWindow(this);
66 _creatingContoursActive = false;
68 // _modelManager = NULL;
70 // _buttonsBar = NULL;
72 // _drawToolsPanel = NULL;
73 // _operationsToolsPanel = NULL;
74 //_autoFormsPanel = NULL;
75 // _standardToolsPanel = NULL;
76 // _editionToolsPanel = NULL;
77 // _listViewPanel = NULL;
78 // _sceneManager = NULL;
79 //_actualInstant = NULL;
80 _numberOfVariablesStatistics= 6+1;
82 _refLineControl = NULL;
85 // _actorPresent = false;
87 // set up default notebook style
88 // m_notebook_style =wxAUI_NB_TAB_SPLIT | wxAUI_NB_TAB_EXTERNAL_MOVE | wxNO_BORDER;
89 // m_notebook_theme = 0;
90 //wxContour_ActionCommandsID a;
92 _contourextractdata = NULL;
93 _viewMaskImage = NULL;
94 _viewMaskImagePanel = NULL;
95 _viewThresholdImage = NULL;
96 _viewThresholdImagePanel = NULL;
97 _viewColorLayerImagePanel = NULL;
98 printf("EED wxContourMainFrame :: wxContourMainFrame End 1\n");
101 wxContourMainFrame :: wxContourMainFrame(wxWindow* parent, wxWindowID id,const wxString& title,const wxPoint& pos,const wxSize& size,std::vector<vtkImageData*> images, long style,std::string datadir)
102 : wxPanel(parent, id, pos, size, style)
104 printf("EED wxContourMainFrame :: wxContourMainFrame Start 2\n");
105 m_mgr.SetManagedWindow(this);
107 _creatingContoursActive = false;
108 _theViewPanel = NULL;
110 _instantPanel = NULL;
111 _refLineControl = NULL;
112 _refLineModel = NULL;
114 // _actorPresent = false;
115 _viewMaskImage = NULL;
116 _viewMaskImagePanel = NULL;
117 _viewThresholdImage = NULL;
118 _viewThresholdImagePanel = NULL;
119 _viewColorLayerImagePanel = NULL;
120 printf("EED wxContourMainFrame :: wxContourMainFrame A\n");
121 // set up default notebook style
122 m_notebook_style = wxAUI_NB_TAB_SPLIT | wxAUI_NB_TAB_EXTERNAL_MOVE | wxNO_BORDER;
123 m_notebook_theme = 0;
124 //wxContour_ActionCommandsID a;
125 _numberOfVariablesStatistics= 7;
129 printf("EED wxContourMainFrame :: wxContourMainFrame B\n");
130 _pannew = interfMainPanel::getInstance(this,datadir+"/data/Icons");//, eventHandler);
131 printf("EED wxContourMainFrame :: wxContourMainFrame C\n");
132 _performingOperation = new PerformingOperation();
133 printf("EED wxContourMainFrame :: wxContourMainFrame C.1\n");
134 if(images.size() > 0)
136 printf("EED wxContourMainFrame :: wxContourMainFrame C.2\n");
137 this->setVectImages(images);
138 printf("EED wxContourMainFrame :: wxContourMainFrame C.3\n");
140 _contourextractdata = NULL;
141 printf("EED wxContourMainFrame :: wxContourMainFrame End 2\n");
144 void wxContourMainFrame::setVectImages(std::vector<vtkImageData*> imgs)
146 printf("EED wxContourMainFrame::setVectImages Start\n");
148 #if defined(__GNUC__)
149 std::string str_home(getenv("HOME"));
150 #elif defined(_WIN32)
151 std::string str_home(getenv("USERPROFILE"));
153 std::string strCreaContourDataTmp = str_home + "/.creaContourDataTemp/";
154 std::vector<std::string> conceptNameVect;
155 std::vector<int> conceptSizeVect;
156 printf("EED wxContourMainFrame::setVectImages Start 01\n");
157 notebook = this->createNotebook();
158 printf("EED wxContourMainFrame::setVectImages Start 02\n");
159 kernelManager = new KernelManagerContour( imgs , _datadir+"/data/" , strCreaContourDataTmp );
160 printf("EED wxContourMainFrame::setVectImages Start 03\n");
161 _instantPanel = new wxInstantChooserPanel( notebook, "Instant Chooser", true, false, "c" );
162 printf("EED wxContourMainFrame::setVectImages Start 04\n");
163 _theViewPanel = new wxContourViewPanel( kernelManager->getSourceImage(), notebook );
164 printf("EED wxContourMainFrame::setVectImages Start 05\n");
165 //-------------------------------------------------------------
166 kernelManager->getConceptsInformation(conceptNameVect, conceptSizeVect);
167 printf("EED wxContourMainFrame::setVectImages 1\n");
168 _instantPanel->addConcepts(conceptNameVect, conceptSizeVect);
169 printf("EED wxContourMainFrame::setVectImages 2\n");
170 double val = _theViewPanel->getCurrentDeep();
171 _instantPanel->setConceptValue( "Axe Depth", (int)val );
172 //JCP _instantPanel->setConceptValue("time", num de imagenes);
173 ConceptDataWrap * data = _instantPanel->getConceptDataOf( "Axe Depth" );
174 //*******************changeInstant();
175 _theViewPanel->setVerticalConcept( "Axe Depth", data->getMinValue(), data->getMaxValue(), data->getMinShowedValue(), data->getMaxShowedValue(), data->getActualValue() );
176 this->configurePanels( );
177 printf("EED wxContourMainFrame::setVectImages End\n");
181 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 )
183 if(instance == NULL){
184 instance = new wxContourMainFrame(parent, id, title, pos, size, images, style,datadir);
189 std::vector<vtkImageData*> wxContourMainFrame ::getVectImages()
191 return kernelManager->getVectImages();
194 wxContourMainFrame* wxContourMainFrame :: getInstance()
199 void wxContourMainFrame :: resetInstance()
204 wxContourMainFrame :: ~wxContourMainFrame()
206 delete _contourextractdata;
209 interfMainPanel::resetInstance();
210 delete kernelManager;
212 //_pannew->Destroy();
218 //El problema al cerrar la aplicacion puede estar asociado
219 //a que wxAUINotebook esta en la aplicacion
220 //principal (wxContourGUIExample)tambien
221 //EED???? delete _theViewPanel;
222 //EED???? delete _instantPanel;
223 //EED???? delete _buttonsBar;
224 //EED???? delete _actualInstant;
225 //EED???? delete _sceneManager;
229 //------------------------------------------------------------------------------------------------------------
230 // Creational and initialization methods using WxAui
231 //------------------------------------------------------------------------------------------------------------
233 wxAuiNotebook * wxContourMainFrame :: createNotebook()
235 wxSize client_size = GetClientSize();
236 wxAuiNotebook* noteBook = new wxAuiNotebook(this, -1, wxPoint(client_size.x, client_size.y), wxSize(430,200), m_notebook_style);
237 wxBitmap page_bmp = wxArtProvider::GetBitmap(wxART_NORMAL_FILE, wxART_OTHER, wxSize(16,16));
242 //------------------------------------------------------------------------------------------------------------
243 // Creational and initialization methods
244 //------------------------------------------------------------------------------------------------------------
245 bool wxContourMainFrame :: configurePanels( )
247 bool configured = _theViewPanel!=NULL;
249 configured &= _theViewPanel!=NULL;
250 if( _theViewPanel!=NULL )
252 notebook->AddPage( _theViewPanel, wxT(" View ") );
259 notebook->AddPage( _instantPanel, wxT("Instant Page") );
263 m_mgr.AddPane(notebook, wxAuiPaneInfo().Name(wxT("notebook_content")).CenterPane().PaneBorder(false));
266 SetMinSize(wxSize(300,300));
272 bool wxContourMainFrame::addNewPanel(wxPanel* panel)
274 bool configured = panel!=NULL;
275 configured &= panel!=NULL;
279 notebook->AddPage( panel, wxT(" Viewer "), true );
285 //------------------------------------------------------------------------------------------------------------
286 // Attributes getters and setters
287 //------------------------------------------------------------------------------------------------------------
291 void wxContourMainFrame :: setInstantChooserPanel( wxInstantChooserPanel * theInstantChooserPanel )
293 _instantPanel = theInstantChooserPanel;
296 // void wxContourMainFrame :: setButtonsBar( wxContour_ButtonsBar * theButtonsBar )
298 // _buttonsBar = theButtonsBar;
301 // void wxContourMainFrame :: setGrid( wxContour_Grid * theGridPanel )
303 // _gridPanel = theGridPanel;
306 // void wxContourMainFrame :: setDrawToolsPanel( wxContour_DrawToolsPanel * theDrawToolsPanel )
308 // _drawToolsPanel = theDrawToolsPanel;
311 // void wxContourMainFrame :: setOperationsToolsPanel( wxContour_OperationsToolsPanel * theOperationsToolsPanel )
313 // _operationsToolsPanel = theOperationsToolsPanel;
316 // void wxContourMainFrame :: setAutomaticFormsPanel( wxContour_AutomaticFormsToolsPanel * theAutoFormsPanel )
318 // _autoFormsPanel = theAutoFormsPanel;
321 // void wxContourMainFrame :: setStandardToolsPanel( wxContour_StandardToolsPanel * theStandardToolsPanel )
323 // _standardToolsPanel= theStandardToolsPanel;
326 // void wxContourMainFrame :: setEditionToolsPanel( wxContour_EdtionToolsPanel * theEditionToolsPanel )
328 // _editionToolsPanel = theEditionToolsPanel;
331 // void wxContourMainFrame :: setListViewPanel( wxContour_ListViewPanel * theListViewPanel )
333 // _listViewPanel = theListViewPanel;
338 void wxContourMainFrame::onCreateContourSpline( ){
340 //JCP 20-10-08 Undo redo implementation
342 //JCP 20-10-08 Undo redo implementation
346 void wxContourMainFrame::onCreateContourRectangle( ){
347 //JCP 20-10-08 Undo redo implementation
349 //JCP 20-10-08 Undo redo implementation
352 void wxContourMainFrame::onCreateContourCircle( ){
353 //JCP 20-10-08 Undo redo implementation
355 //JCP 20-10-08 Undo redo implementation
359 void wxContourMainFrame::onCreateContourLine( ){
360 //JCP 20-10-08 Undo redo implementation
362 //JCP 20-10-08 Undo redo implementation
366 // RaC 09-09 --------------------------------------
367 void wxContourMainFrame::onCreateContourPoints( ){
368 //JCP 20-10-08 Undo redo implementation
370 //JCP 20-10-08 Undo redo implementation
373 // RaC 09-09 --------------------------------------
375 // RaC 10-09 --------------------------------------
376 void wxContourMainFrame::onCreateContourPolygon( ){
377 //JCP 20-10-08 Undo redo implementation
379 //JCP 20-10-08 Undo redo implementation
382 // RaC 10-09 --------------------------------------
384 //------------------------------------------------------------------------------------------------------------
386 void wxContourMainFrame :: onCreateContourBullEye(wxPanel* panel )
388 //Creating the manualBaseModel and including in the model
389 manualBaseModel * manModelContour = factoryManualContourModel(panel );
391 std::vector<int> instantVector;
392 _instantPanel->getInstant( instantVector );
393 std::string theName = kernelManager->createOutline(manModelContour, instantVector);
395 /*std::vector<int> instantVector;
396 _instantPanel->getInstant( instantVector );
398 theName= _modelManager->createOutline( manModelContour, instantVector );*/
399 bool addedModel = theName.compare("") != 0;//??
403 double spc[3];//Si no hay imagen pero hay contornos que spacing se pone por default
404 _theViewPanel->getSpacing(spc);
405 //Adding the manualContourControler to interface objects structure
406 //Adding the manualViewContour to interface objects structure
407 //_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.
408 _theViewPanel->getSceneManager()->configureViewControlTo( theName, manModelContour,spc , 4) ;
411 void wxContourMainFrame :: createContour( int typeContour )
413 //Creating the manualContourModel and including in the model
414 manualBaseModel * manModelContour = kernelManager->factoryManualContourModel(typeContour);
416 std::vector<int> instantVector;
417 _instantPanel->getInstant( instantVector );
418 std::string theName = kernelManager->createOutline(manModelContour, instantVector);
420 /*std::vector<int> instantVector;
421 _instantPanel->getInstant( instantVector );
423 theName= _modelManager->createOutline( manModelContour, instantVector );*/
424 bool addedModel = theName.compare("") != 0;//??
427 double spc[3];//Si no hay imagen pero hay contornos que spacing se pone por default
428 _theViewPanel->getSpacing(spc);
429 //Adding the manualContourControler to interface objects structure
430 //Adding the manualViewContour to interface objects structure
431 //_sceneManager->setControlActiveStateOfALL( false );//This call is being done here because if the ROI is created underneath the previously created ROIS will still be active.
432 _theViewPanel->getSceneManager()->configureViewControlTo( theName, manModelContour,spc , typeContour) ;
436 manualBaseModel * wxContourMainFrame::factoryManualContourModel(wxPanel* panel){
438 manualContourModelBullEye *manModelContourBullEye = new manualContourModelBullEye();
439 manualBaseModel *manModelContour=NULL;
440 manModelContour = manModelContourBullEye;
442 int iCrown,sizeCrowns,iSector,sizeSectors;
443 double radioA,radioB,ang,angDelta ;
444 sizeCrowns = ((PanelBullEyeOptions*)panel)->GetNumberOfCrowns();
445 for ( iCrown=0 ; iCrown<sizeCrowns ; iCrown++ )
447 sizeSectors = ((PanelBullEyeOptions*)panel)->GetNumberOfSections(iCrown);
448 radioB = ((PanelBullEyeOptions*)panel)->GetRadioOfCrown(iCrown);
449 if (iCrown==sizeCrowns-1)
453 radioA = ((PanelBullEyeOptions*)panel)->GetRadioOfCrown(iCrown+1);
457 for ( iSector=0 ; iSector<sizeSectors ; iSector++ )
459 ang = ((PanelBullEyeOptions*)panel)->GetAngOfCrownSection(iCrown,iSector);
460 angDelta= ((PanelBullEyeOptions*)panel)->GetAngDeltaOfCrownSection(iCrown);
461 manModelContourBullEye->AddSector(radioA,radioB,ang,angDelta);
464 } // if _panelBullEyeOptions
466 return manModelContour;
468 void wxContourMainFrame :: saveState(){
470 std::string temp = kernelManager->saveState();
471 saveFileWithContours(temp);
474 void wxContourMainFrame::onDeleteContour(){
475 //JCP 20-10-08 Undo redo implementation
477 //JCP 20-10-08 Undo redo implementation
479 std::vector<std::string> lstKeyNameToBeErase;
480 lstKeyNameToBeErase = _theViewPanel->getSceneManager()->getSelectedObjects();
481 deleteContours( lstKeyNameToBeErase );
483 int i,size=_sceneManager->getSelectedObjects().size();
486 std::string keyName = _sceneManager->getSelectedObjects()[i];
487 int ispartofstaticlist = this->_modelManager->IsPartOfStaticList( keyName );
488 if ( ispartofstaticlist>=0 )
490 std::vector<int> tempVector;
491 _instantPanel->getInstant( tempVector );
492 Instant instant(&tempVector);
493 this->_modelManager->ChangeContourOfList(keyName, &instant);
497 std::vector<std::string> lstKeyName;
498 std::vector<std::string> lstKeyNameActualSlice;
499 std::vector<std::string> lstKeyNameToBeErase;
501 lstKeyNameToBeErase = _sceneManager->getSelectedObjects();
502 lstKeyNameActualSlice = _sceneManager->GetlstContoursNameActualSlice();
503 int k,kSize=lstKeyNameToBeErase.size();
504 int j,jSize=lstKeyNameActualSlice.size();
506 for (k=0;k<kSize; k++)
509 for (j=0;j<jSize; j++)
511 if (lstKeyNameToBeErase[k]==lstKeyNameActualSlice[j])
518 lstKeyName.push_back( lstKeyNameToBeErase[k] );
522 deleteContours( lstKeyName );
526 void wxContourMainFrame :: deleteContours( std::vector<std::string> keyNamesVector )
528 int i,size=keyNamesVector.size();
531 deleteContour( keyNamesVector[i] );
535 void wxContourMainFrame :: deleteContour( std::string theKeyName ){
537 manualContourModel * cModel;
538 manualViewBaseContour * cViewer;
539 manualContourBaseControler * cControler;
541 ContourWrap_ViewControl *conwrapviewControl = _theViewPanel->getSceneManager()->getContourWrap_ViewControlOf( theKeyName );
542 cControler = conwrapviewControl->getControler();*/
545 bool isedit = _theViewPanel->isEditableCControler(theKeyName);
546 bool ispartofstaticlst = kernelManager->IsPartOfStaticList(theKeyName);
548 if (isedit && ispartofstaticlst)
550 _theViewPanel->removeFromScene(theKeyName);
552 kernelManager->deleteCModel(theKeyName);
553 //_theViewPanel->getSceneManager()->removeFromScene( theKeyName );
554 //cViewer = conwrapviewControl->getViewer();
555 //_theViewPanel->getSceneManager()->removeWrap( theKeyName );
556 //cControler* conwrapviewControl->getControler();
559 // delete cControler;
564 void wxContourMainFrame::onDeleteContoursActSlice(){
565 //JCP 20-10-08 Undo redo implementation
567 //JCP 20-10-08 Undo redo implementation
568 deleteContours( (std::vector<std::string>)_theViewPanel->getSceneManager()->GetlstContoursNameActualSlice() );
570 void wxContourMainFrame::onDeleteAllContours(){
571 //JCP 20-10-08 Undo redo implementation
575 void wxContourMainFrame::deleteAllContours(){
576 //JCP 20-10-08 Undo redo implementation
579 std::vector<int> tempVector;
580 _instantPanel->getInstant( tempVector );
582 //JCP --08-09-2008 When using a diferent interface the _mbarrangeDeleteAll might not be initialize
583 // the values in GetStart and GetEnd will then not be initialize also.
584 // We use instead the values given when initializing the _deletepanel.
586 //int minZ = _mbarrangeDeleteAll->GetStart();
587 //int maxZ = _mbarrangeDeleteAll->GetEnd();
591 maxZ = _theViewPanel->getSceneManager()->GetImageDataSizeZ();
595 _theViewPanel->getSceneManager()->removeSceneContours( );
596 _theViewPanel->getSceneManager()->removeAllOutlines();
597 kernelManager->removeAllOutlines();
600 if ( (minZ==0) && (maxZ==_mbarrangeDeleteAll->GetMax() ))
602 _theViewPanel->getSceneManager()->removeSceneContours( );
603 _modelManager->removeAllOutlines();
604 _theViewPanel->getSceneManager()->removeAllOutlines();
607 for ( z=minZ ; z<=maxZ ; z++)
610 Instant instant(&tempVector);
611 std::vector<ContourThing**> lstContourThings = this->_modelManager->getOutlinesAtInstant( &instant );
613 sizeLstContourThings = lstContourThings.size();
614 for (ii=0 ; ii<sizeLstContourThings ; ii++)
616 ContourThing **contourthing = lstContourThings[ii];
617 deleteContour( (*contourthing)->getName() );
624 void wxContourMainFrame::setConceptValue( std::string name, int value ){
625 _instantPanel->setConceptValue(name, value);
629 ConceptDataWrap* wxContourMainFrame::getLastConceptData(){
630 return _instantPanel->getLastConceptData();
634 bool wxContourMainFrame::getIfConceptCheckedAt( std::string name, int pos ){
635 return _instantPanel->getIfConceptCheckedAt( name, pos );
640 void wxContourMainFrame::ShowResultImages(int typeContourGroup, int selection, int minZ, int maxZ)
643 vtkImageData * value;
644 this->getMaskValue(&mask, &value, typeContourGroup, selection, minZ, maxZ);
646 std::vector<int> nTypeView;
647 nTypeView.push_back(5);
648 nTypeView.push_back(1);
649 nTypeView.push_back(2);
650 nTypeView.push_back(0);
652 wxFrame *frame = new wxFrame(this, -1,_T("Result image extracted.."),wxDefaultPosition,wxSize(600,600), wxDEFAULT_FRAME_STYLE|wxSTAY_ON_TOP);
653 wxAuiManager *m_mgr_noteBookViewerResult = new wxAuiManager();
654 m_mgr_noteBookViewerResult->SetManagedWindow(frame);
656 wxAuiNotebook* noteBookViewerResult = new wxAuiNotebook(frame, -1, wxPoint(600, 600), wxSize(430,200), m_notebook_style);
657 m_mgr_noteBookViewerResult->AddPane(noteBookViewerResult, wxAuiPaneInfo().Name(wxT("notebook_content")).CenterPane().PaneBorder(false));
659 wxPanel *panelViewer1 = new wxMaracas_N_ViewersWidget(noteBookViewerResult, value,&nTypeView);
660 wxPanel *panelViewer2 = new wxMaracas_N_ViewersWidget(noteBookViewerResult, mask,&nTypeView);
663 noteBookViewerResult->AddPage( panelViewer1, wxT("Image result") );
664 noteBookViewerResult->AddPage( panelViewer2, wxT("Mask result") );
665 m_mgr_noteBookViewerResult->Update();
672 void wxContourMainFrame::changeInstant()
674 std::vector<int> instantVect;
675 _instantPanel->getInstant( instantVect );
676 int actualSlice = instantVect[1];
678 kernelManager->setInstant(instantVect);
680 // Refresh Mask image
681 if(_viewMaskImage!=NULL){
682 _viewMaskImage->SetZ(actualSlice);
683 if (_viewMaskImagePanel->IsVisible()==true)
685 vtkImageData *mask, *value;
686 getMaskValue(&mask,&value, _contourGroup , 0, -1, -1);
687 _viewMaskImage->onThreshold();
691 // Refresh Threshold image
692 if(_viewThresholdImage!=NULL){
693 _viewThresholdImage->SetZ(actualSlice);
694 if (_viewThresholdImagePanel->IsVisible()==true){
695 _viewThresholdImage->onThreshold();
700 updateInstantOutlines();
701 updateInstantImageData();
707 void wxContourMainFrame :: updateInstantOutlines()
709 _theViewPanel->removeSceneContours();
710 _theViewPanel->addNameWrapperToScene();
712 //for( int i=0; i<size; i++)
714 // _theViewPanel->getSceneManager()->addToScene(namesWrapping[i]->getKeyName(), true, true, true, false, false );
718 int wxContourMainFrame::getNamesWrappingSize(){
719 return kernelManager->getNamesWrappingSize();
721 std::string wxContourMainFrame::getNameWrapping(int i){
722 return kernelManager->getNameWrapping(i);
725 void wxContourMainFrame::updateInstantImageData()
727 std::vector<int> inst;
728 _instantPanel->getInstant(inst);
730 vtkImageData* img = kernelManager->getImageAtInstant(inst);
732 _theViewPanel->changeImage(img);
735 int z = _instantPanel->getConceptDataOf("Axe Depth")->getActualValue();
736 _theViewPanel->setImageSlice(z);
740 void wxContourMainFrame::updateInstantAxes()
745 void wxContourMainFrame::onChangeDeep(int val){
746 _instantPanel->setConceptValue( "Axe Depth", (int)val );
751 void wxContourMainFrame::onCopy(){
752 std::vector<std::string> currentSelection = _theViewPanel->getSelectedObjects();
754 std::vector<int> tempVector;
755 _instantPanel->getInstant( tempVector );
756 _performingOperation->reset();
757 _performingOperation->setStartCommand( COPY );
758 _performingOperation->setStartOperationInstantVector( tempVector );
759 _performingOperation->setKeyNamesOperationElems( currentSelection );
762 void wxContourMainFrame::onPaste(){
765 char theStartCommand = _performingOperation->getStartCommand();
766 if ( theStartCommand == COPY )
768 //JCP 20-10-08 Undo redo implementation
770 //JCP 20-10-08 Undo redo implementation
771 std::vector<int> tempVector;
772 _instantPanel->getInstant( tempVector );
773 _performingOperation->setEndOperationInstantVector ( tempVector );
774 std::vector<std::string> elems = _performingOperation->getKeyNamesOperationElems();
775 int i,size = elems.size();
776 for( i=0; i<size; i++ )
778 createCopyContourOf( elems[i], tempVector, i>0 );
782 void wxContourMainFrame::onUndo(){
783 std::string filename;
784 if(kernelManager->onUndoSaveFile(filename)){
785 saveFileWithContours(filename);
787 if(kernelManager->onUndo(filename)){
791 void wxContourMainFrame::onRedo(){
792 std::string filename;
793 if(kernelManager->onRedo(filename)){
798 void wxContourMainFrame :: createCopyContourOf ( std::string anExistingKName, std::vector<int> &instantNoTouchData, bool append )
800 std::string cloneName = kernelManager->createCopyContourOf( anExistingKName, instantNoTouchData );
801 manualBaseModel * manualModel = kernelManager->getOutlineByKeyName(cloneName);//_modelManager->getOutlineByKeyName( cloneName )->getModel();
802 _theViewPanel->getSceneManager()->createCopyContourOf( anExistingKName, cloneName, manualModel , append );
805 ///AD: 03-09 Copy the object and apply the given transformation
806 void wxContourMainFrame :: createMirrorContourOf ( std::string anExistingKName, std::vector<int> &instantNoTouchData, bool append )
808 std::string cloneName = kernelManager->createCopyContourOf( anExistingKName, instantNoTouchData );
809 manualBaseModel * manualModel = kernelManager->getOutlineByKeyName(cloneName);
811 manualPoint * refPoint1 = _refLineModel->GetManualPoint(0);
812 manualPoint * refPoint2 = _refLineModel->GetManualPoint(1);
814 double pnt1X = refPoint1->GetX();
815 double pnt1Y = refPoint1->GetY();
816 // double pnt1Z = refPoint1->GetZ();
817 double pnt2X = refPoint2->GetX();
818 double pnt2Y = refPoint2->GetY();
819 // double pnt2Z = refPoint2->GetZ();
821 double angle = (atan2(pnt2Y - pnt1Y, pnt2X - pnt1X) * 180 / 3.1415926535897932384626433832795)+90;
822 vtkTransform *t = vtkTransform::New();
826 t->Translate(-pnt1X, -pnt1Y, 0);
830 t->Translate(pnt1X, pnt1Y, 0);
833 int i,size=manualModel->GetSizeLstPoints();
836 manualPoint * mp = manualModel->GetManualPoint(i);
842 t->TransformPoint( vecIn, vecOut );
843 mp->SetPointX( vecOut[0] );
844 mp->SetPointY( vecOut[1] );
845 mp->SetPointZ( vecOut[2] );
848 _theViewPanel->getSceneManager()->createCopyContourOf( anExistingKName, cloneName, manualModel , append );
852 void wxContourMainFrame ::loadState(std::string filename){
855 onLoadContours(filename,false);
859 FILE *pFile=fopen(filename.c_str(),"r+");
861 fscanf(pFile,"%s",tmp); // --CreaContour--
863 fscanf(pFile,"%s",tmp); // Version
864 fscanf(pFile,"%s",tmp); // 1.0.3 || 1.0.2 || 1.0.1 || 1.0.0
868 loadContours(pFile, false);
869 loadContours(pFile, true);
878 void wxContourMainFrame::loadContours( FILE *pFile, bool staticContour )
882 if (staticContour==false)
884 fscanf(pFile,"%s",tmp); // ImageDimensions
885 fscanf(pFile,"%s",tmp); // X
886 fscanf(pFile,"%s",tmp); // Y
887 fscanf(pFile,"%s",tmp); // Z
889 fscanf(pFile,"%s",tmp); // ImageSpacing
890 fscanf(pFile,"%s",tmp); // X
891 fscanf(pFile,"%s",tmp); // Y
892 fscanf(pFile,"%s",tmp); // Z
895 fscanf(pFile,"%s",tmp); // NumberOfContours
896 fscanf(pFile,"%s",tmp); // ##
897 int numberOfContours = atoi(tmp);
899 std::vector<int> instantVector;
900 int typeContourModel;
901 manualBaseModel *manModelContour;
905 for (i=0;i<numberOfContours;i++)
907 instantVector.clear();
908 fscanf(pFile,"%s",tmp); // Instant
909 fscanf(pFile,"%s",tmp); // 1
910 instantVector.push_back( atoi(tmp) );
911 fscanf(pFile,"%s",tmp); // 2
912 instantVector.push_back( atoi(tmp) );
913 fscanf(pFile,"%s",tmp); // 3
914 instantVector.push_back( atoi(tmp) );
915 fscanf(pFile,"%s",tmp); // 4
916 instantVector.push_back( atoi(tmp) );
917 fscanf(pFile,"%s",tmp); // 5
918 instantVector.push_back( atoi(tmp) );
919 fscanf(pFile,"%s",tmp); // 6
920 instantVector.push_back( atoi(tmp) );
922 fscanf(pFile,"%s",tmp); // TypeContourModel
923 fscanf(pFile,"%s",tmp); // ##
924 typeContourModel = atoi(tmp);
926 manModelContour = kernelManager->factoryManualContourModel(typeContourModel);
927 manModelContour->Open(pFile);
929 fscanf(pFile,"%s",tmp); // TypeView
930 fscanf(pFile,"%s",tmp); // ##
931 typeView = atoi(tmp);
934 theName = kernelManager->createOutline( manModelContour, instantVector );
935 bool addedModel = theName.compare("") != 0;
938 double spc[3];//Si no hay imagen pero hay contornos que spacing se pone por default
939 _theViewPanel->getSpacing(spc);
940 //Adding the manualContourControler to interface objects structure
941 //Adding the manualViewContour to interface objects structure
942 //_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.
943 _theViewPanel->getSceneManager()->configureViewControlTo( theName, manModelContour,spc , typeView) ;
946 if (staticContour==true)
948 Instant instant(&instantVector);
949 kernelManager->changeContourOfManager( theName , &instant );
951 }// for numberOfContours
956 void wxContourMainFrame::onLoad()
958 std::string fileNameContourROI = GetFileLocation();
959 //CMRU 03-09-09-----------------------------------------------------------------------------------------------
960 if(GetFileLocation().empty())
962 //------------------------------------------------------------------------------------------------------------
963 //EED 2017-09-16 Migration wxWidgets 2.8 to 3.0
964 #if wxMAJOR_VERSION <= 2
965 wxFileDialog dialog(NULL, _T("Choose a file"), _T(""), _T(""), _T("*.roi"), wxOPEN );
967 wxFileDialog dialog(NULL, _T("Choose a file"), _T(""), _T(""), _T("*.roi"), wxFD_OPEN );
969 if (dialog.ShowModal() == wxID_OK)
971 fileNameContourROI = (const char *)(dialog.GetPath().mb_str());
975 onLoadContours(fileNameContourROI,true);
979 void wxContourMainFrame::SetZForAllContours(int pz)
981 printf("EED wxContourMainFrame::SetZForAllContours\n");
985 std::vector< std::string > lstNameThings;
986 int i,sizeLstNameThings;
987 int ii,sizeLstPoints;
989 lstNameThings = kernelManager->GetLstNameThings();
990 sizeLstNameThings = lstNameThings.size();
991 for (i=0 ; i<sizeLstNameThings ; i++)
993 printf("EED wxContourMainFrame::SetZForAllContours contour=%d \n", i );
994 manualBaseModel * manualModel = kernelManager->getOutlineByKeyName(lstNameThings[i]);
995 sizeLstPoints = manualModel->GetSizeLstPoints();
996 for (ii=0 ; ii<sizeLstPoints ; ii++)
998 manualModel->GetManualPoint(ii)->SetPointZ(-900);
999 }// for ii list of points
1000 }// for i list of Things
1002 //-- Static Contours
1004 lstNameThings = kernelManager->GetLstNameThingsStatic();
1005 sizeLstNameThings = lstNameThings.size();
1006 for (i=0 ; i<sizeLstNameThings ; i++)
1008 manualBaseModel * manualModel = kernelManager->getOutlineByKeyName(lstNameThings[i]);
1009 sizeLstPoints = manualModel->GetSizeLstPoints();
1010 for (ii=0 ; ii<sizeLstPoints ; ii++)
1012 manualModel->GetManualPoint(ii)->SetPointZ(-900);
1013 }// for ii list of points
1014 }// for i list of static things
1017 void wxContourMainFrame::onLoadContours(std::string fileNameContourROI, bool interactiveInterface)
1021 FILE *pFile =fopen(fileNameContourROI.c_str(),"r+");
1022 //CMRU 03-09-09- ----------------------------------------------------------------------------------------------
1025 //------------------------------------------------------------------------------------------------------------
1026 fileNameContourROI.append("data");
1027 FILE *pFileData=fopen(fileNameContourROI.c_str(),"r+");
1028 if(pFileData != NULL)
1030 fscanf(pFileData,"%s",tmpD); // --CreaContour--
1031 fscanf(pFileData,"%s",tmpD); // Version
1032 fscanf(pFileData,"%s",tmpD); // 1.0.3 || 1.0.2 || 1.0.1 || 1.0.0
1034 fscanf(pFileData,"%s",tmpD); // onePixelSize
1035 fscanf(pFileData,"%s",tmpD); // #
1036 _onePixelSize = atof(tmpD);
1037 fscanf(pFileData,"%s",tmpD); // NumberOfContours
1038 fscanf(pFileData,"%s",tmpD); // #
1041 fscanf(pFile,"%s",tmp); // --CreaContour--
1043 fscanf(pFile,"%s",tmp); // Version
1044 fscanf(pFile,"%s",tmp); // 1.0.3 || 1.0.2 || 1.0.1 || 1.0.0
1045 std::string version(tmp);
1048 printf("EED wxContourMainFrame::onLoadContours version%s \n", version.c_str() );
1052 _tmpReadFileTypeOfTransformation=-1;
1053 if (version=="1.0.3")
1055 readDimSpc(pFile,interactiveInterface); // DimSpc interactive ON
1056 openContours(pFile,pFileData,false);
1057 openContours(pFile,pFileData,true); //Load StaticContours
1060 if (version=="1.0.2")
1063 readDimSpc(pFile,interactiveInterface); // DimSpc interactive ON
1064 openContours(pFile,pFileData,false);
1065 readDimSpc(pFile,false); // DimSpc interactive OFF
1066 openContours(pFile,pFileData,true); // Load StaticContours
1067 SetZForAllContours(-900);
1071 else if (version=="1.0.1")
1073 openContours(pFile,pFileData,false); //Skips ImageDimensions and ImageSpacing
1074 openContours(pFile,pFileData,true); //Load StaticContours, skips ImageDimensions and ImageSpacing
1078 else if (version=="1.0.0")
1080 openContours(pFile,pFileData,false); //Skips ImageDimensions and ImageSpacing
1085 if(pFileData != NULL)
1090 _theViewPanel->getSceneManager()->removeSceneContours();
1095 void wxContourMainFrame::onImport()
1097 std::string filename, filenamecontours;
1098 //EED 2017-09-16 Migration wxWidgets 2.8 to 3.0
1099 #if wxMAJOR_VERSION <= 2
1100 wxFileDialog dialog(NULL, _T("Choose a XML Osirix File"), _T(""), _T(""), _T("*.xml"), wxOPEN );
1102 wxFileDialog dialog(NULL, _T("Choose a XML Osirix File"), _T(""), _T(""), _T("*.xml"), wxFD_OPEN );
1104 if (dialog.ShowModal() == wxID_OK)
1106 filename = dialog.GetPath().mb_str();
1107 filenamecontours = kernelManager->parseOsirixFile(filename);
1109 if(filenamecontours.compare("") != 0){
1110 onLoadContours(filenamecontours,true);
1115 void wxContourMainFrame::onTest()
1117 std::string filename, filenamecontours;
1118 //EED 2017-09-16 Migration wxWidgets 2.8 to 3.0
1119 #if wxMAJOR_VERSION <= 2
1120 wxFileDialog dialog(NULL, _T("Choose a File"), _T(""), _T(""), _T("*.*"), wxOPEN );
1122 wxFileDialog dialog(NULL, _T("Choose a File"), _T(""), _T(""), _T("*.*"), wxFD_OPEN );
1125 if (dialog.ShowModal() == wxID_OK)
1127 filename = dialog.GetPath().mb_str();
1128 std::cout << "This is the filename: " << filename << std::endl;
1134 void wxContourMainFrame::onSave(){
1135 //CMRU 03-09-09-----------------------------------------------------------------------------------------------
1136 if(GetFileLocation().empty())
1138 //------------------------------------------------------------------------------------------------------------
1139 //EED 2017-09-16 Migration wxWidgets 2.8 to 3.0
1140 #if wxMAJOR_VERSION <= 2
1141 wxFileDialog dialog(NULL, _T("Choose a file"), _T(""), _T(""), _T("*.roi"), wxSAVE );
1143 wxFileDialog dialog(NULL, _T("Choose a file"), _T(""), _T(""), _T("*.roi"), wxFD_SAVE );
1145 if (dialog.ShowModal() == wxID_OK)
1147 std::string fileNameContourROI = (const char *)(dialog.GetPath().mb_str());
1148 kernelManager->setCurrentFileName(fileNameContourROI);
1149 saveFileWithContours( fileNameContourROI );
1152 //CMRU 03-09-09-----------------------------------------------------------------------------------------------
1155 std::cout<<"Nombre del archivo: "<<GetFileLocation()<<std::endl;
1156 std::string fileNameContourROI = GetFileLocation();
1157 std::cout<<"Nombre del archivo: "<<fileNameContourROI<<std::endl;
1158 kernelManager->setCurrentFileName(fileNameContourROI);
1159 saveFileWithContours( fileNameContourROI);
1161 //------------------------------------------------------------------------------------------------------------
1165 void wxContourMainFrame::saveFileWithContours( std::string filename )
1168 FILE *pFile=fopen(filename.c_str(),"w+");
1170 //CMRU 03-09-09-----------------------------------------------------------------------------------------------
1171 filename.append("data");
1172 std::cout<<"Nombre del archivo: "<<filename<<std::endl;
1173 FILE *pFileData=fopen(filename.c_str(),"w+");
1174 //------------------------------------------------------------------------------------------------------------
1176 std::vector< std::string > lstNameThings;
1177 int i,sizeLstNameThings;
1179 fprintf(pFile,"--CreaContour--\n");
1180 fprintf(pFile,"Version %s\n", "1.0.3" );
1182 //CMRU 03-09-09-----------------------------------------------------------------------------------------------
1183 fprintf(pFileData,"--CreaContour--\n");
1184 fprintf(pFileData,"Version %s\n", "1.0.3" );
1185 fprintf(pFileData,"OnePixelSize %f\n", _onePixelSize);
1187 //------------------------------------------------------------------------------------------------------------
1189 vtkImageData *image = _images[0];
1192 image->GetDimensions(dimRange);
1194 fprintf(pFile,"ImageDimensions %d %d %d\n", dimRange[0], dimRange[1], dimRange[2] );
1197 image->GetSpacing(spaRange);
1199 fprintf(pFile,"ImageSpacing %f %f %f\n", spaRange[0], spaRange[1], spaRange[2] );
1203 lstNameThings = kernelManager->GetLstNameThings();
1204 sizeLstNameThings = lstNameThings.size();
1205 fprintf(pFile,"NumberOfContours %d\n", sizeLstNameThings );
1207 //CMRU 03-09-09-----------------------------------------------------------------------------------------------
1208 fprintf(pFileData,"NumberOfContours %d\n", sizeLstNameThings );
1209 //------------------------------------------------------------------------------------------------------------
1218 for (i=0 ; i<sizeLstNameThings ; i++)
1220 //CMRU 03-09-09-----------------------------------------------------------------------------------------------
1221 manualBaseModel * manualModel = kernelManager->getOutlineByKeyName(lstNameThings[i]);
1224 // double sizeInPixel = manualModel ->GetPathSize( );
1225 double sizeInPixel = manualModel ->GetPathSize( spc );
1227 double realContourSize = sizeInPixel*_onePixelSize;
1228 manualModel ->SetRealSize(realContourSize);
1229 //------------------------------------------------------------------------------------------------------------
1231 //int size= kernelManager->GetLstNameThings().size();
1233 kernelManager->SaveThingName( pFile, pFileData, lstNameThings[i] );
1234 _theViewPanel->getSceneManager()->SaveThingName( pFile, lstNameThings[i] );
1237 //-- Static Contours
1239 // fprintf(pFile,"ImageDimensions %d %d %d\n", dimRange[0], dimRange[1], dimRange[2] );
1240 // fprintf(pFile,"ImageSpacing %f %f %f\n", spaRange[0], spaRange[1], spaRange[2] );
1242 lstNameThings = kernelManager->GetLstNameThingsStatic();
1243 sizeLstNameThings = lstNameThings.size();
1244 fprintf(pFile,"NumberOfContoursStatic %d\n", sizeLstNameThings );
1246 //CMRU 03-09-09-----------------------------------------------------------------------------------------------
1247 fprintf(pFileData,"NumberOfContoursStatic %d\n", sizeLstNameThings );
1248 //------------------------------------------------------------------------------------------------------------
1250 for (i=0 ; i<sizeLstNameThings ; i++)
1252 kernelManager->SaveThingName( pFile, pFileData, lstNameThings[i] );
1253 _theViewPanel->getSceneManager()->SaveThingName( pFile, lstNameThings[i] );
1261 void wxContourMainFrame::readDimSpc(FILE *pFile, bool interactiveOption)
1265 double imageSpac[3];
1266 vtkImageData *image = _images[0];
1267 image->GetDimensions(imageDim);
1268 image->GetSpacing(imageSpac);
1270 fscanf(pFile,"%s",tmp); // ImageDimensions
1271 fscanf(pFile,"%s",tmp); // X
1272 _tmpReadFileImageDim[0] = atoi(tmp);
1273 fscanf(pFile,"%s",tmp); // Y
1274 _tmpReadFileImageDim[1] = atoi(tmp);
1275 fscanf(pFile,"%s",tmp); // Z
1276 _tmpReadFileImageDim[2] = atoi(tmp);
1278 fscanf(pFile,"%s",tmp); // ImageSpacing
1279 fscanf(pFile,"%s",tmp); // X
1280 _tmpReadFileImageSpac[0] = atof(tmp);
1281 fscanf(pFile,"%s",tmp); // Y
1282 _tmpReadFileImageSpac[1] = atof(tmp);
1283 fscanf(pFile,"%s",tmp); // Z
1284 _tmpReadFileImageSpac[2] = atof(tmp);
1287 if (interactiveOption==true)
1289 //Compare Spacing and Dims in X and Y (Necessary in Z?) - Just for Version 2
1290 if (imageDim[0]!=_tmpReadFileImageDim[0] || imageDim[1]!=_tmpReadFileImageDim[1] || imageSpac[0]!=_tmpReadFileImageSpac[0] || imageSpac[1]!=_tmpReadFileImageSpac[1])
1292 wxDialog* dial = new wxDialog (this,-1,_T("Tools"),wxDefaultPosition, wxSize(460,360));
1293 wxSizer* buttonsSizer = dial->CreateSeparatedButtonSizer(wxOK|wxCANCEL);
1294 wxBoxSizer *dialSizer = new wxBoxSizer(wxVERTICAL);
1296 wxString lstOptOperation[2];
1297 lstOptOperation[0]=_T("By Dimension");
1298 lstOptOperation[1]=_T("By Spacing");
1299 wxRadioBox * radioOpts = new wxRadioBox(dial, -1, _T("Type of Transformation"), wxDefaultPosition, wxSize(270,45), 2 , lstOptOperation, 2, wxRA_SPECIFY_COLS);
1301 dialSizer->Add( new wxStaticText(dial,-1,_T("The image resolution is not compatible with the ")) , 0, wxGROW );
1302 dialSizer->Add( new wxStaticText(dial,-1,_T("selected Roi file. Do you want to tranform it?")) , 0, wxGROW );
1303 dialSizer->Add( new wxStaticText(dial,-1,_T(" ")) , 0, wxGROW );
1304 dialSizer->Add(radioOpts,0,wxGROW);
1305 dialSizer->Add( new wxStaticText(dial,-1,_T(" ")) , 0, wxGROW );
1306 dialSizer->Add(buttonsSizer,0,wxGROW);
1307 dial->SetSizer(dialSizer, true);
1311 int _tmpReadFileTypeOfTransformation = -1;
1312 //EED bool transform = false;
1314 if (dial->GetReturnCode() == wxID_OK)
1316 _tmpReadFileTypeOfTransformation = radioOpts->GetSelection();
1320 } // if interactiveOption
1327 void wxContourMainFrame::openContours( FILE *pFile, FILE *pFileData, bool staticContour )
1332 vtkImageData *image = _images[0];
1335 double imageSpac[3];
1336 image->GetDimensions(imageDim);
1337 image->GetSpacing(imageSpac);
1340 fscanf(pFile,"%s",tmp); // NumberOfContours
1341 fscanf(pFile,"%s",tmp); // ##
1342 int numberOfContours = atoi(tmp);
1344 std::vector<int> instantVector;
1345 int typeContourModel;
1346 manualBaseModel *manModelContour;
1350 if (compatible==true)
1353 for (i=0;i<numberOfContours;i++)
1355 instantVector.clear();
1356 fscanf(pFile,"%s",tmp); // Instant
1358 fscanf(pFile,"%s",tmp); // 1
1359 instantVector.push_back( atoi(tmp) );
1360 fscanf(pFile,"%s",tmp); // 2
1361 instantVector.push_back( atoi(tmp) );
1362 fscanf(pFile,"%s",tmp); // 3
1363 instantVector.push_back( atoi(tmp) );
1364 fscanf(pFile,"%s",tmp); // 4
1365 instantVector.push_back( atoi(tmp) );
1366 fscanf(pFile,"%s",tmp); // 5
1367 instantVector.push_back( atoi(tmp) );
1368 fscanf(pFile,"%s",tmp); // 6
1369 instantVector.push_back( atoi(tmp) );
1372 fscanf(pFile,"%s",tmp); // TypeContourModel
1373 fscanf(pFile,"%s",tmp); // ##
1374 typeContourModel = atoi(tmp);
1376 manModelContour = kernelManager->factoryManualContourModel(typeContourModel);
1377 manModelContour->Open(pFile);
1378 if(pFileData != NULL)
1380 manModelContour->OpenData(pFileData);
1383 fscanf(pFile,"%s",tmp); // TypeView
1384 fscanf(pFile,"%s",tmp); // ##
1385 typeView = atoi(tmp);
1387 std::string theName;
1388 theName = kernelManager->createOutline( manModelContour, instantVector );
1389 bool addedModel = theName.compare("") != 0;
1392 double spc[3];//Si no hay imagen pero hay contornos que spacing se pone por default
1393 _theViewPanel->getSpacing(spc);
1394 //Adding the manualContourControler to interface objects structure
1395 //Adding the manualViewContour to interface objects structure
1396 //_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.
1397 _theViewPanel->getSceneManager()->configureViewControlTo( theName, manModelContour,spc , typeView) ;
1400 if (staticContour) //StaticContours (will appear in all slices)
1402 Instant instant(&instantVector);
1403 kernelManager->changeContourOfManager( theName , &instant );
1406 }// for numberOfContours
1409 else if (compatible==false)
1414 for (i=0;i<numberOfContours;i++)
1416 instantVector.clear();
1417 fscanf(pFile,"%s",tmp); // Instant
1419 fscanf(pFile,"%s",tmp); // 1
1420 instantVector.push_back( atoi(tmp) );
1421 fscanf(pFile,"%s",tmp); // 2
1422 instantVector.push_back( atoi(tmp) );
1423 fscanf(pFile,"%s",tmp); // 3
1424 instantVector.push_back( atoi(tmp) );
1425 fscanf(pFile,"%s",tmp); // 4
1426 instantVector.push_back( atoi(tmp) );
1427 fscanf(pFile,"%s",tmp); // 5
1428 instantVector.push_back( atoi(tmp) );
1429 fscanf(pFile,"%s",tmp); // 6
1430 instantVector.push_back( atoi(tmp) );
1432 fscanf(pFile,"%s",tmp); // TypeContourModel
1433 fscanf(pFile,"%s",tmp); // ##
1434 typeContourModel = atoi(tmp);
1436 manModelContour = kernelManager->factoryManualContourModel(typeContourModel);
1437 manModelContour->Open(pFile);
1438 if(pFileData != NULL)
1440 manModelContour->OpenData(pFileData);
1443 if (_tmpReadFileTypeOfTransformation==-1){
1445 } else if (_tmpReadFileTypeOfTransformation==0){
1446 double transX, transY;
1447 transX = (double) imageDim[0]/_tmpReadFileImageDim[0];
1448 transY = (double) imageDim[1]/_tmpReadFileImageDim[1];
1449 manModelContour->Transform_Ax_Plus_B(transX,0,transY,0);
1450 } else if (_tmpReadFileTypeOfTransformation==1) {
1451 double transX, transY;
1452 transX = (double) _tmpReadFileImageSpac[0]/imageDim[0];
1453 transY = (double) _tmpReadFileImageSpac[1]/imageDim[1];
1454 manModelContour->Transform_Ax_Plus_B(transX,0,transY,0);
1457 fscanf(pFile,"%s",tmp); // TypeView
1458 fscanf(pFile,"%s",tmp); // ##
1459 typeView = atoi(tmp);
1461 std::string theName;
1462 theName = kernelManager->createOutline( manModelContour, instantVector );
1463 bool addedModel = theName.compare("") != 0;
1466 double spc[3];//Si no hay imagen pero hay contornos que spacing se pone por default
1467 _theViewPanel->getSpacing(spc);
1468 //Adding the manualContourControler to interface objects structure
1469 //Adding the manualViewContour to interface objects structure
1470 //_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.
1471 _theViewPanel->getSceneManager()->configureViewControlTo( theName, manModelContour,spc , typeView) ;
1474 if (staticContour) //StaticContours (will appear in all slices)
1476 Instant instant(&instantVector);
1477 kernelManager->changeContourOfManager( theName , &instant );
1479 }// for numberOfContours
1485 void wxContourMainFrame::RefreshInterface(){
1487 _theViewPanel->RefreshInterface();
1488 //wxVtk2DBaseView *wxvtk2dbaseview = (wxVtk2DBaseView*)this->_theViewPanel->getWxVtkBaseView();
1489 //wxvtk2dbaseview->Refresh();
1492 vtkImageData* wxContourMainFrame::getImageData(){
1493 return _theViewPanel->getImageData();
1496 void wxContourMainFrame::onSegmentationOneSliceITK(wxString distance, wxString sigma, wxString alfa, wxString beta, wxString propagation, wxString iterations, wxString inflation)
1498 //JCP 20-10-08 Undo redo implementation
1500 //JCP 20-10-08 Undo redo implementation
1503 int x = _theViewPanel->GetX();
1504 int y = _theViewPanel->GetY();
1505 int z = _theViewPanel->GetZ();
1506 SegmentationOneSliceITK( x,y,z,distance, sigma, alfa, beta, propagation, iterations, inflation);
1510 void wxContourMainFrame::SegmentationOneSliceITK(int x, int y, int z, wxString distanc, wxString sigm, wxString alf, wxString bet, wxString prop, wxString iter, wxString inflation)
1512 int typeofcontour = 1;
1514 vtkImageData *imagedata = getImageData();
1516 //Tipo de pixeles a utilizar internamente en ITK
1517 typedef float InternalPixelType;
1518 const unsigned int Dimension = 2;
1519 typedef itk::Image< InternalPixelType, Dimension > InternalImageType;
1521 //Tipo de pixeles de salida 1
1522 typedef unsigned char OutputPixelType;
1523 typedef itk::Image< OutputPixelType, Dimension > OutputImageType;
1525 //Tipo de pixeles de salida 2
1526 typedef unsigned short OutputPixelType2;
1527 typedef itk::Image< OutputPixelType2, Dimension > OutputImageType2;
1529 //DefiniciÛn del thresholder
1530 typedef itk::BinaryThresholdImageFilter<
1532 OutputImageType > ThresholdingFilterType;
1534 //DefiniciÛn del primer filtro de conversiÛn de pixeles
1535 typedef itk::CastImageFilter<
1536 OutputImageType, OutputImageType2 > CastFilterType;
1538 //DefiniciÛn del segundo tipo de conversiÛn de pixeles
1539 typedef itk::CastImageFilter<
1540 OutputImageType2, InternalImageType > CastFilterType2;
1542 //Tercer tipo de conversiÛn
1543 typedef itk::RescaleIntensityImageFilter<
1545 OutputImageType > CastFilterType3;
1547 //Cuarto tipo de conversiÛn
1548 typedef itk::RescaleIntensityImageFilter<
1550 OutputImageType > CastFilterType4;
1552 ThresholdingFilterType::Pointer thresholder = ThresholdingFilterType::New();
1554 thresholder->SetLowerThreshold( 0.0 );
1555 thresholder->SetUpperThreshold( 128 );
1557 thresholder->SetOutsideValue( 255 );
1558 thresholder->SetInsideValue( 0 );
1560 //DefinciÛn de conexiÛnes entre VTK e ITK y el writer
1561 typedef itk::VTKImageToImageFilter<OutputImageType2> ConnectorType;
1562 typedef itk::ImageToVTKImageFilter<OutputImageType> ConnectorType2;
1563 //EED10JUIN2011 typedef itk::ImageFileWriter< OutputImageType > WriterType;
1565 ConnectorType::Pointer connector= ConnectorType::New();
1566 ConnectorType2::Pointer connector2= ConnectorType2::New();
1569 CastFilterType::Pointer filter=CastFilterType::New();
1570 CastFilterType2::Pointer filter2=CastFilterType2::New();
1572 connector->SetInput( imagedata );
1573 filter2->SetInput(connector->GetOutput());
1575 typedef itk::CurvatureAnisotropicDiffusionImageFilter<
1577 InternalImageType > SmoothingFilterType;
1579 SmoothingFilterType::Pointer smoothing = SmoothingFilterType::New();
1581 typedef itk::GradientMagnitudeRecursiveGaussianImageFilter<
1583 InternalImageType > GradientFilterType;
1585 typedef itk::SigmoidImageFilter<
1587 InternalImageType > SigmoidFilterType;
1589 GradientFilterType::Pointer gradientMagnitude = GradientFilterType::New();
1591 SigmoidFilterType::Pointer sigmoid = SigmoidFilterType::New();
1593 sigmoid->SetOutputMinimum( 0.0 );
1594 sigmoid->SetOutputMaximum( 255.0 );
1597 typedef itk::FastMarchingImageFilter<
1599 InternalImageType > FastMarchingFilterType;
1602 FastMarchingFilterType::Pointer fastMarching = FastMarchingFilterType::New();
1604 printf("EED wxContourMainFrame::SegmentationOneSliceITK Skypping this code. Not compiling GeodesicActiveContourLevelSetImageFilter in fedora 17 with ITK 3.20.1 \n ");
1606 > - > - > - > - > - > - > - > - > - > - > - > - > - > - > - > - Not compiling GeodesicActiveContourLevelSetImageFilter in fedora 17 with ITK 3.20.1
1609 typedef itk::GeodesicActiveContourLevelSetImageFilter< InternalImageType,
1610 InternalImageType > GeodesicActiveContourFilterType;
1611 GeodesicActiveContourFilterType::Pointer geodesicActiveContour =
1612 GeodesicActiveContourFilterType::New();
1614 typedef itk::ZeroCrossingImageFilter<
1616 InternalImageType > ZeroCrossingFilterType;
1617 ZeroCrossingFilterType::Pointer zeroCrossing =
1618 ZeroCrossingFilterType::New();
1620 const double propagationScaling = atof( crea::wx2std(prop).c_str() );
1622 geodesicActiveContour->SetPropagationScaling( propagationScaling );
1623 geodesicActiveContour->SetCurvatureScaling( 1.0 );
1624 geodesicActiveContour->SetAdvectionScaling( 1.0 );
1626 geodesicActiveContour->SetMaximumRMSError( 0.02 );
1627 int it=atoi( crea::wx2std(iter).c_str() );
1628 geodesicActiveContour->SetNumberOfIterations( it );
1630 smoothing->SetInput( filter2->GetOutput() );
1631 gradientMagnitude->SetInput( smoothing->GetOutput() );
1632 sigmoid->SetInput( gradientMagnitude->GetOutput() );
1633 fastMarching->SetInput( sigmoid->GetOutput() );
1634 geodesicActiveContour->SetInput( fastMarching->GetOutput() );
1635 geodesicActiveContour->SetFeatureImage( sigmoid->GetOutput() );
1637 zeroCrossing->SetInput( geodesicActiveContour->GetOutput() );
1638 //thresholder->SetInput( zeroCrossing->GetOutput() );
1639 thresholder->SetInput( geodesicActiveContour->GetOutput() );
1640 connector2->SetInput( thresholder->GetOutput() );
1642 < - < - < - < - < - < - < - < - < - < - < - < - < - < - < - < - < - < - < - < -
1648 smoothing->SetTimeStep( 0.125 );
1649 smoothing->SetNumberOfIterations( 5 );
1650 smoothing->SetConductanceParameter( 9.0 );
1653 const double sigma = atof( crea::wx2std(sigm).c_str() );
1654 gradientMagnitude->SetSigma( sigma );
1656 const double alpha = atof( crea::wx2std(alf).c_str() );
1657 const double beta = atof( crea::wx2std(bet).c_str() );
1659 sigmoid->SetAlpha( alpha );
1660 sigmoid->SetBeta( beta );
1662 typedef FastMarchingFilterType::NodeContainer NodeContainer;
1663 typedef FastMarchingFilterType::NodeType NodeType;
1665 NodeContainer::Pointer seeds = NodeContainer::New();
1667 InternalImageType::IndexType seedPosition;
1668 seedPosition[0] = x;
1669 seedPosition[1] = y;
1671 const double initialDistance = atof( crea::wx2std(distanc).c_str() );
1675 const double seedValue = - initialDistance;
1677 node.SetValue( seedValue );
1678 node.SetIndex( seedPosition );
1680 seeds->Initialize();
1681 seeds->InsertElement( 0, node );
1683 fastMarching->SetTrialPoints( seeds );
1685 fastMarching->SetSpeedConstant( 1.0 );
1687 fastMarching->SetOutputSize(
1688 connector->GetOutput()->GetBufferedRegion().GetSize() );
1690 fastMarching->SetStoppingValue( 800 );
1694 connector2->Update();
1695 vtkImageData *idata = connector2->GetOutput();
1697 vtkMarchingContourFilter* cntVTK = vtkMarchingContourFilter::New( );
1699 cntVTK->SetNumberOfContours( 1 );
1700 cntVTK->SetValue( 0, 255 );
1701 //EED 2017-01-01 Migration VTK7
1702 #if VTK_MAJOR_VERSION <= 5
1703 cntVTK->SetInput( idata );
1705 cntVTK->UpdateInformation();
1707 cntVTK->SetInputData( idata );
1710 vtkCleanPolyData* cpd = vtkCleanPolyData::New( );
1712 //EED 2017-01-01 Migration VTK7
1713 #if VTK_MAJOR_VERSION <= 5
1714 cpd->SetInput( cntVTK->GetOutput( ) );
1716 cpd->UpdateInformation();
1718 cpd->SetInputData( cntVTK->GetOutput( ) );
1722 vtkPolyDataConnectivityFilter* conn = vtkPolyDataConnectivityFilter::New( );
1723 conn->SetExtractionModeToLargestRegion( );
1724 //EED 2017-01-01 Migration VTK7
1725 #if VTK_MAJOR_VERSION <= 5
1726 conn->SetInput( cpd->GetOutput( ) );
1728 conn->UpdateInformation();
1730 conn->SetInputData( cpd->GetOutput( ) );
1734 vtkStripper* vtkstripper = vtkStripper::New( );
1736 //EED 2017-01-01 Migration VTK7
1737 #if VTK_MAJOR_VERSION <= 5
1738 vtkstripper->SetInput( conn->GetOutput() );
1739 vtkstripper->Update();
1740 vtkstripper->UpdateInformation();
1742 vtkstripper->SetInputData( conn->GetOutput() );
1746 vtkPolyData* polyDataResult = cntVTK->GetOutput();
1747 //std::cout<<"Points "<<polyDataResult->GetNumberOfPoints()<<std::endl;
1749 //EED 2017-01-01 Migration VTK7
1750 #if VTK_MAJOR_VERSION <= 5
1751 polyDataResult->Update( );
1752 polyDataResult->UpdateInformation();
1760 myfile.open ("C:/Creatis/example.txt");
1762 polyDataResult->Print(myfile);
1763 myfile << "-------------------------------------\n";
1764 polyDataResult->GetLines()->Print(myfile);
1772 //--Calculating control points
1774 std::vector<double> vecX;
1775 std::vector<double> vecY;
1776 std::vector<double> vecXo;
1777 std::vector<double> vecYo;
1778 std::vector<double>::iterator vecXoi;
1779 std::vector<double>::iterator vecYoi;
1780 std::vector<double> vecZ;
1782 std::vector<double> vecCtrlPointX;
1783 std::vector<double> vecCtrlPointY;
1784 std::vector<double> vecCtrlPointZ;
1790 int ii,size=polyDataResult->GetNumberOfPoints();
1792 myfile.open ("C:/Creatis/example2.txt");
1794 size=polyDataResult->GetNumberOfPoints();
1795 for (ii=0;ii<size;ii++)
1802 p = polyDataResult->GetPoint(ii);
1805 /*if(fabs(yAct-y)>20)
1807 if((xAct-x)>1 || (xAct-x)<-1)
1809 vecX.push_back( p[0] );
1810 vecY.push_back( p[1] );
1811 myfile <<p[0]<<","<<p[1]<<"\n";
1812 std::cout<<" x Anterior "<<xAct<<" x actual "<<x<<std::endl;
1813 std::cout<<" y Anterior "<<yAct<<" y actual "<<y<<std::endl;
1814 std::cout<<" x "<<p[0]<<" y "<<p[1]<<std::endl;
1815 vecZ.push_back( 900 );
1821 vecXo.push_back(p[0]);
1822 vecYo.push_back(p[1]);
1826 else*/ if(fabs(xAct-x)>11)
1828 vecXo.push_back(p[0]);
1829 vecYo.push_back(p[1]);
1833 vecX.push_back( p[0] );
1834 myfile <<p[0]<<","<<p[1]<<"\n";
1835 //std::cout<<" x Anterior "<<xAct<<" x actual "<<x<<std::endl;
1836 //std::cout<<" y Anterior "<<yAct<<" y actual "<<y<<std::endl;
1837 //std::cout<<" x "<<p[0]<<" y "<<p[1]<<std::endl;
1838 vecY.push_back( p[1] );
1839 vecZ.push_back( 900 );
1847 while(!vecXo.empty())
1849 vecX.push_back(vecXo.back());
1850 //std::cout<<" x Siguiente "<<vecXo.back();
1852 vecZ.push_back( 900 );
1854 while(!vecYo.empty())
1856 vecY.push_back(vecYo.back());
1861 /*for(int l=0;l<vecX.size();l++)
1865 vecXo.push_back(p[0]);
1866 vecYo.push_back(p[1]);
1877 ExtractControlPoints2D *extractcontrolpoints2d = new ExtractControlPoints2D();
1879 extractcontrolpoints2d->SetContour( &vecX , &vecY , &vecZ );
1883 extractcontrolpoints2d->GetInitialControlPoints( &vecCtrlPointX , &vecCtrlPointY , &vecCtrlPointZ );
1885 else if (method==1){
1886 extractcontrolpoints2d->GetControlPoints( &vecCtrlPointX , &vecCtrlPointY , &vecCtrlPointZ );
1888 else if (method==2){
1889 extractcontrolpoints2d->SetSamplingControlPoints( 15 );
1890 extractcontrolpoints2d->GetSamplingControlPoints( &vecCtrlPointX , &vecCtrlPointY , &vecCtrlPointZ );
1892 //--Adding contour to the system
1894 std::vector<int> actualInstantVector;
1895 _instantPanel->getInstant( actualInstantVector );
1896 actualInstantVector[1]=z;
1898 int j,sizeCtrPt = vecCtrlPointX.size();
1900 manualBaseModel *manModelContour = kernelManager->factoryManualContourModel( typeofcontour );
1901 manModelContour->SetNumberOfPointsSpline( ((sizeCtrPt/100)+1)*100 );
1903 for (j=0 ; j<sizeCtrPt ; j++)
1905 manModelContour->AddPoint( vecCtrlPointX[j] , vecCtrlPointY[j] , vecCtrlPointZ[j] );
1907 std::string theName;
1908 //theName = _modelManager->createOutline( manModelContour, actualInstantVector );
1909 theName = kernelManager->createOutline( manModelContour, actualInstantVector );
1910 bool addedModel = theName.compare("") != 0;
1913 double spc[3];//Si no hay imagen pero hay contornos que spacing se pone por default
1914 _theViewPanel->getSpacing(spc);
1915 //Adding the manualContourControler to interface objects structure
1916 //Adding the manualViewContour to interface objects structure
1917 //_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.
1918 _theViewPanel->configureViewControlTo(theName, manModelContour, spc, typeofcontour);
1919 //_theViewPanel->getSceneManager()->configureViewControlTo( theName, manModelContour,spc, typeofcontour ) ;
1926 WriterType::Pointer writer = WriterType::New();
1927 CastFilterType3::Pointer caster = CastFilterType3::New();
1929 caster->SetInput( gradientMagnitude->GetOutput() );
1930 writer->SetInput( caster->GetOutput() );
1931 writer->SetFileName("Gradient Magnitude.png");
1932 caster->SetOutputMinimum( 0 );
1933 caster->SetOutputMaximum( 255 );
1936 CastFilterType3::Pointer caster2 = CastFilterType3::New();
1937 WriterType::Pointer writer2 = WriterType::New();
1939 caster2->SetInput( sigmoid->GetOutput() );
1940 writer2->SetInput( caster2->GetOutput() );
1941 writer2->SetFileName("Sigmoid.png");
1942 caster2->SetOutputMinimum( 0 );
1943 caster2->SetOutputMaximum( 255 );
1946 CastFilterType3::Pointer caster3 = CastFilterType3::New();
1947 WriterType::Pointer writer3 = WriterType::New();
1949 caster3->SetInput( fastMarching->GetOutput() );
1950 writer3->SetInput( caster3->GetOutput() );
1951 writer3->SetFileName("FastMarching.bmp");
1952 caster3->SetOutputMinimum( 0 );
1953 caster3->SetOutputMaximum( 255 );
1956 CastFilterType3::Pointer caster4 = CastFilterType3::New();
1957 WriterType::Pointer writer4 = WriterType::New();
1959 caster4->SetInput( geodesicActiveContour->GetOutput() );
1960 writer4->SetInput( caster4->GetOutput() );
1961 writer4->SetFileName("GeodesicActiveContour.png");
1962 caster4->SetOutputMinimum( 0 );
1963 caster4->SetOutputMaximum( 255 );
1966 CastFilterType3::Pointer caster5 = CastFilterType3::New();
1967 WriterType::Pointer writer5 = WriterType::New();
1969 caster5->SetInput( zeroCrossing->GetOutput() );
1970 writer5->SetInput( caster5->GetOutput() );
1971 writer5->SetFileName("ZeroCrossing.bmp");
1972 caster5->SetOutputMinimum( 0 );
1973 caster5->SetOutputMaximum( 255 );
1977 catch( itk::ExceptionObject & excep )
1979 std::cerr << "Exception caught !" << std::endl;
1980 std::cerr << excep << std::endl;
1984 void wxContourMainFrame::onSegmentationOneSlice(int isovalue,int sampling,int method){
1986 //JCP 20-10-08 Undo redo implementation
1988 //JCP 20-10-08 Undo redo implementation
1991 int x = _theViewPanel->GetX();
1992 int y = _theViewPanel->GetY();
1993 int z = _theViewPanel->GetZ();
1994 SegmentationOneSlice( x,y,z,isovalue, sampling, method );
1999 void wxContourMainFrame::SegmentationOneSlice( int x, int y, int z, int isovalue, int sampling, int method )
2001 int typeofcontour = 1;
2002 //--Extracting Contour
2003 //vtkImageData *imagedata = _theViewPanel->getSceneManager()->GetImageData();
2004 vtkImageData *imagedata = getImageData();
2005 // double *range = imagedata->GetScalarRange();
2008 vtkImageReslice *imageReslice = vtkImageReslice::New();
2011 // imagedata->GetSpacing(spc);
2016 //EED 2017-01-01 Migration VTK7
2017 #if VTK_MAJOR_VERSION <= 5
2018 imageReslice->SetInput( imagedata );
2020 imageReslice->SetInputData( imagedata );
2022 imageReslice->SetInformationInput(imagedata);
2023 imageReslice->SetResliceAxesDirectionCosines(1,0,0, 0,1,0 ,0,0,1);
2024 imageReslice->SetResliceAxesOrigin(0,0,z);
2025 imageReslice->SetOutputDimensionality(2);
2026 imageReslice->SetInterpolationModeToLinear();
2028 //EED 2017-01-01 Migration VTK7
2029 #if VTK_MAJOR_VERSION <= 5
2032 imageReslice->Update();
2035 imagedata = imageReslice->GetOutput();
2036 //EED 2017-01-01 Migration VTK7
2037 #if VTK_MAJOR_VERSION <= 5
2038 imagedata->Update();
2039 imagedata->UpdateInformation();
2044 vtkContourFilter* cntVTK = vtkContourFilter::New( );
2045 //EED 2017-01-01 Migration VTK7
2046 #if VTK_MAJOR_VERSION <= 5
2047 cntVTK->SetInput( imagedata );
2049 cntVTK->SetInputData( imagedata );
2052 cntVTK->SetNumberOfContours( 1 );
2053 //cntVTK->SetValue( 0, vmin );
2054 // cntVTK->SetValue( 0, (range[1]*thr/100) );
2055 cntVTK->SetValue( 1, isovalue );
2056 // cntVTK->SetValue( 1, vmax );
2058 cntVTK->UpdateInformation();
2060 vtkCleanPolyData* cpd = vtkCleanPolyData::New( );
2061 //EED 2017-01-01 Migration VTK7
2062 #if VTK_MAJOR_VERSION <= 5
2063 cpd->SetInput( cntVTK->GetOutput( ) );
2065 cpd->SetInputData( cntVTK->GetOutput( ) );
2067 cpd->ConvertLinesToPointsOff( );
2069 cpd->UpdateInformation();
2071 vtkPolyDataConnectivityFilter* conn = vtkPolyDataConnectivityFilter::New( );
2072 conn->SetExtractionModeToClosestPointRegion( );
2073 //conn->SetMaxRecursionDepth( 3000 );
2075 //EED 2017-01-01 Migration VTK7
2076 #if VTK_MAJOR_VERSION <= 5
2077 conn->SetInput( cpd->GetOutput( ) );
2079 conn->SetInputData( cpd->GetOutput( ) );
2082 conn->SetClosestPoint( x, y, 0 );
2084 conn->UpdateInformation();
2086 vtkCleanPolyData* cpd2 = vtkCleanPolyData::New( );
2087 //EED 2017-01-01 Migration VTK7
2088 #if VTK_MAJOR_VERSION <= 5
2089 cpd2->SetInput( conn->GetOutput( ) );
2091 cpd2->SetInputData( conn->GetOutput( ) );
2094 cpd2->UpdateInformation();
2096 vtkStripper* vtkstripper = vtkStripper::New( );
2097 //EED 2017-01-01 Migration VTK7
2098 #if VTK_MAJOR_VERSION <= 5
2099 vtkstripper->SetInput( cpd2->GetOutput() );
2101 vtkstripper->SetInputData( cpd2->GetOutput() );
2103 vtkstripper->Update();
2104 vtkstripper->UpdateInformation();
2107 vtkPolyData* polyDataResult = vtkstripper->GetOutput();
2109 //EED 2017-01-01 Migration VTK7
2110 #if VTK_MAJOR_VERSION <= 5
2111 polyDataResult->Update( );
2112 polyDataResult->UpdateInformation();
2119 myfile.open ("c:/temp/example.txt");
2121 polyDataResult->Print(myfile);
2122 myfile << "-------------------------------------\n";
2123 polyDataResult->GetLines()->Print(myfile);
2133 //--Calculating control points
2135 std::vector<double> vecX;
2136 std::vector<double> vecY;
2137 std::vector<double> vecZ;
2139 std::vector<double> vecCtrlPointX;
2140 std::vector<double> vecCtrlPointY;
2141 std::vector<double> vecCtrlPointZ;
2145 int ii,size=polyDataResult->GetNumberOfPoints();
2147 for (ii=1;ii<=size;ii++)
2149 id = polyDataResult->GetLines()->GetData()->GetValue(ii);
2150 p = polyDataResult->GetPoint(id);
2153 vecX.push_back( p[0] );
2154 vecY.push_back( p[1] );
2155 vecZ.push_back( 900 );
2156 // vecZ.push_back( p[2] );
2160 ExtractControlPoints2D *extractcontrolpoints2d = new ExtractControlPoints2D();
2161 extractcontrolpoints2d->SetContour( &vecX , &vecY , &vecZ );
2164 /*if (methodRadiobox->GetSelection()==0){
2165 extractcontrolpoints2d->GetInitialControlPoints( &vecCtrlPointX , &vecCtrlPointY , &vecCtrlPointZ );
2167 if (methodRadiobox->GetSelection()==1){
2168 extractcontrolpoints2d->GetControlPoints( &vecCtrlPointX , &vecCtrlPointY , &vecCtrlPointZ );
2170 if (methodRadiobox->GetSelection()==2){
2171 extractcontrolpoints2d->SetSamplingControlPoints( sampling );
2172 extractcontrolpoints2d->GetSamplingControlPoints( &vecCtrlPointX , &vecCtrlPointY , &vecCtrlPointZ );
2176 extractcontrolpoints2d->GetInitialControlPoints( &vecCtrlPointX , &vecCtrlPointY , &vecCtrlPointZ );
2178 else if (method==1){
2179 extractcontrolpoints2d->GetControlPoints( &vecCtrlPointX , &vecCtrlPointY , &vecCtrlPointZ );
2181 else if (method==2){
2182 extractcontrolpoints2d->SetSamplingControlPoints( sampling );
2183 extractcontrolpoints2d->GetSamplingControlPoints( &vecCtrlPointX , &vecCtrlPointY , &vecCtrlPointZ );
2186 //--Adding contour to the system
2188 std::vector<int> actualInstantVector;
2189 _instantPanel->getInstant( actualInstantVector );
2190 actualInstantVector[1]=z;
2192 int j,sizeCtrPt = vecCtrlPointX.size();
2193 manualBaseModel *manModelContour = kernelManager->factoryManualContourModel( typeofcontour );
2194 manModelContour->SetNumberOfPointsSpline( ((sizeCtrPt/100)+1)*100 );
2196 for (j=0 ; j<sizeCtrPt ; j++)
2198 manModelContour->AddPoint( vecCtrlPointX[j] , vecCtrlPointY[j] , vecCtrlPointZ[j] );
2200 std::string theName;
2201 //theName = _modelManager->createOutline( manModelContour, actualInstantVector );
2202 theName = kernelManager->createOutline( manModelContour, actualInstantVector );
2203 bool addedModel = theName.compare("") != 0;
2206 double spc[3];//Si no hay imagen pero hay contornos que spacing se pone por default
2207 _theViewPanel->getSpacing(spc);
2208 //Adding the manualContourControler to interface objects structure
2209 //Adding the manualViewContour to interface objects structure
2210 //_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.
2211 _theViewPanel->configureViewControlTo(theName, manModelContour, spc, typeofcontour);
2212 //_theViewPanel->getSceneManager()->configureViewControlTo( theName, manModelContour,spc, typeofcontour ) ;
2216 int wxContourMainFrame::GetImageDataSizeZ(){
2217 return _theViewPanel->GetImageDataSizeZ();
2220 void wxContourMainFrame::GetImageDataRange(double *range){
2221 _theViewPanel->GetImageDataRange(range);
2224 void wxContourMainFrame::onSegmentationAllSlice(int minZ,int maxZ,int isovalue,int sampling,int method){
2225 //JCP 20-10-08 Undo redo implementation
2227 //JCP 20-10-08 Undo redo implementation
2230 int x = _theViewPanel->GetX();
2231 int y = _theViewPanel->GetY();
2235 double totalZ = maxZ-minZ+1;
2236 for( z=minZ ; z<=maxZ ; z++ )
2238 porcent = 100.0* (z-minZ)/totalZ;
2239 tmpString.Printf(_T(" %d %c %d/%d %d"), (int)porcent , 37 , z-minZ+1, (int)totalZ,z );
2240 interfMainPanel::getInstance()->setLabelSegmentationPanelVTK(tmpString);
2241 //_staticTextSegmentation->SetLabel(tmpString);
2242 SegmentationOneSlice( x,y,z,isovalue, sampling,method );
2244 interfMainPanel::getInstance()->setLabelSegmentationPanelVTK(_T(" "));
2249 //Creates a reference line to be used as the axis of the mirroring
2250 void wxContourMainFrame::referenceLine()
2252 if (_refLineControl==NULL)
2257 vtkImageData *vtkimagedata = _theViewPanel->getImageData();
2258 vtkimagedata->GetSpacing(spc);
2260 wxVtkBaseView * viewer2D = _theViewPanel->getWxVtkBaseView();
2262 _refLineControl = new manualLineControler();
2263 _refLineModel = new manualContourModelLine();
2264 _refLineView = new manualViewLine();
2265 _refLineView->SetModel( _refLineModel );
2266 _refLineView->SetWxVtkBaseView( viewer2D );
2267 _refLineView->SetRange( 2 );
2268 _refLineView->SetZ( 1200 );
2270 _refLineView->SetSpacing(spc);
2272 _refLineView->SetColorNormalContour(0, 0, 1);
2273 _refLineView->SetColorEditContour(0, 0.5, 0.5);
2274 _refLineView->SetWidthLine(4);
2276 _refLineControl->SetModelView( _refLineModel , _refLineView );
2277 vtkInteractorStyleBaseView* style = (vtkInteractorStyleBaseView*)viewer2D->GetInteractorStyleBaseView();
2278 style->AddInteractorStyleMaracas( _refLineControl );
2279 _refLineModel->SetCloseContour(false);
2280 _refLineControl->CreateNewManualContour();
2282 //AD: Inicializar el mirroring con una linea ya pintada
2284 double z = _refLineControl->GetZ();
2287 image->GetDimensions(imageDim);
2288 double x = (double) imageDim[0]/2;
2289 double y1 = (double) (imageDim[1]/2)+15;
2290 double y2 = (double) (imageDim[1]/2)-15;
2292 _refLineControl->AddPoint(x,y1,z);
2293 _refLineControl->AddPoint(x,y2,z);
2294 _refLineControl->SetCompleteCreation(true);
2296 _refLineModel->AddPoint(x,y1,z);
2297 _refLineModel->AddPoint(x,y2,z);
2298 _refLineModel->UpdateSpline();
2300 _refLineView->UpdateViewPoint(0);
2301 _refLineView->UpdateViewPoint(1);
2304 _refLineControl->SetActive(true);
2305 _refLineView->RefreshContour();
2309 //Hides the referenceLine
2310 void wxContourMainFrame::refLineHide()
2312 if (_refLineControl!=NULL)
2314 if (_refLineControl->GetActive())
2316 _refLineView->RemoveCompleteContourActor();
2317 _refLineControl->SetEditable(false);
2318 _refLineControl->SetActive(false);
2325 //Shows the referenceLine
2326 void wxContourMainFrame::refLineShow()
2328 if (_refLineControl!=NULL)
2330 if (_refLineControl->GetActive()==false)
2332 wxVtkBaseView * viewer2D = _theViewPanel->getWxVtkBaseView();
2334 _refLineView->SetModel( _refLineModel );
2335 _refLineView->SetWxVtkBaseView( viewer2D );
2336 _refLineView->SetRange( 2 );
2337 _refLineView->SetZ( 1200 );
2339 _refLineControl->SetModelView( _refLineModel , _refLineView );
2340 vtkInteractorStyleBaseView* style = (vtkInteractorStyleBaseView*)viewer2D->GetInteractorStyleBaseView();
2341 style->AddInteractorStyleMaracas( _refLineControl );
2342 _refLineControl->CreateNewManualContour();
2343 _refLineControl->SetActive(true);
2344 _refLineView->RefreshContour();
2351 void wxContourMainFrame::refLineChangeWidth(int width)
2353 _refLineView->SetWidthLine(width);
2354 _refLineView->RefreshContour();
2360 void wxContourMainFrame::onMirror()
2363 std::vector<std::string> currentSelection = _theViewPanel->getSelectedObjects();
2364 std::vector<std::string> filterCurrentSelection;
2366 std::vector<int> tempVector;
2367 _instantPanel->getInstant( tempVector );
2368 _performingOperation->reset();
2369 _performingOperation->setStartCommand( COPY );
2370 _performingOperation->setStartOperationInstantVector( tempVector );
2371 _performingOperation->setKeyNamesOperationElems( currentSelection );
2373 char theStartCommand = _performingOperation->getStartCommand();
2374 if ( theStartCommand == COPY )
2376 //JCP 20-10-08 Undo redo implementation
2378 //JCP 20-10-08 Undo redo implementation
2379 std::vector<int> tempVector;
2380 _instantPanel->getInstant( tempVector );
2381 _performingOperation->setEndOperationInstantVector ( tempVector );
2382 std::vector<std::string> elems = _performingOperation->getKeyNamesOperationElems();
2383 int i,size = elems.size();
2384 for( i=0; i<size; i++ )
2386 createMirrorContourOf( elems[i], tempVector, i>0 );
2390 //deleteContour( _refName );
2395 void wxContourMainFrame::showAxis(bool show)
2397 _theViewPanel->SetVisibleAxis(show);
2398 _theViewPanel->Refresh();
2402 void wxContourMainFrame::onRigidPressed(){
2403 std::vector<std::string> currentSelection = _theViewPanel->getSelectedObjects();
2404 int elementsSelected = currentSelection.size();
2406 if ( elementsSelected >= 1 ){
2407 //JCP 20-10-08 Undo redo implementation
2409 //JCP 20-10-08 Undo redo implementation
2411 std::vector<int> tempVector;
2412 _instantPanel->getInstant( tempVector );
2413 Instant instant(&tempVector);
2415 int i , size=currentSelection.size();
2416 for ( i=0 ; i<size ; i++ )
2418 kernelManager->changeContourOfManager(currentSelection[i], &instant);
2423 void wxContourMainFrame::onWidthOfContour(double width){
2425 _theViewPanel->removeSceneContours();
2426 _theViewPanel->SetWidthContour(width);
2428 //_theViewPanel->getSceneManager()->SetWidthContour( width );
2433 int wxContourMainFrame::getColorWindow()
2437 vtkImageData * img = getImageData();
2438 img->GetScalarRange(range);
2440 std::cout<<"Val 1: "<<range[0]<<" Val 2: "<<range[1]<<std::endl;
2442 return (int)range[1];
2444 return _theViewPanel->getColorWindow();
2447 int wxContourMainFrame::getWindowLevel()
2451 vtkImageData * img = getImageData();
2452 img->GetScalarRange(range);
2454 std::cout<<"Val 1: "<<range[0]<<" Val 2: "<<range[1]<<std::endl;
2456 return (int)range[1];
2458 return _theViewPanel->getWindowLevel();
2461 void wxContourMainFrame::onBrigthnessColorWindowLevel(int colorwindow,int windowlevel){
2462 _theViewPanel->onBrigthnessColorWindowLevel(colorwindow, windowlevel);
2467 void wxContourMainFrame::onInterpolation(bool interpolate){
2468 _theViewPanel->onInterpolation(interpolate);
2472 void wxContourMainFrame::onChangeInstant(std::string name,int actual){
2473 _instantPanel->setConceptValue( name, actual );
2477 void wxContourMainFrame::resetAppend(){
2478 kernelManager->resetAppend();
2483 void wxContourMainFrame::onSpreadAdd(){
2484 std::vector<double> vecX;
2485 std::vector<double> vecY;
2486 std::vector<double> vecZ;
2487 _theViewPanel->GetPointsOfActualContour(&vecX , &vecY , &vecZ );
2488 std::vector<int> tempVector;
2489 _instantPanel->getInstant( tempVector );
2490 std::string val = kernelManager->onSpreadAdd(&vecX , &vecY , &vecZ, tempVector);
2491 interfMainPanel::getInstance()->appendStringSpread(val);
2495 void wxContourMainFrame::onSpreadAddAll(){
2497 std::vector<int> tempVector;
2498 _instantPanel->getInstant( tempVector );
2501 maxZ = interfMainPanel::getInstance()->GetImageDataSizeZ();
2503 int sizeLstContourThings;
2504 for ( z=minZ ; z<=maxZ ; z++ )
2507 Instant instant(&tempVector);
2508 std::vector<ContourThing**> lstContourThings = kernelManager->getOutlinesAtInstant( &instant );
2509 sizeLstContourThings = lstContourThings.size();
2510 if (sizeLstContourThings>=1)
2512 std::vector<double> vecX;
2513 std::vector<double> vecY;
2514 std::vector<double> vecZ;
2515 ContourThing **contourthing = lstContourThings[0];
2516 manualBaseModel *cModel = (*contourthing)->getModel();
2517 int i,size = cModel->GetNumberOfPointsSpline();
2519 for (i=0; i<size; i++)
2521 cModel->GetSpline_i_Point(i, &x, &y, &z);
2526 std::string val = kernelManager->onSpreadAdd(&vecX , &vecY , &vecZ, tempVector);
2527 interfMainPanel::getInstance()->appendStringSpread(val);
2528 }// if sizeLstContourThings
2533 void wxContourMainFrame::onSpreadGo(int type){
2534 //JCP 20-10-08 Undo redo implementation
2536 //JCP 20-10-08 Undo redo implementation
2538 std::vector<double> vecCtrlPointX;
2539 std::vector<double> vecCtrlPointY;
2540 std::vector<double> vecCtrlPointZ;
2544 std::vector<int> tempVector;
2545 _instantPanel->getInstant( tempVector );
2548 kernelManager->getMaxMinZ(&minZ,&maxZ);
2549 //JSTG_16-07-08_----------------------------------------------------------------
2550 //_contourPropagation->setInterpolationNumber(maxZ-minZ+1);
2551 kernelManager->CalculeSplinePropagation();
2553 double totalZ = maxZ-minZ+1;
2556 //--------------------------------------------------------------------
2557 for ( z=(int)minZ ; z<=(int)maxZ ; z++ )
2559 porcent = 100.0* (z-minZ)/totalZ;
2560 int numero = (int)(z-minZ+1)/(int)totalZ;
2561 std::string stringtemp = " "+kernelManager->intToString(porcent)+"% "+kernelManager->intToString(numero)+" "+kernelManager->intToString(z);
2563 interfMainPanel::getInstance()->setStringSpread(stringtemp);
2565 int typeofcontour = 1;
2566 std::string theName;
2567 manualBaseModel* manModelContour = kernelManager->GetPoints(z, type, &vecCtrlPointX,&vecCtrlPointY,&vecCtrlPointZ, theName,typeofcontour, tempVector);
2569 if( manModelContour!=NULL ){
2570 double spc[3];//Si no hay imagen pero hay contornos que spacing se pone por default
2571 this->_theViewPanel->getSpacing(spc);
2572 //Adding the manualContourControler to interface objects structure
2573 //Adding the manualViewContour to interface objects structure
2574 //_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.
2575 _theViewPanel->configureViewControlTo( theName, manModelContour,spc,typeofcontour ) ;
2580 int numero = (int)(z-minZ+1)/(int)totalZ;
2581 std::string stringtemp = " "+kernelManager->intToString(porcent)+"% "+kernelManager->intToString(numero)+" "+kernelManager->intToString(z);
2583 interfMainPanel::getInstance()->setStringSpread(stringtemp);
2585 //RefreshInterface();
2588 void wxContourMainFrame::getInstantVector(std::vector<int>& tempVector){
2592 std::vector<std::string> wxContourMainFrame::getOutlinesName(int slide){
2593 std::vector<int> tempVector;
2594 _instantPanel->getInstant(tempVector);
2595 //Asignation of slide number should be different ex by name
2596 tempVector[1]=slide;
2597 return kernelManager->getOutlinesNameAtInstant(tempVector);
2601 void wxContourMainFrame::SetScalarRange(int grayRangeMin, int grayRangeMax)
2603 _contourextractdata->SetScalarRange(grayRangeMin,grayRangeMax);
2607 void wxContourMainFrame::onInformationContourLabels(int typeContourGroup,int selection,int minimumZ,int maximumZ,int grayRangeMin, int grayRangeMax)
2610 wxString tempString;
2611 int maxContourGroup = 0;
2613 _contourextractdata ->SetTypeOperation( typeContourGroup % 3 );
2615 std::vector<manualBaseModel*> lstManConMod;
2616 std::vector<manualBaseModel*> lstManConModTmp;
2617 std::vector<manualBaseModel*> lstManConModExp;
2618 std::vector<double> pLstValue;
2619 std::vector<double> pLstValuePosX;
2620 std::vector<double> pLstValuePosY;
2621 std::vector<double> pLstValuePosZ;
2624 int resultGrayRangeCount;
2627 double resultAverage;
2628 double resultStandardeviation;
2630 std::vector<int> tempVector;
2631 _instantPanel->getInstant( tempVector );
2634 int ii,sizeLstContourThings;
2643 if (selection==0 ) // actual slice
2645 int actualSlice = tempVector[1];
2648 } else { // slice range
2654 totalZ = maxZ-minZ+1;
2656 _contourextractdata->InitVolumeStatistics();
2659 for ( z=minZ ; z<=maxZ ; z++ )
2662 porcent = 100.0* (z-minZ)/totalZ;
2663 tmpString.Printf(_T(" %d %c %d/%d %d"), (int)porcent , 37 , z-minZ+1, (int)totalZ ,z);
2665 interfMainPanel::getInstance()->setStringInfoPanel(tmpString);
2666 //_staticTextInformation->SetLabel(tmpString);
2668 //Extraction data from contours of each slice
2669 _contourextractdata->SetZtoBeAnalys(z);
2672 Instant instant(&tempVector);
2673 std::vector<ContourThing**> lstContourThings = kernelManager->getOutlinesAtInstant( &instant );
2674 sizeLstContourThings = lstContourThings.size();
2676 lstManConMod.clear();
2677 for (ii=0 ; ii<sizeLstContourThings ; ii++)
2679 ContourThing **contourthing = lstContourThings[ii];
2680 lstManConMod.push_back( (*contourthing)->getModel() );
2683 lstManConModExp = kernelManager->ExploseEachModel( lstManConMod );
2685 tempString.Printf(_T("%d - %d"),z, sizeLstContourThings);
2686 interfMainPanel::getInstance()->setRowLabelInfoPanel(z, tempString);
2687 //_grid->SetRowLabelValue(z, tempString );
2689 int iContourGroup,sizeContourGroup;
2690 if (typeContourGroup==3) // contour separete
2692 sizeContourGroup=lstManConModExp.size();
2693 if ( maxContourGroup<sizeContourGroup )
2695 maxContourGroup=sizeContourGroup;
2697 } else { // contour AND OR XOR
2704 for( iContourGroup=0 ; iContourGroup<sizeContourGroup ; iContourGroup++ ){
2705 lstManConModTmp.clear();
2709 if (typeContourGroup==3) // contour separete
2711 lstManConModTmp.push_back( lstManConModExp[iContourGroup]);
2712 } else { // contour AND OR XOR
2713 lstManConModTmp = lstManConModExp;
2716 _contourextractdata->SetLstManualContourModel( lstManConModTmp );
2717 _contourextractdata->SetScalarRange(grayRangeMin,grayRangeMax);
2720 pLstValuePosX.clear();
2721 pLstValuePosY.clear();
2722 pLstValuePosZ.clear();
2726 _contourextractdata->GetValuesInsideCrown( &numberOfPixels,
2732 resultSize=numberOfPixels;
2733 // Statistics of each slice.
2734 _contourextractdata->Statistics( &pLstValue,
2737 &resultGrayRangeCount,
2742 &resultStandardeviation);
2744 if (interfMainPanel::getInstance()->getNumberColsInformationPanel()<_numberOfVariablesStatistics*(iContourGroup+1) )
2746 interfMainPanel::getInstance()->appendColsInformationPanel(_numberOfVariablesStatistics);
2749 tmpIntA=_numberOfVariablesStatistics*iContourGroup ;
2751 tempString.Printf(_T("%d"),numberOfPixels);
2753 interfMainPanel::getInstance()->setCellValueInfoPanel(z, tmpIntA, tempString);
2755 tempString.Printf(_T("%d"),resultGrayRangeCount);
2756 interfMainPanel::getInstance()->setCellValueInfoPanel(z, tmpIntA+1, tempString);
2758 tempString.Printf(_T("%f"),resultMin);
2759 interfMainPanel::getInstance()->setCellValueInfoPanel(z, tmpIntA+2, tempString);
2761 tempString.Printf(_T("%f"),resultMax);
2762 interfMainPanel::getInstance()->setCellValueInfoPanel(z, tmpIntA+3, tempString);
2764 tempString.Printf(_T("%f"),resultAverage);
2765 interfMainPanel::getInstance()->setCellValueInfoPanel(z, tmpIntA+4, tempString);
2767 tempString.Printf(_T("%f"),resultStandardeviation);
2768 interfMainPanel::getInstance()->setCellValueInfoPanel(z, tmpIntA+5, tempString);
2771 } // for iContourGroup
2774 // Print Volume Statistics
2777 int vol_rCountRange;
2779 double vol_minValue;
2780 double vol_maxValue;
2782 double vol_standardeviation;
2784 if (selection!=0 ) // actual slice
2787 _contourextractdata->GetVolumeStatistics(&vol_rCountRange, &vol_rsize,
2788 &vol_minValue, &vol_maxValue,
2789 &vol_average, &vol_standardeviation);
2791 interfMainPanel::getInstance()->setRowLabelInfoPanel(maxZ+2, _T("Total:"));
2793 tempString.Printf(_T("%d"),vol_rsize);
2794 interfMainPanel::getInstance()->setCellValueInfoPanel(maxZ+2, 0, tempString);
2796 tempString.Printf(_T("%d"),vol_rCountRange);
2797 interfMainPanel::getInstance()->setCellValueInfoPanel(maxZ+2, 1, tempString);
2799 tempString.Printf(_T("%f"),vol_minValue);
2800 interfMainPanel::getInstance()->setCellValueInfoPanel(maxZ+2, 2, tempString);
2802 tempString.Printf(_T("%f"),vol_maxValue);
2803 interfMainPanel::getInstance()->setCellValueInfoPanel(maxZ+2, 3, tempString);
2805 tempString.Printf(_T("%f"),vol_average);
2806 interfMainPanel::getInstance()->setCellValueInfoPanel(maxZ+2, 4, tempString);
2808 tempString.Printf(_T("%f"),vol_standardeviation);
2809 interfMainPanel::getInstance()->setCellValueInfoPanel(maxZ+2, 5, tempString);
2811 //-----------------------------------------
2814 wxString tmpTitleString;
2816 for ( iTitleGroup=0 ; iTitleGroup<maxContourGroup ; iTitleGroup++ )
2818 tmpIntB =_numberOfVariablesStatistics*iTitleGroup;
2819 tmpTitleString.Printf(_T("%d-Size Data"),iTitleGroup);
2820 interfMainPanel::getInstance()->setColLableInfoPanel(tmpIntB + 0, tmpTitleString);
2822 interfMainPanel::getInstance()->setColLableInfoPanel(tmpIntB + 0, tmpTitleString );
2823 interfMainPanel::getInstance()->setColLableInfoPanel( tmpIntB + 1, _T("Size Range") );
2824 interfMainPanel::getInstance()->setColLableInfoPanel( tmpIntB + 2, _T("Min") );
2825 interfMainPanel::getInstance()->setColLableInfoPanel( tmpIntB + 3, _T("Max") );
2826 interfMainPanel::getInstance()->setColLableInfoPanel( tmpIntB + 4, _T("Average") );
2827 interfMainPanel::getInstance()->setColLableInfoPanel( tmpIntB + 5, _T("St.Dev.") );
2828 interfMainPanel::getInstance()->setColLableInfoPanel( tmpIntB + 6, _T(" ") );
2830 interfMainPanel::getInstance()->setStringInfoPanel( _T("") );
2834 void wxContourMainFrame::onSaveResults(std::string directory,std::string namefile, std::string filename,
2835 int typeContourGroup, int selection, int minZ, int maxZ, bool XYZValues, bool contourImage, bool statistics)
2839 SaveValuesXYZ( directory , namefile, typeContourGroup );
2844 vtkImageData * mask;
2845 vtkImageData * value;
2846 this->getMaskValue(&mask, &value, typeContourGroup,selection,minZ,maxZ);
2847 this->SaveImageResult( directory , namefile, mask, value);
2852 std::ostringstream name;
2853 name << filename << ".xls";
2856 FILE *pFile=fopen(name.str().c_str(),"w+");
2862 // int sizeZ = _theViewPanel->GetImageDataSizeZ();
2863 // int maxY=sizeZ+2;
2865 maxX= interfMainPanel::getInstance()->getNumberColsInformationPanel();//this->_grid->GetNumberCols();
2868 int iTitle,sizeTitle = (maxX / _numberOfVariablesStatistics);
2869 for ( iTitle=0; iTitle<sizeTitle ; iTitle++)
2871 // fprintf(pFile,"-- \t %d-Size \t SizeRange \t Min \t Max \t Ave \t StDv \t" , iTitle,tmpString.c_str() );
2872 fprintf(pFile,"slice\t %d-Size \t SizeRange \t Min \t Max \t Ave \t StDv \t" , iTitle );
2874 fprintf(pFile,"\n\n" );
2878 if (selection==0 ) // actual slice
2880 std::vector<int> tempVector;
2881 _instantPanel->getInstant( tempVector );
2882 int actualSlice = tempVector[1];
2888 for ( j=minZ; j<=maxZ ; j++)
2890 fprintf(pFile,"%d\t" , j );
2891 for (i=0 ; i<maxX ; i++){
2892 tmpString = interfMainPanel::getInstance()->getCellValue(j, i);//_grid->GetCellValue( j , i );
2893 fprintf(pFile,"%s\t" , (const char *)(tmpString.mb_str()) );
2895 fprintf(pFile,"\n" );
2899 // Total of stadistics.....
2902 fprintf(pFile,"\n Total:\t" );
2903 for (i=0 ; i<maxX ; i++){
2904 tmpString = interfMainPanel::getInstance()->getCellValue(maxZ+2, i);//_grid->GetCellValue( maxZ+2 , i );
2905 fprintf(pFile,"%s\t" , (const char *)(tmpString.mb_str()) );
2907 fprintf(pFile,"\n" );
2915 void wxContourMainFrame::SaveValuesXYZ(std::string directory,std::string namefile,int typeContourGroup)
2919 //int typeContourGroup = this->_radiolstboxContourGroup->GetSelection();
2920 _contourextractdata ->SetTypeOperation( typeContourGroup % 3 );
2922 std::vector<manualBaseModel*> lstManConMod;
2923 std::vector<manualBaseModel*> lstManConModTmp;
2924 std::vector<manualBaseModel*> lstManConModExp;
2925 std::vector<double> pLstValue;
2926 std::vector<double> pLstValuePosX;
2927 std::vector<double> pLstValuePosY;
2928 std::vector<double> pLstValuePosZ;
2930 std::vector<int> tempVector;
2931 _instantPanel->getInstant( tempVector );
2933 int sizeZ = _theViewPanel->getSceneManager()->GetImageDataSizeZ();
2935 int ii,sizeLstContourThings;
2942 minZ = 0;// _mbarrange->GetStart();
2943 maxZ = sizeZ;//_mbarrange->GetEnd();
2944 totalZ = maxZ-minZ+1;
2948 for ( z=0 ; z<sizeZ ; z++)
2951 porcent = 100.0* (z-minZ)/totalZ;
2953 tmpString.Printf(_T("Saving Values"));
2954 tmpString.Printf(_T(" %d %c %d/%d %d"), (int)porcent , 37 , z-minZ+1, (int)totalZ ,z);
2955 interfMainPanel::getInstance()->setStringInfoPanel(tmpString);
2956 //_staticTextInformation->SetLabel(tmpString);
2959 //Extraction data from contours of each slice
2960 _contourextractdata->SetZtoBeAnalys( z);
2963 Instant instant(&tempVector);
2964 std::vector<ContourThing**> lstContourThings = kernelManager->getOutlinesAtInstant(&instant);//this->_modelManager->getOutlinesAtInstant( &instant );
2965 sizeLstContourThings = lstContourThings.size();
2967 lstManConMod.clear();
2968 for (ii=0 ; ii<sizeLstContourThings ; ii++)
2970 ContourThing **contourthing = lstContourThings[ii];
2971 lstManConMod.push_back( (*contourthing)->getModel() );
2973 lstManConModExp = kernelManager->ExploseEachModel( lstManConMod );
2978 int iContourGroup,sizeContourGroup;
2979 if (typeContourGroup==3) // contour separete
2981 sizeContourGroup=lstManConModExp.size();
2982 } else { // contour AND OR XOR
2986 for( iContourGroup=0 ; iContourGroup<sizeContourGroup ; iContourGroup++ ){
2987 lstManConModTmp.clear();
2988 if (typeContourGroup==3) // contour separete
2990 lstManConModTmp.push_back( lstManConModExp[iContourGroup]);
2991 } else { // contour AND OR XOR
2992 lstManConModTmp = lstManConModExp;
2995 _contourextractdata->SetLstManualContourModel( lstManConModTmp );
2998 pLstValuePosX.clear();
2999 pLstValuePosY.clear();
3000 pLstValuePosZ.clear();
3002 _contourextractdata->GetValuesInsideCrown( &numberOfPixels,
3008 std::string temp = directory + "/" + namefile + "-slice";
3009 temp = temp + kernelManager->intToString(z) + "-cont" + kernelManager->intToString(iContourGroup);
3010 temp = temp + ".txt";
3012 // LG 14/01/09 : using crea
3013 wxString filename = crea::std2wx(temp);
3014 /*filename.Printf(_T("%s"),directory.c_str());
3015 filename.append(_T("\\"));
3016 filename.append(_T("%s"),namefile.c_str());
3017 filename.append(_T("-slice"));
3018 filename.append(_T("%d"),z);
3019 filename.append(_T("-cont"));
3020 filename.append(_T("%d"),iContourGroup);
3021 filename.append(_T(".txt"));*/
3022 // filename.Printf(temp.c_str());
3026 FILE *pFile=fopen((const char *)filename.mb_str(),"w+");
3027 fprintf(pFile,"value \t x \t y \t z\n" );
3028 int iLstValue,sizeLstValue=pLstValue.size();
3029 for (iLstValue=0 ; iLstValue<sizeLstValue ; iLstValue++ )
3031 fprintf(pFile,"%f\t %f\t %f\t %f\n", (float)pLstValue[iLstValue] , (float)pLstValuePosX[iLstValue], (float)pLstValuePosY[iLstValue], (float)z );
3034 } // for iContourGroup
3036 interfMainPanel::getInstance()->setStringInfoPanel(_T(""));
3037 //_staticTextInformation->SetLabel( _T("") );
3041 void wxContourMainFrame::getMaskValue(vtkImageData ** mask,vtkImageData ** value,int typeContourGroup, int selection, int minZ, int maxZ){
3044 //int typeContourGroup = this->_radiolstboxContourGroup->GetSelection();
3045 if (typeContourGroup==3)
3049 _contourextractdata ->SetTypeOperation( typeContourGroup % 3 );
3051 std::vector<manualBaseModel*> lstManConMod;
3052 std::vector<manualBaseModel*> lstManConModTmp;
3053 std::vector<manualBaseModel*> lstManConModExp;
3055 std::vector<int> tempVector;
3056 _instantPanel->getInstant( tempVector );
3058 vtkImageData *imagedata = _theViewPanel->getImageData();
3060 imagedata->GetExtent(ext);
3061 int sizeZimage = ext[5]-ext[4]+1;
3063 int ii,sizeLstContourThings;
3072 if (selection==0 ) // actual slice
3074 int actualSlice = tempVector[1];
3082 // cleanning image before range
3083 for (z=0; z<minZ; z++){
3084 _contourextractdata->ResetImageResult(z);
3086 // cleanning image after range
3087 for (z=maxZ+1; z<sizeZimage; z++){
3088 _contourextractdata->ResetImageResult(z);
3093 for ( z=minZ ; z<=maxZ ; z++)
3096 porcent = 100.0* (z-minZ)/totalZ;
3097 tmpString.Printf(_T("Saving Values"));
3098 tmpString.Printf(_T("%d %c %d/%d %d"), (int)porcent , 37 , z-minZ+1, (int)totalZ ,z);
3099 interfMainPanel::getInstance()->setStringInfoPanel(tmpString);
3101 //Extraction data from contours of each slice
3102 _contourextractdata->SetZtoBeAnalys( z);
3105 Instant instant(&tempVector);
3106 std::vector<ContourThing**> lstContourThings = kernelManager->getOutlinesAtInstant( &instant );
3107 sizeLstContourThings = lstContourThings.size();
3109 lstManConMod.clear();
3110 for (ii=0 ; ii<sizeLstContourThings ; ii++)
3112 ContourThing **contourthing = lstContourThings[ii];
3113 lstManConMod.push_back( (*contourthing)->getModel() );
3115 lstManConModExp = kernelManager->ExploseEachModel( lstManConMod );
3118 int iContourGroup,sizeContourGroup;
3119 if (typeContourGroup==3) // contour separete
3121 sizeContourGroup=lstManConModExp.size();
3122 } else { // contour AND OR XOR
3126 for( iContourGroup=0 ; iContourGroup<sizeContourGroup ; iContourGroup++ ){
3127 lstManConModTmp.clear();
3128 if (typeContourGroup==3) // contour separete
3130 lstManConModTmp.push_back( lstManConModExp[iContourGroup]);
3131 } else { // contour AND OR XOR
3132 lstManConModTmp = lstManConModExp;
3135 _contourextractdata->SetLstManualContourModel( lstManConModTmp );
3136 _contourextractdata->CalculateImageResult(); // with actual Z
3138 } // for iContourGroup
3141 (*value) = _contourextractdata->GetVtkImageValueResult();
3142 (*mask) = _contourextractdata->GetVtkImageMaskResult();
3146 void wxContourMainFrame::SaveImageResult(std::string directory,std::string namefile, vtkImageData* mask,vtkImageData* value)
3150 kernelManager->GetSpacing(spc,0); // returns the spacing of the first image
3152 std::string temp = directory + "/" + namefile + "-image-Value.mhd";
3154 wxString filename = crea::std2wx(temp);
3158 vtkImageChangeInformation *valueChInfo = vtkImageChangeInformation::New();
3159 //EED 2017-01-01 Migration VTK7
3160 #if VTK_MAJOR_VERSION <= 5
3161 valueChInfo->SetInput(value);
3163 valueChInfo->SetInputData(value);
3165 valueChInfo->SetSpacingScale(spc);
3166 vtkMetaImageWriter *writerValueImage = vtkMetaImageWriter::New( );
3168 //EED 2017-01-01 Migration VTK7
3169 #if VTK_MAJOR_VERSION <= 5
3170 writerValueImage->SetInput( valueChInfo->GetOutput() );
3172 writerValueImage->SetInputData( valueChInfo->GetOutput() );
3174 writerValueImage->SetFileName( (const char *)filename.mb_str() );
3175 writerValueImage->SetFileDimensionality( 3 );
3176 writerValueImage->SetCompression(false);
3177 writerValueImage->Write( );
3180 temp = directory + "/" + namefile + "-image-Mask.mhd";
3182 // LG 14/01/09 : using crea
3183 filename = crea::std2wx(temp);
3184 // filename.Printf(_T(temp.c_str()));
3187 vtkImageChangeInformation *maskChInfo = vtkImageChangeInformation::New();
3188 //EED 2017-01-01 Migration VTK7
3189 #if VTK_MAJOR_VERSION <= 5
3190 maskChInfo->SetInput(mask);
3192 maskChInfo->SetInputData(mask);
3194 maskChInfo->SetSpacingScale(spc);
3195 vtkMetaImageWriter *writerMaskImage = vtkMetaImageWriter::New( );
3197 //EED 2017-01-01 Migration VTK7
3198 #if VTK_MAJOR_VERSION <= 5
3199 writerMaskImage->SetInput( maskChInfo->GetOutput() );
3201 writerMaskImage->SetInputData( maskChInfo->GetOutput() );
3204 writerMaskImage->SetFileName( (const char *)filename.mb_str() );
3205 writerMaskImage->SetFileDimensionality( 3 );
3206 writerMaskImage->SetCompression(false);
3207 writerMaskImage->Write( );
3209 interfMainPanel::getInstance()->setStringInfoPanel( _T("") );
3215 void wxContourMainFrame::onChangeInstantInstantPanel(std::string name,int value, int minshow, int maxshow){
3216 if( name.compare( _theViewPanel->getVerticalConceptName() ) == 0){
3217 _theViewPanel->setActualVertical( value);
3219 else if( name.compare( _theViewPanel->getHorizontalConceptName() ) == 0|| _instantPanel->getIfConceptCheckedAt( name, 0 ) ) {
3220 _theViewPanel->setHorizontalConcept( name, minshow, maxshow, minshow, maxshow, value);
3226 void wxContourMainFrame::onSnakePressed(){
3227 std::vector<double> vecX;
3228 std::vector<double> vecY;
3229 std::vector<double> vecZ;
3230 _theViewPanel->GetPointsOfActualContour( &vecX , &vecY , &vecZ );
3232 if (vecX.size()!=0){
3233 std::vector<int> tempVector;
3234 _instantPanel->getInstant( tempVector );
3235 int i,size=vecZ.size();
3236 int actualSlice = tempVector[1];
3237 for ( i=0 ; i<size ; i++ )
3239 vecZ[i] = actualSlice;
3242 wxDialog* dialog = new wxDialog(this, -1, wxString(_T("Snake")));
3243 wxPanel* panel = new wxPanel(dialog,-1);
3244 // wxStaticText* sttext = new wxStaticText(panel, -1, wxString(_T("Panel para snake")));
3245 new wxStaticText(panel, -1, wxString(_T("Panel para snake")));
3246 dialog->ShowModal();
3251 void wxContourMainFrame::saveFileWithContoursAutomatique(){
3252 std::string filename = kernelManager->getCurrentFileName();
3253 if(filename.compare("")!=0){
3254 saveFileWithContours(filename);
3259 void wxContourMainFrame::ShowToolsPanel(bool show){
3260 _pannew->Show(show);
3265 void wxContourMainFrame::SetContourGroup(int contourGroup)
3267 _contourGroup = contourGroup;
3271 wxPanel *wxContourMainFrame::getMaskImageViewPanel(wxWindow *parent)
3274 if (_viewMaskImagePanel==NULL)
3276 _contourextractdata = new ContourExtractData(true);
3277 _contourextractdata->SetImage( _theViewPanel->getImageData() );
3279 // _theViewPanel->getImageData()->GetScalarRange(range);
3280 //int min = (int)floor (range[0]);
3281 //int max = (int)ceil (range[1]);
3284 _viewMaskImagePanel = new ThresholdImageViewPanel( parent, -1, -1 , 0);
3285 _viewMaskImage = new ThresholdImageView();
3286 _viewMaskImage->SetImage(_contourextractdata->GetVtkImageMaskResult() );
3287 _viewMaskImage->SetminMaxValue( min, max);
3288 _viewMaskImage->SetBaseColor( 0,0,1 );
3289 _viewMaskImagePanel->SetThresholdImageView( _viewMaskImage );
3290 _viewMaskImage->SetwxVtkBaseView( _theViewPanel->getWxVtkBaseView() );
3292 return _viewMaskImagePanel;
3296 wxPanel *wxContourMainFrame::getColorLayerImageViewPanel(wxWindow *parent)
3298 if (_viewColorLayerImagePanel==NULL)
3301 _theViewPanel->getImageData()->GetScalarRange(range);
3302 int min = (int)floor (range[0]);
3303 int max = (int)ceil (range[1]);
3304 _viewColorLayerImagePanel = new ColorLayerImageViewPanel( parent, min, max, 100, 1);
3305 _viewColorLayerImagePanel->GetColorLayerImageViewManager()->SetwxVtkBaseView( 0 , _theViewPanel->getWxVtkBaseView() );
3307 return _viewColorLayerImagePanel;
3311 wxPanel *wxContourMainFrame::getThresholdImageViewPanel(wxWindow *parent)
3313 if (_viewThresholdImagePanel==NULL)
3316 _theViewPanel->getImageData()->GetScalarRange(range);
3317 int min = (int)floor (range[0]);
3318 int max = (int)ceil (range[1]);
3319 _viewThresholdImagePanel = new ThresholdImageViewPanel( parent, min, max , 1);
3320 _viewThresholdImage = new ThresholdImageView();
3321 _viewThresholdImage->SetImage( _theViewPanel->getImageData() );
3322 _viewThresholdImage->SetminMaxValue( min, max);
3323 _viewThresholdImage->SetBaseColor( 1,0,0 );
3324 _viewThresholdImagePanel->SetThresholdImageView( _viewThresholdImage );
3325 _viewThresholdImage->SetwxVtkBaseView( _theViewPanel->getWxVtkBaseView() );
3327 return _viewThresholdImagePanel;
3330 //CMRU 17-08-09-----------------------------------------------------------------------------------------------
3331 int wxContourMainFrame::getType ()
3334 std::vector<std::string> currentSelection = _theViewPanel->getSelectedObjects();
3336 if(!currentSelection.empty())
3338 std::string cloneName = currentSelection [0];
3339 manualBaseModel * manualModel = kernelManager->getOutlineByKeyName(cloneName);
3340 tipo = manualModel-> GetTypeModel();
3345 double wxContourMainFrame::getContourSizeInPixels()
3347 double contourSize = 0;
3349 std::vector<std::string> currentSelection = _theViewPanel->getSelectedObjects(); if(!currentSelection.empty())
3350 if(!currentSelection.empty())
3352 std::string cloneName = currentSelection [0];
3354 manualBaseModel * manualModel = kernelManager->getOutlineByKeyName(cloneName);//_modelManager->getOutlineByKeyName( cloneName )->getModel();
3357 // contourSize = manualModel->GetPathSize();
3362 contourSize = manualModel->GetPathSize( spc );
3367 manualBaseModel * wxContourMainFrame::getContour ()
3369 std::vector<std::string> currentSelection = _theViewPanel->getSelectedObjects();
3371 if(!currentSelection.empty())
3373 std::string cloneName = currentSelection [0];
3374 manualBaseModel * manualModel = kernelManager->getOutlineByKeyName(cloneName);//_modelManager->getOutlineByKeyName( cloneName )->getModel();
3379 void wxContourMainFrame::onPrintLabel (wxString label, manualBaseModel* manualModel)
3381 std::string labelAscii(label.ToAscii());
3382 int pos = labelAscii.find(" ");
3386 for (j=0 ; pos != string::npos;j++)
3388 labelAscii.replace( pos, 1, "_" );
3389 pos= labelAscii.find(" ");
3392 manualModel -> SetLabel(labelAscii);
3394 void wxContourMainFrame::onInsertCalculation(manualBaseModel* manualModel)
3397 // double sizeInPixel = manualModel ->GetPathSize( );
3402 double sizeInPixel = manualModel ->GetPathSize( spc );
3404 double onePixelRealSize = interfMainPanel::getInstance()->GetPixelValue();;
3405 double realContourSize = sizeInPixel*onePixelRealSize;
3406 manualModel ->SetRealSize(realContourSize);
3409 double wxContourMainFrame::onePixelSize( double value)
3411 return _onePixelSize = value;
3414 std::string wxContourMainFrame::GetFileLocation()
3416 return _fileLocation;
3419 void wxContourMainFrame::SetFileLocation(std::string newFileLocation)
3421 _fileLocation = newFileLocation;
3422 std::cout<<"GETFILELOCATION:"<<_fileLocation<<std::endl;
3424 //------------------------------------------------------------------------------------------------------------
3433 void wxContourMainFrame::FlipSelectedContours(int flipDirection)
3435 printf("EED wxContourMainFrame::FlipSelectedContours flipDirection=%d \n", flipDirection );
3437 (std::vector<std::string>)_theViewPanel->getSceneManager()->getSelectedObjects() ,
3443 void wxContourMainFrame::FlipActualSliceContours(int flipDirection)
3445 printf("EED wxContourMainFrame::FlipActualSliceContours flipDirection=%d \n", flipDirection );
3447 (std::vector<std::string>)_theViewPanel->getSceneManager()->GetlstContoursNameActualSlice() ,
3452 void wxContourMainFrame::FlipAllContours(int flipDirection)
3454 printf("EED wxContourMainFrame::FlipAllContours flipDirection=%d \n", flipDirection );
3456 kernelManager->GetLstNameThings() ,
3461 void wxContourMainFrame::FlipLstOfContours(std::vector<std::string> lstNameThings, int flipDirection)
3464 getImageData()->GetExtent(ext);
3465 int sizeX = ext[1]-ext[0];
3466 int sizeY = ext[3]-ext[2];
3469 int i,sizeLstNameThings;
3470 int ii,sizeLstPoints;
3472 sizeLstNameThings = lstNameThings.size();
3473 for (i=0 ; i<sizeLstNameThings ; i++)
3475 printf("EED wxContourMainFrame::FlipAllContours contour=%d \n", i );
3476 manualBaseModel * manualModel = kernelManager->getOutlineByKeyName(lstNameThings[i]);
3477 if (flipDirection==0)
3479 manualModel->Transform_Ax_Plus_B(-1,sizeX,1,0 );
3481 manualModel->Transform_Ax_Plus_B(1,0,-1,sizeY );
3483 }// for i list of Things
3485 //-- Static Contours
3487 lstNameThings = kernelManager->GetLstNameThingsStatic();
3488 sizeLstNameThings = lstNameThings.size();
3489 for (i=0 ; i<sizeLstNameThings ; i++)
3491 manualBaseModel * manualModel = kernelManager->getOutlineByKeyName(lstNameThings[i]);
3492 if (flipDirection==0)
3494 manualModel->Transform_Ax_Plus_B(-1,sizeX,1,0 );
3496 manualModel->Transform_Ax_Plus_B(1,0,-1,sizeY );
3498 }// for i list of static things
3501 void wxContourMainFrame::FlipContours(int typeContourFlip, int flipDirection)
3503 printf("EED wxContourMainFrame::FlipContours( %d , %d ) \n",typeContourFlip, flipDirection );
3507 if (typeContourFlip==0) //
3509 FlipSelectedContours(flipDirection);
3512 if (typeContourFlip==1) //
3514 FlipActualSliceContours(flipDirection);
3517 if (typeContourFlip==2) //
3519 FlipAllContours(flipDirection);