1 /*# ---------------------------------------------------------------------
3 # Copyright (c) CREATIS (Centre de Recherche en Acquisition et Traitement de l'Image
5 # Authors : Eduardo Davila, Frederic Cervenansky, Claire Mouton
6 # Previous Authors : Laurent Guigues, Jean-Pierre Roux
7 # CreaTools website : www.creatis.insa-lyon.fr/site/fr/creatools_accueil
9 # This software is governed by the CeCILL-B license under French law and
10 # abiding by the rules of distribution of free software. You can use,
11 # modify and/ or redistribute the software under the terms of the CeCILL-B
12 # license as circulated by CEA, CNRS and INRIA at the following URL
13 # http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
14 # or in the file LICENSE.txt.
16 # As a counterpart to the access to the source code and rights to copy,
17 # modify and redistribute granted by the license, users are provided only
18 # with a limited warranty and the software's author, the holder of the
19 # economic rights, and the successive licensors have only limited
22 # The fact that you are presently reading this means that you have had
23 # knowledge of the CeCILL-B license and that you accept its terms.
24 # ------------------------------------------------------------------------ */
26 //----------------------------------------------------------------------------------------------------------------
27 // Class definition include
28 //----------------------------------------------------------------------------------------------------------------
29 #include "wxContourMainFrame.h"
33 //----------------------------------------------------------------------------------------------------------------
35 //----------------------------------------------------------------------------------------------------------------
38 #include "NameWrapper.h"
39 #include "wx/artprov.h"
40 #include "ConceptDataWrap.h"
46 //----------------------------------------------------------------------------------------------------------------
47 // Class implementation
48 //----------------------------------------------------------------------------------------------------------------
49 /** @file wxContourMainFrame.cxx */
51 //------------------------------------------------------------------------------------------------------------
52 // Constructors & Destructors
53 //------------------------------------------------------------------------------------------------------------
55 wxContourMainFrame* wxContourMainFrame:: instance = NULL;
56 char wxContourMainFrame::COPY = 'C';
58 wxContourMainFrame :: wxContourMainFrame(wxWindow* parent, wxWindowID id,const wxString& title,const wxPoint& pos,const wxSize& size,long style)
59 //: wxPanel(parent, id, title, pos, size, style)
60 //: wxWindow(parent, id, pos, size, style)
61 : wxPanel(parent, id, pos, size, style)
63 m_mgr.SetManagedWindow(this);
65 _creatingContoursActive = false;
67 // _modelManager = NULL;
69 // _buttonsBar = NULL;
71 // _drawToolsPanel = NULL;
72 // _operationsToolsPanel = NULL;
73 //_autoFormsPanel = NULL;
74 // _standardToolsPanel = NULL;
75 // _editionToolsPanel = NULL;
76 // _listViewPanel = NULL;
77 // _sceneManager = NULL;
78 //_actualInstant = NULL;
79 _numberOfVariablesStatistics= 6+1;
81 _refLineControl = NULL;
84 // _actorPresent = false;
86 // set up default notebook style
87 // m_notebook_style =wxAUI_NB_TAB_SPLIT | wxAUI_NB_TAB_EXTERNAL_MOVE | wxNO_BORDER;
88 // m_notebook_theme = 0;
89 //wxContour_ActionCommandsID a;
91 _contourextractdata = NULL;
92 _viewMaskImage = NULL;
93 _viewMaskImagePanel = NULL;
94 _viewThresholdImage = NULL;
95 _viewThresholdImagePanel = NULL;
96 _viewColorLayerImagePanel = NULL;
99 wxContourMainFrame::wxContourMainFrame(wxWindow* parent, wxWindowID id,const wxString& title,const wxPoint& pos,const wxSize& size,std::vector<vtkImageData*> images, long style,std::string datadir)
100 : wxPanel(parent, id, pos, size, style)
102 m_mgr.SetManagedWindow(this);
104 _creatingContoursActive = false;
105 _theViewPanel = NULL;
107 _instantPanel = NULL;
108 _refLineControl = NULL;
109 _refLineModel = NULL;
111 // _actorPresent = false;
112 _viewMaskImage = NULL;
113 _viewMaskImagePanel = NULL;
114 _viewThresholdImage = NULL;
115 _viewThresholdImagePanel = NULL;
116 _viewColorLayerImagePanel = NULL;
117 // set up default notebook style
118 m_notebook_style = wxAUI_NB_TAB_SPLIT | wxAUI_NB_TAB_EXTERNAL_MOVE | wxNO_BORDER;
119 m_notebook_theme = 0;
120 //wxContour_ActionCommandsID a;
121 _numberOfVariablesStatistics= 7;
125 _pannew = interfMainPanel::getInstance(this,datadir+"/data/Icons");//, eventHandler);
126 _performingOperation = new PerformingOperation();
127 if(images.size() > 0)
129 this->setVectImages(images);
131 _contourextractdata = NULL;
134 void wxContourMainFrame::setVectImages(std::vector<vtkImageData*> imgs)
137 #if defined(__GNUC__)
138 std::string str_home(getenv("HOME"));
139 #elif defined(_WIN32)
140 std::string str_home(getenv("USERPROFILE"));
142 std::string strCreaContourDataTmp = str_home + "/.creaContourDataTemp/";
143 std::vector<std::string> conceptNameVect;
144 std::vector<int> conceptSizeVect;
145 notebook = this->createNotebook();
146 kernelManager = new KernelManagerContour( imgs , _datadir+"/data/" , strCreaContourDataTmp );
147 _instantPanel = new wxInstantChooserPanel( notebook, "Instant Chooser", true, false, "c" );
148 _theViewPanel = new wxContourViewPanel( kernelManager->getSourceImage(), notebook );
149 //-------------------------------------------------------------
150 kernelManager->getConceptsInformation(conceptNameVect, conceptSizeVect);
151 _instantPanel->addConcepts(conceptNameVect, conceptSizeVect);
152 double val = _theViewPanel->getCurrentDeep();
153 _instantPanel->setConceptValue( "Axe Depth", (int)val );
154 //JCP _instantPanel->setConceptValue("time", num de imagenes);
155 ConceptDataWrap * data = _instantPanel->getConceptDataOf( "Axe Depth" );
156 //*******************changeInstant();
157 _theViewPanel->setVerticalConcept( "Axe Depth", data->getMinValue(), data->getMaxValue(), data->getMinShowedValue(), data->getMaxShowedValue(), data->getActualValue() );
158 this->configurePanels( );
162 wxContourMainFrame* wxContourMainFrame :: getInstance(wxWindow* parent, wxWindowID id,const wxString& title,const wxPoint& pos,const wxSize& size,std::vector<vtkImageData*> images, long style,std::string datadir )
164 if(instance == NULL){
165 instance = new wxContourMainFrame(parent, id, title, pos, size, images, style,datadir);
170 std::vector<vtkImageData*> wxContourMainFrame ::getVectImages()
172 return kernelManager->getVectImages();
175 wxContourMainFrame* wxContourMainFrame :: getInstance()
180 void wxContourMainFrame :: resetInstance()
185 wxContourMainFrame :: ~wxContourMainFrame()
187 delete _contourextractdata;
190 interfMainPanel::resetInstance();
191 delete kernelManager;
193 //_pannew->Destroy();
199 //El problema al cerrar la aplicacion puede estar asociado
200 //a que wxAUINotebook esta en la aplicacion
201 //principal (wxContourGUIExample)tambien
202 //EED???? delete _theViewPanel;
203 //EED???? delete _instantPanel;
204 //EED???? delete _buttonsBar;
205 //EED???? delete _actualInstant;
206 //EED???? delete _sceneManager;
210 //------------------------------------------------------------------------------------------------------------
211 // Creational and initialization methods using WxAui
212 //------------------------------------------------------------------------------------------------------------
214 wxAuiNotebook * wxContourMainFrame :: createNotebook()
216 wxSize client_size = GetClientSize();
217 wxAuiNotebook* noteBook = new wxAuiNotebook(this, -1, wxPoint(client_size.x, client_size.y), wxSize(430,200), m_notebook_style);
218 wxBitmap page_bmp = wxArtProvider::GetBitmap(wxART_NORMAL_FILE, wxART_OTHER, wxSize(16,16));
223 //------------------------------------------------------------------------------------------------------------
224 // Creational and initialization methods
225 //------------------------------------------------------------------------------------------------------------
226 bool wxContourMainFrame :: configurePanels( )
228 bool configured = _theViewPanel!=NULL;
230 configured &= _theViewPanel!=NULL;
231 if( _theViewPanel!=NULL )
233 notebook->AddPage( _theViewPanel, wxT(" View ") );
238 notebook->AddPage( _instantPanel, wxT("Instant Page") );
241 m_mgr.AddPane(notebook, wxAuiPaneInfo().Name(wxT("notebook_content")).CenterPane().PaneBorder(false));
243 SetMinSize(wxSize(300,300));
249 bool wxContourMainFrame::addNewPanel(wxPanel* panel)
251 bool configured = panel!=NULL;
252 configured &= panel!=NULL;
256 notebook->AddPage( panel, wxT(" Viewer "), true );
262 //------------------------------------------------------------------------------------------------------------
263 // Attributes getters and setters
264 //------------------------------------------------------------------------------------------------------------
268 void wxContourMainFrame :: setInstantChooserPanel( wxInstantChooserPanel * theInstantChooserPanel )
270 _instantPanel = theInstantChooserPanel;
273 // void wxContourMainFrame :: setButtonsBar( wxContour_ButtonsBar * theButtonsBar )
275 // _buttonsBar = theButtonsBar;
278 // void wxContourMainFrame :: setGrid( wxContour_Grid * theGridPanel )
280 // _gridPanel = theGridPanel;
283 // void wxContourMainFrame :: setDrawToolsPanel( wxContour_DrawToolsPanel * theDrawToolsPanel )
285 // _drawToolsPanel = theDrawToolsPanel;
288 // void wxContourMainFrame :: setOperationsToolsPanel( wxContour_OperationsToolsPanel * theOperationsToolsPanel )
290 // _operationsToolsPanel = theOperationsToolsPanel;
293 // void wxContourMainFrame :: setAutomaticFormsPanel( wxContour_AutomaticFormsToolsPanel * theAutoFormsPanel )
295 // _autoFormsPanel = theAutoFormsPanel;
298 // void wxContourMainFrame :: setStandardToolsPanel( wxContour_StandardToolsPanel * theStandardToolsPanel )
300 // _standardToolsPanel= theStandardToolsPanel;
303 // void wxContourMainFrame :: setEditionToolsPanel( wxContour_EdtionToolsPanel * theEditionToolsPanel )
305 // _editionToolsPanel = theEditionToolsPanel;
308 // void wxContourMainFrame :: setListViewPanel( wxContour_ListViewPanel * theListViewPanel )
310 // _listViewPanel = theListViewPanel;
315 void wxContourMainFrame::onCreateContourSpline( ){
317 //JCP 20-10-08 Undo redo implementation
319 //JCP 20-10-08 Undo redo implementation
324 void wxContourMainFrame::onCreateContourRectangle( )
326 //JCP 20-10-08 Undo redo implementation
328 //JCP 20-10-08 Undo redo implementation
332 void wxContourMainFrame::onCreateContourCircle( )
334 //JCP 20-10-08 Undo redo implementation
336 //JCP 20-10-08 Undo redo implementation
340 void wxContourMainFrame::onCreateContourLine( )
342 //JCP 20-10-08 Undo redo implementation
344 //JCP 20-10-08 Undo redo implementation
348 // RaC 09-09 --------------------------------------
349 void wxContourMainFrame::onCreateContourPoints( )
351 //JCP 20-10-08 Undo redo implementation
353 //JCP 20-10-08 Undo redo implementation
356 // RaC 09-09 --------------------------------------
358 // RaC 10-09 --------------------------------------
359 void wxContourMainFrame::onCreateContourPolygon( )
361 //JCP 20-10-08 Undo redo implementation
363 //JCP 20-10-08 Undo redo implementation
366 // RaC 10-09 --------------------------------------
368 //------------------------------------------------------------------------------------------------------------
370 void wxContourMainFrame :: onCreateContourBullEye(wxPanel* panel )
372 //Creating the manualBaseModel and including in the model
373 manualBaseModel * manModelContour = factoryManualContourModel(panel );
375 std::vector<int> instantVector;
376 _instantPanel->getInstant( instantVector );
377 std::string theName = kernelManager->createOutline(manModelContour, instantVector);
379 /*std::vector<int> instantVector;
380 _instantPanel->getInstant( instantVector );
382 theName= _modelManager->createOutline( manModelContour, instantVector );*/
383 bool addedModel = theName.compare("") != 0;//??
387 double spc[3];//Si no hay imagen pero hay contornos que spacing se pone por default
388 _theViewPanel->getSpacing(spc);
389 //Adding the manualContourControler to interface objects structure
390 //Adding the manualViewContour to interface objects structure
391 //_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.
392 _theViewPanel->getSceneManager()->configureViewControlTo( theName, manModelContour,spc , 4) ;
396 void wxContourMainFrame :: createContour( int typeContour )
398 //Creating the manualContourModel and including in the model
399 manualBaseModel * manModelContour = kernelManager->factoryManualContourModel(typeContour);
400 std::vector<int> instantVector;
401 _instantPanel->getInstant( instantVector );
402 std::string theName = kernelManager->createOutline(manModelContour, instantVector);
403 /*std::vector<int> instantVector;
404 _instantPanel->getInstant( instantVector );
406 theName= _modelManager->createOutline( manModelContour, instantVector );*/
407 bool addedModel = theName.compare("") != 0;//??
410 double spc[3];//Si no hay imagen pero hay contornos que spacing se pone por default
411 _theViewPanel->getSpacing(spc);
412 //Adding the manualContourControler to interface objects structure
413 //Adding the manualViewContour to interface objects structure
414 //_sceneManager->setControlActiveStateOfALL( false );//This call is being done here because if the ROI is created underneath the previously created ROIS will still be active.
415 _theViewPanel->getSceneManager()->configureViewControlTo( theName, manModelContour,spc , typeContour) ;
419 manualBaseModel * wxContourMainFrame::factoryManualContourModel(wxPanel* panel){
421 manualContourModelBullEye *manModelContourBullEye = new manualContourModelBullEye();
422 manualBaseModel *manModelContour=NULL;
423 manModelContour = manModelContourBullEye;
425 int iCrown,sizeCrowns,iSector,sizeSectors;
426 double radioA,radioB,ang,angDelta ;
427 sizeCrowns = ((PanelBullEyeOptions*)panel)->GetNumberOfCrowns();
428 for ( iCrown=0 ; iCrown<sizeCrowns ; iCrown++ )
430 sizeSectors = ((PanelBullEyeOptions*)panel)->GetNumberOfSections(iCrown);
431 radioB = ((PanelBullEyeOptions*)panel)->GetRadioOfCrown(iCrown);
432 if (iCrown==sizeCrowns-1)
436 radioA = ((PanelBullEyeOptions*)panel)->GetRadioOfCrown(iCrown+1);
440 for ( iSector=0 ; iSector<sizeSectors ; iSector++ )
442 ang = ((PanelBullEyeOptions*)panel)->GetAngOfCrownSection(iCrown,iSector);
443 angDelta= ((PanelBullEyeOptions*)panel)->GetAngDeltaOfCrownSection(iCrown);
444 manModelContourBullEye->AddSector(radioA,radioB,ang,angDelta);
447 } // if _panelBullEyeOptions
449 return manModelContour;
452 void wxContourMainFrame :: saveState()
454 std::string temp = kernelManager->saveState();
455 saveFileWithContours(temp);
458 void wxContourMainFrame::onDeleteContour()
460 //JCP 20-10-08 Undo redo implementation
462 //JCP 20-10-08 Undo redo implementation
464 std::vector<std::string> lstKeyNameToBeErase;
465 lstKeyNameToBeErase = _theViewPanel->getSceneManager()->getSelectedObjects();
466 deleteContours( lstKeyNameToBeErase );
468 int i,size=_sceneManager->getSelectedObjects().size();
471 std::string keyName = _sceneManager->getSelectedObjects()[i];
472 int ispartofstaticlist = this->_modelManager->IsPartOfStaticList( keyName );
473 if ( ispartofstaticlist>=0 )
475 std::vector<int> tempVector;
476 _instantPanel->getInstant( tempVector );
477 Instant instant(&tempVector);
478 this->_modelManager->ChangeContourOfList(keyName, &instant);
482 std::vector<std::string> lstKeyName;
483 std::vector<std::string> lstKeyNameActualSlice;
484 std::vector<std::string> lstKeyNameToBeErase;
486 lstKeyNameToBeErase = _sceneManager->getSelectedObjects();
487 lstKeyNameActualSlice = _sceneManager->GetlstContoursNameActualSlice();
488 int k,kSize=lstKeyNameToBeErase.size();
489 int j,jSize=lstKeyNameActualSlice.size();
491 for (k=0;k<kSize; k++)
494 for (j=0;j<jSize; j++)
496 if (lstKeyNameToBeErase[k]==lstKeyNameActualSlice[j])
503 lstKeyName.push_back( lstKeyNameToBeErase[k] );
507 deleteContours( lstKeyName );
511 void wxContourMainFrame :: deleteContours( std::vector<std::string> keyNamesVector )
513 int i,size=keyNamesVector.size();
516 deleteContour( keyNamesVector[i] );
520 void wxContourMainFrame :: deleteContour( std::string theKeyName )
523 manualContourModel * cModel;
524 manualViewBaseContour * cViewer;
525 manualContourBaseControler * cControler;
527 ContourWrap_ViewControl *conwrapviewControl = _theViewPanel->getSceneManager()->getContourWrap_ViewControlOf( theKeyName );
528 cControler = conwrapviewControl->getControler();*/
531 bool isedit = _theViewPanel->isEditableCControler(theKeyName);
532 bool ispartofstaticlst = kernelManager->IsPartOfStaticList(theKeyName);
534 if (isedit && ispartofstaticlst)
536 _theViewPanel->removeFromScene(theKeyName);
538 kernelManager->deleteCModel(theKeyName);
539 //_theViewPanel->getSceneManager()->removeFromScene( theKeyName );
540 //cViewer = conwrapviewControl->getViewer();
541 //_theViewPanel->getSceneManager()->removeWrap( theKeyName );
542 //cControler* conwrapviewControl->getControler();
545 // delete cControler;
550 void wxContourMainFrame::onDeleteContoursActSlice(){
551 //JCP 20-10-08 Undo redo implementation
553 //JCP 20-10-08 Undo redo implementation
554 deleteContours( (std::vector<std::string>)_theViewPanel->getSceneManager()->GetlstContoursNameActualSlice() );
556 void wxContourMainFrame::onDeleteAllContours(){
557 //JCP 20-10-08 Undo redo implementation
561 void wxContourMainFrame::deleteAllContours(){
562 //JCP 20-10-08 Undo redo implementation
565 std::vector<int> tempVector;
566 _instantPanel->getInstant( tempVector );
568 //JCP --08-09-2008 When using a diferent interface the _mbarrangeDeleteAll might not be initialize
569 // the values in GetStart and GetEnd will then not be initialize also.
570 // We use instead the values given when initializing the _deletepanel.
572 //int minZ = _mbarrangeDeleteAll->GetStart();
573 //int maxZ = _mbarrangeDeleteAll->GetEnd();
577 maxZ = _theViewPanel->getSceneManager()->GetImageDataSizeZ();
581 _theViewPanel->getSceneManager()->removeSceneContours( );
582 _theViewPanel->getSceneManager()->removeAllOutlines();
583 kernelManager->removeAllOutlines();
586 if ( (minZ==0) && (maxZ==_mbarrangeDeleteAll->GetMax() ))
588 _theViewPanel->getSceneManager()->removeSceneContours( );
589 _modelManager->removeAllOutlines();
590 _theViewPanel->getSceneManager()->removeAllOutlines();
593 for ( z=minZ ; z<=maxZ ; z++)
596 Instant instant(&tempVector);
597 std::vector<ContourThing**> lstContourThings = this->_modelManager->getOutlinesAtInstant( &instant );
599 sizeLstContourThings = lstContourThings.size();
600 for (ii=0 ; ii<sizeLstContourThings ; ii++)
602 ContourThing **contourthing = lstContourThings[ii];
603 deleteContour( (*contourthing)->getName() );
610 void wxContourMainFrame::setConceptValue( std::string name, int value )
612 _instantPanel->setConceptValue(name, value);
616 ConceptDataWrap* wxContourMainFrame::getLastConceptData()
618 return _instantPanel->getLastConceptData();
622 bool wxContourMainFrame::getIfConceptCheckedAt( std::string name, int pos )
624 return _instantPanel->getIfConceptCheckedAt( name, pos );
629 void wxContourMainFrame::ShowResultImages(int typeContourGroup, int selection, int minZ, int maxZ)
632 vtkImageData * value;
633 this->getMaskValue(&mask, &value, typeContourGroup, selection, minZ, maxZ);
635 std::vector<int> nTypeView;
636 nTypeView.push_back(5);
637 nTypeView.push_back(1);
638 nTypeView.push_back(2);
639 nTypeView.push_back(0);
641 wxFrame *frame = new wxFrame(this, -1,_T("Result image extracted.."),wxDefaultPosition,wxSize(600,600), wxDEFAULT_FRAME_STYLE|wxSTAY_ON_TOP);
642 wxAuiManager *m_mgr_noteBookViewerResult = new wxAuiManager();
643 m_mgr_noteBookViewerResult->SetManagedWindow(frame);
645 wxAuiNotebook* noteBookViewerResult = new wxAuiNotebook(frame, -1, wxPoint(600, 600), wxSize(430,200), m_notebook_style);
646 m_mgr_noteBookViewerResult->AddPane(noteBookViewerResult, wxAuiPaneInfo().Name(wxT("notebook_content")).CenterPane().PaneBorder(false));
648 wxPanel *panelViewer1 = new wxMaracas_N_ViewersWidget(noteBookViewerResult, value,&nTypeView);
649 wxPanel *panelViewer2 = new wxMaracas_N_ViewersWidget(noteBookViewerResult, mask,&nTypeView);
652 noteBookViewerResult->AddPage( panelViewer1, wxT("Image result") );
653 noteBookViewerResult->AddPage( panelViewer2, wxT("Mask result") );
654 m_mgr_noteBookViewerResult->Update();
661 void wxContourMainFrame::changeInstant()
663 std::vector<int> instantVect;
664 _instantPanel->getInstant( instantVect );
665 int actualSlice = instantVect[1];
666 kernelManager->setInstant(instantVect);
667 // Refresh Mask image
668 if(_viewMaskImage!=NULL)
670 _viewMaskImage->SetZ(actualSlice);
671 if (_viewMaskImagePanel->IsVisible()==true)
673 vtkImageData *mask, *value;
674 getMaskValue(&mask,&value, _contourGroup , 0, -1, -1);
675 _viewMaskImage->onThreshold();
677 } // if _viewMaskImage
678 // Refresh Threshold image
679 if(_viewThresholdImage!=NULL)
681 _viewThresholdImage->SetZ(actualSlice);
682 if (_viewThresholdImagePanel->IsVisible()==true)
684 _viewThresholdImage->onThreshold();
686 } // if _viewThresholdImage
687 updateInstantOutlines();
688 updateInstantImageData();
694 void wxContourMainFrame::updateInstantOutlines()
696 _theViewPanel->removeSceneContours();
697 _theViewPanel->addNameWrapperToScene();
699 //for( int i=0; i<size; i++)
701 // _theViewPanel->getSceneManager()->addToScene(namesWrapping[i]->getKeyName(), true, true, true, false, false );
705 int wxContourMainFrame::getNamesWrappingSize()
707 return kernelManager->getNamesWrappingSize();
710 std::string wxContourMainFrame::getNameWrapping(int i)
712 return kernelManager->getNameWrapping(i);
715 void wxContourMainFrame::updateInstantImageData()
717 std::vector<int> inst;
718 _instantPanel->getInstant(inst);
720 vtkImageData* img = kernelManager->getImageAtInstant(inst);
722 _theViewPanel->changeImage(img);
725 int z = _instantPanel->getConceptDataOf("Axe Depth")->getActualValue();
726 _theViewPanel->setImageSlice(z);
730 void wxContourMainFrame::updateInstantAxes()
735 void wxContourMainFrame::onChangeDeep(int val){
736 _instantPanel->setConceptValue( "Axe Depth", (int)val );
741 void wxContourMainFrame::onCopy(){
742 std::vector<std::string> currentSelection = _theViewPanel->getSelectedObjects();
743 std::vector<int> tempVector;
744 _instantPanel->getInstant( tempVector );
745 _performingOperation->reset();
746 _performingOperation->setStartCommand( COPY );
747 _performingOperation->setStartOperationInstantVector( tempVector );
748 _performingOperation->setKeyNamesOperationElems( currentSelection );
751 void wxContourMainFrame::onPaste()
753 char theStartCommand = _performingOperation->getStartCommand();
754 if ( theStartCommand == COPY )
756 //JCP 20-10-08 Undo redo implementation
758 //JCP 20-10-08 Undo redo implementation
759 std::vector<int> tempVector;
760 _instantPanel->getInstant( tempVector );
761 _performingOperation->setEndOperationInstantVector ( tempVector );
762 std::vector<std::string> elems = _performingOperation->getKeyNamesOperationElems();
763 int i,size = elems.size();
764 for( i=0; i<size; i++ )
766 createCopyContourOf( elems[i], tempVector, i>0 );
771 void wxContourMainFrame::onUndo()
773 std::string filename;
774 if(kernelManager->onUndoSaveFile(filename)){
775 saveFileWithContours(filename);
777 if(kernelManager->onUndo(filename)){
781 void wxContourMainFrame::onRedo(){
782 std::string filename;
783 if(kernelManager->onRedo(filename)){
788 void wxContourMainFrame :: createCopyContourOf ( std::string anExistingKName, std::vector<int> &instantNoTouchData, bool append )
790 std::string cloneName = kernelManager->createCopyContourOf( anExistingKName, instantNoTouchData );
791 manualBaseModel * manualModel = kernelManager->getOutlineByKeyName(cloneName);//_modelManager->getOutlineByKeyName( cloneName )->getModel();
792 _theViewPanel->getSceneManager()->createCopyContourOf( anExistingKName, cloneName, manualModel , append );
795 ///AD: 03-09 Copy the object and apply the given transformation
796 void wxContourMainFrame :: createMirrorContourOf ( std::string anExistingKName, std::vector<int> &instantNoTouchData, bool append )
798 std::string cloneName = kernelManager->createCopyContourOf( anExistingKName, instantNoTouchData );
799 manualBaseModel * manualModel = kernelManager->getOutlineByKeyName(cloneName);
801 manualPoint * refPoint1 = _refLineModel->GetManualPoint(0);
802 manualPoint * refPoint2 = _refLineModel->GetManualPoint(1);
804 double pnt1X = refPoint1->GetX();
805 double pnt1Y = refPoint1->GetY();
806 // double pnt1Z = refPoint1->GetZ();
807 double pnt2X = refPoint2->GetX();
808 double pnt2Y = refPoint2->GetY();
809 // double pnt2Z = refPoint2->GetZ();
811 double angle = (atan2(pnt2Y - pnt1Y, pnt2X - pnt1X) * 180 / 3.1415926535897932384626433832795)+90;
812 vtkTransform *t = vtkTransform::New();
816 t->Translate(-pnt1X, -pnt1Y, 0);
820 t->Translate(pnt1X, pnt1Y, 0);
823 int i,size=manualModel->GetSizeLstPoints();
826 manualPoint * mp = manualModel->GetManualPoint(i);
832 t->TransformPoint( vecIn, vecOut );
833 mp->SetPointX( vecOut[0] );
834 mp->SetPointY( vecOut[1] );
835 mp->SetPointZ( vecOut[2] );
838 _theViewPanel->getSceneManager()->createCopyContourOf( anExistingKName, cloneName, manualModel , append );
841 void wxContourMainFrame ::loadState(std::string filename)
844 onLoadContours(filename,false);
848 void wxContourMainFrame::onLoad()
850 std::string fileNameContourROI = GetFileLocation();
851 //CMRU 03-09-09-----------------------------------------------------------------------------------------------
852 if(GetFileLocation().empty())
854 //------------------------------------------------------------------------------------------------------------
855 //EED 2017-09-16 Migration wxWidgets 2.8 to 3.0
856 #if wxMAJOR_VERSION <= 2
857 wxFileDialog dialog(NULL, _T("Choose a file"), _T(""), _T(""), _T("*.roi"), wxOPEN );
859 wxFileDialog dialog(NULL, _T("Choose a file"), _T(""), _T(""), _T("*.roi"), wxFD_OPEN );
861 if (dialog.ShowModal() == wxID_OK)
863 fileNameContourROI = (const char *)(dialog.GetPath().mb_str());
867 onLoadContours(fileNameContourROI,true);
871 void wxContourMainFrame::SetZForAllContours(int pz)
874 std::vector< std::string > lstNameThings;
875 int i,sizeLstNameThings;
876 int ii,sizeLstPoints;
878 lstNameThings = kernelManager->GetLstNameThings();
879 sizeLstNameThings = lstNameThings.size();
880 for (i=0 ; i<sizeLstNameThings ; i++)
882 printf("EED wxContourMainFrame::SetZForAllContours contour=%d \n", i );
883 manualBaseModel * manualModel = kernelManager->getOutlineByKeyName(lstNameThings[i]);
884 sizeLstPoints = manualModel->GetSizeLstPoints();
885 for (ii=0 ; ii<sizeLstPoints ; ii++)
887 manualModel->GetManualPoint(ii)->SetPointZ(-900);
888 }// for ii list of points
889 }// for i list of Things
893 lstNameThings = kernelManager->GetLstNameThingsStatic();
894 sizeLstNameThings = lstNameThings.size();
895 for (i=0 ; i<sizeLstNameThings ; i++)
897 manualBaseModel * manualModel = kernelManager->getOutlineByKeyName(lstNameThings[i]);
898 sizeLstPoints = manualModel->GetSizeLstPoints();
899 for (ii=0 ; ii<sizeLstPoints ; ii++)
901 manualModel->GetManualPoint(ii)->SetPointZ(-900);
902 }// for ii list of points
903 }// for i list of static things
906 void wxContourMainFrame::onLoadContours(std::string fileNameContourROI, bool interactiveInterface)
910 FILE *pFile =fopen(fileNameContourROI.c_str(),"r+");
911 //CMRU 03-09-09- ----------------------------------------------------------------------------------------------
914 //------------------------------------------------------------------------------------------------------------
915 fileNameContourROI.append("data");
916 FILE *pFileData=fopen(fileNameContourROI.c_str(),"r+");
917 if(pFileData != NULL)
919 fscanf(pFileData,"%s",tmpD); // --CreaContour--
920 fscanf(pFileData,"%s",tmpD); // Version
921 fscanf(pFileData,"%s",tmpD); // 1.0.3 || 1.0.2 || 1.0.1 || 1.0.0
923 fscanf(pFileData,"%s",tmpD); // onePixelSize
924 fscanf(pFileData,"%s",tmpD); // #
925 _onePixelSize = atof(tmpD);
926 fscanf(pFileData,"%s",tmpD); // NumberOfContours
927 fscanf(pFileData,"%s",tmpD); // #
929 fscanf(pFile,"%s",tmp); // --CreaContour--
930 fscanf(pFile,"%s",tmp); // Version
931 fscanf(pFile,"%s",tmp); // 1.0.3 || 1.0.2 || 1.0.1 || 1.0.0
932 std::string version(tmp);
934 _tmpReadFileTypeOfTransformation=-1;
935 if (version=="1.0.3")
937 readDimSpc(pFile,interactiveInterface); // DimSpc interactive ON
938 openContours(pFile,pFileData,false);
939 openContours(pFile,pFileData,true); //Load StaticContours
941 if (version=="1.0.2")
944 readDimSpc(pFile,interactiveInterface); // DimSpc interactive ON
945 openContours(pFile,pFileData,false);
946 readDimSpc(pFile,false); // DimSpc interactive OFF
947 openContours(pFile,pFileData,true); // Load StaticContours
948 SetZForAllContours(-900);
951 else if (version=="1.0.1")
953 openContours(pFile,pFileData,false); //Skips ImageDimensions and ImageSpacing
954 openContours(pFile,pFileData,true); //Load StaticContours, skips ImageDimensions and ImageSpacing
958 else if (version=="1.0.0")
960 openContours(pFile,pFileData,false); //Skips ImageDimensions and ImageSpacing
965 if(pFileData != NULL)
970 _theViewPanel->getSceneManager()->removeSceneContours();
975 void wxContourMainFrame::onImport()
977 std::string filename, filenamecontours;
978 //EED 2017-09-16 Migration wxWidgets 2.8 to 3.0
979 #if wxMAJOR_VERSION <= 2
980 wxFileDialog dialog(NULL, _T("Choose a XML Osirix File"), _T(""), _T(""), _T("*.xml"), wxOPEN );
982 wxFileDialog dialog(NULL, _T("Choose a XML Osirix File"), _T(""), _T(""), _T("*.xml"), wxFD_OPEN );
984 if (dialog.ShowModal() == wxID_OK)
986 filename = dialog.GetPath().mb_str();
987 filenamecontours = kernelManager->parseOsirixFile(filename);
989 if(filenamecontours.compare("") != 0){
990 onLoadContours(filenamecontours,true);
995 void wxContourMainFrame::onTest()
997 std::string filename, filenamecontours;
998 //EED 2017-09-16 Migration wxWidgets 2.8 to 3.0
999 #if wxMAJOR_VERSION <= 2
1000 wxFileDialog dialog(NULL, _T("Choose a File"), _T(""), _T(""), _T("*.*"), wxOPEN );
1002 wxFileDialog dialog(NULL, _T("Choose a File"), _T(""), _T(""), _T("*.*"), wxFD_OPEN );
1005 if (dialog.ShowModal() == wxID_OK)
1007 filename = dialog.GetPath().mb_str();
1008 std::cout << "This is the filename: " << filename << std::endl;
1014 void wxContourMainFrame::onSave(){
1015 //CMRU 03-09-09-----------------------------------------------------------------------------------------------
1016 if(GetFileLocation().empty())
1018 //------------------------------------------------------------------------------------------------------------
1019 //EED 2017-09-16 Migration wxWidgets 2.8 to 3.0
1020 #if wxMAJOR_VERSION <= 2
1021 wxFileDialog dialog(NULL, _T("Choose a file"), _T(""), _T(""), _T("*.roi"), wxSAVE );
1023 wxFileDialog dialog(NULL, _T("Choose a file"), _T(""), _T(""), _T("*.roi"), wxFD_SAVE );
1025 if (dialog.ShowModal() == wxID_OK)
1027 std::string fileNameContourROI = (const char *)(dialog.GetPath().mb_str());
1028 kernelManager->setCurrentFileName(fileNameContourROI);
1029 saveFileWithContours( fileNameContourROI );
1032 //CMRU 03-09-09-----------------------------------------------------------------------------------------------
1035 std::cout<<"Nombre del archivo: "<<GetFileLocation()<<std::endl;
1036 std::string fileNameContourROI = GetFileLocation();
1037 std::cout<<"Nombre del archivo: "<<fileNameContourROI<<std::endl;
1038 kernelManager->setCurrentFileName(fileNameContourROI);
1039 saveFileWithContours( fileNameContourROI);
1041 //------------------------------------------------------------------------------------------------------------
1045 void wxContourMainFrame::saveFileWithContours( std::string filename )
1048 FILE *pFile=fopen(filename.c_str(),"w+");
1050 //CMRU 03-09-09-----------------------------------------------------------------------------------------------
1051 filename.append("data");
1052 std::cout<<"Nombre del archivo: "<<filename<<std::endl;
1053 FILE *pFileData=fopen(filename.c_str(),"w+");
1054 //------------------------------------------------------------------------------------------------------------
1056 std::vector< std::string > lstNameThings;
1057 int i,sizeLstNameThings;
1059 fprintf(pFile,"--CreaContour--\n");
1060 fprintf(pFile,"Version %s\n", "1.0.3" );
1062 //CMRU 03-09-09-----------------------------------------------------------------------------------------------
1063 fprintf(pFileData,"--CreaContour--\n");
1064 fprintf(pFileData,"Version %s\n", "1.0.3" );
1065 fprintf(pFileData,"OnePixelSize %f\n", _onePixelSize);
1067 //------------------------------------------------------------------------------------------------------------
1069 vtkImageData *image = _images[0];
1072 image->GetDimensions(dimRange);
1074 fprintf(pFile,"ImageDimensions %d %d %d\n", dimRange[0], dimRange[1], dimRange[2] );
1077 image->GetSpacing(spaRange);
1079 fprintf(pFile,"ImageSpacing %f %f %f\n", spaRange[0], spaRange[1], spaRange[2] );
1083 lstNameThings = kernelManager->GetLstNameThings();
1084 sizeLstNameThings = lstNameThings.size();
1085 fprintf(pFile,"NumberOfContours %d\n", sizeLstNameThings );
1087 //CMRU 03-09-09-----------------------------------------------------------------------------------------------
1088 fprintf(pFileData,"NumberOfContours %d\n", sizeLstNameThings );
1089 //------------------------------------------------------------------------------------------------------------
1098 for (i=0 ; i<sizeLstNameThings ; i++)
1100 //CMRU 03-09-09-----------------------------------------------------------------------------------------------
1101 manualBaseModel * manualModel = kernelManager->getOutlineByKeyName(lstNameThings[i]);
1104 // double sizeInPixel = manualModel ->GetPathSize( );
1105 double sizeInPixel = manualModel ->GetPathSize( spc );
1107 double realContourSize = sizeInPixel*_onePixelSize;
1108 manualModel ->SetRealSize(realContourSize);
1109 //------------------------------------------------------------------------------------------------------------
1111 //int size= kernelManager->GetLstNameThings().size();
1113 kernelManager->SaveThingName( pFile, pFileData, lstNameThings[i] );
1114 _theViewPanel->getSceneManager()->SaveThingName( pFile, lstNameThings[i] );
1117 //-- Static Contours
1119 // fprintf(pFile,"ImageDimensions %d %d %d\n", dimRange[0], dimRange[1], dimRange[2] );
1120 // fprintf(pFile,"ImageSpacing %f %f %f\n", spaRange[0], spaRange[1], spaRange[2] );
1122 lstNameThings = kernelManager->GetLstNameThingsStatic();
1123 sizeLstNameThings = lstNameThings.size();
1124 fprintf(pFile,"NumberOfContoursStatic %d\n", sizeLstNameThings );
1126 //CMRU 03-09-09-----------------------------------------------------------------------------------------------
1127 fprintf(pFileData,"NumberOfContoursStatic %d\n", sizeLstNameThings );
1128 //------------------------------------------------------------------------------------------------------------
1130 for (i=0 ; i<sizeLstNameThings ; i++)
1132 kernelManager->SaveThingName( pFile, pFileData, lstNameThings[i] );
1133 _theViewPanel->getSceneManager()->SaveThingName( pFile, lstNameThings[i] );
1141 void wxContourMainFrame::readDimSpc(FILE *pFile, bool interactiveOption)
1145 double imageSpac[3];
1146 vtkImageData *image = _images[0];
1147 image->GetDimensions(imageDim);
1148 image->GetSpacing(imageSpac);
1150 fscanf(pFile,"%s",tmp); // ImageDimensions
1151 fscanf(pFile,"%s",tmp); // X
1152 _tmpReadFileImageDim[0] = atoi(tmp);
1153 fscanf(pFile,"%s",tmp); // Y
1154 _tmpReadFileImageDim[1] = atoi(tmp);
1155 fscanf(pFile,"%s",tmp); // Z
1156 _tmpReadFileImageDim[2] = atoi(tmp);
1158 fscanf(pFile,"%s",tmp); // ImageSpacing
1159 fscanf(pFile,"%s",tmp); // X
1160 _tmpReadFileImageSpac[0] = atof(tmp);
1161 fscanf(pFile,"%s",tmp); // Y
1162 _tmpReadFileImageSpac[1] = atof(tmp);
1163 fscanf(pFile,"%s",tmp); // Z
1164 _tmpReadFileImageSpac[2] = atof(tmp);
1167 if (interactiveOption==true)
1169 //Compare Spacing and Dims in X and Y (Necessary in Z?) - Just for Version 2
1170 if (imageDim[0]!=_tmpReadFileImageDim[0] || imageDim[1]!=_tmpReadFileImageDim[1] || imageSpac[0]!=_tmpReadFileImageSpac[0] || imageSpac[1]!=_tmpReadFileImageSpac[1])
1172 wxDialog* dial = new wxDialog (this,-1,_T("Tools"),wxDefaultPosition, wxSize(460,360));
1173 wxSizer* buttonsSizer = dial->CreateSeparatedButtonSizer(wxOK|wxCANCEL);
1174 wxBoxSizer *dialSizer = new wxBoxSizer(wxVERTICAL);
1176 wxString lstOptOperation[2];
1177 lstOptOperation[0]=_T("By Dimension");
1178 lstOptOperation[1]=_T("By Spacing");
1179 wxRadioBox * radioOpts = new wxRadioBox(dial, -1, _T("Type of Transformation"), wxDefaultPosition, wxSize(270,45), 2 , lstOptOperation, 2, wxRA_SPECIFY_COLS);
1181 dialSizer->Add( new wxStaticText(dial,-1,_T("The image resolution is not compatible with the ")) , 0, wxGROW );
1182 dialSizer->Add( new wxStaticText(dial,-1,_T("selected Roi file. Do you want to tranform it?")) , 0, wxGROW );
1183 dialSizer->Add( new wxStaticText(dial,-1,_T(" ")) , 0, wxGROW );
1184 dialSizer->Add(radioOpts,0,wxGROW);
1185 dialSizer->Add( new wxStaticText(dial,-1,_T(" ")) , 0, wxGROW );
1186 dialSizer->Add(buttonsSizer,0,wxGROW);
1187 dial->SetSizer(dialSizer, true);
1191 int _tmpReadFileTypeOfTransformation = -1;
1192 //EED bool transform = false;
1194 if (dial->GetReturnCode() == wxID_OK)
1196 _tmpReadFileTypeOfTransformation = radioOpts->GetSelection();
1200 } // if interactiveOption
1207 void wxContourMainFrame::openContours( FILE *pFile, FILE *pFileData, bool staticContour )
1212 vtkImageData *image = _images[0];
1215 double imageSpac[3];
1216 image->GetDimensions(imageDim);
1217 image->GetSpacing(imageSpac);
1220 fscanf(pFile,"%s",tmp); // NumberOfContours
1221 fscanf(pFile,"%s",tmp); // ##
1222 int numberOfContours = atoi(tmp);
1224 std::vector<int> instantVector;
1225 int typeContourModel;
1226 manualBaseModel *manModelContour;
1230 if (compatible==true)
1233 for (i=0;i<numberOfContours;i++)
1235 instantVector.clear();
1236 fscanf(pFile,"%s",tmp); // Instant
1238 fscanf(pFile,"%s",tmp); // 1
1239 instantVector.push_back( atoi(tmp) );
1240 fscanf(pFile,"%s",tmp); // 2
1241 instantVector.push_back( atoi(tmp) );
1242 fscanf(pFile,"%s",tmp); // 3
1243 instantVector.push_back( atoi(tmp) );
1244 fscanf(pFile,"%s",tmp); // 4
1245 instantVector.push_back( atoi(tmp) );
1246 fscanf(pFile,"%s",tmp); // 5
1247 instantVector.push_back( atoi(tmp) );
1248 fscanf(pFile,"%s",tmp); // 6
1249 instantVector.push_back( atoi(tmp) );
1252 fscanf(pFile,"%s",tmp); // TypeContourModel
1253 fscanf(pFile,"%s",tmp); // ##
1254 typeContourModel = atoi(tmp);
1256 manModelContour = kernelManager->factoryManualContourModel(typeContourModel);
1257 manModelContour->Open(pFile);
1258 if(pFileData != NULL)
1260 manModelContour->OpenData(pFileData);
1263 fscanf(pFile,"%s",tmp); // TypeView
1264 fscanf(pFile,"%s",tmp); // ##
1265 typeView = atoi(tmp);
1267 std::string theName;
1268 theName = kernelManager->createOutline( manModelContour, instantVector );
1269 bool addedModel = theName.compare("") != 0;
1272 double spc[3];//Si no hay imagen pero hay contornos que spacing se pone por default
1273 _theViewPanel->getSpacing(spc);
1274 //Adding the manualContourControler to interface objects structure
1275 //Adding the manualViewContour to interface objects structure
1276 //_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.
1277 _theViewPanel->getSceneManager()->configureViewControlTo( theName, manModelContour,spc , typeView) ;
1280 if (staticContour) //StaticContours (will appear in all slices)
1282 Instant instant(&instantVector);
1283 kernelManager->changeContourOfManager( theName , &instant );
1286 }// for numberOfContours
1289 else if (compatible==false)
1294 for (i=0;i<numberOfContours;i++)
1296 instantVector.clear();
1297 fscanf(pFile,"%s",tmp); // Instant
1299 fscanf(pFile,"%s",tmp); // 1
1300 instantVector.push_back( atoi(tmp) );
1301 fscanf(pFile,"%s",tmp); // 2
1302 instantVector.push_back( atoi(tmp) );
1303 fscanf(pFile,"%s",tmp); // 3
1304 instantVector.push_back( atoi(tmp) );
1305 fscanf(pFile,"%s",tmp); // 4
1306 instantVector.push_back( atoi(tmp) );
1307 fscanf(pFile,"%s",tmp); // 5
1308 instantVector.push_back( atoi(tmp) );
1309 fscanf(pFile,"%s",tmp); // 6
1310 instantVector.push_back( atoi(tmp) );
1312 fscanf(pFile,"%s",tmp); // TypeContourModel
1313 fscanf(pFile,"%s",tmp); // ##
1314 typeContourModel = atoi(tmp);
1316 manModelContour = kernelManager->factoryManualContourModel(typeContourModel);
1317 manModelContour->Open(pFile);
1318 if(pFileData != NULL)
1320 manModelContour->OpenData(pFileData);
1323 if (_tmpReadFileTypeOfTransformation==-1){
1325 } else if (_tmpReadFileTypeOfTransformation==0){
1326 double transX, transY;
1327 transX = (double) imageDim[0]/_tmpReadFileImageDim[0];
1328 transY = (double) imageDim[1]/_tmpReadFileImageDim[1];
1329 manModelContour->Transform_Ax_Plus_B(transX,0,transY,0);
1330 } else if (_tmpReadFileTypeOfTransformation==1) {
1331 double transX, transY;
1332 transX = (double) _tmpReadFileImageSpac[0]/imageDim[0];
1333 transY = (double) _tmpReadFileImageSpac[1]/imageDim[1];
1334 manModelContour->Transform_Ax_Plus_B(transX,0,transY,0);
1337 fscanf(pFile,"%s",tmp); // TypeView
1338 fscanf(pFile,"%s",tmp); // ##
1339 typeView = atoi(tmp);
1341 std::string theName;
1342 theName = kernelManager->createOutline( manModelContour, instantVector );
1343 bool addedModel = theName.compare("") != 0;
1346 double spc[3];//Si no hay imagen pero hay contornos que spacing se pone por default
1347 _theViewPanel->getSpacing(spc);
1348 //Adding the manualContourControler to interface objects structure
1349 //Adding the manualViewContour to interface objects structure
1350 //_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.
1351 _theViewPanel->getSceneManager()->configureViewControlTo( theName, manModelContour,spc , typeView) ;
1354 if (staticContour) //StaticContours (will appear in all slices)
1356 Instant instant(&instantVector);
1357 kernelManager->changeContourOfManager( theName , &instant );
1359 }// for numberOfContours
1365 void wxContourMainFrame::RefreshInterface()
1368 _theViewPanel->RefreshInterface();
1369 //wxVtk2DBaseView *wxvtk2dbaseview = (wxVtk2DBaseView*)this->_theViewPanel->getWxVtkBaseView();
1370 //wxvtk2dbaseview->Refresh();
1373 vtkImageData* wxContourMainFrame::getImageData()
1375 return _theViewPanel->getImageData();
1378 void wxContourMainFrame::onSegmentationOneSliceITK(wxString distance, wxString sigma, wxString alfa, wxString beta, wxString propagation, wxString iterations, wxString inflation)
1380 //JCP 20-10-08 Undo redo implementation
1382 //JCP 20-10-08 Undo redo implementation
1385 int x = _theViewPanel->GetX();
1386 int y = _theViewPanel->GetY();
1387 int z = _theViewPanel->GetZ();
1388 SegmentationOneSliceITK( x,y,z,distance, sigma, alfa, beta, propagation, iterations, inflation);
1392 void wxContourMainFrame::SegmentationOneSliceITK(int x, int y, int z, wxString distanc, wxString sigm, wxString alf, wxString bet, wxString prop, wxString iter, wxString inflation)
1394 int typeofcontour = 1;
1396 vtkImageData *imagedata = getImageData();
1398 //Tipo de pixeles a utilizar internamente en ITK
1399 typedef float InternalPixelType;
1400 const unsigned int Dimension = 2;
1401 typedef itk::Image< InternalPixelType, Dimension > InternalImageType;
1403 //Tipo de pixeles de salida 1
1404 typedef unsigned char OutputPixelType;
1405 typedef itk::Image< OutputPixelType, Dimension > OutputImageType;
1407 //Tipo de pixeles de salida 2
1408 typedef unsigned short OutputPixelType2;
1409 typedef itk::Image< OutputPixelType2, Dimension > OutputImageType2;
1411 //DefiniciÛn del thresholder
1412 typedef itk::BinaryThresholdImageFilter<
1414 OutputImageType > ThresholdingFilterType;
1416 //DefiniciÛn del primer filtro de conversiÛn de pixeles
1417 typedef itk::CastImageFilter<
1418 OutputImageType, OutputImageType2 > CastFilterType;
1420 //DefiniciÛn del segundo tipo de conversiÛn de pixeles
1421 typedef itk::CastImageFilter<
1422 OutputImageType2, InternalImageType > CastFilterType2;
1424 //Tercer tipo de conversiÛn
1425 typedef itk::RescaleIntensityImageFilter<
1427 OutputImageType > CastFilterType3;
1429 //Cuarto tipo de conversiÛn
1430 typedef itk::RescaleIntensityImageFilter<
1432 OutputImageType > CastFilterType4;
1434 ThresholdingFilterType::Pointer thresholder = ThresholdingFilterType::New();
1436 thresholder->SetLowerThreshold( 0.0 );
1437 thresholder->SetUpperThreshold( 128 );
1439 thresholder->SetOutsideValue( 255 );
1440 thresholder->SetInsideValue( 0 );
1442 //DefinciÛn de conexiÛnes entre VTK e ITK y el writer
1443 typedef itk::VTKImageToImageFilter<OutputImageType2> ConnectorType;
1444 typedef itk::ImageToVTKImageFilter<OutputImageType> ConnectorType2;
1445 //EED10JUIN2011 typedef itk::ImageFileWriter< OutputImageType > WriterType;
1447 ConnectorType::Pointer connector= ConnectorType::New();
1448 ConnectorType2::Pointer connector2= ConnectorType2::New();
1451 CastFilterType::Pointer filter=CastFilterType::New();
1452 CastFilterType2::Pointer filter2=CastFilterType2::New();
1454 connector->SetInput( imagedata );
1455 filter2->SetInput(connector->GetOutput());
1457 typedef itk::CurvatureAnisotropicDiffusionImageFilter<
1459 InternalImageType > SmoothingFilterType;
1461 SmoothingFilterType::Pointer smoothing = SmoothingFilterType::New();
1463 typedef itk::GradientMagnitudeRecursiveGaussianImageFilter<
1465 InternalImageType > GradientFilterType;
1467 typedef itk::SigmoidImageFilter<
1469 InternalImageType > SigmoidFilterType;
1471 GradientFilterType::Pointer gradientMagnitude = GradientFilterType::New();
1473 SigmoidFilterType::Pointer sigmoid = SigmoidFilterType::New();
1475 sigmoid->SetOutputMinimum( 0.0 );
1476 sigmoid->SetOutputMaximum( 255.0 );
1479 typedef itk::FastMarchingImageFilter<
1481 InternalImageType > FastMarchingFilterType;
1484 FastMarchingFilterType::Pointer fastMarching = FastMarchingFilterType::New();
1486 printf("EED wxContourMainFrame::SegmentationOneSliceITK Skypping this code. Not compiling GeodesicActiveContourLevelSetImageFilter in fedora 17 with ITK 3.20.1 \n ");
1488 > - > - > - > - > - > - > - > - > - > - > - > - > - > - > - > - Not compiling GeodesicActiveContourLevelSetImageFilter in fedora 17 with ITK 3.20.1
1491 typedef itk::GeodesicActiveContourLevelSetImageFilter< InternalImageType,
1492 InternalImageType > GeodesicActiveContourFilterType;
1493 GeodesicActiveContourFilterType::Pointer geodesicActiveContour =
1494 GeodesicActiveContourFilterType::New();
1496 typedef itk::ZeroCrossingImageFilter<
1498 InternalImageType > ZeroCrossingFilterType;
1499 ZeroCrossingFilterType::Pointer zeroCrossing =
1500 ZeroCrossingFilterType::New();
1502 const double propagationScaling = atof( crea::wx2std(prop).c_str() );
1504 geodesicActiveContour->SetPropagationScaling( propagationScaling );
1505 geodesicActiveContour->SetCurvatureScaling( 1.0 );
1506 geodesicActiveContour->SetAdvectionScaling( 1.0 );
1508 geodesicActiveContour->SetMaximumRMSError( 0.02 );
1509 int it=atoi( crea::wx2std(iter).c_str() );
1510 geodesicActiveContour->SetNumberOfIterations( it );
1512 smoothing->SetInput( filter2->GetOutput() );
1513 gradientMagnitude->SetInput( smoothing->GetOutput() );
1514 sigmoid->SetInput( gradientMagnitude->GetOutput() );
1515 fastMarching->SetInput( sigmoid->GetOutput() );
1516 geodesicActiveContour->SetInput( fastMarching->GetOutput() );
1517 geodesicActiveContour->SetFeatureImage( sigmoid->GetOutput() );
1519 zeroCrossing->SetInput( geodesicActiveContour->GetOutput() );
1520 //thresholder->SetInput( zeroCrossing->GetOutput() );
1521 thresholder->SetInput( geodesicActiveContour->GetOutput() );
1522 connector2->SetInput( thresholder->GetOutput() );
1524 < - < - < - < - < - < - < - < - < - < - < - < - < - < - < - < - < - < - < - < -
1530 smoothing->SetTimeStep( 0.125 );
1531 smoothing->SetNumberOfIterations( 5 );
1532 smoothing->SetConductanceParameter( 9.0 );
1535 const double sigma = atof( crea::wx2std(sigm).c_str() );
1536 gradientMagnitude->SetSigma( sigma );
1538 const double alpha = atof( crea::wx2std(alf).c_str() );
1539 const double beta = atof( crea::wx2std(bet).c_str() );
1541 sigmoid->SetAlpha( alpha );
1542 sigmoid->SetBeta( beta );
1544 typedef FastMarchingFilterType::NodeContainer NodeContainer;
1545 typedef FastMarchingFilterType::NodeType NodeType;
1547 NodeContainer::Pointer seeds = NodeContainer::New();
1549 InternalImageType::IndexType seedPosition;
1550 seedPosition[0] = x;
1551 seedPosition[1] = y;
1553 const double initialDistance = atof( crea::wx2std(distanc).c_str() );
1557 const double seedValue = - initialDistance;
1559 node.SetValue( seedValue );
1560 node.SetIndex( seedPosition );
1562 seeds->Initialize();
1563 seeds->InsertElement( 0, node );
1565 fastMarching->SetTrialPoints( seeds );
1567 fastMarching->SetSpeedConstant( 1.0 );
1569 fastMarching->SetOutputSize(
1570 connector->GetOutput()->GetBufferedRegion().GetSize() );
1572 fastMarching->SetStoppingValue( 800 );
1576 connector2->Update();
1577 vtkImageData *idata = connector2->GetOutput();
1579 vtkMarchingContourFilter* cntVTK = vtkMarchingContourFilter::New( );
1581 cntVTK->SetNumberOfContours( 1 );
1582 cntVTK->SetValue( 0, 255 );
1583 //EED 2017-01-01 Migration VTK7
1584 #if VTK_MAJOR_VERSION <= 5
1585 cntVTK->SetInput( idata );
1587 cntVTK->UpdateInformation();
1589 cntVTK->SetInputData( idata );
1592 vtkCleanPolyData* cpd = vtkCleanPolyData::New( );
1594 //EED 2017-01-01 Migration VTK7
1595 #if VTK_MAJOR_VERSION <= 5
1596 cpd->SetInput( cntVTK->GetOutput( ) );
1598 cpd->UpdateInformation();
1600 cpd->SetInputData( cntVTK->GetOutput( ) );
1604 vtkPolyDataConnectivityFilter* conn = vtkPolyDataConnectivityFilter::New( );
1605 conn->SetExtractionModeToLargestRegion( );
1606 //EED 2017-01-01 Migration VTK7
1607 #if VTK_MAJOR_VERSION <= 5
1608 conn->SetInput( cpd->GetOutput( ) );
1610 conn->UpdateInformation();
1612 conn->SetInputData( cpd->GetOutput( ) );
1616 vtkStripper* vtkstripper = vtkStripper::New( );
1618 //EED 2017-01-01 Migration VTK7
1619 #if VTK_MAJOR_VERSION <= 5
1620 vtkstripper->SetInput( conn->GetOutput() );
1621 vtkstripper->Update();
1622 vtkstripper->UpdateInformation();
1624 vtkstripper->SetInputData( conn->GetOutput() );
1628 vtkPolyData* polyDataResult = cntVTK->GetOutput();
1629 //std::cout<<"Points "<<polyDataResult->GetNumberOfPoints()<<std::endl;
1631 //EED 2017-01-01 Migration VTK7
1632 #if VTK_MAJOR_VERSION <= 5
1633 polyDataResult->Update( );
1634 polyDataResult->UpdateInformation();
1642 myfile.open ("C:/Creatis/example.txt");
1644 polyDataResult->Print(myfile);
1645 myfile << "-------------------------------------\n";
1646 polyDataResult->GetLines()->Print(myfile);
1654 //--Calculating control points
1656 std::vector<double> vecX;
1657 std::vector<double> vecY;
1658 std::vector<double> vecXo;
1659 std::vector<double> vecYo;
1660 std::vector<double>::iterator vecXoi;
1661 std::vector<double>::iterator vecYoi;
1662 std::vector<double> vecZ;
1664 std::vector<double> vecCtrlPointX;
1665 std::vector<double> vecCtrlPointY;
1666 std::vector<double> vecCtrlPointZ;
1672 int ii,size=polyDataResult->GetNumberOfPoints();
1674 myfile.open ("C:/Creatis/example2.txt");
1676 size=polyDataResult->GetNumberOfPoints();
1677 for (ii=0;ii<size;ii++)
1684 p = polyDataResult->GetPoint(ii);
1687 /*if(fabs(yAct-y)>20)
1689 if((xAct-x)>1 || (xAct-x)<-1)
1691 vecX.push_back( p[0] );
1692 vecY.push_back( p[1] );
1693 myfile <<p[0]<<","<<p[1]<<"\n";
1694 std::cout<<" x Anterior "<<xAct<<" x actual "<<x<<std::endl;
1695 std::cout<<" y Anterior "<<yAct<<" y actual "<<y<<std::endl;
1696 std::cout<<" x "<<p[0]<<" y "<<p[1]<<std::endl;
1697 vecZ.push_back( 900 );
1703 vecXo.push_back(p[0]);
1704 vecYo.push_back(p[1]);
1708 else*/ if(fabs(xAct-x)>11)
1710 vecXo.push_back(p[0]);
1711 vecYo.push_back(p[1]);
1715 vecX.push_back( p[0] );
1716 myfile <<p[0]<<","<<p[1]<<"\n";
1717 //std::cout<<" x Anterior "<<xAct<<" x actual "<<x<<std::endl;
1718 //std::cout<<" y Anterior "<<yAct<<" y actual "<<y<<std::endl;
1719 //std::cout<<" x "<<p[0]<<" y "<<p[1]<<std::endl;
1720 vecY.push_back( p[1] );
1721 vecZ.push_back( 900 );
1729 while(!vecXo.empty())
1731 vecX.push_back(vecXo.back());
1732 //std::cout<<" x Siguiente "<<vecXo.back();
1734 vecZ.push_back( 900 );
1736 while(!vecYo.empty())
1738 vecY.push_back(vecYo.back());
1743 /*for(int l=0;l<vecX.size();l++)
1747 vecXo.push_back(p[0]);
1748 vecYo.push_back(p[1]);
1759 ExtractControlPoints2D *extractcontrolpoints2d = new ExtractControlPoints2D();
1761 extractcontrolpoints2d->SetContour( &vecX , &vecY , &vecZ );
1765 extractcontrolpoints2d->GetInitialControlPoints( &vecCtrlPointX , &vecCtrlPointY , &vecCtrlPointZ );
1767 else if (method==1){
1768 extractcontrolpoints2d->GetControlPoints( &vecCtrlPointX , &vecCtrlPointY , &vecCtrlPointZ );
1770 else if (method==2){
1771 extractcontrolpoints2d->SetSamplingControlPoints( 15 );
1772 extractcontrolpoints2d->GetSamplingControlPoints( &vecCtrlPointX , &vecCtrlPointY , &vecCtrlPointZ );
1774 //--Adding contour to the system
1776 std::vector<int> actualInstantVector;
1777 _instantPanel->getInstant( actualInstantVector );
1778 actualInstantVector[1]=z;
1780 int j,sizeCtrPt = vecCtrlPointX.size();
1782 manualBaseModel *manModelContour = kernelManager->factoryManualContourModel( typeofcontour );
1783 manModelContour->SetNumberOfPointsSpline( ((sizeCtrPt/100)+1)*100 );
1785 for (j=0 ; j<sizeCtrPt ; j++)
1787 manModelContour->AddPoint( vecCtrlPointX[j] , vecCtrlPointY[j] , vecCtrlPointZ[j] );
1789 std::string theName;
1790 //theName = _modelManager->createOutline( manModelContour, actualInstantVector );
1791 theName = kernelManager->createOutline( manModelContour, actualInstantVector );
1792 bool addedModel = theName.compare("") != 0;
1795 double spc[3];//Si no hay imagen pero hay contornos que spacing se pone por default
1796 _theViewPanel->getSpacing(spc);
1797 //Adding the manualContourControler to interface objects structure
1798 //Adding the manualViewContour to interface objects structure
1799 //_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.
1800 _theViewPanel->configureViewControlTo(theName, manModelContour, spc, typeofcontour);
1801 //_theViewPanel->getSceneManager()->configureViewControlTo( theName, manModelContour,spc, typeofcontour ) ;
1808 WriterType::Pointer writer = WriterType::New();
1809 CastFilterType3::Pointer caster = CastFilterType3::New();
1811 caster->SetInput( gradientMagnitude->GetOutput() );
1812 writer->SetInput( caster->GetOutput() );
1813 writer->SetFileName("Gradient Magnitude.png");
1814 caster->SetOutputMinimum( 0 );
1815 caster->SetOutputMaximum( 255 );
1818 CastFilterType3::Pointer caster2 = CastFilterType3::New();
1819 WriterType::Pointer writer2 = WriterType::New();
1821 caster2->SetInput( sigmoid->GetOutput() );
1822 writer2->SetInput( caster2->GetOutput() );
1823 writer2->SetFileName("Sigmoid.png");
1824 caster2->SetOutputMinimum( 0 );
1825 caster2->SetOutputMaximum( 255 );
1828 CastFilterType3::Pointer caster3 = CastFilterType3::New();
1829 WriterType::Pointer writer3 = WriterType::New();
1831 caster3->SetInput( fastMarching->GetOutput() );
1832 writer3->SetInput( caster3->GetOutput() );
1833 writer3->SetFileName("FastMarching.bmp");
1834 caster3->SetOutputMinimum( 0 );
1835 caster3->SetOutputMaximum( 255 );
1838 CastFilterType3::Pointer caster4 = CastFilterType3::New();
1839 WriterType::Pointer writer4 = WriterType::New();
1841 caster4->SetInput( geodesicActiveContour->GetOutput() );
1842 writer4->SetInput( caster4->GetOutput() );
1843 writer4->SetFileName("GeodesicActiveContour.png");
1844 caster4->SetOutputMinimum( 0 );
1845 caster4->SetOutputMaximum( 255 );
1848 CastFilterType3::Pointer caster5 = CastFilterType3::New();
1849 WriterType::Pointer writer5 = WriterType::New();
1851 caster5->SetInput( zeroCrossing->GetOutput() );
1852 writer5->SetInput( caster5->GetOutput() );
1853 writer5->SetFileName("ZeroCrossing.bmp");
1854 caster5->SetOutputMinimum( 0 );
1855 caster5->SetOutputMaximum( 255 );
1859 catch( itk::ExceptionObject & excep )
1861 std::cerr << "Exception caught !" << std::endl;
1862 std::cerr << excep << std::endl;
1866 void wxContourMainFrame::onSegmentationOneSlice(int isovalue,int sampling,int method){
1868 //JCP 20-10-08 Undo redo implementation
1870 //JCP 20-10-08 Undo redo implementation
1873 int x = _theViewPanel->GetX();
1874 int y = _theViewPanel->GetY();
1875 int z = _theViewPanel->GetZ();
1876 SegmentationOneSlice( x,y,z,isovalue, sampling, method );
1881 void wxContourMainFrame::SegmentationOneSlice( int x, int y, int z, int isovalue, int sampling, int method )
1883 int typeofcontour = 1;
1884 //--Extracting Contour
1885 //vtkImageData *imagedata = _theViewPanel->getSceneManager()->GetImageData();
1886 vtkImageData *imagedata = getImageData();
1887 // double *range = imagedata->GetScalarRange();
1890 vtkImageReslice *imageReslice = vtkImageReslice::New();
1893 // imagedata->GetSpacing(spc);
1898 //EED 2017-01-01 Migration VTK7
1899 #if VTK_MAJOR_VERSION <= 5
1900 imageReslice->SetInput( imagedata );
1902 imageReslice->SetInputData( imagedata );
1904 imageReslice->SetInformationInput(imagedata);
1905 imageReslice->SetResliceAxesDirectionCosines(1,0,0, 0,1,0 ,0,0,1);
1906 imageReslice->SetResliceAxesOrigin(0,0,z);
1907 imageReslice->SetOutputDimensionality(2);
1908 imageReslice->SetInterpolationModeToLinear();
1910 //EED 2017-01-01 Migration VTK7
1911 #if VTK_MAJOR_VERSION <= 5
1914 imageReslice->Update();
1917 imagedata = imageReslice->GetOutput();
1918 //EED 2017-01-01 Migration VTK7
1919 #if VTK_MAJOR_VERSION <= 5
1920 imagedata->Update();
1921 imagedata->UpdateInformation();
1926 vtkContourFilter* cntVTK = vtkContourFilter::New( );
1927 //EED 2017-01-01 Migration VTK7
1928 #if VTK_MAJOR_VERSION <= 5
1929 cntVTK->SetInput( imagedata );
1931 cntVTK->SetInputData( imagedata );
1934 cntVTK->SetNumberOfContours( 1 );
1935 //cntVTK->SetValue( 0, vmin );
1936 // cntVTK->SetValue( 0, (range[1]*thr/100) );
1937 cntVTK->SetValue( 1, isovalue );
1938 // cntVTK->SetValue( 1, vmax );
1940 cntVTK->UpdateInformation();
1942 vtkCleanPolyData* cpd = vtkCleanPolyData::New( );
1943 //EED 2017-01-01 Migration VTK7
1944 #if VTK_MAJOR_VERSION <= 5
1945 cpd->SetInput( cntVTK->GetOutput( ) );
1947 cpd->SetInputData( cntVTK->GetOutput( ) );
1949 cpd->ConvertLinesToPointsOff( );
1951 cpd->UpdateInformation();
1953 vtkPolyDataConnectivityFilter* conn = vtkPolyDataConnectivityFilter::New( );
1954 conn->SetExtractionModeToClosestPointRegion( );
1955 //conn->SetMaxRecursionDepth( 3000 );
1957 //EED 2017-01-01 Migration VTK7
1958 #if VTK_MAJOR_VERSION <= 5
1959 conn->SetInput( cpd->GetOutput( ) );
1961 conn->SetInputData( cpd->GetOutput( ) );
1964 conn->SetClosestPoint( x, y, 0 );
1966 conn->UpdateInformation();
1968 vtkCleanPolyData* cpd2 = vtkCleanPolyData::New( );
1969 //EED 2017-01-01 Migration VTK7
1970 #if VTK_MAJOR_VERSION <= 5
1971 cpd2->SetInput( conn->GetOutput( ) );
1973 cpd2->SetInputData( conn->GetOutput( ) );
1976 cpd2->UpdateInformation();
1978 vtkStripper* vtkstripper = vtkStripper::New( );
1979 //EED 2017-01-01 Migration VTK7
1980 #if VTK_MAJOR_VERSION <= 5
1981 vtkstripper->SetInput( cpd2->GetOutput() );
1983 vtkstripper->SetInputData( cpd2->GetOutput() );
1985 vtkstripper->Update();
1986 vtkstripper->UpdateInformation();
1989 vtkPolyData* polyDataResult = vtkstripper->GetOutput();
1991 //EED 2017-01-01 Migration VTK7
1992 #if VTK_MAJOR_VERSION <= 5
1993 polyDataResult->Update( );
1994 polyDataResult->UpdateInformation();
2001 myfile.open ("c:/temp/example.txt");
2003 polyDataResult->Print(myfile);
2004 myfile << "-------------------------------------\n";
2005 polyDataResult->GetLines()->Print(myfile);
2015 //--Calculating control points
2017 std::vector<double> vecX;
2018 std::vector<double> vecY;
2019 std::vector<double> vecZ;
2021 std::vector<double> vecCtrlPointX;
2022 std::vector<double> vecCtrlPointY;
2023 std::vector<double> vecCtrlPointZ;
2027 int ii,size=polyDataResult->GetNumberOfPoints();
2029 for (ii=1;ii<=size;ii++)
2031 id = polyDataResult->GetLines()->GetData()->GetValue(ii);
2032 p = polyDataResult->GetPoint(id);
2035 vecX.push_back( p[0] );
2036 vecY.push_back( p[1] );
2037 vecZ.push_back( 900 );
2038 // vecZ.push_back( p[2] );
2042 ExtractControlPoints2D *extractcontrolpoints2d = new ExtractControlPoints2D();
2043 extractcontrolpoints2d->SetContour( &vecX , &vecY , &vecZ );
2046 /*if (methodRadiobox->GetSelection()==0){
2047 extractcontrolpoints2d->GetInitialControlPoints( &vecCtrlPointX , &vecCtrlPointY , &vecCtrlPointZ );
2049 if (methodRadiobox->GetSelection()==1){
2050 extractcontrolpoints2d->GetControlPoints( &vecCtrlPointX , &vecCtrlPointY , &vecCtrlPointZ );
2052 if (methodRadiobox->GetSelection()==2){
2053 extractcontrolpoints2d->SetSamplingControlPoints( sampling );
2054 extractcontrolpoints2d->GetSamplingControlPoints( &vecCtrlPointX , &vecCtrlPointY , &vecCtrlPointZ );
2058 extractcontrolpoints2d->GetInitialControlPoints( &vecCtrlPointX , &vecCtrlPointY , &vecCtrlPointZ );
2060 else if (method==1){
2061 extractcontrolpoints2d->GetControlPoints( &vecCtrlPointX , &vecCtrlPointY , &vecCtrlPointZ );
2063 else if (method==2){
2064 extractcontrolpoints2d->SetSamplingControlPoints( sampling );
2065 extractcontrolpoints2d->GetSamplingControlPoints( &vecCtrlPointX , &vecCtrlPointY , &vecCtrlPointZ );
2068 //--Adding contour to the system
2070 std::vector<int> actualInstantVector;
2071 _instantPanel->getInstant( actualInstantVector );
2072 actualInstantVector[1]=z;
2074 int j,sizeCtrPt = vecCtrlPointX.size();
2075 manualBaseModel *manModelContour = kernelManager->factoryManualContourModel( typeofcontour );
2076 manModelContour->SetNumberOfPointsSpline( ((sizeCtrPt/100)+1)*100 );
2078 for (j=0 ; j<sizeCtrPt ; j++)
2080 manModelContour->AddPoint( vecCtrlPointX[j] , vecCtrlPointY[j] , vecCtrlPointZ[j] );
2082 std::string theName;
2083 //theName = _modelManager->createOutline( manModelContour, actualInstantVector );
2084 theName = kernelManager->createOutline( manModelContour, actualInstantVector );
2085 bool addedModel = theName.compare("") != 0;
2088 double spc[3];//Si no hay imagen pero hay contornos que spacing se pone por default
2089 _theViewPanel->getSpacing(spc);
2090 //Adding the manualContourControler to interface objects structure
2091 //Adding the manualViewContour to interface objects structure
2092 //_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.
2093 _theViewPanel->configureViewControlTo(theName, manModelContour, spc, typeofcontour);
2094 //_theViewPanel->getSceneManager()->configureViewControlTo( theName, manModelContour,spc, typeofcontour ) ;
2098 int wxContourMainFrame::GetImageDataSizeZ(){
2099 return _theViewPanel->GetImageDataSizeZ();
2102 void wxContourMainFrame::GetImageDataRange(double *range){
2103 _theViewPanel->GetImageDataRange(range);
2106 void wxContourMainFrame::onSegmentationAllSlice(int minZ,int maxZ,int isovalue,int sampling,int method){
2107 //JCP 20-10-08 Undo redo implementation
2109 //JCP 20-10-08 Undo redo implementation
2112 int x = _theViewPanel->GetX();
2113 int y = _theViewPanel->GetY();
2117 double totalZ = maxZ-minZ+1;
2118 for( z=minZ ; z<=maxZ ; z++ )
2120 porcent = 100.0* (z-minZ)/totalZ;
2121 tmpString.Printf(_T(" %d %c %d/%d %d"), (int)porcent , 37 , z-minZ+1, (int)totalZ,z );
2122 interfMainPanel::getInstance()->setLabelSegmentationPanelVTK(tmpString);
2123 //_staticTextSegmentation->SetLabel(tmpString);
2124 SegmentationOneSlice( x,y,z,isovalue, sampling,method );
2126 interfMainPanel::getInstance()->setLabelSegmentationPanelVTK(_T(" "));
2131 //Creates a reference line to be used as the axis of the mirroring
2132 void wxContourMainFrame::referenceLine()
2134 if (_refLineControl==NULL)
2139 vtkImageData *vtkimagedata = _theViewPanel->getImageData();
2140 vtkimagedata->GetSpacing(spc);
2142 wxVtkBaseView * viewer2D = _theViewPanel->getWxVtkBaseView();
2144 _refLineControl = new manualLineControler();
2145 _refLineModel = new manualContourModelLine();
2146 _refLineView = new manualViewLine();
2147 _refLineView->SetModel( _refLineModel );
2148 _refLineView->SetWxVtkBaseView( viewer2D );
2149 _refLineView->SetRange( 2 );
2150 _refLineView->SetZ( 1200 );
2152 _refLineView->SetSpacing(spc);
2154 _refLineView->SetColorNormalContour(0, 0, 1);
2155 _refLineView->SetColorEditContour(0, 0.5, 0.5);
2156 _refLineView->SetWidthLine(4);
2158 _refLineControl->SetModelView( _refLineModel , _refLineView );
2159 vtkInteractorStyleBaseView* style = (vtkInteractorStyleBaseView*)viewer2D->GetInteractorStyleBaseView();
2160 style->AddInteractorStyleMaracas( _refLineControl );
2161 _refLineModel->SetCloseContour(false);
2162 _refLineControl->CreateNewManualContour();
2164 //AD: Inicializar el mirroring con una linea ya pintada
2166 double z = _refLineControl->GetZ();
2169 image->GetDimensions(imageDim);
2170 double x = (double) imageDim[0]/2;
2171 double y1 = (double) (imageDim[1]/2)+15;
2172 double y2 = (double) (imageDim[1]/2)-15;
2174 _refLineControl->AddPoint(x,y1,z);
2175 _refLineControl->AddPoint(x,y2,z);
2176 _refLineControl->SetCompleteCreation(true);
2178 _refLineModel->AddPoint(x,y1,z);
2179 _refLineModel->AddPoint(x,y2,z);
2180 _refLineModel->UpdateSpline();
2182 _refLineView->UpdateViewPoint(0);
2183 _refLineView->UpdateViewPoint(1);
2186 _refLineControl->SetActive(true);
2187 _refLineView->RefreshContour();
2191 //Hides the referenceLine
2192 void wxContourMainFrame::refLineHide()
2194 if (_refLineControl!=NULL)
2196 if (_refLineControl->GetActive())
2198 _refLineView->RemoveCompleteContourActor();
2199 _refLineControl->SetEditable(false);
2200 _refLineControl->SetActive(false);
2207 //Shows the referenceLine
2208 void wxContourMainFrame::refLineShow()
2210 if (_refLineControl!=NULL)
2212 if (_refLineControl->GetActive()==false)
2214 wxVtkBaseView * viewer2D = _theViewPanel->getWxVtkBaseView();
2216 _refLineView->SetModel( _refLineModel );
2217 _refLineView->SetWxVtkBaseView( viewer2D );
2218 _refLineView->SetRange( 2 );
2219 _refLineView->SetZ( 1200 );
2221 _refLineControl->SetModelView( _refLineModel , _refLineView );
2222 vtkInteractorStyleBaseView* style = (vtkInteractorStyleBaseView*)viewer2D->GetInteractorStyleBaseView();
2223 style->AddInteractorStyleMaracas( _refLineControl );
2224 _refLineControl->CreateNewManualContour();
2225 _refLineControl->SetActive(true);
2226 _refLineView->RefreshContour();
2233 void wxContourMainFrame::refLineChangeWidth(int width)
2235 _refLineView->SetWidthLine(width);
2236 _refLineView->RefreshContour();
2242 void wxContourMainFrame::onMirror()
2245 std::vector<std::string> currentSelection = _theViewPanel->getSelectedObjects();
2246 std::vector<std::string> filterCurrentSelection;
2248 std::vector<int> tempVector;
2249 _instantPanel->getInstant( tempVector );
2250 _performingOperation->reset();
2251 _performingOperation->setStartCommand( COPY );
2252 _performingOperation->setStartOperationInstantVector( tempVector );
2253 _performingOperation->setKeyNamesOperationElems( currentSelection );
2255 char theStartCommand = _performingOperation->getStartCommand();
2256 if ( theStartCommand == COPY )
2258 //JCP 20-10-08 Undo redo implementation
2260 //JCP 20-10-08 Undo redo implementation
2261 std::vector<int> tempVector;
2262 _instantPanel->getInstant( tempVector );
2263 _performingOperation->setEndOperationInstantVector ( tempVector );
2264 std::vector<std::string> elems = _performingOperation->getKeyNamesOperationElems();
2265 int i,size = elems.size();
2266 for( i=0; i<size; i++ )
2268 createMirrorContourOf( elems[i], tempVector, i>0 );
2272 //deleteContour( _refName );
2277 void wxContourMainFrame::showAxis(bool show)
2279 _theViewPanel->SetVisibleAxis(show);
2280 _theViewPanel->Refresh();
2284 void wxContourMainFrame::onRigidPressed(){
2285 std::vector<std::string> currentSelection = _theViewPanel->getSelectedObjects();
2286 int elementsSelected = currentSelection.size();
2288 if ( elementsSelected >= 1 ){
2289 //JCP 20-10-08 Undo redo implementation
2291 //JCP 20-10-08 Undo redo implementation
2293 std::vector<int> tempVector;
2294 _instantPanel->getInstant( tempVector );
2295 Instant instant(&tempVector);
2297 int i , size=currentSelection.size();
2298 for ( i=0 ; i<size ; i++ )
2300 kernelManager->changeContourOfManager(currentSelection[i], &instant);
2305 void wxContourMainFrame::onWidthOfContour(double width){
2307 _theViewPanel->removeSceneContours();
2308 _theViewPanel->SetWidthContour(width);
2310 //_theViewPanel->getSceneManager()->SetWidthContour( width );
2315 int wxContourMainFrame::getColorWindow()
2319 vtkImageData * img = getImageData();
2320 img->GetScalarRange(range);
2322 std::cout<<"Val 1: "<<range[0]<<" Val 2: "<<range[1]<<std::endl;
2324 return (int)range[1];
2326 return _theViewPanel->getColorWindow();
2329 int wxContourMainFrame::getWindowLevel()
2333 vtkImageData * img = getImageData();
2334 img->GetScalarRange(range);
2336 std::cout<<"Val 1: "<<range[0]<<" Val 2: "<<range[1]<<std::endl;
2338 return (int)range[1];
2340 return _theViewPanel->getWindowLevel();
2343 void wxContourMainFrame::onBrigthnessColorWindowLevel(int colorwindow,int windowlevel)
2345 _theViewPanel->onBrigthnessColorWindowLevel(colorwindow, windowlevel);
2350 void wxContourMainFrame::onInterpolation(bool interpolate)
2352 _theViewPanel->onInterpolation(interpolate);
2356 void wxContourMainFrame::onChangeInstant(std::string name,int actual)
2358 _instantPanel->setConceptValue( name, actual );
2362 void wxContourMainFrame::resetAppend()
2364 kernelManager->resetAppend();
2368 void wxContourMainFrame::onSpreadAdd()
2370 std::vector<double> vecX;
2371 std::vector<double> vecY;
2372 std::vector<double> vecZ;
2373 _theViewPanel->GetPointsOfActualContour(&vecX , &vecY , &vecZ );
2374 std::vector<int> tempVector;
2375 _instantPanel->getInstant( tempVector );
2376 std::string val = kernelManager->onSpreadAdd(&vecX , &vecY , &vecZ, tempVector);
2377 interfMainPanel::getInstance()->appendStringSpread(val);
2381 void wxContourMainFrame::onSpreadAddAll()
2384 std::vector<int> tempVector;
2385 _instantPanel->getInstant( tempVector );
2388 maxZ = interfMainPanel::getInstance()->GetImageDataSizeZ();
2390 int sizeLstContourThings;
2391 for ( z=minZ ; z<=maxZ ; z++ )
2394 Instant instant(&tempVector);
2395 std::vector<ContourThing**> lstContourThings = kernelManager->getOutlinesAtInstant( &instant );
2396 sizeLstContourThings = lstContourThings.size();
2397 if (sizeLstContourThings>=1)
2399 std::vector<double> vecX;
2400 std::vector<double> vecY;
2401 std::vector<double> vecZ;
2402 ContourThing **contourthing = lstContourThings[0];
2403 manualBaseModel *cModel = (*contourthing)->getModel();
2404 int i,size = cModel->GetNumberOfPointsSpline();
2406 for (i=0; i<size; i++)
2408 cModel->GetSpline_i_Point(i, &x, &y, &z);
2413 std::string val = kernelManager->onSpreadAdd(&vecX , &vecY , &vecZ, tempVector);
2414 interfMainPanel::getInstance()->appendStringSpread(val);
2415 }// if sizeLstContourThings
2420 void wxContourMainFrame::onSpreadGo(int type)
2422 //JCP 20-10-08 Undo redo implementation
2424 //JCP 20-10-08 Undo redo implementation
2426 std::vector<double> vecCtrlPointX;
2427 std::vector<double> vecCtrlPointY;
2428 std::vector<double> vecCtrlPointZ;
2432 std::vector<int> tempVector;
2433 _instantPanel->getInstant( tempVector );
2436 kernelManager->getMaxMinZ(&minZ,&maxZ);
2437 //JSTG_16-07-08_----------------------------------------------------------------
2438 //_contourPropagation->setInterpolationNumber(maxZ-minZ+1);
2439 kernelManager->CalculeSplinePropagation();
2441 double totalZ = maxZ-minZ+1;
2444 //--------------------------------------------------------------------
2445 for ( z=(int)minZ ; z<=(int)maxZ ; z++ )
2447 porcent = 100.0* (z-minZ)/totalZ;
2448 int numero = (int)(z-minZ+1)/(int)totalZ;
2449 std::string stringtemp = " "+kernelManager->intToString(porcent)+"% "+kernelManager->intToString(numero)+" "+kernelManager->intToString(z);
2451 interfMainPanel::getInstance()->setStringSpread(stringtemp);
2453 int typeofcontour = 1;
2454 std::string theName;
2455 manualBaseModel* manModelContour = kernelManager->GetPoints(z, type, &vecCtrlPointX,&vecCtrlPointY,&vecCtrlPointZ, theName,typeofcontour, tempVector);
2457 if( manModelContour!=NULL ){
2458 double spc[3];//Si no hay imagen pero hay contornos que spacing se pone por default
2459 this->_theViewPanel->getSpacing(spc);
2460 //Adding the manualContourControler to interface objects structure
2461 //Adding the manualViewContour to interface objects structure
2462 //_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.
2463 _theViewPanel->configureViewControlTo( theName, manModelContour,spc,typeofcontour ) ;
2468 int numero = (int)(z-minZ+1)/(int)totalZ;
2469 std::string stringtemp = " "+kernelManager->intToString(porcent)+"% "+kernelManager->intToString(numero)+" "+kernelManager->intToString(z);
2471 interfMainPanel::getInstance()->setStringSpread(stringtemp);
2473 //RefreshInterface();
2476 void wxContourMainFrame::getInstantVector(std::vector<int>& tempVector)
2480 std::vector<std::string> wxContourMainFrame::getOutlinesName(int slide)
2482 std::vector<int> tempVector;
2483 _instantPanel->getInstant(tempVector);
2484 //Asignation of slide number should be different ex by name
2485 tempVector[1]=slide;
2486 return kernelManager->getOutlinesNameAtInstant(tempVector);
2490 void wxContourMainFrame::SetScalarRange(int grayRangeMin, int grayRangeMax)
2492 _contourextractdata->SetScalarRange(grayRangeMin,grayRangeMax);
2496 void wxContourMainFrame::onInformationContourLabels(int typeContourGroup,int selection,int minimumZ,int maximumZ,int grayRangeMin, int grayRangeMax)
2499 wxString tempString;
2500 int maxContourGroup = 0;
2502 _contourextractdata ->SetTypeOperation( typeContourGroup % 3 );
2504 std::vector<manualBaseModel*> lstManConMod;
2505 std::vector<manualBaseModel*> lstManConModTmp;
2506 std::vector<manualBaseModel*> lstManConModExp;
2507 std::vector<double> pLstValue;
2508 std::vector<double> pLstValuePosX;
2509 std::vector<double> pLstValuePosY;
2510 std::vector<double> pLstValuePosZ;
2513 int resultGrayRangeCount;
2516 double resultAverage;
2517 double resultStandardeviation;
2519 std::vector<int> tempVector;
2520 _instantPanel->getInstant( tempVector );
2523 int ii,sizeLstContourThings;
2532 if (selection==0 ) // actual slice
2534 int actualSlice = tempVector[1];
2537 } else { // slice range
2543 totalZ = maxZ-minZ+1;
2545 _contourextractdata->InitVolumeStatistics();
2548 for ( z=minZ ; z<=maxZ ; z++ )
2551 porcent = 100.0* (z-minZ)/totalZ;
2552 tmpString.Printf(_T(" %d %c %d/%d %d"), (int)porcent , 37 , z-minZ+1, (int)totalZ ,z);
2554 interfMainPanel::getInstance()->setStringInfoPanel(tmpString);
2555 //_staticTextInformation->SetLabel(tmpString);
2557 //Extraction data from contours of each slice
2558 _contourextractdata->SetZtoBeAnalys(z);
2561 Instant instant(&tempVector);
2562 std::vector<ContourThing**> lstContourThings = kernelManager->getOutlinesAtInstant( &instant );
2563 sizeLstContourThings = lstContourThings.size();
2565 lstManConMod.clear();
2566 for (ii=0 ; ii<sizeLstContourThings ; ii++)
2568 ContourThing **contourthing = lstContourThings[ii];
2569 lstManConMod.push_back( (*contourthing)->getModel() );
2572 lstManConModExp = kernelManager->ExploseEachModel( lstManConMod );
2574 tempString.Printf(_T("%d - %d"),z, sizeLstContourThings);
2575 interfMainPanel::getInstance()->setRowLabelInfoPanel(z, tempString);
2576 //_grid->SetRowLabelValue(z, tempString );
2578 int iContourGroup,sizeContourGroup;
2579 if (typeContourGroup==3) // contour separete
2581 sizeContourGroup=lstManConModExp.size();
2582 if ( maxContourGroup<sizeContourGroup )
2584 maxContourGroup=sizeContourGroup;
2586 } else { // contour AND OR XOR
2593 for( iContourGroup=0 ; iContourGroup<sizeContourGroup ; iContourGroup++ ){
2594 lstManConModTmp.clear();
2598 if (typeContourGroup==3) // contour separete
2600 lstManConModTmp.push_back( lstManConModExp[iContourGroup]);
2601 } else { // contour AND OR XOR
2602 lstManConModTmp = lstManConModExp;
2605 _contourextractdata->SetLstManualContourModel( lstManConModTmp );
2606 _contourextractdata->SetScalarRange(grayRangeMin,grayRangeMax);
2609 pLstValuePosX.clear();
2610 pLstValuePosY.clear();
2611 pLstValuePosZ.clear();
2615 _contourextractdata->GetValuesInsideCrown( &numberOfPixels,
2621 resultSize=numberOfPixels;
2622 // Statistics of each slice.
2623 _contourextractdata->Statistics( &pLstValue,
2626 &resultGrayRangeCount,
2631 &resultStandardeviation);
2633 if (interfMainPanel::getInstance()->getNumberColsInformationPanel()<_numberOfVariablesStatistics*(iContourGroup+1) )
2635 interfMainPanel::getInstance()->appendColsInformationPanel(_numberOfVariablesStatistics);
2638 tmpIntA=_numberOfVariablesStatistics*iContourGroup ;
2640 tempString.Printf(_T("%d"),numberOfPixels);
2642 interfMainPanel::getInstance()->setCellValueInfoPanel(z, tmpIntA, tempString);
2644 tempString.Printf(_T("%d"),resultGrayRangeCount);
2645 interfMainPanel::getInstance()->setCellValueInfoPanel(z, tmpIntA+1, tempString);
2647 tempString.Printf(_T("%f"),resultMin);
2648 interfMainPanel::getInstance()->setCellValueInfoPanel(z, tmpIntA+2, tempString);
2650 tempString.Printf(_T("%f"),resultMax);
2651 interfMainPanel::getInstance()->setCellValueInfoPanel(z, tmpIntA+3, tempString);
2653 tempString.Printf(_T("%f"),resultAverage);
2654 interfMainPanel::getInstance()->setCellValueInfoPanel(z, tmpIntA+4, tempString);
2656 tempString.Printf(_T("%f"),resultStandardeviation);
2657 interfMainPanel::getInstance()->setCellValueInfoPanel(z, tmpIntA+5, tempString);
2660 } // for iContourGroup
2663 // Print Volume Statistics
2666 int vol_rCountRange;
2668 double vol_minValue;
2669 double vol_maxValue;
2671 double vol_standardeviation;
2673 if (selection!=0 ) // actual slice
2676 _contourextractdata->GetVolumeStatistics(&vol_rCountRange, &vol_rsize,
2677 &vol_minValue, &vol_maxValue,
2678 &vol_average, &vol_standardeviation);
2680 interfMainPanel::getInstance()->setRowLabelInfoPanel(maxZ+2, _T("Total:"));
2682 tempString.Printf(_T("%d"),vol_rsize);
2683 interfMainPanel::getInstance()->setCellValueInfoPanel(maxZ+2, 0, tempString);
2685 tempString.Printf(_T("%d"),vol_rCountRange);
2686 interfMainPanel::getInstance()->setCellValueInfoPanel(maxZ+2, 1, tempString);
2688 tempString.Printf(_T("%f"),vol_minValue);
2689 interfMainPanel::getInstance()->setCellValueInfoPanel(maxZ+2, 2, tempString);
2691 tempString.Printf(_T("%f"),vol_maxValue);
2692 interfMainPanel::getInstance()->setCellValueInfoPanel(maxZ+2, 3, tempString);
2694 tempString.Printf(_T("%f"),vol_average);
2695 interfMainPanel::getInstance()->setCellValueInfoPanel(maxZ+2, 4, tempString);
2697 tempString.Printf(_T("%f"),vol_standardeviation);
2698 interfMainPanel::getInstance()->setCellValueInfoPanel(maxZ+2, 5, tempString);
2700 //-----------------------------------------
2703 wxString tmpTitleString;
2705 for ( iTitleGroup=0 ; iTitleGroup<maxContourGroup ; iTitleGroup++ )
2707 tmpIntB =_numberOfVariablesStatistics*iTitleGroup;
2708 tmpTitleString.Printf(_T("%d-Size Data"),iTitleGroup);
2709 interfMainPanel::getInstance()->setColLableInfoPanel(tmpIntB + 0, tmpTitleString);
2711 interfMainPanel::getInstance()->setColLableInfoPanel(tmpIntB + 0, tmpTitleString );
2712 interfMainPanel::getInstance()->setColLableInfoPanel( tmpIntB + 1, _T("Size Range") );
2713 interfMainPanel::getInstance()->setColLableInfoPanel( tmpIntB + 2, _T("Min") );
2714 interfMainPanel::getInstance()->setColLableInfoPanel( tmpIntB + 3, _T("Max") );
2715 interfMainPanel::getInstance()->setColLableInfoPanel( tmpIntB + 4, _T("Average") );
2716 interfMainPanel::getInstance()->setColLableInfoPanel( tmpIntB + 5, _T("St.Dev.") );
2717 interfMainPanel::getInstance()->setColLableInfoPanel( tmpIntB + 6, _T(" ") );
2719 interfMainPanel::getInstance()->setStringInfoPanel( _T("") );
2723 void wxContourMainFrame::onSaveResults(std::string directory,std::string namefile, std::string filename,
2724 int typeContourGroup, int selection, int minZ, int maxZ, bool XYZValues, bool contourImage, bool statistics)
2728 SaveValuesXYZ( directory , namefile, typeContourGroup );
2733 vtkImageData * mask;
2734 vtkImageData * value;
2735 this->getMaskValue(&mask, &value, typeContourGroup,selection,minZ,maxZ);
2736 this->SaveImageResult( directory , namefile, mask, value);
2741 std::ostringstream name;
2742 name << filename << ".xls";
2745 FILE *pFile=fopen(name.str().c_str(),"w+");
2751 // int sizeZ = _theViewPanel->GetImageDataSizeZ();
2752 // int maxY=sizeZ+2;
2754 maxX= interfMainPanel::getInstance()->getNumberColsInformationPanel();//this->_grid->GetNumberCols();
2757 int iTitle,sizeTitle = (maxX / _numberOfVariablesStatistics);
2758 for ( iTitle=0; iTitle<sizeTitle ; iTitle++)
2760 // fprintf(pFile,"-- \t %d-Size \t SizeRange \t Min \t Max \t Ave \t StDv \t" , iTitle,tmpString.c_str() );
2761 fprintf(pFile,"slice\t %d-Size \t SizeRange \t Min \t Max \t Ave \t StDv \t" , iTitle );
2763 fprintf(pFile,"\n\n" );
2767 if (selection==0 ) // actual slice
2769 std::vector<int> tempVector;
2770 _instantPanel->getInstant( tempVector );
2771 int actualSlice = tempVector[1];
2777 for ( j=minZ; j<=maxZ ; j++)
2779 fprintf(pFile,"%d\t" , j );
2780 for (i=0 ; i<maxX ; i++){
2781 tmpString = interfMainPanel::getInstance()->getCellValue(j, i);//_grid->GetCellValue( j , i );
2782 fprintf(pFile,"%s\t" , (const char *)(tmpString.mb_str()) );
2784 fprintf(pFile,"\n" );
2788 // Total of stadistics.....
2791 fprintf(pFile,"\n Total:\t" );
2792 for (i=0 ; i<maxX ; i++){
2793 tmpString = interfMainPanel::getInstance()->getCellValue(maxZ+2, i);//_grid->GetCellValue( maxZ+2 , i );
2794 fprintf(pFile,"%s\t" , (const char *)(tmpString.mb_str()) );
2796 fprintf(pFile,"\n" );
2804 void wxContourMainFrame::SaveValuesXYZ(std::string directory,std::string namefile,int typeContourGroup)
2808 //int typeContourGroup = this->_radiolstboxContourGroup->GetSelection();
2809 _contourextractdata ->SetTypeOperation( typeContourGroup % 3 );
2811 std::vector<manualBaseModel*> lstManConMod;
2812 std::vector<manualBaseModel*> lstManConModTmp;
2813 std::vector<manualBaseModel*> lstManConModExp;
2814 std::vector<double> pLstValue;
2815 std::vector<double> pLstValuePosX;
2816 std::vector<double> pLstValuePosY;
2817 std::vector<double> pLstValuePosZ;
2819 std::vector<int> tempVector;
2820 _instantPanel->getInstant( tempVector );
2822 int sizeZ = _theViewPanel->getSceneManager()->GetImageDataSizeZ();
2824 int ii,sizeLstContourThings;
2831 minZ = 0;// _mbarrange->GetStart();
2832 maxZ = sizeZ;//_mbarrange->GetEnd();
2833 totalZ = maxZ-minZ+1;
2837 for ( z=0 ; z<sizeZ ; z++)
2840 porcent = 100.0* (z-minZ)/totalZ;
2842 tmpString.Printf(_T("Saving Values"));
2843 tmpString.Printf(_T(" %d %c %d/%d %d"), (int)porcent , 37 , z-minZ+1, (int)totalZ ,z);
2844 interfMainPanel::getInstance()->setStringInfoPanel(tmpString);
2845 //_staticTextInformation->SetLabel(tmpString);
2848 //Extraction data from contours of each slice
2849 _contourextractdata->SetZtoBeAnalys( z);
2852 Instant instant(&tempVector);
2853 std::vector<ContourThing**> lstContourThings = kernelManager->getOutlinesAtInstant(&instant);//this->_modelManager->getOutlinesAtInstant( &instant );
2854 sizeLstContourThings = lstContourThings.size();
2856 lstManConMod.clear();
2857 for (ii=0 ; ii<sizeLstContourThings ; ii++)
2859 ContourThing **contourthing = lstContourThings[ii];
2860 lstManConMod.push_back( (*contourthing)->getModel() );
2862 lstManConModExp = kernelManager->ExploseEachModel( lstManConMod );
2867 int iContourGroup,sizeContourGroup;
2868 if (typeContourGroup==3) // contour separete
2870 sizeContourGroup=lstManConModExp.size();
2871 } else { // contour AND OR XOR
2875 for( iContourGroup=0 ; iContourGroup<sizeContourGroup ; iContourGroup++ ){
2876 lstManConModTmp.clear();
2877 if (typeContourGroup==3) // contour separete
2879 lstManConModTmp.push_back( lstManConModExp[iContourGroup]);
2880 } else { // contour AND OR XOR
2881 lstManConModTmp = lstManConModExp;
2884 _contourextractdata->SetLstManualContourModel( lstManConModTmp );
2887 pLstValuePosX.clear();
2888 pLstValuePosY.clear();
2889 pLstValuePosZ.clear();
2891 _contourextractdata->GetValuesInsideCrown( &numberOfPixels,
2897 std::string temp = directory + "/" + namefile + "-slice";
2898 temp = temp + kernelManager->intToString(z) + "-cont" + kernelManager->intToString(iContourGroup);
2899 temp = temp + ".txt";
2901 // LG 14/01/09 : using crea
2902 wxString filename = crea::std2wx(temp);
2903 /*filename.Printf(_T("%s"),directory.c_str());
2904 filename.append(_T("\\"));
2905 filename.append(_T("%s"),namefile.c_str());
2906 filename.append(_T("-slice"));
2907 filename.append(_T("%d"),z);
2908 filename.append(_T("-cont"));
2909 filename.append(_T("%d"),iContourGroup);
2910 filename.append(_T(".txt"));*/
2911 // filename.Printf(temp.c_str());
2915 FILE *pFile=fopen((const char *)filename.mb_str(),"w+");
2916 fprintf(pFile,"value \t x \t y \t z\n" );
2917 int iLstValue,sizeLstValue=pLstValue.size();
2918 for (iLstValue=0 ; iLstValue<sizeLstValue ; iLstValue++ )
2920 fprintf(pFile,"%f\t %f\t %f\t %f\n", (float)pLstValue[iLstValue] , (float)pLstValuePosX[iLstValue], (float)pLstValuePosY[iLstValue], (float)z );
2923 } // for iContourGroup
2925 interfMainPanel::getInstance()->setStringInfoPanel(_T(""));
2926 //_staticTextInformation->SetLabel( _T("") );
2930 void wxContourMainFrame::getMaskValue(vtkImageData ** mask,vtkImageData ** value,int typeContourGroup, int selection, int minZ, int maxZ){
2933 //int typeContourGroup = this->_radiolstboxContourGroup->GetSelection();
2934 if (typeContourGroup==3)
2938 _contourextractdata ->SetTypeOperation( typeContourGroup % 3 );
2940 std::vector<manualBaseModel*> lstManConMod;
2941 std::vector<manualBaseModel*> lstManConModTmp;
2942 std::vector<manualBaseModel*> lstManConModExp;
2944 std::vector<int> tempVector;
2945 _instantPanel->getInstant( tempVector );
2947 vtkImageData *imagedata = _theViewPanel->getImageData();
2949 imagedata->GetExtent(ext);
2950 int sizeZimage = ext[5]-ext[4]+1;
2952 int ii,sizeLstContourThings;
2961 if (selection==0 ) // actual slice
2963 int actualSlice = tempVector[1];
2971 // cleanning image before range
2972 for (z=0; z<minZ; z++){
2973 _contourextractdata->ResetImageResult(z);
2975 // cleanning image after range
2976 for (z=maxZ+1; z<sizeZimage; z++){
2977 _contourextractdata->ResetImageResult(z);
2982 for ( z=minZ ; z<=maxZ ; z++)
2985 porcent = 100.0* (z-minZ)/totalZ;
2986 tmpString.Printf(_T("Saving Values"));
2987 tmpString.Printf(_T("%d %c %d/%d %d"), (int)porcent , 37 , z-minZ+1, (int)totalZ ,z);
2988 interfMainPanel::getInstance()->setStringInfoPanel(tmpString);
2990 //Extraction data from contours of each slice
2991 _contourextractdata->SetZtoBeAnalys( z);
2994 Instant instant(&tempVector);
2995 std::vector<ContourThing**> lstContourThings = kernelManager->getOutlinesAtInstant( &instant );
2996 sizeLstContourThings = lstContourThings.size();
2998 lstManConMod.clear();
2999 for (ii=0 ; ii<sizeLstContourThings ; ii++)
3001 ContourThing **contourthing = lstContourThings[ii];
3002 lstManConMod.push_back( (*contourthing)->getModel() );
3004 lstManConModExp = kernelManager->ExploseEachModel( lstManConMod );
3007 int iContourGroup,sizeContourGroup;
3008 if (typeContourGroup==3) // contour separete
3010 sizeContourGroup=lstManConModExp.size();
3011 } else { // contour AND OR XOR
3015 for( iContourGroup=0 ; iContourGroup<sizeContourGroup ; iContourGroup++ ){
3016 lstManConModTmp.clear();
3017 if (typeContourGroup==3) // contour separete
3019 lstManConModTmp.push_back( lstManConModExp[iContourGroup]);
3020 } else { // contour AND OR XOR
3021 lstManConModTmp = lstManConModExp;
3024 _contourextractdata->SetLstManualContourModel( lstManConModTmp );
3025 _contourextractdata->CalculateImageResult(); // with actual Z
3027 } // for iContourGroup
3030 (*value) = _contourextractdata->GetVtkImageValueResult();
3031 (*mask) = _contourextractdata->GetVtkImageMaskResult();
3035 void wxContourMainFrame::SaveImageResult(std::string directory,std::string namefile, vtkImageData* mask,vtkImageData* value)
3039 kernelManager->GetSpacing(spc,0); // returns the spacing of the first image
3041 std::string temp = directory + "/" + namefile + "-image-Value.mhd";
3043 wxString filename = crea::std2wx(temp);
3047 vtkImageChangeInformation *valueChInfo = vtkImageChangeInformation::New();
3048 //EED 2017-01-01 Migration VTK7
3049 #if VTK_MAJOR_VERSION <= 5
3050 valueChInfo->SetInput(value);
3052 valueChInfo->SetInputData(value);
3054 valueChInfo->SetSpacingScale(spc);
3055 vtkMetaImageWriter *writerValueImage = vtkMetaImageWriter::New( );
3057 //EED 2017-01-01 Migration VTK7
3058 #if VTK_MAJOR_VERSION <= 5
3059 writerValueImage->SetInput( valueChInfo->GetOutput() );
3061 writerValueImage->SetInputData( valueChInfo->GetOutput() );
3063 writerValueImage->SetFileName( (const char *)filename.mb_str() );
3064 writerValueImage->SetFileDimensionality( 3 );
3065 writerValueImage->SetCompression(false);
3066 writerValueImage->Write( );
3069 temp = directory + "/" + namefile + "-image-Mask.mhd";
3071 // LG 14/01/09 : using crea
3072 filename = crea::std2wx(temp);
3073 // filename.Printf(_T(temp.c_str()));
3076 vtkImageChangeInformation *maskChInfo = vtkImageChangeInformation::New();
3077 //EED 2017-01-01 Migration VTK7
3078 #if VTK_MAJOR_VERSION <= 5
3079 maskChInfo->SetInput(mask);
3081 maskChInfo->SetInputData(mask);
3083 maskChInfo->SetSpacingScale(spc);
3084 vtkMetaImageWriter *writerMaskImage = vtkMetaImageWriter::New( );
3086 //EED 2017-01-01 Migration VTK7
3087 #if VTK_MAJOR_VERSION <= 5
3088 writerMaskImage->SetInput( maskChInfo->GetOutput() );
3090 writerMaskImage->SetInputData( maskChInfo->GetOutput() );
3093 writerMaskImage->SetFileName( (const char *)filename.mb_str() );
3094 writerMaskImage->SetFileDimensionality( 3 );
3095 writerMaskImage->SetCompression(false);
3096 writerMaskImage->Write( );
3098 interfMainPanel::getInstance()->setStringInfoPanel( _T("") );
3104 void wxContourMainFrame::onChangeInstantInstantPanel(std::string name,int value, int minshow, int maxshow){
3105 if( name.compare( _theViewPanel->getVerticalConceptName() ) == 0){
3106 _theViewPanel->setActualVertical( value);
3108 else if( name.compare( _theViewPanel->getHorizontalConceptName() ) == 0|| _instantPanel->getIfConceptCheckedAt( name, 0 ) ) {
3109 _theViewPanel->setHorizontalConcept( name, minshow, maxshow, minshow, maxshow, value);
3115 void wxContourMainFrame::onSnakePressed(){
3116 std::vector<double> vecX;
3117 std::vector<double> vecY;
3118 std::vector<double> vecZ;
3119 _theViewPanel->GetPointsOfActualContour( &vecX , &vecY , &vecZ );
3121 if (vecX.size()!=0){
3122 std::vector<int> tempVector;
3123 _instantPanel->getInstant( tempVector );
3124 int i,size=vecZ.size();
3125 int actualSlice = tempVector[1];
3126 for ( i=0 ; i<size ; i++ )
3128 vecZ[i] = actualSlice;
3131 wxDialog* dialog = new wxDialog(this, -1, wxString(_T("Snake")));
3132 wxPanel* panel = new wxPanel(dialog,-1);
3133 // wxStaticText* sttext = new wxStaticText(panel, -1, wxString(_T("Panel para snake")));
3134 new wxStaticText(panel, -1, wxString(_T("Panel para snake")));
3135 dialog->ShowModal();
3140 void wxContourMainFrame::saveFileWithContoursAutomatique(){
3141 std::string filename = kernelManager->getCurrentFileName();
3142 if(filename.compare("")!=0){
3143 saveFileWithContours(filename);
3148 void wxContourMainFrame::ShowToolsPanel(bool show){
3149 _pannew->Show(show);
3154 void wxContourMainFrame::SetContourGroup(int contourGroup)
3156 _contourGroup = contourGroup;
3160 wxPanel *wxContourMainFrame::getMaskImageViewPanel(wxWindow *parent)
3163 if (_viewMaskImagePanel==NULL)
3165 _contourextractdata = new ContourExtractData(true);
3166 _contourextractdata->SetImage( _theViewPanel->getImageData() );
3168 // _theViewPanel->getImageData()->GetScalarRange(range);
3169 //int min = (int)floor (range[0]);
3170 //int max = (int)ceil (range[1]);
3173 _viewMaskImagePanel = new ThresholdImageViewPanel( parent, -1, -1 , 0);
3174 _viewMaskImage = new ThresholdImageView();
3175 _viewMaskImage->SetImage(_contourextractdata->GetVtkImageMaskResult() );
3176 _viewMaskImage->SetminMaxValue( min, max);
3177 _viewMaskImage->SetBaseColor( 0,0,1 );
3178 _viewMaskImagePanel->SetThresholdImageView( _viewMaskImage );
3179 _viewMaskImage->SetwxVtkBaseView( _theViewPanel->getWxVtkBaseView() );
3181 return _viewMaskImagePanel;
3185 wxPanel *wxContourMainFrame::getColorLayerImageViewPanel(wxWindow *parent)
3187 if (_viewColorLayerImagePanel==NULL)
3190 _theViewPanel->getImageData()->GetScalarRange(range);
3191 int min = (int)floor (range[0]);
3192 int max = (int)ceil (range[1]);
3193 _viewColorLayerImagePanel = new ColorLayerImageViewPanel( parent, min, max, 100, 1);
3194 _viewColorLayerImagePanel->GetColorLayerImageViewManager()->SetwxVtkBaseView( 0 , _theViewPanel->getWxVtkBaseView() );
3196 return _viewColorLayerImagePanel;
3200 wxPanel *wxContourMainFrame::getThresholdImageViewPanel(wxWindow *parent)
3202 if (_viewThresholdImagePanel==NULL)
3205 _theViewPanel->getImageData()->GetScalarRange(range);
3206 int min = (int)floor (range[0]);
3207 int max = (int)ceil (range[1]);
3208 _viewThresholdImagePanel = new ThresholdImageViewPanel( parent, min, max , 1);
3209 _viewThresholdImage = new ThresholdImageView();
3210 _viewThresholdImage->SetImage( _theViewPanel->getImageData() );
3211 _viewThresholdImage->SetminMaxValue( min, max);
3212 _viewThresholdImage->SetBaseColor( 1,0,0 );
3213 _viewThresholdImagePanel->SetThresholdImageView( _viewThresholdImage );
3214 _viewThresholdImage->SetwxVtkBaseView( _theViewPanel->getWxVtkBaseView() );
3216 return _viewThresholdImagePanel;
3219 //CMRU 17-08-09-----------------------------------------------------------------------------------------------
3220 int wxContourMainFrame::getType ()
3223 std::vector<std::string> currentSelection = _theViewPanel->getSelectedObjects();
3225 if(!currentSelection.empty())
3227 std::string cloneName = currentSelection [0];
3228 manualBaseModel * manualModel = kernelManager->getOutlineByKeyName(cloneName);
3229 tipo = manualModel-> GetTypeModel();
3234 double wxContourMainFrame::getContourSizeInPixels()
3236 double contourSize = 0;
3238 std::vector<std::string> currentSelection = _theViewPanel->getSelectedObjects(); if(!currentSelection.empty())
3239 if(!currentSelection.empty())
3241 std::string cloneName = currentSelection [0];
3243 manualBaseModel * manualModel = kernelManager->getOutlineByKeyName(cloneName);//_modelManager->getOutlineByKeyName( cloneName )->getModel();
3246 // contourSize = manualModel->GetPathSize();
3251 contourSize = manualModel->GetPathSize( spc );
3256 manualBaseModel * wxContourMainFrame::getContour ()
3258 std::vector<std::string> currentSelection = _theViewPanel->getSelectedObjects();
3260 if(!currentSelection.empty())
3262 std::string cloneName = currentSelection [0];
3263 manualBaseModel * manualModel = kernelManager->getOutlineByKeyName(cloneName);//_modelManager->getOutlineByKeyName( cloneName )->getModel();
3268 void wxContourMainFrame::onPrintLabel (wxString label, manualBaseModel* manualModel)
3270 std::string labelAscii(label.ToAscii());
3271 int pos = labelAscii.find(" ");
3275 for (j=0 ; pos != string::npos;j++)
3277 labelAscii.replace( pos, 1, "_" );
3278 pos= labelAscii.find(" ");
3281 manualModel -> SetLabel(labelAscii);
3283 void wxContourMainFrame::onInsertCalculation(manualBaseModel* manualModel)
3286 // double sizeInPixel = manualModel ->GetPathSize( );
3291 double sizeInPixel = manualModel ->GetPathSize( spc );
3293 double onePixelRealSize = interfMainPanel::getInstance()->GetPixelValue();;
3294 double realContourSize = sizeInPixel*onePixelRealSize;
3295 manualModel ->SetRealSize(realContourSize);
3298 double wxContourMainFrame::onePixelSize( double value)
3300 return _onePixelSize = value;
3303 std::string wxContourMainFrame::GetFileLocation()
3305 return _fileLocation;
3308 void wxContourMainFrame::SetFileLocation(std::string newFileLocation)
3310 _fileLocation = newFileLocation;
3311 std::cout<<"GETFILELOCATION:"<<_fileLocation<<std::endl;
3313 //------------------------------------------------------------------------------------------------------------
3322 void wxContourMainFrame::FlipSelectedContours(int flipDirection)
3325 (std::vector<std::string>)_theViewPanel->getSceneManager()->getSelectedObjects() ,
3331 void wxContourMainFrame::FlipActualSliceContours(int flipDirection)
3334 (std::vector<std::string>)_theViewPanel->getSceneManager()->GetlstContoursNameActualSlice() ,
3339 void wxContourMainFrame::FlipAllContours(int flipDirection)
3342 kernelManager->GetLstNameThings() ,
3347 void wxContourMainFrame::FlipLstOfContours(std::vector<std::string> lstNameThings, int flipDirection)
3350 getImageData()->GetExtent(ext);
3351 int sizeX = ext[1]-ext[0];
3352 int sizeY = ext[3]-ext[2];
3355 int i,sizeLstNameThings;
3356 int ii,sizeLstPoints;
3358 sizeLstNameThings = lstNameThings.size();
3359 for (i=0 ; i<sizeLstNameThings ; i++)
3361 printf("EED wxContourMainFrame::FlipAllContours contour=%d \n", 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 Things
3371 //-- Static Contours
3373 lstNameThings = kernelManager->GetLstNameThingsStatic();
3374 sizeLstNameThings = lstNameThings.size();
3375 for (i=0 ; i<sizeLstNameThings ; i++)
3377 manualBaseModel * manualModel = kernelManager->getOutlineByKeyName(lstNameThings[i]);
3378 if (flipDirection==0)
3380 manualModel->Transform_Ax_Plus_B(-1,sizeX,1,0 );
3382 manualModel->Transform_Ax_Plus_B(1,0,-1,sizeY );
3384 }// for i list of static things
3387 void wxContourMainFrame::FlipContours(int typeContourFlip, int flipDirection)
3389 printf("EED wxContourMainFrame::FlipContours( %d , %d ) \n",typeContourFlip, flipDirection );
3393 if (typeContourFlip==0) //
3395 FlipSelectedContours(flipDirection);
3398 if (typeContourFlip==1) //
3400 FlipActualSliceContours(flipDirection);
3403 if (typeContourFlip==2) //
3405 FlipAllContours(flipDirection);