1 /*# ---------------------------------------------------------------------
3 # Copyright (c) CREATIS (Centre de Recherche en Acquisition et Traitement de l'Image
5 # Authors : Eduardo Davila, Frederic Cervenansky, Claire Mouton
6 # Previous Authors : Laurent Guigues, Jean-Pierre Roux
7 # CreaTools website : www.creatis.insa-lyon.fr/site/fr/creatools_accueil
9 # This software is governed by the CeCILL-B license under French law and
10 # abiding by the rules of distribution of free software. You can use,
11 # modify and/ or redistribute the software under the terms of the CeCILL-B
12 # license as circulated by CEA, CNRS and INRIA at the following URL
13 # http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
14 # or in the file LICENSE.txt.
16 # As a counterpart to the access to the source code and rights to copy,
17 # modify and redistribute granted by the license, users are provided only
18 # with a limited warranty and the software's author, the holder of the
19 # economic rights, and the successive licensors have only limited
22 # The fact that you are presently reading this means that you have had
23 # knowledge of the CeCILL-B license and that you accept its terms.
24 # ------------------------------------------------------------------------ */
26 //----------------------------------------------------------------------------------------------------------------
27 // Class definition include
28 //----------------------------------------------------------------------------------------------------------------
29 #include "wxContourMainFrame.h"
33 //----------------------------------------------------------------------------------------------------------------
35 //----------------------------------------------------------------------------------------------------------------
38 #include "NameWrapper.h"
39 #include "wx/artprov.h"
40 #include "ConceptDataWrap.h"
46 //----------------------------------------------------------------------------------------------------------------
47 // Class implementation
48 //----------------------------------------------------------------------------------------------------------------
49 /** @file wxContourMainFrame.cxx */
51 //------------------------------------------------------------------------------------------------------------
52 // Constructors & Destructors
53 //------------------------------------------------------------------------------------------------------------
55 wxContourMainFrame* wxContourMainFrame:: instance = NULL;
56 char wxContourMainFrame::COPY = 'C';
58 wxContourMainFrame :: wxContourMainFrame(wxWindow* parent, wxWindowID id,const wxString& title,const wxPoint& pos,const wxSize& size,long style)
59 //: wxPanel(parent, id, title, pos, size, style)
60 //: wxWindow(parent, id, pos, size, style)
61 : wxPanel(parent, id, pos, size, style)
63 m_mgr.SetManagedWindow(this);
65 _creatingContoursActive = false;
67 // _modelManager = NULL;
69 // _buttonsBar = NULL;
71 // _drawToolsPanel = NULL;
72 // _operationsToolsPanel = NULL;
73 //_autoFormsPanel = NULL;
74 // _standardToolsPanel = NULL;
75 // _editionToolsPanel = NULL;
76 // _listViewPanel = NULL;
77 // _sceneManager = NULL;
78 //_actualInstant = NULL;
79 _numberOfVariablesStatistics= 6+1;
81 _refLineControl = NULL;
84 // _actorPresent = false;
86 // set up default notebook style
87 // m_notebook_style =wxAUI_NB_TAB_SPLIT | wxAUI_NB_TAB_EXTERNAL_MOVE | wxNO_BORDER;
88 // m_notebook_theme = 0;
89 //wxContour_ActionCommandsID a;
91 _contourextractdata = NULL;
92 _viewMaskImage = NULL;
93 _viewMaskImagePanel = NULL;
94 _viewThresholdImage = NULL;
95 _viewThresholdImagePanel = NULL;
96 _viewColorLayerImagePanel = NULL;
99 wxContourMainFrame :: wxContourMainFrame(wxWindow* parent, wxWindowID id,const wxString& title,const wxPoint& pos,const wxSize& size,std::vector<vtkImageData*> images, long style,std::string datadir)
100 : wxPanel(parent, id, pos, size, style)
102 m_mgr.SetManagedWindow(this);
104 _creatingContoursActive = false;
105 _theViewPanel = NULL;
107 _instantPanel = NULL;
108 _refLineControl = NULL;
109 _refLineModel = NULL;
111 // _actorPresent = false;
112 _viewMaskImage = NULL;
113 _viewMaskImagePanel = NULL;
114 _viewThresholdImage = NULL;
115 _viewThresholdImagePanel = NULL;
116 _viewColorLayerImagePanel = NULL;
117 // set up default notebook style
118 m_notebook_style = wxAUI_NB_TAB_SPLIT | wxAUI_NB_TAB_EXTERNAL_MOVE | wxNO_BORDER;
119 m_notebook_theme = 0;
120 //wxContour_ActionCommandsID a;
121 _numberOfVariablesStatistics= 7;
125 _pannew = interfMainPanel::getInstance(this,datadir+"/data/Icons");//, eventHandler);
126 _performingOperation = new PerformingOperation();
127 if(images.size() > 0)
129 this->setVectImages(images);
131 _contourextractdata = NULL;
134 void wxContourMainFrame::setVectImages(std::vector<vtkImageData*> imgs)
137 #if defined(__GNUC__)
138 std::string str_home(getenv("HOME"));
139 #elif defined(_WIN32)
140 std::string str_home(getenv("USERPROFILE"));
142 std::string strCreaContourDataTmp = str_home + "/.creaContourDataTemp/";
143 std::vector<std::string> conceptNameVect;
144 std::vector<int> conceptSizeVect;
145 notebook = this->createNotebook();
146 kernelManager = new KernelManagerContour( imgs , _datadir+"/data/" , strCreaContourDataTmp );
147 _instantPanel = new wxInstantChooserPanel( notebook, "Instant Chooser", true, false, "c" );
148 _theViewPanel = new wxContourViewPanel( kernelManager->getSourceImage(), notebook );
149 //-------------------------------------------------------------
150 kernelManager->getConceptsInformation(conceptNameVect, conceptSizeVect);
151 _instantPanel->addConcepts(conceptNameVect, conceptSizeVect);
152 double val = _theViewPanel->getCurrentDeep();
153 _instantPanel->setConceptValue( "Axe Depth", (int)val );
154 //JCP _instantPanel->setConceptValue("time", num de imagenes);
155 ConceptDataWrap * data = _instantPanel->getConceptDataOf( "Axe Depth" );
156 //*******************changeInstant();
157 _theViewPanel->setVerticalConcept( "Axe Depth", data->getMinValue(), data->getMaxValue(), data->getMinShowedValue(), data->getMaxShowedValue(), data->getActualValue() );
158 this->configurePanels( );
162 wxContourMainFrame* wxContourMainFrame :: getInstance(wxWindow* parent, wxWindowID id,const wxString& title,const wxPoint& pos,const wxSize& size,std::vector<vtkImageData*> images, long style,std::string datadir )
164 if(instance == NULL){
165 instance = new wxContourMainFrame(parent, id, title, pos, size, images, style,datadir);
170 std::vector<vtkImageData*> wxContourMainFrame ::getVectImages()
172 return kernelManager->getVectImages();
175 wxContourMainFrame* wxContourMainFrame :: getInstance()
180 void wxContourMainFrame :: resetInstance()
185 wxContourMainFrame :: ~wxContourMainFrame()
187 delete _contourextractdata;
190 interfMainPanel::resetInstance();
191 delete kernelManager;
193 //_pannew->Destroy();
199 //El problema al cerrar la aplicacion puede estar asociado
200 //a que wxAUINotebook esta en la aplicacion
201 //principal (wxContourGUIExample)tambien
202 //EED???? delete _theViewPanel;
203 //EED???? delete _instantPanel;
204 //EED???? delete _buttonsBar;
205 //EED???? delete _actualInstant;
206 //EED???? delete _sceneManager;
210 //------------------------------------------------------------------------------------------------------------
211 // Creational and initialization methods using WxAui
212 //------------------------------------------------------------------------------------------------------------
214 wxAuiNotebook * wxContourMainFrame :: createNotebook()
216 wxSize client_size = GetClientSize();
217 wxAuiNotebook* noteBook = new wxAuiNotebook(this, -1, wxPoint(client_size.x, client_size.y), wxSize(430,200), m_notebook_style);
218 wxBitmap page_bmp = wxArtProvider::GetBitmap(wxART_NORMAL_FILE, wxART_OTHER, wxSize(16,16));
223 //------------------------------------------------------------------------------------------------------------
224 // Creational and initialization methods
225 //------------------------------------------------------------------------------------------------------------
226 bool wxContourMainFrame :: configurePanels( )
228 bool configured = _theViewPanel!=NULL;
230 configured &= _theViewPanel!=NULL;
231 if( _theViewPanel!=NULL )
233 notebook->AddPage( _theViewPanel, wxT(" View ") );
240 notebook->AddPage( _instantPanel, wxT("Instant Page") );
244 m_mgr.AddPane(notebook, wxAuiPaneInfo().Name(wxT("notebook_content")).CenterPane().PaneBorder(false));
247 SetMinSize(wxSize(300,300));
253 bool wxContourMainFrame::addNewPanel(wxPanel* panel)
255 bool configured = panel!=NULL;
256 configured &= panel!=NULL;
260 notebook->AddPage( panel, wxT(" Viewer "), true );
266 //------------------------------------------------------------------------------------------------------------
267 // Attributes getters and setters
268 //------------------------------------------------------------------------------------------------------------
272 void wxContourMainFrame :: setInstantChooserPanel( wxInstantChooserPanel * theInstantChooserPanel )
274 _instantPanel = theInstantChooserPanel;
277 // void wxContourMainFrame :: setButtonsBar( wxContour_ButtonsBar * theButtonsBar )
279 // _buttonsBar = theButtonsBar;
282 // void wxContourMainFrame :: setGrid( wxContour_Grid * theGridPanel )
284 // _gridPanel = theGridPanel;
287 // void wxContourMainFrame :: setDrawToolsPanel( wxContour_DrawToolsPanel * theDrawToolsPanel )
289 // _drawToolsPanel = theDrawToolsPanel;
292 // void wxContourMainFrame :: setOperationsToolsPanel( wxContour_OperationsToolsPanel * theOperationsToolsPanel )
294 // _operationsToolsPanel = theOperationsToolsPanel;
297 // void wxContourMainFrame :: setAutomaticFormsPanel( wxContour_AutomaticFormsToolsPanel * theAutoFormsPanel )
299 // _autoFormsPanel = theAutoFormsPanel;
302 // void wxContourMainFrame :: setStandardToolsPanel( wxContour_StandardToolsPanel * theStandardToolsPanel )
304 // _standardToolsPanel= theStandardToolsPanel;
307 // void wxContourMainFrame :: setEditionToolsPanel( wxContour_EdtionToolsPanel * theEditionToolsPanel )
309 // _editionToolsPanel = theEditionToolsPanel;
312 // void wxContourMainFrame :: setListViewPanel( wxContour_ListViewPanel * theListViewPanel )
314 // _listViewPanel = theListViewPanel;
319 void wxContourMainFrame::onCreateContourSpline( ){
321 //JCP 20-10-08 Undo redo implementation
323 //JCP 20-10-08 Undo redo implementation
327 void wxContourMainFrame::onCreateContourRectangle( ){
328 //JCP 20-10-08 Undo redo implementation
330 //JCP 20-10-08 Undo redo implementation
333 void wxContourMainFrame::onCreateContourCircle( ){
334 //JCP 20-10-08 Undo redo implementation
336 //JCP 20-10-08 Undo redo implementation
340 void wxContourMainFrame::onCreateContourLine( ){
341 //JCP 20-10-08 Undo redo implementation
343 //JCP 20-10-08 Undo redo implementation
347 // RaC 09-09 --------------------------------------
348 void wxContourMainFrame::onCreateContourPoints( ){
349 //JCP 20-10-08 Undo redo implementation
351 //JCP 20-10-08 Undo redo implementation
354 // RaC 09-09 --------------------------------------
356 // RaC 10-09 --------------------------------------
357 void wxContourMainFrame::onCreateContourPolygon( ){
358 //JCP 20-10-08 Undo redo implementation
360 //JCP 20-10-08 Undo redo implementation
363 // RaC 10-09 --------------------------------------
365 //------------------------------------------------------------------------------------------------------------
367 void wxContourMainFrame :: onCreateContourBullEye(wxPanel* panel )
369 //Creating the manualBaseModel and including in the model
370 manualBaseModel * manModelContour = factoryManualContourModel(panel );
372 std::vector<int> instantVector;
373 _instantPanel->getInstant( instantVector );
374 std::string theName = kernelManager->createOutline(manModelContour, instantVector);
376 /*std::vector<int> instantVector;
377 _instantPanel->getInstant( instantVector );
379 theName= _modelManager->createOutline( manModelContour, instantVector );*/
380 bool addedModel = theName.compare("") != 0;//??
384 double spc[3];//Si no hay imagen pero hay contornos que spacing se pone por default
385 _theViewPanel->getSpacing(spc);
386 //Adding the manualContourControler to interface objects structure
387 //Adding the manualViewContour to interface objects structure
388 //_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.
389 _theViewPanel->getSceneManager()->configureViewControlTo( theName, manModelContour,spc , 4) ;
392 void wxContourMainFrame :: createContour( int typeContour )
394 //Creating the manualContourModel and including in the model
395 manualBaseModel * manModelContour = kernelManager->factoryManualContourModel(typeContour);
397 std::vector<int> instantVector;
398 _instantPanel->getInstant( instantVector );
399 std::string theName = kernelManager->createOutline(manModelContour, instantVector);
401 /*std::vector<int> instantVector;
402 _instantPanel->getInstant( instantVector );
404 theName= _modelManager->createOutline( manModelContour, instantVector );*/
405 bool addedModel = theName.compare("") != 0;//??
408 double spc[3];//Si no hay imagen pero hay contornos que spacing se pone por default
409 _theViewPanel->getSpacing(spc);
410 //Adding the manualContourControler to interface objects structure
411 //Adding the manualViewContour to interface objects structure
412 //_sceneManager->setControlActiveStateOfALL( false );//This call is being done here because if the ROI is created underneath the previously created ROIS will still be active.
413 _theViewPanel->getSceneManager()->configureViewControlTo( theName, manModelContour,spc , typeContour) ;
417 manualBaseModel * wxContourMainFrame::factoryManualContourModel(wxPanel* panel){
419 manualContourModelBullEye *manModelContourBullEye = new manualContourModelBullEye();
420 manualBaseModel *manModelContour=NULL;
421 manModelContour = manModelContourBullEye;
423 int iCrown,sizeCrowns,iSector,sizeSectors;
424 double radioA,radioB,ang,angDelta ;
425 sizeCrowns = ((PanelBullEyeOptions*)panel)->GetNumberOfCrowns();
426 for ( iCrown=0 ; iCrown<sizeCrowns ; iCrown++ )
428 sizeSectors = ((PanelBullEyeOptions*)panel)->GetNumberOfSections(iCrown);
429 radioB = ((PanelBullEyeOptions*)panel)->GetRadioOfCrown(iCrown);
430 if (iCrown==sizeCrowns-1)
434 radioA = ((PanelBullEyeOptions*)panel)->GetRadioOfCrown(iCrown+1);
438 for ( iSector=0 ; iSector<sizeSectors ; iSector++ )
440 ang = ((PanelBullEyeOptions*)panel)->GetAngOfCrownSection(iCrown,iSector);
441 angDelta= ((PanelBullEyeOptions*)panel)->GetAngDeltaOfCrownSection(iCrown);
442 manModelContourBullEye->AddSector(radioA,radioB,ang,angDelta);
445 } // if _panelBullEyeOptions
447 return manModelContour;
449 void wxContourMainFrame :: saveState(){
451 std::string temp = kernelManager->saveState();
452 saveFileWithContours(temp);
455 void wxContourMainFrame::onDeleteContour(){
456 //JCP 20-10-08 Undo redo implementation
458 //JCP 20-10-08 Undo redo implementation
460 std::vector<std::string> lstKeyNameToBeErase;
461 lstKeyNameToBeErase = _theViewPanel->getSceneManager()->getSelectedObjects();
462 deleteContours( lstKeyNameToBeErase );
464 int i,size=_sceneManager->getSelectedObjects().size();
467 std::string keyName = _sceneManager->getSelectedObjects()[i];
468 int ispartofstaticlist = this->_modelManager->IsPartOfStaticList( keyName );
469 if ( ispartofstaticlist>=0 )
471 std::vector<int> tempVector;
472 _instantPanel->getInstant( tempVector );
473 Instant instant(&tempVector);
474 this->_modelManager->ChangeContourOfList(keyName, &instant);
478 std::vector<std::string> lstKeyName;
479 std::vector<std::string> lstKeyNameActualSlice;
480 std::vector<std::string> lstKeyNameToBeErase;
482 lstKeyNameToBeErase = _sceneManager->getSelectedObjects();
483 lstKeyNameActualSlice = _sceneManager->GetlstContoursNameActualSlice();
484 int k,kSize=lstKeyNameToBeErase.size();
485 int j,jSize=lstKeyNameActualSlice.size();
487 for (k=0;k<kSize; k++)
490 for (j=0;j<jSize; j++)
492 if (lstKeyNameToBeErase[k]==lstKeyNameActualSlice[j])
499 lstKeyName.push_back( lstKeyNameToBeErase[k] );
503 deleteContours( lstKeyName );
507 void wxContourMainFrame :: deleteContours( std::vector<std::string> keyNamesVector )
509 int i,size=keyNamesVector.size();
512 deleteContour( keyNamesVector[i] );
516 void wxContourMainFrame :: deleteContour( std::string theKeyName ){
518 manualContourModel * cModel;
519 manualViewBaseContour * cViewer;
520 manualContourBaseControler * cControler;
522 ContourWrap_ViewControl *conwrapviewControl = _theViewPanel->getSceneManager()->getContourWrap_ViewControlOf( theKeyName );
523 cControler = conwrapviewControl->getControler();*/
526 bool isedit = _theViewPanel->isEditableCControler(theKeyName);
527 bool ispartofstaticlst = kernelManager->IsPartOfStaticList(theKeyName);
529 if (isedit && ispartofstaticlst)
531 _theViewPanel->removeFromScene(theKeyName);
533 kernelManager->deleteCModel(theKeyName);
534 //_theViewPanel->getSceneManager()->removeFromScene( theKeyName );
535 //cViewer = conwrapviewControl->getViewer();
536 //_theViewPanel->getSceneManager()->removeWrap( theKeyName );
537 //cControler* conwrapviewControl->getControler();
540 // delete cControler;
545 void wxContourMainFrame::onDeleteContoursActSlice(){
546 //JCP 20-10-08 Undo redo implementation
548 //JCP 20-10-08 Undo redo implementation
549 deleteContours( (std::vector<std::string>)_theViewPanel->getSceneManager()->GetlstContoursNameActualSlice() );
551 void wxContourMainFrame::onDeleteAllContours(){
552 //JCP 20-10-08 Undo redo implementation
556 void wxContourMainFrame::deleteAllContours(){
557 //JCP 20-10-08 Undo redo implementation
560 std::vector<int> tempVector;
561 _instantPanel->getInstant( tempVector );
563 //JCP --08-09-2008 When using a diferent interface the _mbarrangeDeleteAll might not be initialize
564 // the values in GetStart and GetEnd will then not be initialize also.
565 // We use instead the values given when initializing the _deletepanel.
567 //int minZ = _mbarrangeDeleteAll->GetStart();
568 //int maxZ = _mbarrangeDeleteAll->GetEnd();
572 maxZ = _theViewPanel->getSceneManager()->GetImageDataSizeZ();
576 _theViewPanel->getSceneManager()->removeSceneContours( );
577 _theViewPanel->getSceneManager()->removeAllOutlines();
578 kernelManager->removeAllOutlines();
581 if ( (minZ==0) && (maxZ==_mbarrangeDeleteAll->GetMax() ))
583 _theViewPanel->getSceneManager()->removeSceneContours( );
584 _modelManager->removeAllOutlines();
585 _theViewPanel->getSceneManager()->removeAllOutlines();
588 for ( z=minZ ; z<=maxZ ; z++)
591 Instant instant(&tempVector);
592 std::vector<ContourThing**> lstContourThings = this->_modelManager->getOutlinesAtInstant( &instant );
594 sizeLstContourThings = lstContourThings.size();
595 for (ii=0 ; ii<sizeLstContourThings ; ii++)
597 ContourThing **contourthing = lstContourThings[ii];
598 deleteContour( (*contourthing)->getName() );
605 void wxContourMainFrame::setConceptValue( std::string name, int value ){
606 _instantPanel->setConceptValue(name, value);
610 ConceptDataWrap* wxContourMainFrame::getLastConceptData(){
611 return _instantPanel->getLastConceptData();
615 bool wxContourMainFrame::getIfConceptCheckedAt( std::string name, int pos ){
616 return _instantPanel->getIfConceptCheckedAt( name, pos );
621 void wxContourMainFrame::ShowResultImages(int typeContourGroup, int selection, int minZ, int maxZ)
624 vtkImageData * value;
625 this->getMaskValue(&mask, &value, typeContourGroup, selection, minZ, maxZ);
627 std::vector<int> nTypeView;
628 nTypeView.push_back(5);
629 nTypeView.push_back(1);
630 nTypeView.push_back(2);
631 nTypeView.push_back(0);
633 wxFrame *frame = new wxFrame(this, -1,_T("Result image extracted.."),wxDefaultPosition,wxSize(600,600), wxDEFAULT_FRAME_STYLE|wxSTAY_ON_TOP);
634 wxAuiManager *m_mgr_noteBookViewerResult = new wxAuiManager();
635 m_mgr_noteBookViewerResult->SetManagedWindow(frame);
637 wxAuiNotebook* noteBookViewerResult = new wxAuiNotebook(frame, -1, wxPoint(600, 600), wxSize(430,200), m_notebook_style);
638 m_mgr_noteBookViewerResult->AddPane(noteBookViewerResult, wxAuiPaneInfo().Name(wxT("notebook_content")).CenterPane().PaneBorder(false));
640 wxPanel *panelViewer1 = new wxMaracas_N_ViewersWidget(noteBookViewerResult, value,&nTypeView);
641 wxPanel *panelViewer2 = new wxMaracas_N_ViewersWidget(noteBookViewerResult, mask,&nTypeView);
644 noteBookViewerResult->AddPage( panelViewer1, wxT("Image result") );
645 noteBookViewerResult->AddPage( panelViewer2, wxT("Mask result") );
646 m_mgr_noteBookViewerResult->Update();
653 void wxContourMainFrame::changeInstant()
655 std::vector<int> instantVect;
656 _instantPanel->getInstant( instantVect );
657 int actualSlice = instantVect[1];
659 kernelManager->setInstant(instantVect);
661 // Refresh Mask image
662 if(_viewMaskImage!=NULL){
663 _viewMaskImage->SetZ(actualSlice);
664 if (_viewMaskImagePanel->IsVisible()==true)
666 vtkImageData *mask, *value;
667 getMaskValue(&mask,&value, _contourGroup , 0, -1, -1);
668 _viewMaskImage->onThreshold();
672 // Refresh Threshold image
673 if(_viewThresholdImage!=NULL){
674 _viewThresholdImage->SetZ(actualSlice);
675 if (_viewThresholdImagePanel->IsVisible()==true){
676 _viewThresholdImage->onThreshold();
681 updateInstantOutlines();
682 updateInstantImageData();
688 void wxContourMainFrame :: updateInstantOutlines()
690 _theViewPanel->removeSceneContours();
691 _theViewPanel->addNameWrapperToScene();
693 //for( int i=0; i<size; i++)
695 // _theViewPanel->getSceneManager()->addToScene(namesWrapping[i]->getKeyName(), true, true, true, false, false );
699 int wxContourMainFrame::getNamesWrappingSize(){
700 return kernelManager->getNamesWrappingSize();
702 std::string wxContourMainFrame::getNameWrapping(int i){
703 return kernelManager->getNameWrapping(i);
706 void wxContourMainFrame::updateInstantImageData()
708 std::vector<int> inst;
709 _instantPanel->getInstant(inst);
711 vtkImageData* img = kernelManager->getImageAtInstant(inst);
713 _theViewPanel->changeImage(img);
716 int z = _instantPanel->getConceptDataOf("Axe Depth")->getActualValue();
717 _theViewPanel->setImageSlice(z);
721 void wxContourMainFrame::updateInstantAxes()
726 void wxContourMainFrame::onChangeDeep(int val){
727 _instantPanel->setConceptValue( "Axe Depth", (int)val );
732 void wxContourMainFrame::onCopy(){
733 std::vector<std::string> currentSelection = _theViewPanel->getSelectedObjects();
735 std::vector<int> tempVector;
736 _instantPanel->getInstant( tempVector );
737 _performingOperation->reset();
738 _performingOperation->setStartCommand( COPY );
739 _performingOperation->setStartOperationInstantVector( tempVector );
740 _performingOperation->setKeyNamesOperationElems( currentSelection );
743 void wxContourMainFrame::onPaste(){
746 char theStartCommand = _performingOperation->getStartCommand();
747 if ( theStartCommand == COPY )
749 //JCP 20-10-08 Undo redo implementation
751 //JCP 20-10-08 Undo redo implementation
752 std::vector<int> tempVector;
753 _instantPanel->getInstant( tempVector );
754 _performingOperation->setEndOperationInstantVector ( tempVector );
755 std::vector<std::string> elems = _performingOperation->getKeyNamesOperationElems();
756 int i,size = elems.size();
757 for( i=0; i<size; i++ )
759 createCopyContourOf( elems[i], tempVector, i>0 );
763 void wxContourMainFrame::onUndo(){
764 std::string filename;
765 if(kernelManager->onUndoSaveFile(filename)){
766 saveFileWithContours(filename);
768 if(kernelManager->onUndo(filename)){
772 void wxContourMainFrame::onRedo(){
773 std::string filename;
774 if(kernelManager->onRedo(filename)){
779 void wxContourMainFrame :: createCopyContourOf ( std::string anExistingKName, std::vector<int> &instantNoTouchData, bool append )
781 std::string cloneName = kernelManager->createCopyContourOf( anExistingKName, instantNoTouchData );
782 manualBaseModel * manualModel = kernelManager->getOutlineByKeyName(cloneName);//_modelManager->getOutlineByKeyName( cloneName )->getModel();
783 _theViewPanel->getSceneManager()->createCopyContourOf( anExistingKName, cloneName, manualModel , append );
786 ///AD: 03-09 Copy the object and apply the given transformation
787 void wxContourMainFrame :: createMirrorContourOf ( std::string anExistingKName, std::vector<int> &instantNoTouchData, bool append )
789 std::string cloneName = kernelManager->createCopyContourOf( anExistingKName, instantNoTouchData );
790 manualBaseModel * manualModel = kernelManager->getOutlineByKeyName(cloneName);
792 manualPoint * refPoint1 = _refLineModel->GetManualPoint(0);
793 manualPoint * refPoint2 = _refLineModel->GetManualPoint(1);
795 double pnt1X = refPoint1->GetX();
796 double pnt1Y = refPoint1->GetY();
797 // double pnt1Z = refPoint1->GetZ();
798 double pnt2X = refPoint2->GetX();
799 double pnt2Y = refPoint2->GetY();
800 // double pnt2Z = refPoint2->GetZ();
802 double angle = (atan2(pnt2Y - pnt1Y, pnt2X - pnt1X) * 180 / 3.1415926535897932384626433832795)+90;
803 vtkTransform *t = vtkTransform::New();
807 t->Translate(-pnt1X, -pnt1Y, 0);
811 t->Translate(pnt1X, pnt1Y, 0);
814 int i,size=manualModel->GetSizeLstPoints();
817 manualPoint * mp = manualModel->GetManualPoint(i);
823 t->TransformPoint( vecIn, vecOut );
824 mp->SetPointX( vecOut[0] );
825 mp->SetPointY( vecOut[1] );
826 mp->SetPointZ( vecOut[2] );
829 _theViewPanel->getSceneManager()->createCopyContourOf( anExistingKName, cloneName, manualModel , append );
833 void wxContourMainFrame ::loadState(std::string filename){
836 onLoadContours(filename,false);
840 FILE *pFile=fopen(filename.c_str(),"r+");
842 fscanf(pFile,"%s",tmp); // --CreaContour--
844 fscanf(pFile,"%s",tmp); // Version
845 fscanf(pFile,"%s",tmp); // 1.0.3 || 1.0.2 || 1.0.1 || 1.0.0
849 loadContours(pFile, false);
850 loadContours(pFile, true);
859 void wxContourMainFrame::loadContours( FILE *pFile, bool staticContour )
863 if (staticContour==false)
865 fscanf(pFile,"%s",tmp); // ImageDimensions
866 fscanf(pFile,"%s",tmp); // X
867 fscanf(pFile,"%s",tmp); // Y
868 fscanf(pFile,"%s",tmp); // Z
870 fscanf(pFile,"%s",tmp); // ImageSpacing
871 fscanf(pFile,"%s",tmp); // X
872 fscanf(pFile,"%s",tmp); // Y
873 fscanf(pFile,"%s",tmp); // Z
876 fscanf(pFile,"%s",tmp); // NumberOfContours
877 fscanf(pFile,"%s",tmp); // ##
878 int numberOfContours = atoi(tmp);
880 std::vector<int> instantVector;
881 int typeContourModel;
882 manualBaseModel *manModelContour;
886 for (i=0;i<numberOfContours;i++)
888 instantVector.clear();
889 fscanf(pFile,"%s",tmp); // Instant
890 fscanf(pFile,"%s",tmp); // 1
891 instantVector.push_back( atoi(tmp) );
892 fscanf(pFile,"%s",tmp); // 2
893 instantVector.push_back( atoi(tmp) );
894 fscanf(pFile,"%s",tmp); // 3
895 instantVector.push_back( atoi(tmp) );
896 fscanf(pFile,"%s",tmp); // 4
897 instantVector.push_back( atoi(tmp) );
898 fscanf(pFile,"%s",tmp); // 5
899 instantVector.push_back( atoi(tmp) );
900 fscanf(pFile,"%s",tmp); // 6
901 instantVector.push_back( atoi(tmp) );
903 fscanf(pFile,"%s",tmp); // TypeContourModel
904 fscanf(pFile,"%s",tmp); // ##
905 typeContourModel = atoi(tmp);
907 manModelContour = kernelManager->factoryManualContourModel(typeContourModel);
908 manModelContour->Open(pFile);
910 fscanf(pFile,"%s",tmp); // TypeView
911 fscanf(pFile,"%s",tmp); // ##
912 typeView = atoi(tmp);
915 theName = kernelManager->createOutline( manModelContour, instantVector );
916 bool addedModel = theName.compare("") != 0;
919 double spc[3];//Si no hay imagen pero hay contornos que spacing se pone por default
920 _theViewPanel->getSpacing(spc);
921 //Adding the manualContourControler to interface objects structure
922 //Adding the manualViewContour to interface objects structure
923 //_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.
924 _theViewPanel->getSceneManager()->configureViewControlTo( theName, manModelContour,spc , typeView) ;
927 if (staticContour==true)
929 Instant instant(&instantVector);
930 kernelManager->changeContourOfManager( theName , &instant );
932 }// for numberOfContours
937 void wxContourMainFrame::onLoad()
939 std::string fileNameContourROI = GetFileLocation();
940 //CMRU 03-09-09-----------------------------------------------------------------------------------------------
941 if(GetFileLocation().empty())
943 //------------------------------------------------------------------------------------------------------------
944 //EED 2017-09-16 Migration wxWidgets 2.8 to 3.0
945 #if wxMAJOR_VERSION <= 2
946 wxFileDialog dialog(NULL, _T("Choose a file"), _T(""), _T(""), _T("*.roi"), wxOPEN );
948 wxFileDialog dialog(NULL, _T("Choose a file"), _T(""), _T(""), _T("*.roi"), wxFD_OPEN );
950 if (dialog.ShowModal() == wxID_OK)
952 fileNameContourROI = (const char *)(dialog.GetPath().mb_str());
956 onLoadContours(fileNameContourROI,true);
960 void wxContourMainFrame::SetZForAllContours(int pz)
962 printf("EED wxContourMainFrame::SetZForAllContours\n");
966 std::vector< std::string > lstNameThings;
967 int i,sizeLstNameThings;
968 int ii,sizeLstPoints;
970 lstNameThings = kernelManager->GetLstNameThings();
971 sizeLstNameThings = lstNameThings.size();
972 for (i=0 ; i<sizeLstNameThings ; i++)
974 printf("EED wxContourMainFrame::SetZForAllContours contour=%d \n", i );
975 manualBaseModel * manualModel = kernelManager->getOutlineByKeyName(lstNameThings[i]);
976 sizeLstPoints = manualModel->GetSizeLstPoints();
977 for (ii=0 ; ii<sizeLstPoints ; ii++)
979 manualModel->GetManualPoint(ii)->SetPointZ(-900);
980 }// for ii list of points
981 }// for i list of Things
985 lstNameThings = kernelManager->GetLstNameThingsStatic();
986 sizeLstNameThings = lstNameThings.size();
987 for (i=0 ; i<sizeLstNameThings ; i++)
989 manualBaseModel * manualModel = kernelManager->getOutlineByKeyName(lstNameThings[i]);
990 sizeLstPoints = manualModel->GetSizeLstPoints();
991 for (ii=0 ; ii<sizeLstPoints ; ii++)
993 manualModel->GetManualPoint(ii)->SetPointZ(-900);
994 }// for ii list of points
995 }// for i list of static things
998 void wxContourMainFrame::onLoadContours(std::string fileNameContourROI, bool interactiveInterface)
1002 FILE *pFile =fopen(fileNameContourROI.c_str(),"r+");
1003 //CMRU 03-09-09- ----------------------------------------------------------------------------------------------
1006 //------------------------------------------------------------------------------------------------------------
1007 fileNameContourROI.append("data");
1008 FILE *pFileData=fopen(fileNameContourROI.c_str(),"r+");
1009 if(pFileData != NULL)
1011 fscanf(pFileData,"%s",tmpD); // --CreaContour--
1012 fscanf(pFileData,"%s",tmpD); // Version
1013 fscanf(pFileData,"%s",tmpD); // 1.0.3 || 1.0.2 || 1.0.1 || 1.0.0
1015 fscanf(pFileData,"%s",tmpD); // onePixelSize
1016 fscanf(pFileData,"%s",tmpD); // #
1017 _onePixelSize = atof(tmpD);
1018 fscanf(pFileData,"%s",tmpD); // NumberOfContours
1019 fscanf(pFileData,"%s",tmpD); // #
1022 fscanf(pFile,"%s",tmp); // --CreaContour--
1024 fscanf(pFile,"%s",tmp); // Version
1025 fscanf(pFile,"%s",tmp); // 1.0.3 || 1.0.2 || 1.0.1 || 1.0.0
1026 std::string version(tmp);
1029 printf("EED wxContourMainFrame::onLoadContours version%s \n", version.c_str() );
1033 _tmpReadFileTypeOfTransformation=-1;
1034 if (version=="1.0.3")
1036 readDimSpc(pFile,interactiveInterface); // DimSpc interactive ON
1037 openContours(pFile,pFileData,false);
1038 openContours(pFile,pFileData,true); //Load StaticContours
1041 if (version=="1.0.2")
1044 readDimSpc(pFile,interactiveInterface); // DimSpc interactive ON
1045 openContours(pFile,pFileData,false);
1046 readDimSpc(pFile,false); // DimSpc interactive OFF
1047 openContours(pFile,pFileData,true); // Load StaticContours
1048 SetZForAllContours(-900);
1052 else if (version=="1.0.1")
1054 openContours(pFile,pFileData,false); //Skips ImageDimensions and ImageSpacing
1055 openContours(pFile,pFileData,true); //Load StaticContours, skips ImageDimensions and ImageSpacing
1059 else if (version=="1.0.0")
1061 openContours(pFile,pFileData,false); //Skips ImageDimensions and ImageSpacing
1066 if(pFileData != NULL)
1071 _theViewPanel->getSceneManager()->removeSceneContours();
1076 void wxContourMainFrame::onImport()
1078 std::string filename, filenamecontours;
1079 //EED 2017-09-16 Migration wxWidgets 2.8 to 3.0
1080 #if wxMAJOR_VERSION <= 2
1081 wxFileDialog dialog(NULL, _T("Choose a XML Osirix File"), _T(""), _T(""), _T("*.xml"), wxOPEN );
1083 wxFileDialog dialog(NULL, _T("Choose a XML Osirix File"), _T(""), _T(""), _T("*.xml"), wxFD_OPEN );
1085 if (dialog.ShowModal() == wxID_OK)
1087 filename = dialog.GetPath().mb_str();
1088 filenamecontours = kernelManager->parseOsirixFile(filename);
1090 if(filenamecontours.compare("") != 0){
1091 onLoadContours(filenamecontours,true);
1096 void wxContourMainFrame::onTest()
1098 std::string filename, filenamecontours;
1099 //EED 2017-09-16 Migration wxWidgets 2.8 to 3.0
1100 #if wxMAJOR_VERSION <= 2
1101 wxFileDialog dialog(NULL, _T("Choose a File"), _T(""), _T(""), _T("*.*"), wxOPEN );
1103 wxFileDialog dialog(NULL, _T("Choose a File"), _T(""), _T(""), _T("*.*"), wxFD_OPEN );
1106 if (dialog.ShowModal() == wxID_OK)
1108 filename = dialog.GetPath().mb_str();
1109 std::cout << "This is the filename: " << filename << std::endl;
1115 void wxContourMainFrame::onSave(){
1116 //CMRU 03-09-09-----------------------------------------------------------------------------------------------
1117 if(GetFileLocation().empty())
1119 //------------------------------------------------------------------------------------------------------------
1120 //EED 2017-09-16 Migration wxWidgets 2.8 to 3.0
1121 #if wxMAJOR_VERSION <= 2
1122 wxFileDialog dialog(NULL, _T("Choose a file"), _T(""), _T(""), _T("*.roi"), wxSAVE );
1124 wxFileDialog dialog(NULL, _T("Choose a file"), _T(""), _T(""), _T("*.roi"), wxFD_SAVE );
1126 if (dialog.ShowModal() == wxID_OK)
1128 std::string fileNameContourROI = (const char *)(dialog.GetPath().mb_str());
1129 kernelManager->setCurrentFileName(fileNameContourROI);
1130 saveFileWithContours( fileNameContourROI );
1133 //CMRU 03-09-09-----------------------------------------------------------------------------------------------
1136 std::cout<<"Nombre del archivo: "<<GetFileLocation()<<std::endl;
1137 std::string fileNameContourROI = GetFileLocation();
1138 std::cout<<"Nombre del archivo: "<<fileNameContourROI<<std::endl;
1139 kernelManager->setCurrentFileName(fileNameContourROI);
1140 saveFileWithContours( fileNameContourROI);
1142 //------------------------------------------------------------------------------------------------------------
1146 void wxContourMainFrame::saveFileWithContours( std::string filename )
1149 FILE *pFile=fopen(filename.c_str(),"w+");
1151 //CMRU 03-09-09-----------------------------------------------------------------------------------------------
1152 filename.append("data");
1153 std::cout<<"Nombre del archivo: "<<filename<<std::endl;
1154 FILE *pFileData=fopen(filename.c_str(),"w+");
1155 //------------------------------------------------------------------------------------------------------------
1157 std::vector< std::string > lstNameThings;
1158 int i,sizeLstNameThings;
1160 fprintf(pFile,"--CreaContour--\n");
1161 fprintf(pFile,"Version %s\n", "1.0.3" );
1163 //CMRU 03-09-09-----------------------------------------------------------------------------------------------
1164 fprintf(pFileData,"--CreaContour--\n");
1165 fprintf(pFileData,"Version %s\n", "1.0.3" );
1166 fprintf(pFileData,"OnePixelSize %f\n", _onePixelSize);
1168 //------------------------------------------------------------------------------------------------------------
1170 vtkImageData *image = _images[0];
1173 image->GetDimensions(dimRange);
1175 fprintf(pFile,"ImageDimensions %d %d %d\n", dimRange[0], dimRange[1], dimRange[2] );
1178 image->GetSpacing(spaRange);
1180 fprintf(pFile,"ImageSpacing %f %f %f\n", spaRange[0], spaRange[1], spaRange[2] );
1184 lstNameThings = kernelManager->GetLstNameThings();
1185 sizeLstNameThings = lstNameThings.size();
1186 fprintf(pFile,"NumberOfContours %d\n", sizeLstNameThings );
1188 //CMRU 03-09-09-----------------------------------------------------------------------------------------------
1189 fprintf(pFileData,"NumberOfContours %d\n", sizeLstNameThings );
1190 //------------------------------------------------------------------------------------------------------------
1199 for (i=0 ; i<sizeLstNameThings ; i++)
1201 //CMRU 03-09-09-----------------------------------------------------------------------------------------------
1202 manualBaseModel * manualModel = kernelManager->getOutlineByKeyName(lstNameThings[i]);
1205 // double sizeInPixel = manualModel ->GetPathSize( );
1206 double sizeInPixel = manualModel ->GetPathSize( spc );
1208 double realContourSize = sizeInPixel*_onePixelSize;
1209 manualModel ->SetRealSize(realContourSize);
1210 //------------------------------------------------------------------------------------------------------------
1212 //int size= kernelManager->GetLstNameThings().size();
1214 kernelManager->SaveThingName( pFile, pFileData, lstNameThings[i] );
1215 _theViewPanel->getSceneManager()->SaveThingName( pFile, lstNameThings[i] );
1218 //-- Static Contours
1220 // fprintf(pFile,"ImageDimensions %d %d %d\n", dimRange[0], dimRange[1], dimRange[2] );
1221 // fprintf(pFile,"ImageSpacing %f %f %f\n", spaRange[0], spaRange[1], spaRange[2] );
1223 lstNameThings = kernelManager->GetLstNameThingsStatic();
1224 sizeLstNameThings = lstNameThings.size();
1225 fprintf(pFile,"NumberOfContoursStatic %d\n", sizeLstNameThings );
1227 //CMRU 03-09-09-----------------------------------------------------------------------------------------------
1228 fprintf(pFileData,"NumberOfContoursStatic %d\n", sizeLstNameThings );
1229 //------------------------------------------------------------------------------------------------------------
1231 for (i=0 ; i<sizeLstNameThings ; i++)
1233 kernelManager->SaveThingName( pFile, pFileData, lstNameThings[i] );
1234 _theViewPanel->getSceneManager()->SaveThingName( pFile, lstNameThings[i] );
1242 void wxContourMainFrame::readDimSpc(FILE *pFile, bool interactiveOption)
1246 double imageSpac[3];
1247 vtkImageData *image = _images[0];
1248 image->GetDimensions(imageDim);
1249 image->GetSpacing(imageSpac);
1251 fscanf(pFile,"%s",tmp); // ImageDimensions
1252 fscanf(pFile,"%s",tmp); // X
1253 _tmpReadFileImageDim[0] = atoi(tmp);
1254 fscanf(pFile,"%s",tmp); // Y
1255 _tmpReadFileImageDim[1] = atoi(tmp);
1256 fscanf(pFile,"%s",tmp); // Z
1257 _tmpReadFileImageDim[2] = atoi(tmp);
1259 fscanf(pFile,"%s",tmp); // ImageSpacing
1260 fscanf(pFile,"%s",tmp); // X
1261 _tmpReadFileImageSpac[0] = atof(tmp);
1262 fscanf(pFile,"%s",tmp); // Y
1263 _tmpReadFileImageSpac[1] = atof(tmp);
1264 fscanf(pFile,"%s",tmp); // Z
1265 _tmpReadFileImageSpac[2] = atof(tmp);
1268 if (interactiveOption==true)
1270 //Compare Spacing and Dims in X and Y (Necessary in Z?) - Just for Version 2
1271 if (imageDim[0]!=_tmpReadFileImageDim[0] || imageDim[1]!=_tmpReadFileImageDim[1] || imageSpac[0]!=_tmpReadFileImageSpac[0] || imageSpac[1]!=_tmpReadFileImageSpac[1])
1273 wxDialog* dial = new wxDialog (this,-1,_T("Tools"),wxDefaultPosition, wxSize(460,360));
1274 wxSizer* buttonsSizer = dial->CreateSeparatedButtonSizer(wxOK|wxCANCEL);
1275 wxBoxSizer *dialSizer = new wxBoxSizer(wxVERTICAL);
1277 wxString lstOptOperation[2];
1278 lstOptOperation[0]=_T("By Dimension");
1279 lstOptOperation[1]=_T("By Spacing");
1280 wxRadioBox * radioOpts = new wxRadioBox(dial, -1, _T("Type of Transformation"), wxDefaultPosition, wxSize(270,45), 2 , lstOptOperation, 2, wxRA_SPECIFY_COLS);
1282 dialSizer->Add( new wxStaticText(dial,-1,_T("The image resolution is not compatible with the ")) , 0, wxGROW );
1283 dialSizer->Add( new wxStaticText(dial,-1,_T("selected Roi file. Do you want to tranform it?")) , 0, wxGROW );
1284 dialSizer->Add( new wxStaticText(dial,-1,_T(" ")) , 0, wxGROW );
1285 dialSizer->Add(radioOpts,0,wxGROW);
1286 dialSizer->Add( new wxStaticText(dial,-1,_T(" ")) , 0, wxGROW );
1287 dialSizer->Add(buttonsSizer,0,wxGROW);
1288 dial->SetSizer(dialSizer, true);
1292 int _tmpReadFileTypeOfTransformation = -1;
1293 //EED bool transform = false;
1295 if (dial->GetReturnCode() == wxID_OK)
1297 _tmpReadFileTypeOfTransformation = radioOpts->GetSelection();
1301 } // if interactiveOption
1308 void wxContourMainFrame::openContours( FILE *pFile, FILE *pFileData, bool staticContour )
1313 vtkImageData *image = _images[0];
1316 double imageSpac[3];
1317 image->GetDimensions(imageDim);
1318 image->GetSpacing(imageSpac);
1321 fscanf(pFile,"%s",tmp); // NumberOfContours
1322 fscanf(pFile,"%s",tmp); // ##
1323 int numberOfContours = atoi(tmp);
1325 std::vector<int> instantVector;
1326 int typeContourModel;
1327 manualBaseModel *manModelContour;
1331 if (compatible==true)
1334 for (i=0;i<numberOfContours;i++)
1336 instantVector.clear();
1337 fscanf(pFile,"%s",tmp); // Instant
1339 fscanf(pFile,"%s",tmp); // 1
1340 instantVector.push_back( atoi(tmp) );
1341 fscanf(pFile,"%s",tmp); // 2
1342 instantVector.push_back( atoi(tmp) );
1343 fscanf(pFile,"%s",tmp); // 3
1344 instantVector.push_back( atoi(tmp) );
1345 fscanf(pFile,"%s",tmp); // 4
1346 instantVector.push_back( atoi(tmp) );
1347 fscanf(pFile,"%s",tmp); // 5
1348 instantVector.push_back( atoi(tmp) );
1349 fscanf(pFile,"%s",tmp); // 6
1350 instantVector.push_back( atoi(tmp) );
1353 fscanf(pFile,"%s",tmp); // TypeContourModel
1354 fscanf(pFile,"%s",tmp); // ##
1355 typeContourModel = atoi(tmp);
1357 manModelContour = kernelManager->factoryManualContourModel(typeContourModel);
1358 manModelContour->Open(pFile);
1359 if(pFileData != NULL)
1361 manModelContour->OpenData(pFileData);
1364 fscanf(pFile,"%s",tmp); // TypeView
1365 fscanf(pFile,"%s",tmp); // ##
1366 typeView = atoi(tmp);
1368 std::string theName;
1369 theName = kernelManager->createOutline( manModelContour, instantVector );
1370 bool addedModel = theName.compare("") != 0;
1373 double spc[3];//Si no hay imagen pero hay contornos que spacing se pone por default
1374 _theViewPanel->getSpacing(spc);
1375 //Adding the manualContourControler to interface objects structure
1376 //Adding the manualViewContour to interface objects structure
1377 //_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.
1378 _theViewPanel->getSceneManager()->configureViewControlTo( theName, manModelContour,spc , typeView) ;
1381 if (staticContour) //StaticContours (will appear in all slices)
1383 Instant instant(&instantVector);
1384 kernelManager->changeContourOfManager( theName , &instant );
1387 }// for numberOfContours
1390 else if (compatible==false)
1395 for (i=0;i<numberOfContours;i++)
1397 instantVector.clear();
1398 fscanf(pFile,"%s",tmp); // Instant
1400 fscanf(pFile,"%s",tmp); // 1
1401 instantVector.push_back( atoi(tmp) );
1402 fscanf(pFile,"%s",tmp); // 2
1403 instantVector.push_back( atoi(tmp) );
1404 fscanf(pFile,"%s",tmp); // 3
1405 instantVector.push_back( atoi(tmp) );
1406 fscanf(pFile,"%s",tmp); // 4
1407 instantVector.push_back( atoi(tmp) );
1408 fscanf(pFile,"%s",tmp); // 5
1409 instantVector.push_back( atoi(tmp) );
1410 fscanf(pFile,"%s",tmp); // 6
1411 instantVector.push_back( atoi(tmp) );
1413 fscanf(pFile,"%s",tmp); // TypeContourModel
1414 fscanf(pFile,"%s",tmp); // ##
1415 typeContourModel = atoi(tmp);
1417 manModelContour = kernelManager->factoryManualContourModel(typeContourModel);
1418 manModelContour->Open(pFile);
1419 if(pFileData != NULL)
1421 manModelContour->OpenData(pFileData);
1424 if (_tmpReadFileTypeOfTransformation==-1){
1426 } else if (_tmpReadFileTypeOfTransformation==0){
1427 double transX, transY;
1428 transX = (double) imageDim[0]/_tmpReadFileImageDim[0];
1429 transY = (double) imageDim[1]/_tmpReadFileImageDim[1];
1430 manModelContour->Transform_Ax_Plus_B(transX,0,transY,0);
1431 } else if (_tmpReadFileTypeOfTransformation==1) {
1432 double transX, transY;
1433 transX = (double) _tmpReadFileImageSpac[0]/imageDim[0];
1434 transY = (double) _tmpReadFileImageSpac[1]/imageDim[1];
1435 manModelContour->Transform_Ax_Plus_B(transX,0,transY,0);
1438 fscanf(pFile,"%s",tmp); // TypeView
1439 fscanf(pFile,"%s",tmp); // ##
1440 typeView = atoi(tmp);
1442 std::string theName;
1443 theName = kernelManager->createOutline( manModelContour, instantVector );
1444 bool addedModel = theName.compare("") != 0;
1447 double spc[3];//Si no hay imagen pero hay contornos que spacing se pone por default
1448 _theViewPanel->getSpacing(spc);
1449 //Adding the manualContourControler to interface objects structure
1450 //Adding the manualViewContour to interface objects structure
1451 //_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.
1452 _theViewPanel->getSceneManager()->configureViewControlTo( theName, manModelContour,spc , typeView) ;
1455 if (staticContour) //StaticContours (will appear in all slices)
1457 Instant instant(&instantVector);
1458 kernelManager->changeContourOfManager( theName , &instant );
1460 }// for numberOfContours
1466 void wxContourMainFrame::RefreshInterface(){
1468 _theViewPanel->RefreshInterface();
1469 //wxVtk2DBaseView *wxvtk2dbaseview = (wxVtk2DBaseView*)this->_theViewPanel->getWxVtkBaseView();
1470 //wxvtk2dbaseview->Refresh();
1473 vtkImageData* wxContourMainFrame::getImageData(){
1474 return _theViewPanel->getImageData();
1477 void wxContourMainFrame::onSegmentationOneSliceITK(wxString distance, wxString sigma, wxString alfa, wxString beta, wxString propagation, wxString iterations, wxString inflation)
1479 //JCP 20-10-08 Undo redo implementation
1481 //JCP 20-10-08 Undo redo implementation
1484 int x = _theViewPanel->GetX();
1485 int y = _theViewPanel->GetY();
1486 int z = _theViewPanel->GetZ();
1487 SegmentationOneSliceITK( x,y,z,distance, sigma, alfa, beta, propagation, iterations, inflation);
1491 void wxContourMainFrame::SegmentationOneSliceITK(int x, int y, int z, wxString distanc, wxString sigm, wxString alf, wxString bet, wxString prop, wxString iter, wxString inflation)
1493 int typeofcontour = 1;
1495 vtkImageData *imagedata = getImageData();
1497 //Tipo de pixeles a utilizar internamente en ITK
1498 typedef float InternalPixelType;
1499 const unsigned int Dimension = 2;
1500 typedef itk::Image< InternalPixelType, Dimension > InternalImageType;
1502 //Tipo de pixeles de salida 1
1503 typedef unsigned char OutputPixelType;
1504 typedef itk::Image< OutputPixelType, Dimension > OutputImageType;
1506 //Tipo de pixeles de salida 2
1507 typedef unsigned short OutputPixelType2;
1508 typedef itk::Image< OutputPixelType2, Dimension > OutputImageType2;
1510 //DefiniciÛn del thresholder
1511 typedef itk::BinaryThresholdImageFilter<
1513 OutputImageType > ThresholdingFilterType;
1515 //DefiniciÛn del primer filtro de conversiÛn de pixeles
1516 typedef itk::CastImageFilter<
1517 OutputImageType, OutputImageType2 > CastFilterType;
1519 //DefiniciÛn del segundo tipo de conversiÛn de pixeles
1520 typedef itk::CastImageFilter<
1521 OutputImageType2, InternalImageType > CastFilterType2;
1523 //Tercer tipo de conversiÛn
1524 typedef itk::RescaleIntensityImageFilter<
1526 OutputImageType > CastFilterType3;
1528 //Cuarto tipo de conversiÛn
1529 typedef itk::RescaleIntensityImageFilter<
1531 OutputImageType > CastFilterType4;
1533 ThresholdingFilterType::Pointer thresholder = ThresholdingFilterType::New();
1535 thresholder->SetLowerThreshold( 0.0 );
1536 thresholder->SetUpperThreshold( 128 );
1538 thresholder->SetOutsideValue( 255 );
1539 thresholder->SetInsideValue( 0 );
1541 //DefinciÛn de conexiÛnes entre VTK e ITK y el writer
1542 typedef itk::VTKImageToImageFilter<OutputImageType2> ConnectorType;
1543 typedef itk::ImageToVTKImageFilter<OutputImageType> ConnectorType2;
1544 //EED10JUIN2011 typedef itk::ImageFileWriter< OutputImageType > WriterType;
1546 ConnectorType::Pointer connector= ConnectorType::New();
1547 ConnectorType2::Pointer connector2= ConnectorType2::New();
1550 CastFilterType::Pointer filter=CastFilterType::New();
1551 CastFilterType2::Pointer filter2=CastFilterType2::New();
1553 connector->SetInput( imagedata );
1554 filter2->SetInput(connector->GetOutput());
1556 typedef itk::CurvatureAnisotropicDiffusionImageFilter<
1558 InternalImageType > SmoothingFilterType;
1560 SmoothingFilterType::Pointer smoothing = SmoothingFilterType::New();
1562 typedef itk::GradientMagnitudeRecursiveGaussianImageFilter<
1564 InternalImageType > GradientFilterType;
1566 typedef itk::SigmoidImageFilter<
1568 InternalImageType > SigmoidFilterType;
1570 GradientFilterType::Pointer gradientMagnitude = GradientFilterType::New();
1572 SigmoidFilterType::Pointer sigmoid = SigmoidFilterType::New();
1574 sigmoid->SetOutputMinimum( 0.0 );
1575 sigmoid->SetOutputMaximum( 255.0 );
1578 typedef itk::FastMarchingImageFilter<
1580 InternalImageType > FastMarchingFilterType;
1583 FastMarchingFilterType::Pointer fastMarching = FastMarchingFilterType::New();
1585 printf("EED wxContourMainFrame::SegmentationOneSliceITK Skypping this code. Not compiling GeodesicActiveContourLevelSetImageFilter in fedora 17 with ITK 3.20.1 \n ");
1587 > - > - > - > - > - > - > - > - > - > - > - > - > - > - > - > - Not compiling GeodesicActiveContourLevelSetImageFilter in fedora 17 with ITK 3.20.1
1590 typedef itk::GeodesicActiveContourLevelSetImageFilter< InternalImageType,
1591 InternalImageType > GeodesicActiveContourFilterType;
1592 GeodesicActiveContourFilterType::Pointer geodesicActiveContour =
1593 GeodesicActiveContourFilterType::New();
1595 typedef itk::ZeroCrossingImageFilter<
1597 InternalImageType > ZeroCrossingFilterType;
1598 ZeroCrossingFilterType::Pointer zeroCrossing =
1599 ZeroCrossingFilterType::New();
1601 const double propagationScaling = atof( crea::wx2std(prop).c_str() );
1603 geodesicActiveContour->SetPropagationScaling( propagationScaling );
1604 geodesicActiveContour->SetCurvatureScaling( 1.0 );
1605 geodesicActiveContour->SetAdvectionScaling( 1.0 );
1607 geodesicActiveContour->SetMaximumRMSError( 0.02 );
1608 int it=atoi( crea::wx2std(iter).c_str() );
1609 geodesicActiveContour->SetNumberOfIterations( it );
1611 smoothing->SetInput( filter2->GetOutput() );
1612 gradientMagnitude->SetInput( smoothing->GetOutput() );
1613 sigmoid->SetInput( gradientMagnitude->GetOutput() );
1614 fastMarching->SetInput( sigmoid->GetOutput() );
1615 geodesicActiveContour->SetInput( fastMarching->GetOutput() );
1616 geodesicActiveContour->SetFeatureImage( sigmoid->GetOutput() );
1618 zeroCrossing->SetInput( geodesicActiveContour->GetOutput() );
1619 //thresholder->SetInput( zeroCrossing->GetOutput() );
1620 thresholder->SetInput( geodesicActiveContour->GetOutput() );
1621 connector2->SetInput( thresholder->GetOutput() );
1623 < - < - < - < - < - < - < - < - < - < - < - < - < - < - < - < - < - < - < - < -
1629 smoothing->SetTimeStep( 0.125 );
1630 smoothing->SetNumberOfIterations( 5 );
1631 smoothing->SetConductanceParameter( 9.0 );
1634 const double sigma = atof( crea::wx2std(sigm).c_str() );
1635 gradientMagnitude->SetSigma( sigma );
1637 const double alpha = atof( crea::wx2std(alf).c_str() );
1638 const double beta = atof( crea::wx2std(bet).c_str() );
1640 sigmoid->SetAlpha( alpha );
1641 sigmoid->SetBeta( beta );
1643 typedef FastMarchingFilterType::NodeContainer NodeContainer;
1644 typedef FastMarchingFilterType::NodeType NodeType;
1646 NodeContainer::Pointer seeds = NodeContainer::New();
1648 InternalImageType::IndexType seedPosition;
1649 seedPosition[0] = x;
1650 seedPosition[1] = y;
1652 const double initialDistance = atof( crea::wx2std(distanc).c_str() );
1656 const double seedValue = - initialDistance;
1658 node.SetValue( seedValue );
1659 node.SetIndex( seedPosition );
1661 seeds->Initialize();
1662 seeds->InsertElement( 0, node );
1664 fastMarching->SetTrialPoints( seeds );
1666 fastMarching->SetSpeedConstant( 1.0 );
1668 fastMarching->SetOutputSize(
1669 connector->GetOutput()->GetBufferedRegion().GetSize() );
1671 fastMarching->SetStoppingValue( 800 );
1675 connector2->Update();
1676 vtkImageData *idata = connector2->GetOutput();
1678 vtkMarchingContourFilter* cntVTK = vtkMarchingContourFilter::New( );
1680 cntVTK->SetNumberOfContours( 1 );
1681 cntVTK->SetValue( 0, 255 );
1682 //EED 2017-01-01 Migration VTK7
1683 #if VTK_MAJOR_VERSION <= 5
1684 cntVTK->SetInput( idata );
1686 cntVTK->UpdateInformation();
1688 cntVTK->SetInputData( idata );
1691 vtkCleanPolyData* cpd = vtkCleanPolyData::New( );
1693 //EED 2017-01-01 Migration VTK7
1694 #if VTK_MAJOR_VERSION <= 5
1695 cpd->SetInput( cntVTK->GetOutput( ) );
1697 cpd->UpdateInformation();
1699 cpd->SetInputData( cntVTK->GetOutput( ) );
1703 vtkPolyDataConnectivityFilter* conn = vtkPolyDataConnectivityFilter::New( );
1704 conn->SetExtractionModeToLargestRegion( );
1705 //EED 2017-01-01 Migration VTK7
1706 #if VTK_MAJOR_VERSION <= 5
1707 conn->SetInput( cpd->GetOutput( ) );
1709 conn->UpdateInformation();
1711 conn->SetInputData( cpd->GetOutput( ) );
1715 vtkStripper* vtkstripper = vtkStripper::New( );
1717 //EED 2017-01-01 Migration VTK7
1718 #if VTK_MAJOR_VERSION <= 5
1719 vtkstripper->SetInput( conn->GetOutput() );
1720 vtkstripper->Update();
1721 vtkstripper->UpdateInformation();
1723 vtkstripper->SetInputData( conn->GetOutput() );
1727 vtkPolyData* polyDataResult = cntVTK->GetOutput();
1728 //std::cout<<"Points "<<polyDataResult->GetNumberOfPoints()<<std::endl;
1730 //EED 2017-01-01 Migration VTK7
1731 #if VTK_MAJOR_VERSION <= 5
1732 polyDataResult->Update( );
1733 polyDataResult->UpdateInformation();
1741 myfile.open ("C:/Creatis/example.txt");
1743 polyDataResult->Print(myfile);
1744 myfile << "-------------------------------------\n";
1745 polyDataResult->GetLines()->Print(myfile);
1753 //--Calculating control points
1755 std::vector<double> vecX;
1756 std::vector<double> vecY;
1757 std::vector<double> vecXo;
1758 std::vector<double> vecYo;
1759 std::vector<double>::iterator vecXoi;
1760 std::vector<double>::iterator vecYoi;
1761 std::vector<double> vecZ;
1763 std::vector<double> vecCtrlPointX;
1764 std::vector<double> vecCtrlPointY;
1765 std::vector<double> vecCtrlPointZ;
1771 int ii,size=polyDataResult->GetNumberOfPoints();
1773 myfile.open ("C:/Creatis/example2.txt");
1775 size=polyDataResult->GetNumberOfPoints();
1776 for (ii=0;ii<size;ii++)
1783 p = polyDataResult->GetPoint(ii);
1786 /*if(fabs(yAct-y)>20)
1788 if((xAct-x)>1 || (xAct-x)<-1)
1790 vecX.push_back( p[0] );
1791 vecY.push_back( p[1] );
1792 myfile <<p[0]<<","<<p[1]<<"\n";
1793 std::cout<<" x Anterior "<<xAct<<" x actual "<<x<<std::endl;
1794 std::cout<<" y Anterior "<<yAct<<" y actual "<<y<<std::endl;
1795 std::cout<<" x "<<p[0]<<" y "<<p[1]<<std::endl;
1796 vecZ.push_back( 900 );
1802 vecXo.push_back(p[0]);
1803 vecYo.push_back(p[1]);
1807 else*/ if(fabs(xAct-x)>11)
1809 vecXo.push_back(p[0]);
1810 vecYo.push_back(p[1]);
1814 vecX.push_back( p[0] );
1815 myfile <<p[0]<<","<<p[1]<<"\n";
1816 //std::cout<<" x Anterior "<<xAct<<" x actual "<<x<<std::endl;
1817 //std::cout<<" y Anterior "<<yAct<<" y actual "<<y<<std::endl;
1818 //std::cout<<" x "<<p[0]<<" y "<<p[1]<<std::endl;
1819 vecY.push_back( p[1] );
1820 vecZ.push_back( 900 );
1828 while(!vecXo.empty())
1830 vecX.push_back(vecXo.back());
1831 //std::cout<<" x Siguiente "<<vecXo.back();
1833 vecZ.push_back( 900 );
1835 while(!vecYo.empty())
1837 vecY.push_back(vecYo.back());
1842 /*for(int l=0;l<vecX.size();l++)
1846 vecXo.push_back(p[0]);
1847 vecYo.push_back(p[1]);
1858 ExtractControlPoints2D *extractcontrolpoints2d = new ExtractControlPoints2D();
1860 extractcontrolpoints2d->SetContour( &vecX , &vecY , &vecZ );
1864 extractcontrolpoints2d->GetInitialControlPoints( &vecCtrlPointX , &vecCtrlPointY , &vecCtrlPointZ );
1866 else if (method==1){
1867 extractcontrolpoints2d->GetControlPoints( &vecCtrlPointX , &vecCtrlPointY , &vecCtrlPointZ );
1869 else if (method==2){
1870 extractcontrolpoints2d->SetSamplingControlPoints( 15 );
1871 extractcontrolpoints2d->GetSamplingControlPoints( &vecCtrlPointX , &vecCtrlPointY , &vecCtrlPointZ );
1873 //--Adding contour to the system
1875 std::vector<int> actualInstantVector;
1876 _instantPanel->getInstant( actualInstantVector );
1877 actualInstantVector[1]=z;
1879 int j,sizeCtrPt = vecCtrlPointX.size();
1881 manualBaseModel *manModelContour = kernelManager->factoryManualContourModel( typeofcontour );
1882 manModelContour->SetNumberOfPointsSpline( ((sizeCtrPt/100)+1)*100 );
1884 for (j=0 ; j<sizeCtrPt ; j++)
1886 manModelContour->AddPoint( vecCtrlPointX[j] , vecCtrlPointY[j] , vecCtrlPointZ[j] );
1888 std::string theName;
1889 //theName = _modelManager->createOutline( manModelContour, actualInstantVector );
1890 theName = kernelManager->createOutline( manModelContour, actualInstantVector );
1891 bool addedModel = theName.compare("") != 0;
1894 double spc[3];//Si no hay imagen pero hay contornos que spacing se pone por default
1895 _theViewPanel->getSpacing(spc);
1896 //Adding the manualContourControler to interface objects structure
1897 //Adding the manualViewContour to interface objects structure
1898 //_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.
1899 _theViewPanel->configureViewControlTo(theName, manModelContour, spc, typeofcontour);
1900 //_theViewPanel->getSceneManager()->configureViewControlTo( theName, manModelContour,spc, typeofcontour ) ;
1907 WriterType::Pointer writer = WriterType::New();
1908 CastFilterType3::Pointer caster = CastFilterType3::New();
1910 caster->SetInput( gradientMagnitude->GetOutput() );
1911 writer->SetInput( caster->GetOutput() );
1912 writer->SetFileName("Gradient Magnitude.png");
1913 caster->SetOutputMinimum( 0 );
1914 caster->SetOutputMaximum( 255 );
1917 CastFilterType3::Pointer caster2 = CastFilterType3::New();
1918 WriterType::Pointer writer2 = WriterType::New();
1920 caster2->SetInput( sigmoid->GetOutput() );
1921 writer2->SetInput( caster2->GetOutput() );
1922 writer2->SetFileName("Sigmoid.png");
1923 caster2->SetOutputMinimum( 0 );
1924 caster2->SetOutputMaximum( 255 );
1927 CastFilterType3::Pointer caster3 = CastFilterType3::New();
1928 WriterType::Pointer writer3 = WriterType::New();
1930 caster3->SetInput( fastMarching->GetOutput() );
1931 writer3->SetInput( caster3->GetOutput() );
1932 writer3->SetFileName("FastMarching.bmp");
1933 caster3->SetOutputMinimum( 0 );
1934 caster3->SetOutputMaximum( 255 );
1937 CastFilterType3::Pointer caster4 = CastFilterType3::New();
1938 WriterType::Pointer writer4 = WriterType::New();
1940 caster4->SetInput( geodesicActiveContour->GetOutput() );
1941 writer4->SetInput( caster4->GetOutput() );
1942 writer4->SetFileName("GeodesicActiveContour.png");
1943 caster4->SetOutputMinimum( 0 );
1944 caster4->SetOutputMaximum( 255 );
1947 CastFilterType3::Pointer caster5 = CastFilterType3::New();
1948 WriterType::Pointer writer5 = WriterType::New();
1950 caster5->SetInput( zeroCrossing->GetOutput() );
1951 writer5->SetInput( caster5->GetOutput() );
1952 writer5->SetFileName("ZeroCrossing.bmp");
1953 caster5->SetOutputMinimum( 0 );
1954 caster5->SetOutputMaximum( 255 );
1958 catch( itk::ExceptionObject & excep )
1960 std::cerr << "Exception caught !" << std::endl;
1961 std::cerr << excep << std::endl;
1965 void wxContourMainFrame::onSegmentationOneSlice(int isovalue,int sampling,int method){
1967 //JCP 20-10-08 Undo redo implementation
1969 //JCP 20-10-08 Undo redo implementation
1972 int x = _theViewPanel->GetX();
1973 int y = _theViewPanel->GetY();
1974 int z = _theViewPanel->GetZ();
1975 SegmentationOneSlice( x,y,z,isovalue, sampling, method );
1980 void wxContourMainFrame::SegmentationOneSlice( int x, int y, int z, int isovalue, int sampling, int method )
1982 int typeofcontour = 1;
1983 //--Extracting Contour
1984 //vtkImageData *imagedata = _theViewPanel->getSceneManager()->GetImageData();
1985 vtkImageData *imagedata = getImageData();
1986 // double *range = imagedata->GetScalarRange();
1989 vtkImageReslice *imageReslice = vtkImageReslice::New();
1992 // imagedata->GetSpacing(spc);
1997 //EED 2017-01-01 Migration VTK7
1998 #if VTK_MAJOR_VERSION <= 5
1999 imageReslice->SetInput( imagedata );
2001 imageReslice->SetInputData( imagedata );
2003 imageReslice->SetInformationInput(imagedata);
2004 imageReslice->SetResliceAxesDirectionCosines(1,0,0, 0,1,0 ,0,0,1);
2005 imageReslice->SetResliceAxesOrigin(0,0,z);
2006 imageReslice->SetOutputDimensionality(2);
2007 imageReslice->SetInterpolationModeToLinear();
2009 //EED 2017-01-01 Migration VTK7
2010 #if VTK_MAJOR_VERSION <= 5
2013 imageReslice->Update();
2016 imagedata = imageReslice->GetOutput();
2017 //EED 2017-01-01 Migration VTK7
2018 #if VTK_MAJOR_VERSION <= 5
2019 imagedata->Update();
2020 imagedata->UpdateInformation();
2025 vtkContourFilter* cntVTK = vtkContourFilter::New( );
2026 //EED 2017-01-01 Migration VTK7
2027 #if VTK_MAJOR_VERSION <= 5
2028 cntVTK->SetInput( imagedata );
2030 cntVTK->SetInputData( imagedata );
2033 cntVTK->SetNumberOfContours( 1 );
2034 //cntVTK->SetValue( 0, vmin );
2035 // cntVTK->SetValue( 0, (range[1]*thr/100) );
2036 cntVTK->SetValue( 1, isovalue );
2037 // cntVTK->SetValue( 1, vmax );
2039 cntVTK->UpdateInformation();
2041 vtkCleanPolyData* cpd = vtkCleanPolyData::New( );
2042 //EED 2017-01-01 Migration VTK7
2043 #if VTK_MAJOR_VERSION <= 5
2044 cpd->SetInput( cntVTK->GetOutput( ) );
2046 cpd->SetInputData( cntVTK->GetOutput( ) );
2048 cpd->ConvertLinesToPointsOff( );
2050 cpd->UpdateInformation();
2052 vtkPolyDataConnectivityFilter* conn = vtkPolyDataConnectivityFilter::New( );
2053 conn->SetExtractionModeToClosestPointRegion( );
2054 //conn->SetMaxRecursionDepth( 3000 );
2056 //EED 2017-01-01 Migration VTK7
2057 #if VTK_MAJOR_VERSION <= 5
2058 conn->SetInput( cpd->GetOutput( ) );
2060 conn->SetInputData( cpd->GetOutput( ) );
2063 conn->SetClosestPoint( x, y, 0 );
2065 conn->UpdateInformation();
2067 vtkCleanPolyData* cpd2 = vtkCleanPolyData::New( );
2068 //EED 2017-01-01 Migration VTK7
2069 #if VTK_MAJOR_VERSION <= 5
2070 cpd2->SetInput( conn->GetOutput( ) );
2072 cpd2->SetInputData( conn->GetOutput( ) );
2075 cpd2->UpdateInformation();
2077 vtkStripper* vtkstripper = vtkStripper::New( );
2078 //EED 2017-01-01 Migration VTK7
2079 #if VTK_MAJOR_VERSION <= 5
2080 vtkstripper->SetInput( cpd2->GetOutput() );
2082 vtkstripper->SetInputData( cpd2->GetOutput() );
2084 vtkstripper->Update();
2085 vtkstripper->UpdateInformation();
2088 vtkPolyData* polyDataResult = vtkstripper->GetOutput();
2090 //EED 2017-01-01 Migration VTK7
2091 #if VTK_MAJOR_VERSION <= 5
2092 polyDataResult->Update( );
2093 polyDataResult->UpdateInformation();
2100 myfile.open ("c:/temp/example.txt");
2102 polyDataResult->Print(myfile);
2103 myfile << "-------------------------------------\n";
2104 polyDataResult->GetLines()->Print(myfile);
2114 //--Calculating control points
2116 std::vector<double> vecX;
2117 std::vector<double> vecY;
2118 std::vector<double> vecZ;
2120 std::vector<double> vecCtrlPointX;
2121 std::vector<double> vecCtrlPointY;
2122 std::vector<double> vecCtrlPointZ;
2126 int ii,size=polyDataResult->GetNumberOfPoints();
2128 for (ii=1;ii<=size;ii++)
2130 id = polyDataResult->GetLines()->GetData()->GetValue(ii);
2131 p = polyDataResult->GetPoint(id);
2134 vecX.push_back( p[0] );
2135 vecY.push_back( p[1] );
2136 vecZ.push_back( 900 );
2137 // vecZ.push_back( p[2] );
2141 ExtractControlPoints2D *extractcontrolpoints2d = new ExtractControlPoints2D();
2142 extractcontrolpoints2d->SetContour( &vecX , &vecY , &vecZ );
2145 /*if (methodRadiobox->GetSelection()==0){
2146 extractcontrolpoints2d->GetInitialControlPoints( &vecCtrlPointX , &vecCtrlPointY , &vecCtrlPointZ );
2148 if (methodRadiobox->GetSelection()==1){
2149 extractcontrolpoints2d->GetControlPoints( &vecCtrlPointX , &vecCtrlPointY , &vecCtrlPointZ );
2151 if (methodRadiobox->GetSelection()==2){
2152 extractcontrolpoints2d->SetSamplingControlPoints( sampling );
2153 extractcontrolpoints2d->GetSamplingControlPoints( &vecCtrlPointX , &vecCtrlPointY , &vecCtrlPointZ );
2157 extractcontrolpoints2d->GetInitialControlPoints( &vecCtrlPointX , &vecCtrlPointY , &vecCtrlPointZ );
2159 else if (method==1){
2160 extractcontrolpoints2d->GetControlPoints( &vecCtrlPointX , &vecCtrlPointY , &vecCtrlPointZ );
2162 else if (method==2){
2163 extractcontrolpoints2d->SetSamplingControlPoints( sampling );
2164 extractcontrolpoints2d->GetSamplingControlPoints( &vecCtrlPointX , &vecCtrlPointY , &vecCtrlPointZ );
2167 //--Adding contour to the system
2169 std::vector<int> actualInstantVector;
2170 _instantPanel->getInstant( actualInstantVector );
2171 actualInstantVector[1]=z;
2173 int j,sizeCtrPt = vecCtrlPointX.size();
2174 manualBaseModel *manModelContour = kernelManager->factoryManualContourModel( typeofcontour );
2175 manModelContour->SetNumberOfPointsSpline( ((sizeCtrPt/100)+1)*100 );
2177 for (j=0 ; j<sizeCtrPt ; j++)
2179 manModelContour->AddPoint( vecCtrlPointX[j] , vecCtrlPointY[j] , vecCtrlPointZ[j] );
2181 std::string theName;
2182 //theName = _modelManager->createOutline( manModelContour, actualInstantVector );
2183 theName = kernelManager->createOutline( manModelContour, actualInstantVector );
2184 bool addedModel = theName.compare("") != 0;
2187 double spc[3];//Si no hay imagen pero hay contornos que spacing se pone por default
2188 _theViewPanel->getSpacing(spc);
2189 //Adding the manualContourControler to interface objects structure
2190 //Adding the manualViewContour to interface objects structure
2191 //_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.
2192 _theViewPanel->configureViewControlTo(theName, manModelContour, spc, typeofcontour);
2193 //_theViewPanel->getSceneManager()->configureViewControlTo( theName, manModelContour,spc, typeofcontour ) ;
2197 int wxContourMainFrame::GetImageDataSizeZ(){
2198 return _theViewPanel->GetImageDataSizeZ();
2201 void wxContourMainFrame::GetImageDataRange(double *range){
2202 _theViewPanel->GetImageDataRange(range);
2205 void wxContourMainFrame::onSegmentationAllSlice(int minZ,int maxZ,int isovalue,int sampling,int method){
2206 //JCP 20-10-08 Undo redo implementation
2208 //JCP 20-10-08 Undo redo implementation
2211 int x = _theViewPanel->GetX();
2212 int y = _theViewPanel->GetY();
2216 double totalZ = maxZ-minZ+1;
2217 for( z=minZ ; z<=maxZ ; z++ )
2219 porcent = 100.0* (z-minZ)/totalZ;
2220 tmpString.Printf(_T(" %d %c %d/%d %d"), (int)porcent , 37 , z-minZ+1, (int)totalZ,z );
2221 interfMainPanel::getInstance()->setLabelSegmentationPanelVTK(tmpString);
2222 //_staticTextSegmentation->SetLabel(tmpString);
2223 SegmentationOneSlice( x,y,z,isovalue, sampling,method );
2225 interfMainPanel::getInstance()->setLabelSegmentationPanelVTK(_T(" "));
2230 //Creates a reference line to be used as the axis of the mirroring
2231 void wxContourMainFrame::referenceLine()
2233 if (_refLineControl==NULL)
2238 vtkImageData *vtkimagedata = _theViewPanel->getImageData();
2239 vtkimagedata->GetSpacing(spc);
2241 wxVtkBaseView * viewer2D = _theViewPanel->getWxVtkBaseView();
2243 _refLineControl = new manualLineControler();
2244 _refLineModel = new manualContourModelLine();
2245 _refLineView = new manualViewLine();
2246 _refLineView->SetModel( _refLineModel );
2247 _refLineView->SetWxVtkBaseView( viewer2D );
2248 _refLineView->SetRange( 2 );
2249 _refLineView->SetZ( 1200 );
2251 _refLineView->SetSpacing(spc);
2253 _refLineView->SetColorNormalContour(0, 0, 1);
2254 _refLineView->SetColorEditContour(0, 0.5, 0.5);
2255 _refLineView->SetWidthLine(4);
2257 _refLineControl->SetModelView( _refLineModel , _refLineView );
2258 vtkInteractorStyleBaseView* style = (vtkInteractorStyleBaseView*)viewer2D->GetInteractorStyleBaseView();
2259 style->AddInteractorStyleMaracas( _refLineControl );
2260 _refLineModel->SetCloseContour(false);
2261 _refLineControl->CreateNewManualContour();
2263 //AD: Inicializar el mirroring con una linea ya pintada
2265 double z = _refLineControl->GetZ();
2268 image->GetDimensions(imageDim);
2269 double x = (double) imageDim[0]/2;
2270 double y1 = (double) (imageDim[1]/2)+15;
2271 double y2 = (double) (imageDim[1]/2)-15;
2273 _refLineControl->AddPoint(x,y1,z);
2274 _refLineControl->AddPoint(x,y2,z);
2275 _refLineControl->SetCompleteCreation(true);
2277 _refLineModel->AddPoint(x,y1,z);
2278 _refLineModel->AddPoint(x,y2,z);
2279 _refLineModel->UpdateSpline();
2281 _refLineView->UpdateViewPoint(0);
2282 _refLineView->UpdateViewPoint(1);
2285 _refLineControl->SetActive(true);
2286 _refLineView->RefreshContour();
2290 //Hides the referenceLine
2291 void wxContourMainFrame::refLineHide()
2293 if (_refLineControl!=NULL)
2295 if (_refLineControl->GetActive())
2297 _refLineView->RemoveCompleteContourActor();
2298 _refLineControl->SetEditable(false);
2299 _refLineControl->SetActive(false);
2306 //Shows the referenceLine
2307 void wxContourMainFrame::refLineShow()
2309 if (_refLineControl!=NULL)
2311 if (_refLineControl->GetActive()==false)
2313 wxVtkBaseView * viewer2D = _theViewPanel->getWxVtkBaseView();
2315 _refLineView->SetModel( _refLineModel );
2316 _refLineView->SetWxVtkBaseView( viewer2D );
2317 _refLineView->SetRange( 2 );
2318 _refLineView->SetZ( 1200 );
2320 _refLineControl->SetModelView( _refLineModel , _refLineView );
2321 vtkInteractorStyleBaseView* style = (vtkInteractorStyleBaseView*)viewer2D->GetInteractorStyleBaseView();
2322 style->AddInteractorStyleMaracas( _refLineControl );
2323 _refLineControl->CreateNewManualContour();
2324 _refLineControl->SetActive(true);
2325 _refLineView->RefreshContour();
2332 void wxContourMainFrame::refLineChangeWidth(int width)
2334 _refLineView->SetWidthLine(width);
2335 _refLineView->RefreshContour();
2341 void wxContourMainFrame::onMirror()
2344 std::vector<std::string> currentSelection = _theViewPanel->getSelectedObjects();
2345 std::vector<std::string> filterCurrentSelection;
2347 std::vector<int> tempVector;
2348 _instantPanel->getInstant( tempVector );
2349 _performingOperation->reset();
2350 _performingOperation->setStartCommand( COPY );
2351 _performingOperation->setStartOperationInstantVector( tempVector );
2352 _performingOperation->setKeyNamesOperationElems( currentSelection );
2354 char theStartCommand = _performingOperation->getStartCommand();
2355 if ( theStartCommand == COPY )
2357 //JCP 20-10-08 Undo redo implementation
2359 //JCP 20-10-08 Undo redo implementation
2360 std::vector<int> tempVector;
2361 _instantPanel->getInstant( tempVector );
2362 _performingOperation->setEndOperationInstantVector ( tempVector );
2363 std::vector<std::string> elems = _performingOperation->getKeyNamesOperationElems();
2364 int i,size = elems.size();
2365 for( i=0; i<size; i++ )
2367 createMirrorContourOf( elems[i], tempVector, i>0 );
2371 //deleteContour( _refName );
2376 void wxContourMainFrame::showAxis(bool show)
2378 _theViewPanel->SetVisibleAxis(show);
2379 _theViewPanel->Refresh();
2383 void wxContourMainFrame::onRigidPressed(){
2384 std::vector<std::string> currentSelection = _theViewPanel->getSelectedObjects();
2385 int elementsSelected = currentSelection.size();
2387 if ( elementsSelected >= 1 ){
2388 //JCP 20-10-08 Undo redo implementation
2390 //JCP 20-10-08 Undo redo implementation
2392 std::vector<int> tempVector;
2393 _instantPanel->getInstant( tempVector );
2394 Instant instant(&tempVector);
2396 int i , size=currentSelection.size();
2397 for ( i=0 ; i<size ; i++ )
2399 kernelManager->changeContourOfManager(currentSelection[i], &instant);
2404 void wxContourMainFrame::onWidthOfContour(double width){
2406 _theViewPanel->removeSceneContours();
2407 _theViewPanel->SetWidthContour(width);
2409 //_theViewPanel->getSceneManager()->SetWidthContour( width );
2414 int wxContourMainFrame::getColorWindow()
2418 vtkImageData * img = getImageData();
2419 img->GetScalarRange(range);
2421 std::cout<<"Val 1: "<<range[0]<<" Val 2: "<<range[1]<<std::endl;
2423 return (int)range[1];
2425 return _theViewPanel->getColorWindow();
2428 int wxContourMainFrame::getWindowLevel()
2432 vtkImageData * img = getImageData();
2433 img->GetScalarRange(range);
2435 std::cout<<"Val 1: "<<range[0]<<" Val 2: "<<range[1]<<std::endl;
2437 return (int)range[1];
2439 return _theViewPanel->getWindowLevel();
2442 void wxContourMainFrame::onBrigthnessColorWindowLevel(int colorwindow,int windowlevel){
2443 _theViewPanel->onBrigthnessColorWindowLevel(colorwindow, windowlevel);
2448 void wxContourMainFrame::onInterpolation(bool interpolate){
2449 _theViewPanel->onInterpolation(interpolate);
2453 void wxContourMainFrame::onChangeInstant(std::string name,int actual){
2454 _instantPanel->setConceptValue( name, actual );
2458 void wxContourMainFrame::resetAppend(){
2459 kernelManager->resetAppend();
2464 void wxContourMainFrame::onSpreadAdd(){
2465 std::vector<double> vecX;
2466 std::vector<double> vecY;
2467 std::vector<double> vecZ;
2468 _theViewPanel->GetPointsOfActualContour(&vecX , &vecY , &vecZ );
2469 std::vector<int> tempVector;
2470 _instantPanel->getInstant( tempVector );
2471 std::string val = kernelManager->onSpreadAdd(&vecX , &vecY , &vecZ, tempVector);
2472 interfMainPanel::getInstance()->appendStringSpread(val);
2476 void wxContourMainFrame::onSpreadAddAll(){
2478 std::vector<int> tempVector;
2479 _instantPanel->getInstant( tempVector );
2482 maxZ = interfMainPanel::getInstance()->GetImageDataSizeZ();
2484 int sizeLstContourThings;
2485 for ( z=minZ ; z<=maxZ ; z++ )
2488 Instant instant(&tempVector);
2489 std::vector<ContourThing**> lstContourThings = kernelManager->getOutlinesAtInstant( &instant );
2490 sizeLstContourThings = lstContourThings.size();
2491 if (sizeLstContourThings>=1)
2493 std::vector<double> vecX;
2494 std::vector<double> vecY;
2495 std::vector<double> vecZ;
2496 ContourThing **contourthing = lstContourThings[0];
2497 manualBaseModel *cModel = (*contourthing)->getModel();
2498 int i,size = cModel->GetNumberOfPointsSpline();
2500 for (i=0; i<size; i++)
2502 cModel->GetSpline_i_Point(i, &x, &y, &z);
2507 std::string val = kernelManager->onSpreadAdd(&vecX , &vecY , &vecZ, tempVector);
2508 interfMainPanel::getInstance()->appendStringSpread(val);
2509 }// if sizeLstContourThings
2514 void wxContourMainFrame::onSpreadGo(int type){
2515 //JCP 20-10-08 Undo redo implementation
2517 //JCP 20-10-08 Undo redo implementation
2519 std::vector<double> vecCtrlPointX;
2520 std::vector<double> vecCtrlPointY;
2521 std::vector<double> vecCtrlPointZ;
2525 std::vector<int> tempVector;
2526 _instantPanel->getInstant( tempVector );
2529 kernelManager->getMaxMinZ(&minZ,&maxZ);
2530 //JSTG_16-07-08_----------------------------------------------------------------
2531 //_contourPropagation->setInterpolationNumber(maxZ-minZ+1);
2532 kernelManager->CalculeSplinePropagation();
2534 double totalZ = maxZ-minZ+1;
2537 //--------------------------------------------------------------------
2538 for ( z=(int)minZ ; z<=(int)maxZ ; z++ )
2540 porcent = 100.0* (z-minZ)/totalZ;
2541 int numero = (int)(z-minZ+1)/(int)totalZ;
2542 std::string stringtemp = " "+kernelManager->intToString(porcent)+"% "+kernelManager->intToString(numero)+" "+kernelManager->intToString(z);
2544 interfMainPanel::getInstance()->setStringSpread(stringtemp);
2546 int typeofcontour = 1;
2547 std::string theName;
2548 manualBaseModel* manModelContour = kernelManager->GetPoints(z, type, &vecCtrlPointX,&vecCtrlPointY,&vecCtrlPointZ, theName,typeofcontour, tempVector);
2550 if( manModelContour!=NULL ){
2551 double spc[3];//Si no hay imagen pero hay contornos que spacing se pone por default
2552 this->_theViewPanel->getSpacing(spc);
2553 //Adding the manualContourControler to interface objects structure
2554 //Adding the manualViewContour to interface objects structure
2555 //_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.
2556 _theViewPanel->configureViewControlTo( theName, manModelContour,spc,typeofcontour ) ;
2561 int numero = (int)(z-minZ+1)/(int)totalZ;
2562 std::string stringtemp = " "+kernelManager->intToString(porcent)+"% "+kernelManager->intToString(numero)+" "+kernelManager->intToString(z);
2564 interfMainPanel::getInstance()->setStringSpread(stringtemp);
2566 //RefreshInterface();
2569 void wxContourMainFrame::getInstantVector(std::vector<int>& tempVector){
2573 std::vector<std::string> wxContourMainFrame::getOutlinesName(int slide){
2574 std::vector<int> tempVector;
2575 _instantPanel->getInstant(tempVector);
2576 //Asignation of slide number should be different ex by name
2577 tempVector[1]=slide;
2578 return kernelManager->getOutlinesNameAtInstant(tempVector);
2582 void wxContourMainFrame::SetScalarRange(int grayRangeMin, int grayRangeMax)
2584 _contourextractdata->SetScalarRange(grayRangeMin,grayRangeMax);
2588 void wxContourMainFrame::onInformationContourLabels(int typeContourGroup,int selection,int minimumZ,int maximumZ,int grayRangeMin, int grayRangeMax)
2591 wxString tempString;
2592 int maxContourGroup = 0;
2594 _contourextractdata ->SetTypeOperation( typeContourGroup % 3 );
2596 std::vector<manualBaseModel*> lstManConMod;
2597 std::vector<manualBaseModel*> lstManConModTmp;
2598 std::vector<manualBaseModel*> lstManConModExp;
2599 std::vector<double> pLstValue;
2600 std::vector<double> pLstValuePosX;
2601 std::vector<double> pLstValuePosY;
2602 std::vector<double> pLstValuePosZ;
2605 int resultGrayRangeCount;
2608 double resultAverage;
2609 double resultStandardeviation;
2611 std::vector<int> tempVector;
2612 _instantPanel->getInstant( tempVector );
2615 int ii,sizeLstContourThings;
2624 if (selection==0 ) // actual slice
2626 int actualSlice = tempVector[1];
2629 } else { // slice range
2635 totalZ = maxZ-minZ+1;
2637 _contourextractdata->InitVolumeStatistics();
2640 for ( z=minZ ; z<=maxZ ; z++ )
2643 porcent = 100.0* (z-minZ)/totalZ;
2644 tmpString.Printf(_T(" %d %c %d/%d %d"), (int)porcent , 37 , z-minZ+1, (int)totalZ ,z);
2646 interfMainPanel::getInstance()->setStringInfoPanel(tmpString);
2647 //_staticTextInformation->SetLabel(tmpString);
2649 //Extraction data from contours of each slice
2650 _contourextractdata->SetZtoBeAnalys(z);
2653 Instant instant(&tempVector);
2654 std::vector<ContourThing**> lstContourThings = kernelManager->getOutlinesAtInstant( &instant );
2655 sizeLstContourThings = lstContourThings.size();
2657 lstManConMod.clear();
2658 for (ii=0 ; ii<sizeLstContourThings ; ii++)
2660 ContourThing **contourthing = lstContourThings[ii];
2661 lstManConMod.push_back( (*contourthing)->getModel() );
2664 lstManConModExp = kernelManager->ExploseEachModel( lstManConMod );
2666 tempString.Printf(_T("%d - %d"),z, sizeLstContourThings);
2667 interfMainPanel::getInstance()->setRowLabelInfoPanel(z, tempString);
2668 //_grid->SetRowLabelValue(z, tempString );
2670 int iContourGroup,sizeContourGroup;
2671 if (typeContourGroup==3) // contour separete
2673 sizeContourGroup=lstManConModExp.size();
2674 if ( maxContourGroup<sizeContourGroup )
2676 maxContourGroup=sizeContourGroup;
2678 } else { // contour AND OR XOR
2685 for( iContourGroup=0 ; iContourGroup<sizeContourGroup ; iContourGroup++ ){
2686 lstManConModTmp.clear();
2690 if (typeContourGroup==3) // contour separete
2692 lstManConModTmp.push_back( lstManConModExp[iContourGroup]);
2693 } else { // contour AND OR XOR
2694 lstManConModTmp = lstManConModExp;
2697 _contourextractdata->SetLstManualContourModel( lstManConModTmp );
2698 _contourextractdata->SetScalarRange(grayRangeMin,grayRangeMax);
2701 pLstValuePosX.clear();
2702 pLstValuePosY.clear();
2703 pLstValuePosZ.clear();
2707 _contourextractdata->GetValuesInsideCrown( &numberOfPixels,
2713 resultSize=numberOfPixels;
2714 // Statistics of each slice.
2715 _contourextractdata->Statistics( &pLstValue,
2718 &resultGrayRangeCount,
2723 &resultStandardeviation);
2725 if (interfMainPanel::getInstance()->getNumberColsInformationPanel()<_numberOfVariablesStatistics*(iContourGroup+1) )
2727 interfMainPanel::getInstance()->appendColsInformationPanel(_numberOfVariablesStatistics);
2730 tmpIntA=_numberOfVariablesStatistics*iContourGroup ;
2732 tempString.Printf(_T("%d"),numberOfPixels);
2734 interfMainPanel::getInstance()->setCellValueInfoPanel(z, tmpIntA, tempString);
2736 tempString.Printf(_T("%d"),resultGrayRangeCount);
2737 interfMainPanel::getInstance()->setCellValueInfoPanel(z, tmpIntA+1, tempString);
2739 tempString.Printf(_T("%f"),resultMin);
2740 interfMainPanel::getInstance()->setCellValueInfoPanel(z, tmpIntA+2, tempString);
2742 tempString.Printf(_T("%f"),resultMax);
2743 interfMainPanel::getInstance()->setCellValueInfoPanel(z, tmpIntA+3, tempString);
2745 tempString.Printf(_T("%f"),resultAverage);
2746 interfMainPanel::getInstance()->setCellValueInfoPanel(z, tmpIntA+4, tempString);
2748 tempString.Printf(_T("%f"),resultStandardeviation);
2749 interfMainPanel::getInstance()->setCellValueInfoPanel(z, tmpIntA+5, tempString);
2752 } // for iContourGroup
2755 // Print Volume Statistics
2758 int vol_rCountRange;
2760 double vol_minValue;
2761 double vol_maxValue;
2763 double vol_standardeviation;
2765 if (selection!=0 ) // actual slice
2768 _contourextractdata->GetVolumeStatistics(&vol_rCountRange, &vol_rsize,
2769 &vol_minValue, &vol_maxValue,
2770 &vol_average, &vol_standardeviation);
2772 interfMainPanel::getInstance()->setRowLabelInfoPanel(maxZ+2, _T("Total:"));
2774 tempString.Printf(_T("%d"),vol_rsize);
2775 interfMainPanel::getInstance()->setCellValueInfoPanel(maxZ+2, 0, tempString);
2777 tempString.Printf(_T("%d"),vol_rCountRange);
2778 interfMainPanel::getInstance()->setCellValueInfoPanel(maxZ+2, 1, tempString);
2780 tempString.Printf(_T("%f"),vol_minValue);
2781 interfMainPanel::getInstance()->setCellValueInfoPanel(maxZ+2, 2, tempString);
2783 tempString.Printf(_T("%f"),vol_maxValue);
2784 interfMainPanel::getInstance()->setCellValueInfoPanel(maxZ+2, 3, tempString);
2786 tempString.Printf(_T("%f"),vol_average);
2787 interfMainPanel::getInstance()->setCellValueInfoPanel(maxZ+2, 4, tempString);
2789 tempString.Printf(_T("%f"),vol_standardeviation);
2790 interfMainPanel::getInstance()->setCellValueInfoPanel(maxZ+2, 5, tempString);
2792 //-----------------------------------------
2795 wxString tmpTitleString;
2797 for ( iTitleGroup=0 ; iTitleGroup<maxContourGroup ; iTitleGroup++ )
2799 tmpIntB =_numberOfVariablesStatistics*iTitleGroup;
2800 tmpTitleString.Printf(_T("%d-Size Data"),iTitleGroup);
2801 interfMainPanel::getInstance()->setColLableInfoPanel(tmpIntB + 0, tmpTitleString);
2803 interfMainPanel::getInstance()->setColLableInfoPanel(tmpIntB + 0, tmpTitleString );
2804 interfMainPanel::getInstance()->setColLableInfoPanel( tmpIntB + 1, _T("Size Range") );
2805 interfMainPanel::getInstance()->setColLableInfoPanel( tmpIntB + 2, _T("Min") );
2806 interfMainPanel::getInstance()->setColLableInfoPanel( tmpIntB + 3, _T("Max") );
2807 interfMainPanel::getInstance()->setColLableInfoPanel( tmpIntB + 4, _T("Average") );
2808 interfMainPanel::getInstance()->setColLableInfoPanel( tmpIntB + 5, _T("St.Dev.") );
2809 interfMainPanel::getInstance()->setColLableInfoPanel( tmpIntB + 6, _T(" ") );
2811 interfMainPanel::getInstance()->setStringInfoPanel( _T("") );
2815 void wxContourMainFrame::onSaveResults(std::string directory,std::string namefile, std::string filename,
2816 int typeContourGroup, int selection, int minZ, int maxZ, bool XYZValues, bool contourImage, bool statistics)
2820 SaveValuesXYZ( directory , namefile, typeContourGroup );
2825 vtkImageData * mask;
2826 vtkImageData * value;
2827 this->getMaskValue(&mask, &value, typeContourGroup,selection,minZ,maxZ);
2828 this->SaveImageResult( directory , namefile, mask, value);
2833 std::ostringstream name;
2834 name << filename << ".xls";
2837 FILE *pFile=fopen(name.str().c_str(),"w+");
2843 // int sizeZ = _theViewPanel->GetImageDataSizeZ();
2844 // int maxY=sizeZ+2;
2846 maxX= interfMainPanel::getInstance()->getNumberColsInformationPanel();//this->_grid->GetNumberCols();
2849 int iTitle,sizeTitle = (maxX / _numberOfVariablesStatistics);
2850 for ( iTitle=0; iTitle<sizeTitle ; iTitle++)
2852 // fprintf(pFile,"-- \t %d-Size \t SizeRange \t Min \t Max \t Ave \t StDv \t" , iTitle,tmpString.c_str() );
2853 fprintf(pFile,"slice\t %d-Size \t SizeRange \t Min \t Max \t Ave \t StDv \t" , iTitle );
2855 fprintf(pFile,"\n\n" );
2859 if (selection==0 ) // actual slice
2861 std::vector<int> tempVector;
2862 _instantPanel->getInstant( tempVector );
2863 int actualSlice = tempVector[1];
2869 for ( j=minZ; j<=maxZ ; j++)
2871 fprintf(pFile,"%d\t" , j );
2872 for (i=0 ; i<maxX ; i++){
2873 tmpString = interfMainPanel::getInstance()->getCellValue(j, i);//_grid->GetCellValue( j , i );
2874 fprintf(pFile,"%s\t" , (const char *)(tmpString.mb_str()) );
2876 fprintf(pFile,"\n" );
2880 // Total of stadistics.....
2883 fprintf(pFile,"\n Total:\t" );
2884 for (i=0 ; i<maxX ; i++){
2885 tmpString = interfMainPanel::getInstance()->getCellValue(maxZ+2, i);//_grid->GetCellValue( maxZ+2 , i );
2886 fprintf(pFile,"%s\t" , (const char *)(tmpString.mb_str()) );
2888 fprintf(pFile,"\n" );
2896 void wxContourMainFrame::SaveValuesXYZ(std::string directory,std::string namefile,int typeContourGroup)
2900 //int typeContourGroup = this->_radiolstboxContourGroup->GetSelection();
2901 _contourextractdata ->SetTypeOperation( typeContourGroup % 3 );
2903 std::vector<manualBaseModel*> lstManConMod;
2904 std::vector<manualBaseModel*> lstManConModTmp;
2905 std::vector<manualBaseModel*> lstManConModExp;
2906 std::vector<double> pLstValue;
2907 std::vector<double> pLstValuePosX;
2908 std::vector<double> pLstValuePosY;
2909 std::vector<double> pLstValuePosZ;
2911 std::vector<int> tempVector;
2912 _instantPanel->getInstant( tempVector );
2914 int sizeZ = _theViewPanel->getSceneManager()->GetImageDataSizeZ();
2916 int ii,sizeLstContourThings;
2923 minZ = 0;// _mbarrange->GetStart();
2924 maxZ = sizeZ;//_mbarrange->GetEnd();
2925 totalZ = maxZ-minZ+1;
2929 for ( z=0 ; z<sizeZ ; z++)
2932 porcent = 100.0* (z-minZ)/totalZ;
2934 tmpString.Printf(_T("Saving Values"));
2935 tmpString.Printf(_T(" %d %c %d/%d %d"), (int)porcent , 37 , z-minZ+1, (int)totalZ ,z);
2936 interfMainPanel::getInstance()->setStringInfoPanel(tmpString);
2937 //_staticTextInformation->SetLabel(tmpString);
2940 //Extraction data from contours of each slice
2941 _contourextractdata->SetZtoBeAnalys( z);
2944 Instant instant(&tempVector);
2945 std::vector<ContourThing**> lstContourThings = kernelManager->getOutlinesAtInstant(&instant);//this->_modelManager->getOutlinesAtInstant( &instant );
2946 sizeLstContourThings = lstContourThings.size();
2948 lstManConMod.clear();
2949 for (ii=0 ; ii<sizeLstContourThings ; ii++)
2951 ContourThing **contourthing = lstContourThings[ii];
2952 lstManConMod.push_back( (*contourthing)->getModel() );
2954 lstManConModExp = kernelManager->ExploseEachModel( lstManConMod );
2959 int iContourGroup,sizeContourGroup;
2960 if (typeContourGroup==3) // contour separete
2962 sizeContourGroup=lstManConModExp.size();
2963 } else { // contour AND OR XOR
2967 for( iContourGroup=0 ; iContourGroup<sizeContourGroup ; iContourGroup++ ){
2968 lstManConModTmp.clear();
2969 if (typeContourGroup==3) // contour separete
2971 lstManConModTmp.push_back( lstManConModExp[iContourGroup]);
2972 } else { // contour AND OR XOR
2973 lstManConModTmp = lstManConModExp;
2976 _contourextractdata->SetLstManualContourModel( lstManConModTmp );
2979 pLstValuePosX.clear();
2980 pLstValuePosY.clear();
2981 pLstValuePosZ.clear();
2983 _contourextractdata->GetValuesInsideCrown( &numberOfPixels,
2989 std::string temp = directory + "/" + namefile + "-slice";
2990 temp = temp + kernelManager->intToString(z) + "-cont" + kernelManager->intToString(iContourGroup);
2991 temp = temp + ".txt";
2993 // LG 14/01/09 : using crea
2994 wxString filename = crea::std2wx(temp);
2995 /*filename.Printf(_T("%s"),directory.c_str());
2996 filename.append(_T("\\"));
2997 filename.append(_T("%s"),namefile.c_str());
2998 filename.append(_T("-slice"));
2999 filename.append(_T("%d"),z);
3000 filename.append(_T("-cont"));
3001 filename.append(_T("%d"),iContourGroup);
3002 filename.append(_T(".txt"));*/
3003 // filename.Printf(temp.c_str());
3007 FILE *pFile=fopen((const char *)filename.mb_str(),"w+");
3008 fprintf(pFile,"value \t x \t y \t z\n" );
3009 int iLstValue,sizeLstValue=pLstValue.size();
3010 for (iLstValue=0 ; iLstValue<sizeLstValue ; iLstValue++ )
3012 fprintf(pFile,"%f\t %f\t %f\t %f\n", (float)pLstValue[iLstValue] , (float)pLstValuePosX[iLstValue], (float)pLstValuePosY[iLstValue], (float)z );
3015 } // for iContourGroup
3017 interfMainPanel::getInstance()->setStringInfoPanel(_T(""));
3018 //_staticTextInformation->SetLabel( _T("") );
3022 void wxContourMainFrame::getMaskValue(vtkImageData ** mask,vtkImageData ** value,int typeContourGroup, int selection, int minZ, int maxZ){
3025 //int typeContourGroup = this->_radiolstboxContourGroup->GetSelection();
3026 if (typeContourGroup==3)
3030 _contourextractdata ->SetTypeOperation( typeContourGroup % 3 );
3032 std::vector<manualBaseModel*> lstManConMod;
3033 std::vector<manualBaseModel*> lstManConModTmp;
3034 std::vector<manualBaseModel*> lstManConModExp;
3036 std::vector<int> tempVector;
3037 _instantPanel->getInstant( tempVector );
3039 vtkImageData *imagedata = _theViewPanel->getImageData();
3041 imagedata->GetExtent(ext);
3042 int sizeZimage = ext[5]-ext[4]+1;
3044 int ii,sizeLstContourThings;
3053 if (selection==0 ) // actual slice
3055 int actualSlice = tempVector[1];
3063 // cleanning image before range
3064 for (z=0; z<minZ; z++){
3065 _contourextractdata->ResetImageResult(z);
3067 // cleanning image after range
3068 for (z=maxZ+1; z<sizeZimage; z++){
3069 _contourextractdata->ResetImageResult(z);
3074 for ( z=minZ ; z<=maxZ ; z++)
3077 porcent = 100.0* (z-minZ)/totalZ;
3078 tmpString.Printf(_T("Saving Values"));
3079 tmpString.Printf(_T("%d %c %d/%d %d"), (int)porcent , 37 , z-minZ+1, (int)totalZ ,z);
3080 interfMainPanel::getInstance()->setStringInfoPanel(tmpString);
3082 //Extraction data from contours of each slice
3083 _contourextractdata->SetZtoBeAnalys( z);
3086 Instant instant(&tempVector);
3087 std::vector<ContourThing**> lstContourThings = kernelManager->getOutlinesAtInstant( &instant );
3088 sizeLstContourThings = lstContourThings.size();
3090 lstManConMod.clear();
3091 for (ii=0 ; ii<sizeLstContourThings ; ii++)
3093 ContourThing **contourthing = lstContourThings[ii];
3094 lstManConMod.push_back( (*contourthing)->getModel() );
3096 lstManConModExp = kernelManager->ExploseEachModel( lstManConMod );
3099 int iContourGroup,sizeContourGroup;
3100 if (typeContourGroup==3) // contour separete
3102 sizeContourGroup=lstManConModExp.size();
3103 } else { // contour AND OR XOR
3107 for( iContourGroup=0 ; iContourGroup<sizeContourGroup ; iContourGroup++ ){
3108 lstManConModTmp.clear();
3109 if (typeContourGroup==3) // contour separete
3111 lstManConModTmp.push_back( lstManConModExp[iContourGroup]);
3112 } else { // contour AND OR XOR
3113 lstManConModTmp = lstManConModExp;
3116 _contourextractdata->SetLstManualContourModel( lstManConModTmp );
3117 _contourextractdata->CalculateImageResult(); // with actual Z
3119 } // for iContourGroup
3122 (*value) = _contourextractdata->GetVtkImageValueResult();
3123 (*mask) = _contourextractdata->GetVtkImageMaskResult();
3127 void wxContourMainFrame::SaveImageResult(std::string directory,std::string namefile, vtkImageData* mask,vtkImageData* value)
3131 kernelManager->GetSpacing(spc,0); // returns the spacing of the first image
3133 std::string temp = directory + "/" + namefile + "-image-Value.mhd";
3135 wxString filename = crea::std2wx(temp);
3139 vtkImageChangeInformation *valueChInfo = vtkImageChangeInformation::New();
3140 //EED 2017-01-01 Migration VTK7
3141 #if VTK_MAJOR_VERSION <= 5
3142 valueChInfo->SetInput(value);
3144 valueChInfo->SetInputData(value);
3146 valueChInfo->SetSpacingScale(spc);
3147 vtkMetaImageWriter *writerValueImage = vtkMetaImageWriter::New( );
3149 //EED 2017-01-01 Migration VTK7
3150 #if VTK_MAJOR_VERSION <= 5
3151 writerValueImage->SetInput( valueChInfo->GetOutput() );
3153 writerValueImage->SetInputData( valueChInfo->GetOutput() );
3155 writerValueImage->SetFileName( (const char *)filename.mb_str() );
3156 writerValueImage->SetFileDimensionality( 3 );
3157 writerValueImage->SetCompression(false);
3158 writerValueImage->Write( );
3161 temp = directory + "/" + namefile + "-image-Mask.mhd";
3163 // LG 14/01/09 : using crea
3164 filename = crea::std2wx(temp);
3165 // filename.Printf(_T(temp.c_str()));
3168 vtkImageChangeInformation *maskChInfo = vtkImageChangeInformation::New();
3169 //EED 2017-01-01 Migration VTK7
3170 #if VTK_MAJOR_VERSION <= 5
3171 maskChInfo->SetInput(mask);
3173 maskChInfo->SetInputData(mask);
3175 maskChInfo->SetSpacingScale(spc);
3176 vtkMetaImageWriter *writerMaskImage = vtkMetaImageWriter::New( );
3178 //EED 2017-01-01 Migration VTK7
3179 #if VTK_MAJOR_VERSION <= 5
3180 writerMaskImage->SetInput( maskChInfo->GetOutput() );
3182 writerMaskImage->SetInputData( maskChInfo->GetOutput() );
3185 writerMaskImage->SetFileName( (const char *)filename.mb_str() );
3186 writerMaskImage->SetFileDimensionality( 3 );
3187 writerMaskImage->SetCompression(false);
3188 writerMaskImage->Write( );
3190 interfMainPanel::getInstance()->setStringInfoPanel( _T("") );
3196 void wxContourMainFrame::onChangeInstantInstantPanel(std::string name,int value, int minshow, int maxshow){
3197 if( name.compare( _theViewPanel->getVerticalConceptName() ) == 0){
3198 _theViewPanel->setActualVertical( value);
3200 else if( name.compare( _theViewPanel->getHorizontalConceptName() ) == 0|| _instantPanel->getIfConceptCheckedAt( name, 0 ) ) {
3201 _theViewPanel->setHorizontalConcept( name, minshow, maxshow, minshow, maxshow, value);
3207 void wxContourMainFrame::onSnakePressed(){
3208 std::vector<double> vecX;
3209 std::vector<double> vecY;
3210 std::vector<double> vecZ;
3211 _theViewPanel->GetPointsOfActualContour( &vecX , &vecY , &vecZ );
3213 if (vecX.size()!=0){
3214 std::vector<int> tempVector;
3215 _instantPanel->getInstant( tempVector );
3216 int i,size=vecZ.size();
3217 int actualSlice = tempVector[1];
3218 for ( i=0 ; i<size ; i++ )
3220 vecZ[i] = actualSlice;
3223 wxDialog* dialog = new wxDialog(this, -1, wxString(_T("Snake")));
3224 wxPanel* panel = new wxPanel(dialog,-1);
3225 // wxStaticText* sttext = new wxStaticText(panel, -1, wxString(_T("Panel para snake")));
3226 new wxStaticText(panel, -1, wxString(_T("Panel para snake")));
3227 dialog->ShowModal();
3232 void wxContourMainFrame::saveFileWithContoursAutomatique(){
3233 std::string filename = kernelManager->getCurrentFileName();
3234 if(filename.compare("")!=0){
3235 saveFileWithContours(filename);
3240 void wxContourMainFrame::ShowToolsPanel(bool show){
3241 _pannew->Show(show);
3246 void wxContourMainFrame::SetContourGroup(int contourGroup)
3248 _contourGroup = contourGroup;
3252 wxPanel *wxContourMainFrame::getMaskImageViewPanel(wxWindow *parent)
3255 if (_viewMaskImagePanel==NULL)
3257 _contourextractdata = new ContourExtractData(true);
3258 _contourextractdata->SetImage( _theViewPanel->getImageData() );
3260 // _theViewPanel->getImageData()->GetScalarRange(range);
3261 //int min = (int)floor (range[0]);
3262 //int max = (int)ceil (range[1]);
3265 _viewMaskImagePanel = new ThresholdImageViewPanel( parent, -1, -1 , 0);
3266 _viewMaskImage = new ThresholdImageView();
3267 _viewMaskImage->SetImage(_contourextractdata->GetVtkImageMaskResult() );
3268 _viewMaskImage->SetminMaxValue( min, max);
3269 _viewMaskImage->SetBaseColor( 0,0,1 );
3270 _viewMaskImagePanel->SetThresholdImageView( _viewMaskImage );
3271 _viewMaskImage->SetwxVtkBaseView( _theViewPanel->getWxVtkBaseView() );
3273 return _viewMaskImagePanel;
3277 wxPanel *wxContourMainFrame::getColorLayerImageViewPanel(wxWindow *parent)
3279 if (_viewColorLayerImagePanel==NULL)
3282 _theViewPanel->getImageData()->GetScalarRange(range);
3283 int min = (int)floor (range[0]);
3284 int max = (int)ceil (range[1]);
3285 _viewColorLayerImagePanel = new ColorLayerImageViewPanel( parent, min, max, 100, 1);
3286 _viewColorLayerImagePanel->GetColorLayerImageViewManager()->SetwxVtkBaseView( 0 , _theViewPanel->getWxVtkBaseView() );
3288 return _viewColorLayerImagePanel;
3292 wxPanel *wxContourMainFrame::getThresholdImageViewPanel(wxWindow *parent)
3294 if (_viewThresholdImagePanel==NULL)
3297 _theViewPanel->getImageData()->GetScalarRange(range);
3298 int min = (int)floor (range[0]);
3299 int max = (int)ceil (range[1]);
3300 _viewThresholdImagePanel = new ThresholdImageViewPanel( parent, min, max , 1);
3301 _viewThresholdImage = new ThresholdImageView();
3302 _viewThresholdImage->SetImage( _theViewPanel->getImageData() );
3303 _viewThresholdImage->SetminMaxValue( min, max);
3304 _viewThresholdImage->SetBaseColor( 1,0,0 );
3305 _viewThresholdImagePanel->SetThresholdImageView( _viewThresholdImage );
3306 _viewThresholdImage->SetwxVtkBaseView( _theViewPanel->getWxVtkBaseView() );
3308 return _viewThresholdImagePanel;
3311 //CMRU 17-08-09-----------------------------------------------------------------------------------------------
3312 int wxContourMainFrame::getType ()
3315 std::vector<std::string> currentSelection = _theViewPanel->getSelectedObjects();
3317 if(!currentSelection.empty())
3319 std::string cloneName = currentSelection [0];
3320 manualBaseModel * manualModel = kernelManager->getOutlineByKeyName(cloneName);
3321 tipo = manualModel-> GetTypeModel();
3326 double wxContourMainFrame::getContourSizeInPixels()
3328 double contourSize = 0;
3330 std::vector<std::string> currentSelection = _theViewPanel->getSelectedObjects(); if(!currentSelection.empty())
3331 if(!currentSelection.empty())
3333 std::string cloneName = currentSelection [0];
3335 manualBaseModel * manualModel = kernelManager->getOutlineByKeyName(cloneName);//_modelManager->getOutlineByKeyName( cloneName )->getModel();
3338 // contourSize = manualModel->GetPathSize();
3343 contourSize = manualModel->GetPathSize( spc );
3348 manualBaseModel * wxContourMainFrame::getContour ()
3350 std::vector<std::string> currentSelection = _theViewPanel->getSelectedObjects();
3352 if(!currentSelection.empty())
3354 std::string cloneName = currentSelection [0];
3355 manualBaseModel * manualModel = kernelManager->getOutlineByKeyName(cloneName);//_modelManager->getOutlineByKeyName( cloneName )->getModel();
3360 void wxContourMainFrame::onPrintLabel (wxString label, manualBaseModel* manualModel)
3362 std::string labelAscii(label.ToAscii());
3363 int pos = labelAscii.find(" ");
3367 for (j=0 ; pos != string::npos;j++)
3369 labelAscii.replace( pos, 1, "_" );
3370 pos= labelAscii.find(" ");
3373 manualModel -> SetLabel(labelAscii);
3375 void wxContourMainFrame::onInsertCalculation(manualBaseModel* manualModel)
3378 // double sizeInPixel = manualModel ->GetPathSize( );
3383 double sizeInPixel = manualModel ->GetPathSize( spc );
3385 double onePixelRealSize = interfMainPanel::getInstance()->GetPixelValue();;
3386 double realContourSize = sizeInPixel*onePixelRealSize;
3387 manualModel ->SetRealSize(realContourSize);
3390 double wxContourMainFrame::onePixelSize( double value)
3392 return _onePixelSize = value;
3395 std::string wxContourMainFrame::GetFileLocation()
3397 return _fileLocation;
3400 void wxContourMainFrame::SetFileLocation(std::string newFileLocation)
3402 _fileLocation = newFileLocation;
3403 std::cout<<"GETFILELOCATION:"<<_fileLocation<<std::endl;
3405 //------------------------------------------------------------------------------------------------------------
3414 void wxContourMainFrame::FlipSelectedContours(int flipDirection)
3416 printf("EED wxContourMainFrame::FlipSelectedContours flipDirection=%d \n", flipDirection );
3418 (std::vector<std::string>)_theViewPanel->getSceneManager()->getSelectedObjects() ,
3424 void wxContourMainFrame::FlipActualSliceContours(int flipDirection)
3426 printf("EED wxContourMainFrame::FlipActualSliceContours flipDirection=%d \n", flipDirection );
3428 (std::vector<std::string>)_theViewPanel->getSceneManager()->GetlstContoursNameActualSlice() ,
3433 void wxContourMainFrame::FlipAllContours(int flipDirection)
3435 printf("EED wxContourMainFrame::FlipAllContours flipDirection=%d \n", flipDirection );
3437 kernelManager->GetLstNameThings() ,
3442 void wxContourMainFrame::FlipLstOfContours(std::vector<std::string> lstNameThings, int flipDirection)
3445 getImageData()->GetExtent(ext);
3446 int sizeX = ext[1]-ext[0];
3447 int sizeY = ext[3]-ext[2];
3450 int i,sizeLstNameThings;
3451 int ii,sizeLstPoints;
3453 sizeLstNameThings = lstNameThings.size();
3454 for (i=0 ; i<sizeLstNameThings ; i++)
3456 printf("EED wxContourMainFrame::FlipAllContours contour=%d \n", i );
3457 manualBaseModel * manualModel = kernelManager->getOutlineByKeyName(lstNameThings[i]);
3458 if (flipDirection==0)
3460 manualModel->Transform_Ax_Plus_B(-1,sizeX,1,0 );
3462 manualModel->Transform_Ax_Plus_B(1,0,-1,sizeY );
3464 }// for i list of Things
3466 //-- Static Contours
3468 lstNameThings = kernelManager->GetLstNameThingsStatic();
3469 sizeLstNameThings = lstNameThings.size();
3470 for (i=0 ; i<sizeLstNameThings ; i++)
3472 manualBaseModel * manualModel = kernelManager->getOutlineByKeyName(lstNameThings[i]);
3473 if (flipDirection==0)
3475 manualModel->Transform_Ax_Plus_B(-1,sizeX,1,0 );
3477 manualModel->Transform_Ax_Plus_B(1,0,-1,sizeY );
3479 }// for i list of static things
3482 void wxContourMainFrame::FlipContours(int typeContourFlip, int flipDirection)
3484 printf("EED wxContourMainFrame::FlipContours( %d , %d ) \n",typeContourFlip, flipDirection );
3488 if (typeContourFlip==0) //
3490 FlipSelectedContours(flipDirection);
3493 if (typeContourFlip==1) //
3495 FlipActualSliceContours(flipDirection);
3498 if (typeContourFlip==2) //
3500 FlipAllContours(flipDirection);