1 /*# ---------------------------------------------------------------------
3 # Copyright (c) CREATIS (Centre de Recherche en Acquisition et Traitement de l'Image
5 # Authors : Eduardo Davila, Frederic Cervenansky, Claire Mouton
6 # Previous Authors : Laurent Guigues, Jean-Pierre Roux
7 # CreaTools website : www.creatis.insa-lyon.fr/site/fr/creatools_accueil
9 # This software is governed by the CeCILL-B license under French law and
10 # abiding by the rules of distribution of free software. You can use,
11 # modify and/ or redistribute the software under the terms of the CeCILL-B
12 # license as circulated by CEA, CNRS and INRIA at the following URL
13 # http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
14 # or in the file LICENSE.txt.
16 # As a counterpart to the access to the source code and rights to copy,
17 # modify and redistribute granted by the license, users are provided only
18 # with a limited warranty and the software's author, the holder of the
19 # economic rights, and the successive licensors have only limited
22 # The fact that you are presently reading this means that you have had
23 # knowledge of the CeCILL-B license and that you accept its terms.
24 # ------------------------------------------------------------------------ */
26 //----------------------------------------------------------------------------------------------------------------
27 // Class definition include
28 //----------------------------------------------------------------------------------------------------------------
29 #include "wxContourMainFrame.h"
33 //----------------------------------------------------------------------------------------------------------------
35 //----------------------------------------------------------------------------------------------------------------
38 #include "NameWrapper.h"
39 #include "wx/artprov.h"
40 #include "ConceptDataWrap.h"
46 //----------------------------------------------------------------------------------------------------------------
47 // Class implementation
48 //----------------------------------------------------------------------------------------------------------------
49 /** @file wxContourMainFrame.cxx */
51 //------------------------------------------------------------------------------------------------------------
52 // Constructors & Destructors
53 //------------------------------------------------------------------------------------------------------------
55 wxContourMainFrame* wxContourMainFrame::instance=NULL;
56 char wxContourMainFrame::COPY = 'C';
58 wxContourMainFrame :: wxContourMainFrame(wxWindow* parent, wxWindowID id,const wxString& title,const wxPoint& pos,const wxSize& size,long style)
59 //: wxPanel(parent, id, title, pos, size, style)
60 //: wxWindow(parent, id, pos, size, style)
61 : wxPanel(parent, id, pos, size, style)
63 m_mgr.SetManagedWindow(this);
65 _creatingContoursActive = false;
67 // _modelManager = NULL;
69 // _buttonsBar = NULL;
71 // _drawToolsPanel = NULL;
72 // _operationsToolsPanel = NULL;
73 //_autoFormsPanel = NULL;
74 // _standardToolsPanel = NULL;
75 // _editionToolsPanel = NULL;
76 // _listViewPanel = NULL;
77 // _sceneManager = NULL;
78 //_actualInstant = NULL;
79 _numberOfVariablesStatistics= 6+1;
81 _refLineControl = NULL;
84 // _actorPresent = false;
86 // set up default notebook style
87 // m_notebook_style =wxAUI_NB_TAB_SPLIT | wxAUI_NB_TAB_EXTERNAL_MOVE | wxNO_BORDER;
88 // m_notebook_theme = 0;
89 //wxContour_ActionCommandsID a;
91 _contourextractdata = NULL;
92 _viewMaskImage = NULL;
93 _viewMaskImagePanel = NULL;
94 _viewThresholdImage = NULL;
95 _viewThresholdImagePanel = NULL;
96 _viewColorLayerImagePanel = NULL;
97 _frameShowResultImages = NULL;
100 wxContourMainFrame::wxContourMainFrame(wxWindow* parent, wxWindowID id,const wxString& title,const wxPoint& pos,const wxSize& size,std::vector<vtkImageData*> images, long style,std::string datadir)
101 : wxPanel(parent, id, pos, size, style)
103 m_mgr.SetManagedWindow(this);
105 _creatingContoursActive = false;
106 _theViewPanel = NULL;
107 _instantPanel = NULL;
108 _refLineControl = NULL;
109 _refLineModel = NULL;
111 // _actorPresent = false;
112 _viewMaskImage = NULL;
113 _viewMaskImagePanel = NULL;
114 _viewThresholdImage = NULL;
115 _viewThresholdImagePanel = NULL;
116 _viewColorLayerImagePanel = NULL;
117 // set up default notebook style
118 m_notebook_style = wxAUI_NB_TAB_SPLIT | wxAUI_NB_TAB_EXTERNAL_MOVE | wxNO_BORDER;
119 m_notebook_theme = 0;
120 //wxContour_ActionCommandsID a;
121 _numberOfVariablesStatistics= 7;
125 _pannew = interfMainPanel::getInstance(this,datadir+"/data/Icons");//, eventHandler);
126 _performingOperation = new PerformingOperation();
127 if(images.size() > 0)
129 this->configure(images);
131 _contourextractdata = NULL;
135 void wxContourMainFrame::changeImage(int id, vtkImageData *img)
137 if ( id<_images.size() ) _images[id]=img;
138 kernelManager->changeImage(id,img);
139 _theViewPanel->changeImage(img);
140 // updateInstantImageData();
144 void wxContourMainFrame::configure(std::vector<vtkImageData*> imgs)
148 std::string str_home(getenv("USERPROFILE"));
149 #elif defined(__GNUC__)
150 std::string str_home(getenv("HOME"));
152 std::string strCreaContourDataTmp = str_home + "/.creaContourDataTemp/";
153 std::vector<std::string> conceptNameVect;
154 std::vector<int> conceptSizeVect;
155 notebook = this->createNotebook();
156 kernelManager = new KernelManagerContour( imgs , _datadir+"/data/" , strCreaContourDataTmp );
157 _instantPanel = new wxInstantChooserPanel( notebook, "Instant Chooser", true, false, "c" );
158 _theViewPanel = new wxContourViewPanel( kernelManager->getSourceImage(), notebook );
159 //-------------------------------------------------------------
160 kernelManager->getConceptsInformation(conceptNameVect, conceptSizeVect);
161 _instantPanel->addConcepts(conceptNameVect, conceptSizeVect);
162 double val = _theViewPanel->getCurrentDeep();
163 _instantPanel->setConceptValue( "Axe Depth", (int)val );
164 //JCP _instantPanel->setConceptValue("time", num de imagenes);
165 ConceptDataWrap * data = _instantPanel->getConceptDataOf( "Axe Depth" );
166 //*******************changeInstant();
167 _theViewPanel->setVerticalConcept( "Axe Depth", data->getMinValue(), data->getMaxValue(), data->getMinShowedValue(), data->getMaxShowedValue(), data->getActualValue() );
168 this->configurePanels( );
172 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 )
176 instance=new wxContourMainFrame(parent, id, title, pos, size, images, style,datadir);
181 std::vector<vtkImageData*> wxContourMainFrame::getVectImages()
183 return kernelManager->getVectImages();
186 wxContourMainFrame* wxContourMainFrame::getInstance()
191 void wxContourMainFrame::resetInstance()
196 wxContourMainFrame::~wxContourMainFrame()
198 delete _contourextractdata;
201 interfMainPanel::resetInstance();
202 delete kernelManager;
204 //_pannew->Destroy();
210 //El problema al cerrar la aplicacion puede estar asociado
211 //a que wxAUINotebook esta en la aplicacion
212 //principal (wxContourGUIExample)tambien
213 //EED???? delete _theViewPanel;
214 //EED???? delete _instantPanel;
215 //EED???? delete _buttonsBar;
216 //EED???? delete _actualInstant;
217 //EED???? delete _sceneManager;
221 //------------------------------------------------------------------------------------------------------------
222 // Creational and initialization methods using WxAui
223 //------------------------------------------------------------------------------------------------------------
225 wxAuiNotebook * wxContourMainFrame::createNotebook()
227 wxSize client_size = GetClientSize();
228 wxAuiNotebook* noteBook = new wxAuiNotebook(this, -1, wxPoint(client_size.x, client_size.y), wxSize(430,200), m_notebook_style);
229 wxBitmap page_bmp = wxArtProvider::GetBitmap(wxART_NORMAL_FILE, wxART_OTHER, wxSize(16,16));
234 //------------------------------------------------------------------------------------------------------------
235 // Creational and initialization methods
236 //------------------------------------------------------------------------------------------------------------
237 bool wxContourMainFrame::configurePanels( )
239 bool configured = _theViewPanel!=NULL;
241 configured &= _theViewPanel!=NULL;
242 if( _theViewPanel!=NULL )
244 notebook->AddPage( _theViewPanel, wxT(" View ") );
249 notebook->AddPage( _instantPanel, wxT("Instant Page") );
252 m_mgr.AddPane(notebook, wxAuiPaneInfo().Name(wxT("notebook_content")).CenterPane().PaneBorder(false));
254 SetMinSize(wxSize(300,300));
260 bool wxContourMainFrame::addNewPanel(wxPanel* panel)
262 bool configured = panel!=NULL;
263 configured &= panel!=NULL;
267 notebook->AddPage( panel, wxT(" Viewer "), true );
273 //------------------------------------------------------------------------------------------------------------
274 // Attributes getters and setters
275 //------------------------------------------------------------------------------------------------------------
279 void wxContourMainFrame :: setInstantChooserPanel( wxInstantChooserPanel * theInstantChooserPanel )
281 _instantPanel = theInstantChooserPanel;
284 // void wxContourMainFrame :: setButtonsBar( wxContour_ButtonsBar * theButtonsBar )
286 // _buttonsBar = theButtonsBar;
289 // void wxContourMainFrame :: setGrid( wxContour_Grid * theGridPanel )
291 // _gridPanel = theGridPanel;
294 // void wxContourMainFrame :: setDrawToolsPanel( wxContour_DrawToolsPanel * theDrawToolsPanel )
296 // _drawToolsPanel = theDrawToolsPanel;
299 // void wxContourMainFrame :: setOperationsToolsPanel( wxContour_OperationsToolsPanel * theOperationsToolsPanel )
301 // _operationsToolsPanel = theOperationsToolsPanel;
304 // void wxContourMainFrame :: setAutomaticFormsPanel( wxContour_AutomaticFormsToolsPanel * theAutoFormsPanel )
306 // _autoFormsPanel = theAutoFormsPanel;
309 // void wxContourMainFrame :: setStandardToolsPanel( wxContour_StandardToolsPanel * theStandardToolsPanel )
311 // _standardToolsPanel= theStandardToolsPanel;
314 // void wxContourMainFrame :: setEditionToolsPanel( wxContour_EdtionToolsPanel * theEditionToolsPanel )
316 // _editionToolsPanel = theEditionToolsPanel;
319 // void wxContourMainFrame :: setListViewPanel( wxContour_ListViewPanel * theListViewPanel )
321 // _listViewPanel = theListViewPanel;
326 void wxContourMainFrame::onCreateContourSpline( ){
328 //JCP 20-10-08 Undo redo implementation
330 //JCP 20-10-08 Undo redo implementation
335 void wxContourMainFrame::onCreateContourRectangle( )
337 //JCP 20-10-08 Undo redo implementation
339 //JCP 20-10-08 Undo redo implementation
343 void wxContourMainFrame::onCreateContourCircle( )
345 //JCP 20-10-08 Undo redo implementation
347 //JCP 20-10-08 Undo redo implementation
351 void wxContourMainFrame::onCreateContourLine( )
353 //JCP 20-10-08 Undo redo implementation
355 //JCP 20-10-08 Undo redo implementation
359 // RaC 09-09 --------------------------------------
360 void wxContourMainFrame::onCreateContourPoints( )
362 //JCP 20-10-08 Undo redo implementation
364 //JCP 20-10-08 Undo redo implementation
367 // RaC 09-09 --------------------------------------
369 // RaC 10-09 --------------------------------------
370 void wxContourMainFrame::onCreateContourPolygon( )
372 //JCP 20-10-08 Undo redo implementation
374 //JCP 20-10-08 Undo redo implementation
377 // RaC 10-09 --------------------------------------
379 //------------------------------------------------------------------------------------------------------------
381 void wxContourMainFrame :: onCreateContourBullEye(wxPanel* panel )
383 //Creating the manualBaseModel and including in the model
384 manualBaseModel * manModelContour = factoryManualContourModel(panel );
386 std::vector<int> instantVector;
387 _instantPanel->getInstant( instantVector );
388 std::string theName = kernelManager->createOutline(manModelContour, instantVector);
390 /*std::vector<int> instantVector;
391 _instantPanel->getInstant( instantVector );
393 theName= _modelManager->createOutline( manModelContour, instantVector );*/
394 bool addedModel = theName.compare("") != 0;//??
398 double spc[3];//Si no hay imagen pero hay contornos que spacing se pone por default
399 _theViewPanel->getSpacing(spc);
400 //Adding the manualContourControler to interface objects structure
401 //Adding the manualViewContour to interface objects structure
402 //_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.
403 _theViewPanel->getSceneManager()->configureViewControlTo( theName, manModelContour,spc , 4) ;
407 void wxContourMainFrame::createContour( int typeContour )
409 //Creating the manualContourModel and including in the model
410 manualBaseModel * manModelContour = kernelManager->factoryManualContourModel(typeContour);
411 std::vector<int> instantVector;
412 _instantPanel->getInstant( instantVector );
414 std::vector<int> tempVector;
415 getInstantVector( tempVector );
416 manModelContour->SetLabel2( std::to_string(tempVector[1]) );
418 std::string theName = kernelManager->createOutline(manModelContour, instantVector);
419 /*std::vector<int> instantVector;
420 _instantPanel->getInstant( instantVector );
422 theName= _modelManager->createOutline( manModelContour, instantVector );*/
423 bool addedModel = theName.compare("") != 0;//??
426 double spc[3];//Si no hay imagen pero hay contornos que spacing se pone por default
427 _theViewPanel->getSpacing(spc);
428 //Adding the manualContourControler to interface objects structure
429 //Adding the manualViewContour to interface objects structure
430 //_sceneManager->setControlActiveStateOfALL( false );//This call is being done here because if the ROI is created underneath the previously created ROIS will still be active.
431 _theViewPanel->getSceneManager()->configureViewControlTo( theName, manModelContour,spc , typeContour) ;
435 manualBaseModel * wxContourMainFrame::factoryManualContourModel(wxPanel* panel){
437 manualContourModelBullEye *manModelContourBullEye = new manualContourModelBullEye();
438 manualBaseModel *manModelContour=NULL;
439 manModelContour = manModelContourBullEye;
441 int iCrown,sizeCrowns,iSector,sizeSectors;
442 double radioA,radioB,ang,angDelta ;
443 sizeCrowns = ((PanelBullEyeOptions*)panel)->GetNumberOfCrowns();
444 for ( iCrown=0 ; iCrown<sizeCrowns ; iCrown++ )
446 sizeSectors = ((PanelBullEyeOptions*)panel)->GetNumberOfSections(iCrown);
447 radioB = ((PanelBullEyeOptions*)panel)->GetRadioOfCrown(iCrown);
448 if (iCrown==sizeCrowns-1)
452 radioA = ((PanelBullEyeOptions*)panel)->GetRadioOfCrown(iCrown+1);
456 for ( iSector=0 ; iSector<sizeSectors ; iSector++ )
458 ang = ((PanelBullEyeOptions*)panel)->GetAngOfCrownSection(iCrown,iSector);
459 angDelta= ((PanelBullEyeOptions*)panel)->GetAngDeltaOfCrownSection(iCrown);
460 manModelContourBullEye->AddSector(radioA,radioB,ang,angDelta);
463 } // if _panelBullEyeOptions
465 return manModelContour;
468 void wxContourMainFrame :: saveState()
470 std::string temp = kernelManager->saveState();
471 saveFileWithContours(temp);
474 void wxContourMainFrame::onDeleteContour()
476 //JCP 20-10-08 Undo redo implementation
478 //JCP 20-10-08 Undo redo implementation
480 std::vector<std::string> lstKeyNameToBeErase;
481 lstKeyNameToBeErase = _theViewPanel->getSceneManager()->getSelectedObjects();
482 deleteContours( lstKeyNameToBeErase );
484 int i,size=_sceneManager->getSelectedObjects().size();
487 std::string keyName = _sceneManager->getSelectedObjects()[i];
488 int ispartofstaticlist = this->_modelManager->IsPartOfStaticList( keyName );
489 if ( ispartofstaticlist>=0 )
491 std::vector<int> tempVector;
492 _instantPanel->getInstant( tempVector );
493 Instant instant(&tempVector);
494 this->_modelManager->ChangeContourOfList(keyName, &instant);
498 std::vector<std::string> lstKeyName;
499 std::vector<std::string> lstKeyNameActualSlice;
500 std::vector<std::string> lstKeyNameToBeErase;
502 lstKeyNameToBeErase = _sceneManager->getSelectedObjects();
503 lstKeyNameActualSlice = _sceneManager->GetlstContoursNameActualSlice();
504 int k,kSize=lstKeyNameToBeErase.size();
505 int j,jSize=lstKeyNameActualSlice.size();
507 for (k=0;k<kSize; k++)
510 for (j=0;j<jSize; j++)
512 if (lstKeyNameToBeErase[k]==lstKeyNameActualSlice[j])
519 lstKeyName.push_back( lstKeyNameToBeErase[k] );
523 deleteContours( lstKeyName );
527 void wxContourMainFrame :: deleteContours( std::vector<std::string> keyNamesVector )
529 int i,size=keyNamesVector.size();
532 deleteContour( keyNamesVector[i] );
536 void wxContourMainFrame :: deleteContour( std::string theKeyName )
539 manualContourModel * cModel;
540 manualViewBaseContour * cViewer;
541 manualContourBaseControler * cControler;
543 ContourWrap_ViewControl *conwrapviewControl = _theViewPanel->getSceneManager()->getContourWrap_ViewControlOf( theKeyName );
544 cControler = conwrapviewControl->getControler();*/
547 bool isedit = _theViewPanel->isEditableCControler(theKeyName);
548 bool ispartofstaticlst = kernelManager->IsPartOfStaticList(theKeyName);
550 if (isedit && ispartofstaticlst)
552 _theViewPanel->removeFromScene(theKeyName);
554 kernelManager->deleteCModel(theKeyName);
555 //_theViewPanel->getSceneManager()->removeFromScene( theKeyName );
556 //cViewer = conwrapviewControl->getViewer();
557 //_theViewPanel->getSceneManager()->removeWrap( theKeyName );
558 //cControler* conwrapviewControl->getControler();
561 // delete cControler;
566 void wxContourMainFrame::onDeleteContoursActSlice()
568 //JCP 20-10-08 Undo redo implementation
570 //JCP 20-10-08 Undo redo implementation
572 std::vector<int> tempVector;
573 getInstantVector( tempVector );
574 deleteContours( getOutlinesName( tempVector[1] ) );
575 // deleteContours( (std::vector<std::string>)_theViewPanel->getSceneManager()->GetlstContoursNameActualSlice() );
578 void wxContourMainFrame::onDeleteAllContours(){
579 //JCP 20-10-08 Undo redo implementation
583 void wxContourMainFrame::deleteAllContours(){
584 //JCP 20-10-08 Undo redo implementation
587 std::vector<int> tempVector;
588 _instantPanel->getInstant( tempVector );
590 //JCP --08-09-2008 When using a diferent interface the _mbarrangeDeleteAll might not be initialize
591 // the values in GetStart and GetEnd will then not be initialize also.
592 // We use instead the values given when initializing the _deletepanel.
594 //int minZ = _mbarrangeDeleteAll->GetStart();
595 //int maxZ = _mbarrangeDeleteAll->GetEnd();
599 maxZ = _theViewPanel->getSceneManager()->GetImageDataSizeZ();
603 _theViewPanel->getSceneManager()->removeSceneContours( );
604 _theViewPanel->getSceneManager()->removeAllOutlines();
605 kernelManager->removeAllOutlines();
608 if ( (minZ==0) && (maxZ==_mbarrangeDeleteAll->GetMax() ))
610 _theViewPanel->getSceneManager()->removeSceneContours( );
611 _modelManager->removeAllOutlines();
612 _theViewPanel->getSceneManager()->removeAllOutlines();
615 for ( z=minZ ; z<=maxZ ; z++)
618 Instant instant(&tempVector);
619 std::vector<ContourThing**> lstContourThings = this->_modelManager->getOutlinesAtInstant( &instant );
621 sizeLstContourThings = lstContourThings.size();
622 for (ii=0 ; ii<sizeLstContourThings ; ii++)
624 ContourThing **contourthing = lstContourThings[ii];
625 deleteContour( (*contourthing)->getName() );
632 void wxContourMainFrame::setConceptValue( std::string name, int value )
634 _instantPanel->setConceptValue(name, value);
638 ConceptDataWrap* wxContourMainFrame::getLastConceptData()
640 return _instantPanel->getLastConceptData();
644 bool wxContourMainFrame::getIfConceptCheckedAt( std::string name, int pos )
646 return _instantPanel->getIfConceptCheckedAt( name, pos );
651 void wxContourMainFrame::ShowResultImages(int typeContourGroup, int selection, int minZ, int maxZ)
654 vtkImageData * value;
655 this->getMaskValue(&mask, &value, typeContourGroup, selection, minZ, maxZ);
657 std::vector<int> nTypeView;
658 nTypeView.push_back(5);
659 nTypeView.push_back(1);
660 nTypeView.push_back(2);
661 nTypeView.push_back(0);
663 if (_frameShowResultImages==NULL)
665 // wxFrame *_frameShowResultImages = new wxFrame(this, -1,_T("Result image extracted.."),wxDefaultPosition,wxSize(600,600), wxDEFAULT_FRAME_STYLE|wxSTAY_ON_TOP);
666 _frameShowResultImages = new wxFrame(this, -1,_T("Result image extracted.."),wxDefaultPosition,wxSize(600,600),
667 wxFRAME_TOOL_WINDOW|wxSYSTEM_MENU | wxCAPTION | wxCLIP_CHILDREN |wxFRAME_FLOAT_ON_PARENT | wxRESIZE_BORDER );
669 wxAuiManager *m_mgr_noteBookViewerResult = new wxAuiManager();
670 m_mgr_noteBookViewerResult->SetManagedWindow(_frameShowResultImages);
672 wxAuiNotebook* noteBookViewerResult = new wxAuiNotebook(_frameShowResultImages, -1, wxPoint(600, 600), wxSize(430,200), m_notebook_style);
673 m_mgr_noteBookViewerResult->AddPane(noteBookViewerResult, wxAuiPaneInfo().Name(wxT("notebook_content")).CenterPane().PaneBorder(false));
675 wxPanel *panelViewer1 = new wxMaracas_N_ViewersWidget(noteBookViewerResult, value,&nTypeView);
676 wxPanel *panelViewer2 = new wxMaracas_N_ViewersWidget(noteBookViewerResult, mask,&nTypeView);
679 noteBookViewerResult->AddPage( panelViewer1, wxT("Image result") );
680 noteBookViewerResult->AddPage( panelViewer2, wxT("Mask result") );
681 m_mgr_noteBookViewerResult->Update();
682 _frameShowResultImages->Show();
683 } // if _frameShowResultImages
689 void wxContourMainFrame::changeInstant()
691 std::vector<int> instantVect;
692 _instantPanel->getInstant( instantVect );
693 int actualSlice = instantVect[1];
694 kernelManager->setInstant(instantVect);
695 // Refresh Mask image
696 if(_viewMaskImage!=NULL)
698 _viewMaskImage->SetZ(actualSlice);
699 if (_viewMaskImagePanel->IsVisible()==true)
701 vtkImageData *mask, *value;
702 getMaskValue(&mask,&value, _contourGroup , 0, -1, -1);
703 _viewMaskImage->onThreshold();
705 } // if _viewMaskImage
706 // Refresh Threshold image
707 if(_viewThresholdImage!=NULL)
709 _viewThresholdImage->SetZ(actualSlice);
710 if (_viewThresholdImagePanel->IsVisible()==true)
712 _viewThresholdImage->onThreshold();
714 } // if _viewThresholdImage
715 updateInstantOutlines();
716 updateInstantImageData();
722 void wxContourMainFrame::updateInstantOutlines()
724 _theViewPanel->removeSceneContours();
725 _theViewPanel->addNameWrapperToScene();
727 //for( int i=0; i<size; i++)
729 // _theViewPanel->getSceneManager()->addToScene(namesWrapping[i]->getKeyName(), true, true, true, false, false );
733 int wxContourMainFrame::getNamesWrappingSize()
735 return kernelManager->getNamesWrappingSize();
738 std::string wxContourMainFrame::getNameWrapping(int i)
740 return kernelManager->getNameWrapping(i);
743 void wxContourMainFrame::updateInstantImageData()
745 std::vector<int> inst;
746 _instantPanel->getInstant(inst);
747 vtkImageData* img = kernelManager->getImageAtInstant(inst);
750 _theViewPanel->changeImage(img);
753 int z = _instantPanel->getConceptDataOf("Axe Depth")->getActualValue();
754 _theViewPanel->setImageSlice(z);
758 void wxContourMainFrame::updateInstantAxes()
763 void wxContourMainFrame::onChangeDeep(int val){
764 _instantPanel->setConceptValue( "Axe Depth", (int)val );
769 void wxContourMainFrame::onCopy(){
770 std::vector<std::string> currentSelection = _theViewPanel->getSelectedObjects();
771 std::vector<int> tempVector;
772 _instantPanel->getInstant( tempVector );
773 _performingOperation->reset();
774 _performingOperation->setStartCommand( COPY );
775 _performingOperation->setStartOperationInstantVector( tempVector );
776 _performingOperation->setKeyNamesOperationElems( currentSelection );
779 void wxContourMainFrame::onPaste()
781 char theStartCommand = _performingOperation->getStartCommand();
782 if ( theStartCommand == COPY )
784 //JCP 20-10-08 Undo redo implementation
786 //JCP 20-10-08 Undo redo implementation
787 std::vector<int> tempVector;
788 _instantPanel->getInstant( tempVector );
789 _performingOperation->setEndOperationInstantVector ( tempVector );
790 std::vector<std::string> elems = _performingOperation->getKeyNamesOperationElems();
791 int i,size = elems.size();
792 for( i=0; i<size; i++ )
794 createCopyContourOf( elems[i], tempVector, i>0 );
799 void wxContourMainFrame::onUndo()
801 std::string filename;
802 if(kernelManager->onUndoSaveFile(filename)){
803 saveFileWithContours(filename);
805 if(kernelManager->onUndo(filename)){
809 void wxContourMainFrame::onRedo(){
810 std::string filename;
811 if(kernelManager->onRedo(filename)){
816 void wxContourMainFrame :: createCopyContourOf ( std::string anExistingKName, std::vector<int> &instantNoTouchData, bool append )
818 std::string cloneName = kernelManager->createCopyContourOf( anExistingKName, instantNoTouchData );
819 manualBaseModel * manualModel = kernelManager->getOutlineByKeyName(cloneName);//_modelManager->getOutlineByKeyName( cloneName )->getModel();
820 _theViewPanel->getSceneManager()->createCopyContourOf( anExistingKName, cloneName, manualModel , append );
823 ///AD: 03-09 Copy the object and apply the given transformation
824 void wxContourMainFrame :: createMirrorContourOf ( std::string anExistingKName, std::vector<int> &instantNoTouchData, bool append )
826 std::string cloneName = kernelManager->createCopyContourOf( anExistingKName, instantNoTouchData );
827 manualBaseModel * manualModel = kernelManager->getOutlineByKeyName(cloneName);
829 manualPoint * refPoint1 = _refLineModel->GetManualPoint(0);
830 manualPoint * refPoint2 = _refLineModel->GetManualPoint(1);
832 double pnt1X = refPoint1->GetX();
833 double pnt1Y = refPoint1->GetY();
834 // double pnt1Z = refPoint1->GetZ();
835 double pnt2X = refPoint2->GetX();
836 double pnt2Y = refPoint2->GetY();
837 // double pnt2Z = refPoint2->GetZ();
839 double angle = (atan2(pnt2Y - pnt1Y, pnt2X - pnt1X) * 180 / 3.1415926535897932384626433832795)+90;
840 vtkTransform *t = vtkTransform::New();
844 t->Translate(-pnt1X, -pnt1Y, 0);
848 t->Translate(pnt1X, pnt1Y, 0);
851 int i,size=manualModel->GetSizeLstPoints();
854 manualPoint * mp = manualModel->GetManualPoint(i);
860 t->TransformPoint( vecIn, vecOut );
861 mp->SetPointX( vecOut[0] );
862 mp->SetPointY( vecOut[1] );
863 mp->SetPointZ( vecOut[2] );
866 _theViewPanel->getSceneManager()->createCopyContourOf( anExistingKName, cloneName, manualModel , append );
869 void wxContourMainFrame ::loadState(std::string filename)
872 onLoadContours(filename,false);
875 void wxContourMainFrame::onLoad(bool interactiveInterface) // interactiveInterface default true
877 std::string fileNameContourROI = GetFileLocation();
878 //CMRU 03-09-09-----------------------------------------------------------------------------------------------
879 if(GetFileLocation().empty())
881 //------------------------------------------------------------------------------------------------------------
882 //EED 2017-09-16 Migration wxWidgets 2.8 to 3.0
883 #if wxMAJOR_VERSION <= 2
884 wxFileDialog dialog(NULL, _T("Choose a file"), _T(""), _T(""), _T("*.roi"), wxOPEN );
886 wxFileDialog dialog(NULL, _T("Choose a file"), _T(""), _T(""), _T("*.roi"), wxFD_OPEN );
888 if (dialog.ShowModal() == wxID_OK)
890 fileNameContourROI = (const char *)(dialog.GetPath().mb_str());
893 onLoadContours(fileNameContourROI, interactiveInterface );
896 void wxContourMainFrame::SetZForAllContours(int pz)
899 std::vector< std::string > lstNameThings;
900 int i,sizeLstNameThings;
901 int ii,sizeLstPoints;
902 lstNameThings = kernelManager->GetLstNameThings();
903 sizeLstNameThings = lstNameThings.size();
904 for (i=0 ; i<sizeLstNameThings ; i++)
906 manualBaseModel * manualModel = kernelManager->getOutlineByKeyName(lstNameThings[i]);
907 sizeLstPoints = manualModel->GetSizeLstPoints();
908 for (ii=0 ; ii<sizeLstPoints ; ii++)
910 manualModel->GetManualPoint(ii)->SetPointZ(-900);
911 }// for ii list of points
912 }// for i list of Things
916 lstNameThings = kernelManager->GetLstNameThingsStatic();
917 sizeLstNameThings = lstNameThings.size();
918 for (i=0 ; i<sizeLstNameThings ; i++)
920 manualBaseModel * manualModel = kernelManager->getOutlineByKeyName(lstNameThings[i]);
921 sizeLstPoints = manualModel->GetSizeLstPoints();
922 for (ii=0 ; ii<sizeLstPoints ; ii++)
924 manualModel->GetManualPoint(ii)->SetPointZ(-900);
925 }// for ii list of points
926 }// for i list of static things
929 void wxContourMainFrame::onLoadContours(std::string fileNameContourROI, bool interactiveInterface)
933 FILE *pFile =fopen(fileNameContourROI.c_str(),"r+");
934 //CMRU 03-09-09- ----------------------------------------------------------------------------------------------
937 //------------------------------------------------------------------------------------------------------------
938 fileNameContourROI.append("data");
939 FILE *pFileData=fopen(fileNameContourROI.c_str(),"r+");
940 if(pFileData != NULL)
942 fscanf(pFileData,"%s",tmpD); // --CreaContour--
943 fscanf(pFileData,"%s",tmpD); // Version
944 fscanf(pFileData,"%s",tmpD); // 1.0.3 || 1.0.2 || 1.0.1 || 1.0.0
946 fscanf(pFileData,"%s",tmpD); // onePixelSize
947 fscanf(pFileData,"%s",tmpD); // #
948 _onePixelSize = atof(tmpD);
949 fscanf(pFileData,"%s",tmpD); // NumberOfContours
950 fscanf(pFileData,"%s",tmpD); // #
952 fscanf(pFile,"%s",tmp); // --CreaContour--
953 fscanf(pFile,"%s",tmp); // Version
954 fscanf(pFile,"%s",tmp); // 1.0.3 || 1.0.2 || 1.0.1 || 1.0.0
955 std::string version(tmp);
957 _tmpReadFileTypeOfTransformation=-1;
958 if (version=="1.0.3")
960 readDimSpc(pFile,interactiveInterface); // DimSpc interactive ON
961 openContours(pFile,pFileData,false);
962 openContours(pFile,pFileData,true); //Load StaticContours
964 if (version=="1.0.2")
967 readDimSpc(pFile,interactiveInterface); // DimSpc interactive ON
968 openContours(pFile,pFileData,false);
969 readDimSpc(pFile,false); // DimSpc interactive OFF
970 openContours(pFile,pFileData,true); // Load StaticContours
971 SetZForAllContours(-900);
972 } else if (version=="1.0.1") { //AD:02-06-09
973 openContours(pFile,pFileData,false); //Skips ImageDimensions and ImageSpacing
974 openContours(pFile,pFileData,true); //Load StaticContours, skips ImageDimensions and ImageSpacing
975 } else if (version=="1.0.0") { //AD:02-06-09
976 openContours(pFile,pFileData,false); //Skips ImageDimensions and ImageSpacing
979 if(pFileData != NULL)
984 _theViewPanel->getSceneManager()->removeSceneContours();
989 void wxContourMainFrame::onImport()
991 std::string filename, filenamecontours;
992 //EED 2017-09-16 Migration wxWidgets 2.8 to 3.0
993 #if wxMAJOR_VERSION <= 2
994 wxFileDialog dialog(NULL, _T("Choose a XML Osirix File"), _T(""), _T(""), _T("*.xml"), wxOPEN );
996 wxFileDialog dialog(NULL, _T("Choose a XML Osirix File"), _T(""), _T(""), _T("*.xml"), wxFD_OPEN );
998 if (dialog.ShowModal() == wxID_OK)
1000 filename = dialog.GetPath().mb_str();
1001 filenamecontours = kernelManager->parseOsirixFile(filename);
1003 if(filenamecontours.compare("") != 0)
1005 onLoadContours(filenamecontours,true);
1010 void wxContourMainFrame::onTest()
1012 std::string filename, filenamecontours;
1013 //EED 2017-09-16 Migration wxWidgets 2.8 to 3.0
1014 #if wxMAJOR_VERSION <= 2
1015 wxFileDialog dialog(NULL, _T("Choose a File"), _T(""), _T(""), _T("*.*"), wxOPEN );
1017 wxFileDialog dialog(NULL, _T("Choose a File"), _T(""), _T(""), _T("*.*"), wxFD_OPEN );
1019 if (dialog.ShowModal() == wxID_OK)
1021 filename = dialog.GetPath().mb_str();
1022 std::cout << "This is the filename: " << filename << std::endl;
1027 void wxContourMainFrame::onSave()
1029 //CMRU 03-09-09-----------------------------------------------------------------------------------------------
1030 if(GetFileLocation().empty())
1032 //------------------------------------------------------------------------------------------------------------
1033 //EED 2017-09-16 Migration wxWidgets 2.8 to 3.0
1034 #if wxMAJOR_VERSION <= 2
1035 wxFileDialog dialog(NULL, _T("Choose a file"), _T(""), _T(""), _T("*.roi"), wxSAVE );
1037 wxFileDialog dialog(NULL, _T("Choose a file"), _T(""), _T(""), _T("*.roi"), wxFD_SAVE );
1039 if (dialog.ShowModal() == wxID_OK)
1041 std::string fileNameContourROI = (const char *)(dialog.GetPath().mb_str());
1042 kernelManager->setCurrentFileName(fileNameContourROI);
1043 saveFileWithContours( fileNameContourROI );
1045 } else {//CMRU 03-09-09-----------------------------------------------------------------------------------------------
1046 std::cout<<"Nombre del archivo: "<<GetFileLocation()<<std::endl;
1047 std::string fileNameContourROI = GetFileLocation();
1048 std::cout<<"Nombre del archivo: "<<fileNameContourROI<<std::endl;
1049 kernelManager->setCurrentFileName(fileNameContourROI);
1050 saveFileWithContours( fileNameContourROI);
1052 //------------------------------------------------------------------------------------------------------------
1056 void wxContourMainFrame::saveFileWithContours( std::string filename )
1059 FILE *pFile=fopen(filename.c_str(),"w+");
1061 //CMRU 03-09-09-----------------------------------------------------------------------------------------------
1062 filename.append("data");
1063 std::cout<<"Nombre del archivo: "<<filename<<std::endl;
1064 FILE *pFileData=fopen(filename.c_str(),"w+");
1065 //------------------------------------------------------------------------------------------------------------
1067 std::vector< std::string > lstNameThings;
1068 int i,sizeLstNameThings;
1070 fprintf(pFile,"--CreaContour--\n");
1071 fprintf(pFile,"Version %s\n", "1.0.3" );
1073 //CMRU 03-09-09-----------------------------------------------------------------------------------------------
1074 fprintf(pFileData,"--CreaContour--\n");
1075 fprintf(pFileData,"Version %s\n", "1.0.3" );
1076 fprintf(pFileData,"OnePixelSize %f\n", _onePixelSize);
1077 //------------------------------------------------------------------------------------------------------------
1078 vtkImageData *image = _images[0];
1080 image->GetDimensions(dimRange);
1081 fprintf(pFile,"ImageDimensions %d %d %d\n", dimRange[0], dimRange[1], dimRange[2] );
1083 image->GetSpacing(spaRange);
1084 fprintf(pFile,"ImageSpacing %f %f %f\n", spaRange[0], spaRange[1], spaRange[2] );
1086 lstNameThings = kernelManager->GetLstNameThings();
1087 sizeLstNameThings = lstNameThings.size();
1088 fprintf(pFile,"NumberOfContours %d\n", sizeLstNameThings );
1089 //CMRU 03-09-09-----------------------------------------------------------------------------------------------
1090 fprintf(pFileData,"NumberOfContours %d\n", sizeLstNameThings );
1091 //------------------------------------------------------------------------------------------------------------
1097 for (i=0 ; i<sizeLstNameThings ; i++)
1099 //CMRU 03-09-09-----------------------------------------------------------------------------------------------
1100 manualBaseModel * manualModel = kernelManager->getOutlineByKeyName(lstNameThings[i]);
1102 // double sizeInPixel = manualModel ->GetPathSize( );
1103 double sizeInPixel = manualModel ->GetPathSize( spc );
1104 double realContourSize = sizeInPixel*_onePixelSize;
1105 manualModel ->SetRealSize(realContourSize);
1106 //------------------------------------------------------------------------------------------------------------
1107 //int size= kernelManager->GetLstNameThings().size();
1108 kernelManager->SaveThingName( pFile, pFileData, lstNameThings[i] );
1109 _theViewPanel->getSceneManager()->SaveThingName( pFile, lstNameThings[i] );
1111 //-- Static Contours
1112 // fprintf(pFile,"ImageDimensions %d %d %d\n", dimRange[0], dimRange[1], dimRange[2] );
1113 // fprintf(pFile,"ImageSpacing %f %f %f\n", spaRange[0], spaRange[1], spaRange[2] );
1114 lstNameThings = kernelManager->GetLstNameThingsStatic();
1115 sizeLstNameThings = lstNameThings.size();
1116 fprintf(pFile,"NumberOfContoursStatic %d\n", sizeLstNameThings );
1117 //CMRU 03-09-09-----------------------------------------------------------------------------------------------
1118 fprintf(pFileData,"NumberOfContoursStatic %d\n", sizeLstNameThings );
1119 //------------------------------------------------------------------------------------------------------------
1120 for (i=0 ; i<sizeLstNameThings ; i++)
1122 kernelManager->SaveThingName( pFile, pFileData, lstNameThings[i] );
1123 _theViewPanel->getSceneManager()->SaveThingName( pFile, lstNameThings[i] );
1131 void wxContourMainFrame::readDimSpc(FILE *pFile, bool interactiveOption)
1135 double imageSpac[3];
1136 vtkImageData *image = _images[0];
1137 image->GetDimensions(imageDim);
1138 image->GetSpacing(imageSpac);
1140 fscanf(pFile,"%s",tmp); // ImageDimensions
1141 fscanf(pFile,"%s",tmp); // X
1142 _tmpReadFileImageDim[0] = atoi(tmp);
1143 fscanf(pFile,"%s",tmp); // Y
1144 _tmpReadFileImageDim[1] = atoi(tmp);
1145 fscanf(pFile,"%s",tmp); // Z
1146 _tmpReadFileImageDim[2] = atoi(tmp);
1148 fscanf(pFile,"%s",tmp); // ImageSpacing
1149 fscanf(pFile,"%s",tmp); // X
1150 _tmpReadFileImageSpac[0] = atof(tmp);
1151 fscanf(pFile,"%s",tmp); // Y
1152 _tmpReadFileImageSpac[1] = atof(tmp);
1153 fscanf(pFile,"%s",tmp); // Z
1154 _tmpReadFileImageSpac[2] = atof(tmp);
1157 if (interactiveOption==true)
1159 //Compare Spacing and Dims in X and Y (Necessary in Z?) - Just for Version 2
1160 if (imageDim[0]!=_tmpReadFileImageDim[0] || imageDim[1]!=_tmpReadFileImageDim[1] || imageSpac[0]!=_tmpReadFileImageSpac[0] || imageSpac[1]!=_tmpReadFileImageSpac[1])
1162 wxDialog* dial = new wxDialog (this,-1,_T("Tools"),wxDefaultPosition, wxSize(460,360));
1163 wxSizer* buttonsSizer = dial->CreateSeparatedButtonSizer(wxOK|wxCANCEL);
1164 // wxBoxSizer *dialSizer = new wxBoxSizer(wxVERTICAL);
1165 wxFlexGridSizer *dialSizer = new wxFlexGridSizer(1);
1167 wxString lstOptOperation[3];
1168 lstOptOperation[0]=_T("By Dimension (XY)");
1169 lstOptOperation[1]=_T("By Spacing (XY)");
1170 lstOptOperation[2]=_T("By Spacing (XYZ)");
1171 wxRadioBox * radioOpts = new wxRadioBox(dial, -1, _T("Type of Transformation"), wxDefaultPosition, wxSize(370,200), 3 , lstOptOperation, 3, wxRA_SPECIFY_ROWS);
1173 dialSizer->Add( new wxStaticText(dial,-1,_T("The image resolution is not compatible with the ")) , 0, wxGROW );
1174 dialSizer->Add( new wxStaticText(dial,-1,_T("selected Roi file. Do you want to tranform it?")) , 0, wxGROW );
1175 dialSizer->Add( new wxStaticText(dial,-1,_T(" ")) , 0, wxGROW );
1176 dialSizer->Add(radioOpts,0,wxGROW);
1177 dialSizer->Add( new wxStaticText(dial,-1,_T(" ")) , 0, wxGROW );
1178 dialSizer->Add(buttonsSizer,0,wxGROW);
1179 dial->SetSizer(dialSizer, true);
1183 _tmpReadFileTypeOfTransformation = -1;
1184 //EED bool transform = false;
1186 if (dial->GetReturnCode() == wxID_OK)
1188 _tmpReadFileTypeOfTransformation = radioOpts->GetSelection();
1192 } // if interactiveOption
1199 void wxContourMainFrame::openContours( FILE *pFile, FILE *pFileData, bool staticContour )
1203 vtkImageData *image = _images[0];
1206 double imageSpac[3];
1207 image->GetDimensions(imageDim);
1208 image->GetSpacing(imageSpac);
1211 fscanf(pFile,"%s",tmp); // NumberOfContours
1212 fscanf(pFile,"%s",tmp); // ##
1213 int numberOfContours = atoi(tmp);
1215 std::vector<int> instantVector;
1216 int typeContourModel;
1217 manualBaseModel *manModelContour;
1221 if (compatible==true)
1224 for (i=0;i<numberOfContours;i++)
1226 instantVector.clear();
1227 fscanf(pFile,"%s",tmp); // Instant
1229 fscanf(pFile,"%s",tmp); // 1
1230 instantVector.push_back( atoi(tmp) );
1231 fscanf(pFile,"%s",tmp); // 2
1232 instantVector.push_back( atoi(tmp) );
1233 fscanf(pFile,"%s",tmp); // 3
1234 instantVector.push_back( atoi(tmp) );
1235 fscanf(pFile,"%s",tmp); // 4
1236 instantVector.push_back( atoi(tmp) );
1237 fscanf(pFile,"%s",tmp); // 5
1238 instantVector.push_back( atoi(tmp) );
1239 fscanf(pFile,"%s",tmp); // 6
1240 instantVector.push_back( atoi(tmp) );
1243 fscanf(pFile,"%s",tmp); // TypeContourModel
1244 fscanf(pFile,"%s",tmp); // ##
1245 typeContourModel = atoi(tmp);
1247 manModelContour = kernelManager->factoryManualContourModel(typeContourModel);
1248 manModelContour->Open(pFile);
1249 if(pFileData != NULL)
1251 manModelContour->OpenData(pFileData);
1254 fscanf(pFile,"%s",tmp); // TypeView
1255 fscanf(pFile,"%s",tmp); // ##
1256 typeView = atoi(tmp);
1258 std::string theName;
1259 theName = kernelManager->createOutline( manModelContour, instantVector );
1260 bool addedModel = theName.compare("") != 0;
1263 double spc[3];//Si no hay imagen pero hay contornos que spacing se pone por default
1264 _theViewPanel->getSpacing(spc);
1265 //Adding the manualContourControler to interface objects structure
1266 //Adding the manualViewContour to interface objects structure
1267 //_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.
1268 _theViewPanel->getSceneManager()->configureViewControlTo( theName, manModelContour,spc , typeView) ;
1271 if (staticContour) //StaticContours (will appear in all slices)
1273 Instant instant(&instantVector);
1274 kernelManager->changeContourOfManager( theName , &instant );
1277 }// for numberOfContours
1280 else if (compatible==false)
1285 for (i=0;i<numberOfContours;i++)
1287 instantVector.clear();
1288 fscanf(pFile,"%s",tmp); // Instant
1290 fscanf(pFile,"%s",tmp); // 1
1291 instantVector.push_back( atoi(tmp) );
1292 fscanf(pFile,"%s",tmp); // 2
1293 instantVector.push_back( atoi(tmp) );
1294 fscanf(pFile,"%s",tmp); // 3
1295 instantVector.push_back( atoi(tmp) );
1296 fscanf(pFile,"%s",tmp); // 4
1297 instantVector.push_back( atoi(tmp) );
1298 fscanf(pFile,"%s",tmp); // 5
1299 instantVector.push_back( atoi(tmp) );
1300 fscanf(pFile,"%s",tmp); // 6
1301 instantVector.push_back( atoi(tmp) );
1303 fscanf(pFile,"%s",tmp); // TypeContourModel
1304 fscanf(pFile,"%s",tmp); // ##
1305 typeContourModel = atoi(tmp);
1307 manModelContour = kernelManager->factoryManualContourModel(typeContourModel);
1308 manModelContour->Open(pFile);
1309 if(pFileData != NULL)
1311 manModelContour->OpenData(pFileData);
1314 if (_tmpReadFileTypeOfTransformation==-1){
1316 } else if (_tmpReadFileTypeOfTransformation==0){
1317 double transX, transY;
1318 transX = (double) imageDim[0]/_tmpReadFileImageDim[0]; // X
1319 transY = (double) imageDim[1]/_tmpReadFileImageDim[1]; // Y
1320 manModelContour->Transform_Ax_Plus_B(transX,0,transY,0);
1321 } else if (_tmpReadFileTypeOfTransformation==1) {
1322 double transX, transY;
1323 transX = (double) _tmpReadFileImageSpac[0]/imageSpac[0]; // X
1324 transY = (double) _tmpReadFileImageSpac[1]/imageSpac[1]; // Y
1325 manModelContour->Transform_Ax_Plus_B(transX,0,transY,0);
1326 } else if (_tmpReadFileTypeOfTransformation==2) { // with Z include
1327 double transX, transY;
1328 transX = (double) _tmpReadFileImageSpac[0]/imageSpac[0]; // X
1329 transY = (double) _tmpReadFileImageSpac[1]/imageSpac[1]; // Y
1330 instantVector[1]=instantVector[1]*_tmpReadFileImageSpac[2]/imageSpac[2]; // Z
1331 manModelContour->Transform_Ax_Plus_B(transX,0,transY,0);
1333 printf ("EED Warnning! wxContourMainFrame::openContours _tmpReadFileTypeOfTransformation not set. \n");
1336 fscanf(pFile,"%s",tmp); // TypeView
1337 fscanf(pFile,"%s",tmp); // ##
1338 typeView = atoi(tmp);
1340 std::string theName;
1341 theName = kernelManager->createOutline( manModelContour, instantVector );
1342 bool addedModel = theName.compare("") != 0;
1345 double spc[3];//Si no hay imagen pero hay contornos que spacing se pone por default
1346 _theViewPanel->getSpacing(spc);
1347 //Adding the manualContourControler to interface objects structure
1348 //Adding the manualViewContour to interface objects structure
1349 //_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.
1350 _theViewPanel->getSceneManager()->configureViewControlTo( theName, manModelContour,spc , typeView) ;
1353 if (staticContour) //StaticContours (will appear in all slices)
1355 Instant instant(&instantVector);
1356 kernelManager->changeContourOfManager( theName , &instant );
1358 }// for numberOfContours
1364 void wxContourMainFrame::RefreshInterface()
1367 _theViewPanel->RefreshInterface();
1368 //wxVtk2DBaseView *wxvtk2dbaseview = (wxVtk2DBaseView*)this->_theViewPanel->getWxVtkBaseView();
1369 //wxvtk2dbaseview->Refresh();
1372 vtkImageData* wxContourMainFrame::getImageData()
1374 return _theViewPanel->getImageData();
1377 void wxContourMainFrame::onSegmentationOneSliceITK(wxString distance, wxString sigma, wxString alfa, wxString beta, wxString propagation, wxString iterations, wxString inflation)
1379 //JCP 20-10-08 Undo redo implementation
1381 //JCP 20-10-08 Undo redo implementation
1384 int x = _theViewPanel->GetX();
1385 int y = _theViewPanel->GetY();
1386 int z = _theViewPanel->GetZ();
1387 SegmentationOneSliceITK( x,y,z,distance, sigma, alfa, beta, propagation, iterations, inflation);
1391 void wxContourMainFrame::SegmentationOneSliceITK(int x, int y, int z, wxString distanc, wxString sigm, wxString alf, wxString bet, wxString prop, wxString iter, wxString inflation)
1393 int typeofcontour = 1;
1395 vtkImageData *imagedata = getImageData();
1396 //Tipo de pixeles a utilizar internamente en ITK
1397 typedef float InternalPixelType;
1398 const unsigned int Dimension = 2;
1399 typedef itk::Image< InternalPixelType, Dimension > InternalImageType;
1400 //Tipo de pixeles de salida 1
1401 typedef unsigned char OutputPixelType;
1402 typedef itk::Image< OutputPixelType, Dimension > OutputImageType;
1403 //Tipo de pixeles de salida 2
1404 typedef unsigned short OutputPixelType2;
1405 typedef itk::Image< OutputPixelType2, Dimension > OutputImageType2;
1406 //DefiniciÛn del thresholder
1407 typedef itk::BinaryThresholdImageFilter<
1409 OutputImageType > ThresholdingFilterType;
1410 //DefiniciÛn del primer filtro de conversiÛn de pixeles
1411 typedef itk::CastImageFilter<
1412 OutputImageType, OutputImageType2 > CastFilterType;
1413 //DefiniciÛn del segundo tipo de conversiÛn de pixeles
1414 typedef itk::CastImageFilter<
1415 OutputImageType2, InternalImageType > CastFilterType2;
1416 //Tercer tipo de conversiÛn
1417 typedef itk::RescaleIntensityImageFilter<
1419 OutputImageType > CastFilterType3;
1420 //Cuarto tipo de conversiÛn
1421 typedef itk::RescaleIntensityImageFilter<
1423 OutputImageType > CastFilterType4;
1424 ThresholdingFilterType::Pointer thresholder = ThresholdingFilterType::New();
1425 thresholder->SetLowerThreshold( 0.0 );
1426 thresholder->SetUpperThreshold( 128 );
1427 thresholder->SetOutsideValue( 255 );
1428 thresholder->SetInsideValue( 0 );
1429 //DefinciÛn de conexiÛnes entre VTK e ITK y el writer
1430 typedef itk::VTKImageToImageFilter<OutputImageType2> ConnectorType;
1431 typedef itk::ImageToVTKImageFilter<OutputImageType> ConnectorType2;
1432 //EED10JUIN2011 typedef itk::ImageFileWriter< OutputImageType > WriterType;
1433 ConnectorType::Pointer connector = ConnectorType::New();
1434 ConnectorType2::Pointer connector2 = ConnectorType2::New();
1435 CastFilterType::Pointer filter = CastFilterType::New();
1436 CastFilterType2::Pointer filter2 = CastFilterType2::New();
1437 connector->SetInput( imagedata );
1438 filter2->SetInput(connector->GetOutput());
1439 typedef itk::CurvatureAnisotropicDiffusionImageFilter<
1441 InternalImageType > SmoothingFilterType;
1442 SmoothingFilterType::Pointer smoothing = SmoothingFilterType::New();
1443 typedef itk::GradientMagnitudeRecursiveGaussianImageFilter<
1445 InternalImageType > GradientFilterType;
1446 typedef itk::SigmoidImageFilter<
1448 InternalImageType > SigmoidFilterType;
1449 GradientFilterType::Pointer gradientMagnitude = GradientFilterType::New();
1450 SigmoidFilterType::Pointer sigmoid = SigmoidFilterType::New();
1451 sigmoid->SetOutputMinimum( 0.0 );
1452 sigmoid->SetOutputMaximum( 255.0 );
1453 typedef itk::FastMarchingImageFilter<
1455 InternalImageType > FastMarchingFilterType;
1456 FastMarchingFilterType::Pointer fastMarching = FastMarchingFilterType::New();
1457 typedef itk::GeodesicActiveContourLevelSetImageFilter< InternalImageType,
1458 InternalImageType > GeodesicActiveContourFilterType;
1459 GeodesicActiveContourFilterType::Pointer geodesicActiveContour =
1460 GeodesicActiveContourFilterType::New();
1461 typedef itk::ZeroCrossingImageFilter<
1463 InternalImageType > ZeroCrossingFilterType;
1464 ZeroCrossingFilterType::Pointer zeroCrossing =
1465 ZeroCrossingFilterType::New();
1466 const double propagationScaling = atof( crea::wx2std(prop).c_str() );
1467 geodesicActiveContour->SetPropagationScaling( propagationScaling );
1468 geodesicActiveContour->SetCurvatureScaling( 1.0 );
1469 geodesicActiveContour->SetAdvectionScaling( 1.0 );
1470 geodesicActiveContour->SetMaximumRMSError( 0.02 );
1471 int it=atoi( crea::wx2std(iter).c_str() );
1472 geodesicActiveContour->SetNumberOfIterations( it );
1473 smoothing->SetInput( filter2->GetOutput() );
1474 gradientMagnitude->SetInput( smoothing->GetOutput() );
1475 sigmoid->SetInput( gradientMagnitude->GetOutput() );
1476 fastMarching->SetInput( sigmoid->GetOutput() );
1477 geodesicActiveContour->SetInput( fastMarching->GetOutput() );
1478 geodesicActiveContour->SetFeatureImage( sigmoid->GetOutput() );
1479 zeroCrossing->SetInput( geodesicActiveContour->GetOutput() );
1480 //thresholder->SetInput( zeroCrossing->GetOutput() );
1481 thresholder->SetInput( geodesicActiveContour->GetOutput() );
1482 connector2->SetInput( thresholder->GetOutput() );
1483 smoothing->SetTimeStep( 0.125 );
1484 smoothing->SetNumberOfIterations( 5 );
1485 smoothing->SetConductanceParameter( 9.0 );
1486 const double sigma = atof( crea::wx2std(sigm).c_str() );
1487 gradientMagnitude->SetSigma( sigma );
1488 const double alpha = atof( crea::wx2std(alf).c_str() );
1489 const double beta = atof( crea::wx2std(bet).c_str() );
1490 sigmoid->SetAlpha( alpha );
1491 sigmoid->SetBeta( beta );
1492 typedef FastMarchingFilterType::NodeContainer NodeContainer;
1493 typedef FastMarchingFilterType::NodeType NodeType;
1494 NodeContainer::Pointer seeds = NodeContainer::New();
1495 InternalImageType::IndexType seedPosition;
1496 seedPosition[0] = x;
1497 seedPosition[1] = y;
1498 const double initialDistance = atof( crea::wx2std(distanc).c_str() );
1500 const double seedValue = - initialDistance;
1501 node.SetValue( seedValue );
1502 node.SetIndex( seedPosition );
1503 seeds->Initialize();
1504 seeds->InsertElement( 0, node );
1505 fastMarching->SetTrialPoints( seeds );
1506 fastMarching->SetSpeedConstant( 1.0 );
1507 fastMarching->SetOutputSize( connector->GetOutput()->GetBufferedRegion().GetSize() );
1508 fastMarching->SetStoppingValue( 800 );
1511 // connector2->Update();
1512 vtkImageData *idata = NULL;
1513 idata = connector2->GetOutput();
1514 vtkMarchingContourFilter* cntVTK = vtkMarchingContourFilter::New( );
1515 cntVTK->SetNumberOfContours( 1 );
1516 cntVTK->SetValue( 0, 255 );
1517 //EED 2017-01-01 Migration VTK7
1518 #if VTK_MAJOR_VERSION <= 5
1519 cntVTK->SetInput( idata );
1521 cntVTK->UpdateInformation();
1523 cntVTK->SetInputData( idata );
1525 vtkCleanPolyData* cpd = vtkCleanPolyData::New( );
1526 //EED 2017-01-01 Migration VTK7
1527 #if VTK_MAJOR_VERSION <= 5
1528 cpd->SetInput( cntVTK->GetOutput( ) );
1530 cpd->UpdateInformation();
1532 cpd->SetInputData( cntVTK->GetOutput( ) );
1534 vtkPolyDataConnectivityFilter* conn = vtkPolyDataConnectivityFilter::New( );
1535 conn->SetExtractionModeToLargestRegion( );
1536 //EED 2017-01-01 Migration VTK7
1537 #if VTK_MAJOR_VERSION <= 5
1538 conn->SetInput( cpd->GetOutput( ) );
1540 conn->UpdateInformation();
1542 conn->SetInputData( cpd->GetOutput( ) );
1544 vtkStripper* vtkstripper = vtkStripper::New( );
1545 //EED 2017-01-01 Migration VTK7
1546 #if VTK_MAJOR_VERSION <= 5
1547 vtkstripper->SetInput( conn->GetOutput() );
1548 vtkstripper->Update();
1549 vtkstripper->UpdateInformation();
1551 vtkstripper->SetInputData( conn->GetOutput() );
1554 vtkPolyData* polyDataResult = cntVTK->GetOutput();
1555 //std::cout<<"Points "<<polyDataResult->GetNumberOfPoints()<<std::endl;
1557 //EED 2017-01-01 Migration VTK7
1558 #if VTK_MAJOR_VERSION <= 5
1559 polyDataResult->Update( );
1560 polyDataResult->UpdateInformation();
1567 //--Calculating control points
1568 std::vector<double> vecX;
1569 std::vector<double> vecY;
1570 std::vector<double> vecXo;
1571 std::vector<double> vecYo;
1572 std::vector<double>::iterator vecXoi;
1573 std::vector<double>::iterator vecYoi;
1574 std::vector<double> vecZ;
1575 std::vector<double> vecCtrlPointX;
1576 std::vector<double> vecCtrlPointY;
1577 std::vector<double> vecCtrlPointZ;
1581 int ii,size=polyDataResult->GetNumberOfPoints();
1583 myfile.open ("C:/Creatis/example2.txt");
1584 size=polyDataResult->GetNumberOfPoints();
1585 for (ii=0;ii<size;ii++)
1592 p = polyDataResult->GetPoint(ii);
1595 // if(fabs(yAct-y)>20)
1597 // if((xAct-x)>1 || (xAct-x)<-1)
1599 // vecX.push_back( p[0] );
1600 // vecY.push_back( p[1] );
1601 // myfile <<p[0]<<","<<p[1]<<"\n";
1602 // std::cout<<" x Anterior "<<xAct<<" x actual "<<x<<std::endl;
1603 // std::cout<<" y Anterior "<<yAct<<" y actual "<<y<<std::endl;
1604 // std::cout<<" x "<<p[0]<<" y "<<p[1]<<std::endl;
1605 // vecZ.push_back( 900 );
1609 // vecXo.push_back(p[0]);
1610 // vecYo.push_back(p[1]);
1616 vecXo.push_back(p[0]);
1617 vecYo.push_back(p[1]);
1619 vecX.push_back( p[0] );
1620 myfile <<p[0]<<","<<p[1]<<"\n";
1621 //std::cout<<" x Anterior "<<xAct<<" x actual "<<x<<std::endl;
1622 //std::cout<<" y Anterior "<<yAct<<" y actual "<<y<<std::endl;
1623 //std::cout<<" x "<<p[0]<<" y "<<p[1]<<std::endl;
1624 vecY.push_back( p[1] );
1626 vecZ.push_back( -900 );
1634 while(!vecXo.empty())
1636 vecX.push_back(vecXo.back());
1637 //std::cout<<" x Siguiente "<<vecXo.back();
1640 vecZ.push_back( -900 );
1642 while(!vecYo.empty())
1644 vecY.push_back(vecYo.back());
1649 // for(int l=0;l<vecX.size();l++)
1653 // vecXo.push_back(p[0]);
1654 // vecYo.push_back(p[1]);
1656 // if(vecXoi[l-1]==)
1662 ExtractControlPoints2D *extractcontrolpoints2d = new ExtractControlPoints2D();
1663 extractcontrolpoints2d->SetContour( &vecX , &vecY , &vecZ );
1668 extractcontrolpoints2d->GetInitialControlPoints( &vecCtrlPointX , &vecCtrlPointY , &vecCtrlPointZ );
1669 } else if (method==1){
1670 extractcontrolpoints2d->GetControlPoints( &vecCtrlPointX , &vecCtrlPointY , &vecCtrlPointZ );
1671 } else if (method==2){
1672 extractcontrolpoints2d->SetSamplingControlPoints( 15 );
1673 extractcontrolpoints2d->GetSamplingControlPoints( &vecCtrlPointX , &vecCtrlPointY , &vecCtrlPointZ );
1675 //--Adding contour to the system
1677 std::vector<int> actualInstantVector;
1678 _instantPanel->getInstant( actualInstantVector );
1679 actualInstantVector[1]=z;
1681 int j,sizeCtrPt = vecCtrlPointX.size();
1683 manualBaseModel *manModelContour = kernelManager->factoryManualContourModel( typeofcontour );
1684 manModelContour->SetNumberOfPointsSpline( ((sizeCtrPt/100)+1)*100 );
1686 for (j=0 ; j<sizeCtrPt ; j++)
1688 manModelContour->AddPoint( vecCtrlPointX[j] , vecCtrlPointY[j] , vecCtrlPointZ[j] );
1690 std::string theName;
1691 //theName = _modelManager->createOutline( manModelContour, actualInstantVector );
1692 theName = kernelManager->createOutline( manModelContour, actualInstantVector );
1693 bool addedModel = theName.compare("") != 0;
1696 double spc[3];//Si no hay imagen pero hay contornos que spacing se pone por default
1697 _theViewPanel->getSpacing(spc);
1698 //Adding the manualContourControler to interface objects structure
1699 //Adding the manualViewContour to interface objects structure
1700 //_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.
1701 _theViewPanel->configureViewControlTo(theName, manModelContour, spc, typeofcontour);
1702 //_theViewPanel->getSceneManager()->configureViewControlTo( theName, manModelContour,spc, typeofcontour ) ;
1706 } catch( itk::ExceptionObject & excep ) {
1707 std::cerr << "Exception caught !" << std::endl;
1708 std::cerr << excep << std::endl;
1713 void wxContourMainFrame::onSegmentationOneSlice(int isovalue,int sampling,int method){
1715 //JCP 20-10-08 Undo redo implementation
1717 //JCP 20-10-08 Undo redo implementation
1720 int x = _theViewPanel->GetX();
1721 int y = _theViewPanel->GetY();
1722 int z = _theViewPanel->GetZ();
1723 SegmentationOneSlice( x,y,z,isovalue, sampling, method );
1728 void wxContourMainFrame::SegmentationOneSlice( int x, int y, int z, int isovalue, int sampling, int method )
1730 int typeofcontour = 1;
1731 //--Extracting Contour
1732 vtkImageData *imagedata = getImageData();
1734 vtkImageReslice *imageReslice = vtkImageReslice::New();
1737 imagedata->GetSpacing(spc);
1742 //EED 2017-01-01 Migration VTK7
1743 #if VTK_MAJOR_VERSION <= 5
1744 imageReslice->SetInput( imagedata );
1746 imageReslice->SetInputData( imagedata );
1748 imageReslice->SetInformationInput(imagedata);
1749 imageReslice->SetResliceAxesDirectionCosines(1,0,0, 0,1,0 ,0,0,1);
1750 imageReslice->SetResliceAxesOrigin(0,0,z*spc[2]);
1751 imageReslice->SetOutputDimensionality(2);
1752 imageReslice->SetInterpolationModeToLinear();
1754 //EED 2017-01-01 Migration VTK7
1755 #if VTK_MAJOR_VERSION <= 5
1758 imageReslice->Update();
1761 imagedata = imageReslice->GetOutput();
1762 //EED 2017-01-01 Migration VTK7
1763 #if VTK_MAJOR_VERSION <= 5
1764 imagedata->Update();
1765 imagedata->UpdateInformation();
1770 vtkContourFilter* cntVTK = vtkContourFilter::New( );
1771 //EED 2017-01-01 Migration VTK7
1772 #if VTK_MAJOR_VERSION <= 5
1773 cntVTK->SetInput( imagedata );
1775 cntVTK->SetInputData( imagedata );
1778 cntVTK->SetNumberOfContours( 1 );
1779 //cntVTK->SetValue( 0, vmin );
1780 // cntVTK->SetValue( 0, (range[1]*thr/100) );
1781 cntVTK->SetValue( 1, isovalue );
1782 // cntVTK->SetValue( 1, vmax );
1784 cntVTK->UpdateInformation();
1786 vtkCleanPolyData* cpd = vtkCleanPolyData::New( );
1787 //EED 2017-01-01 Migration VTK7
1788 #if VTK_MAJOR_VERSION <= 5
1789 cpd->SetInput( cntVTK->GetOutput( ) );
1791 cpd->SetInputData( cntVTK->GetOutput( ) );
1793 cpd->ConvertLinesToPointsOff( );
1795 cpd->UpdateInformation();
1797 vtkPolyDataConnectivityFilter* conn = vtkPolyDataConnectivityFilter::New( );
1799 // conn->SetExtractionModeToPointSeededRegions();
1800 // conn->SetExtractionModeToCellSeededRegions();
1801 // conn->SetExtractionModeToSpecifiedRegions();
1802 // conn->SetExtractionModeToLargestRegion();
1803 // conn->SetExtractionModeToAllRegions();
1805 conn->SetExtractionModeToClosestPointRegion();
1807 //conn->SetMaxRecursionDepth( 3000 );
1809 //EED 2017-01-01 Migration VTK7
1810 #if VTK_MAJOR_VERSION <= 5
1811 conn->SetInput( cpd->GetOutput( ) );
1813 conn->SetInputData( cpd->GetOutput( ) );
1816 conn->SetClosestPoint( x, y, 0 );
1818 conn->UpdateInformation();
1820 vtkCleanPolyData* cpd2 = vtkCleanPolyData::New( );
1821 //EED 2017-01-01 Migration VTK7
1822 #if VTK_MAJOR_VERSION <= 5
1823 cpd2->SetInput( conn->GetOutput( ) );
1825 cpd2->SetInputData( conn->GetOutput( ) );
1828 cpd2->UpdateInformation();
1830 vtkStripper* vtkstripper = vtkStripper::New( );
1831 vtkstripper->SetJoinContiguousSegments(true);
1832 vtkstripper->SetMaximumLength(20000);
1833 //EED 2017-01-01 Migration VTK7
1834 #if VTK_MAJOR_VERSION <= 5
1835 vtkstripper->SetInput( cpd2->GetOutput() );
1837 vtkstripper->SetInputData( cpd2->GetOutput() );
1838 // vtkstripper->SetInputData( cntVTK->GetOutput() );
1841 vtkstripper->Update();
1842 vtkstripper->UpdateInformation();
1845 vtkPolyData* polyDataResult = vtkstripper->GetOutput();
1847 //EED 2017-01-01 Migration VTK7
1848 #if VTK_MAJOR_VERSION <= 5
1849 polyDataResult->Update( );
1850 polyDataResult->UpdateInformation();
1857 myfile.open ("c:/temp/example.txt");
1859 polyDataResult->Print(myfile);
1860 myfile << "-------------------------------------\n";
1861 polyDataResult->GetLines()->Print(myfile);
1869 //--Calculating control points
1870 std::vector<double> vecX;
1871 std::vector<double> vecY;
1872 std::vector<double> vecZ;
1873 std::vector<double> vecCtrlPointX;
1874 std::vector<double> vecCtrlPointY;
1875 std::vector<double> vecCtrlPointZ;
1877 //printf("EED wxContourMainFrame::SegmentationOneSlice GetNumberOfLines=%d \n",polyDataResult->GetNumberOfLines() );
1878 //int numberOfPointsInCell;
1879 //int numberOfcells=polyDataResult->GetNumberOfCells();
1880 //for (int jj=0; jj<numberOfcells ; jj++)
1882 // vtkCell* vtkcell = polyDataResult->GetCell( jj );
1883 // numberOfPointsInCell=vtkcell->GetNumberOfPoints();
1884 // printf("EED wxContourMainFrame::SegmentationOneSlice cell=%d points=%d \n",jj,numberOfPointsInCell );
1886 // printf("EED wxContourMainFrame::SegmentationOneSlice PrintSelf \n");
1887 // polyDataResult->PrintSelf( std::cout, vtkIndent(0) );
1890 if (polyDataResult->GetNumberOfCells()>0)
1893 vtkCell* vtkcell = polyDataResult->GetCell( 0 );
1894 // int ii,size=polyDataResult->GetNumberOfPoints();
1895 int ii,size=vtkcell->GetNumberOfPoints();
1897 for (ii=0;ii<size;ii++)
1899 // id = polyDataResult->GetLines()->GetData()->GetValue(ii);
1900 // p = polyDataResult->GetPoint(id);
1901 p = vtkcell->GetPoints()->GetPoint(ii);
1902 // printf("EED wxContourMainFrame::SegmentationOneSlice (%d) id=%d px=%f py=%f\n",ii,id, p[0],p[1]);
1905 vecX.push_back( p[0] );
1906 vecY.push_back( p[1] );
1908 vecZ.push_back( -900 );
1909 // vecZ.push_back( p[2] );
1911 ExtractControlPoints2D *extractcontrolpoints2d = new ExtractControlPoints2D();
1912 extractcontrolpoints2d->SetContour( &vecX , &vecY , &vecZ );
1914 /*if (methodRadiobox->GetSelection()==0){
1915 extractcontrolpoints2d->GetInitialControlPoints( &vecCtrlPointX , &vecCtrlPointY , &vecCtrlPointZ );
1917 if (methodRadiobox->GetSelection()==1){
1918 extractcontrolpoints2d->GetControlPoints( &vecCtrlPointX , &vecCtrlPointY , &vecCtrlPointZ );
1920 if (methodRadiobox->GetSelection()==2){
1921 extractcontrolpoints2d->SetSamplingControlPoints( sampling );
1922 extractcontrolpoints2d->GetSamplingControlPoints( &vecCtrlPointX , &vecCtrlPointY , &vecCtrlPointZ );
1927 extractcontrolpoints2d->GetInitialControlPoints( &vecCtrlPointX , &vecCtrlPointY , &vecCtrlPointZ );
1928 } else if (method==1){
1929 extractcontrolpoints2d->GetControlPoints( &vecCtrlPointX , &vecCtrlPointY , &vecCtrlPointZ );
1930 } else if (method==2){
1931 extractcontrolpoints2d->SetSamplingControlPoints( sampling );
1932 extractcontrolpoints2d->GetSamplingControlPoints( &vecCtrlPointX , &vecCtrlPointY , &vecCtrlPointZ );
1935 //--Adding contour to the system
1936 std::vector<int> actualInstantVector;
1937 _instantPanel->getInstant( actualInstantVector );
1938 actualInstantVector[1]=z;
1940 int j,sizeCtrPt = vecCtrlPointX.size();
1941 manualBaseModel *manModelContour = kernelManager->factoryManualContourModel( typeofcontour );
1942 manModelContour->SetNumberOfPointsSpline( ((sizeCtrPt/100)+1)*100 *2 );
1943 manModelContour->SetLabel2( std::to_string(z) );
1946 for (j=0 ; j<sizeCtrPt ; j++)
1948 manModelContour->AddPoint( vecCtrlPointX[j] / spc[0], vecCtrlPointY[j] / spc[1], vecCtrlPointZ[j] );
1950 std::string theName;
1951 //theName = _modelManager->createOutline( manModelContour, actualInstantVector );
1952 theName = kernelManager->createOutline( manModelContour, actualInstantVector );
1953 bool addedModel = theName.compare("") != 0;
1956 double spc[3];//Si no hay imagen pero hay contornos que spacing se pone por default
1957 _theViewPanel->getSpacing(spc);
1958 //Adding the manualContourControler to interface objects structure
1959 //Adding the manualViewContour to interface objects structure
1960 //_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.
1961 _theViewPanel->configureViewControlTo(theName, manModelContour, spc, typeofcontour);
1962 //_theViewPanel->getSceneManager()->configureViewControlTo( theName, manModelContour,spc, typeofcontour ) ;
1965 } // if NumberOfCells > 0
1966 //printf("EED wxContourMainFrame::SegmentationOneSlice End\n");
1969 int wxContourMainFrame::GetImageDataSizeZ()
1971 return _theViewPanel->GetImageDataSizeZ();
1974 void wxContourMainFrame::GetImageDataRange(double *range)
1976 _theViewPanel->GetImageDataRange(range);
1979 void wxContourMainFrame::onSegmentationAllSlice(int minZ,int maxZ,int isovalue,int sampling,int method)
1981 //JCP 20-10-08 Undo redo implementation
1983 //JCP 20-10-08 Undo redo implementation
1986 int x = _theViewPanel->GetX();
1987 int y = _theViewPanel->GetY();
1991 double totalZ = maxZ-minZ+1;
1992 for( z=minZ ; z<=maxZ ; z++ )
1994 porcent = 100.0* (z-minZ)/totalZ;
1995 tmpString.Printf(_T(" %d %c %d/%d %d"), (int)porcent , 37 , z-minZ+1, (int)totalZ,z );
1996 interfMainPanel::getInstance()->setLabelSegmentationPanelVTK(tmpString);
1997 //_staticTextSegmentation->SetLabel(tmpString);
1998 SegmentationOneSlice( x,y,z,isovalue, sampling,method );
2000 interfMainPanel::getInstance()->setLabelSegmentationPanelVTK(_T(" "));
2005 //Creates a reference line to be used as the axis of the mirroring
2006 void wxContourMainFrame::referenceLine()
2008 if (_refLineControl==NULL)
2013 vtkImageData *vtkimagedata = _theViewPanel->getImageData();
2014 vtkimagedata->GetSpacing(spc);
2016 wxVtkBaseView * viewer2D = _theViewPanel->getWxVtkBaseView();
2018 _refLineControl = new manualLineControler();
2019 _refLineModel = new manualContourModelLine();
2020 _refLineView = new manualViewLine();
2021 _refLineView->SetModel( _refLineModel );
2022 _refLineView->SetWxVtkBaseView( viewer2D );
2023 _refLineView->SetRange( 2 );
2024 _refLineView->SetZ( 1200 );
2026 _refLineView->SetSpacing(spc);
2028 _refLineView->SetColorNormalContour(0, 0, 1);
2029 _refLineView->SetColorEditContour(0, 0.5, 0.5);
2030 _refLineView->SetWidthLine(4);
2032 _refLineControl->SetModelView( _refLineModel , _refLineView );
2033 vtkInteractorStyleBaseView* style = (vtkInteractorStyleBaseView*)viewer2D->GetInteractorStyleBaseView();
2034 style->AddInteractorStyleMaracas( _refLineControl );
2035 _refLineModel->SetCloseContour(false);
2036 _refLineControl->CreateNewManualContour();
2038 //AD: Inicializar el mirroring con una linea ya pintada
2040 double z = _refLineControl->GetZ();
2043 image->GetDimensions(imageDim);
2044 double x = (double) imageDim[0]/2;
2045 double y1 = (double) (imageDim[1]/2)+15;
2046 double y2 = (double) (imageDim[1]/2)-15;
2048 _refLineControl->AddPoint(x,y1,z);
2049 _refLineControl->AddPoint(x,y2,z);
2050 _refLineControl->SetCompleteCreation(true);
2052 _refLineModel->AddPoint(x,y1,z);
2053 _refLineModel->AddPoint(x,y2,z);
2054 _refLineModel->UpdateSpline();
2056 _refLineView->UpdateViewPoint(0);
2057 _refLineView->UpdateViewPoint(1);
2060 _refLineControl->SetActive(true);
2061 _refLineView->RefreshContour();
2065 //Hides the referenceLine
2066 void wxContourMainFrame::refLineHide()
2068 if (_refLineControl!=NULL)
2070 if (_refLineControl->GetActive())
2072 _refLineView->RemoveCompleteContourActor();
2073 _refLineControl->SetEditable(false);
2074 _refLineControl->SetActive(false);
2081 //Shows the referenceLine
2082 void wxContourMainFrame::refLineShow()
2084 if (_refLineControl!=NULL)
2086 if (_refLineControl->GetActive()==false)
2088 wxVtkBaseView * viewer2D = _theViewPanel->getWxVtkBaseView();
2090 _refLineView->SetModel( _refLineModel );
2091 _refLineView->SetWxVtkBaseView( viewer2D );
2092 _refLineView->SetRange( 2 );
2093 _refLineView->SetZ( 1200 );
2095 _refLineControl->SetModelView( _refLineModel , _refLineView );
2096 vtkInteractorStyleBaseView* style = (vtkInteractorStyleBaseView*)viewer2D->GetInteractorStyleBaseView();
2097 style->AddInteractorStyleMaracas( _refLineControl );
2098 _refLineControl->CreateNewManualContour();
2099 _refLineControl->SetActive(true);
2100 _refLineView->RefreshContour();
2107 void wxContourMainFrame::refLineChangeWidth(int width)
2109 _refLineView->SetWidthLine(width);
2110 _refLineView->RefreshContour();
2116 void wxContourMainFrame::onMirror()
2119 std::vector<std::string> currentSelection = _theViewPanel->getSelectedObjects();
2120 std::vector<std::string> filterCurrentSelection;
2122 std::vector<int> tempVector;
2123 _instantPanel->getInstant( tempVector );
2124 _performingOperation->reset();
2125 _performingOperation->setStartCommand( COPY );
2126 _performingOperation->setStartOperationInstantVector( tempVector );
2127 _performingOperation->setKeyNamesOperationElems( currentSelection );
2129 char theStartCommand = _performingOperation->getStartCommand();
2130 if ( theStartCommand == COPY )
2132 //JCP 20-10-08 Undo redo implementation
2134 //JCP 20-10-08 Undo redo implementation
2135 std::vector<int> tempVector;
2136 _instantPanel->getInstant( tempVector );
2137 _performingOperation->setEndOperationInstantVector ( tempVector );
2138 std::vector<std::string> elems = _performingOperation->getKeyNamesOperationElems();
2139 int i,size = elems.size();
2140 for( i=0; i<size; i++ )
2142 createMirrorContourOf( elems[i], tempVector, i>0 );
2146 //deleteContour( _refName );
2151 void wxContourMainFrame::showAxis(bool show)
2153 _theViewPanel->SetVisibleAxis(show);
2154 _theViewPanel->Refresh();
2158 void wxContourMainFrame::onRigidPressed(){
2159 std::vector<std::string> currentSelection = _theViewPanel->getSelectedObjects();
2160 int elementsSelected = currentSelection.size();
2162 if ( elementsSelected >= 1 ){
2163 //JCP 20-10-08 Undo redo implementation
2165 //JCP 20-10-08 Undo redo implementation
2167 std::vector<int> tempVector;
2168 _instantPanel->getInstant( tempVector );
2169 Instant instant(&tempVector);
2171 int i , size=currentSelection.size();
2172 for ( i=0 ; i<size ; i++ )
2174 kernelManager->changeContourOfManager(currentSelection[i], &instant);
2179 void wxContourMainFrame::onWidthOfContour(double width){
2181 _theViewPanel->removeSceneContours();
2182 _theViewPanel->SetWidthContour(width);
2184 //_theViewPanel->getSceneManager()->SetWidthContour( width );
2189 int wxContourMainFrame::getColorWindow()
2193 vtkImageData * img = getImageData();
2194 img->GetScalarRange(range);
2196 std::cout<<"Val 1: "<<range[0]<<" Val 2: "<<range[1]<<std::endl;
2198 return (int)range[1];
2200 return _theViewPanel->getColorWindow();
2203 int wxContourMainFrame::getWindowLevel()
2207 vtkImageData * img = getImageData();
2208 img->GetScalarRange(range);
2210 std::cout<<"Val 1: "<<range[0]<<" Val 2: "<<range[1]<<std::endl;
2212 return (int)range[1];
2214 return _theViewPanel->getWindowLevel();
2217 void wxContourMainFrame::onBrigthnessColorWindowLevel(int colorwindow,int windowlevel)
2219 _theViewPanel->onBrigthnessColorWindowLevel(colorwindow, windowlevel);
2223 void wxContourMainFrame::onInterpolation(bool interpolate)
2225 _theViewPanel->onInterpolation(interpolate);
2229 void wxContourMainFrame::onBeforeAfterContour(bool before,bool after)
2231 _theViewPanel->onBeforeAfterContour(before,after);
2235 void wxContourMainFrame::onJumpSlice(int step, int shift)
2237 std::vector<int> tempVector;
2238 _instantPanel->getInstant( tempVector );
2240 int pos = tempVector[1];
2241 int maxZ = interfMainPanel::getInstance()->GetImageDataSizeZ();
2242 pos=(pos/ss)*ss+step+shift;
2243 if ((pos>=0) && (pos<maxZ))
2246 _instantPanel->setInstant( tempVector );
2251 void wxContourMainFrame::onShowTextContour(bool show)
2253 _theViewPanel->onShowTextContour(show);
2257 void wxContourMainFrame::onChangeInstant(std::string name,int actual)
2259 _instantPanel->setConceptValue( name, actual );
2262 void wxContourMainFrame::resetAppend()
2264 kernelManager->resetAppend();
2267 void wxContourMainFrame::onSpreadAdd()
2269 std::vector<double> vecX;
2270 std::vector<double> vecY;
2271 std::vector<double> vecZ;
2272 _theViewPanel->GetPointsOfActualContour(&vecX , &vecY , &vecZ );
2273 std::vector<int> tempVector;
2274 _instantPanel->getInstant( tempVector );
2275 std::string val = kernelManager->onSpreadAdd(&vecX , &vecY , &vecZ, tempVector);
2276 interfMainPanel::getInstance()->appendStringSpread(val);
2280 void wxContourMainFrame::onSpreadAddAll()
2283 std::vector<int> tempVector;
2284 _instantPanel->getInstant( tempVector );
2287 maxZ = interfMainPanel::getInstance()->GetImageDataSizeZ();
2289 int sizeLstContourThings;
2290 for ( z=minZ ; z<=maxZ ; z++ )
2293 Instant instant(&tempVector);
2294 std::vector<ContourThing**> lstContourThings = kernelManager->getOutlinesAtInstant( &instant );
2295 sizeLstContourThings = lstContourThings.size();
2296 if (sizeLstContourThings>=1)
2298 std::vector<double> vecX;
2299 std::vector<double> vecY;
2300 std::vector<double> vecZ;
2301 ContourThing **contourthing = lstContourThings[0];
2302 manualBaseModel *cModel = (*contourthing)->getModel();
2303 int i,size = cModel->GetNumberOfPointsSpline();
2305 for (i=0; i<size; i++)
2307 cModel->GetSpline_i_Point(i, &x, &y, &z);
2312 std::string val = kernelManager->onSpreadAdd(&vecX , &vecY , &vecZ, tempVector);
2313 interfMainPanel::getInstance()->appendStringSpread(val);
2314 }// if sizeLstContourThings
2319 void wxContourMainFrame::onSpreadGo(int type)
2321 //JCP 20-10-08 Undo redo implementation
2323 //JCP 20-10-08 Undo redo implementation
2325 std::vector<double> vecCtrlPointX;
2326 std::vector<double> vecCtrlPointY;
2327 std::vector<double> vecCtrlPointZ;
2331 std::vector<int> tempVector;
2332 _instantPanel->getInstant( tempVector );
2335 kernelManager->getMaxMinZ(&minZ,&maxZ);
2336 //JSTG_16-07-08_----------------------------------------------------------------
2337 //_contourPropagation->setInterpolationNumber(maxZ-minZ+1);
2338 kernelManager->CalculeSplinePropagation();
2340 double totalZ = maxZ-minZ+1;
2343 //--------------------------------------------------------------------
2344 for ( z=(int)minZ ; z<=(int)maxZ ; z++ )
2346 porcent = 100.0* (z-minZ)/totalZ;
2347 int numero = (int)(z-minZ+1)/(int)totalZ;
2348 std::string stringtemp = " "+kernelManager->intToString(porcent)+"% "+kernelManager->intToString(numero)+" "+kernelManager->intToString(z);
2350 interfMainPanel::getInstance()->setStringSpread(stringtemp);
2352 int typeofcontour = 1;
2353 std::string theName;
2354 manualBaseModel* manModelContour = kernelManager->GetPoints(z, type, &vecCtrlPointX,&vecCtrlPointY,&vecCtrlPointZ, theName,typeofcontour, tempVector);
2356 if( manModelContour!=NULL ){
2357 double spc[3];//Si no hay imagen pero hay contornos que spacing se pone por default
2358 this->_theViewPanel->getSpacing(spc);
2359 //Adding the manualContourControler to interface objects structure
2360 //Adding the manualViewContour to interface objects structure
2361 //_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.
2362 _theViewPanel->configureViewControlTo( theName, manModelContour,spc,typeofcontour ) ;
2367 int numero = (int)(z-minZ+1)/(int)totalZ;
2368 std::string stringtemp = " "+kernelManager->intToString(porcent)+"% "+kernelManager->intToString(numero)+" "+kernelManager->intToString(z);
2370 interfMainPanel::getInstance()->setStringSpread(stringtemp);
2372 //RefreshInterface();
2375 void wxContourMainFrame::getInstantVector(std::vector<int>& tempVector)
2377 _instantPanel->getInstant( tempVector );
2380 std::vector<std::string> wxContourMainFrame::getOutlinesName(int slide)
2382 std::vector<int> tempVector;
2383 _instantPanel->getInstant(tempVector);
2384 //Asignation of slide number should be different ex by name
2385 tempVector[1]=slide;
2386 return kernelManager->getOutlinesNameAtInstant(tempVector);
2390 void wxContourMainFrame::SetScalarRange(int grayRangeMin, int grayRangeMax)
2392 _contourextractdata->SetScalarRange(grayRangeMin,grayRangeMax);
2396 void wxContourMainFrame::onInformationContourLabels(int typeContourGroup,int selection,int minimumZ,int maximumZ,int grayRangeMin, int grayRangeMax)
2399 wxString tempString;
2400 int maxContourGroup = 0;
2402 _contourextractdata ->SetTypeOperation( typeContourGroup % 3 );
2404 std::vector<manualBaseModel*> lstManConMod;
2405 std::vector<manualBaseModel*> lstManConModTmp;
2406 std::vector<manualBaseModel*> lstManConModExp;
2407 std::vector<double> pLstValue;
2408 std::vector<double> pLstValuePosX;
2409 std::vector<double> pLstValuePosY;
2410 std::vector<double> pLstValuePosZ;
2413 int resultGrayRangeCount;
2416 double resultAverage;
2417 double resultStandardeviation;
2419 std::vector<int> tempVector;
2420 _instantPanel->getInstant( tempVector );
2423 int ii,sizeLstContourThings;
2432 if (selection==0 ) // actual slice
2434 int actualSlice = tempVector[1];
2437 } else { // slice range
2443 totalZ = maxZ-minZ+1;
2445 _contourextractdata->InitVolumeStatistics();
2448 for ( z=minZ ; z<=maxZ ; z++ )
2451 porcent = 100.0* (z-minZ)/totalZ;
2452 tmpString.Printf(_T(" %d %c %d/%d %d"), (int)porcent , 37 , z-minZ+1, (int)totalZ ,z);
2454 interfMainPanel::getInstance()->setStringInfoPanel(tmpString);
2455 //_staticTextInformation->SetLabel(tmpString);
2457 //Extraction data from contours of each slice
2458 _contourextractdata->SetZtoBeAnalys(z);
2461 Instant instant(&tempVector);
2462 std::vector<ContourThing**> lstContourThings = kernelManager->getOutlinesAtInstant( &instant );
2463 sizeLstContourThings = lstContourThings.size();
2465 lstManConMod.clear();
2466 for (ii=0 ; ii<sizeLstContourThings ; ii++)
2468 ContourThing **contourthing = lstContourThings[ii];
2469 lstManConMod.push_back( (*contourthing)->getModel() );
2472 lstManConModExp = kernelManager->ExploseEachModel( lstManConMod );
2474 tempString.Printf(_T("%d - %d"),z, sizeLstContourThings);
2475 interfMainPanel::getInstance()->setRowLabelInfoPanel(z, tempString);
2476 //_grid->SetRowLabelValue(z, tempString );
2478 int iContourGroup,sizeContourGroup;
2479 if (typeContourGroup==3) // contour separete
2481 sizeContourGroup=lstManConModExp.size();
2482 if ( maxContourGroup<sizeContourGroup )
2484 maxContourGroup=sizeContourGroup;
2486 } else { // contour AND OR XOR
2493 for( iContourGroup=0 ; iContourGroup<sizeContourGroup ; iContourGroup++ ){
2494 lstManConModTmp.clear();
2498 if (typeContourGroup==3) // contour separete
2500 lstManConModTmp.push_back( lstManConModExp[iContourGroup]);
2501 } else { // contour AND OR XOR
2502 lstManConModTmp = lstManConModExp;
2505 _contourextractdata->SetLstManualContourModel( lstManConModTmp );
2506 _contourextractdata->SetScalarRange(grayRangeMin,grayRangeMax);
2509 pLstValuePosX.clear();
2510 pLstValuePosY.clear();
2511 pLstValuePosZ.clear();
2515 _contourextractdata->GetValuesInsideCrown( &numberOfPixels,
2521 resultSize=numberOfPixels;
2522 // Statistics of each slice.
2523 _contourextractdata->Statistics( &pLstValue,
2526 &resultGrayRangeCount,
2531 &resultStandardeviation);
2533 if (interfMainPanel::getInstance()->getNumberColsInformationPanel()<_numberOfVariablesStatistics*(iContourGroup+1) )
2535 interfMainPanel::getInstance()->appendColsInformationPanel(_numberOfVariablesStatistics);
2538 tmpIntA=_numberOfVariablesStatistics*iContourGroup ;
2540 tempString.Printf(_T("%d"),numberOfPixels);
2542 interfMainPanel::getInstance()->setCellValueInfoPanel(z, tmpIntA, tempString);
2544 tempString.Printf(_T("%d"),resultGrayRangeCount);
2545 interfMainPanel::getInstance()->setCellValueInfoPanel(z, tmpIntA+1, tempString);
2547 tempString.Printf(_T("%f"),resultMin);
2548 interfMainPanel::getInstance()->setCellValueInfoPanel(z, tmpIntA+2, tempString);
2550 tempString.Printf(_T("%f"),resultMax);
2551 interfMainPanel::getInstance()->setCellValueInfoPanel(z, tmpIntA+3, tempString);
2553 tempString.Printf(_T("%f"),resultAverage);
2554 interfMainPanel::getInstance()->setCellValueInfoPanel(z, tmpIntA+4, tempString);
2556 tempString.Printf(_T("%f"),resultStandardeviation);
2557 interfMainPanel::getInstance()->setCellValueInfoPanel(z, tmpIntA+5, tempString);
2560 } // for iContourGroup
2563 // Print Volume Statistics
2566 int vol_rCountRange;
2568 double vol_minValue;
2569 double vol_maxValue;
2571 double vol_standardeviation;
2573 if (selection!=0 ) // actual slice
2576 _contourextractdata->GetVolumeStatistics(&vol_rCountRange, &vol_rsize,
2577 &vol_minValue, &vol_maxValue,
2578 &vol_average, &vol_standardeviation);
2580 interfMainPanel::getInstance()->setRowLabelInfoPanel(maxZ+2, _T("Total:"));
2582 tempString.Printf(_T("%d"),vol_rsize);
2583 interfMainPanel::getInstance()->setCellValueInfoPanel(maxZ+2, 0, tempString);
2585 tempString.Printf(_T("%d"),vol_rCountRange);
2586 interfMainPanel::getInstance()->setCellValueInfoPanel(maxZ+2, 1, tempString);
2588 tempString.Printf(_T("%f"),vol_minValue);
2589 interfMainPanel::getInstance()->setCellValueInfoPanel(maxZ+2, 2, tempString);
2591 tempString.Printf(_T("%f"),vol_maxValue);
2592 interfMainPanel::getInstance()->setCellValueInfoPanel(maxZ+2, 3, tempString);
2594 tempString.Printf(_T("%f"),vol_average);
2595 interfMainPanel::getInstance()->setCellValueInfoPanel(maxZ+2, 4, tempString);
2597 tempString.Printf(_T("%f"),vol_standardeviation);
2598 interfMainPanel::getInstance()->setCellValueInfoPanel(maxZ+2, 5, tempString);
2600 //-----------------------------------------
2603 wxString tmpTitleString;
2605 for ( iTitleGroup=0 ; iTitleGroup<maxContourGroup ; iTitleGroup++ )
2607 tmpIntB =_numberOfVariablesStatistics*iTitleGroup;
2608 tmpTitleString.Printf(_T("%d-Size Data"),iTitleGroup);
2609 interfMainPanel::getInstance()->setColLableInfoPanel(tmpIntB + 0, tmpTitleString);
2611 interfMainPanel::getInstance()->setColLableInfoPanel(tmpIntB + 0, tmpTitleString );
2612 interfMainPanel::getInstance()->setColLableInfoPanel( tmpIntB + 1, _T("Size Range") );
2613 interfMainPanel::getInstance()->setColLableInfoPanel( tmpIntB + 2, _T("Min") );
2614 interfMainPanel::getInstance()->setColLableInfoPanel( tmpIntB + 3, _T("Max") );
2615 interfMainPanel::getInstance()->setColLableInfoPanel( tmpIntB + 4, _T("Average") );
2616 interfMainPanel::getInstance()->setColLableInfoPanel( tmpIntB + 5, _T("St.Dev.") );
2617 interfMainPanel::getInstance()->setColLableInfoPanel( tmpIntB + 6, _T(" ") );
2619 interfMainPanel::getInstance()->setStringInfoPanel( _T("") );
2623 void wxContourMainFrame::onSaveResults(std::string directory,std::string namefile, std::string filename,
2624 int typeContourGroup, int selection, int minZ, int maxZ, bool XYZValues, bool contourImage, bool statistics)
2628 SaveValuesXYZ( directory , namefile, typeContourGroup );
2633 vtkImageData * mask;
2634 vtkImageData * value;
2635 this->getMaskValue(&mask, &value, typeContourGroup,selection,minZ,maxZ);
2636 this->SaveImageResult( directory , namefile, mask, value);
2641 std::ostringstream name;
2642 name << filename << ".xls";
2645 FILE *pFile=fopen(name.str().c_str(),"w+");
2651 // int sizeZ = _theViewPanel->GetImageDataSizeZ();
2652 // int maxY=sizeZ+2;
2654 maxX= interfMainPanel::getInstance()->getNumberColsInformationPanel();//this->_grid->GetNumberCols();
2657 int iTitle,sizeTitle = (maxX / _numberOfVariablesStatistics);
2658 for ( iTitle=0; iTitle<sizeTitle ; iTitle++)
2660 // fprintf(pFile,"-- \t %d-Size \t SizeRange \t Min \t Max \t Ave \t StDv \t" , iTitle,tmpString.c_str() );
2661 fprintf(pFile,"slice\t %d-Size \t SizeRange \t Min \t Max \t Ave \t StDv \t" , iTitle );
2663 fprintf(pFile,"\n\n" );
2667 if (selection==0 ) // actual slice
2669 std::vector<int> tempVector;
2670 _instantPanel->getInstant( tempVector );
2671 int actualSlice = tempVector[1];
2677 for ( j=minZ; j<=maxZ ; j++)
2679 fprintf(pFile,"%d\t" , j );
2680 for (i=0 ; i<maxX ; i++){
2681 tmpString = interfMainPanel::getInstance()->getCellValue(j, i);//_grid->GetCellValue( j , i );
2682 fprintf(pFile,"%s\t" , (const char *)(tmpString.mb_str()) );
2684 fprintf(pFile,"\n" );
2688 // Total of stadistics.....
2691 fprintf(pFile,"\n Total:\t" );
2692 for (i=0 ; i<maxX ; i++){
2693 tmpString = interfMainPanel::getInstance()->getCellValue(maxZ+2, i);//_grid->GetCellValue( maxZ+2 , i );
2694 fprintf(pFile,"%s\t" , (const char *)(tmpString.mb_str()) );
2696 fprintf(pFile,"\n" );
2704 void wxContourMainFrame::SaveValuesXYZ(std::string directory,std::string namefile,int typeContourGroup)
2708 //int typeContourGroup = this->_radiolstboxContourGroup->GetSelection();
2709 _contourextractdata ->SetTypeOperation( typeContourGroup % 3 );
2711 std::vector<manualBaseModel*> lstManConMod;
2712 std::vector<manualBaseModel*> lstManConModTmp;
2713 std::vector<manualBaseModel*> lstManConModExp;
2714 std::vector<double> pLstValue;
2715 std::vector<double> pLstValuePosX;
2716 std::vector<double> pLstValuePosY;
2717 std::vector<double> pLstValuePosZ;
2719 std::vector<int> tempVector;
2720 _instantPanel->getInstant( tempVector );
2722 int sizeZ = _theViewPanel->getSceneManager()->GetImageDataSizeZ();
2724 int ii,sizeLstContourThings;
2731 minZ = 0;// _mbarrange->GetStart();
2732 maxZ = sizeZ;//_mbarrange->GetEnd();
2733 totalZ = maxZ-minZ+1;
2737 for ( z=0 ; z<sizeZ ; z++)
2740 porcent = 100.0* (z-minZ)/totalZ;
2742 tmpString.Printf(_T("Saving Values"));
2743 tmpString.Printf(_T(" %d %c %d/%d %d"), (int)porcent , 37 , z-minZ+1, (int)totalZ ,z);
2744 interfMainPanel::getInstance()->setStringInfoPanel(tmpString);
2745 //_staticTextInformation->SetLabel(tmpString);
2748 //Extraction data from contours of each slice
2749 _contourextractdata->SetZtoBeAnalys( z);
2752 Instant instant(&tempVector);
2753 std::vector<ContourThing**> lstContourThings = kernelManager->getOutlinesAtInstant(&instant);//this->_modelManager->getOutlinesAtInstant( &instant );
2754 sizeLstContourThings = lstContourThings.size();
2756 lstManConMod.clear();
2757 for (ii=0 ; ii<sizeLstContourThings ; ii++)
2759 ContourThing **contourthing = lstContourThings[ii];
2760 lstManConMod.push_back( (*contourthing)->getModel() );
2762 lstManConModExp = kernelManager->ExploseEachModel( lstManConMod );
2767 int iContourGroup,sizeContourGroup;
2768 if (typeContourGroup==3) // contour separete
2770 sizeContourGroup=lstManConModExp.size();
2771 } else { // contour AND OR XOR
2775 for( iContourGroup=0 ; iContourGroup<sizeContourGroup ; iContourGroup++ ){
2776 lstManConModTmp.clear();
2777 if (typeContourGroup==3) // contour separete
2779 lstManConModTmp.push_back( lstManConModExp[iContourGroup]);
2780 } else { // contour AND OR XOR
2781 lstManConModTmp = lstManConModExp;
2784 _contourextractdata->SetLstManualContourModel( lstManConModTmp );
2787 pLstValuePosX.clear();
2788 pLstValuePosY.clear();
2789 pLstValuePosZ.clear();
2791 _contourextractdata->GetValuesInsideCrown( &numberOfPixels,
2797 std::string temp = directory + "/" + namefile + "-slice";
2798 temp = temp + kernelManager->intToString(z) + "-cont" + kernelManager->intToString(iContourGroup);
2799 temp = temp + ".txt";
2801 // LG 14/01/09 : using crea
2802 wxString filename = crea::std2wx(temp);
2803 /*filename.Printf(_T("%s"),directory.c_str());
2804 filename.append(_T("\\"));
2805 filename.append(_T("%s"),namefile.c_str());
2806 filename.append(_T("-slice"));
2807 filename.append(_T("%d"),z);
2808 filename.append(_T("-cont"));
2809 filename.append(_T("%d"),iContourGroup);
2810 filename.append(_T(".txt"));*/
2811 // filename.Printf(temp.c_str());
2815 FILE *pFile=fopen((const char *)filename.mb_str(),"w+");
2816 fprintf(pFile,"value \t x \t y \t z\n" );
2817 int iLstValue,sizeLstValue=pLstValue.size();
2818 for (iLstValue=0 ; iLstValue<sizeLstValue ; iLstValue++ )
2820 fprintf(pFile,"%f\t %f\t %f\t %f\n", (float)pLstValue[iLstValue] , (float)pLstValuePosX[iLstValue], (float)pLstValuePosY[iLstValue], (float)z );
2823 } // for iContourGroup
2825 interfMainPanel::getInstance()->setStringInfoPanel(_T(""));
2826 //_staticTextInformation->SetLabel( _T("") );
2830 void wxContourMainFrame::getMaskValue(vtkImageData ** mask,vtkImageData ** value,int typeContourGroup, int selection, int minZ, int maxZ){
2833 //int typeContourGroup = this->_radiolstboxContourGroup->GetSelection();
2834 if (typeContourGroup==3)
2838 _contourextractdata ->SetTypeOperation( typeContourGroup % 3 );
2840 std::vector<manualBaseModel*> lstManConMod;
2841 std::vector<manualBaseModel*> lstManConModTmp;
2842 std::vector<manualBaseModel*> lstManConModExp;
2844 std::vector<int> tempVector;
2845 _instantPanel->getInstant( tempVector );
2847 vtkImageData *imagedata = _theViewPanel->getImageData();
2849 imagedata->GetExtent(ext);
2850 int sizeZimage = ext[5]-ext[4]+1;
2852 int ii,sizeLstContourThings;
2860 if (selection==0 ) // actual slice
2862 int actualSlice = tempVector[1];
2870 // cleanning image before range
2871 for (z=0; z<minZ; z++){
2872 _contourextractdata->ResetImageResult(z);
2874 // cleanning image after range
2875 for (z=maxZ+1; z<sizeZimage; z++){
2876 _contourextractdata->ResetImageResult(z);
2881 for ( z=minZ ; z<=maxZ ; z++)
2884 porcent = 100.0* (z-minZ)/totalZ;
2885 tmpString.Printf(_T("Saving Values"));
2886 tmpString.Printf(_T("%d %c %d/%d %d"), (int)porcent , 37 , z-minZ+1, (int)totalZ ,z);
2887 interfMainPanel::getInstance()->setStringInfoPanel(tmpString);
2889 //Extraction data from contours of each slice
2890 _contourextractdata->SetZtoBeAnalys( z);
2893 Instant instant(&tempVector);
2894 std::vector<ContourThing**> lstContourThings = kernelManager->getOutlinesAtInstant( &instant );
2895 sizeLstContourThings = lstContourThings.size();
2897 lstManConMod.clear();
2898 for (ii=0 ; ii<sizeLstContourThings ; ii++)
2900 ContourThing **contourthing = lstContourThings[ii];
2901 lstManConMod.push_back( (*contourthing)->getModel() );
2903 lstManConModExp = kernelManager->ExploseEachModel( lstManConMod );
2906 int iContourGroup,sizeContourGroup;
2907 if (typeContourGroup==3) // contour separete
2909 sizeContourGroup=lstManConModExp.size();
2910 } else { // contour AND OR XOR
2914 for( iContourGroup=0 ; iContourGroup<sizeContourGroup ; iContourGroup++ ){
2915 lstManConModTmp.clear();
2916 if (typeContourGroup==3) // contour separete
2918 lstManConModTmp.push_back( lstManConModExp[iContourGroup]);
2919 } else { // contour AND OR XOR
2920 lstManConModTmp = lstManConModExp;
2923 _contourextractdata->SetLstManualContourModel( lstManConModTmp );
2924 _contourextractdata->CalculateImageResult(); // with actual Z
2926 } // for iContourGroup
2929 (*value) = _contourextractdata->GetVtkImageValueResult();
2930 (*mask) = _contourextractdata->GetVtkImageMaskResult();
2934 std::string wxContourMainFrame::GetStringTypeImage( vtkImageData* image)
2936 std::string result="";
2937 if ( image->GetScalarType()==VTK_CHAR )
2940 } else if ( image->GetScalarType()==VTK_UNSIGNED_CHAR ){
2942 } else if ( image->GetScalarType()==VTK_FLOAT ){
2944 } else if ( image->GetScalarType()==VTK_DOUBLE ){
2946 } else if ( image->GetScalarType()==VTK_INT ){
2948 } else if ( image->GetScalarType()==VTK_UNSIGNED_INT ){
2950 } else if ( image->GetScalarType()==VTK_SHORT ){
2952 } else if ( image->GetScalarType()==VTK_UNSIGNED_SHORT ){
2954 } else if ( image->GetScalarType()==VTK_LONG ){
2956 } else if ( image->GetScalarType()==VTK_UNSIGNED_LONG ){
2962 void wxContourMainFrame::SaveImageResult(std::string directory,std::string namefile, vtkImageData* mask,vtkImageData* value)
2964 std::string stringType;
2966 kernelManager->GetSpacing(spc,0); // returns the spacing of the first image
2967 stringType = GetStringTypeImage(value);
2968 std::string temp = directory + "/" + namefile + "-image-Value-"+stringType+".mhd";
2970 wxString filename = crea::std2wx(temp);
2974 vtkImageChangeInformation *valueChInfo = vtkImageChangeInformation::New();
2975 //EED 2017-01-01 Migration VTK7
2976 #if VTK_MAJOR_VERSION <= 5
2977 valueChInfo->SetInput(value);
2979 valueChInfo->SetInputData(value);
2981 valueChInfo->SetSpacingScale(spc);
2982 valueChInfo->Update();
2983 vtkMetaImageWriter *writerValueImage = vtkMetaImageWriter::New( );
2985 //EED 2017-01-01 Migration VTK7
2986 #if VTK_MAJOR_VERSION <= 5
2987 writerValueImage->SetInput( valueChInfo->GetOutput() );
2989 writerValueImage->SetInputData( valueChInfo->GetOutput() );
2991 writerValueImage->SetFileName( (const char *)filename.mb_str() );
2992 writerValueImage->SetFileDimensionality( 3 );
2993 writerValueImage->SetCompression(false);
2994 writerValueImage->Write( );
2997 stringType = GetStringTypeImage(mask);
2998 temp = directory + "/" + namefile + "-image-Mask-"+stringType+".mhd";
3000 // LG 14/01/09 : using crea
3001 filename = crea::std2wx(temp);
3002 // filename.Printf(_T(temp.c_str()));
3005 vtkImageChangeInformation *maskChInfo = vtkImageChangeInformation::New();
3006 //EED 2017-01-01 Migration VTK7
3007 #if VTK_MAJOR_VERSION <= 5
3008 maskChInfo->SetInput(mask);
3010 maskChInfo->SetInputData(mask);
3012 maskChInfo->SetSpacingScale(spc);
3013 maskChInfo->Update();
3014 vtkMetaImageWriter *writerMaskImage = vtkMetaImageWriter::New( );
3016 //EED 2017-01-01 Migration VTK7
3017 #if VTK_MAJOR_VERSION <= 5
3018 writerMaskImage->SetInput( maskChInfo->GetOutput() );
3020 writerMaskImage->SetInputData( maskChInfo->GetOutput() );
3023 writerMaskImage->SetFileName( (const char *)filename.mb_str() );
3024 writerMaskImage->SetFileDimensionality( 3 );
3025 writerMaskImage->SetCompression(false);
3026 writerMaskImage->Write( );
3028 interfMainPanel::getInstance()->setStringInfoPanel( _T("") );
3034 void wxContourMainFrame::onChangeInstantInstantPanel(std::string name,int value, int minshow, int maxshow){
3035 if( name.compare( _theViewPanel->getVerticalConceptName() ) == 0){
3036 _theViewPanel->setActualVertical( value);
3038 else if( name.compare( _theViewPanel->getHorizontalConceptName() ) == 0|| _instantPanel->getIfConceptCheckedAt( name, 0 ) ) {
3039 _theViewPanel->setHorizontalConcept( name, minshow, maxshow, minshow, maxshow, value);
3045 void wxContourMainFrame::onSnakePressed(){
3046 std::vector<double> vecX;
3047 std::vector<double> vecY;
3048 std::vector<double> vecZ;
3049 _theViewPanel->GetPointsOfActualContour( &vecX , &vecY , &vecZ );
3051 if (vecX.size()!=0){
3052 std::vector<int> tempVector;
3053 _instantPanel->getInstant( tempVector );
3054 int i,size=vecZ.size();
3055 int actualSlice = tempVector[1];
3056 for ( i=0 ; i<size ; i++ )
3058 vecZ[i] = actualSlice;
3061 wxDialog* dialog = new wxDialog(this, -1, wxString(_T("Snake")));
3062 wxPanel* panel = new wxPanel(dialog,-1);
3063 // wxStaticText* sttext = new wxStaticText(panel, -1, wxString(_T("Panel para snake")));
3064 new wxStaticText(panel, -1, wxString(_T("Panel para snake")));
3065 dialog->ShowModal();
3070 void wxContourMainFrame::saveFileWithContoursAutomatique()
3072 std::string filename = kernelManager->getCurrentFileName();
3073 if(filename.compare("")!=0){
3074 saveFileWithContours(filename);
3080 void wxContourMainFrame::ShowToolsPanel(bool show)
3082 _pannew->Show(show);
3085 void wxContourMainFrame::SetContourGroup(int contourGroup)
3087 _contourGroup = contourGroup;
3090 wxPanel *wxContourMainFrame::getMaskImageViewPanel(wxWindow *parent)
3092 if (_viewMaskImagePanel==NULL)
3094 _contourextractdata = new ContourExtractData(true);
3095 _contourextractdata->SetImage( _theViewPanel->getImageData() );
3097 // _theViewPanel->getImageData()->GetScalarRange(range);
3098 //int min = (int)floor (range[0]);
3099 //int max = (int)ceil (range[1]);
3105 _viewMaskImagePanel = new ThresholdImageViewPanel( parent, -1, -1 , -1,-1, 0);
3106 _viewMaskImage = new ThresholdImageView();
3107 _viewMaskImage->SetImage( _contourextractdata->GetVtkImageMaskResult() );
3108 _viewMaskImage->SetminMaxValue( min, max);
3109 _viewMaskImage->SetBaseColor( 0,0,1 );
3112 std::vector<int> colorbarposition;
3113 colorbarposition.push_back( -999 );
3114 colorbarposition.push_back( -999 );
3115 _viewMaskImage->SetColorBarPosition( colorbarposition );
3117 _viewMaskImage->SetSpcBase( _theViewPanel->getImageData()->GetSpacing() );
3118 _viewMaskImage->SetNewSpacingLayer( _theViewPanel->getImageData()->GetSpacing() );
3120 _viewMaskImagePanel->SetThresholdImageView( _viewMaskImage );
3121 _viewMaskImage->SetwxVtkBaseView( _theViewPanel->getWxVtkBaseView() );
3122 _viewMaskImage->onThresholdChangeOpacity( 25 );
3124 return _viewMaskImagePanel;
3128 wxPanel *wxContourMainFrame::getColorLayerImageViewPanel(wxWindow *parent)
3130 if (_viewColorLayerImagePanel==NULL)
3133 _theViewPanel->getImageData()->GetScalarRange(range);
3134 int min = (int)floor (range[0]);
3135 int max = (int)ceil (range[1]);
3136 _viewColorLayerImagePanel = new ColorLayerImageViewPanel( parent, min, max, 100, 1);
3137 _viewColorLayerImagePanel->GetColorLayerImageViewManager()->SetwxVtkBaseView( 0 , _theViewPanel->getWxVtkBaseView() );
3138 // std::vector<double> range = bbGetInputlstRangeForColorBar();
3139 // clivp->GetColorLayerImageViewManager()->SetRangeForColorBar( range );
3140 std::vector<int> colorbarposition;
3141 colorbarposition.push_back( 50 );
3142 colorbarposition.push_back( 105 );
3143 _viewColorLayerImagePanel->GetColorLayerImageViewManager()->SetColorBarPosition( colorbarposition );
3144 // std::vector<double> base_color;
3145 // _viewColorLayerImagePanel->GetColorLayerImageViewManager()->SetBaseColors( base_color );
3146 // std::vector<double> grey_level_boundaries;
3147 // clivp->GetColorLayerImageViewManager()->SetGreyLevelBoundaries( grey_level_boundaries );
3148 std::vector<double> transparence_level_boundaries;
3149 transparence_level_boundaries.push_back(0);
3150 _viewColorLayerImagePanel->GetColorLayerImageViewManager()->SetBaseTransparence( transparence_level_boundaries );
3151 _viewColorLayerImagePanel->GetColorLayerImageViewManager()->SetPlainOrGradientColor( false );
3152 // _viewColorLayerImagePanel->SetFittingMode( 3 );
3154 return _viewColorLayerImagePanel;
3157 void wxContourMainFrame::SetColorLayerImage(vtkImageData* img)
3159 if (_viewColorLayerImagePanel!=NULL)
3163 _viewColorLayerImagePanel->SetActive(true);
3164 _viewColorLayerImagePanel->SetImage( img );
3165 // RefreshInterface();
3167 } // _viewColorLayerImagePanel
3170 wxPanel *wxContourMainFrame::getThresholdImageViewPanel(wxWindow *parent)
3172 if (_viewThresholdImagePanel==NULL)
3175 _theViewPanel->getImageData()->GetScalarRange(range);
3176 int min = (int)floor (range[0]);
3177 int max = (int)ceil (range[1]);
3178 int start = (max+min)/2 - (max-min)*0.25;
3179 int end = (max+min)/2 + (max-min)*0.25;
3180 _viewThresholdImagePanel = new ThresholdImageViewPanel( parent, min, max, start, end , 1);
3181 _viewThresholdImage = new ThresholdImageView();
3182 _viewThresholdImage->SetminMaxValue(start,end);
3183 // _viewThresholdImage->SetminMaxValue(range[0],range[1]);
3184 _viewThresholdImage->SetImage( _theViewPanel->getImageData() );
3185 std::vector<int> colorbarposition;
3186 colorbarposition.push_back( 10 );
3187 colorbarposition.push_back( 105 );
3188 _viewThresholdImage->SetColorBarPosition( colorbarposition );
3190 _viewThresholdImage->SetSpcBase( _theViewPanel->getImageData()->GetSpacing() );
3191 _viewThresholdImage->SetNewSpacingLayer( _theViewPanel->getImageData()->GetSpacing() );
3193 _viewThresholdImage->SetBaseColor( 1,0,0 );
3194 _viewThresholdImagePanel->SetThresholdImageView( _viewThresholdImage );
3195 _viewThresholdImage->SetwxVtkBaseView( _theViewPanel->getWxVtkBaseView() );
3196 _viewThresholdImage->onThresholdChangeOpacity( 25 );
3199 return _viewThresholdImagePanel;
3202 //CMRU 17-08-09-----------------------------------------------------------------------------------------------
3203 int wxContourMainFrame::getType ()
3206 std::vector<std::string> currentSelection = _theViewPanel->getSelectedObjects();
3208 if(!currentSelection.empty())
3210 std::string cloneName = currentSelection [0];
3211 manualBaseModel * manualModel = kernelManager->getOutlineByKeyName(cloneName);
3212 tipo = manualModel-> GetTypeModel();
3217 double wxContourMainFrame::getContourSizeInPixels()
3219 double contourSize = 0;
3221 std::vector<std::string> currentSelection = _theViewPanel->getSelectedObjects(); if(!currentSelection.empty())
3222 if(!currentSelection.empty())
3224 std::string cloneName = currentSelection [0];
3226 manualBaseModel * manualModel = kernelManager->getOutlineByKeyName(cloneName);//_modelManager->getOutlineByKeyName( cloneName )->getModel();
3229 // contourSize = manualModel->GetPathSize();
3234 contourSize = manualModel->GetPathSize( spc );
3239 manualBaseModel * wxContourMainFrame::getContour ()
3241 std::vector<std::string> currentSelection = _theViewPanel->getSelectedObjects();
3243 if(!currentSelection.empty())
3245 std::string cloneName = currentSelection [0];
3246 manualBaseModel * manualModel = kernelManager->getOutlineByKeyName(cloneName);//_modelManager->getOutlineByKeyName( cloneName )->getModel();
3251 void wxContourMainFrame::onPrintLabel (wxString label, manualBaseModel* manualModel)
3253 std::string labelAscii(label.ToAscii());
3254 int pos = labelAscii.find(" ");
3258 for (j=0 ; pos != string::npos;j++)
3260 labelAscii.replace( pos, 1, "_" );
3261 pos= labelAscii.find(" ");
3264 manualModel -> SetLabel(labelAscii);
3266 void wxContourMainFrame::onInsertCalculation(manualBaseModel* manualModel)
3269 // double sizeInPixel = manualModel ->GetPathSize( );
3274 double sizeInPixel = manualModel ->GetPathSize( spc );
3276 double onePixelRealSize = interfMainPanel::getInstance()->GetPixelValue();;
3277 double realContourSize = sizeInPixel*onePixelRealSize;
3278 manualModel ->SetRealSize(realContourSize);
3281 double wxContourMainFrame::onePixelSize( double value)
3283 return _onePixelSize = value;
3286 std::string wxContourMainFrame::GetFileLocation()
3288 return _fileLocation;
3291 void wxContourMainFrame::SetFileLocation(std::string newFileLocation)
3293 _fileLocation = newFileLocation;
3294 std::cout<<"GETFILELOCATION:"<<_fileLocation<<std::endl;
3297 kernelManager->setCurrentFileName(_fileLocation);
3299 //------------------------------------------------------------------------------------------------------------
3308 void wxContourMainFrame::FlipSelectedContours(int flipDirection)
3311 (std::vector<std::string>)_theViewPanel->getSceneManager()->getSelectedObjects() ,
3317 void wxContourMainFrame::FlipActualSliceContours(int flipDirection)
3320 (std::vector<std::string>)_theViewPanel->getSceneManager()->GetlstContoursNameActualSlice() ,
3325 void wxContourMainFrame::FlipAllContours(int flipDirection)
3328 kernelManager->GetLstNameThings() ,
3333 void wxContourMainFrame::FlipLstOfContours(std::vector<std::string> lstNameThings, int flipDirection)
3336 getImageData()->GetExtent(ext);
3337 int sizeX = ext[1]-ext[0];
3338 int sizeY = ext[3]-ext[2];
3341 int i,sizeLstNameThings;
3342 int ii,sizeLstPoints;
3344 sizeLstNameThings = lstNameThings.size();
3345 for (i=0 ; i<sizeLstNameThings ; i++)
3347 manualBaseModel * manualModel = kernelManager->getOutlineByKeyName(lstNameThings[i]);
3348 if (flipDirection==0)
3350 manualModel->Transform_Ax_Plus_B(-1,sizeX,1,0 );
3352 manualModel->Transform_Ax_Plus_B(1,0,-1,sizeY );
3354 }// for i list of Things
3356 //-- Static Contours
3358 lstNameThings = kernelManager->GetLstNameThingsStatic();
3359 sizeLstNameThings = lstNameThings.size();
3360 for (i=0 ; i<sizeLstNameThings ; i++)
3362 manualBaseModel * manualModel = kernelManager->getOutlineByKeyName(lstNameThings[i]);
3363 if (flipDirection==0)
3365 manualModel->Transform_Ax_Plus_B(-1,sizeX,1,0 );
3367 manualModel->Transform_Ax_Plus_B(1,0,-1,sizeY );
3369 }// for i list of static things
3372 void wxContourMainFrame::FlipContours(int typeContourFlip, int flipDirection)
3376 if (typeContourFlip==0) //
3378 FlipSelectedContours(flipDirection);
3381 if (typeContourFlip==1) //
3383 FlipActualSliceContours(flipDirection);
3386 if (typeContourFlip==2) //
3388 FlipAllContours(flipDirection);
3393 void wxContourMainFrame::SetXY(int x, int y)
3395 _theViewPanel->SetXY(x,y);
3398 wxVtkBaseView* wxContourMainFrame::GetWxVtkBaseView()
3400 if (_theViewPanel!=NULL)
3402 return _theViewPanel->getWxVtkBaseView();;