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(imgs);
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.1
758 std::string version(tmp);
762 openContours(pFile,false);
763 if (version!="1.0.0"){
764 openContours(pFile,true);
769 //_theViewPanel->getSceneManager()->removeSceneContours();
774 void wxContourMainFrame::onLoad(){
776 wxFileDialog dialog(NULL, _T("Choose a file"), _T(""), _T(""), _T("*.roi"), wxOPEN );
777 if (dialog.ShowModal() == wxID_OK)
779 std::string fileNameContourROI = (const char *)(dialog.GetPath().mb_str());
780 FILE *pFile=fopen(fileNameContourROI.c_str(),"r+");
782 fscanf(pFile,"%s",tmp); // --CreaContour--
784 fscanf(pFile,"%s",tmp); // Version
785 fscanf(pFile,"%s",tmp); // 1.0.1 || 1.0.0
786 std::string version(tmp);
789 if (version=="1.0.1")
791 openContours(pFile,false);
795 else if (version=="1.0.0")
797 openContours(pFile,true);
799 // _theViewPanel->getSceneManager()->openFileWithContours(ff);
803 _theViewPanel->getSceneManager()->removeSceneContours();
808 void wxContourMainFrame::onSave(){
809 wxFileDialog dialog(NULL, _T("Choose a file"), _T(""), _T(""), _T("*.roi"), wxSAVE );
810 if (dialog.ShowModal() == wxID_OK)
812 std::string fileNameContourROI = (const char *)(dialog.GetPath().mb_str());
813 kernelManager->setCurrentFileName(fileNameContourROI);
814 saveFileWithContours( fileNameContourROI );
819 void wxContourMainFrame::saveFileWithContours( std::string filename )
822 FILE *pFile=fopen(filename.c_str(),"w+");
823 std::vector< std::string > lstNameThings;
824 int i,sizeLstNameThings;
826 fprintf(pFile,"--CreaContour--\n");
827 fprintf(pFile,"Version %s\n", "1.0.1" );
830 lstNameThings = kernelManager->GetLstNameThings();
831 sizeLstNameThings = lstNameThings.size();
832 fprintf(pFile,"NumberOfContours %d\n", sizeLstNameThings );
834 vtkImageData *image = _images[0];
837 image->GetDimensions(dimRange);
839 fprintf(pFile,"ImageDimensions %d %d %d\n", dimRange[0], dimRange[1], dimRange[2] );
842 image->GetSpacing(spaRange);
844 fprintf(pFile,"ImageSpacing %f %f %f\n", spaRange[0], spaRange[1], spaRange[2] );
846 for (i=0 ; i<sizeLstNameThings ; i++)
848 kernelManager->SaveThingName( pFile, lstNameThings[i] );
849 _theViewPanel->getSceneManager()->SaveThingName( pFile, lstNameThings[i] );
852 //-- Contours Statics
853 lstNameThings = kernelManager->GetLstNameThingsStatic();
854 sizeLstNameThings = lstNameThings.size();
855 fprintf(pFile,"NumberOfContoursStatic %d\n", sizeLstNameThings );
856 for (i=0 ; i<sizeLstNameThings ; i++)
858 kernelManager->SaveThingName( pFile, lstNameThings[i] );
859 _theViewPanel->getSceneManager()->SaveThingName( pFile, lstNameThings[i] );
864 //AD:02-06-09: TODO: Adjust spacing and dimensions to Rois comming from images with different specifications
865 void wxContourMainFrame::openContours( FILE *pFile, bool staticContour ){
867 fscanf(pFile,"%s",tmp); // NumberOfContours
868 fscanf(pFile,"%s",tmp); // ##
869 int numberOfContours = atoi(tmp);
871 std::vector<int> instantVector;
872 int typeContourModel;
873 manualContourModel *manModelContour;
876 vtkImageData *image = _images[0];
878 image->GetDimensions(imageDim);
880 image->GetSpacing(imageSpac);
885 fscanf(pFile,"%s",tmp); // ImageDimensions
886 fscanf(pFile,"%s",tmp); // X
887 tempDim[0] = atoi(tmp);
888 fscanf(pFile,"%s",tmp); // Y
889 tempDim[1] = atoi(tmp);
890 fscanf(pFile,"%s",tmp); // Z
891 tempDim[2] = atoi(tmp);
893 fscanf(pFile,"%s",tmp); // ImageSpacing
894 fscanf(pFile,"%s",tmp); // X
895 tempSpac[0] = atof(tmp);
896 fscanf(pFile,"%s",tmp); // Y
897 tempSpac[1] = atof(tmp);
898 fscanf(pFile,"%s",tmp); // Z
899 tempSpac[2] = atof(tmp);
901 bool compatible = true;
903 //Compare Spacing and Dims in X and Y (Necessary in Z?)
904 if (imageDim[0]!=tempDim[0] || imageDim[1]!=tempDim[1] ||
905 imageSpac[0]!=tempSpac[0] || imageSpac[1]!=tempSpac[1])
910 if (compatible==true)
913 for (i=0;i<numberOfContours;i++)
915 instantVector.clear();
916 fscanf(pFile,"%s",tmp); // Instant
918 fscanf(pFile,"%s",tmp); // 1
919 instantVector.push_back( atoi(tmp) );
920 fscanf(pFile,"%s",tmp); // 2
921 instantVector.push_back( atoi(tmp) );
922 fscanf(pFile,"%s",tmp); // 3
923 instantVector.push_back( atoi(tmp) );
924 fscanf(pFile,"%s",tmp); // 4
925 instantVector.push_back( atoi(tmp) );
926 fscanf(pFile,"%s",tmp); // 5
927 instantVector.push_back( atoi(tmp) );
928 fscanf(pFile,"%s",tmp); // 6
929 instantVector.push_back( atoi(tmp) );
932 fscanf(pFile,"%s",tmp); // TypeContourModel
933 fscanf(pFile,"%s",tmp); // ##
934 typeContourModel = atoi(tmp);
936 manModelContour = kernelManager->factoryManualContourModel(typeContourModel);
937 manModelContour->Open(pFile);
939 fscanf(pFile,"%s",tmp); // TypeView
940 fscanf(pFile,"%s",tmp); // ##
941 typeView = atoi(tmp);
950 theName = kernelManager->createOutline( manModelContour, instantVector );
951 bool addedModel = theName.compare("") != 0;
954 double spc[3];//Si no hay imagen pero hay contornos que spacing se pone por default
955 _theViewPanel->getSpacing(spc);
956 //Adding the manualContourControler to interface objects structure
957 //Adding the manualViewContour to interface objects structure
958 //_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.
959 _theViewPanel->getSceneManager()->configureViewControlTo( theName, manModelContour,spc , typeView) ;
962 if (staticContour==true)
964 Instant instant(&instantVector);
965 kernelManager->changeContourOfManager( theName , &instant );
968 }// for numberOfContours
971 else if (compatible==false)
973 wxMessageBox(_T("The actual image is not compatible with the selected Roi file"), _T("Error"), wxICON_ERROR | wxOK);
977 void wxContourMainFrame::RefreshInterface(){
979 _theViewPanel->RefreshInterface();
980 //wxVtk2DBaseView *wxvtk2dbaseview = (wxVtk2DBaseView*)this->_theViewPanel->getWxVtkBaseView();
981 //wxvtk2dbaseview->Refresh();
984 vtkImageData* wxContourMainFrame::getImageData(){
985 return _theViewPanel->getImageData();
988 void wxContourMainFrame::onSegmentationOneSliceITK(wxString distance, wxString sigma, wxString alfa, wxString beta, wxString propagation, wxString iterations, wxString inflation)
990 //JCP 20-10-08 Undo redo implementation
992 //JCP 20-10-08 Undo redo implementation
995 int x = _theViewPanel->GetX();
996 int y = _theViewPanel->GetY();
997 int z = _theViewPanel->GetZ();
998 SegmentationOneSliceITK( x,y,z,distance, sigma, alfa, beta, propagation, iterations, inflation);
1002 void wxContourMainFrame::SegmentationOneSliceITK(int x, int y, int z, wxString distanc, wxString sigm, wxString alf, wxString bet, wxString prop, wxString iter, wxString inflation)
1004 int typeofcontour = 1;
1006 vtkImageData *imagedata = getImageData();
1008 //Tipo de pixeles a utilizar internamente en ITK
1009 typedef float InternalPixelType;
1010 const unsigned int Dimension = 2;
1011 typedef itk::Image< InternalPixelType, Dimension > InternalImageType;
1013 //Tipo de pixeles de salida 1
1014 typedef unsigned char OutputPixelType;
1015 typedef itk::Image< OutputPixelType, Dimension > OutputImageType;
1017 //Tipo de pixeles de salida 2
1018 typedef unsigned short OutputPixelType2;
1019 typedef itk::Image< OutputPixelType2, Dimension > OutputImageType2;
1021 //DefiniciÛn del thresholder
1022 typedef itk::BinaryThresholdImageFilter<
1024 OutputImageType > ThresholdingFilterType;
1026 //DefiniciÛn del primer filtro de conversiÛn de pixeles
1027 typedef itk::CastImageFilter<
1028 OutputImageType, OutputImageType2 > CastFilterType;
1030 //DefiniciÛn del segundo tipo de conversiÛn de pixeles
1031 typedef itk::CastImageFilter<
1032 OutputImageType2, InternalImageType > CastFilterType2;
1034 //Tercer tipo de conversiÛn
1035 typedef itk::RescaleIntensityImageFilter<
1037 OutputImageType > CastFilterType3;
1039 //Cuarto tipo de conversiÛn
1040 typedef itk::RescaleIntensityImageFilter<
1042 OutputImageType > CastFilterType4;
1044 ThresholdingFilterType::Pointer thresholder = ThresholdingFilterType::New();
1046 thresholder->SetLowerThreshold( 0.0 );
1047 thresholder->SetUpperThreshold( 128 );
1049 thresholder->SetOutsideValue( 255 );
1050 thresholder->SetInsideValue( 0 );
1052 //DefinciÛn de conexiÛnes entre VTK e ITK y el writer
1053 typedef itk::VTKImageToImageFilter<OutputImageType2> ConnectorType;
1054 typedef itk::ImageToVTKImageFilter<OutputImageType> ConnectorType2;
1055 typedef itk::ImageFileWriter< OutputImageType > WriterType;
1057 ConnectorType::Pointer connector= ConnectorType::New();
1058 ConnectorType2::Pointer connector2= ConnectorType2::New();
1061 CastFilterType::Pointer filter=CastFilterType::New();
1062 CastFilterType2::Pointer filter2=CastFilterType2::New();
1064 connector->SetInput( imagedata );
1065 filter2->SetInput(connector->GetOutput());
1067 typedef itk::CurvatureAnisotropicDiffusionImageFilter<
1069 InternalImageType > SmoothingFilterType;
1071 SmoothingFilterType::Pointer smoothing = SmoothingFilterType::New();
1073 typedef itk::GradientMagnitudeRecursiveGaussianImageFilter<
1075 InternalImageType > GradientFilterType;
1077 typedef itk::SigmoidImageFilter<
1079 InternalImageType > SigmoidFilterType;
1081 GradientFilterType::Pointer gradientMagnitude = GradientFilterType::New();
1083 SigmoidFilterType::Pointer sigmoid = SigmoidFilterType::New();
1085 sigmoid->SetOutputMinimum( 0.0 );
1086 sigmoid->SetOutputMaximum( 255.0 );
1089 typedef itk::FastMarchingImageFilter<
1091 InternalImageType > FastMarchingFilterType;
1094 FastMarchingFilterType::Pointer fastMarching = FastMarchingFilterType::New();
1096 typedef itk::GeodesicActiveContourLevelSetImageFilter< InternalImageType,
1097 InternalImageType > GeodesicActiveContourFilterType;
1098 GeodesicActiveContourFilterType::Pointer geodesicActiveContour =
1099 GeodesicActiveContourFilterType::New();
1101 typedef itk::ZeroCrossingImageFilter<
1103 InternalImageType > ZeroCrossingFilterType;
1104 ZeroCrossingFilterType::Pointer zeroCrossing =
1105 ZeroCrossingFilterType::New();
1107 const double propagationScaling = atof( crea::wx2std(prop).c_str() );
1109 geodesicActiveContour->SetPropagationScaling( propagationScaling );
1110 geodesicActiveContour->SetCurvatureScaling( 1.0 );
1111 geodesicActiveContour->SetAdvectionScaling( 1.0 );
1113 geodesicActiveContour->SetMaximumRMSError( 0.02 );
1114 int it=atoi( crea::wx2std(iter).c_str() );
1115 geodesicActiveContour->SetNumberOfIterations( it );
1117 smoothing->SetInput( filter2->GetOutput() );
1118 gradientMagnitude->SetInput( smoothing->GetOutput() );
1119 sigmoid->SetInput( gradientMagnitude->GetOutput() );
1120 fastMarching->SetInput( sigmoid->GetOutput() );
1121 geodesicActiveContour->SetInput( fastMarching->GetOutput() );
1122 geodesicActiveContour->SetFeatureImage( sigmoid->GetOutput() );
1124 zeroCrossing->SetInput( geodesicActiveContour->GetOutput() );
1125 //thresholder->SetInput( zeroCrossing->GetOutput() );
1126 thresholder->SetInput( geodesicActiveContour->GetOutput() );
1127 connector2->SetInput( thresholder->GetOutput() );
1130 smoothing->SetTimeStep( 0.125 );
1131 smoothing->SetNumberOfIterations( 5 );
1132 smoothing->SetConductanceParameter( 9.0 );
1135 const double sigma = atof( crea::wx2std(sigm).c_str() );
1136 gradientMagnitude->SetSigma( sigma );
1138 const double alpha = atof( crea::wx2std(alf).c_str() );
1139 const double beta = atof( crea::wx2std(bet).c_str() );
1141 sigmoid->SetAlpha( alpha );
1142 sigmoid->SetBeta( beta );
1144 typedef FastMarchingFilterType::NodeContainer NodeContainer;
1145 typedef FastMarchingFilterType::NodeType NodeType;
1147 NodeContainer::Pointer seeds = NodeContainer::New();
1149 InternalImageType::IndexType seedPosition;
1150 seedPosition[0] = x;
1151 seedPosition[1] = y;
1153 const double initialDistance = atof( crea::wx2std(distanc).c_str() );
1157 const double seedValue = - initialDistance;
1159 node.SetValue( seedValue );
1160 node.SetIndex( seedPosition );
1162 seeds->Initialize();
1163 seeds->InsertElement( 0, node );
1165 fastMarching->SetTrialPoints( seeds );
1167 fastMarching->SetSpeedConstant( 1.0 );
1169 fastMarching->SetOutputSize(
1170 connector->GetOutput()->GetBufferedRegion().GetSize() );
1172 fastMarching->SetStoppingValue( 800 );
1176 connector2->Update();
1177 vtkImageData *idata = connector2->GetOutput();
1179 vtkMarchingContourFilter* cntVTK = vtkMarchingContourFilter::New( );
1181 cntVTK->SetInput( idata );
1183 cntVTK->SetNumberOfContours( 1 );
1184 cntVTK->SetValue( 0, 255 );
1186 cntVTK->UpdateInformation();
1188 vtkCleanPolyData* cpd = vtkCleanPolyData::New( );
1189 cpd->SetInput( cntVTK->GetOutput( ) );
1191 cpd->UpdateInformation();
1193 vtkPolyDataConnectivityFilter* conn = vtkPolyDataConnectivityFilter::New( );
1194 conn->SetExtractionModeToLargestRegion( );
1195 conn->SetInput( cpd->GetOutput( ) );
1197 conn->UpdateInformation();
1199 vtkStripper* vtkstripper = vtkStripper::New( );
1200 vtkstripper->SetInput( conn->GetOutput() );
1201 vtkstripper->Update();
1202 vtkstripper->UpdateInformation();
1205 vtkPolyData* polyDataResult = cntVTK->GetOutput();
1206 //std::cout<<"Points "<<polyDataResult->GetNumberOfPoints()<<std::endl;
1207 polyDataResult->Update( );
1208 polyDataResult->UpdateInformation();
1213 myfile.open ("C:/Creatis/example.txt");
1215 polyDataResult->Print(myfile);
1216 myfile << "-------------------------------------\n";
1217 polyDataResult->GetLines()->Print(myfile);
1225 //--Calculating control points
1227 std::vector<double> vecX;
1228 std::vector<double> vecY;
1229 std::vector<double> vecXo;
1230 std::vector<double> vecYo;
1231 std::vector<double>::iterator vecXoi;
1232 std::vector<double>::iterator vecYoi;
1233 std::vector<double> vecZ;
1235 std::vector<double> vecCtrlPointX;
1236 std::vector<double> vecCtrlPointY;
1237 std::vector<double> vecCtrlPointZ;
1243 int ii,size=polyDataResult->GetNumberOfPoints();
1245 myfile.open ("C:/Creatis/example2.txt");
1247 size=polyDataResult->GetNumberOfPoints();
1248 for (ii=0;ii<size;ii++)
1255 p = polyDataResult->GetPoint(ii);
1258 /*if(fabs(yAct-y)>20)
1260 if((xAct-x)>1 || (xAct-x)<-1)
1262 vecX.push_back( p[0] );
1263 vecY.push_back( p[1] );
1264 myfile <<p[0]<<","<<p[1]<<"\n";
1265 std::cout<<" x Anterior "<<xAct<<" x actual "<<x<<std::endl;
1266 std::cout<<" y Anterior "<<yAct<<" y actual "<<y<<std::endl;
1267 std::cout<<" x "<<p[0]<<" y "<<p[1]<<std::endl;
1268 vecZ.push_back( 900 );
1274 vecXo.push_back(p[0]);
1275 vecYo.push_back(p[1]);
1279 else*/ if(fabs(xAct-x)>11)
1281 vecXo.push_back(p[0]);
1282 vecYo.push_back(p[1]);
1286 vecX.push_back( p[0] );
1287 myfile <<p[0]<<","<<p[1]<<"\n";
1288 //std::cout<<" x Anterior "<<xAct<<" x actual "<<x<<std::endl;
1289 //std::cout<<" y Anterior "<<yAct<<" y actual "<<y<<std::endl;
1290 //std::cout<<" x "<<p[0]<<" y "<<p[1]<<std::endl;
1291 vecY.push_back( p[1] );
1292 vecZ.push_back( 900 );
1300 while(!vecXo.empty())
1302 vecX.push_back(vecXo.back());
1303 //std::cout<<" x Siguiente "<<vecXo.back();
1305 vecZ.push_back( 900 );
1307 while(!vecYo.empty())
1309 vecY.push_back(vecYo.back());
1314 /*for(int l=0;l<vecX.size();l++)
1318 vecXo.push_back(p[0]);
1319 vecYo.push_back(p[1]);
1330 ExtractControlPoints2D *extractcontrolpoints2d = new ExtractControlPoints2D();
1332 extractcontrolpoints2d->SetContour( &vecX , &vecY , &vecZ );
1336 extractcontrolpoints2d->GetInitialControlPoints( &vecCtrlPointX , &vecCtrlPointY , &vecCtrlPointZ );
1338 else if (method==1){
1339 extractcontrolpoints2d->GetControlPoints( &vecCtrlPointX , &vecCtrlPointY , &vecCtrlPointZ );
1341 else if (method==2){
1342 extractcontrolpoints2d->SetSamplingControlPoints( 15 );
1343 extractcontrolpoints2d->GetSamplingControlPoints( &vecCtrlPointX , &vecCtrlPointY , &vecCtrlPointZ );
1345 //--Adding contour to the system
1347 std::vector<int> actualInstantVector;
1348 _instantPanel->getInstant( actualInstantVector );
1349 actualInstantVector[1]=z;
1351 int j,sizeCtrPt = vecCtrlPointX.size();
1353 manualContourModel *manModelContour = kernelManager->factoryManualContourModel( typeofcontour );
1354 manModelContour->SetNumberOfPointsSpline( ((sizeCtrPt/100)+1)*100 );
1356 for (j=0 ; j<sizeCtrPt ; j++)
1358 manModelContour->AddPoint( vecCtrlPointX[j] , vecCtrlPointY[j] , vecCtrlPointZ[j] );
1360 std::string theName;
1361 //theName = _modelManager->createOutline( manModelContour, actualInstantVector );
1362 theName = kernelManager->createOutline( manModelContour, actualInstantVector );
1363 bool addedModel = theName.compare("") != 0;
1366 double spc[3];//Si no hay imagen pero hay contornos que spacing se pone por default
1367 _theViewPanel->getSpacing(spc);
1368 //Adding the manualContourControler to interface objects structure
1369 //Adding the manualViewContour to interface objects structure
1370 //_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.
1371 _theViewPanel->configureViewControlTo(theName, manModelContour, spc, typeofcontour);
1372 //_theViewPanel->getSceneManager()->configureViewControlTo( theName, manModelContour,spc, typeofcontour ) ;
1378 WriterType::Pointer writer = WriterType::New();
1379 CastFilterType3::Pointer caster = CastFilterType3::New();
1381 caster->SetInput( gradientMagnitude->GetOutput() );
1382 writer->SetInput( caster->GetOutput() );
1383 writer->SetFileName("Gradient Magnitude.png");
1384 caster->SetOutputMinimum( 0 );
1385 caster->SetOutputMaximum( 255 );
1388 CastFilterType3::Pointer caster2 = CastFilterType3::New();
1389 WriterType::Pointer writer2 = WriterType::New();
1391 caster2->SetInput( sigmoid->GetOutput() );
1392 writer2->SetInput( caster2->GetOutput() );
1393 writer2->SetFileName("Sigmoid.png");
1394 caster2->SetOutputMinimum( 0 );
1395 caster2->SetOutputMaximum( 255 );
1398 CastFilterType3::Pointer caster3 = CastFilterType3::New();
1399 WriterType::Pointer writer3 = WriterType::New();
1401 caster3->SetInput( fastMarching->GetOutput() );
1402 writer3->SetInput( caster3->GetOutput() );
1403 writer3->SetFileName("FastMarching.bmp");
1404 caster3->SetOutputMinimum( 0 );
1405 caster3->SetOutputMaximum( 255 );
1408 CastFilterType3::Pointer caster4 = CastFilterType3::New();
1409 WriterType::Pointer writer4 = WriterType::New();
1411 caster4->SetInput( geodesicActiveContour->GetOutput() );
1412 writer4->SetInput( caster4->GetOutput() );
1413 writer4->SetFileName("GeodesicActiveContour.png");
1414 caster4->SetOutputMinimum( 0 );
1415 caster4->SetOutputMaximum( 255 );
1418 CastFilterType3::Pointer caster5 = CastFilterType3::New();
1419 WriterType::Pointer writer5 = WriterType::New();
1421 caster5->SetInput( zeroCrossing->GetOutput() );
1422 writer5->SetInput( caster5->GetOutput() );
1423 writer5->SetFileName("ZeroCrossing.bmp");
1424 caster5->SetOutputMinimum( 0 );
1425 caster5->SetOutputMaximum( 255 );
1428 catch( itk::ExceptionObject & excep )
1430 std::cerr << "Exception caught !" << std::endl;
1431 std::cerr << excep << std::endl;
1435 void wxContourMainFrame::onSegmentationOneSlice(int isovalue,int sampling,int method){
1437 //JCP 20-10-08 Undo redo implementation
1439 //JCP 20-10-08 Undo redo implementation
1442 int x = _theViewPanel->GetX();
1443 int y = _theViewPanel->GetY();
1444 int z = _theViewPanel->GetZ();
1445 SegmentationOneSlice( x,y,z,isovalue, sampling, method );
1450 void wxContourMainFrame::SegmentationOneSlice( int x, int y, int z, int isovalue, int sampling, int method )
1452 int typeofcontour = 1;
1453 //--Extracting Contour
1454 //vtkImageData *imagedata = _theViewPanel->getSceneManager()->GetImageData();
1455 vtkImageData *imagedata = getImageData();
1456 // double *range = imagedata->GetScalarRange();
1459 vtkImageReslice *imageReslice = vtkImageReslice::New();
1462 // imagedata->GetSpacing(spc);
1467 imageReslice->SetInput( imagedata );
1468 imageReslice->SetInformationInput(imagedata);
1469 imageReslice->SetResliceAxesDirectionCosines(1,0,0, 0,1,0 ,0,0,1);
1470 imageReslice->SetResliceAxesOrigin(0,0,z);
1471 imageReslice->SetOutputDimensionality(2);
1472 imageReslice->SetInterpolationModeToLinear();
1474 imagedata = imageReslice->GetOutput();
1475 imagedata->Update();
1476 imagedata->UpdateInformation();
1478 vtkContourFilter* cntVTK = vtkContourFilter::New( );
1479 cntVTK->SetInput( imagedata );
1481 cntVTK->SetNumberOfContours( 1 );
1482 //cntVTK->SetValue( 0, vmin );
1483 // cntVTK->SetValue( 0, (range[1]*thr/100) );
1484 cntVTK->SetValue( 1, isovalue );
1485 // cntVTK->SetValue( 1, vmax );
1487 cntVTK->UpdateInformation();
1489 vtkCleanPolyData* cpd = vtkCleanPolyData::New( );
1490 cpd->SetInput( cntVTK->GetOutput( ) );
1491 cpd->ConvertLinesToPointsOff( );
1493 cpd->UpdateInformation();
1495 vtkPolyDataConnectivityFilter* conn = vtkPolyDataConnectivityFilter::New( );
1496 conn->SetExtractionModeToClosestPointRegion( );
1497 //conn->SetMaxRecursionDepth( 3000 );
1499 conn->SetInput( cpd->GetOutput( ) );
1501 conn->SetClosestPoint( x, y, 0 );
1503 conn->UpdateInformation();
1505 vtkCleanPolyData* cpd2 = vtkCleanPolyData::New( );
1506 cpd2->SetInput( conn->GetOutput( ) );
1508 cpd2->UpdateInformation();
1510 vtkStripper* vtkstripper = vtkStripper::New( );
1511 vtkstripper->SetInput( cpd2->GetOutput() );
1512 vtkstripper->Update();
1513 vtkstripper->UpdateInformation();
1516 vtkPolyData* polyDataResult = vtkstripper->GetOutput();
1518 polyDataResult->Update( );
1519 polyDataResult->UpdateInformation();
1523 myfile.open ("c:/temp/example.txt");
1525 polyDataResult->Print(myfile);
1526 myfile << "-------------------------------------\n";
1527 polyDataResult->GetLines()->Print(myfile);
1537 //--Calculating control points
1539 std::vector<double> vecX;
1540 std::vector<double> vecY;
1541 std::vector<double> vecZ;
1543 std::vector<double> vecCtrlPointX;
1544 std::vector<double> vecCtrlPointY;
1545 std::vector<double> vecCtrlPointZ;
1549 int ii,size=polyDataResult->GetNumberOfPoints();
1551 for (ii=1;ii<=size;ii++)
1553 id = polyDataResult->GetLines()->GetData()->GetValue(ii);
1554 p = polyDataResult->GetPoint(id);
1557 vecX.push_back( p[0] );
1558 vecY.push_back( p[1] );
1559 vecZ.push_back( 900 );
1560 // vecZ.push_back( p[2] );
1564 ExtractControlPoints2D *extractcontrolpoints2d = new ExtractControlPoints2D();
1565 extractcontrolpoints2d->SetContour( &vecX , &vecY , &vecZ );
1568 /*if (methodRadiobox->GetSelection()==0){
1569 extractcontrolpoints2d->GetInitialControlPoints( &vecCtrlPointX , &vecCtrlPointY , &vecCtrlPointZ );
1571 if (methodRadiobox->GetSelection()==1){
1572 extractcontrolpoints2d->GetControlPoints( &vecCtrlPointX , &vecCtrlPointY , &vecCtrlPointZ );
1574 if (methodRadiobox->GetSelection()==2){
1575 extractcontrolpoints2d->SetSamplingControlPoints( sampling );
1576 extractcontrolpoints2d->GetSamplingControlPoints( &vecCtrlPointX , &vecCtrlPointY , &vecCtrlPointZ );
1580 extractcontrolpoints2d->GetInitialControlPoints( &vecCtrlPointX , &vecCtrlPointY , &vecCtrlPointZ );
1582 else if (method==1){
1583 extractcontrolpoints2d->GetControlPoints( &vecCtrlPointX , &vecCtrlPointY , &vecCtrlPointZ );
1585 else if (method==2){
1586 extractcontrolpoints2d->SetSamplingControlPoints( sampling );
1587 extractcontrolpoints2d->GetSamplingControlPoints( &vecCtrlPointX , &vecCtrlPointY , &vecCtrlPointZ );
1590 //--Adding contour to the system
1592 std::vector<int> actualInstantVector;
1593 _instantPanel->getInstant( actualInstantVector );
1594 actualInstantVector[1]=z;
1596 int j,sizeCtrPt = vecCtrlPointX.size();
1597 manualContourModel *manModelContour = kernelManager->factoryManualContourModel( typeofcontour );
1598 manModelContour->SetNumberOfPointsSpline( ((sizeCtrPt/100)+1)*100 );
1600 for (j=0 ; j<sizeCtrPt ; j++)
1602 manModelContour->AddPoint( vecCtrlPointX[j] , vecCtrlPointY[j] , vecCtrlPointZ[j] );
1604 std::string theName;
1605 //theName = _modelManager->createOutline( manModelContour, actualInstantVector );
1606 theName = kernelManager->createOutline( manModelContour, actualInstantVector );
1607 bool addedModel = theName.compare("") != 0;
1610 double spc[3];//Si no hay imagen pero hay contornos que spacing se pone por default
1611 _theViewPanel->getSpacing(spc);
1612 //Adding the manualContourControler to interface objects structure
1613 //Adding the manualViewContour to interface objects structure
1614 //_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.
1615 _theViewPanel->configureViewControlTo(theName, manModelContour, spc, typeofcontour);
1616 //_theViewPanel->getSceneManager()->configureViewControlTo( theName, manModelContour,spc, typeofcontour ) ;
1620 int wxContourMainFrame::GetImageDataSizeZ(){
1621 return _theViewPanel->GetImageDataSizeZ();
1624 void wxContourMainFrame::GetImageDataRange(double *range){
1625 _theViewPanel->GetImageDataRange(range);
1628 void wxContourMainFrame::onSegmentationAllSlice(int minZ,int maxZ,int isovalue,int sampling,int method){
1629 //JCP 20-10-08 Undo redo implementation
1631 //JCP 20-10-08 Undo redo implementation
1634 int x = _theViewPanel->GetX();
1635 int y = _theViewPanel->GetY();
1639 double totalZ = maxZ-minZ+1;
1640 for( z=minZ ; z<=maxZ ; z++ )
1642 porcent = 100.0* (z-minZ)/totalZ;
1643 tmpString.Printf(_T(" %d %c %d/%d %d"), (int)porcent , 37 , z-minZ+1, (int)totalZ,z );
1644 interfMainPanel::getInstance()->setLabelSegmentationPanelVTK(tmpString);
1645 //_staticTextSegmentation->SetLabel(tmpString);
1646 SegmentationOneSlice( x,y,z,isovalue, sampling,method );
1648 interfMainPanel::getInstance()->setLabelSegmentationPanelVTK(_T(" "));
1653 //Creates a reference line to be used as the axis of the mirroring
1654 void wxContourMainFrame::referenceLine()
1656 if (_refLineControl==NULL)
1661 vtkImageData *vtkimagedata = _theViewPanel->getImageData();
1662 vtkimagedata->GetSpacing(spc);
1664 wxVtkBaseView * viewer2D = _theViewPanel->getWxVtkBaseView();
1666 _refLineControl = new manualLineControler();
1667 _refLineModel = new manualContourModelLine();
1668 _refLineView = new manualViewLine();
1669 _refLineView->SetModel( _refLineModel );
1670 _refLineView->SetWxVtkBaseView( viewer2D );
1671 _refLineView->SetRange( 2 );
1672 _refLineView->SetZ( 1200 );
1674 _refLineView->SetSpacing(spc);
1676 _refLineView->SetColorNormalContour(0, 0, 1);
1677 _refLineView->SetColorEditContour(0, 0.5, 0.5);
1678 _refLineView->SetWidthLine(4);
1680 _refLineControl->SetModelView( _refLineModel , _refLineView );
1681 vtkInteractorStyleBaseView* style = (vtkInteractorStyleBaseView*)viewer2D->GetInteractorStyleBaseView();
1682 style->AddInteractorStyleMaracas( _refLineControl );
1683 _refLineModel->SetCloseContour(false);
1684 _refLineControl->CreateNewManualContour();
1686 //EED?? double z = _refLineControl->GetZ();
1688 _refLineControl->AddPoint(50,100,z);
1689 _refLineControl->AddPoint(80,40,z);
1690 _refLineControl->SetCompleteCreation(true);
1692 _refLineModel->AddPoint(50,100,z);
1693 _refLineModel->AddPoint(80,40,z);
1694 _refLineModel->UpdateSpline();
1696 _refLineView->UpdateViewPoint(0);
1697 _refLineView->UpdateViewPoint(1);
1700 _refLineControl->SetActive(true);
1701 _refLineView->RefreshContour();
1705 //Hides the referenceLine
1706 void wxContourMainFrame::refLineHide()
1708 if (_refLineControl!=NULL)
1710 if (_refLineControl->GetActive())
1712 _refLineView->RemoveCompleteContourActor();
1713 _refLineControl->SetEditable(false);
1714 _refLineControl->SetActive(false);
1721 //Shows the referenceLine
1722 void wxContourMainFrame::refLineShow()
1724 if (_refLineControl!=NULL)
1726 if (_refLineControl->GetActive()==false)
1728 wxVtkBaseView * viewer2D = _theViewPanel->getWxVtkBaseView();
1730 _refLineView->SetModel( _refLineModel );
1731 _refLineView->SetWxVtkBaseView( viewer2D );
1732 _refLineView->SetRange( 2 );
1733 _refLineView->SetZ( 1200 );
1735 _refLineControl->SetModelView( _refLineModel , _refLineView );
1736 vtkInteractorStyleBaseView* style = (vtkInteractorStyleBaseView*)viewer2D->GetInteractorStyleBaseView();
1737 style->AddInteractorStyleMaracas( _refLineControl );
1738 _refLineControl->CreateNewManualContour();
1739 _refLineControl->SetActive(true);
1740 _refLineView->RefreshContour();
1747 void wxContourMainFrame::refLineChangeWidth(int width)
1749 _refLineView->SetWidthLine(width);
1750 _refLineView->RefreshContour();
1756 void wxContourMainFrame::onMirror()
1759 std::vector<std::string> currentSelection = _theViewPanel->getSelectedObjects();
1760 std::vector<std::string> filterCurrentSelection;
1762 std::vector<int> tempVector;
1763 _instantPanel->getInstant( tempVector );
1764 _performingOperation->reset();
1765 _performingOperation->setStartCommand( COPY );
1766 _performingOperation->setStartOperationInstantVector( tempVector );
1767 _performingOperation->setKeyNamesOperationElems( currentSelection );
1769 char theStartCommand = _performingOperation->getStartCommand();
1770 if ( theStartCommand == COPY )
1772 //JCP 20-10-08 Undo redo implementation
1774 //JCP 20-10-08 Undo redo implementation
1775 std::vector<int> tempVector;
1776 _instantPanel->getInstant( tempVector );
1777 _performingOperation->setEndOperationInstantVector ( tempVector );
1778 std::vector<std::string> elems = _performingOperation->getKeyNamesOperationElems();
1779 int i,size = elems.size();
1780 for( i=0; i<size; i++ )
1782 createMirrorContourOf( elems[i], tempVector, i>0 );
1786 //deleteContour( _refName );
1790 void wxContourMainFrame::onThreshold()
1792 int z = _theViewPanel->GetZ();
1795 vtkImageData * img = getImageData();
1796 img->GetScalarRange(range);
1798 int minTot = floor (range[0]);
1799 int maxTot = ceil (range[1]);
1802 _pannew->onThresholdInstantChange(minMax);
1803 int minVal = floor (minMax[0]);
1804 int maxVal = floor (minMax[1]);
1808 if (_imageReslicer==NULL)
1810 _imageReslicer = vtkImageReslice::New();
1811 _imageReslicer->SetInput( img );
1812 _imageReslicer->SetInformationInput(img);
1813 _imageReslicer->SetResliceAxesDirectionCosines(1,0,0, 0,1,0 ,0,0,1);
1814 _imageReslicer->SetOutputDimensionality(2);
1815 _imageReslicer->SetInterpolationModeToLinear();
1818 _imageReslicer->SetResliceAxesOrigin(0,0,z);
1820 img = _imageReslicer->GetOutput();
1822 img->UpdateInformation();
1824 wxVtkBaseView * baseView = _theViewPanel->getWxVtkBaseView();
1826 if (_thresholdTable==NULL)
1829 _thresholdTable = vtkLookupTable::New();
1830 _thresholdTable->SetNumberOfTableValues(maxTot+1);
1831 _thresholdTable->SetTableRange(range);
1832 _thresholdTable->SetAlphaRange(0, 1);
1833 _thresholdTable->SetValueRange(0, 1);
1834 _thresholdTable->SetSaturationRange(0, 0);
1835 _thresholdTable->SetRampToLinear( );
1838 //Assign a fake color for the upper image, and set the white as transparent
1840 for(i = minTot; i <= maxTot; i++)
1842 if( i >= minVal && i <= maxVal )
1844 _thresholdTable->SetTableValue(i, 1.0, 0.0, 0.0, 1);
1846 else if( i >= minTot && i < minVal )
1848 _thresholdTable->SetTableValue(i, 1.0, 1.0, 1.0, 0); //transparent
1850 else if( i > maxVal && i < maxTot )
1852 _thresholdTable->SetTableValue(i, 1.0, 1.0, 1.0, 0); //transparent
1856 _thresholdTable->SetTableValue(i, 1.0, 1.0, 1.0, 0); //transparent
1859 _thresholdTable->Build( );
1861 if (_thresholdMapper==NULL)
1863 _thresholdMapper = vtkImageMapToColors::New( );
1866 _thresholdMapper->SetLookupTable( _thresholdTable );
1867 _thresholdMapper->SetInput( img );
1869 if (_thresholdActor==NULL)
1871 _thresholdActor = vtkImageActor::New( );
1872 _thresholdActor->SetOpacity( 0.6 );
1873 _thresholdActor->InterpolateOn( );
1874 _thresholdActor->SetPosition( 0,0, 900-1 );
1877 _thresholdActor->SetInput( _thresholdMapper->GetOutput() );
1879 baseView->GetRenderer()->AddActor( _thresholdActor );
1880 _actorPresent = true;
1885 _imageReslicer->SetResliceAxesOrigin(0,0,z);
1886 img = _imageReslicer->GetOutput();
1888 img->UpdateInformation();
1890 //Assign a fake color for the upper image, and set the white as transparent
1892 for(i = minTot; i <= maxTot; i++)
1894 if( i >= minVal && i <= maxVal )
1896 _thresholdTable->SetTableValue(i, 1.0, 0.0, 0.0, 1);
1898 else if( i >= minTot && i < minVal )
1900 _thresholdTable->SetTableValue(i, 1.0, 1.0, 1.0, 0); //transparent
1902 else if( i > maxVal && i < maxTot )
1904 _thresholdTable->SetTableValue(i, 1.0, 1.0, 1.0, 0); //transparent
1908 _thresholdTable->SetTableValue(i, 1.0, 1.0, 1.0, 0); //transparent
1912 _thresholdTable->Build( );
1913 _thresholdMapper->SetLookupTable( _thresholdTable );
1914 _thresholdMapper->SetInput( img );
1915 _thresholdActor->SetInput( _thresholdMapper->GetOutput() );
1918 vtkImageViewer2* viewer = vtkImageViewer2::New();
1919 viewer->SetInput( upperImageActor->GetInput() );
1920 viewer->SetColorLevel((range[1]-range[0])/2);
1921 viewer->SetColorWindow(range[1]);
1922 viewer->GetRenderer()->AddActor( upperImageActor );
1925 _theViewPanel->RefreshInterface();
1929 void wxContourMainFrame::onThresholdChange()
1937 void wxContourMainFrame::onThresholdInterpolation(bool interpolate)
1939 if (_thresholdActor!=NULL)
1943 _thresholdActor->InterpolateOn( );
1948 _thresholdActor->InterpolateOff( );
1951 _theViewPanel->RefreshInterface();
1955 void wxContourMainFrame::onThresholdChangeOpacity (int opacity)
1959 _thresholdActor->SetOpacity(opacity*0.1);
1962 _theViewPanel->RefreshInterface();
1965 void wxContourMainFrame::onThresholdRemove()
1969 wxVtkBaseView * baseView = _theViewPanel->getWxVtkBaseView();
1970 baseView->GetRenderer()->RemoveActor( _thresholdActor );
1971 _actorPresent = false;
1974 _theViewPanel->RefreshInterface();
1977 void wxContourMainFrame::showAxis(bool show)
1979 _theViewPanel->SetVisibleAxis(show);
1980 _theViewPanel->Refresh();
1984 void wxContourMainFrame::onRigidPressed(){
1985 std::vector<std::string> currentSelection = _theViewPanel->getSelectedObjects();
1986 int elementsSelected = currentSelection.size();
1988 if ( elementsSelected >= 1 ){
1989 //JCP 20-10-08 Undo redo implementation
1991 //JCP 20-10-08 Undo redo implementation
1993 std::vector<int> tempVector;
1994 _instantPanel->getInstant( tempVector );
1995 Instant instant(&tempVector);
1997 int i , size=currentSelection.size();
1998 for ( i=0 ; i<size ; i++ )
2000 kernelManager->changeContourOfManager(currentSelection[i], &instant);
2005 void wxContourMainFrame::onWidthOfContour(double width){
2007 _theViewPanel->removeSceneContours();
2008 _theViewPanel->SetWidthContour(width);
2010 //_theViewPanel->getSceneManager()->SetWidthContour( width );
2015 int wxContourMainFrame::getColorWindow()
2019 vtkImageData * img = getImageData();
2020 img->GetScalarRange(range);
2022 std::cout<<"Val 1: "<<range[0]<<" Val 2: "<<range[1]<<std::endl;
2024 return (int)range[1];
2026 return _theViewPanel->getColorWindow();
2029 int wxContourMainFrame::getWindowLevel()
2033 vtkImageData * img = getImageData();
2034 img->GetScalarRange(range);
2036 std::cout<<"Val 1: "<<range[0]<<" Val 2: "<<range[1]<<std::endl;
2038 return (int)range[1];
2040 return _theViewPanel->getWindowLevel();
2043 void wxContourMainFrame::onBrigthnessColorWindowLevel(int colorwindow,int windowlevel){
2044 _theViewPanel->onBrigthnessColorWindowLevel(colorwindow, windowlevel);
2049 void wxContourMainFrame::onInterpolation(bool interpolate){
2050 _theViewPanel->onInterpolation(interpolate);
2054 void wxContourMainFrame::onChangeInstant(std::string name,int actual){
2055 _instantPanel->setConceptValue( name, actual );
2058 void wxContourMainFrame::resetAppend(){
2059 kernelManager->resetAppend();
2063 void wxContourMainFrame::onSpreadAdd(){
2064 std::vector<double> vecX;
2065 std::vector<double> vecY;
2066 std::vector<double> vecZ;
2067 _theViewPanel->GetPointsOfActualContour(&vecX , &vecY , &vecZ );
2069 std::vector<int> tempVector;
2070 _instantPanel->getInstant( tempVector );
2072 std::string val = kernelManager->onSpreadAdd(&vecX , &vecY , &vecZ, tempVector);
2074 interfMainPanel::getInstance()->appendStringSpread(val);
2078 void wxContourMainFrame::onSpreadGo(int type){
2080 //JCP 20-10-08 Undo redo implementation
2082 //JCP 20-10-08 Undo redo implementation
2085 std::vector<double> vecCtrlPointX;
2086 std::vector<double> vecCtrlPointY;
2087 std::vector<double> vecCtrlPointZ;
2091 std::vector<int> tempVector;
2092 _instantPanel->getInstant( tempVector );
2095 kernelManager->getMaxMinZ(&minZ,&maxZ);
2096 //JSTG_16-07-08_----------------------------------------------------------------
2097 //_contourPropagation->setInterpolationNumber(maxZ-minZ+1);
2098 kernelManager->CalculeSplinePropagation();
2100 double totalZ = maxZ-minZ+1;
2103 //--------------------------------------------------------------------
2104 for ( z=(int)minZ ; z<=(int)maxZ ; z++ )
2106 porcent = 100.0* (z-minZ)/totalZ;
2107 int numero = (int)(z-minZ+1)/(int)totalZ;
2108 std::string stringtemp = " "+kernelManager->intToString(porcent)+"% "+kernelManager->intToString(numero)+" "+kernelManager->intToString(z);
2110 interfMainPanel::getInstance()->setStringSpread(stringtemp);
2112 int typeofcontour = 1;
2113 std::string theName;
2114 manualContourModel* manModelContour = kernelManager->GetPoints(z, type, &vecCtrlPointX,&vecCtrlPointY,&vecCtrlPointZ, theName,typeofcontour, tempVector);
2116 if( manModelContour!=NULL ){
2117 double spc[3];//Si no hay imagen pero hay contornos que spacing se pone por default
2118 this->_theViewPanel->getSpacing(spc);
2119 //Adding the manualContourControler to interface objects structure
2120 //Adding the manualViewContour to interface objects structure
2121 //_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.
2122 _theViewPanel->configureViewControlTo( theName, manModelContour,spc,typeofcontour ) ;
2127 int numero = (int)(z-minZ+1)/(int)totalZ;
2128 std::string stringtemp = " "+kernelManager->intToString(porcent)+"% "+kernelManager->intToString(numero)+" "+kernelManager->intToString(z);
2130 interfMainPanel::getInstance()->setStringSpread(stringtemp);
2132 //RefreshInterface();
2135 void wxContourMainFrame::getInstantVector(std::vector<int>& tempVector){
2139 std::vector<std::string> wxContourMainFrame::getOutlinesName(int slide){
2140 std::vector<int> tempVector;
2141 _instantPanel->getInstant(tempVector);
2142 //Asignation of slide number should be different ex by name
2143 tempVector[1]=slide;
2144 return kernelManager->getOutlinesNameAtInstant(tempVector);
2147 void wxContourMainFrame::onInformationContourLabels(int typeContourGroup,int selection,int minimumZ,int maximumZ)
2149 int maxContourGroup = 0;
2151 ContourExtractData *contourextractdata = new ContourExtractData();
2153 contourextractdata ->SetTypeOperation( typeContourGroup % 3 );
2155 std::vector<manualContourModel*> lstManConMod;
2156 std::vector<manualContourModel*> lstManConModTmp;
2157 std::vector<manualContourModel*> lstManConModExp;
2158 std::vector<double> pLstValue;
2159 std::vector<double> pLstValuePosX;
2160 std::vector<double> pLstValuePosY;
2161 std::vector<double> pLstValuePosZ;
2164 int resultGrayRangeCount;
2167 double resultAverage;
2168 double resultStandardeviation;
2170 std::vector<int> tempVector;
2171 _instantPanel->getInstant( tempVector );
2173 vtkImageData *imagedata = _theViewPanel->getImageData();
2174 int sizeZ = _theViewPanel->GetImageDataSizeZ();
2176 int ii,sizeLstContourThings;
2186 if (selection==0 ) // actual slice
2188 std::vector<int> tempVector;
2189 _instantPanel->getInstant( tempVector );
2190 int actualSlice = tempVector[1];
2194 else if (selection==2 ) // All slices
2199 else if (selection==1 ) // slice range
2206 totalZ = maxZ-minZ+1;
2207 contourextractdata->SetImage( imagedata);
2210 for ( z=minZ ; z<=maxZ ; z++ )
2213 porcent = 100.0* (z-minZ)/totalZ;
2214 tmpString.Printf(_T(" %d %c %d/%d %d"), (int)porcent , 37 , z-minZ+1, (int)totalZ ,z);
2216 interfMainPanel::getInstance()->setStringInfoPanel(tmpString);
2217 //_staticTextInformation->SetLabel(tmpString);
2219 //Extraction data from contours of each slice
2220 contourextractdata->SetZtoBeAnalys(z);
2223 Instant instant(&tempVector);
2224 std::vector<ContourThing**> lstContourThings = kernelManager->getOutlinesAtInstant( &instant );
2225 sizeLstContourThings = lstContourThings.size();
2227 lstManConMod.clear();
2228 for (ii=0 ; ii<sizeLstContourThings ; ii++)
2230 ContourThing **contourthing = lstContourThings[ii];
2231 lstManConMod.push_back( (*contourthing)->getModel() );
2233 lstManConModExp = kernelManager->ExploseEachModel( lstManConMod );
2236 wxString tempString;
2237 tempString.Printf(_T("%d - %d"),z, sizeLstContourThings);
2238 interfMainPanel::getInstance()->setRowLabelInfoPanel(z, tempString);
2239 //_grid->SetRowLabelValue(z, tempString );
2241 int iContourGroup,sizeContourGroup;
2242 if (typeContourGroup==3) // contour separete
2244 sizeContourGroup=lstManConModExp.size();
2245 if ( maxContourGroup<sizeContourGroup )
2247 maxContourGroup=sizeContourGroup;
2249 } else { // contour AND OR XOR
2258 for( iContourGroup=0 ; iContourGroup<sizeContourGroup ; iContourGroup++ ){
2259 lstManConModTmp.clear();
2260 if (typeContourGroup==3) // contour separete
2262 lstManConModTmp.push_back( lstManConModExp[iContourGroup]);
2263 } else { // contour AND OR XOR
2264 lstManConModTmp = lstManConModExp;
2267 contourextractdata->SetLstManualContourModel( lstManConModTmp );
2270 pLstValuePosX.clear();
2271 pLstValuePosY.clear();
2272 pLstValuePosZ.clear();
2273 contourextractdata->GetValuesInsideCrown( &pLstValue,
2277 // Statistics of each slice.
2278 contourextractdata->Statistics( &pLstValue,
2281 &resultGrayRangeCount,
2286 &resultStandardeviation);
2288 if (interfMainPanel::getInstance()->getNumberColsInformationPanel()<_numberOfVariablesStatistics*(iContourGroup+1) )
2290 interfMainPanel::getInstance()->appendColsInformationPanel(_numberOfVariablesStatistics);
2293 tmpIntA=_numberOfVariablesStatistics*iContourGroup ;
2295 tempString.Printf(_T("%d"),resultSize);
2296 interfMainPanel::getInstance()->setCellValueInfoPanel(z, tmpIntA, tempString);
2298 tempString.Printf(_T("%d"),resultGrayRangeCount);
2299 interfMainPanel::getInstance()->setCellValueInfoPanel(z, tmpIntA+1, tempString);
2301 tempString.Printf(_T("%f"),resultMin);
2302 interfMainPanel::getInstance()->setCellValueInfoPanel(z, tmpIntA+2, tempString);
2304 tempString.Printf(_T("%f"),resultMax);
2305 interfMainPanel::getInstance()->setCellValueInfoPanel(z, tmpIntA+3, tempString);
2307 tempString.Printf(_T("%f"),resultAverage);
2308 interfMainPanel::getInstance()->setCellValueInfoPanel(z, tmpIntA+4, tempString);
2310 tempString.Printf(_T("%f"),resultStandardeviation);
2311 interfMainPanel::getInstance()->setCellValueInfoPanel(z, tmpIntA+5, tempString);
2314 } // for iContourGroup
2318 wxString tmpTitleString;
2320 for ( iTitleGroup=0 ; iTitleGroup<maxContourGroup ; iTitleGroup++ )
2322 tmpIntB =_numberOfVariablesStatistics*iTitleGroup;
2323 tmpTitleString.Printf(_T("%d-Size Data"),iTitleGroup);
2324 interfMainPanel::getInstance()->setColLableInfoPanel(tmpIntB + 0, tmpTitleString);
2326 interfMainPanel::getInstance()->setColLableInfoPanel(tmpIntB + 0, tmpTitleString );
2327 interfMainPanel::getInstance()->setColLableInfoPanel( tmpIntB + 1, _T("Size Range") );
2328 interfMainPanel::getInstance()->setColLableInfoPanel( tmpIntB + 2, _T("Min") );
2329 interfMainPanel::getInstance()->setColLableInfoPanel( tmpIntB + 3, _T("Max") );
2330 interfMainPanel::getInstance()->setColLableInfoPanel( tmpIntB + 4, _T("Average") );
2331 interfMainPanel::getInstance()->setColLableInfoPanel( tmpIntB + 5, _T("St.Dev.") );
2332 interfMainPanel::getInstance()->setColLableInfoPanel( tmpIntB + 6, _T(" ") );
2335 interfMainPanel::getInstance()->setStringInfoPanel( _T("") );
2336 delete contourextractdata;
2340 void wxContourMainFrame::onSaveResults(std::string directory,std::string namefile, std::string filename,
2341 int typeContourGroup, bool XYZValues, bool contourImage, bool statistics)
2345 SaveValuesXYZ( directory , namefile, typeContourGroup );
2350 vtkImageData * mask;
2351 vtkImageData * value;
2352 this->getMaskValue(&mask, &value, typeContourGroup);
2353 this->SaveImageResult( directory , namefile, mask, value);
2358 std::ostringstream name;
2359 name << filename << ".xls";
2362 FILE *pFile=fopen(name.str().c_str(),"w+");
2364 int sizeZ = _theViewPanel->GetImageDataSizeZ();
2367 int i,j,maxX,maxY=sizeZ;
2368 maxX= interfMainPanel::getInstance()->getNumberColsInformationPanel();//this->_grid->GetNumberCols();
2370 int iTitle,sizeTitle = (maxX / _numberOfVariablesStatistics);
2371 for ( iTitle=0; iTitle<sizeTitle ; iTitle++)
2373 // fprintf(pFile,"-- \t %d-Size \t SizeRange \t Min \t Max \t Ave \t StDv \t" , iTitle,tmpString.c_str() );
2374 fprintf(pFile,"-- \t %d-Size \t SizeRange \t Min \t Max \t Ave \t StDv \t" , iTitle );
2376 fprintf(pFile,"\n" );
2380 for ( j=0; j<maxY ; j++)
2382 fprintf(pFile,"%d\t" , j );
2383 for (i=0 ; i<maxX ; i++){
2384 tmpString = interfMainPanel::getInstance()->getCellValue(j, i);//_grid->GetCellValue( j , i );
2385 fprintf(pFile,"%s\t" , (const char *)(tmpString.mb_str()) );
2387 fprintf(pFile,"\n" );
2395 void wxContourMainFrame::SaveValuesXYZ(std::string directory,std::string namefile,int typeContourGroup)
2398 ContourExtractData *contourextractdata = new ContourExtractData();
2399 //int typeContourGroup = this->_radiolstboxContourGroup->GetSelection();
2400 contourextractdata ->SetTypeOperation( typeContourGroup % 3 );
2402 std::vector<manualContourModel*> lstManConMod;
2403 std::vector<manualContourModel*> lstManConModTmp;
2404 std::vector<manualContourModel*> lstManConModExp;
2405 std::vector<double> pLstValue;
2406 std::vector<double> pLstValuePosX;
2407 std::vector<double> pLstValuePosY;
2408 std::vector<double> pLstValuePosZ;
2410 std::vector<int> tempVector;
2411 _instantPanel->getInstant( tempVector );
2413 vtkImageData *imagedata = _theViewPanel->getSceneManager()->GetImageData();
2414 int sizeZ = _theViewPanel->getSceneManager()->GetImageDataSizeZ();
2416 int ii,sizeLstContourThings;
2423 minZ = 0;// _mbarrange->GetStart();
2424 maxZ = sizeZ;//_mbarrange->GetEnd();
2425 totalZ = maxZ-minZ+1;
2427 contourextractdata->SetImage( imagedata);
2430 for ( z=0 ; z<sizeZ ; z++)
2433 porcent = 100.0* (z-minZ)/totalZ;
2435 tmpString.Printf(_T("Saving Values"));
2436 tmpString.Printf(_T(" %d %c %d/%d %d"), (int)porcent , 37 , z-minZ+1, (int)totalZ ,z);
2437 interfMainPanel::getInstance()->setStringInfoPanel(tmpString);
2438 //_staticTextInformation->SetLabel(tmpString);
2441 //Extraction data from contours of each slice
2442 contourextractdata->SetZtoBeAnalys( z);
2445 Instant instant(&tempVector);
2446 std::vector<ContourThing**> lstContourThings = kernelManager->getOutlinesAtInstant(&instant);//this->_modelManager->getOutlinesAtInstant( &instant );
2447 sizeLstContourThings = lstContourThings.size();
2449 lstManConMod.clear();
2450 for (ii=0 ; ii<sizeLstContourThings ; ii++)
2452 ContourThing **contourthing = lstContourThings[ii];
2453 lstManConMod.push_back( (*contourthing)->getModel() );
2455 lstManConModExp = kernelManager->ExploseEachModel( lstManConMod );
2460 int iContourGroup,sizeContourGroup;
2461 if (typeContourGroup==3) // contour separete
2463 sizeContourGroup=lstManConModExp.size();
2464 } else { // contour AND OR XOR
2468 for( iContourGroup=0 ; iContourGroup<sizeContourGroup ; iContourGroup++ ){
2469 lstManConModTmp.clear();
2470 if (typeContourGroup==3) // contour separete
2472 lstManConModTmp.push_back( lstManConModExp[iContourGroup]);
2473 } else { // contour AND OR XOR
2474 lstManConModTmp = lstManConModExp;
2477 contourextractdata->SetLstManualContourModel( lstManConModTmp );
2480 pLstValuePosX.clear();
2481 pLstValuePosY.clear();
2482 pLstValuePosZ.clear();
2483 contourextractdata->GetValuesInsideCrown( &pLstValue,
2488 std::string temp = directory + "/" + namefile + "-slice";
2489 temp = temp + kernelManager->intToString(z) + "-cont" + kernelManager->intToString(iContourGroup);
2490 temp = temp + ".txt";
2492 // LG 14/01/09 : using crea
2493 wxString filename = crea::std2wx(temp);
2494 /*filename.Printf(_T("%s"),directory.c_str());
2495 filename.append(_T("\\"));
2496 filename.append(_T("%s"),namefile.c_str());
2497 filename.append(_T("-slice"));
2498 filename.append(_T("%d"),z);
2499 filename.append(_T("-cont"));
2500 filename.append(_T("%d"),iContourGroup);
2501 filename.append(_T(".txt"));*/
2502 // filename.Printf(temp.c_str());
2506 FILE *pFile=fopen((const char *)filename.mb_str(),"w+");
2507 fprintf(pFile,"value \t x \t y \t z\n" );
2508 int iLstValue,sizeLstValue=pLstValue.size();
2509 for (iLstValue=0 ; iLstValue<sizeLstValue ; iLstValue++ )
2511 fprintf(pFile,"%f\t %f\t %f\t %f\n", (float)pLstValue[iLstValue] , (float)pLstValuePosX[iLstValue], (float)pLstValuePosY[iLstValue], (float)z );
2514 } // for iContourGroup
2516 interfMainPanel::getInstance()->setStringInfoPanel(_T(""));
2517 //_staticTextInformation->SetLabel( _T("") );
2518 delete contourextractdata;
2521 void wxContourMainFrame::getMaskValue(vtkImageData ** mask,vtkImageData ** value,int typeContourGroup){
2523 ContourExtractData *contourextractdata = new ContourExtractData( true );
2524 //int typeContourGroup = this->_radiolstboxContourGroup->GetSelection();
2525 if (typeContourGroup==3)
2529 contourextractdata ->SetTypeOperation( typeContourGroup % 3 );
2531 std::vector<manualContourModel*> lstManConMod;
2532 std::vector<manualContourModel*> lstManConModTmp;
2533 std::vector<manualContourModel*> lstManConModExp;
2535 std::vector<int> tempVector;
2536 _instantPanel->getInstant( tempVector );
2538 vtkImageData *imagedata = _theViewPanel->getImageData();
2539 int sizeZ = _theViewPanel->GetImageDataSizeZ();
2541 int ii,sizeLstContourThings;
2550 minZ = 0;// _mbarrange->GetStart();
2551 maxZ = sizeZ;//_mbarrange->GetEnd();
2552 totalZ = maxZ-minZ+1;
2554 contourextractdata->SetImage( imagedata);
2557 for ( z=0 ; z<sizeZ ; z++)
2560 porcent = 100.0* (z-minZ)/totalZ;
2561 tmpString.Printf(_T("Saving Values"));
2562 tmpString.Printf(_T("%d %c %d/%d %d"), (int)porcent , 37 , z-minZ+1, (int)totalZ ,z);
2563 interfMainPanel::getInstance()->setStringInfoPanel(tmpString);
2565 //Extraction data from contours of each slice
2566 contourextractdata->SetZtoBeAnalys( z);
2569 Instant instant(&tempVector);
2570 std::vector<ContourThing**> lstContourThings = kernelManager->getOutlinesAtInstant( &instant );
2571 sizeLstContourThings = lstContourThings.size();
2573 lstManConMod.clear();
2574 for (ii=0 ; ii<sizeLstContourThings ; ii++)
2576 ContourThing **contourthing = lstContourThings[ii];
2577 lstManConMod.push_back( (*contourthing)->getModel() );
2579 lstManConModExp = kernelManager->ExploseEachModel( lstManConMod );
2582 int iContourGroup,sizeContourGroup;
2583 if (typeContourGroup==3) // contour separete
2585 sizeContourGroup=lstManConModExp.size();
2586 } else { // contour AND OR XOR
2590 for( iContourGroup=0 ; iContourGroup<sizeContourGroup ; iContourGroup++ ){
2591 lstManConModTmp.clear();
2592 if (typeContourGroup==3) // contour separete
2594 lstManConModTmp.push_back( lstManConModExp[iContourGroup]);
2595 } else { // contour AND OR XOR
2596 lstManConModTmp = lstManConModExp;
2599 contourextractdata->SetLstManualContourModel( lstManConModTmp );
2600 contourextractdata->CalculateImageResult(); // with actual Z
2602 } // for iContourGroup
2605 (*value) = contourextractdata->GetVtkImageValueResult();
2606 (*mask) = contourextractdata->GetVtkImageMaskResult();
2607 delete contourextractdata;
2610 void wxContourMainFrame::SaveImageResult(std::string directory,std::string namefile, vtkImageData* mask,vtkImageData* value)
2613 std::string temp = directory + "/" + namefile + "-Value.mhd";
2615 wxString filename = crea::std2wx(temp);
2617 // filename.Printf(_T(temp.c_str()));
2618 //filename.Printf(_T("%s\\%s-Value.mhd",directory.c_str(),namefile.c_str(),z);
2619 /*filename.Printf(_T("%s"),directory.c_str());
2620 filename.append(_T("\\"));
2621 filename.append(_T("%s"),namefile.c_str());
2622 filename.append(_T("-Value.mhd"));*/
2625 vtkMetaImageWriter *writerValueImage = vtkMetaImageWriter::New( );
2626 writerValueImage->SetInput( value );
2627 writerValueImage->SetFileName( (const char *)filename.mb_str() );
2628 writerValueImage->SetFileDimensionality( 3 );
2629 writerValueImage->Write( );
2632 // filename.Printf("%s\\%s-Mask.mhd",directory.c_str(),namefile.c_str(),z);
2633 temp = directory + "/" + namefile + "-Mask.mhd";
2635 // LG 14/01/09 : using crea
2636 filename = crea::std2wx(temp);
2637 // filename.Printf(_T(temp.c_str()));
2639 /*filename.Printf(_T("%s"),directory.c_str());
2640 filename.append(_T("\\"));
2641 filename.append(_T("%s"),namefile.c_str());
2642 filename.append(_T("-Mask.mhd"));*/
2644 vtkMetaImageWriter *writerMaskImage = vtkMetaImageWriter::New( );
2645 writerMaskImage->SetInput( mask );
2646 writerMaskImage->SetFileName( (const char *)filename.mb_str() );
2647 writerMaskImage->SetFileDimensionality( 3 );
2648 writerMaskImage->Write( );
2650 interfMainPanel::getInstance()->setStringInfoPanel( _T("") );
2656 void wxContourMainFrame::onChangeInstantInstantPanel(std::string name,int value, int minshow, int maxshow){
2657 if( name.compare( _theViewPanel->getVerticalConceptName() ) == 0){
2658 _theViewPanel->setActualVertical( value);
2660 else if( name.compare( _theViewPanel->getHorizontalConceptName() ) == 0|| _instantPanel->getIfConceptCheckedAt( name, 0 ) ) {
2661 _theViewPanel->setHorizontalConcept( name, minshow, maxshow, minshow, maxshow, value);
2667 void wxContourMainFrame::onSnakePressed(){
2668 std::vector<double> vecX;
2669 std::vector<double> vecY;
2670 std::vector<double> vecZ;
2671 _theViewPanel->GetPointsOfActualContour( &vecX , &vecY , &vecZ );
2673 if (vecX.size()!=0){
2674 std::vector<int> tempVector;
2675 _instantPanel->getInstant( tempVector );
2676 int i,size=vecZ.size();
2677 int actualSlice = tempVector[1];
2678 for ( i=0 ; i<size ; i++ )
2680 vecZ[i] = actualSlice;
2683 wxDialog* dialog = new wxDialog(this, -1, wxString(_T("Snake")));
2684 wxPanel* panel = new wxPanel(dialog,-1);
2685 // wxStaticText* sttext = new wxStaticText(panel, -1, wxString(_T("Panel para snake")));
2686 new wxStaticText(panel, -1, wxString(_T("Panel para snake")));
2687 dialog->ShowModal();
2692 void wxContourMainFrame::saveFileWithContoursAutomatique(){
2693 std::string filename = kernelManager->getCurrentFileName();
2694 if(filename.compare("")!=0){
2695 saveFileWithContours(filename);
2700 void wxContourMainFrame::ShowToolsPanel(bool show){
2701 _pannew->Show(show);