1 //----------------------------------------------------------------------------------------------------------------
2 // Class definition include
3 //----------------------------------------------------------------------------------------------------------------
4 #include "wxContourMainFrame.h"
8 //----------------------------------------------------------------------------------------------------------------
10 //----------------------------------------------------------------------------------------------------------------
13 #include "NameWrapper.h"
14 #include "wx/artprov.h"
15 #include "ConceptDataWrap.h"
21 //----------------------------------------------------------------------------------------------------------------
22 // Class implementation
23 //----------------------------------------------------------------------------------------------------------------
24 /** @file wxContourMainFrame.cxx */
26 //------------------------------------------------------------------------------------------------------------
27 // Constructors & Destructors
28 //------------------------------------------------------------------------------------------------------------
30 wxContourMainFrame* wxContourMainFrame:: instance = NULL;
31 char wxContourMainFrame::COPY = 'C';
33 wxContourMainFrame :: wxContourMainFrame(wxWindow* parent, wxWindowID id,const wxString& title,const wxPoint& pos,const wxSize& size,long style)
34 //: wxPanel(parent, id, title, pos, size, style)
35 //: wxWindow(parent, id, pos, size, style)
36 : wxPanel(parent, id, pos, size, style)
38 m_mgr.SetManagedWindow(this);
40 _creatingContoursActive = false;
42 // _modelManager = NULL;
44 // _buttonsBar = NULL;
46 // _drawToolsPanel = NULL;
47 // _operationsToolsPanel = NULL;
48 //_autoFormsPanel = NULL;
49 // _standardToolsPanel = NULL;
50 // _editionToolsPanel = NULL;
51 // _listViewPanel = NULL;
52 // _sceneManager = NULL;
53 //_actualInstant = NULL;
54 _numberOfVariablesStatistics = 6+1;
56 _refLineControl = NULL;
59 // _actorPresent = false;
61 // set up default notebook style
62 // m_notebook_style =wxAUI_NB_TAB_SPLIT | wxAUI_NB_TAB_EXTERNAL_MOVE | wxNO_BORDER;
63 // m_notebook_theme = 0;
64 //wxContour_ActionCommandsID a;
66 _contourextractdata = NULL;
67 _viewMaskImage = NULL;
68 _viewMaskImagePanel = NULL;
69 _viewThresholdImage = NULL;
70 _viewThresholdImagePanel = NULL;
74 wxContourMainFrame :: wxContourMainFrame(wxWindow* parent, wxWindowID id,const wxString& title,const wxPoint& pos,const wxSize& size,std::vector<vtkImageData*> images, long style,std::string datadir)
75 : wxPanel(parent, id, pos, size, style)
77 m_mgr.SetManagedWindow(this);
79 _creatingContoursActive = false;
83 _refLineControl = NULL;
86 // _actorPresent = false;
87 _viewMaskImage = NULL;
88 _viewMaskImagePanel = NULL;
89 _viewThresholdImage = NULL;
90 _viewThresholdImagePanel = NULL;
92 // set up default notebook style
93 m_notebook_style =wxAUI_NB_TAB_SPLIT | wxAUI_NB_TAB_EXTERNAL_MOVE | wxNO_BORDER;
95 //wxContour_ActionCommandsID a;
96 _numberOfVariablesStatistics = 7;
104 _pannew = interfMainPanel::getInstance(this,datadir+"/data/Icons");//, eventHandler);
105 _performingOperation = new PerformingOperation();
107 if(images.size() > 0)
109 this->setVectImages(images);
112 _contourextractdata = NULL;
115 void wxContourMainFrame::setVectImages(std::vector<vtkImageData*> imgs)
120 #if defined(__GNUC__)
121 std::string str_home(getenv("HOME"));
122 #elif defined(_WIN32)
123 std::string str_home(getenv("USERPROFILE"));
125 std::string strCreaContourDataTmp = str_home + "/.creaContourDataTemp/";
127 std::vector<std::string> conceptNameVect;
128 std::vector<int> conceptSizeVect;
130 notebook = this->createNotebook();
133 kernelManager = new KernelManagerContour( imgs , _datadir+"/data/" , strCreaContourDataTmp );
136 _instantPanel = new wxInstantChooserPanel( notebook, "Instant Chooser", true, false, "c" );
137 _theViewPanel = new wxContourViewPanel( kernelManager->getSourceImage(), notebook );
139 //-------------------------------------------------------------
140 kernelManager->getConceptsInformation(conceptNameVect, conceptSizeVect);
141 _instantPanel->addConcepts(conceptNameVect, conceptSizeVect);
144 double val = _theViewPanel->getCurrentDeep();
145 _instantPanel->setConceptValue( "Axe Depth", (int)val );
146 //JCP _instantPanel->setConceptValue("time", num de imagenes);
147 ConceptDataWrap * data = _instantPanel->getConceptDataOf( "Axe Depth" );
148 //*******************changeInstant();
149 _theViewPanel->setVerticalConcept( "Axe Depth", data->getMinValue(), data->getMaxValue(), data->getMinShowedValue(), data->getMaxShowedValue(), data->getActualValue() );
151 this->configurePanels( );
156 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 ){
157 if(instance == NULL){
158 instance = new wxContourMainFrame(parent, id, title, pos, size, images, style,datadir);
163 std::vector<vtkImageData*> wxContourMainFrame ::getVectImages()
165 return kernelManager->getVectImages();
168 wxContourMainFrame* wxContourMainFrame :: getInstance()
173 void wxContourMainFrame :: resetInstance()
178 wxContourMainFrame :: ~wxContourMainFrame()
180 delete _contourextractdata;
183 interfMainPanel::resetInstance();
184 delete kernelManager;
186 //_pannew->Destroy();
192 //El problema al cerrar la aplicacion puede estar asociado
193 //a que wxAUINotebook esta en la aplicacion
194 //principal (wxContourGUIExample)tambien
195 //EED???? delete _theViewPanel;
196 //EED???? delete _instantPanel;
197 //EED???? delete _buttonsBar;
198 //EED???? delete _actualInstant;
199 //EED???? delete _sceneManager;
203 //------------------------------------------------------------------------------------------------------------
204 // Creational and initialization methods using WxAui
205 //------------------------------------------------------------------------------------------------------------
207 wxAuiNotebook * wxContourMainFrame :: createNotebook()
209 wxSize client_size = GetClientSize();
210 wxAuiNotebook* noteBook = new wxAuiNotebook(this, -1, wxPoint(client_size.x, client_size.y), wxSize(430,200), m_notebook_style);
211 wxBitmap page_bmp = wxArtProvider::GetBitmap(wxART_NORMAL_FILE, wxART_OTHER, wxSize(16,16));
216 //------------------------------------------------------------------------------------------------------------
217 // Creational and initialization methods
218 //------------------------------------------------------------------------------------------------------------
219 bool wxContourMainFrame :: configurePanels( )
221 bool configured = _theViewPanel!=NULL;
223 configured &= _theViewPanel!=NULL;
224 if( _theViewPanel!=NULL )
226 notebook->AddPage( _theViewPanel, wxT(" View ") );
233 notebook->AddPage( _instantPanel, wxT("Instant Page") );
237 m_mgr.AddPane(notebook, wxAuiPaneInfo().Name(wxT("notebook_content")).CenterPane().PaneBorder(false));
240 SetMinSize(wxSize(300,300));
246 bool wxContourMainFrame::addNewPanel(wxPanel* panel)
248 bool configured = panel!=NULL;
249 configured &= panel!=NULL;
253 notebook->AddPage( panel, wxT(" Viewer "), true );
259 //------------------------------------------------------------------------------------------------------------
260 // Attributes getters and setters
261 //------------------------------------------------------------------------------------------------------------
265 void wxContourMainFrame :: setInstantChooserPanel( wxInstantChooserPanel * theInstantChooserPanel )
267 _instantPanel = theInstantChooserPanel;
270 // void wxContourMainFrame :: setButtonsBar( wxContour_ButtonsBar * theButtonsBar )
272 // _buttonsBar = theButtonsBar;
275 // void wxContourMainFrame :: setGrid( wxContour_Grid * theGridPanel )
277 // _gridPanel = theGridPanel;
280 // void wxContourMainFrame :: setDrawToolsPanel( wxContour_DrawToolsPanel * theDrawToolsPanel )
282 // _drawToolsPanel = theDrawToolsPanel;
285 // void wxContourMainFrame :: setOperationsToolsPanel( wxContour_OperationsToolsPanel * theOperationsToolsPanel )
287 // _operationsToolsPanel = theOperationsToolsPanel;
290 // void wxContourMainFrame :: setAutomaticFormsPanel( wxContour_AutomaticFormsToolsPanel * theAutoFormsPanel )
292 // _autoFormsPanel = theAutoFormsPanel;
295 // void wxContourMainFrame :: setStandardToolsPanel( wxContour_StandardToolsPanel * theStandardToolsPanel )
297 // _standardToolsPanel= theStandardToolsPanel;
300 // void wxContourMainFrame :: setEditionToolsPanel( wxContour_EdtionToolsPanel * theEditionToolsPanel )
302 // _editionToolsPanel = theEditionToolsPanel;
305 // void wxContourMainFrame :: setListViewPanel( wxContour_ListViewPanel * theListViewPanel )
307 // _listViewPanel = theListViewPanel;
312 void wxContourMainFrame::onCreateContourSpline( ){
314 //JCP 20-10-08 Undo redo implementation
316 //JCP 20-10-08 Undo redo implementation
320 void wxContourMainFrame::onCreateContourRectangle( ){
321 //JCP 20-10-08 Undo redo implementation
323 //JCP 20-10-08 Undo redo implementation
326 void wxContourMainFrame::onCreateContourCircle( ){
327 //JCP 20-10-08 Undo redo implementation
329 //JCP 20-10-08 Undo redo implementation
333 void wxContourMainFrame::onCreateContourLine( ){
334 //JCP 20-10-08 Undo redo implementation
336 //JCP 20-10-08 Undo redo implementation
340 // RaC 09-09 --------------------------------------
341 void wxContourMainFrame::onCreateContourPoints( ){
342 //JCP 20-10-08 Undo redo implementation
344 //JCP 20-10-08 Undo redo implementation
347 // RaC 09-09 --------------------------------------
349 //------------------------------------------------------------------------------------------------------------
351 void wxContourMainFrame :: onCreateContourBullEye(wxPanel* panel )
353 //Creating the manualBaseModel and including in the model
354 manualBaseModel * manModelContour = factoryManualContourModel(panel );
356 std::vector<int> instantVector;
357 _instantPanel->getInstant( instantVector );
358 std::string theName = kernelManager->createOutline(manModelContour, instantVector);
360 /*std::vector<int> instantVector;
361 _instantPanel->getInstant( instantVector );
363 theName= _modelManager->createOutline( manModelContour, instantVector );*/
364 bool addedModel = theName.compare("") != 0;//??
368 double spc[3];//Si no hay imagen pero hay contornos que spacing se pone por default
369 _theViewPanel->getSpacing(spc);
370 //Adding the manualContourControler to interface objects structure
371 //Adding the manualViewContour to interface objects structure
372 //_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.
373 _theViewPanel->getSceneManager()->configureViewControlTo( theName, manModelContour,spc , 4) ;
376 void wxContourMainFrame :: createContour( int typeContour )
378 //Creating the manualContourModel and including in the model
379 manualBaseModel * manModelContour = kernelManager->factoryManualContourModel(typeContour);
381 std::vector<int> instantVector;
382 _instantPanel->getInstant( instantVector );
383 std::string theName = kernelManager->createOutline(manModelContour, instantVector);
385 /*std::vector<int> instantVector;
386 _instantPanel->getInstant( instantVector );
388 theName= _modelManager->createOutline( manModelContour, instantVector );*/
389 bool addedModel = theName.compare("") != 0;//??
392 double spc[3];//Si no hay imagen pero hay contornos que spacing se pone por default
393 _theViewPanel->getSpacing(spc);
394 //Adding the manualContourControler to interface objects structure
395 //Adding the manualViewContour to interface objects structure
396 //_sceneManager->setControlActiveStateOfALL( false );//This call is being done here because if the ROI is created underneath the previously created ROIS will still be active.
397 _theViewPanel->getSceneManager()->configureViewControlTo( theName, manModelContour,spc , typeContour) ;
401 manualBaseModel * wxContourMainFrame::factoryManualContourModel(wxPanel* panel){
403 manualContourModelBullEye *manModelContourBullEye = new manualContourModelBullEye();
404 manualBaseModel *manModelContour=NULL;
405 manModelContour = manModelContourBullEye;
407 int iCrown,sizeCrowns,iSector,sizeSectors;
408 double radioA,radioB,ang,angDelta ;
409 sizeCrowns = ((PanelBullEyeOptions*)panel)->GetNumberOfCrowns();
410 for ( iCrown=0 ; iCrown<sizeCrowns ; iCrown++ )
412 sizeSectors = ((PanelBullEyeOptions*)panel)->GetNumberOfSections(iCrown);
413 radioB = ((PanelBullEyeOptions*)panel)->GetRadioOfCrown(iCrown);
414 if (iCrown==sizeCrowns-1)
418 radioA = ((PanelBullEyeOptions*)panel)->GetRadioOfCrown(iCrown+1);
422 for ( iSector=0 ; iSector<sizeSectors ; iSector++ )
424 ang = ((PanelBullEyeOptions*)panel)->GetAngOfCrownSection(iCrown,iSector);
425 angDelta= ((PanelBullEyeOptions*)panel)->GetAngDeltaOfCrownSection(iCrown);
426 manModelContourBullEye->AddSector(radioA,radioB,ang,angDelta);
429 } // if _panelBullEyeOptions
431 return manModelContour;
433 void wxContourMainFrame :: saveState(){
435 std::string temp = kernelManager->saveState();
436 saveFileWithContours(temp);
439 void wxContourMainFrame::onDeleteContour(){
440 //JCP 20-10-08 Undo redo implementation
442 //JCP 20-10-08 Undo redo implementation
444 std::vector<std::string> lstKeyNameToBeErase;
445 lstKeyNameToBeErase = _theViewPanel->getSceneManager()->getSelectedObjects();
446 deleteContours( lstKeyNameToBeErase );
448 int i,size=_sceneManager->getSelectedObjects().size();
451 std::string keyName = _sceneManager->getSelectedObjects()[i];
452 int ispartofstaticlist = this->_modelManager->IsPartOfStaticList( keyName );
453 if ( ispartofstaticlist>=0 )
455 std::vector<int> tempVector;
456 _instantPanel->getInstant( tempVector );
457 Instant instant(&tempVector);
458 this->_modelManager->ChangeContourOfList(keyName, &instant);
462 std::vector<std::string> lstKeyName;
463 std::vector<std::string> lstKeyNameActualSlice;
464 std::vector<std::string> lstKeyNameToBeErase;
466 lstKeyNameToBeErase = _sceneManager->getSelectedObjects();
467 lstKeyNameActualSlice = _sceneManager->GetlstContoursNameActualSlice();
468 int k,kSize=lstKeyNameToBeErase.size();
469 int j,jSize=lstKeyNameActualSlice.size();
471 for (k=0;k<kSize; k++)
474 for (j=0;j<jSize; j++)
476 if (lstKeyNameToBeErase[k]==lstKeyNameActualSlice[j])
483 lstKeyName.push_back( lstKeyNameToBeErase[k] );
487 deleteContours( lstKeyName );
491 void wxContourMainFrame :: deleteContours( std::vector<std::string> keyNamesVector )
493 int i,size=keyNamesVector.size();
496 deleteContour( keyNamesVector[i] );
500 void wxContourMainFrame :: deleteContour( std::string theKeyName ){
502 manualContourModel * cModel;
503 manualViewBaseContour * cViewer;
504 manualContourBaseControler * cControler;
506 ContourWrap_ViewControl *conwrapviewControl = _theViewPanel->getSceneManager()->getContourWrap_ViewControlOf( theKeyName );
507 cControler = conwrapviewControl->getControler();*/
510 bool isedit = _theViewPanel->isEditableCControler(theKeyName);
511 bool ispartofstaticlst = kernelManager->IsPartOfStaticList(theKeyName);
513 if (isedit && ispartofstaticlst)
515 _theViewPanel->removeFromScene(theKeyName);
517 kernelManager->deleteCModel(theKeyName);
518 //_theViewPanel->getSceneManager()->removeFromScene( theKeyName );
519 //cViewer = conwrapviewControl->getViewer();
520 //_theViewPanel->getSceneManager()->removeWrap( theKeyName );
521 //cControler* conwrapviewControl->getControler();
524 // delete cControler;
529 void wxContourMainFrame::onDeleteContoursActSlice(){
530 //JCP 20-10-08 Undo redo implementation
532 //JCP 20-10-08 Undo redo implementation
533 deleteContours( (std::vector<std::string>)_theViewPanel->getSceneManager()->GetlstContoursNameActualSlice() );
535 void wxContourMainFrame::onDeleteAllContours(){
536 //JCP 20-10-08 Undo redo implementation
540 void wxContourMainFrame::deleteAllContours(){
541 //JCP 20-10-08 Undo redo implementation
544 std::vector<int> tempVector;
545 _instantPanel->getInstant( tempVector );
547 //JCP --08-09-2008 When using a diferent interface the _mbarrangeDeleteAll might not be initialize
548 // the values in GetStart and GetEnd will then not be initialize also.
549 // We use instead the values given when initializing the _deletepanel.
551 //int minZ = _mbarrangeDeleteAll->GetStart();
552 //int maxZ = _mbarrangeDeleteAll->GetEnd();
556 maxZ = _theViewPanel->getSceneManager()->GetImageDataSizeZ();
560 _theViewPanel->getSceneManager()->removeSceneContours( );
561 _theViewPanel->getSceneManager()->removeAllOutlines();
562 kernelManager->removeAllOutlines();
565 if ( (minZ==0) && (maxZ==_mbarrangeDeleteAll->GetMax() ))
567 _theViewPanel->getSceneManager()->removeSceneContours( );
568 _modelManager->removeAllOutlines();
569 _theViewPanel->getSceneManager()->removeAllOutlines();
572 for ( z=minZ ; z<=maxZ ; z++)
575 Instant instant(&tempVector);
576 std::vector<ContourThing**> lstContourThings = this->_modelManager->getOutlinesAtInstant( &instant );
578 sizeLstContourThings = lstContourThings.size();
579 for (ii=0 ; ii<sizeLstContourThings ; ii++)
581 ContourThing **contourthing = lstContourThings[ii];
582 deleteContour( (*contourthing)->getName() );
589 void wxContourMainFrame::setConceptValue( std::string name, int value ){
590 _instantPanel->setConceptValue(name, value);
594 ConceptDataWrap* wxContourMainFrame::getLastConceptData(){
595 return _instantPanel->getLastConceptData();
599 bool wxContourMainFrame::getIfConceptCheckedAt( std::string name, int pos ){
600 return _instantPanel->getIfConceptCheckedAt( name, pos );
605 void wxContourMainFrame::ShowResultImages(int typeContourGroup, int selection, int minZ, int maxZ)
608 vtkImageData * value;
609 this->getMaskValue(&mask, &value, typeContourGroup, selection, minZ, maxZ);
611 std::vector<int> nTypeView;
612 nTypeView.push_back(5);
613 nTypeView.push_back(1);
614 nTypeView.push_back(2);
615 nTypeView.push_back(0);
617 wxFrame *frame = new wxFrame(this, -1,_T("Result image extracted.."),wxDefaultPosition,wxSize(600,600), wxDEFAULT_FRAME_STYLE|wxSTAY_ON_TOP);
618 wxAuiManager *m_mgr_noteBookViewerResult = new wxAuiManager();
619 m_mgr_noteBookViewerResult->SetManagedWindow(frame);
621 wxAuiNotebook* noteBookViewerResult = new wxAuiNotebook(frame, -1, wxPoint(600, 600), wxSize(430,200), m_notebook_style);
622 m_mgr_noteBookViewerResult->AddPane(noteBookViewerResult, wxAuiPaneInfo().Name(wxT("notebook_content")).CenterPane().PaneBorder(false));
624 wxPanel *panelViewer1 = new wxMaracas_N_ViewersWidget(noteBookViewerResult, value,&nTypeView);
625 wxPanel *panelViewer2 = new wxMaracas_N_ViewersWidget(noteBookViewerResult, mask,&nTypeView);
628 noteBookViewerResult->AddPage( panelViewer1, wxT("Image result") );
629 noteBookViewerResult->AddPage( panelViewer2, wxT("Mask result") );
630 m_mgr_noteBookViewerResult->Update();
637 void wxContourMainFrame::changeInstant()
639 std::vector<int> instantVect;
640 _instantPanel->getInstant( instantVect );
641 int actualSlice = instantVect[1];
643 kernelManager->setInstant(instantVect);
645 // Refresh Mask image
646 if(_viewMaskImage!=NULL){
647 _viewMaskImage->SetZ(actualSlice);
648 if (_viewMaskImagePanel->IsVisible()==true)
650 vtkImageData *mask, *value;
651 getMaskValue(&mask,&value, _contourGroup , 0, -1, -1);
652 _viewMaskImage->onThreshold();
656 // Refresh Threshold image
657 if(_viewThresholdImage!=NULL){
658 _viewThresholdImage->SetZ(actualSlice);
659 if (_viewThresholdImagePanel->IsVisible()==true){
660 _viewThresholdImage->onThreshold();
664 updateInstantOutlines();
665 updateInstantImageData();
671 void wxContourMainFrame :: updateInstantOutlines()
673 _theViewPanel->removeSceneContours();
674 _theViewPanel->addNameWrapperToScene();
676 //for( int i=0; i<size; i++)
678 // _theViewPanel->getSceneManager()->addToScene(namesWrapping[i]->getKeyName(), true, true, true, false, false );
682 int wxContourMainFrame::getNamesWrappingSize(){
683 return kernelManager->getNamesWrappingSize();
685 std::string wxContourMainFrame::getNameWrapping(int i){
686 return kernelManager->getNameWrapping(i);
689 void wxContourMainFrame::updateInstantImageData()
691 std::vector<int> inst;
692 _instantPanel->getInstant(inst);
694 vtkImageData* img = kernelManager->getImageAtInstant(inst);
696 _theViewPanel->changeImage(img);
699 int z = _instantPanel->getConceptDataOf("Axe Depth")->getActualValue();
700 _theViewPanel->setImageSlice(z);
704 void wxContourMainFrame::updateInstantAxes()
709 void wxContourMainFrame::onChangeDeep(int val){
710 _instantPanel->setConceptValue( "Axe Depth", (int)val );
715 void wxContourMainFrame::onCopy(){
716 std::vector<std::string> currentSelection = _theViewPanel->getSelectedObjects();
718 std::vector<int> tempVector;
719 _instantPanel->getInstant( tempVector );
720 _performingOperation->reset();
721 _performingOperation->setStartCommand( COPY );
722 _performingOperation->setStartOperationInstantVector( tempVector );
723 _performingOperation->setKeyNamesOperationElems( currentSelection );
726 void wxContourMainFrame::onPaste(){
729 char theStartCommand = _performingOperation->getStartCommand();
730 if ( theStartCommand == COPY )
732 //JCP 20-10-08 Undo redo implementation
734 //JCP 20-10-08 Undo redo implementation
735 std::vector<int> tempVector;
736 _instantPanel->getInstant( tempVector );
737 _performingOperation->setEndOperationInstantVector ( tempVector );
738 std::vector<std::string> elems = _performingOperation->getKeyNamesOperationElems();
739 int i,size = elems.size();
740 for( i=0; i<size; i++ )
742 createCopyContourOf( elems[i], tempVector, i>0 );
746 void wxContourMainFrame::onUndo(){
747 std::string filename;
748 if(kernelManager->onUndoSaveFile(filename)){
749 saveFileWithContours(filename);
751 if(kernelManager->onUndo(filename)){
755 void wxContourMainFrame::onRedo(){
756 std::string filename;
757 if(kernelManager->onRedo(filename)){
762 void wxContourMainFrame :: createCopyContourOf ( std::string anExistingKName, std::vector<int> &instantNoTouchData, bool append )
764 std::string cloneName = kernelManager->createCopyContourOf( anExistingKName, instantNoTouchData );
765 manualBaseModel * manualModel = kernelManager->getOutlineByKeyName(cloneName);//_modelManager->getOutlineByKeyName( cloneName )->getModel();
766 _theViewPanel->getSceneManager()->createCopyContourOf( anExistingKName, cloneName, manualModel , append );
769 ///AD: 03-09 Copy the object and apply the given transformation
770 void wxContourMainFrame :: createMirrorContourOf ( std::string anExistingKName, std::vector<int> &instantNoTouchData, bool append )
772 std::string cloneName = kernelManager->createCopyContourOf( anExistingKName, instantNoTouchData );
773 manualBaseModel * manualModel = kernelManager->getOutlineByKeyName(cloneName);
775 manualPoint * refPoint1 = _refLineModel->GetManualPoint(0);
776 manualPoint * refPoint2 = _refLineModel->GetManualPoint(1);
778 double pnt1X = refPoint1->GetX();
779 double pnt1Y = refPoint1->GetY();
780 // double pnt1Z = refPoint1->GetZ();
781 double pnt2X = refPoint2->GetX();
782 double pnt2Y = refPoint2->GetY();
783 // double pnt2Z = refPoint2->GetZ();
785 double angle = (atan2(pnt2Y - pnt1Y, pnt2X - pnt1X) * 180 / 3.1415926535897932384626433832795)+90;
786 vtkTransform *t = vtkTransform::New();
790 t->Translate(-pnt1X, -pnt1Y, 0);
794 t->Translate(pnt1X, pnt1Y, 0);
797 int i,size=manualModel->GetSizeLstPoints();
800 manualPoint * mp = manualModel->GetManualPoint(i);
806 t->TransformPoint( vecIn, vecOut );
807 mp->SetPointX( vecOut[0] );
808 mp->SetPointY( vecOut[1] );
809 mp->SetPointZ( vecOut[2] );
812 _theViewPanel->getSceneManager()->createCopyContourOf( anExistingKName, cloneName, manualModel , append );
815 void wxContourMainFrame ::loadState(std::string filename){
817 FILE *pFile=fopen(filename.c_str(),"r+");
819 fscanf(pFile,"%s",tmp); // --CreaContour--
821 fscanf(pFile,"%s",tmp); // Version
822 fscanf(pFile,"%s",tmp); // 1.0.2 || 1.0.1 || 1.0.0
826 loadContours(pFile, false);
827 loadContours(pFile, true);
832 void wxContourMainFrame ::loadContours( FILE *pFile, bool staticContour )
836 fscanf(pFile,"%s",tmp); // ImageDimensions
837 fscanf(pFile,"%s",tmp); // X
838 fscanf(pFile,"%s",tmp); // Y
839 fscanf(pFile,"%s",tmp); // Z
841 fscanf(pFile,"%s",tmp); // ImageSpacing
842 fscanf(pFile,"%s",tmp); // X
843 fscanf(pFile,"%s",tmp); // Y
844 fscanf(pFile,"%s",tmp); // Z
846 fscanf(pFile,"%s",tmp); // NumberOfContours
847 fscanf(pFile,"%s",tmp); // ##
848 int numberOfContours = atoi(tmp);
850 std::vector<int> instantVector;
851 int typeContourModel;
852 manualBaseModel *manModelContour;
856 for (i=0;i<numberOfContours;i++)
858 instantVector.clear();
859 fscanf(pFile,"%s",tmp); // Instant
860 fscanf(pFile,"%s",tmp); // 1
861 instantVector.push_back( atoi(tmp) );
862 fscanf(pFile,"%s",tmp); // 2
863 instantVector.push_back( atoi(tmp) );
864 fscanf(pFile,"%s",tmp); // 3
865 instantVector.push_back( atoi(tmp) );
866 fscanf(pFile,"%s",tmp); // 4
867 instantVector.push_back( atoi(tmp) );
868 fscanf(pFile,"%s",tmp); // 5
869 instantVector.push_back( atoi(tmp) );
870 fscanf(pFile,"%s",tmp); // 6
871 instantVector.push_back( atoi(tmp) );
873 fscanf(pFile,"%s",tmp); // TypeContourModel
874 fscanf(pFile,"%s",tmp); // ##
875 typeContourModel = atoi(tmp);
877 manModelContour = kernelManager->factoryManualContourModel(typeContourModel);
878 manModelContour->Open(pFile);
880 fscanf(pFile,"%s",tmp); // TypeView
881 fscanf(pFile,"%s",tmp); // ##
882 typeView = atoi(tmp);
885 theName = kernelManager->createOutline( manModelContour, instantVector );
886 bool addedModel = theName.compare("") != 0;
889 double spc[3];//Si no hay imagen pero hay contornos que spacing se pone por default
890 _theViewPanel->getSpacing(spc);
891 //Adding the manualContourControler to interface objects structure
892 //Adding the manualViewContour to interface objects structure
893 //_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.
894 _theViewPanel->getSceneManager()->configureViewControlTo( theName, manModelContour,spc , typeView) ;
897 if (staticContour==true)
899 Instant instant(&instantVector);
900 kernelManager->changeContourOfManager( theName , &instant );
902 }// for numberOfContours
905 void wxContourMainFrame::onLoad()
909 std::string fileNameContourROI = GetFileLocation();
911 //CMRU 03-09-09-----------------------------------------------------------------------------------------------
912 if(GetFileLocation().empty())
914 //------------------------------------------------------------------------------------------------------------
915 wxFileDialog dialog(NULL, _T("Choose a file"), _T(""), _T(""), _T("*.roi"), wxOPEN );
916 if (dialog.ShowModal() == wxID_OK)
918 fileNameContourROI = (const char *)(dialog.GetPath().mb_str());
922 FILE *pFile =fopen(fileNameContourROI.c_str(),"r+");
925 //CMRU 03-09-09- ----------------------------------------------------------------------------------------------
928 //------------------------------------------------------------------------------------------------------------
929 fileNameContourROI.append("data");
930 FILE *pFileData=fopen(fileNameContourROI.c_str(),"r+");
931 if(pFileData != NULL)
933 fscanf(pFileData,"%s",tmpD); // --CreaContour--
934 fscanf(pFileData,"%s",tmpD); // Version
935 fscanf(pFileData,"%s",tmpD); // 1.0.2 || 1.0.1 || 1.0.0
937 fscanf(pFileData,"%s",tmpD); // onePixelSize
938 fscanf(pFileData,"%s",tmpD); // #
939 _onePixelSize = atof(tmpD);
940 fscanf(pFileData,"%s",tmpD); // NumberOfContours
941 fscanf(pFileData,"%s",tmpD); // #
944 fscanf(pFile,"%s",tmp); // --CreaContour--
946 fscanf(pFile,"%s",tmp); // Version
947 fscanf(pFile,"%s",tmp); // 1.0.2 || 1.0.1 || 1.0.0
948 std::string version(tmp);
951 if (version=="1.0.2")
953 openContours(pFile,pFileData,2,false);
954 openContours(pFile,pFileData,2,true); //Load StaticContours
958 else if (version=="1.0.1")
960 openContours(pFile,pFileData,1,false); //Skips ImageDimensions and ImageSpacing
961 openContours(pFile,pFileData,1,true); //Load StaticContours, skips ImageDimensions and ImageSpacing
965 else if (version=="1.0.0")
967 openContours(pFile,pFileData,1,false); //Skips ImageDimensions and ImageSpacing
972 if(pFileData != NULL)
977 _theViewPanel->getSceneManager()->removeSceneContours();
982 void wxContourMainFrame::onSave(){
983 //CMRU 03-09-09-----------------------------------------------------------------------------------------------
984 if(GetFileLocation().empty())
986 //------------------------------------------------------------------------------------------------------------
987 wxFileDialog dialog(NULL, _T("Choose a file"), _T(""), _T(""), _T("*.roi"), wxSAVE );
988 if (dialog.ShowModal() == wxID_OK)
990 std::string fileNameContourROI = (const char *)(dialog.GetPath().mb_str());
991 kernelManager->setCurrentFileName(fileNameContourROI);
992 saveFileWithContours( fileNameContourROI );
995 //CMRU 03-09-09-----------------------------------------------------------------------------------------------
998 std::cout<<"Nombre del archivo: "<<GetFileLocation()<<std::endl;
999 std::string fileNameContourROI = GetFileLocation();
1000 std::cout<<"Nombre del archivo: "<<fileNameContourROI<<std::endl;
1001 kernelManager->setCurrentFileName(fileNameContourROI);
1002 saveFileWithContours( fileNameContourROI);
1004 //------------------------------------------------------------------------------------------------------------
1008 void wxContourMainFrame::saveFileWithContours( std::string filename )
1011 FILE *pFile=fopen(filename.c_str(),"w+");
1013 //CMRU 03-09-09-----------------------------------------------------------------------------------------------
1014 filename.append("data");
1015 std::cout<<"Nombre del archivo: "<<filename<<std::endl;
1016 FILE *pFileData=fopen(filename.c_str(),"w+");
1017 //------------------------------------------------------------------------------------------------------------
1019 std::vector< std::string > lstNameThings;
1020 int i,sizeLstNameThings;
1022 fprintf(pFile,"--CreaContour--\n");
1023 fprintf(pFile,"Version %s\n", "1.0.2" );
1025 //CMRU 03-09-09-----------------------------------------------------------------------------------------------
1026 fprintf(pFileData,"--CreaContour--\n");
1027 fprintf(pFileData,"Version %s\n", "1.0.2" );
1028 fprintf(pFileData,"OnePixelSize %f\n", _onePixelSize);
1029 std::cout<<"Valor de un pixel: "<<_onePixelSize<<std::endl;
1031 //------------------------------------------------------------------------------------------------------------
1033 vtkImageData *image = _images[0];
1036 image->GetDimensions(dimRange);
1038 fprintf(pFile,"ImageDimensions %d %d %d\n", dimRange[0], dimRange[1], dimRange[2] );
1041 image->GetSpacing(spaRange);
1043 fprintf(pFile,"ImageSpacing %f %f %f\n", spaRange[0], spaRange[1], spaRange[2] );
1047 lstNameThings = kernelManager->GetLstNameThings();
1048 sizeLstNameThings = lstNameThings.size();
1049 fprintf(pFile,"NumberOfContours %d\n", sizeLstNameThings );
1051 //CMRU 03-09-09-----------------------------------------------------------------------------------------------
1052 fprintf(pFileData,"NumberOfContours %d\n", sizeLstNameThings );
1053 //------------------------------------------------------------------------------------------------------------
1055 for (i=0 ; i<sizeLstNameThings ; i++)
1057 //CMRU 03-09-09-----------------------------------------------------------------------------------------------
1058 manualBaseModel * manualModel = kernelManager->getOutlineByKeyName(lstNameThings[i]);
1059 double sizeInPixel = manualModel ->GetPathSize();
1060 double realContourSize = sizeInPixel*_onePixelSize;
1061 manualModel ->SetRealSize(realContourSize);
1062 //------------------------------------------------------------------------------------------------------------
1064 //int size= kernelManager->GetLstNameThings().size();
1066 kernelManager->SaveThingName( pFile, pFileData, lstNameThings[i] );
1067 _theViewPanel->getSceneManager()->SaveThingName( pFile, lstNameThings[i] );
1070 //-- Static Contours
1072 fprintf(pFile,"ImageDimensions %d %d %d\n", dimRange[0], dimRange[1], dimRange[2] );
1074 fprintf(pFile,"ImageSpacing %f %f %f\n", spaRange[0], spaRange[1], spaRange[2] );
1076 lstNameThings = kernelManager->GetLstNameThingsStatic();
1077 sizeLstNameThings = lstNameThings.size();
1078 fprintf(pFile,"NumberOfContoursStatic %d\n", sizeLstNameThings );
1080 //CMRU 03-09-09-----------------------------------------------------------------------------------------------
1081 fprintf(pFileData,"NumberOfContoursStatic %d\n", sizeLstNameThings );
1082 //------------------------------------------------------------------------------------------------------------
1084 for (i=0 ; i<sizeLstNameThings ; i++)
1086 kernelManager->SaveThingName( pFile, pFileData, lstNameThings[i] );
1087 _theViewPanel->getSceneManager()->SaveThingName( pFile, lstNameThings[i] );
1094 void wxContourMainFrame::openContours( FILE *pFile, FILE *pFileData, int version, bool staticContour )
1098 vtkImageData *image = _images[0];
1100 double imageSpac[3];
1104 bool compatible = true;
1109 image->GetDimensions(imageDim);
1110 image->GetSpacing(imageSpac);
1112 fscanf(pFile,"%s",tmp); // ImageDimensions
1113 fscanf(pFile,"%s",tmp); // X
1114 tempDim[0] = atoi(tmp);
1115 fscanf(pFile,"%s",tmp); // Y
1116 tempDim[1] = atoi(tmp);
1117 fscanf(pFile,"%s",tmp); // Z
1118 tempDim[2] = atoi(tmp);
1120 fscanf(pFile,"%s",tmp); // ImageSpacing
1121 fscanf(pFile,"%s",tmp); // X
1122 tempSpac[0] = atof(tmp);
1123 fscanf(pFile,"%s",tmp); // Y
1124 tempSpac[1] = atof(tmp);
1125 fscanf(pFile,"%s",tmp); // Z
1126 tempSpac[2] = atof(tmp);
1128 //Compare Spacing and Dims in X and Y (Necessary in Z?) - Just for Version 2
1129 if (imageDim[0]!=tempDim[0] || imageDim[1]!=tempDim[1] || imageSpac[0]!=tempSpac[0] || imageSpac[1]!=tempSpac[1])
1135 fscanf(pFile,"%s",tmp); // NumberOfContours
1136 fscanf(pFile,"%s",tmp); // ##
1137 int numberOfContours = atoi(tmp);
1139 std::vector<int> instantVector;
1140 int typeContourModel;
1141 manualBaseModel *manModelContour;
1144 if (compatible==true)
1147 for (i=0;i<numberOfContours;i++)
1149 instantVector.clear();
1150 fscanf(pFile,"%s",tmp); // Instant
1152 fscanf(pFile,"%s",tmp); // 1
1153 instantVector.push_back( atoi(tmp) );
1154 fscanf(pFile,"%s",tmp); // 2
1155 instantVector.push_back( atoi(tmp) );
1156 fscanf(pFile,"%s",tmp); // 3
1157 instantVector.push_back( atoi(tmp) );
1158 fscanf(pFile,"%s",tmp); // 4
1159 instantVector.push_back( atoi(tmp) );
1160 fscanf(pFile,"%s",tmp); // 5
1161 instantVector.push_back( atoi(tmp) );
1162 fscanf(pFile,"%s",tmp); // 6
1163 instantVector.push_back( atoi(tmp) );
1166 fscanf(pFile,"%s",tmp); // TypeContourModel
1167 fscanf(pFile,"%s",tmp); // ##
1168 typeContourModel = atoi(tmp);
1170 manModelContour = kernelManager->factoryManualContourModel(typeContourModel);
1171 manModelContour->Open(pFile);
1172 if(pFileData != NULL)
1174 manModelContour->OpenData(pFileData);
1177 fscanf(pFile,"%s",tmp); // TypeView
1178 fscanf(pFile,"%s",tmp); // ##
1179 typeView = atoi(tmp);
1181 std::string theName;
1182 theName = kernelManager->createOutline( manModelContour, instantVector );
1183 bool addedModel = theName.compare("") != 0;
1186 double spc[3];//Si no hay imagen pero hay contornos que spacing se pone por default
1187 _theViewPanel->getSpacing(spc);
1188 //Adding the manualContourControler to interface objects structure
1189 //Adding the manualViewContour to interface objects structure
1190 //_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.
1191 _theViewPanel->getSceneManager()->configureViewControlTo( theName, manModelContour,spc , typeView) ;
1194 if (staticContour) //StaticContours (will appear in all slices)
1196 Instant instant(&instantVector);
1197 kernelManager->changeContourOfManager( theName , &instant );
1200 }// for numberOfContours
1203 else if (compatible==false)
1205 wxDialog* dial = new wxDialog (this,-1,_T("Tools"),wxDefaultPosition, wxSize(260,160));
1206 wxSizer* buttonsSizer = dial->CreateSeparatedButtonSizer(wxOK|wxCANCEL);
1207 wxBoxSizer *dialSizer = new wxBoxSizer(wxVERTICAL);
1209 wxString lstOptOperation[2];
1210 lstOptOperation[0]=_T("By Dimension");
1211 lstOptOperation[1]=_T("By Spacing");
1212 wxRadioBox * radioOpts = new wxRadioBox(dial, -1, _T("Type of Transformation"), wxDefaultPosition, wxSize(270,45), 2 , lstOptOperation, 2, wxRA_SPECIFY_COLS);
1214 dialSizer->Add( new wxStaticText(dial,-1,_T("The image resolution is not compatible with the ")) , 0, wxGROW );
1215 dialSizer->Add( new wxStaticText(dial,-1,_T("selected Roi file. Do you want to tranform it?")) , 0, wxGROW );
1216 dialSizer->Add( new wxStaticText(dial,-1,_T(" ")) , 0, wxGROW );
1217 dialSizer->Add(radioOpts,0,wxGROW);
1218 dialSizer->Add( new wxStaticText(dial,-1,_T(" ")) , 0, wxGROW );
1219 dialSizer->Add(buttonsSizer,0,wxGROW);
1220 dial->SetSizer(dialSizer, true);
1224 int typeOfTransformation = -1;
1225 bool transform = false;
1227 if (dial->GetReturnCode() == wxID_OK)
1229 typeOfTransformation = radioOpts->GetSelection();
1234 for (i=0;i<numberOfContours;i++)
1236 instantVector.clear();
1237 fscanf(pFile,"%s",tmp); // Instant
1239 fscanf(pFile,"%s",tmp); // 1
1240 instantVector.push_back( atoi(tmp) );
1241 fscanf(pFile,"%s",tmp); // 2
1242 instantVector.push_back( atoi(tmp) );
1243 fscanf(pFile,"%s",tmp); // 3
1244 instantVector.push_back( atoi(tmp) );
1245 fscanf(pFile,"%s",tmp); // 4
1246 instantVector.push_back( atoi(tmp) );
1247 fscanf(pFile,"%s",tmp); // 5
1248 instantVector.push_back( atoi(tmp) );
1249 fscanf(pFile,"%s",tmp); // 6
1250 instantVector.push_back( atoi(tmp) );
1252 fscanf(pFile,"%s",tmp); // TypeContourModel
1253 fscanf(pFile,"%s",tmp); // ##
1254 typeContourModel = atoi(tmp);
1256 manModelContour = kernelManager->factoryManualContourModel(typeContourModel);
1257 manModelContour->Open(pFile);
1258 if(pFileData != NULL)
1260 manModelContour->OpenData(pFileData);
1262 if (transform==true)
1264 if (typeOfTransformation==0)
1266 double transX, transY;
1267 transX = (double) imageDim[0]/tempDim[0];
1268 transY = (double) imageDim[1]/tempDim[1];
1269 manModelContour->Transform_Ax_Plus_B(transX,0,transY,0);
1271 else if (typeOfTransformation==1)
1273 double transX, transY;
1274 transX = (double) tempSpac[0]/imageSpac[0];
1275 transY = (double) tempSpac[1]/imageSpac[1];
1276 manModelContour->Transform_Ax_Plus_B(transX,0,transY,0);
1280 fscanf(pFile,"%s",tmp); // TypeView
1281 fscanf(pFile,"%s",tmp); // ##
1282 typeView = atoi(tmp);
1284 std::string theName;
1285 theName = kernelManager->createOutline( manModelContour, instantVector );
1286 bool addedModel = theName.compare("") != 0;
1289 double spc[3];//Si no hay imagen pero hay contornos que spacing se pone por default
1290 _theViewPanel->getSpacing(spc);
1291 //Adding the manualContourControler to interface objects structure
1292 //Adding the manualViewContour to interface objects structure
1293 //_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.
1294 _theViewPanel->getSceneManager()->configureViewControlTo( theName, manModelContour,spc , typeView) ;
1297 if (staticContour) //StaticContours (will appear in all slices)
1299 Instant instant(&instantVector);
1300 kernelManager->changeContourOfManager( theName , &instant );
1302 }// for numberOfContours
1306 void wxContourMainFrame::RefreshInterface(){
1308 _theViewPanel->RefreshInterface();
1309 //wxVtk2DBaseView *wxvtk2dbaseview = (wxVtk2DBaseView*)this->_theViewPanel->getWxVtkBaseView();
1310 //wxvtk2dbaseview->Refresh();
1313 vtkImageData* wxContourMainFrame::getImageData(){
1314 return _theViewPanel->getImageData();
1317 void wxContourMainFrame::onSegmentationOneSliceITK(wxString distance, wxString sigma, wxString alfa, wxString beta, wxString propagation, wxString iterations, wxString inflation)
1319 //JCP 20-10-08 Undo redo implementation
1321 //JCP 20-10-08 Undo redo implementation
1324 int x = _theViewPanel->GetX();
1325 int y = _theViewPanel->GetY();
1326 int z = _theViewPanel->GetZ();
1327 SegmentationOneSliceITK( x,y,z,distance, sigma, alfa, beta, propagation, iterations, inflation);
1331 void wxContourMainFrame::SegmentationOneSliceITK(int x, int y, int z, wxString distanc, wxString sigm, wxString alf, wxString bet, wxString prop, wxString iter, wxString inflation)
1333 int typeofcontour = 1;
1335 vtkImageData *imagedata = getImageData();
1337 //Tipo de pixeles a utilizar internamente en ITK
1338 typedef float InternalPixelType;
1339 const unsigned int Dimension = 2;
1340 typedef itk::Image< InternalPixelType, Dimension > InternalImageType;
1342 //Tipo de pixeles de salida 1
1343 typedef unsigned char OutputPixelType;
1344 typedef itk::Image< OutputPixelType, Dimension > OutputImageType;
1346 //Tipo de pixeles de salida 2
1347 typedef unsigned short OutputPixelType2;
1348 typedef itk::Image< OutputPixelType2, Dimension > OutputImageType2;
1350 //DefiniciÛn del thresholder
1351 typedef itk::BinaryThresholdImageFilter<
1353 OutputImageType > ThresholdingFilterType;
1355 //DefiniciÛn del primer filtro de conversiÛn de pixeles
1356 typedef itk::CastImageFilter<
1357 OutputImageType, OutputImageType2 > CastFilterType;
1359 //DefiniciÛn del segundo tipo de conversiÛn de pixeles
1360 typedef itk::CastImageFilter<
1361 OutputImageType2, InternalImageType > CastFilterType2;
1363 //Tercer tipo de conversiÛn
1364 typedef itk::RescaleIntensityImageFilter<
1366 OutputImageType > CastFilterType3;
1368 //Cuarto tipo de conversiÛn
1369 typedef itk::RescaleIntensityImageFilter<
1371 OutputImageType > CastFilterType4;
1373 ThresholdingFilterType::Pointer thresholder = ThresholdingFilterType::New();
1375 thresholder->SetLowerThreshold( 0.0 );
1376 thresholder->SetUpperThreshold( 128 );
1378 thresholder->SetOutsideValue( 255 );
1379 thresholder->SetInsideValue( 0 );
1381 //DefinciÛn de conexiÛnes entre VTK e ITK y el writer
1382 typedef itk::VTKImageToImageFilter<OutputImageType2> ConnectorType;
1383 typedef itk::ImageToVTKImageFilter<OutputImageType> ConnectorType2;
1384 typedef itk::ImageFileWriter< OutputImageType > WriterType;
1386 ConnectorType::Pointer connector= ConnectorType::New();
1387 ConnectorType2::Pointer connector2= ConnectorType2::New();
1390 CastFilterType::Pointer filter=CastFilterType::New();
1391 CastFilterType2::Pointer filter2=CastFilterType2::New();
1393 connector->SetInput( imagedata );
1394 filter2->SetInput(connector->GetOutput());
1396 typedef itk::CurvatureAnisotropicDiffusionImageFilter<
1398 InternalImageType > SmoothingFilterType;
1400 SmoothingFilterType::Pointer smoothing = SmoothingFilterType::New();
1402 typedef itk::GradientMagnitudeRecursiveGaussianImageFilter<
1404 InternalImageType > GradientFilterType;
1406 typedef itk::SigmoidImageFilter<
1408 InternalImageType > SigmoidFilterType;
1410 GradientFilterType::Pointer gradientMagnitude = GradientFilterType::New();
1412 SigmoidFilterType::Pointer sigmoid = SigmoidFilterType::New();
1414 sigmoid->SetOutputMinimum( 0.0 );
1415 sigmoid->SetOutputMaximum( 255.0 );
1418 typedef itk::FastMarchingImageFilter<
1420 InternalImageType > FastMarchingFilterType;
1423 FastMarchingFilterType::Pointer fastMarching = FastMarchingFilterType::New();
1425 typedef itk::GeodesicActiveContourLevelSetImageFilter< InternalImageType,
1426 InternalImageType > GeodesicActiveContourFilterType;
1427 GeodesicActiveContourFilterType::Pointer geodesicActiveContour =
1428 GeodesicActiveContourFilterType::New();
1430 typedef itk::ZeroCrossingImageFilter<
1432 InternalImageType > ZeroCrossingFilterType;
1433 ZeroCrossingFilterType::Pointer zeroCrossing =
1434 ZeroCrossingFilterType::New();
1436 const double propagationScaling = atof( crea::wx2std(prop).c_str() );
1438 geodesicActiveContour->SetPropagationScaling( propagationScaling );
1439 geodesicActiveContour->SetCurvatureScaling( 1.0 );
1440 geodesicActiveContour->SetAdvectionScaling( 1.0 );
1442 geodesicActiveContour->SetMaximumRMSError( 0.02 );
1443 int it=atoi( crea::wx2std(iter).c_str() );
1444 geodesicActiveContour->SetNumberOfIterations( it );
1446 smoothing->SetInput( filter2->GetOutput() );
1447 gradientMagnitude->SetInput( smoothing->GetOutput() );
1448 sigmoid->SetInput( gradientMagnitude->GetOutput() );
1449 fastMarching->SetInput( sigmoid->GetOutput() );
1450 geodesicActiveContour->SetInput( fastMarching->GetOutput() );
1451 geodesicActiveContour->SetFeatureImage( sigmoid->GetOutput() );
1453 zeroCrossing->SetInput( geodesicActiveContour->GetOutput() );
1454 //thresholder->SetInput( zeroCrossing->GetOutput() );
1455 thresholder->SetInput( geodesicActiveContour->GetOutput() );
1456 connector2->SetInput( thresholder->GetOutput() );
1459 smoothing->SetTimeStep( 0.125 );
1460 smoothing->SetNumberOfIterations( 5 );
1461 smoothing->SetConductanceParameter( 9.0 );
1464 const double sigma = atof( crea::wx2std(sigm).c_str() );
1465 gradientMagnitude->SetSigma( sigma );
1467 const double alpha = atof( crea::wx2std(alf).c_str() );
1468 const double beta = atof( crea::wx2std(bet).c_str() );
1470 sigmoid->SetAlpha( alpha );
1471 sigmoid->SetBeta( beta );
1473 typedef FastMarchingFilterType::NodeContainer NodeContainer;
1474 typedef FastMarchingFilterType::NodeType NodeType;
1476 NodeContainer::Pointer seeds = NodeContainer::New();
1478 InternalImageType::IndexType seedPosition;
1479 seedPosition[0] = x;
1480 seedPosition[1] = y;
1482 const double initialDistance = atof( crea::wx2std(distanc).c_str() );
1486 const double seedValue = - initialDistance;
1488 node.SetValue( seedValue );
1489 node.SetIndex( seedPosition );
1491 seeds->Initialize();
1492 seeds->InsertElement( 0, node );
1494 fastMarching->SetTrialPoints( seeds );
1496 fastMarching->SetSpeedConstant( 1.0 );
1498 fastMarching->SetOutputSize(
1499 connector->GetOutput()->GetBufferedRegion().GetSize() );
1501 fastMarching->SetStoppingValue( 800 );
1505 connector2->Update();
1506 vtkImageData *idata = connector2->GetOutput();
1508 vtkMarchingContourFilter* cntVTK = vtkMarchingContourFilter::New( );
1510 cntVTK->SetInput( idata );
1512 cntVTK->SetNumberOfContours( 1 );
1513 cntVTK->SetValue( 0, 255 );
1515 cntVTK->UpdateInformation();
1517 vtkCleanPolyData* cpd = vtkCleanPolyData::New( );
1518 cpd->SetInput( cntVTK->GetOutput( ) );
1520 cpd->UpdateInformation();
1522 vtkPolyDataConnectivityFilter* conn = vtkPolyDataConnectivityFilter::New( );
1523 conn->SetExtractionModeToLargestRegion( );
1524 conn->SetInput( cpd->GetOutput( ) );
1526 conn->UpdateInformation();
1528 vtkStripper* vtkstripper = vtkStripper::New( );
1529 vtkstripper->SetInput( conn->GetOutput() );
1530 vtkstripper->Update();
1531 vtkstripper->UpdateInformation();
1534 vtkPolyData* polyDataResult = cntVTK->GetOutput();
1535 //std::cout<<"Points "<<polyDataResult->GetNumberOfPoints()<<std::endl;
1536 polyDataResult->Update( );
1537 polyDataResult->UpdateInformation();
1542 myfile.open ("C:/Creatis/example.txt");
1544 polyDataResult->Print(myfile);
1545 myfile << "-------------------------------------\n";
1546 polyDataResult->GetLines()->Print(myfile);
1554 //--Calculating control points
1556 std::vector<double> vecX;
1557 std::vector<double> vecY;
1558 std::vector<double> vecXo;
1559 std::vector<double> vecYo;
1560 std::vector<double>::iterator vecXoi;
1561 std::vector<double>::iterator vecYoi;
1562 std::vector<double> vecZ;
1564 std::vector<double> vecCtrlPointX;
1565 std::vector<double> vecCtrlPointY;
1566 std::vector<double> vecCtrlPointZ;
1572 int ii,size=polyDataResult->GetNumberOfPoints();
1574 myfile.open ("C:/Creatis/example2.txt");
1576 size=polyDataResult->GetNumberOfPoints();
1577 for (ii=0;ii<size;ii++)
1584 p = polyDataResult->GetPoint(ii);
1587 /*if(fabs(yAct-y)>20)
1589 if((xAct-x)>1 || (xAct-x)<-1)
1591 vecX.push_back( p[0] );
1592 vecY.push_back( p[1] );
1593 myfile <<p[0]<<","<<p[1]<<"\n";
1594 std::cout<<" x Anterior "<<xAct<<" x actual "<<x<<std::endl;
1595 std::cout<<" y Anterior "<<yAct<<" y actual "<<y<<std::endl;
1596 std::cout<<" x "<<p[0]<<" y "<<p[1]<<std::endl;
1597 vecZ.push_back( 900 );
1603 vecXo.push_back(p[0]);
1604 vecYo.push_back(p[1]);
1608 else*/ if(fabs(xAct-x)>11)
1610 vecXo.push_back(p[0]);
1611 vecYo.push_back(p[1]);
1615 vecX.push_back( p[0] );
1616 myfile <<p[0]<<","<<p[1]<<"\n";
1617 //std::cout<<" x Anterior "<<xAct<<" x actual "<<x<<std::endl;
1618 //std::cout<<" y Anterior "<<yAct<<" y actual "<<y<<std::endl;
1619 //std::cout<<" x "<<p[0]<<" y "<<p[1]<<std::endl;
1620 vecY.push_back( p[1] );
1621 vecZ.push_back( 900 );
1629 while(!vecXo.empty())
1631 vecX.push_back(vecXo.back());
1632 //std::cout<<" x Siguiente "<<vecXo.back();
1634 vecZ.push_back( 900 );
1636 while(!vecYo.empty())
1638 vecY.push_back(vecYo.back());
1643 /*for(int l=0;l<vecX.size();l++)
1647 vecXo.push_back(p[0]);
1648 vecYo.push_back(p[1]);
1659 ExtractControlPoints2D *extractcontrolpoints2d = new ExtractControlPoints2D();
1661 extractcontrolpoints2d->SetContour( &vecX , &vecY , &vecZ );
1665 extractcontrolpoints2d->GetInitialControlPoints( &vecCtrlPointX , &vecCtrlPointY , &vecCtrlPointZ );
1667 else if (method==1){
1668 extractcontrolpoints2d->GetControlPoints( &vecCtrlPointX , &vecCtrlPointY , &vecCtrlPointZ );
1670 else if (method==2){
1671 extractcontrolpoints2d->SetSamplingControlPoints( 15 );
1672 extractcontrolpoints2d->GetSamplingControlPoints( &vecCtrlPointX , &vecCtrlPointY , &vecCtrlPointZ );
1674 //--Adding contour to the system
1676 std::vector<int> actualInstantVector;
1677 _instantPanel->getInstant( actualInstantVector );
1678 actualInstantVector[1]=z;
1680 int j,sizeCtrPt = vecCtrlPointX.size();
1682 manualBaseModel *manModelContour = kernelManager->factoryManualContourModel( typeofcontour );
1683 manModelContour->SetNumberOfPointsSpline( ((sizeCtrPt/100)+1)*100 );
1685 for (j=0 ; j<sizeCtrPt ; j++)
1687 manModelContour->AddPoint( vecCtrlPointX[j] , vecCtrlPointY[j] , vecCtrlPointZ[j] );
1689 std::string theName;
1690 //theName = _modelManager->createOutline( manModelContour, actualInstantVector );
1691 theName = kernelManager->createOutline( manModelContour, actualInstantVector );
1692 bool addedModel = theName.compare("") != 0;
1695 double spc[3];//Si no hay imagen pero hay contornos que spacing se pone por default
1696 _theViewPanel->getSpacing(spc);
1697 //Adding the manualContourControler to interface objects structure
1698 //Adding the manualViewContour to interface objects structure
1699 //_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.
1700 _theViewPanel->configureViewControlTo(theName, manModelContour, spc, typeofcontour);
1701 //_theViewPanel->getSceneManager()->configureViewControlTo( theName, manModelContour,spc, typeofcontour ) ;
1707 WriterType::Pointer writer = WriterType::New();
1708 CastFilterType3::Pointer caster = CastFilterType3::New();
1710 caster->SetInput( gradientMagnitude->GetOutput() );
1711 writer->SetInput( caster->GetOutput() );
1712 writer->SetFileName("Gradient Magnitude.png");
1713 caster->SetOutputMinimum( 0 );
1714 caster->SetOutputMaximum( 255 );
1717 CastFilterType3::Pointer caster2 = CastFilterType3::New();
1718 WriterType::Pointer writer2 = WriterType::New();
1720 caster2->SetInput( sigmoid->GetOutput() );
1721 writer2->SetInput( caster2->GetOutput() );
1722 writer2->SetFileName("Sigmoid.png");
1723 caster2->SetOutputMinimum( 0 );
1724 caster2->SetOutputMaximum( 255 );
1727 CastFilterType3::Pointer caster3 = CastFilterType3::New();
1728 WriterType::Pointer writer3 = WriterType::New();
1730 caster3->SetInput( fastMarching->GetOutput() );
1731 writer3->SetInput( caster3->GetOutput() );
1732 writer3->SetFileName("FastMarching.bmp");
1733 caster3->SetOutputMinimum( 0 );
1734 caster3->SetOutputMaximum( 255 );
1737 CastFilterType3::Pointer caster4 = CastFilterType3::New();
1738 WriterType::Pointer writer4 = WriterType::New();
1740 caster4->SetInput( geodesicActiveContour->GetOutput() );
1741 writer4->SetInput( caster4->GetOutput() );
1742 writer4->SetFileName("GeodesicActiveContour.png");
1743 caster4->SetOutputMinimum( 0 );
1744 caster4->SetOutputMaximum( 255 );
1747 CastFilterType3::Pointer caster5 = CastFilterType3::New();
1748 WriterType::Pointer writer5 = WriterType::New();
1750 caster5->SetInput( zeroCrossing->GetOutput() );
1751 writer5->SetInput( caster5->GetOutput() );
1752 writer5->SetFileName("ZeroCrossing.bmp");
1753 caster5->SetOutputMinimum( 0 );
1754 caster5->SetOutputMaximum( 255 );
1757 catch( itk::ExceptionObject & excep )
1759 std::cerr << "Exception caught !" << std::endl;
1760 std::cerr << excep << std::endl;
1764 void wxContourMainFrame::onSegmentationOneSlice(int isovalue,int sampling,int method){
1766 //JCP 20-10-08 Undo redo implementation
1768 //JCP 20-10-08 Undo redo implementation
1771 int x = _theViewPanel->GetX();
1772 int y = _theViewPanel->GetY();
1773 int z = _theViewPanel->GetZ();
1774 SegmentationOneSlice( x,y,z,isovalue, sampling, method );
1779 void wxContourMainFrame::SegmentationOneSlice( int x, int y, int z, int isovalue, int sampling, int method )
1781 int typeofcontour = 1;
1782 //--Extracting Contour
1783 //vtkImageData *imagedata = _theViewPanel->getSceneManager()->GetImageData();
1784 vtkImageData *imagedata = getImageData();
1785 // double *range = imagedata->GetScalarRange();
1788 vtkImageReslice *imageReslice = vtkImageReslice::New();
1791 // imagedata->GetSpacing(spc);
1796 imageReslice->SetInput( imagedata );
1797 imageReslice->SetInformationInput(imagedata);
1798 imageReslice->SetResliceAxesDirectionCosines(1,0,0, 0,1,0 ,0,0,1);
1799 imageReslice->SetResliceAxesOrigin(0,0,z);
1800 imageReslice->SetOutputDimensionality(2);
1801 imageReslice->SetInterpolationModeToLinear();
1803 imagedata = imageReslice->GetOutput();
1804 imagedata->Update();
1805 imagedata->UpdateInformation();
1807 vtkContourFilter* cntVTK = vtkContourFilter::New( );
1808 cntVTK->SetInput( imagedata );
1810 cntVTK->SetNumberOfContours( 1 );
1811 //cntVTK->SetValue( 0, vmin );
1812 // cntVTK->SetValue( 0, (range[1]*thr/100) );
1813 cntVTK->SetValue( 1, isovalue );
1814 // cntVTK->SetValue( 1, vmax );
1816 cntVTK->UpdateInformation();
1818 vtkCleanPolyData* cpd = vtkCleanPolyData::New( );
1819 cpd->SetInput( cntVTK->GetOutput( ) );
1820 cpd->ConvertLinesToPointsOff( );
1822 cpd->UpdateInformation();
1824 vtkPolyDataConnectivityFilter* conn = vtkPolyDataConnectivityFilter::New( );
1825 conn->SetExtractionModeToClosestPointRegion( );
1826 //conn->SetMaxRecursionDepth( 3000 );
1828 conn->SetInput( cpd->GetOutput( ) );
1830 conn->SetClosestPoint( x, y, 0 );
1832 conn->UpdateInformation();
1834 vtkCleanPolyData* cpd2 = vtkCleanPolyData::New( );
1835 cpd2->SetInput( conn->GetOutput( ) );
1837 cpd2->UpdateInformation();
1839 vtkStripper* vtkstripper = vtkStripper::New( );
1840 vtkstripper->SetInput( cpd2->GetOutput() );
1841 vtkstripper->Update();
1842 vtkstripper->UpdateInformation();
1845 vtkPolyData* polyDataResult = vtkstripper->GetOutput();
1847 polyDataResult->Update( );
1848 polyDataResult->UpdateInformation();
1852 myfile.open ("c:/temp/example.txt");
1854 polyDataResult->Print(myfile);
1855 myfile << "-------------------------------------\n";
1856 polyDataResult->GetLines()->Print(myfile);
1866 //--Calculating control points
1868 std::vector<double> vecX;
1869 std::vector<double> vecY;
1870 std::vector<double> vecZ;
1872 std::vector<double> vecCtrlPointX;
1873 std::vector<double> vecCtrlPointY;
1874 std::vector<double> vecCtrlPointZ;
1878 int ii,size=polyDataResult->GetNumberOfPoints();
1880 for (ii=1;ii<=size;ii++)
1882 id = polyDataResult->GetLines()->GetData()->GetValue(ii);
1883 p = polyDataResult->GetPoint(id);
1886 vecX.push_back( p[0] );
1887 vecY.push_back( p[1] );
1888 vecZ.push_back( 900 );
1889 // vecZ.push_back( p[2] );
1893 ExtractControlPoints2D *extractcontrolpoints2d = new ExtractControlPoints2D();
1894 extractcontrolpoints2d->SetContour( &vecX , &vecY , &vecZ );
1897 /*if (methodRadiobox->GetSelection()==0){
1898 extractcontrolpoints2d->GetInitialControlPoints( &vecCtrlPointX , &vecCtrlPointY , &vecCtrlPointZ );
1900 if (methodRadiobox->GetSelection()==1){
1901 extractcontrolpoints2d->GetControlPoints( &vecCtrlPointX , &vecCtrlPointY , &vecCtrlPointZ );
1903 if (methodRadiobox->GetSelection()==2){
1904 extractcontrolpoints2d->SetSamplingControlPoints( sampling );
1905 extractcontrolpoints2d->GetSamplingControlPoints( &vecCtrlPointX , &vecCtrlPointY , &vecCtrlPointZ );
1909 extractcontrolpoints2d->GetInitialControlPoints( &vecCtrlPointX , &vecCtrlPointY , &vecCtrlPointZ );
1911 else if (method==1){
1912 extractcontrolpoints2d->GetControlPoints( &vecCtrlPointX , &vecCtrlPointY , &vecCtrlPointZ );
1914 else if (method==2){
1915 extractcontrolpoints2d->SetSamplingControlPoints( sampling );
1916 extractcontrolpoints2d->GetSamplingControlPoints( &vecCtrlPointX , &vecCtrlPointY , &vecCtrlPointZ );
1919 //--Adding contour to the system
1921 std::vector<int> actualInstantVector;
1922 _instantPanel->getInstant( actualInstantVector );
1923 actualInstantVector[1]=z;
1925 int j,sizeCtrPt = vecCtrlPointX.size();
1926 manualBaseModel *manModelContour = kernelManager->factoryManualContourModel( typeofcontour );
1927 manModelContour->SetNumberOfPointsSpline( ((sizeCtrPt/100)+1)*100 );
1929 for (j=0 ; j<sizeCtrPt ; j++)
1931 manModelContour->AddPoint( vecCtrlPointX[j] , vecCtrlPointY[j] , vecCtrlPointZ[j] );
1933 std::string theName;
1934 //theName = _modelManager->createOutline( manModelContour, actualInstantVector );
1935 theName = kernelManager->createOutline( manModelContour, actualInstantVector );
1936 bool addedModel = theName.compare("") != 0;
1939 double spc[3];//Si no hay imagen pero hay contornos que spacing se pone por default
1940 _theViewPanel->getSpacing(spc);
1941 //Adding the manualContourControler to interface objects structure
1942 //Adding the manualViewContour to interface objects structure
1943 //_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.
1944 _theViewPanel->configureViewControlTo(theName, manModelContour, spc, typeofcontour);
1945 //_theViewPanel->getSceneManager()->configureViewControlTo( theName, manModelContour,spc, typeofcontour ) ;
1949 int wxContourMainFrame::GetImageDataSizeZ(){
1950 return _theViewPanel->GetImageDataSizeZ();
1953 void wxContourMainFrame::GetImageDataRange(double *range){
1954 _theViewPanel->GetImageDataRange(range);
1957 void wxContourMainFrame::onSegmentationAllSlice(int minZ,int maxZ,int isovalue,int sampling,int method){
1958 //JCP 20-10-08 Undo redo implementation
1960 //JCP 20-10-08 Undo redo implementation
1963 int x = _theViewPanel->GetX();
1964 int y = _theViewPanel->GetY();
1968 double totalZ = maxZ-minZ+1;
1969 for( z=minZ ; z<=maxZ ; z++ )
1971 porcent = 100.0* (z-minZ)/totalZ;
1972 tmpString.Printf(_T(" %d %c %d/%d %d"), (int)porcent , 37 , z-minZ+1, (int)totalZ,z );
1973 interfMainPanel::getInstance()->setLabelSegmentationPanelVTK(tmpString);
1974 //_staticTextSegmentation->SetLabel(tmpString);
1975 SegmentationOneSlice( x,y,z,isovalue, sampling,method );
1977 interfMainPanel::getInstance()->setLabelSegmentationPanelVTK(_T(" "));
1982 //Creates a reference line to be used as the axis of the mirroring
1983 void wxContourMainFrame::referenceLine()
1985 if (_refLineControl==NULL)
1990 vtkImageData *vtkimagedata = _theViewPanel->getImageData();
1991 vtkimagedata->GetSpacing(spc);
1993 wxVtkBaseView * viewer2D = _theViewPanel->getWxVtkBaseView();
1995 _refLineControl = new manualLineControler();
1996 _refLineModel = new manualContourModelLine();
1997 _refLineView = new manualViewLine();
1998 _refLineView->SetModel( _refLineModel );
1999 _refLineView->SetWxVtkBaseView( viewer2D );
2000 _refLineView->SetRange( 2 );
2001 _refLineView->SetZ( 1200 );
2003 _refLineView->SetSpacing(spc);
2005 _refLineView->SetColorNormalContour(0, 0, 1);
2006 _refLineView->SetColorEditContour(0, 0.5, 0.5);
2007 _refLineView->SetWidthLine(4);
2009 _refLineControl->SetModelView( _refLineModel , _refLineView );
2010 vtkInteractorStyleBaseView* style = (vtkInteractorStyleBaseView*)viewer2D->GetInteractorStyleBaseView();
2011 style->AddInteractorStyleMaracas( _refLineControl );
2012 _refLineModel->SetCloseContour(false);
2013 _refLineControl->CreateNewManualContour();
2015 //AD: Inicializar el mirroring con una linea ya pintada
2017 double z = _refLineControl->GetZ();
2020 image->GetDimensions(imageDim);
2021 double x = (double) imageDim[0]/2;
2022 double y1 = (double) (imageDim[1]/2)+15;
2023 double y2 = (double) (imageDim[1]/2)-15;
2025 _refLineControl->AddPoint(x,y1,z);
2026 _refLineControl->AddPoint(x,y2,z);
2027 _refLineControl->SetCompleteCreation(true);
2029 _refLineModel->AddPoint(x,y1,z);
2030 _refLineModel->AddPoint(x,y2,z);
2031 _refLineModel->UpdateSpline();
2033 _refLineView->UpdateViewPoint(0);
2034 _refLineView->UpdateViewPoint(1);
2037 _refLineControl->SetActive(true);
2038 _refLineView->RefreshContour();
2042 //Hides the referenceLine
2043 void wxContourMainFrame::refLineHide()
2045 if (_refLineControl!=NULL)
2047 if (_refLineControl->GetActive())
2049 _refLineView->RemoveCompleteContourActor();
2050 _refLineControl->SetEditable(false);
2051 _refLineControl->SetActive(false);
2058 //Shows the referenceLine
2059 void wxContourMainFrame::refLineShow()
2061 if (_refLineControl!=NULL)
2063 if (_refLineControl->GetActive()==false)
2065 wxVtkBaseView * viewer2D = _theViewPanel->getWxVtkBaseView();
2067 _refLineView->SetModel( _refLineModel );
2068 _refLineView->SetWxVtkBaseView( viewer2D );
2069 _refLineView->SetRange( 2 );
2070 _refLineView->SetZ( 1200 );
2072 _refLineControl->SetModelView( _refLineModel , _refLineView );
2073 vtkInteractorStyleBaseView* style = (vtkInteractorStyleBaseView*)viewer2D->GetInteractorStyleBaseView();
2074 style->AddInteractorStyleMaracas( _refLineControl );
2075 _refLineControl->CreateNewManualContour();
2076 _refLineControl->SetActive(true);
2077 _refLineView->RefreshContour();
2084 void wxContourMainFrame::refLineChangeWidth(int width)
2086 _refLineView->SetWidthLine(width);
2087 _refLineView->RefreshContour();
2093 void wxContourMainFrame::onMirror()
2096 std::vector<std::string> currentSelection = _theViewPanel->getSelectedObjects();
2097 std::vector<std::string> filterCurrentSelection;
2099 std::vector<int> tempVector;
2100 _instantPanel->getInstant( tempVector );
2101 _performingOperation->reset();
2102 _performingOperation->setStartCommand( COPY );
2103 _performingOperation->setStartOperationInstantVector( tempVector );
2104 _performingOperation->setKeyNamesOperationElems( currentSelection );
2106 char theStartCommand = _performingOperation->getStartCommand();
2107 if ( theStartCommand == COPY )
2109 //JCP 20-10-08 Undo redo implementation
2111 //JCP 20-10-08 Undo redo implementation
2112 std::vector<int> tempVector;
2113 _instantPanel->getInstant( tempVector );
2114 _performingOperation->setEndOperationInstantVector ( tempVector );
2115 std::vector<std::string> elems = _performingOperation->getKeyNamesOperationElems();
2116 int i,size = elems.size();
2117 for( i=0; i<size; i++ )
2119 createMirrorContourOf( elems[i], tempVector, i>0 );
2123 //deleteContour( _refName );
2128 void wxContourMainFrame::showAxis(bool show)
2130 _theViewPanel->SetVisibleAxis(show);
2131 _theViewPanel->Refresh();
2135 void wxContourMainFrame::onRigidPressed(){
2136 std::vector<std::string> currentSelection = _theViewPanel->getSelectedObjects();
2137 int elementsSelected = currentSelection.size();
2139 if ( elementsSelected >= 1 ){
2140 //JCP 20-10-08 Undo redo implementation
2142 //JCP 20-10-08 Undo redo implementation
2144 std::vector<int> tempVector;
2145 _instantPanel->getInstant( tempVector );
2146 Instant instant(&tempVector);
2148 int i , size=currentSelection.size();
2149 for ( i=0 ; i<size ; i++ )
2151 kernelManager->changeContourOfManager(currentSelection[i], &instant);
2156 void wxContourMainFrame::onWidthOfContour(double width){
2158 _theViewPanel->removeSceneContours();
2159 _theViewPanel->SetWidthContour(width);
2161 //_theViewPanel->getSceneManager()->SetWidthContour( width );
2166 int wxContourMainFrame::getColorWindow()
2170 vtkImageData * img = getImageData();
2171 img->GetScalarRange(range);
2173 std::cout<<"Val 1: "<<range[0]<<" Val 2: "<<range[1]<<std::endl;
2175 return (int)range[1];
2177 return _theViewPanel->getColorWindow();
2180 int wxContourMainFrame::getWindowLevel()
2184 vtkImageData * img = getImageData();
2185 img->GetScalarRange(range);
2187 std::cout<<"Val 1: "<<range[0]<<" Val 2: "<<range[1]<<std::endl;
2189 return (int)range[1];
2191 return _theViewPanel->getWindowLevel();
2194 void wxContourMainFrame::onBrigthnessColorWindowLevel(int colorwindow,int windowlevel){
2195 _theViewPanel->onBrigthnessColorWindowLevel(colorwindow, windowlevel);
2200 void wxContourMainFrame::onInterpolation(bool interpolate){
2201 _theViewPanel->onInterpolation(interpolate);
2205 void wxContourMainFrame::onChangeInstant(std::string name,int actual){
2206 _instantPanel->setConceptValue( name, actual );
2209 void wxContourMainFrame::resetAppend(){
2210 kernelManager->resetAppend();
2214 void wxContourMainFrame::onSpreadAdd(){
2215 std::vector<double> vecX;
2216 std::vector<double> vecY;
2217 std::vector<double> vecZ;
2218 _theViewPanel->GetPointsOfActualContour(&vecX , &vecY , &vecZ );
2220 std::vector<int> tempVector;
2221 _instantPanel->getInstant( tempVector );
2223 std::string val = kernelManager->onSpreadAdd(&vecX , &vecY , &vecZ, tempVector);
2225 interfMainPanel::getInstance()->appendStringSpread(val);
2229 void wxContourMainFrame::onSpreadGo(int type){
2231 //JCP 20-10-08 Undo redo implementation
2233 //JCP 20-10-08 Undo redo implementation
2236 std::vector<double> vecCtrlPointX;
2237 std::vector<double> vecCtrlPointY;
2238 std::vector<double> vecCtrlPointZ;
2242 std::vector<int> tempVector;
2243 _instantPanel->getInstant( tempVector );
2246 kernelManager->getMaxMinZ(&minZ,&maxZ);
2247 //JSTG_16-07-08_----------------------------------------------------------------
2248 //_contourPropagation->setInterpolationNumber(maxZ-minZ+1);
2249 kernelManager->CalculeSplinePropagation();
2251 double totalZ = maxZ-minZ+1;
2254 //--------------------------------------------------------------------
2255 for ( z=(int)minZ ; z<=(int)maxZ ; z++ )
2257 porcent = 100.0* (z-minZ)/totalZ;
2258 int numero = (int)(z-minZ+1)/(int)totalZ;
2259 std::string stringtemp = " "+kernelManager->intToString(porcent)+"% "+kernelManager->intToString(numero)+" "+kernelManager->intToString(z);
2261 interfMainPanel::getInstance()->setStringSpread(stringtemp);
2263 int typeofcontour = 1;
2264 std::string theName;
2265 manualBaseModel* manModelContour = kernelManager->GetPoints(z, type, &vecCtrlPointX,&vecCtrlPointY,&vecCtrlPointZ, theName,typeofcontour, tempVector);
2267 if( manModelContour!=NULL ){
2268 double spc[3];//Si no hay imagen pero hay contornos que spacing se pone por default
2269 this->_theViewPanel->getSpacing(spc);
2270 //Adding the manualContourControler to interface objects structure
2271 //Adding the manualViewContour to interface objects structure
2272 //_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.
2273 _theViewPanel->configureViewControlTo( theName, manModelContour,spc,typeofcontour ) ;
2278 int numero = (int)(z-minZ+1)/(int)totalZ;
2279 std::string stringtemp = " "+kernelManager->intToString(porcent)+"% "+kernelManager->intToString(numero)+" "+kernelManager->intToString(z);
2281 interfMainPanel::getInstance()->setStringSpread(stringtemp);
2283 //RefreshInterface();
2286 void wxContourMainFrame::getInstantVector(std::vector<int>& tempVector){
2290 std::vector<std::string> wxContourMainFrame::getOutlinesName(int slide){
2291 std::vector<int> tempVector;
2292 _instantPanel->getInstant(tempVector);
2293 //Asignation of slide number should be different ex by name
2294 tempVector[1]=slide;
2295 return kernelManager->getOutlinesNameAtInstant(tempVector);
2300 void wxContourMainFrame::onInformationContourLabels(int typeContourGroup,int selection,int minimumZ,int maximumZ,int grayRangeMin, int grayRangeMax)
2302 //EED01Juillet2009 GenerateContourExtractData();
2304 wxString tempString;
2305 int maxContourGroup = 0;
2307 _contourextractdata ->SetTypeOperation( typeContourGroup % 3 );
2309 std::vector<manualBaseModel*> lstManConMod;
2310 std::vector<manualBaseModel*> lstManConModTmp;
2311 std::vector<manualBaseModel*> lstManConModExp;
2312 std::vector<double> pLstValue;
2313 std::vector<double> pLstValuePosX;
2314 std::vector<double> pLstValuePosY;
2315 std::vector<double> pLstValuePosZ;
2318 int resultGrayRangeCount;
2321 double resultAverage;
2322 double resultStandardeviation;
2324 std::vector<int> tempVector;
2325 _instantPanel->getInstant( tempVector );
2327 //EED01Juillet2009 vtkImageData *imagedata = _theViewPanel->getImageData();
2328 // int sizeZ = _theViewPanel->GetImageDataSizeZ();
2330 int ii,sizeLstContourThings;
2339 if (selection==0 ) // actual slice
2341 int actualSlice = tempVector[1];
2344 } else { // slice range
2350 totalZ = maxZ-minZ+1;
2351 //EED01Juillet2009 _contourextractdata->SetImage( imagedata);
2353 _contourextractdata->InitVolumeStatistics();
2356 for ( z=minZ ; z<=maxZ ; z++ )
2359 porcent = 100.0* (z-minZ)/totalZ;
2360 tmpString.Printf(_T(" %d %c %d/%d %d"), (int)porcent , 37 , z-minZ+1, (int)totalZ ,z);
2362 interfMainPanel::getInstance()->setStringInfoPanel(tmpString);
2363 //_staticTextInformation->SetLabel(tmpString);
2365 //Extraction data from contours of each slice
2366 _contourextractdata->SetZtoBeAnalys(z);
2369 Instant instant(&tempVector);
2370 std::vector<ContourThing**> lstContourThings = kernelManager->getOutlinesAtInstant( &instant );
2371 sizeLstContourThings = lstContourThings.size();
2373 lstManConMod.clear();
2374 for (ii=0 ; ii<sizeLstContourThings ; ii++)
2376 ContourThing **contourthing = lstContourThings[ii];
2377 lstManConMod.push_back( (*contourthing)->getModel() );
2380 lstManConModExp = kernelManager->ExploseEachModel( lstManConMod );
2382 tempString.Printf(_T("%d - %d"),z, sizeLstContourThings);
2383 interfMainPanel::getInstance()->setRowLabelInfoPanel(z, tempString);
2384 //_grid->SetRowLabelValue(z, tempString );
2386 int iContourGroup,sizeContourGroup;
2387 if (typeContourGroup==3) // contour separete
2389 sizeContourGroup=lstManConModExp.size();
2390 if ( maxContourGroup<sizeContourGroup )
2392 maxContourGroup=sizeContourGroup;
2394 } else { // contour AND OR XOR
2401 for( iContourGroup=0 ; iContourGroup<sizeContourGroup ; iContourGroup++ ){
2402 lstManConModTmp.clear();
2406 if (typeContourGroup==3) // contour separete
2408 lstManConModTmp.push_back( lstManConModExp[iContourGroup]);
2409 } else { // contour AND OR XOR
2410 lstManConModTmp = lstManConModExp;
2413 _contourextractdata->SetLstManualContourModel( lstManConModTmp );
2416 pLstValuePosX.clear();
2417 pLstValuePosY.clear();
2418 pLstValuePosZ.clear();
2419 _contourextractdata->GetValuesInsideCrown( &pLstValue,
2424 // Statistics of each slice.
2425 _contourextractdata->Statistics( &pLstValue,
2428 &resultGrayRangeCount,
2433 &resultStandardeviation);
2435 if (interfMainPanel::getInstance()->getNumberColsInformationPanel()<_numberOfVariablesStatistics*(iContourGroup+1) )
2437 interfMainPanel::getInstance()->appendColsInformationPanel(_numberOfVariablesStatistics);
2440 tmpIntA=_numberOfVariablesStatistics*iContourGroup ;
2442 tempString.Printf(_T("%d"),resultSize);
2443 interfMainPanel::getInstance()->setCellValueInfoPanel(z, tmpIntA, tempString);
2445 tempString.Printf(_T("%d"),resultGrayRangeCount);
2446 interfMainPanel::getInstance()->setCellValueInfoPanel(z, tmpIntA+1, tempString);
2448 tempString.Printf(_T("%f"),resultMin);
2449 interfMainPanel::getInstance()->setCellValueInfoPanel(z, tmpIntA+2, tempString);
2451 tempString.Printf(_T("%f"),resultMax);
2452 interfMainPanel::getInstance()->setCellValueInfoPanel(z, tmpIntA+3, tempString);
2454 tempString.Printf(_T("%f"),resultAverage);
2455 interfMainPanel::getInstance()->setCellValueInfoPanel(z, tmpIntA+4, tempString);
2457 tempString.Printf(_T("%f"),resultStandardeviation);
2458 interfMainPanel::getInstance()->setCellValueInfoPanel(z, tmpIntA+5, tempString);
2461 } // for iContourGroup
2464 // Print Volume Statistics
2467 int vol_rCountRange;
2469 double vol_minValue;
2470 double vol_maxValue;
2472 double vol_standardeviation;
2474 if (selection!=0 ) // actual slice
2477 _contourextractdata->GetVolumeStatistics(&vol_rCountRange, &vol_rsize,
2478 &vol_minValue, &vol_maxValue,
2479 &vol_average, &vol_standardeviation);
2481 interfMainPanel::getInstance()->setRowLabelInfoPanel(maxZ+2, _T("Total:"));
2483 tempString.Printf(_T("%d"),vol_rsize);
2484 interfMainPanel::getInstance()->setCellValueInfoPanel(maxZ+2, 0, tempString);
2486 tempString.Printf(_T("%d"),vol_rCountRange);
2487 interfMainPanel::getInstance()->setCellValueInfoPanel(maxZ+2, 1, tempString);
2489 tempString.Printf(_T("%f"),vol_minValue);
2490 interfMainPanel::getInstance()->setCellValueInfoPanel(maxZ+2, 2, tempString);
2492 tempString.Printf(_T("%f"),vol_maxValue);
2493 interfMainPanel::getInstance()->setCellValueInfoPanel(maxZ+2, 3, tempString);
2495 tempString.Printf(_T("%f"),vol_average);
2496 interfMainPanel::getInstance()->setCellValueInfoPanel(maxZ+2, 4, tempString);
2498 tempString.Printf(_T("%f"),vol_standardeviation);
2499 interfMainPanel::getInstance()->setCellValueInfoPanel(maxZ+2, 5, tempString);
2501 //-----------------------------------------
2504 wxString tmpTitleString;
2506 for ( iTitleGroup=0 ; iTitleGroup<maxContourGroup ; iTitleGroup++ )
2508 tmpIntB =_numberOfVariablesStatistics*iTitleGroup;
2509 tmpTitleString.Printf(_T("%d-Size Data"),iTitleGroup);
2510 interfMainPanel::getInstance()->setColLableInfoPanel(tmpIntB + 0, tmpTitleString);
2512 interfMainPanel::getInstance()->setColLableInfoPanel(tmpIntB + 0, tmpTitleString );
2513 interfMainPanel::getInstance()->setColLableInfoPanel( tmpIntB + 1, _T("Size Range") );
2514 interfMainPanel::getInstance()->setColLableInfoPanel( tmpIntB + 2, _T("Min") );
2515 interfMainPanel::getInstance()->setColLableInfoPanel( tmpIntB + 3, _T("Max") );
2516 interfMainPanel::getInstance()->setColLableInfoPanel( tmpIntB + 4, _T("Average") );
2517 interfMainPanel::getInstance()->setColLableInfoPanel( tmpIntB + 5, _T("St.Dev.") );
2518 interfMainPanel::getInstance()->setColLableInfoPanel( tmpIntB + 6, _T(" ") );
2520 interfMainPanel::getInstance()->setStringInfoPanel( _T("") );
2524 void wxContourMainFrame::onSaveResults(std::string directory,std::string namefile, std::string filename,
2525 int typeContourGroup, int selection, int minZ, int maxZ, bool XYZValues, bool contourImage, bool statistics)
2529 SaveValuesXYZ( directory , namefile, typeContourGroup );
2534 vtkImageData * mask;
2535 vtkImageData * value;
2536 this->getMaskValue(&mask, &value, typeContourGroup,selection,minZ,maxZ);
2537 this->SaveImageResult( directory , namefile, mask, value);
2542 std::ostringstream name;
2543 name << filename << ".xls";
2546 FILE *pFile=fopen(name.str().c_str(),"w+");
2552 // int sizeZ = _theViewPanel->GetImageDataSizeZ();
2553 // int maxY=sizeZ+2;
2555 maxX= interfMainPanel::getInstance()->getNumberColsInformationPanel();//this->_grid->GetNumberCols();
2558 int iTitle,sizeTitle = (maxX / _numberOfVariablesStatistics);
2559 for ( iTitle=0; iTitle<sizeTitle ; iTitle++)
2561 // fprintf(pFile,"-- \t %d-Size \t SizeRange \t Min \t Max \t Ave \t StDv \t" , iTitle,tmpString.c_str() );
2562 fprintf(pFile,"slice\t %d-Size \t SizeRange \t Min \t Max \t Ave \t StDv \t" , iTitle );
2564 fprintf(pFile,"\n\n" );
2568 if (selection==0 ) // actual slice
2570 std::vector<int> tempVector;
2571 _instantPanel->getInstant( tempVector );
2572 int actualSlice = tempVector[1];
2578 for ( j=minZ; j<=maxZ ; j++)
2580 fprintf(pFile,"%d\t" , j );
2581 for (i=0 ; i<maxX ; i++){
2582 tmpString = interfMainPanel::getInstance()->getCellValue(j, i);//_grid->GetCellValue( j , i );
2583 fprintf(pFile,"%s\t" , (const char *)(tmpString.mb_str()) );
2585 fprintf(pFile,"\n" );
2589 // Total of stadistics.....
2592 fprintf(pFile,"\n Total:\t" );
2593 for (i=0 ; i<maxX ; i++){
2594 tmpString = interfMainPanel::getInstance()->getCellValue(maxZ+2, i);//_grid->GetCellValue( maxZ+2 , i );
2595 fprintf(pFile,"%s\t" , (const char *)(tmpString.mb_str()) );
2597 fprintf(pFile,"\n" );
2605 void wxContourMainFrame::SaveValuesXYZ(std::string directory,std::string namefile,int typeContourGroup)
2608 //EED01Juillet2009 GenerateContourExtractData();
2610 //int typeContourGroup = this->_radiolstboxContourGroup->GetSelection();
2611 _contourextractdata ->SetTypeOperation( typeContourGroup % 3 );
2613 std::vector<manualBaseModel*> lstManConMod;
2614 std::vector<manualBaseModel*> lstManConModTmp;
2615 std::vector<manualBaseModel*> lstManConModExp;
2616 std::vector<double> pLstValue;
2617 std::vector<double> pLstValuePosX;
2618 std::vector<double> pLstValuePosY;
2619 std::vector<double> pLstValuePosZ;
2621 std::vector<int> tempVector;
2622 _instantPanel->getInstant( tempVector );
2624 //EED01Juillet2009 vtkImageData *imagedata = _theViewPanel->getSceneManager()->GetImageData();
2625 int sizeZ = _theViewPanel->getSceneManager()->GetImageDataSizeZ();
2627 int ii,sizeLstContourThings;
2634 minZ = 0;// _mbarrange->GetStart();
2635 maxZ = sizeZ;//_mbarrange->GetEnd();
2636 totalZ = maxZ-minZ+1;
2638 //EED01Juillet2009 _contourextractdata->SetImage( imagedata);
2641 for ( z=0 ; z<sizeZ ; z++)
2644 porcent = 100.0* (z-minZ)/totalZ;
2646 tmpString.Printf(_T("Saving Values"));
2647 tmpString.Printf(_T(" %d %c %d/%d %d"), (int)porcent , 37 , z-minZ+1, (int)totalZ ,z);
2648 interfMainPanel::getInstance()->setStringInfoPanel(tmpString);
2649 //_staticTextInformation->SetLabel(tmpString);
2652 //Extraction data from contours of each slice
2653 _contourextractdata->SetZtoBeAnalys( z);
2656 Instant instant(&tempVector);
2657 std::vector<ContourThing**> lstContourThings = kernelManager->getOutlinesAtInstant(&instant);//this->_modelManager->getOutlinesAtInstant( &instant );
2658 sizeLstContourThings = lstContourThings.size();
2660 lstManConMod.clear();
2661 for (ii=0 ; ii<sizeLstContourThings ; ii++)
2663 ContourThing **contourthing = lstContourThings[ii];
2664 lstManConMod.push_back( (*contourthing)->getModel() );
2666 lstManConModExp = kernelManager->ExploseEachModel( lstManConMod );
2671 int iContourGroup,sizeContourGroup;
2672 if (typeContourGroup==3) // contour separete
2674 sizeContourGroup=lstManConModExp.size();
2675 } else { // contour AND OR XOR
2679 for( iContourGroup=0 ; iContourGroup<sizeContourGroup ; iContourGroup++ ){
2680 lstManConModTmp.clear();
2681 if (typeContourGroup==3) // contour separete
2683 lstManConModTmp.push_back( lstManConModExp[iContourGroup]);
2684 } else { // contour AND OR XOR
2685 lstManConModTmp = lstManConModExp;
2688 _contourextractdata->SetLstManualContourModel( lstManConModTmp );
2691 pLstValuePosX.clear();
2692 pLstValuePosY.clear();
2693 pLstValuePosZ.clear();
2694 _contourextractdata->GetValuesInsideCrown( &pLstValue,
2699 std::string temp = directory + "/" + namefile + "-slice";
2700 temp = temp + kernelManager->intToString(z) + "-cont" + kernelManager->intToString(iContourGroup);
2701 temp = temp + ".txt";
2703 // LG 14/01/09 : using crea
2704 wxString filename = crea::std2wx(temp);
2705 /*filename.Printf(_T("%s"),directory.c_str());
2706 filename.append(_T("\\"));
2707 filename.append(_T("%s"),namefile.c_str());
2708 filename.append(_T("-slice"));
2709 filename.append(_T("%d"),z);
2710 filename.append(_T("-cont"));
2711 filename.append(_T("%d"),iContourGroup);
2712 filename.append(_T(".txt"));*/
2713 // filename.Printf(temp.c_str());
2717 FILE *pFile=fopen((const char *)filename.mb_str(),"w+");
2718 fprintf(pFile,"value \t x \t y \t z\n" );
2719 int iLstValue,sizeLstValue=pLstValue.size();
2720 for (iLstValue=0 ; iLstValue<sizeLstValue ; iLstValue++ )
2722 fprintf(pFile,"%f\t %f\t %f\t %f\n", (float)pLstValue[iLstValue] , (float)pLstValuePosX[iLstValue], (float)pLstValuePosY[iLstValue], (float)z );
2725 } // for iContourGroup
2727 interfMainPanel::getInstance()->setStringInfoPanel(_T(""));
2728 //_staticTextInformation->SetLabel( _T("") );
2732 void wxContourMainFrame::getMaskValue(vtkImageData ** mask,vtkImageData ** value,int typeContourGroup, int selection, int minZ, int maxZ){
2734 //EED01Juillet2009 GenerateContourExtractData();
2736 //int typeContourGroup = this->_radiolstboxContourGroup->GetSelection();
2737 if (typeContourGroup==3)
2741 _contourextractdata ->SetTypeOperation( typeContourGroup % 3 );
2743 std::vector<manualBaseModel*> lstManConMod;
2744 std::vector<manualBaseModel*> lstManConModTmp;
2745 std::vector<manualBaseModel*> lstManConModExp;
2747 std::vector<int> tempVector;
2748 _instantPanel->getInstant( tempVector );
2750 vtkImageData *imagedata = _theViewPanel->getImageData();
2752 imagedata->GetExtent(ext);
2753 int sizeZimage = ext[5]-ext[4]+1;
2755 int ii,sizeLstContourThings;
2764 if (selection==0 ) // actual slice
2766 int actualSlice = tempVector[1];
2773 //EED01Juillet2009 _contourextractdata->SetImage( imagedata);
2775 // cleanning image before range
2776 for (z=0; z<minZ; z++){
2777 _contourextractdata->ResetImageResult(z);
2779 // cleanning image after range
2780 for (z=maxZ+1; z<sizeZimage; z++){
2781 _contourextractdata->ResetImageResult(z);
2786 for ( z=minZ ; z<=maxZ ; z++)
2789 porcent = 100.0* (z-minZ)/totalZ;
2790 tmpString.Printf(_T("Saving Values"));
2791 tmpString.Printf(_T("%d %c %d/%d %d"), (int)porcent , 37 , z-minZ+1, (int)totalZ ,z);
2792 interfMainPanel::getInstance()->setStringInfoPanel(tmpString);
2794 //Extraction data from contours of each slice
2795 _contourextractdata->SetZtoBeAnalys( z);
2798 Instant instant(&tempVector);
2799 std::vector<ContourThing**> lstContourThings = kernelManager->getOutlinesAtInstant( &instant );
2800 sizeLstContourThings = lstContourThings.size();
2802 lstManConMod.clear();
2803 for (ii=0 ; ii<sizeLstContourThings ; ii++)
2805 ContourThing **contourthing = lstContourThings[ii];
2806 lstManConMod.push_back( (*contourthing)->getModel() );
2808 lstManConModExp = kernelManager->ExploseEachModel( lstManConMod );
2811 int iContourGroup,sizeContourGroup;
2812 if (typeContourGroup==3) // contour separete
2814 sizeContourGroup=lstManConModExp.size();
2815 } else { // contour AND OR XOR
2819 for( iContourGroup=0 ; iContourGroup<sizeContourGroup ; iContourGroup++ ){
2820 lstManConModTmp.clear();
2821 if (typeContourGroup==3) // contour separete
2823 lstManConModTmp.push_back( lstManConModExp[iContourGroup]);
2824 } else { // contour AND OR XOR
2825 lstManConModTmp = lstManConModExp;
2828 _contourextractdata->SetLstManualContourModel( lstManConModTmp );
2829 _contourextractdata->CalculateImageResult(); // with actual Z
2831 } // for iContourGroup
2834 (*value) = _contourextractdata->GetVtkImageValueResult();
2835 (*mask) = _contourextractdata->GetVtkImageMaskResult();
2839 void wxContourMainFrame::SaveImageResult(std::string directory,std::string namefile, vtkImageData* mask,vtkImageData* value)
2842 std::string temp = directory + "/" + namefile + "-Value.mhd";
2844 wxString filename = crea::std2wx(temp);
2846 // filename.Printf(_T(temp.c_str()));
2847 //filename.Printf(_T("%s\\%s-Value.mhd",directory.c_str(),namefile.c_str(),z);
2848 /*filename.Printf(_T("%s"),directory.c_str());
2849 filename.append(_T("\\"));
2850 filename.append(_T("%s"),namefile.c_str());
2851 filename.append(_T("-Value.mhd"));*/
2854 vtkMetaImageWriter *writerValueImage = vtkMetaImageWriter::New( );
2855 writerValueImage->SetInput( value );
2856 writerValueImage->SetFileName( (const char *)filename.mb_str() );
2857 writerValueImage->SetFileDimensionality( 3 );
2858 writerValueImage->Write( );
2861 // filename.Printf("%s\\%s-Mask.mhd",directory.c_str(),namefile.c_str(),z);
2862 temp = directory + "/" + namefile + "-Mask.mhd";
2864 // LG 14/01/09 : using crea
2865 filename = crea::std2wx(temp);
2866 // filename.Printf(_T(temp.c_str()));
2868 /*filename.Printf(_T("%s"),directory.c_str());
2869 filename.append(_T("\\"));
2870 filename.append(_T("%s"),namefile.c_str());
2871 filename.append(_T("-Mask.mhd"));*/
2873 vtkMetaImageWriter *writerMaskImage = vtkMetaImageWriter::New( );
2874 writerMaskImage->SetInput( mask );
2875 writerMaskImage->SetFileName( (const char *)filename.mb_str() );
2876 writerMaskImage->SetFileDimensionality( 3 );
2877 writerMaskImage->Write( );
2879 interfMainPanel::getInstance()->setStringInfoPanel( _T("") );
2885 void wxContourMainFrame::onChangeInstantInstantPanel(std::string name,int value, int minshow, int maxshow){
2886 if( name.compare( _theViewPanel->getVerticalConceptName() ) == 0){
2887 _theViewPanel->setActualVertical( value);
2889 else if( name.compare( _theViewPanel->getHorizontalConceptName() ) == 0|| _instantPanel->getIfConceptCheckedAt( name, 0 ) ) {
2890 _theViewPanel->setHorizontalConcept( name, minshow, maxshow, minshow, maxshow, value);
2896 void wxContourMainFrame::onSnakePressed(){
2897 std::vector<double> vecX;
2898 std::vector<double> vecY;
2899 std::vector<double> vecZ;
2900 _theViewPanel->GetPointsOfActualContour( &vecX , &vecY , &vecZ );
2902 if (vecX.size()!=0){
2903 std::vector<int> tempVector;
2904 _instantPanel->getInstant( tempVector );
2905 int i,size=vecZ.size();
2906 int actualSlice = tempVector[1];
2907 for ( i=0 ; i<size ; i++ )
2909 vecZ[i] = actualSlice;
2912 wxDialog* dialog = new wxDialog(this, -1, wxString(_T("Snake")));
2913 wxPanel* panel = new wxPanel(dialog,-1);
2914 // wxStaticText* sttext = new wxStaticText(panel, -1, wxString(_T("Panel para snake")));
2915 new wxStaticText(panel, -1, wxString(_T("Panel para snake")));
2916 dialog->ShowModal();
2921 void wxContourMainFrame::saveFileWithContoursAutomatique(){
2922 std::string filename = kernelManager->getCurrentFileName();
2923 if(filename.compare("")!=0){
2924 saveFileWithContours(filename);
2929 void wxContourMainFrame::ShowToolsPanel(bool show){
2930 _pannew->Show(show);
2935 void wxContourMainFrame::SetContourGroup(int contourGroup)
2937 _contourGroup = contourGroup;
2941 wxPanel *wxContourMainFrame::getMaskImageViewPanel(wxWindow *parent)
2944 if (_viewMaskImagePanel==NULL)
2946 _contourextractdata = new ContourExtractData(true);
2947 _contourextractdata->SetImage( _theViewPanel->getImageData() );
2950 // _theViewPanel->getImageData()->GetScalarRange(range);
2951 //int min = (int)floor (range[0]);
2952 //int max = (int)ceil (range[1]);
2956 _viewMaskImagePanel = new ThresholdImageViewPanel( parent, -1, -1 , 0);
2957 _viewMaskImage = new ThresholdImageView();
2958 _viewMaskImage->SetImage(_contourextractdata->GetVtkImageMaskResult() );
2959 _viewMaskImage->SetminMaxValue( min, max);
2960 _viewMaskImage->SetBaseColor( 0,0,1 );
2961 _viewMaskImagePanel->SetThresholdImageView( _viewMaskImage );
2962 _viewMaskImage->SetwxVtkBaseView( _theViewPanel->getWxVtkBaseView() );
2965 return _viewMaskImagePanel;
2968 wxPanel *wxContourMainFrame::getThresholdImageViewPanel(wxWindow *parent)
2970 if (_viewThresholdImagePanel==NULL)
2973 _theViewPanel->getImageData()->GetScalarRange(range);
2974 int min = (int)floor (range[0]);
2975 int max = (int)ceil (range[1]);
2976 _viewThresholdImagePanel = new ThresholdImageViewPanel( parent, min, max , 1);
2977 _viewThresholdImage = new ThresholdImageView();
2978 _viewThresholdImage->SetImage( _theViewPanel->getImageData() );
2979 _viewThresholdImage->SetminMaxValue( min, max);
2980 _viewThresholdImage->SetBaseColor( 1,0,0 );
2981 _viewThresholdImagePanel->SetThresholdImageView( _viewThresholdImage );
2982 _viewThresholdImage->SetwxVtkBaseView( _theViewPanel->getWxVtkBaseView() );
2984 return _viewThresholdImagePanel;
2987 //CMRU 17-08-09-----------------------------------------------------------------------------------------------
2988 int wxContourMainFrame::getType ()
2991 std::vector<std::string> currentSelection = _theViewPanel->getSelectedObjects();
2993 if(!currentSelection.empty())
2995 std::string cloneName = currentSelection [0];
2996 manualBaseModel * manualModel = kernelManager->getOutlineByKeyName(cloneName);
2997 tipo = manualModel-> GetTypeModel();
3001 double wxContourMainFrame::getContourSizeInPixels()
3003 double contourSize = 0;
3005 std::vector<std::string> currentSelection = _theViewPanel->getSelectedObjects(); if(!currentSelection.empty())
3006 if(!currentSelection.empty())
3008 std::string cloneName = currentSelection [0];
3010 manualBaseModel * manualModel = kernelManager->getOutlineByKeyName(cloneName);//_modelManager->getOutlineByKeyName( cloneName )->getModel();
3011 contourSize = manualModel-> GetPathSize();
3015 manualBaseModel * wxContourMainFrame::getContour ()
3017 std::vector<std::string> currentSelection = _theViewPanel->getSelectedObjects();
3019 if(!currentSelection.empty())
3021 std::string cloneName = currentSelection [0];
3022 manualBaseModel * manualModel = kernelManager->getOutlineByKeyName(cloneName);//_modelManager->getOutlineByKeyName( cloneName )->getModel();
3027 void wxContourMainFrame::onPrintLabel (wxString label, manualBaseModel* manualModel)
3029 std::string labelAscii(label.ToAscii());
3030 int pos = labelAscii.find(" ");
3034 for (j=0 ; pos != string::npos;j++)
3036 labelAscii.replace( pos, 1, "_" );
3037 pos= labelAscii.find(" ");
3040 manualModel -> SetLabel(labelAscii);
3042 void wxContourMainFrame::onInsertCalculation(manualBaseModel* manualModel)
3044 double sizeInPixel = manualModel ->GetPathSize();
3045 double onePixelRealSize = interfMainPanel::getInstance()->GetPixelValue();;
3046 double realContourSize = sizeInPixel*onePixelRealSize;
3047 manualModel ->SetRealSize(realContourSize);
3050 double wxContourMainFrame::onePixelSize( double value)
3052 return _onePixelSize = value;
3055 std::string wxContourMainFrame::GetFileLocation()
3057 return _fileLocation;
3060 void wxContourMainFrame::SetFileLocation(std::string newFileLocation)
3062 _fileLocation = newFileLocation;
3063 std::cout<<"GETFILELOCATION:"<<_fileLocation<<std::endl;
3065 //------------------------------------------------------------------------------------------------------------