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;
68 wxContourMainFrame :: wxContourMainFrame(wxWindow* parent, wxWindowID id,const wxString& title,const wxPoint& pos,const wxSize& size,std::vector<vtkImageData*> images, long style,std::string datadir)
69 : wxPanel(parent, id, pos, size, style)
71 m_mgr.SetManagedWindow(this);
72 _creatingContoursActive = false;
76 _refLineControl = NULL;
79 _imageReslicer = NULL;
80 _thresholdTable = NULL;
81 _thresholdMapper = NULL;
82 _thresholdActor = NULL;
83 _actorPresent = false;
85 // set up default notebook style
86 m_notebook_style =wxAUI_NB_TAB_SPLIT | wxAUI_NB_TAB_EXTERNAL_MOVE | wxNO_BORDER;
88 //wxContour_ActionCommandsID a;
89 _numberOfVariablesStatistics = 7;
97 _pannew = interfMainPanel::getInstance(this,datadir+"/data/Icons");//, eventHandler);
98 _performingOperation = new PerformingOperation();
100 if(images.size() > 0)
102 this->setVectImages(images);
107 void wxContourMainFrame::setVectImages(std::vector<vtkImageData*> imgs)
112 #if defined(__GNUC__)
113 std::string str_home(getenv("HOME"));
114 #elif defined(_WIN32)
115 std::string str_home(getenv("USERPROFILE"));
117 std::string strCreaContourDataTmp = str_home + "/.creaContourDataTemp/";
119 std::vector<std::string> conceptNameVect;
120 std::vector<int> conceptSizeVect;
122 notebook = this->createNotebook();
125 kernelManager = new KernelManagerContour( imgs , _datadir+"/data/" , strCreaContourDataTmp );
128 _instantPanel = new wxInstantChooserPanel( notebook, "Instant Chooser", true, false, "c" );
129 _theViewPanel = new wxContourViewPanel( kernelManager->getSourceImage(), notebook );
131 //-------------------------------------------------------------
132 kernelManager->getConceptsInformation(conceptNameVect, conceptSizeVect);
133 _instantPanel->addConcepts(conceptNameVect, conceptSizeVect);
136 double val = _theViewPanel->getCurrentDeep();
137 _instantPanel->setConceptValue( "Axe Depth", (int)val );
138 //JCP _instantPanel->setConceptValue("time", num de imagenes);
139 ConceptDataWrap * data = _instantPanel->getConceptDataOf( "Axe Depth" );
140 //*******************changeInstant();
141 _theViewPanel->setVerticalConcept( "Axe Depth", data->getMinValue(), data->getMaxValue(), data->getMinShowedValue(), data->getMaxShowedValue(), data->getActualValue() );
143 this->configurePanels( );
148 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 ){
149 if(instance == NULL){
150 instance = new wxContourMainFrame(parent, id, title, pos, size, images, style,datadir);
155 std::vector<vtkImageData*> wxContourMainFrame ::getVectImages()
157 return kernelManager->getVectImages();
160 wxContourMainFrame* wxContourMainFrame :: getInstance()
165 void wxContourMainFrame :: resetInstance()
170 wxContourMainFrame :: ~wxContourMainFrame()
174 interfMainPanel::resetInstance();
175 delete kernelManager;
177 //_pannew->Destroy();
183 //El problema al cerrar la aplicacion puede estar asociado
184 //a que wxAUINotebook esta en la aplicacion
185 //principal (wxContourGUIExample)tambien
186 //EED???? delete _theViewPanel;
187 //EED???? delete _instantPanel;
188 //EED???? delete _buttonsBar;
189 //EED???? delete _actualInstant;
190 //EED???? delete _sceneManager;
194 //------------------------------------------------------------------------------------------------------------
195 // Creational and initialization methods using WxAui
196 //------------------------------------------------------------------------------------------------------------
198 wxAuiNotebook * wxContourMainFrame :: createNotebook()
200 wxSize client_size = GetClientSize();
201 wxAuiNotebook* noteBook = new wxAuiNotebook(this, -1, wxPoint(client_size.x, client_size.y), wxSize(430,200), m_notebook_style);
202 wxBitmap page_bmp = wxArtProvider::GetBitmap(wxART_NORMAL_FILE, wxART_OTHER, wxSize(16,16));
207 //------------------------------------------------------------------------------------------------------------
208 // Creational and initialization methods
209 //------------------------------------------------------------------------------------------------------------
210 bool wxContourMainFrame :: configurePanels( )
212 bool configured = _theViewPanel!=NULL;
214 configured &= _theViewPanel!=NULL;
215 if( _theViewPanel!=NULL )
217 notebook->AddPage( _theViewPanel, wxT(" View ") );
224 notebook->AddPage( _instantPanel, wxT("Instant Page") );
228 m_mgr.AddPane(notebook, wxAuiPaneInfo().Name(wxT("notebook_content")).CenterPane().PaneBorder(false));
231 SetMinSize(wxSize(300,300));
237 bool wxContourMainFrame::addNewPanel(wxPanel* panel)
239 bool configured = panel!=NULL;
240 configured &= panel!=NULL;
244 notebook->AddPage( panel, wxT(" Viewer "), true );
250 //------------------------------------------------------------------------------------------------------------
251 // Attributes getters and setters
252 //------------------------------------------------------------------------------------------------------------
256 void wxContourMainFrame :: setInstantChooserPanel( wxInstantChooserPanel * theInstantChooserPanel )
258 _instantPanel = theInstantChooserPanel;
261 // void wxContourMainFrame :: setButtonsBar( wxContour_ButtonsBar * theButtonsBar )
263 // _buttonsBar = theButtonsBar;
266 // void wxContourMainFrame :: setGrid( wxContour_Grid * theGridPanel )
268 // _gridPanel = theGridPanel;
271 // void wxContourMainFrame :: setDrawToolsPanel( wxContour_DrawToolsPanel * theDrawToolsPanel )
273 // _drawToolsPanel = theDrawToolsPanel;
276 // void wxContourMainFrame :: setOperationsToolsPanel( wxContour_OperationsToolsPanel * theOperationsToolsPanel )
278 // _operationsToolsPanel = theOperationsToolsPanel;
281 // void wxContourMainFrame :: setAutomaticFormsPanel( wxContour_AutomaticFormsToolsPanel * theAutoFormsPanel )
283 // _autoFormsPanel = theAutoFormsPanel;
286 // void wxContourMainFrame :: setStandardToolsPanel( wxContour_StandardToolsPanel * theStandardToolsPanel )
288 // _standardToolsPanel= theStandardToolsPanel;
291 // void wxContourMainFrame :: setEditionToolsPanel( wxContour_EdtionToolsPanel * theEditionToolsPanel )
293 // _editionToolsPanel = theEditionToolsPanel;
296 // void wxContourMainFrame :: setListViewPanel( wxContour_ListViewPanel * theListViewPanel )
298 // _listViewPanel = theListViewPanel;
303 void wxContourMainFrame::onCreateContourSpline( ){
305 //JCP 20-10-08 Undo redo implementation
307 //JCP 20-10-08 Undo redo implementation
311 void wxContourMainFrame::onCreateContourRectangle( ){
312 //JCP 20-10-08 Undo redo implementation
314 //JCP 20-10-08 Undo redo implementation
317 void wxContourMainFrame::onCreateContourCircle( ){
318 //JCP 20-10-08 Undo redo implementation
320 //JCP 20-10-08 Undo redo implementation
324 void wxContourMainFrame::onCreateContourLine( ){
325 //JCP 20-10-08 Undo redo implementation
327 //JCP 20-10-08 Undo redo implementation
331 //------------------------------------------------------------------------------------------------------------
333 void wxContourMainFrame :: onCreateContourBullEye(wxPanel* panel )
335 //Creating the manualContourModel and including in the model
336 manualContourModel * manModelContour = factoryManualContourModel(panel );
338 std::vector<int> instantVector;
339 _instantPanel->getInstant( instantVector );
340 std::string theName = kernelManager->createOutline(manModelContour, instantVector);
342 /*std::vector<int> instantVector;
343 _instantPanel->getInstant( instantVector );
345 theName= _modelManager->createOutline( manModelContour, instantVector );*/
346 bool addedModel = theName.compare("") != 0;//??
350 double spc[3];//Si no hay imagen pero hay contornos que spacing se pone por default
351 _theViewPanel->getSpacing(spc);
352 //Adding the manualContourControler to interface objects structure
353 //Adding the manualViewContour to interface objects structure
354 //_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.
355 _theViewPanel->getSceneManager()->configureViewControlTo( theName, manModelContour,spc , 4) ;
358 void wxContourMainFrame :: createContour( int typeContour )
360 //Creating the manualContourModel and including in the model
361 manualContourModel * manModelContour = kernelManager->factoryManualContourModel(typeContour);
364 std::vector<int> instantVector;
365 _instantPanel->getInstant( instantVector );
366 std::string theName = kernelManager->createOutline(manModelContour, instantVector);
368 /*std::vector<int> instantVector;
369 _instantPanel->getInstant( instantVector );
371 theName= _modelManager->createOutline( manModelContour, instantVector );*/
372 bool addedModel = theName.compare("") != 0;//??
375 double spc[3];//Si no hay imagen pero hay contornos que spacing se pone por default
376 _theViewPanel->getSpacing(spc);
377 //Adding the manualContourControler to interface objects structure
378 //Adding the manualViewContour to interface objects structure
379 //_sceneManager->setControlActiveStateOfALL( false );//This call is being done here because if the ROI is created underneath the previously created ROIS will still be active.
380 _theViewPanel->getSceneManager()->configureViewControlTo( theName, manModelContour,spc , typeContour) ;
384 manualContourModel * wxContourMainFrame::factoryManualContourModel(wxPanel* panel){
386 manualContourModelBullEye *manModelContourBullEye = new manualContourModelBullEye();
387 manualContourModel *manModelContour=NULL;
388 manModelContour = manModelContourBullEye;
390 int iCrown,sizeCrowns,iSector,sizeSectors;
391 double radioA,radioB,ang,angDelta ;
392 sizeCrowns = ((PanelBullEyeOptions*)panel)->GetNumberOfCrowns();
393 for ( iCrown=0 ; iCrown<sizeCrowns ; iCrown++ )
395 sizeSectors = ((PanelBullEyeOptions*)panel)->GetNumberOfSections(iCrown);
396 radioB = ((PanelBullEyeOptions*)panel)->GetRadioOfCrown(iCrown);
397 if (iCrown==sizeCrowns-1)
401 radioA = ((PanelBullEyeOptions*)panel)->GetRadioOfCrown(iCrown+1);
405 for ( iSector=0 ; iSector<sizeSectors ; iSector++ )
407 ang = ((PanelBullEyeOptions*)panel)->GetAngOfCrownSection(iCrown,iSector);
408 angDelta= ((PanelBullEyeOptions*)panel)->GetAngDeltaOfCrownSection(iCrown);
409 manModelContourBullEye->AddSector(radioA,radioB,ang,angDelta);
412 } // if _panelBullEyeOptions
414 return manModelContour;
416 void wxContourMainFrame :: saveState(){
418 std::string temp = kernelManager->saveState();
419 saveFileWithContours(temp);
422 void wxContourMainFrame::onDeleteContour(){
423 //JCP 20-10-08 Undo redo implementation
425 //JCP 20-10-08 Undo redo implementation
427 std::vector<std::string> lstKeyNameToBeErase;
428 lstKeyNameToBeErase = _theViewPanel->getSceneManager()->getSelectedObjects();
429 deleteContours( lstKeyNameToBeErase );
431 int i,size=_sceneManager->getSelectedObjects().size();
434 std::string keyName = _sceneManager->getSelectedObjects()[i];
435 int ispartofstaticlist = this->_modelManager->IsPartOfStaticList( keyName );
436 if ( ispartofstaticlist>=0 )
438 std::vector<int> tempVector;
439 _instantPanel->getInstant( tempVector );
440 Instant instant(&tempVector);
441 this->_modelManager->ChangeContourOfList(keyName, &instant);
445 std::vector<std::string> lstKeyName;
446 std::vector<std::string> lstKeyNameActualSlice;
447 std::vector<std::string> lstKeyNameToBeErase;
449 lstKeyNameToBeErase = _sceneManager->getSelectedObjects();
450 lstKeyNameActualSlice = _sceneManager->GetlstContoursNameActualSlice();
451 int k,kSize=lstKeyNameToBeErase.size();
452 int j,jSize=lstKeyNameActualSlice.size();
454 for (k=0;k<kSize; k++)
457 for (j=0;j<jSize; j++)
459 if (lstKeyNameToBeErase[k]==lstKeyNameActualSlice[j])
466 lstKeyName.push_back( lstKeyNameToBeErase[k] );
470 deleteContours( lstKeyName );
474 void wxContourMainFrame :: deleteContours( std::vector<std::string> keyNamesVector )
476 int i,size=keyNamesVector.size();
479 deleteContour( keyNamesVector[i] );
483 void wxContourMainFrame :: deleteContour( std::string theKeyName ){
485 manualContourModel * cModel;
486 manualViewBaseContour * cViewer;
487 manualContourBaseControler * cControler;
489 ContourWrap_ViewControl *conwrapviewControl = _theViewPanel->getSceneManager()->getContourWrap_ViewControlOf( theKeyName );
490 cControler = conwrapviewControl->getControler();*/
493 bool isedit = _theViewPanel->isEditableCControler(theKeyName);
494 bool ispartofstaticlst = kernelManager->IsPartOfStaticList(theKeyName);
496 if (isedit && ispartofstaticlst)
498 _theViewPanel->removeFromScene(theKeyName);
500 kernelManager->deleteCModel(theKeyName);
501 //_theViewPanel->getSceneManager()->removeFromScene( theKeyName );
502 //cViewer = conwrapviewControl->getViewer();
503 //_theViewPanel->getSceneManager()->removeWrap( theKeyName );
504 //cControler* conwrapviewControl->getControler();
506 //FILE *ff = fopen("c:/temp/wxVtkBaseView_SceneManagerStadistics.txt","a+");
507 //fprintf(ff,"EED wxContourEventHandler::deleteContours() \n" );
508 //fprintf(ff," %s %p\n",keyNamesVector[i].c_str(), cControler );
512 // delete cControler;
517 void wxContourMainFrame::onDeleteContoursActSlice(){
518 //JCP 20-10-08 Undo redo implementation
520 //JCP 20-10-08 Undo redo implementation
521 deleteContours( (std::vector<std::string>)_theViewPanel->getSceneManager()->GetlstContoursNameActualSlice() );
523 void wxContourMainFrame::onDeleteAllContours(){
524 //JCP 20-10-08 Undo redo implementation
528 void wxContourMainFrame::deleteAllContours(){
529 //JCP 20-10-08 Undo redo implementation
532 std::vector<int> tempVector;
533 _instantPanel->getInstant( tempVector );
535 //JCP --08-09-2008 When using a diferent interface the _mbarrangeDeleteAll might not be initialize
536 // the values in GetStart and GetEnd will then not be initialize also.
537 // We use instead the values given when initializing the _deletepanel.
539 //int minZ = _mbarrangeDeleteAll->GetStart();
540 //int maxZ = _mbarrangeDeleteAll->GetEnd();
544 maxZ = _theViewPanel->getSceneManager()->GetImageDataSizeZ();
548 _theViewPanel->getSceneManager()->removeSceneContours( );
549 _theViewPanel->getSceneManager()->removeAllOutlines();
550 kernelManager->removeAllOutlines();
553 if ( (minZ==0) && (maxZ==_mbarrangeDeleteAll->GetMax() ))
555 _theViewPanel->getSceneManager()->removeSceneContours( );
556 _modelManager->removeAllOutlines();
557 _theViewPanel->getSceneManager()->removeAllOutlines();
560 for ( z=minZ ; z<=maxZ ; z++)
563 Instant instant(&tempVector);
564 std::vector<ContourThing**> lstContourThings = this->_modelManager->getOutlinesAtInstant( &instant );
566 sizeLstContourThings = lstContourThings.size();
567 for (ii=0 ; ii<sizeLstContourThings ; ii++)
569 ContourThing **contourthing = lstContourThings[ii];
570 deleteContour( (*contourthing)->getName() );
577 void wxContourMainFrame::setConceptValue( std::string name, int value ){
578 _instantPanel->setConceptValue(name, value);
581 ConceptDataWrap* wxContourMainFrame::getLastConceptData(){
582 return _instantPanel->getLastConceptData();
584 bool wxContourMainFrame::getIfConceptCheckedAt( std::string name, int pos ){
585 return _instantPanel->getIfConceptCheckedAt( name, pos );
588 void wxContourMainFrame::changeInstant()
590 std::vector<int> instantVect;
591 _instantPanel->getInstant( instantVect );
592 // Instant * theInstant = new Instant ( &instantVect );
594 //Setting the actual instant
595 //_actualInstant = theInstant;
597 kernelManager->setInstant(instantVect);
598 //_modelManager->setInstant( _actualInstant );
601 updateInstantOutlines();
602 updateInstantImageData();
607 void wxContourMainFrame :: updateInstantOutlines()
609 _theViewPanel->removeSceneContours();
610 _theViewPanel->addNameWrapperToScene();
612 //for( int i=0; i<size; i++)
614 // _theViewPanel->getSceneManager()->addToScene(namesWrapping[i]->getKeyName(), true, true, true, false, false );
618 int wxContourMainFrame::getNamesWrappingSize(){
619 return kernelManager->getNamesWrappingSize();
621 std::string wxContourMainFrame::getNameWrapping(int i){
622 return kernelManager->getNameWrapping(i);
625 void wxContourMainFrame::updateInstantImageData()
627 std::vector<int> inst;
628 _instantPanel->getInstant(inst);
630 vtkImageData* img = kernelManager->getImageAtInstant(inst);
632 _theViewPanel->changeImage(img);
635 int z = _instantPanel->getConceptDataOf("Axe Depth")->getActualValue();
636 _theViewPanel->setImageSlice(z);
640 void wxContourMainFrame::updateInstantAxes()
645 void wxContourMainFrame::onChangeDeep(int val){
646 _instantPanel->setConceptValue( "Axe Depth", (int)val );
651 void wxContourMainFrame::onCopy(){
652 std::vector<std::string> currentSelection = _theViewPanel->getSelectedObjects();
654 std::vector<int> tempVector;
655 _instantPanel->getInstant( tempVector );
656 _performingOperation->reset();
657 _performingOperation->setStartCommand( COPY );
658 _performingOperation->setStartOperationInstantVector( tempVector );
659 _performingOperation->setKeyNamesOperationElems( currentSelection );
662 void wxContourMainFrame::onPaste(){
665 char theStartCommand = _performingOperation->getStartCommand();
666 if ( theStartCommand == COPY )
668 //JCP 20-10-08 Undo redo implementation
670 //JCP 20-10-08 Undo redo implementation
671 std::vector<int> tempVector;
672 _instantPanel->getInstant( tempVector );
673 _performingOperation->setEndOperationInstantVector ( tempVector );
674 std::vector<std::string> elems = _performingOperation->getKeyNamesOperationElems();
675 int i,size = elems.size();
676 for( i=0; i<size; i++ )
678 createCopyContourOf( elems[i], tempVector, i>0 );
682 void wxContourMainFrame::onUndo(){
683 std::string filename;
684 if(kernelManager->onUndoSaveFile(filename)){
685 saveFileWithContours(filename);
687 if(kernelManager->onUndo(filename)){
691 void wxContourMainFrame::onRedo(){
692 std::string filename;
693 if(kernelManager->onRedo(filename)){
698 void wxContourMainFrame :: createCopyContourOf ( std::string anExistingKName, std::vector<int> &instantNoTouchData, bool append )
700 std::string cloneName = kernelManager->createCopyContourOf( anExistingKName, instantNoTouchData );
701 manualContourModel * manualModel = kernelManager->getOutlineByKeyName(cloneName);//_modelManager->getOutlineByKeyName( cloneName )->getModel();
702 _theViewPanel->getSceneManager()->createCopyContourOf( anExistingKName, cloneName, manualModel , append );
705 ///AD: 03-09 Copy the object and apply the given transformation
706 void wxContourMainFrame :: createMirrorContourOf ( std::string anExistingKName, std::vector<int> &instantNoTouchData, bool append )
708 std::string cloneName = kernelManager->createCopyContourOf( anExistingKName, instantNoTouchData );
709 manualContourModel * manualModel = kernelManager->getOutlineByKeyName(cloneName);
711 manualPoint * refPoint1 = _refLineModel->GetManualPoint(0);
712 manualPoint * refPoint2 = _refLineModel->GetManualPoint(1);
714 double pnt1X = refPoint1->GetX();
715 double pnt1Y = refPoint1->GetY();
716 // double pnt1Z = refPoint1->GetZ();
717 double pnt2X = refPoint2->GetX();
718 double pnt2Y = refPoint2->GetY();
719 // double pnt2Z = refPoint2->GetZ();
721 double angle = (atan2(pnt2Y - pnt1Y, pnt2X - pnt1X) * 180 / 3.1415926535897932384626433832795)+90;
722 vtkTransform *t = vtkTransform::New();
726 t->Translate(-pnt1X, -pnt1Y, 0);
730 t->Translate(pnt1X, pnt1Y, 0);
733 int i,size=manualModel->GetSizeLstPoints();
736 manualPoint * mp = manualModel->GetManualPoint(i);
742 t->TransformPoint( vecIn, vecOut );
743 mp->SetPointX( vecOut[0] );
744 mp->SetPointY( vecOut[1] );
745 mp->SetPointZ( vecOut[2] );
748 _theViewPanel->getSceneManager()->createCopyContourOf( anExistingKName, cloneName, manualModel , append );
751 void wxContourMainFrame ::loadState(std::string filename){
753 FILE *pFile=fopen(filename.c_str(),"r+");
755 fscanf(pFile,"%s",tmp); // --CreaContour--
757 fscanf(pFile,"%s",tmp); // Version
758 fscanf(pFile,"%s",tmp); // 1.0.2 || 1.0.1 || 1.0.0
762 loadContours(pFile, false);
763 loadContours(pFile, true);
768 void wxContourMainFrame ::loadContours( FILE *pFile, bool staticContour )
772 if (staticContour==false)
774 fscanf(pFile,"%s",tmp); // ImageDimensions
775 fscanf(pFile,"%s",tmp); // X
776 fscanf(pFile,"%s",tmp); // Y
777 fscanf(pFile,"%s",tmp); // Z
779 fscanf(pFile,"%s",tmp); // ImageSpacing
780 fscanf(pFile,"%s",tmp); // X
781 fscanf(pFile,"%s",tmp); // Y
782 fscanf(pFile,"%s",tmp); // Z
785 fscanf(pFile,"%s",tmp); // NumberOfContours
786 fscanf(pFile,"%s",tmp); // ##
787 int numberOfContours = atoi(tmp);
789 std::vector<int> instantVector;
790 int typeContourModel;
791 manualContourModel *manModelContour;
795 for (i=0;i<numberOfContours;i++)
797 instantVector.clear();
798 fscanf(pFile,"%s",tmp); // Instant
799 fscanf(pFile,"%s",tmp); // 1
800 instantVector.push_back( atoi(tmp) );
801 fscanf(pFile,"%s",tmp); // 2
802 instantVector.push_back( atoi(tmp) );
803 fscanf(pFile,"%s",tmp); // 3
804 instantVector.push_back( atoi(tmp) );
805 fscanf(pFile,"%s",tmp); // 4
806 instantVector.push_back( atoi(tmp) );
807 fscanf(pFile,"%s",tmp); // 5
808 instantVector.push_back( atoi(tmp) );
809 fscanf(pFile,"%s",tmp); // 6
810 instantVector.push_back( atoi(tmp) );
812 fscanf(pFile,"%s",tmp); // TypeContourModel
813 fscanf(pFile,"%s",tmp); // ##
814 typeContourModel = atoi(tmp);
816 manModelContour = kernelManager->factoryManualContourModel(typeContourModel);
817 manModelContour->Open(pFile);
819 fscanf(pFile,"%s",tmp); // TypeView
820 fscanf(pFile,"%s",tmp); // ##
821 typeView = atoi(tmp);
824 theName = kernelManager->createOutline( manModelContour, instantVector );
825 bool addedModel = theName.compare("") != 0;
828 double spc[3];//Si no hay imagen pero hay contornos que spacing se pone por default
829 _theViewPanel->getSpacing(spc);
830 //Adding the manualContourControler to interface objects structure
831 //Adding the manualViewContour to interface objects structure
832 //_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.
833 _theViewPanel->getSceneManager()->configureViewControlTo( theName, manModelContour,spc , typeView) ;
836 if (staticContour==true)
838 Instant instant(&instantVector);
839 kernelManager->changeContourOfManager( theName , &instant );
841 }// for numberOfContours
844 void wxContourMainFrame::onLoad()
847 wxFileDialog dialog(NULL, _T("Choose a file"), _T(""), _T(""), _T("*.roi"), wxOPEN );
848 if (dialog.ShowModal() == wxID_OK)
850 std::string fileNameContourROI = (const char *)(dialog.GetPath().mb_str());
851 FILE *pFile=fopen(fileNameContourROI.c_str(),"r+");
853 fscanf(pFile,"%s",tmp); // --CreaContour--
855 fscanf(pFile,"%s",tmp); // Version
856 fscanf(pFile,"%s",tmp); // 1.0.2 || 1.0.1 || 1.0.0
857 std::string version(tmp);
860 if (version=="1.0.2")
862 openContours(pFile,2,false);
863 openContours(pFile,2,true); //Load StaticContours
867 else if (version=="1.0.1")
869 openContours(pFile,1,false); //Skips ImageDimensions and ImageSpacing
870 openContours(pFile,1,true); //Load StaticContours, skips ImageDimensions and ImageSpacing
874 else if (version=="1.0.0")
876 openContours(pFile,1,false); //Skips ImageDimensions and ImageSpacing
881 _theViewPanel->getSceneManager()->removeSceneContours();
886 void wxContourMainFrame::onSave(){
887 wxFileDialog dialog(NULL, _T("Choose a file"), _T(""), _T(""), _T("*.roi"), wxSAVE );
888 if (dialog.ShowModal() == wxID_OK)
890 std::string fileNameContourROI = (const char *)(dialog.GetPath().mb_str());
891 kernelManager->setCurrentFileName(fileNameContourROI);
892 saveFileWithContours( fileNameContourROI );
897 void wxContourMainFrame::saveFileWithContours( std::string filename )
900 FILE *pFile=fopen(filename.c_str(),"w+");
901 std::vector< std::string > lstNameThings;
902 int i,sizeLstNameThings;
904 fprintf(pFile,"--CreaContour--\n");
905 fprintf(pFile,"Version %s\n", "1.0.2" );
907 vtkImageData *image = _images[0];
910 image->GetDimensions(dimRange);
912 fprintf(pFile,"ImageDimensions %d %d %d\n", dimRange[0], dimRange[1], dimRange[2] );
915 image->GetSpacing(spaRange);
917 fprintf(pFile,"ImageSpacing %f %f %f\n", spaRange[0], spaRange[1], spaRange[2] );
921 lstNameThings = kernelManager->GetLstNameThings();
922 sizeLstNameThings = lstNameThings.size();
923 fprintf(pFile,"NumberOfContours %d\n", sizeLstNameThings );
925 for (i=0 ; i<sizeLstNameThings ; i++)
927 kernelManager->SaveThingName( pFile, lstNameThings[i] );
928 _theViewPanel->getSceneManager()->SaveThingName( pFile, lstNameThings[i] );
933 fprintf(pFile,"ImageDimensions %d %d %d\n", dimRange[0], dimRange[1], dimRange[2] );
935 fprintf(pFile,"ImageSpacing %f %f %f\n", spaRange[0], spaRange[1], spaRange[2] );
937 lstNameThings = kernelManager->GetLstNameThingsStatic();
938 sizeLstNameThings = lstNameThings.size();
939 fprintf(pFile,"NumberOfContoursStatic %d\n", sizeLstNameThings );
940 for (i=0 ; i<sizeLstNameThings ; i++)
942 kernelManager->SaveThingName( pFile, lstNameThings[i] );
943 _theViewPanel->getSceneManager()->SaveThingName( pFile, lstNameThings[i] );
949 void wxContourMainFrame::openContours( FILE *pFile, int version, bool staticContour )
953 vtkImageData *image = _images[0];
959 bool compatible = true;
964 image->GetDimensions(imageDim);
965 image->GetSpacing(imageSpac);
967 fscanf(pFile,"%s",tmp); // ImageDimensions
968 fscanf(pFile,"%s",tmp); // X
969 tempDim[0] = atoi(tmp);
970 fscanf(pFile,"%s",tmp); // Y
971 tempDim[1] = atoi(tmp);
972 fscanf(pFile,"%s",tmp); // Z
973 tempDim[2] = atoi(tmp);
975 fscanf(pFile,"%s",tmp); // ImageSpacing
976 fscanf(pFile,"%s",tmp); // X
977 tempSpac[0] = atof(tmp);
978 fscanf(pFile,"%s",tmp); // Y
979 tempSpac[1] = atof(tmp);
980 fscanf(pFile,"%s",tmp); // Z
981 tempSpac[2] = atof(tmp);
983 //Compare Spacing and Dims in X and Y (Necessary in Z?) - Just for Version 2
984 if (imageDim[0]!=tempDim[0] || imageDim[1]!=tempDim[1] || imageSpac[0]!=tempSpac[0] || imageSpac[1]!=tempSpac[1])
990 fscanf(pFile,"%s",tmp); // NumberOfContours
991 fscanf(pFile,"%s",tmp); // ##
992 int numberOfContours = atoi(tmp);
994 std::vector<int> instantVector;
995 int typeContourModel;
996 manualContourModel *manModelContour;
999 if (compatible==true)
1002 for (i=0;i<numberOfContours;i++)
1004 instantVector.clear();
1005 fscanf(pFile,"%s",tmp); // Instant
1007 fscanf(pFile,"%s",tmp); // 1
1008 instantVector.push_back( atoi(tmp) );
1009 fscanf(pFile,"%s",tmp); // 2
1010 instantVector.push_back( atoi(tmp) );
1011 fscanf(pFile,"%s",tmp); // 3
1012 instantVector.push_back( atoi(tmp) );
1013 fscanf(pFile,"%s",tmp); // 4
1014 instantVector.push_back( atoi(tmp) );
1015 fscanf(pFile,"%s",tmp); // 5
1016 instantVector.push_back( atoi(tmp) );
1017 fscanf(pFile,"%s",tmp); // 6
1018 instantVector.push_back( atoi(tmp) );
1021 fscanf(pFile,"%s",tmp); // TypeContourModel
1022 fscanf(pFile,"%s",tmp); // ##
1023 typeContourModel = atoi(tmp);
1025 manModelContour = kernelManager->factoryManualContourModel(typeContourModel);
1026 manModelContour->Open(pFile);
1028 fscanf(pFile,"%s",tmp); // TypeView
1029 fscanf(pFile,"%s",tmp); // ##
1030 typeView = atoi(tmp);
1032 std::string theName;
1033 theName = kernelManager->createOutline( manModelContour, instantVector );
1034 bool addedModel = theName.compare("") != 0;
1037 double spc[3];//Si no hay imagen pero hay contornos que spacing se pone por default
1038 _theViewPanel->getSpacing(spc);
1039 //Adding the manualContourControler to interface objects structure
1040 //Adding the manualViewContour to interface objects structure
1041 //_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.
1042 _theViewPanel->getSceneManager()->configureViewControlTo( theName, manModelContour,spc , typeView) ;
1045 if (staticContour) //StaticContours (will appear in all slices)
1047 Instant instant(&instantVector);
1048 kernelManager->changeContourOfManager( theName , &instant );
1051 }// for numberOfContours
1054 else if (compatible==false)
1056 wxDialog* dial = new wxDialog (this,-1,_T("Tools"),wxDefaultPosition, wxSize(260,160));
1057 wxSizer* buttonsSizer = dial->CreateSeparatedButtonSizer(wxOK|wxCANCEL);
1058 wxBoxSizer *dialSizer = new wxBoxSizer(wxVERTICAL);
1060 wxString lstOptOperation[2];
1061 lstOptOperation[0]=_T("By Dimension");
1062 lstOptOperation[1]=_T("By Spacing");
1063 wxRadioBox * radioOpts = new wxRadioBox(dial, -1, _T("Type of Transformation"), wxDefaultPosition, wxSize(270,45), 2 , lstOptOperation, 2, wxRA_SPECIFY_COLS);
1065 dialSizer->Add( new wxStaticText(dial,-1,_T("The image resolution is not compatible with the ")) , 0, wxGROW );
1066 dialSizer->Add( new wxStaticText(dial,-1,_T("selected Roi file. Do you want to tranform it?")) , 0, wxGROW );
1067 dialSizer->Add( new wxStaticText(dial,-1,_T(" ")) , 0, wxGROW );
1068 dialSizer->Add(radioOpts,0,wxGROW);
1069 dialSizer->Add( new wxStaticText(dial,-1,_T(" ")) , 0, wxGROW );
1070 dialSizer->Add(buttonsSizer,0,wxGROW);
1071 dial->SetSizer(dialSizer, true);
1075 int typeOfTransformation = -1;
1076 bool transform = false;
1078 if (dial->GetReturnCode() == wxID_OK)
1080 typeOfTransformation = radioOpts->GetSelection();
1085 for (i=0;i<numberOfContours;i++)
1087 instantVector.clear();
1088 fscanf(pFile,"%s",tmp); // Instant
1090 fscanf(pFile,"%s",tmp); // 1
1091 instantVector.push_back( atoi(tmp) );
1092 fscanf(pFile,"%s",tmp); // 2
1093 instantVector.push_back( atoi(tmp) );
1094 fscanf(pFile,"%s",tmp); // 3
1095 instantVector.push_back( atoi(tmp) );
1096 fscanf(pFile,"%s",tmp); // 4
1097 instantVector.push_back( atoi(tmp) );
1098 fscanf(pFile,"%s",tmp); // 5
1099 instantVector.push_back( atoi(tmp) );
1100 fscanf(pFile,"%s",tmp); // 6
1101 instantVector.push_back( atoi(tmp) );
1103 fscanf(pFile,"%s",tmp); // TypeContourModel
1104 fscanf(pFile,"%s",tmp); // ##
1105 typeContourModel = atoi(tmp);
1107 manModelContour = kernelManager->factoryManualContourModel(typeContourModel);
1108 manModelContour->Open(pFile);
1110 if (transform==true)
1112 if (typeOfTransformation==0)
1114 double transX, transY;
1115 transX = (double) imageDim[0]/tempDim[0];
1116 transY = (double) imageDim[1]/tempDim[1];
1117 manModelContour->Transform_Ax_Plus_B(transX,0,transY,0);
1119 else if (typeOfTransformation==1)
1121 double transX, transY;
1122 transX = (double) tempSpac[0]/imageSpac[0];
1123 transY = (double) tempSpac[1]/imageSpac[1];
1124 manModelContour->Transform_Ax_Plus_B(transX,0,transY,0);
1128 fscanf(pFile,"%s",tmp); // TypeView
1129 fscanf(pFile,"%s",tmp); // ##
1130 typeView = atoi(tmp);
1132 std::string theName;
1133 theName = kernelManager->createOutline( manModelContour, instantVector );
1134 bool addedModel = theName.compare("") != 0;
1137 double spc[3];//Si no hay imagen pero hay contornos que spacing se pone por default
1138 _theViewPanel->getSpacing(spc);
1139 //Adding the manualContourControler to interface objects structure
1140 //Adding the manualViewContour to interface objects structure
1141 //_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.
1142 _theViewPanel->getSceneManager()->configureViewControlTo( theName, manModelContour,spc , typeView) ;
1145 if (staticContour) //StaticContours (will appear in all slices)
1147 Instant instant(&instantVector);
1148 kernelManager->changeContourOfManager( theName , &instant );
1150 }// for numberOfContours
1154 void wxContourMainFrame::RefreshInterface(){
1156 _theViewPanel->RefreshInterface();
1157 //wxVtk2DBaseView *wxvtk2dbaseview = (wxVtk2DBaseView*)this->_theViewPanel->getWxVtkBaseView();
1158 //wxvtk2dbaseview->Refresh();
1161 vtkImageData* wxContourMainFrame::getImageData(){
1162 return _theViewPanel->getImageData();
1165 void wxContourMainFrame::onSegmentationOneSliceITK(wxString distance, wxString sigma, wxString alfa, wxString beta, wxString propagation, wxString iterations, wxString inflation)
1167 //JCP 20-10-08 Undo redo implementation
1169 //JCP 20-10-08 Undo redo implementation
1172 int x = _theViewPanel->GetX();
1173 int y = _theViewPanel->GetY();
1174 int z = _theViewPanel->GetZ();
1175 SegmentationOneSliceITK( x,y,z,distance, sigma, alfa, beta, propagation, iterations, inflation);
1179 void wxContourMainFrame::SegmentationOneSliceITK(int x, int y, int z, wxString distanc, wxString sigm, wxString alf, wxString bet, wxString prop, wxString iter, wxString inflation)
1181 int typeofcontour = 1;
1183 vtkImageData *imagedata = getImageData();
1185 //Tipo de pixeles a utilizar internamente en ITK
1186 typedef float InternalPixelType;
1187 const unsigned int Dimension = 2;
1188 typedef itk::Image< InternalPixelType, Dimension > InternalImageType;
1190 //Tipo de pixeles de salida 1
1191 typedef unsigned char OutputPixelType;
1192 typedef itk::Image< OutputPixelType, Dimension > OutputImageType;
1194 //Tipo de pixeles de salida 2
1195 typedef unsigned short OutputPixelType2;
1196 typedef itk::Image< OutputPixelType2, Dimension > OutputImageType2;
1198 //DefiniciÛn del thresholder
1199 typedef itk::BinaryThresholdImageFilter<
1201 OutputImageType > ThresholdingFilterType;
1203 //DefiniciÛn del primer filtro de conversiÛn de pixeles
1204 typedef itk::CastImageFilter<
1205 OutputImageType, OutputImageType2 > CastFilterType;
1207 //DefiniciÛn del segundo tipo de conversiÛn de pixeles
1208 typedef itk::CastImageFilter<
1209 OutputImageType2, InternalImageType > CastFilterType2;
1211 //Tercer tipo de conversiÛn
1212 typedef itk::RescaleIntensityImageFilter<
1214 OutputImageType > CastFilterType3;
1216 //Cuarto tipo de conversiÛn
1217 typedef itk::RescaleIntensityImageFilter<
1219 OutputImageType > CastFilterType4;
1221 ThresholdingFilterType::Pointer thresholder = ThresholdingFilterType::New();
1223 thresholder->SetLowerThreshold( 0.0 );
1224 thresholder->SetUpperThreshold( 128 );
1226 thresholder->SetOutsideValue( 255 );
1227 thresholder->SetInsideValue( 0 );
1229 //DefinciÛn de conexiÛnes entre VTK e ITK y el writer
1230 typedef itk::VTKImageToImageFilter<OutputImageType2> ConnectorType;
1231 typedef itk::ImageToVTKImageFilter<OutputImageType> ConnectorType2;
1232 typedef itk::ImageFileWriter< OutputImageType > WriterType;
1234 ConnectorType::Pointer connector= ConnectorType::New();
1235 ConnectorType2::Pointer connector2= ConnectorType2::New();
1238 CastFilterType::Pointer filter=CastFilterType::New();
1239 CastFilterType2::Pointer filter2=CastFilterType2::New();
1241 connector->SetInput( imagedata );
1242 filter2->SetInput(connector->GetOutput());
1244 typedef itk::CurvatureAnisotropicDiffusionImageFilter<
1246 InternalImageType > SmoothingFilterType;
1248 SmoothingFilterType::Pointer smoothing = SmoothingFilterType::New();
1250 typedef itk::GradientMagnitudeRecursiveGaussianImageFilter<
1252 InternalImageType > GradientFilterType;
1254 typedef itk::SigmoidImageFilter<
1256 InternalImageType > SigmoidFilterType;
1258 GradientFilterType::Pointer gradientMagnitude = GradientFilterType::New();
1260 SigmoidFilterType::Pointer sigmoid = SigmoidFilterType::New();
1262 sigmoid->SetOutputMinimum( 0.0 );
1263 sigmoid->SetOutputMaximum( 255.0 );
1266 typedef itk::FastMarchingImageFilter<
1268 InternalImageType > FastMarchingFilterType;
1271 FastMarchingFilterType::Pointer fastMarching = FastMarchingFilterType::New();
1273 typedef itk::GeodesicActiveContourLevelSetImageFilter< InternalImageType,
1274 InternalImageType > GeodesicActiveContourFilterType;
1275 GeodesicActiveContourFilterType::Pointer geodesicActiveContour =
1276 GeodesicActiveContourFilterType::New();
1278 typedef itk::ZeroCrossingImageFilter<
1280 InternalImageType > ZeroCrossingFilterType;
1281 ZeroCrossingFilterType::Pointer zeroCrossing =
1282 ZeroCrossingFilterType::New();
1284 const double propagationScaling = atof( crea::wx2std(prop).c_str() );
1286 geodesicActiveContour->SetPropagationScaling( propagationScaling );
1287 geodesicActiveContour->SetCurvatureScaling( 1.0 );
1288 geodesicActiveContour->SetAdvectionScaling( 1.0 );
1290 geodesicActiveContour->SetMaximumRMSError( 0.02 );
1291 int it=atoi( crea::wx2std(iter).c_str() );
1292 geodesicActiveContour->SetNumberOfIterations( it );
1294 smoothing->SetInput( filter2->GetOutput() );
1295 gradientMagnitude->SetInput( smoothing->GetOutput() );
1296 sigmoid->SetInput( gradientMagnitude->GetOutput() );
1297 fastMarching->SetInput( sigmoid->GetOutput() );
1298 geodesicActiveContour->SetInput( fastMarching->GetOutput() );
1299 geodesicActiveContour->SetFeatureImage( sigmoid->GetOutput() );
1301 zeroCrossing->SetInput( geodesicActiveContour->GetOutput() );
1302 //thresholder->SetInput( zeroCrossing->GetOutput() );
1303 thresholder->SetInput( geodesicActiveContour->GetOutput() );
1304 connector2->SetInput( thresholder->GetOutput() );
1307 smoothing->SetTimeStep( 0.125 );
1308 smoothing->SetNumberOfIterations( 5 );
1309 smoothing->SetConductanceParameter( 9.0 );
1312 const double sigma = atof( crea::wx2std(sigm).c_str() );
1313 gradientMagnitude->SetSigma( sigma );
1315 const double alpha = atof( crea::wx2std(alf).c_str() );
1316 const double beta = atof( crea::wx2std(bet).c_str() );
1318 sigmoid->SetAlpha( alpha );
1319 sigmoid->SetBeta( beta );
1321 typedef FastMarchingFilterType::NodeContainer NodeContainer;
1322 typedef FastMarchingFilterType::NodeType NodeType;
1324 NodeContainer::Pointer seeds = NodeContainer::New();
1326 InternalImageType::IndexType seedPosition;
1327 seedPosition[0] = x;
1328 seedPosition[1] = y;
1330 const double initialDistance = atof( crea::wx2std(distanc).c_str() );
1334 const double seedValue = - initialDistance;
1336 node.SetValue( seedValue );
1337 node.SetIndex( seedPosition );
1339 seeds->Initialize();
1340 seeds->InsertElement( 0, node );
1342 fastMarching->SetTrialPoints( seeds );
1344 fastMarching->SetSpeedConstant( 1.0 );
1346 fastMarching->SetOutputSize(
1347 connector->GetOutput()->GetBufferedRegion().GetSize() );
1349 fastMarching->SetStoppingValue( 800 );
1353 connector2->Update();
1354 vtkImageData *idata = connector2->GetOutput();
1356 vtkMarchingContourFilter* cntVTK = vtkMarchingContourFilter::New( );
1358 cntVTK->SetInput( idata );
1360 cntVTK->SetNumberOfContours( 1 );
1361 cntVTK->SetValue( 0, 255 );
1363 cntVTK->UpdateInformation();
1365 vtkCleanPolyData* cpd = vtkCleanPolyData::New( );
1366 cpd->SetInput( cntVTK->GetOutput( ) );
1368 cpd->UpdateInformation();
1370 vtkPolyDataConnectivityFilter* conn = vtkPolyDataConnectivityFilter::New( );
1371 conn->SetExtractionModeToLargestRegion( );
1372 conn->SetInput( cpd->GetOutput( ) );
1374 conn->UpdateInformation();
1376 vtkStripper* vtkstripper = vtkStripper::New( );
1377 vtkstripper->SetInput( conn->GetOutput() );
1378 vtkstripper->Update();
1379 vtkstripper->UpdateInformation();
1382 vtkPolyData* polyDataResult = cntVTK->GetOutput();
1383 //std::cout<<"Points "<<polyDataResult->GetNumberOfPoints()<<std::endl;
1384 polyDataResult->Update( );
1385 polyDataResult->UpdateInformation();
1390 myfile.open ("C:/Creatis/example.txt");
1392 polyDataResult->Print(myfile);
1393 myfile << "-------------------------------------\n";
1394 polyDataResult->GetLines()->Print(myfile);
1402 //--Calculating control points
1404 std::vector<double> vecX;
1405 std::vector<double> vecY;
1406 std::vector<double> vecXo;
1407 std::vector<double> vecYo;
1408 std::vector<double>::iterator vecXoi;
1409 std::vector<double>::iterator vecYoi;
1410 std::vector<double> vecZ;
1412 std::vector<double> vecCtrlPointX;
1413 std::vector<double> vecCtrlPointY;
1414 std::vector<double> vecCtrlPointZ;
1420 int ii,size=polyDataResult->GetNumberOfPoints();
1422 myfile.open ("C:/Creatis/example2.txt");
1424 size=polyDataResult->GetNumberOfPoints();
1425 for (ii=0;ii<size;ii++)
1432 p = polyDataResult->GetPoint(ii);
1435 /*if(fabs(yAct-y)>20)
1437 if((xAct-x)>1 || (xAct-x)<-1)
1439 vecX.push_back( p[0] );
1440 vecY.push_back( p[1] );
1441 myfile <<p[0]<<","<<p[1]<<"\n";
1442 std::cout<<" x Anterior "<<xAct<<" x actual "<<x<<std::endl;
1443 std::cout<<" y Anterior "<<yAct<<" y actual "<<y<<std::endl;
1444 std::cout<<" x "<<p[0]<<" y "<<p[1]<<std::endl;
1445 vecZ.push_back( 900 );
1451 vecXo.push_back(p[0]);
1452 vecYo.push_back(p[1]);
1456 else*/ if(fabs(xAct-x)>11)
1458 vecXo.push_back(p[0]);
1459 vecYo.push_back(p[1]);
1463 vecX.push_back( p[0] );
1464 myfile <<p[0]<<","<<p[1]<<"\n";
1465 //std::cout<<" x Anterior "<<xAct<<" x actual "<<x<<std::endl;
1466 //std::cout<<" y Anterior "<<yAct<<" y actual "<<y<<std::endl;
1467 //std::cout<<" x "<<p[0]<<" y "<<p[1]<<std::endl;
1468 vecY.push_back( p[1] );
1469 vecZ.push_back( 900 );
1477 while(!vecXo.empty())
1479 vecX.push_back(vecXo.back());
1480 //std::cout<<" x Siguiente "<<vecXo.back();
1482 vecZ.push_back( 900 );
1484 while(!vecYo.empty())
1486 vecY.push_back(vecYo.back());
1491 /*for(int l=0;l<vecX.size();l++)
1495 vecXo.push_back(p[0]);
1496 vecYo.push_back(p[1]);
1507 ExtractControlPoints2D *extractcontrolpoints2d = new ExtractControlPoints2D();
1509 extractcontrolpoints2d->SetContour( &vecX , &vecY , &vecZ );
1513 extractcontrolpoints2d->GetInitialControlPoints( &vecCtrlPointX , &vecCtrlPointY , &vecCtrlPointZ );
1515 else if (method==1){
1516 extractcontrolpoints2d->GetControlPoints( &vecCtrlPointX , &vecCtrlPointY , &vecCtrlPointZ );
1518 else if (method==2){
1519 extractcontrolpoints2d->SetSamplingControlPoints( 15 );
1520 extractcontrolpoints2d->GetSamplingControlPoints( &vecCtrlPointX , &vecCtrlPointY , &vecCtrlPointZ );
1522 //--Adding contour to the system
1524 std::vector<int> actualInstantVector;
1525 _instantPanel->getInstant( actualInstantVector );
1526 actualInstantVector[1]=z;
1528 int j,sizeCtrPt = vecCtrlPointX.size();
1530 manualContourModel *manModelContour = kernelManager->factoryManualContourModel( typeofcontour );
1531 manModelContour->SetNumberOfPointsSpline( ((sizeCtrPt/100)+1)*100 );
1533 for (j=0 ; j<sizeCtrPt ; j++)
1535 manModelContour->AddPoint( vecCtrlPointX[j] , vecCtrlPointY[j] , vecCtrlPointZ[j] );
1537 std::string theName;
1538 //theName = _modelManager->createOutline( manModelContour, actualInstantVector );
1539 theName = kernelManager->createOutline( manModelContour, actualInstantVector );
1540 bool addedModel = theName.compare("") != 0;
1543 double spc[3];//Si no hay imagen pero hay contornos que spacing se pone por default
1544 _theViewPanel->getSpacing(spc);
1545 //Adding the manualContourControler to interface objects structure
1546 //Adding the manualViewContour to interface objects structure
1547 //_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.
1548 _theViewPanel->configureViewControlTo(theName, manModelContour, spc, typeofcontour);
1549 //_theViewPanel->getSceneManager()->configureViewControlTo( theName, manModelContour,spc, typeofcontour ) ;
1555 WriterType::Pointer writer = WriterType::New();
1556 CastFilterType3::Pointer caster = CastFilterType3::New();
1558 caster->SetInput( gradientMagnitude->GetOutput() );
1559 writer->SetInput( caster->GetOutput() );
1560 writer->SetFileName("Gradient Magnitude.png");
1561 caster->SetOutputMinimum( 0 );
1562 caster->SetOutputMaximum( 255 );
1565 CastFilterType3::Pointer caster2 = CastFilterType3::New();
1566 WriterType::Pointer writer2 = WriterType::New();
1568 caster2->SetInput( sigmoid->GetOutput() );
1569 writer2->SetInput( caster2->GetOutput() );
1570 writer2->SetFileName("Sigmoid.png");
1571 caster2->SetOutputMinimum( 0 );
1572 caster2->SetOutputMaximum( 255 );
1575 CastFilterType3::Pointer caster3 = CastFilterType3::New();
1576 WriterType::Pointer writer3 = WriterType::New();
1578 caster3->SetInput( fastMarching->GetOutput() );
1579 writer3->SetInput( caster3->GetOutput() );
1580 writer3->SetFileName("FastMarching.bmp");
1581 caster3->SetOutputMinimum( 0 );
1582 caster3->SetOutputMaximum( 255 );
1585 CastFilterType3::Pointer caster4 = CastFilterType3::New();
1586 WriterType::Pointer writer4 = WriterType::New();
1588 caster4->SetInput( geodesicActiveContour->GetOutput() );
1589 writer4->SetInput( caster4->GetOutput() );
1590 writer4->SetFileName("GeodesicActiveContour.png");
1591 caster4->SetOutputMinimum( 0 );
1592 caster4->SetOutputMaximum( 255 );
1595 CastFilterType3::Pointer caster5 = CastFilterType3::New();
1596 WriterType::Pointer writer5 = WriterType::New();
1598 caster5->SetInput( zeroCrossing->GetOutput() );
1599 writer5->SetInput( caster5->GetOutput() );
1600 writer5->SetFileName("ZeroCrossing.bmp");
1601 caster5->SetOutputMinimum( 0 );
1602 caster5->SetOutputMaximum( 255 );
1605 catch( itk::ExceptionObject & excep )
1607 std::cerr << "Exception caught !" << std::endl;
1608 std::cerr << excep << std::endl;
1612 void wxContourMainFrame::onSegmentationOneSlice(int isovalue,int sampling,int method){
1614 //JCP 20-10-08 Undo redo implementation
1616 //JCP 20-10-08 Undo redo implementation
1619 int x = _theViewPanel->GetX();
1620 int y = _theViewPanel->GetY();
1621 int z = _theViewPanel->GetZ();
1622 SegmentationOneSlice( x,y,z,isovalue, sampling, method );
1627 void wxContourMainFrame::SegmentationOneSlice( int x, int y, int z, int isovalue, int sampling, int method )
1629 int typeofcontour = 1;
1630 //--Extracting Contour
1631 //vtkImageData *imagedata = _theViewPanel->getSceneManager()->GetImageData();
1632 vtkImageData *imagedata = getImageData();
1633 // double *range = imagedata->GetScalarRange();
1636 vtkImageReslice *imageReslice = vtkImageReslice::New();
1639 // imagedata->GetSpacing(spc);
1644 imageReslice->SetInput( imagedata );
1645 imageReslice->SetInformationInput(imagedata);
1646 imageReslice->SetResliceAxesDirectionCosines(1,0,0, 0,1,0 ,0,0,1);
1647 imageReslice->SetResliceAxesOrigin(0,0,z);
1648 imageReslice->SetOutputDimensionality(2);
1649 imageReslice->SetInterpolationModeToLinear();
1651 imagedata = imageReslice->GetOutput();
1652 imagedata->Update();
1653 imagedata->UpdateInformation();
1655 vtkContourFilter* cntVTK = vtkContourFilter::New( );
1656 cntVTK->SetInput( imagedata );
1658 cntVTK->SetNumberOfContours( 1 );
1659 //cntVTK->SetValue( 0, vmin );
1660 // cntVTK->SetValue( 0, (range[1]*thr/100) );
1661 cntVTK->SetValue( 1, isovalue );
1662 // cntVTK->SetValue( 1, vmax );
1664 cntVTK->UpdateInformation();
1666 vtkCleanPolyData* cpd = vtkCleanPolyData::New( );
1667 cpd->SetInput( cntVTK->GetOutput( ) );
1668 cpd->ConvertLinesToPointsOff( );
1670 cpd->UpdateInformation();
1672 vtkPolyDataConnectivityFilter* conn = vtkPolyDataConnectivityFilter::New( );
1673 conn->SetExtractionModeToClosestPointRegion( );
1674 //conn->SetMaxRecursionDepth( 3000 );
1676 conn->SetInput( cpd->GetOutput( ) );
1678 conn->SetClosestPoint( x, y, 0 );
1680 conn->UpdateInformation();
1682 vtkCleanPolyData* cpd2 = vtkCleanPolyData::New( );
1683 cpd2->SetInput( conn->GetOutput( ) );
1685 cpd2->UpdateInformation();
1687 vtkStripper* vtkstripper = vtkStripper::New( );
1688 vtkstripper->SetInput( cpd2->GetOutput() );
1689 vtkstripper->Update();
1690 vtkstripper->UpdateInformation();
1693 vtkPolyData* polyDataResult = vtkstripper->GetOutput();
1695 polyDataResult->Update( );
1696 polyDataResult->UpdateInformation();
1700 myfile.open ("c:/temp/example.txt");
1702 polyDataResult->Print(myfile);
1703 myfile << "-------------------------------------\n";
1704 polyDataResult->GetLines()->Print(myfile);
1714 //--Calculating control points
1716 std::vector<double> vecX;
1717 std::vector<double> vecY;
1718 std::vector<double> vecZ;
1720 std::vector<double> vecCtrlPointX;
1721 std::vector<double> vecCtrlPointY;
1722 std::vector<double> vecCtrlPointZ;
1726 int ii,size=polyDataResult->GetNumberOfPoints();
1728 for (ii=1;ii<=size;ii++)
1730 id = polyDataResult->GetLines()->GetData()->GetValue(ii);
1731 p = polyDataResult->GetPoint(id);
1734 vecX.push_back( p[0] );
1735 vecY.push_back( p[1] );
1736 vecZ.push_back( 900 );
1737 // vecZ.push_back( p[2] );
1741 ExtractControlPoints2D *extractcontrolpoints2d = new ExtractControlPoints2D();
1742 extractcontrolpoints2d->SetContour( &vecX , &vecY , &vecZ );
1745 /*if (methodRadiobox->GetSelection()==0){
1746 extractcontrolpoints2d->GetInitialControlPoints( &vecCtrlPointX , &vecCtrlPointY , &vecCtrlPointZ );
1748 if (methodRadiobox->GetSelection()==1){
1749 extractcontrolpoints2d->GetControlPoints( &vecCtrlPointX , &vecCtrlPointY , &vecCtrlPointZ );
1751 if (methodRadiobox->GetSelection()==2){
1752 extractcontrolpoints2d->SetSamplingControlPoints( sampling );
1753 extractcontrolpoints2d->GetSamplingControlPoints( &vecCtrlPointX , &vecCtrlPointY , &vecCtrlPointZ );
1757 extractcontrolpoints2d->GetInitialControlPoints( &vecCtrlPointX , &vecCtrlPointY , &vecCtrlPointZ );
1759 else if (method==1){
1760 extractcontrolpoints2d->GetControlPoints( &vecCtrlPointX , &vecCtrlPointY , &vecCtrlPointZ );
1762 else if (method==2){
1763 extractcontrolpoints2d->SetSamplingControlPoints( sampling );
1764 extractcontrolpoints2d->GetSamplingControlPoints( &vecCtrlPointX , &vecCtrlPointY , &vecCtrlPointZ );
1767 //--Adding contour to the system
1769 std::vector<int> actualInstantVector;
1770 _instantPanel->getInstant( actualInstantVector );
1771 actualInstantVector[1]=z;
1773 int j,sizeCtrPt = vecCtrlPointX.size();
1774 manualContourModel *manModelContour = kernelManager->factoryManualContourModel( typeofcontour );
1775 manModelContour->SetNumberOfPointsSpline( ((sizeCtrPt/100)+1)*100 );
1777 for (j=0 ; j<sizeCtrPt ; j++)
1779 manModelContour->AddPoint( vecCtrlPointX[j] , vecCtrlPointY[j] , vecCtrlPointZ[j] );
1781 std::string theName;
1782 //theName = _modelManager->createOutline( manModelContour, actualInstantVector );
1783 theName = kernelManager->createOutline( manModelContour, actualInstantVector );
1784 bool addedModel = theName.compare("") != 0;
1787 double spc[3];//Si no hay imagen pero hay contornos que spacing se pone por default
1788 _theViewPanel->getSpacing(spc);
1789 //Adding the manualContourControler to interface objects structure
1790 //Adding the manualViewContour to interface objects structure
1791 //_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.
1792 _theViewPanel->configureViewControlTo(theName, manModelContour, spc, typeofcontour);
1793 //_theViewPanel->getSceneManager()->configureViewControlTo( theName, manModelContour,spc, typeofcontour ) ;
1797 int wxContourMainFrame::GetImageDataSizeZ(){
1798 return _theViewPanel->GetImageDataSizeZ();
1801 void wxContourMainFrame::GetImageDataRange(double *range){
1802 _theViewPanel->GetImageDataRange(range);
1805 void wxContourMainFrame::onSegmentationAllSlice(int minZ,int maxZ,int isovalue,int sampling,int method){
1806 //JCP 20-10-08 Undo redo implementation
1808 //JCP 20-10-08 Undo redo implementation
1811 int x = _theViewPanel->GetX();
1812 int y = _theViewPanel->GetY();
1816 double totalZ = maxZ-minZ+1;
1817 for( z=minZ ; z<=maxZ ; z++ )
1819 porcent = 100.0* (z-minZ)/totalZ;
1820 tmpString.Printf(_T(" %d %c %d/%d %d"), (int)porcent , 37 , z-minZ+1, (int)totalZ,z );
1821 interfMainPanel::getInstance()->setLabelSegmentationPanelVTK(tmpString);
1822 //_staticTextSegmentation->SetLabel(tmpString);
1823 SegmentationOneSlice( x,y,z,isovalue, sampling,method );
1825 interfMainPanel::getInstance()->setLabelSegmentationPanelVTK(_T(" "));
1830 //Creates a reference line to be used as the axis of the mirroring
1831 void wxContourMainFrame::referenceLine()
1833 if (_refLineControl==NULL)
1838 vtkImageData *vtkimagedata = _theViewPanel->getImageData();
1839 vtkimagedata->GetSpacing(spc);
1841 wxVtkBaseView * viewer2D = _theViewPanel->getWxVtkBaseView();
1843 _refLineControl = new manualLineControler();
1844 _refLineModel = new manualContourModelLine();
1845 _refLineView = new manualViewLine();
1846 _refLineView->SetModel( _refLineModel );
1847 _refLineView->SetWxVtkBaseView( viewer2D );
1848 _refLineView->SetRange( 2 );
1849 _refLineView->SetZ( 1200 );
1851 _refLineView->SetSpacing(spc);
1853 _refLineView->SetColorNormalContour(0, 0, 1);
1854 _refLineView->SetColorEditContour(0, 0.5, 0.5);
1855 _refLineView->SetWidthLine(4);
1857 _refLineControl->SetModelView( _refLineModel , _refLineView );
1858 vtkInteractorStyleBaseView* style = (vtkInteractorStyleBaseView*)viewer2D->GetInteractorStyleBaseView();
1859 style->AddInteractorStyleMaracas( _refLineControl );
1860 _refLineModel->SetCloseContour(false);
1861 _refLineControl->CreateNewManualContour();
1863 //AD: Inicializar el mirroring con una linea ya pintada
1865 double z = _refLineControl->GetZ();
1868 image->GetDimensions(imageDim);
1869 double x = (double) imageDim[0]/2;
1870 double y1 = (double) (imageDim[1]/2)+15;
1871 double y2 = (double) (imageDim[1]/2)-15;
1873 _refLineControl->AddPoint(x,y1,z);
1874 _refLineControl->AddPoint(x,y2,z);
1875 _refLineControl->SetCompleteCreation(true);
1877 _refLineModel->AddPoint(x,y1,z);
1878 _refLineModel->AddPoint(x,y2,z);
1879 _refLineModel->UpdateSpline();
1881 _refLineView->UpdateViewPoint(0);
1882 _refLineView->UpdateViewPoint(1);
1885 _refLineControl->SetActive(true);
1886 _refLineView->RefreshContour();
1890 //Hides the referenceLine
1891 void wxContourMainFrame::refLineHide()
1893 if (_refLineControl!=NULL)
1895 if (_refLineControl->GetActive())
1897 _refLineView->RemoveCompleteContourActor();
1898 _refLineControl->SetEditable(false);
1899 _refLineControl->SetActive(false);
1906 //Shows the referenceLine
1907 void wxContourMainFrame::refLineShow()
1909 if (_refLineControl!=NULL)
1911 if (_refLineControl->GetActive()==false)
1913 wxVtkBaseView * viewer2D = _theViewPanel->getWxVtkBaseView();
1915 _refLineView->SetModel( _refLineModel );
1916 _refLineView->SetWxVtkBaseView( viewer2D );
1917 _refLineView->SetRange( 2 );
1918 _refLineView->SetZ( 1200 );
1920 _refLineControl->SetModelView( _refLineModel , _refLineView );
1921 vtkInteractorStyleBaseView* style = (vtkInteractorStyleBaseView*)viewer2D->GetInteractorStyleBaseView();
1922 style->AddInteractorStyleMaracas( _refLineControl );
1923 _refLineControl->CreateNewManualContour();
1924 _refLineControl->SetActive(true);
1925 _refLineView->RefreshContour();
1932 void wxContourMainFrame::refLineChangeWidth(int width)
1934 _refLineView->SetWidthLine(width);
1935 _refLineView->RefreshContour();
1941 void wxContourMainFrame::onMirror()
1944 std::vector<std::string> currentSelection = _theViewPanel->getSelectedObjects();
1945 std::vector<std::string> filterCurrentSelection;
1947 std::vector<int> tempVector;
1948 _instantPanel->getInstant( tempVector );
1949 _performingOperation->reset();
1950 _performingOperation->setStartCommand( COPY );
1951 _performingOperation->setStartOperationInstantVector( tempVector );
1952 _performingOperation->setKeyNamesOperationElems( currentSelection );
1954 char theStartCommand = _performingOperation->getStartCommand();
1955 if ( theStartCommand == COPY )
1957 //JCP 20-10-08 Undo redo implementation
1959 //JCP 20-10-08 Undo redo implementation
1960 std::vector<int> tempVector;
1961 _instantPanel->getInstant( tempVector );
1962 _performingOperation->setEndOperationInstantVector ( tempVector );
1963 std::vector<std::string> elems = _performingOperation->getKeyNamesOperationElems();
1964 int i,size = elems.size();
1965 for( i=0; i<size; i++ )
1967 createMirrorContourOf( elems[i], tempVector, i>0 );
1971 //deleteContour( _refName );
1975 void wxContourMainFrame::onThreshold()
1977 int z = _theViewPanel->GetZ();
1980 vtkImageData * img = getImageData();
1981 img->GetScalarRange(range);
1983 int minTot = floor (range[0]);
1984 int maxTot = ceil (range[1]);
1987 _pannew->onThresholdInstantChange(minMax);
1988 int minVal = floor (minMax[0]);
1989 int maxVal = floor (minMax[1]);
1993 if (_imageReslicer==NULL)
1995 _imageReslicer = vtkImageReslice::New();
1996 _imageReslicer->SetInput( img );
1997 _imageReslicer->SetInformationInput(img);
1998 _imageReslicer->SetResliceAxesDirectionCosines(1,0,0, 0,1,0 ,0,0,1);
1999 _imageReslicer->SetOutputDimensionality(2);
2000 _imageReslicer->SetInterpolationModeToLinear();
2003 _imageReslicer->SetResliceAxesOrigin(0,0,z);
2005 img = _imageReslicer->GetOutput();
2007 img->UpdateInformation();
2009 wxVtkBaseView * baseView = _theViewPanel->getWxVtkBaseView();
2011 if (_thresholdTable==NULL)
2014 _thresholdTable = vtkLookupTable::New();
2015 _thresholdTable->SetNumberOfTableValues(maxTot+1);
2016 _thresholdTable->SetTableRange(range);
2017 _thresholdTable->SetAlphaRange(0, 1);
2018 _thresholdTable->SetValueRange(0, 1);
2019 _thresholdTable->SetSaturationRange(0, 0);
2020 _thresholdTable->SetRampToLinear( );
2023 //Assign a fake color for the upper image, and set the white as transparent
2025 for(i = minTot; i <= maxTot; i++)
2027 if( i >= minVal && i <= maxVal )
2029 _thresholdTable->SetTableValue(i, 1.0, 0.0, 0.0, 1);
2031 else if( i >= minTot && i < minVal )
2033 _thresholdTable->SetTableValue(i, 1.0, 1.0, 1.0, 0); //transparent
2035 else if( i > maxVal && i < maxTot )
2037 _thresholdTable->SetTableValue(i, 1.0, 1.0, 1.0, 0); //transparent
2041 _thresholdTable->SetTableValue(i, 1.0, 1.0, 1.0, 0); //transparent
2044 _thresholdTable->Build( );
2046 if (_thresholdMapper==NULL)
2048 _thresholdMapper = vtkImageMapToColors::New( );
2051 _thresholdMapper->SetLookupTable( _thresholdTable );
2052 _thresholdMapper->SetInput( img );
2054 if (_thresholdActor==NULL)
2056 _thresholdActor = vtkImageActor::New( );
2057 _thresholdActor->SetOpacity( 0.6 );
2058 _thresholdActor->InterpolateOn( );
2059 _thresholdActor->SetPosition( 0,0, 900-1 );
2062 _thresholdActor->SetInput( _thresholdMapper->GetOutput() );
2064 baseView->GetRenderer()->AddActor( _thresholdActor );
2065 _actorPresent = true;
2070 _imageReslicer->SetResliceAxesOrigin(0,0,z);
2071 img = _imageReslicer->GetOutput();
2073 img->UpdateInformation();
2075 //Assign a fake color for the upper image, and set the white as transparent
2077 for(i = minTot; i <= maxTot; i++)
2079 if( i >= minVal && i <= maxVal )
2081 _thresholdTable->SetTableValue(i, 1.0, 0.0, 0.0, 1);
2083 else if( i >= minTot && i < minVal )
2085 _thresholdTable->SetTableValue(i, 1.0, 1.0, 1.0, 0); //transparent
2087 else if( i > maxVal && i < maxTot )
2089 _thresholdTable->SetTableValue(i, 1.0, 1.0, 1.0, 0); //transparent
2093 _thresholdTable->SetTableValue(i, 1.0, 1.0, 1.0, 0); //transparent
2097 _thresholdTable->Build( );
2098 _thresholdMapper->SetLookupTable( _thresholdTable );
2099 _thresholdMapper->SetInput( img );
2100 _thresholdActor->SetInput( _thresholdMapper->GetOutput() );
2103 vtkImageViewer2* viewer = vtkImageViewer2::New();
2104 viewer->SetInput( upperImageActor->GetInput() );
2105 viewer->SetColorLevel((range[1]-range[0])/2);
2106 viewer->SetColorWindow(range[1]);
2107 viewer->GetRenderer()->AddActor( upperImageActor );
2110 _theViewPanel->RefreshInterface();
2114 void wxContourMainFrame::onThresholdChange()
2122 void wxContourMainFrame::onThresholdInterpolation(bool interpolate)
2124 if (_thresholdActor!=NULL)
2128 _thresholdActor->InterpolateOn( );
2133 _thresholdActor->InterpolateOff( );
2136 _theViewPanel->RefreshInterface();
2140 void wxContourMainFrame::onThresholdChangeOpacity (int opacity)
2144 _thresholdActor->SetOpacity(opacity*0.1);
2147 _theViewPanel->RefreshInterface();
2150 void wxContourMainFrame::onThresholdRemove()
2154 wxVtkBaseView * baseView = _theViewPanel->getWxVtkBaseView();
2155 baseView->GetRenderer()->RemoveActor( _thresholdActor );
2156 _actorPresent = false;
2159 _theViewPanel->RefreshInterface();
2162 void wxContourMainFrame::showAxis(bool show)
2164 _theViewPanel->SetVisibleAxis(show);
2165 _theViewPanel->Refresh();
2169 void wxContourMainFrame::onRigidPressed(){
2170 std::vector<std::string> currentSelection = _theViewPanel->getSelectedObjects();
2171 int elementsSelected = currentSelection.size();
2173 if ( elementsSelected >= 1 ){
2174 //JCP 20-10-08 Undo redo implementation
2176 //JCP 20-10-08 Undo redo implementation
2178 std::vector<int> tempVector;
2179 _instantPanel->getInstant( tempVector );
2180 Instant instant(&tempVector);
2182 int i , size=currentSelection.size();
2183 for ( i=0 ; i<size ; i++ )
2185 kernelManager->changeContourOfManager(currentSelection[i], &instant);
2190 void wxContourMainFrame::onWidthOfContour(double width){
2192 _theViewPanel->removeSceneContours();
2193 _theViewPanel->SetWidthContour(width);
2195 //_theViewPanel->getSceneManager()->SetWidthContour( width );
2200 int wxContourMainFrame::getColorWindow()
2204 vtkImageData * img = getImageData();
2205 img->GetScalarRange(range);
2207 std::cout<<"Val 1: "<<range[0]<<" Val 2: "<<range[1]<<std::endl;
2209 return (int)range[1];
2211 return _theViewPanel->getColorWindow();
2214 int wxContourMainFrame::getWindowLevel()
2218 vtkImageData * img = getImageData();
2219 img->GetScalarRange(range);
2221 std::cout<<"Val 1: "<<range[0]<<" Val 2: "<<range[1]<<std::endl;
2223 return (int)range[1];
2225 return _theViewPanel->getWindowLevel();
2228 void wxContourMainFrame::onBrigthnessColorWindowLevel(int colorwindow,int windowlevel){
2229 _theViewPanel->onBrigthnessColorWindowLevel(colorwindow, windowlevel);
2234 void wxContourMainFrame::onInterpolation(bool interpolate){
2235 _theViewPanel->onInterpolation(interpolate);
2239 void wxContourMainFrame::onChangeInstant(std::string name,int actual){
2240 _instantPanel->setConceptValue( name, actual );
2243 void wxContourMainFrame::resetAppend(){
2244 kernelManager->resetAppend();
2248 void wxContourMainFrame::onSpreadAdd(){
2249 std::vector<double> vecX;
2250 std::vector<double> vecY;
2251 std::vector<double> vecZ;
2252 _theViewPanel->GetPointsOfActualContour(&vecX , &vecY , &vecZ );
2254 std::vector<int> tempVector;
2255 _instantPanel->getInstant( tempVector );
2257 std::string val = kernelManager->onSpreadAdd(&vecX , &vecY , &vecZ, tempVector);
2259 interfMainPanel::getInstance()->appendStringSpread(val);
2263 void wxContourMainFrame::onSpreadGo(int type){
2265 //JCP 20-10-08 Undo redo implementation
2267 //JCP 20-10-08 Undo redo implementation
2270 std::vector<double> vecCtrlPointX;
2271 std::vector<double> vecCtrlPointY;
2272 std::vector<double> vecCtrlPointZ;
2276 std::vector<int> tempVector;
2277 _instantPanel->getInstant( tempVector );
2280 kernelManager->getMaxMinZ(&minZ,&maxZ);
2281 //JSTG_16-07-08_----------------------------------------------------------------
2282 //_contourPropagation->setInterpolationNumber(maxZ-minZ+1);
2283 kernelManager->CalculeSplinePropagation();
2285 double totalZ = maxZ-minZ+1;
2288 //--------------------------------------------------------------------
2289 for ( z=(int)minZ ; z<=(int)maxZ ; z++ )
2291 porcent = 100.0* (z-minZ)/totalZ;
2292 int numero = (int)(z-minZ+1)/(int)totalZ;
2293 std::string stringtemp = " "+kernelManager->intToString(porcent)+"% "+kernelManager->intToString(numero)+" "+kernelManager->intToString(z);
2295 interfMainPanel::getInstance()->setStringSpread(stringtemp);
2297 int typeofcontour = 1;
2298 std::string theName;
2299 manualContourModel* manModelContour = kernelManager->GetPoints(z, type, &vecCtrlPointX,&vecCtrlPointY,&vecCtrlPointZ, theName,typeofcontour, tempVector);
2301 if( manModelContour!=NULL ){
2302 double spc[3];//Si no hay imagen pero hay contornos que spacing se pone por default
2303 this->_theViewPanel->getSpacing(spc);
2304 //Adding the manualContourControler to interface objects structure
2305 //Adding the manualViewContour to interface objects structure
2306 //_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.
2307 _theViewPanel->configureViewControlTo( theName, manModelContour,spc,typeofcontour ) ;
2312 int numero = (int)(z-minZ+1)/(int)totalZ;
2313 std::string stringtemp = " "+kernelManager->intToString(porcent)+"% "+kernelManager->intToString(numero)+" "+kernelManager->intToString(z);
2315 interfMainPanel::getInstance()->setStringSpread(stringtemp);
2317 //RefreshInterface();
2320 void wxContourMainFrame::getInstantVector(std::vector<int>& tempVector){
2324 std::vector<std::string> wxContourMainFrame::getOutlinesName(int slide){
2325 std::vector<int> tempVector;
2326 _instantPanel->getInstant(tempVector);
2327 //Asignation of slide number should be different ex by name
2328 tempVector[1]=slide;
2329 return kernelManager->getOutlinesNameAtInstant(tempVector);
2332 void wxContourMainFrame::onInformationContourLabels(int typeContourGroup,int selection,int minimumZ,int maximumZ)
2334 int maxContourGroup = 0;
2336 ContourExtractData *contourextractdata = new ContourExtractData();
2338 contourextractdata ->SetTypeOperation( typeContourGroup % 3 );
2340 std::vector<manualContourModel*> lstManConMod;
2341 std::vector<manualContourModel*> lstManConModTmp;
2342 std::vector<manualContourModel*> lstManConModExp;
2343 std::vector<double> pLstValue;
2344 std::vector<double> pLstValuePosX;
2345 std::vector<double> pLstValuePosY;
2346 std::vector<double> pLstValuePosZ;
2349 int resultGrayRangeCount;
2352 double resultAverage;
2353 double resultStandardeviation;
2355 std::vector<int> tempVector;
2356 _instantPanel->getInstant( tempVector );
2358 vtkImageData *imagedata = _theViewPanel->getImageData();
2359 int sizeZ = _theViewPanel->GetImageDataSizeZ();
2361 int ii,sizeLstContourThings;
2371 if (selection==0 ) // actual slice
2373 std::vector<int> tempVector;
2374 _instantPanel->getInstant( tempVector );
2375 int actualSlice = tempVector[1];
2379 else if (selection==2 ) // All slices
2384 else if (selection==1 ) // slice range
2391 totalZ = maxZ-minZ+1;
2392 contourextractdata->SetImage( imagedata);
2395 for ( z=minZ ; z<=maxZ ; z++ )
2398 porcent = 100.0* (z-minZ)/totalZ;
2399 tmpString.Printf(_T(" %d %c %d/%d %d"), (int)porcent , 37 , z-minZ+1, (int)totalZ ,z);
2401 interfMainPanel::getInstance()->setStringInfoPanel(tmpString);
2402 //_staticTextInformation->SetLabel(tmpString);
2404 //Extraction data from contours of each slice
2405 contourextractdata->SetZtoBeAnalys(z);
2408 Instant instant(&tempVector);
2409 std::vector<ContourThing**> lstContourThings = kernelManager->getOutlinesAtInstant( &instant );
2410 sizeLstContourThings = lstContourThings.size();
2412 lstManConMod.clear();
2413 for (ii=0 ; ii<sizeLstContourThings ; ii++)
2415 ContourThing **contourthing = lstContourThings[ii];
2416 lstManConMod.push_back( (*contourthing)->getModel() );
2418 lstManConModExp = kernelManager->ExploseEachModel( lstManConMod );
2421 wxString tempString;
2422 tempString.Printf(_T("%d - %d"),z, sizeLstContourThings);
2423 interfMainPanel::getInstance()->setRowLabelInfoPanel(z, tempString);
2424 //_grid->SetRowLabelValue(z, tempString );
2426 int iContourGroup,sizeContourGroup;
2427 if (typeContourGroup==3) // contour separete
2429 sizeContourGroup=lstManConModExp.size();
2430 if ( maxContourGroup<sizeContourGroup )
2432 maxContourGroup=sizeContourGroup;
2434 } else { // contour AND OR XOR
2443 for( iContourGroup=0 ; iContourGroup<sizeContourGroup ; iContourGroup++ ){
2444 lstManConModTmp.clear();
2445 if (typeContourGroup==3) // contour separete
2447 lstManConModTmp.push_back( lstManConModExp[iContourGroup]);
2448 } else { // contour AND OR XOR
2449 lstManConModTmp = lstManConModExp;
2452 contourextractdata->SetLstManualContourModel( lstManConModTmp );
2455 pLstValuePosX.clear();
2456 pLstValuePosY.clear();
2457 pLstValuePosZ.clear();
2458 contourextractdata->GetValuesInsideCrown( &pLstValue,
2462 // Statistics of each slice.
2463 contourextractdata->Statistics( &pLstValue,
2466 &resultGrayRangeCount,
2471 &resultStandardeviation);
2473 if (interfMainPanel::getInstance()->getNumberColsInformationPanel()<_numberOfVariablesStatistics*(iContourGroup+1) )
2475 interfMainPanel::getInstance()->appendColsInformationPanel(_numberOfVariablesStatistics);
2478 tmpIntA=_numberOfVariablesStatistics*iContourGroup ;
2480 tempString.Printf(_T("%d"),resultSize);
2481 interfMainPanel::getInstance()->setCellValueInfoPanel(z, tmpIntA, tempString);
2483 tempString.Printf(_T("%d"),resultGrayRangeCount);
2484 interfMainPanel::getInstance()->setCellValueInfoPanel(z, tmpIntA+1, tempString);
2486 tempString.Printf(_T("%f"),resultMin);
2487 interfMainPanel::getInstance()->setCellValueInfoPanel(z, tmpIntA+2, tempString);
2489 tempString.Printf(_T("%f"),resultMax);
2490 interfMainPanel::getInstance()->setCellValueInfoPanel(z, tmpIntA+3, tempString);
2492 tempString.Printf(_T("%f"),resultAverage);
2493 interfMainPanel::getInstance()->setCellValueInfoPanel(z, tmpIntA+4, tempString);
2495 tempString.Printf(_T("%f"),resultStandardeviation);
2496 interfMainPanel::getInstance()->setCellValueInfoPanel(z, tmpIntA+5, tempString);
2499 } // for iContourGroup
2503 wxString tmpTitleString;
2505 for ( iTitleGroup=0 ; iTitleGroup<maxContourGroup ; iTitleGroup++ )
2507 tmpIntB =_numberOfVariablesStatistics*iTitleGroup;
2508 tmpTitleString.Printf(_T("%d-Size Data"),iTitleGroup);
2509 interfMainPanel::getInstance()->setColLableInfoPanel(tmpIntB + 0, tmpTitleString);
2511 interfMainPanel::getInstance()->setColLableInfoPanel(tmpIntB + 0, tmpTitleString );
2512 interfMainPanel::getInstance()->setColLableInfoPanel( tmpIntB + 1, _T("Size Range") );
2513 interfMainPanel::getInstance()->setColLableInfoPanel( tmpIntB + 2, _T("Min") );
2514 interfMainPanel::getInstance()->setColLableInfoPanel( tmpIntB + 3, _T("Max") );
2515 interfMainPanel::getInstance()->setColLableInfoPanel( tmpIntB + 4, _T("Average") );
2516 interfMainPanel::getInstance()->setColLableInfoPanel( tmpIntB + 5, _T("St.Dev.") );
2517 interfMainPanel::getInstance()->setColLableInfoPanel( tmpIntB + 6, _T(" ") );
2520 interfMainPanel::getInstance()->setStringInfoPanel( _T("") );
2521 delete contourextractdata;
2525 void wxContourMainFrame::onSaveResults(std::string directory,std::string namefile, std::string filename,
2526 int typeContourGroup, bool XYZValues, bool contourImage, bool statistics)
2530 SaveValuesXYZ( directory , namefile, typeContourGroup );
2535 vtkImageData * mask;
2536 vtkImageData * value;
2537 this->getMaskValue(&mask, &value, typeContourGroup);
2538 this->SaveImageResult( directory , namefile, mask, value);
2543 std::ostringstream name;
2544 name << filename << ".xls";
2547 FILE *pFile=fopen(name.str().c_str(),"w+");
2549 int sizeZ = _theViewPanel->GetImageDataSizeZ();
2552 int i,j,maxX,maxY=sizeZ;
2553 maxX= interfMainPanel::getInstance()->getNumberColsInformationPanel();//this->_grid->GetNumberCols();
2555 int iTitle,sizeTitle = (maxX / _numberOfVariablesStatistics);
2556 for ( iTitle=0; iTitle<sizeTitle ; iTitle++)
2558 // fprintf(pFile,"-- \t %d-Size \t SizeRange \t Min \t Max \t Ave \t StDv \t" , iTitle,tmpString.c_str() );
2559 fprintf(pFile,"-- \t %d-Size \t SizeRange \t Min \t Max \t Ave \t StDv \t" , iTitle );
2561 fprintf(pFile,"\n" );
2565 for ( j=0; j<maxY ; j++)
2567 fprintf(pFile,"%d\t" , j );
2568 for (i=0 ; i<maxX ; i++){
2569 tmpString = interfMainPanel::getInstance()->getCellValue(j, i);//_grid->GetCellValue( j , i );
2570 fprintf(pFile,"%s\t" , (const char *)(tmpString.mb_str()) );
2572 fprintf(pFile,"\n" );
2580 void wxContourMainFrame::SaveValuesXYZ(std::string directory,std::string namefile,int typeContourGroup)
2583 ContourExtractData *contourextractdata = new ContourExtractData();
2584 //int typeContourGroup = this->_radiolstboxContourGroup->GetSelection();
2585 contourextractdata ->SetTypeOperation( typeContourGroup % 3 );
2587 std::vector<manualContourModel*> lstManConMod;
2588 std::vector<manualContourModel*> lstManConModTmp;
2589 std::vector<manualContourModel*> lstManConModExp;
2590 std::vector<double> pLstValue;
2591 std::vector<double> pLstValuePosX;
2592 std::vector<double> pLstValuePosY;
2593 std::vector<double> pLstValuePosZ;
2595 std::vector<int> tempVector;
2596 _instantPanel->getInstant( tempVector );
2598 vtkImageData *imagedata = _theViewPanel->getSceneManager()->GetImageData();
2599 int sizeZ = _theViewPanel->getSceneManager()->GetImageDataSizeZ();
2601 int ii,sizeLstContourThings;
2608 minZ = 0;// _mbarrange->GetStart();
2609 maxZ = sizeZ;//_mbarrange->GetEnd();
2610 totalZ = maxZ-minZ+1;
2612 contourextractdata->SetImage( imagedata);
2615 for ( z=0 ; z<sizeZ ; z++)
2618 porcent = 100.0* (z-minZ)/totalZ;
2620 tmpString.Printf(_T("Saving Values"));
2621 tmpString.Printf(_T(" %d %c %d/%d %d"), (int)porcent , 37 , z-minZ+1, (int)totalZ ,z);
2622 interfMainPanel::getInstance()->setStringInfoPanel(tmpString);
2623 //_staticTextInformation->SetLabel(tmpString);
2626 //Extraction data from contours of each slice
2627 contourextractdata->SetZtoBeAnalys( z);
2630 Instant instant(&tempVector);
2631 std::vector<ContourThing**> lstContourThings = kernelManager->getOutlinesAtInstant(&instant);//this->_modelManager->getOutlinesAtInstant( &instant );
2632 sizeLstContourThings = lstContourThings.size();
2634 lstManConMod.clear();
2635 for (ii=0 ; ii<sizeLstContourThings ; ii++)
2637 ContourThing **contourthing = lstContourThings[ii];
2638 lstManConMod.push_back( (*contourthing)->getModel() );
2640 lstManConModExp = kernelManager->ExploseEachModel( lstManConMod );
2645 int iContourGroup,sizeContourGroup;
2646 if (typeContourGroup==3) // contour separete
2648 sizeContourGroup=lstManConModExp.size();
2649 } else { // contour AND OR XOR
2653 for( iContourGroup=0 ; iContourGroup<sizeContourGroup ; iContourGroup++ ){
2654 lstManConModTmp.clear();
2655 if (typeContourGroup==3) // contour separete
2657 lstManConModTmp.push_back( lstManConModExp[iContourGroup]);
2658 } else { // contour AND OR XOR
2659 lstManConModTmp = lstManConModExp;
2662 contourextractdata->SetLstManualContourModel( lstManConModTmp );
2665 pLstValuePosX.clear();
2666 pLstValuePosY.clear();
2667 pLstValuePosZ.clear();
2668 contourextractdata->GetValuesInsideCrown( &pLstValue,
2673 std::string temp = directory + "/" + namefile + "-slice";
2674 temp = temp + kernelManager->intToString(z) + "-cont" + kernelManager->intToString(iContourGroup);
2675 temp = temp + ".txt";
2677 // LG 14/01/09 : using crea
2678 wxString filename = crea::std2wx(temp);
2679 /*filename.Printf(_T("%s"),directory.c_str());
2680 filename.append(_T("\\"));
2681 filename.append(_T("%s"),namefile.c_str());
2682 filename.append(_T("-slice"));
2683 filename.append(_T("%d"),z);
2684 filename.append(_T("-cont"));
2685 filename.append(_T("%d"),iContourGroup);
2686 filename.append(_T(".txt"));*/
2687 // filename.Printf(temp.c_str());
2691 FILE *pFile=fopen((const char *)filename.mb_str(),"w+");
2692 fprintf(pFile,"value \t x \t y \t z\n" );
2693 int iLstValue,sizeLstValue=pLstValue.size();
2694 for (iLstValue=0 ; iLstValue<sizeLstValue ; iLstValue++ )
2696 fprintf(pFile,"%f\t %f\t %f\t %f\n", (float)pLstValue[iLstValue] , (float)pLstValuePosX[iLstValue], (float)pLstValuePosY[iLstValue], (float)z );
2699 } // for iContourGroup
2701 interfMainPanel::getInstance()->setStringInfoPanel(_T(""));
2702 //_staticTextInformation->SetLabel( _T("") );
2703 delete contourextractdata;
2706 void wxContourMainFrame::getMaskValue(vtkImageData ** mask,vtkImageData ** value,int typeContourGroup){
2708 ContourExtractData *contourextractdata = new ContourExtractData( true );
2709 //int typeContourGroup = this->_radiolstboxContourGroup->GetSelection();
2710 if (typeContourGroup==3)
2714 contourextractdata ->SetTypeOperation( typeContourGroup % 3 );
2716 std::vector<manualContourModel*> lstManConMod;
2717 std::vector<manualContourModel*> lstManConModTmp;
2718 std::vector<manualContourModel*> lstManConModExp;
2720 std::vector<int> tempVector;
2721 _instantPanel->getInstant( tempVector );
2723 vtkImageData *imagedata = _theViewPanel->getImageData();
2724 int sizeZ = _theViewPanel->GetImageDataSizeZ();
2726 int ii,sizeLstContourThings;
2735 minZ = 0;// _mbarrange->GetStart();
2736 maxZ = sizeZ;//_mbarrange->GetEnd();
2737 totalZ = maxZ-minZ+1;
2739 contourextractdata->SetImage( imagedata);
2742 for ( z=0 ; z<sizeZ ; z++)
2745 porcent = 100.0* (z-minZ)/totalZ;
2746 tmpString.Printf(_T("Saving Values"));
2747 tmpString.Printf(_T("%d %c %d/%d %d"), (int)porcent , 37 , z-minZ+1, (int)totalZ ,z);
2748 interfMainPanel::getInstance()->setStringInfoPanel(tmpString);
2750 //Extraction data from contours of each slice
2751 contourextractdata->SetZtoBeAnalys( z);
2754 Instant instant(&tempVector);
2755 std::vector<ContourThing**> lstContourThings = kernelManager->getOutlinesAtInstant( &instant );
2756 sizeLstContourThings = lstContourThings.size();
2758 lstManConMod.clear();
2759 for (ii=0 ; ii<sizeLstContourThings ; ii++)
2761 ContourThing **contourthing = lstContourThings[ii];
2762 lstManConMod.push_back( (*contourthing)->getModel() );
2764 lstManConModExp = kernelManager->ExploseEachModel( lstManConMod );
2767 int iContourGroup,sizeContourGroup;
2768 if (typeContourGroup==3) // contour separete
2770 sizeContourGroup=lstManConModExp.size();
2771 } else { // contour AND OR XOR
2775 for( iContourGroup=0 ; iContourGroup<sizeContourGroup ; iContourGroup++ ){
2776 lstManConModTmp.clear();
2777 if (typeContourGroup==3) // contour separete
2779 lstManConModTmp.push_back( lstManConModExp[iContourGroup]);
2780 } else { // contour AND OR XOR
2781 lstManConModTmp = lstManConModExp;
2784 contourextractdata->SetLstManualContourModel( lstManConModTmp );
2785 contourextractdata->CalculateImageResult(); // with actual Z
2787 } // for iContourGroup
2790 (*value) = contourextractdata->GetVtkImageValueResult();
2791 (*mask) = contourextractdata->GetVtkImageMaskResult();
2792 delete contourextractdata;
2795 void wxContourMainFrame::SaveImageResult(std::string directory,std::string namefile, vtkImageData* mask,vtkImageData* value)
2798 std::string temp = directory + "/" + namefile + "-Value.mhd";
2800 wxString filename = crea::std2wx(temp);
2802 // filename.Printf(_T(temp.c_str()));
2803 //filename.Printf(_T("%s\\%s-Value.mhd",directory.c_str(),namefile.c_str(),z);
2804 /*filename.Printf(_T("%s"),directory.c_str());
2805 filename.append(_T("\\"));
2806 filename.append(_T("%s"),namefile.c_str());
2807 filename.append(_T("-Value.mhd"));*/
2810 vtkMetaImageWriter *writerValueImage = vtkMetaImageWriter::New( );
2811 writerValueImage->SetInput( value );
2812 writerValueImage->SetFileName( (const char *)filename.mb_str() );
2813 writerValueImage->SetFileDimensionality( 3 );
2814 writerValueImage->Write( );
2817 // filename.Printf("%s\\%s-Mask.mhd",directory.c_str(),namefile.c_str(),z);
2818 temp = directory + "/" + namefile + "-Mask.mhd";
2820 // LG 14/01/09 : using crea
2821 filename = crea::std2wx(temp);
2822 // filename.Printf(_T(temp.c_str()));
2824 /*filename.Printf(_T("%s"),directory.c_str());
2825 filename.append(_T("\\"));
2826 filename.append(_T("%s"),namefile.c_str());
2827 filename.append(_T("-Mask.mhd"));*/
2829 vtkMetaImageWriter *writerMaskImage = vtkMetaImageWriter::New( );
2830 writerMaskImage->SetInput( mask );
2831 writerMaskImage->SetFileName( (const char *)filename.mb_str() );
2832 writerMaskImage->SetFileDimensionality( 3 );
2833 writerMaskImage->Write( );
2835 interfMainPanel::getInstance()->setStringInfoPanel( _T("") );
2841 void wxContourMainFrame::onChangeInstantInstantPanel(std::string name,int value, int minshow, int maxshow){
2842 if( name.compare( _theViewPanel->getVerticalConceptName() ) == 0){
2843 _theViewPanel->setActualVertical( value);
2845 else if( name.compare( _theViewPanel->getHorizontalConceptName() ) == 0|| _instantPanel->getIfConceptCheckedAt( name, 0 ) ) {
2846 _theViewPanel->setHorizontalConcept( name, minshow, maxshow, minshow, maxshow, value);
2852 void wxContourMainFrame::onSnakePressed(){
2853 std::vector<double> vecX;
2854 std::vector<double> vecY;
2855 std::vector<double> vecZ;
2856 _theViewPanel->GetPointsOfActualContour( &vecX , &vecY , &vecZ );
2858 if (vecX.size()!=0){
2859 std::vector<int> tempVector;
2860 _instantPanel->getInstant( tempVector );
2861 int i,size=vecZ.size();
2862 int actualSlice = tempVector[1];
2863 for ( i=0 ; i<size ; i++ )
2865 vecZ[i] = actualSlice;
2868 wxDialog* dialog = new wxDialog(this, -1, wxString(_T("Snake")));
2869 wxPanel* panel = new wxPanel(dialog,-1);
2870 // wxStaticText* sttext = new wxStaticText(panel, -1, wxString(_T("Panel para snake")));
2871 new wxStaticText(panel, -1, wxString(_T("Panel para snake")));
2872 dialog->ShowModal();
2877 void wxContourMainFrame::saveFileWithContoursAutomatique(){
2878 std::string filename = kernelManager->getCurrentFileName();
2879 if(filename.compare("")!=0){
2880 saveFileWithContours(filename);
2885 void wxContourMainFrame::ShowToolsPanel(bool show){
2886 _pannew->Show(show);