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;
118 // set up default notebook style
119 m_notebook_style =wxAUI_NB_TAB_SPLIT | wxAUI_NB_TAB_EXTERNAL_MOVE | wxNO_BORDER;
120 m_notebook_theme = 0;
121 //wxContour_ActionCommandsID a;
122 _numberOfVariablesStatistics = 7;
130 _pannew = interfMainPanel::getInstance(this,datadir+"/data/Icons");//, eventHandler);
131 _performingOperation = new PerformingOperation();
133 if(images.size() > 0)
135 this->setVectImages(images);
138 _contourextractdata = NULL;
141 void wxContourMainFrame::setVectImages(std::vector<vtkImageData*> imgs)
146 #if defined(__GNUC__)
147 std::string str_home(getenv("HOME"));
148 #elif defined(_WIN32)
149 std::string str_home(getenv("USERPROFILE"));
151 std::string strCreaContourDataTmp = str_home + "/.creaContourDataTemp/";
153 std::vector<std::string> conceptNameVect;
154 std::vector<int> conceptSizeVect;
156 notebook = this->createNotebook();
159 kernelManager = new KernelManagerContour( imgs , _datadir+"/data/" , strCreaContourDataTmp );
162 _instantPanel = new wxInstantChooserPanel( notebook, "Instant Chooser", true, false, "c" );
163 _theViewPanel = new wxContourViewPanel( kernelManager->getSourceImage(), notebook );
165 //-------------------------------------------------------------
166 kernelManager->getConceptsInformation(conceptNameVect, conceptSizeVect);
167 _instantPanel->addConcepts(conceptNameVect, conceptSizeVect);
170 double val = _theViewPanel->getCurrentDeep();
171 _instantPanel->setConceptValue( "Axe Depth", (int)val );
172 //JCP _instantPanel->setConceptValue("time", num de imagenes);
173 ConceptDataWrap * data = _instantPanel->getConceptDataOf( "Axe Depth" );
174 //*******************changeInstant();
175 _theViewPanel->setVerticalConcept( "Axe Depth", data->getMinValue(), data->getMaxValue(), data->getMinShowedValue(), data->getMaxShowedValue(), data->getActualValue() );
177 this->configurePanels( );
182 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 )
184 if(instance == NULL){
185 instance = new wxContourMainFrame(parent, id, title, pos, size, images, style,datadir);
190 std::vector<vtkImageData*> wxContourMainFrame ::getVectImages()
192 return kernelManager->getVectImages();
195 wxContourMainFrame* wxContourMainFrame :: getInstance()
200 void wxContourMainFrame :: resetInstance()
205 wxContourMainFrame :: ~wxContourMainFrame()
207 delete _contourextractdata;
210 interfMainPanel::resetInstance();
211 delete kernelManager;
213 //_pannew->Destroy();
219 //El problema al cerrar la aplicacion puede estar asociado
220 //a que wxAUINotebook esta en la aplicacion
221 //principal (wxContourGUIExample)tambien
222 //EED???? delete _theViewPanel;
223 //EED???? delete _instantPanel;
224 //EED???? delete _buttonsBar;
225 //EED???? delete _actualInstant;
226 //EED???? delete _sceneManager;
230 //------------------------------------------------------------------------------------------------------------
231 // Creational and initialization methods using WxAui
232 //------------------------------------------------------------------------------------------------------------
234 wxAuiNotebook * wxContourMainFrame :: createNotebook()
236 wxSize client_size = GetClientSize();
237 wxAuiNotebook* noteBook = new wxAuiNotebook(this, -1, wxPoint(client_size.x, client_size.y), wxSize(430,200), m_notebook_style);
238 wxBitmap page_bmp = wxArtProvider::GetBitmap(wxART_NORMAL_FILE, wxART_OTHER, wxSize(16,16));
243 //------------------------------------------------------------------------------------------------------------
244 // Creational and initialization methods
245 //------------------------------------------------------------------------------------------------------------
246 bool wxContourMainFrame :: configurePanels( )
248 bool configured = _theViewPanel!=NULL;
250 configured &= _theViewPanel!=NULL;
251 if( _theViewPanel!=NULL )
253 notebook->AddPage( _theViewPanel, wxT(" View ") );
260 notebook->AddPage( _instantPanel, wxT("Instant Page") );
264 m_mgr.AddPane(notebook, wxAuiPaneInfo().Name(wxT("notebook_content")).CenterPane().PaneBorder(false));
267 SetMinSize(wxSize(300,300));
273 bool wxContourMainFrame::addNewPanel(wxPanel* panel)
275 bool configured = panel!=NULL;
276 configured &= panel!=NULL;
280 notebook->AddPage( panel, wxT(" Viewer "), true );
286 //------------------------------------------------------------------------------------------------------------
287 // Attributes getters and setters
288 //------------------------------------------------------------------------------------------------------------
292 void wxContourMainFrame :: setInstantChooserPanel( wxInstantChooserPanel * theInstantChooserPanel )
294 _instantPanel = theInstantChooserPanel;
297 // void wxContourMainFrame :: setButtonsBar( wxContour_ButtonsBar * theButtonsBar )
299 // _buttonsBar = theButtonsBar;
302 // void wxContourMainFrame :: setGrid( wxContour_Grid * theGridPanel )
304 // _gridPanel = theGridPanel;
307 // void wxContourMainFrame :: setDrawToolsPanel( wxContour_DrawToolsPanel * theDrawToolsPanel )
309 // _drawToolsPanel = theDrawToolsPanel;
312 // void wxContourMainFrame :: setOperationsToolsPanel( wxContour_OperationsToolsPanel * theOperationsToolsPanel )
314 // _operationsToolsPanel = theOperationsToolsPanel;
317 // void wxContourMainFrame :: setAutomaticFormsPanel( wxContour_AutomaticFormsToolsPanel * theAutoFormsPanel )
319 // _autoFormsPanel = theAutoFormsPanel;
322 // void wxContourMainFrame :: setStandardToolsPanel( wxContour_StandardToolsPanel * theStandardToolsPanel )
324 // _standardToolsPanel= theStandardToolsPanel;
327 // void wxContourMainFrame :: setEditionToolsPanel( wxContour_EdtionToolsPanel * theEditionToolsPanel )
329 // _editionToolsPanel = theEditionToolsPanel;
332 // void wxContourMainFrame :: setListViewPanel( wxContour_ListViewPanel * theListViewPanel )
334 // _listViewPanel = theListViewPanel;
339 void wxContourMainFrame::onCreateContourSpline( ){
341 //JCP 20-10-08 Undo redo implementation
343 //JCP 20-10-08 Undo redo implementation
347 void wxContourMainFrame::onCreateContourRectangle( ){
348 //JCP 20-10-08 Undo redo implementation
350 //JCP 20-10-08 Undo redo implementation
353 void wxContourMainFrame::onCreateContourCircle( ){
354 //JCP 20-10-08 Undo redo implementation
356 //JCP 20-10-08 Undo redo implementation
360 void wxContourMainFrame::onCreateContourLine( ){
361 //JCP 20-10-08 Undo redo implementation
363 //JCP 20-10-08 Undo redo implementation
367 // RaC 09-09 --------------------------------------
368 void wxContourMainFrame::onCreateContourPoints( ){
369 //JCP 20-10-08 Undo redo implementation
371 //JCP 20-10-08 Undo redo implementation
374 // RaC 09-09 --------------------------------------
376 // RaC 10-09 --------------------------------------
377 void wxContourMainFrame::onCreateContourPolygon( ){
378 //JCP 20-10-08 Undo redo implementation
380 //JCP 20-10-08 Undo redo implementation
383 // RaC 10-09 --------------------------------------
385 //------------------------------------------------------------------------------------------------------------
387 void wxContourMainFrame :: onCreateContourBullEye(wxPanel* panel )
389 //Creating the manualBaseModel and including in the model
390 manualBaseModel * manModelContour = factoryManualContourModel(panel );
392 std::vector<int> instantVector;
393 _instantPanel->getInstant( instantVector );
394 std::string theName = kernelManager->createOutline(manModelContour, instantVector);
396 /*std::vector<int> instantVector;
397 _instantPanel->getInstant( instantVector );
399 theName= _modelManager->createOutline( manModelContour, instantVector );*/
400 bool addedModel = theName.compare("") != 0;//??
404 double spc[3];//Si no hay imagen pero hay contornos que spacing se pone por default
405 _theViewPanel->getSpacing(spc);
406 //Adding the manualContourControler to interface objects structure
407 //Adding the manualViewContour to interface objects structure
408 //_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.
409 _theViewPanel->getSceneManager()->configureViewControlTo( theName, manModelContour,spc , 4) ;
412 void wxContourMainFrame :: createContour( int typeContour )
414 //Creating the manualContourModel and including in the model
415 manualBaseModel * manModelContour = kernelManager->factoryManualContourModel(typeContour);
417 std::vector<int> instantVector;
418 _instantPanel->getInstant( instantVector );
419 std::string theName = kernelManager->createOutline(manModelContour, instantVector);
421 /*std::vector<int> instantVector;
422 _instantPanel->getInstant( instantVector );
424 theName= _modelManager->createOutline( manModelContour, instantVector );*/
425 bool addedModel = theName.compare("") != 0;//??
428 double spc[3];//Si no hay imagen pero hay contornos que spacing se pone por default
429 _theViewPanel->getSpacing(spc);
430 //Adding the manualContourControler to interface objects structure
431 //Adding the manualViewContour to interface objects structure
432 //_sceneManager->setControlActiveStateOfALL( false );//This call is being done here because if the ROI is created underneath the previously created ROIS will still be active.
433 _theViewPanel->getSceneManager()->configureViewControlTo( theName, manModelContour,spc , typeContour) ;
437 manualBaseModel * wxContourMainFrame::factoryManualContourModel(wxPanel* panel){
439 manualContourModelBullEye *manModelContourBullEye = new manualContourModelBullEye();
440 manualBaseModel *manModelContour=NULL;
441 manModelContour = manModelContourBullEye;
443 int iCrown,sizeCrowns,iSector,sizeSectors;
444 double radioA,radioB,ang,angDelta ;
445 sizeCrowns = ((PanelBullEyeOptions*)panel)->GetNumberOfCrowns();
446 for ( iCrown=0 ; iCrown<sizeCrowns ; iCrown++ )
448 sizeSectors = ((PanelBullEyeOptions*)panel)->GetNumberOfSections(iCrown);
449 radioB = ((PanelBullEyeOptions*)panel)->GetRadioOfCrown(iCrown);
450 if (iCrown==sizeCrowns-1)
454 radioA = ((PanelBullEyeOptions*)panel)->GetRadioOfCrown(iCrown+1);
458 for ( iSector=0 ; iSector<sizeSectors ; iSector++ )
460 ang = ((PanelBullEyeOptions*)panel)->GetAngOfCrownSection(iCrown,iSector);
461 angDelta= ((PanelBullEyeOptions*)panel)->GetAngDeltaOfCrownSection(iCrown);
462 manModelContourBullEye->AddSector(radioA,radioB,ang,angDelta);
465 } // if _panelBullEyeOptions
467 return manModelContour;
469 void wxContourMainFrame :: saveState(){
471 std::string temp = kernelManager->saveState();
472 saveFileWithContours(temp);
475 void wxContourMainFrame::onDeleteContour(){
476 //JCP 20-10-08 Undo redo implementation
478 //JCP 20-10-08 Undo redo implementation
480 std::vector<std::string> lstKeyNameToBeErase;
481 lstKeyNameToBeErase = _theViewPanel->getSceneManager()->getSelectedObjects();
482 deleteContours( lstKeyNameToBeErase );
484 int i,size=_sceneManager->getSelectedObjects().size();
487 std::string keyName = _sceneManager->getSelectedObjects()[i];
488 int ispartofstaticlist = this->_modelManager->IsPartOfStaticList( keyName );
489 if ( ispartofstaticlist>=0 )
491 std::vector<int> tempVector;
492 _instantPanel->getInstant( tempVector );
493 Instant instant(&tempVector);
494 this->_modelManager->ChangeContourOfList(keyName, &instant);
498 std::vector<std::string> lstKeyName;
499 std::vector<std::string> lstKeyNameActualSlice;
500 std::vector<std::string> lstKeyNameToBeErase;
502 lstKeyNameToBeErase = _sceneManager->getSelectedObjects();
503 lstKeyNameActualSlice = _sceneManager->GetlstContoursNameActualSlice();
504 int k,kSize=lstKeyNameToBeErase.size();
505 int j,jSize=lstKeyNameActualSlice.size();
507 for (k=0;k<kSize; k++)
510 for (j=0;j<jSize; j++)
512 if (lstKeyNameToBeErase[k]==lstKeyNameActualSlice[j])
519 lstKeyName.push_back( lstKeyNameToBeErase[k] );
523 deleteContours( lstKeyName );
527 void wxContourMainFrame :: deleteContours( std::vector<std::string> keyNamesVector )
529 int i,size=keyNamesVector.size();
532 deleteContour( keyNamesVector[i] );
536 void wxContourMainFrame :: deleteContour( std::string theKeyName ){
538 manualContourModel * cModel;
539 manualViewBaseContour * cViewer;
540 manualContourBaseControler * cControler;
542 ContourWrap_ViewControl *conwrapviewControl = _theViewPanel->getSceneManager()->getContourWrap_ViewControlOf( theKeyName );
543 cControler = conwrapviewControl->getControler();*/
546 bool isedit = _theViewPanel->isEditableCControler(theKeyName);
547 bool ispartofstaticlst = kernelManager->IsPartOfStaticList(theKeyName);
549 if (isedit && ispartofstaticlst)
551 _theViewPanel->removeFromScene(theKeyName);
553 kernelManager->deleteCModel(theKeyName);
554 //_theViewPanel->getSceneManager()->removeFromScene( theKeyName );
555 //cViewer = conwrapviewControl->getViewer();
556 //_theViewPanel->getSceneManager()->removeWrap( theKeyName );
557 //cControler* conwrapviewControl->getControler();
560 // delete cControler;
565 void wxContourMainFrame::onDeleteContoursActSlice(){
566 //JCP 20-10-08 Undo redo implementation
568 //JCP 20-10-08 Undo redo implementation
569 deleteContours( (std::vector<std::string>)_theViewPanel->getSceneManager()->GetlstContoursNameActualSlice() );
571 void wxContourMainFrame::onDeleteAllContours(){
572 //JCP 20-10-08 Undo redo implementation
576 void wxContourMainFrame::deleteAllContours(){
577 //JCP 20-10-08 Undo redo implementation
580 std::vector<int> tempVector;
581 _instantPanel->getInstant( tempVector );
583 //JCP --08-09-2008 When using a diferent interface the _mbarrangeDeleteAll might not be initialize
584 // the values in GetStart and GetEnd will then not be initialize also.
585 // We use instead the values given when initializing the _deletepanel.
587 //int minZ = _mbarrangeDeleteAll->GetStart();
588 //int maxZ = _mbarrangeDeleteAll->GetEnd();
592 maxZ = _theViewPanel->getSceneManager()->GetImageDataSizeZ();
596 _theViewPanel->getSceneManager()->removeSceneContours( );
597 _theViewPanel->getSceneManager()->removeAllOutlines();
598 kernelManager->removeAllOutlines();
601 if ( (minZ==0) && (maxZ==_mbarrangeDeleteAll->GetMax() ))
603 _theViewPanel->getSceneManager()->removeSceneContours( );
604 _modelManager->removeAllOutlines();
605 _theViewPanel->getSceneManager()->removeAllOutlines();
608 for ( z=minZ ; z<=maxZ ; z++)
611 Instant instant(&tempVector);
612 std::vector<ContourThing**> lstContourThings = this->_modelManager->getOutlinesAtInstant( &instant );
614 sizeLstContourThings = lstContourThings.size();
615 for (ii=0 ; ii<sizeLstContourThings ; ii++)
617 ContourThing **contourthing = lstContourThings[ii];
618 deleteContour( (*contourthing)->getName() );
625 void wxContourMainFrame::setConceptValue( std::string name, int value ){
626 _instantPanel->setConceptValue(name, value);
630 ConceptDataWrap* wxContourMainFrame::getLastConceptData(){
631 return _instantPanel->getLastConceptData();
635 bool wxContourMainFrame::getIfConceptCheckedAt( std::string name, int pos ){
636 return _instantPanel->getIfConceptCheckedAt( name, pos );
641 void wxContourMainFrame::ShowResultImages(int typeContourGroup, int selection, int minZ, int maxZ)
644 vtkImageData * value;
645 this->getMaskValue(&mask, &value, typeContourGroup, selection, minZ, maxZ);
647 std::vector<int> nTypeView;
648 nTypeView.push_back(5);
649 nTypeView.push_back(1);
650 nTypeView.push_back(2);
651 nTypeView.push_back(0);
653 wxFrame *frame = new wxFrame(this, -1,_T("Result image extracted.."),wxDefaultPosition,wxSize(600,600), wxDEFAULT_FRAME_STYLE|wxSTAY_ON_TOP);
654 wxAuiManager *m_mgr_noteBookViewerResult = new wxAuiManager();
655 m_mgr_noteBookViewerResult->SetManagedWindow(frame);
657 wxAuiNotebook* noteBookViewerResult = new wxAuiNotebook(frame, -1, wxPoint(600, 600), wxSize(430,200), m_notebook_style);
658 m_mgr_noteBookViewerResult->AddPane(noteBookViewerResult, wxAuiPaneInfo().Name(wxT("notebook_content")).CenterPane().PaneBorder(false));
660 wxPanel *panelViewer1 = new wxMaracas_N_ViewersWidget(noteBookViewerResult, value,&nTypeView);
661 wxPanel *panelViewer2 = new wxMaracas_N_ViewersWidget(noteBookViewerResult, mask,&nTypeView);
664 noteBookViewerResult->AddPage( panelViewer1, wxT("Image result") );
665 noteBookViewerResult->AddPage( panelViewer2, wxT("Mask result") );
666 m_mgr_noteBookViewerResult->Update();
673 void wxContourMainFrame::changeInstant()
675 std::vector<int> instantVect;
676 _instantPanel->getInstant( instantVect );
677 int actualSlice = instantVect[1];
679 kernelManager->setInstant(instantVect);
681 // Refresh Mask image
682 if(_viewMaskImage!=NULL){
683 _viewMaskImage->SetZ(actualSlice);
684 if (_viewMaskImagePanel->IsVisible()==true)
686 vtkImageData *mask, *value;
687 getMaskValue(&mask,&value, _contourGroup , 0, -1, -1);
688 _viewMaskImage->onThreshold();
692 // Refresh Threshold image
693 if(_viewThresholdImage!=NULL){
694 _viewThresholdImage->SetZ(actualSlice);
695 if (_viewThresholdImagePanel->IsVisible()==true){
696 _viewThresholdImage->onThreshold();
701 updateInstantOutlines();
702 updateInstantImageData();
708 void wxContourMainFrame :: updateInstantOutlines()
710 _theViewPanel->removeSceneContours();
711 _theViewPanel->addNameWrapperToScene();
713 //for( int i=0; i<size; i++)
715 // _theViewPanel->getSceneManager()->addToScene(namesWrapping[i]->getKeyName(), true, true, true, false, false );
719 int wxContourMainFrame::getNamesWrappingSize(){
720 return kernelManager->getNamesWrappingSize();
722 std::string wxContourMainFrame::getNameWrapping(int i){
723 return kernelManager->getNameWrapping(i);
726 void wxContourMainFrame::updateInstantImageData()
728 std::vector<int> inst;
729 _instantPanel->getInstant(inst);
731 vtkImageData* img = kernelManager->getImageAtInstant(inst);
733 _theViewPanel->changeImage(img);
736 int z = _instantPanel->getConceptDataOf("Axe Depth")->getActualValue();
737 _theViewPanel->setImageSlice(z);
741 void wxContourMainFrame::updateInstantAxes()
746 void wxContourMainFrame::onChangeDeep(int val){
747 _instantPanel->setConceptValue( "Axe Depth", (int)val );
752 void wxContourMainFrame::onCopy(){
753 std::vector<std::string> currentSelection = _theViewPanel->getSelectedObjects();
755 std::vector<int> tempVector;
756 _instantPanel->getInstant( tempVector );
757 _performingOperation->reset();
758 _performingOperation->setStartCommand( COPY );
759 _performingOperation->setStartOperationInstantVector( tempVector );
760 _performingOperation->setKeyNamesOperationElems( currentSelection );
763 void wxContourMainFrame::onPaste(){
766 char theStartCommand = _performingOperation->getStartCommand();
767 if ( theStartCommand == COPY )
769 //JCP 20-10-08 Undo redo implementation
771 //JCP 20-10-08 Undo redo implementation
772 std::vector<int> tempVector;
773 _instantPanel->getInstant( tempVector );
774 _performingOperation->setEndOperationInstantVector ( tempVector );
775 std::vector<std::string> elems = _performingOperation->getKeyNamesOperationElems();
776 int i,size = elems.size();
777 for( i=0; i<size; i++ )
779 createCopyContourOf( elems[i], tempVector, i>0 );
783 void wxContourMainFrame::onUndo(){
784 std::string filename;
785 if(kernelManager->onUndoSaveFile(filename)){
786 saveFileWithContours(filename);
788 if(kernelManager->onUndo(filename)){
792 void wxContourMainFrame::onRedo(){
793 std::string filename;
794 if(kernelManager->onRedo(filename)){
799 void wxContourMainFrame :: createCopyContourOf ( std::string anExistingKName, std::vector<int> &instantNoTouchData, bool append )
801 std::string cloneName = kernelManager->createCopyContourOf( anExistingKName, instantNoTouchData );
802 manualBaseModel * manualModel = kernelManager->getOutlineByKeyName(cloneName);//_modelManager->getOutlineByKeyName( cloneName )->getModel();
803 _theViewPanel->getSceneManager()->createCopyContourOf( anExistingKName, cloneName, manualModel , append );
806 ///AD: 03-09 Copy the object and apply the given transformation
807 void wxContourMainFrame :: createMirrorContourOf ( std::string anExistingKName, std::vector<int> &instantNoTouchData, bool append )
809 std::string cloneName = kernelManager->createCopyContourOf( anExistingKName, instantNoTouchData );
810 manualBaseModel * manualModel = kernelManager->getOutlineByKeyName(cloneName);
812 manualPoint * refPoint1 = _refLineModel->GetManualPoint(0);
813 manualPoint * refPoint2 = _refLineModel->GetManualPoint(1);
815 double pnt1X = refPoint1->GetX();
816 double pnt1Y = refPoint1->GetY();
817 // double pnt1Z = refPoint1->GetZ();
818 double pnt2X = refPoint2->GetX();
819 double pnt2Y = refPoint2->GetY();
820 // double pnt2Z = refPoint2->GetZ();
822 double angle = (atan2(pnt2Y - pnt1Y, pnt2X - pnt1X) * 180 / 3.1415926535897932384626433832795)+90;
823 vtkTransform *t = vtkTransform::New();
827 t->Translate(-pnt1X, -pnt1Y, 0);
831 t->Translate(pnt1X, pnt1Y, 0);
834 int i,size=manualModel->GetSizeLstPoints();
837 manualPoint * mp = manualModel->GetManualPoint(i);
843 t->TransformPoint( vecIn, vecOut );
844 mp->SetPointX( vecOut[0] );
845 mp->SetPointY( vecOut[1] );
846 mp->SetPointZ( vecOut[2] );
849 _theViewPanel->getSceneManager()->createCopyContourOf( anExistingKName, cloneName, manualModel , append );
853 void wxContourMainFrame ::loadState(std::string filename){
856 onLoadContours(filename,false);
860 FILE *pFile=fopen(filename.c_str(),"r+");
862 fscanf(pFile,"%s",tmp); // --CreaContour--
864 fscanf(pFile,"%s",tmp); // Version
865 fscanf(pFile,"%s",tmp); // 1.0.3 || 1.0.2 || 1.0.1 || 1.0.0
869 loadContours(pFile, false);
870 loadContours(pFile, true);
879 void wxContourMainFrame::loadContours( FILE *pFile, bool staticContour )
883 if (staticContour==false)
885 fscanf(pFile,"%s",tmp); // ImageDimensions
886 fscanf(pFile,"%s",tmp); // X
887 fscanf(pFile,"%s",tmp); // Y
888 fscanf(pFile,"%s",tmp); // Z
890 fscanf(pFile,"%s",tmp); // ImageSpacing
891 fscanf(pFile,"%s",tmp); // X
892 fscanf(pFile,"%s",tmp); // Y
893 fscanf(pFile,"%s",tmp); // Z
896 fscanf(pFile,"%s",tmp); // NumberOfContours
897 fscanf(pFile,"%s",tmp); // ##
898 int numberOfContours = atoi(tmp);
900 std::vector<int> instantVector;
901 int typeContourModel;
902 manualBaseModel *manModelContour;
906 for (i=0;i<numberOfContours;i++)
908 instantVector.clear();
909 fscanf(pFile,"%s",tmp); // Instant
910 fscanf(pFile,"%s",tmp); // 1
911 instantVector.push_back( atoi(tmp) );
912 fscanf(pFile,"%s",tmp); // 2
913 instantVector.push_back( atoi(tmp) );
914 fscanf(pFile,"%s",tmp); // 3
915 instantVector.push_back( atoi(tmp) );
916 fscanf(pFile,"%s",tmp); // 4
917 instantVector.push_back( atoi(tmp) );
918 fscanf(pFile,"%s",tmp); // 5
919 instantVector.push_back( atoi(tmp) );
920 fscanf(pFile,"%s",tmp); // 6
921 instantVector.push_back( atoi(tmp) );
923 fscanf(pFile,"%s",tmp); // TypeContourModel
924 fscanf(pFile,"%s",tmp); // ##
925 typeContourModel = atoi(tmp);
927 manModelContour = kernelManager->factoryManualContourModel(typeContourModel);
928 manModelContour->Open(pFile);
930 fscanf(pFile,"%s",tmp); // TypeView
931 fscanf(pFile,"%s",tmp); // ##
932 typeView = atoi(tmp);
935 theName = kernelManager->createOutline( manModelContour, instantVector );
936 bool addedModel = theName.compare("") != 0;
939 double spc[3];//Si no hay imagen pero hay contornos que spacing se pone por default
940 _theViewPanel->getSpacing(spc);
941 //Adding the manualContourControler to interface objects structure
942 //Adding the manualViewContour to interface objects structure
943 //_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.
944 _theViewPanel->getSceneManager()->configureViewControlTo( theName, manModelContour,spc , typeView) ;
947 if (staticContour==true)
949 Instant instant(&instantVector);
950 kernelManager->changeContourOfManager( theName , &instant );
952 }// for numberOfContours
957 void wxContourMainFrame::onLoad()
959 std::string fileNameContourROI = GetFileLocation();
960 //CMRU 03-09-09-----------------------------------------------------------------------------------------------
961 if(GetFileLocation().empty())
963 //------------------------------------------------------------------------------------------------------------
964 //EED 2017-09-16 Migration wxWidgets 2.8 to 3.0
965 #if wxMAJOR_VERSION <= 2
966 wxFileDialog dialog(NULL, _T("Choose a file"), _T(""), _T(""), _T("*.roi"), wxOPEN );
968 wxFileDialog dialog(NULL, _T("Choose a file"), _T(""), _T(""), _T("*.roi"), wxFD_OPEN );
970 if (dialog.ShowModal() == wxID_OK)
972 fileNameContourROI = (const char *)(dialog.GetPath().mb_str());
976 onLoadContours(fileNameContourROI,true);
980 void wxContourMainFrame::SetZForAllContours(int pz)
982 printf("EED wxContourMainFrame::SetZForAllContours\n");
986 std::vector< std::string > lstNameThings;
987 int i,sizeLstNameThings;
988 int ii,sizeLstPoints;
990 lstNameThings = kernelManager->GetLstNameThings();
991 sizeLstNameThings = lstNameThings.size();
992 for (i=0 ; i<sizeLstNameThings ; i++)
994 printf("EED wxContourMainFrame::SetZForAllContours contour=%d \n", i );
995 manualBaseModel * manualModel = kernelManager->getOutlineByKeyName(lstNameThings[i]);
996 sizeLstPoints = manualModel->GetSizeLstPoints();
997 for (ii=0 ; ii<sizeLstPoints ; ii++)
999 manualModel->GetManualPoint(ii)->SetPointZ(-900);
1000 }// for ii list of points
1001 }// for i list of Things
1003 //-- Static Contours
1005 lstNameThings = kernelManager->GetLstNameThingsStatic();
1006 sizeLstNameThings = lstNameThings.size();
1007 for (i=0 ; i<sizeLstNameThings ; i++)
1009 manualBaseModel * manualModel = kernelManager->getOutlineByKeyName(lstNameThings[i]);
1010 sizeLstPoints = manualModel->GetSizeLstPoints();
1011 for (ii=0 ; ii<sizeLstPoints ; ii++)
1013 manualModel->GetManualPoint(ii)->SetPointZ(-900);
1014 }// for ii list of points
1015 }// for i list of static things
1018 void wxContourMainFrame::onLoadContours(std::string fileNameContourROI, bool interactiveInterface)
1022 FILE *pFile =fopen(fileNameContourROI.c_str(),"r+");
1023 //CMRU 03-09-09- ----------------------------------------------------------------------------------------------
1026 //------------------------------------------------------------------------------------------------------------
1027 fileNameContourROI.append("data");
1028 FILE *pFileData=fopen(fileNameContourROI.c_str(),"r+");
1029 if(pFileData != NULL)
1031 fscanf(pFileData,"%s",tmpD); // --CreaContour--
1032 fscanf(pFileData,"%s",tmpD); // Version
1033 fscanf(pFileData,"%s",tmpD); // 1.0.3 || 1.0.2 || 1.0.1 || 1.0.0
1035 fscanf(pFileData,"%s",tmpD); // onePixelSize
1036 fscanf(pFileData,"%s",tmpD); // #
1037 _onePixelSize = atof(tmpD);
1038 fscanf(pFileData,"%s",tmpD); // NumberOfContours
1039 fscanf(pFileData,"%s",tmpD); // #
1042 fscanf(pFile,"%s",tmp); // --CreaContour--
1044 fscanf(pFile,"%s",tmp); // Version
1045 fscanf(pFile,"%s",tmp); // 1.0.3 || 1.0.2 || 1.0.1 || 1.0.0
1046 std::string version(tmp);
1049 printf("EED wxContourMainFrame::onLoadContours version%s \n", version.c_str() );
1053 _tmpReadFileTypeOfTransformation=-1;
1054 if (version=="1.0.3")
1056 readDimSpc(pFile,interactiveInterface); // DimSpc interactive ON
1057 openContours(pFile,pFileData,false);
1058 openContours(pFile,pFileData,true); //Load StaticContours
1061 if (version=="1.0.2")
1064 readDimSpc(pFile,interactiveInterface); // DimSpc interactive ON
1065 openContours(pFile,pFileData,false);
1066 readDimSpc(pFile,false); // DimSpc interactive OFF
1067 openContours(pFile,pFileData,true); // Load StaticContours
1068 SetZForAllContours(-900);
1072 else if (version=="1.0.1")
1074 openContours(pFile,pFileData,false); //Skips ImageDimensions and ImageSpacing
1075 openContours(pFile,pFileData,true); //Load StaticContours, skips ImageDimensions and ImageSpacing
1079 else if (version=="1.0.0")
1081 openContours(pFile,pFileData,false); //Skips ImageDimensions and ImageSpacing
1086 if(pFileData != NULL)
1091 _theViewPanel->getSceneManager()->removeSceneContours();
1096 void wxContourMainFrame::onImport()
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 XML Osirix File"), _T(""), _T(""), _T("*.xml"), wxOPEN );
1103 wxFileDialog dialog(NULL, _T("Choose a XML Osirix File"), _T(""), _T(""), _T("*.xml"), wxFD_OPEN );
1105 if (dialog.ShowModal() == wxID_OK)
1107 filename = dialog.GetPath().mb_str();
1108 filenamecontours = kernelManager->parseOsirixFile(filename);
1110 if(filenamecontours.compare("") != 0){
1111 onLoadContours(filenamecontours,true);
1116 void wxContourMainFrame::onTest()
1118 std::string filename, filenamecontours;
1119 //EED 2017-09-16 Migration wxWidgets 2.8 to 3.0
1120 #if wxMAJOR_VERSION <= 2
1121 wxFileDialog dialog(NULL, _T("Choose a File"), _T(""), _T(""), _T("*.*"), wxOPEN );
1123 wxFileDialog dialog(NULL, _T("Choose a File"), _T(""), _T(""), _T("*.*"), wxFD_OPEN );
1126 if (dialog.ShowModal() == wxID_OK)
1128 filename = dialog.GetPath().mb_str();
1129 std::cout << "This is the filename: " << filename << std::endl;
1135 void wxContourMainFrame::onSave(){
1136 //CMRU 03-09-09-----------------------------------------------------------------------------------------------
1137 if(GetFileLocation().empty())
1139 //------------------------------------------------------------------------------------------------------------
1140 //EED 2017-09-16 Migration wxWidgets 2.8 to 3.0
1141 #if wxMAJOR_VERSION <= 2
1142 wxFileDialog dialog(NULL, _T("Choose a file"), _T(""), _T(""), _T("*.roi"), wxSAVE );
1144 wxFileDialog dialog(NULL, _T("Choose a file"), _T(""), _T(""), _T("*.roi"), wxFD_SAVE );
1146 if (dialog.ShowModal() == wxID_OK)
1148 std::string fileNameContourROI = (const char *)(dialog.GetPath().mb_str());
1149 kernelManager->setCurrentFileName(fileNameContourROI);
1150 saveFileWithContours( fileNameContourROI );
1153 //CMRU 03-09-09-----------------------------------------------------------------------------------------------
1156 std::cout<<"Nombre del archivo: "<<GetFileLocation()<<std::endl;
1157 std::string fileNameContourROI = GetFileLocation();
1158 std::cout<<"Nombre del archivo: "<<fileNameContourROI<<std::endl;
1159 kernelManager->setCurrentFileName(fileNameContourROI);
1160 saveFileWithContours( fileNameContourROI);
1162 //------------------------------------------------------------------------------------------------------------
1166 void wxContourMainFrame::saveFileWithContours( std::string filename )
1169 FILE *pFile=fopen(filename.c_str(),"w+");
1171 //CMRU 03-09-09-----------------------------------------------------------------------------------------------
1172 filename.append("data");
1173 std::cout<<"Nombre del archivo: "<<filename<<std::endl;
1174 FILE *pFileData=fopen(filename.c_str(),"w+");
1175 //------------------------------------------------------------------------------------------------------------
1177 std::vector< std::string > lstNameThings;
1178 int i,sizeLstNameThings;
1180 fprintf(pFile,"--CreaContour--\n");
1181 fprintf(pFile,"Version %s\n", "1.0.3" );
1183 //CMRU 03-09-09-----------------------------------------------------------------------------------------------
1184 fprintf(pFileData,"--CreaContour--\n");
1185 fprintf(pFileData,"Version %s\n", "1.0.3" );
1186 fprintf(pFileData,"OnePixelSize %f\n", _onePixelSize);
1188 //------------------------------------------------------------------------------------------------------------
1190 vtkImageData *image = _images[0];
1193 image->GetDimensions(dimRange);
1195 fprintf(pFile,"ImageDimensions %d %d %d\n", dimRange[0], dimRange[1], dimRange[2] );
1198 image->GetSpacing(spaRange);
1200 fprintf(pFile,"ImageSpacing %f %f %f\n", spaRange[0], spaRange[1], spaRange[2] );
1204 lstNameThings = kernelManager->GetLstNameThings();
1205 sizeLstNameThings = lstNameThings.size();
1206 fprintf(pFile,"NumberOfContours %d\n", sizeLstNameThings );
1208 //CMRU 03-09-09-----------------------------------------------------------------------------------------------
1209 fprintf(pFileData,"NumberOfContours %d\n", sizeLstNameThings );
1210 //------------------------------------------------------------------------------------------------------------
1219 for (i=0 ; i<sizeLstNameThings ; i++)
1221 //CMRU 03-09-09-----------------------------------------------------------------------------------------------
1222 manualBaseModel * manualModel = kernelManager->getOutlineByKeyName(lstNameThings[i]);
1225 // double sizeInPixel = manualModel ->GetPathSize( );
1226 double sizeInPixel = manualModel ->GetPathSize( spc );
1228 double realContourSize = sizeInPixel*_onePixelSize;
1229 manualModel ->SetRealSize(realContourSize);
1230 //------------------------------------------------------------------------------------------------------------
1232 //int size= kernelManager->GetLstNameThings().size();
1234 kernelManager->SaveThingName( pFile, pFileData, lstNameThings[i] );
1235 _theViewPanel->getSceneManager()->SaveThingName( pFile, lstNameThings[i] );
1238 //-- Static Contours
1240 // fprintf(pFile,"ImageDimensions %d %d %d\n", dimRange[0], dimRange[1], dimRange[2] );
1241 // fprintf(pFile,"ImageSpacing %f %f %f\n", spaRange[0], spaRange[1], spaRange[2] );
1243 lstNameThings = kernelManager->GetLstNameThingsStatic();
1244 sizeLstNameThings = lstNameThings.size();
1245 fprintf(pFile,"NumberOfContoursStatic %d\n", sizeLstNameThings );
1247 //CMRU 03-09-09-----------------------------------------------------------------------------------------------
1248 fprintf(pFileData,"NumberOfContoursStatic %d\n", sizeLstNameThings );
1249 //------------------------------------------------------------------------------------------------------------
1251 for (i=0 ; i<sizeLstNameThings ; i++)
1253 kernelManager->SaveThingName( pFile, pFileData, lstNameThings[i] );
1254 _theViewPanel->getSceneManager()->SaveThingName( pFile, lstNameThings[i] );
1262 void wxContourMainFrame::readDimSpc(FILE *pFile, bool interactiveOption)
1266 double imageSpac[3];
1267 vtkImageData *image = _images[0];
1268 image->GetDimensions(imageDim);
1269 image->GetSpacing(imageSpac);
1271 fscanf(pFile,"%s",tmp); // ImageDimensions
1272 fscanf(pFile,"%s",tmp); // X
1273 _tmpReadFileImageDim[0] = atoi(tmp);
1274 fscanf(pFile,"%s",tmp); // Y
1275 _tmpReadFileImageDim[1] = atoi(tmp);
1276 fscanf(pFile,"%s",tmp); // Z
1277 _tmpReadFileImageDim[2] = atoi(tmp);
1279 fscanf(pFile,"%s",tmp); // ImageSpacing
1280 fscanf(pFile,"%s",tmp); // X
1281 _tmpReadFileImageSpac[0] = atof(tmp);
1282 fscanf(pFile,"%s",tmp); // Y
1283 _tmpReadFileImageSpac[1] = atof(tmp);
1284 fscanf(pFile,"%s",tmp); // Z
1285 _tmpReadFileImageSpac[2] = atof(tmp);
1288 if (interactiveOption==true)
1290 //Compare Spacing and Dims in X and Y (Necessary in Z?) - Just for Version 2
1291 if (imageDim[0]!=_tmpReadFileImageDim[0] || imageDim[1]!=_tmpReadFileImageDim[1] || imageSpac[0]!=_tmpReadFileImageSpac[0] || imageSpac[1]!=_tmpReadFileImageSpac[1])
1293 wxDialog* dial = new wxDialog (this,-1,_T("Tools"),wxDefaultPosition, wxSize(460,360));
1294 wxSizer* buttonsSizer = dial->CreateSeparatedButtonSizer(wxOK|wxCANCEL);
1295 wxBoxSizer *dialSizer = new wxBoxSizer(wxVERTICAL);
1297 wxString lstOptOperation[2];
1298 lstOptOperation[0]=_T("By Dimension");
1299 lstOptOperation[1]=_T("By Spacing");
1300 wxRadioBox * radioOpts = new wxRadioBox(dial, -1, _T("Type of Transformation"), wxDefaultPosition, wxSize(270,45), 2 , lstOptOperation, 2, wxRA_SPECIFY_COLS);
1302 dialSizer->Add( new wxStaticText(dial,-1,_T("The image resolution is not compatible with the ")) , 0, wxGROW );
1303 dialSizer->Add( new wxStaticText(dial,-1,_T("selected Roi file. Do you want to tranform it?")) , 0, wxGROW );
1304 dialSizer->Add( new wxStaticText(dial,-1,_T(" ")) , 0, wxGROW );
1305 dialSizer->Add(radioOpts,0,wxGROW);
1306 dialSizer->Add( new wxStaticText(dial,-1,_T(" ")) , 0, wxGROW );
1307 dialSizer->Add(buttonsSizer,0,wxGROW);
1308 dial->SetSizer(dialSizer, true);
1312 int _tmpReadFileTypeOfTransformation = -1;
1313 //EED bool transform = false;
1315 if (dial->GetReturnCode() == wxID_OK)
1317 _tmpReadFileTypeOfTransformation = radioOpts->GetSelection();
1321 } // if interactiveOption
1328 void wxContourMainFrame::openContours( FILE *pFile, FILE *pFileData, bool staticContour )
1333 vtkImageData *image = _images[0];
1336 double imageSpac[3];
1337 image->GetDimensions(imageDim);
1338 image->GetSpacing(imageSpac);
1341 fscanf(pFile,"%s",tmp); // NumberOfContours
1342 fscanf(pFile,"%s",tmp); // ##
1343 int numberOfContours = atoi(tmp);
1345 std::vector<int> instantVector;
1346 int typeContourModel;
1347 manualBaseModel *manModelContour;
1351 if (compatible==true)
1354 for (i=0;i<numberOfContours;i++)
1356 instantVector.clear();
1357 fscanf(pFile,"%s",tmp); // Instant
1359 fscanf(pFile,"%s",tmp); // 1
1360 instantVector.push_back( atoi(tmp) );
1361 fscanf(pFile,"%s",tmp); // 2
1362 instantVector.push_back( atoi(tmp) );
1363 fscanf(pFile,"%s",tmp); // 3
1364 instantVector.push_back( atoi(tmp) );
1365 fscanf(pFile,"%s",tmp); // 4
1366 instantVector.push_back( atoi(tmp) );
1367 fscanf(pFile,"%s",tmp); // 5
1368 instantVector.push_back( atoi(tmp) );
1369 fscanf(pFile,"%s",tmp); // 6
1370 instantVector.push_back( atoi(tmp) );
1373 fscanf(pFile,"%s",tmp); // TypeContourModel
1374 fscanf(pFile,"%s",tmp); // ##
1375 typeContourModel = atoi(tmp);
1377 manModelContour = kernelManager->factoryManualContourModel(typeContourModel);
1378 manModelContour->Open(pFile);
1379 if(pFileData != NULL)
1381 manModelContour->OpenData(pFileData);
1384 fscanf(pFile,"%s",tmp); // TypeView
1385 fscanf(pFile,"%s",tmp); // ##
1386 typeView = atoi(tmp);
1388 std::string theName;
1389 theName = kernelManager->createOutline( manModelContour, instantVector );
1390 bool addedModel = theName.compare("") != 0;
1393 double spc[3];//Si no hay imagen pero hay contornos que spacing se pone por default
1394 _theViewPanel->getSpacing(spc);
1395 //Adding the manualContourControler to interface objects structure
1396 //Adding the manualViewContour to interface objects structure
1397 //_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.
1398 _theViewPanel->getSceneManager()->configureViewControlTo( theName, manModelContour,spc , typeView) ;
1401 if (staticContour) //StaticContours (will appear in all slices)
1403 Instant instant(&instantVector);
1404 kernelManager->changeContourOfManager( theName , &instant );
1407 }// for numberOfContours
1410 else if (compatible==false)
1415 for (i=0;i<numberOfContours;i++)
1417 instantVector.clear();
1418 fscanf(pFile,"%s",tmp); // Instant
1420 fscanf(pFile,"%s",tmp); // 1
1421 instantVector.push_back( atoi(tmp) );
1422 fscanf(pFile,"%s",tmp); // 2
1423 instantVector.push_back( atoi(tmp) );
1424 fscanf(pFile,"%s",tmp); // 3
1425 instantVector.push_back( atoi(tmp) );
1426 fscanf(pFile,"%s",tmp); // 4
1427 instantVector.push_back( atoi(tmp) );
1428 fscanf(pFile,"%s",tmp); // 5
1429 instantVector.push_back( atoi(tmp) );
1430 fscanf(pFile,"%s",tmp); // 6
1431 instantVector.push_back( atoi(tmp) );
1433 fscanf(pFile,"%s",tmp); // TypeContourModel
1434 fscanf(pFile,"%s",tmp); // ##
1435 typeContourModel = atoi(tmp);
1437 manModelContour = kernelManager->factoryManualContourModel(typeContourModel);
1438 manModelContour->Open(pFile);
1439 if(pFileData != NULL)
1441 manModelContour->OpenData(pFileData);
1444 if (_tmpReadFileTypeOfTransformation==-1){
1446 } else if (_tmpReadFileTypeOfTransformation==0){
1447 double transX, transY;
1448 transX = (double) imageDim[0]/_tmpReadFileImageDim[0];
1449 transY = (double) imageDim[1]/_tmpReadFileImageDim[1];
1450 manModelContour->Transform_Ax_Plus_B(transX,0,transY,0);
1451 } else if (_tmpReadFileTypeOfTransformation==1) {
1452 double transX, transY;
1453 transX = (double) _tmpReadFileImageSpac[0]/imageDim[0];
1454 transY = (double) _tmpReadFileImageSpac[1]/imageDim[1];
1455 manModelContour->Transform_Ax_Plus_B(transX,0,transY,0);
1458 fscanf(pFile,"%s",tmp); // TypeView
1459 fscanf(pFile,"%s",tmp); // ##
1460 typeView = atoi(tmp);
1462 std::string theName;
1463 theName = kernelManager->createOutline( manModelContour, instantVector );
1464 bool addedModel = theName.compare("") != 0;
1467 double spc[3];//Si no hay imagen pero hay contornos que spacing se pone por default
1468 _theViewPanel->getSpacing(spc);
1469 //Adding the manualContourControler to interface objects structure
1470 //Adding the manualViewContour to interface objects structure
1471 //_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.
1472 _theViewPanel->getSceneManager()->configureViewControlTo( theName, manModelContour,spc , typeView) ;
1475 if (staticContour) //StaticContours (will appear in all slices)
1477 Instant instant(&instantVector);
1478 kernelManager->changeContourOfManager( theName , &instant );
1480 }// for numberOfContours
1486 void wxContourMainFrame::RefreshInterface(){
1488 _theViewPanel->RefreshInterface();
1489 //wxVtk2DBaseView *wxvtk2dbaseview = (wxVtk2DBaseView*)this->_theViewPanel->getWxVtkBaseView();
1490 //wxvtk2dbaseview->Refresh();
1493 vtkImageData* wxContourMainFrame::getImageData(){
1494 return _theViewPanel->getImageData();
1497 void wxContourMainFrame::onSegmentationOneSliceITK(wxString distance, wxString sigma, wxString alfa, wxString beta, wxString propagation, wxString iterations, wxString inflation)
1499 //JCP 20-10-08 Undo redo implementation
1501 //JCP 20-10-08 Undo redo implementation
1504 int x = _theViewPanel->GetX();
1505 int y = _theViewPanel->GetY();
1506 int z = _theViewPanel->GetZ();
1507 SegmentationOneSliceITK( x,y,z,distance, sigma, alfa, beta, propagation, iterations, inflation);
1511 void wxContourMainFrame::SegmentationOneSliceITK(int x, int y, int z, wxString distanc, wxString sigm, wxString alf, wxString bet, wxString prop, wxString iter, wxString inflation)
1513 int typeofcontour = 1;
1515 vtkImageData *imagedata = getImageData();
1517 //Tipo de pixeles a utilizar internamente en ITK
1518 typedef float InternalPixelType;
1519 const unsigned int Dimension = 2;
1520 typedef itk::Image< InternalPixelType, Dimension > InternalImageType;
1522 //Tipo de pixeles de salida 1
1523 typedef unsigned char OutputPixelType;
1524 typedef itk::Image< OutputPixelType, Dimension > OutputImageType;
1526 //Tipo de pixeles de salida 2
1527 typedef unsigned short OutputPixelType2;
1528 typedef itk::Image< OutputPixelType2, Dimension > OutputImageType2;
1530 //DefiniciÛn del thresholder
1531 typedef itk::BinaryThresholdImageFilter<
1533 OutputImageType > ThresholdingFilterType;
1535 //DefiniciÛn del primer filtro de conversiÛn de pixeles
1536 typedef itk::CastImageFilter<
1537 OutputImageType, OutputImageType2 > CastFilterType;
1539 //DefiniciÛn del segundo tipo de conversiÛn de pixeles
1540 typedef itk::CastImageFilter<
1541 OutputImageType2, InternalImageType > CastFilterType2;
1543 //Tercer tipo de conversiÛn
1544 typedef itk::RescaleIntensityImageFilter<
1546 OutputImageType > CastFilterType3;
1548 //Cuarto tipo de conversiÛn
1549 typedef itk::RescaleIntensityImageFilter<
1551 OutputImageType > CastFilterType4;
1553 ThresholdingFilterType::Pointer thresholder = ThresholdingFilterType::New();
1555 thresholder->SetLowerThreshold( 0.0 );
1556 thresholder->SetUpperThreshold( 128 );
1558 thresholder->SetOutsideValue( 255 );
1559 thresholder->SetInsideValue( 0 );
1561 //DefinciÛn de conexiÛnes entre VTK e ITK y el writer
1562 typedef itk::VTKImageToImageFilter<OutputImageType2> ConnectorType;
1563 typedef itk::ImageToVTKImageFilter<OutputImageType> ConnectorType2;
1564 //EED10JUIN2011 typedef itk::ImageFileWriter< OutputImageType > WriterType;
1566 ConnectorType::Pointer connector= ConnectorType::New();
1567 ConnectorType2::Pointer connector2= ConnectorType2::New();
1570 CastFilterType::Pointer filter=CastFilterType::New();
1571 CastFilterType2::Pointer filter2=CastFilterType2::New();
1573 connector->SetInput( imagedata );
1574 filter2->SetInput(connector->GetOutput());
1576 typedef itk::CurvatureAnisotropicDiffusionImageFilter<
1578 InternalImageType > SmoothingFilterType;
1580 SmoothingFilterType::Pointer smoothing = SmoothingFilterType::New();
1582 typedef itk::GradientMagnitudeRecursiveGaussianImageFilter<
1584 InternalImageType > GradientFilterType;
1586 typedef itk::SigmoidImageFilter<
1588 InternalImageType > SigmoidFilterType;
1590 GradientFilterType::Pointer gradientMagnitude = GradientFilterType::New();
1592 SigmoidFilterType::Pointer sigmoid = SigmoidFilterType::New();
1594 sigmoid->SetOutputMinimum( 0.0 );
1595 sigmoid->SetOutputMaximum( 255.0 );
1598 typedef itk::FastMarchingImageFilter<
1600 InternalImageType > FastMarchingFilterType;
1603 FastMarchingFilterType::Pointer fastMarching = FastMarchingFilterType::New();
1605 printf("EED wxContourMainFrame::SegmentationOneSliceITK Skypping this code. Not compiling GeodesicActiveContourLevelSetImageFilter in fedora 17 with ITK 3.20.1 \n ");
1607 > - > - > - > - > - > - > - > - > - > - > - > - > - > - > - > - Not compiling GeodesicActiveContourLevelSetImageFilter in fedora 17 with ITK 3.20.1
1610 typedef itk::GeodesicActiveContourLevelSetImageFilter< InternalImageType,
1611 InternalImageType > GeodesicActiveContourFilterType;
1612 GeodesicActiveContourFilterType::Pointer geodesicActiveContour =
1613 GeodesicActiveContourFilterType::New();
1615 typedef itk::ZeroCrossingImageFilter<
1617 InternalImageType > ZeroCrossingFilterType;
1618 ZeroCrossingFilterType::Pointer zeroCrossing =
1619 ZeroCrossingFilterType::New();
1621 const double propagationScaling = atof( crea::wx2std(prop).c_str() );
1623 geodesicActiveContour->SetPropagationScaling( propagationScaling );
1624 geodesicActiveContour->SetCurvatureScaling( 1.0 );
1625 geodesicActiveContour->SetAdvectionScaling( 1.0 );
1627 geodesicActiveContour->SetMaximumRMSError( 0.02 );
1628 int it=atoi( crea::wx2std(iter).c_str() );
1629 geodesicActiveContour->SetNumberOfIterations( it );
1631 smoothing->SetInput( filter2->GetOutput() );
1632 gradientMagnitude->SetInput( smoothing->GetOutput() );
1633 sigmoid->SetInput( gradientMagnitude->GetOutput() );
1634 fastMarching->SetInput( sigmoid->GetOutput() );
1635 geodesicActiveContour->SetInput( fastMarching->GetOutput() );
1636 geodesicActiveContour->SetFeatureImage( sigmoid->GetOutput() );
1638 zeroCrossing->SetInput( geodesicActiveContour->GetOutput() );
1639 //thresholder->SetInput( zeroCrossing->GetOutput() );
1640 thresholder->SetInput( geodesicActiveContour->GetOutput() );
1641 connector2->SetInput( thresholder->GetOutput() );
1643 < - < - < - < - < - < - < - < - < - < - < - < - < - < - < - < - < - < - < - < -
1649 smoothing->SetTimeStep( 0.125 );
1650 smoothing->SetNumberOfIterations( 5 );
1651 smoothing->SetConductanceParameter( 9.0 );
1654 const double sigma = atof( crea::wx2std(sigm).c_str() );
1655 gradientMagnitude->SetSigma( sigma );
1657 const double alpha = atof( crea::wx2std(alf).c_str() );
1658 const double beta = atof( crea::wx2std(bet).c_str() );
1660 sigmoid->SetAlpha( alpha );
1661 sigmoid->SetBeta( beta );
1663 typedef FastMarchingFilterType::NodeContainer NodeContainer;
1664 typedef FastMarchingFilterType::NodeType NodeType;
1666 NodeContainer::Pointer seeds = NodeContainer::New();
1668 InternalImageType::IndexType seedPosition;
1669 seedPosition[0] = x;
1670 seedPosition[1] = y;
1672 const double initialDistance = atof( crea::wx2std(distanc).c_str() );
1676 const double seedValue = - initialDistance;
1678 node.SetValue( seedValue );
1679 node.SetIndex( seedPosition );
1681 seeds->Initialize();
1682 seeds->InsertElement( 0, node );
1684 fastMarching->SetTrialPoints( seeds );
1686 fastMarching->SetSpeedConstant( 1.0 );
1688 fastMarching->SetOutputSize(
1689 connector->GetOutput()->GetBufferedRegion().GetSize() );
1691 fastMarching->SetStoppingValue( 800 );
1695 connector2->Update();
1696 vtkImageData *idata = connector2->GetOutput();
1698 vtkMarchingContourFilter* cntVTK = vtkMarchingContourFilter::New( );
1700 cntVTK->SetNumberOfContours( 1 );
1701 cntVTK->SetValue( 0, 255 );
1702 //EED 2017-01-01 Migration VTK7
1703 #if VTK_MAJOR_VERSION <= 5
1704 cntVTK->SetInput( idata );
1706 cntVTK->UpdateInformation();
1708 cntVTK->SetInputData( idata );
1711 vtkCleanPolyData* cpd = vtkCleanPolyData::New( );
1713 //EED 2017-01-01 Migration VTK7
1714 #if VTK_MAJOR_VERSION <= 5
1715 cpd->SetInput( cntVTK->GetOutput( ) );
1717 cpd->UpdateInformation();
1719 cpd->SetInputData( cntVTK->GetOutput( ) );
1723 vtkPolyDataConnectivityFilter* conn = vtkPolyDataConnectivityFilter::New( );
1724 conn->SetExtractionModeToLargestRegion( );
1725 //EED 2017-01-01 Migration VTK7
1726 #if VTK_MAJOR_VERSION <= 5
1727 conn->SetInput( cpd->GetOutput( ) );
1729 conn->UpdateInformation();
1731 conn->SetInputData( cpd->GetOutput( ) );
1735 vtkStripper* vtkstripper = vtkStripper::New( );
1737 //EED 2017-01-01 Migration VTK7
1738 #if VTK_MAJOR_VERSION <= 5
1739 vtkstripper->SetInput( conn->GetOutput() );
1740 vtkstripper->Update();
1741 vtkstripper->UpdateInformation();
1743 vtkstripper->SetInputData( conn->GetOutput() );
1747 vtkPolyData* polyDataResult = cntVTK->GetOutput();
1748 //std::cout<<"Points "<<polyDataResult->GetNumberOfPoints()<<std::endl;
1750 //EED 2017-01-01 Migration VTK7
1751 #if VTK_MAJOR_VERSION <= 5
1752 polyDataResult->Update( );
1753 polyDataResult->UpdateInformation();
1761 myfile.open ("C:/Creatis/example.txt");
1763 polyDataResult->Print(myfile);
1764 myfile << "-------------------------------------\n";
1765 polyDataResult->GetLines()->Print(myfile);
1773 //--Calculating control points
1775 std::vector<double> vecX;
1776 std::vector<double> vecY;
1777 std::vector<double> vecXo;
1778 std::vector<double> vecYo;
1779 std::vector<double>::iterator vecXoi;
1780 std::vector<double>::iterator vecYoi;
1781 std::vector<double> vecZ;
1783 std::vector<double> vecCtrlPointX;
1784 std::vector<double> vecCtrlPointY;
1785 std::vector<double> vecCtrlPointZ;
1791 int ii,size=polyDataResult->GetNumberOfPoints();
1793 myfile.open ("C:/Creatis/example2.txt");
1795 size=polyDataResult->GetNumberOfPoints();
1796 for (ii=0;ii<size;ii++)
1803 p = polyDataResult->GetPoint(ii);
1806 /*if(fabs(yAct-y)>20)
1808 if((xAct-x)>1 || (xAct-x)<-1)
1810 vecX.push_back( p[0] );
1811 vecY.push_back( p[1] );
1812 myfile <<p[0]<<","<<p[1]<<"\n";
1813 std::cout<<" x Anterior "<<xAct<<" x actual "<<x<<std::endl;
1814 std::cout<<" y Anterior "<<yAct<<" y actual "<<y<<std::endl;
1815 std::cout<<" x "<<p[0]<<" y "<<p[1]<<std::endl;
1816 vecZ.push_back( 900 );
1822 vecXo.push_back(p[0]);
1823 vecYo.push_back(p[1]);
1827 else*/ if(fabs(xAct-x)>11)
1829 vecXo.push_back(p[0]);
1830 vecYo.push_back(p[1]);
1834 vecX.push_back( p[0] );
1835 myfile <<p[0]<<","<<p[1]<<"\n";
1836 //std::cout<<" x Anterior "<<xAct<<" x actual "<<x<<std::endl;
1837 //std::cout<<" y Anterior "<<yAct<<" y actual "<<y<<std::endl;
1838 //std::cout<<" x "<<p[0]<<" y "<<p[1]<<std::endl;
1839 vecY.push_back( p[1] );
1840 vecZ.push_back( 900 );
1848 while(!vecXo.empty())
1850 vecX.push_back(vecXo.back());
1851 //std::cout<<" x Siguiente "<<vecXo.back();
1853 vecZ.push_back( 900 );
1855 while(!vecYo.empty())
1857 vecY.push_back(vecYo.back());
1862 /*for(int l=0;l<vecX.size();l++)
1866 vecXo.push_back(p[0]);
1867 vecYo.push_back(p[1]);
1878 ExtractControlPoints2D *extractcontrolpoints2d = new ExtractControlPoints2D();
1880 extractcontrolpoints2d->SetContour( &vecX , &vecY , &vecZ );
1884 extractcontrolpoints2d->GetInitialControlPoints( &vecCtrlPointX , &vecCtrlPointY , &vecCtrlPointZ );
1886 else if (method==1){
1887 extractcontrolpoints2d->GetControlPoints( &vecCtrlPointX , &vecCtrlPointY , &vecCtrlPointZ );
1889 else if (method==2){
1890 extractcontrolpoints2d->SetSamplingControlPoints( 15 );
1891 extractcontrolpoints2d->GetSamplingControlPoints( &vecCtrlPointX , &vecCtrlPointY , &vecCtrlPointZ );
1893 //--Adding contour to the system
1895 std::vector<int> actualInstantVector;
1896 _instantPanel->getInstant( actualInstantVector );
1897 actualInstantVector[1]=z;
1899 int j,sizeCtrPt = vecCtrlPointX.size();
1901 manualBaseModel *manModelContour = kernelManager->factoryManualContourModel( typeofcontour );
1902 manModelContour->SetNumberOfPointsSpline( ((sizeCtrPt/100)+1)*100 );
1904 for (j=0 ; j<sizeCtrPt ; j++)
1906 manModelContour->AddPoint( vecCtrlPointX[j] , vecCtrlPointY[j] , vecCtrlPointZ[j] );
1908 std::string theName;
1909 //theName = _modelManager->createOutline( manModelContour, actualInstantVector );
1910 theName = kernelManager->createOutline( manModelContour, actualInstantVector );
1911 bool addedModel = theName.compare("") != 0;
1914 double spc[3];//Si no hay imagen pero hay contornos que spacing se pone por default
1915 _theViewPanel->getSpacing(spc);
1916 //Adding the manualContourControler to interface objects structure
1917 //Adding the manualViewContour to interface objects structure
1918 //_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.
1919 _theViewPanel->configureViewControlTo(theName, manModelContour, spc, typeofcontour);
1920 //_theViewPanel->getSceneManager()->configureViewControlTo( theName, manModelContour,spc, typeofcontour ) ;
1927 WriterType::Pointer writer = WriterType::New();
1928 CastFilterType3::Pointer caster = CastFilterType3::New();
1930 caster->SetInput( gradientMagnitude->GetOutput() );
1931 writer->SetInput( caster->GetOutput() );
1932 writer->SetFileName("Gradient Magnitude.png");
1933 caster->SetOutputMinimum( 0 );
1934 caster->SetOutputMaximum( 255 );
1937 CastFilterType3::Pointer caster2 = CastFilterType3::New();
1938 WriterType::Pointer writer2 = WriterType::New();
1940 caster2->SetInput( sigmoid->GetOutput() );
1941 writer2->SetInput( caster2->GetOutput() );
1942 writer2->SetFileName("Sigmoid.png");
1943 caster2->SetOutputMinimum( 0 );
1944 caster2->SetOutputMaximum( 255 );
1947 CastFilterType3::Pointer caster3 = CastFilterType3::New();
1948 WriterType::Pointer writer3 = WriterType::New();
1950 caster3->SetInput( fastMarching->GetOutput() );
1951 writer3->SetInput( caster3->GetOutput() );
1952 writer3->SetFileName("FastMarching.bmp");
1953 caster3->SetOutputMinimum( 0 );
1954 caster3->SetOutputMaximum( 255 );
1957 CastFilterType3::Pointer caster4 = CastFilterType3::New();
1958 WriterType::Pointer writer4 = WriterType::New();
1960 caster4->SetInput( geodesicActiveContour->GetOutput() );
1961 writer4->SetInput( caster4->GetOutput() );
1962 writer4->SetFileName("GeodesicActiveContour.png");
1963 caster4->SetOutputMinimum( 0 );
1964 caster4->SetOutputMaximum( 255 );
1967 CastFilterType3::Pointer caster5 = CastFilterType3::New();
1968 WriterType::Pointer writer5 = WriterType::New();
1970 caster5->SetInput( zeroCrossing->GetOutput() );
1971 writer5->SetInput( caster5->GetOutput() );
1972 writer5->SetFileName("ZeroCrossing.bmp");
1973 caster5->SetOutputMinimum( 0 );
1974 caster5->SetOutputMaximum( 255 );
1978 catch( itk::ExceptionObject & excep )
1980 std::cerr << "Exception caught !" << std::endl;
1981 std::cerr << excep << std::endl;
1985 void wxContourMainFrame::onSegmentationOneSlice(int isovalue,int sampling,int method){
1987 //JCP 20-10-08 Undo redo implementation
1989 //JCP 20-10-08 Undo redo implementation
1992 int x = _theViewPanel->GetX();
1993 int y = _theViewPanel->GetY();
1994 int z = _theViewPanel->GetZ();
1995 SegmentationOneSlice( x,y,z,isovalue, sampling, method );
2000 void wxContourMainFrame::SegmentationOneSlice( int x, int y, int z, int isovalue, int sampling, int method )
2002 int typeofcontour = 1;
2003 //--Extracting Contour
2004 //vtkImageData *imagedata = _theViewPanel->getSceneManager()->GetImageData();
2005 vtkImageData *imagedata = getImageData();
2006 // double *range = imagedata->GetScalarRange();
2009 vtkImageReslice *imageReslice = vtkImageReslice::New();
2012 // imagedata->GetSpacing(spc);
2017 //EED 2017-01-01 Migration VTK7
2018 #if VTK_MAJOR_VERSION <= 5
2019 imageReslice->SetInput( imagedata );
2021 imageReslice->SetInputData( imagedata );
2023 imageReslice->SetInformationInput(imagedata);
2024 imageReslice->SetResliceAxesDirectionCosines(1,0,0, 0,1,0 ,0,0,1);
2025 imageReslice->SetResliceAxesOrigin(0,0,z);
2026 imageReslice->SetOutputDimensionality(2);
2027 imageReslice->SetInterpolationModeToLinear();
2029 //EED 2017-01-01 Migration VTK7
2030 #if VTK_MAJOR_VERSION <= 5
2033 imageReslice->Update();
2036 imagedata = imageReslice->GetOutput();
2037 //EED 2017-01-01 Migration VTK7
2038 #if VTK_MAJOR_VERSION <= 5
2039 imagedata->Update();
2040 imagedata->UpdateInformation();
2045 vtkContourFilter* cntVTK = vtkContourFilter::New( );
2046 //EED 2017-01-01 Migration VTK7
2047 #if VTK_MAJOR_VERSION <= 5
2048 cntVTK->SetInput( imagedata );
2050 cntVTK->SetInputData( imagedata );
2053 cntVTK->SetNumberOfContours( 1 );
2054 //cntVTK->SetValue( 0, vmin );
2055 // cntVTK->SetValue( 0, (range[1]*thr/100) );
2056 cntVTK->SetValue( 1, isovalue );
2057 // cntVTK->SetValue( 1, vmax );
2059 cntVTK->UpdateInformation();
2061 vtkCleanPolyData* cpd = vtkCleanPolyData::New( );
2062 //EED 2017-01-01 Migration VTK7
2063 #if VTK_MAJOR_VERSION <= 5
2064 cpd->SetInput( cntVTK->GetOutput( ) );
2066 cpd->SetInputData( cntVTK->GetOutput( ) );
2068 cpd->ConvertLinesToPointsOff( );
2070 cpd->UpdateInformation();
2072 vtkPolyDataConnectivityFilter* conn = vtkPolyDataConnectivityFilter::New( );
2073 conn->SetExtractionModeToClosestPointRegion( );
2074 //conn->SetMaxRecursionDepth( 3000 );
2076 //EED 2017-01-01 Migration VTK7
2077 #if VTK_MAJOR_VERSION <= 5
2078 conn->SetInput( cpd->GetOutput( ) );
2080 conn->SetInputData( cpd->GetOutput( ) );
2083 conn->SetClosestPoint( x, y, 0 );
2085 conn->UpdateInformation();
2087 vtkCleanPolyData* cpd2 = vtkCleanPolyData::New( );
2088 //EED 2017-01-01 Migration VTK7
2089 #if VTK_MAJOR_VERSION <= 5
2090 cpd2->SetInput( conn->GetOutput( ) );
2092 cpd2->SetInputData( conn->GetOutput( ) );
2095 cpd2->UpdateInformation();
2097 vtkStripper* vtkstripper = vtkStripper::New( );
2098 //EED 2017-01-01 Migration VTK7
2099 #if VTK_MAJOR_VERSION <= 5
2100 vtkstripper->SetInput( cpd2->GetOutput() );
2102 vtkstripper->SetInputData( cpd2->GetOutput() );
2104 vtkstripper->Update();
2105 vtkstripper->UpdateInformation();
2108 vtkPolyData* polyDataResult = vtkstripper->GetOutput();
2110 //EED 2017-01-01 Migration VTK7
2111 #if VTK_MAJOR_VERSION <= 5
2112 polyDataResult->Update( );
2113 polyDataResult->UpdateInformation();
2120 myfile.open ("c:/temp/example.txt");
2122 polyDataResult->Print(myfile);
2123 myfile << "-------------------------------------\n";
2124 polyDataResult->GetLines()->Print(myfile);
2134 //--Calculating control points
2136 std::vector<double> vecX;
2137 std::vector<double> vecY;
2138 std::vector<double> vecZ;
2140 std::vector<double> vecCtrlPointX;
2141 std::vector<double> vecCtrlPointY;
2142 std::vector<double> vecCtrlPointZ;
2146 int ii,size=polyDataResult->GetNumberOfPoints();
2148 for (ii=1;ii<=size;ii++)
2150 id = polyDataResult->GetLines()->GetData()->GetValue(ii);
2151 p = polyDataResult->GetPoint(id);
2154 vecX.push_back( p[0] );
2155 vecY.push_back( p[1] );
2156 vecZ.push_back( 900 );
2157 // vecZ.push_back( p[2] );
2161 ExtractControlPoints2D *extractcontrolpoints2d = new ExtractControlPoints2D();
2162 extractcontrolpoints2d->SetContour( &vecX , &vecY , &vecZ );
2165 /*if (methodRadiobox->GetSelection()==0){
2166 extractcontrolpoints2d->GetInitialControlPoints( &vecCtrlPointX , &vecCtrlPointY , &vecCtrlPointZ );
2168 if (methodRadiobox->GetSelection()==1){
2169 extractcontrolpoints2d->GetControlPoints( &vecCtrlPointX , &vecCtrlPointY , &vecCtrlPointZ );
2171 if (methodRadiobox->GetSelection()==2){
2172 extractcontrolpoints2d->SetSamplingControlPoints( sampling );
2173 extractcontrolpoints2d->GetSamplingControlPoints( &vecCtrlPointX , &vecCtrlPointY , &vecCtrlPointZ );
2177 extractcontrolpoints2d->GetInitialControlPoints( &vecCtrlPointX , &vecCtrlPointY , &vecCtrlPointZ );
2179 else if (method==1){
2180 extractcontrolpoints2d->GetControlPoints( &vecCtrlPointX , &vecCtrlPointY , &vecCtrlPointZ );
2182 else if (method==2){
2183 extractcontrolpoints2d->SetSamplingControlPoints( sampling );
2184 extractcontrolpoints2d->GetSamplingControlPoints( &vecCtrlPointX , &vecCtrlPointY , &vecCtrlPointZ );
2187 //--Adding contour to the system
2189 std::vector<int> actualInstantVector;
2190 _instantPanel->getInstant( actualInstantVector );
2191 actualInstantVector[1]=z;
2193 int j,sizeCtrPt = vecCtrlPointX.size();
2194 manualBaseModel *manModelContour = kernelManager->factoryManualContourModel( typeofcontour );
2195 manModelContour->SetNumberOfPointsSpline( ((sizeCtrPt/100)+1)*100 );
2197 for (j=0 ; j<sizeCtrPt ; j++)
2199 manModelContour->AddPoint( vecCtrlPointX[j] , vecCtrlPointY[j] , vecCtrlPointZ[j] );
2201 std::string theName;
2202 //theName = _modelManager->createOutline( manModelContour, actualInstantVector );
2203 theName = kernelManager->createOutline( manModelContour, actualInstantVector );
2204 bool addedModel = theName.compare("") != 0;
2207 double spc[3];//Si no hay imagen pero hay contornos que spacing se pone por default
2208 _theViewPanel->getSpacing(spc);
2209 //Adding the manualContourControler to interface objects structure
2210 //Adding the manualViewContour to interface objects structure
2211 //_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.
2212 _theViewPanel->configureViewControlTo(theName, manModelContour, spc, typeofcontour);
2213 //_theViewPanel->getSceneManager()->configureViewControlTo( theName, manModelContour,spc, typeofcontour ) ;
2217 int wxContourMainFrame::GetImageDataSizeZ(){
2218 return _theViewPanel->GetImageDataSizeZ();
2221 void wxContourMainFrame::GetImageDataRange(double *range){
2222 _theViewPanel->GetImageDataRange(range);
2225 void wxContourMainFrame::onSegmentationAllSlice(int minZ,int maxZ,int isovalue,int sampling,int method){
2226 //JCP 20-10-08 Undo redo implementation
2228 //JCP 20-10-08 Undo redo implementation
2231 int x = _theViewPanel->GetX();
2232 int y = _theViewPanel->GetY();
2236 double totalZ = maxZ-minZ+1;
2237 for( z=minZ ; z<=maxZ ; z++ )
2239 porcent = 100.0* (z-minZ)/totalZ;
2240 tmpString.Printf(_T(" %d %c %d/%d %d"), (int)porcent , 37 , z-minZ+1, (int)totalZ,z );
2241 interfMainPanel::getInstance()->setLabelSegmentationPanelVTK(tmpString);
2242 //_staticTextSegmentation->SetLabel(tmpString);
2243 SegmentationOneSlice( x,y,z,isovalue, sampling,method );
2245 interfMainPanel::getInstance()->setLabelSegmentationPanelVTK(_T(" "));
2250 //Creates a reference line to be used as the axis of the mirroring
2251 void wxContourMainFrame::referenceLine()
2253 if (_refLineControl==NULL)
2258 vtkImageData *vtkimagedata = _theViewPanel->getImageData();
2259 vtkimagedata->GetSpacing(spc);
2261 wxVtkBaseView * viewer2D = _theViewPanel->getWxVtkBaseView();
2263 _refLineControl = new manualLineControler();
2264 _refLineModel = new manualContourModelLine();
2265 _refLineView = new manualViewLine();
2266 _refLineView->SetModel( _refLineModel );
2267 _refLineView->SetWxVtkBaseView( viewer2D );
2268 _refLineView->SetRange( 2 );
2269 _refLineView->SetZ( 1200 );
2271 _refLineView->SetSpacing(spc);
2273 _refLineView->SetColorNormalContour(0, 0, 1);
2274 _refLineView->SetColorEditContour(0, 0.5, 0.5);
2275 _refLineView->SetWidthLine(4);
2277 _refLineControl->SetModelView( _refLineModel , _refLineView );
2278 vtkInteractorStyleBaseView* style = (vtkInteractorStyleBaseView*)viewer2D->GetInteractorStyleBaseView();
2279 style->AddInteractorStyleMaracas( _refLineControl );
2280 _refLineModel->SetCloseContour(false);
2281 _refLineControl->CreateNewManualContour();
2283 //AD: Inicializar el mirroring con una linea ya pintada
2285 double z = _refLineControl->GetZ();
2288 image->GetDimensions(imageDim);
2289 double x = (double) imageDim[0]/2;
2290 double y1 = (double) (imageDim[1]/2)+15;
2291 double y2 = (double) (imageDim[1]/2)-15;
2293 _refLineControl->AddPoint(x,y1,z);
2294 _refLineControl->AddPoint(x,y2,z);
2295 _refLineControl->SetCompleteCreation(true);
2297 _refLineModel->AddPoint(x,y1,z);
2298 _refLineModel->AddPoint(x,y2,z);
2299 _refLineModel->UpdateSpline();
2301 _refLineView->UpdateViewPoint(0);
2302 _refLineView->UpdateViewPoint(1);
2305 _refLineControl->SetActive(true);
2306 _refLineView->RefreshContour();
2310 //Hides the referenceLine
2311 void wxContourMainFrame::refLineHide()
2313 if (_refLineControl!=NULL)
2315 if (_refLineControl->GetActive())
2317 _refLineView->RemoveCompleteContourActor();
2318 _refLineControl->SetEditable(false);
2319 _refLineControl->SetActive(false);
2326 //Shows the referenceLine
2327 void wxContourMainFrame::refLineShow()
2329 if (_refLineControl!=NULL)
2331 if (_refLineControl->GetActive()==false)
2333 wxVtkBaseView * viewer2D = _theViewPanel->getWxVtkBaseView();
2335 _refLineView->SetModel( _refLineModel );
2336 _refLineView->SetWxVtkBaseView( viewer2D );
2337 _refLineView->SetRange( 2 );
2338 _refLineView->SetZ( 1200 );
2340 _refLineControl->SetModelView( _refLineModel , _refLineView );
2341 vtkInteractorStyleBaseView* style = (vtkInteractorStyleBaseView*)viewer2D->GetInteractorStyleBaseView();
2342 style->AddInteractorStyleMaracas( _refLineControl );
2343 _refLineControl->CreateNewManualContour();
2344 _refLineControl->SetActive(true);
2345 _refLineView->RefreshContour();
2352 void wxContourMainFrame::refLineChangeWidth(int width)
2354 _refLineView->SetWidthLine(width);
2355 _refLineView->RefreshContour();
2361 void wxContourMainFrame::onMirror()
2364 std::vector<std::string> currentSelection = _theViewPanel->getSelectedObjects();
2365 std::vector<std::string> filterCurrentSelection;
2367 std::vector<int> tempVector;
2368 _instantPanel->getInstant( tempVector );
2369 _performingOperation->reset();
2370 _performingOperation->setStartCommand( COPY );
2371 _performingOperation->setStartOperationInstantVector( tempVector );
2372 _performingOperation->setKeyNamesOperationElems( currentSelection );
2374 char theStartCommand = _performingOperation->getStartCommand();
2375 if ( theStartCommand == COPY )
2377 //JCP 20-10-08 Undo redo implementation
2379 //JCP 20-10-08 Undo redo implementation
2380 std::vector<int> tempVector;
2381 _instantPanel->getInstant( tempVector );
2382 _performingOperation->setEndOperationInstantVector ( tempVector );
2383 std::vector<std::string> elems = _performingOperation->getKeyNamesOperationElems();
2384 int i,size = elems.size();
2385 for( i=0; i<size; i++ )
2387 createMirrorContourOf( elems[i], tempVector, i>0 );
2391 //deleteContour( _refName );
2396 void wxContourMainFrame::showAxis(bool show)
2398 _theViewPanel->SetVisibleAxis(show);
2399 _theViewPanel->Refresh();
2403 void wxContourMainFrame::onRigidPressed(){
2404 std::vector<std::string> currentSelection = _theViewPanel->getSelectedObjects();
2405 int elementsSelected = currentSelection.size();
2407 if ( elementsSelected >= 1 ){
2408 //JCP 20-10-08 Undo redo implementation
2410 //JCP 20-10-08 Undo redo implementation
2412 std::vector<int> tempVector;
2413 _instantPanel->getInstant( tempVector );
2414 Instant instant(&tempVector);
2416 int i , size=currentSelection.size();
2417 for ( i=0 ; i<size ; i++ )
2419 kernelManager->changeContourOfManager(currentSelection[i], &instant);
2424 void wxContourMainFrame::onWidthOfContour(double width){
2426 _theViewPanel->removeSceneContours();
2427 _theViewPanel->SetWidthContour(width);
2429 //_theViewPanel->getSceneManager()->SetWidthContour( width );
2434 int wxContourMainFrame::getColorWindow()
2438 vtkImageData * img = getImageData();
2439 img->GetScalarRange(range);
2441 std::cout<<"Val 1: "<<range[0]<<" Val 2: "<<range[1]<<std::endl;
2443 return (int)range[1];
2445 return _theViewPanel->getColorWindow();
2448 int wxContourMainFrame::getWindowLevel()
2452 vtkImageData * img = getImageData();
2453 img->GetScalarRange(range);
2455 std::cout<<"Val 1: "<<range[0]<<" Val 2: "<<range[1]<<std::endl;
2457 return (int)range[1];
2459 return _theViewPanel->getWindowLevel();
2462 void wxContourMainFrame::onBrigthnessColorWindowLevel(int colorwindow,int windowlevel){
2463 _theViewPanel->onBrigthnessColorWindowLevel(colorwindow, windowlevel);
2468 void wxContourMainFrame::onInterpolation(bool interpolate){
2469 _theViewPanel->onInterpolation(interpolate);
2473 void wxContourMainFrame::onChangeInstant(std::string name,int actual){
2474 _instantPanel->setConceptValue( name, actual );
2478 void wxContourMainFrame::resetAppend(){
2479 kernelManager->resetAppend();
2484 void wxContourMainFrame::onSpreadAdd(){
2485 std::vector<double> vecX;
2486 std::vector<double> vecY;
2487 std::vector<double> vecZ;
2488 _theViewPanel->GetPointsOfActualContour(&vecX , &vecY , &vecZ );
2489 std::vector<int> tempVector;
2490 _instantPanel->getInstant( tempVector );
2491 std::string val = kernelManager->onSpreadAdd(&vecX , &vecY , &vecZ, tempVector);
2492 interfMainPanel::getInstance()->appendStringSpread(val);
2496 void wxContourMainFrame::onSpreadAddAll(){
2498 std::vector<int> tempVector;
2499 _instantPanel->getInstant( tempVector );
2502 maxZ = interfMainPanel::getInstance()->GetImageDataSizeZ();
2504 int sizeLstContourThings;
2505 for ( z=minZ ; z<=maxZ ; z++ )
2508 Instant instant(&tempVector);
2509 std::vector<ContourThing**> lstContourThings = kernelManager->getOutlinesAtInstant( &instant );
2510 sizeLstContourThings = lstContourThings.size();
2511 if (sizeLstContourThings>=1)
2513 std::vector<double> vecX;
2514 std::vector<double> vecY;
2515 std::vector<double> vecZ;
2516 ContourThing **contourthing = lstContourThings[0];
2517 manualBaseModel *cModel = (*contourthing)->getModel();
2518 int i,size = cModel->GetNumberOfPointsSpline();
2520 for (i=0; i<size; i++)
2522 cModel->GetSpline_i_Point(i, &x, &y, &z);
2527 std::string val = kernelManager->onSpreadAdd(&vecX , &vecY , &vecZ, tempVector);
2528 interfMainPanel::getInstance()->appendStringSpread(val);
2529 }// if sizeLstContourThings
2534 void wxContourMainFrame::onSpreadGo(int type){
2535 //JCP 20-10-08 Undo redo implementation
2537 //JCP 20-10-08 Undo redo implementation
2539 std::vector<double> vecCtrlPointX;
2540 std::vector<double> vecCtrlPointY;
2541 std::vector<double> vecCtrlPointZ;
2545 std::vector<int> tempVector;
2546 _instantPanel->getInstant( tempVector );
2549 kernelManager->getMaxMinZ(&minZ,&maxZ);
2550 //JSTG_16-07-08_----------------------------------------------------------------
2551 //_contourPropagation->setInterpolationNumber(maxZ-minZ+1);
2552 kernelManager->CalculeSplinePropagation();
2554 double totalZ = maxZ-minZ+1;
2557 //--------------------------------------------------------------------
2558 for ( z=(int)minZ ; z<=(int)maxZ ; z++ )
2560 porcent = 100.0* (z-minZ)/totalZ;
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 int typeofcontour = 1;
2567 std::string theName;
2568 manualBaseModel* manModelContour = kernelManager->GetPoints(z, type, &vecCtrlPointX,&vecCtrlPointY,&vecCtrlPointZ, theName,typeofcontour, tempVector);
2570 if( manModelContour!=NULL ){
2571 double spc[3];//Si no hay imagen pero hay contornos que spacing se pone por default
2572 this->_theViewPanel->getSpacing(spc);
2573 //Adding the manualContourControler to interface objects structure
2574 //Adding the manualViewContour to interface objects structure
2575 //_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.
2576 _theViewPanel->configureViewControlTo( theName, manModelContour,spc,typeofcontour ) ;
2581 int numero = (int)(z-minZ+1)/(int)totalZ;
2582 std::string stringtemp = " "+kernelManager->intToString(porcent)+"% "+kernelManager->intToString(numero)+" "+kernelManager->intToString(z);
2584 interfMainPanel::getInstance()->setStringSpread(stringtemp);
2586 //RefreshInterface();
2589 void wxContourMainFrame::getInstantVector(std::vector<int>& tempVector){
2593 std::vector<std::string> wxContourMainFrame::getOutlinesName(int slide){
2594 std::vector<int> tempVector;
2595 _instantPanel->getInstant(tempVector);
2596 //Asignation of slide number should be different ex by name
2597 tempVector[1]=slide;
2598 return kernelManager->getOutlinesNameAtInstant(tempVector);
2602 void wxContourMainFrame::SetScalarRange(int grayRangeMin, int grayRangeMax)
2604 _contourextractdata->SetScalarRange(grayRangeMin,grayRangeMax);
2608 void wxContourMainFrame::onInformationContourLabels(int typeContourGroup,int selection,int minimumZ,int maximumZ,int grayRangeMin, int grayRangeMax)
2611 wxString tempString;
2612 int maxContourGroup = 0;
2614 _contourextractdata ->SetTypeOperation( typeContourGroup % 3 );
2616 std::vector<manualBaseModel*> lstManConMod;
2617 std::vector<manualBaseModel*> lstManConModTmp;
2618 std::vector<manualBaseModel*> lstManConModExp;
2619 std::vector<double> pLstValue;
2620 std::vector<double> pLstValuePosX;
2621 std::vector<double> pLstValuePosY;
2622 std::vector<double> pLstValuePosZ;
2625 int resultGrayRangeCount;
2628 double resultAverage;
2629 double resultStandardeviation;
2631 std::vector<int> tempVector;
2632 _instantPanel->getInstant( tempVector );
2635 int ii,sizeLstContourThings;
2644 if (selection==0 ) // actual slice
2646 int actualSlice = tempVector[1];
2649 } else { // slice range
2655 totalZ = maxZ-minZ+1;
2657 _contourextractdata->InitVolumeStatistics();
2660 for ( z=minZ ; z<=maxZ ; z++ )
2663 porcent = 100.0* (z-minZ)/totalZ;
2664 tmpString.Printf(_T(" %d %c %d/%d %d"), (int)porcent , 37 , z-minZ+1, (int)totalZ ,z);
2666 interfMainPanel::getInstance()->setStringInfoPanel(tmpString);
2667 //_staticTextInformation->SetLabel(tmpString);
2669 //Extraction data from contours of each slice
2670 _contourextractdata->SetZtoBeAnalys(z);
2673 Instant instant(&tempVector);
2674 std::vector<ContourThing**> lstContourThings = kernelManager->getOutlinesAtInstant( &instant );
2675 sizeLstContourThings = lstContourThings.size();
2677 lstManConMod.clear();
2678 for (ii=0 ; ii<sizeLstContourThings ; ii++)
2680 ContourThing **contourthing = lstContourThings[ii];
2681 lstManConMod.push_back( (*contourthing)->getModel() );
2684 lstManConModExp = kernelManager->ExploseEachModel( lstManConMod );
2686 tempString.Printf(_T("%d - %d"),z, sizeLstContourThings);
2687 interfMainPanel::getInstance()->setRowLabelInfoPanel(z, tempString);
2688 //_grid->SetRowLabelValue(z, tempString );
2690 int iContourGroup,sizeContourGroup;
2691 if (typeContourGroup==3) // contour separete
2693 sizeContourGroup=lstManConModExp.size();
2694 if ( maxContourGroup<sizeContourGroup )
2696 maxContourGroup=sizeContourGroup;
2698 } else { // contour AND OR XOR
2705 for( iContourGroup=0 ; iContourGroup<sizeContourGroup ; iContourGroup++ ){
2706 lstManConModTmp.clear();
2710 if (typeContourGroup==3) // contour separete
2712 lstManConModTmp.push_back( lstManConModExp[iContourGroup]);
2713 } else { // contour AND OR XOR
2714 lstManConModTmp = lstManConModExp;
2717 _contourextractdata->SetLstManualContourModel( lstManConModTmp );
2718 _contourextractdata->SetScalarRange(grayRangeMin,grayRangeMax);
2721 pLstValuePosX.clear();
2722 pLstValuePosY.clear();
2723 pLstValuePosZ.clear();
2727 _contourextractdata->GetValuesInsideCrown( &numberOfPixels,
2733 resultSize=numberOfPixels;
2734 // Statistics of each slice.
2735 _contourextractdata->Statistics( &pLstValue,
2738 &resultGrayRangeCount,
2743 &resultStandardeviation);
2745 if (interfMainPanel::getInstance()->getNumberColsInformationPanel()<_numberOfVariablesStatistics*(iContourGroup+1) )
2747 interfMainPanel::getInstance()->appendColsInformationPanel(_numberOfVariablesStatistics);
2750 tmpIntA=_numberOfVariablesStatistics*iContourGroup ;
2752 tempString.Printf(_T("%d"),numberOfPixels);
2754 interfMainPanel::getInstance()->setCellValueInfoPanel(z, tmpIntA, tempString);
2756 tempString.Printf(_T("%d"),resultGrayRangeCount);
2757 interfMainPanel::getInstance()->setCellValueInfoPanel(z, tmpIntA+1, tempString);
2759 tempString.Printf(_T("%f"),resultMin);
2760 interfMainPanel::getInstance()->setCellValueInfoPanel(z, tmpIntA+2, tempString);
2762 tempString.Printf(_T("%f"),resultMax);
2763 interfMainPanel::getInstance()->setCellValueInfoPanel(z, tmpIntA+3, tempString);
2765 tempString.Printf(_T("%f"),resultAverage);
2766 interfMainPanel::getInstance()->setCellValueInfoPanel(z, tmpIntA+4, tempString);
2768 tempString.Printf(_T("%f"),resultStandardeviation);
2769 interfMainPanel::getInstance()->setCellValueInfoPanel(z, tmpIntA+5, tempString);
2772 } // for iContourGroup
2775 // Print Volume Statistics
2778 int vol_rCountRange;
2780 double vol_minValue;
2781 double vol_maxValue;
2783 double vol_standardeviation;
2785 if (selection!=0 ) // actual slice
2788 _contourextractdata->GetVolumeStatistics(&vol_rCountRange, &vol_rsize,
2789 &vol_minValue, &vol_maxValue,
2790 &vol_average, &vol_standardeviation);
2792 interfMainPanel::getInstance()->setRowLabelInfoPanel(maxZ+2, _T("Total:"));
2794 tempString.Printf(_T("%d"),vol_rsize);
2795 interfMainPanel::getInstance()->setCellValueInfoPanel(maxZ+2, 0, tempString);
2797 tempString.Printf(_T("%d"),vol_rCountRange);
2798 interfMainPanel::getInstance()->setCellValueInfoPanel(maxZ+2, 1, tempString);
2800 tempString.Printf(_T("%f"),vol_minValue);
2801 interfMainPanel::getInstance()->setCellValueInfoPanel(maxZ+2, 2, tempString);
2803 tempString.Printf(_T("%f"),vol_maxValue);
2804 interfMainPanel::getInstance()->setCellValueInfoPanel(maxZ+2, 3, tempString);
2806 tempString.Printf(_T("%f"),vol_average);
2807 interfMainPanel::getInstance()->setCellValueInfoPanel(maxZ+2, 4, tempString);
2809 tempString.Printf(_T("%f"),vol_standardeviation);
2810 interfMainPanel::getInstance()->setCellValueInfoPanel(maxZ+2, 5, tempString);
2812 //-----------------------------------------
2815 wxString tmpTitleString;
2817 for ( iTitleGroup=0 ; iTitleGroup<maxContourGroup ; iTitleGroup++ )
2819 tmpIntB =_numberOfVariablesStatistics*iTitleGroup;
2820 tmpTitleString.Printf(_T("%d-Size Data"),iTitleGroup);
2821 interfMainPanel::getInstance()->setColLableInfoPanel(tmpIntB + 0, tmpTitleString);
2823 interfMainPanel::getInstance()->setColLableInfoPanel(tmpIntB + 0, tmpTitleString );
2824 interfMainPanel::getInstance()->setColLableInfoPanel( tmpIntB + 1, _T("Size Range") );
2825 interfMainPanel::getInstance()->setColLableInfoPanel( tmpIntB + 2, _T("Min") );
2826 interfMainPanel::getInstance()->setColLableInfoPanel( tmpIntB + 3, _T("Max") );
2827 interfMainPanel::getInstance()->setColLableInfoPanel( tmpIntB + 4, _T("Average") );
2828 interfMainPanel::getInstance()->setColLableInfoPanel( tmpIntB + 5, _T("St.Dev.") );
2829 interfMainPanel::getInstance()->setColLableInfoPanel( tmpIntB + 6, _T(" ") );
2831 interfMainPanel::getInstance()->setStringInfoPanel( _T("") );
2835 void wxContourMainFrame::onSaveResults(std::string directory,std::string namefile, std::string filename,
2836 int typeContourGroup, int selection, int minZ, int maxZ, bool XYZValues, bool contourImage, bool statistics)
2840 SaveValuesXYZ( directory , namefile, typeContourGroup );
2845 vtkImageData * mask;
2846 vtkImageData * value;
2847 this->getMaskValue(&mask, &value, typeContourGroup,selection,minZ,maxZ);
2848 this->SaveImageResult( directory , namefile, mask, value);
2853 std::ostringstream name;
2854 name << filename << ".xls";
2857 FILE *pFile=fopen(name.str().c_str(),"w+");
2863 // int sizeZ = _theViewPanel->GetImageDataSizeZ();
2864 // int maxY=sizeZ+2;
2866 maxX= interfMainPanel::getInstance()->getNumberColsInformationPanel();//this->_grid->GetNumberCols();
2869 int iTitle,sizeTitle = (maxX / _numberOfVariablesStatistics);
2870 for ( iTitle=0; iTitle<sizeTitle ; iTitle++)
2872 // fprintf(pFile,"-- \t %d-Size \t SizeRange \t Min \t Max \t Ave \t StDv \t" , iTitle,tmpString.c_str() );
2873 fprintf(pFile,"slice\t %d-Size \t SizeRange \t Min \t Max \t Ave \t StDv \t" , iTitle );
2875 fprintf(pFile,"\n\n" );
2879 if (selection==0 ) // actual slice
2881 std::vector<int> tempVector;
2882 _instantPanel->getInstant( tempVector );
2883 int actualSlice = tempVector[1];
2889 for ( j=minZ; j<=maxZ ; j++)
2891 fprintf(pFile,"%d\t" , j );
2892 for (i=0 ; i<maxX ; i++){
2893 tmpString = interfMainPanel::getInstance()->getCellValue(j, i);//_grid->GetCellValue( j , i );
2894 fprintf(pFile,"%s\t" , (const char *)(tmpString.mb_str()) );
2896 fprintf(pFile,"\n" );
2900 // Total of stadistics.....
2903 fprintf(pFile,"\n Total:\t" );
2904 for (i=0 ; i<maxX ; i++){
2905 tmpString = interfMainPanel::getInstance()->getCellValue(maxZ+2, i);//_grid->GetCellValue( maxZ+2 , i );
2906 fprintf(pFile,"%s\t" , (const char *)(tmpString.mb_str()) );
2908 fprintf(pFile,"\n" );
2916 void wxContourMainFrame::SaveValuesXYZ(std::string directory,std::string namefile,int typeContourGroup)
2920 //int typeContourGroup = this->_radiolstboxContourGroup->GetSelection();
2921 _contourextractdata ->SetTypeOperation( typeContourGroup % 3 );
2923 std::vector<manualBaseModel*> lstManConMod;
2924 std::vector<manualBaseModel*> lstManConModTmp;
2925 std::vector<manualBaseModel*> lstManConModExp;
2926 std::vector<double> pLstValue;
2927 std::vector<double> pLstValuePosX;
2928 std::vector<double> pLstValuePosY;
2929 std::vector<double> pLstValuePosZ;
2931 std::vector<int> tempVector;
2932 _instantPanel->getInstant( tempVector );
2934 int sizeZ = _theViewPanel->getSceneManager()->GetImageDataSizeZ();
2936 int ii,sizeLstContourThings;
2943 minZ = 0;// _mbarrange->GetStart();
2944 maxZ = sizeZ;//_mbarrange->GetEnd();
2945 totalZ = maxZ-minZ+1;
2949 for ( z=0 ; z<sizeZ ; z++)
2952 porcent = 100.0* (z-minZ)/totalZ;
2954 tmpString.Printf(_T("Saving Values"));
2955 tmpString.Printf(_T(" %d %c %d/%d %d"), (int)porcent , 37 , z-minZ+1, (int)totalZ ,z);
2956 interfMainPanel::getInstance()->setStringInfoPanel(tmpString);
2957 //_staticTextInformation->SetLabel(tmpString);
2960 //Extraction data from contours of each slice
2961 _contourextractdata->SetZtoBeAnalys( z);
2964 Instant instant(&tempVector);
2965 std::vector<ContourThing**> lstContourThings = kernelManager->getOutlinesAtInstant(&instant);//this->_modelManager->getOutlinesAtInstant( &instant );
2966 sizeLstContourThings = lstContourThings.size();
2968 lstManConMod.clear();
2969 for (ii=0 ; ii<sizeLstContourThings ; ii++)
2971 ContourThing **contourthing = lstContourThings[ii];
2972 lstManConMod.push_back( (*contourthing)->getModel() );
2974 lstManConModExp = kernelManager->ExploseEachModel( lstManConMod );
2979 int iContourGroup,sizeContourGroup;
2980 if (typeContourGroup==3) // contour separete
2982 sizeContourGroup=lstManConModExp.size();
2983 } else { // contour AND OR XOR
2987 for( iContourGroup=0 ; iContourGroup<sizeContourGroup ; iContourGroup++ ){
2988 lstManConModTmp.clear();
2989 if (typeContourGroup==3) // contour separete
2991 lstManConModTmp.push_back( lstManConModExp[iContourGroup]);
2992 } else { // contour AND OR XOR
2993 lstManConModTmp = lstManConModExp;
2996 _contourextractdata->SetLstManualContourModel( lstManConModTmp );
2999 pLstValuePosX.clear();
3000 pLstValuePosY.clear();
3001 pLstValuePosZ.clear();
3003 _contourextractdata->GetValuesInsideCrown( &numberOfPixels,
3009 std::string temp = directory + "/" + namefile + "-slice";
3010 temp = temp + kernelManager->intToString(z) + "-cont" + kernelManager->intToString(iContourGroup);
3011 temp = temp + ".txt";
3013 // LG 14/01/09 : using crea
3014 wxString filename = crea::std2wx(temp);
3015 /*filename.Printf(_T("%s"),directory.c_str());
3016 filename.append(_T("\\"));
3017 filename.append(_T("%s"),namefile.c_str());
3018 filename.append(_T("-slice"));
3019 filename.append(_T("%d"),z);
3020 filename.append(_T("-cont"));
3021 filename.append(_T("%d"),iContourGroup);
3022 filename.append(_T(".txt"));*/
3023 // filename.Printf(temp.c_str());
3027 FILE *pFile=fopen((const char *)filename.mb_str(),"w+");
3028 fprintf(pFile,"value \t x \t y \t z\n" );
3029 int iLstValue,sizeLstValue=pLstValue.size();
3030 for (iLstValue=0 ; iLstValue<sizeLstValue ; iLstValue++ )
3032 fprintf(pFile,"%f\t %f\t %f\t %f\n", (float)pLstValue[iLstValue] , (float)pLstValuePosX[iLstValue], (float)pLstValuePosY[iLstValue], (float)z );
3035 } // for iContourGroup
3037 interfMainPanel::getInstance()->setStringInfoPanel(_T(""));
3038 //_staticTextInformation->SetLabel( _T("") );
3042 void wxContourMainFrame::getMaskValue(vtkImageData ** mask,vtkImageData ** value,int typeContourGroup, int selection, int minZ, int maxZ){
3045 //int typeContourGroup = this->_radiolstboxContourGroup->GetSelection();
3046 if (typeContourGroup==3)
3050 _contourextractdata ->SetTypeOperation( typeContourGroup % 3 );
3052 std::vector<manualBaseModel*> lstManConMod;
3053 std::vector<manualBaseModel*> lstManConModTmp;
3054 std::vector<manualBaseModel*> lstManConModExp;
3056 std::vector<int> tempVector;
3057 _instantPanel->getInstant( tempVector );
3059 vtkImageData *imagedata = _theViewPanel->getImageData();
3061 imagedata->GetExtent(ext);
3062 int sizeZimage = ext[5]-ext[4]+1;
3064 int ii,sizeLstContourThings;
3073 if (selection==0 ) // actual slice
3075 int actualSlice = tempVector[1];
3083 // cleanning image before range
3084 for (z=0; z<minZ; z++){
3085 _contourextractdata->ResetImageResult(z);
3087 // cleanning image after range
3088 for (z=maxZ+1; z<sizeZimage; z++){
3089 _contourextractdata->ResetImageResult(z);
3094 for ( z=minZ ; z<=maxZ ; z++)
3097 porcent = 100.0* (z-minZ)/totalZ;
3098 tmpString.Printf(_T("Saving Values"));
3099 tmpString.Printf(_T("%d %c %d/%d %d"), (int)porcent , 37 , z-minZ+1, (int)totalZ ,z);
3100 interfMainPanel::getInstance()->setStringInfoPanel(tmpString);
3102 //Extraction data from contours of each slice
3103 _contourextractdata->SetZtoBeAnalys( z);
3106 Instant instant(&tempVector);
3107 std::vector<ContourThing**> lstContourThings = kernelManager->getOutlinesAtInstant( &instant );
3108 sizeLstContourThings = lstContourThings.size();
3110 lstManConMod.clear();
3111 for (ii=0 ; ii<sizeLstContourThings ; ii++)
3113 ContourThing **contourthing = lstContourThings[ii];
3114 lstManConMod.push_back( (*contourthing)->getModel() );
3116 lstManConModExp = kernelManager->ExploseEachModel( lstManConMod );
3119 int iContourGroup,sizeContourGroup;
3120 if (typeContourGroup==3) // contour separete
3122 sizeContourGroup=lstManConModExp.size();
3123 } else { // contour AND OR XOR
3127 for( iContourGroup=0 ; iContourGroup<sizeContourGroup ; iContourGroup++ ){
3128 lstManConModTmp.clear();
3129 if (typeContourGroup==3) // contour separete
3131 lstManConModTmp.push_back( lstManConModExp[iContourGroup]);
3132 } else { // contour AND OR XOR
3133 lstManConModTmp = lstManConModExp;
3136 _contourextractdata->SetLstManualContourModel( lstManConModTmp );
3137 _contourextractdata->CalculateImageResult(); // with actual Z
3139 } // for iContourGroup
3142 (*value) = _contourextractdata->GetVtkImageValueResult();
3143 (*mask) = _contourextractdata->GetVtkImageMaskResult();
3147 void wxContourMainFrame::SaveImageResult(std::string directory,std::string namefile, vtkImageData* mask,vtkImageData* value)
3151 kernelManager->GetSpacing(spc,0); // returns the spacing of the first image
3153 std::string temp = directory + "/" + namefile + "-image-Value.mhd";
3155 wxString filename = crea::std2wx(temp);
3159 vtkImageChangeInformation *valueChInfo = vtkImageChangeInformation::New();
3160 //EED 2017-01-01 Migration VTK7
3161 #if VTK_MAJOR_VERSION <= 5
3162 valueChInfo->SetInput(value);
3164 valueChInfo->SetInputData(value);
3166 valueChInfo->SetSpacingScale(spc);
3167 vtkMetaImageWriter *writerValueImage = vtkMetaImageWriter::New( );
3169 //EED 2017-01-01 Migration VTK7
3170 #if VTK_MAJOR_VERSION <= 5
3171 writerValueImage->SetInput( valueChInfo->GetOutput() );
3173 writerValueImage->SetInputData( valueChInfo->GetOutput() );
3175 writerValueImage->SetFileName( (const char *)filename.mb_str() );
3176 writerValueImage->SetFileDimensionality( 3 );
3177 writerValueImage->SetCompression(false);
3178 writerValueImage->Write( );
3181 temp = directory + "/" + namefile + "-image-Mask.mhd";
3183 // LG 14/01/09 : using crea
3184 filename = crea::std2wx(temp);
3185 // filename.Printf(_T(temp.c_str()));
3188 vtkImageChangeInformation *maskChInfo = vtkImageChangeInformation::New();
3189 //EED 2017-01-01 Migration VTK7
3190 #if VTK_MAJOR_VERSION <= 5
3191 maskChInfo->SetInput(mask);
3193 maskChInfo->SetInputData(mask);
3195 maskChInfo->SetSpacingScale(spc);
3196 vtkMetaImageWriter *writerMaskImage = vtkMetaImageWriter::New( );
3198 //EED 2017-01-01 Migration VTK7
3199 #if VTK_MAJOR_VERSION <= 5
3200 writerMaskImage->SetInput( maskChInfo->GetOutput() );
3202 writerMaskImage->SetInputData( maskChInfo->GetOutput() );
3205 writerMaskImage->SetFileName( (const char *)filename.mb_str() );
3206 writerMaskImage->SetFileDimensionality( 3 );
3207 writerMaskImage->SetCompression(false);
3208 writerMaskImage->Write( );
3210 interfMainPanel::getInstance()->setStringInfoPanel( _T("") );
3216 void wxContourMainFrame::onChangeInstantInstantPanel(std::string name,int value, int minshow, int maxshow){
3217 if( name.compare( _theViewPanel->getVerticalConceptName() ) == 0){
3218 _theViewPanel->setActualVertical( value);
3220 else if( name.compare( _theViewPanel->getHorizontalConceptName() ) == 0|| _instantPanel->getIfConceptCheckedAt( name, 0 ) ) {
3221 _theViewPanel->setHorizontalConcept( name, minshow, maxshow, minshow, maxshow, value);
3227 void wxContourMainFrame::onSnakePressed(){
3228 std::vector<double> vecX;
3229 std::vector<double> vecY;
3230 std::vector<double> vecZ;
3231 _theViewPanel->GetPointsOfActualContour( &vecX , &vecY , &vecZ );
3233 if (vecX.size()!=0){
3234 std::vector<int> tempVector;
3235 _instantPanel->getInstant( tempVector );
3236 int i,size=vecZ.size();
3237 int actualSlice = tempVector[1];
3238 for ( i=0 ; i<size ; i++ )
3240 vecZ[i] = actualSlice;
3243 wxDialog* dialog = new wxDialog(this, -1, wxString(_T("Snake")));
3244 wxPanel* panel = new wxPanel(dialog,-1);
3245 // wxStaticText* sttext = new wxStaticText(panel, -1, wxString(_T("Panel para snake")));
3246 new wxStaticText(panel, -1, wxString(_T("Panel para snake")));
3247 dialog->ShowModal();
3252 void wxContourMainFrame::saveFileWithContoursAutomatique(){
3253 std::string filename = kernelManager->getCurrentFileName();
3254 if(filename.compare("")!=0){
3255 saveFileWithContours(filename);
3260 void wxContourMainFrame::ShowToolsPanel(bool show){
3261 _pannew->Show(show);
3266 void wxContourMainFrame::SetContourGroup(int contourGroup)
3268 _contourGroup = contourGroup;
3272 wxPanel *wxContourMainFrame::getMaskImageViewPanel(wxWindow *parent)
3275 if (_viewMaskImagePanel==NULL)
3277 _contourextractdata = new ContourExtractData(true);
3278 _contourextractdata->SetImage( _theViewPanel->getImageData() );
3280 // _theViewPanel->getImageData()->GetScalarRange(range);
3281 //int min = (int)floor (range[0]);
3282 //int max = (int)ceil (range[1]);
3285 _viewMaskImagePanel = new ThresholdImageViewPanel( parent, -1, -1 , 0);
3286 _viewMaskImage = new ThresholdImageView();
3287 _viewMaskImage->SetImage(_contourextractdata->GetVtkImageMaskResult() );
3288 _viewMaskImage->SetminMaxValue( min, max);
3289 _viewMaskImage->SetBaseColor( 0,0,1 );
3290 _viewMaskImagePanel->SetThresholdImageView( _viewMaskImage );
3291 _viewMaskImage->SetwxVtkBaseView( _theViewPanel->getWxVtkBaseView() );
3293 return _viewMaskImagePanel;
3297 wxPanel *wxContourMainFrame::getColorLayerImageViewPanel(wxWindow *parent)
3299 if (_viewColorLayerImagePanel==NULL)
3302 _theViewPanel->getImageData()->GetScalarRange(range);
3303 int min = (int)floor (range[0]);
3304 int max = (int)ceil (range[1]);
3305 _viewColorLayerImagePanel = new ColorLayerImageViewPanel( parent, min, max, 100, 1);
3306 _viewColorLayerImagePanel->GetColorLayerImageViewManager()->SetwxVtkBaseView( 0 , _theViewPanel->getWxVtkBaseView() );
3308 return _viewColorLayerImagePanel;
3312 wxPanel *wxContourMainFrame::getThresholdImageViewPanel(wxWindow *parent)
3314 if (_viewThresholdImagePanel==NULL)
3317 _theViewPanel->getImageData()->GetScalarRange(range);
3318 int min = (int)floor (range[0]);
3319 int max = (int)ceil (range[1]);
3320 _viewThresholdImagePanel = new ThresholdImageViewPanel( parent, min, max , 1);
3321 _viewThresholdImage = new ThresholdImageView();
3322 _viewThresholdImage->SetImage( _theViewPanel->getImageData() );
3323 _viewThresholdImage->SetminMaxValue( min, max);
3324 _viewThresholdImage->SetBaseColor( 1,0,0 );
3325 _viewThresholdImagePanel->SetThresholdImageView( _viewThresholdImage );
3326 _viewThresholdImage->SetwxVtkBaseView( _theViewPanel->getWxVtkBaseView() );
3328 return _viewThresholdImagePanel;
3331 //CMRU 17-08-09-----------------------------------------------------------------------------------------------
3332 int wxContourMainFrame::getType ()
3335 std::vector<std::string> currentSelection = _theViewPanel->getSelectedObjects();
3337 if(!currentSelection.empty())
3339 std::string cloneName = currentSelection [0];
3340 manualBaseModel * manualModel = kernelManager->getOutlineByKeyName(cloneName);
3341 tipo = manualModel-> GetTypeModel();
3346 double wxContourMainFrame::getContourSizeInPixels()
3348 double contourSize = 0;
3350 std::vector<std::string> currentSelection = _theViewPanel->getSelectedObjects(); if(!currentSelection.empty())
3351 if(!currentSelection.empty())
3353 std::string cloneName = currentSelection [0];
3355 manualBaseModel * manualModel = kernelManager->getOutlineByKeyName(cloneName);//_modelManager->getOutlineByKeyName( cloneName )->getModel();
3358 // contourSize = manualModel->GetPathSize();
3363 contourSize = manualModel->GetPathSize( spc );
3368 manualBaseModel * wxContourMainFrame::getContour ()
3370 std::vector<std::string> currentSelection = _theViewPanel->getSelectedObjects();
3372 if(!currentSelection.empty())
3374 std::string cloneName = currentSelection [0];
3375 manualBaseModel * manualModel = kernelManager->getOutlineByKeyName(cloneName);//_modelManager->getOutlineByKeyName( cloneName )->getModel();
3380 void wxContourMainFrame::onPrintLabel (wxString label, manualBaseModel* manualModel)
3382 std::string labelAscii(label.ToAscii());
3383 int pos = labelAscii.find(" ");
3387 for (j=0 ; pos != string::npos;j++)
3389 labelAscii.replace( pos, 1, "_" );
3390 pos= labelAscii.find(" ");
3393 manualModel -> SetLabel(labelAscii);
3395 void wxContourMainFrame::onInsertCalculation(manualBaseModel* manualModel)
3398 // double sizeInPixel = manualModel ->GetPathSize( );
3403 double sizeInPixel = manualModel ->GetPathSize( spc );
3405 double onePixelRealSize = interfMainPanel::getInstance()->GetPixelValue();;
3406 double realContourSize = sizeInPixel*onePixelRealSize;
3407 manualModel ->SetRealSize(realContourSize);
3410 double wxContourMainFrame::onePixelSize( double value)
3412 return _onePixelSize = value;
3415 std::string wxContourMainFrame::GetFileLocation()
3417 return _fileLocation;
3420 void wxContourMainFrame::SetFileLocation(std::string newFileLocation)
3422 _fileLocation = newFileLocation;
3423 std::cout<<"GETFILELOCATION:"<<_fileLocation<<std::endl;
3425 //------------------------------------------------------------------------------------------------------------
3434 void wxContourMainFrame::FlipSelectedContours(int flipDirection)
3436 printf("EED wxContourMainFrame::FlipSelectedContours flipDirection=%d \n", flipDirection );
3438 (std::vector<std::string>)_theViewPanel->getSceneManager()->getSelectedObjects() ,
3444 void wxContourMainFrame::FlipActualSliceContours(int flipDirection)
3446 printf("EED wxContourMainFrame::FlipActualSliceContours flipDirection=%d \n", flipDirection );
3448 (std::vector<std::string>)_theViewPanel->getSceneManager()->GetlstContoursNameActualSlice() ,
3453 void wxContourMainFrame::FlipAllContours(int flipDirection)
3455 printf("EED wxContourMainFrame::FlipAllContours flipDirection=%d \n", flipDirection );
3457 kernelManager->GetLstNameThings() ,
3462 void wxContourMainFrame::FlipLstOfContours(std::vector<std::string> lstNameThings, int flipDirection)
3465 getImageData()->GetExtent(ext);
3466 int sizeX = ext[1]-ext[0];
3467 int sizeY = ext[3]-ext[2];
3470 int i,sizeLstNameThings;
3471 int ii,sizeLstPoints;
3473 sizeLstNameThings = lstNameThings.size();
3474 for (i=0 ; i<sizeLstNameThings ; i++)
3476 printf("EED wxContourMainFrame::FlipAllContours contour=%d \n", i );
3477 manualBaseModel * manualModel = kernelManager->getOutlineByKeyName(lstNameThings[i]);
3478 if (flipDirection==0)
3480 manualModel->Transform_Ax_Plus_B(-1,sizeX,1,0 );
3482 manualModel->Transform_Ax_Plus_B(1,0,-1,sizeY );
3484 }// for i list of Things
3486 //-- Static Contours
3488 lstNameThings = kernelManager->GetLstNameThingsStatic();
3489 sizeLstNameThings = lstNameThings.size();
3490 for (i=0 ; i<sizeLstNameThings ; i++)
3492 manualBaseModel * manualModel = kernelManager->getOutlineByKeyName(lstNameThings[i]);
3493 if (flipDirection==0)
3495 manualModel->Transform_Ax_Plus_B(-1,sizeX,1,0 );
3497 manualModel->Transform_Ax_Plus_B(1,0,-1,sizeY );
3499 }// for i list of static things
3502 void wxContourMainFrame::FlipContours(int typeContourFlip, int flipDirection)
3504 printf("EED wxContourMainFrame::FlipContours( %d , %d ) \n",typeContourFlip, flipDirection );
3508 if (typeContourFlip==0) //
3510 FlipSelectedContours(flipDirection);
3513 if (typeContourFlip==1) //
3515 FlipActualSliceContours(flipDirection);
3518 if (typeContourFlip==2) //
3520 FlipAllContours(flipDirection);