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 // RaC 10-09 --------------------------------------
350 void wxContourMainFrame::onCreateContourPolygon( ){
351 //JCP 20-10-08 Undo redo implementation
353 //JCP 20-10-08 Undo redo implementation
356 // RaC 10-09 --------------------------------------
358 //------------------------------------------------------------------------------------------------------------
360 void wxContourMainFrame :: onCreateContourBullEye(wxPanel* panel )
362 //Creating the manualBaseModel and including in the model
363 manualBaseModel * manModelContour = factoryManualContourModel(panel );
365 std::vector<int> instantVector;
366 _instantPanel->getInstant( instantVector );
367 std::string theName = kernelManager->createOutline(manModelContour, instantVector);
369 /*std::vector<int> instantVector;
370 _instantPanel->getInstant( instantVector );
372 theName= _modelManager->createOutline( manModelContour, instantVector );*/
373 bool addedModel = theName.compare("") != 0;//??
377 double spc[3];//Si no hay imagen pero hay contornos que spacing se pone por default
378 _theViewPanel->getSpacing(spc);
379 //Adding the manualContourControler to interface objects structure
380 //Adding the manualViewContour to interface objects structure
381 //_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.
382 _theViewPanel->getSceneManager()->configureViewControlTo( theName, manModelContour,spc , 4) ;
385 void wxContourMainFrame :: createContour( int typeContour )
387 //Creating the manualContourModel and including in the model
388 manualBaseModel * manModelContour = kernelManager->factoryManualContourModel(typeContour);
390 std::vector<int> instantVector;
391 _instantPanel->getInstant( instantVector );
392 std::string theName = kernelManager->createOutline(manModelContour, instantVector);
394 /*std::vector<int> instantVector;
395 _instantPanel->getInstant( instantVector );
397 theName= _modelManager->createOutline( manModelContour, instantVector );*/
398 bool addedModel = theName.compare("") != 0;//??
401 double spc[3];//Si no hay imagen pero hay contornos que spacing se pone por default
402 _theViewPanel->getSpacing(spc);
403 //Adding the manualContourControler to interface objects structure
404 //Adding the manualViewContour to interface objects structure
405 //_sceneManager->setControlActiveStateOfALL( false );//This call is being done here because if the ROI is created underneath the previously created ROIS will still be active.
406 _theViewPanel->getSceneManager()->configureViewControlTo( theName, manModelContour,spc , typeContour) ;
410 manualBaseModel * wxContourMainFrame::factoryManualContourModel(wxPanel* panel){
412 manualContourModelBullEye *manModelContourBullEye = new manualContourModelBullEye();
413 manualBaseModel *manModelContour=NULL;
414 manModelContour = manModelContourBullEye;
416 int iCrown,sizeCrowns,iSector,sizeSectors;
417 double radioA,radioB,ang,angDelta ;
418 sizeCrowns = ((PanelBullEyeOptions*)panel)->GetNumberOfCrowns();
419 for ( iCrown=0 ; iCrown<sizeCrowns ; iCrown++ )
421 sizeSectors = ((PanelBullEyeOptions*)panel)->GetNumberOfSections(iCrown);
422 radioB = ((PanelBullEyeOptions*)panel)->GetRadioOfCrown(iCrown);
423 if (iCrown==sizeCrowns-1)
427 radioA = ((PanelBullEyeOptions*)panel)->GetRadioOfCrown(iCrown+1);
431 for ( iSector=0 ; iSector<sizeSectors ; iSector++ )
433 ang = ((PanelBullEyeOptions*)panel)->GetAngOfCrownSection(iCrown,iSector);
434 angDelta= ((PanelBullEyeOptions*)panel)->GetAngDeltaOfCrownSection(iCrown);
435 manModelContourBullEye->AddSector(radioA,radioB,ang,angDelta);
438 } // if _panelBullEyeOptions
440 return manModelContour;
442 void wxContourMainFrame :: saveState(){
444 std::string temp = kernelManager->saveState();
445 saveFileWithContours(temp);
448 void wxContourMainFrame::onDeleteContour(){
449 //JCP 20-10-08 Undo redo implementation
451 //JCP 20-10-08 Undo redo implementation
453 std::vector<std::string> lstKeyNameToBeErase;
454 lstKeyNameToBeErase = _theViewPanel->getSceneManager()->getSelectedObjects();
455 deleteContours( lstKeyNameToBeErase );
457 int i,size=_sceneManager->getSelectedObjects().size();
460 std::string keyName = _sceneManager->getSelectedObjects()[i];
461 int ispartofstaticlist = this->_modelManager->IsPartOfStaticList( keyName );
462 if ( ispartofstaticlist>=0 )
464 std::vector<int> tempVector;
465 _instantPanel->getInstant( tempVector );
466 Instant instant(&tempVector);
467 this->_modelManager->ChangeContourOfList(keyName, &instant);
471 std::vector<std::string> lstKeyName;
472 std::vector<std::string> lstKeyNameActualSlice;
473 std::vector<std::string> lstKeyNameToBeErase;
475 lstKeyNameToBeErase = _sceneManager->getSelectedObjects();
476 lstKeyNameActualSlice = _sceneManager->GetlstContoursNameActualSlice();
477 int k,kSize=lstKeyNameToBeErase.size();
478 int j,jSize=lstKeyNameActualSlice.size();
480 for (k=0;k<kSize; k++)
483 for (j=0;j<jSize; j++)
485 if (lstKeyNameToBeErase[k]==lstKeyNameActualSlice[j])
492 lstKeyName.push_back( lstKeyNameToBeErase[k] );
496 deleteContours( lstKeyName );
500 void wxContourMainFrame :: deleteContours( std::vector<std::string> keyNamesVector )
502 int i,size=keyNamesVector.size();
505 deleteContour( keyNamesVector[i] );
509 void wxContourMainFrame :: deleteContour( std::string theKeyName ){
511 manualContourModel * cModel;
512 manualViewBaseContour * cViewer;
513 manualContourBaseControler * cControler;
515 ContourWrap_ViewControl *conwrapviewControl = _theViewPanel->getSceneManager()->getContourWrap_ViewControlOf( theKeyName );
516 cControler = conwrapviewControl->getControler();*/
519 bool isedit = _theViewPanel->isEditableCControler(theKeyName);
520 bool ispartofstaticlst = kernelManager->IsPartOfStaticList(theKeyName);
522 if (isedit && ispartofstaticlst)
524 _theViewPanel->removeFromScene(theKeyName);
526 kernelManager->deleteCModel(theKeyName);
527 //_theViewPanel->getSceneManager()->removeFromScene( theKeyName );
528 //cViewer = conwrapviewControl->getViewer();
529 //_theViewPanel->getSceneManager()->removeWrap( theKeyName );
530 //cControler* conwrapviewControl->getControler();
533 // delete cControler;
538 void wxContourMainFrame::onDeleteContoursActSlice(){
539 //JCP 20-10-08 Undo redo implementation
541 //JCP 20-10-08 Undo redo implementation
542 deleteContours( (std::vector<std::string>)_theViewPanel->getSceneManager()->GetlstContoursNameActualSlice() );
544 void wxContourMainFrame::onDeleteAllContours(){
545 //JCP 20-10-08 Undo redo implementation
549 void wxContourMainFrame::deleteAllContours(){
550 //JCP 20-10-08 Undo redo implementation
553 std::vector<int> tempVector;
554 _instantPanel->getInstant( tempVector );
556 //JCP --08-09-2008 When using a diferent interface the _mbarrangeDeleteAll might not be initialize
557 // the values in GetStart and GetEnd will then not be initialize also.
558 // We use instead the values given when initializing the _deletepanel.
560 //int minZ = _mbarrangeDeleteAll->GetStart();
561 //int maxZ = _mbarrangeDeleteAll->GetEnd();
565 maxZ = _theViewPanel->getSceneManager()->GetImageDataSizeZ();
569 _theViewPanel->getSceneManager()->removeSceneContours( );
570 _theViewPanel->getSceneManager()->removeAllOutlines();
571 kernelManager->removeAllOutlines();
574 if ( (minZ==0) && (maxZ==_mbarrangeDeleteAll->GetMax() ))
576 _theViewPanel->getSceneManager()->removeSceneContours( );
577 _modelManager->removeAllOutlines();
578 _theViewPanel->getSceneManager()->removeAllOutlines();
581 for ( z=minZ ; z<=maxZ ; z++)
584 Instant instant(&tempVector);
585 std::vector<ContourThing**> lstContourThings = this->_modelManager->getOutlinesAtInstant( &instant );
587 sizeLstContourThings = lstContourThings.size();
588 for (ii=0 ; ii<sizeLstContourThings ; ii++)
590 ContourThing **contourthing = lstContourThings[ii];
591 deleteContour( (*contourthing)->getName() );
598 void wxContourMainFrame::setConceptValue( std::string name, int value ){
599 _instantPanel->setConceptValue(name, value);
603 ConceptDataWrap* wxContourMainFrame::getLastConceptData(){
604 return _instantPanel->getLastConceptData();
608 bool wxContourMainFrame::getIfConceptCheckedAt( std::string name, int pos ){
609 return _instantPanel->getIfConceptCheckedAt( name, pos );
614 void wxContourMainFrame::ShowResultImages(int typeContourGroup, int selection, int minZ, int maxZ)
617 vtkImageData * value;
618 this->getMaskValue(&mask, &value, typeContourGroup, selection, minZ, maxZ);
620 std::vector<int> nTypeView;
621 nTypeView.push_back(5);
622 nTypeView.push_back(1);
623 nTypeView.push_back(2);
624 nTypeView.push_back(0);
626 wxFrame *frame = new wxFrame(this, -1,_T("Result image extracted.."),wxDefaultPosition,wxSize(600,600), wxDEFAULT_FRAME_STYLE|wxSTAY_ON_TOP);
627 wxAuiManager *m_mgr_noteBookViewerResult = new wxAuiManager();
628 m_mgr_noteBookViewerResult->SetManagedWindow(frame);
630 wxAuiNotebook* noteBookViewerResult = new wxAuiNotebook(frame, -1, wxPoint(600, 600), wxSize(430,200), m_notebook_style);
631 m_mgr_noteBookViewerResult->AddPane(noteBookViewerResult, wxAuiPaneInfo().Name(wxT("notebook_content")).CenterPane().PaneBorder(false));
633 wxPanel *panelViewer1 = new wxMaracas_N_ViewersWidget(noteBookViewerResult, value,&nTypeView);
634 wxPanel *panelViewer2 = new wxMaracas_N_ViewersWidget(noteBookViewerResult, mask,&nTypeView);
637 noteBookViewerResult->AddPage( panelViewer1, wxT("Image result") );
638 noteBookViewerResult->AddPage( panelViewer2, wxT("Mask result") );
639 m_mgr_noteBookViewerResult->Update();
646 void wxContourMainFrame::changeInstant()
648 std::vector<int> instantVect;
649 _instantPanel->getInstant( instantVect );
650 int actualSlice = instantVect[1];
652 kernelManager->setInstant(instantVect);
654 // Refresh Mask image
655 if(_viewMaskImage!=NULL){
656 _viewMaskImage->SetZ(actualSlice);
657 if (_viewMaskImagePanel->IsVisible()==true)
659 vtkImageData *mask, *value;
660 getMaskValue(&mask,&value, _contourGroup , 0, -1, -1);
661 _viewMaskImage->onThreshold();
665 // Refresh Threshold image
666 if(_viewThresholdImage!=NULL){
667 _viewThresholdImage->SetZ(actualSlice);
668 if (_viewThresholdImagePanel->IsVisible()==true){
669 _viewThresholdImage->onThreshold();
673 updateInstantOutlines();
674 updateInstantImageData();
680 void wxContourMainFrame :: updateInstantOutlines()
682 _theViewPanel->removeSceneContours();
683 _theViewPanel->addNameWrapperToScene();
685 //for( int i=0; i<size; i++)
687 // _theViewPanel->getSceneManager()->addToScene(namesWrapping[i]->getKeyName(), true, true, true, false, false );
691 int wxContourMainFrame::getNamesWrappingSize(){
692 return kernelManager->getNamesWrappingSize();
694 std::string wxContourMainFrame::getNameWrapping(int i){
695 return kernelManager->getNameWrapping(i);
698 void wxContourMainFrame::updateInstantImageData()
700 std::vector<int> inst;
701 _instantPanel->getInstant(inst);
703 vtkImageData* img = kernelManager->getImageAtInstant(inst);
705 _theViewPanel->changeImage(img);
708 int z = _instantPanel->getConceptDataOf("Axe Depth")->getActualValue();
709 _theViewPanel->setImageSlice(z);
713 void wxContourMainFrame::updateInstantAxes()
718 void wxContourMainFrame::onChangeDeep(int val){
719 _instantPanel->setConceptValue( "Axe Depth", (int)val );
724 void wxContourMainFrame::onCopy(){
725 std::vector<std::string> currentSelection = _theViewPanel->getSelectedObjects();
727 std::vector<int> tempVector;
728 _instantPanel->getInstant( tempVector );
729 _performingOperation->reset();
730 _performingOperation->setStartCommand( COPY );
731 _performingOperation->setStartOperationInstantVector( tempVector );
732 _performingOperation->setKeyNamesOperationElems( currentSelection );
735 void wxContourMainFrame::onPaste(){
738 char theStartCommand = _performingOperation->getStartCommand();
739 if ( theStartCommand == COPY )
741 //JCP 20-10-08 Undo redo implementation
743 //JCP 20-10-08 Undo redo implementation
744 std::vector<int> tempVector;
745 _instantPanel->getInstant( tempVector );
746 _performingOperation->setEndOperationInstantVector ( tempVector );
747 std::vector<std::string> elems = _performingOperation->getKeyNamesOperationElems();
748 int i,size = elems.size();
749 for( i=0; i<size; i++ )
751 createCopyContourOf( elems[i], tempVector, i>0 );
755 void wxContourMainFrame::onUndo(){
756 std::string filename;
757 if(kernelManager->onUndoSaveFile(filename)){
758 saveFileWithContours(filename);
760 if(kernelManager->onUndo(filename)){
764 void wxContourMainFrame::onRedo(){
765 std::string filename;
766 if(kernelManager->onRedo(filename)){
771 void wxContourMainFrame :: createCopyContourOf ( std::string anExistingKName, std::vector<int> &instantNoTouchData, bool append )
773 std::string cloneName = kernelManager->createCopyContourOf( anExistingKName, instantNoTouchData );
774 manualBaseModel * manualModel = kernelManager->getOutlineByKeyName(cloneName);//_modelManager->getOutlineByKeyName( cloneName )->getModel();
775 _theViewPanel->getSceneManager()->createCopyContourOf( anExistingKName, cloneName, manualModel , append );
778 ///AD: 03-09 Copy the object and apply the given transformation
779 void wxContourMainFrame :: createMirrorContourOf ( std::string anExistingKName, std::vector<int> &instantNoTouchData, bool append )
781 std::string cloneName = kernelManager->createCopyContourOf( anExistingKName, instantNoTouchData );
782 manualBaseModel * manualModel = kernelManager->getOutlineByKeyName(cloneName);
784 manualPoint * refPoint1 = _refLineModel->GetManualPoint(0);
785 manualPoint * refPoint2 = _refLineModel->GetManualPoint(1);
787 double pnt1X = refPoint1->GetX();
788 double pnt1Y = refPoint1->GetY();
789 // double pnt1Z = refPoint1->GetZ();
790 double pnt2X = refPoint2->GetX();
791 double pnt2Y = refPoint2->GetY();
792 // double pnt2Z = refPoint2->GetZ();
794 double angle = (atan2(pnt2Y - pnt1Y, pnt2X - pnt1X) * 180 / 3.1415926535897932384626433832795)+90;
795 vtkTransform *t = vtkTransform::New();
799 t->Translate(-pnt1X, -pnt1Y, 0);
803 t->Translate(pnt1X, pnt1Y, 0);
806 int i,size=manualModel->GetSizeLstPoints();
809 manualPoint * mp = manualModel->GetManualPoint(i);
815 t->TransformPoint( vecIn, vecOut );
816 mp->SetPointX( vecOut[0] );
817 mp->SetPointY( vecOut[1] );
818 mp->SetPointZ( vecOut[2] );
821 _theViewPanel->getSceneManager()->createCopyContourOf( anExistingKName, cloneName, manualModel , append );
824 void wxContourMainFrame ::loadState(std::string filename){
826 FILE *pFile=fopen(filename.c_str(),"r+");
828 fscanf(pFile,"%s",tmp); // --CreaContour--
830 fscanf(pFile,"%s",tmp); // Version
831 fscanf(pFile,"%s",tmp); // 1.0.2 || 1.0.1 || 1.0.0
835 loadContours(pFile, false);
836 loadContours(pFile, true);
841 void wxContourMainFrame ::loadContours( FILE *pFile, bool staticContour )
845 fscanf(pFile,"%s",tmp); // ImageDimensions
846 fscanf(pFile,"%s",tmp); // X
847 fscanf(pFile,"%s",tmp); // Y
848 fscanf(pFile,"%s",tmp); // Z
850 fscanf(pFile,"%s",tmp); // ImageSpacing
851 fscanf(pFile,"%s",tmp); // X
852 fscanf(pFile,"%s",tmp); // Y
853 fscanf(pFile,"%s",tmp); // Z
855 fscanf(pFile,"%s",tmp); // NumberOfContours
856 fscanf(pFile,"%s",tmp); // ##
857 int numberOfContours = atoi(tmp);
859 std::vector<int> instantVector;
860 int typeContourModel;
861 manualBaseModel *manModelContour;
865 for (i=0;i<numberOfContours;i++)
867 instantVector.clear();
868 fscanf(pFile,"%s",tmp); // Instant
869 fscanf(pFile,"%s",tmp); // 1
870 instantVector.push_back( atoi(tmp) );
871 fscanf(pFile,"%s",tmp); // 2
872 instantVector.push_back( atoi(tmp) );
873 fscanf(pFile,"%s",tmp); // 3
874 instantVector.push_back( atoi(tmp) );
875 fscanf(pFile,"%s",tmp); // 4
876 instantVector.push_back( atoi(tmp) );
877 fscanf(pFile,"%s",tmp); // 5
878 instantVector.push_back( atoi(tmp) );
879 fscanf(pFile,"%s",tmp); // 6
880 instantVector.push_back( atoi(tmp) );
882 fscanf(pFile,"%s",tmp); // TypeContourModel
883 fscanf(pFile,"%s",tmp); // ##
884 typeContourModel = atoi(tmp);
886 manModelContour = kernelManager->factoryManualContourModel(typeContourModel);
887 manModelContour->Open(pFile);
889 fscanf(pFile,"%s",tmp); // TypeView
890 fscanf(pFile,"%s",tmp); // ##
891 typeView = atoi(tmp);
894 theName = kernelManager->createOutline( manModelContour, instantVector );
895 bool addedModel = theName.compare("") != 0;
898 double spc[3];//Si no hay imagen pero hay contornos que spacing se pone por default
899 _theViewPanel->getSpacing(spc);
900 //Adding the manualContourControler to interface objects structure
901 //Adding the manualViewContour to interface objects structure
902 //_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.
903 _theViewPanel->getSceneManager()->configureViewControlTo( theName, manModelContour,spc , typeView) ;
906 if (staticContour==true)
908 Instant instant(&instantVector);
909 kernelManager->changeContourOfManager( theName , &instant );
911 }// for numberOfContours
914 void wxContourMainFrame::onLoad()
916 std::string fileNameContourROI = GetFileLocation();
917 //CMRU 03-09-09-----------------------------------------------------------------------------------------------
918 if(GetFileLocation().empty())
920 //------------------------------------------------------------------------------------------------------------
921 wxFileDialog dialog(NULL, _T("Choose a file"), _T(""), _T(""), _T("*.roi"), wxOPEN );
922 if (dialog.ShowModal() == wxID_OK)
924 fileNameContourROI = (const char *)(dialog.GetPath().mb_str());
928 onLoadContours(fileNameContourROI);
931 void wxContourMainFrame::onLoadContours(std::string fileNameContourROI){
935 FILE *pFile =fopen(fileNameContourROI.c_str(),"r+");
938 //CMRU 03-09-09- ----------------------------------------------------------------------------------------------
941 //------------------------------------------------------------------------------------------------------------
942 fileNameContourROI.append("data");
943 FILE *pFileData=fopen(fileNameContourROI.c_str(),"r+");
944 if(pFileData != NULL)
946 fscanf(pFileData,"%s",tmpD); // --CreaContour--
947 fscanf(pFileData,"%s",tmpD); // Version
948 fscanf(pFileData,"%s",tmpD); // 1.0.2 || 1.0.1 || 1.0.0
950 fscanf(pFileData,"%s",tmpD); // onePixelSize
951 fscanf(pFileData,"%s",tmpD); // #
952 _onePixelSize = atof(tmpD);
953 fscanf(pFileData,"%s",tmpD); // NumberOfContours
954 fscanf(pFileData,"%s",tmpD); // #
957 fscanf(pFile,"%s",tmp); // --CreaContour--
959 fscanf(pFile,"%s",tmp); // Version
960 fscanf(pFile,"%s",tmp); // 1.0.2 || 1.0.1 || 1.0.0
961 std::string version(tmp);
964 if (version=="1.0.2")
966 openContours(pFile,pFileData,2,false);
967 openContours(pFile,pFileData,2,true); //Load StaticContours
971 else if (version=="1.0.1")
973 openContours(pFile,pFileData,1,false); //Skips ImageDimensions and ImageSpacing
974 openContours(pFile,pFileData,1,true); //Load StaticContours, skips ImageDimensions and ImageSpacing
978 else if (version=="1.0.0")
980 openContours(pFile,pFileData,1,false); //Skips ImageDimensions and ImageSpacing
985 if(pFileData != NULL)
990 _theViewPanel->getSceneManager()->removeSceneContours();
995 void wxContourMainFrame::onImport(){
996 std::string filename, filenamecontours;
997 wxFileDialog dialog(NULL, _T("Choose a XML Osirix File"), _T(""), _T(""), _T("*.xml"), wxOPEN );
999 if (dialog.ShowModal() == wxID_OK)
1001 filename = dialog.GetPath().mb_str();
1002 filenamecontours = kernelManager->parseOsirixFile(filename);
1004 if(filenamecontours.compare("") != 0){
1005 onLoadContours(filenamecontours);
1012 void wxContourMainFrame::onSave(){
1013 //CMRU 03-09-09-----------------------------------------------------------------------------------------------
1014 if(GetFileLocation().empty())
1016 //------------------------------------------------------------------------------------------------------------
1017 wxFileDialog dialog(NULL, _T("Choose a file"), _T(""), _T(""), _T("*.roi"), wxSAVE );
1018 if (dialog.ShowModal() == wxID_OK)
1020 std::string fileNameContourROI = (const char *)(dialog.GetPath().mb_str());
1021 kernelManager->setCurrentFileName(fileNameContourROI);
1022 saveFileWithContours( fileNameContourROI );
1025 //CMRU 03-09-09-----------------------------------------------------------------------------------------------
1028 std::cout<<"Nombre del archivo: "<<GetFileLocation()<<std::endl;
1029 std::string fileNameContourROI = GetFileLocation();
1030 std::cout<<"Nombre del archivo: "<<fileNameContourROI<<std::endl;
1031 kernelManager->setCurrentFileName(fileNameContourROI);
1032 saveFileWithContours( fileNameContourROI);
1034 //------------------------------------------------------------------------------------------------------------
1038 void wxContourMainFrame::saveFileWithContours( std::string filename )
1041 FILE *pFile=fopen(filename.c_str(),"w+");
1043 //CMRU 03-09-09-----------------------------------------------------------------------------------------------
1044 filename.append("data");
1045 std::cout<<"Nombre del archivo: "<<filename<<std::endl;
1046 FILE *pFileData=fopen(filename.c_str(),"w+");
1047 //------------------------------------------------------------------------------------------------------------
1049 std::vector< std::string > lstNameThings;
1050 int i,sizeLstNameThings;
1052 fprintf(pFile,"--CreaContour--\n");
1053 fprintf(pFile,"Version %s\n", "1.0.2" );
1055 //CMRU 03-09-09-----------------------------------------------------------------------------------------------
1056 fprintf(pFileData,"--CreaContour--\n");
1057 fprintf(pFileData,"Version %s\n", "1.0.2" );
1058 fprintf(pFileData,"OnePixelSize %f\n", _onePixelSize);
1060 //------------------------------------------------------------------------------------------------------------
1062 vtkImageData *image = _images[0];
1065 image->GetDimensions(dimRange);
1067 fprintf(pFile,"ImageDimensions %d %d %d\n", dimRange[0], dimRange[1], dimRange[2] );
1070 image->GetSpacing(spaRange);
1072 fprintf(pFile,"ImageSpacing %f %f %f\n", spaRange[0], spaRange[1], spaRange[2] );
1076 lstNameThings = kernelManager->GetLstNameThings();
1077 sizeLstNameThings = lstNameThings.size();
1078 fprintf(pFile,"NumberOfContours %d\n", sizeLstNameThings );
1080 //CMRU 03-09-09-----------------------------------------------------------------------------------------------
1081 fprintf(pFileData,"NumberOfContours %d\n", sizeLstNameThings );
1082 //------------------------------------------------------------------------------------------------------------
1084 for (i=0 ; i<sizeLstNameThings ; i++)
1086 //CMRU 03-09-09-----------------------------------------------------------------------------------------------
1087 manualBaseModel * manualModel = kernelManager->getOutlineByKeyName(lstNameThings[i]);
1088 double sizeInPixel = manualModel ->GetPathSize();
1089 double realContourSize = sizeInPixel*_onePixelSize;
1090 manualModel ->SetRealSize(realContourSize);
1091 //------------------------------------------------------------------------------------------------------------
1093 //int size= kernelManager->GetLstNameThings().size();
1095 kernelManager->SaveThingName( pFile, pFileData, lstNameThings[i] );
1096 _theViewPanel->getSceneManager()->SaveThingName( pFile, lstNameThings[i] );
1099 //-- Static Contours
1101 fprintf(pFile,"ImageDimensions %d %d %d\n", dimRange[0], dimRange[1], dimRange[2] );
1103 fprintf(pFile,"ImageSpacing %f %f %f\n", spaRange[0], spaRange[1], spaRange[2] );
1105 lstNameThings = kernelManager->GetLstNameThingsStatic();
1106 sizeLstNameThings = lstNameThings.size();
1107 fprintf(pFile,"NumberOfContoursStatic %d\n", sizeLstNameThings );
1109 //CMRU 03-09-09-----------------------------------------------------------------------------------------------
1110 fprintf(pFileData,"NumberOfContoursStatic %d\n", sizeLstNameThings );
1111 //------------------------------------------------------------------------------------------------------------
1113 for (i=0 ; i<sizeLstNameThings ; i++)
1115 kernelManager->SaveThingName( pFile, pFileData, lstNameThings[i] );
1116 _theViewPanel->getSceneManager()->SaveThingName( pFile, lstNameThings[i] );
1123 void wxContourMainFrame::openContours( FILE *pFile, FILE *pFileData, int version, bool staticContour )
1127 vtkImageData *image = _images[0];
1129 double imageSpac[3];
1133 bool compatible = true;
1138 image->GetDimensions(imageDim);
1139 image->GetSpacing(imageSpac);
1141 fscanf(pFile,"%s",tmp); // ImageDimensions
1142 fscanf(pFile,"%s",tmp); // X
1143 tempDim[0] = atoi(tmp);
1144 fscanf(pFile,"%s",tmp); // Y
1145 tempDim[1] = atoi(tmp);
1146 fscanf(pFile,"%s",tmp); // Z
1147 tempDim[2] = atoi(tmp);
1149 fscanf(pFile,"%s",tmp); // ImageSpacing
1150 fscanf(pFile,"%s",tmp); // X
1151 tempSpac[0] = atof(tmp);
1152 fscanf(pFile,"%s",tmp); // Y
1153 tempSpac[1] = atof(tmp);
1154 fscanf(pFile,"%s",tmp); // Z
1155 tempSpac[2] = atof(tmp);
1157 //Compare Spacing and Dims in X and Y (Necessary in Z?) - Just for Version 2
1158 if (imageDim[0]!=tempDim[0] || imageDim[1]!=tempDim[1] || imageSpac[0]!=tempSpac[0] || imageSpac[1]!=tempSpac[1])
1164 fscanf(pFile,"%s",tmp); // NumberOfContours
1165 fscanf(pFile,"%s",tmp); // ##
1166 int numberOfContours = atoi(tmp);
1168 std::vector<int> instantVector;
1169 int typeContourModel;
1170 manualBaseModel *manModelContour;
1173 if (compatible==true)
1176 for (i=0;i<numberOfContours;i++)
1178 instantVector.clear();
1179 fscanf(pFile,"%s",tmp); // Instant
1181 fscanf(pFile,"%s",tmp); // 1
1182 instantVector.push_back( atoi(tmp) );
1183 fscanf(pFile,"%s",tmp); // 2
1184 instantVector.push_back( atoi(tmp) );
1185 fscanf(pFile,"%s",tmp); // 3
1186 instantVector.push_back( atoi(tmp) );
1187 fscanf(pFile,"%s",tmp); // 4
1188 instantVector.push_back( atoi(tmp) );
1189 fscanf(pFile,"%s",tmp); // 5
1190 instantVector.push_back( atoi(tmp) );
1191 fscanf(pFile,"%s",tmp); // 6
1192 instantVector.push_back( atoi(tmp) );
1195 fscanf(pFile,"%s",tmp); // TypeContourModel
1196 fscanf(pFile,"%s",tmp); // ##
1197 typeContourModel = atoi(tmp);
1199 manModelContour = kernelManager->factoryManualContourModel(typeContourModel);
1200 manModelContour->Open(pFile);
1201 if(pFileData != NULL)
1203 manModelContour->OpenData(pFileData);
1206 fscanf(pFile,"%s",tmp); // TypeView
1207 fscanf(pFile,"%s",tmp); // ##
1208 typeView = atoi(tmp);
1210 std::string theName;
1211 theName = kernelManager->createOutline( manModelContour, instantVector );
1212 bool addedModel = theName.compare("") != 0;
1215 double spc[3];//Si no hay imagen pero hay contornos que spacing se pone por default
1216 _theViewPanel->getSpacing(spc);
1217 //Adding the manualContourControler to interface objects structure
1218 //Adding the manualViewContour to interface objects structure
1219 //_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.
1220 _theViewPanel->getSceneManager()->configureViewControlTo( theName, manModelContour,spc , typeView) ;
1223 if (staticContour) //StaticContours (will appear in all slices)
1225 Instant instant(&instantVector);
1226 kernelManager->changeContourOfManager( theName , &instant );
1229 }// for numberOfContours
1232 else if (compatible==false)
1234 wxDialog* dial = new wxDialog (this,-1,_T("Tools"),wxDefaultPosition, wxSize(260,160));
1235 wxSizer* buttonsSizer = dial->CreateSeparatedButtonSizer(wxOK|wxCANCEL);
1236 wxBoxSizer *dialSizer = new wxBoxSizer(wxVERTICAL);
1238 wxString lstOptOperation[2];
1239 lstOptOperation[0]=_T("By Dimension");
1240 lstOptOperation[1]=_T("By Spacing");
1241 wxRadioBox * radioOpts = new wxRadioBox(dial, -1, _T("Type of Transformation"), wxDefaultPosition, wxSize(270,45), 2 , lstOptOperation, 2, wxRA_SPECIFY_COLS);
1243 dialSizer->Add( new wxStaticText(dial,-1,_T("The image resolution is not compatible with the ")) , 0, wxGROW );
1244 dialSizer->Add( new wxStaticText(dial,-1,_T("selected Roi file. Do you want to tranform it?")) , 0, wxGROW );
1245 dialSizer->Add( new wxStaticText(dial,-1,_T(" ")) , 0, wxGROW );
1246 dialSizer->Add(radioOpts,0,wxGROW);
1247 dialSizer->Add( new wxStaticText(dial,-1,_T(" ")) , 0, wxGROW );
1248 dialSizer->Add(buttonsSizer,0,wxGROW);
1249 dial->SetSizer(dialSizer, true);
1253 int typeOfTransformation = -1;
1254 bool transform = false;
1256 if (dial->GetReturnCode() == wxID_OK)
1258 typeOfTransformation = radioOpts->GetSelection();
1263 for (i=0;i<numberOfContours;i++)
1265 instantVector.clear();
1266 fscanf(pFile,"%s",tmp); // Instant
1268 fscanf(pFile,"%s",tmp); // 1
1269 instantVector.push_back( atoi(tmp) );
1270 fscanf(pFile,"%s",tmp); // 2
1271 instantVector.push_back( atoi(tmp) );
1272 fscanf(pFile,"%s",tmp); // 3
1273 instantVector.push_back( atoi(tmp) );
1274 fscanf(pFile,"%s",tmp); // 4
1275 instantVector.push_back( atoi(tmp) );
1276 fscanf(pFile,"%s",tmp); // 5
1277 instantVector.push_back( atoi(tmp) );
1278 fscanf(pFile,"%s",tmp); // 6
1279 instantVector.push_back( atoi(tmp) );
1281 fscanf(pFile,"%s",tmp); // TypeContourModel
1282 fscanf(pFile,"%s",tmp); // ##
1283 typeContourModel = atoi(tmp);
1285 manModelContour = kernelManager->factoryManualContourModel(typeContourModel);
1286 manModelContour->Open(pFile);
1287 if(pFileData != NULL)
1289 manModelContour->OpenData(pFileData);
1291 if (transform==true)
1293 if (typeOfTransformation==0)
1295 double transX, transY;
1296 transX = (double) imageDim[0]/tempDim[0];
1297 transY = (double) imageDim[1]/tempDim[1];
1298 manModelContour->Transform_Ax_Plus_B(transX,0,transY,0);
1300 else if (typeOfTransformation==1)
1302 double transX, transY;
1303 transX = (double) tempSpac[0]/imageSpac[0];
1304 transY = (double) tempSpac[1]/imageSpac[1];
1305 manModelContour->Transform_Ax_Plus_B(transX,0,transY,0);
1309 fscanf(pFile,"%s",tmp); // TypeView
1310 fscanf(pFile,"%s",tmp); // ##
1311 typeView = atoi(tmp);
1313 std::string theName;
1314 theName = kernelManager->createOutline( manModelContour, instantVector );
1315 bool addedModel = theName.compare("") != 0;
1318 double spc[3];//Si no hay imagen pero hay contornos que spacing se pone por default
1319 _theViewPanel->getSpacing(spc);
1320 //Adding the manualContourControler to interface objects structure
1321 //Adding the manualViewContour to interface objects structure
1322 //_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.
1323 _theViewPanel->getSceneManager()->configureViewControlTo( theName, manModelContour,spc , typeView) ;
1326 if (staticContour) //StaticContours (will appear in all slices)
1328 Instant instant(&instantVector);
1329 kernelManager->changeContourOfManager( theName , &instant );
1331 }// for numberOfContours
1335 void wxContourMainFrame::RefreshInterface(){
1337 _theViewPanel->RefreshInterface();
1338 //wxVtk2DBaseView *wxvtk2dbaseview = (wxVtk2DBaseView*)this->_theViewPanel->getWxVtkBaseView();
1339 //wxvtk2dbaseview->Refresh();
1342 vtkImageData* wxContourMainFrame::getImageData(){
1343 return _theViewPanel->getImageData();
1346 void wxContourMainFrame::onSegmentationOneSliceITK(wxString distance, wxString sigma, wxString alfa, wxString beta, wxString propagation, wxString iterations, wxString inflation)
1348 //JCP 20-10-08 Undo redo implementation
1350 //JCP 20-10-08 Undo redo implementation
1353 int x = _theViewPanel->GetX();
1354 int y = _theViewPanel->GetY();
1355 int z = _theViewPanel->GetZ();
1356 SegmentationOneSliceITK( x,y,z,distance, sigma, alfa, beta, propagation, iterations, inflation);
1360 void wxContourMainFrame::SegmentationOneSliceITK(int x, int y, int z, wxString distanc, wxString sigm, wxString alf, wxString bet, wxString prop, wxString iter, wxString inflation)
1362 int typeofcontour = 1;
1364 vtkImageData *imagedata = getImageData();
1366 //Tipo de pixeles a utilizar internamente en ITK
1367 typedef float InternalPixelType;
1368 const unsigned int Dimension = 2;
1369 typedef itk::Image< InternalPixelType, Dimension > InternalImageType;
1371 //Tipo de pixeles de salida 1
1372 typedef unsigned char OutputPixelType;
1373 typedef itk::Image< OutputPixelType, Dimension > OutputImageType;
1375 //Tipo de pixeles de salida 2
1376 typedef unsigned short OutputPixelType2;
1377 typedef itk::Image< OutputPixelType2, Dimension > OutputImageType2;
1379 //DefiniciÛn del thresholder
1380 typedef itk::BinaryThresholdImageFilter<
1382 OutputImageType > ThresholdingFilterType;
1384 //DefiniciÛn del primer filtro de conversiÛn de pixeles
1385 typedef itk::CastImageFilter<
1386 OutputImageType, OutputImageType2 > CastFilterType;
1388 //DefiniciÛn del segundo tipo de conversiÛn de pixeles
1389 typedef itk::CastImageFilter<
1390 OutputImageType2, InternalImageType > CastFilterType2;
1392 //Tercer tipo de conversiÛn
1393 typedef itk::RescaleIntensityImageFilter<
1395 OutputImageType > CastFilterType3;
1397 //Cuarto tipo de conversiÛn
1398 typedef itk::RescaleIntensityImageFilter<
1400 OutputImageType > CastFilterType4;
1402 ThresholdingFilterType::Pointer thresholder = ThresholdingFilterType::New();
1404 thresholder->SetLowerThreshold( 0.0 );
1405 thresholder->SetUpperThreshold( 128 );
1407 thresholder->SetOutsideValue( 255 );
1408 thresholder->SetInsideValue( 0 );
1410 //DefinciÛn de conexiÛnes entre VTK e ITK y el writer
1411 typedef itk::VTKImageToImageFilter<OutputImageType2> ConnectorType;
1412 typedef itk::ImageToVTKImageFilter<OutputImageType> ConnectorType2;
1413 typedef itk::ImageFileWriter< OutputImageType > WriterType;
1415 ConnectorType::Pointer connector= ConnectorType::New();
1416 ConnectorType2::Pointer connector2= ConnectorType2::New();
1419 CastFilterType::Pointer filter=CastFilterType::New();
1420 CastFilterType2::Pointer filter2=CastFilterType2::New();
1422 connector->SetInput( imagedata );
1423 filter2->SetInput(connector->GetOutput());
1425 typedef itk::CurvatureAnisotropicDiffusionImageFilter<
1427 InternalImageType > SmoothingFilterType;
1429 SmoothingFilterType::Pointer smoothing = SmoothingFilterType::New();
1431 typedef itk::GradientMagnitudeRecursiveGaussianImageFilter<
1433 InternalImageType > GradientFilterType;
1435 typedef itk::SigmoidImageFilter<
1437 InternalImageType > SigmoidFilterType;
1439 GradientFilterType::Pointer gradientMagnitude = GradientFilterType::New();
1441 SigmoidFilterType::Pointer sigmoid = SigmoidFilterType::New();
1443 sigmoid->SetOutputMinimum( 0.0 );
1444 sigmoid->SetOutputMaximum( 255.0 );
1447 typedef itk::FastMarchingImageFilter<
1449 InternalImageType > FastMarchingFilterType;
1452 FastMarchingFilterType::Pointer fastMarching = FastMarchingFilterType::New();
1454 typedef itk::GeodesicActiveContourLevelSetImageFilter< InternalImageType,
1455 InternalImageType > GeodesicActiveContourFilterType;
1456 GeodesicActiveContourFilterType::Pointer geodesicActiveContour =
1457 GeodesicActiveContourFilterType::New();
1459 typedef itk::ZeroCrossingImageFilter<
1461 InternalImageType > ZeroCrossingFilterType;
1462 ZeroCrossingFilterType::Pointer zeroCrossing =
1463 ZeroCrossingFilterType::New();
1465 const double propagationScaling = atof( crea::wx2std(prop).c_str() );
1467 geodesicActiveContour->SetPropagationScaling( propagationScaling );
1468 geodesicActiveContour->SetCurvatureScaling( 1.0 );
1469 geodesicActiveContour->SetAdvectionScaling( 1.0 );
1471 geodesicActiveContour->SetMaximumRMSError( 0.02 );
1472 int it=atoi( crea::wx2std(iter).c_str() );
1473 geodesicActiveContour->SetNumberOfIterations( it );
1475 smoothing->SetInput( filter2->GetOutput() );
1476 gradientMagnitude->SetInput( smoothing->GetOutput() );
1477 sigmoid->SetInput( gradientMagnitude->GetOutput() );
1478 fastMarching->SetInput( sigmoid->GetOutput() );
1479 geodesicActiveContour->SetInput( fastMarching->GetOutput() );
1480 geodesicActiveContour->SetFeatureImage( sigmoid->GetOutput() );
1482 zeroCrossing->SetInput( geodesicActiveContour->GetOutput() );
1483 //thresholder->SetInput( zeroCrossing->GetOutput() );
1484 thresholder->SetInput( geodesicActiveContour->GetOutput() );
1485 connector2->SetInput( thresholder->GetOutput() );
1488 smoothing->SetTimeStep( 0.125 );
1489 smoothing->SetNumberOfIterations( 5 );
1490 smoothing->SetConductanceParameter( 9.0 );
1493 const double sigma = atof( crea::wx2std(sigm).c_str() );
1494 gradientMagnitude->SetSigma( sigma );
1496 const double alpha = atof( crea::wx2std(alf).c_str() );
1497 const double beta = atof( crea::wx2std(bet).c_str() );
1499 sigmoid->SetAlpha( alpha );
1500 sigmoid->SetBeta( beta );
1502 typedef FastMarchingFilterType::NodeContainer NodeContainer;
1503 typedef FastMarchingFilterType::NodeType NodeType;
1505 NodeContainer::Pointer seeds = NodeContainer::New();
1507 InternalImageType::IndexType seedPosition;
1508 seedPosition[0] = x;
1509 seedPosition[1] = y;
1511 const double initialDistance = atof( crea::wx2std(distanc).c_str() );
1515 const double seedValue = - initialDistance;
1517 node.SetValue( seedValue );
1518 node.SetIndex( seedPosition );
1520 seeds->Initialize();
1521 seeds->InsertElement( 0, node );
1523 fastMarching->SetTrialPoints( seeds );
1525 fastMarching->SetSpeedConstant( 1.0 );
1527 fastMarching->SetOutputSize(
1528 connector->GetOutput()->GetBufferedRegion().GetSize() );
1530 fastMarching->SetStoppingValue( 800 );
1534 connector2->Update();
1535 vtkImageData *idata = connector2->GetOutput();
1537 vtkMarchingContourFilter* cntVTK = vtkMarchingContourFilter::New( );
1539 cntVTK->SetInput( idata );
1541 cntVTK->SetNumberOfContours( 1 );
1542 cntVTK->SetValue( 0, 255 );
1544 cntVTK->UpdateInformation();
1546 vtkCleanPolyData* cpd = vtkCleanPolyData::New( );
1547 cpd->SetInput( cntVTK->GetOutput( ) );
1549 cpd->UpdateInformation();
1551 vtkPolyDataConnectivityFilter* conn = vtkPolyDataConnectivityFilter::New( );
1552 conn->SetExtractionModeToLargestRegion( );
1553 conn->SetInput( cpd->GetOutput( ) );
1555 conn->UpdateInformation();
1557 vtkStripper* vtkstripper = vtkStripper::New( );
1558 vtkstripper->SetInput( conn->GetOutput() );
1559 vtkstripper->Update();
1560 vtkstripper->UpdateInformation();
1563 vtkPolyData* polyDataResult = cntVTK->GetOutput();
1564 //std::cout<<"Points "<<polyDataResult->GetNumberOfPoints()<<std::endl;
1565 polyDataResult->Update( );
1566 polyDataResult->UpdateInformation();
1571 myfile.open ("C:/Creatis/example.txt");
1573 polyDataResult->Print(myfile);
1574 myfile << "-------------------------------------\n";
1575 polyDataResult->GetLines()->Print(myfile);
1583 //--Calculating control points
1585 std::vector<double> vecX;
1586 std::vector<double> vecY;
1587 std::vector<double> vecXo;
1588 std::vector<double> vecYo;
1589 std::vector<double>::iterator vecXoi;
1590 std::vector<double>::iterator vecYoi;
1591 std::vector<double> vecZ;
1593 std::vector<double> vecCtrlPointX;
1594 std::vector<double> vecCtrlPointY;
1595 std::vector<double> vecCtrlPointZ;
1601 int ii,size=polyDataResult->GetNumberOfPoints();
1603 myfile.open ("C:/Creatis/example2.txt");
1605 size=polyDataResult->GetNumberOfPoints();
1606 for (ii=0;ii<size;ii++)
1613 p = polyDataResult->GetPoint(ii);
1616 /*if(fabs(yAct-y)>20)
1618 if((xAct-x)>1 || (xAct-x)<-1)
1620 vecX.push_back( p[0] );
1621 vecY.push_back( p[1] );
1622 myfile <<p[0]<<","<<p[1]<<"\n";
1623 std::cout<<" x Anterior "<<xAct<<" x actual "<<x<<std::endl;
1624 std::cout<<" y Anterior "<<yAct<<" y actual "<<y<<std::endl;
1625 std::cout<<" x "<<p[0]<<" y "<<p[1]<<std::endl;
1626 vecZ.push_back( 900 );
1632 vecXo.push_back(p[0]);
1633 vecYo.push_back(p[1]);
1637 else*/ if(fabs(xAct-x)>11)
1639 vecXo.push_back(p[0]);
1640 vecYo.push_back(p[1]);
1644 vecX.push_back( p[0] );
1645 myfile <<p[0]<<","<<p[1]<<"\n";
1646 //std::cout<<" x Anterior "<<xAct<<" x actual "<<x<<std::endl;
1647 //std::cout<<" y Anterior "<<yAct<<" y actual "<<y<<std::endl;
1648 //std::cout<<" x "<<p[0]<<" y "<<p[1]<<std::endl;
1649 vecY.push_back( p[1] );
1650 vecZ.push_back( 900 );
1658 while(!vecXo.empty())
1660 vecX.push_back(vecXo.back());
1661 //std::cout<<" x Siguiente "<<vecXo.back();
1663 vecZ.push_back( 900 );
1665 while(!vecYo.empty())
1667 vecY.push_back(vecYo.back());
1672 /*for(int l=0;l<vecX.size();l++)
1676 vecXo.push_back(p[0]);
1677 vecYo.push_back(p[1]);
1688 ExtractControlPoints2D *extractcontrolpoints2d = new ExtractControlPoints2D();
1690 extractcontrolpoints2d->SetContour( &vecX , &vecY , &vecZ );
1694 extractcontrolpoints2d->GetInitialControlPoints( &vecCtrlPointX , &vecCtrlPointY , &vecCtrlPointZ );
1696 else if (method==1){
1697 extractcontrolpoints2d->GetControlPoints( &vecCtrlPointX , &vecCtrlPointY , &vecCtrlPointZ );
1699 else if (method==2){
1700 extractcontrolpoints2d->SetSamplingControlPoints( 15 );
1701 extractcontrolpoints2d->GetSamplingControlPoints( &vecCtrlPointX , &vecCtrlPointY , &vecCtrlPointZ );
1703 //--Adding contour to the system
1705 std::vector<int> actualInstantVector;
1706 _instantPanel->getInstant( actualInstantVector );
1707 actualInstantVector[1]=z;
1709 int j,sizeCtrPt = vecCtrlPointX.size();
1711 manualBaseModel *manModelContour = kernelManager->factoryManualContourModel( typeofcontour );
1712 manModelContour->SetNumberOfPointsSpline( ((sizeCtrPt/100)+1)*100 );
1714 for (j=0 ; j<sizeCtrPt ; j++)
1716 manModelContour->AddPoint( vecCtrlPointX[j] , vecCtrlPointY[j] , vecCtrlPointZ[j] );
1718 std::string theName;
1719 //theName = _modelManager->createOutline( manModelContour, actualInstantVector );
1720 theName = kernelManager->createOutline( manModelContour, actualInstantVector );
1721 bool addedModel = theName.compare("") != 0;
1724 double spc[3];//Si no hay imagen pero hay contornos que spacing se pone por default
1725 _theViewPanel->getSpacing(spc);
1726 //Adding the manualContourControler to interface objects structure
1727 //Adding the manualViewContour to interface objects structure
1728 //_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.
1729 _theViewPanel->configureViewControlTo(theName, manModelContour, spc, typeofcontour);
1730 //_theViewPanel->getSceneManager()->configureViewControlTo( theName, manModelContour,spc, typeofcontour ) ;
1736 WriterType::Pointer writer = WriterType::New();
1737 CastFilterType3::Pointer caster = CastFilterType3::New();
1739 caster->SetInput( gradientMagnitude->GetOutput() );
1740 writer->SetInput( caster->GetOutput() );
1741 writer->SetFileName("Gradient Magnitude.png");
1742 caster->SetOutputMinimum( 0 );
1743 caster->SetOutputMaximum( 255 );
1746 CastFilterType3::Pointer caster2 = CastFilterType3::New();
1747 WriterType::Pointer writer2 = WriterType::New();
1749 caster2->SetInput( sigmoid->GetOutput() );
1750 writer2->SetInput( caster2->GetOutput() );
1751 writer2->SetFileName("Sigmoid.png");
1752 caster2->SetOutputMinimum( 0 );
1753 caster2->SetOutputMaximum( 255 );
1756 CastFilterType3::Pointer caster3 = CastFilterType3::New();
1757 WriterType::Pointer writer3 = WriterType::New();
1759 caster3->SetInput( fastMarching->GetOutput() );
1760 writer3->SetInput( caster3->GetOutput() );
1761 writer3->SetFileName("FastMarching.bmp");
1762 caster3->SetOutputMinimum( 0 );
1763 caster3->SetOutputMaximum( 255 );
1766 CastFilterType3::Pointer caster4 = CastFilterType3::New();
1767 WriterType::Pointer writer4 = WriterType::New();
1769 caster4->SetInput( geodesicActiveContour->GetOutput() );
1770 writer4->SetInput( caster4->GetOutput() );
1771 writer4->SetFileName("GeodesicActiveContour.png");
1772 caster4->SetOutputMinimum( 0 );
1773 caster4->SetOutputMaximum( 255 );
1776 CastFilterType3::Pointer caster5 = CastFilterType3::New();
1777 WriterType::Pointer writer5 = WriterType::New();
1779 caster5->SetInput( zeroCrossing->GetOutput() );
1780 writer5->SetInput( caster5->GetOutput() );
1781 writer5->SetFileName("ZeroCrossing.bmp");
1782 caster5->SetOutputMinimum( 0 );
1783 caster5->SetOutputMaximum( 255 );
1786 catch( itk::ExceptionObject & excep )
1788 std::cerr << "Exception caught !" << std::endl;
1789 std::cerr << excep << std::endl;
1793 void wxContourMainFrame::onSegmentationOneSlice(int isovalue,int sampling,int method){
1795 //JCP 20-10-08 Undo redo implementation
1797 //JCP 20-10-08 Undo redo implementation
1800 int x = _theViewPanel->GetX();
1801 int y = _theViewPanel->GetY();
1802 int z = _theViewPanel->GetZ();
1803 SegmentationOneSlice( x,y,z,isovalue, sampling, method );
1808 void wxContourMainFrame::SegmentationOneSlice( int x, int y, int z, int isovalue, int sampling, int method )
1810 int typeofcontour = 1;
1811 //--Extracting Contour
1812 //vtkImageData *imagedata = _theViewPanel->getSceneManager()->GetImageData();
1813 vtkImageData *imagedata = getImageData();
1814 // double *range = imagedata->GetScalarRange();
1817 vtkImageReslice *imageReslice = vtkImageReslice::New();
1820 // imagedata->GetSpacing(spc);
1825 imageReslice->SetInput( imagedata );
1826 imageReslice->SetInformationInput(imagedata);
1827 imageReslice->SetResliceAxesDirectionCosines(1,0,0, 0,1,0 ,0,0,1);
1828 imageReslice->SetResliceAxesOrigin(0,0,z);
1829 imageReslice->SetOutputDimensionality(2);
1830 imageReslice->SetInterpolationModeToLinear();
1832 imagedata = imageReslice->GetOutput();
1833 imagedata->Update();
1834 imagedata->UpdateInformation();
1836 vtkContourFilter* cntVTK = vtkContourFilter::New( );
1837 cntVTK->SetInput( imagedata );
1839 cntVTK->SetNumberOfContours( 1 );
1840 //cntVTK->SetValue( 0, vmin );
1841 // cntVTK->SetValue( 0, (range[1]*thr/100) );
1842 cntVTK->SetValue( 1, isovalue );
1843 // cntVTK->SetValue( 1, vmax );
1845 cntVTK->UpdateInformation();
1847 vtkCleanPolyData* cpd = vtkCleanPolyData::New( );
1848 cpd->SetInput( cntVTK->GetOutput( ) );
1849 cpd->ConvertLinesToPointsOff( );
1851 cpd->UpdateInformation();
1853 vtkPolyDataConnectivityFilter* conn = vtkPolyDataConnectivityFilter::New( );
1854 conn->SetExtractionModeToClosestPointRegion( );
1855 //conn->SetMaxRecursionDepth( 3000 );
1857 conn->SetInput( cpd->GetOutput( ) );
1859 conn->SetClosestPoint( x, y, 0 );
1861 conn->UpdateInformation();
1863 vtkCleanPolyData* cpd2 = vtkCleanPolyData::New( );
1864 cpd2->SetInput( conn->GetOutput( ) );
1866 cpd2->UpdateInformation();
1868 vtkStripper* vtkstripper = vtkStripper::New( );
1869 vtkstripper->SetInput( cpd2->GetOutput() );
1870 vtkstripper->Update();
1871 vtkstripper->UpdateInformation();
1874 vtkPolyData* polyDataResult = vtkstripper->GetOutput();
1876 polyDataResult->Update( );
1877 polyDataResult->UpdateInformation();
1881 myfile.open ("c:/temp/example.txt");
1883 polyDataResult->Print(myfile);
1884 myfile << "-------------------------------------\n";
1885 polyDataResult->GetLines()->Print(myfile);
1895 //--Calculating control points
1897 std::vector<double> vecX;
1898 std::vector<double> vecY;
1899 std::vector<double> vecZ;
1901 std::vector<double> vecCtrlPointX;
1902 std::vector<double> vecCtrlPointY;
1903 std::vector<double> vecCtrlPointZ;
1907 int ii,size=polyDataResult->GetNumberOfPoints();
1909 for (ii=1;ii<=size;ii++)
1911 id = polyDataResult->GetLines()->GetData()->GetValue(ii);
1912 p = polyDataResult->GetPoint(id);
1915 vecX.push_back( p[0] );
1916 vecY.push_back( p[1] );
1917 vecZ.push_back( 900 );
1918 // vecZ.push_back( p[2] );
1922 ExtractControlPoints2D *extractcontrolpoints2d = new ExtractControlPoints2D();
1923 extractcontrolpoints2d->SetContour( &vecX , &vecY , &vecZ );
1926 /*if (methodRadiobox->GetSelection()==0){
1927 extractcontrolpoints2d->GetInitialControlPoints( &vecCtrlPointX , &vecCtrlPointY , &vecCtrlPointZ );
1929 if (methodRadiobox->GetSelection()==1){
1930 extractcontrolpoints2d->GetControlPoints( &vecCtrlPointX , &vecCtrlPointY , &vecCtrlPointZ );
1932 if (methodRadiobox->GetSelection()==2){
1933 extractcontrolpoints2d->SetSamplingControlPoints( sampling );
1934 extractcontrolpoints2d->GetSamplingControlPoints( &vecCtrlPointX , &vecCtrlPointY , &vecCtrlPointZ );
1938 extractcontrolpoints2d->GetInitialControlPoints( &vecCtrlPointX , &vecCtrlPointY , &vecCtrlPointZ );
1940 else if (method==1){
1941 extractcontrolpoints2d->GetControlPoints( &vecCtrlPointX , &vecCtrlPointY , &vecCtrlPointZ );
1943 else if (method==2){
1944 extractcontrolpoints2d->SetSamplingControlPoints( sampling );
1945 extractcontrolpoints2d->GetSamplingControlPoints( &vecCtrlPointX , &vecCtrlPointY , &vecCtrlPointZ );
1948 //--Adding contour to the system
1950 std::vector<int> actualInstantVector;
1951 _instantPanel->getInstant( actualInstantVector );
1952 actualInstantVector[1]=z;
1954 int j,sizeCtrPt = vecCtrlPointX.size();
1955 manualBaseModel *manModelContour = kernelManager->factoryManualContourModel( typeofcontour );
1956 manModelContour->SetNumberOfPointsSpline( ((sizeCtrPt/100)+1)*100 );
1958 for (j=0 ; j<sizeCtrPt ; j++)
1960 manModelContour->AddPoint( vecCtrlPointX[j] , vecCtrlPointY[j] , vecCtrlPointZ[j] );
1962 std::string theName;
1963 //theName = _modelManager->createOutline( manModelContour, actualInstantVector );
1964 theName = kernelManager->createOutline( manModelContour, actualInstantVector );
1965 bool addedModel = theName.compare("") != 0;
1968 double spc[3];//Si no hay imagen pero hay contornos que spacing se pone por default
1969 _theViewPanel->getSpacing(spc);
1970 //Adding the manualContourControler to interface objects structure
1971 //Adding the manualViewContour to interface objects structure
1972 //_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.
1973 _theViewPanel->configureViewControlTo(theName, manModelContour, spc, typeofcontour);
1974 //_theViewPanel->getSceneManager()->configureViewControlTo( theName, manModelContour,spc, typeofcontour ) ;
1978 int wxContourMainFrame::GetImageDataSizeZ(){
1979 return _theViewPanel->GetImageDataSizeZ();
1982 void wxContourMainFrame::GetImageDataRange(double *range){
1983 _theViewPanel->GetImageDataRange(range);
1986 void wxContourMainFrame::onSegmentationAllSlice(int minZ,int maxZ,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();
1997 double totalZ = maxZ-minZ+1;
1998 for( z=minZ ; z<=maxZ ; z++ )
2000 porcent = 100.0* (z-minZ)/totalZ;
2001 tmpString.Printf(_T(" %d %c %d/%d %d"), (int)porcent , 37 , z-minZ+1, (int)totalZ,z );
2002 interfMainPanel::getInstance()->setLabelSegmentationPanelVTK(tmpString);
2003 //_staticTextSegmentation->SetLabel(tmpString);
2004 SegmentationOneSlice( x,y,z,isovalue, sampling,method );
2006 interfMainPanel::getInstance()->setLabelSegmentationPanelVTK(_T(" "));
2011 //Creates a reference line to be used as the axis of the mirroring
2012 void wxContourMainFrame::referenceLine()
2014 if (_refLineControl==NULL)
2019 vtkImageData *vtkimagedata = _theViewPanel->getImageData();
2020 vtkimagedata->GetSpacing(spc);
2022 wxVtkBaseView * viewer2D = _theViewPanel->getWxVtkBaseView();
2024 _refLineControl = new manualLineControler();
2025 _refLineModel = new manualContourModelLine();
2026 _refLineView = new manualViewLine();
2027 _refLineView->SetModel( _refLineModel );
2028 _refLineView->SetWxVtkBaseView( viewer2D );
2029 _refLineView->SetRange( 2 );
2030 _refLineView->SetZ( 1200 );
2032 _refLineView->SetSpacing(spc);
2034 _refLineView->SetColorNormalContour(0, 0, 1);
2035 _refLineView->SetColorEditContour(0, 0.5, 0.5);
2036 _refLineView->SetWidthLine(4);
2038 _refLineControl->SetModelView( _refLineModel , _refLineView );
2039 vtkInteractorStyleBaseView* style = (vtkInteractorStyleBaseView*)viewer2D->GetInteractorStyleBaseView();
2040 style->AddInteractorStyleMaracas( _refLineControl );
2041 _refLineModel->SetCloseContour(false);
2042 _refLineControl->CreateNewManualContour();
2044 //AD: Inicializar el mirroring con una linea ya pintada
2046 double z = _refLineControl->GetZ();
2049 image->GetDimensions(imageDim);
2050 double x = (double) imageDim[0]/2;
2051 double y1 = (double) (imageDim[1]/2)+15;
2052 double y2 = (double) (imageDim[1]/2)-15;
2054 _refLineControl->AddPoint(x,y1,z);
2055 _refLineControl->AddPoint(x,y2,z);
2056 _refLineControl->SetCompleteCreation(true);
2058 _refLineModel->AddPoint(x,y1,z);
2059 _refLineModel->AddPoint(x,y2,z);
2060 _refLineModel->UpdateSpline();
2062 _refLineView->UpdateViewPoint(0);
2063 _refLineView->UpdateViewPoint(1);
2066 _refLineControl->SetActive(true);
2067 _refLineView->RefreshContour();
2071 //Hides the referenceLine
2072 void wxContourMainFrame::refLineHide()
2074 if (_refLineControl!=NULL)
2076 if (_refLineControl->GetActive())
2078 _refLineView->RemoveCompleteContourActor();
2079 _refLineControl->SetEditable(false);
2080 _refLineControl->SetActive(false);
2087 //Shows the referenceLine
2088 void wxContourMainFrame::refLineShow()
2090 if (_refLineControl!=NULL)
2092 if (_refLineControl->GetActive()==false)
2094 wxVtkBaseView * viewer2D = _theViewPanel->getWxVtkBaseView();
2096 _refLineView->SetModel( _refLineModel );
2097 _refLineView->SetWxVtkBaseView( viewer2D );
2098 _refLineView->SetRange( 2 );
2099 _refLineView->SetZ( 1200 );
2101 _refLineControl->SetModelView( _refLineModel , _refLineView );
2102 vtkInteractorStyleBaseView* style = (vtkInteractorStyleBaseView*)viewer2D->GetInteractorStyleBaseView();
2103 style->AddInteractorStyleMaracas( _refLineControl );
2104 _refLineControl->CreateNewManualContour();
2105 _refLineControl->SetActive(true);
2106 _refLineView->RefreshContour();
2113 void wxContourMainFrame::refLineChangeWidth(int width)
2115 _refLineView->SetWidthLine(width);
2116 _refLineView->RefreshContour();
2122 void wxContourMainFrame::onMirror()
2125 std::vector<std::string> currentSelection = _theViewPanel->getSelectedObjects();
2126 std::vector<std::string> filterCurrentSelection;
2128 std::vector<int> tempVector;
2129 _instantPanel->getInstant( tempVector );
2130 _performingOperation->reset();
2131 _performingOperation->setStartCommand( COPY );
2132 _performingOperation->setStartOperationInstantVector( tempVector );
2133 _performingOperation->setKeyNamesOperationElems( currentSelection );
2135 char theStartCommand = _performingOperation->getStartCommand();
2136 if ( theStartCommand == COPY )
2138 //JCP 20-10-08 Undo redo implementation
2140 //JCP 20-10-08 Undo redo implementation
2141 std::vector<int> tempVector;
2142 _instantPanel->getInstant( tempVector );
2143 _performingOperation->setEndOperationInstantVector ( tempVector );
2144 std::vector<std::string> elems = _performingOperation->getKeyNamesOperationElems();
2145 int i,size = elems.size();
2146 for( i=0; i<size; i++ )
2148 createMirrorContourOf( elems[i], tempVector, i>0 );
2152 //deleteContour( _refName );
2157 void wxContourMainFrame::showAxis(bool show)
2159 _theViewPanel->SetVisibleAxis(show);
2160 _theViewPanel->Refresh();
2164 void wxContourMainFrame::onRigidPressed(){
2165 std::vector<std::string> currentSelection = _theViewPanel->getSelectedObjects();
2166 int elementsSelected = currentSelection.size();
2168 if ( elementsSelected >= 1 ){
2169 //JCP 20-10-08 Undo redo implementation
2171 //JCP 20-10-08 Undo redo implementation
2173 std::vector<int> tempVector;
2174 _instantPanel->getInstant( tempVector );
2175 Instant instant(&tempVector);
2177 int i , size=currentSelection.size();
2178 for ( i=0 ; i<size ; i++ )
2180 kernelManager->changeContourOfManager(currentSelection[i], &instant);
2185 void wxContourMainFrame::onWidthOfContour(double width){
2187 _theViewPanel->removeSceneContours();
2188 _theViewPanel->SetWidthContour(width);
2190 //_theViewPanel->getSceneManager()->SetWidthContour( width );
2195 int wxContourMainFrame::getColorWindow()
2199 vtkImageData * img = getImageData();
2200 img->GetScalarRange(range);
2202 std::cout<<"Val 1: "<<range[0]<<" Val 2: "<<range[1]<<std::endl;
2204 return (int)range[1];
2206 return _theViewPanel->getColorWindow();
2209 int wxContourMainFrame::getWindowLevel()
2213 vtkImageData * img = getImageData();
2214 img->GetScalarRange(range);
2216 std::cout<<"Val 1: "<<range[0]<<" Val 2: "<<range[1]<<std::endl;
2218 return (int)range[1];
2220 return _theViewPanel->getWindowLevel();
2223 void wxContourMainFrame::onBrigthnessColorWindowLevel(int colorwindow,int windowlevel){
2224 _theViewPanel->onBrigthnessColorWindowLevel(colorwindow, windowlevel);
2229 void wxContourMainFrame::onInterpolation(bool interpolate){
2230 _theViewPanel->onInterpolation(interpolate);
2234 void wxContourMainFrame::onChangeInstant(std::string name,int actual){
2235 _instantPanel->setConceptValue( name, actual );
2238 void wxContourMainFrame::resetAppend(){
2239 kernelManager->resetAppend();
2243 void wxContourMainFrame::onSpreadAdd(){
2244 std::vector<double> vecX;
2245 std::vector<double> vecY;
2246 std::vector<double> vecZ;
2247 _theViewPanel->GetPointsOfActualContour(&vecX , &vecY , &vecZ );
2249 std::vector<int> tempVector;
2250 _instantPanel->getInstant( tempVector );
2252 std::string val = kernelManager->onSpreadAdd(&vecX , &vecY , &vecZ, tempVector);
2254 interfMainPanel::getInstance()->appendStringSpread(val);
2258 void wxContourMainFrame::onSpreadGo(int type){
2260 //JCP 20-10-08 Undo redo implementation
2262 //JCP 20-10-08 Undo redo implementation
2265 std::vector<double> vecCtrlPointX;
2266 std::vector<double> vecCtrlPointY;
2267 std::vector<double> vecCtrlPointZ;
2271 std::vector<int> tempVector;
2272 _instantPanel->getInstant( tempVector );
2275 kernelManager->getMaxMinZ(&minZ,&maxZ);
2276 //JSTG_16-07-08_----------------------------------------------------------------
2277 //_contourPropagation->setInterpolationNumber(maxZ-minZ+1);
2278 kernelManager->CalculeSplinePropagation();
2280 double totalZ = maxZ-minZ+1;
2283 //--------------------------------------------------------------------
2284 for ( z=(int)minZ ; z<=(int)maxZ ; z++ )
2286 porcent = 100.0* (z-minZ)/totalZ;
2287 int numero = (int)(z-minZ+1)/(int)totalZ;
2288 std::string stringtemp = " "+kernelManager->intToString(porcent)+"% "+kernelManager->intToString(numero)+" "+kernelManager->intToString(z);
2290 interfMainPanel::getInstance()->setStringSpread(stringtemp);
2292 int typeofcontour = 1;
2293 std::string theName;
2294 manualBaseModel* manModelContour = kernelManager->GetPoints(z, type, &vecCtrlPointX,&vecCtrlPointY,&vecCtrlPointZ, theName,typeofcontour, tempVector);
2296 if( manModelContour!=NULL ){
2297 double spc[3];//Si no hay imagen pero hay contornos que spacing se pone por default
2298 this->_theViewPanel->getSpacing(spc);
2299 //Adding the manualContourControler to interface objects structure
2300 //Adding the manualViewContour to interface objects structure
2301 //_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.
2302 _theViewPanel->configureViewControlTo( theName, manModelContour,spc,typeofcontour ) ;
2307 int numero = (int)(z-minZ+1)/(int)totalZ;
2308 std::string stringtemp = " "+kernelManager->intToString(porcent)+"% "+kernelManager->intToString(numero)+" "+kernelManager->intToString(z);
2310 interfMainPanel::getInstance()->setStringSpread(stringtemp);
2312 //RefreshInterface();
2315 void wxContourMainFrame::getInstantVector(std::vector<int>& tempVector){
2319 std::vector<std::string> wxContourMainFrame::getOutlinesName(int slide){
2320 std::vector<int> tempVector;
2321 _instantPanel->getInstant(tempVector);
2322 //Asignation of slide number should be different ex by name
2323 tempVector[1]=slide;
2324 return kernelManager->getOutlinesNameAtInstant(tempVector);
2328 void wxContourMainFrame::SetScalarRange(int grayRangeMin, int grayRangeMax)
2330 _contourextractdata->SetScalarRange(grayRangeMin,grayRangeMax);
2334 void wxContourMainFrame::onInformationContourLabels(int typeContourGroup,int selection,int minimumZ,int maximumZ,int grayRangeMin, int grayRangeMax)
2336 //EED01Juillet2009 GenerateContourExtractData();
2338 wxString tempString;
2339 int maxContourGroup = 0;
2341 _contourextractdata ->SetTypeOperation( typeContourGroup % 3 );
2343 std::vector<manualBaseModel*> lstManConMod;
2344 std::vector<manualBaseModel*> lstManConModTmp;
2345 std::vector<manualBaseModel*> lstManConModExp;
2346 std::vector<double> pLstValue;
2347 std::vector<double> pLstValuePosX;
2348 std::vector<double> pLstValuePosY;
2349 std::vector<double> pLstValuePosZ;
2352 int resultGrayRangeCount;
2355 double resultAverage;
2356 double resultStandardeviation;
2358 std::vector<int> tempVector;
2359 _instantPanel->getInstant( tempVector );
2361 //EED01Juillet2009 vtkImageData *imagedata = _theViewPanel->getImageData();
2362 // int sizeZ = _theViewPanel->GetImageDataSizeZ();
2364 int ii,sizeLstContourThings;
2373 if (selection==0 ) // actual slice
2375 int actualSlice = tempVector[1];
2378 } else { // slice range
2384 totalZ = maxZ-minZ+1;
2385 //EED01Juillet2009 _contourextractdata->SetImage( imagedata);
2387 _contourextractdata->InitVolumeStatistics();
2390 for ( z=minZ ; z<=maxZ ; z++ )
2393 porcent = 100.0* (z-minZ)/totalZ;
2394 tmpString.Printf(_T(" %d %c %d/%d %d"), (int)porcent , 37 , z-minZ+1, (int)totalZ ,z);
2396 interfMainPanel::getInstance()->setStringInfoPanel(tmpString);
2397 //_staticTextInformation->SetLabel(tmpString);
2399 //Extraction data from contours of each slice
2400 _contourextractdata->SetZtoBeAnalys(z);
2403 Instant instant(&tempVector);
2404 std::vector<ContourThing**> lstContourThings = kernelManager->getOutlinesAtInstant( &instant );
2405 sizeLstContourThings = lstContourThings.size();
2407 lstManConMod.clear();
2408 for (ii=0 ; ii<sizeLstContourThings ; ii++)
2410 ContourThing **contourthing = lstContourThings[ii];
2411 lstManConMod.push_back( (*contourthing)->getModel() );
2414 lstManConModExp = kernelManager->ExploseEachModel( lstManConMod );
2416 tempString.Printf(_T("%d - %d"),z, sizeLstContourThings);
2417 interfMainPanel::getInstance()->setRowLabelInfoPanel(z, tempString);
2418 //_grid->SetRowLabelValue(z, tempString );
2420 int iContourGroup,sizeContourGroup;
2421 if (typeContourGroup==3) // contour separete
2423 sizeContourGroup=lstManConModExp.size();
2424 if ( maxContourGroup<sizeContourGroup )
2426 maxContourGroup=sizeContourGroup;
2428 } else { // contour AND OR XOR
2435 for( iContourGroup=0 ; iContourGroup<sizeContourGroup ; iContourGroup++ ){
2436 lstManConModTmp.clear();
2440 if (typeContourGroup==3) // contour separete
2442 lstManConModTmp.push_back( lstManConModExp[iContourGroup]);
2443 } else { // contour AND OR XOR
2444 lstManConModTmp = lstManConModExp;
2447 _contourextractdata->SetLstManualContourModel( lstManConModTmp );
2448 _contourextractdata->SetScalarRange(grayRangeMin,grayRangeMax);
2451 pLstValuePosX.clear();
2452 pLstValuePosY.clear();
2453 pLstValuePosZ.clear();
2457 _contourextractdata->GetValuesInsideCrown( &numberOfPixels,
2463 resultSize=numberOfPixels;
2464 // Statistics of each slice.
2465 _contourextractdata->Statistics( &pLstValue,
2468 &resultGrayRangeCount,
2473 &resultStandardeviation);
2475 if (interfMainPanel::getInstance()->getNumberColsInformationPanel()<_numberOfVariablesStatistics*(iContourGroup+1) )
2477 interfMainPanel::getInstance()->appendColsInformationPanel(_numberOfVariablesStatistics);
2480 tmpIntA=_numberOfVariablesStatistics*iContourGroup ;
2482 tempString.Printf(_T("%d"),numberOfPixels);
2484 interfMainPanel::getInstance()->setCellValueInfoPanel(z, tmpIntA, tempString);
2486 tempString.Printf(_T("%d"),resultGrayRangeCount);
2487 interfMainPanel::getInstance()->setCellValueInfoPanel(z, tmpIntA+1, tempString);
2489 tempString.Printf(_T("%f"),resultMin);
2490 interfMainPanel::getInstance()->setCellValueInfoPanel(z, tmpIntA+2, tempString);
2492 tempString.Printf(_T("%f"),resultMax);
2493 interfMainPanel::getInstance()->setCellValueInfoPanel(z, tmpIntA+3, tempString);
2495 tempString.Printf(_T("%f"),resultAverage);
2496 interfMainPanel::getInstance()->setCellValueInfoPanel(z, tmpIntA+4, tempString);
2498 tempString.Printf(_T("%f"),resultStandardeviation);
2499 interfMainPanel::getInstance()->setCellValueInfoPanel(z, tmpIntA+5, tempString);
2502 } // for iContourGroup
2505 // Print Volume Statistics
2508 int vol_rCountRange;
2510 double vol_minValue;
2511 double vol_maxValue;
2513 double vol_standardeviation;
2515 if (selection!=0 ) // actual slice
2518 _contourextractdata->GetVolumeStatistics(&vol_rCountRange, &vol_rsize,
2519 &vol_minValue, &vol_maxValue,
2520 &vol_average, &vol_standardeviation);
2522 interfMainPanel::getInstance()->setRowLabelInfoPanel(maxZ+2, _T("Total:"));
2524 tempString.Printf(_T("%d"),vol_rsize);
2525 interfMainPanel::getInstance()->setCellValueInfoPanel(maxZ+2, 0, tempString);
2527 tempString.Printf(_T("%d"),vol_rCountRange);
2528 interfMainPanel::getInstance()->setCellValueInfoPanel(maxZ+2, 1, tempString);
2530 tempString.Printf(_T("%f"),vol_minValue);
2531 interfMainPanel::getInstance()->setCellValueInfoPanel(maxZ+2, 2, tempString);
2533 tempString.Printf(_T("%f"),vol_maxValue);
2534 interfMainPanel::getInstance()->setCellValueInfoPanel(maxZ+2, 3, tempString);
2536 tempString.Printf(_T("%f"),vol_average);
2537 interfMainPanel::getInstance()->setCellValueInfoPanel(maxZ+2, 4, tempString);
2539 tempString.Printf(_T("%f"),vol_standardeviation);
2540 interfMainPanel::getInstance()->setCellValueInfoPanel(maxZ+2, 5, tempString);
2542 //-----------------------------------------
2545 wxString tmpTitleString;
2547 for ( iTitleGroup=0 ; iTitleGroup<maxContourGroup ; iTitleGroup++ )
2549 tmpIntB =_numberOfVariablesStatistics*iTitleGroup;
2550 tmpTitleString.Printf(_T("%d-Size Data"),iTitleGroup);
2551 interfMainPanel::getInstance()->setColLableInfoPanel(tmpIntB + 0, tmpTitleString);
2553 interfMainPanel::getInstance()->setColLableInfoPanel(tmpIntB + 0, tmpTitleString );
2554 interfMainPanel::getInstance()->setColLableInfoPanel( tmpIntB + 1, _T("Size Range") );
2555 interfMainPanel::getInstance()->setColLableInfoPanel( tmpIntB + 2, _T("Min") );
2556 interfMainPanel::getInstance()->setColLableInfoPanel( tmpIntB + 3, _T("Max") );
2557 interfMainPanel::getInstance()->setColLableInfoPanel( tmpIntB + 4, _T("Average") );
2558 interfMainPanel::getInstance()->setColLableInfoPanel( tmpIntB + 5, _T("St.Dev.") );
2559 interfMainPanel::getInstance()->setColLableInfoPanel( tmpIntB + 6, _T(" ") );
2561 interfMainPanel::getInstance()->setStringInfoPanel( _T("") );
2565 void wxContourMainFrame::onSaveResults(std::string directory,std::string namefile, std::string filename,
2566 int typeContourGroup, int selection, int minZ, int maxZ, bool XYZValues, bool contourImage, bool statistics)
2570 SaveValuesXYZ( directory , namefile, typeContourGroup );
2575 vtkImageData * mask;
2576 vtkImageData * value;
2577 this->getMaskValue(&mask, &value, typeContourGroup,selection,minZ,maxZ);
2578 this->SaveImageResult( directory , namefile, mask, value);
2583 std::ostringstream name;
2584 name << filename << ".xls";
2587 FILE *pFile=fopen(name.str().c_str(),"w+");
2593 // int sizeZ = _theViewPanel->GetImageDataSizeZ();
2594 // int maxY=sizeZ+2;
2596 maxX= interfMainPanel::getInstance()->getNumberColsInformationPanel();//this->_grid->GetNumberCols();
2599 int iTitle,sizeTitle = (maxX / _numberOfVariablesStatistics);
2600 for ( iTitle=0; iTitle<sizeTitle ; iTitle++)
2602 // fprintf(pFile,"-- \t %d-Size \t SizeRange \t Min \t Max \t Ave \t StDv \t" , iTitle,tmpString.c_str() );
2603 fprintf(pFile,"slice\t %d-Size \t SizeRange \t Min \t Max \t Ave \t StDv \t" , iTitle );
2605 fprintf(pFile,"\n\n" );
2609 if (selection==0 ) // actual slice
2611 std::vector<int> tempVector;
2612 _instantPanel->getInstant( tempVector );
2613 int actualSlice = tempVector[1];
2619 for ( j=minZ; j<=maxZ ; j++)
2621 fprintf(pFile,"%d\t" , j );
2622 for (i=0 ; i<maxX ; i++){
2623 tmpString = interfMainPanel::getInstance()->getCellValue(j, i);//_grid->GetCellValue( j , i );
2624 fprintf(pFile,"%s\t" , (const char *)(tmpString.mb_str()) );
2626 fprintf(pFile,"\n" );
2630 // Total of stadistics.....
2633 fprintf(pFile,"\n Total:\t" );
2634 for (i=0 ; i<maxX ; i++){
2635 tmpString = interfMainPanel::getInstance()->getCellValue(maxZ+2, i);//_grid->GetCellValue( maxZ+2 , i );
2636 fprintf(pFile,"%s\t" , (const char *)(tmpString.mb_str()) );
2638 fprintf(pFile,"\n" );
2646 void wxContourMainFrame::SaveValuesXYZ(std::string directory,std::string namefile,int typeContourGroup)
2649 //EED01Juillet2009 GenerateContourExtractData();
2651 //int typeContourGroup = this->_radiolstboxContourGroup->GetSelection();
2652 _contourextractdata ->SetTypeOperation( typeContourGroup % 3 );
2654 std::vector<manualBaseModel*> lstManConMod;
2655 std::vector<manualBaseModel*> lstManConModTmp;
2656 std::vector<manualBaseModel*> lstManConModExp;
2657 std::vector<double> pLstValue;
2658 std::vector<double> pLstValuePosX;
2659 std::vector<double> pLstValuePosY;
2660 std::vector<double> pLstValuePosZ;
2662 std::vector<int> tempVector;
2663 _instantPanel->getInstant( tempVector );
2665 //EED01Juillet2009 vtkImageData *imagedata = _theViewPanel->getSceneManager()->GetImageData();
2666 int sizeZ = _theViewPanel->getSceneManager()->GetImageDataSizeZ();
2668 int ii,sizeLstContourThings;
2675 minZ = 0;// _mbarrange->GetStart();
2676 maxZ = sizeZ;//_mbarrange->GetEnd();
2677 totalZ = maxZ-minZ+1;
2679 //EED01Juillet2009 _contourextractdata->SetImage( imagedata);
2682 for ( z=0 ; z<sizeZ ; z++)
2685 porcent = 100.0* (z-minZ)/totalZ;
2687 tmpString.Printf(_T("Saving Values"));
2688 tmpString.Printf(_T(" %d %c %d/%d %d"), (int)porcent , 37 , z-minZ+1, (int)totalZ ,z);
2689 interfMainPanel::getInstance()->setStringInfoPanel(tmpString);
2690 //_staticTextInformation->SetLabel(tmpString);
2693 //Extraction data from contours of each slice
2694 _contourextractdata->SetZtoBeAnalys( z);
2697 Instant instant(&tempVector);
2698 std::vector<ContourThing**> lstContourThings = kernelManager->getOutlinesAtInstant(&instant);//this->_modelManager->getOutlinesAtInstant( &instant );
2699 sizeLstContourThings = lstContourThings.size();
2701 lstManConMod.clear();
2702 for (ii=0 ; ii<sizeLstContourThings ; ii++)
2704 ContourThing **contourthing = lstContourThings[ii];
2705 lstManConMod.push_back( (*contourthing)->getModel() );
2707 lstManConModExp = kernelManager->ExploseEachModel( lstManConMod );
2712 int iContourGroup,sizeContourGroup;
2713 if (typeContourGroup==3) // contour separete
2715 sizeContourGroup=lstManConModExp.size();
2716 } else { // contour AND OR XOR
2720 for( iContourGroup=0 ; iContourGroup<sizeContourGroup ; iContourGroup++ ){
2721 lstManConModTmp.clear();
2722 if (typeContourGroup==3) // contour separete
2724 lstManConModTmp.push_back( lstManConModExp[iContourGroup]);
2725 } else { // contour AND OR XOR
2726 lstManConModTmp = lstManConModExp;
2729 _contourextractdata->SetLstManualContourModel( lstManConModTmp );
2732 pLstValuePosX.clear();
2733 pLstValuePosY.clear();
2734 pLstValuePosZ.clear();
2736 _contourextractdata->GetValuesInsideCrown( &numberOfPixels,
2742 std::string temp = directory + "/" + namefile + "-slice";
2743 temp = temp + kernelManager->intToString(z) + "-cont" + kernelManager->intToString(iContourGroup);
2744 temp = temp + ".txt";
2746 // LG 14/01/09 : using crea
2747 wxString filename = crea::std2wx(temp);
2748 /*filename.Printf(_T("%s"),directory.c_str());
2749 filename.append(_T("\\"));
2750 filename.append(_T("%s"),namefile.c_str());
2751 filename.append(_T("-slice"));
2752 filename.append(_T("%d"),z);
2753 filename.append(_T("-cont"));
2754 filename.append(_T("%d"),iContourGroup);
2755 filename.append(_T(".txt"));*/
2756 // filename.Printf(temp.c_str());
2760 FILE *pFile=fopen((const char *)filename.mb_str(),"w+");
2761 fprintf(pFile,"value \t x \t y \t z\n" );
2762 int iLstValue,sizeLstValue=pLstValue.size();
2763 for (iLstValue=0 ; iLstValue<sizeLstValue ; iLstValue++ )
2765 fprintf(pFile,"%f\t %f\t %f\t %f\n", (float)pLstValue[iLstValue] , (float)pLstValuePosX[iLstValue], (float)pLstValuePosY[iLstValue], (float)z );
2768 } // for iContourGroup
2770 interfMainPanel::getInstance()->setStringInfoPanel(_T(""));
2771 //_staticTextInformation->SetLabel( _T("") );
2775 void wxContourMainFrame::getMaskValue(vtkImageData ** mask,vtkImageData ** value,int typeContourGroup, int selection, int minZ, int maxZ){
2777 //EED01Juillet2009 GenerateContourExtractData();
2779 //int typeContourGroup = this->_radiolstboxContourGroup->GetSelection();
2780 if (typeContourGroup==3)
2784 _contourextractdata ->SetTypeOperation( typeContourGroup % 3 );
2786 std::vector<manualBaseModel*> lstManConMod;
2787 std::vector<manualBaseModel*> lstManConModTmp;
2788 std::vector<manualBaseModel*> lstManConModExp;
2790 std::vector<int> tempVector;
2791 _instantPanel->getInstant( tempVector );
2793 vtkImageData *imagedata = _theViewPanel->getImageData();
2795 imagedata->GetExtent(ext);
2796 int sizeZimage = ext[5]-ext[4]+1;
2798 int ii,sizeLstContourThings;
2807 if (selection==0 ) // actual slice
2809 int actualSlice = tempVector[1];
2816 //EED01Juillet2009 _contourextractdata->SetImage( imagedata);
2818 // cleanning image before range
2819 for (z=0; z<minZ; z++){
2820 _contourextractdata->ResetImageResult(z);
2822 // cleanning image after range
2823 for (z=maxZ+1; z<sizeZimage; z++){
2824 _contourextractdata->ResetImageResult(z);
2829 for ( z=minZ ; z<=maxZ ; z++)
2832 porcent = 100.0* (z-minZ)/totalZ;
2833 tmpString.Printf(_T("Saving Values"));
2834 tmpString.Printf(_T("%d %c %d/%d %d"), (int)porcent , 37 , z-minZ+1, (int)totalZ ,z);
2835 interfMainPanel::getInstance()->setStringInfoPanel(tmpString);
2837 //Extraction data from contours of each slice
2838 _contourextractdata->SetZtoBeAnalys( z);
2841 Instant instant(&tempVector);
2842 std::vector<ContourThing**> lstContourThings = kernelManager->getOutlinesAtInstant( &instant );
2843 sizeLstContourThings = lstContourThings.size();
2845 lstManConMod.clear();
2846 for (ii=0 ; ii<sizeLstContourThings ; ii++)
2848 ContourThing **contourthing = lstContourThings[ii];
2849 lstManConMod.push_back( (*contourthing)->getModel() );
2851 lstManConModExp = kernelManager->ExploseEachModel( lstManConMod );
2854 int iContourGroup,sizeContourGroup;
2855 if (typeContourGroup==3) // contour separete
2857 sizeContourGroup=lstManConModExp.size();
2858 } else { // contour AND OR XOR
2862 for( iContourGroup=0 ; iContourGroup<sizeContourGroup ; iContourGroup++ ){
2863 lstManConModTmp.clear();
2864 if (typeContourGroup==3) // contour separete
2866 lstManConModTmp.push_back( lstManConModExp[iContourGroup]);
2867 } else { // contour AND OR XOR
2868 lstManConModTmp = lstManConModExp;
2871 _contourextractdata->SetLstManualContourModel( lstManConModTmp );
2872 _contourextractdata->CalculateImageResult(); // with actual Z
2874 } // for iContourGroup
2877 (*value) = _contourextractdata->GetVtkImageValueResult();
2878 (*mask) = _contourextractdata->GetVtkImageMaskResult();
2882 void wxContourMainFrame::SaveImageResult(std::string directory,std::string namefile, vtkImageData* mask,vtkImageData* value)
2885 std::string temp = directory + "/" + namefile + "-Value.mhd";
2887 wxString filename = crea::std2wx(temp);
2889 // filename.Printf(_T(temp.c_str()));
2890 //filename.Printf(_T("%s\\%s-Value.mhd",directory.c_str(),namefile.c_str(),z);
2891 /*filename.Printf(_T("%s"),directory.c_str());
2892 filename.append(_T("\\"));
2893 filename.append(_T("%s"),namefile.c_str());
2894 filename.append(_T("-Value.mhd"));*/
2897 vtkMetaImageWriter *writerValueImage = vtkMetaImageWriter::New( );
2898 writerValueImage->SetInput( value );
2899 writerValueImage->SetFileName( (const char *)filename.mb_str() );
2900 writerValueImage->SetFileDimensionality( 3 );
2901 writerValueImage->Write( );
2904 // filename.Printf("%s\\%s-Mask.mhd",directory.c_str(),namefile.c_str(),z);
2905 temp = directory + "/" + namefile + "-Mask.mhd";
2907 // LG 14/01/09 : using crea
2908 filename = crea::std2wx(temp);
2909 // filename.Printf(_T(temp.c_str()));
2911 /*filename.Printf(_T("%s"),directory.c_str());
2912 filename.append(_T("\\"));
2913 filename.append(_T("%s"),namefile.c_str());
2914 filename.append(_T("-Mask.mhd"));*/
2916 vtkMetaImageWriter *writerMaskImage = vtkMetaImageWriter::New( );
2917 writerMaskImage->SetInput( mask );
2918 writerMaskImage->SetFileName( (const char *)filename.mb_str() );
2919 writerMaskImage->SetFileDimensionality( 3 );
2920 writerMaskImage->Write( );
2922 interfMainPanel::getInstance()->setStringInfoPanel( _T("") );
2928 void wxContourMainFrame::onChangeInstantInstantPanel(std::string name,int value, int minshow, int maxshow){
2929 if( name.compare( _theViewPanel->getVerticalConceptName() ) == 0){
2930 _theViewPanel->setActualVertical( value);
2932 else if( name.compare( _theViewPanel->getHorizontalConceptName() ) == 0|| _instantPanel->getIfConceptCheckedAt( name, 0 ) ) {
2933 _theViewPanel->setHorizontalConcept( name, minshow, maxshow, minshow, maxshow, value);
2939 void wxContourMainFrame::onSnakePressed(){
2940 std::vector<double> vecX;
2941 std::vector<double> vecY;
2942 std::vector<double> vecZ;
2943 _theViewPanel->GetPointsOfActualContour( &vecX , &vecY , &vecZ );
2945 if (vecX.size()!=0){
2946 std::vector<int> tempVector;
2947 _instantPanel->getInstant( tempVector );
2948 int i,size=vecZ.size();
2949 int actualSlice = tempVector[1];
2950 for ( i=0 ; i<size ; i++ )
2952 vecZ[i] = actualSlice;
2955 wxDialog* dialog = new wxDialog(this, -1, wxString(_T("Snake")));
2956 wxPanel* panel = new wxPanel(dialog,-1);
2957 // wxStaticText* sttext = new wxStaticText(panel, -1, wxString(_T("Panel para snake")));
2958 new wxStaticText(panel, -1, wxString(_T("Panel para snake")));
2959 dialog->ShowModal();
2964 void wxContourMainFrame::saveFileWithContoursAutomatique(){
2965 std::string filename = kernelManager->getCurrentFileName();
2966 if(filename.compare("")!=0){
2967 saveFileWithContours(filename);
2972 void wxContourMainFrame::ShowToolsPanel(bool show){
2973 _pannew->Show(show);
2978 void wxContourMainFrame::SetContourGroup(int contourGroup)
2980 _contourGroup = contourGroup;
2984 wxPanel *wxContourMainFrame::getMaskImageViewPanel(wxWindow *parent)
2987 if (_viewMaskImagePanel==NULL)
2989 _contourextractdata = new ContourExtractData(true);
2990 _contourextractdata->SetImage( _theViewPanel->getImageData() );
2993 // _theViewPanel->getImageData()->GetScalarRange(range);
2994 //int min = (int)floor (range[0]);
2995 //int max = (int)ceil (range[1]);
2999 _viewMaskImagePanel = new ThresholdImageViewPanel( parent, -1, -1 , 0);
3000 _viewMaskImage = new ThresholdImageView();
3001 _viewMaskImage->SetImage(_contourextractdata->GetVtkImageMaskResult() );
3002 _viewMaskImage->SetminMaxValue( min, max);
3003 _viewMaskImage->SetBaseColor( 0,0,1 );
3004 _viewMaskImagePanel->SetThresholdImageView( _viewMaskImage );
3005 _viewMaskImage->SetwxVtkBaseView( _theViewPanel->getWxVtkBaseView() );
3008 return _viewMaskImagePanel;
3011 wxPanel *wxContourMainFrame::getThresholdImageViewPanel(wxWindow *parent)
3013 if (_viewThresholdImagePanel==NULL)
3016 _theViewPanel->getImageData()->GetScalarRange(range);
3017 int min = (int)floor (range[0]);
3018 int max = (int)ceil (range[1]);
3019 _viewThresholdImagePanel = new ThresholdImageViewPanel( parent, min, max , 1);
3020 _viewThresholdImage = new ThresholdImageView();
3021 _viewThresholdImage->SetImage( _theViewPanel->getImageData() );
3022 _viewThresholdImage->SetminMaxValue( min, max);
3023 _viewThresholdImage->SetBaseColor( 1,0,0 );
3024 _viewThresholdImagePanel->SetThresholdImageView( _viewThresholdImage );
3025 _viewThresholdImage->SetwxVtkBaseView( _theViewPanel->getWxVtkBaseView() );
3027 return _viewThresholdImagePanel;
3030 //CMRU 17-08-09-----------------------------------------------------------------------------------------------
3031 int wxContourMainFrame::getType ()
3034 std::vector<std::string> currentSelection = _theViewPanel->getSelectedObjects();
3036 if(!currentSelection.empty())
3038 std::string cloneName = currentSelection [0];
3039 manualBaseModel * manualModel = kernelManager->getOutlineByKeyName(cloneName);
3040 tipo = manualModel-> GetTypeModel();
3045 double wxContourMainFrame::getContourSizeInPixels()
3047 double contourSize = 0;
3049 std::vector<std::string> currentSelection = _theViewPanel->getSelectedObjects(); if(!currentSelection.empty())
3050 if(!currentSelection.empty())
3052 std::string cloneName = currentSelection [0];
3054 manualBaseModel * manualModel = kernelManager->getOutlineByKeyName(cloneName);//_modelManager->getOutlineByKeyName( cloneName )->getModel();
3055 contourSize = manualModel-> GetPathSize();
3059 manualBaseModel * wxContourMainFrame::getContour ()
3061 std::vector<std::string> currentSelection = _theViewPanel->getSelectedObjects();
3063 if(!currentSelection.empty())
3065 std::string cloneName = currentSelection [0];
3066 manualBaseModel * manualModel = kernelManager->getOutlineByKeyName(cloneName);//_modelManager->getOutlineByKeyName( cloneName )->getModel();
3071 void wxContourMainFrame::onPrintLabel (wxString label, manualBaseModel* manualModel)
3073 std::string labelAscii(label.ToAscii());
3074 int pos = labelAscii.find(" ");
3078 for (j=0 ; pos != string::npos;j++)
3080 labelAscii.replace( pos, 1, "_" );
3081 pos= labelAscii.find(" ");
3084 manualModel -> SetLabel(labelAscii);
3086 void wxContourMainFrame::onInsertCalculation(manualBaseModel* manualModel)
3088 double sizeInPixel = manualModel ->GetPathSize();
3089 double onePixelRealSize = interfMainPanel::getInstance()->GetPixelValue();;
3090 double realContourSize = sizeInPixel*onePixelRealSize;
3091 manualModel ->SetRealSize(realContourSize);
3094 double wxContourMainFrame::onePixelSize( double value)
3096 return _onePixelSize = value;
3099 std::string wxContourMainFrame::GetFileLocation()
3101 return _fileLocation;
3104 void wxContourMainFrame::SetFileLocation(std::string newFileLocation)
3106 _fileLocation = newFileLocation;
3107 std::cout<<"GETFILELOCATION:"<<_fileLocation<<std::endl;
3109 //------------------------------------------------------------------------------------------------------------