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 // set up default notebook style
59 // m_notebook_style =wxAUI_NB_TAB_SPLIT | wxAUI_NB_TAB_EXTERNAL_MOVE | wxNO_BORDER;
60 // m_notebook_theme = 0;
61 //wxContour_ActionCommandsID a;
65 wxContourMainFrame :: wxContourMainFrame(wxWindow* parent, wxWindowID id,const wxString& title,const wxPoint& pos,const wxSize& size,std::vector<vtkImageData*> images, long style)
66 : wxPanel(parent, id, pos, size, style)
68 m_mgr.SetManagedWindow(this);
69 _creatingContoursActive = false;
71 // _modelManager = NULL;
73 // _buttonsBar = NULL;
75 // _drawToolsPanel = NULL;
76 // _operationsToolsPanel = NULL;
77 // _autoFormsPanel = NULL;
78 // _standardToolsPanel = NULL;
79 // _editionToolsPanel = NULL;
80 // _listViewPanel = NULL;
81 // _sceneManager = NULL;
82 //_actualInstant = NULL;
84 // set up default notebook style
85 m_notebook_style =wxAUI_NB_TAB_SPLIT | wxAUI_NB_TAB_EXTERNAL_MOVE | wxNO_BORDER;
87 //wxContour_ActionCommandsID a;
88 _numberOfVariablesStatistics = 6+1;
91 _performingOperation = new PerformingOperation();
97 kernelManager = new KernelManagerContour(images);
98 //kernelManager->setVectImages(images);
99 //kernelManager->initializeEnvironment();
101 //vtkImageData* selectedimage = kernelManager->getVectImages()[0];
103 //-------------------------------------------------------------
105 /*frame = new wxContourMainFrame(_builder->getImSourceEnv(), _builder->getImSectionEnv(), _builder->getAxesEnv(), _builder->getContourEnv(),NULL, wxID_ANY, wxT("ROI Application Sample"), wxPoint(50,50), wxSize(800, 600));
108 //Creating the evtHandler of the panels
109 //wxContourEventHandler * eventHandler = new wxContourEventHandler();
111 //Creating the window that will show the panels
113 //Getting the parent for the panels ( using aui )
114 wxAuiNotebook * notebook = this->createNotebook();
117 //wxInstantChooserPanel * instantPanel = new wxInstantChooserPanel( notebook, "Instant Chooser", true);
119 std::vector<std::string> conceptNameVect;
120 std::vector<int> conceptSizeVect;
124 _instantPanel = new wxInstantChooserPanel( notebook, "Instant Chooser", true, false, "c" );
125 _theViewPanel = new wxContourViewPanel( kernelManager->getSourceImage(), notebook );
129 kernelManager->getConceptsInformation(conceptNameVect, conceptSizeVect);
130 _instantPanel->addConcepts(conceptNameVect, conceptSizeVect);
133 double val = _theViewPanel->getCurrentDeep();
134 _instantPanel->setConceptValue( "Axe Depth", (int)val );
135 //JCP _instantPanel->setConceptValue("time", num de imagenes);
136 ConceptDataWrap * data = _instantPanel->getConceptDataOf( "Axe Depth" );
137 //*******************changeInstant();
138 _theViewPanel->setVerticalConcept( "Axe Depth", data->getMinValue(), data->getMaxValue(), data->getMinShowedValue(), data->getMaxShowedValue(), data->getActualValue() );
140 //eventHandler->setModelManager( kernelManager->getOutlineModelManager() );
141 //eventHandler->setViewPanel( _theViewPanel );
142 //_theViewPanel->initializeScenceManager();
143 //eventHandler->setInstantChooserPanel( _instantPanel );
145 //bool successConfiuration = eventHandler->configureEventsHandling();
147 //successConfiuration &= this->configurePanels( notebook );
148 this->configurePanels( notebook );
150 interfMainPanel* pannew = interfMainPanel::getInstance(parent);//, eventHandler);
158 wxContourMainFrame* wxContourMainFrame :: getInstance(wxWindow* parent, wxWindowID id,const wxString& title,const wxPoint& pos,const wxSize& size,std::vector<vtkImageData*> images, long style ){
159 if(instance == NULL){
160 instance = new wxContourMainFrame(parent, id, title, pos, size, images, style);
165 std::vector<vtkImageData*> wxContourMainFrame ::getVectImages(){
166 return kernelManager->getVectImages();
168 wxContourMainFrame* wxContourMainFrame :: getInstance(){
173 wxContourMainFrame :: ~wxContourMainFrame()
176 //El problema al cerrar la aplicacion puede estar asociado
177 //a que wxAUINotebook esta en la aplicacion
178 //principal (wxContourGUIExample)tambien
179 //EED???? delete _theViewPanel;
180 //EED???? delete _instantPanel;
181 //EED???? delete _buttonsBar;
182 //EED???? delete _actualInstant;
183 //EED???? delete _sceneManager;
187 //------------------------------------------------------------------------------------------------------------
188 // Creational and initialization methods using WxAui
189 //------------------------------------------------------------------------------------------------------------
191 wxAuiNotebook * wxContourMainFrame :: createNotebook()
193 wxSize client_size = GetClientSize();
194 wxAuiNotebook* noteBook = new wxAuiNotebook(this, -1, wxPoint(client_size.x, client_size.y), wxSize(430,200), m_notebook_style);
195 wxBitmap page_bmp = wxArtProvider::GetBitmap(wxART_NORMAL_FILE, wxART_OTHER, wxSize(16,16));
200 //------------------------------------------------------------------------------------------------------------
201 // Creational and initialization methods
202 //------------------------------------------------------------------------------------------------------------
203 bool wxContourMainFrame :: configurePanels(wxAuiNotebook* theNoteBook)
205 bool configured = _theViewPanel!=NULL;
207 configured &= _theViewPanel!=NULL;
208 if( _theViewPanel!=NULL )
210 theNoteBook->AddPage( _theViewPanel, wxT(" View ") );
217 theNoteBook->AddPage( _instantPanel, wxT("Instant Page") );
221 m_mgr.AddPane(theNoteBook, wxAuiPaneInfo().Name(wxT("notebook_content")).CenterPane().PaneBorder(false));
223 /* configured &= _buttonsBar!=NULL;
224 if( _buttonsBar!=NULL )
226 m_mgr.AddPane(_buttonsBar, wxAuiPaneInfo().
227 Name(wxT("TB")).Caption(wxT("Buttons Bar")).
229 LeftDockable( ).RightDockable( false ).CloseButton(false));
234 SetMinSize(wxSize(300,300));
239 void wxContourMainFrame :: setNotebook( wxAuiNotebook * noteBook )
244 //------------------------------------------------------------------------------------------------------------
245 // Attributes getters and setters
246 //------------------------------------------------------------------------------------------------------------
250 void wxContourMainFrame :: setInstantChooserPanel( wxInstantChooserPanel * theInstantChooserPanel )
252 _instantPanel = theInstantChooserPanel;
255 // void wxContourMainFrame :: setButtonsBar( wxContour_ButtonsBar * theButtonsBar )
257 // _buttonsBar = theButtonsBar;
260 // void wxContourMainFrame :: setGrid( wxContour_Grid * theGridPanel )
262 // _gridPanel = theGridPanel;
265 // void wxContourMainFrame :: setDrawToolsPanel( wxContour_DrawToolsPanel * theDrawToolsPanel )
267 // _drawToolsPanel = theDrawToolsPanel;
270 // void wxContourMainFrame :: setOperationsToolsPanel( wxContour_OperationsToolsPanel * theOperationsToolsPanel )
272 // _operationsToolsPanel = theOperationsToolsPanel;
275 // void wxContourMainFrame :: setAutomaticFormsPanel( wxContour_AutomaticFormsToolsPanel * theAutoFormsPanel )
277 // _autoFormsPanel = theAutoFormsPanel;
280 // void wxContourMainFrame :: setStandardToolsPanel( wxContour_StandardToolsPanel * theStandardToolsPanel )
282 // _standardToolsPanel= theStandardToolsPanel;
285 // void wxContourMainFrame :: setEditionToolsPanel( wxContour_EdtionToolsPanel * theEditionToolsPanel )
287 // _editionToolsPanel = theEditionToolsPanel;
290 // void wxContourMainFrame :: setListViewPanel( wxContour_ListViewPanel * theListViewPanel )
292 // _listViewPanel = theListViewPanel;
297 void wxContourMainFrame::onCreateContourSpline( ){
299 //JCP 20-10-08 Undo redo implementation
301 //JCP 20-10-08 Undo redo implementation
305 void wxContourMainFrame::onCreateContourRectangle( ){
306 //JCP 20-10-08 Undo redo implementation
308 //JCP 20-10-08 Undo redo implementation
311 void wxContourMainFrame::onCreateContourCircle( ){
312 //JCP 20-10-08 Undo redo implementation
314 //JCP 20-10-08 Undo redo implementation
317 //------------------------------------------------------------------------------------------------------------
319 void wxContourMainFrame :: onCreateContourBullEye(wxPanel* panel )
321 //Creating the manualContourModel and including in the model
322 manualContourModel * manModelContour = factoryManualContourModel(panel );
324 std::vector<int> instantVector;
325 _instantPanel->getInstant( instantVector );
326 std::string theName = kernelManager->createOutline(manModelContour, instantVector);
328 /*std::vector<int> instantVector;
329 _instantPanel->getInstant( instantVector );
331 theName= _modelManager->createOutline( manModelContour, instantVector );*/
332 bool addedModel = theName.compare("") != 0;//??
336 double spc[3];//Si no hay imagen pero hay contornos que spacing se pone por default
337 _theViewPanel->getSpacing(spc);
338 //Adding the manualContourControler to interface objects structure
339 //Adding the manualViewContour to interface objects structure
340 //_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.
341 _theViewPanel->getSceneManager()->configureViewControlTo( theName, manModelContour,spc , 4) ;
344 void wxContourMainFrame :: createContour( int typeContour )
346 //Creating the manualContourModel and including in the model
347 manualContourModel * manModelContour = kernelManager->factoryManualContourModel(typeContour);
350 std::vector<int> instantVector;
351 _instantPanel->getInstant( instantVector );
352 std::string theName = kernelManager->createOutline(manModelContour, instantVector);
354 /*std::vector<int> instantVector;
355 _instantPanel->getInstant( instantVector );
357 theName= _modelManager->createOutline( manModelContour, instantVector );*/
358 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 //_sceneManager->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 , typeContour) ;
370 manualContourModel * wxContourMainFrame::factoryManualContourModel(wxPanel* panel){
372 manualContourModelBullEye *manModelContourBullEye = new manualContourModelBullEye();
373 manualContourModel *manModelContour=NULL;
374 manModelContour = manModelContourBullEye;
376 int iCrown,sizeCrowns,iSector,sizeSectors;
377 double radioA,radioB,ang,angDelta ;
378 sizeCrowns = ((PanelBullEyeOptions*)panel)->GetNumberOfCrowns();
379 for ( iCrown=0 ; iCrown<sizeCrowns ; iCrown++ )
381 sizeSectors = ((PanelBullEyeOptions*)panel)->GetNumberOfSections(iCrown);
382 radioB = ((PanelBullEyeOptions*)panel)->GetRadioOfCrown(iCrown);
383 if (iCrown==sizeCrowns-1)
387 radioA = ((PanelBullEyeOptions*)panel)->GetRadioOfCrown(iCrown+1);
391 for ( iSector=0 ; iSector<sizeSectors ; iSector++ )
393 ang = ((PanelBullEyeOptions*)panel)->GetAngOfCrownSection(iCrown,iSector);
394 angDelta= ((PanelBullEyeOptions*)panel)->GetAngDeltaOfCrownSection(iCrown);
395 manModelContourBullEye->AddSector(radioA,radioB,ang,angDelta);
398 } // if _panelBullEyeOptions
400 return manModelContour;
402 void wxContourMainFrame :: saveState(){
404 std::string temp = kernelManager->saveState();
405 saveFileWithContours(temp);
408 void wxContourMainFrame::onDeleteContour(){
409 //JCP 20-10-08 Undo redo implementation
411 //JCP 20-10-08 Undo redo implementation
413 std::vector<std::string> lstKeyNameToBeErase;
414 lstKeyNameToBeErase = _theViewPanel->getSceneManager()->getSelectedObjects();
415 deleteContours( lstKeyNameToBeErase );
417 int i,size=_sceneManager->getSelectedObjects().size();
420 std::string keyName = _sceneManager->getSelectedObjects()[i];
421 int ispartofstaticlist = this->_modelManager->IsPartOfStaticList( keyName );
422 if ( ispartofstaticlist>=0 )
424 std::vector<int> tempVector;
425 _instantPanel->getInstant( tempVector );
426 Instant instant(&tempVector);
427 this->_modelManager->ChangeContourOfList(keyName, &instant);
431 std::vector<std::string> lstKeyName;
432 std::vector<std::string> lstKeyNameActualSlice;
433 std::vector<std::string> lstKeyNameToBeErase;
435 lstKeyNameToBeErase = _sceneManager->getSelectedObjects();
436 lstKeyNameActualSlice = _sceneManager->GetlstContoursNameActualSlice();
437 int k,kSize=lstKeyNameToBeErase.size();
438 int j,jSize=lstKeyNameActualSlice.size();
440 for (k=0;k<kSize; k++)
443 for (j=0;j<jSize; j++)
445 if (lstKeyNameToBeErase[k]==lstKeyNameActualSlice[j])
452 lstKeyName.push_back( lstKeyNameToBeErase[k] );
456 deleteContours( lstKeyName );
460 void wxContourMainFrame :: deleteContours( std::vector<std::string> keyNamesVector )
462 int i,size=keyNamesVector.size();
465 deleteContour( keyNamesVector[i] );
469 void wxContourMainFrame :: deleteContour( std::string theKeyName ){
470 /*manualContourModel * cModel;
471 manualViewBaseContour * cViewer;
472 manualContourBaseControler * cControler;
474 ContourWrap_ViewControl *conwrapviewControl = _theViewPanel->getSceneManager()->getContourWrap_ViewControlOf( theKeyName );
475 cControler = conwrapviewControl->getControler();*/
478 bool isedit = _theViewPanel->isEditableCControler(theKeyName);
479 bool ispartofstaticlst = kernelManager->IsPartOfStaticList(theKeyName);
481 if (isedit && ispartofstaticlst)
483 _theViewPanel->removeFromScene(theKeyName);
485 kernelManager->deleteCModel(theKeyName);
486 //_theViewPanel->getSceneManager()->removeFromScene( theKeyName );
487 //cViewer = conwrapviewControl->getViewer();
488 //_theViewPanel->getSceneManager()->removeWrap( theKeyName );
489 //cControler* conwrapviewControl->getControler();
491 //FILE *ff = fopen("c:/temp/wxVtkBaseView_SceneManagerStadistics.txt","a+");
492 //fprintf(ff,"EED wxContourEventHandler::deleteContours() \n" );
493 //fprintf(ff," %s %p\n",keyNamesVector[i].c_str(), cControler );
497 // delete cControler;
502 void wxContourMainFrame::onDeleteContoursActSlice(){
503 //JCP 20-10-08 Undo redo implementation
505 //JCP 20-10-08 Undo redo implementation
506 deleteContours( (std::vector<std::string>)_theViewPanel->getSceneManager()->GetlstContoursNameActualSlice() );
508 void wxContourMainFrame::onDeleteAllContours(){
509 //JCP 20-10-08 Undo redo implementation
513 void wxContourMainFrame::deleteAllContours(){
514 //JCP 20-10-08 Undo redo implementation
517 std::vector<int> tempVector;
518 _instantPanel->getInstant( tempVector );
520 //JCP --08-09-2008 When using a diferent interface the _mbarrangeDeleteAll might not be initialize
521 // the values in GetStart and GetEnd will then not be initialize also.
522 // We use instead the values given when initializing the _deletepanel.
524 //int minZ = _mbarrangeDeleteAll->GetStart();
525 //int maxZ = _mbarrangeDeleteAll->GetEnd();
529 maxZ = _theViewPanel->getSceneManager()->GetImageDataSizeZ();
533 _theViewPanel->getSceneManager()->removeSceneContours( );
534 _theViewPanel->getSceneManager()->removeAllOutlines();
535 kernelManager->removeAllOutlines();
538 if ( (minZ==0) && (maxZ==_mbarrangeDeleteAll->GetMax() ))
540 _theViewPanel->getSceneManager()->removeSceneContours( );
541 _modelManager->removeAllOutlines();
542 _theViewPanel->getSceneManager()->removeAllOutlines();
545 for ( z=minZ ; z<=maxZ ; z++)
548 Instant instant(&tempVector);
549 std::vector<ContourThing**> lstContourThings = this->_modelManager->getOutlinesAtInstant( &instant );
551 sizeLstContourThings = lstContourThings.size();
552 for (ii=0 ; ii<sizeLstContourThings ; ii++)
554 ContourThing **contourthing = lstContourThings[ii];
555 deleteContour( (*contourthing)->getName() );
562 void wxContourMainFrame::setConceptValue( std::string name, int value ){
563 _instantPanel->setConceptValue(name, value);
566 ConceptDataWrap* wxContourMainFrame::getLastConceptData(){
567 return _instantPanel->getLastConceptData();
569 bool wxContourMainFrame::getIfConceptCheckedAt( std::string name, int pos ){
570 return _instantPanel->getIfConceptCheckedAt( name, pos );
573 void wxContourMainFrame::changeInstant(){
574 std::vector<int> instantVect;
575 _instantPanel->getInstant( instantVect );
576 // Instant * theInstant = new Instant ( &instantVect );
578 //Setting the actual instant
579 //_actualInstant = theInstant;
581 kernelManager->setInstant(instantVect);
582 //_modelManager->setInstant( _actualInstant );
584 updateInstantOutlines();
585 updateInstantImageData();
590 void wxContourMainFrame :: updateInstantOutlines(){
592 _theViewPanel->removeSceneContours();
593 _theViewPanel->addNameWrapperToScene();
595 //for( int i=0; i<size; i++)
597 // _theViewPanel->getSceneManager()->addToScene(namesWrapping[i]->getKeyName(), true, true, true, false, false );
601 int wxContourMainFrame::getNamesWrappingSize(){
602 return kernelManager->getNamesWrappingSize();
604 std::string wxContourMainFrame::getNameWrapping(int i){
605 return kernelManager->getNameWrapping(i);
608 void wxContourMainFrame::updateInstantImageData(){
609 std::vector<int> inst;
610 _instantPanel->getInstant(inst);
612 vtkImageData* img = kernelManager->getImageAtInstant(inst);
614 _theViewPanel->changeImage(img);
617 int z = _instantPanel->getConceptDataOf("Axe Depth")->getActualValue();
618 _theViewPanel->setImageSlice(z);
621 void wxContourMainFrame::updateInstantAxes(){
624 void wxContourMainFrame::onChangeDeep(int val){
625 _instantPanel->setConceptValue( "Axe Depth", (int)val );
630 void wxContourMainFrame::onCopy(){
631 std::vector<std::string> currentSelection = _theViewPanel->getSelectedObjects();
633 std::vector<int> tempVector;
634 _instantPanel->getInstant( tempVector );
635 _performingOperation->reset();
636 _performingOperation->setStartCommand( COPY );
637 _performingOperation->setStartOperationInstantVector( tempVector );
638 _performingOperation->setKeyNamesOperationElems( currentSelection );
640 void wxContourMainFrame::onPaste(){
643 char theStartCommand = _performingOperation->getStartCommand();
644 if ( theStartCommand == COPY )
646 //JCP 20-10-08 Undo redo implementation
648 //JCP 20-10-08 Undo redo implementation
649 std::vector<int> tempVector;
650 _instantPanel->getInstant( tempVector );
651 _performingOperation->setEndOperationInstantVector ( tempVector );
652 std::vector<std::string> elems = _performingOperation->getKeyNamesOperationElems();
653 int i,size = elems.size();
654 for( i=0; i<size; i++ )
656 createCopyContourOf( elems[i], tempVector, i>0 );
660 void wxContourMainFrame::onUndo(){
661 std::string filename;
662 if(kernelManager->onUndoSaveFile(filename)){
663 saveFileWithContours(filename);
665 if(kernelManager->onUndo(filename)){
669 void wxContourMainFrame::onRedo(){
670 std::string filename;
671 if(kernelManager->onRedo(filename)){
676 void wxContourMainFrame :: createCopyContourOf ( std::string anExistingKName, std::vector<int> &instantNoTouchData, bool append ){
677 std::string cloneName = kernelManager->createCopyContourOf( anExistingKName, instantNoTouchData );
678 manualContourModel * manualModel = kernelManager->getOutlineByKeyName(cloneName);//_modelManager->getOutlineByKeyName( cloneName )->getModel();
679 _theViewPanel->getSceneManager()->createCopyContourOf( anExistingKName, cloneName, manualModel , append );
682 void wxContourMainFrame ::loadState(std::string filename){
684 FILE *pFile=fopen(filename.c_str(),"r+");
686 fscanf(pFile,"%s",tmp); // --CreaContour--
688 fscanf(pFile,"%s",tmp); // Version
689 fscanf(pFile,"%s",tmp); // 1.0.1
690 std::string version(tmp);
694 openContours(pFile,false);
695 if (version!="1.0.0"){
696 openContours(pFile,true);
701 //_theViewPanel->getSceneManager()->removeSceneContours();
706 void wxContourMainFrame::onLoad(){
708 wxFileDialog dialog(NULL, _T("Choose a file"), _T(""), _T(""), _T("*.roi"), wxOPEN );
709 if (dialog.ShowModal() == wxID_OK)
711 std::string fileNameContourROI = (const char *)(dialog.GetPath().mb_str());
712 FILE *pFile=fopen(fileNameContourROI.c_str(),"r+");
714 fscanf(pFile,"%s",tmp); // --CreaContour--
716 fscanf(pFile,"%s",tmp); // Version
717 fscanf(pFile,"%s",tmp); // 1.0.1
718 std::string version(tmp);
720 openContours(pFile,false);
721 if (version!="1.0.0"){
722 openContours(pFile,true);
724 // _theViewPanel->getSceneManager()->openFileWithContours(ff);
728 _theViewPanel->getSceneManager()->removeSceneContours();
731 void wxContourMainFrame::onSave(){
732 wxFileDialog dialog(NULL, _T("Choose a file"), _T(""), _T(""), _T("*.roi"), wxSAVE );
733 if (dialog.ShowModal() == wxID_OK)
735 std::string fileNameContourROI = (const char *)(dialog.GetPath().mb_str());
736 kernelManager->setCurrentFileName(fileNameContourROI);
737 saveFileWithContours( fileNameContourROI );
740 void wxContourMainFrame::saveFileWithContours( std::string filename ){
742 FILE *pFile=fopen(filename.c_str(),"w+");
743 std::vector< std::string > lstNameThings;
744 int i,sizeLstNameThings;
746 fprintf(pFile,"--CreaContour--\n");
747 fprintf(pFile,"Version %s\n", "1.0.1" );
750 lstNameThings = kernelManager->GetLstNameThings();
751 sizeLstNameThings = lstNameThings.size();
752 fprintf(pFile,"NumberOfContours %d\n", sizeLstNameThings );
753 for (i=0 ; i<sizeLstNameThings ; i++)
755 kernelManager->SaveThingName( pFile, lstNameThings[i] );
756 _theViewPanel->getSceneManager()->SaveThingName( pFile, lstNameThings[i] );
759 //-- Contours Statics
760 lstNameThings = kernelManager->GetLstNameThingsStatic();
761 sizeLstNameThings = lstNameThings.size();
762 fprintf(pFile,"NumberOfContoursStatic %d\n", sizeLstNameThings );
763 for (i=0 ; i<sizeLstNameThings ; i++)
765 kernelManager->SaveThingName( pFile, lstNameThings[i] );
766 _theViewPanel->getSceneManager()->SaveThingName( pFile, lstNameThings[i] );
771 void wxContourMainFrame::openContours( FILE *pFile, bool staticContour ){
773 fscanf(pFile,"%s",tmp); // NumberOfContours
774 fscanf(pFile,"%s",tmp); // ##
775 int numberOfContours = atoi(tmp);
777 std::vector<int> instantVector;
778 int typeContourModel;
779 manualContourModel *manModelContour;
783 for (i=0;i<numberOfContours;i++)
785 instantVector.clear();
786 fscanf(pFile,"%s",tmp); // Instant
788 fscanf(pFile,"%s",tmp); // 1
789 instantVector.push_back( atoi(tmp) );
790 fscanf(pFile,"%s",tmp); // 2
791 instantVector.push_back( atoi(tmp) );
792 fscanf(pFile,"%s",tmp); // 3
793 instantVector.push_back( atoi(tmp) );
794 fscanf(pFile,"%s",tmp); // 4
795 instantVector.push_back( atoi(tmp) );
796 fscanf(pFile,"%s",tmp); // 5
797 instantVector.push_back( atoi(tmp) );
798 fscanf(pFile,"%s",tmp); // 6
799 instantVector.push_back( atoi(tmp) );
802 fscanf(pFile,"%s",tmp); // TypeContourModel
803 fscanf(pFile,"%s",tmp); // ##
804 typeContourModel = atoi(tmp);
806 manModelContour = kernelManager->factoryManualContourModel(typeContourModel);
807 manModelContour->Open(pFile);
809 fscanf(pFile,"%s",tmp); // TypeView
810 fscanf(pFile,"%s",tmp); // ##
811 typeView = atoi(tmp);
820 theName = kernelManager->createOutline( manModelContour, instantVector );
821 bool addedModel = theName.compare("") != 0;
824 double spc[3];//Si no hay imagen pero hay contornos que spacing se pone por default
825 _theViewPanel->getSpacing(spc);
826 //Adding the manualContourControler to interface objects structure
827 //Adding the manualViewContour to interface objects structure
828 //_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.
829 _theViewPanel->getSceneManager()->configureViewControlTo( theName, manModelContour,spc , typeView) ;
832 if (staticContour==true)
834 Instant instant(&instantVector);
835 kernelManager->changeContourOfManager( theName , &instant );
838 }// for numberOfContours
842 void wxContourMainFrame::RefreshInterface(){
844 _theViewPanel->RefreshInterface();
845 //wxVtk2DBaseView *wxvtk2dbaseview = (wxVtk2DBaseView*)this->_theViewPanel->getWxVtkBaseView();
846 //wxvtk2dbaseview->Refresh();
849 vtkImageData* wxContourMainFrame::getImageData(){
850 return _theViewPanel->getImageData();
853 void wxContourMainFrame::onSegmentationOneSlice(int isovalue,int sampling,int method){
855 //JCP 20-10-08 Undo redo implementation
857 //JCP 20-10-08 Undo redo implementation
860 int x = _theViewPanel->GetX();
861 int y = _theViewPanel->GetY();
862 int z = _theViewPanel->GetZ();
863 SegmentationOneSlice( x,y,z,isovalue, sampling, method );
867 void wxContourMainFrame::SegmentationOneSlice( int x, int y, int z, int isovalue, int sampling, int method )
869 int typeofcontour = 1;
870 //--Extracting Contour
871 //vtkImageData *imagedata = _theViewPanel->getSceneManager()->GetImageData();
872 vtkImageData *imagedata = getImageData();
873 // double *range = imagedata->GetScalarRange();
876 vtkImageReslice *imageReslice = vtkImageReslice::New();
879 // imagedata->GetSpacing(spc);
884 imageReslice->SetInput( imagedata );
885 imageReslice->SetInformationInput(imagedata);
886 imageReslice->SetResliceAxesDirectionCosines(1,0,0, 0,1,0 ,0,0,1);
887 imageReslice->SetResliceAxesOrigin(0,0,z);
888 imageReslice->SetOutputDimensionality(2);
889 imageReslice->SetInterpolationModeToLinear();
891 imagedata = imageReslice->GetOutput();
893 imagedata->UpdateInformation();
895 vtkContourFilter* cntVTK = vtkContourFilter::New( );
896 cntVTK->SetInput( imagedata );
898 cntVTK->SetNumberOfContours( 1 );
899 //cntVTK->SetValue( 0, vmin );
900 // cntVTK->SetValue( 0, (range[1]*thr/100) );
901 cntVTK->SetValue( 1, isovalue );
902 // cntVTK->SetValue( 1, vmax );
904 cntVTK->UpdateInformation();
906 vtkCleanPolyData* cpd = vtkCleanPolyData::New( );
907 cpd->SetInput( cntVTK->GetOutput( ) );
908 cpd->ConvertLinesToPointsOff( );
910 cpd->UpdateInformation();
912 vtkPolyDataConnectivityFilter* conn = vtkPolyDataConnectivityFilter::New( );
913 conn->SetExtractionModeToClosestPointRegion( );
914 //conn->SetMaxRecursionDepth( 3000 );
916 conn->SetInput( cpd->GetOutput( ) );
918 conn->SetClosestPoint( x, y, 0 );
920 conn->UpdateInformation();
922 vtkCleanPolyData* cpd2 = vtkCleanPolyData::New( );
923 cpd2->SetInput( conn->GetOutput( ) );
925 cpd2->UpdateInformation();
927 vtkStripper* vtkstripper = vtkStripper::New( );
928 vtkstripper->SetInput( cpd2->GetOutput() );
929 vtkstripper->Update();
930 vtkstripper->UpdateInformation();
933 vtkPolyData* polyDataResult = vtkstripper->GetOutput();
935 polyDataResult->Update( );
936 polyDataResult->UpdateInformation();
940 myfile.open ("c:/temp/example.txt");
942 polyDataResult->Print(myfile);
943 myfile << "-------------------------------------\n";
944 polyDataResult->GetLines()->Print(myfile);
954 //--Calculating control points
956 std::vector<double> vecX;
957 std::vector<double> vecY;
958 std::vector<double> vecZ;
960 std::vector<double> vecCtrlPointX;
961 std::vector<double> vecCtrlPointY;
962 std::vector<double> vecCtrlPointZ;
966 int ii,size=polyDataResult->GetNumberOfPoints();
968 for (ii=1;ii<=size;ii++)
970 id = polyDataResult->GetLines()->GetData()->GetValue(ii);
971 p = polyDataResult->GetPoint(id);
974 vecX.push_back( p[0] );
975 vecY.push_back( p[1] );
976 vecZ.push_back( -900 );
977 // vecZ.push_back( p[2] );
981 ExtractControlPoints2D *extractcontrolpoints2d = new ExtractControlPoints2D();
982 extractcontrolpoints2d->SetContour( &vecX , &vecY , &vecZ );
985 /*if (methodRadiobox->GetSelection()==0){
986 extractcontrolpoints2d->GetInitialControlPoints( &vecCtrlPointX , &vecCtrlPointY , &vecCtrlPointZ );
988 if (methodRadiobox->GetSelection()==1){
989 extractcontrolpoints2d->GetControlPoints( &vecCtrlPointX , &vecCtrlPointY , &vecCtrlPointZ );
991 if (methodRadiobox->GetSelection()==2){
992 extractcontrolpoints2d->SetSamplingControlPoints( sampling );
993 extractcontrolpoints2d->GetSamplingControlPoints( &vecCtrlPointX , &vecCtrlPointY , &vecCtrlPointZ );
997 extractcontrolpoints2d->GetInitialControlPoints( &vecCtrlPointX , &vecCtrlPointY , &vecCtrlPointZ );
1000 extractcontrolpoints2d->GetControlPoints( &vecCtrlPointX , &vecCtrlPointY , &vecCtrlPointZ );
1002 else if (method==2){
1003 extractcontrolpoints2d->SetSamplingControlPoints( sampling );
1004 extractcontrolpoints2d->GetSamplingControlPoints( &vecCtrlPointX , &vecCtrlPointY , &vecCtrlPointZ );
1007 //--Adding contour to the system
1009 std::vector<int> actualInstantVector;
1010 _instantPanel->getInstant( actualInstantVector );
1011 actualInstantVector[1]=z;
1013 int j,sizeCtrPt = vecCtrlPointX.size();
1014 manualContourModel *manModelContour = kernelManager->factoryManualContourModel( typeofcontour );
1015 manModelContour->SetNumberOfPointsSpline( ((sizeCtrPt/100)+1)*100 );
1017 for (j=0 ; j<sizeCtrPt ; j++)
1019 manModelContour->AddPoint( vecCtrlPointX[j] , vecCtrlPointY[j] , vecCtrlPointZ[j] );
1021 std::string theName;
1022 //theName = _modelManager->createOutline( manModelContour, actualInstantVector );
1023 theName = kernelManager->createOutline( manModelContour, actualInstantVector );
1024 bool addedModel = theName.compare("") != 0;
1027 double spc[3];//Si no hay imagen pero hay contornos que spacing se pone por default
1028 _theViewPanel->getSpacing(spc);
1029 //Adding the manualContourControler to interface objects structure
1030 //Adding the manualViewContour to interface objects structure
1031 //_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.
1032 _theViewPanel->configureViewControlTo(theName, manModelContour, spc, typeofcontour);
1033 //_theViewPanel->getSceneManager()->configureViewControlTo( theName, manModelContour,spc, typeofcontour ) ;
1038 int wxContourMainFrame::GetImageDataSizeZ(){
1039 return _theViewPanel->GetImageDataSizeZ();
1042 void wxContourMainFrame::GetImageDataRange(double *range){
1043 _theViewPanel->GetImageDataRange(range);
1046 void wxContourMainFrame::onSegmentationAllSlice(int minZ,int maxZ,int isovalue,int sampling,int method){
1047 //JCP 20-10-08 Undo redo implementation
1049 //JCP 20-10-08 Undo redo implementation
1052 int x = _theViewPanel->GetX();
1053 int y = _theViewPanel->GetY();
1057 double totalZ = maxZ-minZ+1;
1058 for( z=minZ ; z<=maxZ ; z++ )
1060 porcent = 100.0* (z-minZ)/totalZ;
1061 tmpString.Printf(_T(" %d %c %d/%d %d"), (int)porcent , 37 , z-minZ+1, (int)totalZ,z );
1062 interfMainPanel::getInstance()->setLabelSegmentationPanelVTK(tmpString);
1063 //_staticTextSegmentation->SetLabel(tmpString);
1064 SegmentationOneSlice( x,y,z,isovalue, sampling,method );
1066 interfMainPanel::getInstance()->setLabelSegmentationPanelVTK(_T(" "));
1070 void wxContourMainFrame::showAxis(bool show){
1071 _theViewPanel->SetVisibleAxis(show);
1072 _theViewPanel->Refresh();
1076 void wxContourMainFrame::onRigidPressed(){
1077 std::vector<std::string> currentSelection = _theViewPanel->getSelectedObjects();
1078 int elementsSelected = currentSelection.size();
1080 if ( elementsSelected >= 1 ){
1081 //JCP 20-10-08 Undo redo implementation
1083 //JCP 20-10-08 Undo redo implementation
1085 std::vector<int> tempVector;
1086 _instantPanel->getInstant( tempVector );
1087 Instant instant(&tempVector);
1089 int i , size=currentSelection.size();
1090 for ( i=0 ; i<size ; i++ )
1092 kernelManager->changeContourOfManager(currentSelection[i], &instant);
1097 void wxContourMainFrame::onWidthOfContour(double width){
1099 _theViewPanel->removeSceneContours();
1100 _theViewPanel->SetWidthContour(width);
1102 //_theViewPanel->getSceneManager()->SetWidthContour( width );
1106 int wxContourMainFrame::getColorWindow(){
1107 return _theViewPanel->getColorWindow();
1109 int wxContourMainFrame::getWindowLevel(){
1110 return _theViewPanel->getWindowLevel();
1113 void wxContourMainFrame::onBrigthnessColorWindowLevel(int colorwindow,int windowlevel){
1114 _theViewPanel->onBrigthnessColorWindowLevel(colorwindow, windowlevel);
1120 void wxContourMainFrame::onInterpolation(bool interpolate){
1121 _theViewPanel->onInterpolation(interpolate);
1125 void wxContourMainFrame::onChangeInstant(std::string name,int actual){
1126 _instantPanel->setConceptValue( name, actual );
1129 void wxContourMainFrame::resetAppend(){
1130 kernelManager->resetAppend();
1134 void wxContourMainFrame::onSpreadAdd(){
1135 std::vector<double> vecX;
1136 std::vector<double> vecY;
1137 std::vector<double> vecZ;
1138 _theViewPanel->GetPointsOfActualContour(&vecX , &vecY , &vecZ );
1140 std::vector<int> tempVector;
1141 _instantPanel->getInstant( tempVector );
1143 std::string val = kernelManager->onSpreadAdd(&vecX , &vecY , &vecZ, tempVector);
1145 interfMainPanel::getInstance()->appendStringSpread(val);
1149 void wxContourMainFrame::onSpreadGo(int type){
1151 //JCP 20-10-08 Undo redo implementation
1153 //JCP 20-10-08 Undo redo implementation
1156 std::vector<double> vecCtrlPointX;
1157 std::vector<double> vecCtrlPointY;
1158 std::vector<double> vecCtrlPointZ;
1162 std::vector<int> tempVector;
1163 _instantPanel->getInstant( tempVector );
1166 kernelManager->getMaxMinZ(&minZ,&maxZ);
1167 //JSTG_16-07-08_----------------------------------------------------------------
1168 //_contourPropagation->setInterpolationNumber(maxZ-minZ+1);
1169 kernelManager->CalculeSplinePropagation();
1171 double totalZ = maxZ-minZ+1;
1174 //--------------------------------------------------------------------
1175 for ( z=(int)minZ ; z<=(int)maxZ ; z++ )
1177 porcent = 100.0* (z-minZ)/totalZ;
1178 int numero = (int)(z-minZ+1)/(int)totalZ;
1179 std::string stringtemp = " "+kernelManager->intToString(porcent)+"% "+kernelManager->intToString(numero)+" "+kernelManager->intToString(z);
1181 interfMainPanel::getInstance()->setStringSpread(stringtemp);
1183 int typeofcontour = 1;
1184 std::string theName;
1185 manualContourModel* manModelContour = kernelManager->GetPoints(z, type, &vecCtrlPointX,&vecCtrlPointY,&vecCtrlPointZ, theName,typeofcontour, tempVector);
1187 if( manModelContour!=NULL ){
1188 double spc[3];//Si no hay imagen pero hay contornos que spacing se pone por default
1189 this->_theViewPanel->getSpacing(spc);
1190 //Adding the manualContourControler to interface objects structure
1191 //Adding the manualViewContour to interface objects structure
1192 //_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.
1193 _theViewPanel->configureViewControlTo( theName, manModelContour,spc,typeofcontour ) ;
1198 int numero = (int)(z-minZ+1)/(int)totalZ;
1199 std::string stringtemp = " "+kernelManager->intToString(porcent)+"% "+kernelManager->intToString(numero)+" "+kernelManager->intToString(z);
1201 interfMainPanel::getInstance()->setStringSpread(stringtemp);
1203 //RefreshInterface();
1206 void wxContourMainFrame::getInstantVector(std::vector<int>& tempVector){
1210 std::vector<std::string> wxContourMainFrame::getOutlinesName(int slide){
1211 std::vector<int> tempVector;
1212 _instantPanel->getInstant(tempVector);
1213 //Asignation of slide number should be different ex by name
1214 tempVector[1]=slide;
1215 return kernelManager->getOutlinesNameAtInstant(tempVector);
1218 void wxContourMainFrame::onInformationContourLabels(int typeContourGroup,int selection,int minimumZ,int maximumZ){
1219 int maxContourGroup = 0;
1221 ContourExtractData *contourextractdata = new ContourExtractData();
1223 contourextractdata ->SetTypeOperation( typeContourGroup % 3 );
1225 std::vector<manualContourModel*> lstManConMod;
1226 std::vector<manualContourModel*> lstManConModTmp;
1227 std::vector<manualContourModel*> lstManConModExp;
1228 std::vector<double> pLstValue;
1229 std::vector<double> pLstValuePosX;
1230 std::vector<double> pLstValuePosY;
1231 std::vector<double> pLstValuePosZ;
1234 int resultGrayRangeCount;
1237 double resultAverage;
1238 double resultStandardeviation;
1240 std::vector<int> tempVector;
1241 _instantPanel->getInstant( tempVector );
1243 vtkImageData *imagedata = _theViewPanel->getImageData();
1244 int sizeZ = _theViewPanel->GetImageDataSizeZ();
1246 int ii,sizeLstContourThings;
1256 if (selection==0 ) // actual slice
1258 std::vector<int> tempVector;
1259 _instantPanel->getInstant( tempVector );
1260 int actualSlice = tempVector[1];
1264 else if (selection==2 ) // All slices
1269 else if (selection==1 ) // slice range
1276 totalZ = maxZ-minZ+1;
1277 contourextractdata->SetImage( imagedata);
1280 for ( z=minZ ; z<=maxZ ; z++ )
1283 porcent = 100.0* (z-minZ)/totalZ;
1284 tmpString.Printf(_T(" %d %c %d/%d %d"), (int)porcent , 37 , z-minZ+1, (int)totalZ ,z);
1286 interfMainPanel::getInstance()->setStringInfoPanel(tmpString);
1287 //_staticTextInformation->SetLabel(tmpString);
1289 //Extraction data from contours of each slice
1290 contourextractdata->SetZtoBeAnalys( z);
1293 Instant instant(&tempVector);
1294 std::vector<ContourThing**> lstContourThings = kernelManager->getOutlinesAtInstant( &instant );
1295 sizeLstContourThings = lstContourThings.size();
1297 lstManConMod.clear();
1298 for (ii=0 ; ii<sizeLstContourThings ; ii++)
1300 ContourThing **contourthing = lstContourThings[ii];
1301 lstManConMod.push_back( (*contourthing)->getModel() );
1303 lstManConModExp = kernelManager->ExploseEachModel( lstManConMod );
1306 wxString tempString;
1307 tempString.Printf(_T("%d - %d"),z, sizeLstContourThings);
1308 interfMainPanel::getInstance()->setRowLabelInfoPanel(z, tempString);
1309 //_grid->SetRowLabelValue(z, tempString );
1311 int iContourGroup,sizeContourGroup;
1312 if (typeContourGroup==3) // contour separete
1314 sizeContourGroup=lstManConModExp.size();
1315 if ( maxContourGroup<sizeContourGroup )
1317 maxContourGroup=sizeContourGroup;
1319 } else { // contour AND OR XOR
1328 for( iContourGroup=0 ; iContourGroup<sizeContourGroup ; iContourGroup++ ){
1329 lstManConModTmp.clear();
1330 if (typeContourGroup==3) // contour separete
1332 lstManConModTmp.push_back( lstManConModExp[iContourGroup]);
1333 } else { // contour AND OR XOR
1334 lstManConModTmp = lstManConModExp;
1337 contourextractdata->SetLstManualContourModel( lstManConModTmp );
1340 pLstValuePosX.clear();
1341 pLstValuePosY.clear();
1342 pLstValuePosZ.clear();
1343 contourextractdata->GetValuesInsideCrown( &pLstValue,
1347 // Statistics of each slice.
1348 contourextractdata->Statistics( &pLstValue,
1351 &resultGrayRangeCount,
1356 &resultStandardeviation);
1358 if (interfMainPanel::getInstance()->getNumberColsInformationPanel()<_numberOfVariablesStatistics*(iContourGroup+1) )
1360 interfMainPanel::getInstance()->appendColsInformationPanel(_numberOfVariablesStatistics);
1363 tmpIntA=_numberOfVariablesStatistics*iContourGroup ;
1365 tempString.Printf(_T("%d"),resultSize);
1366 interfMainPanel::getInstance()->setCellValueInfoPanel(z, tmpIntA, tempString);
1368 tempString.Printf(_T("%d"),resultGrayRangeCount);
1369 interfMainPanel::getInstance()->setCellValueInfoPanel(z, tmpIntA+1, tempString);
1371 tempString.Printf(_T("%f"),resultMin);
1372 interfMainPanel::getInstance()->setCellValueInfoPanel(z, tmpIntA+2, tempString);
1374 tempString.Printf(_T("%f"),resultMax);
1375 interfMainPanel::getInstance()->setCellValueInfoPanel(z, tmpIntA+3, tempString);
1377 tempString.Printf(_T("%f"),resultAverage);
1378 interfMainPanel::getInstance()->setCellValueInfoPanel(z, tmpIntA+4, tempString);
1380 tempString.Printf(_T("%f"),resultStandardeviation);
1381 interfMainPanel::getInstance()->setCellValueInfoPanel(z, tmpIntA+5, tempString);
1384 } // for iContourGroup
1388 wxString tmpTitleString;
1390 for ( iTitleGroup=0 ; iTitleGroup<maxContourGroup ; iTitleGroup++ )
1392 tmpIntB =_numberOfVariablesStatistics*iTitleGroup;
1393 tmpTitleString.Printf(_T("%d-Size Data"),iTitleGroup);
1394 interfMainPanel::getInstance()->setColLableInfoPanel(tmpIntB + 0, tmpTitleString);
1396 interfMainPanel::getInstance()->setColLableInfoPanel(tmpIntB + 0, tmpTitleString );
1397 interfMainPanel::getInstance()->setColLableInfoPanel( tmpIntB + 1, _T("Size Range") );
1398 interfMainPanel::getInstance()->setColLableInfoPanel( tmpIntB + 2, _T("Min") );
1399 interfMainPanel::getInstance()->setColLableInfoPanel( tmpIntB + 3, _T("Max") );
1400 interfMainPanel::getInstance()->setColLableInfoPanel( tmpIntB + 4, _T("Average") );
1401 interfMainPanel::getInstance()->setColLableInfoPanel( tmpIntB + 5, _T("St.Dev.") );
1402 interfMainPanel::getInstance()->setColLableInfoPanel( tmpIntB + 6, _T(" ") );
1405 interfMainPanel::getInstance()->setStringInfoPanel( _T("") );
1406 delete contourextractdata;
1409 void wxContourMainFrame::onSaveResults(std::string directory,std::string namefile, std::string filename, int typeContourGroup){
1410 SaveValuesXYZ( directory , namefile, typeContourGroup );
1411 SaveImageResult( directory , namefile, typeContourGroup);
1414 FILE *pFile=fopen(filename.c_str(),"w+");
1416 int sizeZ = _theViewPanel->GetImageDataSizeZ();
1419 int i,j,maxX,maxY=sizeZ;
1420 maxX= interfMainPanel::getInstance()->getNumberColsInformationPanel();//this->_grid->GetNumberCols();
1422 int iTitle,sizeTitle = (maxX / _numberOfVariablesStatistics);
1423 for ( iTitle=0; iTitle<sizeTitle ; iTitle++)
1425 fprintf(pFile,"-- \t %d-Size \t SizeRange \t Min \t Max \t Ave \t StDv \t" , iTitle,tmpString.c_str() );
1427 fprintf(pFile,"\n" );
1431 for ( j=0; j<maxY ; j++)
1433 fprintf(pFile,"%d\t" , j );
1434 for (i=0 ; i<maxX ; i++){
1435 tmpString = interfMainPanel::getInstance()->getCellValue(j, i);//_grid->GetCellValue( j , i );
1436 fprintf(pFile,"%s\t" , (const char *)(tmpString.mb_str()) );
1438 fprintf(pFile,"\n" );
1444 void wxContourMainFrame::SaveValuesXYZ(std::string directory,std::string namefile,int typeContourGroup)
1447 ContourExtractData *contourextractdata = new ContourExtractData();
1448 //int typeContourGroup = this->_radiolstboxContourGroup->GetSelection();
1449 contourextractdata ->SetTypeOperation( typeContourGroup % 3 );
1451 std::vector<manualContourModel*> lstManConMod;
1452 std::vector<manualContourModel*> lstManConModTmp;
1453 std::vector<manualContourModel*> lstManConModExp;
1454 std::vector<double> pLstValue;
1455 std::vector<double> pLstValuePosX;
1456 std::vector<double> pLstValuePosY;
1457 std::vector<double> pLstValuePosZ;
1459 std::vector<int> tempVector;
1460 _instantPanel->getInstant( tempVector );
1462 vtkImageData *imagedata = _theViewPanel->getSceneManager()->GetImageData();
1463 int sizeZ = _theViewPanel->getSceneManager()->GetImageDataSizeZ();
1465 int ii,sizeLstContourThings;
1472 minZ = 0;// _mbarrange->GetStart();
1473 maxZ = sizeZ;//_mbarrange->GetEnd();
1474 totalZ = maxZ-minZ+1;
1476 contourextractdata->SetImage( imagedata);
1479 for ( z=0 ; z<sizeZ ; z++)
1482 porcent = 100.0* (z-minZ)/totalZ;
1484 tmpString.Printf(_T("Saving Values"));
1485 tmpString.Printf(_T(" %d %c %d/%d %d"), (int)porcent , 37 , z-minZ+1, (int)totalZ ,z);
1486 interfMainPanel::getInstance()->setStringInfoPanel(tmpString);
1487 //_staticTextInformation->SetLabel(tmpString);
1490 //Extraction data from contours of each slice
1491 contourextractdata->SetZtoBeAnalys( z);
1494 Instant instant(&tempVector);
1495 std::vector<ContourThing**> lstContourThings = kernelManager->getOutlinesAtInstant(&instant);//this->_modelManager->getOutlinesAtInstant( &instant );
1496 sizeLstContourThings = lstContourThings.size();
1498 lstManConMod.clear();
1499 for (ii=0 ; ii<sizeLstContourThings ; ii++)
1501 ContourThing **contourthing = lstContourThings[ii];
1502 lstManConMod.push_back( (*contourthing)->getModel() );
1504 lstManConModExp = kernelManager->ExploseEachModel( lstManConMod );
1509 int iContourGroup,sizeContourGroup;
1510 if (typeContourGroup==3) // contour separete
1512 sizeContourGroup=lstManConModExp.size();
1513 } else { // contour AND OR XOR
1517 for( iContourGroup=0 ; iContourGroup<sizeContourGroup ; iContourGroup++ ){
1518 lstManConModTmp.clear();
1519 if (typeContourGroup==3) // contour separete
1521 lstManConModTmp.push_back( lstManConModExp[iContourGroup]);
1522 } else { // contour AND OR XOR
1523 lstManConModTmp = lstManConModExp;
1526 contourextractdata->SetLstManualContourModel( lstManConModTmp );
1529 pLstValuePosX.clear();
1530 pLstValuePosY.clear();
1531 pLstValuePosZ.clear();
1532 contourextractdata->GetValuesInsideCrown( &pLstValue,
1537 std::string temp = directory + "/" + namefile + "-slice";
1538 temp = temp + kernelManager->intToString(z) + "-cont" + kernelManager->intToString(iContourGroup);
1539 temp = temp + ".txt";
1541 // LG 14/01/09 : using crea
1542 wxString filename = crea::std2wx(temp);
1543 /*filename.Printf(_T("%s"),directory.c_str());
1544 filename.append(_T("\\"));
1545 filename.append(_T("%s"),namefile.c_str());
1546 filename.append(_T("-slice"));
1547 filename.append(_T("%d"),z);
1548 filename.append(_T("-cont"));
1549 filename.append(_T("%d"),iContourGroup);
1550 filename.append(_T(".txt"));*/
1551 // filename.Printf(temp.c_str());
1555 FILE *pFile=fopen((const char *)filename.mb_str(),"w+");
1556 fprintf(pFile,"value \t x \t y \t z\n" );
1557 int iLstValue,sizeLstValue=pLstValue.size();
1558 for (iLstValue=0 ; iLstValue<sizeLstValue ; iLstValue++ )
1560 fprintf(pFile,"%f\t %f\t %f\t %f\n", (float)pLstValue[iLstValue] , (float)pLstValuePosX[iLstValue], (float)pLstValuePosY[iLstValue], (float)z );
1563 } // for iContourGroup
1565 interfMainPanel::getInstance()->setStringInfoPanel(_T(""));
1566 //_staticTextInformation->SetLabel( _T("") );
1567 delete contourextractdata;
1570 void wxContourMainFrame::SaveImageResult(std::string directory,std::string namefile, int typeContourGroup)
1573 ContourExtractData *contourextractdata = new ContourExtractData( true );
1574 //int typeContourGroup = this->_radiolstboxContourGroup->GetSelection();
1575 if (typeContourGroup==3)
1579 contourextractdata ->SetTypeOperation( typeContourGroup % 3 );
1581 std::vector<manualContourModel*> lstManConMod;
1582 std::vector<manualContourModel*> lstManConModTmp;
1583 std::vector<manualContourModel*> lstManConModExp;
1585 std::vector<int> tempVector;
1586 _instantPanel->getInstant( tempVector );
1588 vtkImageData *imagedata = _theViewPanel->getImageData();
1589 int sizeZ = _theViewPanel->GetImageDataSizeZ();
1591 int ii,sizeLstContourThings;
1600 minZ = 0;// _mbarrange->GetStart();
1601 maxZ = sizeZ;//_mbarrange->GetEnd();
1602 totalZ = maxZ-minZ+1;
1604 contourextractdata->SetImage( imagedata);
1607 for ( z=0 ; z<sizeZ ; z++)
1610 porcent = 100.0* (z-minZ)/totalZ;
1611 tmpString.Printf(_T("Saving Values"));
1612 tmpString.Printf(_T("%d %c %d/%d %d"), (int)porcent , 37 , z-minZ+1, (int)totalZ ,z);
1613 interfMainPanel::getInstance()->setStringInfoPanel(tmpString);
1615 //Extraction data from contours of each slice
1616 contourextractdata->SetZtoBeAnalys( z);
1619 Instant instant(&tempVector);
1620 std::vector<ContourThing**> lstContourThings = kernelManager->getOutlinesAtInstant( &instant );
1621 sizeLstContourThings = lstContourThings.size();
1623 lstManConMod.clear();
1624 for (ii=0 ; ii<sizeLstContourThings ; ii++)
1626 ContourThing **contourthing = lstContourThings[ii];
1627 lstManConMod.push_back( (*contourthing)->getModel() );
1629 lstManConModExp = kernelManager->ExploseEachModel( lstManConMod );
1632 int iContourGroup,sizeContourGroup;
1633 if (typeContourGroup==3) // contour separete
1635 sizeContourGroup=lstManConModExp.size();
1636 } else { // contour AND OR XOR
1640 for( iContourGroup=0 ; iContourGroup<sizeContourGroup ; iContourGroup++ ){
1641 lstManConModTmp.clear();
1642 if (typeContourGroup==3) // contour separete
1644 lstManConModTmp.push_back( lstManConModExp[iContourGroup]);
1645 } else { // contour AND OR XOR
1646 lstManConModTmp = lstManConModExp;
1649 contourextractdata->SetLstManualContourModel( lstManConModTmp );
1652 // for (ii=0 ; ii<sizeLstContourThings ; ii++)
1654 // ContourThing **contourthing = lstContourThings[ii];
1655 // lstManConMod.push_back( (*contourthing)->getModel() );
1657 // contourextractdata->SetLstManualContourModel( lstManConMod );
1659 contourextractdata->CalculateImageResult(); // with actual Z
1661 } // for iContourGroup
1664 std::string temp = directory + "/" + namefile + "-Value.mhd";
1666 wxString filename = crea::std2wx(temp);
1668 // filename.Printf(_T(temp.c_str()));
1669 //filename.Printf(_T("%s\\%s-Value.mhd",directory.c_str(),namefile.c_str(),z);
1670 /*filename.Printf(_T("%s"),directory.c_str());
1671 filename.append(_T("\\"));
1672 filename.append(_T("%s"),namefile.c_str());
1673 filename.append(_T("-Value.mhd"));*/
1676 vtkMetaImageWriter *writerValueImage = vtkMetaImageWriter::New( );
1677 writerValueImage->SetInput( contourextractdata->GetVtkImageValueResult() );
1678 writerValueImage->SetFileName( (const char *)filename.mb_str() );
1679 writerValueImage->SetFileDimensionality( 3 );
1680 writerValueImage->Write( );
1683 // filename.Printf("%s\\%s-Mask.mhd",directory.c_str(),namefile.c_str(),z);
1684 temp = directory + "/" + namefile + "-Mask.mhd";
1686 // LG 14/01/09 : using crea
1687 filename = crea::std2wx(temp);
1688 // filename.Printf(_T(temp.c_str()));
1690 /*filename.Printf(_T("%s"),directory.c_str());
1691 filename.append(_T("\\"));
1692 filename.append(_T("%s"),namefile.c_str());
1693 filename.append(_T("-Mask.mhd"));*/
1695 vtkMetaImageWriter *writerMaskImage = vtkMetaImageWriter::New( );
1696 writerMaskImage->SetInput( contourextractdata->GetVtkImageMaskResult() );
1697 writerMaskImage->SetFileName( (const char *)filename.mb_str() );
1698 writerMaskImage->SetFileDimensionality( 3 );
1699 writerMaskImage->Write( );
1701 interfMainPanel::getInstance()->setStringInfoPanel( _T("") );
1702 delete contourextractdata;
1705 void wxContourMainFrame::onChangeInstantInstantPanel(std::string name,int value, int minshow, int maxshow){
1706 if( name.compare( _theViewPanel->getVerticalConceptName() ) == 0){
1707 _theViewPanel->setActualVertical( value);
1709 else if( name.compare( _theViewPanel->getHorizontalConceptName() ) == 0|| _instantPanel->getIfConceptCheckedAt( name, 0 ) ) {
1710 _theViewPanel->setHorizontalConcept( name, minshow, maxshow, minshow, maxshow, value);
1716 void wxContourMainFrame::onSnakePressed(){
1717 std::vector<double> vecX;
1718 std::vector<double> vecY;
1719 std::vector<double> vecZ;
1720 _theViewPanel->GetPointsOfActualContour( &vecX , &vecY , &vecZ );
1722 if (vecX.size()!=0){
1723 std::vector<int> tempVector;
1724 _instantPanel->getInstant( tempVector );
1725 int i,size=vecZ.size();
1726 int actualSlice = tempVector[1];
1727 for ( i=0 ; i<size ; i++ )
1729 vecZ[i] = actualSlice;
1732 wxDialog* dialog = new wxDialog(this, -1, wxString(_T("Snake")));
1733 wxPanel* panel = new wxPanel(dialog,-1);
1734 wxStaticText* sttext = new wxStaticText(panel, -1, wxString(_T("Panel para snake")));
1735 dialog->ShowModal();
1740 void wxContourMainFrame::saveFileWithContoursAutomatique(){
1741 std::string filename = kernelManager->getCurrentFileName();
1742 if(filename.compare("")!=0){
1743 saveFileWithContours(filename);