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 _viewColorLayerImage = NULL;
97 _viewColorLayerImagePanel = NULL;
100 wxContourMainFrame :: wxContourMainFrame(wxWindow* parent, wxWindowID id,const wxString& title,const wxPoint& pos,const wxSize& size,std::vector<vtkImageData*> images, long style,std::string datadir)
101 : wxPanel(parent, id, pos, size, style)
103 m_mgr.SetManagedWindow(this);
105 _creatingContoursActive = false;
106 _theViewPanel = NULL;
108 _instantPanel = NULL;
109 _refLineControl = NULL;
110 _refLineModel = NULL;
112 // _actorPresent = false;
113 _viewMaskImage = NULL;
114 _viewMaskImagePanel = NULL;
115 _viewThresholdImage = NULL;
116 _viewThresholdImagePanel = NULL;
117 _viewColorLayerImage = NULL;
118 _viewColorLayerImagePanel = NULL;
120 // set up default notebook style
121 m_notebook_style =wxAUI_NB_TAB_SPLIT | wxAUI_NB_TAB_EXTERNAL_MOVE | wxNO_BORDER;
122 m_notebook_theme = 0;
123 //wxContour_ActionCommandsID a;
124 _numberOfVariablesStatistics = 7;
132 _pannew = interfMainPanel::getInstance(this,datadir+"/data/Icons");//, eventHandler);
133 _performingOperation = new PerformingOperation();
135 if(images.size() > 0)
137 this->setVectImages(images);
140 _contourextractdata = NULL;
143 void wxContourMainFrame::setVectImages(std::vector<vtkImageData*> imgs)
148 #if defined(__GNUC__)
149 std::string str_home(getenv("HOME"));
150 #elif defined(_WIN32)
151 std::string str_home(getenv("USERPROFILE"));
153 std::string strCreaContourDataTmp = str_home + "/.creaContourDataTemp/";
155 std::vector<std::string> conceptNameVect;
156 std::vector<int> conceptSizeVect;
158 notebook = this->createNotebook();
161 kernelManager = new KernelManagerContour( imgs , _datadir+"/data/" , strCreaContourDataTmp );
164 _instantPanel = new wxInstantChooserPanel( notebook, "Instant Chooser", true, false, "c" );
165 _theViewPanel = new wxContourViewPanel( kernelManager->getSourceImage(), notebook );
167 //-------------------------------------------------------------
168 kernelManager->getConceptsInformation(conceptNameVect, conceptSizeVect);
169 _instantPanel->addConcepts(conceptNameVect, conceptSizeVect);
172 double val = _theViewPanel->getCurrentDeep();
173 _instantPanel->setConceptValue( "Axe Depth", (int)val );
174 //JCP _instantPanel->setConceptValue("time", num de imagenes);
175 ConceptDataWrap * data = _instantPanel->getConceptDataOf( "Axe Depth" );
176 //*******************changeInstant();
177 _theViewPanel->setVerticalConcept( "Axe Depth", data->getMinValue(), data->getMaxValue(), data->getMinShowedValue(), data->getMaxShowedValue(), data->getActualValue() );
179 this->configurePanels( );
184 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 )
186 if(instance == NULL){
187 instance = new wxContourMainFrame(parent, id, title, pos, size, images, style,datadir);
192 std::vector<vtkImageData*> wxContourMainFrame ::getVectImages()
194 return kernelManager->getVectImages();
197 wxContourMainFrame* wxContourMainFrame :: getInstance()
202 void wxContourMainFrame :: resetInstance()
207 wxContourMainFrame :: ~wxContourMainFrame()
209 delete _contourextractdata;
212 interfMainPanel::resetInstance();
213 delete kernelManager;
215 //_pannew->Destroy();
221 //El problema al cerrar la aplicacion puede estar asociado
222 //a que wxAUINotebook esta en la aplicacion
223 //principal (wxContourGUIExample)tambien
224 //EED???? delete _theViewPanel;
225 //EED???? delete _instantPanel;
226 //EED???? delete _buttonsBar;
227 //EED???? delete _actualInstant;
228 //EED???? delete _sceneManager;
232 //------------------------------------------------------------------------------------------------------------
233 // Creational and initialization methods using WxAui
234 //------------------------------------------------------------------------------------------------------------
236 wxAuiNotebook * wxContourMainFrame :: createNotebook()
238 wxSize client_size = GetClientSize();
239 wxAuiNotebook* noteBook = new wxAuiNotebook(this, -1, wxPoint(client_size.x, client_size.y), wxSize(430,200), m_notebook_style);
240 wxBitmap page_bmp = wxArtProvider::GetBitmap(wxART_NORMAL_FILE, wxART_OTHER, wxSize(16,16));
245 //------------------------------------------------------------------------------------------------------------
246 // Creational and initialization methods
247 //------------------------------------------------------------------------------------------------------------
248 bool wxContourMainFrame :: configurePanels( )
250 bool configured = _theViewPanel!=NULL;
252 configured &= _theViewPanel!=NULL;
253 if( _theViewPanel!=NULL )
255 notebook->AddPage( _theViewPanel, wxT(" View ") );
262 notebook->AddPage( _instantPanel, wxT("Instant Page") );
266 m_mgr.AddPane(notebook, wxAuiPaneInfo().Name(wxT("notebook_content")).CenterPane().PaneBorder(false));
269 SetMinSize(wxSize(300,300));
275 bool wxContourMainFrame::addNewPanel(wxPanel* panel)
277 bool configured = panel!=NULL;
278 configured &= panel!=NULL;
282 notebook->AddPage( panel, wxT(" Viewer "), true );
288 //------------------------------------------------------------------------------------------------------------
289 // Attributes getters and setters
290 //------------------------------------------------------------------------------------------------------------
294 void wxContourMainFrame :: setInstantChooserPanel( wxInstantChooserPanel * theInstantChooserPanel )
296 _instantPanel = theInstantChooserPanel;
299 // void wxContourMainFrame :: setButtonsBar( wxContour_ButtonsBar * theButtonsBar )
301 // _buttonsBar = theButtonsBar;
304 // void wxContourMainFrame :: setGrid( wxContour_Grid * theGridPanel )
306 // _gridPanel = theGridPanel;
309 // void wxContourMainFrame :: setDrawToolsPanel( wxContour_DrawToolsPanel * theDrawToolsPanel )
311 // _drawToolsPanel = theDrawToolsPanel;
314 // void wxContourMainFrame :: setOperationsToolsPanel( wxContour_OperationsToolsPanel * theOperationsToolsPanel )
316 // _operationsToolsPanel = theOperationsToolsPanel;
319 // void wxContourMainFrame :: setAutomaticFormsPanel( wxContour_AutomaticFormsToolsPanel * theAutoFormsPanel )
321 // _autoFormsPanel = theAutoFormsPanel;
324 // void wxContourMainFrame :: setStandardToolsPanel( wxContour_StandardToolsPanel * theStandardToolsPanel )
326 // _standardToolsPanel= theStandardToolsPanel;
329 // void wxContourMainFrame :: setEditionToolsPanel( wxContour_EdtionToolsPanel * theEditionToolsPanel )
331 // _editionToolsPanel = theEditionToolsPanel;
334 // void wxContourMainFrame :: setListViewPanel( wxContour_ListViewPanel * theListViewPanel )
336 // _listViewPanel = theListViewPanel;
341 void wxContourMainFrame::onCreateContourSpline( ){
343 //JCP 20-10-08 Undo redo implementation
345 //JCP 20-10-08 Undo redo implementation
349 void wxContourMainFrame::onCreateContourRectangle( ){
350 //JCP 20-10-08 Undo redo implementation
352 //JCP 20-10-08 Undo redo implementation
355 void wxContourMainFrame::onCreateContourCircle( ){
356 //JCP 20-10-08 Undo redo implementation
358 //JCP 20-10-08 Undo redo implementation
362 void wxContourMainFrame::onCreateContourLine( ){
363 //JCP 20-10-08 Undo redo implementation
365 //JCP 20-10-08 Undo redo implementation
369 // RaC 09-09 --------------------------------------
370 void wxContourMainFrame::onCreateContourPoints( ){
371 //JCP 20-10-08 Undo redo implementation
373 //JCP 20-10-08 Undo redo implementation
376 // RaC 09-09 --------------------------------------
378 // RaC 10-09 --------------------------------------
379 void wxContourMainFrame::onCreateContourPolygon( ){
380 //JCP 20-10-08 Undo redo implementation
382 //JCP 20-10-08 Undo redo implementation
385 // RaC 10-09 --------------------------------------
387 //------------------------------------------------------------------------------------------------------------
389 void wxContourMainFrame :: onCreateContourBullEye(wxPanel* panel )
391 //Creating the manualBaseModel and including in the model
392 manualBaseModel * manModelContour = factoryManualContourModel(panel );
394 std::vector<int> instantVector;
395 _instantPanel->getInstant( instantVector );
396 std::string theName = kernelManager->createOutline(manModelContour, instantVector);
398 /*std::vector<int> instantVector;
399 _instantPanel->getInstant( instantVector );
401 theName= _modelManager->createOutline( manModelContour, instantVector );*/
402 bool addedModel = theName.compare("") != 0;//??
406 double spc[3];//Si no hay imagen pero hay contornos que spacing se pone por default
407 _theViewPanel->getSpacing(spc);
408 //Adding the manualContourControler to interface objects structure
409 //Adding the manualViewContour to interface objects structure
410 //_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.
411 _theViewPanel->getSceneManager()->configureViewControlTo( theName, manModelContour,spc , 4) ;
414 void wxContourMainFrame :: createContour( int typeContour )
416 //Creating the manualContourModel and including in the model
417 manualBaseModel * manModelContour = kernelManager->factoryManualContourModel(typeContour);
419 std::vector<int> instantVector;
420 _instantPanel->getInstant( instantVector );
421 std::string theName = kernelManager->createOutline(manModelContour, instantVector);
423 /*std::vector<int> instantVector;
424 _instantPanel->getInstant( instantVector );
426 theName= _modelManager->createOutline( manModelContour, instantVector );*/
427 bool addedModel = theName.compare("") != 0;//??
430 double spc[3];//Si no hay imagen pero hay contornos que spacing se pone por default
431 _theViewPanel->getSpacing(spc);
432 //Adding the manualContourControler to interface objects structure
433 //Adding the manualViewContour to interface objects structure
434 //_sceneManager->setControlActiveStateOfALL( false );//This call is being done here because if the ROI is created underneath the previously created ROIS will still be active.
435 _theViewPanel->getSceneManager()->configureViewControlTo( theName, manModelContour,spc , typeContour) ;
439 manualBaseModel * wxContourMainFrame::factoryManualContourModel(wxPanel* panel){
441 manualContourModelBullEye *manModelContourBullEye = new manualContourModelBullEye();
442 manualBaseModel *manModelContour=NULL;
443 manModelContour = manModelContourBullEye;
445 int iCrown,sizeCrowns,iSector,sizeSectors;
446 double radioA,radioB,ang,angDelta ;
447 sizeCrowns = ((PanelBullEyeOptions*)panel)->GetNumberOfCrowns();
448 for ( iCrown=0 ; iCrown<sizeCrowns ; iCrown++ )
450 sizeSectors = ((PanelBullEyeOptions*)panel)->GetNumberOfSections(iCrown);
451 radioB = ((PanelBullEyeOptions*)panel)->GetRadioOfCrown(iCrown);
452 if (iCrown==sizeCrowns-1)
456 radioA = ((PanelBullEyeOptions*)panel)->GetRadioOfCrown(iCrown+1);
460 for ( iSector=0 ; iSector<sizeSectors ; iSector++ )
462 ang = ((PanelBullEyeOptions*)panel)->GetAngOfCrownSection(iCrown,iSector);
463 angDelta= ((PanelBullEyeOptions*)panel)->GetAngDeltaOfCrownSection(iCrown);
464 manModelContourBullEye->AddSector(radioA,radioB,ang,angDelta);
467 } // if _panelBullEyeOptions
469 return manModelContour;
471 void wxContourMainFrame :: saveState(){
473 std::string temp = kernelManager->saveState();
474 saveFileWithContours(temp);
477 void wxContourMainFrame::onDeleteContour(){
478 //JCP 20-10-08 Undo redo implementation
480 //JCP 20-10-08 Undo redo implementation
482 std::vector<std::string> lstKeyNameToBeErase;
483 lstKeyNameToBeErase = _theViewPanel->getSceneManager()->getSelectedObjects();
484 deleteContours( lstKeyNameToBeErase );
486 int i,size=_sceneManager->getSelectedObjects().size();
489 std::string keyName = _sceneManager->getSelectedObjects()[i];
490 int ispartofstaticlist = this->_modelManager->IsPartOfStaticList( keyName );
491 if ( ispartofstaticlist>=0 )
493 std::vector<int> tempVector;
494 _instantPanel->getInstant( tempVector );
495 Instant instant(&tempVector);
496 this->_modelManager->ChangeContourOfList(keyName, &instant);
500 std::vector<std::string> lstKeyName;
501 std::vector<std::string> lstKeyNameActualSlice;
502 std::vector<std::string> lstKeyNameToBeErase;
504 lstKeyNameToBeErase = _sceneManager->getSelectedObjects();
505 lstKeyNameActualSlice = _sceneManager->GetlstContoursNameActualSlice();
506 int k,kSize=lstKeyNameToBeErase.size();
507 int j,jSize=lstKeyNameActualSlice.size();
509 for (k=0;k<kSize; k++)
512 for (j=0;j<jSize; j++)
514 if (lstKeyNameToBeErase[k]==lstKeyNameActualSlice[j])
521 lstKeyName.push_back( lstKeyNameToBeErase[k] );
525 deleteContours( lstKeyName );
529 void wxContourMainFrame :: deleteContours( std::vector<std::string> keyNamesVector )
531 int i,size=keyNamesVector.size();
534 deleteContour( keyNamesVector[i] );
538 void wxContourMainFrame :: deleteContour( std::string theKeyName ){
540 manualContourModel * cModel;
541 manualViewBaseContour * cViewer;
542 manualContourBaseControler * cControler;
544 ContourWrap_ViewControl *conwrapviewControl = _theViewPanel->getSceneManager()->getContourWrap_ViewControlOf( theKeyName );
545 cControler = conwrapviewControl->getControler();*/
548 bool isedit = _theViewPanel->isEditableCControler(theKeyName);
549 bool ispartofstaticlst = kernelManager->IsPartOfStaticList(theKeyName);
551 if (isedit && ispartofstaticlst)
553 _theViewPanel->removeFromScene(theKeyName);
555 kernelManager->deleteCModel(theKeyName);
556 //_theViewPanel->getSceneManager()->removeFromScene( theKeyName );
557 //cViewer = conwrapviewControl->getViewer();
558 //_theViewPanel->getSceneManager()->removeWrap( theKeyName );
559 //cControler* conwrapviewControl->getControler();
562 // delete cControler;
567 void wxContourMainFrame::onDeleteContoursActSlice(){
568 //JCP 20-10-08 Undo redo implementation
570 //JCP 20-10-08 Undo redo implementation
571 deleteContours( (std::vector<std::string>)_theViewPanel->getSceneManager()->GetlstContoursNameActualSlice() );
573 void wxContourMainFrame::onDeleteAllContours(){
574 //JCP 20-10-08 Undo redo implementation
578 void wxContourMainFrame::deleteAllContours(){
579 //JCP 20-10-08 Undo redo implementation
582 std::vector<int> tempVector;
583 _instantPanel->getInstant( tempVector );
585 //JCP --08-09-2008 When using a diferent interface the _mbarrangeDeleteAll might not be initialize
586 // the values in GetStart and GetEnd will then not be initialize also.
587 // We use instead the values given when initializing the _deletepanel.
589 //int minZ = _mbarrangeDeleteAll->GetStart();
590 //int maxZ = _mbarrangeDeleteAll->GetEnd();
594 maxZ = _theViewPanel->getSceneManager()->GetImageDataSizeZ();
598 _theViewPanel->getSceneManager()->removeSceneContours( );
599 _theViewPanel->getSceneManager()->removeAllOutlines();
600 kernelManager->removeAllOutlines();
603 if ( (minZ==0) && (maxZ==_mbarrangeDeleteAll->GetMax() ))
605 _theViewPanel->getSceneManager()->removeSceneContours( );
606 _modelManager->removeAllOutlines();
607 _theViewPanel->getSceneManager()->removeAllOutlines();
610 for ( z=minZ ; z<=maxZ ; z++)
613 Instant instant(&tempVector);
614 std::vector<ContourThing**> lstContourThings = this->_modelManager->getOutlinesAtInstant( &instant );
616 sizeLstContourThings = lstContourThings.size();
617 for (ii=0 ; ii<sizeLstContourThings ; ii++)
619 ContourThing **contourthing = lstContourThings[ii];
620 deleteContour( (*contourthing)->getName() );
627 void wxContourMainFrame::setConceptValue( std::string name, int value ){
628 _instantPanel->setConceptValue(name, value);
632 ConceptDataWrap* wxContourMainFrame::getLastConceptData(){
633 return _instantPanel->getLastConceptData();
637 bool wxContourMainFrame::getIfConceptCheckedAt( std::string name, int pos ){
638 return _instantPanel->getIfConceptCheckedAt( name, pos );
643 void wxContourMainFrame::ShowResultImages(int typeContourGroup, int selection, int minZ, int maxZ)
646 vtkImageData * value;
647 this->getMaskValue(&mask, &value, typeContourGroup, selection, minZ, maxZ);
649 std::vector<int> nTypeView;
650 nTypeView.push_back(5);
651 nTypeView.push_back(1);
652 nTypeView.push_back(2);
653 nTypeView.push_back(0);
655 wxFrame *frame = new wxFrame(this, -1,_T("Result image extracted.."),wxDefaultPosition,wxSize(600,600), wxDEFAULT_FRAME_STYLE|wxSTAY_ON_TOP);
656 wxAuiManager *m_mgr_noteBookViewerResult = new wxAuiManager();
657 m_mgr_noteBookViewerResult->SetManagedWindow(frame);
659 wxAuiNotebook* noteBookViewerResult = new wxAuiNotebook(frame, -1, wxPoint(600, 600), wxSize(430,200), m_notebook_style);
660 m_mgr_noteBookViewerResult->AddPane(noteBookViewerResult, wxAuiPaneInfo().Name(wxT("notebook_content")).CenterPane().PaneBorder(false));
662 wxPanel *panelViewer1 = new wxMaracas_N_ViewersWidget(noteBookViewerResult, value,&nTypeView);
663 wxPanel *panelViewer2 = new wxMaracas_N_ViewersWidget(noteBookViewerResult, mask,&nTypeView);
666 noteBookViewerResult->AddPage( panelViewer1, wxT("Image result") );
667 noteBookViewerResult->AddPage( panelViewer2, wxT("Mask result") );
668 m_mgr_noteBookViewerResult->Update();
675 void wxContourMainFrame::changeInstant()
677 std::vector<int> instantVect;
678 _instantPanel->getInstant( instantVect );
679 int actualSlice = instantVect[1];
681 kernelManager->setInstant(instantVect);
683 // Refresh Mask image
684 if(_viewMaskImage!=NULL){
685 _viewMaskImage->SetZ(actualSlice);
686 if (_viewMaskImagePanel->IsVisible()==true)
688 vtkImageData *mask, *value;
689 getMaskValue(&mask,&value, _contourGroup , 0, -1, -1);
690 _viewMaskImage->onThreshold();
694 // Refresh Threshold image
695 if(_viewThresholdImage!=NULL){
696 _viewThresholdImage->SetZ(actualSlice);
697 if (_viewThresholdImagePanel->IsVisible()==true){
698 _viewThresholdImage->onThreshold();
702 // Refresh Threshold image
703 if(_viewColorLayerImage!=NULL){
704 _viewColorLayerImage->SetZ(actualSlice);
705 if (_viewColorLayerImagePanel->IsVisible()==true){
706 _viewColorLayerImage->onThreshold();
710 updateInstantOutlines();
711 updateInstantImageData();
717 void wxContourMainFrame :: updateInstantOutlines()
719 _theViewPanel->removeSceneContours();
720 _theViewPanel->addNameWrapperToScene();
722 //for( int i=0; i<size; i++)
724 // _theViewPanel->getSceneManager()->addToScene(namesWrapping[i]->getKeyName(), true, true, true, false, false );
728 int wxContourMainFrame::getNamesWrappingSize(){
729 return kernelManager->getNamesWrappingSize();
731 std::string wxContourMainFrame::getNameWrapping(int i){
732 return kernelManager->getNameWrapping(i);
735 void wxContourMainFrame::updateInstantImageData()
737 std::vector<int> inst;
738 _instantPanel->getInstant(inst);
740 vtkImageData* img = kernelManager->getImageAtInstant(inst);
742 _theViewPanel->changeImage(img);
745 int z = _instantPanel->getConceptDataOf("Axe Depth")->getActualValue();
746 _theViewPanel->setImageSlice(z);
750 void wxContourMainFrame::updateInstantAxes()
755 void wxContourMainFrame::onChangeDeep(int val){
756 _instantPanel->setConceptValue( "Axe Depth", (int)val );
761 void wxContourMainFrame::onCopy(){
762 std::vector<std::string> currentSelection = _theViewPanel->getSelectedObjects();
764 std::vector<int> tempVector;
765 _instantPanel->getInstant( tempVector );
766 _performingOperation->reset();
767 _performingOperation->setStartCommand( COPY );
768 _performingOperation->setStartOperationInstantVector( tempVector );
769 _performingOperation->setKeyNamesOperationElems( currentSelection );
772 void wxContourMainFrame::onPaste(){
775 char theStartCommand = _performingOperation->getStartCommand();
776 if ( theStartCommand == COPY )
778 //JCP 20-10-08 Undo redo implementation
780 //JCP 20-10-08 Undo redo implementation
781 std::vector<int> tempVector;
782 _instantPanel->getInstant( tempVector );
783 _performingOperation->setEndOperationInstantVector ( tempVector );
784 std::vector<std::string> elems = _performingOperation->getKeyNamesOperationElems();
785 int i,size = elems.size();
786 for( i=0; i<size; i++ )
788 createCopyContourOf( elems[i], tempVector, i>0 );
792 void wxContourMainFrame::onUndo(){
793 std::string filename;
794 if(kernelManager->onUndoSaveFile(filename)){
795 saveFileWithContours(filename);
797 if(kernelManager->onUndo(filename)){
801 void wxContourMainFrame::onRedo(){
802 std::string filename;
803 if(kernelManager->onRedo(filename)){
808 void wxContourMainFrame :: createCopyContourOf ( std::string anExistingKName, std::vector<int> &instantNoTouchData, bool append )
810 std::string cloneName = kernelManager->createCopyContourOf( anExistingKName, instantNoTouchData );
811 manualBaseModel * manualModel = kernelManager->getOutlineByKeyName(cloneName);//_modelManager->getOutlineByKeyName( cloneName )->getModel();
812 _theViewPanel->getSceneManager()->createCopyContourOf( anExistingKName, cloneName, manualModel , append );
815 ///AD: 03-09 Copy the object and apply the given transformation
816 void wxContourMainFrame :: createMirrorContourOf ( std::string anExistingKName, std::vector<int> &instantNoTouchData, bool append )
818 std::string cloneName = kernelManager->createCopyContourOf( anExistingKName, instantNoTouchData );
819 manualBaseModel * manualModel = kernelManager->getOutlineByKeyName(cloneName);
821 manualPoint * refPoint1 = _refLineModel->GetManualPoint(0);
822 manualPoint * refPoint2 = _refLineModel->GetManualPoint(1);
824 double pnt1X = refPoint1->GetX();
825 double pnt1Y = refPoint1->GetY();
826 // double pnt1Z = refPoint1->GetZ();
827 double pnt2X = refPoint2->GetX();
828 double pnt2Y = refPoint2->GetY();
829 // double pnt2Z = refPoint2->GetZ();
831 double angle = (atan2(pnt2Y - pnt1Y, pnt2X - pnt1X) * 180 / 3.1415926535897932384626433832795)+90;
832 vtkTransform *t = vtkTransform::New();
836 t->Translate(-pnt1X, -pnt1Y, 0);
840 t->Translate(pnt1X, pnt1Y, 0);
843 int i,size=manualModel->GetSizeLstPoints();
846 manualPoint * mp = manualModel->GetManualPoint(i);
852 t->TransformPoint( vecIn, vecOut );
853 mp->SetPointX( vecOut[0] );
854 mp->SetPointY( vecOut[1] );
855 mp->SetPointZ( vecOut[2] );
858 _theViewPanel->getSceneManager()->createCopyContourOf( anExistingKName, cloneName, manualModel , append );
862 void wxContourMainFrame ::loadState(std::string filename){
865 onLoadContours(filename,false);
869 FILE *pFile=fopen(filename.c_str(),"r+");
871 fscanf(pFile,"%s",tmp); // --CreaContour--
873 fscanf(pFile,"%s",tmp); // Version
874 fscanf(pFile,"%s",tmp); // 1.0.3 || 1.0.2 || 1.0.1 || 1.0.0
878 loadContours(pFile, false);
879 loadContours(pFile, true);
888 void wxContourMainFrame::loadContours( FILE *pFile, bool staticContour )
892 if (staticContour==false)
894 fscanf(pFile,"%s",tmp); // ImageDimensions
895 fscanf(pFile,"%s",tmp); // X
896 fscanf(pFile,"%s",tmp); // Y
897 fscanf(pFile,"%s",tmp); // Z
899 fscanf(pFile,"%s",tmp); // ImageSpacing
900 fscanf(pFile,"%s",tmp); // X
901 fscanf(pFile,"%s",tmp); // Y
902 fscanf(pFile,"%s",tmp); // Z
905 fscanf(pFile,"%s",tmp); // NumberOfContours
906 fscanf(pFile,"%s",tmp); // ##
907 int numberOfContours = atoi(tmp);
909 std::vector<int> instantVector;
910 int typeContourModel;
911 manualBaseModel *manModelContour;
915 for (i=0;i<numberOfContours;i++)
917 instantVector.clear();
918 fscanf(pFile,"%s",tmp); // Instant
919 fscanf(pFile,"%s",tmp); // 1
920 instantVector.push_back( atoi(tmp) );
921 fscanf(pFile,"%s",tmp); // 2
922 instantVector.push_back( atoi(tmp) );
923 fscanf(pFile,"%s",tmp); // 3
924 instantVector.push_back( atoi(tmp) );
925 fscanf(pFile,"%s",tmp); // 4
926 instantVector.push_back( atoi(tmp) );
927 fscanf(pFile,"%s",tmp); // 5
928 instantVector.push_back( atoi(tmp) );
929 fscanf(pFile,"%s",tmp); // 6
930 instantVector.push_back( atoi(tmp) );
932 fscanf(pFile,"%s",tmp); // TypeContourModel
933 fscanf(pFile,"%s",tmp); // ##
934 typeContourModel = atoi(tmp);
936 manModelContour = kernelManager->factoryManualContourModel(typeContourModel);
937 manModelContour->Open(pFile);
939 fscanf(pFile,"%s",tmp); // TypeView
940 fscanf(pFile,"%s",tmp); // ##
941 typeView = atoi(tmp);
944 theName = kernelManager->createOutline( manModelContour, instantVector );
945 bool addedModel = theName.compare("") != 0;
948 double spc[3];//Si no hay imagen pero hay contornos que spacing se pone por default
949 _theViewPanel->getSpacing(spc);
950 //Adding the manualContourControler to interface objects structure
951 //Adding the manualViewContour to interface objects structure
952 //_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.
953 _theViewPanel->getSceneManager()->configureViewControlTo( theName, manModelContour,spc , typeView) ;
956 if (staticContour==true)
958 Instant instant(&instantVector);
959 kernelManager->changeContourOfManager( theName , &instant );
961 }// for numberOfContours
966 void wxContourMainFrame::onLoad()
968 std::string fileNameContourROI = GetFileLocation();
969 //CMRU 03-09-09-----------------------------------------------------------------------------------------------
970 if(GetFileLocation().empty())
972 //------------------------------------------------------------------------------------------------------------
973 wxFileDialog dialog(NULL, _T("Choose a file"), _T(""), _T(""), _T("*.roi"), wxOPEN );
974 if (dialog.ShowModal() == wxID_OK)
976 fileNameContourROI = (const char *)(dialog.GetPath().mb_str());
980 onLoadContours(fileNameContourROI,true);
984 void wxContourMainFrame::SetZForAllContours(int pz)
986 printf("EED wxContourMainFrame::SetZForAllContours\n");
990 std::vector< std::string > lstNameThings;
991 int i,sizeLstNameThings;
992 int ii,sizeLstPoints;
994 lstNameThings = kernelManager->GetLstNameThings();
995 sizeLstNameThings = lstNameThings.size();
996 for (i=0 ; i<sizeLstNameThings ; i++)
998 printf("EED wxContourMainFrame::SetZForAllContours contour=%d \n", i );
999 manualBaseModel * manualModel = kernelManager->getOutlineByKeyName(lstNameThings[i]);
1000 sizeLstPoints = manualModel->GetSizeLstPoints();
1001 for (ii=0 ; ii<sizeLstPoints ; ii++)
1003 manualModel->GetManualPoint(ii)->SetPointZ(-900);
1004 }// for ii list of points
1005 }// for i list of Things
1007 //-- Static Contours
1009 lstNameThings = kernelManager->GetLstNameThingsStatic();
1010 sizeLstNameThings = lstNameThings.size();
1011 for (i=0 ; i<sizeLstNameThings ; i++)
1013 manualBaseModel * manualModel = kernelManager->getOutlineByKeyName(lstNameThings[i]);
1014 sizeLstPoints = manualModel->GetSizeLstPoints();
1015 for (ii=0 ; ii<sizeLstPoints ; ii++)
1017 manualModel->GetManualPoint(ii)->SetPointZ(-900);
1018 }// for ii list of points
1019 }// for i list of static things
1024 void wxContourMainFrame::onLoadContours(std::string fileNameContourROI, bool interactiveInterface)
1029 FILE *pFile =fopen(fileNameContourROI.c_str(),"r+");
1032 //CMRU 03-09-09- ----------------------------------------------------------------------------------------------
1035 //------------------------------------------------------------------------------------------------------------
1036 fileNameContourROI.append("data");
1037 FILE *pFileData=fopen(fileNameContourROI.c_str(),"r+");
1038 if(pFileData != NULL)
1040 fscanf(pFileData,"%s",tmpD); // --CreaContour--
1041 fscanf(pFileData,"%s",tmpD); // Version
1042 fscanf(pFileData,"%s",tmpD); // 1.0.3 || 1.0.2 || 1.0.1 || 1.0.0
1044 fscanf(pFileData,"%s",tmpD); // onePixelSize
1045 fscanf(pFileData,"%s",tmpD); // #
1046 _onePixelSize = atof(tmpD);
1047 fscanf(pFileData,"%s",tmpD); // NumberOfContours
1048 fscanf(pFileData,"%s",tmpD); // #
1051 fscanf(pFile,"%s",tmp); // --CreaContour--
1053 fscanf(pFile,"%s",tmp); // Version
1054 fscanf(pFile,"%s",tmp); // 1.0.3 || 1.0.2 || 1.0.1 || 1.0.0
1055 std::string version(tmp);
1058 printf("EED wxContourMainFrame::onLoadContours version%s \n", version.c_str() );
1062 _tmpReadFileTypeOfTransformation=-1;
1063 if (version=="1.0.3")
1065 readDimSpc(pFile,interactiveInterface); // DimSpc interactive ON
1066 openContours(pFile,pFileData,false);
1067 openContours(pFile,pFileData,true); //Load StaticContours
1070 if (version=="1.0.2")
1073 readDimSpc(pFile,interactiveInterface); // DimSpc interactive ON
1074 openContours(pFile,pFileData,false);
1075 readDimSpc(pFile,false); // DimSpc interactive OFF
1076 openContours(pFile,pFileData,true); // Load StaticContours
1077 SetZForAllContours(-900);
1081 else if (version=="1.0.1")
1083 openContours(pFile,pFileData,false); //Skips ImageDimensions and ImageSpacing
1084 openContours(pFile,pFileData,true); //Load StaticContours, skips ImageDimensions and ImageSpacing
1088 else if (version=="1.0.0")
1090 openContours(pFile,pFileData,false); //Skips ImageDimensions and ImageSpacing
1095 if(pFileData != NULL)
1100 _theViewPanel->getSceneManager()->removeSceneContours();
1106 void wxContourMainFrame::onImport(){
1107 std::string filename, filenamecontours;
1108 wxFileDialog dialog(NULL, _T("Choose a XML Osirix File"), _T(""), _T(""), _T("*.xml"), wxOPEN );
1110 if (dialog.ShowModal() == wxID_OK)
1112 filename = dialog.GetPath().mb_str();
1113 filenamecontours = kernelManager->parseOsirixFile(filename);
1115 if(filenamecontours.compare("") != 0){
1116 onLoadContours(filenamecontours,true);
1121 void wxContourMainFrame::onTest(){
1122 std::string filename, filenamecontours;
1123 wxFileDialog dialog(NULL, _T("Choose a File"), _T(""), _T(""), _T("*.*"), wxOPEN );
1125 if (dialog.ShowModal() == wxID_OK)
1127 filename = dialog.GetPath().mb_str();
1128 std::cout << "This is the filename: " << filename << std::endl;
1134 void wxContourMainFrame::onSave(){
1135 //CMRU 03-09-09-----------------------------------------------------------------------------------------------
1136 if(GetFileLocation().empty())
1138 //------------------------------------------------------------------------------------------------------------
1139 wxFileDialog dialog(NULL, _T("Choose a file"), _T(""), _T(""), _T("*.roi"), wxSAVE );
1140 if (dialog.ShowModal() == wxID_OK)
1142 std::string fileNameContourROI = (const char *)(dialog.GetPath().mb_str());
1143 kernelManager->setCurrentFileName(fileNameContourROI);
1144 saveFileWithContours( fileNameContourROI );
1147 //CMRU 03-09-09-----------------------------------------------------------------------------------------------
1150 std::cout<<"Nombre del archivo: "<<GetFileLocation()<<std::endl;
1151 std::string fileNameContourROI = GetFileLocation();
1152 std::cout<<"Nombre del archivo: "<<fileNameContourROI<<std::endl;
1153 kernelManager->setCurrentFileName(fileNameContourROI);
1154 saveFileWithContours( fileNameContourROI);
1156 //------------------------------------------------------------------------------------------------------------
1160 void wxContourMainFrame::saveFileWithContours( std::string filename )
1163 FILE *pFile=fopen(filename.c_str(),"w+");
1165 //CMRU 03-09-09-----------------------------------------------------------------------------------------------
1166 filename.append("data");
1167 std::cout<<"Nombre del archivo: "<<filename<<std::endl;
1168 FILE *pFileData=fopen(filename.c_str(),"w+");
1169 //------------------------------------------------------------------------------------------------------------
1171 std::vector< std::string > lstNameThings;
1172 int i,sizeLstNameThings;
1174 fprintf(pFile,"--CreaContour--\n");
1175 fprintf(pFile,"Version %s\n", "1.0.3" );
1177 //CMRU 03-09-09-----------------------------------------------------------------------------------------------
1178 fprintf(pFileData,"--CreaContour--\n");
1179 fprintf(pFileData,"Version %s\n", "1.0.3" );
1180 fprintf(pFileData,"OnePixelSize %f\n", _onePixelSize);
1182 //------------------------------------------------------------------------------------------------------------
1184 vtkImageData *image = _images[0];
1187 image->GetDimensions(dimRange);
1189 fprintf(pFile,"ImageDimensions %d %d %d\n", dimRange[0], dimRange[1], dimRange[2] );
1192 image->GetSpacing(spaRange);
1194 fprintf(pFile,"ImageSpacing %f %f %f\n", spaRange[0], spaRange[1], spaRange[2] );
1198 lstNameThings = kernelManager->GetLstNameThings();
1199 sizeLstNameThings = lstNameThings.size();
1200 fprintf(pFile,"NumberOfContours %d\n", sizeLstNameThings );
1202 //CMRU 03-09-09-----------------------------------------------------------------------------------------------
1203 fprintf(pFileData,"NumberOfContours %d\n", sizeLstNameThings );
1204 //------------------------------------------------------------------------------------------------------------
1206 for (i=0 ; i<sizeLstNameThings ; i++)
1208 //CMRU 03-09-09-----------------------------------------------------------------------------------------------
1209 manualBaseModel * manualModel = kernelManager->getOutlineByKeyName(lstNameThings[i]);
1210 double sizeInPixel = manualModel ->GetPathSize();
1211 double realContourSize = sizeInPixel*_onePixelSize;
1212 manualModel ->SetRealSize(realContourSize);
1213 //------------------------------------------------------------------------------------------------------------
1215 //int size= kernelManager->GetLstNameThings().size();
1217 kernelManager->SaveThingName( pFile, pFileData, lstNameThings[i] );
1218 _theViewPanel->getSceneManager()->SaveThingName( pFile, lstNameThings[i] );
1221 //-- Static Contours
1223 // fprintf(pFile,"ImageDimensions %d %d %d\n", dimRange[0], dimRange[1], dimRange[2] );
1224 // fprintf(pFile,"ImageSpacing %f %f %f\n", spaRange[0], spaRange[1], spaRange[2] );
1226 lstNameThings = kernelManager->GetLstNameThingsStatic();
1227 sizeLstNameThings = lstNameThings.size();
1228 fprintf(pFile,"NumberOfContoursStatic %d\n", sizeLstNameThings );
1230 //CMRU 03-09-09-----------------------------------------------------------------------------------------------
1231 fprintf(pFileData,"NumberOfContoursStatic %d\n", sizeLstNameThings );
1232 //------------------------------------------------------------------------------------------------------------
1234 for (i=0 ; i<sizeLstNameThings ; i++)
1236 kernelManager->SaveThingName( pFile, pFileData, lstNameThings[i] );
1237 _theViewPanel->getSceneManager()->SaveThingName( pFile, lstNameThings[i] );
1245 void wxContourMainFrame::readDimSpc(FILE *pFile, bool interactiveOption)
1249 double imageSpac[3];
1250 vtkImageData *image = _images[0];
1251 image->GetDimensions(imageDim);
1252 image->GetSpacing(imageSpac);
1254 fscanf(pFile,"%s",tmp); // ImageDimensions
1255 fscanf(pFile,"%s",tmp); // X
1256 _tmpReadFileImageDim[0] = atoi(tmp);
1257 fscanf(pFile,"%s",tmp); // Y
1258 _tmpReadFileImageDim[1] = atoi(tmp);
1259 fscanf(pFile,"%s",tmp); // Z
1260 _tmpReadFileImageDim[2] = atoi(tmp);
1262 fscanf(pFile,"%s",tmp); // ImageSpacing
1263 fscanf(pFile,"%s",tmp); // X
1264 _tmpReadFileImageSpac[0] = atof(tmp);
1265 fscanf(pFile,"%s",tmp); // Y
1266 _tmpReadFileImageSpac[1] = atof(tmp);
1267 fscanf(pFile,"%s",tmp); // Z
1268 _tmpReadFileImageSpac[2] = atof(tmp);
1271 if (interactiveOption==true)
1273 //Compare Spacing and Dims in X and Y (Necessary in Z?) - Just for Version 2
1274 if (imageDim[0]!=_tmpReadFileImageDim[0] || imageDim[1]!=_tmpReadFileImageDim[1] || imageSpac[0]!=_tmpReadFileImageSpac[0] || imageSpac[1]!=_tmpReadFileImageSpac[1])
1276 wxDialog* dial = new wxDialog (this,-1,_T("Tools"),wxDefaultPosition, wxSize(460,360));
1277 wxSizer* buttonsSizer = dial->CreateSeparatedButtonSizer(wxOK|wxCANCEL);
1278 wxBoxSizer *dialSizer = new wxBoxSizer(wxVERTICAL);
1280 wxString lstOptOperation[2];
1281 lstOptOperation[0]=_T("By Dimension");
1282 lstOptOperation[1]=_T("By Spacing");
1283 wxRadioBox * radioOpts = new wxRadioBox(dial, -1, _T("Type of Transformation"), wxDefaultPosition, wxSize(270,45), 2 , lstOptOperation, 2, wxRA_SPECIFY_COLS);
1285 dialSizer->Add( new wxStaticText(dial,-1,_T("The image resolution is not compatible with the ")) , 0, wxGROW );
1286 dialSizer->Add( new wxStaticText(dial,-1,_T("selected Roi file. Do you want to tranform it?")) , 0, wxGROW );
1287 dialSizer->Add( new wxStaticText(dial,-1,_T(" ")) , 0, wxGROW );
1288 dialSizer->Add(radioOpts,0,wxGROW);
1289 dialSizer->Add( new wxStaticText(dial,-1,_T(" ")) , 0, wxGROW );
1290 dialSizer->Add(buttonsSizer,0,wxGROW);
1291 dial->SetSizer(dialSizer, true);
1295 int _tmpReadFileTypeOfTransformation = -1;
1296 //EED bool transform = false;
1298 if (dial->GetReturnCode() == wxID_OK)
1300 _tmpReadFileTypeOfTransformation = radioOpts->GetSelection();
1304 } // if interactiveOption
1311 void wxContourMainFrame::openContours( FILE *pFile, FILE *pFileData, bool staticContour )
1316 vtkImageData *image = _images[0];
1319 double imageSpac[3];
1320 image->GetDimensions(imageDim);
1321 image->GetSpacing(imageSpac);
1324 fscanf(pFile,"%s",tmp); // NumberOfContours
1325 fscanf(pFile,"%s",tmp); // ##
1326 int numberOfContours = atoi(tmp);
1328 std::vector<int> instantVector;
1329 int typeContourModel;
1330 manualBaseModel *manModelContour;
1334 if (compatible==true)
1337 for (i=0;i<numberOfContours;i++)
1339 instantVector.clear();
1340 fscanf(pFile,"%s",tmp); // Instant
1342 fscanf(pFile,"%s",tmp); // 1
1343 instantVector.push_back( atoi(tmp) );
1344 fscanf(pFile,"%s",tmp); // 2
1345 instantVector.push_back( atoi(tmp) );
1346 fscanf(pFile,"%s",tmp); // 3
1347 instantVector.push_back( atoi(tmp) );
1348 fscanf(pFile,"%s",tmp); // 4
1349 instantVector.push_back( atoi(tmp) );
1350 fscanf(pFile,"%s",tmp); // 5
1351 instantVector.push_back( atoi(tmp) );
1352 fscanf(pFile,"%s",tmp); // 6
1353 instantVector.push_back( atoi(tmp) );
1356 fscanf(pFile,"%s",tmp); // TypeContourModel
1357 fscanf(pFile,"%s",tmp); // ##
1358 typeContourModel = atoi(tmp);
1360 manModelContour = kernelManager->factoryManualContourModel(typeContourModel);
1361 manModelContour->Open(pFile);
1362 if(pFileData != NULL)
1364 manModelContour->OpenData(pFileData);
1367 fscanf(pFile,"%s",tmp); // TypeView
1368 fscanf(pFile,"%s",tmp); // ##
1369 typeView = atoi(tmp);
1371 std::string theName;
1372 theName = kernelManager->createOutline( manModelContour, instantVector );
1373 bool addedModel = theName.compare("") != 0;
1376 double spc[3];//Si no hay imagen pero hay contornos que spacing se pone por default
1377 _theViewPanel->getSpacing(spc);
1378 //Adding the manualContourControler to interface objects structure
1379 //Adding the manualViewContour to interface objects structure
1380 //_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.
1381 _theViewPanel->getSceneManager()->configureViewControlTo( theName, manModelContour,spc , typeView) ;
1384 if (staticContour) //StaticContours (will appear in all slices)
1386 Instant instant(&instantVector);
1387 kernelManager->changeContourOfManager( theName , &instant );
1390 }// for numberOfContours
1393 else if (compatible==false)
1398 for (i=0;i<numberOfContours;i++)
1400 instantVector.clear();
1401 fscanf(pFile,"%s",tmp); // Instant
1403 fscanf(pFile,"%s",tmp); // 1
1404 instantVector.push_back( atoi(tmp) );
1405 fscanf(pFile,"%s",tmp); // 2
1406 instantVector.push_back( atoi(tmp) );
1407 fscanf(pFile,"%s",tmp); // 3
1408 instantVector.push_back( atoi(tmp) );
1409 fscanf(pFile,"%s",tmp); // 4
1410 instantVector.push_back( atoi(tmp) );
1411 fscanf(pFile,"%s",tmp); // 5
1412 instantVector.push_back( atoi(tmp) );
1413 fscanf(pFile,"%s",tmp); // 6
1414 instantVector.push_back( atoi(tmp) );
1416 fscanf(pFile,"%s",tmp); // TypeContourModel
1417 fscanf(pFile,"%s",tmp); // ##
1418 typeContourModel = atoi(tmp);
1420 manModelContour = kernelManager->factoryManualContourModel(typeContourModel);
1421 manModelContour->Open(pFile);
1422 if(pFileData != NULL)
1424 manModelContour->OpenData(pFileData);
1427 if (_tmpReadFileTypeOfTransformation==-1){
1429 } else if (_tmpReadFileTypeOfTransformation==0){
1430 double transX, transY;
1431 transX = (double) imageDim[0]/_tmpReadFileImageDim[0];
1432 transY = (double) imageDim[1]/_tmpReadFileImageDim[1];
1433 manModelContour->Transform_Ax_Plus_B(transX,0,transY,0);
1434 } else if (_tmpReadFileTypeOfTransformation==1) {
1435 double transX, transY;
1436 transX = (double) _tmpReadFileImageSpac[0]/imageDim[0];
1437 transY = (double) _tmpReadFileImageSpac[1]/imageDim[1];
1438 manModelContour->Transform_Ax_Plus_B(transX,0,transY,0);
1441 fscanf(pFile,"%s",tmp); // TypeView
1442 fscanf(pFile,"%s",tmp); // ##
1443 typeView = atoi(tmp);
1445 std::string theName;
1446 theName = kernelManager->createOutline( manModelContour, instantVector );
1447 bool addedModel = theName.compare("") != 0;
1450 double spc[3];//Si no hay imagen pero hay contornos que spacing se pone por default
1451 _theViewPanel->getSpacing(spc);
1452 //Adding the manualContourControler to interface objects structure
1453 //Adding the manualViewContour to interface objects structure
1454 //_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.
1455 _theViewPanel->getSceneManager()->configureViewControlTo( theName, manModelContour,spc , typeView) ;
1458 if (staticContour) //StaticContours (will appear in all slices)
1460 Instant instant(&instantVector);
1461 kernelManager->changeContourOfManager( theName , &instant );
1463 }// for numberOfContours
1469 void wxContourMainFrame::RefreshInterface(){
1471 _theViewPanel->RefreshInterface();
1472 //wxVtk2DBaseView *wxvtk2dbaseview = (wxVtk2DBaseView*)this->_theViewPanel->getWxVtkBaseView();
1473 //wxvtk2dbaseview->Refresh();
1476 vtkImageData* wxContourMainFrame::getImageData(){
1477 return _theViewPanel->getImageData();
1480 void wxContourMainFrame::onSegmentationOneSliceITK(wxString distance, wxString sigma, wxString alfa, wxString beta, wxString propagation, wxString iterations, wxString inflation)
1482 //JCP 20-10-08 Undo redo implementation
1484 //JCP 20-10-08 Undo redo implementation
1487 int x = _theViewPanel->GetX();
1488 int y = _theViewPanel->GetY();
1489 int z = _theViewPanel->GetZ();
1490 SegmentationOneSliceITK( x,y,z,distance, sigma, alfa, beta, propagation, iterations, inflation);
1494 void wxContourMainFrame::SegmentationOneSliceITK(int x, int y, int z, wxString distanc, wxString sigm, wxString alf, wxString bet, wxString prop, wxString iter, wxString inflation)
1496 int typeofcontour = 1;
1498 vtkImageData *imagedata = getImageData();
1500 //Tipo de pixeles a utilizar internamente en ITK
1501 typedef float InternalPixelType;
1502 const unsigned int Dimension = 2;
1503 typedef itk::Image< InternalPixelType, Dimension > InternalImageType;
1505 //Tipo de pixeles de salida 1
1506 typedef unsigned char OutputPixelType;
1507 typedef itk::Image< OutputPixelType, Dimension > OutputImageType;
1509 //Tipo de pixeles de salida 2
1510 typedef unsigned short OutputPixelType2;
1511 typedef itk::Image< OutputPixelType2, Dimension > OutputImageType2;
1513 //DefiniciÛn del thresholder
1514 typedef itk::BinaryThresholdImageFilter<
1516 OutputImageType > ThresholdingFilterType;
1518 //DefiniciÛn del primer filtro de conversiÛn de pixeles
1519 typedef itk::CastImageFilter<
1520 OutputImageType, OutputImageType2 > CastFilterType;
1522 //DefiniciÛn del segundo tipo de conversiÛn de pixeles
1523 typedef itk::CastImageFilter<
1524 OutputImageType2, InternalImageType > CastFilterType2;
1526 //Tercer tipo de conversiÛn
1527 typedef itk::RescaleIntensityImageFilter<
1529 OutputImageType > CastFilterType3;
1531 //Cuarto tipo de conversiÛn
1532 typedef itk::RescaleIntensityImageFilter<
1534 OutputImageType > CastFilterType4;
1536 ThresholdingFilterType::Pointer thresholder = ThresholdingFilterType::New();
1538 thresholder->SetLowerThreshold( 0.0 );
1539 thresholder->SetUpperThreshold( 128 );
1541 thresholder->SetOutsideValue( 255 );
1542 thresholder->SetInsideValue( 0 );
1544 //DefinciÛn de conexiÛnes entre VTK e ITK y el writer
1545 typedef itk::VTKImageToImageFilter<OutputImageType2> ConnectorType;
1546 typedef itk::ImageToVTKImageFilter<OutputImageType> ConnectorType2;
1547 //EED10JUIN2011 typedef itk::ImageFileWriter< OutputImageType > WriterType;
1549 ConnectorType::Pointer connector= ConnectorType::New();
1550 ConnectorType2::Pointer connector2= ConnectorType2::New();
1553 CastFilterType::Pointer filter=CastFilterType::New();
1554 CastFilterType2::Pointer filter2=CastFilterType2::New();
1556 connector->SetInput( imagedata );
1557 filter2->SetInput(connector->GetOutput());
1559 typedef itk::CurvatureAnisotropicDiffusionImageFilter<
1561 InternalImageType > SmoothingFilterType;
1563 SmoothingFilterType::Pointer smoothing = SmoothingFilterType::New();
1565 typedef itk::GradientMagnitudeRecursiveGaussianImageFilter<
1567 InternalImageType > GradientFilterType;
1569 typedef itk::SigmoidImageFilter<
1571 InternalImageType > SigmoidFilterType;
1573 GradientFilterType::Pointer gradientMagnitude = GradientFilterType::New();
1575 SigmoidFilterType::Pointer sigmoid = SigmoidFilterType::New();
1577 sigmoid->SetOutputMinimum( 0.0 );
1578 sigmoid->SetOutputMaximum( 255.0 );
1581 typedef itk::FastMarchingImageFilter<
1583 InternalImageType > FastMarchingFilterType;
1586 FastMarchingFilterType::Pointer fastMarching = FastMarchingFilterType::New();
1588 printf("EED wxContourMainFrame::SegmentationOneSliceITK Skypping this code. Not compiling GeodesicActiveContourLevelSetImageFilter in fedora 17 with ITK 3.20.1 \n ");
1590 > - > - > - > - > - > - > - > - > - > - > - > - > - > - > - > - Not compiling GeodesicActiveContourLevelSetImageFilter in fedora 17 with ITK 3.20.1
1593 typedef itk::GeodesicActiveContourLevelSetImageFilter< InternalImageType,
1594 InternalImageType > GeodesicActiveContourFilterType;
1595 GeodesicActiveContourFilterType::Pointer geodesicActiveContour =
1596 GeodesicActiveContourFilterType::New();
1598 typedef itk::ZeroCrossingImageFilter<
1600 InternalImageType > ZeroCrossingFilterType;
1601 ZeroCrossingFilterType::Pointer zeroCrossing =
1602 ZeroCrossingFilterType::New();
1604 const double propagationScaling = atof( crea::wx2std(prop).c_str() );
1606 geodesicActiveContour->SetPropagationScaling( propagationScaling );
1607 geodesicActiveContour->SetCurvatureScaling( 1.0 );
1608 geodesicActiveContour->SetAdvectionScaling( 1.0 );
1610 geodesicActiveContour->SetMaximumRMSError( 0.02 );
1611 int it=atoi( crea::wx2std(iter).c_str() );
1612 geodesicActiveContour->SetNumberOfIterations( it );
1614 smoothing->SetInput( filter2->GetOutput() );
1615 gradientMagnitude->SetInput( smoothing->GetOutput() );
1616 sigmoid->SetInput( gradientMagnitude->GetOutput() );
1617 fastMarching->SetInput( sigmoid->GetOutput() );
1618 geodesicActiveContour->SetInput( fastMarching->GetOutput() );
1619 geodesicActiveContour->SetFeatureImage( sigmoid->GetOutput() );
1621 zeroCrossing->SetInput( geodesicActiveContour->GetOutput() );
1622 //thresholder->SetInput( zeroCrossing->GetOutput() );
1623 thresholder->SetInput( geodesicActiveContour->GetOutput() );
1624 connector2->SetInput( thresholder->GetOutput() );
1626 < - < - < - < - < - < - < - < - < - < - < - < - < - < - < - < - < - < - < - < -
1632 smoothing->SetTimeStep( 0.125 );
1633 smoothing->SetNumberOfIterations( 5 );
1634 smoothing->SetConductanceParameter( 9.0 );
1637 const double sigma = atof( crea::wx2std(sigm).c_str() );
1638 gradientMagnitude->SetSigma( sigma );
1640 const double alpha = atof( crea::wx2std(alf).c_str() );
1641 const double beta = atof( crea::wx2std(bet).c_str() );
1643 sigmoid->SetAlpha( alpha );
1644 sigmoid->SetBeta( beta );
1646 typedef FastMarchingFilterType::NodeContainer NodeContainer;
1647 typedef FastMarchingFilterType::NodeType NodeType;
1649 NodeContainer::Pointer seeds = NodeContainer::New();
1651 InternalImageType::IndexType seedPosition;
1652 seedPosition[0] = x;
1653 seedPosition[1] = y;
1655 const double initialDistance = atof( crea::wx2std(distanc).c_str() );
1659 const double seedValue = - initialDistance;
1661 node.SetValue( seedValue );
1662 node.SetIndex( seedPosition );
1664 seeds->Initialize();
1665 seeds->InsertElement( 0, node );
1667 fastMarching->SetTrialPoints( seeds );
1669 fastMarching->SetSpeedConstant( 1.0 );
1671 fastMarching->SetOutputSize(
1672 connector->GetOutput()->GetBufferedRegion().GetSize() );
1674 fastMarching->SetStoppingValue( 800 );
1678 connector2->Update();
1679 vtkImageData *idata = connector2->GetOutput();
1681 vtkMarchingContourFilter* cntVTK = vtkMarchingContourFilter::New( );
1683 cntVTK->SetInput( idata );
1685 cntVTK->SetNumberOfContours( 1 );
1686 cntVTK->SetValue( 0, 255 );
1688 cntVTK->UpdateInformation();
1690 vtkCleanPolyData* cpd = vtkCleanPolyData::New( );
1691 cpd->SetInput( cntVTK->GetOutput( ) );
1693 cpd->UpdateInformation();
1695 vtkPolyDataConnectivityFilter* conn = vtkPolyDataConnectivityFilter::New( );
1696 conn->SetExtractionModeToLargestRegion( );
1697 conn->SetInput( cpd->GetOutput( ) );
1699 conn->UpdateInformation();
1701 vtkStripper* vtkstripper = vtkStripper::New( );
1702 vtkstripper->SetInput( conn->GetOutput() );
1703 vtkstripper->Update();
1704 vtkstripper->UpdateInformation();
1706 vtkPolyData* polyDataResult = cntVTK->GetOutput();
1707 //std::cout<<"Points "<<polyDataResult->GetNumberOfPoints()<<std::endl;
1708 polyDataResult->Update( );
1709 polyDataResult->UpdateInformation();
1714 myfile.open ("C:/Creatis/example.txt");
1716 polyDataResult->Print(myfile);
1717 myfile << "-------------------------------------\n";
1718 polyDataResult->GetLines()->Print(myfile);
1726 //--Calculating control points
1728 std::vector<double> vecX;
1729 std::vector<double> vecY;
1730 std::vector<double> vecXo;
1731 std::vector<double> vecYo;
1732 std::vector<double>::iterator vecXoi;
1733 std::vector<double>::iterator vecYoi;
1734 std::vector<double> vecZ;
1736 std::vector<double> vecCtrlPointX;
1737 std::vector<double> vecCtrlPointY;
1738 std::vector<double> vecCtrlPointZ;
1744 int ii,size=polyDataResult->GetNumberOfPoints();
1746 myfile.open ("C:/Creatis/example2.txt");
1748 size=polyDataResult->GetNumberOfPoints();
1749 for (ii=0;ii<size;ii++)
1756 p = polyDataResult->GetPoint(ii);
1759 /*if(fabs(yAct-y)>20)
1761 if((xAct-x)>1 || (xAct-x)<-1)
1763 vecX.push_back( p[0] );
1764 vecY.push_back( p[1] );
1765 myfile <<p[0]<<","<<p[1]<<"\n";
1766 std::cout<<" x Anterior "<<xAct<<" x actual "<<x<<std::endl;
1767 std::cout<<" y Anterior "<<yAct<<" y actual "<<y<<std::endl;
1768 std::cout<<" x "<<p[0]<<" y "<<p[1]<<std::endl;
1769 vecZ.push_back( 900 );
1775 vecXo.push_back(p[0]);
1776 vecYo.push_back(p[1]);
1780 else*/ if(fabs(xAct-x)>11)
1782 vecXo.push_back(p[0]);
1783 vecYo.push_back(p[1]);
1787 vecX.push_back( p[0] );
1788 myfile <<p[0]<<","<<p[1]<<"\n";
1789 //std::cout<<" x Anterior "<<xAct<<" x actual "<<x<<std::endl;
1790 //std::cout<<" y Anterior "<<yAct<<" y actual "<<y<<std::endl;
1791 //std::cout<<" x "<<p[0]<<" y "<<p[1]<<std::endl;
1792 vecY.push_back( p[1] );
1793 vecZ.push_back( 900 );
1801 while(!vecXo.empty())
1803 vecX.push_back(vecXo.back());
1804 //std::cout<<" x Siguiente "<<vecXo.back();
1806 vecZ.push_back( 900 );
1808 while(!vecYo.empty())
1810 vecY.push_back(vecYo.back());
1815 /*for(int l=0;l<vecX.size();l++)
1819 vecXo.push_back(p[0]);
1820 vecYo.push_back(p[1]);
1831 ExtractControlPoints2D *extractcontrolpoints2d = new ExtractControlPoints2D();
1833 extractcontrolpoints2d->SetContour( &vecX , &vecY , &vecZ );
1837 extractcontrolpoints2d->GetInitialControlPoints( &vecCtrlPointX , &vecCtrlPointY , &vecCtrlPointZ );
1839 else if (method==1){
1840 extractcontrolpoints2d->GetControlPoints( &vecCtrlPointX , &vecCtrlPointY , &vecCtrlPointZ );
1842 else if (method==2){
1843 extractcontrolpoints2d->SetSamplingControlPoints( 15 );
1844 extractcontrolpoints2d->GetSamplingControlPoints( &vecCtrlPointX , &vecCtrlPointY , &vecCtrlPointZ );
1846 //--Adding contour to the system
1848 std::vector<int> actualInstantVector;
1849 _instantPanel->getInstant( actualInstantVector );
1850 actualInstantVector[1]=z;
1852 int j,sizeCtrPt = vecCtrlPointX.size();
1854 manualBaseModel *manModelContour = kernelManager->factoryManualContourModel( typeofcontour );
1855 manModelContour->SetNumberOfPointsSpline( ((sizeCtrPt/100)+1)*100 );
1857 for (j=0 ; j<sizeCtrPt ; j++)
1859 manModelContour->AddPoint( vecCtrlPointX[j] , vecCtrlPointY[j] , vecCtrlPointZ[j] );
1861 std::string theName;
1862 //theName = _modelManager->createOutline( manModelContour, actualInstantVector );
1863 theName = kernelManager->createOutline( manModelContour, actualInstantVector );
1864 bool addedModel = theName.compare("") != 0;
1867 double spc[3];//Si no hay imagen pero hay contornos que spacing se pone por default
1868 _theViewPanel->getSpacing(spc);
1869 //Adding the manualContourControler to interface objects structure
1870 //Adding the manualViewContour to interface objects structure
1871 //_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.
1872 _theViewPanel->configureViewControlTo(theName, manModelContour, spc, typeofcontour);
1873 //_theViewPanel->getSceneManager()->configureViewControlTo( theName, manModelContour,spc, typeofcontour ) ;
1880 WriterType::Pointer writer = WriterType::New();
1881 CastFilterType3::Pointer caster = CastFilterType3::New();
1883 caster->SetInput( gradientMagnitude->GetOutput() );
1884 writer->SetInput( caster->GetOutput() );
1885 writer->SetFileName("Gradient Magnitude.png");
1886 caster->SetOutputMinimum( 0 );
1887 caster->SetOutputMaximum( 255 );
1890 CastFilterType3::Pointer caster2 = CastFilterType3::New();
1891 WriterType::Pointer writer2 = WriterType::New();
1893 caster2->SetInput( sigmoid->GetOutput() );
1894 writer2->SetInput( caster2->GetOutput() );
1895 writer2->SetFileName("Sigmoid.png");
1896 caster2->SetOutputMinimum( 0 );
1897 caster2->SetOutputMaximum( 255 );
1900 CastFilterType3::Pointer caster3 = CastFilterType3::New();
1901 WriterType::Pointer writer3 = WriterType::New();
1903 caster3->SetInput( fastMarching->GetOutput() );
1904 writer3->SetInput( caster3->GetOutput() );
1905 writer3->SetFileName("FastMarching.bmp");
1906 caster3->SetOutputMinimum( 0 );
1907 caster3->SetOutputMaximum( 255 );
1910 CastFilterType3::Pointer caster4 = CastFilterType3::New();
1911 WriterType::Pointer writer4 = WriterType::New();
1913 caster4->SetInput( geodesicActiveContour->GetOutput() );
1914 writer4->SetInput( caster4->GetOutput() );
1915 writer4->SetFileName("GeodesicActiveContour.png");
1916 caster4->SetOutputMinimum( 0 );
1917 caster4->SetOutputMaximum( 255 );
1920 CastFilterType3::Pointer caster5 = CastFilterType3::New();
1921 WriterType::Pointer writer5 = WriterType::New();
1923 caster5->SetInput( zeroCrossing->GetOutput() );
1924 writer5->SetInput( caster5->GetOutput() );
1925 writer5->SetFileName("ZeroCrossing.bmp");
1926 caster5->SetOutputMinimum( 0 );
1927 caster5->SetOutputMaximum( 255 );
1931 catch( itk::ExceptionObject & excep )
1933 std::cerr << "Exception caught !" << std::endl;
1934 std::cerr << excep << std::endl;
1938 void wxContourMainFrame::onSegmentationOneSlice(int isovalue,int sampling,int method){
1940 //JCP 20-10-08 Undo redo implementation
1942 //JCP 20-10-08 Undo redo implementation
1945 int x = _theViewPanel->GetX();
1946 int y = _theViewPanel->GetY();
1947 int z = _theViewPanel->GetZ();
1948 SegmentationOneSlice( x,y,z,isovalue, sampling, method );
1953 void wxContourMainFrame::SegmentationOneSlice( int x, int y, int z, int isovalue, int sampling, int method )
1955 int typeofcontour = 1;
1956 //--Extracting Contour
1957 //vtkImageData *imagedata = _theViewPanel->getSceneManager()->GetImageData();
1958 vtkImageData *imagedata = getImageData();
1959 // double *range = imagedata->GetScalarRange();
1962 vtkImageReslice *imageReslice = vtkImageReslice::New();
1965 // imagedata->GetSpacing(spc);
1970 imageReslice->SetInput( imagedata );
1971 imageReslice->SetInformationInput(imagedata);
1972 imageReslice->SetResliceAxesDirectionCosines(1,0,0, 0,1,0 ,0,0,1);
1973 imageReslice->SetResliceAxesOrigin(0,0,z);
1974 imageReslice->SetOutputDimensionality(2);
1975 imageReslice->SetInterpolationModeToLinear();
1977 imagedata = imageReslice->GetOutput();
1978 imagedata->Update();
1979 imagedata->UpdateInformation();
1981 vtkContourFilter* cntVTK = vtkContourFilter::New( );
1982 cntVTK->SetInput( imagedata );
1984 cntVTK->SetNumberOfContours( 1 );
1985 //cntVTK->SetValue( 0, vmin );
1986 // cntVTK->SetValue( 0, (range[1]*thr/100) );
1987 cntVTK->SetValue( 1, isovalue );
1988 // cntVTK->SetValue( 1, vmax );
1990 cntVTK->UpdateInformation();
1992 vtkCleanPolyData* cpd = vtkCleanPolyData::New( );
1993 cpd->SetInput( cntVTK->GetOutput( ) );
1994 cpd->ConvertLinesToPointsOff( );
1996 cpd->UpdateInformation();
1998 vtkPolyDataConnectivityFilter* conn = vtkPolyDataConnectivityFilter::New( );
1999 conn->SetExtractionModeToClosestPointRegion( );
2000 //conn->SetMaxRecursionDepth( 3000 );
2002 conn->SetInput( cpd->GetOutput( ) );
2004 conn->SetClosestPoint( x, y, 0 );
2006 conn->UpdateInformation();
2008 vtkCleanPolyData* cpd2 = vtkCleanPolyData::New( );
2009 cpd2->SetInput( conn->GetOutput( ) );
2011 cpd2->UpdateInformation();
2013 vtkStripper* vtkstripper = vtkStripper::New( );
2014 vtkstripper->SetInput( cpd2->GetOutput() );
2015 vtkstripper->Update();
2016 vtkstripper->UpdateInformation();
2019 vtkPolyData* polyDataResult = vtkstripper->GetOutput();
2021 polyDataResult->Update( );
2022 polyDataResult->UpdateInformation();
2026 myfile.open ("c:/temp/example.txt");
2028 polyDataResult->Print(myfile);
2029 myfile << "-------------------------------------\n";
2030 polyDataResult->GetLines()->Print(myfile);
2040 //--Calculating control points
2042 std::vector<double> vecX;
2043 std::vector<double> vecY;
2044 std::vector<double> vecZ;
2046 std::vector<double> vecCtrlPointX;
2047 std::vector<double> vecCtrlPointY;
2048 std::vector<double> vecCtrlPointZ;
2052 int ii,size=polyDataResult->GetNumberOfPoints();
2054 for (ii=1;ii<=size;ii++)
2056 id = polyDataResult->GetLines()->GetData()->GetValue(ii);
2057 p = polyDataResult->GetPoint(id);
2060 vecX.push_back( p[0] );
2061 vecY.push_back( p[1] );
2062 vecZ.push_back( 900 );
2063 // vecZ.push_back( p[2] );
2067 ExtractControlPoints2D *extractcontrolpoints2d = new ExtractControlPoints2D();
2068 extractcontrolpoints2d->SetContour( &vecX , &vecY , &vecZ );
2071 /*if (methodRadiobox->GetSelection()==0){
2072 extractcontrolpoints2d->GetInitialControlPoints( &vecCtrlPointX , &vecCtrlPointY , &vecCtrlPointZ );
2074 if (methodRadiobox->GetSelection()==1){
2075 extractcontrolpoints2d->GetControlPoints( &vecCtrlPointX , &vecCtrlPointY , &vecCtrlPointZ );
2077 if (methodRadiobox->GetSelection()==2){
2078 extractcontrolpoints2d->SetSamplingControlPoints( sampling );
2079 extractcontrolpoints2d->GetSamplingControlPoints( &vecCtrlPointX , &vecCtrlPointY , &vecCtrlPointZ );
2083 extractcontrolpoints2d->GetInitialControlPoints( &vecCtrlPointX , &vecCtrlPointY , &vecCtrlPointZ );
2085 else if (method==1){
2086 extractcontrolpoints2d->GetControlPoints( &vecCtrlPointX , &vecCtrlPointY , &vecCtrlPointZ );
2088 else if (method==2){
2089 extractcontrolpoints2d->SetSamplingControlPoints( sampling );
2090 extractcontrolpoints2d->GetSamplingControlPoints( &vecCtrlPointX , &vecCtrlPointY , &vecCtrlPointZ );
2093 //--Adding contour to the system
2095 std::vector<int> actualInstantVector;
2096 _instantPanel->getInstant( actualInstantVector );
2097 actualInstantVector[1]=z;
2099 int j,sizeCtrPt = vecCtrlPointX.size();
2100 manualBaseModel *manModelContour = kernelManager->factoryManualContourModel( typeofcontour );
2101 manModelContour->SetNumberOfPointsSpline( ((sizeCtrPt/100)+1)*100 );
2103 for (j=0 ; j<sizeCtrPt ; j++)
2105 manModelContour->AddPoint( vecCtrlPointX[j] , vecCtrlPointY[j] , vecCtrlPointZ[j] );
2107 std::string theName;
2108 //theName = _modelManager->createOutline( manModelContour, actualInstantVector );
2109 theName = kernelManager->createOutline( manModelContour, actualInstantVector );
2110 bool addedModel = theName.compare("") != 0;
2113 double spc[3];//Si no hay imagen pero hay contornos que spacing se pone por default
2114 _theViewPanel->getSpacing(spc);
2115 //Adding the manualContourControler to interface objects structure
2116 //Adding the manualViewContour to interface objects structure
2117 //_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.
2118 _theViewPanel->configureViewControlTo(theName, manModelContour, spc, typeofcontour);
2119 //_theViewPanel->getSceneManager()->configureViewControlTo( theName, manModelContour,spc, typeofcontour ) ;
2123 int wxContourMainFrame::GetImageDataSizeZ(){
2124 return _theViewPanel->GetImageDataSizeZ();
2127 void wxContourMainFrame::GetImageDataRange(double *range){
2128 _theViewPanel->GetImageDataRange(range);
2131 void wxContourMainFrame::onSegmentationAllSlice(int minZ,int maxZ,int isovalue,int sampling,int method){
2132 //JCP 20-10-08 Undo redo implementation
2134 //JCP 20-10-08 Undo redo implementation
2137 int x = _theViewPanel->GetX();
2138 int y = _theViewPanel->GetY();
2142 double totalZ = maxZ-minZ+1;
2143 for( z=minZ ; z<=maxZ ; z++ )
2145 porcent = 100.0* (z-minZ)/totalZ;
2146 tmpString.Printf(_T(" %d %c %d/%d %d"), (int)porcent , 37 , z-minZ+1, (int)totalZ,z );
2147 interfMainPanel::getInstance()->setLabelSegmentationPanelVTK(tmpString);
2148 //_staticTextSegmentation->SetLabel(tmpString);
2149 SegmentationOneSlice( x,y,z,isovalue, sampling,method );
2151 interfMainPanel::getInstance()->setLabelSegmentationPanelVTK(_T(" "));
2156 //Creates a reference line to be used as the axis of the mirroring
2157 void wxContourMainFrame::referenceLine()
2159 if (_refLineControl==NULL)
2164 vtkImageData *vtkimagedata = _theViewPanel->getImageData();
2165 vtkimagedata->GetSpacing(spc);
2167 wxVtkBaseView * viewer2D = _theViewPanel->getWxVtkBaseView();
2169 _refLineControl = new manualLineControler();
2170 _refLineModel = new manualContourModelLine();
2171 _refLineView = new manualViewLine();
2172 _refLineView->SetModel( _refLineModel );
2173 _refLineView->SetWxVtkBaseView( viewer2D );
2174 _refLineView->SetRange( 2 );
2175 _refLineView->SetZ( 1200 );
2177 _refLineView->SetSpacing(spc);
2179 _refLineView->SetColorNormalContour(0, 0, 1);
2180 _refLineView->SetColorEditContour(0, 0.5, 0.5);
2181 _refLineView->SetWidthLine(4);
2183 _refLineControl->SetModelView( _refLineModel , _refLineView );
2184 vtkInteractorStyleBaseView* style = (vtkInteractorStyleBaseView*)viewer2D->GetInteractorStyleBaseView();
2185 style->AddInteractorStyleMaracas( _refLineControl );
2186 _refLineModel->SetCloseContour(false);
2187 _refLineControl->CreateNewManualContour();
2189 //AD: Inicializar el mirroring con una linea ya pintada
2191 double z = _refLineControl->GetZ();
2194 image->GetDimensions(imageDim);
2195 double x = (double) imageDim[0]/2;
2196 double y1 = (double) (imageDim[1]/2)+15;
2197 double y2 = (double) (imageDim[1]/2)-15;
2199 _refLineControl->AddPoint(x,y1,z);
2200 _refLineControl->AddPoint(x,y2,z);
2201 _refLineControl->SetCompleteCreation(true);
2203 _refLineModel->AddPoint(x,y1,z);
2204 _refLineModel->AddPoint(x,y2,z);
2205 _refLineModel->UpdateSpline();
2207 _refLineView->UpdateViewPoint(0);
2208 _refLineView->UpdateViewPoint(1);
2211 _refLineControl->SetActive(true);
2212 _refLineView->RefreshContour();
2216 //Hides the referenceLine
2217 void wxContourMainFrame::refLineHide()
2219 if (_refLineControl!=NULL)
2221 if (_refLineControl->GetActive())
2223 _refLineView->RemoveCompleteContourActor();
2224 _refLineControl->SetEditable(false);
2225 _refLineControl->SetActive(false);
2232 //Shows the referenceLine
2233 void wxContourMainFrame::refLineShow()
2235 if (_refLineControl!=NULL)
2237 if (_refLineControl->GetActive()==false)
2239 wxVtkBaseView * viewer2D = _theViewPanel->getWxVtkBaseView();
2241 _refLineView->SetModel( _refLineModel );
2242 _refLineView->SetWxVtkBaseView( viewer2D );
2243 _refLineView->SetRange( 2 );
2244 _refLineView->SetZ( 1200 );
2246 _refLineControl->SetModelView( _refLineModel , _refLineView );
2247 vtkInteractorStyleBaseView* style = (vtkInteractorStyleBaseView*)viewer2D->GetInteractorStyleBaseView();
2248 style->AddInteractorStyleMaracas( _refLineControl );
2249 _refLineControl->CreateNewManualContour();
2250 _refLineControl->SetActive(true);
2251 _refLineView->RefreshContour();
2258 void wxContourMainFrame::refLineChangeWidth(int width)
2260 _refLineView->SetWidthLine(width);
2261 _refLineView->RefreshContour();
2267 void wxContourMainFrame::onMirror()
2270 std::vector<std::string> currentSelection = _theViewPanel->getSelectedObjects();
2271 std::vector<std::string> filterCurrentSelection;
2273 std::vector<int> tempVector;
2274 _instantPanel->getInstant( tempVector );
2275 _performingOperation->reset();
2276 _performingOperation->setStartCommand( COPY );
2277 _performingOperation->setStartOperationInstantVector( tempVector );
2278 _performingOperation->setKeyNamesOperationElems( currentSelection );
2280 char theStartCommand = _performingOperation->getStartCommand();
2281 if ( theStartCommand == COPY )
2283 //JCP 20-10-08 Undo redo implementation
2285 //JCP 20-10-08 Undo redo implementation
2286 std::vector<int> tempVector;
2287 _instantPanel->getInstant( tempVector );
2288 _performingOperation->setEndOperationInstantVector ( tempVector );
2289 std::vector<std::string> elems = _performingOperation->getKeyNamesOperationElems();
2290 int i,size = elems.size();
2291 for( i=0; i<size; i++ )
2293 createMirrorContourOf( elems[i], tempVector, i>0 );
2297 //deleteContour( _refName );
2302 void wxContourMainFrame::showAxis(bool show)
2304 _theViewPanel->SetVisibleAxis(show);
2305 _theViewPanel->Refresh();
2309 void wxContourMainFrame::onRigidPressed(){
2310 std::vector<std::string> currentSelection = _theViewPanel->getSelectedObjects();
2311 int elementsSelected = currentSelection.size();
2313 if ( elementsSelected >= 1 ){
2314 //JCP 20-10-08 Undo redo implementation
2316 //JCP 20-10-08 Undo redo implementation
2318 std::vector<int> tempVector;
2319 _instantPanel->getInstant( tempVector );
2320 Instant instant(&tempVector);
2322 int i , size=currentSelection.size();
2323 for ( i=0 ; i<size ; i++ )
2325 kernelManager->changeContourOfManager(currentSelection[i], &instant);
2330 void wxContourMainFrame::onWidthOfContour(double width){
2332 _theViewPanel->removeSceneContours();
2333 _theViewPanel->SetWidthContour(width);
2335 //_theViewPanel->getSceneManager()->SetWidthContour( width );
2340 int wxContourMainFrame::getColorWindow()
2344 vtkImageData * img = getImageData();
2345 img->GetScalarRange(range);
2347 std::cout<<"Val 1: "<<range[0]<<" Val 2: "<<range[1]<<std::endl;
2349 return (int)range[1];
2351 return _theViewPanel->getColorWindow();
2354 int wxContourMainFrame::getWindowLevel()
2358 vtkImageData * img = getImageData();
2359 img->GetScalarRange(range);
2361 std::cout<<"Val 1: "<<range[0]<<" Val 2: "<<range[1]<<std::endl;
2363 return (int)range[1];
2365 return _theViewPanel->getWindowLevel();
2368 void wxContourMainFrame::onBrigthnessColorWindowLevel(int colorwindow,int windowlevel){
2369 _theViewPanel->onBrigthnessColorWindowLevel(colorwindow, windowlevel);
2374 void wxContourMainFrame::onInterpolation(bool interpolate){
2375 _theViewPanel->onInterpolation(interpolate);
2379 void wxContourMainFrame::onChangeInstant(std::string name,int actual){
2380 _instantPanel->setConceptValue( name, actual );
2384 void wxContourMainFrame::resetAppend(){
2385 kernelManager->resetAppend();
2390 void wxContourMainFrame::onSpreadAdd(){
2391 std::vector<double> vecX;
2392 std::vector<double> vecY;
2393 std::vector<double> vecZ;
2394 _theViewPanel->GetPointsOfActualContour(&vecX , &vecY , &vecZ );
2395 std::vector<int> tempVector;
2396 _instantPanel->getInstant( tempVector );
2397 std::string val = kernelManager->onSpreadAdd(&vecX , &vecY , &vecZ, tempVector);
2398 interfMainPanel::getInstance()->appendStringSpread(val);
2402 void wxContourMainFrame::onSpreadAddAll(){
2404 std::vector<int> tempVector;
2405 _instantPanel->getInstant( tempVector );
2408 maxZ = interfMainPanel::getInstance()->GetImageDataSizeZ();
2410 int sizeLstContourThings;
2411 for ( z=minZ ; z<=maxZ ; z++ )
2414 Instant instant(&tempVector);
2415 std::vector<ContourThing**> lstContourThings = kernelManager->getOutlinesAtInstant( &instant );
2416 sizeLstContourThings = lstContourThings.size();
2417 if (sizeLstContourThings>=1)
2419 std::vector<double> vecX;
2420 std::vector<double> vecY;
2421 std::vector<double> vecZ;
2422 ContourThing **contourthing = lstContourThings[0];
2423 manualBaseModel *cModel = (*contourthing)->getModel();
2424 int i,size = cModel->GetNumberOfPointsSpline();
2426 for (i=0; i<size; i++)
2428 cModel->GetSpline_i_Point(i, &x, &y, &z);
2433 std::string val = kernelManager->onSpreadAdd(&vecX , &vecY , &vecZ, tempVector);
2434 interfMainPanel::getInstance()->appendStringSpread(val);
2435 }// if sizeLstContourThings
2440 void wxContourMainFrame::onSpreadGo(int type){
2441 //JCP 20-10-08 Undo redo implementation
2443 //JCP 20-10-08 Undo redo implementation
2445 std::vector<double> vecCtrlPointX;
2446 std::vector<double> vecCtrlPointY;
2447 std::vector<double> vecCtrlPointZ;
2451 std::vector<int> tempVector;
2452 _instantPanel->getInstant( tempVector );
2455 kernelManager->getMaxMinZ(&minZ,&maxZ);
2456 //JSTG_16-07-08_----------------------------------------------------------------
2457 //_contourPropagation->setInterpolationNumber(maxZ-minZ+1);
2458 kernelManager->CalculeSplinePropagation();
2460 double totalZ = maxZ-minZ+1;
2463 //--------------------------------------------------------------------
2464 for ( z=(int)minZ ; z<=(int)maxZ ; z++ )
2466 porcent = 100.0* (z-minZ)/totalZ;
2467 int numero = (int)(z-minZ+1)/(int)totalZ;
2468 std::string stringtemp = " "+kernelManager->intToString(porcent)+"% "+kernelManager->intToString(numero)+" "+kernelManager->intToString(z);
2470 interfMainPanel::getInstance()->setStringSpread(stringtemp);
2472 int typeofcontour = 1;
2473 std::string theName;
2474 manualBaseModel* manModelContour = kernelManager->GetPoints(z, type, &vecCtrlPointX,&vecCtrlPointY,&vecCtrlPointZ, theName,typeofcontour, tempVector);
2476 if( manModelContour!=NULL ){
2477 double spc[3];//Si no hay imagen pero hay contornos que spacing se pone por default
2478 this->_theViewPanel->getSpacing(spc);
2479 //Adding the manualContourControler to interface objects structure
2480 //Adding the manualViewContour to interface objects structure
2481 //_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.
2482 _theViewPanel->configureViewControlTo( theName, manModelContour,spc,typeofcontour ) ;
2487 int numero = (int)(z-minZ+1)/(int)totalZ;
2488 std::string stringtemp = " "+kernelManager->intToString(porcent)+"% "+kernelManager->intToString(numero)+" "+kernelManager->intToString(z);
2490 interfMainPanel::getInstance()->setStringSpread(stringtemp);
2492 //RefreshInterface();
2495 void wxContourMainFrame::getInstantVector(std::vector<int>& tempVector){
2499 std::vector<std::string> wxContourMainFrame::getOutlinesName(int slide){
2500 std::vector<int> tempVector;
2501 _instantPanel->getInstant(tempVector);
2502 //Asignation of slide number should be different ex by name
2503 tempVector[1]=slide;
2504 return kernelManager->getOutlinesNameAtInstant(tempVector);
2508 void wxContourMainFrame::SetScalarRange(int grayRangeMin, int grayRangeMax)
2510 _contourextractdata->SetScalarRange(grayRangeMin,grayRangeMax);
2514 void wxContourMainFrame::onInformationContourLabels(int typeContourGroup,int selection,int minimumZ,int maximumZ,int grayRangeMin, int grayRangeMax)
2516 //EED01Juillet2009 GenerateContourExtractData();
2518 wxString tempString;
2519 int maxContourGroup = 0;
2521 _contourextractdata ->SetTypeOperation( typeContourGroup % 3 );
2523 std::vector<manualBaseModel*> lstManConMod;
2524 std::vector<manualBaseModel*> lstManConModTmp;
2525 std::vector<manualBaseModel*> lstManConModExp;
2526 std::vector<double> pLstValue;
2527 std::vector<double> pLstValuePosX;
2528 std::vector<double> pLstValuePosY;
2529 std::vector<double> pLstValuePosZ;
2532 int resultGrayRangeCount;
2535 double resultAverage;
2536 double resultStandardeviation;
2538 std::vector<int> tempVector;
2539 _instantPanel->getInstant( tempVector );
2541 //EED01Juillet2009 vtkImageData *imagedata = _theViewPanel->getImageData();
2542 // int sizeZ = _theViewPanel->GetImageDataSizeZ();
2544 int ii,sizeLstContourThings;
2553 if (selection==0 ) // actual slice
2555 int actualSlice = tempVector[1];
2558 } else { // slice range
2564 totalZ = maxZ-minZ+1;
2565 //EED01Juillet2009 _contourextractdata->SetImage( imagedata);
2567 _contourextractdata->InitVolumeStatistics();
2570 for ( z=minZ ; z<=maxZ ; z++ )
2573 porcent = 100.0* (z-minZ)/totalZ;
2574 tmpString.Printf(_T(" %d %c %d/%d %d"), (int)porcent , 37 , z-minZ+1, (int)totalZ ,z);
2576 interfMainPanel::getInstance()->setStringInfoPanel(tmpString);
2577 //_staticTextInformation->SetLabel(tmpString);
2579 //Extraction data from contours of each slice
2580 _contourextractdata->SetZtoBeAnalys(z);
2583 Instant instant(&tempVector);
2584 std::vector<ContourThing**> lstContourThings = kernelManager->getOutlinesAtInstant( &instant );
2585 sizeLstContourThings = lstContourThings.size();
2587 lstManConMod.clear();
2588 for (ii=0 ; ii<sizeLstContourThings ; ii++)
2590 ContourThing **contourthing = lstContourThings[ii];
2591 lstManConMod.push_back( (*contourthing)->getModel() );
2594 lstManConModExp = kernelManager->ExploseEachModel( lstManConMod );
2596 tempString.Printf(_T("%d - %d"),z, sizeLstContourThings);
2597 interfMainPanel::getInstance()->setRowLabelInfoPanel(z, tempString);
2598 //_grid->SetRowLabelValue(z, tempString );
2600 int iContourGroup,sizeContourGroup;
2601 if (typeContourGroup==3) // contour separete
2603 sizeContourGroup=lstManConModExp.size();
2604 if ( maxContourGroup<sizeContourGroup )
2606 maxContourGroup=sizeContourGroup;
2608 } else { // contour AND OR XOR
2615 for( iContourGroup=0 ; iContourGroup<sizeContourGroup ; iContourGroup++ ){
2616 lstManConModTmp.clear();
2620 if (typeContourGroup==3) // contour separete
2622 lstManConModTmp.push_back( lstManConModExp[iContourGroup]);
2623 } else { // contour AND OR XOR
2624 lstManConModTmp = lstManConModExp;
2627 _contourextractdata->SetLstManualContourModel( lstManConModTmp );
2628 _contourextractdata->SetScalarRange(grayRangeMin,grayRangeMax);
2631 pLstValuePosX.clear();
2632 pLstValuePosY.clear();
2633 pLstValuePosZ.clear();
2637 _contourextractdata->GetValuesInsideCrown( &numberOfPixels,
2643 resultSize=numberOfPixels;
2644 // Statistics of each slice.
2645 _contourextractdata->Statistics( &pLstValue,
2648 &resultGrayRangeCount,
2653 &resultStandardeviation);
2655 if (interfMainPanel::getInstance()->getNumberColsInformationPanel()<_numberOfVariablesStatistics*(iContourGroup+1) )
2657 interfMainPanel::getInstance()->appendColsInformationPanel(_numberOfVariablesStatistics);
2660 tmpIntA=_numberOfVariablesStatistics*iContourGroup ;
2662 tempString.Printf(_T("%d"),numberOfPixels);
2664 interfMainPanel::getInstance()->setCellValueInfoPanel(z, tmpIntA, tempString);
2666 tempString.Printf(_T("%d"),resultGrayRangeCount);
2667 interfMainPanel::getInstance()->setCellValueInfoPanel(z, tmpIntA+1, tempString);
2669 tempString.Printf(_T("%f"),resultMin);
2670 interfMainPanel::getInstance()->setCellValueInfoPanel(z, tmpIntA+2, tempString);
2672 tempString.Printf(_T("%f"),resultMax);
2673 interfMainPanel::getInstance()->setCellValueInfoPanel(z, tmpIntA+3, tempString);
2675 tempString.Printf(_T("%f"),resultAverage);
2676 interfMainPanel::getInstance()->setCellValueInfoPanel(z, tmpIntA+4, tempString);
2678 tempString.Printf(_T("%f"),resultStandardeviation);
2679 interfMainPanel::getInstance()->setCellValueInfoPanel(z, tmpIntA+5, tempString);
2682 } // for iContourGroup
2685 // Print Volume Statistics
2688 int vol_rCountRange;
2690 double vol_minValue;
2691 double vol_maxValue;
2693 double vol_standardeviation;
2695 if (selection!=0 ) // actual slice
2698 _contourextractdata->GetVolumeStatistics(&vol_rCountRange, &vol_rsize,
2699 &vol_minValue, &vol_maxValue,
2700 &vol_average, &vol_standardeviation);
2702 interfMainPanel::getInstance()->setRowLabelInfoPanel(maxZ+2, _T("Total:"));
2704 tempString.Printf(_T("%d"),vol_rsize);
2705 interfMainPanel::getInstance()->setCellValueInfoPanel(maxZ+2, 0, tempString);
2707 tempString.Printf(_T("%d"),vol_rCountRange);
2708 interfMainPanel::getInstance()->setCellValueInfoPanel(maxZ+2, 1, tempString);
2710 tempString.Printf(_T("%f"),vol_minValue);
2711 interfMainPanel::getInstance()->setCellValueInfoPanel(maxZ+2, 2, tempString);
2713 tempString.Printf(_T("%f"),vol_maxValue);
2714 interfMainPanel::getInstance()->setCellValueInfoPanel(maxZ+2, 3, tempString);
2716 tempString.Printf(_T("%f"),vol_average);
2717 interfMainPanel::getInstance()->setCellValueInfoPanel(maxZ+2, 4, tempString);
2719 tempString.Printf(_T("%f"),vol_standardeviation);
2720 interfMainPanel::getInstance()->setCellValueInfoPanel(maxZ+2, 5, tempString);
2722 //-----------------------------------------
2725 wxString tmpTitleString;
2727 for ( iTitleGroup=0 ; iTitleGroup<maxContourGroup ; iTitleGroup++ )
2729 tmpIntB =_numberOfVariablesStatistics*iTitleGroup;
2730 tmpTitleString.Printf(_T("%d-Size Data"),iTitleGroup);
2731 interfMainPanel::getInstance()->setColLableInfoPanel(tmpIntB + 0, tmpTitleString);
2733 interfMainPanel::getInstance()->setColLableInfoPanel(tmpIntB + 0, tmpTitleString );
2734 interfMainPanel::getInstance()->setColLableInfoPanel( tmpIntB + 1, _T("Size Range") );
2735 interfMainPanel::getInstance()->setColLableInfoPanel( tmpIntB + 2, _T("Min") );
2736 interfMainPanel::getInstance()->setColLableInfoPanel( tmpIntB + 3, _T("Max") );
2737 interfMainPanel::getInstance()->setColLableInfoPanel( tmpIntB + 4, _T("Average") );
2738 interfMainPanel::getInstance()->setColLableInfoPanel( tmpIntB + 5, _T("St.Dev.") );
2739 interfMainPanel::getInstance()->setColLableInfoPanel( tmpIntB + 6, _T(" ") );
2741 interfMainPanel::getInstance()->setStringInfoPanel( _T("") );
2745 void wxContourMainFrame::onSaveResults(std::string directory,std::string namefile, std::string filename,
2746 int typeContourGroup, int selection, int minZ, int maxZ, bool XYZValues, bool contourImage, bool statistics)
2750 SaveValuesXYZ( directory , namefile, typeContourGroup );
2755 vtkImageData * mask;
2756 vtkImageData * value;
2757 this->getMaskValue(&mask, &value, typeContourGroup,selection,minZ,maxZ);
2758 this->SaveImageResult( directory , namefile, mask, value);
2763 std::ostringstream name;
2764 name << filename << ".xls";
2767 FILE *pFile=fopen(name.str().c_str(),"w+");
2773 // int sizeZ = _theViewPanel->GetImageDataSizeZ();
2774 // int maxY=sizeZ+2;
2776 maxX= interfMainPanel::getInstance()->getNumberColsInformationPanel();//this->_grid->GetNumberCols();
2779 int iTitle,sizeTitle = (maxX / _numberOfVariablesStatistics);
2780 for ( iTitle=0; iTitle<sizeTitle ; iTitle++)
2782 // fprintf(pFile,"-- \t %d-Size \t SizeRange \t Min \t Max \t Ave \t StDv \t" , iTitle,tmpString.c_str() );
2783 fprintf(pFile,"slice\t %d-Size \t SizeRange \t Min \t Max \t Ave \t StDv \t" , iTitle );
2785 fprintf(pFile,"\n\n" );
2789 if (selection==0 ) // actual slice
2791 std::vector<int> tempVector;
2792 _instantPanel->getInstant( tempVector );
2793 int actualSlice = tempVector[1];
2799 for ( j=minZ; j<=maxZ ; j++)
2801 fprintf(pFile,"%d\t" , j );
2802 for (i=0 ; i<maxX ; i++){
2803 tmpString = interfMainPanel::getInstance()->getCellValue(j, i);//_grid->GetCellValue( j , i );
2804 fprintf(pFile,"%s\t" , (const char *)(tmpString.mb_str()) );
2806 fprintf(pFile,"\n" );
2810 // Total of stadistics.....
2813 fprintf(pFile,"\n Total:\t" );
2814 for (i=0 ; i<maxX ; i++){
2815 tmpString = interfMainPanel::getInstance()->getCellValue(maxZ+2, i);//_grid->GetCellValue( maxZ+2 , i );
2816 fprintf(pFile,"%s\t" , (const char *)(tmpString.mb_str()) );
2818 fprintf(pFile,"\n" );
2826 void wxContourMainFrame::SaveValuesXYZ(std::string directory,std::string namefile,int typeContourGroup)
2829 //EED01Juillet2009 GenerateContourExtractData();
2831 //int typeContourGroup = this->_radiolstboxContourGroup->GetSelection();
2832 _contourextractdata ->SetTypeOperation( typeContourGroup % 3 );
2834 std::vector<manualBaseModel*> lstManConMod;
2835 std::vector<manualBaseModel*> lstManConModTmp;
2836 std::vector<manualBaseModel*> lstManConModExp;
2837 std::vector<double> pLstValue;
2838 std::vector<double> pLstValuePosX;
2839 std::vector<double> pLstValuePosY;
2840 std::vector<double> pLstValuePosZ;
2842 std::vector<int> tempVector;
2843 _instantPanel->getInstant( tempVector );
2845 //EED01Juillet2009 vtkImageData *imagedata = _theViewPanel->getSceneManager()->GetImageData();
2846 int sizeZ = _theViewPanel->getSceneManager()->GetImageDataSizeZ();
2848 int ii,sizeLstContourThings;
2855 minZ = 0;// _mbarrange->GetStart();
2856 maxZ = sizeZ;//_mbarrange->GetEnd();
2857 totalZ = maxZ-minZ+1;
2859 //EED01Juillet2009 _contourextractdata->SetImage( imagedata);
2862 for ( z=0 ; z<sizeZ ; z++)
2865 porcent = 100.0* (z-minZ)/totalZ;
2867 tmpString.Printf(_T("Saving Values"));
2868 tmpString.Printf(_T(" %d %c %d/%d %d"), (int)porcent , 37 , z-minZ+1, (int)totalZ ,z);
2869 interfMainPanel::getInstance()->setStringInfoPanel(tmpString);
2870 //_staticTextInformation->SetLabel(tmpString);
2873 //Extraction data from contours of each slice
2874 _contourextractdata->SetZtoBeAnalys( z);
2877 Instant instant(&tempVector);
2878 std::vector<ContourThing**> lstContourThings = kernelManager->getOutlinesAtInstant(&instant);//this->_modelManager->getOutlinesAtInstant( &instant );
2879 sizeLstContourThings = lstContourThings.size();
2881 lstManConMod.clear();
2882 for (ii=0 ; ii<sizeLstContourThings ; ii++)
2884 ContourThing **contourthing = lstContourThings[ii];
2885 lstManConMod.push_back( (*contourthing)->getModel() );
2887 lstManConModExp = kernelManager->ExploseEachModel( lstManConMod );
2892 int iContourGroup,sizeContourGroup;
2893 if (typeContourGroup==3) // contour separete
2895 sizeContourGroup=lstManConModExp.size();
2896 } else { // contour AND OR XOR
2900 for( iContourGroup=0 ; iContourGroup<sizeContourGroup ; iContourGroup++ ){
2901 lstManConModTmp.clear();
2902 if (typeContourGroup==3) // contour separete
2904 lstManConModTmp.push_back( lstManConModExp[iContourGroup]);
2905 } else { // contour AND OR XOR
2906 lstManConModTmp = lstManConModExp;
2909 _contourextractdata->SetLstManualContourModel( lstManConModTmp );
2912 pLstValuePosX.clear();
2913 pLstValuePosY.clear();
2914 pLstValuePosZ.clear();
2916 _contourextractdata->GetValuesInsideCrown( &numberOfPixels,
2922 std::string temp = directory + "/" + namefile + "-slice";
2923 temp = temp + kernelManager->intToString(z) + "-cont" + kernelManager->intToString(iContourGroup);
2924 temp = temp + ".txt";
2926 // LG 14/01/09 : using crea
2927 wxString filename = crea::std2wx(temp);
2928 /*filename.Printf(_T("%s"),directory.c_str());
2929 filename.append(_T("\\"));
2930 filename.append(_T("%s"),namefile.c_str());
2931 filename.append(_T("-slice"));
2932 filename.append(_T("%d"),z);
2933 filename.append(_T("-cont"));
2934 filename.append(_T("%d"),iContourGroup);
2935 filename.append(_T(".txt"));*/
2936 // filename.Printf(temp.c_str());
2940 FILE *pFile=fopen((const char *)filename.mb_str(),"w+");
2941 fprintf(pFile,"value \t x \t y \t z\n" );
2942 int iLstValue,sizeLstValue=pLstValue.size();
2943 for (iLstValue=0 ; iLstValue<sizeLstValue ; iLstValue++ )
2945 fprintf(pFile,"%f\t %f\t %f\t %f\n", (float)pLstValue[iLstValue] , (float)pLstValuePosX[iLstValue], (float)pLstValuePosY[iLstValue], (float)z );
2948 } // for iContourGroup
2950 interfMainPanel::getInstance()->setStringInfoPanel(_T(""));
2951 //_staticTextInformation->SetLabel( _T("") );
2955 void wxContourMainFrame::getMaskValue(vtkImageData ** mask,vtkImageData ** value,int typeContourGroup, int selection, int minZ, int maxZ){
2957 //EED01Juillet2009 GenerateContourExtractData();
2959 //int typeContourGroup = this->_radiolstboxContourGroup->GetSelection();
2960 if (typeContourGroup==3)
2964 _contourextractdata ->SetTypeOperation( typeContourGroup % 3 );
2966 std::vector<manualBaseModel*> lstManConMod;
2967 std::vector<manualBaseModel*> lstManConModTmp;
2968 std::vector<manualBaseModel*> lstManConModExp;
2970 std::vector<int> tempVector;
2971 _instantPanel->getInstant( tempVector );
2973 vtkImageData *imagedata = _theViewPanel->getImageData();
2975 imagedata->GetExtent(ext);
2976 int sizeZimage = ext[5]-ext[4]+1;
2978 int ii,sizeLstContourThings;
2987 if (selection==0 ) // actual slice
2989 int actualSlice = tempVector[1];
2996 //EED01Juillet2009 _contourextractdata->SetImage( imagedata);
2998 // cleanning image before range
2999 for (z=0; z<minZ; z++){
3000 _contourextractdata->ResetImageResult(z);
3002 // cleanning image after range
3003 for (z=maxZ+1; z<sizeZimage; z++){
3004 _contourextractdata->ResetImageResult(z);
3009 for ( z=minZ ; z<=maxZ ; z++)
3012 porcent = 100.0* (z-minZ)/totalZ;
3013 tmpString.Printf(_T("Saving Values"));
3014 tmpString.Printf(_T("%d %c %d/%d %d"), (int)porcent , 37 , z-minZ+1, (int)totalZ ,z);
3015 interfMainPanel::getInstance()->setStringInfoPanel(tmpString);
3017 //Extraction data from contours of each slice
3018 _contourextractdata->SetZtoBeAnalys( z);
3021 Instant instant(&tempVector);
3022 std::vector<ContourThing**> lstContourThings = kernelManager->getOutlinesAtInstant( &instant );
3023 sizeLstContourThings = lstContourThings.size();
3025 lstManConMod.clear();
3026 for (ii=0 ; ii<sizeLstContourThings ; ii++)
3028 ContourThing **contourthing = lstContourThings[ii];
3029 lstManConMod.push_back( (*contourthing)->getModel() );
3031 lstManConModExp = kernelManager->ExploseEachModel( lstManConMod );
3034 int iContourGroup,sizeContourGroup;
3035 if (typeContourGroup==3) // contour separete
3037 sizeContourGroup=lstManConModExp.size();
3038 } else { // contour AND OR XOR
3042 for( iContourGroup=0 ; iContourGroup<sizeContourGroup ; iContourGroup++ ){
3043 lstManConModTmp.clear();
3044 if (typeContourGroup==3) // contour separete
3046 lstManConModTmp.push_back( lstManConModExp[iContourGroup]);
3047 } else { // contour AND OR XOR
3048 lstManConModTmp = lstManConModExp;
3051 _contourextractdata->SetLstManualContourModel( lstManConModTmp );
3052 _contourextractdata->CalculateImageResult(); // with actual Z
3054 } // for iContourGroup
3057 (*value) = _contourextractdata->GetVtkImageValueResult();
3058 (*mask) = _contourextractdata->GetVtkImageMaskResult();
3062 void wxContourMainFrame::SaveImageResult(std::string directory,std::string namefile, vtkImageData* mask,vtkImageData* value)
3066 kernelManager->GetSpacing(spc,0); // returns the spacing of the first image
3068 std::string temp = directory + "/" + namefile + "-image-Value.mhd";
3070 wxString filename = crea::std2wx(temp);
3074 vtkImageChangeInformation *valueChInfo = vtkImageChangeInformation::New();
3075 valueChInfo->SetInput(value);
3076 valueChInfo->SetSpacingScale(spc);
3077 vtkMetaImageWriter *writerValueImage = vtkMetaImageWriter::New( );
3078 writerValueImage->SetInput( valueChInfo->GetOutput() );
3079 writerValueImage->SetFileName( (const char *)filename.mb_str() );
3080 writerValueImage->SetFileDimensionality( 3 );
3081 writerValueImage->SetCompression(false);
3082 writerValueImage->Write( );
3085 temp = directory + "/" + namefile + "-image-Mask.mhd";
3087 // LG 14/01/09 : using crea
3088 filename = crea::std2wx(temp);
3089 // filename.Printf(_T(temp.c_str()));
3092 vtkImageChangeInformation *maskChInfo = vtkImageChangeInformation::New();
3093 maskChInfo->SetInput(mask);
3094 maskChInfo->SetSpacingScale(spc);
3095 vtkMetaImageWriter *writerMaskImage = vtkMetaImageWriter::New( );
3096 writerMaskImage->SetInput( maskChInfo->GetOutput() );
3097 writerMaskImage->SetFileName( (const char *)filename.mb_str() );
3098 writerMaskImage->SetFileDimensionality( 3 );
3099 writerMaskImage->SetCompression(false);
3100 writerMaskImage->Write( );
3102 interfMainPanel::getInstance()->setStringInfoPanel( _T("") );
3108 void wxContourMainFrame::onChangeInstantInstantPanel(std::string name,int value, int minshow, int maxshow){
3109 if( name.compare( _theViewPanel->getVerticalConceptName() ) == 0){
3110 _theViewPanel->setActualVertical( value);
3112 else if( name.compare( _theViewPanel->getHorizontalConceptName() ) == 0|| _instantPanel->getIfConceptCheckedAt( name, 0 ) ) {
3113 _theViewPanel->setHorizontalConcept( name, minshow, maxshow, minshow, maxshow, value);
3119 void wxContourMainFrame::onSnakePressed(){
3120 std::vector<double> vecX;
3121 std::vector<double> vecY;
3122 std::vector<double> vecZ;
3123 _theViewPanel->GetPointsOfActualContour( &vecX , &vecY , &vecZ );
3125 if (vecX.size()!=0){
3126 std::vector<int> tempVector;
3127 _instantPanel->getInstant( tempVector );
3128 int i,size=vecZ.size();
3129 int actualSlice = tempVector[1];
3130 for ( i=0 ; i<size ; i++ )
3132 vecZ[i] = actualSlice;
3135 wxDialog* dialog = new wxDialog(this, -1, wxString(_T("Snake")));
3136 wxPanel* panel = new wxPanel(dialog,-1);
3137 // wxStaticText* sttext = new wxStaticText(panel, -1, wxString(_T("Panel para snake")));
3138 new wxStaticText(panel, -1, wxString(_T("Panel para snake")));
3139 dialog->ShowModal();
3144 void wxContourMainFrame::saveFileWithContoursAutomatique(){
3145 std::string filename = kernelManager->getCurrentFileName();
3146 if(filename.compare("")!=0){
3147 saveFileWithContours(filename);
3152 void wxContourMainFrame::ShowToolsPanel(bool show){
3153 _pannew->Show(show);
3158 void wxContourMainFrame::SetContourGroup(int contourGroup)
3160 _contourGroup = contourGroup;
3164 wxPanel *wxContourMainFrame::getMaskImageViewPanel(wxWindow *parent)
3167 if (_viewMaskImagePanel==NULL)
3169 _contourextractdata = new ContourExtractData(true);
3170 _contourextractdata->SetImage( _theViewPanel->getImageData() );
3172 // _theViewPanel->getImageData()->GetScalarRange(range);
3173 //int min = (int)floor (range[0]);
3174 //int max = (int)ceil (range[1]);
3177 _viewMaskImagePanel = new ThresholdImageViewPanel( parent, -1, -1 , 0);
3178 _viewMaskImage = new ThresholdImageView();
3179 _viewMaskImage->SetImage(_contourextractdata->GetVtkImageMaskResult() );
3180 _viewMaskImage->SetminMaxValue( min, max);
3181 _viewMaskImage->SetBaseColor( 0,0,1 );
3182 _viewMaskImagePanel->SetThresholdImageView( _viewMaskImage );
3183 _viewMaskImage->SetwxVtkBaseView( _theViewPanel->getWxVtkBaseView() );
3185 return _viewMaskImagePanel;
3189 wxPanel *wxContourMainFrame::getColorLayerImageViewPanel(wxWindow *parent)
3191 if (_viewColorLayerImagePanel==NULL)
3194 _theViewPanel->getImageData()->GetScalarRange(range);
3195 int min = (int)floor (range[0]);
3196 int max = (int)ceil (range[1]);
3197 _viewColorLayerImagePanel = new ColorLayerImageViewPanel( parent, min, max , 1);
3198 _viewColorLayerImage = new ColorLayerImageView();
3199 // _viewColorLayerImage->SetImage( _theViewPanel->getImageData() );
3200 _viewColorLayerImage->SetImage( NULL );
3201 _viewColorLayerImagePanel->SetColorLayerImageView( _viewColorLayerImage );
3202 _viewColorLayerImage->SetwxVtkBaseView( _theViewPanel->getWxVtkBaseView() );
3204 return _viewColorLayerImagePanel;
3208 wxPanel *wxContourMainFrame::getThresholdImageViewPanel(wxWindow *parent)
3210 if (_viewThresholdImagePanel==NULL)
3213 _theViewPanel->getImageData()->GetScalarRange(range);
3214 int min = (int)floor (range[0]);
3215 int max = (int)ceil (range[1]);
3216 _viewThresholdImagePanel = new ThresholdImageViewPanel( parent, min, max , 1);
3217 _viewThresholdImage = new ThresholdImageView();
3218 _viewThresholdImage->SetImage( _theViewPanel->getImageData() );
3219 _viewThresholdImage->SetminMaxValue( min, max);
3220 _viewThresholdImage->SetBaseColor( 1,0,0 );
3221 _viewThresholdImagePanel->SetThresholdImageView( _viewThresholdImage );
3222 _viewThresholdImage->SetwxVtkBaseView( _theViewPanel->getWxVtkBaseView() );
3224 return _viewThresholdImagePanel;
3227 //CMRU 17-08-09-----------------------------------------------------------------------------------------------
3228 int wxContourMainFrame::getType ()
3231 std::vector<std::string> currentSelection = _theViewPanel->getSelectedObjects();
3233 if(!currentSelection.empty())
3235 std::string cloneName = currentSelection [0];
3236 manualBaseModel * manualModel = kernelManager->getOutlineByKeyName(cloneName);
3237 tipo = manualModel-> GetTypeModel();
3242 double wxContourMainFrame::getContourSizeInPixels()
3244 double contourSize = 0;
3246 std::vector<std::string> currentSelection = _theViewPanel->getSelectedObjects(); if(!currentSelection.empty())
3247 if(!currentSelection.empty())
3249 std::string cloneName = currentSelection [0];
3251 manualBaseModel * manualModel = kernelManager->getOutlineByKeyName(cloneName);//_modelManager->getOutlineByKeyName( cloneName )->getModel();
3252 contourSize = manualModel-> GetPathSize();
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)
3285 double sizeInPixel = manualModel ->GetPathSize();
3286 double onePixelRealSize = interfMainPanel::getInstance()->GetPixelValue();;
3287 double realContourSize = sizeInPixel*onePixelRealSize;
3288 manualModel ->SetRealSize(realContourSize);
3291 double wxContourMainFrame::onePixelSize( double value)
3293 return _onePixelSize = value;
3296 std::string wxContourMainFrame::GetFileLocation()
3298 return _fileLocation;
3301 void wxContourMainFrame::SetFileLocation(std::string newFileLocation)
3303 _fileLocation = newFileLocation;
3304 std::cout<<"GETFILELOCATION:"<<_fileLocation<<std::endl;
3306 //------------------------------------------------------------------------------------------------------------
3315 void wxContourMainFrame::FlipSelectedContours(int flipDirection)
3317 printf("EED wxContourMainFrame::FlipSelectedContours flipDirection=%d \n", flipDirection );
3319 (std::vector<std::string>)_theViewPanel->getSceneManager()->getSelectedObjects() ,
3325 void wxContourMainFrame::FlipActualSliceContours(int flipDirection)
3327 printf("EED wxContourMainFrame::FlipActualSliceContours flipDirection=%d \n", flipDirection );
3329 (std::vector<std::string>)_theViewPanel->getSceneManager()->GetlstContoursNameActualSlice() ,
3334 void wxContourMainFrame::FlipAllContours(int flipDirection)
3336 printf("EED wxContourMainFrame::FlipAllContours flipDirection=%d \n", flipDirection );
3338 kernelManager->GetLstNameThings() ,
3343 void wxContourMainFrame::FlipLstOfContours(std::vector<std::string> lstNameThings, int flipDirection)
3346 getImageData()->GetExtent(ext);
3347 int sizeX = ext[1]-ext[0];
3348 int sizeY = ext[3]-ext[2];
3351 int i,sizeLstNameThings;
3352 int ii,sizeLstPoints;
3354 sizeLstNameThings = lstNameThings.size();
3355 for (i=0 ; i<sizeLstNameThings ; i++)
3357 printf("EED wxContourMainFrame::FlipAllContours contour=%d \n", i );
3358 manualBaseModel * manualModel = kernelManager->getOutlineByKeyName(lstNameThings[i]);
3359 if (flipDirection==0)
3361 manualModel->Transform_Ax_Plus_B(-1,sizeX,1,0 );
3363 manualModel->Transform_Ax_Plus_B(1,0,-1,sizeY );
3365 }// for i list of Things
3367 //-- Static Contours
3369 lstNameThings = kernelManager->GetLstNameThingsStatic();
3370 sizeLstNameThings = lstNameThings.size();
3371 for (i=0 ; i<sizeLstNameThings ; i++)
3373 manualBaseModel * manualModel = kernelManager->getOutlineByKeyName(lstNameThings[i]);
3374 if (flipDirection==0)
3376 manualModel->Transform_Ax_Plus_B(-1,sizeX,1,0 );
3378 manualModel->Transform_Ax_Plus_B(1,0,-1,sizeY );
3380 }// for i list of static things
3383 void wxContourMainFrame::FlipContours(int typeContourFlip, int flipDirection)
3385 printf("EED wxContourMainFrame::FlipContours( %d , %d ) \n",typeContourFlip, flipDirection );
3389 if (typeContourFlip==0) //
3391 FlipSelectedContours(flipDirection);
3394 if (typeContourFlip==1) //
3396 FlipActualSliceContours(flipDirection);
3399 if (typeContourFlip==2) //
3401 FlipAllContours(flipDirection);