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)
103 this->setVectImages(images);
108 void wxContourMainFrame::setVectImages(std::vector<vtkImageData*> imgs)
111 #if defined(__GNUC__)
112 std::string str_home(getenv("HOME"));
113 #elif defined(_WIN32)
114 std::string str_home(getenv("USERPROFILE"));
116 std::string strCreaContourDataTmp = str_home + "/.creaContourDataTemp/";
118 std::vector<std::string> conceptNameVect;
119 std::vector<int> conceptSizeVect;
121 notebook = this->createNotebook();
124 kernelManager = new KernelManagerContour( imgs , _datadir+"/data/" , strCreaContourDataTmp );
127 _instantPanel = new wxInstantChooserPanel( notebook, "Instant Chooser", true, false, "c" );
128 _theViewPanel = new wxContourViewPanel( kernelManager->getSourceImage(), notebook );
130 //-------------------------------------------------------------
131 kernelManager->getConceptsInformation(conceptNameVect, conceptSizeVect);
132 _instantPanel->addConcepts(conceptNameVect, conceptSizeVect);
135 double val = _theViewPanel->getCurrentDeep();
136 _instantPanel->setConceptValue( "Axe Depth", (int)val );
137 //JCP _instantPanel->setConceptValue("time", num de imagenes);
138 ConceptDataWrap * data = _instantPanel->getConceptDataOf( "Axe Depth" );
139 //*******************changeInstant();
140 _theViewPanel->setVerticalConcept( "Axe Depth", data->getMinValue(), data->getMaxValue(), data->getMinShowedValue(), data->getMaxShowedValue(), data->getActualValue() );
142 this->configurePanels( );
147 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 ){
148 if(instance == NULL){
149 instance = new wxContourMainFrame(parent, id, title, pos, size, images, style,datadir);
154 std::vector<vtkImageData*> wxContourMainFrame ::getVectImages()
156 return kernelManager->getVectImages();
159 wxContourMainFrame* wxContourMainFrame :: getInstance()
164 void wxContourMainFrame :: resetInstance()
169 wxContourMainFrame :: ~wxContourMainFrame()
173 interfMainPanel::resetInstance();
174 delete kernelManager;
176 //_pannew->Destroy();
182 //El problema al cerrar la aplicacion puede estar asociado
183 //a que wxAUINotebook esta en la aplicacion
184 //principal (wxContourGUIExample)tambien
185 //EED???? delete _theViewPanel;
186 //EED???? delete _instantPanel;
187 //EED???? delete _buttonsBar;
188 //EED???? delete _actualInstant;
189 //EED???? delete _sceneManager;
193 //------------------------------------------------------------------------------------------------------------
194 // Creational and initialization methods using WxAui
195 //------------------------------------------------------------------------------------------------------------
197 wxAuiNotebook * wxContourMainFrame :: createNotebook()
199 wxSize client_size = GetClientSize();
200 wxAuiNotebook* noteBook = new wxAuiNotebook(this, -1, wxPoint(client_size.x, client_size.y), wxSize(430,200), m_notebook_style);
201 wxBitmap page_bmp = wxArtProvider::GetBitmap(wxART_NORMAL_FILE, wxART_OTHER, wxSize(16,16));
206 //------------------------------------------------------------------------------------------------------------
207 // Creational and initialization methods
208 //------------------------------------------------------------------------------------------------------------
209 bool wxContourMainFrame :: configurePanels( )
211 bool configured = _theViewPanel!=NULL;
213 configured &= _theViewPanel!=NULL;
214 if( _theViewPanel!=NULL )
216 notebook->AddPage( _theViewPanel, wxT(" View ") );
223 notebook->AddPage( _instantPanel, wxT("Instant Page") );
227 m_mgr.AddPane(notebook, wxAuiPaneInfo().Name(wxT("notebook_content")).CenterPane().PaneBorder(false));
230 SetMinSize(wxSize(300,300));
236 bool wxContourMainFrame::addNewPanel(wxPanel* panel)
238 bool configured = panel!=NULL;
239 configured &= panel!=NULL;
243 notebook->AddPage( panel, wxT(" Viewer "), true );
249 //------------------------------------------------------------------------------------------------------------
250 // Attributes getters and setters
251 //------------------------------------------------------------------------------------------------------------
255 void wxContourMainFrame :: setInstantChooserPanel( wxInstantChooserPanel * theInstantChooserPanel )
257 _instantPanel = theInstantChooserPanel;
260 // void wxContourMainFrame :: setButtonsBar( wxContour_ButtonsBar * theButtonsBar )
262 // _buttonsBar = theButtonsBar;
265 // void wxContourMainFrame :: setGrid( wxContour_Grid * theGridPanel )
267 // _gridPanel = theGridPanel;
270 // void wxContourMainFrame :: setDrawToolsPanel( wxContour_DrawToolsPanel * theDrawToolsPanel )
272 // _drawToolsPanel = theDrawToolsPanel;
275 // void wxContourMainFrame :: setOperationsToolsPanel( wxContour_OperationsToolsPanel * theOperationsToolsPanel )
277 // _operationsToolsPanel = theOperationsToolsPanel;
280 // void wxContourMainFrame :: setAutomaticFormsPanel( wxContour_AutomaticFormsToolsPanel * theAutoFormsPanel )
282 // _autoFormsPanel = theAutoFormsPanel;
285 // void wxContourMainFrame :: setStandardToolsPanel( wxContour_StandardToolsPanel * theStandardToolsPanel )
287 // _standardToolsPanel= theStandardToolsPanel;
290 // void wxContourMainFrame :: setEditionToolsPanel( wxContour_EdtionToolsPanel * theEditionToolsPanel )
292 // _editionToolsPanel = theEditionToolsPanel;
295 // void wxContourMainFrame :: setListViewPanel( wxContour_ListViewPanel * theListViewPanel )
297 // _listViewPanel = theListViewPanel;
302 void wxContourMainFrame::onCreateContourSpline( ){
304 //JCP 20-10-08 Undo redo implementation
306 //JCP 20-10-08 Undo redo implementation
310 void wxContourMainFrame::onCreateContourRectangle( ){
311 //JCP 20-10-08 Undo redo implementation
313 //JCP 20-10-08 Undo redo implementation
316 void wxContourMainFrame::onCreateContourCircle( ){
317 //JCP 20-10-08 Undo redo implementation
319 //JCP 20-10-08 Undo redo implementation
323 void wxContourMainFrame::onCreateContourLine( ){
324 //JCP 20-10-08 Undo redo implementation
326 //JCP 20-10-08 Undo redo implementation
330 //------------------------------------------------------------------------------------------------------------
332 void wxContourMainFrame :: onCreateContourBullEye(wxPanel* panel )
334 //Creating the manualContourModel and including in the model
335 manualContourModel * manModelContour = factoryManualContourModel(panel );
337 std::vector<int> instantVector;
338 _instantPanel->getInstant( instantVector );
339 std::string theName = kernelManager->createOutline(manModelContour, instantVector);
341 /*std::vector<int> instantVector;
342 _instantPanel->getInstant( instantVector );
344 theName= _modelManager->createOutline( manModelContour, instantVector );*/
345 bool addedModel = theName.compare("") != 0;//??
349 double spc[3];//Si no hay imagen pero hay contornos que spacing se pone por default
350 _theViewPanel->getSpacing(spc);
351 //Adding the manualContourControler to interface objects structure
352 //Adding the manualViewContour to interface objects structure
353 //_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.
354 _theViewPanel->getSceneManager()->configureViewControlTo( theName, manModelContour,spc , 4) ;
357 void wxContourMainFrame :: createContour( int typeContour )
359 //Creating the manualContourModel and including in the model
360 manualContourModel * manModelContour = kernelManager->factoryManualContourModel(typeContour);
363 std::vector<int> instantVector;
364 _instantPanel->getInstant( instantVector );
365 std::string theName = kernelManager->createOutline(manModelContour, instantVector);
367 /*std::vector<int> instantVector;
368 _instantPanel->getInstant( instantVector );
370 theName= _modelManager->createOutline( manModelContour, instantVector );*/
371 bool addedModel = theName.compare("") != 0;//??
374 double spc[3];//Si no hay imagen pero hay contornos que spacing se pone por default
375 _theViewPanel->getSpacing(spc);
376 //Adding the manualContourControler to interface objects structure
377 //Adding the manualViewContour to interface objects structure
378 //_sceneManager->setControlActiveStateOfALL( false );//This call is being done here because if the ROI is created underneath the previously created ROIS will still be active.
379 _theViewPanel->getSceneManager()->configureViewControlTo( theName, manModelContour,spc , typeContour) ;
383 manualContourModel * wxContourMainFrame::factoryManualContourModel(wxPanel* panel){
385 manualContourModelBullEye *manModelContourBullEye = new manualContourModelBullEye();
386 manualContourModel *manModelContour=NULL;
387 manModelContour = manModelContourBullEye;
389 int iCrown,sizeCrowns,iSector,sizeSectors;
390 double radioA,radioB,ang,angDelta ;
391 sizeCrowns = ((PanelBullEyeOptions*)panel)->GetNumberOfCrowns();
392 for ( iCrown=0 ; iCrown<sizeCrowns ; iCrown++ )
394 sizeSectors = ((PanelBullEyeOptions*)panel)->GetNumberOfSections(iCrown);
395 radioB = ((PanelBullEyeOptions*)panel)->GetRadioOfCrown(iCrown);
396 if (iCrown==sizeCrowns-1)
400 radioA = ((PanelBullEyeOptions*)panel)->GetRadioOfCrown(iCrown+1);
404 for ( iSector=0 ; iSector<sizeSectors ; iSector++ )
406 ang = ((PanelBullEyeOptions*)panel)->GetAngOfCrownSection(iCrown,iSector);
407 angDelta= ((PanelBullEyeOptions*)panel)->GetAngDeltaOfCrownSection(iCrown);
408 manModelContourBullEye->AddSector(radioA,radioB,ang,angDelta);
411 } // if _panelBullEyeOptions
413 return manModelContour;
415 void wxContourMainFrame :: saveState(){
417 std::string temp = kernelManager->saveState();
418 saveFileWithContours(temp);
421 void wxContourMainFrame::onDeleteContour(){
422 //JCP 20-10-08 Undo redo implementation
424 //JCP 20-10-08 Undo redo implementation
426 std::vector<std::string> lstKeyNameToBeErase;
427 lstKeyNameToBeErase = _theViewPanel->getSceneManager()->getSelectedObjects();
428 deleteContours( lstKeyNameToBeErase );
430 int i,size=_sceneManager->getSelectedObjects().size();
433 std::string keyName = _sceneManager->getSelectedObjects()[i];
434 int ispartofstaticlist = this->_modelManager->IsPartOfStaticList( keyName );
435 if ( ispartofstaticlist>=0 )
437 std::vector<int> tempVector;
438 _instantPanel->getInstant( tempVector );
439 Instant instant(&tempVector);
440 this->_modelManager->ChangeContourOfList(keyName, &instant);
444 std::vector<std::string> lstKeyName;
445 std::vector<std::string> lstKeyNameActualSlice;
446 std::vector<std::string> lstKeyNameToBeErase;
448 lstKeyNameToBeErase = _sceneManager->getSelectedObjects();
449 lstKeyNameActualSlice = _sceneManager->GetlstContoursNameActualSlice();
450 int k,kSize=lstKeyNameToBeErase.size();
451 int j,jSize=lstKeyNameActualSlice.size();
453 for (k=0;k<kSize; k++)
456 for (j=0;j<jSize; j++)
458 if (lstKeyNameToBeErase[k]==lstKeyNameActualSlice[j])
465 lstKeyName.push_back( lstKeyNameToBeErase[k] );
469 deleteContours( lstKeyName );
473 void wxContourMainFrame :: deleteContours( std::vector<std::string> keyNamesVector )
475 int i,size=keyNamesVector.size();
478 deleteContour( keyNamesVector[i] );
482 void wxContourMainFrame :: deleteContour( std::string theKeyName ){
484 manualContourModel * cModel;
485 manualViewBaseContour * cViewer;
486 manualContourBaseControler * cControler;
488 ContourWrap_ViewControl *conwrapviewControl = _theViewPanel->getSceneManager()->getContourWrap_ViewControlOf( theKeyName );
489 cControler = conwrapviewControl->getControler();*/
492 bool isedit = _theViewPanel->isEditableCControler(theKeyName);
493 bool ispartofstaticlst = kernelManager->IsPartOfStaticList(theKeyName);
495 if (isedit && ispartofstaticlst)
497 _theViewPanel->removeFromScene(theKeyName);
499 kernelManager->deleteCModel(theKeyName);
500 //_theViewPanel->getSceneManager()->removeFromScene( theKeyName );
501 //cViewer = conwrapviewControl->getViewer();
502 //_theViewPanel->getSceneManager()->removeWrap( theKeyName );
503 //cControler* conwrapviewControl->getControler();
505 //FILE *ff = fopen("c:/temp/wxVtkBaseView_SceneManagerStadistics.txt","a+");
506 //fprintf(ff,"EED wxContourEventHandler::deleteContours() \n" );
507 //fprintf(ff," %s %p\n",keyNamesVector[i].c_str(), cControler );
511 // delete cControler;
516 void wxContourMainFrame::onDeleteContoursActSlice(){
517 //JCP 20-10-08 Undo redo implementation
519 //JCP 20-10-08 Undo redo implementation
520 deleteContours( (std::vector<std::string>)_theViewPanel->getSceneManager()->GetlstContoursNameActualSlice() );
522 void wxContourMainFrame::onDeleteAllContours(){
523 //JCP 20-10-08 Undo redo implementation
527 void wxContourMainFrame::deleteAllContours(){
528 //JCP 20-10-08 Undo redo implementation
531 std::vector<int> tempVector;
532 _instantPanel->getInstant( tempVector );
534 //JCP --08-09-2008 When using a diferent interface the _mbarrangeDeleteAll might not be initialize
535 // the values in GetStart and GetEnd will then not be initialize also.
536 // We use instead the values given when initializing the _deletepanel.
538 //int minZ = _mbarrangeDeleteAll->GetStart();
539 //int maxZ = _mbarrangeDeleteAll->GetEnd();
543 maxZ = _theViewPanel->getSceneManager()->GetImageDataSizeZ();
547 _theViewPanel->getSceneManager()->removeSceneContours( );
548 _theViewPanel->getSceneManager()->removeAllOutlines();
549 kernelManager->removeAllOutlines();
552 if ( (minZ==0) && (maxZ==_mbarrangeDeleteAll->GetMax() ))
554 _theViewPanel->getSceneManager()->removeSceneContours( );
555 _modelManager->removeAllOutlines();
556 _theViewPanel->getSceneManager()->removeAllOutlines();
559 for ( z=minZ ; z<=maxZ ; z++)
562 Instant instant(&tempVector);
563 std::vector<ContourThing**> lstContourThings = this->_modelManager->getOutlinesAtInstant( &instant );
565 sizeLstContourThings = lstContourThings.size();
566 for (ii=0 ; ii<sizeLstContourThings ; ii++)
568 ContourThing **contourthing = lstContourThings[ii];
569 deleteContour( (*contourthing)->getName() );
576 void wxContourMainFrame::setConceptValue( std::string name, int value ){
577 _instantPanel->setConceptValue(name, value);
580 ConceptDataWrap* wxContourMainFrame::getLastConceptData(){
581 return _instantPanel->getLastConceptData();
583 bool wxContourMainFrame::getIfConceptCheckedAt( std::string name, int pos ){
584 return _instantPanel->getIfConceptCheckedAt( name, pos );
587 void wxContourMainFrame::changeInstant()
589 std::vector<int> instantVect;
590 _instantPanel->getInstant( instantVect );
591 // Instant * theInstant = new Instant ( &instantVect );
593 //Setting the actual instant
594 //_actualInstant = theInstant;
596 kernelManager->setInstant(instantVect);
597 //_modelManager->setInstant( _actualInstant );
600 updateInstantOutlines();
601 updateInstantImageData();
606 void wxContourMainFrame :: updateInstantOutlines()
608 _theViewPanel->removeSceneContours();
609 _theViewPanel->addNameWrapperToScene();
611 //for( int i=0; i<size; i++)
613 // _theViewPanel->getSceneManager()->addToScene(namesWrapping[i]->getKeyName(), true, true, true, false, false );
617 int wxContourMainFrame::getNamesWrappingSize(){
618 return kernelManager->getNamesWrappingSize();
620 std::string wxContourMainFrame::getNameWrapping(int i){
621 return kernelManager->getNameWrapping(i);
624 void wxContourMainFrame::updateInstantImageData()
626 std::vector<int> inst;
627 _instantPanel->getInstant(inst);
629 vtkImageData* img = kernelManager->getImageAtInstant(inst);
631 _theViewPanel->changeImage(img);
634 int z = _instantPanel->getConceptDataOf("Axe Depth")->getActualValue();
635 _theViewPanel->setImageSlice(z);
639 void wxContourMainFrame::updateInstantAxes()
644 void wxContourMainFrame::onChangeDeep(int val){
645 _instantPanel->setConceptValue( "Axe Depth", (int)val );
650 void wxContourMainFrame::onCopy(){
651 std::vector<std::string> currentSelection = _theViewPanel->getSelectedObjects();
653 std::vector<int> tempVector;
654 _instantPanel->getInstant( tempVector );
655 _performingOperation->reset();
656 _performingOperation->setStartCommand( COPY );
657 _performingOperation->setStartOperationInstantVector( tempVector );
658 _performingOperation->setKeyNamesOperationElems( currentSelection );
661 void wxContourMainFrame::onPaste(){
664 char theStartCommand = _performingOperation->getStartCommand();
665 if ( theStartCommand == COPY )
667 //JCP 20-10-08 Undo redo implementation
669 //JCP 20-10-08 Undo redo implementation
670 std::vector<int> tempVector;
671 _instantPanel->getInstant( tempVector );
672 _performingOperation->setEndOperationInstantVector ( tempVector );
673 std::vector<std::string> elems = _performingOperation->getKeyNamesOperationElems();
674 int i,size = elems.size();
675 for( i=0; i<size; i++ )
677 createCopyContourOf( elems[i], tempVector, i>0 );
681 void wxContourMainFrame::onUndo(){
682 std::string filename;
683 if(kernelManager->onUndoSaveFile(filename)){
684 saveFileWithContours(filename);
686 if(kernelManager->onUndo(filename)){
690 void wxContourMainFrame::onRedo(){
691 std::string filename;
692 if(kernelManager->onRedo(filename)){
697 void wxContourMainFrame :: createCopyContourOf ( std::string anExistingKName, std::vector<int> &instantNoTouchData, bool append )
699 std::string cloneName = kernelManager->createCopyContourOf( anExistingKName, instantNoTouchData );
700 manualContourModel * manualModel = kernelManager->getOutlineByKeyName(cloneName);//_modelManager->getOutlineByKeyName( cloneName )->getModel();
701 _theViewPanel->getSceneManager()->createCopyContourOf( anExistingKName, cloneName, manualModel , append );
704 ///AD: 03-09 Copy the object and apply the given transformation
705 void wxContourMainFrame :: createMirrorContourOf ( std::string anExistingKName, std::vector<int> &instantNoTouchData, bool append )
707 std::string cloneName = kernelManager->createCopyContourOf( anExistingKName, instantNoTouchData );
708 manualContourModel * manualModel = kernelManager->getOutlineByKeyName(cloneName);
710 manualPoint * refPoint1 = _refLineModel->GetManualPoint(0);
711 manualPoint * refPoint2 = _refLineModel->GetManualPoint(1);
713 double pnt1X = refPoint1->GetX();
714 double pnt1Y = refPoint1->GetY();
715 // double pnt1Z = refPoint1->GetZ();
716 double pnt2X = refPoint2->GetX();
717 double pnt2Y = refPoint2->GetY();
718 // double pnt2Z = refPoint2->GetZ();
720 double angle = (atan2(pnt2Y - pnt1Y, pnt2X - pnt1X) * 180 / 3.1415926535897932384626433832795)+90;
721 vtkTransform *t = vtkTransform::New();
725 t->Translate(-pnt1X, -pnt1Y, 0);
729 t->Translate(pnt1X, pnt1Y, 0);
732 int i,size=manualModel->GetSizeLstPoints();
735 manualPoint * mp = manualModel->GetManualPoint(i);
741 t->TransformPoint( vecIn, vecOut );
742 mp->SetPointX( vecOut[0] );
743 mp->SetPointY( vecOut[1] );
744 mp->SetPointZ( vecOut[2] );
747 _theViewPanel->getSceneManager()->createCopyContourOf( anExistingKName, cloneName, manualModel , append );
750 void wxContourMainFrame ::loadState(std::string filename){
752 FILE *pFile=fopen(filename.c_str(),"r+");
754 fscanf(pFile,"%s",tmp); // --CreaContour--
756 fscanf(pFile,"%s",tmp); // Version
757 fscanf(pFile,"%s",tmp); // 1.0.2 || 1.0.1 || 1.0.0
758 std::string version(tmp);
763 if (version=="1.0.2")
769 else if (version=="1.0.1")
775 else if (version=="1.0.0")
783 void wxContourMainFrame ::loadContours( FILE *pFile )
786 fscanf(pFile,"%s",tmp); // NumberOfContours
787 fscanf(pFile,"%s",tmp); // ##
788 int numberOfContours = atoi(tmp);
790 std::vector<int> instantVector;
791 int typeContourModel;
792 manualContourModel *manModelContour;
795 fscanf(pFile,"%s",tmp); // ImageDimensions
796 fscanf(pFile,"%s",tmp); // X
797 fscanf(pFile,"%s",tmp); // Y
798 fscanf(pFile,"%s",tmp); // Z
800 fscanf(pFile,"%s",tmp); // ImageSpacing
801 fscanf(pFile,"%s",tmp); // X
802 fscanf(pFile,"%s",tmp); // Y
803 fscanf(pFile,"%s",tmp); // Z
806 for (i=0;i<numberOfContours;i++)
808 instantVector.clear();
809 fscanf(pFile,"%s",tmp); // Instant
810 fscanf(pFile,"%s",tmp); // 1
811 instantVector.push_back( atoi(tmp) );
812 fscanf(pFile,"%s",tmp); // 2
813 instantVector.push_back( atoi(tmp) );
814 fscanf(pFile,"%s",tmp); // 3
815 instantVector.push_back( atoi(tmp) );
816 fscanf(pFile,"%s",tmp); // 4
817 instantVector.push_back( atoi(tmp) );
818 fscanf(pFile,"%s",tmp); // 5
819 instantVector.push_back( atoi(tmp) );
820 fscanf(pFile,"%s",tmp); // 6
821 instantVector.push_back( atoi(tmp) );
823 fscanf(pFile,"%s",tmp); // TypeContourModel
824 fscanf(pFile,"%s",tmp); // ##
825 typeContourModel = atoi(tmp);
827 manModelContour = kernelManager->factoryManualContourModel(typeContourModel);
828 manModelContour->Open(pFile);
830 fscanf(pFile,"%s",tmp); // TypeView
831 fscanf(pFile,"%s",tmp); // ##
832 typeView = atoi(tmp);
835 theName = kernelManager->createOutline( manModelContour, instantVector );
836 bool addedModel = theName.compare("") != 0;
839 double spc[3];//Si no hay imagen pero hay contornos que spacing se pone por default
840 _theViewPanel->getSpacing(spc);
841 //Adding the manualContourControler to interface objects structure
842 //Adding the manualViewContour to interface objects structure
843 //_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.
844 _theViewPanel->getSceneManager()->configureViewControlTo( theName, manModelContour,spc , typeView) ;
846 }// for numberOfContours
849 void wxContourMainFrame::onLoad()
852 wxFileDialog dialog(NULL, _T("Choose a file"), _T(""), _T(""), _T("*.roi"), wxOPEN );
853 if (dialog.ShowModal() == wxID_OK)
855 std::string fileNameContourROI = (const char *)(dialog.GetPath().mb_str());
856 FILE *pFile=fopen(fileNameContourROI.c_str(),"r+");
858 fscanf(pFile,"%s",tmp); // --CreaContour--
860 fscanf(pFile,"%s",tmp); // Version
861 fscanf(pFile,"%s",tmp); // 1.0.2 || 1.0.1 || 1.0.0
862 std::string version(tmp);
865 if (version=="1.0.2")
867 openContours(pFile,2);
871 else if (version=="1.0.1")
873 openContours(pFile,1);
877 else if (version=="1.0.0")
879 openContours(pFile,0);
884 _theViewPanel->getSceneManager()->removeSceneContours();
889 void wxContourMainFrame::onSave(){
890 wxFileDialog dialog(NULL, _T("Choose a file"), _T(""), _T(""), _T("*.roi"), wxSAVE );
891 if (dialog.ShowModal() == wxID_OK)
893 std::string fileNameContourROI = (const char *)(dialog.GetPath().mb_str());
894 kernelManager->setCurrentFileName(fileNameContourROI);
895 saveFileWithContours( fileNameContourROI );
900 void wxContourMainFrame::saveFileWithContours( std::string filename )
903 FILE *pFile=fopen(filename.c_str(),"w+");
904 std::vector< std::string > lstNameThings;
905 int i,sizeLstNameThings;
907 fprintf(pFile,"--CreaContour--\n");
908 fprintf(pFile,"Version %s\n", "1.0.2" );
911 lstNameThings = kernelManager->GetLstNameThings();
912 sizeLstNameThings = lstNameThings.size();
913 fprintf(pFile,"NumberOfContours %d\n", sizeLstNameThings );
915 vtkImageData *image = _images[0];
918 image->GetDimensions(dimRange);
920 fprintf(pFile,"ImageDimensions %d %d %d\n", dimRange[0], dimRange[1], dimRange[2] );
923 image->GetSpacing(spaRange);
925 fprintf(pFile,"ImageSpacing %f %f %f\n", spaRange[0], spaRange[1], spaRange[2] );
927 for (i=0 ; i<sizeLstNameThings ; i++)
929 kernelManager->SaveThingName( pFile, lstNameThings[i] );
930 _theViewPanel->getSceneManager()->SaveThingName( pFile, lstNameThings[i] );
933 //-- Contours Statics
934 lstNameThings = kernelManager->GetLstNameThingsStatic();
935 sizeLstNameThings = lstNameThings.size();
936 fprintf(pFile,"NumberOfContoursStatic %d\n", sizeLstNameThings );
937 for (i=0 ; i<sizeLstNameThings ; i++)
939 kernelManager->SaveThingName( pFile, lstNameThings[i] );
940 _theViewPanel->getSceneManager()->SaveThingName( pFile, lstNameThings[i] );
946 void wxContourMainFrame::openContours( FILE *pFile, int version )
949 fscanf(pFile,"%s",tmp); // NumberOfContours
950 fscanf(pFile,"%s",tmp); // ##
951 int numberOfContours = atoi(tmp);
953 std::vector<int> instantVector;
954 int typeContourModel;
955 manualContourModel *manModelContour;
958 vtkImageData *image = _images[0];
964 bool compatible = true;
969 image->GetDimensions(imageDim);
970 image->GetSpacing(imageSpac);
972 fscanf(pFile,"%s",tmp); // ImageDimensions
973 fscanf(pFile,"%s",tmp); // X
974 tempDim[0] = atoi(tmp);
975 fscanf(pFile,"%s",tmp); // Y
976 tempDim[1] = atoi(tmp);
977 fscanf(pFile,"%s",tmp); // Z
978 tempDim[2] = atoi(tmp);
980 fscanf(pFile,"%s",tmp); // ImageSpacing
981 fscanf(pFile,"%s",tmp); // X
982 tempSpac[0] = atof(tmp);
983 fscanf(pFile,"%s",tmp); // Y
984 tempSpac[1] = atof(tmp);
985 fscanf(pFile,"%s",tmp); // Z
986 tempSpac[2] = atof(tmp);
988 //Compare Spacing and Dims in X and Y (Necessary in Z?) - Just for Version 3
989 if (imageDim[0]!=tempDim[0] || imageDim[1]!=tempDim[1] || imageSpac[0]!=tempSpac[0] || imageSpac[1]!=tempSpac[1])
995 if (compatible==true)
998 for (i=0;i<numberOfContours;i++)
1000 instantVector.clear();
1001 fscanf(pFile,"%s",tmp); // Instant
1003 fscanf(pFile,"%s",tmp); // 1
1004 instantVector.push_back( atoi(tmp) );
1005 fscanf(pFile,"%s",tmp); // 2
1006 instantVector.push_back( atoi(tmp) );
1007 fscanf(pFile,"%s",tmp); // 3
1008 instantVector.push_back( atoi(tmp) );
1009 fscanf(pFile,"%s",tmp); // 4
1010 instantVector.push_back( atoi(tmp) );
1011 fscanf(pFile,"%s",tmp); // 5
1012 instantVector.push_back( atoi(tmp) );
1013 fscanf(pFile,"%s",tmp); // 6
1014 instantVector.push_back( atoi(tmp) );
1017 fscanf(pFile,"%s",tmp); // TypeContourModel
1018 fscanf(pFile,"%s",tmp); // ##
1019 typeContourModel = atoi(tmp);
1021 manModelContour = kernelManager->factoryManualContourModel(typeContourModel);
1022 manModelContour->Open(pFile);
1024 fscanf(pFile,"%s",tmp); // TypeView
1025 fscanf(pFile,"%s",tmp); // ##
1026 typeView = atoi(tmp);
1028 std::string theName;
1029 theName = kernelManager->createOutline( manModelContour, instantVector );
1030 bool addedModel = theName.compare("") != 0;
1033 double spc[3];//Si no hay imagen pero hay contornos que spacing se pone por default
1034 _theViewPanel->getSpacing(spc);
1035 //Adding the manualContourControler to interface objects structure
1036 //Adding the manualViewContour to interface objects structure
1037 //_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.
1038 _theViewPanel->getSceneManager()->configureViewControlTo( theName, manModelContour,spc , typeView) ;
1041 if (version==0) //StaticContours (will appear in all slices)
1043 Instant instant(&instantVector);
1044 kernelManager->changeContourOfManager( theName , &instant );
1047 }// for numberOfContours
1050 else if (compatible==false)
1052 wxDialog* dial = new wxDialog (this,-1,_T("Tools"),wxDefaultPosition, wxSize(260,160));
1053 wxSizer* buttonsSizer = dial->CreateSeparatedButtonSizer(wxOK|wxCANCEL);
1054 wxBoxSizer *dialSizer = new wxBoxSizer(wxVERTICAL);
1056 wxString lstOptOperation[2];
1057 lstOptOperation[0]=_T("By Dimension");
1058 lstOptOperation[1]=_T("By Spacing");
1059 wxRadioBox * radioOpts = new wxRadioBox(dial, -1, _T("Type of Transformation"), wxDefaultPosition, wxSize(270,45), 2 , lstOptOperation, 2, wxRA_SPECIFY_COLS);
1061 dialSizer->Add( new wxStaticText(dial,-1,_T("The image resolution is not compatible with the ")) , 0, wxGROW );
1062 dialSizer->Add( new wxStaticText(dial,-1,_T("selected Roi file. Do you want to tranform it?")) , 0, wxGROW );
1063 dialSizer->Add( new wxStaticText(dial,-1,_T(" ")) , 0, wxGROW );
1064 dialSizer->Add(radioOpts,0,wxGROW);
1065 dialSizer->Add( new wxStaticText(dial,-1,_T(" ")) , 0, wxGROW );
1066 dialSizer->Add(buttonsSizer,0,wxGROW);
1067 dial->SetSizer(dialSizer, true);
1071 int typeOfTransformation = -1;
1072 bool transform = false;
1074 if (dial->GetReturnCode() == wxID_OK)
1076 typeOfTransformation = radioOpts->GetSelection();
1081 for (i=0;i<numberOfContours;i++)
1083 instantVector.clear();
1084 fscanf(pFile,"%s",tmp); // Instant
1086 fscanf(pFile,"%s",tmp); // 1
1087 instantVector.push_back( atoi(tmp) );
1088 fscanf(pFile,"%s",tmp); // 2
1089 instantVector.push_back( atoi(tmp) );
1090 fscanf(pFile,"%s",tmp); // 3
1091 instantVector.push_back( atoi(tmp) );
1092 fscanf(pFile,"%s",tmp); // 4
1093 instantVector.push_back( atoi(tmp) );
1094 fscanf(pFile,"%s",tmp); // 5
1095 instantVector.push_back( atoi(tmp) );
1096 fscanf(pFile,"%s",tmp); // 6
1097 instantVector.push_back( atoi(tmp) );
1099 fscanf(pFile,"%s",tmp); // TypeContourModel
1100 fscanf(pFile,"%s",tmp); // ##
1101 typeContourModel = atoi(tmp);
1103 manModelContour = kernelManager->factoryManualContourModel(typeContourModel);
1104 manModelContour->Open(pFile);
1106 if (transform==true)
1108 if (typeOfTransformation==0)
1110 double transX, transY;
1111 transX = (double) imageDim[0]/tempDim[0];
1112 transY = (double) imageDim[1]/tempDim[1];
1113 manModelContour->Transform_Ax_Plus_B(transX,0,transY,0);
1115 else if (typeOfTransformation==1)
1117 double transX, transY;
1118 transX = (double) tempSpac[0]/imageSpac[0];
1119 transY = (double) tempSpac[1]/imageSpac[1];
1120 manModelContour->Transform_Ax_Plus_B(transX,0,transY,0);
1124 fscanf(pFile,"%s",tmp); // TypeView
1125 fscanf(pFile,"%s",tmp); // ##
1126 typeView = atoi(tmp);
1128 std::string theName;
1129 theName = kernelManager->createOutline( manModelContour, instantVector );
1130 bool addedModel = theName.compare("") != 0;
1133 double spc[3];//Si no hay imagen pero hay contornos que spacing se pone por default
1134 _theViewPanel->getSpacing(spc);
1135 //Adding the manualContourControler to interface objects structure
1136 //Adding the manualViewContour to interface objects structure
1137 //_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.
1138 _theViewPanel->getSceneManager()->configureViewControlTo( theName, manModelContour,spc , typeView) ;
1141 if (version==0) //StaticContours (will appear in all slices)
1143 Instant instant(&instantVector);
1144 kernelManager->changeContourOfManager( theName , &instant );
1146 }// for numberOfContours
1150 void wxContourMainFrame::RefreshInterface(){
1152 _theViewPanel->RefreshInterface();
1153 //wxVtk2DBaseView *wxvtk2dbaseview = (wxVtk2DBaseView*)this->_theViewPanel->getWxVtkBaseView();
1154 //wxvtk2dbaseview->Refresh();
1157 vtkImageData* wxContourMainFrame::getImageData(){
1158 return _theViewPanel->getImageData();
1161 void wxContourMainFrame::onSegmentationOneSliceITK(wxString distance, wxString sigma, wxString alfa, wxString beta, wxString propagation, wxString iterations, wxString inflation)
1163 //JCP 20-10-08 Undo redo implementation
1165 //JCP 20-10-08 Undo redo implementation
1168 int x = _theViewPanel->GetX();
1169 int y = _theViewPanel->GetY();
1170 int z = _theViewPanel->GetZ();
1171 SegmentationOneSliceITK( x,y,z,distance, sigma, alfa, beta, propagation, iterations, inflation);
1175 void wxContourMainFrame::SegmentationOneSliceITK(int x, int y, int z, wxString distanc, wxString sigm, wxString alf, wxString bet, wxString prop, wxString iter, wxString inflation)
1177 int typeofcontour = 1;
1179 vtkImageData *imagedata = getImageData();
1181 //Tipo de pixeles a utilizar internamente en ITK
1182 typedef float InternalPixelType;
1183 const unsigned int Dimension = 2;
1184 typedef itk::Image< InternalPixelType, Dimension > InternalImageType;
1186 //Tipo de pixeles de salida 1
1187 typedef unsigned char OutputPixelType;
1188 typedef itk::Image< OutputPixelType, Dimension > OutputImageType;
1190 //Tipo de pixeles de salida 2
1191 typedef unsigned short OutputPixelType2;
1192 typedef itk::Image< OutputPixelType2, Dimension > OutputImageType2;
1194 //DefiniciÛn del thresholder
1195 typedef itk::BinaryThresholdImageFilter<
1197 OutputImageType > ThresholdingFilterType;
1199 //DefiniciÛn del primer filtro de conversiÛn de pixeles
1200 typedef itk::CastImageFilter<
1201 OutputImageType, OutputImageType2 > CastFilterType;
1203 //DefiniciÛn del segundo tipo de conversiÛn de pixeles
1204 typedef itk::CastImageFilter<
1205 OutputImageType2, InternalImageType > CastFilterType2;
1207 //Tercer tipo de conversiÛn
1208 typedef itk::RescaleIntensityImageFilter<
1210 OutputImageType > CastFilterType3;
1212 //Cuarto tipo de conversiÛn
1213 typedef itk::RescaleIntensityImageFilter<
1215 OutputImageType > CastFilterType4;
1217 ThresholdingFilterType::Pointer thresholder = ThresholdingFilterType::New();
1219 thresholder->SetLowerThreshold( 0.0 );
1220 thresholder->SetUpperThreshold( 128 );
1222 thresholder->SetOutsideValue( 255 );
1223 thresholder->SetInsideValue( 0 );
1225 //DefinciÛn de conexiÛnes entre VTK e ITK y el writer
1226 typedef itk::VTKImageToImageFilter<OutputImageType2> ConnectorType;
1227 typedef itk::ImageToVTKImageFilter<OutputImageType> ConnectorType2;
1228 typedef itk::ImageFileWriter< OutputImageType > WriterType;
1230 ConnectorType::Pointer connector= ConnectorType::New();
1231 ConnectorType2::Pointer connector2= ConnectorType2::New();
1234 CastFilterType::Pointer filter=CastFilterType::New();
1235 CastFilterType2::Pointer filter2=CastFilterType2::New();
1237 connector->SetInput( imagedata );
1238 filter2->SetInput(connector->GetOutput());
1240 typedef itk::CurvatureAnisotropicDiffusionImageFilter<
1242 InternalImageType > SmoothingFilterType;
1244 SmoothingFilterType::Pointer smoothing = SmoothingFilterType::New();
1246 typedef itk::GradientMagnitudeRecursiveGaussianImageFilter<
1248 InternalImageType > GradientFilterType;
1250 typedef itk::SigmoidImageFilter<
1252 InternalImageType > SigmoidFilterType;
1254 GradientFilterType::Pointer gradientMagnitude = GradientFilterType::New();
1256 SigmoidFilterType::Pointer sigmoid = SigmoidFilterType::New();
1258 sigmoid->SetOutputMinimum( 0.0 );
1259 sigmoid->SetOutputMaximum( 255.0 );
1262 typedef itk::FastMarchingImageFilter<
1264 InternalImageType > FastMarchingFilterType;
1267 FastMarchingFilterType::Pointer fastMarching = FastMarchingFilterType::New();
1269 typedef itk::GeodesicActiveContourLevelSetImageFilter< InternalImageType,
1270 InternalImageType > GeodesicActiveContourFilterType;
1271 GeodesicActiveContourFilterType::Pointer geodesicActiveContour =
1272 GeodesicActiveContourFilterType::New();
1274 typedef itk::ZeroCrossingImageFilter<
1276 InternalImageType > ZeroCrossingFilterType;
1277 ZeroCrossingFilterType::Pointer zeroCrossing =
1278 ZeroCrossingFilterType::New();
1280 const double propagationScaling = atof( crea::wx2std(prop).c_str() );
1282 geodesicActiveContour->SetPropagationScaling( propagationScaling );
1283 geodesicActiveContour->SetCurvatureScaling( 1.0 );
1284 geodesicActiveContour->SetAdvectionScaling( 1.0 );
1286 geodesicActiveContour->SetMaximumRMSError( 0.02 );
1287 int it=atoi( crea::wx2std(iter).c_str() );
1288 geodesicActiveContour->SetNumberOfIterations( it );
1290 smoothing->SetInput( filter2->GetOutput() );
1291 gradientMagnitude->SetInput( smoothing->GetOutput() );
1292 sigmoid->SetInput( gradientMagnitude->GetOutput() );
1293 fastMarching->SetInput( sigmoid->GetOutput() );
1294 geodesicActiveContour->SetInput( fastMarching->GetOutput() );
1295 geodesicActiveContour->SetFeatureImage( sigmoid->GetOutput() );
1297 zeroCrossing->SetInput( geodesicActiveContour->GetOutput() );
1298 //thresholder->SetInput( zeroCrossing->GetOutput() );
1299 thresholder->SetInput( geodesicActiveContour->GetOutput() );
1300 connector2->SetInput( thresholder->GetOutput() );
1303 smoothing->SetTimeStep( 0.125 );
1304 smoothing->SetNumberOfIterations( 5 );
1305 smoothing->SetConductanceParameter( 9.0 );
1308 const double sigma = atof( crea::wx2std(sigm).c_str() );
1309 gradientMagnitude->SetSigma( sigma );
1311 const double alpha = atof( crea::wx2std(alf).c_str() );
1312 const double beta = atof( crea::wx2std(bet).c_str() );
1314 sigmoid->SetAlpha( alpha );
1315 sigmoid->SetBeta( beta );
1317 typedef FastMarchingFilterType::NodeContainer NodeContainer;
1318 typedef FastMarchingFilterType::NodeType NodeType;
1320 NodeContainer::Pointer seeds = NodeContainer::New();
1322 InternalImageType::IndexType seedPosition;
1323 seedPosition[0] = x;
1324 seedPosition[1] = y;
1326 const double initialDistance = atof( crea::wx2std(distanc).c_str() );
1330 const double seedValue = - initialDistance;
1332 node.SetValue( seedValue );
1333 node.SetIndex( seedPosition );
1335 seeds->Initialize();
1336 seeds->InsertElement( 0, node );
1338 fastMarching->SetTrialPoints( seeds );
1340 fastMarching->SetSpeedConstant( 1.0 );
1342 fastMarching->SetOutputSize(
1343 connector->GetOutput()->GetBufferedRegion().GetSize() );
1345 fastMarching->SetStoppingValue( 800 );
1349 connector2->Update();
1350 vtkImageData *idata = connector2->GetOutput();
1352 vtkMarchingContourFilter* cntVTK = vtkMarchingContourFilter::New( );
1354 cntVTK->SetInput( idata );
1356 cntVTK->SetNumberOfContours( 1 );
1357 cntVTK->SetValue( 0, 255 );
1359 cntVTK->UpdateInformation();
1361 vtkCleanPolyData* cpd = vtkCleanPolyData::New( );
1362 cpd->SetInput( cntVTK->GetOutput( ) );
1364 cpd->UpdateInformation();
1366 vtkPolyDataConnectivityFilter* conn = vtkPolyDataConnectivityFilter::New( );
1367 conn->SetExtractionModeToLargestRegion( );
1368 conn->SetInput( cpd->GetOutput( ) );
1370 conn->UpdateInformation();
1372 vtkStripper* vtkstripper = vtkStripper::New( );
1373 vtkstripper->SetInput( conn->GetOutput() );
1374 vtkstripper->Update();
1375 vtkstripper->UpdateInformation();
1378 vtkPolyData* polyDataResult = cntVTK->GetOutput();
1379 //std::cout<<"Points "<<polyDataResult->GetNumberOfPoints()<<std::endl;
1380 polyDataResult->Update( );
1381 polyDataResult->UpdateInformation();
1386 myfile.open ("C:/Creatis/example.txt");
1388 polyDataResult->Print(myfile);
1389 myfile << "-------------------------------------\n";
1390 polyDataResult->GetLines()->Print(myfile);
1398 //--Calculating control points
1400 std::vector<double> vecX;
1401 std::vector<double> vecY;
1402 std::vector<double> vecXo;
1403 std::vector<double> vecYo;
1404 std::vector<double>::iterator vecXoi;
1405 std::vector<double>::iterator vecYoi;
1406 std::vector<double> vecZ;
1408 std::vector<double> vecCtrlPointX;
1409 std::vector<double> vecCtrlPointY;
1410 std::vector<double> vecCtrlPointZ;
1416 int ii,size=polyDataResult->GetNumberOfPoints();
1418 myfile.open ("C:/Creatis/example2.txt");
1420 size=polyDataResult->GetNumberOfPoints();
1421 for (ii=0;ii<size;ii++)
1428 p = polyDataResult->GetPoint(ii);
1431 /*if(fabs(yAct-y)>20)
1433 if((xAct-x)>1 || (xAct-x)<-1)
1435 vecX.push_back( p[0] );
1436 vecY.push_back( p[1] );
1437 myfile <<p[0]<<","<<p[1]<<"\n";
1438 std::cout<<" x Anterior "<<xAct<<" x actual "<<x<<std::endl;
1439 std::cout<<" y Anterior "<<yAct<<" y actual "<<y<<std::endl;
1440 std::cout<<" x "<<p[0]<<" y "<<p[1]<<std::endl;
1441 vecZ.push_back( 900 );
1447 vecXo.push_back(p[0]);
1448 vecYo.push_back(p[1]);
1452 else*/ if(fabs(xAct-x)>11)
1454 vecXo.push_back(p[0]);
1455 vecYo.push_back(p[1]);
1459 vecX.push_back( p[0] );
1460 myfile <<p[0]<<","<<p[1]<<"\n";
1461 //std::cout<<" x Anterior "<<xAct<<" x actual "<<x<<std::endl;
1462 //std::cout<<" y Anterior "<<yAct<<" y actual "<<y<<std::endl;
1463 //std::cout<<" x "<<p[0]<<" y "<<p[1]<<std::endl;
1464 vecY.push_back( p[1] );
1465 vecZ.push_back( 900 );
1473 while(!vecXo.empty())
1475 vecX.push_back(vecXo.back());
1476 //std::cout<<" x Siguiente "<<vecXo.back();
1478 vecZ.push_back( 900 );
1480 while(!vecYo.empty())
1482 vecY.push_back(vecYo.back());
1487 /*for(int l=0;l<vecX.size();l++)
1491 vecXo.push_back(p[0]);
1492 vecYo.push_back(p[1]);
1503 ExtractControlPoints2D *extractcontrolpoints2d = new ExtractControlPoints2D();
1505 extractcontrolpoints2d->SetContour( &vecX , &vecY , &vecZ );
1509 extractcontrolpoints2d->GetInitialControlPoints( &vecCtrlPointX , &vecCtrlPointY , &vecCtrlPointZ );
1511 else if (method==1){
1512 extractcontrolpoints2d->GetControlPoints( &vecCtrlPointX , &vecCtrlPointY , &vecCtrlPointZ );
1514 else if (method==2){
1515 extractcontrolpoints2d->SetSamplingControlPoints( 15 );
1516 extractcontrolpoints2d->GetSamplingControlPoints( &vecCtrlPointX , &vecCtrlPointY , &vecCtrlPointZ );
1518 //--Adding contour to the system
1520 std::vector<int> actualInstantVector;
1521 _instantPanel->getInstant( actualInstantVector );
1522 actualInstantVector[1]=z;
1524 int j,sizeCtrPt = vecCtrlPointX.size();
1526 manualContourModel *manModelContour = kernelManager->factoryManualContourModel( typeofcontour );
1527 manModelContour->SetNumberOfPointsSpline( ((sizeCtrPt/100)+1)*100 );
1529 for (j=0 ; j<sizeCtrPt ; j++)
1531 manModelContour->AddPoint( vecCtrlPointX[j] , vecCtrlPointY[j] , vecCtrlPointZ[j] );
1533 std::string theName;
1534 //theName = _modelManager->createOutline( manModelContour, actualInstantVector );
1535 theName = kernelManager->createOutline( manModelContour, actualInstantVector );
1536 bool addedModel = theName.compare("") != 0;
1539 double spc[3];//Si no hay imagen pero hay contornos que spacing se pone por default
1540 _theViewPanel->getSpacing(spc);
1541 //Adding the manualContourControler to interface objects structure
1542 //Adding the manualViewContour to interface objects structure
1543 //_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.
1544 _theViewPanel->configureViewControlTo(theName, manModelContour, spc, typeofcontour);
1545 //_theViewPanel->getSceneManager()->configureViewControlTo( theName, manModelContour,spc, typeofcontour ) ;
1551 WriterType::Pointer writer = WriterType::New();
1552 CastFilterType3::Pointer caster = CastFilterType3::New();
1554 caster->SetInput( gradientMagnitude->GetOutput() );
1555 writer->SetInput( caster->GetOutput() );
1556 writer->SetFileName("Gradient Magnitude.png");
1557 caster->SetOutputMinimum( 0 );
1558 caster->SetOutputMaximum( 255 );
1561 CastFilterType3::Pointer caster2 = CastFilterType3::New();
1562 WriterType::Pointer writer2 = WriterType::New();
1564 caster2->SetInput( sigmoid->GetOutput() );
1565 writer2->SetInput( caster2->GetOutput() );
1566 writer2->SetFileName("Sigmoid.png");
1567 caster2->SetOutputMinimum( 0 );
1568 caster2->SetOutputMaximum( 255 );
1571 CastFilterType3::Pointer caster3 = CastFilterType3::New();
1572 WriterType::Pointer writer3 = WriterType::New();
1574 caster3->SetInput( fastMarching->GetOutput() );
1575 writer3->SetInput( caster3->GetOutput() );
1576 writer3->SetFileName("FastMarching.bmp");
1577 caster3->SetOutputMinimum( 0 );
1578 caster3->SetOutputMaximum( 255 );
1581 CastFilterType3::Pointer caster4 = CastFilterType3::New();
1582 WriterType::Pointer writer4 = WriterType::New();
1584 caster4->SetInput( geodesicActiveContour->GetOutput() );
1585 writer4->SetInput( caster4->GetOutput() );
1586 writer4->SetFileName("GeodesicActiveContour.png");
1587 caster4->SetOutputMinimum( 0 );
1588 caster4->SetOutputMaximum( 255 );
1591 CastFilterType3::Pointer caster5 = CastFilterType3::New();
1592 WriterType::Pointer writer5 = WriterType::New();
1594 caster5->SetInput( zeroCrossing->GetOutput() );
1595 writer5->SetInput( caster5->GetOutput() );
1596 writer5->SetFileName("ZeroCrossing.bmp");
1597 caster5->SetOutputMinimum( 0 );
1598 caster5->SetOutputMaximum( 255 );
1601 catch( itk::ExceptionObject & excep )
1603 std::cerr << "Exception caught !" << std::endl;
1604 std::cerr << excep << std::endl;
1608 void wxContourMainFrame::onSegmentationOneSlice(int isovalue,int sampling,int method){
1610 //JCP 20-10-08 Undo redo implementation
1612 //JCP 20-10-08 Undo redo implementation
1615 int x = _theViewPanel->GetX();
1616 int y = _theViewPanel->GetY();
1617 int z = _theViewPanel->GetZ();
1618 SegmentationOneSlice( x,y,z,isovalue, sampling, method );
1623 void wxContourMainFrame::SegmentationOneSlice( int x, int y, int z, int isovalue, int sampling, int method )
1625 int typeofcontour = 1;
1626 //--Extracting Contour
1627 //vtkImageData *imagedata = _theViewPanel->getSceneManager()->GetImageData();
1628 vtkImageData *imagedata = getImageData();
1629 // double *range = imagedata->GetScalarRange();
1632 vtkImageReslice *imageReslice = vtkImageReslice::New();
1635 // imagedata->GetSpacing(spc);
1640 imageReslice->SetInput( imagedata );
1641 imageReslice->SetInformationInput(imagedata);
1642 imageReslice->SetResliceAxesDirectionCosines(1,0,0, 0,1,0 ,0,0,1);
1643 imageReslice->SetResliceAxesOrigin(0,0,z);
1644 imageReslice->SetOutputDimensionality(2);
1645 imageReslice->SetInterpolationModeToLinear();
1647 imagedata = imageReslice->GetOutput();
1648 imagedata->Update();
1649 imagedata->UpdateInformation();
1651 vtkContourFilter* cntVTK = vtkContourFilter::New( );
1652 cntVTK->SetInput( imagedata );
1654 cntVTK->SetNumberOfContours( 1 );
1655 //cntVTK->SetValue( 0, vmin );
1656 // cntVTK->SetValue( 0, (range[1]*thr/100) );
1657 cntVTK->SetValue( 1, isovalue );
1658 // cntVTK->SetValue( 1, vmax );
1660 cntVTK->UpdateInformation();
1662 vtkCleanPolyData* cpd = vtkCleanPolyData::New( );
1663 cpd->SetInput( cntVTK->GetOutput( ) );
1664 cpd->ConvertLinesToPointsOff( );
1666 cpd->UpdateInformation();
1668 vtkPolyDataConnectivityFilter* conn = vtkPolyDataConnectivityFilter::New( );
1669 conn->SetExtractionModeToClosestPointRegion( );
1670 //conn->SetMaxRecursionDepth( 3000 );
1672 conn->SetInput( cpd->GetOutput( ) );
1674 conn->SetClosestPoint( x, y, 0 );
1676 conn->UpdateInformation();
1678 vtkCleanPolyData* cpd2 = vtkCleanPolyData::New( );
1679 cpd2->SetInput( conn->GetOutput( ) );
1681 cpd2->UpdateInformation();
1683 vtkStripper* vtkstripper = vtkStripper::New( );
1684 vtkstripper->SetInput( cpd2->GetOutput() );
1685 vtkstripper->Update();
1686 vtkstripper->UpdateInformation();
1689 vtkPolyData* polyDataResult = vtkstripper->GetOutput();
1691 polyDataResult->Update( );
1692 polyDataResult->UpdateInformation();
1696 myfile.open ("c:/temp/example.txt");
1698 polyDataResult->Print(myfile);
1699 myfile << "-------------------------------------\n";
1700 polyDataResult->GetLines()->Print(myfile);
1710 //--Calculating control points
1712 std::vector<double> vecX;
1713 std::vector<double> vecY;
1714 std::vector<double> vecZ;
1716 std::vector<double> vecCtrlPointX;
1717 std::vector<double> vecCtrlPointY;
1718 std::vector<double> vecCtrlPointZ;
1722 int ii,size=polyDataResult->GetNumberOfPoints();
1724 for (ii=1;ii<=size;ii++)
1726 id = polyDataResult->GetLines()->GetData()->GetValue(ii);
1727 p = polyDataResult->GetPoint(id);
1730 vecX.push_back( p[0] );
1731 vecY.push_back( p[1] );
1732 vecZ.push_back( 900 );
1733 // vecZ.push_back( p[2] );
1737 ExtractControlPoints2D *extractcontrolpoints2d = new ExtractControlPoints2D();
1738 extractcontrolpoints2d->SetContour( &vecX , &vecY , &vecZ );
1741 /*if (methodRadiobox->GetSelection()==0){
1742 extractcontrolpoints2d->GetInitialControlPoints( &vecCtrlPointX , &vecCtrlPointY , &vecCtrlPointZ );
1744 if (methodRadiobox->GetSelection()==1){
1745 extractcontrolpoints2d->GetControlPoints( &vecCtrlPointX , &vecCtrlPointY , &vecCtrlPointZ );
1747 if (methodRadiobox->GetSelection()==2){
1748 extractcontrolpoints2d->SetSamplingControlPoints( sampling );
1749 extractcontrolpoints2d->GetSamplingControlPoints( &vecCtrlPointX , &vecCtrlPointY , &vecCtrlPointZ );
1753 extractcontrolpoints2d->GetInitialControlPoints( &vecCtrlPointX , &vecCtrlPointY , &vecCtrlPointZ );
1755 else if (method==1){
1756 extractcontrolpoints2d->GetControlPoints( &vecCtrlPointX , &vecCtrlPointY , &vecCtrlPointZ );
1758 else if (method==2){
1759 extractcontrolpoints2d->SetSamplingControlPoints( sampling );
1760 extractcontrolpoints2d->GetSamplingControlPoints( &vecCtrlPointX , &vecCtrlPointY , &vecCtrlPointZ );
1763 //--Adding contour to the system
1765 std::vector<int> actualInstantVector;
1766 _instantPanel->getInstant( actualInstantVector );
1767 actualInstantVector[1]=z;
1769 int j,sizeCtrPt = vecCtrlPointX.size();
1770 manualContourModel *manModelContour = kernelManager->factoryManualContourModel( typeofcontour );
1771 manModelContour->SetNumberOfPointsSpline( ((sizeCtrPt/100)+1)*100 );
1773 for (j=0 ; j<sizeCtrPt ; j++)
1775 manModelContour->AddPoint( vecCtrlPointX[j] , vecCtrlPointY[j] , vecCtrlPointZ[j] );
1777 std::string theName;
1778 //theName = _modelManager->createOutline( manModelContour, actualInstantVector );
1779 theName = kernelManager->createOutline( manModelContour, actualInstantVector );
1780 bool addedModel = theName.compare("") != 0;
1783 double spc[3];//Si no hay imagen pero hay contornos que spacing se pone por default
1784 _theViewPanel->getSpacing(spc);
1785 //Adding the manualContourControler to interface objects structure
1786 //Adding the manualViewContour to interface objects structure
1787 //_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.
1788 _theViewPanel->configureViewControlTo(theName, manModelContour, spc, typeofcontour);
1789 //_theViewPanel->getSceneManager()->configureViewControlTo( theName, manModelContour,spc, typeofcontour ) ;
1793 int wxContourMainFrame::GetImageDataSizeZ(){
1794 return _theViewPanel->GetImageDataSizeZ();
1797 void wxContourMainFrame::GetImageDataRange(double *range){
1798 _theViewPanel->GetImageDataRange(range);
1801 void wxContourMainFrame::onSegmentationAllSlice(int minZ,int maxZ,int isovalue,int sampling,int method){
1802 //JCP 20-10-08 Undo redo implementation
1804 //JCP 20-10-08 Undo redo implementation
1807 int x = _theViewPanel->GetX();
1808 int y = _theViewPanel->GetY();
1812 double totalZ = maxZ-minZ+1;
1813 for( z=minZ ; z<=maxZ ; z++ )
1815 porcent = 100.0* (z-minZ)/totalZ;
1816 tmpString.Printf(_T(" %d %c %d/%d %d"), (int)porcent , 37 , z-minZ+1, (int)totalZ,z );
1817 interfMainPanel::getInstance()->setLabelSegmentationPanelVTK(tmpString);
1818 //_staticTextSegmentation->SetLabel(tmpString);
1819 SegmentationOneSlice( x,y,z,isovalue, sampling,method );
1821 interfMainPanel::getInstance()->setLabelSegmentationPanelVTK(_T(" "));
1826 //Creates a reference line to be used as the axis of the mirroring
1827 void wxContourMainFrame::referenceLine()
1829 if (_refLineControl==NULL)
1834 vtkImageData *vtkimagedata = _theViewPanel->getImageData();
1835 vtkimagedata->GetSpacing(spc);
1837 wxVtkBaseView * viewer2D = _theViewPanel->getWxVtkBaseView();
1839 _refLineControl = new manualLineControler();
1840 _refLineModel = new manualContourModelLine();
1841 _refLineView = new manualViewLine();
1842 _refLineView->SetModel( _refLineModel );
1843 _refLineView->SetWxVtkBaseView( viewer2D );
1844 _refLineView->SetRange( 2 );
1845 _refLineView->SetZ( 1200 );
1847 _refLineView->SetSpacing(spc);
1849 _refLineView->SetColorNormalContour(0, 0, 1);
1850 _refLineView->SetColorEditContour(0, 0.5, 0.5);
1851 _refLineView->SetWidthLine(4);
1853 _refLineControl->SetModelView( _refLineModel , _refLineView );
1854 vtkInteractorStyleBaseView* style = (vtkInteractorStyleBaseView*)viewer2D->GetInteractorStyleBaseView();
1855 style->AddInteractorStyleMaracas( _refLineControl );
1856 _refLineModel->SetCloseContour(false);
1857 _refLineControl->CreateNewManualContour();
1859 //AD: Inicializar el mirroring con una linea ya pintada
1861 double z = _refLineControl->GetZ();
1864 image->GetDimensions(imageDim);
1865 double x = (double) imageDim[0]/2;
1866 double y1 = (double) (imageDim[1]/2)+15;
1867 double y2 = (double) (imageDim[1]/2)-15;
1869 _refLineControl->AddPoint(x,y1,z);
1870 _refLineControl->AddPoint(x,y2,z);
1871 _refLineControl->SetCompleteCreation(true);
1873 _refLineModel->AddPoint(x,y1,z);
1874 _refLineModel->AddPoint(x,y2,z);
1875 _refLineModel->UpdateSpline();
1877 _refLineView->UpdateViewPoint(0);
1878 _refLineView->UpdateViewPoint(1);
1881 _refLineControl->SetActive(true);
1882 _refLineView->RefreshContour();
1886 //Hides the referenceLine
1887 void wxContourMainFrame::refLineHide()
1889 if (_refLineControl!=NULL)
1891 if (_refLineControl->GetActive())
1893 _refLineView->RemoveCompleteContourActor();
1894 _refLineControl->SetEditable(false);
1895 _refLineControl->SetActive(false);
1902 //Shows the referenceLine
1903 void wxContourMainFrame::refLineShow()
1905 if (_refLineControl!=NULL)
1907 if (_refLineControl->GetActive()==false)
1909 wxVtkBaseView * viewer2D = _theViewPanel->getWxVtkBaseView();
1911 _refLineView->SetModel( _refLineModel );
1912 _refLineView->SetWxVtkBaseView( viewer2D );
1913 _refLineView->SetRange( 2 );
1914 _refLineView->SetZ( 1200 );
1916 _refLineControl->SetModelView( _refLineModel , _refLineView );
1917 vtkInteractorStyleBaseView* style = (vtkInteractorStyleBaseView*)viewer2D->GetInteractorStyleBaseView();
1918 style->AddInteractorStyleMaracas( _refLineControl );
1919 _refLineControl->CreateNewManualContour();
1920 _refLineControl->SetActive(true);
1921 _refLineView->RefreshContour();
1928 void wxContourMainFrame::refLineChangeWidth(int width)
1930 _refLineView->SetWidthLine(width);
1931 _refLineView->RefreshContour();
1937 void wxContourMainFrame::onMirror()
1940 std::vector<std::string> currentSelection = _theViewPanel->getSelectedObjects();
1941 std::vector<std::string> filterCurrentSelection;
1943 std::vector<int> tempVector;
1944 _instantPanel->getInstant( tempVector );
1945 _performingOperation->reset();
1946 _performingOperation->setStartCommand( COPY );
1947 _performingOperation->setStartOperationInstantVector( tempVector );
1948 _performingOperation->setKeyNamesOperationElems( currentSelection );
1950 char theStartCommand = _performingOperation->getStartCommand();
1951 if ( theStartCommand == COPY )
1953 //JCP 20-10-08 Undo redo implementation
1955 //JCP 20-10-08 Undo redo implementation
1956 std::vector<int> tempVector;
1957 _instantPanel->getInstant( tempVector );
1958 _performingOperation->setEndOperationInstantVector ( tempVector );
1959 std::vector<std::string> elems = _performingOperation->getKeyNamesOperationElems();
1960 int i,size = elems.size();
1961 for( i=0; i<size; i++ )
1963 createMirrorContourOf( elems[i], tempVector, i>0 );
1967 //deleteContour( _refName );
1971 void wxContourMainFrame::onThreshold()
1973 int z = _theViewPanel->GetZ();
1976 vtkImageData * img = getImageData();
1977 img->GetScalarRange(range);
1979 int minTot = floor (range[0]);
1980 int maxTot = ceil (range[1]);
1983 _pannew->onThresholdInstantChange(minMax);
1984 int minVal = floor (minMax[0]);
1985 int maxVal = floor (minMax[1]);
1989 if (_imageReslicer==NULL)
1991 _imageReslicer = vtkImageReslice::New();
1992 _imageReslicer->SetInput( img );
1993 _imageReslicer->SetInformationInput(img);
1994 _imageReslicer->SetResliceAxesDirectionCosines(1,0,0, 0,1,0 ,0,0,1);
1995 _imageReslicer->SetOutputDimensionality(2);
1996 _imageReslicer->SetInterpolationModeToLinear();
1999 _imageReslicer->SetResliceAxesOrigin(0,0,z);
2001 img = _imageReslicer->GetOutput();
2003 img->UpdateInformation();
2005 wxVtkBaseView * baseView = _theViewPanel->getWxVtkBaseView();
2007 if (_thresholdTable==NULL)
2010 _thresholdTable = vtkLookupTable::New();
2011 _thresholdTable->SetNumberOfTableValues(maxTot+1);
2012 _thresholdTable->SetTableRange(range);
2013 _thresholdTable->SetAlphaRange(0, 1);
2014 _thresholdTable->SetValueRange(0, 1);
2015 _thresholdTable->SetSaturationRange(0, 0);
2016 _thresholdTable->SetRampToLinear( );
2019 //Assign a fake color for the upper image, and set the white as transparent
2021 for(i = minTot; i <= maxTot; i++)
2023 if( i >= minVal && i <= maxVal )
2025 _thresholdTable->SetTableValue(i, 1.0, 0.0, 0.0, 1);
2027 else if( i >= minTot && i < minVal )
2029 _thresholdTable->SetTableValue(i, 1.0, 1.0, 1.0, 0); //transparent
2031 else if( i > maxVal && i < maxTot )
2033 _thresholdTable->SetTableValue(i, 1.0, 1.0, 1.0, 0); //transparent
2037 _thresholdTable->SetTableValue(i, 1.0, 1.0, 1.0, 0); //transparent
2040 _thresholdTable->Build( );
2042 if (_thresholdMapper==NULL)
2044 _thresholdMapper = vtkImageMapToColors::New( );
2047 _thresholdMapper->SetLookupTable( _thresholdTable );
2048 _thresholdMapper->SetInput( img );
2050 if (_thresholdActor==NULL)
2052 _thresholdActor = vtkImageActor::New( );
2053 _thresholdActor->SetOpacity( 0.6 );
2054 _thresholdActor->InterpolateOn( );
2055 _thresholdActor->SetPosition( 0,0, 900-1 );
2058 _thresholdActor->SetInput( _thresholdMapper->GetOutput() );
2060 baseView->GetRenderer()->AddActor( _thresholdActor );
2061 _actorPresent = true;
2066 _imageReslicer->SetResliceAxesOrigin(0,0,z);
2067 img = _imageReslicer->GetOutput();
2069 img->UpdateInformation();
2071 //Assign a fake color for the upper image, and set the white as transparent
2073 for(i = minTot; i <= maxTot; i++)
2075 if( i >= minVal && i <= maxVal )
2077 _thresholdTable->SetTableValue(i, 1.0, 0.0, 0.0, 1);
2079 else if( i >= minTot && i < minVal )
2081 _thresholdTable->SetTableValue(i, 1.0, 1.0, 1.0, 0); //transparent
2083 else if( i > maxVal && i < maxTot )
2085 _thresholdTable->SetTableValue(i, 1.0, 1.0, 1.0, 0); //transparent
2089 _thresholdTable->SetTableValue(i, 1.0, 1.0, 1.0, 0); //transparent
2093 _thresholdTable->Build( );
2094 _thresholdMapper->SetLookupTable( _thresholdTable );
2095 _thresholdMapper->SetInput( img );
2096 _thresholdActor->SetInput( _thresholdMapper->GetOutput() );
2099 vtkImageViewer2* viewer = vtkImageViewer2::New();
2100 viewer->SetInput( upperImageActor->GetInput() );
2101 viewer->SetColorLevel((range[1]-range[0])/2);
2102 viewer->SetColorWindow(range[1]);
2103 viewer->GetRenderer()->AddActor( upperImageActor );
2106 _theViewPanel->RefreshInterface();
2110 void wxContourMainFrame::onThresholdChange()
2118 void wxContourMainFrame::onThresholdInterpolation(bool interpolate)
2120 if (_thresholdActor!=NULL)
2124 _thresholdActor->InterpolateOn( );
2129 _thresholdActor->InterpolateOff( );
2132 _theViewPanel->RefreshInterface();
2136 void wxContourMainFrame::onThresholdChangeOpacity (int opacity)
2140 _thresholdActor->SetOpacity(opacity*0.1);
2143 _theViewPanel->RefreshInterface();
2146 void wxContourMainFrame::onThresholdRemove()
2150 wxVtkBaseView * baseView = _theViewPanel->getWxVtkBaseView();
2151 baseView->GetRenderer()->RemoveActor( _thresholdActor );
2152 _actorPresent = false;
2155 _theViewPanel->RefreshInterface();
2158 void wxContourMainFrame::showAxis(bool show)
2160 _theViewPanel->SetVisibleAxis(show);
2161 _theViewPanel->Refresh();
2165 void wxContourMainFrame::onRigidPressed(){
2166 std::vector<std::string> currentSelection = _theViewPanel->getSelectedObjects();
2167 int elementsSelected = currentSelection.size();
2169 if ( elementsSelected >= 1 ){
2170 //JCP 20-10-08 Undo redo implementation
2172 //JCP 20-10-08 Undo redo implementation
2174 std::vector<int> tempVector;
2175 _instantPanel->getInstant( tempVector );
2176 Instant instant(&tempVector);
2178 int i , size=currentSelection.size();
2179 for ( i=0 ; i<size ; i++ )
2181 kernelManager->changeContourOfManager(currentSelection[i], &instant);
2186 void wxContourMainFrame::onWidthOfContour(double width){
2188 _theViewPanel->removeSceneContours();
2189 _theViewPanel->SetWidthContour(width);
2191 //_theViewPanel->getSceneManager()->SetWidthContour( width );
2196 int wxContourMainFrame::getColorWindow()
2200 vtkImageData * img = getImageData();
2201 img->GetScalarRange(range);
2203 std::cout<<"Val 1: "<<range[0]<<" Val 2: "<<range[1]<<std::endl;
2205 return (int)range[1];
2207 return _theViewPanel->getColorWindow();
2210 int wxContourMainFrame::getWindowLevel()
2214 vtkImageData * img = getImageData();
2215 img->GetScalarRange(range);
2217 std::cout<<"Val 1: "<<range[0]<<" Val 2: "<<range[1]<<std::endl;
2219 return (int)range[1];
2221 return _theViewPanel->getWindowLevel();
2224 void wxContourMainFrame::onBrigthnessColorWindowLevel(int colorwindow,int windowlevel){
2225 _theViewPanel->onBrigthnessColorWindowLevel(colorwindow, windowlevel);
2230 void wxContourMainFrame::onInterpolation(bool interpolate){
2231 _theViewPanel->onInterpolation(interpolate);
2235 void wxContourMainFrame::onChangeInstant(std::string name,int actual){
2236 _instantPanel->setConceptValue( name, actual );
2239 void wxContourMainFrame::resetAppend(){
2240 kernelManager->resetAppend();
2244 void wxContourMainFrame::onSpreadAdd(){
2245 std::vector<double> vecX;
2246 std::vector<double> vecY;
2247 std::vector<double> vecZ;
2248 _theViewPanel->GetPointsOfActualContour(&vecX , &vecY , &vecZ );
2250 std::vector<int> tempVector;
2251 _instantPanel->getInstant( tempVector );
2253 std::string val = kernelManager->onSpreadAdd(&vecX , &vecY , &vecZ, tempVector);
2255 interfMainPanel::getInstance()->appendStringSpread(val);
2259 void wxContourMainFrame::onSpreadGo(int type){
2261 //JCP 20-10-08 Undo redo implementation
2263 //JCP 20-10-08 Undo redo implementation
2266 std::vector<double> vecCtrlPointX;
2267 std::vector<double> vecCtrlPointY;
2268 std::vector<double> vecCtrlPointZ;
2272 std::vector<int> tempVector;
2273 _instantPanel->getInstant( tempVector );
2276 kernelManager->getMaxMinZ(&minZ,&maxZ);
2277 //JSTG_16-07-08_----------------------------------------------------------------
2278 //_contourPropagation->setInterpolationNumber(maxZ-minZ+1);
2279 kernelManager->CalculeSplinePropagation();
2281 double totalZ = maxZ-minZ+1;
2284 //--------------------------------------------------------------------
2285 for ( z=(int)minZ ; z<=(int)maxZ ; z++ )
2287 porcent = 100.0* (z-minZ)/totalZ;
2288 int numero = (int)(z-minZ+1)/(int)totalZ;
2289 std::string stringtemp = " "+kernelManager->intToString(porcent)+"% "+kernelManager->intToString(numero)+" "+kernelManager->intToString(z);
2291 interfMainPanel::getInstance()->setStringSpread(stringtemp);
2293 int typeofcontour = 1;
2294 std::string theName;
2295 manualContourModel* manModelContour = kernelManager->GetPoints(z, type, &vecCtrlPointX,&vecCtrlPointY,&vecCtrlPointZ, theName,typeofcontour, tempVector);
2297 if( manModelContour!=NULL ){
2298 double spc[3];//Si no hay imagen pero hay contornos que spacing se pone por default
2299 this->_theViewPanel->getSpacing(spc);
2300 //Adding the manualContourControler to interface objects structure
2301 //Adding the manualViewContour to interface objects structure
2302 //_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.
2303 _theViewPanel->configureViewControlTo( theName, manModelContour,spc,typeofcontour ) ;
2308 int numero = (int)(z-minZ+1)/(int)totalZ;
2309 std::string stringtemp = " "+kernelManager->intToString(porcent)+"% "+kernelManager->intToString(numero)+" "+kernelManager->intToString(z);
2311 interfMainPanel::getInstance()->setStringSpread(stringtemp);
2313 //RefreshInterface();
2316 void wxContourMainFrame::getInstantVector(std::vector<int>& tempVector){
2320 std::vector<std::string> wxContourMainFrame::getOutlinesName(int slide){
2321 std::vector<int> tempVector;
2322 _instantPanel->getInstant(tempVector);
2323 //Asignation of slide number should be different ex by name
2324 tempVector[1]=slide;
2325 return kernelManager->getOutlinesNameAtInstant(tempVector);
2328 void wxContourMainFrame::onInformationContourLabels(int typeContourGroup,int selection,int minimumZ,int maximumZ)
2330 int maxContourGroup = 0;
2332 ContourExtractData *contourextractdata = new ContourExtractData();
2334 contourextractdata ->SetTypeOperation( typeContourGroup % 3 );
2336 std::vector<manualContourModel*> lstManConMod;
2337 std::vector<manualContourModel*> lstManConModTmp;
2338 std::vector<manualContourModel*> lstManConModExp;
2339 std::vector<double> pLstValue;
2340 std::vector<double> pLstValuePosX;
2341 std::vector<double> pLstValuePosY;
2342 std::vector<double> pLstValuePosZ;
2345 int resultGrayRangeCount;
2348 double resultAverage;
2349 double resultStandardeviation;
2351 std::vector<int> tempVector;
2352 _instantPanel->getInstant( tempVector );
2354 vtkImageData *imagedata = _theViewPanel->getImageData();
2355 int sizeZ = _theViewPanel->GetImageDataSizeZ();
2357 int ii,sizeLstContourThings;
2367 if (selection==0 ) // actual slice
2369 std::vector<int> tempVector;
2370 _instantPanel->getInstant( tempVector );
2371 int actualSlice = tempVector[1];
2375 else if (selection==2 ) // All slices
2380 else if (selection==1 ) // slice range
2387 totalZ = maxZ-minZ+1;
2388 contourextractdata->SetImage( imagedata);
2391 for ( z=minZ ; z<=maxZ ; z++ )
2394 porcent = 100.0* (z-minZ)/totalZ;
2395 tmpString.Printf(_T(" %d %c %d/%d %d"), (int)porcent , 37 , z-minZ+1, (int)totalZ ,z);
2397 interfMainPanel::getInstance()->setStringInfoPanel(tmpString);
2398 //_staticTextInformation->SetLabel(tmpString);
2400 //Extraction data from contours of each slice
2401 contourextractdata->SetZtoBeAnalys(z);
2404 Instant instant(&tempVector);
2405 std::vector<ContourThing**> lstContourThings = kernelManager->getOutlinesAtInstant( &instant );
2406 sizeLstContourThings = lstContourThings.size();
2408 lstManConMod.clear();
2409 for (ii=0 ; ii<sizeLstContourThings ; ii++)
2411 ContourThing **contourthing = lstContourThings[ii];
2412 lstManConMod.push_back( (*contourthing)->getModel() );
2414 lstManConModExp = kernelManager->ExploseEachModel( lstManConMod );
2417 wxString tempString;
2418 tempString.Printf(_T("%d - %d"),z, sizeLstContourThings);
2419 interfMainPanel::getInstance()->setRowLabelInfoPanel(z, tempString);
2420 //_grid->SetRowLabelValue(z, tempString );
2422 int iContourGroup,sizeContourGroup;
2423 if (typeContourGroup==3) // contour separete
2425 sizeContourGroup=lstManConModExp.size();
2426 if ( maxContourGroup<sizeContourGroup )
2428 maxContourGroup=sizeContourGroup;
2430 } else { // contour AND OR XOR
2439 for( iContourGroup=0 ; iContourGroup<sizeContourGroup ; iContourGroup++ ){
2440 lstManConModTmp.clear();
2441 if (typeContourGroup==3) // contour separete
2443 lstManConModTmp.push_back( lstManConModExp[iContourGroup]);
2444 } else { // contour AND OR XOR
2445 lstManConModTmp = lstManConModExp;
2448 contourextractdata->SetLstManualContourModel( lstManConModTmp );
2451 pLstValuePosX.clear();
2452 pLstValuePosY.clear();
2453 pLstValuePosZ.clear();
2454 contourextractdata->GetValuesInsideCrown( &pLstValue,
2458 // Statistics of each slice.
2459 contourextractdata->Statistics( &pLstValue,
2462 &resultGrayRangeCount,
2467 &resultStandardeviation);
2469 if (interfMainPanel::getInstance()->getNumberColsInformationPanel()<_numberOfVariablesStatistics*(iContourGroup+1) )
2471 interfMainPanel::getInstance()->appendColsInformationPanel(_numberOfVariablesStatistics);
2474 tmpIntA=_numberOfVariablesStatistics*iContourGroup ;
2476 tempString.Printf(_T("%d"),resultSize);
2477 interfMainPanel::getInstance()->setCellValueInfoPanel(z, tmpIntA, tempString);
2479 tempString.Printf(_T("%d"),resultGrayRangeCount);
2480 interfMainPanel::getInstance()->setCellValueInfoPanel(z, tmpIntA+1, tempString);
2482 tempString.Printf(_T("%f"),resultMin);
2483 interfMainPanel::getInstance()->setCellValueInfoPanel(z, tmpIntA+2, tempString);
2485 tempString.Printf(_T("%f"),resultMax);
2486 interfMainPanel::getInstance()->setCellValueInfoPanel(z, tmpIntA+3, tempString);
2488 tempString.Printf(_T("%f"),resultAverage);
2489 interfMainPanel::getInstance()->setCellValueInfoPanel(z, tmpIntA+4, tempString);
2491 tempString.Printf(_T("%f"),resultStandardeviation);
2492 interfMainPanel::getInstance()->setCellValueInfoPanel(z, tmpIntA+5, tempString);
2495 } // for iContourGroup
2499 wxString tmpTitleString;
2501 for ( iTitleGroup=0 ; iTitleGroup<maxContourGroup ; iTitleGroup++ )
2503 tmpIntB =_numberOfVariablesStatistics*iTitleGroup;
2504 tmpTitleString.Printf(_T("%d-Size Data"),iTitleGroup);
2505 interfMainPanel::getInstance()->setColLableInfoPanel(tmpIntB + 0, tmpTitleString);
2507 interfMainPanel::getInstance()->setColLableInfoPanel(tmpIntB + 0, tmpTitleString );
2508 interfMainPanel::getInstance()->setColLableInfoPanel( tmpIntB + 1, _T("Size Range") );
2509 interfMainPanel::getInstance()->setColLableInfoPanel( tmpIntB + 2, _T("Min") );
2510 interfMainPanel::getInstance()->setColLableInfoPanel( tmpIntB + 3, _T("Max") );
2511 interfMainPanel::getInstance()->setColLableInfoPanel( tmpIntB + 4, _T("Average") );
2512 interfMainPanel::getInstance()->setColLableInfoPanel( tmpIntB + 5, _T("St.Dev.") );
2513 interfMainPanel::getInstance()->setColLableInfoPanel( tmpIntB + 6, _T(" ") );
2516 interfMainPanel::getInstance()->setStringInfoPanel( _T("") );
2517 delete contourextractdata;
2521 void wxContourMainFrame::onSaveResults(std::string directory,std::string namefile, std::string filename,
2522 int typeContourGroup, bool XYZValues, bool contourImage, bool statistics)
2526 SaveValuesXYZ( directory , namefile, typeContourGroup );
2531 vtkImageData * mask;
2532 vtkImageData * value;
2533 this->getMaskValue(&mask, &value, typeContourGroup);
2534 this->SaveImageResult( directory , namefile, mask, value);
2539 std::ostringstream name;
2540 name << filename << ".xls";
2543 FILE *pFile=fopen(name.str().c_str(),"w+");
2545 int sizeZ = _theViewPanel->GetImageDataSizeZ();
2548 int i,j,maxX,maxY=sizeZ;
2549 maxX= interfMainPanel::getInstance()->getNumberColsInformationPanel();//this->_grid->GetNumberCols();
2551 int iTitle,sizeTitle = (maxX / _numberOfVariablesStatistics);
2552 for ( iTitle=0; iTitle<sizeTitle ; iTitle++)
2554 // fprintf(pFile,"-- \t %d-Size \t SizeRange \t Min \t Max \t Ave \t StDv \t" , iTitle,tmpString.c_str() );
2555 fprintf(pFile,"-- \t %d-Size \t SizeRange \t Min \t Max \t Ave \t StDv \t" , iTitle );
2557 fprintf(pFile,"\n" );
2561 for ( j=0; j<maxY ; j++)
2563 fprintf(pFile,"%d\t" , j );
2564 for (i=0 ; i<maxX ; i++){
2565 tmpString = interfMainPanel::getInstance()->getCellValue(j, i);//_grid->GetCellValue( j , i );
2566 fprintf(pFile,"%s\t" , (const char *)(tmpString.mb_str()) );
2568 fprintf(pFile,"\n" );
2576 void wxContourMainFrame::SaveValuesXYZ(std::string directory,std::string namefile,int typeContourGroup)
2579 ContourExtractData *contourextractdata = new ContourExtractData();
2580 //int typeContourGroup = this->_radiolstboxContourGroup->GetSelection();
2581 contourextractdata ->SetTypeOperation( typeContourGroup % 3 );
2583 std::vector<manualContourModel*> lstManConMod;
2584 std::vector<manualContourModel*> lstManConModTmp;
2585 std::vector<manualContourModel*> lstManConModExp;
2586 std::vector<double> pLstValue;
2587 std::vector<double> pLstValuePosX;
2588 std::vector<double> pLstValuePosY;
2589 std::vector<double> pLstValuePosZ;
2591 std::vector<int> tempVector;
2592 _instantPanel->getInstant( tempVector );
2594 vtkImageData *imagedata = _theViewPanel->getSceneManager()->GetImageData();
2595 int sizeZ = _theViewPanel->getSceneManager()->GetImageDataSizeZ();
2597 int ii,sizeLstContourThings;
2604 minZ = 0;// _mbarrange->GetStart();
2605 maxZ = sizeZ;//_mbarrange->GetEnd();
2606 totalZ = maxZ-minZ+1;
2608 contourextractdata->SetImage( imagedata);
2611 for ( z=0 ; z<sizeZ ; z++)
2614 porcent = 100.0* (z-minZ)/totalZ;
2616 tmpString.Printf(_T("Saving Values"));
2617 tmpString.Printf(_T(" %d %c %d/%d %d"), (int)porcent , 37 , z-minZ+1, (int)totalZ ,z);
2618 interfMainPanel::getInstance()->setStringInfoPanel(tmpString);
2619 //_staticTextInformation->SetLabel(tmpString);
2622 //Extraction data from contours of each slice
2623 contourextractdata->SetZtoBeAnalys( z);
2626 Instant instant(&tempVector);
2627 std::vector<ContourThing**> lstContourThings = kernelManager->getOutlinesAtInstant(&instant);//this->_modelManager->getOutlinesAtInstant( &instant );
2628 sizeLstContourThings = lstContourThings.size();
2630 lstManConMod.clear();
2631 for (ii=0 ; ii<sizeLstContourThings ; ii++)
2633 ContourThing **contourthing = lstContourThings[ii];
2634 lstManConMod.push_back( (*contourthing)->getModel() );
2636 lstManConModExp = kernelManager->ExploseEachModel( lstManConMod );
2641 int iContourGroup,sizeContourGroup;
2642 if (typeContourGroup==3) // contour separete
2644 sizeContourGroup=lstManConModExp.size();
2645 } else { // contour AND OR XOR
2649 for( iContourGroup=0 ; iContourGroup<sizeContourGroup ; iContourGroup++ ){
2650 lstManConModTmp.clear();
2651 if (typeContourGroup==3) // contour separete
2653 lstManConModTmp.push_back( lstManConModExp[iContourGroup]);
2654 } else { // contour AND OR XOR
2655 lstManConModTmp = lstManConModExp;
2658 contourextractdata->SetLstManualContourModel( lstManConModTmp );
2661 pLstValuePosX.clear();
2662 pLstValuePosY.clear();
2663 pLstValuePosZ.clear();
2664 contourextractdata->GetValuesInsideCrown( &pLstValue,
2669 std::string temp = directory + "/" + namefile + "-slice";
2670 temp = temp + kernelManager->intToString(z) + "-cont" + kernelManager->intToString(iContourGroup);
2671 temp = temp + ".txt";
2673 // LG 14/01/09 : using crea
2674 wxString filename = crea::std2wx(temp);
2675 /*filename.Printf(_T("%s"),directory.c_str());
2676 filename.append(_T("\\"));
2677 filename.append(_T("%s"),namefile.c_str());
2678 filename.append(_T("-slice"));
2679 filename.append(_T("%d"),z);
2680 filename.append(_T("-cont"));
2681 filename.append(_T("%d"),iContourGroup);
2682 filename.append(_T(".txt"));*/
2683 // filename.Printf(temp.c_str());
2687 FILE *pFile=fopen((const char *)filename.mb_str(),"w+");
2688 fprintf(pFile,"value \t x \t y \t z\n" );
2689 int iLstValue,sizeLstValue=pLstValue.size();
2690 for (iLstValue=0 ; iLstValue<sizeLstValue ; iLstValue++ )
2692 fprintf(pFile,"%f\t %f\t %f\t %f\n", (float)pLstValue[iLstValue] , (float)pLstValuePosX[iLstValue], (float)pLstValuePosY[iLstValue], (float)z );
2695 } // for iContourGroup
2697 interfMainPanel::getInstance()->setStringInfoPanel(_T(""));
2698 //_staticTextInformation->SetLabel( _T("") );
2699 delete contourextractdata;
2702 void wxContourMainFrame::getMaskValue(vtkImageData ** mask,vtkImageData ** value,int typeContourGroup){
2704 ContourExtractData *contourextractdata = new ContourExtractData( true );
2705 //int typeContourGroup = this->_radiolstboxContourGroup->GetSelection();
2706 if (typeContourGroup==3)
2710 contourextractdata ->SetTypeOperation( typeContourGroup % 3 );
2712 std::vector<manualContourModel*> lstManConMod;
2713 std::vector<manualContourModel*> lstManConModTmp;
2714 std::vector<manualContourModel*> lstManConModExp;
2716 std::vector<int> tempVector;
2717 _instantPanel->getInstant( tempVector );
2719 vtkImageData *imagedata = _theViewPanel->getImageData();
2720 int sizeZ = _theViewPanel->GetImageDataSizeZ();
2722 int ii,sizeLstContourThings;
2731 minZ = 0;// _mbarrange->GetStart();
2732 maxZ = sizeZ;//_mbarrange->GetEnd();
2733 totalZ = maxZ-minZ+1;
2735 contourextractdata->SetImage( imagedata);
2738 for ( z=0 ; z<sizeZ ; z++)
2741 porcent = 100.0* (z-minZ)/totalZ;
2742 tmpString.Printf(_T("Saving Values"));
2743 tmpString.Printf(_T("%d %c %d/%d %d"), (int)porcent , 37 , z-minZ+1, (int)totalZ ,z);
2744 interfMainPanel::getInstance()->setStringInfoPanel(tmpString);
2746 //Extraction data from contours of each slice
2747 contourextractdata->SetZtoBeAnalys( z);
2750 Instant instant(&tempVector);
2751 std::vector<ContourThing**> lstContourThings = kernelManager->getOutlinesAtInstant( &instant );
2752 sizeLstContourThings = lstContourThings.size();
2754 lstManConMod.clear();
2755 for (ii=0 ; ii<sizeLstContourThings ; ii++)
2757 ContourThing **contourthing = lstContourThings[ii];
2758 lstManConMod.push_back( (*contourthing)->getModel() );
2760 lstManConModExp = kernelManager->ExploseEachModel( lstManConMod );
2763 int iContourGroup,sizeContourGroup;
2764 if (typeContourGroup==3) // contour separete
2766 sizeContourGroup=lstManConModExp.size();
2767 } else { // contour AND OR XOR
2771 for( iContourGroup=0 ; iContourGroup<sizeContourGroup ; iContourGroup++ ){
2772 lstManConModTmp.clear();
2773 if (typeContourGroup==3) // contour separete
2775 lstManConModTmp.push_back( lstManConModExp[iContourGroup]);
2776 } else { // contour AND OR XOR
2777 lstManConModTmp = lstManConModExp;
2780 contourextractdata->SetLstManualContourModel( lstManConModTmp );
2781 contourextractdata->CalculateImageResult(); // with actual Z
2783 } // for iContourGroup
2786 (*value) = contourextractdata->GetVtkImageValueResult();
2787 (*mask) = contourextractdata->GetVtkImageMaskResult();
2788 delete contourextractdata;
2791 void wxContourMainFrame::SaveImageResult(std::string directory,std::string namefile, vtkImageData* mask,vtkImageData* value)
2794 std::string temp = directory + "/" + namefile + "-Value.mhd";
2796 wxString filename = crea::std2wx(temp);
2798 // filename.Printf(_T(temp.c_str()));
2799 //filename.Printf(_T("%s\\%s-Value.mhd",directory.c_str(),namefile.c_str(),z);
2800 /*filename.Printf(_T("%s"),directory.c_str());
2801 filename.append(_T("\\"));
2802 filename.append(_T("%s"),namefile.c_str());
2803 filename.append(_T("-Value.mhd"));*/
2806 vtkMetaImageWriter *writerValueImage = vtkMetaImageWriter::New( );
2807 writerValueImage->SetInput( value );
2808 writerValueImage->SetFileName( (const char *)filename.mb_str() );
2809 writerValueImage->SetFileDimensionality( 3 );
2810 writerValueImage->Write( );
2813 // filename.Printf("%s\\%s-Mask.mhd",directory.c_str(),namefile.c_str(),z);
2814 temp = directory + "/" + namefile + "-Mask.mhd";
2816 // LG 14/01/09 : using crea
2817 filename = crea::std2wx(temp);
2818 // filename.Printf(_T(temp.c_str()));
2820 /*filename.Printf(_T("%s"),directory.c_str());
2821 filename.append(_T("\\"));
2822 filename.append(_T("%s"),namefile.c_str());
2823 filename.append(_T("-Mask.mhd"));*/
2825 vtkMetaImageWriter *writerMaskImage = vtkMetaImageWriter::New( );
2826 writerMaskImage->SetInput( mask );
2827 writerMaskImage->SetFileName( (const char *)filename.mb_str() );
2828 writerMaskImage->SetFileDimensionality( 3 );
2829 writerMaskImage->Write( );
2831 interfMainPanel::getInstance()->setStringInfoPanel( _T("") );
2837 void wxContourMainFrame::onChangeInstantInstantPanel(std::string name,int value, int minshow, int maxshow){
2838 if( name.compare( _theViewPanel->getVerticalConceptName() ) == 0){
2839 _theViewPanel->setActualVertical( value);
2841 else if( name.compare( _theViewPanel->getHorizontalConceptName() ) == 0|| _instantPanel->getIfConceptCheckedAt( name, 0 ) ) {
2842 _theViewPanel->setHorizontalConcept( name, minshow, maxshow, minshow, maxshow, value);
2848 void wxContourMainFrame::onSnakePressed(){
2849 std::vector<double> vecX;
2850 std::vector<double> vecY;
2851 std::vector<double> vecZ;
2852 _theViewPanel->GetPointsOfActualContour( &vecX , &vecY , &vecZ );
2854 if (vecX.size()!=0){
2855 std::vector<int> tempVector;
2856 _instantPanel->getInstant( tempVector );
2857 int i,size=vecZ.size();
2858 int actualSlice = tempVector[1];
2859 for ( i=0 ; i<size ; i++ )
2861 vecZ[i] = actualSlice;
2864 wxDialog* dialog = new wxDialog(this, -1, wxString(_T("Snake")));
2865 wxPanel* panel = new wxPanel(dialog,-1);
2866 // wxStaticText* sttext = new wxStaticText(panel, -1, wxString(_T("Panel para snake")));
2867 new wxStaticText(panel, -1, wxString(_T("Panel para snake")));
2868 dialog->ShowModal();
2873 void wxContourMainFrame::saveFileWithContoursAutomatique(){
2874 std::string filename = kernelManager->getCurrentFileName();
2875 if(filename.compare("")!=0){
2876 saveFileWithContours(filename);
2881 void wxContourMainFrame::ShowToolsPanel(bool show){
2882 _pannew->Show(show);