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"
18 //----------------------------------------------------------------------------------------------------------------
19 // Class implementation
20 //----------------------------------------------------------------------------------------------------------------
21 /** @file wxContourMainFrame.cxx */
23 //------------------------------------------------------------------------------------------------------------
24 // Constructors & Destructors
25 //------------------------------------------------------------------------------------------------------------
27 wxContourMainFrame* wxContourMainFrame:: instance = NULL;
28 char wxContourMainFrame::COPY = 'C';
30 wxContourMainFrame :: wxContourMainFrame(wxWindow* parent, wxWindowID id,const wxString& title,const wxPoint& pos,const wxSize& size,long style)
31 //: wxPanel(parent, id, title, pos, size, style)
32 //: wxWindow(parent, id, pos, size, style)
33 : wxPanel(parent, id, pos, size, style)
35 m_mgr.SetManagedWindow(this);
36 _creatingContoursActive = false;
38 // _modelManager = NULL;
40 // _buttonsBar = NULL;
42 // _drawToolsPanel = NULL;
43 // _operationsToolsPanel = NULL;
44 //_autoFormsPanel = NULL;
45 // _standardToolsPanel = NULL;
46 // _editionToolsPanel = NULL;
47 // _listViewPanel = NULL;
48 // _sceneManager = NULL;
49 //_actualInstant = NULL;
50 _numberOfVariablesStatistics = 6+1;
52 _refLineControl = NULL;
55 _imageReslicer = NULL;
56 _thresholdTable = NULL;
57 _thresholdMapper = NULL;
58 _thresholdActor = 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;
69 wxContourMainFrame :: wxContourMainFrame(wxWindow* parent, wxWindowID id,const wxString& title,const wxPoint& pos,const wxSize& size,std::vector<vtkImageData*> images, long style,std::string datadir)
70 : wxPanel(parent, id, pos, size, style)
72 m_mgr.SetManagedWindow(this);
73 _creatingContoursActive = false;
77 _refLineControl = NULL;
80 _imageReslicer = NULL;
81 _thresholdTable = NULL;
82 _thresholdMapper = NULL;
83 _thresholdActor = NULL;
84 _actorPresent = false;
86 // set up default notebook style
87 m_notebook_style =wxAUI_NB_TAB_SPLIT | wxAUI_NB_TAB_EXTERNAL_MOVE | wxNO_BORDER;
89 //wxContour_ActionCommandsID a;
90 _numberOfVariablesStatistics = 7;
98 _pannew = interfMainPanel::getInstance(this,datadir+"/data/Icons");//, eventHandler);
99 _performingOperation = new PerformingOperation();
101 if(images.size() > 0)
103 this->setVectImages(images);
106 _contourextractdata = NULL;
109 void wxContourMainFrame::setVectImages(std::vector<vtkImageData*> imgs)
114 #if defined(__GNUC__)
115 std::string str_home(getenv("HOME"));
116 #elif defined(_WIN32)
117 std::string str_home(getenv("USERPROFILE"));
119 std::string strCreaContourDataTmp = str_home + "/.creaContourDataTemp/";
121 std::vector<std::string> conceptNameVect;
122 std::vector<int> conceptSizeVect;
124 notebook = this->createNotebook();
127 kernelManager = new KernelManagerContour( imgs , _datadir+"/data/" , strCreaContourDataTmp );
130 _instantPanel = new wxInstantChooserPanel( notebook, "Instant Chooser", true, false, "c" );
131 _theViewPanel = new wxContourViewPanel( kernelManager->getSourceImage(), notebook );
133 //-------------------------------------------------------------
134 kernelManager->getConceptsInformation(conceptNameVect, conceptSizeVect);
135 _instantPanel->addConcepts(conceptNameVect, conceptSizeVect);
138 double val = _theViewPanel->getCurrentDeep();
139 _instantPanel->setConceptValue( "Axe Depth", (int)val );
140 //JCP _instantPanel->setConceptValue("time", num de imagenes);
141 ConceptDataWrap * data = _instantPanel->getConceptDataOf( "Axe Depth" );
142 //*******************changeInstant();
143 _theViewPanel->setVerticalConcept( "Axe Depth", data->getMinValue(), data->getMaxValue(), data->getMinShowedValue(), data->getMaxShowedValue(), data->getActualValue() );
145 this->configurePanels( );
150 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 ){
151 if(instance == NULL){
152 instance = new wxContourMainFrame(parent, id, title, pos, size, images, style,datadir);
157 std::vector<vtkImageData*> wxContourMainFrame ::getVectImages()
159 return kernelManager->getVectImages();
162 wxContourMainFrame* wxContourMainFrame :: getInstance()
167 void wxContourMainFrame :: resetInstance()
172 wxContourMainFrame :: ~wxContourMainFrame()
174 delete _contourextractdata;
177 interfMainPanel::resetInstance();
178 delete kernelManager;
180 //_pannew->Destroy();
186 //El problema al cerrar la aplicacion puede estar asociado
187 //a que wxAUINotebook esta en la aplicacion
188 //principal (wxContourGUIExample)tambien
189 //EED???? delete _theViewPanel;
190 //EED???? delete _instantPanel;
191 //EED???? delete _buttonsBar;
192 //EED???? delete _actualInstant;
193 //EED???? delete _sceneManager;
197 //------------------------------------------------------------------------------------------------------------
198 // Creational and initialization methods using WxAui
199 //------------------------------------------------------------------------------------------------------------
201 wxAuiNotebook * wxContourMainFrame :: createNotebook()
203 wxSize client_size = GetClientSize();
204 wxAuiNotebook* noteBook = new wxAuiNotebook(this, -1, wxPoint(client_size.x, client_size.y), wxSize(430,200), m_notebook_style);
205 wxBitmap page_bmp = wxArtProvider::GetBitmap(wxART_NORMAL_FILE, wxART_OTHER, wxSize(16,16));
210 //------------------------------------------------------------------------------------------------------------
211 // Creational and initialization methods
212 //------------------------------------------------------------------------------------------------------------
213 bool wxContourMainFrame :: configurePanels( )
215 bool configured = _theViewPanel!=NULL;
217 configured &= _theViewPanel!=NULL;
218 if( _theViewPanel!=NULL )
220 notebook->AddPage( _theViewPanel, wxT(" View ") );
227 notebook->AddPage( _instantPanel, wxT("Instant Page") );
231 m_mgr.AddPane(notebook, wxAuiPaneInfo().Name(wxT("notebook_content")).CenterPane().PaneBorder(false));
234 SetMinSize(wxSize(300,300));
240 bool wxContourMainFrame::addNewPanel(wxPanel* panel)
242 bool configured = panel!=NULL;
243 configured &= panel!=NULL;
247 notebook->AddPage( panel, wxT(" Viewer "), true );
253 //------------------------------------------------------------------------------------------------------------
254 // Attributes getters and setters
255 //------------------------------------------------------------------------------------------------------------
259 void wxContourMainFrame :: setInstantChooserPanel( wxInstantChooserPanel * theInstantChooserPanel )
261 _instantPanel = theInstantChooserPanel;
264 // void wxContourMainFrame :: setButtonsBar( wxContour_ButtonsBar * theButtonsBar )
266 // _buttonsBar = theButtonsBar;
269 // void wxContourMainFrame :: setGrid( wxContour_Grid * theGridPanel )
271 // _gridPanel = theGridPanel;
274 // void wxContourMainFrame :: setDrawToolsPanel( wxContour_DrawToolsPanel * theDrawToolsPanel )
276 // _drawToolsPanel = theDrawToolsPanel;
279 // void wxContourMainFrame :: setOperationsToolsPanel( wxContour_OperationsToolsPanel * theOperationsToolsPanel )
281 // _operationsToolsPanel = theOperationsToolsPanel;
284 // void wxContourMainFrame :: setAutomaticFormsPanel( wxContour_AutomaticFormsToolsPanel * theAutoFormsPanel )
286 // _autoFormsPanel = theAutoFormsPanel;
289 // void wxContourMainFrame :: setStandardToolsPanel( wxContour_StandardToolsPanel * theStandardToolsPanel )
291 // _standardToolsPanel= theStandardToolsPanel;
294 // void wxContourMainFrame :: setEditionToolsPanel( wxContour_EdtionToolsPanel * theEditionToolsPanel )
296 // _editionToolsPanel = theEditionToolsPanel;
299 // void wxContourMainFrame :: setListViewPanel( wxContour_ListViewPanel * theListViewPanel )
301 // _listViewPanel = theListViewPanel;
306 void wxContourMainFrame::onCreateContourSpline( ){
308 //JCP 20-10-08 Undo redo implementation
310 //JCP 20-10-08 Undo redo implementation
314 void wxContourMainFrame::onCreateContourRectangle( ){
315 //JCP 20-10-08 Undo redo implementation
317 //JCP 20-10-08 Undo redo implementation
320 void wxContourMainFrame::onCreateContourCircle( ){
321 //JCP 20-10-08 Undo redo implementation
323 //JCP 20-10-08 Undo redo implementation
327 void wxContourMainFrame::onCreateContourLine( ){
328 //JCP 20-10-08 Undo redo implementation
330 //JCP 20-10-08 Undo redo implementation
334 //------------------------------------------------------------------------------------------------------------
336 void wxContourMainFrame :: onCreateContourBullEye(wxPanel* panel )
338 //Creating the manualContourModel and including in the model
339 manualContourModel * manModelContour = factoryManualContourModel(panel );
341 std::vector<int> instantVector;
342 _instantPanel->getInstant( instantVector );
343 std::string theName = kernelManager->createOutline(manModelContour, instantVector);
345 /*std::vector<int> instantVector;
346 _instantPanel->getInstant( instantVector );
348 theName= _modelManager->createOutline( manModelContour, instantVector );*/
349 bool addedModel = theName.compare("") != 0;//??
353 double spc[3];//Si no hay imagen pero hay contornos que spacing se pone por default
354 _theViewPanel->getSpacing(spc);
355 //Adding the manualContourControler to interface objects structure
356 //Adding the manualViewContour to interface objects structure
357 //_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.
358 _theViewPanel->getSceneManager()->configureViewControlTo( theName, manModelContour,spc , 4) ;
361 void wxContourMainFrame :: createContour( int typeContour )
363 //Creating the manualContourModel and including in the model
364 manualContourModel * manModelContour = kernelManager->factoryManualContourModel(typeContour);
367 std::vector<int> instantVector;
368 _instantPanel->getInstant( instantVector );
369 std::string theName = kernelManager->createOutline(manModelContour, instantVector);
371 /*std::vector<int> instantVector;
372 _instantPanel->getInstant( instantVector );
374 theName= _modelManager->createOutline( manModelContour, instantVector );*/
375 bool addedModel = theName.compare("") != 0;//??
378 double spc[3];//Si no hay imagen pero hay contornos que spacing se pone por default
379 _theViewPanel->getSpacing(spc);
380 //Adding the manualContourControler to interface objects structure
381 //Adding the manualViewContour to interface objects structure
382 //_sceneManager->setControlActiveStateOfALL( false );//This call is being done here because if the ROI is created underneath the previously created ROIS will still be active.
383 _theViewPanel->getSceneManager()->configureViewControlTo( theName, manModelContour,spc , typeContour) ;
387 manualContourModel * wxContourMainFrame::factoryManualContourModel(wxPanel* panel){
389 manualContourModelBullEye *manModelContourBullEye = new manualContourModelBullEye();
390 manualContourModel *manModelContour=NULL;
391 manModelContour = manModelContourBullEye;
393 int iCrown,sizeCrowns,iSector,sizeSectors;
394 double radioA,radioB,ang,angDelta ;
395 sizeCrowns = ((PanelBullEyeOptions*)panel)->GetNumberOfCrowns();
396 for ( iCrown=0 ; iCrown<sizeCrowns ; iCrown++ )
398 sizeSectors = ((PanelBullEyeOptions*)panel)->GetNumberOfSections(iCrown);
399 radioB = ((PanelBullEyeOptions*)panel)->GetRadioOfCrown(iCrown);
400 if (iCrown==sizeCrowns-1)
404 radioA = ((PanelBullEyeOptions*)panel)->GetRadioOfCrown(iCrown+1);
408 for ( iSector=0 ; iSector<sizeSectors ; iSector++ )
410 ang = ((PanelBullEyeOptions*)panel)->GetAngOfCrownSection(iCrown,iSector);
411 angDelta= ((PanelBullEyeOptions*)panel)->GetAngDeltaOfCrownSection(iCrown);
412 manModelContourBullEye->AddSector(radioA,radioB,ang,angDelta);
415 } // if _panelBullEyeOptions
417 return manModelContour;
419 void wxContourMainFrame :: saveState(){
421 std::string temp = kernelManager->saveState();
422 saveFileWithContours(temp);
425 void wxContourMainFrame::onDeleteContour(){
426 //JCP 20-10-08 Undo redo implementation
428 //JCP 20-10-08 Undo redo implementation
430 std::vector<std::string> lstKeyNameToBeErase;
431 lstKeyNameToBeErase = _theViewPanel->getSceneManager()->getSelectedObjects();
432 deleteContours( lstKeyNameToBeErase );
434 int i,size=_sceneManager->getSelectedObjects().size();
437 std::string keyName = _sceneManager->getSelectedObjects()[i];
438 int ispartofstaticlist = this->_modelManager->IsPartOfStaticList( keyName );
439 if ( ispartofstaticlist>=0 )
441 std::vector<int> tempVector;
442 _instantPanel->getInstant( tempVector );
443 Instant instant(&tempVector);
444 this->_modelManager->ChangeContourOfList(keyName, &instant);
448 std::vector<std::string> lstKeyName;
449 std::vector<std::string> lstKeyNameActualSlice;
450 std::vector<std::string> lstKeyNameToBeErase;
452 lstKeyNameToBeErase = _sceneManager->getSelectedObjects();
453 lstKeyNameActualSlice = _sceneManager->GetlstContoursNameActualSlice();
454 int k,kSize=lstKeyNameToBeErase.size();
455 int j,jSize=lstKeyNameActualSlice.size();
457 for (k=0;k<kSize; k++)
460 for (j=0;j<jSize; j++)
462 if (lstKeyNameToBeErase[k]==lstKeyNameActualSlice[j])
469 lstKeyName.push_back( lstKeyNameToBeErase[k] );
473 deleteContours( lstKeyName );
477 void wxContourMainFrame :: deleteContours( std::vector<std::string> keyNamesVector )
479 int i,size=keyNamesVector.size();
482 deleteContour( keyNamesVector[i] );
486 void wxContourMainFrame :: deleteContour( std::string theKeyName ){
488 manualContourModel * cModel;
489 manualViewBaseContour * cViewer;
490 manualContourBaseControler * cControler;
492 ContourWrap_ViewControl *conwrapviewControl = _theViewPanel->getSceneManager()->getContourWrap_ViewControlOf( theKeyName );
493 cControler = conwrapviewControl->getControler();*/
496 bool isedit = _theViewPanel->isEditableCControler(theKeyName);
497 bool ispartofstaticlst = kernelManager->IsPartOfStaticList(theKeyName);
499 if (isedit && ispartofstaticlst)
501 _theViewPanel->removeFromScene(theKeyName);
503 kernelManager->deleteCModel(theKeyName);
504 //_theViewPanel->getSceneManager()->removeFromScene( theKeyName );
505 //cViewer = conwrapviewControl->getViewer();
506 //_theViewPanel->getSceneManager()->removeWrap( theKeyName );
507 //cControler* conwrapviewControl->getControler();
509 //FILE *ff = fopen("c:/temp/wxVtkBaseView_SceneManagerStadistics.txt","a+");
510 //fprintf(ff,"EED wxContourEventHandler::deleteContours() \n" );
511 //fprintf(ff," %s %p\n",keyNamesVector[i].c_str(), cControler );
515 // delete cControler;
520 void wxContourMainFrame::onDeleteContoursActSlice(){
521 //JCP 20-10-08 Undo redo implementation
523 //JCP 20-10-08 Undo redo implementation
524 deleteContours( (std::vector<std::string>)_theViewPanel->getSceneManager()->GetlstContoursNameActualSlice() );
526 void wxContourMainFrame::onDeleteAllContours(){
527 //JCP 20-10-08 Undo redo implementation
531 void wxContourMainFrame::deleteAllContours(){
532 //JCP 20-10-08 Undo redo implementation
535 std::vector<int> tempVector;
536 _instantPanel->getInstant( tempVector );
538 //JCP --08-09-2008 When using a diferent interface the _mbarrangeDeleteAll might not be initialize
539 // the values in GetStart and GetEnd will then not be initialize also.
540 // We use instead the values given when initializing the _deletepanel.
542 //int minZ = _mbarrangeDeleteAll->GetStart();
543 //int maxZ = _mbarrangeDeleteAll->GetEnd();
547 maxZ = _theViewPanel->getSceneManager()->GetImageDataSizeZ();
551 _theViewPanel->getSceneManager()->removeSceneContours( );
552 _theViewPanel->getSceneManager()->removeAllOutlines();
553 kernelManager->removeAllOutlines();
556 if ( (minZ==0) && (maxZ==_mbarrangeDeleteAll->GetMax() ))
558 _theViewPanel->getSceneManager()->removeSceneContours( );
559 _modelManager->removeAllOutlines();
560 _theViewPanel->getSceneManager()->removeAllOutlines();
563 for ( z=minZ ; z<=maxZ ; z++)
566 Instant instant(&tempVector);
567 std::vector<ContourThing**> lstContourThings = this->_modelManager->getOutlinesAtInstant( &instant );
569 sizeLstContourThings = lstContourThings.size();
570 for (ii=0 ; ii<sizeLstContourThings ; ii++)
572 ContourThing **contourthing = lstContourThings[ii];
573 deleteContour( (*contourthing)->getName() );
580 void wxContourMainFrame::setConceptValue( std::string name, int value ){
581 _instantPanel->setConceptValue(name, value);
585 ConceptDataWrap* wxContourMainFrame::getLastConceptData(){
586 return _instantPanel->getLastConceptData();
590 bool wxContourMainFrame::getIfConceptCheckedAt( std::string name, int pos ){
591 return _instantPanel->getIfConceptCheckedAt( name, pos );
596 void wxContourMainFrame::ShowResultImages(int typeContourGroup, int selection, int minZ, int maxZ)
599 vtkImageData * value;
600 this->getMaskValue(&mask, &value, typeContourGroup, selection, minZ, maxZ);
602 std::vector<int> nTypeView;
603 nTypeView.push_back(5);
604 nTypeView.push_back(1);
605 nTypeView.push_back(2);
606 nTypeView.push_back(0);
608 wxFrame *frame = new wxFrame(this, -1,_T("Result image extracted.."),wxDefaultPosition,wxSize(600,600), wxDEFAULT_FRAME_STYLE|wxSTAY_ON_TOP);
609 wxAuiManager *m_mgr_noteBookViewerResult = new wxAuiManager();
610 m_mgr_noteBookViewerResult->SetManagedWindow(frame);
612 wxAuiNotebook* noteBookViewerResult = new wxAuiNotebook(frame, -1, wxPoint(600, 600), wxSize(430,200), m_notebook_style);
613 m_mgr_noteBookViewerResult->AddPane(noteBookViewerResult, wxAuiPaneInfo().Name(wxT("notebook_content")).CenterPane().PaneBorder(false));
615 wxPanel *panelViewer1 = new wxMaracas_N_ViewersWidget(noteBookViewerResult, value,&nTypeView);
616 wxPanel *panelViewer2 = new wxMaracas_N_ViewersWidget(noteBookViewerResult, mask,&nTypeView);
619 noteBookViewerResult->AddPage( panelViewer1, wxT("Image result") );
620 noteBookViewerResult->AddPage( panelViewer2, wxT("Mask result") );
621 m_mgr_noteBookViewerResult->Update();
628 void wxContourMainFrame::changeInstant()
630 std::vector<int> instantVect;
631 _instantPanel->getInstant( instantVect );
632 // Instant * theInstant = new Instant ( &instantVect );
634 //Setting the actual instant
635 //_actualInstant = theInstant;
637 kernelManager->setInstant(instantVect);
638 //_modelManager->setInstant( _actualInstant );
641 updateInstantOutlines();
642 updateInstantImageData();
648 void wxContourMainFrame :: updateInstantOutlines()
650 _theViewPanel->removeSceneContours();
651 _theViewPanel->addNameWrapperToScene();
653 //for( int i=0; i<size; i++)
655 // _theViewPanel->getSceneManager()->addToScene(namesWrapping[i]->getKeyName(), true, true, true, false, false );
659 int wxContourMainFrame::getNamesWrappingSize(){
660 return kernelManager->getNamesWrappingSize();
662 std::string wxContourMainFrame::getNameWrapping(int i){
663 return kernelManager->getNameWrapping(i);
666 void wxContourMainFrame::updateInstantImageData()
668 std::vector<int> inst;
669 _instantPanel->getInstant(inst);
671 vtkImageData* img = kernelManager->getImageAtInstant(inst);
673 _theViewPanel->changeImage(img);
676 int z = _instantPanel->getConceptDataOf("Axe Depth")->getActualValue();
677 _theViewPanel->setImageSlice(z);
681 void wxContourMainFrame::updateInstantAxes()
686 void wxContourMainFrame::onChangeDeep(int val){
687 _instantPanel->setConceptValue( "Axe Depth", (int)val );
692 void wxContourMainFrame::onCopy(){
693 std::vector<std::string> currentSelection = _theViewPanel->getSelectedObjects();
695 std::vector<int> tempVector;
696 _instantPanel->getInstant( tempVector );
697 _performingOperation->reset();
698 _performingOperation->setStartCommand( COPY );
699 _performingOperation->setStartOperationInstantVector( tempVector );
700 _performingOperation->setKeyNamesOperationElems( currentSelection );
703 void wxContourMainFrame::onPaste(){
706 char theStartCommand = _performingOperation->getStartCommand();
707 if ( theStartCommand == COPY )
709 //JCP 20-10-08 Undo redo implementation
711 //JCP 20-10-08 Undo redo implementation
712 std::vector<int> tempVector;
713 _instantPanel->getInstant( tempVector );
714 _performingOperation->setEndOperationInstantVector ( tempVector );
715 std::vector<std::string> elems = _performingOperation->getKeyNamesOperationElems();
716 int i,size = elems.size();
717 for( i=0; i<size; i++ )
719 createCopyContourOf( elems[i], tempVector, i>0 );
723 void wxContourMainFrame::onUndo(){
724 std::string filename;
725 if(kernelManager->onUndoSaveFile(filename)){
726 saveFileWithContours(filename);
728 if(kernelManager->onUndo(filename)){
732 void wxContourMainFrame::onRedo(){
733 std::string filename;
734 if(kernelManager->onRedo(filename)){
739 void wxContourMainFrame :: createCopyContourOf ( std::string anExistingKName, std::vector<int> &instantNoTouchData, bool append )
741 std::string cloneName = kernelManager->createCopyContourOf( anExistingKName, instantNoTouchData );
742 manualContourModel * manualModel = kernelManager->getOutlineByKeyName(cloneName);//_modelManager->getOutlineByKeyName( cloneName )->getModel();
743 _theViewPanel->getSceneManager()->createCopyContourOf( anExistingKName, cloneName, manualModel , append );
746 ///AD: 03-09 Copy the object and apply the given transformation
747 void wxContourMainFrame :: createMirrorContourOf ( std::string anExistingKName, std::vector<int> &instantNoTouchData, bool append )
749 std::string cloneName = kernelManager->createCopyContourOf( anExistingKName, instantNoTouchData );
750 manualContourModel * manualModel = kernelManager->getOutlineByKeyName(cloneName);
752 manualPoint * refPoint1 = _refLineModel->GetManualPoint(0);
753 manualPoint * refPoint2 = _refLineModel->GetManualPoint(1);
755 double pnt1X = refPoint1->GetX();
756 double pnt1Y = refPoint1->GetY();
757 // double pnt1Z = refPoint1->GetZ();
758 double pnt2X = refPoint2->GetX();
759 double pnt2Y = refPoint2->GetY();
760 // double pnt2Z = refPoint2->GetZ();
762 double angle = (atan2(pnt2Y - pnt1Y, pnt2X - pnt1X) * 180 / 3.1415926535897932384626433832795)+90;
763 vtkTransform *t = vtkTransform::New();
767 t->Translate(-pnt1X, -pnt1Y, 0);
771 t->Translate(pnt1X, pnt1Y, 0);
774 int i,size=manualModel->GetSizeLstPoints();
777 manualPoint * mp = manualModel->GetManualPoint(i);
783 t->TransformPoint( vecIn, vecOut );
784 mp->SetPointX( vecOut[0] );
785 mp->SetPointY( vecOut[1] );
786 mp->SetPointZ( vecOut[2] );
789 _theViewPanel->getSceneManager()->createCopyContourOf( anExistingKName, cloneName, manualModel , append );
792 void wxContourMainFrame ::loadState(std::string filename){
794 FILE *pFile=fopen(filename.c_str(),"r+");
796 fscanf(pFile,"%s",tmp); // --CreaContour--
798 fscanf(pFile,"%s",tmp); // Version
799 fscanf(pFile,"%s",tmp); // 1.0.2 || 1.0.1 || 1.0.0
803 loadContours(pFile, false);
804 loadContours(pFile, true);
809 void wxContourMainFrame ::loadContours( FILE *pFile, bool staticContour )
813 fscanf(pFile,"%s",tmp); // ImageDimensions
814 fscanf(pFile,"%s",tmp); // X
815 fscanf(pFile,"%s",tmp); // Y
816 fscanf(pFile,"%s",tmp); // Z
818 fscanf(pFile,"%s",tmp); // ImageSpacing
819 fscanf(pFile,"%s",tmp); // X
820 fscanf(pFile,"%s",tmp); // Y
821 fscanf(pFile,"%s",tmp); // Z
823 fscanf(pFile,"%s",tmp); // NumberOfContours
824 fscanf(pFile,"%s",tmp); // ##
825 int numberOfContours = atoi(tmp);
827 std::vector<int> instantVector;
828 int typeContourModel;
829 manualContourModel *manModelContour;
833 for (i=0;i<numberOfContours;i++)
835 instantVector.clear();
836 fscanf(pFile,"%s",tmp); // Instant
837 fscanf(pFile,"%s",tmp); // 1
838 instantVector.push_back( atoi(tmp) );
839 fscanf(pFile,"%s",tmp); // 2
840 instantVector.push_back( atoi(tmp) );
841 fscanf(pFile,"%s",tmp); // 3
842 instantVector.push_back( atoi(tmp) );
843 fscanf(pFile,"%s",tmp); // 4
844 instantVector.push_back( atoi(tmp) );
845 fscanf(pFile,"%s",tmp); // 5
846 instantVector.push_back( atoi(tmp) );
847 fscanf(pFile,"%s",tmp); // 6
848 instantVector.push_back( atoi(tmp) );
850 fscanf(pFile,"%s",tmp); // TypeContourModel
851 fscanf(pFile,"%s",tmp); // ##
852 typeContourModel = atoi(tmp);
854 manModelContour = kernelManager->factoryManualContourModel(typeContourModel);
855 manModelContour->Open(pFile);
857 fscanf(pFile,"%s",tmp); // TypeView
858 fscanf(pFile,"%s",tmp); // ##
859 typeView = atoi(tmp);
862 theName = kernelManager->createOutline( manModelContour, instantVector );
863 bool addedModel = theName.compare("") != 0;
866 double spc[3];//Si no hay imagen pero hay contornos que spacing se pone por default
867 _theViewPanel->getSpacing(spc);
868 //Adding the manualContourControler to interface objects structure
869 //Adding the manualViewContour to interface objects structure
870 //_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.
871 _theViewPanel->getSceneManager()->configureViewControlTo( theName, manModelContour,spc , typeView) ;
874 if (staticContour==true)
876 Instant instant(&instantVector);
877 kernelManager->changeContourOfManager( theName , &instant );
879 }// for numberOfContours
882 void wxContourMainFrame::onLoad()
885 wxFileDialog dialog(NULL, _T("Choose a file"), _T(""), _T(""), _T("*.roi"), wxOPEN );
886 if (dialog.ShowModal() == wxID_OK)
888 std::string fileNameContourROI = (const char *)(dialog.GetPath().mb_str());
889 FILE *pFile=fopen(fileNameContourROI.c_str(),"r+");
891 fscanf(pFile,"%s",tmp); // --CreaContour--
893 fscanf(pFile,"%s",tmp); // Version
894 fscanf(pFile,"%s",tmp); // 1.0.2 || 1.0.1 || 1.0.0
895 std::string version(tmp);
898 if (version=="1.0.2")
900 openContours(pFile,2,false);
901 openContours(pFile,2,true); //Load StaticContours
905 else if (version=="1.0.1")
907 openContours(pFile,1,false); //Skips ImageDimensions and ImageSpacing
908 openContours(pFile,1,true); //Load StaticContours, skips ImageDimensions and ImageSpacing
912 else if (version=="1.0.0")
914 openContours(pFile,1,false); //Skips ImageDimensions and ImageSpacing
919 _theViewPanel->getSceneManager()->removeSceneContours();
924 void wxContourMainFrame::onSave(){
925 wxFileDialog dialog(NULL, _T("Choose a file"), _T(""), _T(""), _T("*.roi"), wxSAVE );
926 if (dialog.ShowModal() == wxID_OK)
928 std::string fileNameContourROI = (const char *)(dialog.GetPath().mb_str());
929 kernelManager->setCurrentFileName(fileNameContourROI);
930 saveFileWithContours( fileNameContourROI );
935 void wxContourMainFrame::saveFileWithContours( std::string filename )
938 FILE *pFile=fopen(filename.c_str(),"w+");
939 std::vector< std::string > lstNameThings;
940 int i,sizeLstNameThings;
942 fprintf(pFile,"--CreaContour--\n");
943 fprintf(pFile,"Version %s\n", "1.0.2" );
945 vtkImageData *image = _images[0];
948 image->GetDimensions(dimRange);
950 fprintf(pFile,"ImageDimensions %d %d %d\n", dimRange[0], dimRange[1], dimRange[2] );
953 image->GetSpacing(spaRange);
955 fprintf(pFile,"ImageSpacing %f %f %f\n", spaRange[0], spaRange[1], spaRange[2] );
959 lstNameThings = kernelManager->GetLstNameThings();
960 sizeLstNameThings = lstNameThings.size();
961 fprintf(pFile,"NumberOfContours %d\n", sizeLstNameThings );
963 for (i=0 ; i<sizeLstNameThings ; i++)
965 kernelManager->SaveThingName( pFile, lstNameThings[i] );
966 _theViewPanel->getSceneManager()->SaveThingName( pFile, lstNameThings[i] );
971 fprintf(pFile,"ImageDimensions %d %d %d\n", dimRange[0], dimRange[1], dimRange[2] );
973 fprintf(pFile,"ImageSpacing %f %f %f\n", spaRange[0], spaRange[1], spaRange[2] );
975 lstNameThings = kernelManager->GetLstNameThingsStatic();
976 sizeLstNameThings = lstNameThings.size();
977 fprintf(pFile,"NumberOfContoursStatic %d\n", sizeLstNameThings );
978 for (i=0 ; i<sizeLstNameThings ; i++)
980 kernelManager->SaveThingName( pFile, lstNameThings[i] );
981 _theViewPanel->getSceneManager()->SaveThingName( pFile, lstNameThings[i] );
987 void wxContourMainFrame::openContours( FILE *pFile, int version, bool staticContour )
991 vtkImageData *image = _images[0];
997 bool compatible = true;
1002 image->GetDimensions(imageDim);
1003 image->GetSpacing(imageSpac);
1005 fscanf(pFile,"%s",tmp); // ImageDimensions
1006 fscanf(pFile,"%s",tmp); // X
1007 tempDim[0] = atoi(tmp);
1008 fscanf(pFile,"%s",tmp); // Y
1009 tempDim[1] = atoi(tmp);
1010 fscanf(pFile,"%s",tmp); // Z
1011 tempDim[2] = atoi(tmp);
1013 fscanf(pFile,"%s",tmp); // ImageSpacing
1014 fscanf(pFile,"%s",tmp); // X
1015 tempSpac[0] = atof(tmp);
1016 fscanf(pFile,"%s",tmp); // Y
1017 tempSpac[1] = atof(tmp);
1018 fscanf(pFile,"%s",tmp); // Z
1019 tempSpac[2] = atof(tmp);
1021 //Compare Spacing and Dims in X and Y (Necessary in Z?) - Just for Version 2
1022 if (imageDim[0]!=tempDim[0] || imageDim[1]!=tempDim[1] || imageSpac[0]!=tempSpac[0] || imageSpac[1]!=tempSpac[1])
1028 fscanf(pFile,"%s",tmp); // NumberOfContours
1029 fscanf(pFile,"%s",tmp); // ##
1030 int numberOfContours = atoi(tmp);
1032 std::vector<int> instantVector;
1033 int typeContourModel;
1034 manualContourModel *manModelContour;
1037 if (compatible==true)
1040 for (i=0;i<numberOfContours;i++)
1042 instantVector.clear();
1043 fscanf(pFile,"%s",tmp); // Instant
1045 fscanf(pFile,"%s",tmp); // 1
1046 instantVector.push_back( atoi(tmp) );
1047 fscanf(pFile,"%s",tmp); // 2
1048 instantVector.push_back( atoi(tmp) );
1049 fscanf(pFile,"%s",tmp); // 3
1050 instantVector.push_back( atoi(tmp) );
1051 fscanf(pFile,"%s",tmp); // 4
1052 instantVector.push_back( atoi(tmp) );
1053 fscanf(pFile,"%s",tmp); // 5
1054 instantVector.push_back( atoi(tmp) );
1055 fscanf(pFile,"%s",tmp); // 6
1056 instantVector.push_back( atoi(tmp) );
1059 fscanf(pFile,"%s",tmp); // TypeContourModel
1060 fscanf(pFile,"%s",tmp); // ##
1061 typeContourModel = atoi(tmp);
1063 manModelContour = kernelManager->factoryManualContourModel(typeContourModel);
1064 manModelContour->Open(pFile);
1066 fscanf(pFile,"%s",tmp); // TypeView
1067 fscanf(pFile,"%s",tmp); // ##
1068 typeView = atoi(tmp);
1070 std::string theName;
1071 theName = kernelManager->createOutline( manModelContour, instantVector );
1072 bool addedModel = theName.compare("") != 0;
1075 double spc[3];//Si no hay imagen pero hay contornos que spacing se pone por default
1076 _theViewPanel->getSpacing(spc);
1077 //Adding the manualContourControler to interface objects structure
1078 //Adding the manualViewContour to interface objects structure
1079 //_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.
1080 _theViewPanel->getSceneManager()->configureViewControlTo( theName, manModelContour,spc , typeView) ;
1083 if (staticContour) //StaticContours (will appear in all slices)
1085 Instant instant(&instantVector);
1086 kernelManager->changeContourOfManager( theName , &instant );
1089 }// for numberOfContours
1092 else if (compatible==false)
1094 wxDialog* dial = new wxDialog (this,-1,_T("Tools"),wxDefaultPosition, wxSize(260,160));
1095 wxSizer* buttonsSizer = dial->CreateSeparatedButtonSizer(wxOK|wxCANCEL);
1096 wxBoxSizer *dialSizer = new wxBoxSizer(wxVERTICAL);
1098 wxString lstOptOperation[2];
1099 lstOptOperation[0]=_T("By Dimension");
1100 lstOptOperation[1]=_T("By Spacing");
1101 wxRadioBox * radioOpts = new wxRadioBox(dial, -1, _T("Type of Transformation"), wxDefaultPosition, wxSize(270,45), 2 , lstOptOperation, 2, wxRA_SPECIFY_COLS);
1103 dialSizer->Add( new wxStaticText(dial,-1,_T("The image resolution is not compatible with the ")) , 0, wxGROW );
1104 dialSizer->Add( new wxStaticText(dial,-1,_T("selected Roi file. Do you want to tranform it?")) , 0, wxGROW );
1105 dialSizer->Add( new wxStaticText(dial,-1,_T(" ")) , 0, wxGROW );
1106 dialSizer->Add(radioOpts,0,wxGROW);
1107 dialSizer->Add( new wxStaticText(dial,-1,_T(" ")) , 0, wxGROW );
1108 dialSizer->Add(buttonsSizer,0,wxGROW);
1109 dial->SetSizer(dialSizer, true);
1113 int typeOfTransformation = -1;
1114 bool transform = false;
1116 if (dial->GetReturnCode() == wxID_OK)
1118 typeOfTransformation = radioOpts->GetSelection();
1123 for (i=0;i<numberOfContours;i++)
1125 instantVector.clear();
1126 fscanf(pFile,"%s",tmp); // Instant
1128 fscanf(pFile,"%s",tmp); // 1
1129 instantVector.push_back( atoi(tmp) );
1130 fscanf(pFile,"%s",tmp); // 2
1131 instantVector.push_back( atoi(tmp) );
1132 fscanf(pFile,"%s",tmp); // 3
1133 instantVector.push_back( atoi(tmp) );
1134 fscanf(pFile,"%s",tmp); // 4
1135 instantVector.push_back( atoi(tmp) );
1136 fscanf(pFile,"%s",tmp); // 5
1137 instantVector.push_back( atoi(tmp) );
1138 fscanf(pFile,"%s",tmp); // 6
1139 instantVector.push_back( atoi(tmp) );
1141 fscanf(pFile,"%s",tmp); // TypeContourModel
1142 fscanf(pFile,"%s",tmp); // ##
1143 typeContourModel = atoi(tmp);
1145 manModelContour = kernelManager->factoryManualContourModel(typeContourModel);
1146 manModelContour->Open(pFile);
1148 if (transform==true)
1150 if (typeOfTransformation==0)
1152 double transX, transY;
1153 transX = (double) imageDim[0]/tempDim[0];
1154 transY = (double) imageDim[1]/tempDim[1];
1155 manModelContour->Transform_Ax_Plus_B(transX,0,transY,0);
1157 else if (typeOfTransformation==1)
1159 double transX, transY;
1160 transX = (double) tempSpac[0]/imageSpac[0];
1161 transY = (double) tempSpac[1]/imageSpac[1];
1162 manModelContour->Transform_Ax_Plus_B(transX,0,transY,0);
1166 fscanf(pFile,"%s",tmp); // TypeView
1167 fscanf(pFile,"%s",tmp); // ##
1168 typeView = atoi(tmp);
1170 std::string theName;
1171 theName = kernelManager->createOutline( manModelContour, instantVector );
1172 bool addedModel = theName.compare("") != 0;
1175 double spc[3];//Si no hay imagen pero hay contornos que spacing se pone por default
1176 _theViewPanel->getSpacing(spc);
1177 //Adding the manualContourControler to interface objects structure
1178 //Adding the manualViewContour to interface objects structure
1179 //_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.
1180 _theViewPanel->getSceneManager()->configureViewControlTo( theName, manModelContour,spc , typeView) ;
1183 if (staticContour) //StaticContours (will appear in all slices)
1185 Instant instant(&instantVector);
1186 kernelManager->changeContourOfManager( theName , &instant );
1188 }// for numberOfContours
1192 void wxContourMainFrame::RefreshInterface(){
1194 _theViewPanel->RefreshInterface();
1195 //wxVtk2DBaseView *wxvtk2dbaseview = (wxVtk2DBaseView*)this->_theViewPanel->getWxVtkBaseView();
1196 //wxvtk2dbaseview->Refresh();
1199 vtkImageData* wxContourMainFrame::getImageData(){
1200 return _theViewPanel->getImageData();
1203 void wxContourMainFrame::onSegmentationOneSliceITK(wxString distance, wxString sigma, wxString alfa, wxString beta, wxString propagation, wxString iterations, wxString inflation)
1205 //JCP 20-10-08 Undo redo implementation
1207 //JCP 20-10-08 Undo redo implementation
1210 int x = _theViewPanel->GetX();
1211 int y = _theViewPanel->GetY();
1212 int z = _theViewPanel->GetZ();
1213 SegmentationOneSliceITK( x,y,z,distance, sigma, alfa, beta, propagation, iterations, inflation);
1217 void wxContourMainFrame::SegmentationOneSliceITK(int x, int y, int z, wxString distanc, wxString sigm, wxString alf, wxString bet, wxString prop, wxString iter, wxString inflation)
1219 int typeofcontour = 1;
1221 vtkImageData *imagedata = getImageData();
1223 //Tipo de pixeles a utilizar internamente en ITK
1224 typedef float InternalPixelType;
1225 const unsigned int Dimension = 2;
1226 typedef itk::Image< InternalPixelType, Dimension > InternalImageType;
1228 //Tipo de pixeles de salida 1
1229 typedef unsigned char OutputPixelType;
1230 typedef itk::Image< OutputPixelType, Dimension > OutputImageType;
1232 //Tipo de pixeles de salida 2
1233 typedef unsigned short OutputPixelType2;
1234 typedef itk::Image< OutputPixelType2, Dimension > OutputImageType2;
1236 //DefiniciÛn del thresholder
1237 typedef itk::BinaryThresholdImageFilter<
1239 OutputImageType > ThresholdingFilterType;
1241 //DefiniciÛn del primer filtro de conversiÛn de pixeles
1242 typedef itk::CastImageFilter<
1243 OutputImageType, OutputImageType2 > CastFilterType;
1245 //DefiniciÛn del segundo tipo de conversiÛn de pixeles
1246 typedef itk::CastImageFilter<
1247 OutputImageType2, InternalImageType > CastFilterType2;
1249 //Tercer tipo de conversiÛn
1250 typedef itk::RescaleIntensityImageFilter<
1252 OutputImageType > CastFilterType3;
1254 //Cuarto tipo de conversiÛn
1255 typedef itk::RescaleIntensityImageFilter<
1257 OutputImageType > CastFilterType4;
1259 ThresholdingFilterType::Pointer thresholder = ThresholdingFilterType::New();
1261 thresholder->SetLowerThreshold( 0.0 );
1262 thresholder->SetUpperThreshold( 128 );
1264 thresholder->SetOutsideValue( 255 );
1265 thresholder->SetInsideValue( 0 );
1267 //DefinciÛn de conexiÛnes entre VTK e ITK y el writer
1268 typedef itk::VTKImageToImageFilter<OutputImageType2> ConnectorType;
1269 typedef itk::ImageToVTKImageFilter<OutputImageType> ConnectorType2;
1270 typedef itk::ImageFileWriter< OutputImageType > WriterType;
1272 ConnectorType::Pointer connector= ConnectorType::New();
1273 ConnectorType2::Pointer connector2= ConnectorType2::New();
1276 CastFilterType::Pointer filter=CastFilterType::New();
1277 CastFilterType2::Pointer filter2=CastFilterType2::New();
1279 connector->SetInput( imagedata );
1280 filter2->SetInput(connector->GetOutput());
1282 typedef itk::CurvatureAnisotropicDiffusionImageFilter<
1284 InternalImageType > SmoothingFilterType;
1286 SmoothingFilterType::Pointer smoothing = SmoothingFilterType::New();
1288 typedef itk::GradientMagnitudeRecursiveGaussianImageFilter<
1290 InternalImageType > GradientFilterType;
1292 typedef itk::SigmoidImageFilter<
1294 InternalImageType > SigmoidFilterType;
1296 GradientFilterType::Pointer gradientMagnitude = GradientFilterType::New();
1298 SigmoidFilterType::Pointer sigmoid = SigmoidFilterType::New();
1300 sigmoid->SetOutputMinimum( 0.0 );
1301 sigmoid->SetOutputMaximum( 255.0 );
1304 typedef itk::FastMarchingImageFilter<
1306 InternalImageType > FastMarchingFilterType;
1309 FastMarchingFilterType::Pointer fastMarching = FastMarchingFilterType::New();
1311 typedef itk::GeodesicActiveContourLevelSetImageFilter< InternalImageType,
1312 InternalImageType > GeodesicActiveContourFilterType;
1313 GeodesicActiveContourFilterType::Pointer geodesicActiveContour =
1314 GeodesicActiveContourFilterType::New();
1316 typedef itk::ZeroCrossingImageFilter<
1318 InternalImageType > ZeroCrossingFilterType;
1319 ZeroCrossingFilterType::Pointer zeroCrossing =
1320 ZeroCrossingFilterType::New();
1322 const double propagationScaling = atof( crea::wx2std(prop).c_str() );
1324 geodesicActiveContour->SetPropagationScaling( propagationScaling );
1325 geodesicActiveContour->SetCurvatureScaling( 1.0 );
1326 geodesicActiveContour->SetAdvectionScaling( 1.0 );
1328 geodesicActiveContour->SetMaximumRMSError( 0.02 );
1329 int it=atoi( crea::wx2std(iter).c_str() );
1330 geodesicActiveContour->SetNumberOfIterations( it );
1332 smoothing->SetInput( filter2->GetOutput() );
1333 gradientMagnitude->SetInput( smoothing->GetOutput() );
1334 sigmoid->SetInput( gradientMagnitude->GetOutput() );
1335 fastMarching->SetInput( sigmoid->GetOutput() );
1336 geodesicActiveContour->SetInput( fastMarching->GetOutput() );
1337 geodesicActiveContour->SetFeatureImage( sigmoid->GetOutput() );
1339 zeroCrossing->SetInput( geodesicActiveContour->GetOutput() );
1340 //thresholder->SetInput( zeroCrossing->GetOutput() );
1341 thresholder->SetInput( geodesicActiveContour->GetOutput() );
1342 connector2->SetInput( thresholder->GetOutput() );
1345 smoothing->SetTimeStep( 0.125 );
1346 smoothing->SetNumberOfIterations( 5 );
1347 smoothing->SetConductanceParameter( 9.0 );
1350 const double sigma = atof( crea::wx2std(sigm).c_str() );
1351 gradientMagnitude->SetSigma( sigma );
1353 const double alpha = atof( crea::wx2std(alf).c_str() );
1354 const double beta = atof( crea::wx2std(bet).c_str() );
1356 sigmoid->SetAlpha( alpha );
1357 sigmoid->SetBeta( beta );
1359 typedef FastMarchingFilterType::NodeContainer NodeContainer;
1360 typedef FastMarchingFilterType::NodeType NodeType;
1362 NodeContainer::Pointer seeds = NodeContainer::New();
1364 InternalImageType::IndexType seedPosition;
1365 seedPosition[0] = x;
1366 seedPosition[1] = y;
1368 const double initialDistance = atof( crea::wx2std(distanc).c_str() );
1372 const double seedValue = - initialDistance;
1374 node.SetValue( seedValue );
1375 node.SetIndex( seedPosition );
1377 seeds->Initialize();
1378 seeds->InsertElement( 0, node );
1380 fastMarching->SetTrialPoints( seeds );
1382 fastMarching->SetSpeedConstant( 1.0 );
1384 fastMarching->SetOutputSize(
1385 connector->GetOutput()->GetBufferedRegion().GetSize() );
1387 fastMarching->SetStoppingValue( 800 );
1391 connector2->Update();
1392 vtkImageData *idata = connector2->GetOutput();
1394 vtkMarchingContourFilter* cntVTK = vtkMarchingContourFilter::New( );
1396 cntVTK->SetInput( idata );
1398 cntVTK->SetNumberOfContours( 1 );
1399 cntVTK->SetValue( 0, 255 );
1401 cntVTK->UpdateInformation();
1403 vtkCleanPolyData* cpd = vtkCleanPolyData::New( );
1404 cpd->SetInput( cntVTK->GetOutput( ) );
1406 cpd->UpdateInformation();
1408 vtkPolyDataConnectivityFilter* conn = vtkPolyDataConnectivityFilter::New( );
1409 conn->SetExtractionModeToLargestRegion( );
1410 conn->SetInput( cpd->GetOutput( ) );
1412 conn->UpdateInformation();
1414 vtkStripper* vtkstripper = vtkStripper::New( );
1415 vtkstripper->SetInput( conn->GetOutput() );
1416 vtkstripper->Update();
1417 vtkstripper->UpdateInformation();
1420 vtkPolyData* polyDataResult = cntVTK->GetOutput();
1421 //std::cout<<"Points "<<polyDataResult->GetNumberOfPoints()<<std::endl;
1422 polyDataResult->Update( );
1423 polyDataResult->UpdateInformation();
1428 myfile.open ("C:/Creatis/example.txt");
1430 polyDataResult->Print(myfile);
1431 myfile << "-------------------------------------\n";
1432 polyDataResult->GetLines()->Print(myfile);
1440 //--Calculating control points
1442 std::vector<double> vecX;
1443 std::vector<double> vecY;
1444 std::vector<double> vecXo;
1445 std::vector<double> vecYo;
1446 std::vector<double>::iterator vecXoi;
1447 std::vector<double>::iterator vecYoi;
1448 std::vector<double> vecZ;
1450 std::vector<double> vecCtrlPointX;
1451 std::vector<double> vecCtrlPointY;
1452 std::vector<double> vecCtrlPointZ;
1458 int ii,size=polyDataResult->GetNumberOfPoints();
1460 myfile.open ("C:/Creatis/example2.txt");
1462 size=polyDataResult->GetNumberOfPoints();
1463 for (ii=0;ii<size;ii++)
1470 p = polyDataResult->GetPoint(ii);
1473 /*if(fabs(yAct-y)>20)
1475 if((xAct-x)>1 || (xAct-x)<-1)
1477 vecX.push_back( p[0] );
1478 vecY.push_back( p[1] );
1479 myfile <<p[0]<<","<<p[1]<<"\n";
1480 std::cout<<" x Anterior "<<xAct<<" x actual "<<x<<std::endl;
1481 std::cout<<" y Anterior "<<yAct<<" y actual "<<y<<std::endl;
1482 std::cout<<" x "<<p[0]<<" y "<<p[1]<<std::endl;
1483 vecZ.push_back( 900 );
1489 vecXo.push_back(p[0]);
1490 vecYo.push_back(p[1]);
1494 else*/ if(fabs(xAct-x)>11)
1496 vecXo.push_back(p[0]);
1497 vecYo.push_back(p[1]);
1501 vecX.push_back( p[0] );
1502 myfile <<p[0]<<","<<p[1]<<"\n";
1503 //std::cout<<" x Anterior "<<xAct<<" x actual "<<x<<std::endl;
1504 //std::cout<<" y Anterior "<<yAct<<" y actual "<<y<<std::endl;
1505 //std::cout<<" x "<<p[0]<<" y "<<p[1]<<std::endl;
1506 vecY.push_back( p[1] );
1507 vecZ.push_back( 900 );
1515 while(!vecXo.empty())
1517 vecX.push_back(vecXo.back());
1518 //std::cout<<" x Siguiente "<<vecXo.back();
1520 vecZ.push_back( 900 );
1522 while(!vecYo.empty())
1524 vecY.push_back(vecYo.back());
1529 /*for(int l=0;l<vecX.size();l++)
1533 vecXo.push_back(p[0]);
1534 vecYo.push_back(p[1]);
1545 ExtractControlPoints2D *extractcontrolpoints2d = new ExtractControlPoints2D();
1547 extractcontrolpoints2d->SetContour( &vecX , &vecY , &vecZ );
1551 extractcontrolpoints2d->GetInitialControlPoints( &vecCtrlPointX , &vecCtrlPointY , &vecCtrlPointZ );
1553 else if (method==1){
1554 extractcontrolpoints2d->GetControlPoints( &vecCtrlPointX , &vecCtrlPointY , &vecCtrlPointZ );
1556 else if (method==2){
1557 extractcontrolpoints2d->SetSamplingControlPoints( 15 );
1558 extractcontrolpoints2d->GetSamplingControlPoints( &vecCtrlPointX , &vecCtrlPointY , &vecCtrlPointZ );
1560 //--Adding contour to the system
1562 std::vector<int> actualInstantVector;
1563 _instantPanel->getInstant( actualInstantVector );
1564 actualInstantVector[1]=z;
1566 int j,sizeCtrPt = vecCtrlPointX.size();
1568 manualContourModel *manModelContour = kernelManager->factoryManualContourModel( typeofcontour );
1569 manModelContour->SetNumberOfPointsSpline( ((sizeCtrPt/100)+1)*100 );
1571 for (j=0 ; j<sizeCtrPt ; j++)
1573 manModelContour->AddPoint( vecCtrlPointX[j] , vecCtrlPointY[j] , vecCtrlPointZ[j] );
1575 std::string theName;
1576 //theName = _modelManager->createOutline( manModelContour, actualInstantVector );
1577 theName = kernelManager->createOutline( manModelContour, actualInstantVector );
1578 bool addedModel = theName.compare("") != 0;
1581 double spc[3];//Si no hay imagen pero hay contornos que spacing se pone por default
1582 _theViewPanel->getSpacing(spc);
1583 //Adding the manualContourControler to interface objects structure
1584 //Adding the manualViewContour to interface objects structure
1585 //_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.
1586 _theViewPanel->configureViewControlTo(theName, manModelContour, spc, typeofcontour);
1587 //_theViewPanel->getSceneManager()->configureViewControlTo( theName, manModelContour,spc, typeofcontour ) ;
1593 WriterType::Pointer writer = WriterType::New();
1594 CastFilterType3::Pointer caster = CastFilterType3::New();
1596 caster->SetInput( gradientMagnitude->GetOutput() );
1597 writer->SetInput( caster->GetOutput() );
1598 writer->SetFileName("Gradient Magnitude.png");
1599 caster->SetOutputMinimum( 0 );
1600 caster->SetOutputMaximum( 255 );
1603 CastFilterType3::Pointer caster2 = CastFilterType3::New();
1604 WriterType::Pointer writer2 = WriterType::New();
1606 caster2->SetInput( sigmoid->GetOutput() );
1607 writer2->SetInput( caster2->GetOutput() );
1608 writer2->SetFileName("Sigmoid.png");
1609 caster2->SetOutputMinimum( 0 );
1610 caster2->SetOutputMaximum( 255 );
1613 CastFilterType3::Pointer caster3 = CastFilterType3::New();
1614 WriterType::Pointer writer3 = WriterType::New();
1616 caster3->SetInput( fastMarching->GetOutput() );
1617 writer3->SetInput( caster3->GetOutput() );
1618 writer3->SetFileName("FastMarching.bmp");
1619 caster3->SetOutputMinimum( 0 );
1620 caster3->SetOutputMaximum( 255 );
1623 CastFilterType3::Pointer caster4 = CastFilterType3::New();
1624 WriterType::Pointer writer4 = WriterType::New();
1626 caster4->SetInput( geodesicActiveContour->GetOutput() );
1627 writer4->SetInput( caster4->GetOutput() );
1628 writer4->SetFileName("GeodesicActiveContour.png");
1629 caster4->SetOutputMinimum( 0 );
1630 caster4->SetOutputMaximum( 255 );
1633 CastFilterType3::Pointer caster5 = CastFilterType3::New();
1634 WriterType::Pointer writer5 = WriterType::New();
1636 caster5->SetInput( zeroCrossing->GetOutput() );
1637 writer5->SetInput( caster5->GetOutput() );
1638 writer5->SetFileName("ZeroCrossing.bmp");
1639 caster5->SetOutputMinimum( 0 );
1640 caster5->SetOutputMaximum( 255 );
1643 catch( itk::ExceptionObject & excep )
1645 std::cerr << "Exception caught !" << std::endl;
1646 std::cerr << excep << std::endl;
1650 void wxContourMainFrame::onSegmentationOneSlice(int isovalue,int sampling,int method){
1652 //JCP 20-10-08 Undo redo implementation
1654 //JCP 20-10-08 Undo redo implementation
1657 int x = _theViewPanel->GetX();
1658 int y = _theViewPanel->GetY();
1659 int z = _theViewPanel->GetZ();
1660 SegmentationOneSlice( x,y,z,isovalue, sampling, method );
1665 void wxContourMainFrame::SegmentationOneSlice( int x, int y, int z, int isovalue, int sampling, int method )
1667 int typeofcontour = 1;
1668 //--Extracting Contour
1669 //vtkImageData *imagedata = _theViewPanel->getSceneManager()->GetImageData();
1670 vtkImageData *imagedata = getImageData();
1671 // double *range = imagedata->GetScalarRange();
1674 vtkImageReslice *imageReslice = vtkImageReslice::New();
1677 // imagedata->GetSpacing(spc);
1682 imageReslice->SetInput( imagedata );
1683 imageReslice->SetInformationInput(imagedata);
1684 imageReslice->SetResliceAxesDirectionCosines(1,0,0, 0,1,0 ,0,0,1);
1685 imageReslice->SetResliceAxesOrigin(0,0,z);
1686 imageReslice->SetOutputDimensionality(2);
1687 imageReslice->SetInterpolationModeToLinear();
1689 imagedata = imageReslice->GetOutput();
1690 imagedata->Update();
1691 imagedata->UpdateInformation();
1693 vtkContourFilter* cntVTK = vtkContourFilter::New( );
1694 cntVTK->SetInput( imagedata );
1696 cntVTK->SetNumberOfContours( 1 );
1697 //cntVTK->SetValue( 0, vmin );
1698 // cntVTK->SetValue( 0, (range[1]*thr/100) );
1699 cntVTK->SetValue( 1, isovalue );
1700 // cntVTK->SetValue( 1, vmax );
1702 cntVTK->UpdateInformation();
1704 vtkCleanPolyData* cpd = vtkCleanPolyData::New( );
1705 cpd->SetInput( cntVTK->GetOutput( ) );
1706 cpd->ConvertLinesToPointsOff( );
1708 cpd->UpdateInformation();
1710 vtkPolyDataConnectivityFilter* conn = vtkPolyDataConnectivityFilter::New( );
1711 conn->SetExtractionModeToClosestPointRegion( );
1712 //conn->SetMaxRecursionDepth( 3000 );
1714 conn->SetInput( cpd->GetOutput( ) );
1716 conn->SetClosestPoint( x, y, 0 );
1718 conn->UpdateInformation();
1720 vtkCleanPolyData* cpd2 = vtkCleanPolyData::New( );
1721 cpd2->SetInput( conn->GetOutput( ) );
1723 cpd2->UpdateInformation();
1725 vtkStripper* vtkstripper = vtkStripper::New( );
1726 vtkstripper->SetInput( cpd2->GetOutput() );
1727 vtkstripper->Update();
1728 vtkstripper->UpdateInformation();
1731 vtkPolyData* polyDataResult = vtkstripper->GetOutput();
1733 polyDataResult->Update( );
1734 polyDataResult->UpdateInformation();
1738 myfile.open ("c:/temp/example.txt");
1740 polyDataResult->Print(myfile);
1741 myfile << "-------------------------------------\n";
1742 polyDataResult->GetLines()->Print(myfile);
1752 //--Calculating control points
1754 std::vector<double> vecX;
1755 std::vector<double> vecY;
1756 std::vector<double> vecZ;
1758 std::vector<double> vecCtrlPointX;
1759 std::vector<double> vecCtrlPointY;
1760 std::vector<double> vecCtrlPointZ;
1764 int ii,size=polyDataResult->GetNumberOfPoints();
1766 for (ii=1;ii<=size;ii++)
1768 id = polyDataResult->GetLines()->GetData()->GetValue(ii);
1769 p = polyDataResult->GetPoint(id);
1772 vecX.push_back( p[0] );
1773 vecY.push_back( p[1] );
1774 vecZ.push_back( 900 );
1775 // vecZ.push_back( p[2] );
1779 ExtractControlPoints2D *extractcontrolpoints2d = new ExtractControlPoints2D();
1780 extractcontrolpoints2d->SetContour( &vecX , &vecY , &vecZ );
1783 /*if (methodRadiobox->GetSelection()==0){
1784 extractcontrolpoints2d->GetInitialControlPoints( &vecCtrlPointX , &vecCtrlPointY , &vecCtrlPointZ );
1786 if (methodRadiobox->GetSelection()==1){
1787 extractcontrolpoints2d->GetControlPoints( &vecCtrlPointX , &vecCtrlPointY , &vecCtrlPointZ );
1789 if (methodRadiobox->GetSelection()==2){
1790 extractcontrolpoints2d->SetSamplingControlPoints( sampling );
1791 extractcontrolpoints2d->GetSamplingControlPoints( &vecCtrlPointX , &vecCtrlPointY , &vecCtrlPointZ );
1795 extractcontrolpoints2d->GetInitialControlPoints( &vecCtrlPointX , &vecCtrlPointY , &vecCtrlPointZ );
1797 else if (method==1){
1798 extractcontrolpoints2d->GetControlPoints( &vecCtrlPointX , &vecCtrlPointY , &vecCtrlPointZ );
1800 else if (method==2){
1801 extractcontrolpoints2d->SetSamplingControlPoints( sampling );
1802 extractcontrolpoints2d->GetSamplingControlPoints( &vecCtrlPointX , &vecCtrlPointY , &vecCtrlPointZ );
1805 //--Adding contour to the system
1807 std::vector<int> actualInstantVector;
1808 _instantPanel->getInstant( actualInstantVector );
1809 actualInstantVector[1]=z;
1811 int j,sizeCtrPt = vecCtrlPointX.size();
1812 manualContourModel *manModelContour = kernelManager->factoryManualContourModel( typeofcontour );
1813 manModelContour->SetNumberOfPointsSpline( ((sizeCtrPt/100)+1)*100 );
1815 for (j=0 ; j<sizeCtrPt ; j++)
1817 manModelContour->AddPoint( vecCtrlPointX[j] , vecCtrlPointY[j] , vecCtrlPointZ[j] );
1819 std::string theName;
1820 //theName = _modelManager->createOutline( manModelContour, actualInstantVector );
1821 theName = kernelManager->createOutline( manModelContour, actualInstantVector );
1822 bool addedModel = theName.compare("") != 0;
1825 double spc[3];//Si no hay imagen pero hay contornos que spacing se pone por default
1826 _theViewPanel->getSpacing(spc);
1827 //Adding the manualContourControler to interface objects structure
1828 //Adding the manualViewContour to interface objects structure
1829 //_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.
1830 _theViewPanel->configureViewControlTo(theName, manModelContour, spc, typeofcontour);
1831 //_theViewPanel->getSceneManager()->configureViewControlTo( theName, manModelContour,spc, typeofcontour ) ;
1835 int wxContourMainFrame::GetImageDataSizeZ(){
1836 return _theViewPanel->GetImageDataSizeZ();
1839 void wxContourMainFrame::GetImageDataRange(double *range){
1840 _theViewPanel->GetImageDataRange(range);
1843 void wxContourMainFrame::onSegmentationAllSlice(int minZ,int maxZ,int isovalue,int sampling,int method){
1844 //JCP 20-10-08 Undo redo implementation
1846 //JCP 20-10-08 Undo redo implementation
1849 int x = _theViewPanel->GetX();
1850 int y = _theViewPanel->GetY();
1854 double totalZ = maxZ-minZ+1;
1855 for( z=minZ ; z<=maxZ ; z++ )
1857 porcent = 100.0* (z-minZ)/totalZ;
1858 tmpString.Printf(_T(" %d %c %d/%d %d"), (int)porcent , 37 , z-minZ+1, (int)totalZ,z );
1859 interfMainPanel::getInstance()->setLabelSegmentationPanelVTK(tmpString);
1860 //_staticTextSegmentation->SetLabel(tmpString);
1861 SegmentationOneSlice( x,y,z,isovalue, sampling,method );
1863 interfMainPanel::getInstance()->setLabelSegmentationPanelVTK(_T(" "));
1868 //Creates a reference line to be used as the axis of the mirroring
1869 void wxContourMainFrame::referenceLine()
1871 if (_refLineControl==NULL)
1876 vtkImageData *vtkimagedata = _theViewPanel->getImageData();
1877 vtkimagedata->GetSpacing(spc);
1879 wxVtkBaseView * viewer2D = _theViewPanel->getWxVtkBaseView();
1881 _refLineControl = new manualLineControler();
1882 _refLineModel = new manualContourModelLine();
1883 _refLineView = new manualViewLine();
1884 _refLineView->SetModel( _refLineModel );
1885 _refLineView->SetWxVtkBaseView( viewer2D );
1886 _refLineView->SetRange( 2 );
1887 _refLineView->SetZ( 1200 );
1889 _refLineView->SetSpacing(spc);
1891 _refLineView->SetColorNormalContour(0, 0, 1);
1892 _refLineView->SetColorEditContour(0, 0.5, 0.5);
1893 _refLineView->SetWidthLine(4);
1895 _refLineControl->SetModelView( _refLineModel , _refLineView );
1896 vtkInteractorStyleBaseView* style = (vtkInteractorStyleBaseView*)viewer2D->GetInteractorStyleBaseView();
1897 style->AddInteractorStyleMaracas( _refLineControl );
1898 _refLineModel->SetCloseContour(false);
1899 _refLineControl->CreateNewManualContour();
1901 //AD: Inicializar el mirroring con una linea ya pintada
1903 double z = _refLineControl->GetZ();
1906 image->GetDimensions(imageDim);
1907 double x = (double) imageDim[0]/2;
1908 double y1 = (double) (imageDim[1]/2)+15;
1909 double y2 = (double) (imageDim[1]/2)-15;
1911 _refLineControl->AddPoint(x,y1,z);
1912 _refLineControl->AddPoint(x,y2,z);
1913 _refLineControl->SetCompleteCreation(true);
1915 _refLineModel->AddPoint(x,y1,z);
1916 _refLineModel->AddPoint(x,y2,z);
1917 _refLineModel->UpdateSpline();
1919 _refLineView->UpdateViewPoint(0);
1920 _refLineView->UpdateViewPoint(1);
1923 _refLineControl->SetActive(true);
1924 _refLineView->RefreshContour();
1928 //Hides the referenceLine
1929 void wxContourMainFrame::refLineHide()
1931 if (_refLineControl!=NULL)
1933 if (_refLineControl->GetActive())
1935 _refLineView->RemoveCompleteContourActor();
1936 _refLineControl->SetEditable(false);
1937 _refLineControl->SetActive(false);
1944 //Shows the referenceLine
1945 void wxContourMainFrame::refLineShow()
1947 if (_refLineControl!=NULL)
1949 if (_refLineControl->GetActive()==false)
1951 wxVtkBaseView * viewer2D = _theViewPanel->getWxVtkBaseView();
1953 _refLineView->SetModel( _refLineModel );
1954 _refLineView->SetWxVtkBaseView( viewer2D );
1955 _refLineView->SetRange( 2 );
1956 _refLineView->SetZ( 1200 );
1958 _refLineControl->SetModelView( _refLineModel , _refLineView );
1959 vtkInteractorStyleBaseView* style = (vtkInteractorStyleBaseView*)viewer2D->GetInteractorStyleBaseView();
1960 style->AddInteractorStyleMaracas( _refLineControl );
1961 _refLineControl->CreateNewManualContour();
1962 _refLineControl->SetActive(true);
1963 _refLineView->RefreshContour();
1970 void wxContourMainFrame::refLineChangeWidth(int width)
1972 _refLineView->SetWidthLine(width);
1973 _refLineView->RefreshContour();
1979 void wxContourMainFrame::onMirror()
1982 std::vector<std::string> currentSelection = _theViewPanel->getSelectedObjects();
1983 std::vector<std::string> filterCurrentSelection;
1985 std::vector<int> tempVector;
1986 _instantPanel->getInstant( tempVector );
1987 _performingOperation->reset();
1988 _performingOperation->setStartCommand( COPY );
1989 _performingOperation->setStartOperationInstantVector( tempVector );
1990 _performingOperation->setKeyNamesOperationElems( currentSelection );
1992 char theStartCommand = _performingOperation->getStartCommand();
1993 if ( theStartCommand == COPY )
1995 //JCP 20-10-08 Undo redo implementation
1997 //JCP 20-10-08 Undo redo implementation
1998 std::vector<int> tempVector;
1999 _instantPanel->getInstant( tempVector );
2000 _performingOperation->setEndOperationInstantVector ( tempVector );
2001 std::vector<std::string> elems = _performingOperation->getKeyNamesOperationElems();
2002 int i,size = elems.size();
2003 for( i=0; i<size; i++ )
2005 createMirrorContourOf( elems[i], tempVector, i>0 );
2009 //deleteContour( _refName );
2013 void wxContourMainFrame::onThreshold()
2015 int z = _theViewPanel->GetZ();
2018 vtkImageData * img = getImageData();
2019 img->GetScalarRange(range);
2021 int minTot = floor (range[0]);
2022 int maxTot = ceil (range[1]);
2025 _pannew->onThresholdInstantChange(minMax);
2026 int minVal = floor (minMax[0]);
2027 int maxVal = floor (minMax[1]);
2031 if (_imageReslicer==NULL)
2033 _imageReslicer = vtkImageReslice::New();
2034 _imageReslicer->SetInput( img );
2035 _imageReslicer->SetInformationInput(img);
2036 _imageReslicer->SetResliceAxesDirectionCosines(1,0,0, 0,1,0 ,0,0,1);
2037 _imageReslicer->SetOutputDimensionality(2);
2038 _imageReslicer->SetInterpolationModeToLinear();
2041 _imageReslicer->SetResliceAxesOrigin(0,0,z);
2043 img = _imageReslicer->GetOutput();
2045 img->UpdateInformation();
2047 wxVtkBaseView * baseView = _theViewPanel->getWxVtkBaseView();
2049 if (_thresholdTable==NULL)
2052 _thresholdTable = vtkLookupTable::New();
2053 _thresholdTable->SetNumberOfTableValues(maxTot+1);
2054 _thresholdTable->SetTableRange(range);
2055 _thresholdTable->SetAlphaRange(0, 1);
2056 _thresholdTable->SetValueRange(0, 1);
2057 _thresholdTable->SetSaturationRange(0, 0);
2058 _thresholdTable->SetRampToLinear( );
2061 //Assign a fake color for the upper image, and set the white as transparent
2063 for(i = minTot; i <= maxTot; i++)
2065 if( i >= minVal && i <= maxVal )
2067 _thresholdTable->SetTableValue(i, 1.0, 0.0, 0.0, 1);
2069 else if( i >= minTot && i < minVal )
2071 _thresholdTable->SetTableValue(i, 1.0, 1.0, 1.0, 0); //transparent
2073 else if( i > maxVal && i < maxTot )
2075 _thresholdTable->SetTableValue(i, 1.0, 1.0, 1.0, 0); //transparent
2079 _thresholdTable->SetTableValue(i, 1.0, 1.0, 1.0, 0); //transparent
2082 _thresholdTable->Build( );
2084 if (_thresholdMapper==NULL)
2086 _thresholdMapper = vtkImageMapToColors::New( );
2089 _thresholdMapper->SetLookupTable( _thresholdTable );
2090 _thresholdMapper->SetInput( img );
2092 if (_thresholdActor==NULL)
2094 _thresholdActor = vtkImageActor::New( );
2095 _thresholdActor->SetOpacity( 0.6 );
2096 _thresholdActor->InterpolateOn( );
2097 _thresholdActor->SetPosition( 0,0, 900-1 );
2100 _thresholdActor->SetInput( _thresholdMapper->GetOutput() );
2102 baseView->GetRenderer()->AddActor( _thresholdActor );
2103 _actorPresent = true;
2108 _imageReslicer->SetResliceAxesOrigin(0,0,z);
2109 img = _imageReslicer->GetOutput();
2111 img->UpdateInformation();
2113 //Assign a fake color for the upper image, and set the white as transparent
2115 for(i = minTot; i <= maxTot; i++)
2117 if( i >= minVal && i <= maxVal )
2119 _thresholdTable->SetTableValue(i, 1.0, 0.0, 0.0, 1);
2121 else if( i >= minTot && i < minVal )
2123 _thresholdTable->SetTableValue(i, 1.0, 1.0, 1.0, 0); //transparent
2125 else if( i > maxVal && i < maxTot )
2127 _thresholdTable->SetTableValue(i, 1.0, 1.0, 1.0, 0); //transparent
2131 _thresholdTable->SetTableValue(i, 1.0, 1.0, 1.0, 0); //transparent
2135 _thresholdTable->Build( );
2136 _thresholdMapper->SetLookupTable( _thresholdTable );
2137 _thresholdMapper->SetInput( img );
2138 _thresholdActor->SetInput( _thresholdMapper->GetOutput() );
2141 vtkImageViewer2* viewer = vtkImageViewer2::New();
2142 viewer->SetInput( upperImageActor->GetInput() );
2143 viewer->SetColorLevel((range[1]-range[0])/2);
2144 viewer->SetColorWindow(range[1]);
2145 viewer->GetRenderer()->AddActor( upperImageActor );
2148 _theViewPanel->RefreshInterface();
2152 void wxContourMainFrame::onThresholdChange()
2160 void wxContourMainFrame::onThresholdInterpolation(bool interpolate)
2162 if (_thresholdActor!=NULL)
2166 _thresholdActor->InterpolateOn( );
2171 _thresholdActor->InterpolateOff( );
2174 _theViewPanel->RefreshInterface();
2178 void wxContourMainFrame::onThresholdChangeOpacity (int opacity)
2182 _thresholdActor->SetOpacity(opacity*0.1);
2185 _theViewPanel->RefreshInterface();
2188 void wxContourMainFrame::onThresholdRemove()
2192 wxVtkBaseView * baseView = _theViewPanel->getWxVtkBaseView();
2193 baseView->GetRenderer()->RemoveActor( _thresholdActor );
2194 _actorPresent = false;
2197 _theViewPanel->RefreshInterface();
2200 void wxContourMainFrame::showAxis(bool show)
2202 _theViewPanel->SetVisibleAxis(show);
2203 _theViewPanel->Refresh();
2207 void wxContourMainFrame::onRigidPressed(){
2208 std::vector<std::string> currentSelection = _theViewPanel->getSelectedObjects();
2209 int elementsSelected = currentSelection.size();
2211 if ( elementsSelected >= 1 ){
2212 //JCP 20-10-08 Undo redo implementation
2214 //JCP 20-10-08 Undo redo implementation
2216 std::vector<int> tempVector;
2217 _instantPanel->getInstant( tempVector );
2218 Instant instant(&tempVector);
2220 int i , size=currentSelection.size();
2221 for ( i=0 ; i<size ; i++ )
2223 kernelManager->changeContourOfManager(currentSelection[i], &instant);
2228 void wxContourMainFrame::onWidthOfContour(double width){
2230 _theViewPanel->removeSceneContours();
2231 _theViewPanel->SetWidthContour(width);
2233 //_theViewPanel->getSceneManager()->SetWidthContour( width );
2238 int wxContourMainFrame::getColorWindow()
2242 vtkImageData * img = getImageData();
2243 img->GetScalarRange(range);
2245 std::cout<<"Val 1: "<<range[0]<<" Val 2: "<<range[1]<<std::endl;
2247 return (int)range[1];
2249 return _theViewPanel->getColorWindow();
2252 int wxContourMainFrame::getWindowLevel()
2256 vtkImageData * img = getImageData();
2257 img->GetScalarRange(range);
2259 std::cout<<"Val 1: "<<range[0]<<" Val 2: "<<range[1]<<std::endl;
2261 return (int)range[1];
2263 return _theViewPanel->getWindowLevel();
2266 void wxContourMainFrame::onBrigthnessColorWindowLevel(int colorwindow,int windowlevel){
2267 _theViewPanel->onBrigthnessColorWindowLevel(colorwindow, windowlevel);
2272 void wxContourMainFrame::onInterpolation(bool interpolate){
2273 _theViewPanel->onInterpolation(interpolate);
2277 void wxContourMainFrame::onChangeInstant(std::string name,int actual){
2278 _instantPanel->setConceptValue( name, actual );
2281 void wxContourMainFrame::resetAppend(){
2282 kernelManager->resetAppend();
2286 void wxContourMainFrame::onSpreadAdd(){
2287 std::vector<double> vecX;
2288 std::vector<double> vecY;
2289 std::vector<double> vecZ;
2290 _theViewPanel->GetPointsOfActualContour(&vecX , &vecY , &vecZ );
2292 std::vector<int> tempVector;
2293 _instantPanel->getInstant( tempVector );
2295 std::string val = kernelManager->onSpreadAdd(&vecX , &vecY , &vecZ, tempVector);
2297 interfMainPanel::getInstance()->appendStringSpread(val);
2301 void wxContourMainFrame::onSpreadGo(int type){
2303 //JCP 20-10-08 Undo redo implementation
2305 //JCP 20-10-08 Undo redo implementation
2308 std::vector<double> vecCtrlPointX;
2309 std::vector<double> vecCtrlPointY;
2310 std::vector<double> vecCtrlPointZ;
2314 std::vector<int> tempVector;
2315 _instantPanel->getInstant( tempVector );
2318 kernelManager->getMaxMinZ(&minZ,&maxZ);
2319 //JSTG_16-07-08_----------------------------------------------------------------
2320 //_contourPropagation->setInterpolationNumber(maxZ-minZ+1);
2321 kernelManager->CalculeSplinePropagation();
2323 double totalZ = maxZ-minZ+1;
2326 //--------------------------------------------------------------------
2327 for ( z=(int)minZ ; z<=(int)maxZ ; z++ )
2329 porcent = 100.0* (z-minZ)/totalZ;
2330 int numero = (int)(z-minZ+1)/(int)totalZ;
2331 std::string stringtemp = " "+kernelManager->intToString(porcent)+"% "+kernelManager->intToString(numero)+" "+kernelManager->intToString(z);
2333 interfMainPanel::getInstance()->setStringSpread(stringtemp);
2335 int typeofcontour = 1;
2336 std::string theName;
2337 manualContourModel* manModelContour = kernelManager->GetPoints(z, type, &vecCtrlPointX,&vecCtrlPointY,&vecCtrlPointZ, theName,typeofcontour, tempVector);
2339 if( manModelContour!=NULL ){
2340 double spc[3];//Si no hay imagen pero hay contornos que spacing se pone por default
2341 this->_theViewPanel->getSpacing(spc);
2342 //Adding the manualContourControler to interface objects structure
2343 //Adding the manualViewContour to interface objects structure
2344 //_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.
2345 _theViewPanel->configureViewControlTo( theName, manModelContour,spc,typeofcontour ) ;
2350 int numero = (int)(z-minZ+1)/(int)totalZ;
2351 std::string stringtemp = " "+kernelManager->intToString(porcent)+"% "+kernelManager->intToString(numero)+" "+kernelManager->intToString(z);
2353 interfMainPanel::getInstance()->setStringSpread(stringtemp);
2355 //RefreshInterface();
2358 void wxContourMainFrame::getInstantVector(std::vector<int>& tempVector){
2362 std::vector<std::string> wxContourMainFrame::getOutlinesName(int slide){
2363 std::vector<int> tempVector;
2364 _instantPanel->getInstant(tempVector);
2365 //Asignation of slide number should be different ex by name
2366 tempVector[1]=slide;
2367 return kernelManager->getOutlinesNameAtInstant(tempVector);
2371 void wxContourMainFrame::GenerateContourExtractData()
2373 if (_contourextractdata==NULL) { _contourextractdata = new ContourExtractData(true); }
2377 void wxContourMainFrame::onInformationContourLabels(int typeContourGroup,int selection,int minimumZ,int maximumZ,int grayRangeMin, int grayRangeMax)
2379 GenerateContourExtractData();
2381 wxString tempString;
2382 int maxContourGroup = 0;
2384 _contourextractdata ->SetTypeOperation( typeContourGroup % 3 );
2386 std::vector<manualContourModel*> lstManConMod;
2387 std::vector<manualContourModel*> lstManConModTmp;
2388 std::vector<manualContourModel*> lstManConModExp;
2389 std::vector<double> pLstValue;
2390 std::vector<double> pLstValuePosX;
2391 std::vector<double> pLstValuePosY;
2392 std::vector<double> pLstValuePosZ;
2395 int resultGrayRangeCount;
2398 double resultAverage;
2399 double resultStandardeviation;
2401 std::vector<int> tempVector;
2402 _instantPanel->getInstant( tempVector );
2404 vtkImageData *imagedata = _theViewPanel->getImageData();
2405 // int sizeZ = _theViewPanel->GetImageDataSizeZ();
2407 int ii,sizeLstContourThings;
2417 if (selection==0 ) // actual slice
2419 int actualSlice = tempVector[1];
2422 } else { // slice range
2428 totalZ = maxZ-minZ+1;
2429 _contourextractdata->SetImage( imagedata);
2431 _contourextractdata->InitVolumeStatistics();
2434 for ( z=minZ ; z<=maxZ ; z++ )
2437 porcent = 100.0* (z-minZ)/totalZ;
2438 tmpString.Printf(_T(" %d %c %d/%d %d"), (int)porcent , 37 , z-minZ+1, (int)totalZ ,z);
2440 interfMainPanel::getInstance()->setStringInfoPanel(tmpString);
2441 //_staticTextInformation->SetLabel(tmpString);
2443 //Extraction data from contours of each slice
2444 _contourextractdata->SetZtoBeAnalys(z);
2447 Instant instant(&tempVector);
2448 std::vector<ContourThing**> lstContourThings = kernelManager->getOutlinesAtInstant( &instant );
2449 sizeLstContourThings = lstContourThings.size();
2451 lstManConMod.clear();
2452 for (ii=0 ; ii<sizeLstContourThings ; ii++)
2454 ContourThing **contourthing = lstContourThings[ii];
2455 lstManConMod.push_back( (*contourthing)->getModel() );
2457 lstManConModExp = kernelManager->ExploseEachModel( lstManConMod );
2460 tempString.Printf(_T("%d - %d"),z, sizeLstContourThings);
2461 interfMainPanel::getInstance()->setRowLabelInfoPanel(z, tempString);
2462 //_grid->SetRowLabelValue(z, tempString );
2464 int iContourGroup,sizeContourGroup;
2465 if (typeContourGroup==3) // contour separete
2467 sizeContourGroup=lstManConModExp.size();
2468 if ( maxContourGroup<sizeContourGroup )
2470 maxContourGroup=sizeContourGroup;
2472 } else { // contour AND OR XOR
2481 for( iContourGroup=0 ; iContourGroup<sizeContourGroup ; iContourGroup++ ){
2482 lstManConModTmp.clear();
2483 if (typeContourGroup==3) // contour separete
2485 lstManConModTmp.push_back( lstManConModExp[iContourGroup]);
2486 } else { // contour AND OR XOR
2487 lstManConModTmp = lstManConModExp;
2490 _contourextractdata->SetLstManualContourModel( lstManConModTmp );
2493 pLstValuePosX.clear();
2494 pLstValuePosY.clear();
2495 pLstValuePosZ.clear();
2496 _contourextractdata->GetValuesInsideCrown( &pLstValue,
2500 // Statistics of each slice.
2501 _contourextractdata->Statistics( &pLstValue,
2504 &resultGrayRangeCount,
2509 &resultStandardeviation);
2511 if (interfMainPanel::getInstance()->getNumberColsInformationPanel()<_numberOfVariablesStatistics*(iContourGroup+1) )
2513 interfMainPanel::getInstance()->appendColsInformationPanel(_numberOfVariablesStatistics);
2516 tmpIntA=_numberOfVariablesStatistics*iContourGroup ;
2518 tempString.Printf(_T("%d"),resultSize);
2519 interfMainPanel::getInstance()->setCellValueInfoPanel(z, tmpIntA, tempString);
2521 tempString.Printf(_T("%d"),resultGrayRangeCount);
2522 interfMainPanel::getInstance()->setCellValueInfoPanel(z, tmpIntA+1, tempString);
2524 tempString.Printf(_T("%f"),resultMin);
2525 interfMainPanel::getInstance()->setCellValueInfoPanel(z, tmpIntA+2, tempString);
2527 tempString.Printf(_T("%f"),resultMax);
2528 interfMainPanel::getInstance()->setCellValueInfoPanel(z, tmpIntA+3, tempString);
2530 tempString.Printf(_T("%f"),resultAverage);
2531 interfMainPanel::getInstance()->setCellValueInfoPanel(z, tmpIntA+4, tempString);
2533 tempString.Printf(_T("%f"),resultStandardeviation);
2534 interfMainPanel::getInstance()->setCellValueInfoPanel(z, tmpIntA+5, tempString);
2537 } // for iContourGroup
2540 // Print Volume Statistics
2543 int vol_rCountRange;
2545 double vol_minValue;
2546 double vol_maxValue;
2548 double vol_standardeviation;
2550 if (selection!=0 ) // actual slice
2553 _contourextractdata->GetVolumeStatistics(&vol_rCountRange, &vol_rsize,
2554 &vol_minValue, &vol_maxValue,
2555 &vol_average, &vol_standardeviation);
2557 interfMainPanel::getInstance()->setRowLabelInfoPanel(maxZ+2, _T("Total:"));
2559 tempString.Printf(_T("%d"),vol_rsize);
2560 interfMainPanel::getInstance()->setCellValueInfoPanel(maxZ+2, 0, tempString);
2562 tempString.Printf(_T("%d"),vol_rCountRange);
2563 interfMainPanel::getInstance()->setCellValueInfoPanel(maxZ+2, 1, tempString);
2565 tempString.Printf(_T("%f"),vol_minValue);
2566 interfMainPanel::getInstance()->setCellValueInfoPanel(maxZ+2, 2, tempString);
2568 tempString.Printf(_T("%f"),vol_maxValue);
2569 interfMainPanel::getInstance()->setCellValueInfoPanel(maxZ+2, 3, tempString);
2571 tempString.Printf(_T("%f"),vol_average);
2572 interfMainPanel::getInstance()->setCellValueInfoPanel(maxZ+2, 4, tempString);
2574 tempString.Printf(_T("%f"),vol_standardeviation);
2575 interfMainPanel::getInstance()->setCellValueInfoPanel(maxZ+2, 5, tempString);
2577 //-----------------------------------------
2580 wxString tmpTitleString;
2582 for ( iTitleGroup=0 ; iTitleGroup<maxContourGroup ; iTitleGroup++ )
2584 tmpIntB =_numberOfVariablesStatistics*iTitleGroup;
2585 tmpTitleString.Printf(_T("%d-Size Data"),iTitleGroup);
2586 interfMainPanel::getInstance()->setColLableInfoPanel(tmpIntB + 0, tmpTitleString);
2588 interfMainPanel::getInstance()->setColLableInfoPanel(tmpIntB + 0, tmpTitleString );
2589 interfMainPanel::getInstance()->setColLableInfoPanel( tmpIntB + 1, _T("Size Range") );
2590 interfMainPanel::getInstance()->setColLableInfoPanel( tmpIntB + 2, _T("Min") );
2591 interfMainPanel::getInstance()->setColLableInfoPanel( tmpIntB + 3, _T("Max") );
2592 interfMainPanel::getInstance()->setColLableInfoPanel( tmpIntB + 4, _T("Average") );
2593 interfMainPanel::getInstance()->setColLableInfoPanel( tmpIntB + 5, _T("St.Dev.") );
2594 interfMainPanel::getInstance()->setColLableInfoPanel( tmpIntB + 6, _T(" ") );
2596 interfMainPanel::getInstance()->setStringInfoPanel( _T("") );
2600 void wxContourMainFrame::onSaveResults(std::string directory,std::string namefile, std::string filename,
2601 int typeContourGroup, int selection, int minZ, int maxZ, bool XYZValues, bool contourImage, bool statistics)
2605 SaveValuesXYZ( directory , namefile, typeContourGroup );
2610 vtkImageData * mask;
2611 vtkImageData * value;
2612 this->getMaskValue(&mask, &value, typeContourGroup,selection,minZ,maxZ);
2613 this->SaveImageResult( directory , namefile, mask, value);
2618 std::ostringstream name;
2619 name << filename << ".xls";
2622 FILE *pFile=fopen(name.str().c_str(),"w+");
2628 // int sizeZ = _theViewPanel->GetImageDataSizeZ();
2629 // int maxY=sizeZ+2;
2631 maxX= interfMainPanel::getInstance()->getNumberColsInformationPanel();//this->_grid->GetNumberCols();
2634 int iTitle,sizeTitle = (maxX / _numberOfVariablesStatistics);
2635 for ( iTitle=0; iTitle<sizeTitle ; iTitle++)
2637 // fprintf(pFile,"-- \t %d-Size \t SizeRange \t Min \t Max \t Ave \t StDv \t" , iTitle,tmpString.c_str() );
2638 fprintf(pFile,"slice\t %d-Size \t SizeRange \t Min \t Max \t Ave \t StDv \t" , iTitle );
2640 fprintf(pFile,"\n\n" );
2645 if (selection==0 ) // actual slice
2647 std::vector<int> tempVector;
2648 _instantPanel->getInstant( tempVector );
2649 int actualSlice = tempVector[1];
2655 for ( j=minZ; j<=maxZ ; j++)
2657 fprintf(pFile,"%d\t" , j );
2658 for (i=0 ; i<maxX ; i++){
2659 tmpString = interfMainPanel::getInstance()->getCellValue(j, i);//_grid->GetCellValue( j , i );
2660 fprintf(pFile,"%s\t" , (const char *)(tmpString.mb_str()) );
2662 fprintf(pFile,"\n" );
2666 // Total of stadistics.....
2669 fprintf(pFile,"\n Total:\t" );
2670 for (i=0 ; i<maxX ; i++){
2671 tmpString = interfMainPanel::getInstance()->getCellValue(maxZ+2, i);//_grid->GetCellValue( maxZ+2 , i );
2672 fprintf(pFile,"%s\t" , (const char *)(tmpString.mb_str()) );
2674 fprintf(pFile,"\n" );
2682 void wxContourMainFrame::SaveValuesXYZ(std::string directory,std::string namefile,int typeContourGroup)
2685 GenerateContourExtractData();
2687 //int typeContourGroup = this->_radiolstboxContourGroup->GetSelection();
2688 _contourextractdata ->SetTypeOperation( typeContourGroup % 3 );
2690 std::vector<manualContourModel*> lstManConMod;
2691 std::vector<manualContourModel*> lstManConModTmp;
2692 std::vector<manualContourModel*> lstManConModExp;
2693 std::vector<double> pLstValue;
2694 std::vector<double> pLstValuePosX;
2695 std::vector<double> pLstValuePosY;
2696 std::vector<double> pLstValuePosZ;
2698 std::vector<int> tempVector;
2699 _instantPanel->getInstant( tempVector );
2701 vtkImageData *imagedata = _theViewPanel->getSceneManager()->GetImageData();
2702 int sizeZ = _theViewPanel->getSceneManager()->GetImageDataSizeZ();
2704 int ii,sizeLstContourThings;
2711 minZ = 0;// _mbarrange->GetStart();
2712 maxZ = sizeZ;//_mbarrange->GetEnd();
2713 totalZ = maxZ-minZ+1;
2715 _contourextractdata->SetImage( imagedata);
2718 for ( z=0 ; z<sizeZ ; z++)
2721 porcent = 100.0* (z-minZ)/totalZ;
2723 tmpString.Printf(_T("Saving Values"));
2724 tmpString.Printf(_T(" %d %c %d/%d %d"), (int)porcent , 37 , z-minZ+1, (int)totalZ ,z);
2725 interfMainPanel::getInstance()->setStringInfoPanel(tmpString);
2726 //_staticTextInformation->SetLabel(tmpString);
2729 //Extraction data from contours of each slice
2730 _contourextractdata->SetZtoBeAnalys( z);
2733 Instant instant(&tempVector);
2734 std::vector<ContourThing**> lstContourThings = kernelManager->getOutlinesAtInstant(&instant);//this->_modelManager->getOutlinesAtInstant( &instant );
2735 sizeLstContourThings = lstContourThings.size();
2737 lstManConMod.clear();
2738 for (ii=0 ; ii<sizeLstContourThings ; ii++)
2740 ContourThing **contourthing = lstContourThings[ii];
2741 lstManConMod.push_back( (*contourthing)->getModel() );
2743 lstManConModExp = kernelManager->ExploseEachModel( lstManConMod );
2748 int iContourGroup,sizeContourGroup;
2749 if (typeContourGroup==3) // contour separete
2751 sizeContourGroup=lstManConModExp.size();
2752 } else { // contour AND OR XOR
2756 for( iContourGroup=0 ; iContourGroup<sizeContourGroup ; iContourGroup++ ){
2757 lstManConModTmp.clear();
2758 if (typeContourGroup==3) // contour separete
2760 lstManConModTmp.push_back( lstManConModExp[iContourGroup]);
2761 } else { // contour AND OR XOR
2762 lstManConModTmp = lstManConModExp;
2765 _contourextractdata->SetLstManualContourModel( lstManConModTmp );
2768 pLstValuePosX.clear();
2769 pLstValuePosY.clear();
2770 pLstValuePosZ.clear();
2771 _contourextractdata->GetValuesInsideCrown( &pLstValue,
2776 std::string temp = directory + "/" + namefile + "-slice";
2777 temp = temp + kernelManager->intToString(z) + "-cont" + kernelManager->intToString(iContourGroup);
2778 temp = temp + ".txt";
2780 // LG 14/01/09 : using crea
2781 wxString filename = crea::std2wx(temp);
2782 /*filename.Printf(_T("%s"),directory.c_str());
2783 filename.append(_T("\\"));
2784 filename.append(_T("%s"),namefile.c_str());
2785 filename.append(_T("-slice"));
2786 filename.append(_T("%d"),z);
2787 filename.append(_T("-cont"));
2788 filename.append(_T("%d"),iContourGroup);
2789 filename.append(_T(".txt"));*/
2790 // filename.Printf(temp.c_str());
2794 FILE *pFile=fopen((const char *)filename.mb_str(),"w+");
2795 fprintf(pFile,"value \t x \t y \t z\n" );
2796 int iLstValue,sizeLstValue=pLstValue.size();
2797 for (iLstValue=0 ; iLstValue<sizeLstValue ; iLstValue++ )
2799 fprintf(pFile,"%f\t %f\t %f\t %f\n", (float)pLstValue[iLstValue] , (float)pLstValuePosX[iLstValue], (float)pLstValuePosY[iLstValue], (float)z );
2802 } // for iContourGroup
2804 interfMainPanel::getInstance()->setStringInfoPanel(_T(""));
2805 //_staticTextInformation->SetLabel( _T("") );
2809 void wxContourMainFrame::getMaskValue(vtkImageData ** mask,vtkImageData ** value,int typeContourGroup, int selection, int minZ, int maxZ){
2811 GenerateContourExtractData();
2813 //int typeContourGroup = this->_radiolstboxContourGroup->GetSelection();
2814 if (typeContourGroup==3)
2818 _contourextractdata ->SetTypeOperation( typeContourGroup % 3 );
2820 std::vector<manualContourModel*> lstManConMod;
2821 std::vector<manualContourModel*> lstManConModTmp;
2822 std::vector<manualContourModel*> lstManConModExp;
2824 std::vector<int> tempVector;
2825 _instantPanel->getInstant( tempVector );
2827 vtkImageData *imagedata = _theViewPanel->getImageData();
2829 int ii,sizeLstContourThings;
2838 if (selection==0 ) // actual slice
2840 int actualSlice = tempVector[1];
2847 _contourextractdata->SetImage( imagedata);
2850 for ( z=minZ ; z<=maxZ ; z++)
2853 porcent = 100.0* (z-minZ)/totalZ;
2854 tmpString.Printf(_T("Saving Values"));
2855 tmpString.Printf(_T("%d %c %d/%d %d"), (int)porcent , 37 , z-minZ+1, (int)totalZ ,z);
2856 interfMainPanel::getInstance()->setStringInfoPanel(tmpString);
2858 //Extraction data from contours of each slice
2859 _contourextractdata->SetZtoBeAnalys( z);
2862 Instant instant(&tempVector);
2863 std::vector<ContourThing**> lstContourThings = kernelManager->getOutlinesAtInstant( &instant );
2864 sizeLstContourThings = lstContourThings.size();
2866 lstManConMod.clear();
2867 for (ii=0 ; ii<sizeLstContourThings ; ii++)
2869 ContourThing **contourthing = lstContourThings[ii];
2870 lstManConMod.push_back( (*contourthing)->getModel() );
2872 lstManConModExp = kernelManager->ExploseEachModel( lstManConMod );
2875 int iContourGroup,sizeContourGroup;
2876 if (typeContourGroup==3) // contour separete
2878 sizeContourGroup=lstManConModExp.size();
2879 } else { // contour AND OR XOR
2883 for( iContourGroup=0 ; iContourGroup<sizeContourGroup ; iContourGroup++ ){
2884 lstManConModTmp.clear();
2885 if (typeContourGroup==3) // contour separete
2887 lstManConModTmp.push_back( lstManConModExp[iContourGroup]);
2888 } else { // contour AND OR XOR
2889 lstManConModTmp = lstManConModExp;
2892 _contourextractdata->SetLstManualContourModel( lstManConModTmp );
2893 _contourextractdata->CalculateImageResult(); // with actual Z
2895 } // for iContourGroup
2898 (*value) = _contourextractdata->GetVtkImageValueResult();
2899 (*mask) = _contourextractdata->GetVtkImageMaskResult();
2903 void wxContourMainFrame::SaveImageResult(std::string directory,std::string namefile, vtkImageData* mask,vtkImageData* value)
2906 std::string temp = directory + "/" + namefile + "-Value.mhd";
2908 wxString filename = crea::std2wx(temp);
2910 // filename.Printf(_T(temp.c_str()));
2911 //filename.Printf(_T("%s\\%s-Value.mhd",directory.c_str(),namefile.c_str(),z);
2912 /*filename.Printf(_T("%s"),directory.c_str());
2913 filename.append(_T("\\"));
2914 filename.append(_T("%s"),namefile.c_str());
2915 filename.append(_T("-Value.mhd"));*/
2918 vtkMetaImageWriter *writerValueImage = vtkMetaImageWriter::New( );
2919 writerValueImage->SetInput( value );
2920 writerValueImage->SetFileName( (const char *)filename.mb_str() );
2921 writerValueImage->SetFileDimensionality( 3 );
2922 writerValueImage->Write( );
2925 // filename.Printf("%s\\%s-Mask.mhd",directory.c_str(),namefile.c_str(),z);
2926 temp = directory + "/" + namefile + "-Mask.mhd";
2928 // LG 14/01/09 : using crea
2929 filename = crea::std2wx(temp);
2930 // filename.Printf(_T(temp.c_str()));
2932 /*filename.Printf(_T("%s"),directory.c_str());
2933 filename.append(_T("\\"));
2934 filename.append(_T("%s"),namefile.c_str());
2935 filename.append(_T("-Mask.mhd"));*/
2937 vtkMetaImageWriter *writerMaskImage = vtkMetaImageWriter::New( );
2938 writerMaskImage->SetInput( mask );
2939 writerMaskImage->SetFileName( (const char *)filename.mb_str() );
2940 writerMaskImage->SetFileDimensionality( 3 );
2941 writerMaskImage->Write( );
2943 interfMainPanel::getInstance()->setStringInfoPanel( _T("") );
2949 void wxContourMainFrame::onChangeInstantInstantPanel(std::string name,int value, int minshow, int maxshow){
2950 if( name.compare( _theViewPanel->getVerticalConceptName() ) == 0){
2951 _theViewPanel->setActualVertical( value);
2953 else if( name.compare( _theViewPanel->getHorizontalConceptName() ) == 0|| _instantPanel->getIfConceptCheckedAt( name, 0 ) ) {
2954 _theViewPanel->setHorizontalConcept( name, minshow, maxshow, minshow, maxshow, value);
2960 void wxContourMainFrame::onSnakePressed(){
2961 std::vector<double> vecX;
2962 std::vector<double> vecY;
2963 std::vector<double> vecZ;
2964 _theViewPanel->GetPointsOfActualContour( &vecX , &vecY , &vecZ );
2966 if (vecX.size()!=0){
2967 std::vector<int> tempVector;
2968 _instantPanel->getInstant( tempVector );
2969 int i,size=vecZ.size();
2970 int actualSlice = tempVector[1];
2971 for ( i=0 ; i<size ; i++ )
2973 vecZ[i] = actualSlice;
2976 wxDialog* dialog = new wxDialog(this, -1, wxString(_T("Snake")));
2977 wxPanel* panel = new wxPanel(dialog,-1);
2978 // wxStaticText* sttext = new wxStaticText(panel, -1, wxString(_T("Panel para snake")));
2979 new wxStaticText(panel, -1, wxString(_T("Panel para snake")));
2980 dialog->ShowModal();
2985 void wxContourMainFrame::saveFileWithContoursAutomatique(){
2986 std::string filename = kernelManager->getCurrentFileName();
2987 if(filename.compare("")!=0){
2988 saveFileWithContours(filename);
2993 void wxContourMainFrame::ShowToolsPanel(bool show){
2994 _pannew->Show(show);