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 _refLineModel->AddPoint(50,100,z);
1627 _refLineModel->AddPoint(80,40,z);
1629 _refLineControl->AddPoint(50,100,z);
1630 _refLineControl->AddPoint(80,40,z);
1632 _refLineView->UpdateViewPoint(0);
1633 _refLineView->UpdateViewPoint(1);
1635 _refLineControl->SetCompleteCreation(true);
1636 _refLineControl->SetEditable(true);
1638 _refLineControl->SetActive(true);
1639 _refLineView->RefreshContour();
1642 //Hides the referenceLine
1643 void wxContourMainFrame::refLineHide()
1645 if (_refLineControl!=NULL)
1647 _refLineView->RemoveCompleteContourActor();
1651 //Shows the referenceLine
1652 void wxContourMainFrame::refLineShow()
1654 if (_refLineControl!=NULL)
1656 wxVtkBaseView * viewer2D = _theViewPanel->getWxVtkBaseView();
1658 _refLineView->SetModel( _refLineModel );
1659 _refLineView->SetWxVtkBaseView( viewer2D );
1660 _refLineView->SetRange( 2 );
1661 _refLineView->SetZ( 1200 );
1663 _refLineControl->SetModelView( _refLineModel , _refLineView );
1664 viewer2D->GetInteractorStyleBaseView()->AddInteractorStyleMaracas( _refLineControl );
1665 _refLineControl->CreateNewManualContour();
1666 //_refLineControl->SetActive(true);
1667 //_refLineControl->SetEditable(true);
1668 _refLineView->RefreshContour();
1672 void wxContourMainFrame::onMirror()
1675 std::vector<std::string> currentSelection = _theViewPanel->getSelectedObjects();
1676 std::vector<std::string> filterCurrentSelection;
1678 std::vector<int> tempVector;
1679 _instantPanel->getInstant( tempVector );
1680 _performingOperation->reset();
1681 _performingOperation->setStartCommand( COPY );
1682 _performingOperation->setStartOperationInstantVector( tempVector );
1683 _performingOperation->setKeyNamesOperationElems( currentSelection );
1685 char theStartCommand = _performingOperation->getStartCommand();
1686 if ( theStartCommand == COPY )
1688 //JCP 20-10-08 Undo redo implementation
1690 //JCP 20-10-08 Undo redo implementation
1691 std::vector<int> tempVector;
1692 _instantPanel->getInstant( tempVector );
1693 _performingOperation->setEndOperationInstantVector ( tempVector );
1694 std::vector<std::string> elems = _performingOperation->getKeyNamesOperationElems();
1695 int i,size = elems.size();
1696 for( i=0; i<size; i++ )
1698 createMirrorContourOf( elems[i], tempVector, i>0 );
1702 //deleteContour( _refName );
1706 void wxContourMainFrame::showAxis(bool show){
1707 _theViewPanel->SetVisibleAxis(show);
1708 _theViewPanel->Refresh();
1712 void wxContourMainFrame::onRigidPressed(){
1713 std::vector<std::string> currentSelection = _theViewPanel->getSelectedObjects();
1714 int elementsSelected = currentSelection.size();
1716 if ( elementsSelected >= 1 ){
1717 //JCP 20-10-08 Undo redo implementation
1719 //JCP 20-10-08 Undo redo implementation
1721 std::vector<int> tempVector;
1722 _instantPanel->getInstant( tempVector );
1723 Instant instant(&tempVector);
1725 int i , size=currentSelection.size();
1726 for ( i=0 ; i<size ; i++ )
1728 kernelManager->changeContourOfManager(currentSelection[i], &instant);
1733 void wxContourMainFrame::onWidthOfContour(double width){
1735 _theViewPanel->removeSceneContours();
1736 _theViewPanel->SetWidthContour(width);
1738 //_theViewPanel->getSceneManager()->SetWidthContour( width );
1742 int wxContourMainFrame::getColorWindow(){
1743 return _theViewPanel->getColorWindow();
1745 int wxContourMainFrame::getWindowLevel(){
1746 return _theViewPanel->getWindowLevel();
1749 void wxContourMainFrame::onBrigthnessColorWindowLevel(int colorwindow,int windowlevel){
1750 _theViewPanel->onBrigthnessColorWindowLevel(colorwindow, windowlevel);
1756 void wxContourMainFrame::onInterpolation(bool interpolate){
1757 _theViewPanel->onInterpolation(interpolate);
1761 void wxContourMainFrame::onChangeInstant(std::string name,int actual){
1762 _instantPanel->setConceptValue( name, actual );
1765 void wxContourMainFrame::resetAppend(){
1766 kernelManager->resetAppend();
1770 void wxContourMainFrame::onSpreadAdd(){
1771 std::vector<double> vecX;
1772 std::vector<double> vecY;
1773 std::vector<double> vecZ;
1774 _theViewPanel->GetPointsOfActualContour(&vecX , &vecY , &vecZ );
1776 std::vector<int> tempVector;
1777 _instantPanel->getInstant( tempVector );
1779 std::string val = kernelManager->onSpreadAdd(&vecX , &vecY , &vecZ, tempVector);
1781 interfMainPanel::getInstance()->appendStringSpread(val);
1785 void wxContourMainFrame::onSpreadGo(int type){
1787 //JCP 20-10-08 Undo redo implementation
1789 //JCP 20-10-08 Undo redo implementation
1792 std::vector<double> vecCtrlPointX;
1793 std::vector<double> vecCtrlPointY;
1794 std::vector<double> vecCtrlPointZ;
1798 std::vector<int> tempVector;
1799 _instantPanel->getInstant( tempVector );
1802 kernelManager->getMaxMinZ(&minZ,&maxZ);
1803 //JSTG_16-07-08_----------------------------------------------------------------
1804 //_contourPropagation->setInterpolationNumber(maxZ-minZ+1);
1805 kernelManager->CalculeSplinePropagation();
1807 double totalZ = maxZ-minZ+1;
1810 //--------------------------------------------------------------------
1811 for ( z=(int)minZ ; z<=(int)maxZ ; z++ )
1813 porcent = 100.0* (z-minZ)/totalZ;
1814 int numero = (int)(z-minZ+1)/(int)totalZ;
1815 std::string stringtemp = " "+kernelManager->intToString(porcent)+"% "+kernelManager->intToString(numero)+" "+kernelManager->intToString(z);
1817 interfMainPanel::getInstance()->setStringSpread(stringtemp);
1819 int typeofcontour = 1;
1820 std::string theName;
1821 manualContourModel* manModelContour = kernelManager->GetPoints(z, type, &vecCtrlPointX,&vecCtrlPointY,&vecCtrlPointZ, theName,typeofcontour, tempVector);
1823 if( manModelContour!=NULL ){
1824 double spc[3];//Si no hay imagen pero hay contornos que spacing se pone por default
1825 this->_theViewPanel->getSpacing(spc);
1826 //Adding the manualContourControler to interface objects structure
1827 //Adding the manualViewContour to interface objects structure
1828 //_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.
1829 _theViewPanel->configureViewControlTo( theName, manModelContour,spc,typeofcontour ) ;
1834 int numero = (int)(z-minZ+1)/(int)totalZ;
1835 std::string stringtemp = " "+kernelManager->intToString(porcent)+"% "+kernelManager->intToString(numero)+" "+kernelManager->intToString(z);
1837 interfMainPanel::getInstance()->setStringSpread(stringtemp);
1839 //RefreshInterface();
1842 void wxContourMainFrame::getInstantVector(std::vector<int>& tempVector){
1846 std::vector<std::string> wxContourMainFrame::getOutlinesName(int slide){
1847 std::vector<int> tempVector;
1848 _instantPanel->getInstant(tempVector);
1849 //Asignation of slide number should be different ex by name
1850 tempVector[1]=slide;
1851 return kernelManager->getOutlinesNameAtInstant(tempVector);
1854 void wxContourMainFrame::onInformationContourLabels(int typeContourGroup,int selection,int minimumZ,int maximumZ){
1855 int maxContourGroup = 0;
1857 ContourExtractData *contourextractdata = new ContourExtractData();
1859 contourextractdata ->SetTypeOperation( typeContourGroup % 3 );
1861 std::vector<manualContourModel*> lstManConMod;
1862 std::vector<manualContourModel*> lstManConModTmp;
1863 std::vector<manualContourModel*> lstManConModExp;
1864 std::vector<double> pLstValue;
1865 std::vector<double> pLstValuePosX;
1866 std::vector<double> pLstValuePosY;
1867 std::vector<double> pLstValuePosZ;
1870 int resultGrayRangeCount;
1873 double resultAverage;
1874 double resultStandardeviation;
1876 std::vector<int> tempVector;
1877 _instantPanel->getInstant( tempVector );
1879 vtkImageData *imagedata = _theViewPanel->getImageData();
1880 int sizeZ = _theViewPanel->GetImageDataSizeZ();
1882 int ii,sizeLstContourThings;
1892 if (selection==0 ) // actual slice
1894 std::vector<int> tempVector;
1895 _instantPanel->getInstant( tempVector );
1896 int actualSlice = tempVector[1];
1900 else if (selection==2 ) // All slices
1905 else if (selection==1 ) // slice range
1912 totalZ = maxZ-minZ+1;
1913 contourextractdata->SetImage( imagedata);
1916 for ( z=minZ ; z<=maxZ ; z++ )
1919 porcent = 100.0* (z-minZ)/totalZ;
1920 tmpString.Printf(_T(" %d %c %d/%d %d"), (int)porcent , 37 , z-minZ+1, (int)totalZ ,z);
1922 interfMainPanel::getInstance()->setStringInfoPanel(tmpString);
1923 //_staticTextInformation->SetLabel(tmpString);
1925 //Extraction data from contours of each slice
1926 contourextractdata->SetZtoBeAnalys( z);
1929 Instant instant(&tempVector);
1930 std::vector<ContourThing**> lstContourThings = kernelManager->getOutlinesAtInstant( &instant );
1931 sizeLstContourThings = lstContourThings.size();
1933 lstManConMod.clear();
1934 for (ii=0 ; ii<sizeLstContourThings ; ii++)
1936 ContourThing **contourthing = lstContourThings[ii];
1937 lstManConMod.push_back( (*contourthing)->getModel() );
1939 lstManConModExp = kernelManager->ExploseEachModel( lstManConMod );
1942 wxString tempString;
1943 tempString.Printf(_T("%d - %d"),z, sizeLstContourThings);
1944 interfMainPanel::getInstance()->setRowLabelInfoPanel(z, tempString);
1945 //_grid->SetRowLabelValue(z, tempString );
1947 int iContourGroup,sizeContourGroup;
1948 if (typeContourGroup==3) // contour separete
1950 sizeContourGroup=lstManConModExp.size();
1951 if ( maxContourGroup<sizeContourGroup )
1953 maxContourGroup=sizeContourGroup;
1955 } else { // contour AND OR XOR
1964 for( iContourGroup=0 ; iContourGroup<sizeContourGroup ; iContourGroup++ ){
1965 lstManConModTmp.clear();
1966 if (typeContourGroup==3) // contour separete
1968 lstManConModTmp.push_back( lstManConModExp[iContourGroup]);
1969 } else { // contour AND OR XOR
1970 lstManConModTmp = lstManConModExp;
1973 contourextractdata->SetLstManualContourModel( lstManConModTmp );
1976 pLstValuePosX.clear();
1977 pLstValuePosY.clear();
1978 pLstValuePosZ.clear();
1979 contourextractdata->GetValuesInsideCrown( &pLstValue,
1983 // Statistics of each slice.
1984 contourextractdata->Statistics( &pLstValue,
1987 &resultGrayRangeCount,
1992 &resultStandardeviation);
1994 if (interfMainPanel::getInstance()->getNumberColsInformationPanel()<_numberOfVariablesStatistics*(iContourGroup+1) )
1996 interfMainPanel::getInstance()->appendColsInformationPanel(_numberOfVariablesStatistics);
1999 tmpIntA=_numberOfVariablesStatistics*iContourGroup ;
2001 tempString.Printf(_T("%d"),resultSize);
2002 interfMainPanel::getInstance()->setCellValueInfoPanel(z, tmpIntA, tempString);
2004 tempString.Printf(_T("%d"),resultGrayRangeCount);
2005 interfMainPanel::getInstance()->setCellValueInfoPanel(z, tmpIntA+1, tempString);
2007 tempString.Printf(_T("%f"),resultMin);
2008 interfMainPanel::getInstance()->setCellValueInfoPanel(z, tmpIntA+2, tempString);
2010 tempString.Printf(_T("%f"),resultMax);
2011 interfMainPanel::getInstance()->setCellValueInfoPanel(z, tmpIntA+3, tempString);
2013 tempString.Printf(_T("%f"),resultAverage);
2014 interfMainPanel::getInstance()->setCellValueInfoPanel(z, tmpIntA+4, tempString);
2016 tempString.Printf(_T("%f"),resultStandardeviation);
2017 interfMainPanel::getInstance()->setCellValueInfoPanel(z, tmpIntA+5, tempString);
2020 } // for iContourGroup
2024 wxString tmpTitleString;
2026 for ( iTitleGroup=0 ; iTitleGroup<maxContourGroup ; iTitleGroup++ )
2028 tmpIntB =_numberOfVariablesStatistics*iTitleGroup;
2029 tmpTitleString.Printf(_T("%d-Size Data"),iTitleGroup);
2030 interfMainPanel::getInstance()->setColLableInfoPanel(tmpIntB + 0, tmpTitleString);
2032 interfMainPanel::getInstance()->setColLableInfoPanel(tmpIntB + 0, tmpTitleString );
2033 interfMainPanel::getInstance()->setColLableInfoPanel( tmpIntB + 1, _T("Size Range") );
2034 interfMainPanel::getInstance()->setColLableInfoPanel( tmpIntB + 2, _T("Min") );
2035 interfMainPanel::getInstance()->setColLableInfoPanel( tmpIntB + 3, _T("Max") );
2036 interfMainPanel::getInstance()->setColLableInfoPanel( tmpIntB + 4, _T("Average") );
2037 interfMainPanel::getInstance()->setColLableInfoPanel( tmpIntB + 5, _T("St.Dev.") );
2038 interfMainPanel::getInstance()->setColLableInfoPanel( tmpIntB + 6, _T(" ") );
2041 interfMainPanel::getInstance()->setStringInfoPanel( _T("") );
2042 delete contourextractdata;
2045 void wxContourMainFrame::onSaveResults(std::string directory,std::string namefile, std::string filename, int typeContourGroup){
2046 SaveValuesXYZ( directory , namefile, typeContourGroup );
2047 SaveImageResult( directory , namefile, typeContourGroup);
2050 FILE *pFile=fopen(filename.c_str(),"w+");
2052 int sizeZ = _theViewPanel->GetImageDataSizeZ();
2055 int i,j,maxX,maxY=sizeZ;
2056 maxX= interfMainPanel::getInstance()->getNumberColsInformationPanel();//this->_grid->GetNumberCols();
2058 int iTitle,sizeTitle = (maxX / _numberOfVariablesStatistics);
2059 for ( iTitle=0; iTitle<sizeTitle ; iTitle++)
2061 // fprintf(pFile,"-- \t %d-Size \t SizeRange \t Min \t Max \t Ave \t StDv \t" , iTitle,tmpString.c_str() );
2062 fprintf(pFile,"-- \t %d-Size \t SizeRange \t Min \t Max \t Ave \t StDv \t" , iTitle );
2064 fprintf(pFile,"\n" );
2068 for ( j=0; j<maxY ; j++)
2070 fprintf(pFile,"%d\t" , j );
2071 for (i=0 ; i<maxX ; i++){
2072 tmpString = interfMainPanel::getInstance()->getCellValue(j, i);//_grid->GetCellValue( j , i );
2073 fprintf(pFile,"%s\t" , (const char *)(tmpString.mb_str()) );
2075 fprintf(pFile,"\n" );
2081 void wxContourMainFrame::SaveValuesXYZ(std::string directory,std::string namefile,int typeContourGroup)
2084 ContourExtractData *contourextractdata = new ContourExtractData();
2085 //int typeContourGroup = this->_radiolstboxContourGroup->GetSelection();
2086 contourextractdata ->SetTypeOperation( typeContourGroup % 3 );
2088 std::vector<manualContourModel*> lstManConMod;
2089 std::vector<manualContourModel*> lstManConModTmp;
2090 std::vector<manualContourModel*> lstManConModExp;
2091 std::vector<double> pLstValue;
2092 std::vector<double> pLstValuePosX;
2093 std::vector<double> pLstValuePosY;
2094 std::vector<double> pLstValuePosZ;
2096 std::vector<int> tempVector;
2097 _instantPanel->getInstant( tempVector );
2099 vtkImageData *imagedata = _theViewPanel->getSceneManager()->GetImageData();
2100 int sizeZ = _theViewPanel->getSceneManager()->GetImageDataSizeZ();
2102 int ii,sizeLstContourThings;
2109 minZ = 0;// _mbarrange->GetStart();
2110 maxZ = sizeZ;//_mbarrange->GetEnd();
2111 totalZ = maxZ-minZ+1;
2113 contourextractdata->SetImage( imagedata);
2116 for ( z=0 ; z<sizeZ ; z++)
2119 porcent = 100.0* (z-minZ)/totalZ;
2121 tmpString.Printf(_T("Saving Values"));
2122 tmpString.Printf(_T(" %d %c %d/%d %d"), (int)porcent , 37 , z-minZ+1, (int)totalZ ,z);
2123 interfMainPanel::getInstance()->setStringInfoPanel(tmpString);
2124 //_staticTextInformation->SetLabel(tmpString);
2127 //Extraction data from contours of each slice
2128 contourextractdata->SetZtoBeAnalys( z);
2131 Instant instant(&tempVector);
2132 std::vector<ContourThing**> lstContourThings = kernelManager->getOutlinesAtInstant(&instant);//this->_modelManager->getOutlinesAtInstant( &instant );
2133 sizeLstContourThings = lstContourThings.size();
2135 lstManConMod.clear();
2136 for (ii=0 ; ii<sizeLstContourThings ; ii++)
2138 ContourThing **contourthing = lstContourThings[ii];
2139 lstManConMod.push_back( (*contourthing)->getModel() );
2141 lstManConModExp = kernelManager->ExploseEachModel( lstManConMod );
2146 int iContourGroup,sizeContourGroup;
2147 if (typeContourGroup==3) // contour separete
2149 sizeContourGroup=lstManConModExp.size();
2150 } else { // contour AND OR XOR
2154 for( iContourGroup=0 ; iContourGroup<sizeContourGroup ; iContourGroup++ ){
2155 lstManConModTmp.clear();
2156 if (typeContourGroup==3) // contour separete
2158 lstManConModTmp.push_back( lstManConModExp[iContourGroup]);
2159 } else { // contour AND OR XOR
2160 lstManConModTmp = lstManConModExp;
2163 contourextractdata->SetLstManualContourModel( lstManConModTmp );
2166 pLstValuePosX.clear();
2167 pLstValuePosY.clear();
2168 pLstValuePosZ.clear();
2169 contourextractdata->GetValuesInsideCrown( &pLstValue,
2174 std::string temp = directory + "/" + namefile + "-slice";
2175 temp = temp + kernelManager->intToString(z) + "-cont" + kernelManager->intToString(iContourGroup);
2176 temp = temp + ".txt";
2178 // LG 14/01/09 : using crea
2179 wxString filename = crea::std2wx(temp);
2180 /*filename.Printf(_T("%s"),directory.c_str());
2181 filename.append(_T("\\"));
2182 filename.append(_T("%s"),namefile.c_str());
2183 filename.append(_T("-slice"));
2184 filename.append(_T("%d"),z);
2185 filename.append(_T("-cont"));
2186 filename.append(_T("%d"),iContourGroup);
2187 filename.append(_T(".txt"));*/
2188 // filename.Printf(temp.c_str());
2192 FILE *pFile=fopen((const char *)filename.mb_str(),"w+");
2193 fprintf(pFile,"value \t x \t y \t z\n" );
2194 int iLstValue,sizeLstValue=pLstValue.size();
2195 for (iLstValue=0 ; iLstValue<sizeLstValue ; iLstValue++ )
2197 fprintf(pFile,"%f\t %f\t %f\t %f\n", (float)pLstValue[iLstValue] , (float)pLstValuePosX[iLstValue], (float)pLstValuePosY[iLstValue], (float)z );
2200 } // for iContourGroup
2202 interfMainPanel::getInstance()->setStringInfoPanel(_T(""));
2203 //_staticTextInformation->SetLabel( _T("") );
2204 delete contourextractdata;
2207 void wxContourMainFrame::SaveImageResult(std::string directory,std::string namefile, int typeContourGroup)
2210 ContourExtractData *contourextractdata = new ContourExtractData( true );
2211 //int typeContourGroup = this->_radiolstboxContourGroup->GetSelection();
2212 if (typeContourGroup==3)
2216 contourextractdata ->SetTypeOperation( typeContourGroup % 3 );
2218 std::vector<manualContourModel*> lstManConMod;
2219 std::vector<manualContourModel*> lstManConModTmp;
2220 std::vector<manualContourModel*> lstManConModExp;
2222 std::vector<int> tempVector;
2223 _instantPanel->getInstant( tempVector );
2225 vtkImageData *imagedata = _theViewPanel->getImageData();
2226 int sizeZ = _theViewPanel->GetImageDataSizeZ();
2228 int ii,sizeLstContourThings;
2237 minZ = 0;// _mbarrange->GetStart();
2238 maxZ = sizeZ;//_mbarrange->GetEnd();
2239 totalZ = maxZ-minZ+1;
2241 contourextractdata->SetImage( imagedata);
2244 for ( z=0 ; z<sizeZ ; z++)
2247 porcent = 100.0* (z-minZ)/totalZ;
2248 tmpString.Printf(_T("Saving Values"));
2249 tmpString.Printf(_T("%d %c %d/%d %d"), (int)porcent , 37 , z-minZ+1, (int)totalZ ,z);
2250 interfMainPanel::getInstance()->setStringInfoPanel(tmpString);
2252 //Extraction data from contours of each slice
2253 contourextractdata->SetZtoBeAnalys( z);
2256 Instant instant(&tempVector);
2257 std::vector<ContourThing**> lstContourThings = kernelManager->getOutlinesAtInstant( &instant );
2258 sizeLstContourThings = lstContourThings.size();
2260 lstManConMod.clear();
2261 for (ii=0 ; ii<sizeLstContourThings ; ii++)
2263 ContourThing **contourthing = lstContourThings[ii];
2264 lstManConMod.push_back( (*contourthing)->getModel() );
2266 lstManConModExp = kernelManager->ExploseEachModel( lstManConMod );
2269 int iContourGroup,sizeContourGroup;
2270 if (typeContourGroup==3) // contour separete
2272 sizeContourGroup=lstManConModExp.size();
2273 } else { // contour AND OR XOR
2277 for( iContourGroup=0 ; iContourGroup<sizeContourGroup ; iContourGroup++ ){
2278 lstManConModTmp.clear();
2279 if (typeContourGroup==3) // contour separete
2281 lstManConModTmp.push_back( lstManConModExp[iContourGroup]);
2282 } else { // contour AND OR XOR
2283 lstManConModTmp = lstManConModExp;
2286 contourextractdata->SetLstManualContourModel( lstManConModTmp );
2289 // for (ii=0 ; ii<sizeLstContourThings ; ii++)
2291 // ContourThing **contourthing = lstContourThings[ii];
2292 // lstManConMod.push_back( (*contourthing)->getModel() );
2294 // contourextractdata->SetLstManualContourModel( lstManConMod );
2296 contourextractdata->CalculateImageResult(); // with actual Z
2298 } // for iContourGroup
2301 std::string temp = directory + "/" + namefile + "-Value.mhd";
2303 wxString filename = crea::std2wx(temp);
2305 // filename.Printf(_T(temp.c_str()));
2306 //filename.Printf(_T("%s\\%s-Value.mhd",directory.c_str(),namefile.c_str(),z);
2307 /*filename.Printf(_T("%s"),directory.c_str());
2308 filename.append(_T("\\"));
2309 filename.append(_T("%s"),namefile.c_str());
2310 filename.append(_T("-Value.mhd"));*/
2313 vtkMetaImageWriter *writerValueImage = vtkMetaImageWriter::New( );
2314 writerValueImage->SetInput( contourextractdata->GetVtkImageValueResult() );
2315 writerValueImage->SetFileName( (const char *)filename.mb_str() );
2316 writerValueImage->SetFileDimensionality( 3 );
2317 writerValueImage->Write( );
2320 // filename.Printf("%s\\%s-Mask.mhd",directory.c_str(),namefile.c_str(),z);
2321 temp = directory + "/" + namefile + "-Mask.mhd";
2323 // LG 14/01/09 : using crea
2324 filename = crea::std2wx(temp);
2325 // filename.Printf(_T(temp.c_str()));
2327 /*filename.Printf(_T("%s"),directory.c_str());
2328 filename.append(_T("\\"));
2329 filename.append(_T("%s"),namefile.c_str());
2330 filename.append(_T("-Mask.mhd"));*/
2332 vtkMetaImageWriter *writerMaskImage = vtkMetaImageWriter::New( );
2333 writerMaskImage->SetInput( contourextractdata->GetVtkImageMaskResult() );
2334 writerMaskImage->SetFileName( (const char *)filename.mb_str() );
2335 writerMaskImage->SetFileDimensionality( 3 );
2336 writerMaskImage->Write( );
2338 interfMainPanel::getInstance()->setStringInfoPanel( _T("") );
2339 delete contourextractdata;
2342 void wxContourMainFrame::onChangeInstantInstantPanel(std::string name,int value, int minshow, int maxshow){
2343 if( name.compare( _theViewPanel->getVerticalConceptName() ) == 0){
2344 _theViewPanel->setActualVertical( value);
2346 else if( name.compare( _theViewPanel->getHorizontalConceptName() ) == 0|| _instantPanel->getIfConceptCheckedAt( name, 0 ) ) {
2347 _theViewPanel->setHorizontalConcept( name, minshow, maxshow, minshow, maxshow, value);
2353 void wxContourMainFrame::onSnakePressed(){
2354 std::vector<double> vecX;
2355 std::vector<double> vecY;
2356 std::vector<double> vecZ;
2357 _theViewPanel->GetPointsOfActualContour( &vecX , &vecY , &vecZ );
2359 if (vecX.size()!=0){
2360 std::vector<int> tempVector;
2361 _instantPanel->getInstant( tempVector );
2362 int i,size=vecZ.size();
2363 int actualSlice = tempVector[1];
2364 for ( i=0 ; i<size ; i++ )
2366 vecZ[i] = actualSlice;
2369 wxDialog* dialog = new wxDialog(this, -1, wxString(_T("Snake")));
2370 wxPanel* panel = new wxPanel(dialog,-1);
2371 // wxStaticText* sttext = new wxStaticText(panel, -1, wxString(_T("Panel para snake")));
2372 new wxStaticText(panel, -1, wxString(_T("Panel para snake")));
2373 dialog->ShowModal();
2378 void wxContourMainFrame::saveFileWithContoursAutomatique(){
2379 std::string filename = kernelManager->getCurrentFileName();
2380 if(filename.compare("")!=0){
2381 saveFileWithContours(filename);