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"
23 //----------------------------------------------------------------------------------------------------------------
24 // Class implementation
25 //----------------------------------------------------------------------------------------------------------------
26 /** @file wxContourMainFrame.cxx */
28 //------------------------------------------------------------------------------------------------------------
29 // Constructors & Destructors
30 //------------------------------------------------------------------------------------------------------------
32 wxContourMainFrame* wxContourMainFrame:: instance = NULL;
33 char wxContourMainFrame::COPY = 'C';
35 wxContourMainFrame :: wxContourMainFrame(wxWindow* parent, wxWindowID id,const wxString& title,const wxPoint& pos,const wxSize& size,long style)
36 //: wxPanel(parent, id, title, pos, size, style)
37 //: wxWindow(parent, id, pos, size, style)
38 : wxPanel(parent, id, pos, size, style)
40 m_mgr.SetManagedWindow(this);
41 _creatingContoursActive = false;
43 // _modelManager = NULL;
47 _drawToolsPanel = NULL;
48 _operationsToolsPanel = NULL;
49 _autoFormsPanel = NULL;
50 _standardToolsPanel = NULL;
51 _editionToolsPanel = NULL;
52 _listViewPanel = NULL;
54 //_actualInstant = NULL;
55 _numberOfVariablesStatistics = 6+1;
57 // set up default notebook style
58 m_notebook_style =wxAUI_NB_TAB_SPLIT | wxAUI_NB_TAB_EXTERNAL_MOVE | wxNO_BORDER;
60 //wxContour_ActionCommandsID a;
64 wxContourMainFrame :: wxContourMainFrame(wxWindow* parent, wxWindowID id,const wxString& title,const wxPoint& pos,const wxSize& size,std::vector<vtkImageData*> images, long style)
65 : wxPanel(parent, id, pos, size, style)
67 m_mgr.SetManagedWindow(this);
68 _creatingContoursActive = false;
70 // _modelManager = NULL;
74 _drawToolsPanel = NULL;
75 _operationsToolsPanel = NULL;
76 _autoFormsPanel = NULL;
77 _standardToolsPanel = NULL;
78 _editionToolsPanel = NULL;
79 _listViewPanel = NULL;
81 //_actualInstant = NULL;
83 // set up default notebook style
84 m_notebook_style =wxAUI_NB_TAB_SPLIT | wxAUI_NB_TAB_EXTERNAL_MOVE | wxNO_BORDER;
86 //wxContour_ActionCommandsID a;
87 _numberOfVariablesStatistics = 6+1;
90 _performingOperation = new PerformingOperation();
96 kernelManager = new KernelManagerContour(images);
97 //kernelManager->setVectImages(images);
98 //kernelManager->initializeEnvironment();
100 //vtkImageData* selectedimage = kernelManager->getVectImages()[0];
102 //-------------------------------------------------------------
104 /*frame = new wxContourMainFrame(_builder->getImSourceEnv(), _builder->getImSectionEnv(), _builder->getAxesEnv(), _builder->getContourEnv(),NULL, wxID_ANY, wxT("ROI Application Sample"), wxPoint(50,50), wxSize(800, 600));
107 //Creating the evtHandler of the panels
108 //wxContourEventHandler * eventHandler = new wxContourEventHandler();
110 //Creating the window that will show the panels
112 //Getting the parent for the panels ( using aui )
113 wxAuiNotebook * notebook = this->createNotebook();
116 //wxInstantChooserPanel * instantPanel = new wxInstantChooserPanel( notebook, "Instant Chooser", true);
118 std::vector<std::string> conceptNameVect;
119 std::vector<int> conceptSizeVect;
123 _instantPanel = new wxInstantChooserPanel( notebook, "Instant Chooser", true, false, "c" );
124 _theViewPanel = new wxContourViewPanel( kernelManager->getSourceImage(), notebook );
128 kernelManager->getConceptsInformation(conceptNameVect, conceptSizeVect);
129 _instantPanel->addConcepts(conceptNameVect, conceptSizeVect);
132 double val = _theViewPanel->getCurrentDeep();
133 _instantPanel->setConceptValue( "Axe Depth", (int)val );
134 //JCP _instantPanel->setConceptValue("time", num de imagenes);
135 ConceptDataWrap * data = _instantPanel->getConceptDataOf( "Axe Depth" );
136 //*******************changeInstant();
137 _theViewPanel->setVerticalConcept( "Axe Depth", data->getMinValue(), data->getMaxValue(), data->getMinShowedValue(), data->getMaxShowedValue(), data->getActualValue() );
139 //eventHandler->setModelManager( kernelManager->getOutlineModelManager() );
140 //eventHandler->setViewPanel( _theViewPanel );
141 //_theViewPanel->initializeScenceManager();
142 //eventHandler->setInstantChooserPanel( _instantPanel );
144 //bool successConfiuration = eventHandler->configureEventsHandling();
146 //successConfiuration &= this->configurePanels( notebook );
147 this->configurePanels( notebook );
149 interfMainPanel* pannew = interfMainPanel::getInstance(parent);//, eventHandler);
157 wxContourMainFrame* wxContourMainFrame :: getInstance(wxWindow* parent, wxWindowID id,const wxString& title,const wxPoint& pos,const wxSize& size,std::vector<vtkImageData*> images, long style ){
158 if(instance == NULL){
159 instance = new wxContourMainFrame(parent, id, title, pos, size, images, style);
164 std::vector<vtkImageData*> wxContourMainFrame ::getVectImages(){
165 return kernelManager->getVectImages();
167 wxContourMainFrame* wxContourMainFrame :: getInstance(){
172 wxContourMainFrame :: ~wxContourMainFrame()
175 //El problema al cerrar la aplicacion puede estar asociado
176 //a que wxAUINotebook esta en la aplicacion
177 //principal (wxContourGUIExample)tambien
178 //EED???? delete _theViewPanel;
179 //EED???? delete _instantPanel;
180 //EED???? delete _buttonsBar;
181 //EED???? delete _actualInstant;
182 //EED???? delete _sceneManager;
186 //------------------------------------------------------------------------------------------------------------
187 // Creational and initialization methods using WxAui
188 //------------------------------------------------------------------------------------------------------------
190 wxAuiNotebook * wxContourMainFrame :: createNotebook()
192 wxSize client_size = GetClientSize();
193 wxAuiNotebook* noteBook = new wxAuiNotebook(this, -1, wxPoint(client_size.x, client_size.y), wxSize(430,200), m_notebook_style);
194 wxBitmap page_bmp = wxArtProvider::GetBitmap(wxART_NORMAL_FILE, wxART_OTHER, wxSize(16,16));
199 //------------------------------------------------------------------------------------------------------------
200 // Creational and initialization methods
201 //------------------------------------------------------------------------------------------------------------
202 bool wxContourMainFrame :: configurePanels(wxAuiNotebook* theNoteBook)
204 bool configured = _theViewPanel!=NULL;
206 configured &= _theViewPanel!=NULL;
207 if( _theViewPanel!=NULL )
209 theNoteBook->AddPage( _theViewPanel, wxT(" View ") );
216 theNoteBook->AddPage( _instantPanel, wxT("Instant Page") );
220 m_mgr.AddPane(theNoteBook, wxAuiPaneInfo().Name(wxT("notebook_content")).CenterPane().PaneBorder(false));
222 configured &= _buttonsBar!=NULL;
223 if( _buttonsBar!=NULL )
225 m_mgr.AddPane(_buttonsBar, wxAuiPaneInfo().
226 Name(wxT("TB")).Caption(wxT("Buttons Bar")).
228 LeftDockable( ).RightDockable( false ).CloseButton(false));
233 SetMinSize(wxSize(300,300));
238 void wxContourMainFrame :: setNotebook( wxAuiNotebook * noteBook )
243 //------------------------------------------------------------------------------------------------------------
244 // Attributes getters and setters
245 //------------------------------------------------------------------------------------------------------------
249 void wxContourMainFrame :: setInstantChooserPanel( wxInstantChooserPanel * theInstantChooserPanel )
251 _instantPanel = theInstantChooserPanel;
254 void wxContourMainFrame :: setButtonsBar( wxContour_ButtonsBar * theButtonsBar )
256 _buttonsBar = theButtonsBar;
259 void wxContourMainFrame :: setGrid( wxContour_Grid * theGridPanel )
261 _gridPanel = theGridPanel;
264 void wxContourMainFrame :: setDrawToolsPanel( wxContour_DrawToolsPanel * theDrawToolsPanel )
266 _drawToolsPanel = theDrawToolsPanel;
269 void wxContourMainFrame :: setOperationsToolsPanel( wxContour_OperationsToolsPanel * theOperationsToolsPanel )
271 _operationsToolsPanel = theOperationsToolsPanel;
274 void wxContourMainFrame :: setAutomaticFormsPanel( wxContour_AutomaticFormsToolsPanel * theAutoFormsPanel )
276 _autoFormsPanel = theAutoFormsPanel;
279 void wxContourMainFrame :: setStandardToolsPanel( wxContour_StandardToolsPanel * theStandardToolsPanel )
281 _standardToolsPanel= theStandardToolsPanel;
284 void wxContourMainFrame :: setEditionToolsPanel( wxContour_EdtionToolsPanel * theEditionToolsPanel )
286 _editionToolsPanel = theEditionToolsPanel;
289 void wxContourMainFrame :: setListViewPanel( wxContour_ListViewPanel * theListViewPanel )
291 _listViewPanel = theListViewPanel;
296 void wxContourMainFrame::onCreateContourSpline( ){
298 //JCP 20-10-08 Undo redo implementation
300 //JCP 20-10-08 Undo redo implementation
304 void wxContourMainFrame::onCreateContourRectangle( ){
305 //JCP 20-10-08 Undo redo implementation
307 //JCP 20-10-08 Undo redo implementation
310 void wxContourMainFrame::onCreateContourCircle( ){
311 //JCP 20-10-08 Undo redo implementation
313 //JCP 20-10-08 Undo redo implementation
316 //------------------------------------------------------------------------------------------------------------
318 void wxContourMainFrame :: onCreateContourBullEye(wxPanel* panel )
320 //Creating the manualContourModel and including in the model
321 manualContourModel * manModelContour = factoryManualContourModel(panel );
323 std::vector<int> instantVector;
324 _instantPanel->getInstant( instantVector );
325 std::string theName = kernelManager->createOutline(manModelContour, instantVector);
327 /*std::vector<int> instantVector;
328 _instantPanel->getInstant( instantVector );
330 theName= _modelManager->createOutline( manModelContour, instantVector );*/
331 bool addedModel = theName.compare("") != 0;//??
335 double spc[3];//Si no hay imagen pero hay contornos que spacing se pone por default
336 _theViewPanel->getSpacing(spc);
337 //Adding the manualContourControler to interface objects structure
338 //Adding the manualViewContour to interface objects structure
339 //_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.
340 _theViewPanel->getSceneManager()->configureViewControlTo( theName, manModelContour,spc , 4) ;
343 void wxContourMainFrame :: createContour( int typeContour )
345 //Creating the manualContourModel and including in the model
346 manualContourModel * manModelContour = kernelManager->factoryManualContourModel(typeContour);
349 std::vector<int> instantVector;
350 _instantPanel->getInstant( instantVector );
351 std::string theName = kernelManager->createOutline(manModelContour, instantVector);
353 /*std::vector<int> instantVector;
354 _instantPanel->getInstant( instantVector );
356 theName= _modelManager->createOutline( manModelContour, instantVector );*/
357 bool addedModel = theName.compare("") != 0;//??
360 double spc[3];//Si no hay imagen pero hay contornos que spacing se pone por default
361 _theViewPanel->getSpacing(spc);
362 //Adding the manualContourControler to interface objects structure
363 //Adding the manualViewContour to interface objects structure
364 //_sceneManager->setControlActiveStateOfALL( false );//This call is being done here because if the ROI is created underneath the previously created ROIS will still be active.
365 _theViewPanel->getSceneManager()->configureViewControlTo( theName, manModelContour,spc , typeContour) ;
369 manualContourModel * wxContourMainFrame::factoryManualContourModel(wxPanel* panel){
371 manualContourModelBullEye *manModelContourBullEye = new manualContourModelBullEye();
372 manualContourModel *manModelContour=NULL;
373 manModelContour = manModelContourBullEye;
375 int iCrown,sizeCrowns,iSector,sizeSectors;
376 double radioA,radioB,ang,angDelta ;
377 sizeCrowns = ((PanelBullEyeOptions*)panel)->GetNumberOfCrowns();
378 for ( iCrown=0 ; iCrown<sizeCrowns ; iCrown++ )
380 sizeSectors = ((PanelBullEyeOptions*)panel)->GetNumberOfSections(iCrown);
381 radioB = ((PanelBullEyeOptions*)panel)->GetRadioOfCrown(iCrown);
382 if (iCrown==sizeCrowns-1)
386 radioA = ((PanelBullEyeOptions*)panel)->GetRadioOfCrown(iCrown+1);
390 for ( iSector=0 ; iSector<sizeSectors ; iSector++ )
392 ang = ((PanelBullEyeOptions*)panel)->GetAngOfCrownSection(iCrown,iSector);
393 angDelta= ((PanelBullEyeOptions*)panel)->GetAngDeltaOfCrownSection(iCrown);
394 manModelContourBullEye->AddSector(radioA,radioB,ang,angDelta);
397 } // if _panelBullEyeOptions
399 return manModelContour;
401 void wxContourMainFrame :: saveState(){
403 std::string temp = kernelManager->saveState();
404 saveFileWithContours(temp);
407 void wxContourMainFrame::onDeleteContour(){
408 //JCP 20-10-08 Undo redo implementation
410 //JCP 20-10-08 Undo redo implementation
412 std::vector<std::string> lstKeyNameToBeErase;
413 lstKeyNameToBeErase = _theViewPanel->getSceneManager()->getSelectedObjects();
414 deleteContours( lstKeyNameToBeErase );
416 int i,size=_sceneManager->getSelectedObjects().size();
419 std::string keyName = _sceneManager->getSelectedObjects()[i];
420 int ispartofstaticlist = this->_modelManager->IsPartOfStaticList( keyName );
421 if ( ispartofstaticlist>=0 )
423 std::vector<int> tempVector;
424 _instantPanel->getInstant( tempVector );
425 Instant instant(&tempVector);
426 this->_modelManager->ChangeContourOfList(keyName, &instant);
430 std::vector<std::string> lstKeyName;
431 std::vector<std::string> lstKeyNameActualSlice;
432 std::vector<std::string> lstKeyNameToBeErase;
434 lstKeyNameToBeErase = _sceneManager->getSelectedObjects();
435 lstKeyNameActualSlice = _sceneManager->GetlstContoursNameActualSlice();
436 int k,kSize=lstKeyNameToBeErase.size();
437 int j,jSize=lstKeyNameActualSlice.size();
439 for (k=0;k<kSize; k++)
442 for (j=0;j<jSize; j++)
444 if (lstKeyNameToBeErase[k]==lstKeyNameActualSlice[j])
451 lstKeyName.push_back( lstKeyNameToBeErase[k] );
455 deleteContours( lstKeyName );
459 void wxContourMainFrame :: deleteContours( std::vector<std::string> keyNamesVector )
461 int i,size=keyNamesVector.size();
464 deleteContour( keyNamesVector[i] );
468 void wxContourMainFrame :: deleteContour( std::string theKeyName ){
469 /*manualContourModel * cModel;
470 manualViewBaseContour * cViewer;
471 manualContourBaseControler * cControler;
473 ContourWrap_ViewControl *conwrapviewControl = _theViewPanel->getSceneManager()->getContourWrap_ViewControlOf( theKeyName );
474 cControler = conwrapviewControl->getControler();*/
477 bool isedit = _theViewPanel->isEditableCControler(theKeyName);
478 bool ispartofstaticlst = kernelManager->IsPartOfStaticList(theKeyName);
480 if (isedit && ispartofstaticlst)
482 _theViewPanel->removeFromScene(theKeyName);
484 kernelManager->deleteCModel(theKeyName);
485 //_theViewPanel->getSceneManager()->removeFromScene( theKeyName );
486 //cViewer = conwrapviewControl->getViewer();
487 //_theViewPanel->getSceneManager()->removeWrap( theKeyName );
488 //cControler* conwrapviewControl->getControler();
490 //FILE *ff = fopen("c:/temp/wxVtkBaseView_SceneManagerStadistics.txt","a+");
491 //fprintf(ff,"EED wxContourEventHandler::deleteContours() \n" );
492 //fprintf(ff," %s %p\n",keyNamesVector[i].c_str(), cControler );
496 // delete cControler;
501 void wxContourMainFrame::onDeleteContoursActSlice(){
502 //JCP 20-10-08 Undo redo implementation
504 //JCP 20-10-08 Undo redo implementation
505 deleteContours( (std::vector<std::string>)_theViewPanel->getSceneManager()->GetlstContoursNameActualSlice() );
507 void wxContourMainFrame::onDeleteAllContours(){
508 //JCP 20-10-08 Undo redo implementation
512 void wxContourMainFrame::deleteAllContours(){
513 //JCP 20-10-08 Undo redo implementation
516 std::vector<int> tempVector;
517 _instantPanel->getInstant( tempVector );
519 //JCP --08-09-2008 When using a diferent interface the _mbarrangeDeleteAll might not be initialize
520 // the values in GetStart and GetEnd will then not be initialize also.
521 // We use instead the values given when initializing the _deletepanel.
523 //int minZ = _mbarrangeDeleteAll->GetStart();
524 //int maxZ = _mbarrangeDeleteAll->GetEnd();
528 maxZ = _theViewPanel->getSceneManager()->GetImageDataSizeZ();
532 _theViewPanel->getSceneManager()->removeSceneContours( );
533 _theViewPanel->getSceneManager()->removeAllOutlines();
534 kernelManager->removeAllOutlines();
537 if ( (minZ==0) && (maxZ==_mbarrangeDeleteAll->GetMax() ))
539 _theViewPanel->getSceneManager()->removeSceneContours( );
540 _modelManager->removeAllOutlines();
541 _theViewPanel->getSceneManager()->removeAllOutlines();
544 for ( z=minZ ; z<=maxZ ; z++)
547 Instant instant(&tempVector);
548 std::vector<ContourThing**> lstContourThings = this->_modelManager->getOutlinesAtInstant( &instant );
550 sizeLstContourThings = lstContourThings.size();
551 for (ii=0 ; ii<sizeLstContourThings ; ii++)
553 ContourThing **contourthing = lstContourThings[ii];
554 deleteContour( (*contourthing)->getName() );
561 void wxContourMainFrame::setConceptValue( std::string name, int value ){
562 _instantPanel->setConceptValue(name, value);
565 ConceptDataWrap* wxContourMainFrame::getLastConceptData(){
566 return _instantPanel->getLastConceptData();
568 bool wxContourMainFrame::getIfConceptCheckedAt( std::string name, int pos ){
569 return _instantPanel->getIfConceptCheckedAt( name, pos );
572 void wxContourMainFrame::changeInstant(){
573 std::vector<int> instantVect;
574 _instantPanel->getInstant( instantVect );
575 // Instant * theInstant = new Instant ( &instantVect );
577 //Setting the actual instant
578 //_actualInstant = theInstant;
580 kernelManager->setInstant(instantVect);
581 //_modelManager->setInstant( _actualInstant );
583 updateInstantOutlines();
584 updateInstantImageData();
589 void wxContourMainFrame :: updateInstantOutlines(){
591 _theViewPanel->removeSceneContours();
592 _theViewPanel->addNameWrapperToScene();
594 //for( int i=0; i<size; i++)
596 // _theViewPanel->getSceneManager()->addToScene(namesWrapping[i]->getKeyName(), true, true, true, false, false );
600 int wxContourMainFrame::getNamesWrappingSize(){
601 return kernelManager->getNamesWrappingSize();
603 std::string wxContourMainFrame::getNameWrapping(int i){
604 return kernelManager->getNameWrapping(i);
607 void wxContourMainFrame::updateInstantImageData(){
608 std::vector<int> inst;
609 _instantPanel->getInstant(inst);
611 vtkImageData* img = kernelManager->getImageAtInstant(inst);
613 _theViewPanel->changeImage(img);
616 void wxContourMainFrame::updateInstantAxes(){
619 void wxContourMainFrame::onChangeDeep(int val){
620 _instantPanel->setConceptValue( "Axe Depth", (int)val );
625 void wxContourMainFrame::onCopy(){
626 std::vector<std::string> currentSelection = _theViewPanel->getSelectedObjects();
628 std::vector<int> tempVector;
629 _instantPanel->getInstant( tempVector );
630 _performingOperation->reset();
631 _performingOperation->setStartCommand( COPY );
632 _performingOperation->setStartOperationInstantVector( tempVector );
633 _performingOperation->setKeyNamesOperationElems( currentSelection );
635 void wxContourMainFrame::onPaste(){
638 char theStartCommand = _performingOperation->getStartCommand();
639 if ( theStartCommand == COPY )
641 //JCP 20-10-08 Undo redo implementation
643 //JCP 20-10-08 Undo redo implementation
644 std::vector<int> tempVector;
645 _instantPanel->getInstant( tempVector );
646 _performingOperation->setEndOperationInstantVector ( tempVector );
647 std::vector<std::string> elems = _performingOperation->getKeyNamesOperationElems();
648 int i,size = elems.size();
649 for( i=0; i<size; i++ )
651 createCopyContourOf( elems[i], tempVector, i>0 );
655 void wxContourMainFrame::onUndo(){
656 std::string filename;
657 if(kernelManager->onUndoSaveFile(filename)){
658 saveFileWithContours(filename);
660 if(kernelManager->onUndo(filename)){
664 void wxContourMainFrame::onRedo(){
665 std::string filename;
666 if(kernelManager->onRedo(filename)){
671 void wxContourMainFrame :: createCopyContourOf ( std::string anExistingKName, std::vector<int> &instantNoTouchData, bool append ){
672 std::string cloneName = kernelManager->createCopyContourOf( anExistingKName, instantNoTouchData );
673 manualContourModel * manualModel = kernelManager->getOutlineByKeyName(cloneName);//_modelManager->getOutlineByKeyName( cloneName )->getModel();
674 _theViewPanel->getSceneManager()->createCopyContourOf( anExistingKName, cloneName, manualModel , append );
677 void wxContourMainFrame ::loadState(std::string filename){
679 FILE *pFile=fopen(filename.c_str(),"r+");
681 fscanf(pFile,"%s",tmp); // --CreaContour--
683 fscanf(pFile,"%s",tmp); // Version
684 fscanf(pFile,"%s",tmp); // 1.0.1
685 std::string version(tmp);
689 openContours(pFile,false);
690 if (version!="1.0.0"){
691 openContours(pFile,true);
696 //_theViewPanel->getSceneManager()->removeSceneContours();
701 void wxContourMainFrame::onLoad(){
703 wxFileDialog dialog(NULL, _T("Choose a file"), _T(""), _T(""), _T("*.roi"), wxOPEN );
704 if (dialog.ShowModal() == wxID_OK)
706 std::string fileNameContourROI = (const char *)(dialog.GetPath().mb_str());
707 FILE *pFile=fopen(fileNameContourROI.c_str(),"r+");
709 fscanf(pFile,"%s",tmp); // --CreaContour--
711 fscanf(pFile,"%s",tmp); // Version
712 fscanf(pFile,"%s",tmp); // 1.0.1
713 std::string version(tmp);
715 openContours(pFile,false);
716 if (version!="1.0.0"){
717 openContours(pFile,true);
719 // _theViewPanel->getSceneManager()->openFileWithContours(ff);
723 _theViewPanel->getSceneManager()->removeSceneContours();
726 void wxContourMainFrame::onSave(){
727 wxFileDialog dialog(NULL, _T("Choose a file"), _T(""), _T(""), _T("*.roi"), wxSAVE );
728 if (dialog.ShowModal() == wxID_OK)
730 std::string fileNameContourROI = (const char *)(dialog.GetPath().mb_str());
731 saveFileWithContours( fileNameContourROI );
734 void wxContourMainFrame::saveFileWithContours( std::string filename ){
736 FILE *pFile=fopen(filename.c_str(),"w+");
737 std::vector< std::string > lstNameThings;
738 int i,sizeLstNameThings;
740 fprintf(pFile,"--CreaContour--\n");
741 fprintf(pFile,"Version %s\n", "1.0.1" );
744 lstNameThings = kernelManager->GetLstNameThings();
745 sizeLstNameThings = lstNameThings.size();
746 fprintf(pFile,"NumberOfContours %d\n", sizeLstNameThings );
747 for (i=0 ; i<sizeLstNameThings ; i++)
749 kernelManager->SaveThingName( pFile, lstNameThings[i] );
750 _theViewPanel->getSceneManager()->SaveThingName( pFile, lstNameThings[i] );
753 //-- Contours Statics
754 lstNameThings = kernelManager->GetLstNameThingsStatic();
755 sizeLstNameThings = lstNameThings.size();
756 fprintf(pFile,"NumberOfContoursStatic %d\n", sizeLstNameThings );
757 for (i=0 ; i<sizeLstNameThings ; i++)
759 kernelManager->SaveThingName( pFile, lstNameThings[i] );
760 _theViewPanel->getSceneManager()->SaveThingName( pFile, lstNameThings[i] );
765 void wxContourMainFrame::openContours( FILE *pFile, bool staticContour ){
767 fscanf(pFile,"%s",tmp); // NumberOfContours
768 fscanf(pFile,"%s",tmp); // ##
769 int numberOfContours = atoi(tmp);
771 std::vector<int> instantVector;
772 int typeContourModel;
773 manualContourModel *manModelContour;
777 for (i=0;i<numberOfContours;i++)
779 instantVector.clear();
780 fscanf(pFile,"%s",tmp); // Instant
782 fscanf(pFile,"%s",tmp); // 1
783 instantVector.push_back( atoi(tmp) );
784 fscanf(pFile,"%s",tmp); // 2
785 instantVector.push_back( atoi(tmp) );
786 fscanf(pFile,"%s",tmp); // 3
787 instantVector.push_back( atoi(tmp) );
788 fscanf(pFile,"%s",tmp); // 4
789 instantVector.push_back( atoi(tmp) );
790 fscanf(pFile,"%s",tmp); // 5
791 instantVector.push_back( atoi(tmp) );
792 fscanf(pFile,"%s",tmp); // 6
793 instantVector.push_back( atoi(tmp) );
796 fscanf(pFile,"%s",tmp); // TypeContourModel
797 fscanf(pFile,"%s",tmp); // ##
798 typeContourModel = atoi(tmp);
800 manModelContour = kernelManager->factoryManualContourModel(typeContourModel);
801 manModelContour->Open(pFile);
803 fscanf(pFile,"%s",tmp); // TypeView
804 fscanf(pFile,"%s",tmp); // ##
805 typeView = atoi(tmp);
814 theName = kernelManager->createOutline( manModelContour, instantVector );
815 bool addedModel = theName.compare("") != 0;
818 double spc[3];//Si no hay imagen pero hay contornos que spacing se pone por default
819 _theViewPanel->getSpacing(spc);
820 //Adding the manualContourControler to interface objects structure
821 //Adding the manualViewContour to interface objects structure
822 //_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.
823 _theViewPanel->getSceneManager()->configureViewControlTo( theName, manModelContour,spc , typeView) ;
826 if (staticContour==true)
828 Instant instant(&instantVector);
829 kernelManager->changeContourOfManager( theName , &instant );
832 }// for numberOfContours
836 void wxContourMainFrame::RefreshInterface(){
838 _theViewPanel->RefreshInterface();
839 //wxVtk2DBaseView *wxvtk2dbaseview = (wxVtk2DBaseView*)this->_theViewPanel->getWxVtkBaseView();
840 //wxvtk2dbaseview->Refresh();
843 vtkImageData* wxContourMainFrame::getImageData(){
844 return _theViewPanel->getImageData();
847 void wxContourMainFrame::onSegmentationOneSlice(int isovalue,int sampling,int method){
849 //JCP 20-10-08 Undo redo implementation
851 //JCP 20-10-08 Undo redo implementation
854 int x = _theViewPanel->GetX();
855 int y = _theViewPanel->GetY();
856 int z = _theViewPanel->GetZ();
857 SegmentationOneSlice( x,y,z,isovalue, sampling, method );
861 void wxContourMainFrame::SegmentationOneSlice( int x, int y, int z, int isovalue, int sampling, int method )
863 int typeofcontour = 1;
864 //--Extracting Contour
865 //vtkImageData *imagedata = _theViewPanel->getSceneManager()->GetImageData();
866 vtkImageData *imagedata = getImageData();
867 // double *range = imagedata->GetScalarRange();
870 vtkImageReslice *imageReslice = vtkImageReslice::New();
873 // imagedata->GetSpacing(spc);
878 imageReslice->SetInput( imagedata );
879 imageReslice->SetInformationInput(imagedata);
880 imageReslice->SetResliceAxesDirectionCosines(1,0,0, 0,1,0 ,0,0,1);
881 imageReslice->SetResliceAxesOrigin(0,0,z);
882 imageReslice->SetOutputDimensionality(2);
883 imageReslice->SetInterpolationModeToLinear();
885 imagedata = imageReslice->GetOutput();
887 imagedata->UpdateInformation();
889 vtkContourFilter* cntVTK = vtkContourFilter::New( );
890 cntVTK->SetInput( imagedata );
892 cntVTK->SetNumberOfContours( 1 );
893 //cntVTK->SetValue( 0, vmin );
894 // cntVTK->SetValue( 0, (range[1]*thr/100) );
895 cntVTK->SetValue( 1, isovalue );
896 // cntVTK->SetValue( 1, vmax );
898 cntVTK->UpdateInformation();
900 vtkCleanPolyData* cpd = vtkCleanPolyData::New( );
901 cpd->SetInput( cntVTK->GetOutput( ) );
902 cpd->ConvertLinesToPointsOff( );
904 cpd->UpdateInformation();
906 vtkPolyDataConnectivityFilter* conn = vtkPolyDataConnectivityFilter::New( );
907 conn->SetExtractionModeToClosestPointRegion( );
908 //conn->SetMaxRecursionDepth( 3000 );
910 conn->SetInput( cpd->GetOutput( ) );
912 conn->SetClosestPoint( x, y, 0 );
914 conn->UpdateInformation();
916 vtkCleanPolyData* cpd2 = vtkCleanPolyData::New( );
917 cpd2->SetInput( conn->GetOutput( ) );
919 cpd2->UpdateInformation();
921 vtkStripper* vtkstripper = vtkStripper::New( );
922 vtkstripper->SetInput( cpd2->GetOutput() );
923 vtkstripper->Update();
924 vtkstripper->UpdateInformation();
927 vtkPolyData* polyDataResult = vtkstripper->GetOutput();
929 polyDataResult->Update( );
930 polyDataResult->UpdateInformation();
934 myfile.open ("c:/temp/example.txt");
936 polyDataResult->Print(myfile);
937 myfile << "-------------------------------------\n";
938 polyDataResult->GetLines()->Print(myfile);
948 //--Calculating control points
950 std::vector<double> vecX;
951 std::vector<double> vecY;
952 std::vector<double> vecZ;
954 std::vector<double> vecCtrlPointX;
955 std::vector<double> vecCtrlPointY;
956 std::vector<double> vecCtrlPointZ;
960 int ii,size=polyDataResult->GetNumberOfPoints();
962 for (ii=1;ii<=size;ii++)
964 id = polyDataResult->GetLines()->GetData()->GetValue(ii);
965 p = polyDataResult->GetPoint(id);
968 vecX.push_back( p[0] );
969 vecY.push_back( p[1] );
970 vecZ.push_back( -900 );
971 // vecZ.push_back( p[2] );
975 ExtractControlPoints2D *extractcontrolpoints2d = new ExtractControlPoints2D();
976 extractcontrolpoints2d->SetContour( &vecX , &vecY , &vecZ );
979 /*if (methodRadiobox->GetSelection()==0){
980 extractcontrolpoints2d->GetInitialControlPoints( &vecCtrlPointX , &vecCtrlPointY , &vecCtrlPointZ );
982 if (methodRadiobox->GetSelection()==1){
983 extractcontrolpoints2d->GetControlPoints( &vecCtrlPointX , &vecCtrlPointY , &vecCtrlPointZ );
985 if (methodRadiobox->GetSelection()==2){
986 extractcontrolpoints2d->SetSamplingControlPoints( sampling );
987 extractcontrolpoints2d->GetSamplingControlPoints( &vecCtrlPointX , &vecCtrlPointY , &vecCtrlPointZ );
991 extractcontrolpoints2d->GetInitialControlPoints( &vecCtrlPointX , &vecCtrlPointY , &vecCtrlPointZ );
994 extractcontrolpoints2d->GetControlPoints( &vecCtrlPointX , &vecCtrlPointY , &vecCtrlPointZ );
997 extractcontrolpoints2d->SetSamplingControlPoints( sampling );
998 extractcontrolpoints2d->GetSamplingControlPoints( &vecCtrlPointX , &vecCtrlPointY , &vecCtrlPointZ );
1001 //--Adding contour to the system
1003 std::vector<int> actualInstantVector;
1004 _instantPanel->getInstant( actualInstantVector );
1005 actualInstantVector[1]=z;
1007 int j,sizeCtrPt = vecCtrlPointX.size();
1008 manualContourModel *manModelContour = kernelManager->factoryManualContourModel( typeofcontour );
1009 manModelContour->SetNumberOfPointsSpline( ((sizeCtrPt/100)+1)*100 );
1011 for (j=0 ; j<sizeCtrPt ; j++)
1013 manModelContour->AddPoint( vecCtrlPointX[j] , vecCtrlPointY[j] , vecCtrlPointZ[j] );
1015 std::string theName;
1016 //theName = _modelManager->createOutline( manModelContour, actualInstantVector );
1017 theName = kernelManager->createOutline( manModelContour, actualInstantVector );
1018 bool addedModel = theName.compare("") != 0;
1021 double spc[3];//Si no hay imagen pero hay contornos que spacing se pone por default
1022 _theViewPanel->getSpacing(spc);
1023 //Adding the manualContourControler to interface objects structure
1024 //Adding the manualViewContour to interface objects structure
1025 //_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.
1026 _theViewPanel->configureViewControlTo(theName, manModelContour, spc, typeofcontour);
1027 //_theViewPanel->getSceneManager()->configureViewControlTo( theName, manModelContour,spc, typeofcontour ) ;
1032 int wxContourMainFrame::GetImageDataSizeZ(){
1033 return _theViewPanel->GetImageDataSizeZ();
1036 void wxContourMainFrame::GetImageDataRange(double *range){
1037 _theViewPanel->GetImageDataRange(range);
1040 void wxContourMainFrame::onSegmentationAllSlice(int minZ,int maxZ,int isovalue,int sampling,int method){
1041 //JCP 20-10-08 Undo redo implementation
1043 //JCP 20-10-08 Undo redo implementation
1046 int x = _theViewPanel->GetX();
1047 int y = _theViewPanel->GetY();
1051 double totalZ = maxZ-minZ+1;
1052 for( z=minZ ; z<=maxZ ; z++ )
1054 porcent = 100.0* (z-minZ)/totalZ;
1055 tmpString.Printf(_T(" %d %c %d/%d %d"), (int)porcent , 37 , z-minZ+1, (int)totalZ,z );
1056 interfMainPanel::getInstance()->setLabelSegmentationPanelVTK(tmpString);
1057 //_staticTextSegmentation->SetLabel(tmpString);
1058 SegmentationOneSlice( x,y,z,isovalue, sampling,method );
1060 interfMainPanel::getInstance()->setLabelSegmentationPanelVTK(_T(" "));
1064 void wxContourMainFrame::showAxis(bool show){
1065 _theViewPanel->SetVisibleAxis(show);
1066 _theViewPanel->Refresh();
1070 void wxContourMainFrame::onRigidPressed(){
1071 std::vector<std::string> currentSelection = _theViewPanel->getSelectedObjects();
1072 int elementsSelected = currentSelection.size();
1074 if ( elementsSelected >= 1 ){
1075 //JCP 20-10-08 Undo redo implementation
1077 //JCP 20-10-08 Undo redo implementation
1079 std::vector<int> tempVector;
1080 _instantPanel->getInstant( tempVector );
1081 Instant instant(&tempVector);
1083 int i , size=currentSelection.size();
1084 for ( i=0 ; i<size ; i++ )
1086 kernelManager->changeContourOfManager(currentSelection[i], &instant);
1091 void wxContourMainFrame::onWidthOfContour(double width){
1093 _theViewPanel->removeSceneContours();
1094 _theViewPanel->SetWidthContour(width);
1096 //_theViewPanel->getSceneManager()->SetWidthContour( width );
1100 int wxContourMainFrame::getColorWindow(){
1101 return _theViewPanel->getColorWindow();
1103 int wxContourMainFrame::getWindowLevel(){
1104 return _theViewPanel->getWindowLevel();
1107 void wxContourMainFrame::onBrigthnessColorWindowLevel(int colorwindow,int windowlevel){
1108 _theViewPanel->onBrigthnessColorWindowLevel(colorwindow, windowlevel);
1114 void wxContourMainFrame::onInterpolation(bool interpolate){
1115 _theViewPanel->onInterpolation(interpolate);
1119 void wxContourMainFrame::onChangeInstant(std::string name,int actual){
1120 _instantPanel->setConceptValue( name, actual );
1123 void wxContourMainFrame::resetAppend(){
1124 kernelManager->resetAppend();
1128 void wxContourMainFrame::onSpreadAdd(){
1129 std::vector<double> vecX;
1130 std::vector<double> vecY;
1131 std::vector<double> vecZ;
1132 _theViewPanel->GetPointsOfActualContour(&vecX , &vecY , &vecZ );
1134 std::vector<int> tempVector;
1135 _instantPanel->getInstant( tempVector );
1137 std::string val = kernelManager->onSpreadAdd(&vecX , &vecY , &vecZ, tempVector);
1139 interfMainPanel::getInstance()->appendStringSpread(val);
1143 void wxContourMainFrame::onSpreadGo(int type){
1145 //JCP 20-10-08 Undo redo implementation
1147 //JCP 20-10-08 Undo redo implementation
1150 std::vector<double> vecCtrlPointX;
1151 std::vector<double> vecCtrlPointY;
1152 std::vector<double> vecCtrlPointZ;
1156 std::vector<int> tempVector;
1157 _instantPanel->getInstant( tempVector );
1160 kernelManager->getMaxMinZ(&minZ,&maxZ);
1161 //JSTG_16-07-08_----------------------------------------------------------------
1162 //_contourPropagation->setInterpolationNumber(maxZ-minZ+1);
1163 kernelManager->CalculeSplinePropagation();
1165 double totalZ = maxZ-minZ+1;
1168 //--------------------------------------------------------------------
1169 for ( z=(int)minZ ; z<=(int)maxZ ; z++ )
1171 porcent = 100.0* (z-minZ)/totalZ;
1172 int numero = (int)(z-minZ+1)/(int)totalZ;
1173 std::string stringtemp = " "+kernelManager->intToString(porcent)+"% "+kernelManager->intToString(numero)+" "+kernelManager->intToString(z);
1175 interfMainPanel::getInstance()->setStringSpread(stringtemp);
1177 int typeofcontour = 1;
1178 std::string theName;
1179 manualContourModel* manModelContour = kernelManager->GetPoints(z, type, &vecCtrlPointX,&vecCtrlPointY,&vecCtrlPointZ, theName,typeofcontour, tempVector);
1181 if( manModelContour!=NULL ){
1182 double spc[3];//Si no hay imagen pero hay contornos que spacing se pone por default
1183 this->_theViewPanel->getSpacing(spc);
1184 //Adding the manualContourControler to interface objects structure
1185 //Adding the manualViewContour to interface objects structure
1186 //_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.
1187 _theViewPanel->configureViewControlTo( theName, manModelContour,spc,typeofcontour ) ;
1192 int numero = (int)(z-minZ+1)/(int)totalZ;
1193 std::string stringtemp = " "+kernelManager->intToString(porcent)+"% "+kernelManager->intToString(numero)+" "+kernelManager->intToString(z);
1195 interfMainPanel::getInstance()->setStringSpread(stringtemp);
1197 //RefreshInterface();
1200 void wxContourMainFrame::getInstantVector(std::vector<int>& tempVector){
1204 std::vector<std::string> wxContourMainFrame::getOutlinesName(int slide){
1205 std::vector<int> tempVector;
1206 _instantPanel->getInstant(tempVector);
1207 //Asignation of slide number should be different ex by name
1208 tempVector[1]=slide;
1209 return kernelManager->getOutlinesNameAtInstant(tempVector);
1212 void wxContourMainFrame::onInformationContourLabels(int typeContourGroup,int selection,int minimumZ,int maximumZ){
1213 int maxContourGroup = 0;
1215 ContourExtractData *contourextractdata = new ContourExtractData();
1217 contourextractdata ->SetTypeOperation( typeContourGroup % 3 );
1219 std::vector<manualContourModel*> lstManConMod;
1220 std::vector<manualContourModel*> lstManConModTmp;
1221 std::vector<manualContourModel*> lstManConModExp;
1222 std::vector<double> pLstValue;
1223 std::vector<double> pLstValuePosX;
1224 std::vector<double> pLstValuePosY;
1225 std::vector<double> pLstValuePosZ;
1228 int resultGrayRangeCount;
1231 double resultAverage;
1232 double resultStandardeviation;
1234 std::vector<int> tempVector;
1235 _instantPanel->getInstant( tempVector );
1237 vtkImageData *imagedata = _theViewPanel->getImageData();
1238 int sizeZ = _theViewPanel->GetImageDataSizeZ();
1240 int ii,sizeLstContourThings;
1250 if (selection==0 ) // actual slice
1252 std::vector<int> tempVector;
1253 _instantPanel->getInstant( tempVector );
1254 int actualSlice = tempVector[1];
1258 else if (selection==2 ) // All slices
1263 else if (selection==1 ) // slice range
1270 totalZ = maxZ-minZ+1;
1271 contourextractdata->SetImage( imagedata);
1274 for ( z=minZ ; z<=maxZ ; z++ )
1277 porcent = 100.0* (z-minZ)/totalZ;
1278 tmpString.Printf(_T(" %d %c %d/%d %d"), (int)porcent , 37 , z-minZ+1, (int)totalZ ,z);
1280 interfMainPanel::getInstance()->setStringInfoPanel(tmpString);
1281 //_staticTextInformation->SetLabel(tmpString);
1283 //Extraction data from contours of each slice
1284 contourextractdata->SetZtoBeAnalys( z);
1287 Instant instant(&tempVector);
1288 std::vector<ContourThing**> lstContourThings = kernelManager->getOutlinesAtInstant( &instant );
1289 sizeLstContourThings = lstContourThings.size();
1291 lstManConMod.clear();
1292 for (ii=0 ; ii<sizeLstContourThings ; ii++)
1294 ContourThing **contourthing = lstContourThings[ii];
1295 lstManConMod.push_back( (*contourthing)->getModel() );
1297 lstManConModExp = kernelManager->ExploseEachModel( lstManConMod );
1300 wxString tempString;
1301 tempString.Printf(_T("%d - %d"),z, sizeLstContourThings);
1302 interfMainPanel::getInstance()->setRowLabelInfoPanel(z, tempString);
1303 //_grid->SetRowLabelValue(z, tempString );
1305 int iContourGroup,sizeContourGroup;
1306 if (typeContourGroup==3) // contour separete
1308 sizeContourGroup=lstManConModExp.size();
1309 if ( maxContourGroup<sizeContourGroup )
1311 maxContourGroup=sizeContourGroup;
1313 } else { // contour AND OR XOR
1322 for( iContourGroup=0 ; iContourGroup<sizeContourGroup ; iContourGroup++ ){
1323 lstManConModTmp.clear();
1324 if (typeContourGroup==3) // contour separete
1326 lstManConModTmp.push_back( lstManConModExp[iContourGroup]);
1327 } else { // contour AND OR XOR
1328 lstManConModTmp = lstManConModExp;
1331 contourextractdata->SetLstManualContourModel( lstManConModTmp );
1334 pLstValuePosX.clear();
1335 pLstValuePosY.clear();
1336 pLstValuePosZ.clear();
1337 contourextractdata->GetValuesInsideCrown( &pLstValue,
1341 // Statistics of each slice.
1342 contourextractdata->Statistics( &pLstValue,
1345 &resultGrayRangeCount,
1350 &resultStandardeviation);
1352 if (interfMainPanel::getInstance()->getNumberColsInformationPanel()<_numberOfVariablesStatistics*(iContourGroup+1) )
1354 interfMainPanel::getInstance()->appendColsInformationPanel(_numberOfVariablesStatistics);
1357 tmpIntA=_numberOfVariablesStatistics*iContourGroup ;
1359 tempString.Printf(_T("%d"),resultSize);
1360 interfMainPanel::getInstance()->setCellValueInfoPanel(z, tmpIntA, tempString);
1362 tempString.Printf(_T("%d"),resultGrayRangeCount);
1363 interfMainPanel::getInstance()->setCellValueInfoPanel(z, tmpIntA+1, tempString);
1365 tempString.Printf(_T("%f"),resultMin);
1366 interfMainPanel::getInstance()->setCellValueInfoPanel(z, tmpIntA+2, tempString);
1368 tempString.Printf(_T("%f"),resultMax);
1369 interfMainPanel::getInstance()->setCellValueInfoPanel(z, tmpIntA+3, tempString);
1371 tempString.Printf(_T("%f"),resultAverage);
1372 interfMainPanel::getInstance()->setCellValueInfoPanel(z, tmpIntA+4, tempString);
1374 tempString.Printf(_T("%f"),resultStandardeviation);
1375 interfMainPanel::getInstance()->setCellValueInfoPanel(z, tmpIntA+5, tempString);
1378 } // for iContourGroup
1382 wxString tmpTitleString;
1384 for ( iTitleGroup=0 ; iTitleGroup<maxContourGroup ; iTitleGroup++ )
1386 tmpIntB =_numberOfVariablesStatistics*iTitleGroup;
1387 tmpTitleString.Printf(_T("%d-Size Data"),iTitleGroup);
1388 interfMainPanel::getInstance()->setColLableInfoPanel(tmpIntB + 0, tmpTitleString);
1390 interfMainPanel::getInstance()->setColLableInfoPanel(tmpIntB + 0, tmpTitleString );
1391 interfMainPanel::getInstance()->setColLableInfoPanel( tmpIntB + 1, _T("Size Range") );
1392 interfMainPanel::getInstance()->setColLableInfoPanel( tmpIntB + 2, _T("Min") );
1393 interfMainPanel::getInstance()->setColLableInfoPanel( tmpIntB + 3, _T("Max") );
1394 interfMainPanel::getInstance()->setColLableInfoPanel( tmpIntB + 4, _T("Average") );
1395 interfMainPanel::getInstance()->setColLableInfoPanel( tmpIntB + 5, _T("St.Dev.") );
1396 interfMainPanel::getInstance()->setColLableInfoPanel( tmpIntB + 6, _T(" ") );
1399 interfMainPanel::getInstance()->setStringInfoPanel( _T("") );
1400 delete contourextractdata;
1403 void wxContourMainFrame::onSaveResults(std::string directory,std::string namefile, std::string filename, int typeContourGroup){
1404 SaveValuesXYZ( directory , namefile, typeContourGroup );
1405 SaveImageResult( directory , namefile, typeContourGroup);
1408 FILE *pFile=fopen(filename.c_str(),"w+");
1410 int sizeZ = _theViewPanel->GetImageDataSizeZ();
1413 int i,j,maxX,maxY=sizeZ;
1414 maxX= interfMainPanel::getInstance()->getNumberColsInformationPanel();//this->_grid->GetNumberCols();
1416 int iTitle,sizeTitle = (maxX / _numberOfVariablesStatistics);
1417 for ( iTitle=0; iTitle<sizeTitle ; iTitle++)
1419 fprintf(pFile,"-- \t %d-Size \t SizeRange \t Min \t Max \t Ave \t StDv \t" , iTitle,tmpString.c_str() );
1421 fprintf(pFile,"\n" );
1425 for ( j=0; j<maxY ; j++)
1427 fprintf(pFile,"%d\t" , j );
1428 for (i=0 ; i<maxX ; i++){
1429 tmpString = interfMainPanel::getInstance()->getCellValue(j, i);//_grid->GetCellValue( j , i );
1430 fprintf(pFile,"%s\t" , (const char *)(tmpString.mb_str()) );
1432 fprintf(pFile,"\n" );
1438 void wxContourMainFrame::SaveValuesXYZ(std::string directory,std::string namefile,int typeContourGroup)
1441 ContourExtractData *contourextractdata = new ContourExtractData();
1442 //int typeContourGroup = this->_radiolstboxContourGroup->GetSelection();
1443 contourextractdata ->SetTypeOperation( typeContourGroup % 3 );
1445 std::vector<manualContourModel*> lstManConMod;
1446 std::vector<manualContourModel*> lstManConModTmp;
1447 std::vector<manualContourModel*> lstManConModExp;
1448 std::vector<double> pLstValue;
1449 std::vector<double> pLstValuePosX;
1450 std::vector<double> pLstValuePosY;
1451 std::vector<double> pLstValuePosZ;
1453 std::vector<int> tempVector;
1454 _instantPanel->getInstant( tempVector );
1456 vtkImageData *imagedata = _theViewPanel->getSceneManager()->GetImageData();
1457 int sizeZ = _theViewPanel->getSceneManager()->GetImageDataSizeZ();
1459 int ii,sizeLstContourThings;
1466 minZ = 0;// _mbarrange->GetStart();
1467 maxZ = sizeZ;//_mbarrange->GetEnd();
1468 totalZ = maxZ-minZ+1;
1470 contourextractdata->SetImage( imagedata);
1473 for ( z=0 ; z<sizeZ ; z++)
1476 porcent = 100.0* (z-minZ)/totalZ;
1478 tmpString.Printf(_T("Saving Values"));
1479 tmpString.Printf(_T(" %d %c %d/%d %d"), (int)porcent , 37 , z-minZ+1, (int)totalZ ,z);
1480 interfMainPanel::getInstance()->setStringInfoPanel(tmpString);
1481 //_staticTextInformation->SetLabel(tmpString);
1484 //Extraction data from contours of each slice
1485 contourextractdata->SetZtoBeAnalys( z);
1488 Instant instant(&tempVector);
1489 std::vector<ContourThing**> lstContourThings = kernelManager->getOutlinesAtInstant(&instant);//this->_modelManager->getOutlinesAtInstant( &instant );
1490 sizeLstContourThings = lstContourThings.size();
1492 lstManConMod.clear();
1493 for (ii=0 ; ii<sizeLstContourThings ; ii++)
1495 ContourThing **contourthing = lstContourThings[ii];
1496 lstManConMod.push_back( (*contourthing)->getModel() );
1498 lstManConModExp = kernelManager->ExploseEachModel( lstManConMod );
1503 int iContourGroup,sizeContourGroup;
1504 if (typeContourGroup==3) // contour separete
1506 sizeContourGroup=lstManConModExp.size();
1507 } else { // contour AND OR XOR
1511 for( iContourGroup=0 ; iContourGroup<sizeContourGroup ; iContourGroup++ ){
1512 lstManConModTmp.clear();
1513 if (typeContourGroup==3) // contour separete
1515 lstManConModTmp.push_back( lstManConModExp[iContourGroup]);
1516 } else { // contour AND OR XOR
1517 lstManConModTmp = lstManConModExp;
1520 contourextractdata->SetLstManualContourModel( lstManConModTmp );
1523 pLstValuePosX.clear();
1524 pLstValuePosY.clear();
1525 pLstValuePosZ.clear();
1526 contourextractdata->GetValuesInsideCrown( &pLstValue,
1531 std::string temp = directory + "/" + namefile + "-slice";
1532 temp = temp + kernelManager->intToString(z) + "-cont" + kernelManager->intToString(iContourGroup);
1533 temp = temp + ".txt";
1536 /*filename.Printf(_T("%s"),directory.c_str());
1537 filename.append(_T("\\"));
1538 filename.append(_T("%s"),namefile.c_str());
1539 filename.append(_T("-slice"));
1540 filename.append(_T("%d"),z);
1541 filename.append(_T("-cont"));
1542 filename.append(_T("%d"),iContourGroup);
1543 filename.append(_T(".txt"));*/
1544 filename.Printf(temp.c_str());
1545 FILE *pFile=fopen((const char *)filename.mb_str(),"w+");
1546 fprintf(pFile,"value \t x \t y \t z\n" );
1547 int iLstValue,sizeLstValue=pLstValue.size();
1548 for (iLstValue=0 ; iLstValue<sizeLstValue ; iLstValue++ )
1550 fprintf(pFile,"%f\t %f\t %f\t %f\n", (float)pLstValue[iLstValue] , (float)pLstValuePosX[iLstValue], (float)pLstValuePosY[iLstValue], (float)z );
1553 } // for iContourGroup
1555 interfMainPanel::getInstance()->setStringInfoPanel(_T(""));
1556 //_staticTextInformation->SetLabel( _T("") );
1557 delete contourextractdata;
1560 void wxContourMainFrame::SaveImageResult(std::string directory,std::string namefile, int typeContourGroup)
1563 ContourExtractData *contourextractdata = new ContourExtractData( true );
1564 //int typeContourGroup = this->_radiolstboxContourGroup->GetSelection();
1565 if (typeContourGroup==3)
1569 contourextractdata ->SetTypeOperation( typeContourGroup % 3 );
1571 std::vector<manualContourModel*> lstManConMod;
1572 std::vector<manualContourModel*> lstManConModTmp;
1573 std::vector<manualContourModel*> lstManConModExp;
1575 std::vector<int> tempVector;
1576 _instantPanel->getInstant( tempVector );
1578 vtkImageData *imagedata = _theViewPanel->getImageData();
1579 int sizeZ = _theViewPanel->GetImageDataSizeZ();
1581 int ii,sizeLstContourThings;
1590 minZ = 0;// _mbarrange->GetStart();
1591 maxZ = sizeZ;//_mbarrange->GetEnd();
1592 totalZ = maxZ-minZ+1;
1594 contourextractdata->SetImage( imagedata);
1597 for ( z=0 ; z<sizeZ ; z++)
1600 porcent = 100.0* (z-minZ)/totalZ;
1601 tmpString.Printf(_T("Saving Values"));
1602 tmpString.Printf(_T("%d %c %d/%d %d"), (int)porcent , 37 , z-minZ+1, (int)totalZ ,z);
1603 interfMainPanel::getInstance()->setStringInfoPanel(tmpString);
1605 //Extraction data from contours of each slice
1606 contourextractdata->SetZtoBeAnalys( z);
1609 Instant instant(&tempVector);
1610 std::vector<ContourThing**> lstContourThings = kernelManager->getOutlinesAtInstant( &instant );
1611 sizeLstContourThings = lstContourThings.size();
1613 lstManConMod.clear();
1614 for (ii=0 ; ii<sizeLstContourThings ; ii++)
1616 ContourThing **contourthing = lstContourThings[ii];
1617 lstManConMod.push_back( (*contourthing)->getModel() );
1619 lstManConModExp = kernelManager->ExploseEachModel( lstManConMod );
1622 int iContourGroup,sizeContourGroup;
1623 if (typeContourGroup==3) // contour separete
1625 sizeContourGroup=lstManConModExp.size();
1626 } else { // contour AND OR XOR
1630 for( iContourGroup=0 ; iContourGroup<sizeContourGroup ; iContourGroup++ ){
1631 lstManConModTmp.clear();
1632 if (typeContourGroup==3) // contour separete
1634 lstManConModTmp.push_back( lstManConModExp[iContourGroup]);
1635 } else { // contour AND OR XOR
1636 lstManConModTmp = lstManConModExp;
1639 contourextractdata->SetLstManualContourModel( lstManConModTmp );
1642 // for (ii=0 ; ii<sizeLstContourThings ; ii++)
1644 // ContourThing **contourthing = lstContourThings[ii];
1645 // lstManConMod.push_back( (*contourthing)->getModel() );
1647 // contourextractdata->SetLstManualContourModel( lstManConMod );
1649 contourextractdata->CalculateImageResult(); // with actual Z
1651 } // for iContourGroup
1654 std::string temp = directory + "/" + namefile + "-Value.mhd";
1657 filename.Printf(_T(temp.c_str()));
1658 //filename.Printf(_T("%s\\%s-Value.mhd",directory.c_str(),namefile.c_str(),z);
1659 /*filename.Printf(_T("%s"),directory.c_str());
1660 filename.append(_T("\\"));
1661 filename.append(_T("%s"),namefile.c_str());
1662 filename.append(_T("-Value.mhd"));*/
1665 vtkMetaImageWriter *writerValueImage = vtkMetaImageWriter::New( );
1666 writerValueImage->SetInput( contourextractdata->GetVtkImageValueResult() );
1667 writerValueImage->SetFileName( (const char *)filename.mb_str() );
1668 writerValueImage->SetFileDimensionality( 3 );
1669 writerValueImage->Write( );
1672 // filename.Printf("%s\\%s-Mask.mhd",directory.c_str(),namefile.c_str(),z);
1673 temp = directory + "/" + namefile + "-Mask.mhd";
1675 filename.Printf(_T(temp.c_str()));
1677 /*filename.Printf(_T("%s"),directory.c_str());
1678 filename.append(_T("\\"));
1679 filename.append(_T("%s"),namefile.c_str());
1680 filename.append(_T("-Mask.mhd"));*/
1682 vtkMetaImageWriter *writerMaskImage = vtkMetaImageWriter::New( );
1683 writerMaskImage->SetInput( contourextractdata->GetVtkImageMaskResult() );
1684 writerMaskImage->SetFileName( (const char *)filename.mb_str() );
1685 writerMaskImage->SetFileDimensionality( 3 );
1686 writerMaskImage->Write( );
1688 interfMainPanel::getInstance()->setStringInfoPanel( _T("") );
1689 delete contourextractdata;
1692 void wxContourMainFrame::onChangeInstantInstantPanel(std::string name,int value, int minshow, int maxshow){
1693 if( name.compare( _theViewPanel->getVerticalConceptName() ) == 0){
1694 _theViewPanel->setActualVertical( value);
1696 else if( name.compare( _theViewPanel->getHorizontalConceptName() ) == 0|| _instantPanel->getIfConceptCheckedAt( name, 0 ) ) {
1697 _theViewPanel->setHorizontalConcept( name, minshow, maxshow, minshow, maxshow, value);