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"
17 #include <manualContour.h>
18 //#include "ImageSourceThing.h"
19 //#include "wxContour_ActionCommandsID.h"
20 //#include "OutlineModelBuilder.h"
21 //#include "wxContourEventHandler.h"
24 //----------------------------------------------------------------------------------------------------------------
25 // Class implementation
26 //----------------------------------------------------------------------------------------------------------------
27 /** @file wxContourMainFrame.cxx */
29 //------------------------------------------------------------------------------------------------------------
30 // Constructors & Destructors
31 //------------------------------------------------------------------------------------------------------------
33 wxContourMainFrame* wxContourMainFrame:: instance = NULL;
34 char wxContourMainFrame::COPY = 'C';
36 wxContourMainFrame :: wxContourMainFrame(wxWindow* parent, wxWindowID id,const wxString& title,const wxPoint& pos,const wxSize& size,long style)
37 //: wxPanel(parent, id, title, pos, size, style)
38 //: wxWindow(parent, id, pos, size, style)
39 : wxPanel(parent, id, pos, size, style)
41 m_mgr.SetManagedWindow(this);
42 _creatingContoursActive = false;
44 // _modelManager = NULL;
46 // _buttonsBar = NULL;
48 // _drawToolsPanel = NULL;
49 // _operationsToolsPanel = NULL;
50 //_autoFormsPanel = NULL;
51 // _standardToolsPanel = NULL;
52 // _editionToolsPanel = NULL;
53 // _listViewPanel = NULL;
54 // _sceneManager = NULL;
55 //_actualInstant = NULL;
56 _numberOfVariablesStatistics = 6+1;
58 _refLineControl = NULL;
62 // set up default notebook style
63 // m_notebook_style =wxAUI_NB_TAB_SPLIT | wxAUI_NB_TAB_EXTERNAL_MOVE | wxNO_BORDER;
64 // m_notebook_theme = 0;
65 //wxContour_ActionCommandsID a;
69 wxContourMainFrame :: wxContourMainFrame(wxWindow* parent, wxWindowID id,const wxString& title,const wxPoint& pos,const wxSize& size,std::vector<vtkImageData*> images, long style,std::string datadir)
70 : wxPanel(parent, id, pos, size, style)
72 m_mgr.SetManagedWindow(this);
73 _creatingContoursActive = false;
75 // _modelManager = NULL;
77 // _buttonsBar = NULL;
79 // _drawToolsPanel = NULL;
80 // _operationsToolsPanel = NULL;
81 // _autoFormsPanel = NULL;
82 // _standardToolsPanel = NULL;
83 // _editionToolsPanel = NULL;
84 // _listViewPanel = NULL;
85 // _sceneManager = NULL;
86 // _actualInstant = NULL;
88 _refLineControl = NULL;
92 // set up default notebook style
93 m_notebook_style =wxAUI_NB_TAB_SPLIT | wxAUI_NB_TAB_EXTERNAL_MOVE | wxNO_BORDER;
95 //wxContour_ActionCommandsID a;
96 _numberOfVariablesStatistics = 6+1;
99 _performingOperation = new PerformingOperation();
105 #if defined(__GNUC__)
106 std::string str_home(getenv("HOME"));
107 #elif defined(_WIN32)
108 std::string str_home(getenv("USERPROFILE"));
110 std::string strCreaContourDataTmp = str_home + "/.creaContourDataTemp/";
111 // std::string command("mkdir "+strCreaContourDataTmp);
112 // system( command.c_str() );
114 kernelManager = new KernelManagerContour( images , datadir+"/data/" , strCreaContourDataTmp );
115 //kernelManager->setVectImages(images);
116 //kernelManager->initializeEnvironment();
118 //vtkImageData* selectedimage = kernelManager->getVectImages()[0];
120 //-------------------------------------------------------------
122 /*frame = new wxContourMainFrame(_builder->getImSourceEnv(), _builder->getImSectionEnv(), _builder->getAxesEnv(), _builder->getContourEnv(),NULL, wxID_ANY, wxT("ROI Application Sample"), wxPoint(50,50), wxSize(800, 600));
125 //Creating the evtHandler of the panels
126 //wxContourEventHandler * eventHandler = new wxContourEventHandler();
128 //Creating the window that will show the panels
130 //Getting the parent for the panels ( using aui )
131 wxAuiNotebook * notebook = this->createNotebook();
134 //wxInstantChooserPanel * instantPanel = new wxInstantChooserPanel( notebook, "Instant Chooser", true);
136 std::vector<std::string> conceptNameVect;
137 std::vector<int> conceptSizeVect;
141 _instantPanel = new wxInstantChooserPanel( notebook, "Instant Chooser", true, false, "c" );
142 _theViewPanel = new wxContourViewPanel( kernelManager->getSourceImage(), notebook );
146 kernelManager->getConceptsInformation(conceptNameVect, conceptSizeVect);
147 _instantPanel->addConcepts(conceptNameVect, conceptSizeVect);
150 double val = _theViewPanel->getCurrentDeep();
151 _instantPanel->setConceptValue( "Axe Depth", (int)val );
152 //JCP _instantPanel->setConceptValue("time", num de imagenes);
153 ConceptDataWrap * data = _instantPanel->getConceptDataOf( "Axe Depth" );
154 //*******************changeInstant();
155 _theViewPanel->setVerticalConcept( "Axe Depth", data->getMinValue(), data->getMaxValue(), data->getMinShowedValue(), data->getMaxShowedValue(), data->getActualValue() );
157 //eventHandler->setModelManager( kernelManager->getOutlineModelManager() );
158 //eventHandler->setViewPanel( _theViewPanel );
159 //_theViewPanel->initializeScenceManager();
160 //eventHandler->setInstantChooserPanel( _instantPanel );
162 //bool successConfiuration = eventHandler->configureEventsHandling();
164 //successConfiuration &= this->configurePanels( notebook );
165 this->configurePanels( notebook );
167 interfMainPanel* pannew = interfMainPanel::getInstance(parent,datadir+"/data/Icons");//, eventHandler);
175 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 ){
176 if(instance == NULL){
177 instance = new wxContourMainFrame(parent, id, title, pos, size, images, style,datadir);
182 std::vector<vtkImageData*> wxContourMainFrame ::getVectImages(){
183 return kernelManager->getVectImages();
185 wxContourMainFrame* wxContourMainFrame :: getInstance(){
190 wxContourMainFrame :: ~wxContourMainFrame()
193 //El problema al cerrar la aplicacion puede estar asociado
194 //a que wxAUINotebook esta en la aplicacion
195 //principal (wxContourGUIExample)tambien
196 //EED???? delete _theViewPanel;
197 //EED???? delete _instantPanel;
198 //EED???? delete _buttonsBar;
199 //EED???? delete _actualInstant;
200 //EED???? delete _sceneManager;
204 //------------------------------------------------------------------------------------------------------------
205 // Creational and initialization methods using WxAui
206 //------------------------------------------------------------------------------------------------------------
208 wxAuiNotebook * wxContourMainFrame :: createNotebook()
210 wxSize client_size = GetClientSize();
211 wxAuiNotebook* noteBook = new wxAuiNotebook(this, -1, wxPoint(client_size.x, client_size.y), wxSize(430,200), m_notebook_style);
212 wxBitmap page_bmp = wxArtProvider::GetBitmap(wxART_NORMAL_FILE, wxART_OTHER, wxSize(16,16));
217 //------------------------------------------------------------------------------------------------------------
218 // Creational and initialization methods
219 //------------------------------------------------------------------------------------------------------------
220 bool wxContourMainFrame :: configurePanels(wxAuiNotebook* theNoteBook)
222 bool configured = _theViewPanel!=NULL;
224 configured &= _theViewPanel!=NULL;
225 if( _theViewPanel!=NULL )
227 theNoteBook->AddPage( _theViewPanel, wxT(" View ") );
234 theNoteBook->AddPage( _instantPanel, wxT("Instant Page") );
238 m_mgr.AddPane(theNoteBook, wxAuiPaneInfo().Name(wxT("notebook_content")).CenterPane().PaneBorder(false));
240 /* configured &= _buttonsBar!=NULL;
241 if( _buttonsBar!=NULL )
243 m_mgr.AddPane(_buttonsBar, wxAuiPaneInfo().
244 Name(wxT("TB")).Caption(wxT("Buttons Bar")).
246 LeftDockable( ).RightDockable( false ).CloseButton(false));
251 SetMinSize(wxSize(300,300));
256 void wxContourMainFrame :: setNotebook( wxAuiNotebook * noteBook )
261 //------------------------------------------------------------------------------------------------------------
262 // Attributes getters and setters
263 //------------------------------------------------------------------------------------------------------------
267 void wxContourMainFrame :: setInstantChooserPanel( wxInstantChooserPanel * theInstantChooserPanel )
269 _instantPanel = theInstantChooserPanel;
272 // void wxContourMainFrame :: setButtonsBar( wxContour_ButtonsBar * theButtonsBar )
274 // _buttonsBar = theButtonsBar;
277 // void wxContourMainFrame :: setGrid( wxContour_Grid * theGridPanel )
279 // _gridPanel = theGridPanel;
282 // void wxContourMainFrame :: setDrawToolsPanel( wxContour_DrawToolsPanel * theDrawToolsPanel )
284 // _drawToolsPanel = theDrawToolsPanel;
287 // void wxContourMainFrame :: setOperationsToolsPanel( wxContour_OperationsToolsPanel * theOperationsToolsPanel )
289 // _operationsToolsPanel = theOperationsToolsPanel;
292 // void wxContourMainFrame :: setAutomaticFormsPanel( wxContour_AutomaticFormsToolsPanel * theAutoFormsPanel )
294 // _autoFormsPanel = theAutoFormsPanel;
297 // void wxContourMainFrame :: setStandardToolsPanel( wxContour_StandardToolsPanel * theStandardToolsPanel )
299 // _standardToolsPanel= theStandardToolsPanel;
302 // void wxContourMainFrame :: setEditionToolsPanel( wxContour_EdtionToolsPanel * theEditionToolsPanel )
304 // _editionToolsPanel = theEditionToolsPanel;
307 // void wxContourMainFrame :: setListViewPanel( wxContour_ListViewPanel * theListViewPanel )
309 // _listViewPanel = theListViewPanel;
314 void wxContourMainFrame::onCreateContourSpline( ){
316 //JCP 20-10-08 Undo redo implementation
318 //JCP 20-10-08 Undo redo implementation
322 void wxContourMainFrame::onCreateContourRectangle( ){
323 //JCP 20-10-08 Undo redo implementation
325 //JCP 20-10-08 Undo redo implementation
328 void wxContourMainFrame::onCreateContourCircle( ){
329 //JCP 20-10-08 Undo redo implementation
331 //JCP 20-10-08 Undo redo implementation
335 void wxContourMainFrame::onCreateContourLine( ){
336 //JCP 20-10-08 Undo redo implementation
338 //JCP 20-10-08 Undo redo implementation
342 //------------------------------------------------------------------------------------------------------------
344 void wxContourMainFrame :: onCreateContourBullEye(wxPanel* panel )
346 //Creating the manualContourModel and including in the model
347 manualContourModel * manModelContour = factoryManualContourModel(panel );
349 std::vector<int> instantVector;
350 _instantPanel->getInstant( instantVector );
351 std::string theName = kernelManager->createOutline(manModelContour, instantVector);
353 /*std::vector<int> instantVector;
354 _instantPanel->getInstant( instantVector );
356 theName= _modelManager->createOutline( manModelContour, instantVector );*/
357 bool addedModel = theName.compare("") != 0;//??
361 double spc[3];//Si no hay imagen pero hay contornos que spacing se pone por default
362 _theViewPanel->getSpacing(spc);
363 //Adding the manualContourControler to interface objects structure
364 //Adding the manualViewContour to interface objects structure
365 //_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.
366 _theViewPanel->getSceneManager()->configureViewControlTo( theName, manModelContour,spc , 4) ;
369 void wxContourMainFrame :: createContour( int typeContour )
371 //Creating the manualContourModel and including in the model
372 manualContourModel * manModelContour = kernelManager->factoryManualContourModel(typeContour);
375 std::vector<int> instantVector;
376 _instantPanel->getInstant( instantVector );
377 std::string theName = kernelManager->createOutline(manModelContour, instantVector);
379 /*std::vector<int> instantVector;
380 _instantPanel->getInstant( instantVector );
382 theName= _modelManager->createOutline( manModelContour, instantVector );*/
383 bool addedModel = theName.compare("") != 0;//??
386 double spc[3];//Si no hay imagen pero hay contornos que spacing se pone por default
387 _theViewPanel->getSpacing(spc);
388 //Adding the manualContourControler to interface objects structure
389 //Adding the manualViewContour to interface objects structure
390 //_sceneManager->setControlActiveStateOfALL( false );//This call is being done here because if the ROI is created underneath the previously created ROIS will still be active.
391 _theViewPanel->getSceneManager()->configureViewControlTo( theName, manModelContour,spc , typeContour) ;
395 manualContourModel * wxContourMainFrame::factoryManualContourModel(wxPanel* panel){
397 manualContourModelBullEye *manModelContourBullEye = new manualContourModelBullEye();
398 manualContourModel *manModelContour=NULL;
399 manModelContour = manModelContourBullEye;
401 int iCrown,sizeCrowns,iSector,sizeSectors;
402 double radioA,radioB,ang,angDelta ;
403 sizeCrowns = ((PanelBullEyeOptions*)panel)->GetNumberOfCrowns();
404 for ( iCrown=0 ; iCrown<sizeCrowns ; iCrown++ )
406 sizeSectors = ((PanelBullEyeOptions*)panel)->GetNumberOfSections(iCrown);
407 radioB = ((PanelBullEyeOptions*)panel)->GetRadioOfCrown(iCrown);
408 if (iCrown==sizeCrowns-1)
412 radioA = ((PanelBullEyeOptions*)panel)->GetRadioOfCrown(iCrown+1);
416 for ( iSector=0 ; iSector<sizeSectors ; iSector++ )
418 ang = ((PanelBullEyeOptions*)panel)->GetAngOfCrownSection(iCrown,iSector);
419 angDelta= ((PanelBullEyeOptions*)panel)->GetAngDeltaOfCrownSection(iCrown);
420 manModelContourBullEye->AddSector(radioA,radioB,ang,angDelta);
423 } // if _panelBullEyeOptions
425 return manModelContour;
427 void wxContourMainFrame :: saveState(){
429 std::string temp = kernelManager->saveState();
430 saveFileWithContours(temp);
433 void wxContourMainFrame::onDeleteContour(){
434 //JCP 20-10-08 Undo redo implementation
436 //JCP 20-10-08 Undo redo implementation
438 std::vector<std::string> lstKeyNameToBeErase;
439 lstKeyNameToBeErase = _theViewPanel->getSceneManager()->getSelectedObjects();
440 deleteContours( lstKeyNameToBeErase );
442 int i,size=_sceneManager->getSelectedObjects().size();
445 std::string keyName = _sceneManager->getSelectedObjects()[i];
446 int ispartofstaticlist = this->_modelManager->IsPartOfStaticList( keyName );
447 if ( ispartofstaticlist>=0 )
449 std::vector<int> tempVector;
450 _instantPanel->getInstant( tempVector );
451 Instant instant(&tempVector);
452 this->_modelManager->ChangeContourOfList(keyName, &instant);
456 std::vector<std::string> lstKeyName;
457 std::vector<std::string> lstKeyNameActualSlice;
458 std::vector<std::string> lstKeyNameToBeErase;
460 lstKeyNameToBeErase = _sceneManager->getSelectedObjects();
461 lstKeyNameActualSlice = _sceneManager->GetlstContoursNameActualSlice();
462 int k,kSize=lstKeyNameToBeErase.size();
463 int j,jSize=lstKeyNameActualSlice.size();
465 for (k=0;k<kSize; k++)
468 for (j=0;j<jSize; j++)
470 if (lstKeyNameToBeErase[k]==lstKeyNameActualSlice[j])
477 lstKeyName.push_back( lstKeyNameToBeErase[k] );
481 deleteContours( lstKeyName );
485 void wxContourMainFrame :: deleteContours( std::vector<std::string> keyNamesVector )
487 int i,size=keyNamesVector.size();
490 deleteContour( keyNamesVector[i] );
494 void wxContourMainFrame :: deleteContour( std::string theKeyName ){
496 manualContourModel * cModel;
497 manualViewBaseContour * cViewer;
498 manualContourBaseControler * cControler;
500 ContourWrap_ViewControl *conwrapviewControl = _theViewPanel->getSceneManager()->getContourWrap_ViewControlOf( theKeyName );
501 cControler = conwrapviewControl->getControler();*/
504 bool isedit = _theViewPanel->isEditableCControler(theKeyName);
505 bool ispartofstaticlst = kernelManager->IsPartOfStaticList(theKeyName);
507 if (isedit && ispartofstaticlst)
509 _theViewPanel->removeFromScene(theKeyName);
511 kernelManager->deleteCModel(theKeyName);
512 //_theViewPanel->getSceneManager()->removeFromScene( theKeyName );
513 //cViewer = conwrapviewControl->getViewer();
514 //_theViewPanel->getSceneManager()->removeWrap( theKeyName );
515 //cControler* conwrapviewControl->getControler();
517 //FILE *ff = fopen("c:/temp/wxVtkBaseView_SceneManagerStadistics.txt","a+");
518 //fprintf(ff,"EED wxContourEventHandler::deleteContours() \n" );
519 //fprintf(ff," %s %p\n",keyNamesVector[i].c_str(), cControler );
523 // delete cControler;
528 void wxContourMainFrame::onDeleteContoursActSlice(){
529 //JCP 20-10-08 Undo redo implementation
531 //JCP 20-10-08 Undo redo implementation
532 deleteContours( (std::vector<std::string>)_theViewPanel->getSceneManager()->GetlstContoursNameActualSlice() );
534 void wxContourMainFrame::onDeleteAllContours(){
535 //JCP 20-10-08 Undo redo implementation
539 void wxContourMainFrame::deleteAllContours(){
540 //JCP 20-10-08 Undo redo implementation
543 std::vector<int> tempVector;
544 _instantPanel->getInstant( tempVector );
546 //JCP --08-09-2008 When using a diferent interface the _mbarrangeDeleteAll might not be initialize
547 // the values in GetStart and GetEnd will then not be initialize also.
548 // We use instead the values given when initializing the _deletepanel.
550 //int minZ = _mbarrangeDeleteAll->GetStart();
551 //int maxZ = _mbarrangeDeleteAll->GetEnd();
555 maxZ = _theViewPanel->getSceneManager()->GetImageDataSizeZ();
559 _theViewPanel->getSceneManager()->removeSceneContours( );
560 _theViewPanel->getSceneManager()->removeAllOutlines();
561 kernelManager->removeAllOutlines();
564 if ( (minZ==0) && (maxZ==_mbarrangeDeleteAll->GetMax() ))
566 _theViewPanel->getSceneManager()->removeSceneContours( );
567 _modelManager->removeAllOutlines();
568 _theViewPanel->getSceneManager()->removeAllOutlines();
571 for ( z=minZ ; z<=maxZ ; z++)
574 Instant instant(&tempVector);
575 std::vector<ContourThing**> lstContourThings = this->_modelManager->getOutlinesAtInstant( &instant );
577 sizeLstContourThings = lstContourThings.size();
578 for (ii=0 ; ii<sizeLstContourThings ; ii++)
580 ContourThing **contourthing = lstContourThings[ii];
581 deleteContour( (*contourthing)->getName() );
588 void wxContourMainFrame::setConceptValue( std::string name, int value ){
589 _instantPanel->setConceptValue(name, value);
592 ConceptDataWrap* wxContourMainFrame::getLastConceptData(){
593 return _instantPanel->getLastConceptData();
595 bool wxContourMainFrame::getIfConceptCheckedAt( std::string name, int pos ){
596 return _instantPanel->getIfConceptCheckedAt( name, pos );
599 void wxContourMainFrame::changeInstant(){
600 std::vector<int> instantVect;
601 _instantPanel->getInstant( instantVect );
602 // Instant * theInstant = new Instant ( &instantVect );
604 //Setting the actual instant
605 //_actualInstant = theInstant;
607 kernelManager->setInstant(instantVect);
608 //_modelManager->setInstant( _actualInstant );
610 updateInstantOutlines();
611 updateInstantImageData();
616 void wxContourMainFrame :: updateInstantOutlines(){
618 _theViewPanel->removeSceneContours();
619 _theViewPanel->addNameWrapperToScene();
621 //for( int i=0; i<size; i++)
623 // _theViewPanel->getSceneManager()->addToScene(namesWrapping[i]->getKeyName(), true, true, true, false, false );
627 int wxContourMainFrame::getNamesWrappingSize(){
628 return kernelManager->getNamesWrappingSize();
630 std::string wxContourMainFrame::getNameWrapping(int i){
631 return kernelManager->getNameWrapping(i);
634 void wxContourMainFrame::updateInstantImageData(){
635 std::vector<int> inst;
636 _instantPanel->getInstant(inst);
638 vtkImageData* img = kernelManager->getImageAtInstant(inst);
640 _theViewPanel->changeImage(img);
643 int z = _instantPanel->getConceptDataOf("Axe Depth")->getActualValue();
644 _theViewPanel->setImageSlice(z);
647 void wxContourMainFrame::updateInstantAxes(){
650 void wxContourMainFrame::onChangeDeep(int val){
651 _instantPanel->setConceptValue( "Axe Depth", (int)val );
656 void wxContourMainFrame::onCopy(){
657 std::vector<std::string> currentSelection = _theViewPanel->getSelectedObjects();
659 std::vector<int> tempVector;
660 _instantPanel->getInstant( tempVector );
661 _performingOperation->reset();
662 _performingOperation->setStartCommand( COPY );
663 _performingOperation->setStartOperationInstantVector( tempVector );
664 _performingOperation->setKeyNamesOperationElems( currentSelection );
667 void wxContourMainFrame::onPaste(){
670 char theStartCommand = _performingOperation->getStartCommand();
671 if ( theStartCommand == COPY )
673 //JCP 20-10-08 Undo redo implementation
675 //JCP 20-10-08 Undo redo implementation
676 std::vector<int> tempVector;
677 _instantPanel->getInstant( tempVector );
678 _performingOperation->setEndOperationInstantVector ( tempVector );
679 std::vector<std::string> elems = _performingOperation->getKeyNamesOperationElems();
680 int i,size = elems.size();
681 for( i=0; i<size; i++ )
683 createCopyContourOf( elems[i], tempVector, i>0 );
687 void wxContourMainFrame::onUndo(){
688 std::string filename;
689 if(kernelManager->onUndoSaveFile(filename)){
690 saveFileWithContours(filename);
692 if(kernelManager->onUndo(filename)){
696 void wxContourMainFrame::onRedo(){
697 std::string filename;
698 if(kernelManager->onRedo(filename)){
703 void wxContourMainFrame :: createCopyContourOf ( std::string anExistingKName, std::vector<int> &instantNoTouchData, bool append )
705 std::string cloneName = kernelManager->createCopyContourOf( anExistingKName, instantNoTouchData );
706 manualContourModel * manualModel = kernelManager->getOutlineByKeyName(cloneName);//_modelManager->getOutlineByKeyName( cloneName )->getModel();
707 _theViewPanel->getSceneManager()->createCopyContourOf( anExistingKName, cloneName, manualModel , append );
710 ///AD: 03-09 Copy the object and apply the given transformation
711 void wxContourMainFrame :: createMirrorContourOf ( std::string anExistingKName, std::vector<int> &instantNoTouchData, bool append )
713 std::string cloneName = kernelManager->createCopyContourOf( anExistingKName, instantNoTouchData );
714 manualContourModel * manualModel = kernelManager->getOutlineByKeyName(cloneName);
716 manualPoint * refPoint1 = _refLineModel->GetManualPoint(0);
717 manualPoint * refPoint2 = _refLineModel->GetManualPoint(1);
719 double pnt1X = refPoint1->GetX();
720 double pnt1Y = refPoint1->GetY();
721 // double pnt1Z = refPoint1->GetZ();
722 double pnt2X = refPoint2->GetX();
723 double pnt2Y = refPoint2->GetY();
724 // double pnt2Z = refPoint2->GetZ();
726 double angle = (atan2(pnt2Y - pnt1Y, pnt2X - pnt1X) * 180 / 3.1415926535897932384626433832795)+90;
727 vtkTransform *t = vtkTransform::New();
731 t->Translate(-pnt1X, -pnt1Y, 0);
735 t->Translate(pnt1X, pnt1Y, 0);
738 int i,size=manualModel->GetSizeLstPoints();
741 manualPoint * mp = manualModel->GetManualPoint(i);
747 t->TransformPoint( vecIn, vecOut );
748 mp->SetPointX( vecOut[0] );
749 mp->SetPointY( vecOut[1] );
750 mp->SetPointZ( vecOut[2] );
753 _theViewPanel->getSceneManager()->createCopyContourOf( anExistingKName, cloneName, manualModel , append );
756 void wxContourMainFrame ::loadState(std::string filename){
758 FILE *pFile=fopen(filename.c_str(),"r+");
760 fscanf(pFile,"%s",tmp); // --CreaContour--
762 fscanf(pFile,"%s",tmp); // Version
763 fscanf(pFile,"%s",tmp); // 1.0.1
764 std::string version(tmp);
768 openContours(pFile,false);
769 if (version!="1.0.0"){
770 openContours(pFile,true);
775 //_theViewPanel->getSceneManager()->removeSceneContours();
780 void wxContourMainFrame::onLoad(){
782 wxFileDialog dialog(NULL, _T("Choose a file"), _T(""), _T(""), _T("*.roi"), wxOPEN );
783 if (dialog.ShowModal() == wxID_OK)
785 std::string fileNameContourROI = (const char *)(dialog.GetPath().mb_str());
786 FILE *pFile=fopen(fileNameContourROI.c_str(),"r+");
788 fscanf(pFile,"%s",tmp); // --CreaContour--
790 fscanf(pFile,"%s",tmp); // Version
791 fscanf(pFile,"%s",tmp); // 1.0.1
792 std::string version(tmp);
794 openContours(pFile,false);
795 if (version!="1.0.0"){
796 openContours(pFile,true);
798 // _theViewPanel->getSceneManager()->openFileWithContours(ff);
802 _theViewPanel->getSceneManager()->removeSceneContours();
805 void wxContourMainFrame::onSave(){
806 wxFileDialog dialog(NULL, _T("Choose a file"), _T(""), _T(""), _T("*.roi"), wxSAVE );
807 if (dialog.ShowModal() == wxID_OK)
809 std::string fileNameContourROI = (const char *)(dialog.GetPath().mb_str());
810 kernelManager->setCurrentFileName(fileNameContourROI);
811 saveFileWithContours( fileNameContourROI );
814 void wxContourMainFrame::saveFileWithContours( std::string filename ){
816 FILE *pFile=fopen(filename.c_str(),"w+");
817 std::vector< std::string > lstNameThings;
818 int i,sizeLstNameThings;
820 fprintf(pFile,"--CreaContour--\n");
821 fprintf(pFile,"Version %s\n", "1.0.1" );
824 lstNameThings = kernelManager->GetLstNameThings();
825 sizeLstNameThings = lstNameThings.size();
826 fprintf(pFile,"NumberOfContours %d\n", sizeLstNameThings );
827 for (i=0 ; i<sizeLstNameThings ; i++)
829 kernelManager->SaveThingName( pFile, lstNameThings[i] );
830 _theViewPanel->getSceneManager()->SaveThingName( pFile, lstNameThings[i] );
833 //-- Contours Statics
834 lstNameThings = kernelManager->GetLstNameThingsStatic();
835 sizeLstNameThings = lstNameThings.size();
836 fprintf(pFile,"NumberOfContoursStatic %d\n", sizeLstNameThings );
837 for (i=0 ; i<sizeLstNameThings ; i++)
839 kernelManager->SaveThingName( pFile, lstNameThings[i] );
840 _theViewPanel->getSceneManager()->SaveThingName( pFile, lstNameThings[i] );
845 void wxContourMainFrame::openContours( FILE *pFile, bool staticContour ){
847 fscanf(pFile,"%s",tmp); // NumberOfContours
848 fscanf(pFile,"%s",tmp); // ##
849 int numberOfContours = atoi(tmp);
851 std::vector<int> instantVector;
852 int typeContourModel;
853 manualContourModel *manModelContour;
857 for (i=0;i<numberOfContours;i++)
859 instantVector.clear();
860 fscanf(pFile,"%s",tmp); // Instant
862 fscanf(pFile,"%s",tmp); // 1
863 instantVector.push_back( atoi(tmp) );
864 fscanf(pFile,"%s",tmp); // 2
865 instantVector.push_back( atoi(tmp) );
866 fscanf(pFile,"%s",tmp); // 3
867 instantVector.push_back( atoi(tmp) );
868 fscanf(pFile,"%s",tmp); // 4
869 instantVector.push_back( atoi(tmp) );
870 fscanf(pFile,"%s",tmp); // 5
871 instantVector.push_back( atoi(tmp) );
872 fscanf(pFile,"%s",tmp); // 6
873 instantVector.push_back( atoi(tmp) );
876 fscanf(pFile,"%s",tmp); // TypeContourModel
877 fscanf(pFile,"%s",tmp); // ##
878 typeContourModel = atoi(tmp);
880 manModelContour = kernelManager->factoryManualContourModel(typeContourModel);
881 manModelContour->Open(pFile);
883 fscanf(pFile,"%s",tmp); // TypeView
884 fscanf(pFile,"%s",tmp); // ##
885 typeView = atoi(tmp);
894 theName = kernelManager->createOutline( manModelContour, instantVector );
895 bool addedModel = theName.compare("") != 0;
898 double spc[3];//Si no hay imagen pero hay contornos que spacing se pone por default
899 _theViewPanel->getSpacing(spc);
900 //Adding the manualContourControler to interface objects structure
901 //Adding the manualViewContour to interface objects structure
902 //_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.
903 _theViewPanel->getSceneManager()->configureViewControlTo( theName, manModelContour,spc , typeView) ;
906 if (staticContour==true)
908 Instant instant(&instantVector);
909 kernelManager->changeContourOfManager( theName , &instant );
912 }// for numberOfContours
916 void wxContourMainFrame::RefreshInterface(){
918 _theViewPanel->RefreshInterface();
919 //wxVtk2DBaseView *wxvtk2dbaseview = (wxVtk2DBaseView*)this->_theViewPanel->getWxVtkBaseView();
920 //wxvtk2dbaseview->Refresh();
923 vtkImageData* wxContourMainFrame::getImageData(){
924 return _theViewPanel->getImageData();
927 void wxContourMainFrame::onSegmentationOneSliceITK(wxString distance, wxString sigma, wxString alfa, wxString beta, wxString propagation, wxString iterations, wxString inflation)
929 //JCP 20-10-08 Undo redo implementation
931 //JCP 20-10-08 Undo redo implementation
934 int x = _theViewPanel->GetX();
935 int y = _theViewPanel->GetY();
936 int z = _theViewPanel->GetZ();
937 SegmentationOneSliceITK( x,y,z,distance, sigma, alfa, beta, propagation, iterations, inflation);
941 void wxContourMainFrame::SegmentationOneSliceITK(int x, int y, int z, wxString distanc, wxString sigm, wxString alf, wxString bet, wxString prop, wxString iter, wxString inflation)
944 int typeofcontour = 1;
946 vtkImageData *imagedata = getImageData();
948 //Tipo de pixeles a utilizar internamente en ITK
949 typedef float InternalPixelType;
950 const unsigned int Dimension = 2;
951 typedef itk::Image< InternalPixelType, Dimension > InternalImageType;
953 //Tipo de pixeles de salida 1
954 typedef unsigned char OutputPixelType;
955 typedef itk::Image< OutputPixelType, Dimension > OutputImageType;
957 //Tipo de pixeles de salida 2
958 typedef unsigned short OutputPixelType2;
959 typedef itk::Image< OutputPixelType2, Dimension > OutputImageType2;
961 //Definición del thresholder
962 typedef itk::BinaryThresholdImageFilter<
964 OutputImageType > ThresholdingFilterType;
966 //Definición del primer filtro de conversión de pixeles
967 typedef itk::CastImageFilter<
968 OutputImageType, OutputImageType2 > CastFilterType;
970 //Definición del segundo tipo de conversión de pixeles
971 typedef itk::CastImageFilter<
972 OutputImageType2, InternalImageType > CastFilterType2;
974 //Tercer tipo de conversión
975 typedef itk::RescaleIntensityImageFilter<
977 OutputImageType > CastFilterType3;
979 //Cuarto tipo de conversión
980 typedef itk::RescaleIntensityImageFilter<
982 OutputImageType > CastFilterType4;
984 ThresholdingFilterType::Pointer thresholder = ThresholdingFilterType::New();
986 thresholder->SetLowerThreshold( 0.0 );
987 thresholder->SetUpperThreshold( 128 );
989 thresholder->SetOutsideValue( 255 );
990 thresholder->SetInsideValue( 0 );
992 //Definción de conexiónes entre VTK e ITK y el writer
993 typedef itk::VTKImageToImageFilter<OutputImageType2> ConnectorType;
994 typedef itk::ImageToVTKImageFilter<OutputImageType> ConnectorType2;
995 typedef itk::ImageFileWriter< OutputImageType > WriterType;
997 ConnectorType::Pointer connector= ConnectorType::New();
998 ConnectorType2::Pointer connector2= ConnectorType2::New();
1001 CastFilterType::Pointer filter=CastFilterType::New();
1002 CastFilterType2::Pointer filter2=CastFilterType2::New();
1004 connector->SetInput( imagedata );
1005 filter2->SetInput(connector->GetOutput());
1007 typedef itk::CurvatureAnisotropicDiffusionImageFilter<
1009 InternalImageType > SmoothingFilterType;
1011 SmoothingFilterType::Pointer smoothing = SmoothingFilterType::New();
1013 typedef itk::GradientMagnitudeRecursiveGaussianImageFilter<
1015 InternalImageType > GradientFilterType;
1017 typedef itk::SigmoidImageFilter<
1019 InternalImageType > SigmoidFilterType;
1021 GradientFilterType::Pointer gradientMagnitude = GradientFilterType::New();
1023 SigmoidFilterType::Pointer sigmoid = SigmoidFilterType::New();
1025 sigmoid->SetOutputMinimum( 0.0 );
1026 sigmoid->SetOutputMaximum( 255.0 );
1029 typedef itk::FastMarchingImageFilter<
1031 InternalImageType > FastMarchingFilterType;
1034 FastMarchingFilterType::Pointer fastMarching = FastMarchingFilterType::New();
1036 typedef itk::GeodesicActiveContourLevelSetImageFilter< InternalImageType,
1037 InternalImageType > GeodesicActiveContourFilterType;
1038 GeodesicActiveContourFilterType::Pointer geodesicActiveContour =
1039 GeodesicActiveContourFilterType::New();
1041 typedef itk::ZeroCrossingImageFilter<
1043 InternalImageType > ZeroCrossingFilterType;
1044 ZeroCrossingFilterType::Pointer zeroCrossing =
1045 ZeroCrossingFilterType::New();
1047 const double propagationScaling = atof( prop );
1049 geodesicActiveContour->SetPropagationScaling( propagationScaling );
1050 geodesicActiveContour->SetCurvatureScaling( 1.0 );
1051 geodesicActiveContour->SetAdvectionScaling( 1.0 );
1053 geodesicActiveContour->SetMaximumRMSError( 0.02 );
1054 int it=atoi( iter );
1055 geodesicActiveContour->SetNumberOfIterations( it );
1057 smoothing->SetInput( filter2->GetOutput() );
1058 gradientMagnitude->SetInput( smoothing->GetOutput() );
1059 sigmoid->SetInput( gradientMagnitude->GetOutput() );
1060 fastMarching->SetInput( sigmoid->GetOutput() );
1061 geodesicActiveContour->SetInput( fastMarching->GetOutput() );
1062 geodesicActiveContour->SetFeatureImage( sigmoid->GetOutput() );
1064 zeroCrossing->SetInput( geodesicActiveContour->GetOutput() );
1065 //thresholder->SetInput( zeroCrossing->GetOutput() );
1066 thresholder->SetInput( geodesicActiveContour->GetOutput() );
1067 connector2->SetInput( thresholder->GetOutput() );
1070 smoothing->SetTimeStep( 0.125 );
1071 smoothing->SetNumberOfIterations( 5 );
1072 smoothing->SetConductanceParameter( 9.0 );
1075 const double sigma = atof( sigm );
1076 gradientMagnitude->SetSigma( sigma );
1078 const double alpha = atof( alf );
1079 const double beta = atof( bet );
1081 sigmoid->SetAlpha( alpha );
1082 sigmoid->SetBeta( beta );
1084 typedef FastMarchingFilterType::NodeContainer NodeContainer;
1085 typedef FastMarchingFilterType::NodeType NodeType;
1087 NodeContainer::Pointer seeds = NodeContainer::New();
1089 InternalImageType::IndexType seedPosition;
1090 seedPosition[0] = x;
1091 seedPosition[1] = y;
1093 const double initialDistance = atof( distanc );
1097 const double seedValue = - initialDistance;
1099 node.SetValue( seedValue );
1100 node.SetIndex( seedPosition );
1102 seeds->Initialize();
1103 seeds->InsertElement( 0, node );
1105 fastMarching->SetTrialPoints( seeds );
1107 fastMarching->SetSpeedConstant( 1.0 );
1109 fastMarching->SetOutputSize(
1110 connector->GetOutput()->GetBufferedRegion().GetSize() );
1112 fastMarching->SetStoppingValue( 800 );
1116 connector2->Update();
1117 vtkImageData *idata = connector2->GetOutput();
1119 vtkMarchingContourFilter* cntVTK = vtkMarchingContourFilter::New( );
1121 cntVTK->SetInput( idata );
1123 cntVTK->SetNumberOfContours( 1 );
1124 cntVTK->SetValue( 0, 255 );
1126 cntVTK->UpdateInformation();
1128 vtkCleanPolyData* cpd = vtkCleanPolyData::New( );
1129 cpd->SetInput( cntVTK->GetOutput( ) );
1131 cpd->UpdateInformation();
1133 vtkPolyDataConnectivityFilter* conn = vtkPolyDataConnectivityFilter::New( );
1134 conn->SetExtractionModeToLargestRegion( );
1135 conn->SetInput( cpd->GetOutput( ) );
1137 conn->UpdateInformation();
1139 vtkStripper* vtkstripper = vtkStripper::New( );
1140 vtkstripper->SetInput( conn->GetOutput() );
1141 vtkstripper->Update();
1142 vtkstripper->UpdateInformation();
1145 vtkPolyData* polyDataResult = cntVTK->GetOutput();
1146 std::cout<<"Points "<<polyDataResult->GetNumberOfPoints()<<std::endl;
1147 polyDataResult->Update( );
1148 polyDataResult->UpdateInformation();
1153 myfile.open ("C:/Creatis/example.txt");
1155 polyDataResult->Print(myfile);
1156 myfile << "-------------------------------------\n";
1157 polyDataResult->GetLines()->Print(myfile);
1165 //--Calculating control points
1167 std::vector<double> vecX;
1168 std::vector<double> vecY;
1169 std::vector<double> vecXo;
1170 std::vector<double> vecYo;
1171 std::vector<double>::iterator vecXoi;
1172 std::vector<double>::iterator vecYoi;
1173 std::vector<double> vecZ;
1175 std::vector<double> vecCtrlPointX;
1176 std::vector<double> vecCtrlPointY;
1177 std::vector<double> vecCtrlPointZ;
1183 int ii,size=polyDataResult->GetNumberOfPoints();
1185 myfile.open ("C:/Creatis/example2.txt");
1187 size=polyDataResult->GetNumberOfPoints();
1188 for (ii=0;ii<size;ii++)
1195 p = polyDataResult->GetPoint(ii);
1198 /*if(fabs(yAct-y)>20)
1200 if((xAct-x)>1 || (xAct-x)<-1)
1202 vecX.push_back( p[0] );
1203 vecY.push_back( p[1] );
1204 myfile <<p[0]<<","<<p[1]<<"\n";
1205 std::cout<<" x Anterior "<<xAct<<" x actual "<<x<<std::endl;
1206 std::cout<<" y Anterior "<<yAct<<" y actual "<<y<<std::endl;
1207 std::cout<<" x "<<p[0]<<" y "<<p[1]<<std::endl;
1208 vecZ.push_back( -900 );
1214 vecXo.push_back(p[0]);
1215 vecYo.push_back(p[1]);
1219 else*/ if(fabs(xAct-x)>11)
1221 vecXo.push_back(p[0]);
1222 vecYo.push_back(p[1]);
1226 vecX.push_back( p[0] );
1227 myfile <<p[0]<<","<<p[1]<<"\n";
1228 std::cout<<" x Anterior "<<xAct<<" x actual "<<x<<std::endl;
1229 std::cout<<" y Anterior "<<yAct<<" y actual "<<y<<std::endl;
1230 std::cout<<" x "<<p[0]<<" y "<<p[1]<<std::endl;
1231 vecY.push_back( p[1] );
1232 vecZ.push_back( -900 );
1240 while(!vecXo.empty())
1242 vecX.push_back(vecXo.back());
1243 std::cout<<" x Siguiente "<<vecXo.back();
1245 vecZ.push_back( -900 );
1247 while(!vecYo.empty())
1249 vecY.push_back(vecYo.back());
1254 /*for(int l=0;l<vecX.size();l++)
1258 vecXo.push_back(p[0]);
1259 vecYo.push_back(p[1]);
1270 ExtractControlPoints2D *extractcontrolpoints2d = new ExtractControlPoints2D();
1272 extractcontrolpoints2d->SetContour( &vecX , &vecY , &vecZ );
1276 extractcontrolpoints2d->GetInitialControlPoints( &vecCtrlPointX , &vecCtrlPointY , &vecCtrlPointZ );
1278 else if (method==1){
1279 extractcontrolpoints2d->GetControlPoints( &vecCtrlPointX , &vecCtrlPointY , &vecCtrlPointZ );
1281 else if (method==2){
1282 extractcontrolpoints2d->SetSamplingControlPoints( 15 );
1283 extractcontrolpoints2d->GetSamplingControlPoints( &vecCtrlPointX , &vecCtrlPointY , &vecCtrlPointZ );
1285 //--Adding contour to the system
1287 std::vector<int> actualInstantVector;
1288 _instantPanel->getInstant( actualInstantVector );
1289 actualInstantVector[1]=z;
1291 int j,sizeCtrPt = vecCtrlPointX.size();
1293 manualContourModel *manModelContour = kernelManager->factoryManualContourModel( typeofcontour );
1294 manModelContour->SetNumberOfPointsSpline( ((sizeCtrPt/100)+1)*100 );
1296 for (j=0 ; j<sizeCtrPt ; j++)
1298 manModelContour->AddPoint( vecCtrlPointX[j] , vecCtrlPointY[j] , vecCtrlPointZ[j] );
1300 std::string theName;
1301 //theName = _modelManager->createOutline( manModelContour, actualInstantVector );
1302 theName = kernelManager->createOutline( manModelContour, actualInstantVector );
1303 bool addedModel = theName.compare("") != 0;
1306 double spc[3];//Si no hay imagen pero hay contornos que spacing se pone por default
1307 _theViewPanel->getSpacing(spc);
1308 //Adding the manualContourControler to interface objects structure
1309 //Adding the manualViewContour to interface objects structure
1310 //_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.
1311 _theViewPanel->configureViewControlTo(theName, manModelContour, spc, typeofcontour);
1312 //_theViewPanel->getSceneManager()->configureViewControlTo( theName, manModelContour,spc, typeofcontour ) ;
1318 WriterType::Pointer writer = WriterType::New();
1319 CastFilterType3::Pointer caster = CastFilterType3::New();
1321 caster->SetInput( gradientMagnitude->GetOutput() );
1322 writer->SetInput( caster->GetOutput() );
1323 writer->SetFileName("Gradient Magnitude.png");
1324 caster->SetOutputMinimum( 0 );
1325 caster->SetOutputMaximum( 255 );
1328 CastFilterType3::Pointer caster2 = CastFilterType3::New();
1329 WriterType::Pointer writer2 = WriterType::New();
1331 caster2->SetInput( sigmoid->GetOutput() );
1332 writer2->SetInput( caster2->GetOutput() );
1333 writer2->SetFileName("Sigmoid.png");
1334 caster2->SetOutputMinimum( 0 );
1335 caster2->SetOutputMaximum( 255 );
1338 CastFilterType3::Pointer caster3 = CastFilterType3::New();
1339 WriterType::Pointer writer3 = WriterType::New();
1341 caster3->SetInput( fastMarching->GetOutput() );
1342 writer3->SetInput( caster3->GetOutput() );
1343 writer3->SetFileName("FastMarching.bmp");
1344 caster3->SetOutputMinimum( 0 );
1345 caster3->SetOutputMaximum( 255 );
1348 CastFilterType3::Pointer caster4 = CastFilterType3::New();
1349 WriterType::Pointer writer4 = WriterType::New();
1351 caster4->SetInput( geodesicActiveContour->GetOutput() );
1352 writer4->SetInput( caster4->GetOutput() );
1353 writer4->SetFileName("GeodesicActiveContour.png");
1354 caster4->SetOutputMinimum( 0 );
1355 caster4->SetOutputMaximum( 255 );
1358 CastFilterType3::Pointer caster5 = CastFilterType3::New();
1359 WriterType::Pointer writer5 = WriterType::New();
1361 caster5->SetInput( zeroCrossing->GetOutput() );
1362 writer5->SetInput( caster5->GetOutput() );
1363 writer5->SetFileName("ZeroCrossing.bmp");
1364 caster5->SetOutputMinimum( 0 );
1365 caster5->SetOutputMaximum( 255 );
1368 catch( itk::ExceptionObject & excep )
1370 std::cerr << "Exception caught !" << std::endl;
1371 std::cerr << excep << std::endl;
1375 void wxContourMainFrame::onSegmentationOneSlice(int isovalue,int sampling,int method){
1377 //JCP 20-10-08 Undo redo implementation
1379 //JCP 20-10-08 Undo redo implementation
1382 int x = _theViewPanel->GetX();
1383 int y = _theViewPanel->GetY();
1384 int z = _theViewPanel->GetZ();
1385 SegmentationOneSlice( x,y,z,isovalue, sampling, method );
1390 void wxContourMainFrame::SegmentationOneSlice( int x, int y, int z, int isovalue, int sampling, int method )
1392 int typeofcontour = 1;
1393 //--Extracting Contour
1394 //vtkImageData *imagedata = _theViewPanel->getSceneManager()->GetImageData();
1395 vtkImageData *imagedata = getImageData();
1396 // double *range = imagedata->GetScalarRange();
1399 vtkImageReslice *imageReslice = vtkImageReslice::New();
1402 // imagedata->GetSpacing(spc);
1407 imageReslice->SetInput( imagedata );
1408 imageReslice->SetInformationInput(imagedata);
1409 imageReslice->SetResliceAxesDirectionCosines(1,0,0, 0,1,0 ,0,0,1);
1410 imageReslice->SetResliceAxesOrigin(0,0,z);
1411 imageReslice->SetOutputDimensionality(2);
1412 imageReslice->SetInterpolationModeToLinear();
1414 imagedata = imageReslice->GetOutput();
1415 imagedata->Update();
1416 imagedata->UpdateInformation();
1418 vtkContourFilter* cntVTK = vtkContourFilter::New( );
1419 cntVTK->SetInput( imagedata );
1421 cntVTK->SetNumberOfContours( 1 );
1422 //cntVTK->SetValue( 0, vmin );
1423 // cntVTK->SetValue( 0, (range[1]*thr/100) );
1424 cntVTK->SetValue( 1, isovalue );
1425 // cntVTK->SetValue( 1, vmax );
1427 cntVTK->UpdateInformation();
1429 vtkCleanPolyData* cpd = vtkCleanPolyData::New( );
1430 cpd->SetInput( cntVTK->GetOutput( ) );
1431 cpd->ConvertLinesToPointsOff( );
1433 cpd->UpdateInformation();
1435 vtkPolyDataConnectivityFilter* conn = vtkPolyDataConnectivityFilter::New( );
1436 conn->SetExtractionModeToClosestPointRegion( );
1437 //conn->SetMaxRecursionDepth( 3000 );
1439 conn->SetInput( cpd->GetOutput( ) );
1441 conn->SetClosestPoint( x, y, 0 );
1443 conn->UpdateInformation();
1445 vtkCleanPolyData* cpd2 = vtkCleanPolyData::New( );
1446 cpd2->SetInput( conn->GetOutput( ) );
1448 cpd2->UpdateInformation();
1450 vtkStripper* vtkstripper = vtkStripper::New( );
1451 vtkstripper->SetInput( cpd2->GetOutput() );
1452 vtkstripper->Update();
1453 vtkstripper->UpdateInformation();
1456 vtkPolyData* polyDataResult = vtkstripper->GetOutput();
1458 polyDataResult->Update( );
1459 polyDataResult->UpdateInformation();
1463 myfile.open ("c:/temp/example.txt");
1465 polyDataResult->Print(myfile);
1466 myfile << "-------------------------------------\n";
1467 polyDataResult->GetLines()->Print(myfile);
1477 //--Calculating control points
1479 std::vector<double> vecX;
1480 std::vector<double> vecY;
1481 std::vector<double> vecZ;
1483 std::vector<double> vecCtrlPointX;
1484 std::vector<double> vecCtrlPointY;
1485 std::vector<double> vecCtrlPointZ;
1489 int ii,size=polyDataResult->GetNumberOfPoints();
1491 for (ii=1;ii<=size;ii++)
1493 id = polyDataResult->GetLines()->GetData()->GetValue(ii);
1494 p = polyDataResult->GetPoint(id);
1497 vecX.push_back( p[0] );
1498 vecY.push_back( p[1] );
1499 vecZ.push_back( -900 );
1500 // vecZ.push_back( p[2] );
1504 ExtractControlPoints2D *extractcontrolpoints2d = new ExtractControlPoints2D();
1505 extractcontrolpoints2d->SetContour( &vecX , &vecY , &vecZ );
1508 /*if (methodRadiobox->GetSelection()==0){
1509 extractcontrolpoints2d->GetInitialControlPoints( &vecCtrlPointX , &vecCtrlPointY , &vecCtrlPointZ );
1511 if (methodRadiobox->GetSelection()==1){
1512 extractcontrolpoints2d->GetControlPoints( &vecCtrlPointX , &vecCtrlPointY , &vecCtrlPointZ );
1514 if (methodRadiobox->GetSelection()==2){
1515 extractcontrolpoints2d->SetSamplingControlPoints( sampling );
1516 extractcontrolpoints2d->GetSamplingControlPoints( &vecCtrlPointX , &vecCtrlPointY , &vecCtrlPointZ );
1520 extractcontrolpoints2d->GetInitialControlPoints( &vecCtrlPointX , &vecCtrlPointY , &vecCtrlPointZ );
1522 else if (method==1){
1523 extractcontrolpoints2d->GetControlPoints( &vecCtrlPointX , &vecCtrlPointY , &vecCtrlPointZ );
1525 else if (method==2){
1526 extractcontrolpoints2d->SetSamplingControlPoints( sampling );
1527 extractcontrolpoints2d->GetSamplingControlPoints( &vecCtrlPointX , &vecCtrlPointY , &vecCtrlPointZ );
1530 //--Adding contour to the system
1532 std::vector<int> actualInstantVector;
1533 _instantPanel->getInstant( actualInstantVector );
1534 actualInstantVector[1]=z;
1536 int j,sizeCtrPt = vecCtrlPointX.size();
1537 manualContourModel *manModelContour = kernelManager->factoryManualContourModel( typeofcontour );
1538 manModelContour->SetNumberOfPointsSpline( ((sizeCtrPt/100)+1)*100 );
1540 for (j=0 ; j<sizeCtrPt ; j++)
1542 manModelContour->AddPoint( vecCtrlPointX[j] , vecCtrlPointY[j] , vecCtrlPointZ[j] );
1544 std::string theName;
1545 //theName = _modelManager->createOutline( manModelContour, actualInstantVector );
1546 theName = kernelManager->createOutline( manModelContour, actualInstantVector );
1547 bool addedModel = theName.compare("") != 0;
1550 double spc[3];//Si no hay imagen pero hay contornos que spacing se pone por default
1551 _theViewPanel->getSpacing(spc);
1552 //Adding the manualContourControler to interface objects structure
1553 //Adding the manualViewContour to interface objects structure
1554 //_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.
1555 _theViewPanel->configureViewControlTo(theName, manModelContour, spc, typeofcontour);
1556 //_theViewPanel->getSceneManager()->configureViewControlTo( theName, manModelContour,spc, typeofcontour ) ;
1561 int wxContourMainFrame::GetImageDataSizeZ(){
1562 return _theViewPanel->GetImageDataSizeZ();
1565 void wxContourMainFrame::GetImageDataRange(double *range){
1566 _theViewPanel->GetImageDataRange(range);
1569 void wxContourMainFrame::onSegmentationAllSlice(int minZ,int maxZ,int isovalue,int sampling,int method){
1570 //JCP 20-10-08 Undo redo implementation
1572 //JCP 20-10-08 Undo redo implementation
1575 int x = _theViewPanel->GetX();
1576 int y = _theViewPanel->GetY();
1580 double totalZ = maxZ-minZ+1;
1581 for( z=minZ ; z<=maxZ ; z++ )
1583 porcent = 100.0* (z-minZ)/totalZ;
1584 tmpString.Printf(_T(" %d %c %d/%d %d"), (int)porcent , 37 , z-minZ+1, (int)totalZ,z );
1585 interfMainPanel::getInstance()->setLabelSegmentationPanelVTK(tmpString);
1586 //_staticTextSegmentation->SetLabel(tmpString);
1587 SegmentationOneSlice( x,y,z,isovalue, sampling,method );
1589 interfMainPanel::getInstance()->setLabelSegmentationPanelVTK(_T(" "));
1594 //Creates a reference line to be used as the axis of the mirroring
1595 void wxContourMainFrame::referenceLine()
1600 vtkImageData *vtkimagedata = _theViewPanel->getImageData();
1601 vtkimagedata->GetSpacing(spc);
1603 wxVtkBaseView * viewer2D = _theViewPanel->getWxVtkBaseView();
1605 _refLineControl = new manualLineControler();
1606 _refLineModel = new manualContourModelLine();
1607 _refLineView = new manualViewLine();
1608 _refLineView->SetModel( _refLineModel );
1609 _refLineView->SetWxVtkBaseView( viewer2D );
1610 _refLineView->SetRange( 2 );
1611 _refLineView->SetZ( 1200 );
1613 _refLineView->SetSpacing(spc);
1615 _refLineView->SetColorNormalContour(0, 0, 1);
1616 _refLineView->SetColorEditContour(0, 0.5, 0.5);
1617 _refLineView->SetWidthLine(4);
1619 _refLineControl->SetModelView( _refLineModel , _refLineView );
1620 viewer2D->GetInteractorStyleBaseView()->AddInteractorStyleMaracas( _refLineControl );
1621 _refLineModel->SetCloseContour(false);
1622 _refLineControl->CreateNewManualContour();
1624 double z = _refLineControl->GetZ();
1626 _refLineControl->AddPoint(50,100,z);
1627 _refLineControl->AddPoint(80,40,z);
1628 _refLineControl->SetCompleteCreation(true);
1630 _refLineModel->AddPoint(50,100,z);
1631 _refLineModel->AddPoint(80,40,z);
1632 _refLineModel->UpdateSpline();
1634 _refLineView->UpdateViewPoint(0);
1635 _refLineView->UpdateViewPoint(1);
1638 _refLineControl->SetActive(true);
1639 _refLineView->RefreshContour();
1642 //Hides the referenceLine
1643 void wxContourMainFrame::refLineHide()
1645 if (_refLineControl!=NULL)
1647 _refLineView->RemoveCompleteContourActor();
1648 _refLineControl->SetEditable(false);
1649 _refLineControl->SetActive(false);
1653 //Shows the referenceLine
1654 void wxContourMainFrame::refLineShow()
1656 if (_refLineControl!=NULL)
1658 wxVtkBaseView * viewer2D = _theViewPanel->getWxVtkBaseView();
1660 _refLineView->SetModel( _refLineModel );
1661 _refLineView->SetWxVtkBaseView( viewer2D );
1662 _refLineView->SetRange( 2 );
1663 _refLineView->SetZ( 1200 );
1665 _refLineControl->SetModelView( _refLineModel , _refLineView );
1666 viewer2D->GetInteractorStyleBaseView()->AddInteractorStyleMaracas( _refLineControl );
1667 _refLineControl->CreateNewManualContour();
1668 _refLineControl->SetActive(true);
1669 _refLineView->RefreshContour();
1673 void wxContourMainFrame::onMirror()
1676 std::vector<std::string> currentSelection = _theViewPanel->getSelectedObjects();
1677 std::vector<std::string> filterCurrentSelection;
1679 std::vector<int> tempVector;
1680 _instantPanel->getInstant( tempVector );
1681 _performingOperation->reset();
1682 _performingOperation->setStartCommand( COPY );
1683 _performingOperation->setStartOperationInstantVector( tempVector );
1684 _performingOperation->setKeyNamesOperationElems( currentSelection );
1686 char theStartCommand = _performingOperation->getStartCommand();
1687 if ( theStartCommand == COPY )
1689 //JCP 20-10-08 Undo redo implementation
1691 //JCP 20-10-08 Undo redo implementation
1692 std::vector<int> tempVector;
1693 _instantPanel->getInstant( tempVector );
1694 _performingOperation->setEndOperationInstantVector ( tempVector );
1695 std::vector<std::string> elems = _performingOperation->getKeyNamesOperationElems();
1696 int i,size = elems.size();
1697 for( i=0; i<size; i++ )
1699 createMirrorContourOf( elems[i], tempVector, i>0 );
1703 //deleteContour( _refName );
1707 void wxContourMainFrame::showAxis(bool show){
1708 _theViewPanel->SetVisibleAxis(show);
1709 _theViewPanel->Refresh();
1713 void wxContourMainFrame::onRigidPressed(){
1714 std::vector<std::string> currentSelection = _theViewPanel->getSelectedObjects();
1715 int elementsSelected = currentSelection.size();
1717 if ( elementsSelected >= 1 ){
1718 //JCP 20-10-08 Undo redo implementation
1720 //JCP 20-10-08 Undo redo implementation
1722 std::vector<int> tempVector;
1723 _instantPanel->getInstant( tempVector );
1724 Instant instant(&tempVector);
1726 int i , size=currentSelection.size();
1727 for ( i=0 ; i<size ; i++ )
1729 kernelManager->changeContourOfManager(currentSelection[i], &instant);
1734 void wxContourMainFrame::onWidthOfContour(double width){
1736 _theViewPanel->removeSceneContours();
1737 _theViewPanel->SetWidthContour(width);
1739 //_theViewPanel->getSceneManager()->SetWidthContour( width );
1743 int wxContourMainFrame::getColorWindow(){
1744 return _theViewPanel->getColorWindow();
1746 int wxContourMainFrame::getWindowLevel(){
1747 return _theViewPanel->getWindowLevel();
1750 void wxContourMainFrame::onBrigthnessColorWindowLevel(int colorwindow,int windowlevel){
1751 _theViewPanel->onBrigthnessColorWindowLevel(colorwindow, windowlevel);
1757 void wxContourMainFrame::onInterpolation(bool interpolate){
1758 _theViewPanel->onInterpolation(interpolate);
1762 void wxContourMainFrame::onChangeInstant(std::string name,int actual){
1763 _instantPanel->setConceptValue( name, actual );
1766 void wxContourMainFrame::resetAppend(){
1767 kernelManager->resetAppend();
1771 void wxContourMainFrame::onSpreadAdd(){
1772 std::vector<double> vecX;
1773 std::vector<double> vecY;
1774 std::vector<double> vecZ;
1775 _theViewPanel->GetPointsOfActualContour(&vecX , &vecY , &vecZ );
1777 std::vector<int> tempVector;
1778 _instantPanel->getInstant( tempVector );
1780 std::string val = kernelManager->onSpreadAdd(&vecX , &vecY , &vecZ, tempVector);
1782 interfMainPanel::getInstance()->appendStringSpread(val);
1786 void wxContourMainFrame::onSpreadGo(int type){
1788 //JCP 20-10-08 Undo redo implementation
1790 //JCP 20-10-08 Undo redo implementation
1793 std::vector<double> vecCtrlPointX;
1794 std::vector<double> vecCtrlPointY;
1795 std::vector<double> vecCtrlPointZ;
1799 std::vector<int> tempVector;
1800 _instantPanel->getInstant( tempVector );
1803 kernelManager->getMaxMinZ(&minZ,&maxZ);
1804 //JSTG_16-07-08_----------------------------------------------------------------
1805 //_contourPropagation->setInterpolationNumber(maxZ-minZ+1);
1806 kernelManager->CalculeSplinePropagation();
1808 double totalZ = maxZ-minZ+1;
1811 //--------------------------------------------------------------------
1812 for ( z=(int)minZ ; z<=(int)maxZ ; z++ )
1814 porcent = 100.0* (z-minZ)/totalZ;
1815 int numero = (int)(z-minZ+1)/(int)totalZ;
1816 std::string stringtemp = " "+kernelManager->intToString(porcent)+"% "+kernelManager->intToString(numero)+" "+kernelManager->intToString(z);
1818 interfMainPanel::getInstance()->setStringSpread(stringtemp);
1820 int typeofcontour = 1;
1821 std::string theName;
1822 manualContourModel* manModelContour = kernelManager->GetPoints(z, type, &vecCtrlPointX,&vecCtrlPointY,&vecCtrlPointZ, theName,typeofcontour, tempVector);
1824 if( manModelContour!=NULL ){
1825 double spc[3];//Si no hay imagen pero hay contornos que spacing se pone por default
1826 this->_theViewPanel->getSpacing(spc);
1827 //Adding the manualContourControler to interface objects structure
1828 //Adding the manualViewContour to interface objects structure
1829 //_theViewPanel->getSceneManager()->setControlActiveStateOfALL( false );//This call is being done here because if the ROI is created underneath the previously created ROIS will still be active.
1830 _theViewPanel->configureViewControlTo( theName, manModelContour,spc,typeofcontour ) ;
1835 int numero = (int)(z-minZ+1)/(int)totalZ;
1836 std::string stringtemp = " "+kernelManager->intToString(porcent)+"% "+kernelManager->intToString(numero)+" "+kernelManager->intToString(z);
1838 interfMainPanel::getInstance()->setStringSpread(stringtemp);
1840 //RefreshInterface();
1843 void wxContourMainFrame::getInstantVector(std::vector<int>& tempVector){
1847 std::vector<std::string> wxContourMainFrame::getOutlinesName(int slide){
1848 std::vector<int> tempVector;
1849 _instantPanel->getInstant(tempVector);
1850 //Asignation of slide number should be different ex by name
1851 tempVector[1]=slide;
1852 return kernelManager->getOutlinesNameAtInstant(tempVector);
1855 void wxContourMainFrame::onInformationContourLabels(int typeContourGroup,int selection,int minimumZ,int maximumZ){
1856 int maxContourGroup = 0;
1858 ContourExtractData *contourextractdata = new ContourExtractData();
1860 contourextractdata ->SetTypeOperation( typeContourGroup % 3 );
1862 std::vector<manualContourModel*> lstManConMod;
1863 std::vector<manualContourModel*> lstManConModTmp;
1864 std::vector<manualContourModel*> lstManConModExp;
1865 std::vector<double> pLstValue;
1866 std::vector<double> pLstValuePosX;
1867 std::vector<double> pLstValuePosY;
1868 std::vector<double> pLstValuePosZ;
1871 int resultGrayRangeCount;
1874 double resultAverage;
1875 double resultStandardeviation;
1877 std::vector<int> tempVector;
1878 _instantPanel->getInstant( tempVector );
1880 vtkImageData *imagedata = _theViewPanel->getImageData();
1881 int sizeZ = _theViewPanel->GetImageDataSizeZ();
1883 int ii,sizeLstContourThings;
1893 if (selection==0 ) // actual slice
1895 std::vector<int> tempVector;
1896 _instantPanel->getInstant( tempVector );
1897 int actualSlice = tempVector[1];
1901 else if (selection==2 ) // All slices
1906 else if (selection==1 ) // slice range
1913 totalZ = maxZ-minZ+1;
1914 contourextractdata->SetImage( imagedata);
1917 for ( z=minZ ; z<=maxZ ; z++ )
1920 porcent = 100.0* (z-minZ)/totalZ;
1921 tmpString.Printf(_T(" %d %c %d/%d %d"), (int)porcent , 37 , z-minZ+1, (int)totalZ ,z);
1923 interfMainPanel::getInstance()->setStringInfoPanel(tmpString);
1924 //_staticTextInformation->SetLabel(tmpString);
1926 //Extraction data from contours of each slice
1927 contourextractdata->SetZtoBeAnalys( z);
1930 Instant instant(&tempVector);
1931 std::vector<ContourThing**> lstContourThings = kernelManager->getOutlinesAtInstant( &instant );
1932 sizeLstContourThings = lstContourThings.size();
1934 lstManConMod.clear();
1935 for (ii=0 ; ii<sizeLstContourThings ; ii++)
1937 ContourThing **contourthing = lstContourThings[ii];
1938 lstManConMod.push_back( (*contourthing)->getModel() );
1940 lstManConModExp = kernelManager->ExploseEachModel( lstManConMod );
1943 wxString tempString;
1944 tempString.Printf(_T("%d - %d"),z, sizeLstContourThings);
1945 interfMainPanel::getInstance()->setRowLabelInfoPanel(z, tempString);
1946 //_grid->SetRowLabelValue(z, tempString );
1948 int iContourGroup,sizeContourGroup;
1949 if (typeContourGroup==3) // contour separete
1951 sizeContourGroup=lstManConModExp.size();
1952 if ( maxContourGroup<sizeContourGroup )
1954 maxContourGroup=sizeContourGroup;
1956 } else { // contour AND OR XOR
1965 for( iContourGroup=0 ; iContourGroup<sizeContourGroup ; iContourGroup++ ){
1966 lstManConModTmp.clear();
1967 if (typeContourGroup==3) // contour separete
1969 lstManConModTmp.push_back( lstManConModExp[iContourGroup]);
1970 } else { // contour AND OR XOR
1971 lstManConModTmp = lstManConModExp;
1974 contourextractdata->SetLstManualContourModel( lstManConModTmp );
1977 pLstValuePosX.clear();
1978 pLstValuePosY.clear();
1979 pLstValuePosZ.clear();
1980 contourextractdata->GetValuesInsideCrown( &pLstValue,
1984 // Statistics of each slice.
1985 contourextractdata->Statistics( &pLstValue,
1988 &resultGrayRangeCount,
1993 &resultStandardeviation);
1995 if (interfMainPanel::getInstance()->getNumberColsInformationPanel()<_numberOfVariablesStatistics*(iContourGroup+1) )
1997 interfMainPanel::getInstance()->appendColsInformationPanel(_numberOfVariablesStatistics);
2000 tmpIntA=_numberOfVariablesStatistics*iContourGroup ;
2002 tempString.Printf(_T("%d"),resultSize);
2003 interfMainPanel::getInstance()->setCellValueInfoPanel(z, tmpIntA, tempString);
2005 tempString.Printf(_T("%d"),resultGrayRangeCount);
2006 interfMainPanel::getInstance()->setCellValueInfoPanel(z, tmpIntA+1, tempString);
2008 tempString.Printf(_T("%f"),resultMin);
2009 interfMainPanel::getInstance()->setCellValueInfoPanel(z, tmpIntA+2, tempString);
2011 tempString.Printf(_T("%f"),resultMax);
2012 interfMainPanel::getInstance()->setCellValueInfoPanel(z, tmpIntA+3, tempString);
2014 tempString.Printf(_T("%f"),resultAverage);
2015 interfMainPanel::getInstance()->setCellValueInfoPanel(z, tmpIntA+4, tempString);
2017 tempString.Printf(_T("%f"),resultStandardeviation);
2018 interfMainPanel::getInstance()->setCellValueInfoPanel(z, tmpIntA+5, tempString);
2021 } // for iContourGroup
2025 wxString tmpTitleString;
2027 for ( iTitleGroup=0 ; iTitleGroup<maxContourGroup ; iTitleGroup++ )
2029 tmpIntB =_numberOfVariablesStatistics*iTitleGroup;
2030 tmpTitleString.Printf(_T("%d-Size Data"),iTitleGroup);
2031 interfMainPanel::getInstance()->setColLableInfoPanel(tmpIntB + 0, tmpTitleString);
2033 interfMainPanel::getInstance()->setColLableInfoPanel(tmpIntB + 0, tmpTitleString );
2034 interfMainPanel::getInstance()->setColLableInfoPanel( tmpIntB + 1, _T("Size Range") );
2035 interfMainPanel::getInstance()->setColLableInfoPanel( tmpIntB + 2, _T("Min") );
2036 interfMainPanel::getInstance()->setColLableInfoPanel( tmpIntB + 3, _T("Max") );
2037 interfMainPanel::getInstance()->setColLableInfoPanel( tmpIntB + 4, _T("Average") );
2038 interfMainPanel::getInstance()->setColLableInfoPanel( tmpIntB + 5, _T("St.Dev.") );
2039 interfMainPanel::getInstance()->setColLableInfoPanel( tmpIntB + 6, _T(" ") );
2042 interfMainPanel::getInstance()->setStringInfoPanel( _T("") );
2043 delete contourextractdata;
2046 void wxContourMainFrame::onSaveResults(std::string directory,std::string namefile, std::string filename, int typeContourGroup){
2047 SaveValuesXYZ( directory , namefile, typeContourGroup );
2048 SaveImageResult( directory , namefile, typeContourGroup);
2051 FILE *pFile=fopen(filename.c_str(),"w+");
2053 int sizeZ = _theViewPanel->GetImageDataSizeZ();
2056 int i,j,maxX,maxY=sizeZ;
2057 maxX= interfMainPanel::getInstance()->getNumberColsInformationPanel();//this->_grid->GetNumberCols();
2059 int iTitle,sizeTitle = (maxX / _numberOfVariablesStatistics);
2060 for ( iTitle=0; iTitle<sizeTitle ; iTitle++)
2062 // fprintf(pFile,"-- \t %d-Size \t SizeRange \t Min \t Max \t Ave \t StDv \t" , iTitle,tmpString.c_str() );
2063 fprintf(pFile,"-- \t %d-Size \t SizeRange \t Min \t Max \t Ave \t StDv \t" , iTitle );
2065 fprintf(pFile,"\n" );
2069 for ( j=0; j<maxY ; j++)
2071 fprintf(pFile,"%d\t" , j );
2072 for (i=0 ; i<maxX ; i++){
2073 tmpString = interfMainPanel::getInstance()->getCellValue(j, i);//_grid->GetCellValue( j , i );
2074 fprintf(pFile,"%s\t" , (const char *)(tmpString.mb_str()) );
2076 fprintf(pFile,"\n" );
2082 void wxContourMainFrame::SaveValuesXYZ(std::string directory,std::string namefile,int typeContourGroup)
2085 ContourExtractData *contourextractdata = new ContourExtractData();
2086 //int typeContourGroup = this->_radiolstboxContourGroup->GetSelection();
2087 contourextractdata ->SetTypeOperation( typeContourGroup % 3 );
2089 std::vector<manualContourModel*> lstManConMod;
2090 std::vector<manualContourModel*> lstManConModTmp;
2091 std::vector<manualContourModel*> lstManConModExp;
2092 std::vector<double> pLstValue;
2093 std::vector<double> pLstValuePosX;
2094 std::vector<double> pLstValuePosY;
2095 std::vector<double> pLstValuePosZ;
2097 std::vector<int> tempVector;
2098 _instantPanel->getInstant( tempVector );
2100 vtkImageData *imagedata = _theViewPanel->getSceneManager()->GetImageData();
2101 int sizeZ = _theViewPanel->getSceneManager()->GetImageDataSizeZ();
2103 int ii,sizeLstContourThings;
2110 minZ = 0;// _mbarrange->GetStart();
2111 maxZ = sizeZ;//_mbarrange->GetEnd();
2112 totalZ = maxZ-minZ+1;
2114 contourextractdata->SetImage( imagedata);
2117 for ( z=0 ; z<sizeZ ; z++)
2120 porcent = 100.0* (z-minZ)/totalZ;
2122 tmpString.Printf(_T("Saving Values"));
2123 tmpString.Printf(_T(" %d %c %d/%d %d"), (int)porcent , 37 , z-minZ+1, (int)totalZ ,z);
2124 interfMainPanel::getInstance()->setStringInfoPanel(tmpString);
2125 //_staticTextInformation->SetLabel(tmpString);
2128 //Extraction data from contours of each slice
2129 contourextractdata->SetZtoBeAnalys( z);
2132 Instant instant(&tempVector);
2133 std::vector<ContourThing**> lstContourThings = kernelManager->getOutlinesAtInstant(&instant);//this->_modelManager->getOutlinesAtInstant( &instant );
2134 sizeLstContourThings = lstContourThings.size();
2136 lstManConMod.clear();
2137 for (ii=0 ; ii<sizeLstContourThings ; ii++)
2139 ContourThing **contourthing = lstContourThings[ii];
2140 lstManConMod.push_back( (*contourthing)->getModel() );
2142 lstManConModExp = kernelManager->ExploseEachModel( lstManConMod );
2147 int iContourGroup,sizeContourGroup;
2148 if (typeContourGroup==3) // contour separete
2150 sizeContourGroup=lstManConModExp.size();
2151 } else { // contour AND OR XOR
2155 for( iContourGroup=0 ; iContourGroup<sizeContourGroup ; iContourGroup++ ){
2156 lstManConModTmp.clear();
2157 if (typeContourGroup==3) // contour separete
2159 lstManConModTmp.push_back( lstManConModExp[iContourGroup]);
2160 } else { // contour AND OR XOR
2161 lstManConModTmp = lstManConModExp;
2164 contourextractdata->SetLstManualContourModel( lstManConModTmp );
2167 pLstValuePosX.clear();
2168 pLstValuePosY.clear();
2169 pLstValuePosZ.clear();
2170 contourextractdata->GetValuesInsideCrown( &pLstValue,
2175 std::string temp = directory + "/" + namefile + "-slice";
2176 temp = temp + kernelManager->intToString(z) + "-cont" + kernelManager->intToString(iContourGroup);
2177 temp = temp + ".txt";
2179 // LG 14/01/09 : using crea
2180 wxString filename = crea::std2wx(temp);
2181 /*filename.Printf(_T("%s"),directory.c_str());
2182 filename.append(_T("\\"));
2183 filename.append(_T("%s"),namefile.c_str());
2184 filename.append(_T("-slice"));
2185 filename.append(_T("%d"),z);
2186 filename.append(_T("-cont"));
2187 filename.append(_T("%d"),iContourGroup);
2188 filename.append(_T(".txt"));*/
2189 // filename.Printf(temp.c_str());
2193 FILE *pFile=fopen((const char *)filename.mb_str(),"w+");
2194 fprintf(pFile,"value \t x \t y \t z\n" );
2195 int iLstValue,sizeLstValue=pLstValue.size();
2196 for (iLstValue=0 ; iLstValue<sizeLstValue ; iLstValue++ )
2198 fprintf(pFile,"%f\t %f\t %f\t %f\n", (float)pLstValue[iLstValue] , (float)pLstValuePosX[iLstValue], (float)pLstValuePosY[iLstValue], (float)z );
2201 } // for iContourGroup
2203 interfMainPanel::getInstance()->setStringInfoPanel(_T(""));
2204 //_staticTextInformation->SetLabel( _T("") );
2205 delete contourextractdata;
2208 void wxContourMainFrame::SaveImageResult(std::string directory,std::string namefile, int typeContourGroup)
2211 ContourExtractData *contourextractdata = new ContourExtractData( true );
2212 //int typeContourGroup = this->_radiolstboxContourGroup->GetSelection();
2213 if (typeContourGroup==3)
2217 contourextractdata ->SetTypeOperation( typeContourGroup % 3 );
2219 std::vector<manualContourModel*> lstManConMod;
2220 std::vector<manualContourModel*> lstManConModTmp;
2221 std::vector<manualContourModel*> lstManConModExp;
2223 std::vector<int> tempVector;
2224 _instantPanel->getInstant( tempVector );
2226 vtkImageData *imagedata = _theViewPanel->getImageData();
2227 int sizeZ = _theViewPanel->GetImageDataSizeZ();
2229 int ii,sizeLstContourThings;
2238 minZ = 0;// _mbarrange->GetStart();
2239 maxZ = sizeZ;//_mbarrange->GetEnd();
2240 totalZ = maxZ-minZ+1;
2242 contourextractdata->SetImage( imagedata);
2245 for ( z=0 ; z<sizeZ ; z++)
2248 porcent = 100.0* (z-minZ)/totalZ;
2249 tmpString.Printf(_T("Saving Values"));
2250 tmpString.Printf(_T("%d %c %d/%d %d"), (int)porcent , 37 , z-minZ+1, (int)totalZ ,z);
2251 interfMainPanel::getInstance()->setStringInfoPanel(tmpString);
2253 //Extraction data from contours of each slice
2254 contourextractdata->SetZtoBeAnalys( z);
2257 Instant instant(&tempVector);
2258 std::vector<ContourThing**> lstContourThings = kernelManager->getOutlinesAtInstant( &instant );
2259 sizeLstContourThings = lstContourThings.size();
2261 lstManConMod.clear();
2262 for (ii=0 ; ii<sizeLstContourThings ; ii++)
2264 ContourThing **contourthing = lstContourThings[ii];
2265 lstManConMod.push_back( (*contourthing)->getModel() );
2267 lstManConModExp = kernelManager->ExploseEachModel( lstManConMod );
2270 int iContourGroup,sizeContourGroup;
2271 if (typeContourGroup==3) // contour separete
2273 sizeContourGroup=lstManConModExp.size();
2274 } else { // contour AND OR XOR
2278 for( iContourGroup=0 ; iContourGroup<sizeContourGroup ; iContourGroup++ ){
2279 lstManConModTmp.clear();
2280 if (typeContourGroup==3) // contour separete
2282 lstManConModTmp.push_back( lstManConModExp[iContourGroup]);
2283 } else { // contour AND OR XOR
2284 lstManConModTmp = lstManConModExp;
2287 contourextractdata->SetLstManualContourModel( lstManConModTmp );
2290 // for (ii=0 ; ii<sizeLstContourThings ; ii++)
2292 // ContourThing **contourthing = lstContourThings[ii];
2293 // lstManConMod.push_back( (*contourthing)->getModel() );
2295 // contourextractdata->SetLstManualContourModel( lstManConMod );
2297 contourextractdata->CalculateImageResult(); // with actual Z
2299 } // for iContourGroup
2302 std::string temp = directory + "/" + namefile + "-Value.mhd";
2304 wxString filename = crea::std2wx(temp);
2306 // filename.Printf(_T(temp.c_str()));
2307 //filename.Printf(_T("%s\\%s-Value.mhd",directory.c_str(),namefile.c_str(),z);
2308 /*filename.Printf(_T("%s"),directory.c_str());
2309 filename.append(_T("\\"));
2310 filename.append(_T("%s"),namefile.c_str());
2311 filename.append(_T("-Value.mhd"));*/
2314 vtkMetaImageWriter *writerValueImage = vtkMetaImageWriter::New( );
2315 writerValueImage->SetInput( contourextractdata->GetVtkImageValueResult() );
2316 writerValueImage->SetFileName( (const char *)filename.mb_str() );
2317 writerValueImage->SetFileDimensionality( 3 );
2318 writerValueImage->Write( );
2321 // filename.Printf("%s\\%s-Mask.mhd",directory.c_str(),namefile.c_str(),z);
2322 temp = directory + "/" + namefile + "-Mask.mhd";
2324 // LG 14/01/09 : using crea
2325 filename = crea::std2wx(temp);
2326 // filename.Printf(_T(temp.c_str()));
2328 /*filename.Printf(_T("%s"),directory.c_str());
2329 filename.append(_T("\\"));
2330 filename.append(_T("%s"),namefile.c_str());
2331 filename.append(_T("-Mask.mhd"));*/
2333 vtkMetaImageWriter *writerMaskImage = vtkMetaImageWriter::New( );
2334 writerMaskImage->SetInput( contourextractdata->GetVtkImageMaskResult() );
2335 writerMaskImage->SetFileName( (const char *)filename.mb_str() );
2336 writerMaskImage->SetFileDimensionality( 3 );
2337 writerMaskImage->Write( );
2339 interfMainPanel::getInstance()->setStringInfoPanel( _T("") );
2340 delete contourextractdata;
2343 void wxContourMainFrame::onChangeInstantInstantPanel(std::string name,int value, int minshow, int maxshow){
2344 if( name.compare( _theViewPanel->getVerticalConceptName() ) == 0){
2345 _theViewPanel->setActualVertical( value);
2347 else if( name.compare( _theViewPanel->getHorizontalConceptName() ) == 0|| _instantPanel->getIfConceptCheckedAt( name, 0 ) ) {
2348 _theViewPanel->setHorizontalConcept( name, minshow, maxshow, minshow, maxshow, value);
2354 void wxContourMainFrame::onSnakePressed(){
2355 std::vector<double> vecX;
2356 std::vector<double> vecY;
2357 std::vector<double> vecZ;
2358 _theViewPanel->GetPointsOfActualContour( &vecX , &vecY , &vecZ );
2360 if (vecX.size()!=0){
2361 std::vector<int> tempVector;
2362 _instantPanel->getInstant( tempVector );
2363 int i,size=vecZ.size();
2364 int actualSlice = tempVector[1];
2365 for ( i=0 ; i<size ; i++ )
2367 vecZ[i] = actualSlice;
2370 wxDialog* dialog = new wxDialog(this, -1, wxString(_T("Snake")));
2371 wxPanel* panel = new wxPanel(dialog,-1);
2372 // wxStaticText* sttext = new wxStaticText(panel, -1, wxString(_T("Panel para snake")));
2373 new wxStaticText(panel, -1, wxString(_T("Panel para snake")));
2374 dialog->ShowModal();
2379 void wxContourMainFrame::saveFileWithContoursAutomatique(){
2380 std::string filename = kernelManager->getCurrentFileName();
2381 if(filename.compare("")!=0){
2382 saveFileWithContours(filename);