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;
71 _viewColorLayerImage = NULL;
72 _viewColorLayerImagePanel = NULL;
75 wxContourMainFrame :: wxContourMainFrame(wxWindow* parent, wxWindowID id,const wxString& title,const wxPoint& pos,const wxSize& size,std::vector<vtkImageData*> images, long style,std::string datadir)
76 : wxPanel(parent, id, pos, size, style)
78 m_mgr.SetManagedWindow(this);
80 _creatingContoursActive = false;
84 _refLineControl = NULL;
87 // _actorPresent = false;
88 _viewMaskImage = NULL;
89 _viewMaskImagePanel = NULL;
90 _viewThresholdImage = NULL;
91 _viewThresholdImagePanel = NULL;
92 _viewColorLayerImage = NULL;
93 _viewColorLayerImagePanel = NULL;
95 // set up default notebook style
96 m_notebook_style =wxAUI_NB_TAB_SPLIT | wxAUI_NB_TAB_EXTERNAL_MOVE | wxNO_BORDER;
98 //wxContour_ActionCommandsID a;
99 _numberOfVariablesStatistics = 7;
107 _pannew = interfMainPanel::getInstance(this,datadir+"/data/Icons");//, eventHandler);
108 _performingOperation = new PerformingOperation();
110 if(images.size() > 0)
112 this->setVectImages(images);
115 _contourextractdata = NULL;
118 void wxContourMainFrame::setVectImages(std::vector<vtkImageData*> imgs)
123 #if defined(__GNUC__)
124 std::string str_home(getenv("HOME"));
125 #elif defined(_WIN32)
126 std::string str_home(getenv("USERPROFILE"));
128 std::string strCreaContourDataTmp = str_home + "/.creaContourDataTemp/";
130 std::vector<std::string> conceptNameVect;
131 std::vector<int> conceptSizeVect;
133 notebook = this->createNotebook();
136 kernelManager = new KernelManagerContour( imgs , _datadir+"/data/" , strCreaContourDataTmp );
139 _instantPanel = new wxInstantChooserPanel( notebook, "Instant Chooser", true, false, "c" );
140 _theViewPanel = new wxContourViewPanel( kernelManager->getSourceImage(), notebook );
142 //-------------------------------------------------------------
143 kernelManager->getConceptsInformation(conceptNameVect, conceptSizeVect);
144 _instantPanel->addConcepts(conceptNameVect, conceptSizeVect);
147 double val = _theViewPanel->getCurrentDeep();
148 _instantPanel->setConceptValue( "Axe Depth", (int)val );
149 //JCP _instantPanel->setConceptValue("time", num de imagenes);
150 ConceptDataWrap * data = _instantPanel->getConceptDataOf( "Axe Depth" );
151 //*******************changeInstant();
152 _theViewPanel->setVerticalConcept( "Axe Depth", data->getMinValue(), data->getMaxValue(), data->getMinShowedValue(), data->getMaxShowedValue(), data->getActualValue() );
154 this->configurePanels( );
159 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 )
161 if(instance == NULL){
162 instance = new wxContourMainFrame(parent, id, title, pos, size, images, style,datadir);
167 std::vector<vtkImageData*> wxContourMainFrame ::getVectImages()
169 return kernelManager->getVectImages();
172 wxContourMainFrame* wxContourMainFrame :: getInstance()
177 void wxContourMainFrame :: resetInstance()
182 wxContourMainFrame :: ~wxContourMainFrame()
184 delete _contourextractdata;
187 interfMainPanel::resetInstance();
188 delete kernelManager;
190 //_pannew->Destroy();
196 //El problema al cerrar la aplicacion puede estar asociado
197 //a que wxAUINotebook esta en la aplicacion
198 //principal (wxContourGUIExample)tambien
199 //EED???? delete _theViewPanel;
200 //EED???? delete _instantPanel;
201 //EED???? delete _buttonsBar;
202 //EED???? delete _actualInstant;
203 //EED???? delete _sceneManager;
207 //------------------------------------------------------------------------------------------------------------
208 // Creational and initialization methods using WxAui
209 //------------------------------------------------------------------------------------------------------------
211 wxAuiNotebook * wxContourMainFrame :: createNotebook()
213 wxSize client_size = GetClientSize();
214 wxAuiNotebook* noteBook = new wxAuiNotebook(this, -1, wxPoint(client_size.x, client_size.y), wxSize(430,200), m_notebook_style);
215 wxBitmap page_bmp = wxArtProvider::GetBitmap(wxART_NORMAL_FILE, wxART_OTHER, wxSize(16,16));
220 //------------------------------------------------------------------------------------------------------------
221 // Creational and initialization methods
222 //------------------------------------------------------------------------------------------------------------
223 bool wxContourMainFrame :: configurePanels( )
225 bool configured = _theViewPanel!=NULL;
227 configured &= _theViewPanel!=NULL;
228 if( _theViewPanel!=NULL )
230 notebook->AddPage( _theViewPanel, wxT(" View ") );
237 notebook->AddPage( _instantPanel, wxT("Instant Page") );
241 m_mgr.AddPane(notebook, wxAuiPaneInfo().Name(wxT("notebook_content")).CenterPane().PaneBorder(false));
244 SetMinSize(wxSize(300,300));
250 bool wxContourMainFrame::addNewPanel(wxPanel* panel)
252 bool configured = panel!=NULL;
253 configured &= panel!=NULL;
257 notebook->AddPage( panel, wxT(" Viewer "), true );
263 //------------------------------------------------------------------------------------------------------------
264 // Attributes getters and setters
265 //------------------------------------------------------------------------------------------------------------
269 void wxContourMainFrame :: setInstantChooserPanel( wxInstantChooserPanel * theInstantChooserPanel )
271 _instantPanel = theInstantChooserPanel;
274 // void wxContourMainFrame :: setButtonsBar( wxContour_ButtonsBar * theButtonsBar )
276 // _buttonsBar = theButtonsBar;
279 // void wxContourMainFrame :: setGrid( wxContour_Grid * theGridPanel )
281 // _gridPanel = theGridPanel;
284 // void wxContourMainFrame :: setDrawToolsPanel( wxContour_DrawToolsPanel * theDrawToolsPanel )
286 // _drawToolsPanel = theDrawToolsPanel;
289 // void wxContourMainFrame :: setOperationsToolsPanel( wxContour_OperationsToolsPanel * theOperationsToolsPanel )
291 // _operationsToolsPanel = theOperationsToolsPanel;
294 // void wxContourMainFrame :: setAutomaticFormsPanel( wxContour_AutomaticFormsToolsPanel * theAutoFormsPanel )
296 // _autoFormsPanel = theAutoFormsPanel;
299 // void wxContourMainFrame :: setStandardToolsPanel( wxContour_StandardToolsPanel * theStandardToolsPanel )
301 // _standardToolsPanel= theStandardToolsPanel;
304 // void wxContourMainFrame :: setEditionToolsPanel( wxContour_EdtionToolsPanel * theEditionToolsPanel )
306 // _editionToolsPanel = theEditionToolsPanel;
309 // void wxContourMainFrame :: setListViewPanel( wxContour_ListViewPanel * theListViewPanel )
311 // _listViewPanel = theListViewPanel;
316 void wxContourMainFrame::onCreateContourSpline( ){
318 //JCP 20-10-08 Undo redo implementation
320 //JCP 20-10-08 Undo redo implementation
324 void wxContourMainFrame::onCreateContourRectangle( ){
325 //JCP 20-10-08 Undo redo implementation
327 //JCP 20-10-08 Undo redo implementation
330 void wxContourMainFrame::onCreateContourCircle( ){
331 //JCP 20-10-08 Undo redo implementation
333 //JCP 20-10-08 Undo redo implementation
337 void wxContourMainFrame::onCreateContourLine( ){
338 //JCP 20-10-08 Undo redo implementation
340 //JCP 20-10-08 Undo redo implementation
344 // RaC 09-09 --------------------------------------
345 void wxContourMainFrame::onCreateContourPoints( ){
346 //JCP 20-10-08 Undo redo implementation
348 //JCP 20-10-08 Undo redo implementation
351 // RaC 09-09 --------------------------------------
353 // RaC 10-09 --------------------------------------
354 void wxContourMainFrame::onCreateContourPolygon( ){
355 //JCP 20-10-08 Undo redo implementation
357 //JCP 20-10-08 Undo redo implementation
360 // RaC 10-09 --------------------------------------
362 //------------------------------------------------------------------------------------------------------------
364 void wxContourMainFrame :: onCreateContourBullEye(wxPanel* panel )
366 //Creating the manualBaseModel and including in the model
367 manualBaseModel * manModelContour = factoryManualContourModel(panel );
369 std::vector<int> instantVector;
370 _instantPanel->getInstant( instantVector );
371 std::string theName = kernelManager->createOutline(manModelContour, instantVector);
373 /*std::vector<int> instantVector;
374 _instantPanel->getInstant( instantVector );
376 theName= _modelManager->createOutline( manModelContour, instantVector );*/
377 bool addedModel = theName.compare("") != 0;//??
381 double spc[3];//Si no hay imagen pero hay contornos que spacing se pone por default
382 _theViewPanel->getSpacing(spc);
383 //Adding the manualContourControler to interface objects structure
384 //Adding the manualViewContour to interface objects structure
385 //_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.
386 _theViewPanel->getSceneManager()->configureViewControlTo( theName, manModelContour,spc , 4) ;
389 void wxContourMainFrame :: createContour( int typeContour )
391 //Creating the manualContourModel and including in the model
392 manualBaseModel * manModelContour = kernelManager->factoryManualContourModel(typeContour);
394 std::vector<int> instantVector;
395 _instantPanel->getInstant( instantVector );
396 std::string theName = kernelManager->createOutline(manModelContour, instantVector);
398 /*std::vector<int> instantVector;
399 _instantPanel->getInstant( instantVector );
401 theName= _modelManager->createOutline( manModelContour, instantVector );*/
402 bool addedModel = theName.compare("") != 0;//??
405 double spc[3];//Si no hay imagen pero hay contornos que spacing se pone por default
406 _theViewPanel->getSpacing(spc);
407 //Adding the manualContourControler to interface objects structure
408 //Adding the manualViewContour to interface objects structure
409 //_sceneManager->setControlActiveStateOfALL( false );//This call is being done here because if the ROI is created underneath the previously created ROIS will still be active.
410 _theViewPanel->getSceneManager()->configureViewControlTo( theName, manModelContour,spc , typeContour) ;
414 manualBaseModel * wxContourMainFrame::factoryManualContourModel(wxPanel* panel){
416 manualContourModelBullEye *manModelContourBullEye = new manualContourModelBullEye();
417 manualBaseModel *manModelContour=NULL;
418 manModelContour = manModelContourBullEye;
420 int iCrown,sizeCrowns,iSector,sizeSectors;
421 double radioA,radioB,ang,angDelta ;
422 sizeCrowns = ((PanelBullEyeOptions*)panel)->GetNumberOfCrowns();
423 for ( iCrown=0 ; iCrown<sizeCrowns ; iCrown++ )
425 sizeSectors = ((PanelBullEyeOptions*)panel)->GetNumberOfSections(iCrown);
426 radioB = ((PanelBullEyeOptions*)panel)->GetRadioOfCrown(iCrown);
427 if (iCrown==sizeCrowns-1)
431 radioA = ((PanelBullEyeOptions*)panel)->GetRadioOfCrown(iCrown+1);
435 for ( iSector=0 ; iSector<sizeSectors ; iSector++ )
437 ang = ((PanelBullEyeOptions*)panel)->GetAngOfCrownSection(iCrown,iSector);
438 angDelta= ((PanelBullEyeOptions*)panel)->GetAngDeltaOfCrownSection(iCrown);
439 manModelContourBullEye->AddSector(radioA,radioB,ang,angDelta);
442 } // if _panelBullEyeOptions
444 return manModelContour;
446 void wxContourMainFrame :: saveState(){
448 std::string temp = kernelManager->saveState();
449 saveFileWithContours(temp);
452 void wxContourMainFrame::onDeleteContour(){
453 //JCP 20-10-08 Undo redo implementation
455 //JCP 20-10-08 Undo redo implementation
457 std::vector<std::string> lstKeyNameToBeErase;
458 lstKeyNameToBeErase = _theViewPanel->getSceneManager()->getSelectedObjects();
459 deleteContours( lstKeyNameToBeErase );
461 int i,size=_sceneManager->getSelectedObjects().size();
464 std::string keyName = _sceneManager->getSelectedObjects()[i];
465 int ispartofstaticlist = this->_modelManager->IsPartOfStaticList( keyName );
466 if ( ispartofstaticlist>=0 )
468 std::vector<int> tempVector;
469 _instantPanel->getInstant( tempVector );
470 Instant instant(&tempVector);
471 this->_modelManager->ChangeContourOfList(keyName, &instant);
475 std::vector<std::string> lstKeyName;
476 std::vector<std::string> lstKeyNameActualSlice;
477 std::vector<std::string> lstKeyNameToBeErase;
479 lstKeyNameToBeErase = _sceneManager->getSelectedObjects();
480 lstKeyNameActualSlice = _sceneManager->GetlstContoursNameActualSlice();
481 int k,kSize=lstKeyNameToBeErase.size();
482 int j,jSize=lstKeyNameActualSlice.size();
484 for (k=0;k<kSize; k++)
487 for (j=0;j<jSize; j++)
489 if (lstKeyNameToBeErase[k]==lstKeyNameActualSlice[j])
496 lstKeyName.push_back( lstKeyNameToBeErase[k] );
500 deleteContours( lstKeyName );
504 void wxContourMainFrame :: deleteContours( std::vector<std::string> keyNamesVector )
506 int i,size=keyNamesVector.size();
509 deleteContour( keyNamesVector[i] );
513 void wxContourMainFrame :: deleteContour( std::string theKeyName ){
515 manualContourModel * cModel;
516 manualViewBaseContour * cViewer;
517 manualContourBaseControler * cControler;
519 ContourWrap_ViewControl *conwrapviewControl = _theViewPanel->getSceneManager()->getContourWrap_ViewControlOf( theKeyName );
520 cControler = conwrapviewControl->getControler();*/
523 bool isedit = _theViewPanel->isEditableCControler(theKeyName);
524 bool ispartofstaticlst = kernelManager->IsPartOfStaticList(theKeyName);
526 if (isedit && ispartofstaticlst)
528 _theViewPanel->removeFromScene(theKeyName);
530 kernelManager->deleteCModel(theKeyName);
531 //_theViewPanel->getSceneManager()->removeFromScene( theKeyName );
532 //cViewer = conwrapviewControl->getViewer();
533 //_theViewPanel->getSceneManager()->removeWrap( theKeyName );
534 //cControler* conwrapviewControl->getControler();
537 // delete cControler;
542 void wxContourMainFrame::onDeleteContoursActSlice(){
543 //JCP 20-10-08 Undo redo implementation
545 //JCP 20-10-08 Undo redo implementation
546 deleteContours( (std::vector<std::string>)_theViewPanel->getSceneManager()->GetlstContoursNameActualSlice() );
548 void wxContourMainFrame::onDeleteAllContours(){
549 //JCP 20-10-08 Undo redo implementation
553 void wxContourMainFrame::deleteAllContours(){
554 //JCP 20-10-08 Undo redo implementation
557 std::vector<int> tempVector;
558 _instantPanel->getInstant( tempVector );
560 //JCP --08-09-2008 When using a diferent interface the _mbarrangeDeleteAll might not be initialize
561 // the values in GetStart and GetEnd will then not be initialize also.
562 // We use instead the values given when initializing the _deletepanel.
564 //int minZ = _mbarrangeDeleteAll->GetStart();
565 //int maxZ = _mbarrangeDeleteAll->GetEnd();
569 maxZ = _theViewPanel->getSceneManager()->GetImageDataSizeZ();
573 _theViewPanel->getSceneManager()->removeSceneContours( );
574 _theViewPanel->getSceneManager()->removeAllOutlines();
575 kernelManager->removeAllOutlines();
578 if ( (minZ==0) && (maxZ==_mbarrangeDeleteAll->GetMax() ))
580 _theViewPanel->getSceneManager()->removeSceneContours( );
581 _modelManager->removeAllOutlines();
582 _theViewPanel->getSceneManager()->removeAllOutlines();
585 for ( z=minZ ; z<=maxZ ; z++)
588 Instant instant(&tempVector);
589 std::vector<ContourThing**> lstContourThings = this->_modelManager->getOutlinesAtInstant( &instant );
591 sizeLstContourThings = lstContourThings.size();
592 for (ii=0 ; ii<sizeLstContourThings ; ii++)
594 ContourThing **contourthing = lstContourThings[ii];
595 deleteContour( (*contourthing)->getName() );
602 void wxContourMainFrame::setConceptValue( std::string name, int value ){
603 _instantPanel->setConceptValue(name, value);
607 ConceptDataWrap* wxContourMainFrame::getLastConceptData(){
608 return _instantPanel->getLastConceptData();
612 bool wxContourMainFrame::getIfConceptCheckedAt( std::string name, int pos ){
613 return _instantPanel->getIfConceptCheckedAt( name, pos );
618 void wxContourMainFrame::ShowResultImages(int typeContourGroup, int selection, int minZ, int maxZ)
621 vtkImageData * value;
622 this->getMaskValue(&mask, &value, typeContourGroup, selection, minZ, maxZ);
624 std::vector<int> nTypeView;
625 nTypeView.push_back(5);
626 nTypeView.push_back(1);
627 nTypeView.push_back(2);
628 nTypeView.push_back(0);
630 wxFrame *frame = new wxFrame(this, -1,_T("Result image extracted.."),wxDefaultPosition,wxSize(600,600), wxDEFAULT_FRAME_STYLE|wxSTAY_ON_TOP);
631 wxAuiManager *m_mgr_noteBookViewerResult = new wxAuiManager();
632 m_mgr_noteBookViewerResult->SetManagedWindow(frame);
634 wxAuiNotebook* noteBookViewerResult = new wxAuiNotebook(frame, -1, wxPoint(600, 600), wxSize(430,200), m_notebook_style);
635 m_mgr_noteBookViewerResult->AddPane(noteBookViewerResult, wxAuiPaneInfo().Name(wxT("notebook_content")).CenterPane().PaneBorder(false));
637 wxPanel *panelViewer1 = new wxMaracas_N_ViewersWidget(noteBookViewerResult, value,&nTypeView);
638 wxPanel *panelViewer2 = new wxMaracas_N_ViewersWidget(noteBookViewerResult, mask,&nTypeView);
641 noteBookViewerResult->AddPage( panelViewer1, wxT("Image result") );
642 noteBookViewerResult->AddPage( panelViewer2, wxT("Mask result") );
643 m_mgr_noteBookViewerResult->Update();
650 void wxContourMainFrame::changeInstant()
652 std::vector<int> instantVect;
653 _instantPanel->getInstant( instantVect );
654 int actualSlice = instantVect[1];
656 kernelManager->setInstant(instantVect);
658 // Refresh Mask image
659 if(_viewMaskImage!=NULL){
660 _viewMaskImage->SetZ(actualSlice);
661 if (_viewMaskImagePanel->IsVisible()==true)
663 vtkImageData *mask, *value;
664 getMaskValue(&mask,&value, _contourGroup , 0, -1, -1);
665 _viewMaskImage->onThreshold();
669 // Refresh Threshold image
670 if(_viewThresholdImage!=NULL){
671 _viewThresholdImage->SetZ(actualSlice);
672 if (_viewThresholdImagePanel->IsVisible()==true){
673 _viewThresholdImage->onThreshold();
677 // Refresh Threshold image
678 if(_viewColorLayerImage!=NULL){
679 _viewColorLayerImage->SetZ(actualSlice);
680 if (_viewColorLayerImagePanel->IsVisible()==true){
681 _viewColorLayerImage->onThreshold();
685 updateInstantOutlines();
686 updateInstantImageData();
692 void wxContourMainFrame :: updateInstantOutlines()
694 _theViewPanel->removeSceneContours();
695 _theViewPanel->addNameWrapperToScene();
697 //for( int i=0; i<size; i++)
699 // _theViewPanel->getSceneManager()->addToScene(namesWrapping[i]->getKeyName(), true, true, true, false, false );
703 int wxContourMainFrame::getNamesWrappingSize(){
704 return kernelManager->getNamesWrappingSize();
706 std::string wxContourMainFrame::getNameWrapping(int i){
707 return kernelManager->getNameWrapping(i);
710 void wxContourMainFrame::updateInstantImageData()
712 std::vector<int> inst;
713 _instantPanel->getInstant(inst);
715 vtkImageData* img = kernelManager->getImageAtInstant(inst);
717 _theViewPanel->changeImage(img);
720 int z = _instantPanel->getConceptDataOf("Axe Depth")->getActualValue();
721 _theViewPanel->setImageSlice(z);
725 void wxContourMainFrame::updateInstantAxes()
730 void wxContourMainFrame::onChangeDeep(int val){
731 _instantPanel->setConceptValue( "Axe Depth", (int)val );
736 void wxContourMainFrame::onCopy(){
737 std::vector<std::string> currentSelection = _theViewPanel->getSelectedObjects();
739 std::vector<int> tempVector;
740 _instantPanel->getInstant( tempVector );
741 _performingOperation->reset();
742 _performingOperation->setStartCommand( COPY );
743 _performingOperation->setStartOperationInstantVector( tempVector );
744 _performingOperation->setKeyNamesOperationElems( currentSelection );
747 void wxContourMainFrame::onPaste(){
750 char theStartCommand = _performingOperation->getStartCommand();
751 if ( theStartCommand == COPY )
753 //JCP 20-10-08 Undo redo implementation
755 //JCP 20-10-08 Undo redo implementation
756 std::vector<int> tempVector;
757 _instantPanel->getInstant( tempVector );
758 _performingOperation->setEndOperationInstantVector ( tempVector );
759 std::vector<std::string> elems = _performingOperation->getKeyNamesOperationElems();
760 int i,size = elems.size();
761 for( i=0; i<size; i++ )
763 createCopyContourOf( elems[i], tempVector, i>0 );
767 void wxContourMainFrame::onUndo(){
768 std::string filename;
769 if(kernelManager->onUndoSaveFile(filename)){
770 saveFileWithContours(filename);
772 if(kernelManager->onUndo(filename)){
776 void wxContourMainFrame::onRedo(){
777 std::string filename;
778 if(kernelManager->onRedo(filename)){
783 void wxContourMainFrame :: createCopyContourOf ( std::string anExistingKName, std::vector<int> &instantNoTouchData, bool append )
785 std::string cloneName = kernelManager->createCopyContourOf( anExistingKName, instantNoTouchData );
786 manualBaseModel * manualModel = kernelManager->getOutlineByKeyName(cloneName);//_modelManager->getOutlineByKeyName( cloneName )->getModel();
787 _theViewPanel->getSceneManager()->createCopyContourOf( anExistingKName, cloneName, manualModel , append );
790 ///AD: 03-09 Copy the object and apply the given transformation
791 void wxContourMainFrame :: createMirrorContourOf ( std::string anExistingKName, std::vector<int> &instantNoTouchData, bool append )
793 std::string cloneName = kernelManager->createCopyContourOf( anExistingKName, instantNoTouchData );
794 manualBaseModel * manualModel = kernelManager->getOutlineByKeyName(cloneName);
796 manualPoint * refPoint1 = _refLineModel->GetManualPoint(0);
797 manualPoint * refPoint2 = _refLineModel->GetManualPoint(1);
799 double pnt1X = refPoint1->GetX();
800 double pnt1Y = refPoint1->GetY();
801 // double pnt1Z = refPoint1->GetZ();
802 double pnt2X = refPoint2->GetX();
803 double pnt2Y = refPoint2->GetY();
804 // double pnt2Z = refPoint2->GetZ();
806 double angle = (atan2(pnt2Y - pnt1Y, pnt2X - pnt1X) * 180 / 3.1415926535897932384626433832795)+90;
807 vtkTransform *t = vtkTransform::New();
811 t->Translate(-pnt1X, -pnt1Y, 0);
815 t->Translate(pnt1X, pnt1Y, 0);
818 int i,size=manualModel->GetSizeLstPoints();
821 manualPoint * mp = manualModel->GetManualPoint(i);
827 t->TransformPoint( vecIn, vecOut );
828 mp->SetPointX( vecOut[0] );
829 mp->SetPointY( vecOut[1] );
830 mp->SetPointZ( vecOut[2] );
833 _theViewPanel->getSceneManager()->createCopyContourOf( anExistingKName, cloneName, manualModel , append );
837 void wxContourMainFrame ::loadState(std::string filename){
840 onLoadContours(filename,false);
844 FILE *pFile=fopen(filename.c_str(),"r+");
846 fscanf(pFile,"%s",tmp); // --CreaContour--
848 fscanf(pFile,"%s",tmp); // Version
849 fscanf(pFile,"%s",tmp); // 1.0.3 || 1.0.2 || 1.0.1 || 1.0.0
853 loadContours(pFile, false);
854 loadContours(pFile, true);
863 void wxContourMainFrame::loadContours( FILE *pFile, bool staticContour )
867 if (staticContour==false)
869 fscanf(pFile,"%s",tmp); // ImageDimensions
870 fscanf(pFile,"%s",tmp); // X
871 fscanf(pFile,"%s",tmp); // Y
872 fscanf(pFile,"%s",tmp); // Z
874 fscanf(pFile,"%s",tmp); // ImageSpacing
875 fscanf(pFile,"%s",tmp); // X
876 fscanf(pFile,"%s",tmp); // Y
877 fscanf(pFile,"%s",tmp); // Z
880 fscanf(pFile,"%s",tmp); // NumberOfContours
881 fscanf(pFile,"%s",tmp); // ##
882 int numberOfContours = atoi(tmp);
884 std::vector<int> instantVector;
885 int typeContourModel;
886 manualBaseModel *manModelContour;
890 for (i=0;i<numberOfContours;i++)
892 instantVector.clear();
893 fscanf(pFile,"%s",tmp); // Instant
894 fscanf(pFile,"%s",tmp); // 1
895 instantVector.push_back( atoi(tmp) );
896 fscanf(pFile,"%s",tmp); // 2
897 instantVector.push_back( atoi(tmp) );
898 fscanf(pFile,"%s",tmp); // 3
899 instantVector.push_back( atoi(tmp) );
900 fscanf(pFile,"%s",tmp); // 4
901 instantVector.push_back( atoi(tmp) );
902 fscanf(pFile,"%s",tmp); // 5
903 instantVector.push_back( atoi(tmp) );
904 fscanf(pFile,"%s",tmp); // 6
905 instantVector.push_back( atoi(tmp) );
907 fscanf(pFile,"%s",tmp); // TypeContourModel
908 fscanf(pFile,"%s",tmp); // ##
909 typeContourModel = atoi(tmp);
911 manModelContour = kernelManager->factoryManualContourModel(typeContourModel);
912 manModelContour->Open(pFile);
914 fscanf(pFile,"%s",tmp); // TypeView
915 fscanf(pFile,"%s",tmp); // ##
916 typeView = atoi(tmp);
919 theName = kernelManager->createOutline( manModelContour, instantVector );
920 bool addedModel = theName.compare("") != 0;
923 double spc[3];//Si no hay imagen pero hay contornos que spacing se pone por default
924 _theViewPanel->getSpacing(spc);
925 //Adding the manualContourControler to interface objects structure
926 //Adding the manualViewContour to interface objects structure
927 //_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.
928 _theViewPanel->getSceneManager()->configureViewControlTo( theName, manModelContour,spc , typeView) ;
931 if (staticContour==true)
933 Instant instant(&instantVector);
934 kernelManager->changeContourOfManager( theName , &instant );
936 }// for numberOfContours
941 void wxContourMainFrame::onLoad()
943 std::string fileNameContourROI = GetFileLocation();
944 //CMRU 03-09-09-----------------------------------------------------------------------------------------------
945 if(GetFileLocation().empty())
947 //------------------------------------------------------------------------------------------------------------
948 wxFileDialog dialog(NULL, _T("Choose a file"), _T(""), _T(""), _T("*.roi"), wxOPEN );
949 if (dialog.ShowModal() == wxID_OK)
951 fileNameContourROI = (const char *)(dialog.GetPath().mb_str());
955 onLoadContours(fileNameContourROI,true);
959 void wxContourMainFrame::onLoadContours(std::string fileNameContourROI, bool interactiveInterface)
964 FILE *pFile =fopen(fileNameContourROI.c_str(),"r+");
967 //CMRU 03-09-09- ----------------------------------------------------------------------------------------------
970 //------------------------------------------------------------------------------------------------------------
971 fileNameContourROI.append("data");
972 FILE *pFileData=fopen(fileNameContourROI.c_str(),"r+");
973 if(pFileData != NULL)
975 fscanf(pFileData,"%s",tmpD); // --CreaContour--
976 fscanf(pFileData,"%s",tmpD); // Version
977 fscanf(pFileData,"%s",tmpD); // 1.0.3 || 1.0.2 || 1.0.1 || 1.0.0
979 fscanf(pFileData,"%s",tmpD); // onePixelSize
980 fscanf(pFileData,"%s",tmpD); // #
981 _onePixelSize = atof(tmpD);
982 fscanf(pFileData,"%s",tmpD); // NumberOfContours
983 fscanf(pFileData,"%s",tmpD); // #
986 fscanf(pFile,"%s",tmp); // --CreaContour--
988 fscanf(pFile,"%s",tmp); // Version
989 fscanf(pFile,"%s",tmp); // 1.0.3 || 1.0.2 || 1.0.1 || 1.0.0
990 std::string version(tmp);
993 _tmpReadFileTypeOfTransformation=-1;
994 if (version=="1.0.3")
996 readDimSpc(pFile,interactiveInterface); // DimSpc interactive ON
997 openContours(pFile,pFileData,false);
998 openContours(pFile,pFileData,true); //Load StaticContours
1001 if (version=="1.0.2")
1004 readDimSpc(pFile,interactiveInterface); // DimSpc interactive ON
1005 openContours(pFile,pFileData,false);
1006 readDimSpc(pFile,false); // DimSpc interactive OFF
1007 openContours(pFile,pFileData,true); //Load StaticContours
1011 else if (version=="1.0.1")
1013 openContours(pFile,pFileData,false); //Skips ImageDimensions and ImageSpacing
1014 openContours(pFile,pFileData,true); //Load StaticContours, skips ImageDimensions and ImageSpacing
1018 else if (version=="1.0.0")
1020 openContours(pFile,pFileData,false); //Skips ImageDimensions and ImageSpacing
1025 if(pFileData != NULL)
1030 _theViewPanel->getSceneManager()->removeSceneContours();
1037 void wxContourMainFrame::onImport(){
1038 std::string filename, filenamecontours;
1039 wxFileDialog dialog(NULL, _T("Choose a XML Osirix File"), _T(""), _T(""), _T("*.xml"), wxOPEN );
1041 if (dialog.ShowModal() == wxID_OK)
1043 filename = dialog.GetPath().mb_str();
1044 filenamecontours = kernelManager->parseOsirixFile(filename);
1046 if(filenamecontours.compare("") != 0){
1047 onLoadContours(filenamecontours,true);
1052 void wxContourMainFrame::onTest(){
1053 std::string filename, filenamecontours;
1054 wxFileDialog dialog(NULL, _T("Choose a File"), _T(""), _T(""), _T("*.*"), wxOPEN );
1056 if (dialog.ShowModal() == wxID_OK)
1058 filename = dialog.GetPath().mb_str();
1059 std::cout << "This is the filename: " << filename << std::endl;
1065 void wxContourMainFrame::onSave(){
1066 //CMRU 03-09-09-----------------------------------------------------------------------------------------------
1067 if(GetFileLocation().empty())
1069 //------------------------------------------------------------------------------------------------------------
1070 wxFileDialog dialog(NULL, _T("Choose a file"), _T(""), _T(""), _T("*.roi"), wxSAVE );
1071 if (dialog.ShowModal() == wxID_OK)
1073 std::string fileNameContourROI = (const char *)(dialog.GetPath().mb_str());
1074 kernelManager->setCurrentFileName(fileNameContourROI);
1075 saveFileWithContours( fileNameContourROI );
1078 //CMRU 03-09-09-----------------------------------------------------------------------------------------------
1081 std::cout<<"Nombre del archivo: "<<GetFileLocation()<<std::endl;
1082 std::string fileNameContourROI = GetFileLocation();
1083 std::cout<<"Nombre del archivo: "<<fileNameContourROI<<std::endl;
1084 kernelManager->setCurrentFileName(fileNameContourROI);
1085 saveFileWithContours( fileNameContourROI);
1087 //------------------------------------------------------------------------------------------------------------
1091 void wxContourMainFrame::saveFileWithContours( std::string filename )
1094 FILE *pFile=fopen(filename.c_str(),"w+");
1096 //CMRU 03-09-09-----------------------------------------------------------------------------------------------
1097 filename.append("data");
1098 std::cout<<"Nombre del archivo: "<<filename<<std::endl;
1099 FILE *pFileData=fopen(filename.c_str(),"w+");
1100 //------------------------------------------------------------------------------------------------------------
1102 std::vector< std::string > lstNameThings;
1103 int i,sizeLstNameThings;
1105 fprintf(pFile,"--CreaContour--\n");
1106 fprintf(pFile,"Version %s\n", "1.0.3" );
1108 //CMRU 03-09-09-----------------------------------------------------------------------------------------------
1109 fprintf(pFileData,"--CreaContour--\n");
1110 fprintf(pFileData,"Version %s\n", "1.0.3" );
1111 fprintf(pFileData,"OnePixelSize %f\n", _onePixelSize);
1113 //------------------------------------------------------------------------------------------------------------
1115 vtkImageData *image = _images[0];
1118 image->GetDimensions(dimRange);
1120 fprintf(pFile,"ImageDimensions %d %d %d\n", dimRange[0], dimRange[1], dimRange[2] );
1123 image->GetSpacing(spaRange);
1125 fprintf(pFile,"ImageSpacing %f %f %f\n", spaRange[0], spaRange[1], spaRange[2] );
1129 lstNameThings = kernelManager->GetLstNameThings();
1130 sizeLstNameThings = lstNameThings.size();
1131 fprintf(pFile,"NumberOfContours %d\n", sizeLstNameThings );
1133 //CMRU 03-09-09-----------------------------------------------------------------------------------------------
1134 fprintf(pFileData,"NumberOfContours %d\n", sizeLstNameThings );
1135 //------------------------------------------------------------------------------------------------------------
1137 for (i=0 ; i<sizeLstNameThings ; i++)
1139 //CMRU 03-09-09-----------------------------------------------------------------------------------------------
1140 manualBaseModel * manualModel = kernelManager->getOutlineByKeyName(lstNameThings[i]);
1141 double sizeInPixel = manualModel ->GetPathSize();
1142 double realContourSize = sizeInPixel*_onePixelSize;
1143 manualModel ->SetRealSize(realContourSize);
1144 //------------------------------------------------------------------------------------------------------------
1146 //int size= kernelManager->GetLstNameThings().size();
1148 kernelManager->SaveThingName( pFile, pFileData, lstNameThings[i] );
1149 _theViewPanel->getSceneManager()->SaveThingName( pFile, lstNameThings[i] );
1152 //-- Static Contours
1154 // fprintf(pFile,"ImageDimensions %d %d %d\n", dimRange[0], dimRange[1], dimRange[2] );
1155 // fprintf(pFile,"ImageSpacing %f %f %f\n", spaRange[0], spaRange[1], spaRange[2] );
1157 lstNameThings = kernelManager->GetLstNameThingsStatic();
1158 sizeLstNameThings = lstNameThings.size();
1159 fprintf(pFile,"NumberOfContoursStatic %d\n", sizeLstNameThings );
1161 //CMRU 03-09-09-----------------------------------------------------------------------------------------------
1162 fprintf(pFileData,"NumberOfContoursStatic %d\n", sizeLstNameThings );
1163 //------------------------------------------------------------------------------------------------------------
1165 for (i=0 ; i<sizeLstNameThings ; i++)
1167 kernelManager->SaveThingName( pFile, pFileData, lstNameThings[i] );
1168 _theViewPanel->getSceneManager()->SaveThingName( pFile, lstNameThings[i] );
1176 void wxContourMainFrame::readDimSpc(FILE *pFile, bool interactiveOption)
1180 double imageSpac[3];
1181 vtkImageData *image = _images[0];
1182 image->GetDimensions(imageDim);
1183 image->GetSpacing(imageSpac);
1185 fscanf(pFile,"%s",tmp); // ImageDimensions
1186 fscanf(pFile,"%s",tmp); // X
1187 _tmpReadFileImageDim[0] = atoi(tmp);
1188 fscanf(pFile,"%s",tmp); // Y
1189 _tmpReadFileImageDim[1] = atoi(tmp);
1190 fscanf(pFile,"%s",tmp); // Z
1191 _tmpReadFileImageDim[2] = atoi(tmp);
1193 fscanf(pFile,"%s",tmp); // ImageSpacing
1194 fscanf(pFile,"%s",tmp); // X
1195 _tmpReadFileImageSpac[0] = atof(tmp);
1196 fscanf(pFile,"%s",tmp); // Y
1197 _tmpReadFileImageSpac[1] = atof(tmp);
1198 fscanf(pFile,"%s",tmp); // Z
1199 _tmpReadFileImageSpac[2] = atof(tmp);
1202 if (interactiveOption==true)
1204 //Compare Spacing and Dims in X and Y (Necessary in Z?) - Just for Version 2
1205 if (imageDim[0]!=_tmpReadFileImageDim[0] || imageDim[1]!=_tmpReadFileImageDim[1] || imageSpac[0]!=_tmpReadFileImageSpac[0] || imageSpac[1]!=_tmpReadFileImageSpac[1])
1207 wxDialog* dial = new wxDialog (this,-1,_T("Tools"),wxDefaultPosition, wxSize(260,160));
1208 wxSizer* buttonsSizer = dial->CreateSeparatedButtonSizer(wxOK|wxCANCEL);
1209 wxBoxSizer *dialSizer = new wxBoxSizer(wxVERTICAL);
1211 wxString lstOptOperation[2];
1212 lstOptOperation[0]=_T("By Dimension");
1213 lstOptOperation[1]=_T("By Spacing");
1214 wxRadioBox * radioOpts = new wxRadioBox(dial, -1, _T("Type of Transformation"), wxDefaultPosition, wxSize(270,45), 2 , lstOptOperation, 2, wxRA_SPECIFY_COLS);
1216 dialSizer->Add( new wxStaticText(dial,-1,_T("The image resolution is not compatible with the ")) , 0, wxGROW );
1217 dialSizer->Add( new wxStaticText(dial,-1,_T("selected Roi file. Do you want to tranform it?")) , 0, wxGROW );
1218 dialSizer->Add( new wxStaticText(dial,-1,_T(" ")) , 0, wxGROW );
1219 dialSizer->Add(radioOpts,0,wxGROW);
1220 dialSizer->Add( new wxStaticText(dial,-1,_T(" ")) , 0, wxGROW );
1221 dialSizer->Add(buttonsSizer,0,wxGROW);
1222 dial->SetSizer(dialSizer, true);
1226 int _tmpReadFileTypeOfTransformation = -1;
1227 //EED bool transform = false;
1229 if (dial->GetReturnCode() == wxID_OK)
1231 _tmpReadFileTypeOfTransformation = radioOpts->GetSelection();
1235 } // if interactiveOption
1242 void wxContourMainFrame::openContours( FILE *pFile, FILE *pFileData, bool staticContour )
1247 vtkImageData *image = _images[0];
1250 double imageSpac[3];
1251 image->GetDimensions(imageDim);
1252 image->GetSpacing(imageSpac);
1255 fscanf(pFile,"%s",tmp); // NumberOfContours
1256 fscanf(pFile,"%s",tmp); // ##
1257 int numberOfContours = atoi(tmp);
1259 std::vector<int> instantVector;
1260 int typeContourModel;
1261 manualBaseModel *manModelContour;
1265 if (compatible==true)
1268 for (i=0;i<numberOfContours;i++)
1270 instantVector.clear();
1271 fscanf(pFile,"%s",tmp); // Instant
1273 fscanf(pFile,"%s",tmp); // 1
1274 instantVector.push_back( atoi(tmp) );
1275 fscanf(pFile,"%s",tmp); // 2
1276 instantVector.push_back( atoi(tmp) );
1277 fscanf(pFile,"%s",tmp); // 3
1278 instantVector.push_back( atoi(tmp) );
1279 fscanf(pFile,"%s",tmp); // 4
1280 instantVector.push_back( atoi(tmp) );
1281 fscanf(pFile,"%s",tmp); // 5
1282 instantVector.push_back( atoi(tmp) );
1283 fscanf(pFile,"%s",tmp); // 6
1284 instantVector.push_back( atoi(tmp) );
1287 fscanf(pFile,"%s",tmp); // TypeContourModel
1288 fscanf(pFile,"%s",tmp); // ##
1289 typeContourModel = atoi(tmp);
1291 manModelContour = kernelManager->factoryManualContourModel(typeContourModel);
1292 manModelContour->Open(pFile);
1293 if(pFileData != NULL)
1295 manModelContour->OpenData(pFileData);
1298 fscanf(pFile,"%s",tmp); // TypeView
1299 fscanf(pFile,"%s",tmp); // ##
1300 typeView = atoi(tmp);
1302 std::string theName;
1303 theName = kernelManager->createOutline( manModelContour, instantVector );
1304 bool addedModel = theName.compare("") != 0;
1307 double spc[3];//Si no hay imagen pero hay contornos que spacing se pone por default
1308 _theViewPanel->getSpacing(spc);
1309 //Adding the manualContourControler to interface objects structure
1310 //Adding the manualViewContour to interface objects structure
1311 //_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.
1312 _theViewPanel->getSceneManager()->configureViewControlTo( theName, manModelContour,spc , typeView) ;
1315 if (staticContour) //StaticContours (will appear in all slices)
1317 Instant instant(&instantVector);
1318 kernelManager->changeContourOfManager( theName , &instant );
1321 }// for numberOfContours
1324 else if (compatible==false)
1329 for (i=0;i<numberOfContours;i++)
1331 instantVector.clear();
1332 fscanf(pFile,"%s",tmp); // Instant
1334 fscanf(pFile,"%s",tmp); // 1
1335 instantVector.push_back( atoi(tmp) );
1336 fscanf(pFile,"%s",tmp); // 2
1337 instantVector.push_back( atoi(tmp) );
1338 fscanf(pFile,"%s",tmp); // 3
1339 instantVector.push_back( atoi(tmp) );
1340 fscanf(pFile,"%s",tmp); // 4
1341 instantVector.push_back( atoi(tmp) );
1342 fscanf(pFile,"%s",tmp); // 5
1343 instantVector.push_back( atoi(tmp) );
1344 fscanf(pFile,"%s",tmp); // 6
1345 instantVector.push_back( atoi(tmp) );
1347 fscanf(pFile,"%s",tmp); // TypeContourModel
1348 fscanf(pFile,"%s",tmp); // ##
1349 typeContourModel = atoi(tmp);
1351 manModelContour = kernelManager->factoryManualContourModel(typeContourModel);
1352 manModelContour->Open(pFile);
1353 if(pFileData != NULL)
1355 manModelContour->OpenData(pFileData);
1358 if (_tmpReadFileTypeOfTransformation==-1){
1360 } else if (_tmpReadFileTypeOfTransformation==0){
1361 double transX, transY;
1362 transX = (double) imageDim[0]/_tmpReadFileImageDim[0];
1363 transY = (double) imageDim[1]/_tmpReadFileImageDim[1];
1364 manModelContour->Transform_Ax_Plus_B(transX,0,transY,0);
1365 } else if (_tmpReadFileTypeOfTransformation==1) {
1366 double transX, transY;
1367 transX = (double) _tmpReadFileImageSpac[0]/imageDim[0];
1368 transY = (double) _tmpReadFileImageSpac[1]/imageDim[1];
1369 manModelContour->Transform_Ax_Plus_B(transX,0,transY,0);
1372 fscanf(pFile,"%s",tmp); // TypeView
1373 fscanf(pFile,"%s",tmp); // ##
1374 typeView = atoi(tmp);
1376 std::string theName;
1377 theName = kernelManager->createOutline( manModelContour, instantVector );
1378 bool addedModel = theName.compare("") != 0;
1381 double spc[3];//Si no hay imagen pero hay contornos que spacing se pone por default
1382 _theViewPanel->getSpacing(spc);
1383 //Adding the manualContourControler to interface objects structure
1384 //Adding the manualViewContour to interface objects structure
1385 //_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.
1386 _theViewPanel->getSceneManager()->configureViewControlTo( theName, manModelContour,spc , typeView) ;
1389 if (staticContour) //StaticContours (will appear in all slices)
1391 Instant instant(&instantVector);
1392 kernelManager->changeContourOfManager( theName , &instant );
1394 }// for numberOfContours
1400 void wxContourMainFrame::RefreshInterface(){
1402 _theViewPanel->RefreshInterface();
1403 //wxVtk2DBaseView *wxvtk2dbaseview = (wxVtk2DBaseView*)this->_theViewPanel->getWxVtkBaseView();
1404 //wxvtk2dbaseview->Refresh();
1407 vtkImageData* wxContourMainFrame::getImageData(){
1408 return _theViewPanel->getImageData();
1411 void wxContourMainFrame::onSegmentationOneSliceITK(wxString distance, wxString sigma, wxString alfa, wxString beta, wxString propagation, wxString iterations, wxString inflation)
1413 //JCP 20-10-08 Undo redo implementation
1415 //JCP 20-10-08 Undo redo implementation
1418 int x = _theViewPanel->GetX();
1419 int y = _theViewPanel->GetY();
1420 int z = _theViewPanel->GetZ();
1421 SegmentationOneSliceITK( x,y,z,distance, sigma, alfa, beta, propagation, iterations, inflation);
1425 void wxContourMainFrame::SegmentationOneSliceITK(int x, int y, int z, wxString distanc, wxString sigm, wxString alf, wxString bet, wxString prop, wxString iter, wxString inflation)
1427 int typeofcontour = 1;
1429 vtkImageData *imagedata = getImageData();
1431 //Tipo de pixeles a utilizar internamente en ITK
1432 typedef float InternalPixelType;
1433 const unsigned int Dimension = 2;
1434 typedef itk::Image< InternalPixelType, Dimension > InternalImageType;
1436 //Tipo de pixeles de salida 1
1437 typedef unsigned char OutputPixelType;
1438 typedef itk::Image< OutputPixelType, Dimension > OutputImageType;
1440 //Tipo de pixeles de salida 2
1441 typedef unsigned short OutputPixelType2;
1442 typedef itk::Image< OutputPixelType2, Dimension > OutputImageType2;
1444 //DefiniciÛn del thresholder
1445 typedef itk::BinaryThresholdImageFilter<
1447 OutputImageType > ThresholdingFilterType;
1449 //DefiniciÛn del primer filtro de conversiÛn de pixeles
1450 typedef itk::CastImageFilter<
1451 OutputImageType, OutputImageType2 > CastFilterType;
1453 //DefiniciÛn del segundo tipo de conversiÛn de pixeles
1454 typedef itk::CastImageFilter<
1455 OutputImageType2, InternalImageType > CastFilterType2;
1457 //Tercer tipo de conversiÛn
1458 typedef itk::RescaleIntensityImageFilter<
1460 OutputImageType > CastFilterType3;
1462 //Cuarto tipo de conversiÛn
1463 typedef itk::RescaleIntensityImageFilter<
1465 OutputImageType > CastFilterType4;
1467 ThresholdingFilterType::Pointer thresholder = ThresholdingFilterType::New();
1469 thresholder->SetLowerThreshold( 0.0 );
1470 thresholder->SetUpperThreshold( 128 );
1472 thresholder->SetOutsideValue( 255 );
1473 thresholder->SetInsideValue( 0 );
1475 //DefinciÛn de conexiÛnes entre VTK e ITK y el writer
1476 typedef itk::VTKImageToImageFilter<OutputImageType2> ConnectorType;
1477 typedef itk::ImageToVTKImageFilter<OutputImageType> ConnectorType2;
1478 //EED10JUIN2011 typedef itk::ImageFileWriter< OutputImageType > WriterType;
1480 ConnectorType::Pointer connector= ConnectorType::New();
1481 ConnectorType2::Pointer connector2= ConnectorType2::New();
1484 CastFilterType::Pointer filter=CastFilterType::New();
1485 CastFilterType2::Pointer filter2=CastFilterType2::New();
1487 connector->SetInput( imagedata );
1488 filter2->SetInput(connector->GetOutput());
1490 typedef itk::CurvatureAnisotropicDiffusionImageFilter<
1492 InternalImageType > SmoothingFilterType;
1494 SmoothingFilterType::Pointer smoothing = SmoothingFilterType::New();
1496 typedef itk::GradientMagnitudeRecursiveGaussianImageFilter<
1498 InternalImageType > GradientFilterType;
1500 typedef itk::SigmoidImageFilter<
1502 InternalImageType > SigmoidFilterType;
1504 GradientFilterType::Pointer gradientMagnitude = GradientFilterType::New();
1506 SigmoidFilterType::Pointer sigmoid = SigmoidFilterType::New();
1508 sigmoid->SetOutputMinimum( 0.0 );
1509 sigmoid->SetOutputMaximum( 255.0 );
1512 typedef itk::FastMarchingImageFilter<
1514 InternalImageType > FastMarchingFilterType;
1517 FastMarchingFilterType::Pointer fastMarching = FastMarchingFilterType::New();
1519 printf("EED wxContourMainFrame::SegmentationOneSliceITK Skypping this code. Not compiling GeodesicActiveContourLevelSetImageFilter in fedora 17 with ITK 3.20.1 \n ");
1521 >>>>>>>>>>> Not compiling GeodesicActiveContourLevelSetImageFilter in fedora 17 with ITK 3.20.1
1524 typedef itk::GeodesicActiveContourLevelSetImageFilter< InternalImageType,
1525 InternalImageType > GeodesicActiveContourFilterType;
1526 GeodesicActiveContourFilterType::Pointer geodesicActiveContour =
1527 GeodesicActiveContourFilterType::New();
1529 typedef itk::ZeroCrossingImageFilter<
1531 InternalImageType > ZeroCrossingFilterType;
1532 ZeroCrossingFilterType::Pointer zeroCrossing =
1533 ZeroCrossingFilterType::New();
1535 const double propagationScaling = atof( crea::wx2std(prop).c_str() );
1537 geodesicActiveContour->SetPropagationScaling( propagationScaling );
1538 geodesicActiveContour->SetCurvatureScaling( 1.0 );
1539 geodesicActiveContour->SetAdvectionScaling( 1.0 );
1541 geodesicActiveContour->SetMaximumRMSError( 0.02 );
1542 int it=atoi( crea::wx2std(iter).c_str() );
1543 geodesicActiveContour->SetNumberOfIterations( it );
1545 smoothing->SetInput( filter2->GetOutput() );
1546 gradientMagnitude->SetInput( smoothing->GetOutput() );
1547 sigmoid->SetInput( gradientMagnitude->GetOutput() );
1548 fastMarching->SetInput( sigmoid->GetOutput() );
1549 geodesicActiveContour->SetInput( fastMarching->GetOutput() );
1550 geodesicActiveContour->SetFeatureImage( sigmoid->GetOutput() );
1552 zeroCrossing->SetInput( geodesicActiveContour->GetOutput() );
1553 //thresholder->SetInput( zeroCrossing->GetOutput() );
1554 thresholder->SetInput( geodesicActiveContour->GetOutput() );
1555 connector2->SetInput( thresholder->GetOutput() );
1563 smoothing->SetTimeStep( 0.125 );
1564 smoothing->SetNumberOfIterations( 5 );
1565 smoothing->SetConductanceParameter( 9.0 );
1568 const double sigma = atof( crea::wx2std(sigm).c_str() );
1569 gradientMagnitude->SetSigma( sigma );
1571 const double alpha = atof( crea::wx2std(alf).c_str() );
1572 const double beta = atof( crea::wx2std(bet).c_str() );
1574 sigmoid->SetAlpha( alpha );
1575 sigmoid->SetBeta( beta );
1577 typedef FastMarchingFilterType::NodeContainer NodeContainer;
1578 typedef FastMarchingFilterType::NodeType NodeType;
1580 NodeContainer::Pointer seeds = NodeContainer::New();
1582 InternalImageType::IndexType seedPosition;
1583 seedPosition[0] = x;
1584 seedPosition[1] = y;
1586 const double initialDistance = atof( crea::wx2std(distanc).c_str() );
1590 const double seedValue = - initialDistance;
1592 node.SetValue( seedValue );
1593 node.SetIndex( seedPosition );
1595 seeds->Initialize();
1596 seeds->InsertElement( 0, node );
1598 fastMarching->SetTrialPoints( seeds );
1600 fastMarching->SetSpeedConstant( 1.0 );
1602 fastMarching->SetOutputSize(
1603 connector->GetOutput()->GetBufferedRegion().GetSize() );
1605 fastMarching->SetStoppingValue( 800 );
1609 connector2->Update();
1610 vtkImageData *idata = connector2->GetOutput();
1612 vtkMarchingContourFilter* cntVTK = vtkMarchingContourFilter::New( );
1614 cntVTK->SetInput( idata );
1616 cntVTK->SetNumberOfContours( 1 );
1617 cntVTK->SetValue( 0, 255 );
1619 cntVTK->UpdateInformation();
1621 vtkCleanPolyData* cpd = vtkCleanPolyData::New( );
1622 cpd->SetInput( cntVTK->GetOutput( ) );
1624 cpd->UpdateInformation();
1626 vtkPolyDataConnectivityFilter* conn = vtkPolyDataConnectivityFilter::New( );
1627 conn->SetExtractionModeToLargestRegion( );
1628 conn->SetInput( cpd->GetOutput( ) );
1630 conn->UpdateInformation();
1632 vtkStripper* vtkstripper = vtkStripper::New( );
1633 vtkstripper->SetInput( conn->GetOutput() );
1634 vtkstripper->Update();
1635 vtkstripper->UpdateInformation();
1637 vtkPolyData* polyDataResult = cntVTK->GetOutput();
1638 //std::cout<<"Points "<<polyDataResult->GetNumberOfPoints()<<std::endl;
1639 polyDataResult->Update( );
1640 polyDataResult->UpdateInformation();
1645 myfile.open ("C:/Creatis/example.txt");
1647 polyDataResult->Print(myfile);
1648 myfile << "-------------------------------------\n";
1649 polyDataResult->GetLines()->Print(myfile);
1657 //--Calculating control points
1659 std::vector<double> vecX;
1660 std::vector<double> vecY;
1661 std::vector<double> vecXo;
1662 std::vector<double> vecYo;
1663 std::vector<double>::iterator vecXoi;
1664 std::vector<double>::iterator vecYoi;
1665 std::vector<double> vecZ;
1667 std::vector<double> vecCtrlPointX;
1668 std::vector<double> vecCtrlPointY;
1669 std::vector<double> vecCtrlPointZ;
1675 int ii,size=polyDataResult->GetNumberOfPoints();
1677 myfile.open ("C:/Creatis/example2.txt");
1679 size=polyDataResult->GetNumberOfPoints();
1680 for (ii=0;ii<size;ii++)
1687 p = polyDataResult->GetPoint(ii);
1690 /*if(fabs(yAct-y)>20)
1692 if((xAct-x)>1 || (xAct-x)<-1)
1694 vecX.push_back( p[0] );
1695 vecY.push_back( p[1] );
1696 myfile <<p[0]<<","<<p[1]<<"\n";
1697 std::cout<<" x Anterior "<<xAct<<" x actual "<<x<<std::endl;
1698 std::cout<<" y Anterior "<<yAct<<" y actual "<<y<<std::endl;
1699 std::cout<<" x "<<p[0]<<" y "<<p[1]<<std::endl;
1700 vecZ.push_back( 900 );
1706 vecXo.push_back(p[0]);
1707 vecYo.push_back(p[1]);
1711 else*/ if(fabs(xAct-x)>11)
1713 vecXo.push_back(p[0]);
1714 vecYo.push_back(p[1]);
1718 vecX.push_back( p[0] );
1719 myfile <<p[0]<<","<<p[1]<<"\n";
1720 //std::cout<<" x Anterior "<<xAct<<" x actual "<<x<<std::endl;
1721 //std::cout<<" y Anterior "<<yAct<<" y actual "<<y<<std::endl;
1722 //std::cout<<" x "<<p[0]<<" y "<<p[1]<<std::endl;
1723 vecY.push_back( p[1] );
1724 vecZ.push_back( 900 );
1732 while(!vecXo.empty())
1734 vecX.push_back(vecXo.back());
1735 //std::cout<<" x Siguiente "<<vecXo.back();
1737 vecZ.push_back( 900 );
1739 while(!vecYo.empty())
1741 vecY.push_back(vecYo.back());
1746 /*for(int l=0;l<vecX.size();l++)
1750 vecXo.push_back(p[0]);
1751 vecYo.push_back(p[1]);
1762 ExtractControlPoints2D *extractcontrolpoints2d = new ExtractControlPoints2D();
1764 extractcontrolpoints2d->SetContour( &vecX , &vecY , &vecZ );
1768 extractcontrolpoints2d->GetInitialControlPoints( &vecCtrlPointX , &vecCtrlPointY , &vecCtrlPointZ );
1770 else if (method==1){
1771 extractcontrolpoints2d->GetControlPoints( &vecCtrlPointX , &vecCtrlPointY , &vecCtrlPointZ );
1773 else if (method==2){
1774 extractcontrolpoints2d->SetSamplingControlPoints( 15 );
1775 extractcontrolpoints2d->GetSamplingControlPoints( &vecCtrlPointX , &vecCtrlPointY , &vecCtrlPointZ );
1777 //--Adding contour to the system
1779 std::vector<int> actualInstantVector;
1780 _instantPanel->getInstant( actualInstantVector );
1781 actualInstantVector[1]=z;
1783 int j,sizeCtrPt = vecCtrlPointX.size();
1785 manualBaseModel *manModelContour = kernelManager->factoryManualContourModel( typeofcontour );
1786 manModelContour->SetNumberOfPointsSpline( ((sizeCtrPt/100)+1)*100 );
1788 for (j=0 ; j<sizeCtrPt ; j++)
1790 manModelContour->AddPoint( vecCtrlPointX[j] , vecCtrlPointY[j] , vecCtrlPointZ[j] );
1792 std::string theName;
1793 //theName = _modelManager->createOutline( manModelContour, actualInstantVector );
1794 theName = kernelManager->createOutline( manModelContour, actualInstantVector );
1795 bool addedModel = theName.compare("") != 0;
1798 double spc[3];//Si no hay imagen pero hay contornos que spacing se pone por default
1799 _theViewPanel->getSpacing(spc);
1800 //Adding the manualContourControler to interface objects structure
1801 //Adding the manualViewContour to interface objects structure
1802 //_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.
1803 _theViewPanel->configureViewControlTo(theName, manModelContour, spc, typeofcontour);
1804 //_theViewPanel->getSceneManager()->configureViewControlTo( theName, manModelContour,spc, typeofcontour ) ;
1811 WriterType::Pointer writer = WriterType::New();
1812 CastFilterType3::Pointer caster = CastFilterType3::New();
1814 caster->SetInput( gradientMagnitude->GetOutput() );
1815 writer->SetInput( caster->GetOutput() );
1816 writer->SetFileName("Gradient Magnitude.png");
1817 caster->SetOutputMinimum( 0 );
1818 caster->SetOutputMaximum( 255 );
1821 CastFilterType3::Pointer caster2 = CastFilterType3::New();
1822 WriterType::Pointer writer2 = WriterType::New();
1824 caster2->SetInput( sigmoid->GetOutput() );
1825 writer2->SetInput( caster2->GetOutput() );
1826 writer2->SetFileName("Sigmoid.png");
1827 caster2->SetOutputMinimum( 0 );
1828 caster2->SetOutputMaximum( 255 );
1831 CastFilterType3::Pointer caster3 = CastFilterType3::New();
1832 WriterType::Pointer writer3 = WriterType::New();
1834 caster3->SetInput( fastMarching->GetOutput() );
1835 writer3->SetInput( caster3->GetOutput() );
1836 writer3->SetFileName("FastMarching.bmp");
1837 caster3->SetOutputMinimum( 0 );
1838 caster3->SetOutputMaximum( 255 );
1841 CastFilterType3::Pointer caster4 = CastFilterType3::New();
1842 WriterType::Pointer writer4 = WriterType::New();
1844 caster4->SetInput( geodesicActiveContour->GetOutput() );
1845 writer4->SetInput( caster4->GetOutput() );
1846 writer4->SetFileName("GeodesicActiveContour.png");
1847 caster4->SetOutputMinimum( 0 );
1848 caster4->SetOutputMaximum( 255 );
1851 CastFilterType3::Pointer caster5 = CastFilterType3::New();
1852 WriterType::Pointer writer5 = WriterType::New();
1854 caster5->SetInput( zeroCrossing->GetOutput() );
1855 writer5->SetInput( caster5->GetOutput() );
1856 writer5->SetFileName("ZeroCrossing.bmp");
1857 caster5->SetOutputMinimum( 0 );
1858 caster5->SetOutputMaximum( 255 );
1862 catch( itk::ExceptionObject & excep )
1864 std::cerr << "Exception caught !" << std::endl;
1865 std::cerr << excep << std::endl;
1869 void wxContourMainFrame::onSegmentationOneSlice(int isovalue,int sampling,int method){
1871 //JCP 20-10-08 Undo redo implementation
1873 //JCP 20-10-08 Undo redo implementation
1876 int x = _theViewPanel->GetX();
1877 int y = _theViewPanel->GetY();
1878 int z = _theViewPanel->GetZ();
1879 SegmentationOneSlice( x,y,z,isovalue, sampling, method );
1884 void wxContourMainFrame::SegmentationOneSlice( int x, int y, int z, int isovalue, int sampling, int method )
1886 int typeofcontour = 1;
1887 //--Extracting Contour
1888 //vtkImageData *imagedata = _theViewPanel->getSceneManager()->GetImageData();
1889 vtkImageData *imagedata = getImageData();
1890 // double *range = imagedata->GetScalarRange();
1893 vtkImageReslice *imageReslice = vtkImageReslice::New();
1896 // imagedata->GetSpacing(spc);
1901 imageReslice->SetInput( imagedata );
1902 imageReslice->SetInformationInput(imagedata);
1903 imageReslice->SetResliceAxesDirectionCosines(1,0,0, 0,1,0 ,0,0,1);
1904 imageReslice->SetResliceAxesOrigin(0,0,z);
1905 imageReslice->SetOutputDimensionality(2);
1906 imageReslice->SetInterpolationModeToLinear();
1908 imagedata = imageReslice->GetOutput();
1909 imagedata->Update();
1910 imagedata->UpdateInformation();
1912 vtkContourFilter* cntVTK = vtkContourFilter::New( );
1913 cntVTK->SetInput( imagedata );
1915 cntVTK->SetNumberOfContours( 1 );
1916 //cntVTK->SetValue( 0, vmin );
1917 // cntVTK->SetValue( 0, (range[1]*thr/100) );
1918 cntVTK->SetValue( 1, isovalue );
1919 // cntVTK->SetValue( 1, vmax );
1921 cntVTK->UpdateInformation();
1923 vtkCleanPolyData* cpd = vtkCleanPolyData::New( );
1924 cpd->SetInput( cntVTK->GetOutput( ) );
1925 cpd->ConvertLinesToPointsOff( );
1927 cpd->UpdateInformation();
1929 vtkPolyDataConnectivityFilter* conn = vtkPolyDataConnectivityFilter::New( );
1930 conn->SetExtractionModeToClosestPointRegion( );
1931 //conn->SetMaxRecursionDepth( 3000 );
1933 conn->SetInput( cpd->GetOutput( ) );
1935 conn->SetClosestPoint( x, y, 0 );
1937 conn->UpdateInformation();
1939 vtkCleanPolyData* cpd2 = vtkCleanPolyData::New( );
1940 cpd2->SetInput( conn->GetOutput( ) );
1942 cpd2->UpdateInformation();
1944 vtkStripper* vtkstripper = vtkStripper::New( );
1945 vtkstripper->SetInput( cpd2->GetOutput() );
1946 vtkstripper->Update();
1947 vtkstripper->UpdateInformation();
1950 vtkPolyData* polyDataResult = vtkstripper->GetOutput();
1952 polyDataResult->Update( );
1953 polyDataResult->UpdateInformation();
1957 myfile.open ("c:/temp/example.txt");
1959 polyDataResult->Print(myfile);
1960 myfile << "-------------------------------------\n";
1961 polyDataResult->GetLines()->Print(myfile);
1971 //--Calculating control points
1973 std::vector<double> vecX;
1974 std::vector<double> vecY;
1975 std::vector<double> vecZ;
1977 std::vector<double> vecCtrlPointX;
1978 std::vector<double> vecCtrlPointY;
1979 std::vector<double> vecCtrlPointZ;
1983 int ii,size=polyDataResult->GetNumberOfPoints();
1985 for (ii=1;ii<=size;ii++)
1987 id = polyDataResult->GetLines()->GetData()->GetValue(ii);
1988 p = polyDataResult->GetPoint(id);
1991 vecX.push_back( p[0] );
1992 vecY.push_back( p[1] );
1993 vecZ.push_back( 900 );
1994 // vecZ.push_back( p[2] );
1998 ExtractControlPoints2D *extractcontrolpoints2d = new ExtractControlPoints2D();
1999 extractcontrolpoints2d->SetContour( &vecX , &vecY , &vecZ );
2002 /*if (methodRadiobox->GetSelection()==0){
2003 extractcontrolpoints2d->GetInitialControlPoints( &vecCtrlPointX , &vecCtrlPointY , &vecCtrlPointZ );
2005 if (methodRadiobox->GetSelection()==1){
2006 extractcontrolpoints2d->GetControlPoints( &vecCtrlPointX , &vecCtrlPointY , &vecCtrlPointZ );
2008 if (methodRadiobox->GetSelection()==2){
2009 extractcontrolpoints2d->SetSamplingControlPoints( sampling );
2010 extractcontrolpoints2d->GetSamplingControlPoints( &vecCtrlPointX , &vecCtrlPointY , &vecCtrlPointZ );
2014 extractcontrolpoints2d->GetInitialControlPoints( &vecCtrlPointX , &vecCtrlPointY , &vecCtrlPointZ );
2016 else if (method==1){
2017 extractcontrolpoints2d->GetControlPoints( &vecCtrlPointX , &vecCtrlPointY , &vecCtrlPointZ );
2019 else if (method==2){
2020 extractcontrolpoints2d->SetSamplingControlPoints( sampling );
2021 extractcontrolpoints2d->GetSamplingControlPoints( &vecCtrlPointX , &vecCtrlPointY , &vecCtrlPointZ );
2024 //--Adding contour to the system
2026 std::vector<int> actualInstantVector;
2027 _instantPanel->getInstant( actualInstantVector );
2028 actualInstantVector[1]=z;
2030 int j,sizeCtrPt = vecCtrlPointX.size();
2031 manualBaseModel *manModelContour = kernelManager->factoryManualContourModel( typeofcontour );
2032 manModelContour->SetNumberOfPointsSpline( ((sizeCtrPt/100)+1)*100 );
2034 for (j=0 ; j<sizeCtrPt ; j++)
2036 manModelContour->AddPoint( vecCtrlPointX[j] , vecCtrlPointY[j] , vecCtrlPointZ[j] );
2038 std::string theName;
2039 //theName = _modelManager->createOutline( manModelContour, actualInstantVector );
2040 theName = kernelManager->createOutline( manModelContour, actualInstantVector );
2041 bool addedModel = theName.compare("") != 0;
2044 double spc[3];//Si no hay imagen pero hay contornos que spacing se pone por default
2045 _theViewPanel->getSpacing(spc);
2046 //Adding the manualContourControler to interface objects structure
2047 //Adding the manualViewContour to interface objects structure
2048 //_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.
2049 _theViewPanel->configureViewControlTo(theName, manModelContour, spc, typeofcontour);
2050 //_theViewPanel->getSceneManager()->configureViewControlTo( theName, manModelContour,spc, typeofcontour ) ;
2054 int wxContourMainFrame::GetImageDataSizeZ(){
2055 return _theViewPanel->GetImageDataSizeZ();
2058 void wxContourMainFrame::GetImageDataRange(double *range){
2059 _theViewPanel->GetImageDataRange(range);
2062 void wxContourMainFrame::onSegmentationAllSlice(int minZ,int maxZ,int isovalue,int sampling,int method){
2063 //JCP 20-10-08 Undo redo implementation
2065 //JCP 20-10-08 Undo redo implementation
2068 int x = _theViewPanel->GetX();
2069 int y = _theViewPanel->GetY();
2073 double totalZ = maxZ-minZ+1;
2074 for( z=minZ ; z<=maxZ ; z++ )
2076 porcent = 100.0* (z-minZ)/totalZ;
2077 tmpString.Printf(_T(" %d %c %d/%d %d"), (int)porcent , 37 , z-minZ+1, (int)totalZ,z );
2078 interfMainPanel::getInstance()->setLabelSegmentationPanelVTK(tmpString);
2079 //_staticTextSegmentation->SetLabel(tmpString);
2080 SegmentationOneSlice( x,y,z,isovalue, sampling,method );
2082 interfMainPanel::getInstance()->setLabelSegmentationPanelVTK(_T(" "));
2087 //Creates a reference line to be used as the axis of the mirroring
2088 void wxContourMainFrame::referenceLine()
2090 if (_refLineControl==NULL)
2095 vtkImageData *vtkimagedata = _theViewPanel->getImageData();
2096 vtkimagedata->GetSpacing(spc);
2098 wxVtkBaseView * viewer2D = _theViewPanel->getWxVtkBaseView();
2100 _refLineControl = new manualLineControler();
2101 _refLineModel = new manualContourModelLine();
2102 _refLineView = new manualViewLine();
2103 _refLineView->SetModel( _refLineModel );
2104 _refLineView->SetWxVtkBaseView( viewer2D );
2105 _refLineView->SetRange( 2 );
2106 _refLineView->SetZ( 1200 );
2108 _refLineView->SetSpacing(spc);
2110 _refLineView->SetColorNormalContour(0, 0, 1);
2111 _refLineView->SetColorEditContour(0, 0.5, 0.5);
2112 _refLineView->SetWidthLine(4);
2114 _refLineControl->SetModelView( _refLineModel , _refLineView );
2115 vtkInteractorStyleBaseView* style = (vtkInteractorStyleBaseView*)viewer2D->GetInteractorStyleBaseView();
2116 style->AddInteractorStyleMaracas( _refLineControl );
2117 _refLineModel->SetCloseContour(false);
2118 _refLineControl->CreateNewManualContour();
2120 //AD: Inicializar el mirroring con una linea ya pintada
2122 double z = _refLineControl->GetZ();
2125 image->GetDimensions(imageDim);
2126 double x = (double) imageDim[0]/2;
2127 double y1 = (double) (imageDim[1]/2)+15;
2128 double y2 = (double) (imageDim[1]/2)-15;
2130 _refLineControl->AddPoint(x,y1,z);
2131 _refLineControl->AddPoint(x,y2,z);
2132 _refLineControl->SetCompleteCreation(true);
2134 _refLineModel->AddPoint(x,y1,z);
2135 _refLineModel->AddPoint(x,y2,z);
2136 _refLineModel->UpdateSpline();
2138 _refLineView->UpdateViewPoint(0);
2139 _refLineView->UpdateViewPoint(1);
2142 _refLineControl->SetActive(true);
2143 _refLineView->RefreshContour();
2147 //Hides the referenceLine
2148 void wxContourMainFrame::refLineHide()
2150 if (_refLineControl!=NULL)
2152 if (_refLineControl->GetActive())
2154 _refLineView->RemoveCompleteContourActor();
2155 _refLineControl->SetEditable(false);
2156 _refLineControl->SetActive(false);
2163 //Shows the referenceLine
2164 void wxContourMainFrame::refLineShow()
2166 if (_refLineControl!=NULL)
2168 if (_refLineControl->GetActive()==false)
2170 wxVtkBaseView * viewer2D = _theViewPanel->getWxVtkBaseView();
2172 _refLineView->SetModel( _refLineModel );
2173 _refLineView->SetWxVtkBaseView( viewer2D );
2174 _refLineView->SetRange( 2 );
2175 _refLineView->SetZ( 1200 );
2177 _refLineControl->SetModelView( _refLineModel , _refLineView );
2178 vtkInteractorStyleBaseView* style = (vtkInteractorStyleBaseView*)viewer2D->GetInteractorStyleBaseView();
2179 style->AddInteractorStyleMaracas( _refLineControl );
2180 _refLineControl->CreateNewManualContour();
2181 _refLineControl->SetActive(true);
2182 _refLineView->RefreshContour();
2189 void wxContourMainFrame::refLineChangeWidth(int width)
2191 _refLineView->SetWidthLine(width);
2192 _refLineView->RefreshContour();
2198 void wxContourMainFrame::onMirror()
2201 std::vector<std::string> currentSelection = _theViewPanel->getSelectedObjects();
2202 std::vector<std::string> filterCurrentSelection;
2204 std::vector<int> tempVector;
2205 _instantPanel->getInstant( tempVector );
2206 _performingOperation->reset();
2207 _performingOperation->setStartCommand( COPY );
2208 _performingOperation->setStartOperationInstantVector( tempVector );
2209 _performingOperation->setKeyNamesOperationElems( currentSelection );
2211 char theStartCommand = _performingOperation->getStartCommand();
2212 if ( theStartCommand == COPY )
2214 //JCP 20-10-08 Undo redo implementation
2216 //JCP 20-10-08 Undo redo implementation
2217 std::vector<int> tempVector;
2218 _instantPanel->getInstant( tempVector );
2219 _performingOperation->setEndOperationInstantVector ( tempVector );
2220 std::vector<std::string> elems = _performingOperation->getKeyNamesOperationElems();
2221 int i,size = elems.size();
2222 for( i=0; i<size; i++ )
2224 createMirrorContourOf( elems[i], tempVector, i>0 );
2228 //deleteContour( _refName );
2233 void wxContourMainFrame::showAxis(bool show)
2235 _theViewPanel->SetVisibleAxis(show);
2236 _theViewPanel->Refresh();
2240 void wxContourMainFrame::onRigidPressed(){
2241 std::vector<std::string> currentSelection = _theViewPanel->getSelectedObjects();
2242 int elementsSelected = currentSelection.size();
2244 if ( elementsSelected >= 1 ){
2245 //JCP 20-10-08 Undo redo implementation
2247 //JCP 20-10-08 Undo redo implementation
2249 std::vector<int> tempVector;
2250 _instantPanel->getInstant( tempVector );
2251 Instant instant(&tempVector);
2253 int i , size=currentSelection.size();
2254 for ( i=0 ; i<size ; i++ )
2256 kernelManager->changeContourOfManager(currentSelection[i], &instant);
2261 void wxContourMainFrame::onWidthOfContour(double width){
2263 _theViewPanel->removeSceneContours();
2264 _theViewPanel->SetWidthContour(width);
2266 //_theViewPanel->getSceneManager()->SetWidthContour( width );
2271 int wxContourMainFrame::getColorWindow()
2275 vtkImageData * img = getImageData();
2276 img->GetScalarRange(range);
2278 std::cout<<"Val 1: "<<range[0]<<" Val 2: "<<range[1]<<std::endl;
2280 return (int)range[1];
2282 return _theViewPanel->getColorWindow();
2285 int wxContourMainFrame::getWindowLevel()
2289 vtkImageData * img = getImageData();
2290 img->GetScalarRange(range);
2292 std::cout<<"Val 1: "<<range[0]<<" Val 2: "<<range[1]<<std::endl;
2294 return (int)range[1];
2296 return _theViewPanel->getWindowLevel();
2299 void wxContourMainFrame::onBrigthnessColorWindowLevel(int colorwindow,int windowlevel){
2300 _theViewPanel->onBrigthnessColorWindowLevel(colorwindow, windowlevel);
2305 void wxContourMainFrame::onInterpolation(bool interpolate){
2306 _theViewPanel->onInterpolation(interpolate);
2310 void wxContourMainFrame::onChangeInstant(std::string name,int actual){
2311 _instantPanel->setConceptValue( name, actual );
2315 void wxContourMainFrame::resetAppend(){
2316 kernelManager->resetAppend();
2321 void wxContourMainFrame::onSpreadAdd(){
2322 std::vector<double> vecX;
2323 std::vector<double> vecY;
2324 std::vector<double> vecZ;
2325 _theViewPanel->GetPointsOfActualContour(&vecX , &vecY , &vecZ );
2326 std::vector<int> tempVector;
2327 _instantPanel->getInstant( tempVector );
2328 std::string val = kernelManager->onSpreadAdd(&vecX , &vecY , &vecZ, tempVector);
2329 interfMainPanel::getInstance()->appendStringSpread(val);
2333 void wxContourMainFrame::onSpreadAddAll(){
2335 std::vector<int> tempVector;
2336 _instantPanel->getInstant( tempVector );
2339 maxZ = interfMainPanel::getInstance()->GetImageDataSizeZ();
2341 int sizeLstContourThings;
2342 for ( z=minZ ; z<=maxZ ; z++ )
2345 Instant instant(&tempVector);
2346 std::vector<ContourThing**> lstContourThings = kernelManager->getOutlinesAtInstant( &instant );
2347 sizeLstContourThings = lstContourThings.size();
2348 if (sizeLstContourThings>=1)
2350 std::vector<double> vecX;
2351 std::vector<double> vecY;
2352 std::vector<double> vecZ;
2353 ContourThing **contourthing = lstContourThings[0];
2354 manualBaseModel *cModel = (*contourthing)->getModel();
2355 int i,size = cModel->GetNumberOfPointsSpline();
2357 for (i=0; i<size; i++)
2359 cModel->GetSpline_i_Point(i, &x, &y, &z);
2364 std::string val = kernelManager->onSpreadAdd(&vecX , &vecY , &vecZ, tempVector);
2365 interfMainPanel::getInstance()->appendStringSpread(val);
2366 }// if sizeLstContourThings
2371 void wxContourMainFrame::onSpreadGo(int type){
2372 //JCP 20-10-08 Undo redo implementation
2374 //JCP 20-10-08 Undo redo implementation
2376 std::vector<double> vecCtrlPointX;
2377 std::vector<double> vecCtrlPointY;
2378 std::vector<double> vecCtrlPointZ;
2382 std::vector<int> tempVector;
2383 _instantPanel->getInstant( tempVector );
2386 kernelManager->getMaxMinZ(&minZ,&maxZ);
2387 //JSTG_16-07-08_----------------------------------------------------------------
2388 //_contourPropagation->setInterpolationNumber(maxZ-minZ+1);
2389 kernelManager->CalculeSplinePropagation();
2391 double totalZ = maxZ-minZ+1;
2394 //--------------------------------------------------------------------
2395 for ( z=(int)minZ ; z<=(int)maxZ ; z++ )
2397 porcent = 100.0* (z-minZ)/totalZ;
2398 int numero = (int)(z-minZ+1)/(int)totalZ;
2399 std::string stringtemp = " "+kernelManager->intToString(porcent)+"% "+kernelManager->intToString(numero)+" "+kernelManager->intToString(z);
2401 interfMainPanel::getInstance()->setStringSpread(stringtemp);
2403 int typeofcontour = 1;
2404 std::string theName;
2405 manualBaseModel* manModelContour = kernelManager->GetPoints(z, type, &vecCtrlPointX,&vecCtrlPointY,&vecCtrlPointZ, theName,typeofcontour, tempVector);
2407 if( manModelContour!=NULL ){
2408 double spc[3];//Si no hay imagen pero hay contornos que spacing se pone por default
2409 this->_theViewPanel->getSpacing(spc);
2410 //Adding the manualContourControler to interface objects structure
2411 //Adding the manualViewContour to interface objects structure
2412 //_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.
2413 _theViewPanel->configureViewControlTo( theName, manModelContour,spc,typeofcontour ) ;
2418 int numero = (int)(z-minZ+1)/(int)totalZ;
2419 std::string stringtemp = " "+kernelManager->intToString(porcent)+"% "+kernelManager->intToString(numero)+" "+kernelManager->intToString(z);
2421 interfMainPanel::getInstance()->setStringSpread(stringtemp);
2423 //RefreshInterface();
2426 void wxContourMainFrame::getInstantVector(std::vector<int>& tempVector){
2430 std::vector<std::string> wxContourMainFrame::getOutlinesName(int slide){
2431 std::vector<int> tempVector;
2432 _instantPanel->getInstant(tempVector);
2433 //Asignation of slide number should be different ex by name
2434 tempVector[1]=slide;
2435 return kernelManager->getOutlinesNameAtInstant(tempVector);
2439 void wxContourMainFrame::SetScalarRange(int grayRangeMin, int grayRangeMax)
2441 _contourextractdata->SetScalarRange(grayRangeMin,grayRangeMax);
2445 void wxContourMainFrame::onInformationContourLabels(int typeContourGroup,int selection,int minimumZ,int maximumZ,int grayRangeMin, int grayRangeMax)
2447 //EED01Juillet2009 GenerateContourExtractData();
2449 wxString tempString;
2450 int maxContourGroup = 0;
2452 _contourextractdata ->SetTypeOperation( typeContourGroup % 3 );
2454 std::vector<manualBaseModel*> lstManConMod;
2455 std::vector<manualBaseModel*> lstManConModTmp;
2456 std::vector<manualBaseModel*> lstManConModExp;
2457 std::vector<double> pLstValue;
2458 std::vector<double> pLstValuePosX;
2459 std::vector<double> pLstValuePosY;
2460 std::vector<double> pLstValuePosZ;
2463 int resultGrayRangeCount;
2466 double resultAverage;
2467 double resultStandardeviation;
2469 std::vector<int> tempVector;
2470 _instantPanel->getInstant( tempVector );
2472 //EED01Juillet2009 vtkImageData *imagedata = _theViewPanel->getImageData();
2473 // int sizeZ = _theViewPanel->GetImageDataSizeZ();
2475 int ii,sizeLstContourThings;
2484 if (selection==0 ) // actual slice
2486 int actualSlice = tempVector[1];
2489 } else { // slice range
2495 totalZ = maxZ-minZ+1;
2496 //EED01Juillet2009 _contourextractdata->SetImage( imagedata);
2498 _contourextractdata->InitVolumeStatistics();
2501 for ( z=minZ ; z<=maxZ ; z++ )
2504 porcent = 100.0* (z-minZ)/totalZ;
2505 tmpString.Printf(_T(" %d %c %d/%d %d"), (int)porcent , 37 , z-minZ+1, (int)totalZ ,z);
2507 interfMainPanel::getInstance()->setStringInfoPanel(tmpString);
2508 //_staticTextInformation->SetLabel(tmpString);
2510 //Extraction data from contours of each slice
2511 _contourextractdata->SetZtoBeAnalys(z);
2514 Instant instant(&tempVector);
2515 std::vector<ContourThing**> lstContourThings = kernelManager->getOutlinesAtInstant( &instant );
2516 sizeLstContourThings = lstContourThings.size();
2518 lstManConMod.clear();
2519 for (ii=0 ; ii<sizeLstContourThings ; ii++)
2521 ContourThing **contourthing = lstContourThings[ii];
2522 lstManConMod.push_back( (*contourthing)->getModel() );
2525 lstManConModExp = kernelManager->ExploseEachModel( lstManConMod );
2527 tempString.Printf(_T("%d - %d"),z, sizeLstContourThings);
2528 interfMainPanel::getInstance()->setRowLabelInfoPanel(z, tempString);
2529 //_grid->SetRowLabelValue(z, tempString );
2531 int iContourGroup,sizeContourGroup;
2532 if (typeContourGroup==3) // contour separete
2534 sizeContourGroup=lstManConModExp.size();
2535 if ( maxContourGroup<sizeContourGroup )
2537 maxContourGroup=sizeContourGroup;
2539 } else { // contour AND OR XOR
2546 for( iContourGroup=0 ; iContourGroup<sizeContourGroup ; iContourGroup++ ){
2547 lstManConModTmp.clear();
2551 if (typeContourGroup==3) // contour separete
2553 lstManConModTmp.push_back( lstManConModExp[iContourGroup]);
2554 } else { // contour AND OR XOR
2555 lstManConModTmp = lstManConModExp;
2558 _contourextractdata->SetLstManualContourModel( lstManConModTmp );
2559 _contourextractdata->SetScalarRange(grayRangeMin,grayRangeMax);
2562 pLstValuePosX.clear();
2563 pLstValuePosY.clear();
2564 pLstValuePosZ.clear();
2568 _contourextractdata->GetValuesInsideCrown( &numberOfPixels,
2574 resultSize=numberOfPixels;
2575 // Statistics of each slice.
2576 _contourextractdata->Statistics( &pLstValue,
2579 &resultGrayRangeCount,
2584 &resultStandardeviation);
2586 if (interfMainPanel::getInstance()->getNumberColsInformationPanel()<_numberOfVariablesStatistics*(iContourGroup+1) )
2588 interfMainPanel::getInstance()->appendColsInformationPanel(_numberOfVariablesStatistics);
2591 tmpIntA=_numberOfVariablesStatistics*iContourGroup ;
2593 tempString.Printf(_T("%d"),numberOfPixels);
2595 interfMainPanel::getInstance()->setCellValueInfoPanel(z, tmpIntA, tempString);
2597 tempString.Printf(_T("%d"),resultGrayRangeCount);
2598 interfMainPanel::getInstance()->setCellValueInfoPanel(z, tmpIntA+1, tempString);
2600 tempString.Printf(_T("%f"),resultMin);
2601 interfMainPanel::getInstance()->setCellValueInfoPanel(z, tmpIntA+2, tempString);
2603 tempString.Printf(_T("%f"),resultMax);
2604 interfMainPanel::getInstance()->setCellValueInfoPanel(z, tmpIntA+3, tempString);
2606 tempString.Printf(_T("%f"),resultAverage);
2607 interfMainPanel::getInstance()->setCellValueInfoPanel(z, tmpIntA+4, tempString);
2609 tempString.Printf(_T("%f"),resultStandardeviation);
2610 interfMainPanel::getInstance()->setCellValueInfoPanel(z, tmpIntA+5, tempString);
2613 } // for iContourGroup
2616 // Print Volume Statistics
2619 int vol_rCountRange;
2621 double vol_minValue;
2622 double vol_maxValue;
2624 double vol_standardeviation;
2626 if (selection!=0 ) // actual slice
2629 _contourextractdata->GetVolumeStatistics(&vol_rCountRange, &vol_rsize,
2630 &vol_minValue, &vol_maxValue,
2631 &vol_average, &vol_standardeviation);
2633 interfMainPanel::getInstance()->setRowLabelInfoPanel(maxZ+2, _T("Total:"));
2635 tempString.Printf(_T("%d"),vol_rsize);
2636 interfMainPanel::getInstance()->setCellValueInfoPanel(maxZ+2, 0, tempString);
2638 tempString.Printf(_T("%d"),vol_rCountRange);
2639 interfMainPanel::getInstance()->setCellValueInfoPanel(maxZ+2, 1, tempString);
2641 tempString.Printf(_T("%f"),vol_minValue);
2642 interfMainPanel::getInstance()->setCellValueInfoPanel(maxZ+2, 2, tempString);
2644 tempString.Printf(_T("%f"),vol_maxValue);
2645 interfMainPanel::getInstance()->setCellValueInfoPanel(maxZ+2, 3, tempString);
2647 tempString.Printf(_T("%f"),vol_average);
2648 interfMainPanel::getInstance()->setCellValueInfoPanel(maxZ+2, 4, tempString);
2650 tempString.Printf(_T("%f"),vol_standardeviation);
2651 interfMainPanel::getInstance()->setCellValueInfoPanel(maxZ+2, 5, tempString);
2653 //-----------------------------------------
2656 wxString tmpTitleString;
2658 for ( iTitleGroup=0 ; iTitleGroup<maxContourGroup ; iTitleGroup++ )
2660 tmpIntB =_numberOfVariablesStatistics*iTitleGroup;
2661 tmpTitleString.Printf(_T("%d-Size Data"),iTitleGroup);
2662 interfMainPanel::getInstance()->setColLableInfoPanel(tmpIntB + 0, tmpTitleString);
2664 interfMainPanel::getInstance()->setColLableInfoPanel(tmpIntB + 0, tmpTitleString );
2665 interfMainPanel::getInstance()->setColLableInfoPanel( tmpIntB + 1, _T("Size Range") );
2666 interfMainPanel::getInstance()->setColLableInfoPanel( tmpIntB + 2, _T("Min") );
2667 interfMainPanel::getInstance()->setColLableInfoPanel( tmpIntB + 3, _T("Max") );
2668 interfMainPanel::getInstance()->setColLableInfoPanel( tmpIntB + 4, _T("Average") );
2669 interfMainPanel::getInstance()->setColLableInfoPanel( tmpIntB + 5, _T("St.Dev.") );
2670 interfMainPanel::getInstance()->setColLableInfoPanel( tmpIntB + 6, _T(" ") );
2672 interfMainPanel::getInstance()->setStringInfoPanel( _T("") );
2676 void wxContourMainFrame::onSaveResults(std::string directory,std::string namefile, std::string filename,
2677 int typeContourGroup, int selection, int minZ, int maxZ, bool XYZValues, bool contourImage, bool statistics)
2681 SaveValuesXYZ( directory , namefile, typeContourGroup );
2686 vtkImageData * mask;
2687 vtkImageData * value;
2688 this->getMaskValue(&mask, &value, typeContourGroup,selection,minZ,maxZ);
2689 this->SaveImageResult( directory , namefile, mask, value);
2694 std::ostringstream name;
2695 name << filename << ".xls";
2698 FILE *pFile=fopen(name.str().c_str(),"w+");
2704 // int sizeZ = _theViewPanel->GetImageDataSizeZ();
2705 // int maxY=sizeZ+2;
2707 maxX= interfMainPanel::getInstance()->getNumberColsInformationPanel();//this->_grid->GetNumberCols();
2710 int iTitle,sizeTitle = (maxX / _numberOfVariablesStatistics);
2711 for ( iTitle=0; iTitle<sizeTitle ; iTitle++)
2713 // fprintf(pFile,"-- \t %d-Size \t SizeRange \t Min \t Max \t Ave \t StDv \t" , iTitle,tmpString.c_str() );
2714 fprintf(pFile,"slice\t %d-Size \t SizeRange \t Min \t Max \t Ave \t StDv \t" , iTitle );
2716 fprintf(pFile,"\n\n" );
2720 if (selection==0 ) // actual slice
2722 std::vector<int> tempVector;
2723 _instantPanel->getInstant( tempVector );
2724 int actualSlice = tempVector[1];
2730 for ( j=minZ; j<=maxZ ; j++)
2732 fprintf(pFile,"%d\t" , j );
2733 for (i=0 ; i<maxX ; i++){
2734 tmpString = interfMainPanel::getInstance()->getCellValue(j, i);//_grid->GetCellValue( j , i );
2735 fprintf(pFile,"%s\t" , (const char *)(tmpString.mb_str()) );
2737 fprintf(pFile,"\n" );
2741 // Total of stadistics.....
2744 fprintf(pFile,"\n Total:\t" );
2745 for (i=0 ; i<maxX ; i++){
2746 tmpString = interfMainPanel::getInstance()->getCellValue(maxZ+2, i);//_grid->GetCellValue( maxZ+2 , i );
2747 fprintf(pFile,"%s\t" , (const char *)(tmpString.mb_str()) );
2749 fprintf(pFile,"\n" );
2757 void wxContourMainFrame::SaveValuesXYZ(std::string directory,std::string namefile,int typeContourGroup)
2760 //EED01Juillet2009 GenerateContourExtractData();
2762 //int typeContourGroup = this->_radiolstboxContourGroup->GetSelection();
2763 _contourextractdata ->SetTypeOperation( typeContourGroup % 3 );
2765 std::vector<manualBaseModel*> lstManConMod;
2766 std::vector<manualBaseModel*> lstManConModTmp;
2767 std::vector<manualBaseModel*> lstManConModExp;
2768 std::vector<double> pLstValue;
2769 std::vector<double> pLstValuePosX;
2770 std::vector<double> pLstValuePosY;
2771 std::vector<double> pLstValuePosZ;
2773 std::vector<int> tempVector;
2774 _instantPanel->getInstant( tempVector );
2776 //EED01Juillet2009 vtkImageData *imagedata = _theViewPanel->getSceneManager()->GetImageData();
2777 int sizeZ = _theViewPanel->getSceneManager()->GetImageDataSizeZ();
2779 int ii,sizeLstContourThings;
2786 minZ = 0;// _mbarrange->GetStart();
2787 maxZ = sizeZ;//_mbarrange->GetEnd();
2788 totalZ = maxZ-minZ+1;
2790 //EED01Juillet2009 _contourextractdata->SetImage( imagedata);
2793 for ( z=0 ; z<sizeZ ; z++)
2796 porcent = 100.0* (z-minZ)/totalZ;
2798 tmpString.Printf(_T("Saving Values"));
2799 tmpString.Printf(_T(" %d %c %d/%d %d"), (int)porcent , 37 , z-minZ+1, (int)totalZ ,z);
2800 interfMainPanel::getInstance()->setStringInfoPanel(tmpString);
2801 //_staticTextInformation->SetLabel(tmpString);
2804 //Extraction data from contours of each slice
2805 _contourextractdata->SetZtoBeAnalys( z);
2808 Instant instant(&tempVector);
2809 std::vector<ContourThing**> lstContourThings = kernelManager->getOutlinesAtInstant(&instant);//this->_modelManager->getOutlinesAtInstant( &instant );
2810 sizeLstContourThings = lstContourThings.size();
2812 lstManConMod.clear();
2813 for (ii=0 ; ii<sizeLstContourThings ; ii++)
2815 ContourThing **contourthing = lstContourThings[ii];
2816 lstManConMod.push_back( (*contourthing)->getModel() );
2818 lstManConModExp = kernelManager->ExploseEachModel( lstManConMod );
2823 int iContourGroup,sizeContourGroup;
2824 if (typeContourGroup==3) // contour separete
2826 sizeContourGroup=lstManConModExp.size();
2827 } else { // contour AND OR XOR
2831 for( iContourGroup=0 ; iContourGroup<sizeContourGroup ; iContourGroup++ ){
2832 lstManConModTmp.clear();
2833 if (typeContourGroup==3) // contour separete
2835 lstManConModTmp.push_back( lstManConModExp[iContourGroup]);
2836 } else { // contour AND OR XOR
2837 lstManConModTmp = lstManConModExp;
2840 _contourextractdata->SetLstManualContourModel( lstManConModTmp );
2843 pLstValuePosX.clear();
2844 pLstValuePosY.clear();
2845 pLstValuePosZ.clear();
2847 _contourextractdata->GetValuesInsideCrown( &numberOfPixels,
2853 std::string temp = directory + "/" + namefile + "-slice";
2854 temp = temp + kernelManager->intToString(z) + "-cont" + kernelManager->intToString(iContourGroup);
2855 temp = temp + ".txt";
2857 // LG 14/01/09 : using crea
2858 wxString filename = crea::std2wx(temp);
2859 /*filename.Printf(_T("%s"),directory.c_str());
2860 filename.append(_T("\\"));
2861 filename.append(_T("%s"),namefile.c_str());
2862 filename.append(_T("-slice"));
2863 filename.append(_T("%d"),z);
2864 filename.append(_T("-cont"));
2865 filename.append(_T("%d"),iContourGroup);
2866 filename.append(_T(".txt"));*/
2867 // filename.Printf(temp.c_str());
2871 FILE *pFile=fopen((const char *)filename.mb_str(),"w+");
2872 fprintf(pFile,"value \t x \t y \t z\n" );
2873 int iLstValue,sizeLstValue=pLstValue.size();
2874 for (iLstValue=0 ; iLstValue<sizeLstValue ; iLstValue++ )
2876 fprintf(pFile,"%f\t %f\t %f\t %f\n", (float)pLstValue[iLstValue] , (float)pLstValuePosX[iLstValue], (float)pLstValuePosY[iLstValue], (float)z );
2879 } // for iContourGroup
2881 interfMainPanel::getInstance()->setStringInfoPanel(_T(""));
2882 //_staticTextInformation->SetLabel( _T("") );
2886 void wxContourMainFrame::getMaskValue(vtkImageData ** mask,vtkImageData ** value,int typeContourGroup, int selection, int minZ, int maxZ){
2888 //EED01Juillet2009 GenerateContourExtractData();
2890 //int typeContourGroup = this->_radiolstboxContourGroup->GetSelection();
2891 if (typeContourGroup==3)
2895 _contourextractdata ->SetTypeOperation( typeContourGroup % 3 );
2897 std::vector<manualBaseModel*> lstManConMod;
2898 std::vector<manualBaseModel*> lstManConModTmp;
2899 std::vector<manualBaseModel*> lstManConModExp;
2901 std::vector<int> tempVector;
2902 _instantPanel->getInstant( tempVector );
2904 vtkImageData *imagedata = _theViewPanel->getImageData();
2906 imagedata->GetExtent(ext);
2907 int sizeZimage = ext[5]-ext[4]+1;
2909 int ii,sizeLstContourThings;
2918 if (selection==0 ) // actual slice
2920 int actualSlice = tempVector[1];
2927 //EED01Juillet2009 _contourextractdata->SetImage( imagedata);
2929 // cleanning image before range
2930 for (z=0; z<minZ; z++){
2931 _contourextractdata->ResetImageResult(z);
2933 // cleanning image after range
2934 for (z=maxZ+1; z<sizeZimage; z++){
2935 _contourextractdata->ResetImageResult(z);
2940 for ( z=minZ ; z<=maxZ ; z++)
2943 porcent = 100.0* (z-minZ)/totalZ;
2944 tmpString.Printf(_T("Saving Values"));
2945 tmpString.Printf(_T("%d %c %d/%d %d"), (int)porcent , 37 , z-minZ+1, (int)totalZ ,z);
2946 interfMainPanel::getInstance()->setStringInfoPanel(tmpString);
2948 //Extraction data from contours of each slice
2949 _contourextractdata->SetZtoBeAnalys( z);
2952 Instant instant(&tempVector);
2953 std::vector<ContourThing**> lstContourThings = kernelManager->getOutlinesAtInstant( &instant );
2954 sizeLstContourThings = lstContourThings.size();
2956 lstManConMod.clear();
2957 for (ii=0 ; ii<sizeLstContourThings ; ii++)
2959 ContourThing **contourthing = lstContourThings[ii];
2960 lstManConMod.push_back( (*contourthing)->getModel() );
2962 lstManConModExp = kernelManager->ExploseEachModel( lstManConMod );
2965 int iContourGroup,sizeContourGroup;
2966 if (typeContourGroup==3) // contour separete
2968 sizeContourGroup=lstManConModExp.size();
2969 } else { // contour AND OR XOR
2973 for( iContourGroup=0 ; iContourGroup<sizeContourGroup ; iContourGroup++ ){
2974 lstManConModTmp.clear();
2975 if (typeContourGroup==3) // contour separete
2977 lstManConModTmp.push_back( lstManConModExp[iContourGroup]);
2978 } else { // contour AND OR XOR
2979 lstManConModTmp = lstManConModExp;
2982 _contourextractdata->SetLstManualContourModel( lstManConModTmp );
2983 _contourextractdata->CalculateImageResult(); // with actual Z
2985 } // for iContourGroup
2988 (*value) = _contourextractdata->GetVtkImageValueResult();
2989 (*mask) = _contourextractdata->GetVtkImageMaskResult();
2993 void wxContourMainFrame::SaveImageResult(std::string directory,std::string namefile, vtkImageData* mask,vtkImageData* value)
2997 kernelManager->GetSpacing(spc,0); // returns the spacing of the first image
2999 std::string temp = directory + "/" + namefile + "-image-Value.mhd";
3001 wxString filename = crea::std2wx(temp);
3005 vtkImageChangeInformation *valueChInfo = vtkImageChangeInformation::New();
3006 valueChInfo->SetInput(value);
3007 valueChInfo->SetSpacingScale(spc);
3008 vtkMetaImageWriter *writerValueImage = vtkMetaImageWriter::New( );
3009 writerValueImage->SetInput( valueChInfo->GetOutput() );
3010 writerValueImage->SetFileName( (const char *)filename.mb_str() );
3011 writerValueImage->SetFileDimensionality( 3 );
3012 writerValueImage->SetCompression(false);
3013 writerValueImage->Write( );
3016 temp = directory + "/" + namefile + "-image-Mask.mhd";
3018 // LG 14/01/09 : using crea
3019 filename = crea::std2wx(temp);
3020 // filename.Printf(_T(temp.c_str()));
3023 vtkImageChangeInformation *maskChInfo = vtkImageChangeInformation::New();
3024 maskChInfo->SetInput(mask);
3025 maskChInfo->SetSpacingScale(spc);
3026 vtkMetaImageWriter *writerMaskImage = vtkMetaImageWriter::New( );
3027 writerMaskImage->SetInput( maskChInfo->GetOutput() );
3028 writerMaskImage->SetFileName( (const char *)filename.mb_str() );
3029 writerMaskImage->SetFileDimensionality( 3 );
3030 writerMaskImage->SetCompression(false);
3031 writerMaskImage->Write( );
3033 interfMainPanel::getInstance()->setStringInfoPanel( _T("") );
3039 void wxContourMainFrame::onChangeInstantInstantPanel(std::string name,int value, int minshow, int maxshow){
3040 if( name.compare( _theViewPanel->getVerticalConceptName() ) == 0){
3041 _theViewPanel->setActualVertical( value);
3043 else if( name.compare( _theViewPanel->getHorizontalConceptName() ) == 0|| _instantPanel->getIfConceptCheckedAt( name, 0 ) ) {
3044 _theViewPanel->setHorizontalConcept( name, minshow, maxshow, minshow, maxshow, value);
3050 void wxContourMainFrame::onSnakePressed(){
3051 std::vector<double> vecX;
3052 std::vector<double> vecY;
3053 std::vector<double> vecZ;
3054 _theViewPanel->GetPointsOfActualContour( &vecX , &vecY , &vecZ );
3056 if (vecX.size()!=0){
3057 std::vector<int> tempVector;
3058 _instantPanel->getInstant( tempVector );
3059 int i,size=vecZ.size();
3060 int actualSlice = tempVector[1];
3061 for ( i=0 ; i<size ; i++ )
3063 vecZ[i] = actualSlice;
3066 wxDialog* dialog = new wxDialog(this, -1, wxString(_T("Snake")));
3067 wxPanel* panel = new wxPanel(dialog,-1);
3068 // wxStaticText* sttext = new wxStaticText(panel, -1, wxString(_T("Panel para snake")));
3069 new wxStaticText(panel, -1, wxString(_T("Panel para snake")));
3070 dialog->ShowModal();
3075 void wxContourMainFrame::saveFileWithContoursAutomatique(){
3076 std::string filename = kernelManager->getCurrentFileName();
3077 if(filename.compare("")!=0){
3078 saveFileWithContours(filename);
3083 void wxContourMainFrame::ShowToolsPanel(bool show){
3084 _pannew->Show(show);
3089 void wxContourMainFrame::SetContourGroup(int contourGroup)
3091 _contourGroup = contourGroup;
3095 wxPanel *wxContourMainFrame::getMaskImageViewPanel(wxWindow *parent)
3098 if (_viewMaskImagePanel==NULL)
3100 _contourextractdata = new ContourExtractData(true);
3101 _contourextractdata->SetImage( _theViewPanel->getImageData() );
3103 // _theViewPanel->getImageData()->GetScalarRange(range);
3104 //int min = (int)floor (range[0]);
3105 //int max = (int)ceil (range[1]);
3108 _viewMaskImagePanel = new ThresholdImageViewPanel( parent, -1, -1 , 0);
3109 _viewMaskImage = new ThresholdImageView();
3110 _viewMaskImage->SetImage(_contourextractdata->GetVtkImageMaskResult() );
3111 _viewMaskImage->SetminMaxValue( min, max);
3112 _viewMaskImage->SetBaseColor( 0,0,1 );
3113 _viewMaskImagePanel->SetThresholdImageView( _viewMaskImage );
3114 _viewMaskImage->SetwxVtkBaseView( _theViewPanel->getWxVtkBaseView() );
3116 return _viewMaskImagePanel;
3120 wxPanel *wxContourMainFrame::getColorLayerImageViewPanel(wxWindow *parent)
3122 if (_viewColorLayerImagePanel==NULL)
3125 _theViewPanel->getImageData()->GetScalarRange(range);
3126 int min = (int)floor (range[0]);
3127 int max = (int)ceil (range[1]);
3128 _viewColorLayerImagePanel = new ColorLayerImageViewPanel( parent, min, max , 1);
3129 _viewColorLayerImage = new ColorLayerImageView();
3130 // _viewColorLayerImage->SetImage( _theViewPanel->getImageData() );
3131 _viewColorLayerImage->SetImage( NULL );
3132 _viewColorLayerImagePanel->SetColorLayerImageView( _viewColorLayerImage );
3133 _viewColorLayerImage->SetwxVtkBaseView( _theViewPanel->getWxVtkBaseView() );
3135 return _viewColorLayerImagePanel;
3139 wxPanel *wxContourMainFrame::getThresholdImageViewPanel(wxWindow *parent)
3141 if (_viewThresholdImagePanel==NULL)
3144 _theViewPanel->getImageData()->GetScalarRange(range);
3145 int min = (int)floor (range[0]);
3146 int max = (int)ceil (range[1]);
3147 _viewThresholdImagePanel = new ThresholdImageViewPanel( parent, min, max , 1);
3148 _viewThresholdImage = new ThresholdImageView();
3149 _viewThresholdImage->SetImage( _theViewPanel->getImageData() );
3150 _viewThresholdImage->SetminMaxValue( min, max);
3151 _viewThresholdImage->SetBaseColor( 1,0,0 );
3152 _viewThresholdImagePanel->SetThresholdImageView( _viewThresholdImage );
3153 _viewThresholdImage->SetwxVtkBaseView( _theViewPanel->getWxVtkBaseView() );
3155 return _viewThresholdImagePanel;
3158 //CMRU 17-08-09-----------------------------------------------------------------------------------------------
3159 int wxContourMainFrame::getType ()
3162 std::vector<std::string> currentSelection = _theViewPanel->getSelectedObjects();
3164 if(!currentSelection.empty())
3166 std::string cloneName = currentSelection [0];
3167 manualBaseModel * manualModel = kernelManager->getOutlineByKeyName(cloneName);
3168 tipo = manualModel-> GetTypeModel();
3173 double wxContourMainFrame::getContourSizeInPixels()
3175 double contourSize = 0;
3177 std::vector<std::string> currentSelection = _theViewPanel->getSelectedObjects(); if(!currentSelection.empty())
3178 if(!currentSelection.empty())
3180 std::string cloneName = currentSelection [0];
3182 manualBaseModel * manualModel = kernelManager->getOutlineByKeyName(cloneName);//_modelManager->getOutlineByKeyName( cloneName )->getModel();
3183 contourSize = manualModel-> GetPathSize();
3187 manualBaseModel * wxContourMainFrame::getContour ()
3189 std::vector<std::string> currentSelection = _theViewPanel->getSelectedObjects();
3191 if(!currentSelection.empty())
3193 std::string cloneName = currentSelection [0];
3194 manualBaseModel * manualModel = kernelManager->getOutlineByKeyName(cloneName);//_modelManager->getOutlineByKeyName( cloneName )->getModel();
3199 void wxContourMainFrame::onPrintLabel (wxString label, manualBaseModel* manualModel)
3201 std::string labelAscii(label.ToAscii());
3202 int pos = labelAscii.find(" ");
3206 for (j=0 ; pos != string::npos;j++)
3208 labelAscii.replace( pos, 1, "_" );
3209 pos= labelAscii.find(" ");
3212 manualModel -> SetLabel(labelAscii);
3214 void wxContourMainFrame::onInsertCalculation(manualBaseModel* manualModel)
3216 double sizeInPixel = manualModel ->GetPathSize();
3217 double onePixelRealSize = interfMainPanel::getInstance()->GetPixelValue();;
3218 double realContourSize = sizeInPixel*onePixelRealSize;
3219 manualModel ->SetRealSize(realContourSize);
3222 double wxContourMainFrame::onePixelSize( double value)
3224 return _onePixelSize = value;
3227 std::string wxContourMainFrame::GetFileLocation()
3229 return _fileLocation;
3232 void wxContourMainFrame::SetFileLocation(std::string newFileLocation)
3234 _fileLocation = newFileLocation;
3235 std::cout<<"GETFILELOCATION:"<<_fileLocation<<std::endl;
3237 //------------------------------------------------------------------------------------------------------------