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,std::string datadir)
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,datadir+"/data/");
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,datadir+"/data/Icons");//, eventHandler);
158 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 ){
159 if(instance == NULL){
160 instance = new wxContourMainFrame(parent, id, title, pos, size, images, style,datadir);
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
318 void wxContourMainFrame::onCreateContourLine( ){
319 //JCP 20-10-08 Undo redo implementation
321 //JCP 20-10-08 Undo redo implementation
325 //------------------------------------------------------------------------------------------------------------
327 void wxContourMainFrame :: onCreateContourBullEye(wxPanel* panel )
329 //Creating the manualContourModel and including in the model
330 manualContourModel * manModelContour = factoryManualContourModel(panel );
332 std::vector<int> instantVector;
333 _instantPanel->getInstant( instantVector );
334 std::string theName = kernelManager->createOutline(manModelContour, instantVector);
336 /*std::vector<int> instantVector;
337 _instantPanel->getInstant( instantVector );
339 theName= _modelManager->createOutline( manModelContour, instantVector );*/
340 bool addedModel = theName.compare("") != 0;//??
344 double spc[3];//Si no hay imagen pero hay contornos que spacing se pone por default
345 _theViewPanel->getSpacing(spc);
346 //Adding the manualContourControler to interface objects structure
347 //Adding the manualViewContour to interface objects structure
348 //_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.
349 _theViewPanel->getSceneManager()->configureViewControlTo( theName, manModelContour,spc , 4) ;
352 void wxContourMainFrame :: createContour( int typeContour )
354 //Creating the manualContourModel and including in the model
355 manualContourModel * manModelContour = kernelManager->factoryManualContourModel(typeContour);
358 std::vector<int> instantVector;
359 _instantPanel->getInstant( instantVector );
360 std::string theName = kernelManager->createOutline(manModelContour, instantVector);
362 /*std::vector<int> instantVector;
363 _instantPanel->getInstant( instantVector );
365 theName= _modelManager->createOutline( manModelContour, instantVector );*/
366 bool addedModel = theName.compare("") != 0;//??
369 double spc[3];//Si no hay imagen pero hay contornos que spacing se pone por default
370 _theViewPanel->getSpacing(spc);
371 //Adding the manualContourControler to interface objects structure
372 //Adding the manualViewContour to interface objects structure
373 //_sceneManager->setControlActiveStateOfALL( false );//This call is being done here because if the ROI is created underneath the previously created ROIS will still be active.
374 _theViewPanel->getSceneManager()->configureViewControlTo( theName, manModelContour,spc , typeContour) ;
378 manualContourModel * wxContourMainFrame::factoryManualContourModel(wxPanel* panel){
380 manualContourModelBullEye *manModelContourBullEye = new manualContourModelBullEye();
381 manualContourModel *manModelContour=NULL;
382 manModelContour = manModelContourBullEye;
384 int iCrown,sizeCrowns,iSector,sizeSectors;
385 double radioA,radioB,ang,angDelta ;
386 sizeCrowns = ((PanelBullEyeOptions*)panel)->GetNumberOfCrowns();
387 for ( iCrown=0 ; iCrown<sizeCrowns ; iCrown++ )
389 sizeSectors = ((PanelBullEyeOptions*)panel)->GetNumberOfSections(iCrown);
390 radioB = ((PanelBullEyeOptions*)panel)->GetRadioOfCrown(iCrown);
391 if (iCrown==sizeCrowns-1)
395 radioA = ((PanelBullEyeOptions*)panel)->GetRadioOfCrown(iCrown+1);
399 for ( iSector=0 ; iSector<sizeSectors ; iSector++ )
401 ang = ((PanelBullEyeOptions*)panel)->GetAngOfCrownSection(iCrown,iSector);
402 angDelta= ((PanelBullEyeOptions*)panel)->GetAngDeltaOfCrownSection(iCrown);
403 manModelContourBullEye->AddSector(radioA,radioB,ang,angDelta);
406 } // if _panelBullEyeOptions
408 return manModelContour;
410 void wxContourMainFrame :: saveState(){
412 std::string temp = kernelManager->saveState();
413 saveFileWithContours(temp);
416 void wxContourMainFrame::onDeleteContour(){
417 //JCP 20-10-08 Undo redo implementation
419 //JCP 20-10-08 Undo redo implementation
421 std::vector<std::string> lstKeyNameToBeErase;
422 lstKeyNameToBeErase = _theViewPanel->getSceneManager()->getSelectedObjects();
423 deleteContours( lstKeyNameToBeErase );
425 int i,size=_sceneManager->getSelectedObjects().size();
428 std::string keyName = _sceneManager->getSelectedObjects()[i];
429 int ispartofstaticlist = this->_modelManager->IsPartOfStaticList( keyName );
430 if ( ispartofstaticlist>=0 )
432 std::vector<int> tempVector;
433 _instantPanel->getInstant( tempVector );
434 Instant instant(&tempVector);
435 this->_modelManager->ChangeContourOfList(keyName, &instant);
439 std::vector<std::string> lstKeyName;
440 std::vector<std::string> lstKeyNameActualSlice;
441 std::vector<std::string> lstKeyNameToBeErase;
443 lstKeyNameToBeErase = _sceneManager->getSelectedObjects();
444 lstKeyNameActualSlice = _sceneManager->GetlstContoursNameActualSlice();
445 int k,kSize=lstKeyNameToBeErase.size();
446 int j,jSize=lstKeyNameActualSlice.size();
448 for (k=0;k<kSize; k++)
451 for (j=0;j<jSize; j++)
453 if (lstKeyNameToBeErase[k]==lstKeyNameActualSlice[j])
460 lstKeyName.push_back( lstKeyNameToBeErase[k] );
464 deleteContours( lstKeyName );
468 void wxContourMainFrame :: deleteContours( std::vector<std::string> keyNamesVector )
470 int i,size=keyNamesVector.size();
473 deleteContour( keyNamesVector[i] );
477 void wxContourMainFrame :: deleteContour( std::string theKeyName ){
478 /*manualContourModel * cModel;
479 manualViewBaseContour * cViewer;
480 manualContourBaseControler * cControler;
482 ContourWrap_ViewControl *conwrapviewControl = _theViewPanel->getSceneManager()->getContourWrap_ViewControlOf( theKeyName );
483 cControler = conwrapviewControl->getControler();*/
486 bool isedit = _theViewPanel->isEditableCControler(theKeyName);
487 bool ispartofstaticlst = kernelManager->IsPartOfStaticList(theKeyName);
489 if (isedit && ispartofstaticlst)
491 _theViewPanel->removeFromScene(theKeyName);
493 kernelManager->deleteCModel(theKeyName);
494 //_theViewPanel->getSceneManager()->removeFromScene( theKeyName );
495 //cViewer = conwrapviewControl->getViewer();
496 //_theViewPanel->getSceneManager()->removeWrap( theKeyName );
497 //cControler* conwrapviewControl->getControler();
499 //FILE *ff = fopen("c:/temp/wxVtkBaseView_SceneManagerStadistics.txt","a+");
500 //fprintf(ff,"EED wxContourEventHandler::deleteContours() \n" );
501 //fprintf(ff," %s %p\n",keyNamesVector[i].c_str(), cControler );
505 // delete cControler;
510 void wxContourMainFrame::onDeleteContoursActSlice(){
511 //JCP 20-10-08 Undo redo implementation
513 //JCP 20-10-08 Undo redo implementation
514 deleteContours( (std::vector<std::string>)_theViewPanel->getSceneManager()->GetlstContoursNameActualSlice() );
516 void wxContourMainFrame::onDeleteAllContours(){
517 //JCP 20-10-08 Undo redo implementation
521 void wxContourMainFrame::deleteAllContours(){
522 //JCP 20-10-08 Undo redo implementation
525 std::vector<int> tempVector;
526 _instantPanel->getInstant( tempVector );
528 //JCP --08-09-2008 When using a diferent interface the _mbarrangeDeleteAll might not be initialize
529 // the values in GetStart and GetEnd will then not be initialize also.
530 // We use instead the values given when initializing the _deletepanel.
532 //int minZ = _mbarrangeDeleteAll->GetStart();
533 //int maxZ = _mbarrangeDeleteAll->GetEnd();
537 maxZ = _theViewPanel->getSceneManager()->GetImageDataSizeZ();
541 _theViewPanel->getSceneManager()->removeSceneContours( );
542 _theViewPanel->getSceneManager()->removeAllOutlines();
543 kernelManager->removeAllOutlines();
546 if ( (minZ==0) && (maxZ==_mbarrangeDeleteAll->GetMax() ))
548 _theViewPanel->getSceneManager()->removeSceneContours( );
549 _modelManager->removeAllOutlines();
550 _theViewPanel->getSceneManager()->removeAllOutlines();
553 for ( z=minZ ; z<=maxZ ; z++)
556 Instant instant(&tempVector);
557 std::vector<ContourThing**> lstContourThings = this->_modelManager->getOutlinesAtInstant( &instant );
559 sizeLstContourThings = lstContourThings.size();
560 for (ii=0 ; ii<sizeLstContourThings ; ii++)
562 ContourThing **contourthing = lstContourThings[ii];
563 deleteContour( (*contourthing)->getName() );
570 void wxContourMainFrame::setConceptValue( std::string name, int value ){
571 _instantPanel->setConceptValue(name, value);
574 ConceptDataWrap* wxContourMainFrame::getLastConceptData(){
575 return _instantPanel->getLastConceptData();
577 bool wxContourMainFrame::getIfConceptCheckedAt( std::string name, int pos ){
578 return _instantPanel->getIfConceptCheckedAt( name, pos );
581 void wxContourMainFrame::changeInstant(){
582 std::vector<int> instantVect;
583 _instantPanel->getInstant( instantVect );
584 // Instant * theInstant = new Instant ( &instantVect );
586 //Setting the actual instant
587 //_actualInstant = theInstant;
589 kernelManager->setInstant(instantVect);
590 //_modelManager->setInstant( _actualInstant );
592 updateInstantOutlines();
593 updateInstantImageData();
598 void wxContourMainFrame :: updateInstantOutlines(){
600 _theViewPanel->removeSceneContours();
601 _theViewPanel->addNameWrapperToScene();
603 //for( int i=0; i<size; i++)
605 // _theViewPanel->getSceneManager()->addToScene(namesWrapping[i]->getKeyName(), true, true, true, false, false );
609 int wxContourMainFrame::getNamesWrappingSize(){
610 return kernelManager->getNamesWrappingSize();
612 std::string wxContourMainFrame::getNameWrapping(int i){
613 return kernelManager->getNameWrapping(i);
616 void wxContourMainFrame::updateInstantImageData(){
617 std::vector<int> inst;
618 _instantPanel->getInstant(inst);
620 vtkImageData* img = kernelManager->getImageAtInstant(inst);
622 _theViewPanel->changeImage(img);
625 int z = _instantPanel->getConceptDataOf("Axe Depth")->getActualValue();
626 _theViewPanel->setImageSlice(z);
629 void wxContourMainFrame::updateInstantAxes(){
632 void wxContourMainFrame::onChangeDeep(int val){
633 _instantPanel->setConceptValue( "Axe Depth", (int)val );
638 void wxContourMainFrame::onCopy(){
639 std::vector<std::string> currentSelection = _theViewPanel->getSelectedObjects();
641 std::vector<int> tempVector;
642 _instantPanel->getInstant( tempVector );
643 _performingOperation->reset();
644 _performingOperation->setStartCommand( COPY );
645 _performingOperation->setStartOperationInstantVector( tempVector );
646 _performingOperation->setKeyNamesOperationElems( currentSelection );
649 void wxContourMainFrame::onPaste(){
652 char theStartCommand = _performingOperation->getStartCommand();
653 if ( theStartCommand == COPY )
655 //JCP 20-10-08 Undo redo implementation
657 //JCP 20-10-08 Undo redo implementation
658 std::vector<int> tempVector;
659 _instantPanel->getInstant( tempVector );
660 _performingOperation->setEndOperationInstantVector ( tempVector );
661 std::vector<std::string> elems = _performingOperation->getKeyNamesOperationElems();
662 int i,size = elems.size();
663 for( i=0; i<size; i++ )
665 createCopyContourOf( elems[i], tempVector, i>0 );
669 void wxContourMainFrame::onUndo(){
670 std::string filename;
671 if(kernelManager->onUndoSaveFile(filename)){
672 saveFileWithContours(filename);
674 if(kernelManager->onUndo(filename)){
678 void wxContourMainFrame::onRedo(){
679 std::string filename;
680 if(kernelManager->onRedo(filename)){
685 void wxContourMainFrame :: createCopyContourOf ( std::string anExistingKName, std::vector<int> &instantNoTouchData, bool append ){
686 std::string cloneName = kernelManager->createCopyContourOf( anExistingKName, instantNoTouchData );
687 manualContourModel * manualModel = kernelManager->getOutlineByKeyName(cloneName);//_modelManager->getOutlineByKeyName( cloneName )->getModel();
688 _theViewPanel->getSceneManager()->createCopyContourOf( anExistingKName, cloneName, manualModel , append );
691 void wxContourMainFrame ::loadState(std::string filename){
693 FILE *pFile=fopen(filename.c_str(),"r+");
695 fscanf(pFile,"%s",tmp); // --CreaContour--
697 fscanf(pFile,"%s",tmp); // Version
698 fscanf(pFile,"%s",tmp); // 1.0.1
699 std::string version(tmp);
703 openContours(pFile,false);
704 if (version!="1.0.0"){
705 openContours(pFile,true);
710 //_theViewPanel->getSceneManager()->removeSceneContours();
715 void wxContourMainFrame::onLoad(){
717 wxFileDialog dialog(NULL, _T("Choose a file"), _T(""), _T(""), _T("*.roi"), wxOPEN );
718 if (dialog.ShowModal() == wxID_OK)
720 std::string fileNameContourROI = (const char *)(dialog.GetPath().mb_str());
721 FILE *pFile=fopen(fileNameContourROI.c_str(),"r+");
723 fscanf(pFile,"%s",tmp); // --CreaContour--
725 fscanf(pFile,"%s",tmp); // Version
726 fscanf(pFile,"%s",tmp); // 1.0.1
727 std::string version(tmp);
729 openContours(pFile,false);
730 if (version!="1.0.0"){
731 openContours(pFile,true);
733 // _theViewPanel->getSceneManager()->openFileWithContours(ff);
737 _theViewPanel->getSceneManager()->removeSceneContours();
740 void wxContourMainFrame::onSave(){
741 wxFileDialog dialog(NULL, _T("Choose a file"), _T(""), _T(""), _T("*.roi"), wxSAVE );
742 if (dialog.ShowModal() == wxID_OK)
744 std::string fileNameContourROI = (const char *)(dialog.GetPath().mb_str());
745 kernelManager->setCurrentFileName(fileNameContourROI);
746 saveFileWithContours( fileNameContourROI );
749 void wxContourMainFrame::saveFileWithContours( std::string filename ){
751 FILE *pFile=fopen(filename.c_str(),"w+");
752 std::vector< std::string > lstNameThings;
753 int i,sizeLstNameThings;
755 fprintf(pFile,"--CreaContour--\n");
756 fprintf(pFile,"Version %s\n", "1.0.1" );
759 lstNameThings = kernelManager->GetLstNameThings();
760 sizeLstNameThings = lstNameThings.size();
761 fprintf(pFile,"NumberOfContours %d\n", sizeLstNameThings );
762 for (i=0 ; i<sizeLstNameThings ; i++)
764 kernelManager->SaveThingName( pFile, lstNameThings[i] );
765 _theViewPanel->getSceneManager()->SaveThingName( pFile, lstNameThings[i] );
768 //-- Contours Statics
769 lstNameThings = kernelManager->GetLstNameThingsStatic();
770 sizeLstNameThings = lstNameThings.size();
771 fprintf(pFile,"NumberOfContoursStatic %d\n", sizeLstNameThings );
772 for (i=0 ; i<sizeLstNameThings ; i++)
774 kernelManager->SaveThingName( pFile, lstNameThings[i] );
775 _theViewPanel->getSceneManager()->SaveThingName( pFile, lstNameThings[i] );
780 void wxContourMainFrame::openContours( FILE *pFile, bool staticContour ){
782 fscanf(pFile,"%s",tmp); // NumberOfContours
783 fscanf(pFile,"%s",tmp); // ##
784 int numberOfContours = atoi(tmp);
786 std::vector<int> instantVector;
787 int typeContourModel;
788 manualContourModel *manModelContour;
792 for (i=0;i<numberOfContours;i++)
794 instantVector.clear();
795 fscanf(pFile,"%s",tmp); // Instant
797 fscanf(pFile,"%s",tmp); // 1
798 instantVector.push_back( atoi(tmp) );
799 fscanf(pFile,"%s",tmp); // 2
800 instantVector.push_back( atoi(tmp) );
801 fscanf(pFile,"%s",tmp); // 3
802 instantVector.push_back( atoi(tmp) );
803 fscanf(pFile,"%s",tmp); // 4
804 instantVector.push_back( atoi(tmp) );
805 fscanf(pFile,"%s",tmp); // 5
806 instantVector.push_back( atoi(tmp) );
807 fscanf(pFile,"%s",tmp); // 6
808 instantVector.push_back( atoi(tmp) );
811 fscanf(pFile,"%s",tmp); // TypeContourModel
812 fscanf(pFile,"%s",tmp); // ##
813 typeContourModel = atoi(tmp);
815 manModelContour = kernelManager->factoryManualContourModel(typeContourModel);
816 manModelContour->Open(pFile);
818 fscanf(pFile,"%s",tmp); // TypeView
819 fscanf(pFile,"%s",tmp); // ##
820 typeView = atoi(tmp);
829 theName = kernelManager->createOutline( manModelContour, instantVector );
830 bool addedModel = theName.compare("") != 0;
833 double spc[3];//Si no hay imagen pero hay contornos que spacing se pone por default
834 _theViewPanel->getSpacing(spc);
835 //Adding the manualContourControler to interface objects structure
836 //Adding the manualViewContour to interface objects structure
837 //_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.
838 _theViewPanel->getSceneManager()->configureViewControlTo( theName, manModelContour,spc , typeView) ;
841 if (staticContour==true)
843 Instant instant(&instantVector);
844 kernelManager->changeContourOfManager( theName , &instant );
847 }// for numberOfContours
851 void wxContourMainFrame::RefreshInterface(){
853 _theViewPanel->RefreshInterface();
854 //wxVtk2DBaseView *wxvtk2dbaseview = (wxVtk2DBaseView*)this->_theViewPanel->getWxVtkBaseView();
855 //wxvtk2dbaseview->Refresh();
858 vtkImageData* wxContourMainFrame::getImageData(){
859 return _theViewPanel->getImageData();
862 void wxContourMainFrame::onSegmentationOneSlice(int isovalue,int sampling,int method){
864 //JCP 20-10-08 Undo redo implementation
866 //JCP 20-10-08 Undo redo implementation
869 int x = _theViewPanel->GetX();
870 int y = _theViewPanel->GetY();
871 int z = _theViewPanel->GetZ();
872 SegmentationOneSlice( x,y,z,isovalue, sampling, method );
877 void wxContourMainFrame::SegmentationOneSlice( int x, int y, int z, int isovalue, int sampling, int method )
879 int typeofcontour = 1;
880 //--Extracting Contour
881 //vtkImageData *imagedata = _theViewPanel->getSceneManager()->GetImageData();
882 vtkImageData *imagedata = getImageData();
883 // double *range = imagedata->GetScalarRange();
886 vtkImageReslice *imageReslice = vtkImageReslice::New();
889 // imagedata->GetSpacing(spc);
894 imageReslice->SetInput( imagedata );
895 imageReslice->SetInformationInput(imagedata);
896 imageReslice->SetResliceAxesDirectionCosines(1,0,0, 0,1,0 ,0,0,1);
897 imageReslice->SetResliceAxesOrigin(0,0,z);
898 imageReslice->SetOutputDimensionality(2);
899 imageReslice->SetInterpolationModeToLinear();
901 imagedata = imageReslice->GetOutput();
903 imagedata->UpdateInformation();
905 vtkContourFilter* cntVTK = vtkContourFilter::New( );
906 cntVTK->SetInput( imagedata );
908 cntVTK->SetNumberOfContours( 1 );
909 //cntVTK->SetValue( 0, vmin );
910 // cntVTK->SetValue( 0, (range[1]*thr/100) );
911 cntVTK->SetValue( 1, isovalue );
912 // cntVTK->SetValue( 1, vmax );
914 cntVTK->UpdateInformation();
916 vtkCleanPolyData* cpd = vtkCleanPolyData::New( );
917 cpd->SetInput( cntVTK->GetOutput( ) );
918 cpd->ConvertLinesToPointsOff( );
920 cpd->UpdateInformation();
922 vtkPolyDataConnectivityFilter* conn = vtkPolyDataConnectivityFilter::New( );
923 conn->SetExtractionModeToClosestPointRegion( );
924 //conn->SetMaxRecursionDepth( 3000 );
926 conn->SetInput( cpd->GetOutput( ) );
928 conn->SetClosestPoint( x, y, 0 );
930 conn->UpdateInformation();
932 vtkCleanPolyData* cpd2 = vtkCleanPolyData::New( );
933 cpd2->SetInput( conn->GetOutput( ) );
935 cpd2->UpdateInformation();
937 vtkStripper* vtkstripper = vtkStripper::New( );
938 vtkstripper->SetInput( cpd2->GetOutput() );
939 vtkstripper->Update();
940 vtkstripper->UpdateInformation();
943 vtkPolyData* polyDataResult = vtkstripper->GetOutput();
945 polyDataResult->Update( );
946 polyDataResult->UpdateInformation();
950 myfile.open ("c:/temp/example.txt");
952 polyDataResult->Print(myfile);
953 myfile << "-------------------------------------\n";
954 polyDataResult->GetLines()->Print(myfile);
964 //--Calculating control points
966 std::vector<double> vecX;
967 std::vector<double> vecY;
968 std::vector<double> vecZ;
970 std::vector<double> vecCtrlPointX;
971 std::vector<double> vecCtrlPointY;
972 std::vector<double> vecCtrlPointZ;
976 int ii,size=polyDataResult->GetNumberOfPoints();
978 for (ii=1;ii<=size;ii++)
980 id = polyDataResult->GetLines()->GetData()->GetValue(ii);
981 p = polyDataResult->GetPoint(id);
984 vecX.push_back( p[0] );
985 vecY.push_back( p[1] );
986 vecZ.push_back( -900 );
987 // vecZ.push_back( p[2] );
991 ExtractControlPoints2D *extractcontrolpoints2d = new ExtractControlPoints2D();
992 extractcontrolpoints2d->SetContour( &vecX , &vecY , &vecZ );
995 /*if (methodRadiobox->GetSelection()==0){
996 extractcontrolpoints2d->GetInitialControlPoints( &vecCtrlPointX , &vecCtrlPointY , &vecCtrlPointZ );
998 if (methodRadiobox->GetSelection()==1){
999 extractcontrolpoints2d->GetControlPoints( &vecCtrlPointX , &vecCtrlPointY , &vecCtrlPointZ );
1001 if (methodRadiobox->GetSelection()==2){
1002 extractcontrolpoints2d->SetSamplingControlPoints( sampling );
1003 extractcontrolpoints2d->GetSamplingControlPoints( &vecCtrlPointX , &vecCtrlPointY , &vecCtrlPointZ );
1007 extractcontrolpoints2d->GetInitialControlPoints( &vecCtrlPointX , &vecCtrlPointY , &vecCtrlPointZ );
1009 else if (method==1){
1010 extractcontrolpoints2d->GetControlPoints( &vecCtrlPointX , &vecCtrlPointY , &vecCtrlPointZ );
1012 else if (method==2){
1013 extractcontrolpoints2d->SetSamplingControlPoints( sampling );
1014 extractcontrolpoints2d->GetSamplingControlPoints( &vecCtrlPointX , &vecCtrlPointY , &vecCtrlPointZ );
1017 //--Adding contour to the system
1019 std::vector<int> actualInstantVector;
1020 _instantPanel->getInstant( actualInstantVector );
1021 actualInstantVector[1]=z;
1023 int j,sizeCtrPt = vecCtrlPointX.size();
1024 manualContourModel *manModelContour = kernelManager->factoryManualContourModel( typeofcontour );
1025 manModelContour->SetNumberOfPointsSpline( ((sizeCtrPt/100)+1)*100 );
1027 for (j=0 ; j<sizeCtrPt ; j++)
1029 manModelContour->AddPoint( vecCtrlPointX[j] , vecCtrlPointY[j] , vecCtrlPointZ[j] );
1031 std::string theName;
1032 //theName = _modelManager->createOutline( manModelContour, actualInstantVector );
1033 theName = kernelManager->createOutline( manModelContour, actualInstantVector );
1034 bool addedModel = theName.compare("") != 0;
1037 double spc[3];//Si no hay imagen pero hay contornos que spacing se pone por default
1038 _theViewPanel->getSpacing(spc);
1039 //Adding the manualContourControler to interface objects structure
1040 //Adding the manualViewContour to interface objects structure
1041 //_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.
1042 _theViewPanel->configureViewControlTo(theName, manModelContour, spc, typeofcontour);
1043 //_theViewPanel->getSceneManager()->configureViewControlTo( theName, manModelContour,spc, typeofcontour ) ;
1048 int wxContourMainFrame::GetImageDataSizeZ(){
1049 return _theViewPanel->GetImageDataSizeZ();
1052 void wxContourMainFrame::GetImageDataRange(double *range){
1053 _theViewPanel->GetImageDataRange(range);
1056 void wxContourMainFrame::onSegmentationAllSlice(int minZ,int maxZ,int isovalue,int sampling,int method){
1057 //JCP 20-10-08 Undo redo implementation
1059 //JCP 20-10-08 Undo redo implementation
1062 int x = _theViewPanel->GetX();
1063 int y = _theViewPanel->GetY();
1067 double totalZ = maxZ-minZ+1;
1068 for( z=minZ ; z<=maxZ ; z++ )
1070 porcent = 100.0* (z-minZ)/totalZ;
1071 tmpString.Printf(_T(" %d %c %d/%d %d"), (int)porcent , 37 , z-minZ+1, (int)totalZ,z );
1072 interfMainPanel::getInstance()->setLabelSegmentationPanelVTK(tmpString);
1073 //_staticTextSegmentation->SetLabel(tmpString);
1074 SegmentationOneSlice( x,y,z,isovalue, sampling,method );
1076 interfMainPanel::getInstance()->setLabelSegmentationPanelVTK(_T(" "));
1080 void wxContourMainFrame::onMirror()
1083 std::vector<std::string> currentSelection = _theViewPanel->getSelectedObjects();
1085 std::vector<int> tempVector;
1086 _instantPanel->getInstant( tempVector );
1087 _performingOperation->reset();
1088 _performingOperation->setStartCommand( COPY );
1089 _performingOperation->setStartOperationInstantVector( tempVector );
1090 _performingOperation->setKeyNamesOperationElems( currentSelection );
1093 char theStartCommand = _performingOperation->getStartCommand();
1094 if ( theStartCommand == COPY )
1096 //JCP 20-10-08 Undo redo implementation
1098 //JCP 20-10-08 Undo redo implementation
1099 std::vector<int> tempVector;
1100 _instantPanel->getInstant( tempVector );
1101 _performingOperation->setEndOperationInstantVector ( tempVector );
1102 std::vector<std::string> elems = _performingOperation->getKeyNamesOperationElems();
1103 int i,size = elems.size();
1104 for( i=0; i<size; i++ )
1106 createCopyContourOf( elems[i], tempVector, i>0 );
1111 void wxContourMainFrame::showAxis(bool show){
1112 _theViewPanel->SetVisibleAxis(show);
1113 _theViewPanel->Refresh();
1117 void wxContourMainFrame::onRigidPressed(){
1118 std::vector<std::string> currentSelection = _theViewPanel->getSelectedObjects();
1119 int elementsSelected = currentSelection.size();
1121 if ( elementsSelected >= 1 ){
1122 //JCP 20-10-08 Undo redo implementation
1124 //JCP 20-10-08 Undo redo implementation
1126 std::vector<int> tempVector;
1127 _instantPanel->getInstant( tempVector );
1128 Instant instant(&tempVector);
1130 int i , size=currentSelection.size();
1131 for ( i=0 ; i<size ; i++ )
1133 kernelManager->changeContourOfManager(currentSelection[i], &instant);
1138 void wxContourMainFrame::onWidthOfContour(double width){
1140 _theViewPanel->removeSceneContours();
1141 _theViewPanel->SetWidthContour(width);
1143 //_theViewPanel->getSceneManager()->SetWidthContour( width );
1147 int wxContourMainFrame::getColorWindow(){
1148 return _theViewPanel->getColorWindow();
1150 int wxContourMainFrame::getWindowLevel(){
1151 return _theViewPanel->getWindowLevel();
1154 void wxContourMainFrame::onBrigthnessColorWindowLevel(int colorwindow,int windowlevel){
1155 _theViewPanel->onBrigthnessColorWindowLevel(colorwindow, windowlevel);
1161 void wxContourMainFrame::onInterpolation(bool interpolate){
1162 _theViewPanel->onInterpolation(interpolate);
1166 void wxContourMainFrame::onChangeInstant(std::string name,int actual){
1167 _instantPanel->setConceptValue( name, actual );
1170 void wxContourMainFrame::resetAppend(){
1171 kernelManager->resetAppend();
1175 void wxContourMainFrame::onSpreadAdd(){
1176 std::vector<double> vecX;
1177 std::vector<double> vecY;
1178 std::vector<double> vecZ;
1179 _theViewPanel->GetPointsOfActualContour(&vecX , &vecY , &vecZ );
1181 std::vector<int> tempVector;
1182 _instantPanel->getInstant( tempVector );
1184 std::string val = kernelManager->onSpreadAdd(&vecX , &vecY , &vecZ, tempVector);
1186 interfMainPanel::getInstance()->appendStringSpread(val);
1190 void wxContourMainFrame::onSpreadGo(int type){
1192 //JCP 20-10-08 Undo redo implementation
1194 //JCP 20-10-08 Undo redo implementation
1197 std::vector<double> vecCtrlPointX;
1198 std::vector<double> vecCtrlPointY;
1199 std::vector<double> vecCtrlPointZ;
1203 std::vector<int> tempVector;
1204 _instantPanel->getInstant( tempVector );
1207 kernelManager->getMaxMinZ(&minZ,&maxZ);
1208 //JSTG_16-07-08_----------------------------------------------------------------
1209 //_contourPropagation->setInterpolationNumber(maxZ-minZ+1);
1210 kernelManager->CalculeSplinePropagation();
1212 double totalZ = maxZ-minZ+1;
1215 //--------------------------------------------------------------------
1216 for ( z=(int)minZ ; z<=(int)maxZ ; z++ )
1218 porcent = 100.0* (z-minZ)/totalZ;
1219 int numero = (int)(z-minZ+1)/(int)totalZ;
1220 std::string stringtemp = " "+kernelManager->intToString(porcent)+"% "+kernelManager->intToString(numero)+" "+kernelManager->intToString(z);
1222 interfMainPanel::getInstance()->setStringSpread(stringtemp);
1224 int typeofcontour = 1;
1225 std::string theName;
1226 manualContourModel* manModelContour = kernelManager->GetPoints(z, type, &vecCtrlPointX,&vecCtrlPointY,&vecCtrlPointZ, theName,typeofcontour, tempVector);
1228 if( manModelContour!=NULL ){
1229 double spc[3];//Si no hay imagen pero hay contornos que spacing se pone por default
1230 this->_theViewPanel->getSpacing(spc);
1231 //Adding the manualContourControler to interface objects structure
1232 //Adding the manualViewContour to interface objects structure
1233 //_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.
1234 _theViewPanel->configureViewControlTo( theName, manModelContour,spc,typeofcontour ) ;
1239 int numero = (int)(z-minZ+1)/(int)totalZ;
1240 std::string stringtemp = " "+kernelManager->intToString(porcent)+"% "+kernelManager->intToString(numero)+" "+kernelManager->intToString(z);
1242 interfMainPanel::getInstance()->setStringSpread(stringtemp);
1244 //RefreshInterface();
1247 void wxContourMainFrame::getInstantVector(std::vector<int>& tempVector){
1251 std::vector<std::string> wxContourMainFrame::getOutlinesName(int slide){
1252 std::vector<int> tempVector;
1253 _instantPanel->getInstant(tempVector);
1254 //Asignation of slide number should be different ex by name
1255 tempVector[1]=slide;
1256 return kernelManager->getOutlinesNameAtInstant(tempVector);
1259 void wxContourMainFrame::onInformationContourLabels(int typeContourGroup,int selection,int minimumZ,int maximumZ){
1260 int maxContourGroup = 0;
1262 ContourExtractData *contourextractdata = new ContourExtractData();
1264 contourextractdata ->SetTypeOperation( typeContourGroup % 3 );
1266 std::vector<manualContourModel*> lstManConMod;
1267 std::vector<manualContourModel*> lstManConModTmp;
1268 std::vector<manualContourModel*> lstManConModExp;
1269 std::vector<double> pLstValue;
1270 std::vector<double> pLstValuePosX;
1271 std::vector<double> pLstValuePosY;
1272 std::vector<double> pLstValuePosZ;
1275 int resultGrayRangeCount;
1278 double resultAverage;
1279 double resultStandardeviation;
1281 std::vector<int> tempVector;
1282 _instantPanel->getInstant( tempVector );
1284 vtkImageData *imagedata = _theViewPanel->getImageData();
1285 int sizeZ = _theViewPanel->GetImageDataSizeZ();
1287 int ii,sizeLstContourThings;
1297 if (selection==0 ) // actual slice
1299 std::vector<int> tempVector;
1300 _instantPanel->getInstant( tempVector );
1301 int actualSlice = tempVector[1];
1305 else if (selection==2 ) // All slices
1310 else if (selection==1 ) // slice range
1317 totalZ = maxZ-minZ+1;
1318 contourextractdata->SetImage( imagedata);
1321 for ( z=minZ ; z<=maxZ ; z++ )
1324 porcent = 100.0* (z-minZ)/totalZ;
1325 tmpString.Printf(_T(" %d %c %d/%d %d"), (int)porcent , 37 , z-minZ+1, (int)totalZ ,z);
1327 interfMainPanel::getInstance()->setStringInfoPanel(tmpString);
1328 //_staticTextInformation->SetLabel(tmpString);
1330 //Extraction data from contours of each slice
1331 contourextractdata->SetZtoBeAnalys( z);
1334 Instant instant(&tempVector);
1335 std::vector<ContourThing**> lstContourThings = kernelManager->getOutlinesAtInstant( &instant );
1336 sizeLstContourThings = lstContourThings.size();
1338 lstManConMod.clear();
1339 for (ii=0 ; ii<sizeLstContourThings ; ii++)
1341 ContourThing **contourthing = lstContourThings[ii];
1342 lstManConMod.push_back( (*contourthing)->getModel() );
1344 lstManConModExp = kernelManager->ExploseEachModel( lstManConMod );
1347 wxString tempString;
1348 tempString.Printf(_T("%d - %d"),z, sizeLstContourThings);
1349 interfMainPanel::getInstance()->setRowLabelInfoPanel(z, tempString);
1350 //_grid->SetRowLabelValue(z, tempString );
1352 int iContourGroup,sizeContourGroup;
1353 if (typeContourGroup==3) // contour separete
1355 sizeContourGroup=lstManConModExp.size();
1356 if ( maxContourGroup<sizeContourGroup )
1358 maxContourGroup=sizeContourGroup;
1360 } else { // contour AND OR XOR
1369 for( iContourGroup=0 ; iContourGroup<sizeContourGroup ; iContourGroup++ ){
1370 lstManConModTmp.clear();
1371 if (typeContourGroup==3) // contour separete
1373 lstManConModTmp.push_back( lstManConModExp[iContourGroup]);
1374 } else { // contour AND OR XOR
1375 lstManConModTmp = lstManConModExp;
1378 contourextractdata->SetLstManualContourModel( lstManConModTmp );
1381 pLstValuePosX.clear();
1382 pLstValuePosY.clear();
1383 pLstValuePosZ.clear();
1384 contourextractdata->GetValuesInsideCrown( &pLstValue,
1388 // Statistics of each slice.
1389 contourextractdata->Statistics( &pLstValue,
1392 &resultGrayRangeCount,
1397 &resultStandardeviation);
1399 if (interfMainPanel::getInstance()->getNumberColsInformationPanel()<_numberOfVariablesStatistics*(iContourGroup+1) )
1401 interfMainPanel::getInstance()->appendColsInformationPanel(_numberOfVariablesStatistics);
1404 tmpIntA=_numberOfVariablesStatistics*iContourGroup ;
1406 tempString.Printf(_T("%d"),resultSize);
1407 interfMainPanel::getInstance()->setCellValueInfoPanel(z, tmpIntA, tempString);
1409 tempString.Printf(_T("%d"),resultGrayRangeCount);
1410 interfMainPanel::getInstance()->setCellValueInfoPanel(z, tmpIntA+1, tempString);
1412 tempString.Printf(_T("%f"),resultMin);
1413 interfMainPanel::getInstance()->setCellValueInfoPanel(z, tmpIntA+2, tempString);
1415 tempString.Printf(_T("%f"),resultMax);
1416 interfMainPanel::getInstance()->setCellValueInfoPanel(z, tmpIntA+3, tempString);
1418 tempString.Printf(_T("%f"),resultAverage);
1419 interfMainPanel::getInstance()->setCellValueInfoPanel(z, tmpIntA+4, tempString);
1421 tempString.Printf(_T("%f"),resultStandardeviation);
1422 interfMainPanel::getInstance()->setCellValueInfoPanel(z, tmpIntA+5, tempString);
1425 } // for iContourGroup
1429 wxString tmpTitleString;
1431 for ( iTitleGroup=0 ; iTitleGroup<maxContourGroup ; iTitleGroup++ )
1433 tmpIntB =_numberOfVariablesStatistics*iTitleGroup;
1434 tmpTitleString.Printf(_T("%d-Size Data"),iTitleGroup);
1435 interfMainPanel::getInstance()->setColLableInfoPanel(tmpIntB + 0, tmpTitleString);
1437 interfMainPanel::getInstance()->setColLableInfoPanel(tmpIntB + 0, tmpTitleString );
1438 interfMainPanel::getInstance()->setColLableInfoPanel( tmpIntB + 1, _T("Size Range") );
1439 interfMainPanel::getInstance()->setColLableInfoPanel( tmpIntB + 2, _T("Min") );
1440 interfMainPanel::getInstance()->setColLableInfoPanel( tmpIntB + 3, _T("Max") );
1441 interfMainPanel::getInstance()->setColLableInfoPanel( tmpIntB + 4, _T("Average") );
1442 interfMainPanel::getInstance()->setColLableInfoPanel( tmpIntB + 5, _T("St.Dev.") );
1443 interfMainPanel::getInstance()->setColLableInfoPanel( tmpIntB + 6, _T(" ") );
1446 interfMainPanel::getInstance()->setStringInfoPanel( _T("") );
1447 delete contourextractdata;
1450 void wxContourMainFrame::onSaveResults(std::string directory,std::string namefile, std::string filename, int typeContourGroup){
1451 SaveValuesXYZ( directory , namefile, typeContourGroup );
1452 SaveImageResult( directory , namefile, typeContourGroup);
1455 FILE *pFile=fopen(filename.c_str(),"w+");
1457 int sizeZ = _theViewPanel->GetImageDataSizeZ();
1460 int i,j,maxX,maxY=sizeZ;
1461 maxX= interfMainPanel::getInstance()->getNumberColsInformationPanel();//this->_grid->GetNumberCols();
1463 int iTitle,sizeTitle = (maxX / _numberOfVariablesStatistics);
1464 for ( iTitle=0; iTitle<sizeTitle ; iTitle++)
1466 fprintf(pFile,"-- \t %d-Size \t SizeRange \t Min \t Max \t Ave \t StDv \t" , iTitle,tmpString.c_str() );
1468 fprintf(pFile,"\n" );
1472 for ( j=0; j<maxY ; j++)
1474 fprintf(pFile,"%d\t" , j );
1475 for (i=0 ; i<maxX ; i++){
1476 tmpString = interfMainPanel::getInstance()->getCellValue(j, i);//_grid->GetCellValue( j , i );
1477 fprintf(pFile,"%s\t" , (const char *)(tmpString.mb_str()) );
1479 fprintf(pFile,"\n" );
1485 void wxContourMainFrame::SaveValuesXYZ(std::string directory,std::string namefile,int typeContourGroup)
1488 ContourExtractData *contourextractdata = new ContourExtractData();
1489 //int typeContourGroup = this->_radiolstboxContourGroup->GetSelection();
1490 contourextractdata ->SetTypeOperation( typeContourGroup % 3 );
1492 std::vector<manualContourModel*> lstManConMod;
1493 std::vector<manualContourModel*> lstManConModTmp;
1494 std::vector<manualContourModel*> lstManConModExp;
1495 std::vector<double> pLstValue;
1496 std::vector<double> pLstValuePosX;
1497 std::vector<double> pLstValuePosY;
1498 std::vector<double> pLstValuePosZ;
1500 std::vector<int> tempVector;
1501 _instantPanel->getInstant( tempVector );
1503 vtkImageData *imagedata = _theViewPanel->getSceneManager()->GetImageData();
1504 int sizeZ = _theViewPanel->getSceneManager()->GetImageDataSizeZ();
1506 int ii,sizeLstContourThings;
1513 minZ = 0;// _mbarrange->GetStart();
1514 maxZ = sizeZ;//_mbarrange->GetEnd();
1515 totalZ = maxZ-minZ+1;
1517 contourextractdata->SetImage( imagedata);
1520 for ( z=0 ; z<sizeZ ; z++)
1523 porcent = 100.0* (z-minZ)/totalZ;
1525 tmpString.Printf(_T("Saving Values"));
1526 tmpString.Printf(_T(" %d %c %d/%d %d"), (int)porcent , 37 , z-minZ+1, (int)totalZ ,z);
1527 interfMainPanel::getInstance()->setStringInfoPanel(tmpString);
1528 //_staticTextInformation->SetLabel(tmpString);
1531 //Extraction data from contours of each slice
1532 contourextractdata->SetZtoBeAnalys( z);
1535 Instant instant(&tempVector);
1536 std::vector<ContourThing**> lstContourThings = kernelManager->getOutlinesAtInstant(&instant);//this->_modelManager->getOutlinesAtInstant( &instant );
1537 sizeLstContourThings = lstContourThings.size();
1539 lstManConMod.clear();
1540 for (ii=0 ; ii<sizeLstContourThings ; ii++)
1542 ContourThing **contourthing = lstContourThings[ii];
1543 lstManConMod.push_back( (*contourthing)->getModel() );
1545 lstManConModExp = kernelManager->ExploseEachModel( lstManConMod );
1550 int iContourGroup,sizeContourGroup;
1551 if (typeContourGroup==3) // contour separete
1553 sizeContourGroup=lstManConModExp.size();
1554 } else { // contour AND OR XOR
1558 for( iContourGroup=0 ; iContourGroup<sizeContourGroup ; iContourGroup++ ){
1559 lstManConModTmp.clear();
1560 if (typeContourGroup==3) // contour separete
1562 lstManConModTmp.push_back( lstManConModExp[iContourGroup]);
1563 } else { // contour AND OR XOR
1564 lstManConModTmp = lstManConModExp;
1567 contourextractdata->SetLstManualContourModel( lstManConModTmp );
1570 pLstValuePosX.clear();
1571 pLstValuePosY.clear();
1572 pLstValuePosZ.clear();
1573 contourextractdata->GetValuesInsideCrown( &pLstValue,
1578 std::string temp = directory + "/" + namefile + "-slice";
1579 temp = temp + kernelManager->intToString(z) + "-cont" + kernelManager->intToString(iContourGroup);
1580 temp = temp + ".txt";
1582 // LG 14/01/09 : using crea
1583 wxString filename = crea::std2wx(temp);
1584 /*filename.Printf(_T("%s"),directory.c_str());
1585 filename.append(_T("\\"));
1586 filename.append(_T("%s"),namefile.c_str());
1587 filename.append(_T("-slice"));
1588 filename.append(_T("%d"),z);
1589 filename.append(_T("-cont"));
1590 filename.append(_T("%d"),iContourGroup);
1591 filename.append(_T(".txt"));*/
1592 // filename.Printf(temp.c_str());
1596 FILE *pFile=fopen((const char *)filename.mb_str(),"w+");
1597 fprintf(pFile,"value \t x \t y \t z\n" );
1598 int iLstValue,sizeLstValue=pLstValue.size();
1599 for (iLstValue=0 ; iLstValue<sizeLstValue ; iLstValue++ )
1601 fprintf(pFile,"%f\t %f\t %f\t %f\n", (float)pLstValue[iLstValue] , (float)pLstValuePosX[iLstValue], (float)pLstValuePosY[iLstValue], (float)z );
1604 } // for iContourGroup
1606 interfMainPanel::getInstance()->setStringInfoPanel(_T(""));
1607 //_staticTextInformation->SetLabel( _T("") );
1608 delete contourextractdata;
1611 void wxContourMainFrame::SaveImageResult(std::string directory,std::string namefile, int typeContourGroup)
1614 ContourExtractData *contourextractdata = new ContourExtractData( true );
1615 //int typeContourGroup = this->_radiolstboxContourGroup->GetSelection();
1616 if (typeContourGroup==3)
1620 contourextractdata ->SetTypeOperation( typeContourGroup % 3 );
1622 std::vector<manualContourModel*> lstManConMod;
1623 std::vector<manualContourModel*> lstManConModTmp;
1624 std::vector<manualContourModel*> lstManConModExp;
1626 std::vector<int> tempVector;
1627 _instantPanel->getInstant( tempVector );
1629 vtkImageData *imagedata = _theViewPanel->getImageData();
1630 int sizeZ = _theViewPanel->GetImageDataSizeZ();
1632 int ii,sizeLstContourThings;
1641 minZ = 0;// _mbarrange->GetStart();
1642 maxZ = sizeZ;//_mbarrange->GetEnd();
1643 totalZ = maxZ-minZ+1;
1645 contourextractdata->SetImage( imagedata);
1648 for ( z=0 ; z<sizeZ ; z++)
1651 porcent = 100.0* (z-minZ)/totalZ;
1652 tmpString.Printf(_T("Saving Values"));
1653 tmpString.Printf(_T("%d %c %d/%d %d"), (int)porcent , 37 , z-minZ+1, (int)totalZ ,z);
1654 interfMainPanel::getInstance()->setStringInfoPanel(tmpString);
1656 //Extraction data from contours of each slice
1657 contourextractdata->SetZtoBeAnalys( z);
1660 Instant instant(&tempVector);
1661 std::vector<ContourThing**> lstContourThings = kernelManager->getOutlinesAtInstant( &instant );
1662 sizeLstContourThings = lstContourThings.size();
1664 lstManConMod.clear();
1665 for (ii=0 ; ii<sizeLstContourThings ; ii++)
1667 ContourThing **contourthing = lstContourThings[ii];
1668 lstManConMod.push_back( (*contourthing)->getModel() );
1670 lstManConModExp = kernelManager->ExploseEachModel( lstManConMod );
1673 int iContourGroup,sizeContourGroup;
1674 if (typeContourGroup==3) // contour separete
1676 sizeContourGroup=lstManConModExp.size();
1677 } else { // contour AND OR XOR
1681 for( iContourGroup=0 ; iContourGroup<sizeContourGroup ; iContourGroup++ ){
1682 lstManConModTmp.clear();
1683 if (typeContourGroup==3) // contour separete
1685 lstManConModTmp.push_back( lstManConModExp[iContourGroup]);
1686 } else { // contour AND OR XOR
1687 lstManConModTmp = lstManConModExp;
1690 contourextractdata->SetLstManualContourModel( lstManConModTmp );
1693 // for (ii=0 ; ii<sizeLstContourThings ; ii++)
1695 // ContourThing **contourthing = lstContourThings[ii];
1696 // lstManConMod.push_back( (*contourthing)->getModel() );
1698 // contourextractdata->SetLstManualContourModel( lstManConMod );
1700 contourextractdata->CalculateImageResult(); // with actual Z
1702 } // for iContourGroup
1705 std::string temp = directory + "/" + namefile + "-Value.mhd";
1707 wxString filename = crea::std2wx(temp);
1709 // filename.Printf(_T(temp.c_str()));
1710 //filename.Printf(_T("%s\\%s-Value.mhd",directory.c_str(),namefile.c_str(),z);
1711 /*filename.Printf(_T("%s"),directory.c_str());
1712 filename.append(_T("\\"));
1713 filename.append(_T("%s"),namefile.c_str());
1714 filename.append(_T("-Value.mhd"));*/
1717 vtkMetaImageWriter *writerValueImage = vtkMetaImageWriter::New( );
1718 writerValueImage->SetInput( contourextractdata->GetVtkImageValueResult() );
1719 writerValueImage->SetFileName( (const char *)filename.mb_str() );
1720 writerValueImage->SetFileDimensionality( 3 );
1721 writerValueImage->Write( );
1724 // filename.Printf("%s\\%s-Mask.mhd",directory.c_str(),namefile.c_str(),z);
1725 temp = directory + "/" + namefile + "-Mask.mhd";
1727 // LG 14/01/09 : using crea
1728 filename = crea::std2wx(temp);
1729 // filename.Printf(_T(temp.c_str()));
1731 /*filename.Printf(_T("%s"),directory.c_str());
1732 filename.append(_T("\\"));
1733 filename.append(_T("%s"),namefile.c_str());
1734 filename.append(_T("-Mask.mhd"));*/
1736 vtkMetaImageWriter *writerMaskImage = vtkMetaImageWriter::New( );
1737 writerMaskImage->SetInput( contourextractdata->GetVtkImageMaskResult() );
1738 writerMaskImage->SetFileName( (const char *)filename.mb_str() );
1739 writerMaskImage->SetFileDimensionality( 3 );
1740 writerMaskImage->Write( );
1742 interfMainPanel::getInstance()->setStringInfoPanel( _T("") );
1743 delete contourextractdata;
1746 void wxContourMainFrame::onChangeInstantInstantPanel(std::string name,int value, int minshow, int maxshow){
1747 if( name.compare( _theViewPanel->getVerticalConceptName() ) == 0){
1748 _theViewPanel->setActualVertical( value);
1750 else if( name.compare( _theViewPanel->getHorizontalConceptName() ) == 0|| _instantPanel->getIfConceptCheckedAt( name, 0 ) ) {
1751 _theViewPanel->setHorizontalConcept( name, minshow, maxshow, minshow, maxshow, value);
1757 void wxContourMainFrame::onSnakePressed(){
1758 std::vector<double> vecX;
1759 std::vector<double> vecY;
1760 std::vector<double> vecZ;
1761 _theViewPanel->GetPointsOfActualContour( &vecX , &vecY , &vecZ );
1763 if (vecX.size()!=0){
1764 std::vector<int> tempVector;
1765 _instantPanel->getInstant( tempVector );
1766 int i,size=vecZ.size();
1767 int actualSlice = tempVector[1];
1768 for ( i=0 ; i<size ; i++ )
1770 vecZ[i] = actualSlice;
1773 wxDialog* dialog = new wxDialog(this, -1, wxString(_T("Snake")));
1774 wxPanel* panel = new wxPanel(dialog,-1);
1775 wxStaticText* sttext = new wxStaticText(panel, -1, wxString(_T("Panel para snake")));
1776 dialog->ShowModal();
1781 void wxContourMainFrame::saveFileWithContoursAutomatique(){
1782 std::string filename = kernelManager->getCurrentFileName();
1783 if(filename.compare("")!=0){
1784 saveFileWithContours(filename);