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;
48 _drawToolsPanel = NULL;
49 _operationsToolsPanel = NULL;
50 _autoFormsPanel = NULL;
51 _standardToolsPanel = NULL;
52 _editionToolsPanel = NULL;
53 _listViewPanel = 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;
61 //wxContour_ActionCommandsID a;
65 wxContourMainFrame :: wxContourMainFrame(wxWindow* parent, wxWindowID id,const wxString& title,const wxPoint& pos,const wxSize& size,std::vector<vtkImageData*> images, long style)
66 : wxPanel(parent, id, pos, size, style)
68 m_mgr.SetManagedWindow(this);
69 _creatingContoursActive = false;
71 // _modelManager = NULL;
75 _drawToolsPanel = NULL;
76 _operationsToolsPanel = NULL;
77 _autoFormsPanel = NULL;
78 _standardToolsPanel = NULL;
79 _editionToolsPanel = NULL;
80 _listViewPanel = NULL;
82 //_actualInstant = NULL;
84 // set up default notebook style
85 m_notebook_style =wxAUI_NB_TAB_SPLIT | wxAUI_NB_TAB_EXTERNAL_MOVE | wxNO_BORDER;
87 //wxContour_ActionCommandsID a;
88 _numberOfVariablesStatistics = 6+1;
91 _performingOperation = new PerformingOperation();
97 kernelManager = new KernelManagerContour(images);
98 //kernelManager->setVectImages(images);
99 //kernelManager->initializeEnvironment();
101 //vtkImageData* selectedimage = kernelManager->getVectImages()[0];
103 //-------------------------------------------------------------
105 /*frame = new wxContourMainFrame(_builder->getImSourceEnv(), _builder->getImSectionEnv(), _builder->getAxesEnv(), _builder->getContourEnv(),NULL, wxID_ANY, wxT("ROI Application Sample"), wxPoint(50,50), wxSize(800, 600));
108 //Creating the evtHandler of the panels
109 //wxContourEventHandler * eventHandler = new wxContourEventHandler();
111 //Creating the window that will show the panels
113 //Getting the parent for the panels ( using aui )
114 wxAuiNotebook * notebook = this->createNotebook();
117 //wxInstantChooserPanel * instantPanel = new wxInstantChooserPanel( notebook, "Instant Chooser", true);
119 std::vector<std::string> conceptNameVect;
120 std::vector<int> conceptSizeVect;
124 _instantPanel = new wxInstantChooserPanel( notebook, "Instant Chooser", true, false, "c" );
125 _theViewPanel = new wxContourViewPanel( kernelManager->getSourceImage(), notebook );
129 kernelManager->getConceptsInformation(conceptNameVect, conceptSizeVect);
130 _instantPanel->addConcepts(conceptNameVect, conceptSizeVect);
133 double val = _theViewPanel->getCurrentDeep();
134 _instantPanel->setConceptValue( "Axe Depth", (int)val );
135 //JCP _instantPanel->setConceptValue("time", num de imagenes);
136 ConceptDataWrap * data = _instantPanel->getConceptDataOf( "Axe Depth" );
137 //*******************changeInstant();
138 _theViewPanel->setVerticalConcept( "Axe Depth", data->getMinValue(), data->getMaxValue(), data->getMinShowedValue(), data->getMaxShowedValue(), data->getActualValue() );
140 //eventHandler->setModelManager( kernelManager->getOutlineModelManager() );
141 //eventHandler->setViewPanel( _theViewPanel );
142 //_theViewPanel->initializeScenceManager();
143 //eventHandler->setInstantChooserPanel( _instantPanel );
145 //bool successConfiuration = eventHandler->configureEventsHandling();
147 //successConfiuration &= this->configurePanels( notebook );
148 this->configurePanels( notebook );
150 interfMainPanel* pannew = interfMainPanel::getInstance(parent);//, eventHandler);
158 wxContourMainFrame* wxContourMainFrame :: getInstance(wxWindow* parent, wxWindowID id,const wxString& title,const wxPoint& pos,const wxSize& size,std::vector<vtkImageData*> images, long style ){
159 if(instance == NULL){
160 instance = new wxContourMainFrame(parent, id, title, pos, size, images, style);
165 std::vector<vtkImageData*> wxContourMainFrame ::getVectImages(){
166 return kernelManager->getVectImages();
168 wxContourMainFrame* wxContourMainFrame :: getInstance(){
173 wxContourMainFrame :: ~wxContourMainFrame()
176 //El problema al cerrar la aplicacion puede estar asociado
177 //a que wxAUINotebook esta en la aplicacion
178 //principal (wxContourGUIExample)tambien
179 //EED???? delete _theViewPanel;
180 //EED???? delete _instantPanel;
181 //EED???? delete _buttonsBar;
182 //EED???? delete _actualInstant;
183 //EED???? delete _sceneManager;
187 //------------------------------------------------------------------------------------------------------------
188 // Creational and initialization methods using WxAui
189 //------------------------------------------------------------------------------------------------------------
191 wxAuiNotebook * wxContourMainFrame :: createNotebook()
193 wxSize client_size = GetClientSize();
194 wxAuiNotebook* noteBook = new wxAuiNotebook(this, -1, wxPoint(client_size.x, client_size.y), wxSize(430,200), m_notebook_style);
195 wxBitmap page_bmp = wxArtProvider::GetBitmap(wxART_NORMAL_FILE, wxART_OTHER, wxSize(16,16));
200 //------------------------------------------------------------------------------------------------------------
201 // Creational and initialization methods
202 //------------------------------------------------------------------------------------------------------------
203 bool wxContourMainFrame :: configurePanels(wxAuiNotebook* theNoteBook)
205 bool configured = _theViewPanel!=NULL;
207 configured &= _theViewPanel!=NULL;
208 if( _theViewPanel!=NULL )
210 theNoteBook->AddPage( _theViewPanel, wxT(" View ") );
217 theNoteBook->AddPage( _instantPanel, wxT("Instant Page") );
221 m_mgr.AddPane(theNoteBook, wxAuiPaneInfo().Name(wxT("notebook_content")).CenterPane().PaneBorder(false));
223 configured &= _buttonsBar!=NULL;
224 if( _buttonsBar!=NULL )
226 m_mgr.AddPane(_buttonsBar, wxAuiPaneInfo().
227 Name(wxT("TB")).Caption(wxT("Buttons Bar")).
229 LeftDockable( ).RightDockable( false ).CloseButton(false));
234 SetMinSize(wxSize(300,300));
239 void wxContourMainFrame :: setNotebook( wxAuiNotebook * noteBook )
244 //------------------------------------------------------------------------------------------------------------
245 // Attributes getters and setters
246 //------------------------------------------------------------------------------------------------------------
250 void wxContourMainFrame :: setInstantChooserPanel( wxInstantChooserPanel * theInstantChooserPanel )
252 _instantPanel = theInstantChooserPanel;
255 void wxContourMainFrame :: setButtonsBar( wxContour_ButtonsBar * theButtonsBar )
257 _buttonsBar = theButtonsBar;
260 void wxContourMainFrame :: setGrid( wxContour_Grid * theGridPanel )
262 _gridPanel = theGridPanel;
265 void wxContourMainFrame :: setDrawToolsPanel( wxContour_DrawToolsPanel * theDrawToolsPanel )
267 _drawToolsPanel = theDrawToolsPanel;
270 void wxContourMainFrame :: setOperationsToolsPanel( wxContour_OperationsToolsPanel * theOperationsToolsPanel )
272 _operationsToolsPanel = theOperationsToolsPanel;
275 void wxContourMainFrame :: setAutomaticFormsPanel( wxContour_AutomaticFormsToolsPanel * theAutoFormsPanel )
277 _autoFormsPanel = theAutoFormsPanel;
280 void wxContourMainFrame :: setStandardToolsPanel( wxContour_StandardToolsPanel * theStandardToolsPanel )
282 _standardToolsPanel= theStandardToolsPanel;
285 void wxContourMainFrame :: setEditionToolsPanel( wxContour_EdtionToolsPanel * theEditionToolsPanel )
287 _editionToolsPanel = theEditionToolsPanel;
290 void wxContourMainFrame :: setListViewPanel( wxContour_ListViewPanel * theListViewPanel )
292 _listViewPanel = theListViewPanel;
297 void wxContourMainFrame::onCreateContourSpline( ){
299 //JCP 20-10-08 Undo redo implementation
301 //JCP 20-10-08 Undo redo implementation
305 void wxContourMainFrame::onCreateContourRectangle( ){
306 //JCP 20-10-08 Undo redo implementation
308 //JCP 20-10-08 Undo redo implementation
311 void wxContourMainFrame::onCreateContourCircle( ){
312 //JCP 20-10-08 Undo redo implementation
314 //JCP 20-10-08 Undo redo implementation
317 //------------------------------------------------------------------------------------------------------------
319 void wxContourMainFrame :: onCreateContourBullEye(wxPanel* panel )
321 //Creating the manualContourModel and including in the model
322 manualContourModel * manModelContour = factoryManualContourModel(panel );
324 std::vector<int> instantVector;
325 _instantPanel->getInstant( instantVector );
326 std::string theName = kernelManager->createOutline(manModelContour, instantVector);
328 /*std::vector<int> instantVector;
329 _instantPanel->getInstant( instantVector );
331 theName= _modelManager->createOutline( manModelContour, instantVector );*/
332 bool addedModel = theName.compare("") != 0;//??
336 double spc[3];//Si no hay imagen pero hay contornos que spacing se pone por default
337 _theViewPanel->getSpacing(spc);
338 //Adding the manualContourControler to interface objects structure
339 //Adding the manualViewContour to interface objects structure
340 //_theViewPanel->getSceneManager()->setControlActiveStateOfALL( false );//This call is being done here because if the ROI is created underneath the previously created ROIS will still be active.
341 _theViewPanel->getSceneManager()->configureViewControlTo( theName, manModelContour,spc , 4) ;
344 void wxContourMainFrame :: createContour( int typeContour )
346 //Creating the manualContourModel and including in the model
347 manualContourModel * manModelContour = kernelManager->factoryManualContourModel(typeContour);
350 std::vector<int> instantVector;
351 _instantPanel->getInstant( instantVector );
352 std::string theName = kernelManager->createOutline(manModelContour, instantVector);
354 /*std::vector<int> instantVector;
355 _instantPanel->getInstant( instantVector );
357 theName= _modelManager->createOutline( manModelContour, instantVector );*/
358 bool addedModel = theName.compare("") != 0;//??
361 double spc[3];//Si no hay imagen pero hay contornos que spacing se pone por default
362 _theViewPanel->getSpacing(spc);
363 //Adding the manualContourControler to interface objects structure
364 //Adding the manualViewContour to interface objects structure
365 //_sceneManager->setControlActiveStateOfALL( false );//This call is being done here because if the ROI is created underneath the previously created ROIS will still be active.
366 _theViewPanel->getSceneManager()->configureViewControlTo( theName, manModelContour,spc , typeContour) ;
370 manualContourModel * wxContourMainFrame::factoryManualContourModel(wxPanel* panel){
372 manualContourModelBullEye *manModelContourBullEye = new manualContourModelBullEye();
373 manualContourModel *manModelContour=NULL;
374 manModelContour = manModelContourBullEye;
376 int iCrown,sizeCrowns,iSector,sizeSectors;
377 double radioA,radioB,ang,angDelta ;
378 sizeCrowns = ((PanelBullEyeOptions*)panel)->GetNumberOfCrowns();
379 for ( iCrown=0 ; iCrown<sizeCrowns ; iCrown++ )
381 sizeSectors = ((PanelBullEyeOptions*)panel)->GetNumberOfSections(iCrown);
382 radioB = ((PanelBullEyeOptions*)panel)->GetRadioOfCrown(iCrown);
383 if (iCrown==sizeCrowns-1)
387 radioA = ((PanelBullEyeOptions*)panel)->GetRadioOfCrown(iCrown+1);
391 for ( iSector=0 ; iSector<sizeSectors ; iSector++ )
393 ang = ((PanelBullEyeOptions*)panel)->GetAngOfCrownSection(iCrown,iSector);
394 angDelta= ((PanelBullEyeOptions*)panel)->GetAngDeltaOfCrownSection(iCrown);
395 manModelContourBullEye->AddSector(radioA,radioB,ang,angDelta);
398 } // if _panelBullEyeOptions
400 return manModelContour;
402 void wxContourMainFrame :: saveState(){
404 std::string temp = kernelManager->saveState();
405 saveFileWithContours(temp);
408 void wxContourMainFrame::onDeleteContour(){
409 //JCP 20-10-08 Undo redo implementation
411 //JCP 20-10-08 Undo redo implementation
413 std::vector<std::string> lstKeyNameToBeErase;
414 lstKeyNameToBeErase = _theViewPanel->getSceneManager()->getSelectedObjects();
415 deleteContours( lstKeyNameToBeErase );
417 int i,size=_sceneManager->getSelectedObjects().size();
420 std::string keyName = _sceneManager->getSelectedObjects()[i];
421 int ispartofstaticlist = this->_modelManager->IsPartOfStaticList( keyName );
422 if ( ispartofstaticlist>=0 )
424 std::vector<int> tempVector;
425 _instantPanel->getInstant( tempVector );
426 Instant instant(&tempVector);
427 this->_modelManager->ChangeContourOfList(keyName, &instant);
431 std::vector<std::string> lstKeyName;
432 std::vector<std::string> lstKeyNameActualSlice;
433 std::vector<std::string> lstKeyNameToBeErase;
435 lstKeyNameToBeErase = _sceneManager->getSelectedObjects();
436 lstKeyNameActualSlice = _sceneManager->GetlstContoursNameActualSlice();
437 int k,kSize=lstKeyNameToBeErase.size();
438 int j,jSize=lstKeyNameActualSlice.size();
440 for (k=0;k<kSize; k++)
443 for (j=0;j<jSize; j++)
445 if (lstKeyNameToBeErase[k]==lstKeyNameActualSlice[j])
452 lstKeyName.push_back( lstKeyNameToBeErase[k] );
456 deleteContours( lstKeyName );
460 void wxContourMainFrame :: deleteContours( std::vector<std::string> keyNamesVector )
462 int i,size=keyNamesVector.size();
465 deleteContour( keyNamesVector[i] );
469 void wxContourMainFrame :: deleteContour( std::string theKeyName ){
470 /*manualContourModel * cModel;
471 manualViewBaseContour * cViewer;
472 manualContourBaseControler * cControler;
474 ContourWrap_ViewControl *conwrapviewControl = _theViewPanel->getSceneManager()->getContourWrap_ViewControlOf( theKeyName );
475 cControler = conwrapviewControl->getControler();*/
478 bool isedit = _theViewPanel->isEditableCControler(theKeyName);
479 bool ispartofstaticlst = kernelManager->IsPartOfStaticList(theKeyName);
481 if (isedit && ispartofstaticlst)
483 _theViewPanel->removeFromScene(theKeyName);
485 kernelManager->deleteCModel(theKeyName);
486 //_theViewPanel->getSceneManager()->removeFromScene( theKeyName );
487 //cViewer = conwrapviewControl->getViewer();
488 //_theViewPanel->getSceneManager()->removeWrap( theKeyName );
489 //cControler* conwrapviewControl->getControler();
491 //FILE *ff = fopen("c:/temp/wxVtkBaseView_SceneManagerStadistics.txt","a+");
492 //fprintf(ff,"EED wxContourEventHandler::deleteContours() \n" );
493 //fprintf(ff," %s %p\n",keyNamesVector[i].c_str(), cControler );
497 // delete cControler;
502 void wxContourMainFrame::onDeleteContoursActSlice(){
503 //JCP 20-10-08 Undo redo implementation
505 //JCP 20-10-08 Undo redo implementation
506 deleteContours( (std::vector<std::string>)_theViewPanel->getSceneManager()->GetlstContoursNameActualSlice() );
508 void wxContourMainFrame::onDeleteAllContours(){
509 //JCP 20-10-08 Undo redo implementation
513 void wxContourMainFrame::deleteAllContours(){
514 //JCP 20-10-08 Undo redo implementation
517 std::vector<int> tempVector;
518 _instantPanel->getInstant( tempVector );
520 //JCP --08-09-2008 When using a diferent interface the _mbarrangeDeleteAll might not be initialize
521 // the values in GetStart and GetEnd will then not be initialize also.
522 // We use instead the values given when initializing the _deletepanel.
524 //int minZ = _mbarrangeDeleteAll->GetStart();
525 //int maxZ = _mbarrangeDeleteAll->GetEnd();
529 maxZ = _theViewPanel->getSceneManager()->GetImageDataSizeZ();
533 _theViewPanel->getSceneManager()->removeSceneContours( );
534 _theViewPanel->getSceneManager()->removeAllOutlines();
535 kernelManager->removeAllOutlines();
538 if ( (minZ==0) && (maxZ==_mbarrangeDeleteAll->GetMax() ))
540 _theViewPanel->getSceneManager()->removeSceneContours( );
541 _modelManager->removeAllOutlines();
542 _theViewPanel->getSceneManager()->removeAllOutlines();
545 for ( z=minZ ; z<=maxZ ; z++)
548 Instant instant(&tempVector);
549 std::vector<ContourThing**> lstContourThings = this->_modelManager->getOutlinesAtInstant( &instant );
551 sizeLstContourThings = lstContourThings.size();
552 for (ii=0 ; ii<sizeLstContourThings ; ii++)
554 ContourThing **contourthing = lstContourThings[ii];
555 deleteContour( (*contourthing)->getName() );
562 void wxContourMainFrame::setConceptValue( std::string name, int value ){
563 _instantPanel->setConceptValue(name, value);
566 ConceptDataWrap* wxContourMainFrame::getLastConceptData(){
567 return _instantPanel->getLastConceptData();
569 bool wxContourMainFrame::getIfConceptCheckedAt( std::string name, int pos ){
570 return _instantPanel->getIfConceptCheckedAt( name, pos );
573 void wxContourMainFrame::changeInstant(){
574 std::vector<int> instantVect;
575 _instantPanel->getInstant( instantVect );
576 // Instant * theInstant = new Instant ( &instantVect );
578 //Setting the actual instant
579 //_actualInstant = theInstant;
581 kernelManager->setInstant(instantVect);
582 //_modelManager->setInstant( _actualInstant );
584 updateInstantOutlines();
585 updateInstantImageData();
590 void wxContourMainFrame :: updateInstantOutlines(){
592 _theViewPanel->removeSceneContours();
593 _theViewPanel->addNameWrapperToScene();
595 //for( int i=0; i<size; i++)
597 // _theViewPanel->getSceneManager()->addToScene(namesWrapping[i]->getKeyName(), true, true, true, false, false );
601 int wxContourMainFrame::getNamesWrappingSize(){
602 return kernelManager->getNamesWrappingSize();
604 std::string wxContourMainFrame::getNameWrapping(int i){
605 return kernelManager->getNameWrapping(i);
608 void wxContourMainFrame::updateInstantImageData(){
609 std::vector<int> inst;
610 _instantPanel->getInstant(inst);
612 vtkImageData* img = kernelManager->getImageAtInstant(inst);
614 _theViewPanel->changeImage(img);
616 int z = _instantPanel->getConceptDataOf("Axe Depth")->getActualValue();
617 _theViewPanel->setImageSlice(z);
620 void wxContourMainFrame::updateInstantAxes(){
623 void wxContourMainFrame::onChangeDeep(int val){
624 _instantPanel->setConceptValue( "Axe Depth", (int)val );
629 void wxContourMainFrame::onCopy(){
630 std::vector<std::string> currentSelection = _theViewPanel->getSelectedObjects();
632 std::vector<int> tempVector;
633 _instantPanel->getInstant( tempVector );
634 _performingOperation->reset();
635 _performingOperation->setStartCommand( COPY );
636 _performingOperation->setStartOperationInstantVector( tempVector );
637 _performingOperation->setKeyNamesOperationElems( currentSelection );
639 void wxContourMainFrame::onPaste(){
642 char theStartCommand = _performingOperation->getStartCommand();
643 if ( theStartCommand == COPY )
645 //JCP 20-10-08 Undo redo implementation
647 //JCP 20-10-08 Undo redo implementation
648 std::vector<int> tempVector;
649 _instantPanel->getInstant( tempVector );
650 _performingOperation->setEndOperationInstantVector ( tempVector );
651 std::vector<std::string> elems = _performingOperation->getKeyNamesOperationElems();
652 int i,size = elems.size();
653 for( i=0; i<size; i++ )
655 createCopyContourOf( elems[i], tempVector, i>0 );
659 void wxContourMainFrame::onUndo(){
660 std::string filename;
661 if(kernelManager->onUndoSaveFile(filename)){
662 saveFileWithContours(filename);
664 if(kernelManager->onUndo(filename)){
668 void wxContourMainFrame::onRedo(){
669 std::string filename;
670 if(kernelManager->onRedo(filename)){
675 void wxContourMainFrame :: createCopyContourOf ( std::string anExistingKName, std::vector<int> &instantNoTouchData, bool append ){
676 std::string cloneName = kernelManager->createCopyContourOf( anExistingKName, instantNoTouchData );
677 manualContourModel * manualModel = kernelManager->getOutlineByKeyName(cloneName);//_modelManager->getOutlineByKeyName( cloneName )->getModel();
678 _theViewPanel->getSceneManager()->createCopyContourOf( anExistingKName, cloneName, manualModel , append );
681 void wxContourMainFrame ::loadState(std::string filename){
683 FILE *pFile=fopen(filename.c_str(),"r+");
685 fscanf(pFile,"%s",tmp); // --CreaContour--
687 fscanf(pFile,"%s",tmp); // Version
688 fscanf(pFile,"%s",tmp); // 1.0.1
689 std::string version(tmp);
693 openContours(pFile,false);
694 if (version!="1.0.0"){
695 openContours(pFile,true);
700 //_theViewPanel->getSceneManager()->removeSceneContours();
705 void wxContourMainFrame::onLoad(){
707 wxFileDialog dialog(NULL, _T("Choose a file"), _T(""), _T(""), _T("*.roi"), wxOPEN );
708 if (dialog.ShowModal() == wxID_OK)
710 std::string fileNameContourROI = (const char *)(dialog.GetPath().mb_str());
711 FILE *pFile=fopen(fileNameContourROI.c_str(),"r+");
713 fscanf(pFile,"%s",tmp); // --CreaContour--
715 fscanf(pFile,"%s",tmp); // Version
716 fscanf(pFile,"%s",tmp); // 1.0.1
717 std::string version(tmp);
719 openContours(pFile,false);
720 if (version!="1.0.0"){
721 openContours(pFile,true);
723 // _theViewPanel->getSceneManager()->openFileWithContours(ff);
727 _theViewPanel->getSceneManager()->removeSceneContours();
730 void wxContourMainFrame::onSave(){
731 wxFileDialog dialog(NULL, _T("Choose a file"), _T(""), _T(""), _T("*.roi"), wxSAVE );
732 if (dialog.ShowModal() == wxID_OK)
734 std::string fileNameContourROI = (const char *)(dialog.GetPath().mb_str());
735 saveFileWithContours( fileNameContourROI );
738 void wxContourMainFrame::saveFileWithContours( std::string filename ){
740 FILE *pFile=fopen(filename.c_str(),"w+");
741 std::vector< std::string > lstNameThings;
742 int i,sizeLstNameThings;
744 fprintf(pFile,"--CreaContour--\n");
745 fprintf(pFile,"Version %s\n", "1.0.1" );
748 lstNameThings = kernelManager->GetLstNameThings();
749 sizeLstNameThings = lstNameThings.size();
750 fprintf(pFile,"NumberOfContours %d\n", sizeLstNameThings );
751 for (i=0 ; i<sizeLstNameThings ; i++)
753 kernelManager->SaveThingName( pFile, lstNameThings[i] );
754 _theViewPanel->getSceneManager()->SaveThingName( pFile, lstNameThings[i] );
757 //-- Contours Statics
758 lstNameThings = kernelManager->GetLstNameThingsStatic();
759 sizeLstNameThings = lstNameThings.size();
760 fprintf(pFile,"NumberOfContoursStatic %d\n", sizeLstNameThings );
761 for (i=0 ; i<sizeLstNameThings ; i++)
763 kernelManager->SaveThingName( pFile, lstNameThings[i] );
764 _theViewPanel->getSceneManager()->SaveThingName( pFile, lstNameThings[i] );
769 void wxContourMainFrame::openContours( FILE *pFile, bool staticContour ){
771 fscanf(pFile,"%s",tmp); // NumberOfContours
772 fscanf(pFile,"%s",tmp); // ##
773 int numberOfContours = atoi(tmp);
775 std::vector<int> instantVector;
776 int typeContourModel;
777 manualContourModel *manModelContour;
781 for (i=0;i<numberOfContours;i++)
783 instantVector.clear();
784 fscanf(pFile,"%s",tmp); // Instant
786 fscanf(pFile,"%s",tmp); // 1
787 instantVector.push_back( atoi(tmp) );
788 fscanf(pFile,"%s",tmp); // 2
789 instantVector.push_back( atoi(tmp) );
790 fscanf(pFile,"%s",tmp); // 3
791 instantVector.push_back( atoi(tmp) );
792 fscanf(pFile,"%s",tmp); // 4
793 instantVector.push_back( atoi(tmp) );
794 fscanf(pFile,"%s",tmp); // 5
795 instantVector.push_back( atoi(tmp) );
796 fscanf(pFile,"%s",tmp); // 6
797 instantVector.push_back( atoi(tmp) );
800 fscanf(pFile,"%s",tmp); // TypeContourModel
801 fscanf(pFile,"%s",tmp); // ##
802 typeContourModel = atoi(tmp);
804 manModelContour = kernelManager->factoryManualContourModel(typeContourModel);
805 manModelContour->Open(pFile);
807 fscanf(pFile,"%s",tmp); // TypeView
808 fscanf(pFile,"%s",tmp); // ##
809 typeView = atoi(tmp);
818 theName = kernelManager->createOutline( manModelContour, instantVector );
819 bool addedModel = theName.compare("") != 0;
822 double spc[3];//Si no hay imagen pero hay contornos que spacing se pone por default
823 _theViewPanel->getSpacing(spc);
824 //Adding the manualContourControler to interface objects structure
825 //Adding the manualViewContour to interface objects structure
826 //_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.
827 _theViewPanel->getSceneManager()->configureViewControlTo( theName, manModelContour,spc , typeView) ;
830 if (staticContour==true)
832 Instant instant(&instantVector);
833 kernelManager->changeContourOfManager( theName , &instant );
836 }// for numberOfContours
840 void wxContourMainFrame::RefreshInterface(){
842 _theViewPanel->RefreshInterface();
843 //wxVtk2DBaseView *wxvtk2dbaseview = (wxVtk2DBaseView*)this->_theViewPanel->getWxVtkBaseView();
844 //wxvtk2dbaseview->Refresh();
847 vtkImageData* wxContourMainFrame::getImageData(){
848 return _theViewPanel->getImageData();
851 void wxContourMainFrame::onSegmentationOneSlice(int isovalue,int sampling,int method){
853 //JCP 20-10-08 Undo redo implementation
855 //JCP 20-10-08 Undo redo implementation
858 int x = _theViewPanel->GetX();
859 int y = _theViewPanel->GetY();
860 int z = _theViewPanel->GetZ();
861 SegmentationOneSlice( x,y,z,isovalue, sampling, method );
865 void wxContourMainFrame::SegmentationOneSlice( int x, int y, int z, int isovalue, int sampling, int method )
867 int typeofcontour = 1;
868 //--Extracting Contour
869 //vtkImageData *imagedata = _theViewPanel->getSceneManager()->GetImageData();
870 vtkImageData *imagedata = getImageData();
871 // double *range = imagedata->GetScalarRange();
874 vtkImageReslice *imageReslice = vtkImageReslice::New();
877 // imagedata->GetSpacing(spc);
882 imageReslice->SetInput( imagedata );
883 imageReslice->SetInformationInput(imagedata);
884 imageReslice->SetResliceAxesDirectionCosines(1,0,0, 0,1,0 ,0,0,1);
885 imageReslice->SetResliceAxesOrigin(0,0,z);
886 imageReslice->SetOutputDimensionality(2);
887 imageReslice->SetInterpolationModeToLinear();
889 imagedata = imageReslice->GetOutput();
891 imagedata->UpdateInformation();
893 vtkContourFilter* cntVTK = vtkContourFilter::New( );
894 cntVTK->SetInput( imagedata );
896 cntVTK->SetNumberOfContours( 1 );
897 //cntVTK->SetValue( 0, vmin );
898 // cntVTK->SetValue( 0, (range[1]*thr/100) );
899 cntVTK->SetValue( 1, isovalue );
900 // cntVTK->SetValue( 1, vmax );
902 cntVTK->UpdateInformation();
904 vtkCleanPolyData* cpd = vtkCleanPolyData::New( );
905 cpd->SetInput( cntVTK->GetOutput( ) );
906 cpd->ConvertLinesToPointsOff( );
908 cpd->UpdateInformation();
910 vtkPolyDataConnectivityFilter* conn = vtkPolyDataConnectivityFilter::New( );
911 conn->SetExtractionModeToClosestPointRegion( );
912 //conn->SetMaxRecursionDepth( 3000 );
914 conn->SetInput( cpd->GetOutput( ) );
916 conn->SetClosestPoint( x, y, 0 );
918 conn->UpdateInformation();
920 vtkCleanPolyData* cpd2 = vtkCleanPolyData::New( );
921 cpd2->SetInput( conn->GetOutput( ) );
923 cpd2->UpdateInformation();
925 vtkStripper* vtkstripper = vtkStripper::New( );
926 vtkstripper->SetInput( cpd2->GetOutput() );
927 vtkstripper->Update();
928 vtkstripper->UpdateInformation();
931 vtkPolyData* polyDataResult = vtkstripper->GetOutput();
933 polyDataResult->Update( );
934 polyDataResult->UpdateInformation();
938 myfile.open ("c:/temp/example.txt");
940 polyDataResult->Print(myfile);
941 myfile << "-------------------------------------\n";
942 polyDataResult->GetLines()->Print(myfile);
952 //--Calculating control points
954 std::vector<double> vecX;
955 std::vector<double> vecY;
956 std::vector<double> vecZ;
958 std::vector<double> vecCtrlPointX;
959 std::vector<double> vecCtrlPointY;
960 std::vector<double> vecCtrlPointZ;
964 int ii,size=polyDataResult->GetNumberOfPoints();
966 for (ii=1;ii<=size;ii++)
968 id = polyDataResult->GetLines()->GetData()->GetValue(ii);
969 p = polyDataResult->GetPoint(id);
972 vecX.push_back( p[0] );
973 vecY.push_back( p[1] );
974 vecZ.push_back( -900 );
975 // vecZ.push_back( p[2] );
979 ExtractControlPoints2D *extractcontrolpoints2d = new ExtractControlPoints2D();
980 extractcontrolpoints2d->SetContour( &vecX , &vecY , &vecZ );
983 /*if (methodRadiobox->GetSelection()==0){
984 extractcontrolpoints2d->GetInitialControlPoints( &vecCtrlPointX , &vecCtrlPointY , &vecCtrlPointZ );
986 if (methodRadiobox->GetSelection()==1){
987 extractcontrolpoints2d->GetControlPoints( &vecCtrlPointX , &vecCtrlPointY , &vecCtrlPointZ );
989 if (methodRadiobox->GetSelection()==2){
990 extractcontrolpoints2d->SetSamplingControlPoints( sampling );
991 extractcontrolpoints2d->GetSamplingControlPoints( &vecCtrlPointX , &vecCtrlPointY , &vecCtrlPointZ );
995 extractcontrolpoints2d->GetInitialControlPoints( &vecCtrlPointX , &vecCtrlPointY , &vecCtrlPointZ );
998 extractcontrolpoints2d->GetControlPoints( &vecCtrlPointX , &vecCtrlPointY , &vecCtrlPointZ );
1000 else if (method==2){
1001 extractcontrolpoints2d->SetSamplingControlPoints( sampling );
1002 extractcontrolpoints2d->GetSamplingControlPoints( &vecCtrlPointX , &vecCtrlPointY , &vecCtrlPointZ );
1005 //--Adding contour to the system
1007 std::vector<int> actualInstantVector;
1008 _instantPanel->getInstant( actualInstantVector );
1009 actualInstantVector[1]=z;
1011 int j,sizeCtrPt = vecCtrlPointX.size();
1012 manualContourModel *manModelContour = kernelManager->factoryManualContourModel( typeofcontour );
1013 manModelContour->SetNumberOfPointsSpline( ((sizeCtrPt/100)+1)*100 );
1015 for (j=0 ; j<sizeCtrPt ; j++)
1017 manModelContour->AddPoint( vecCtrlPointX[j] , vecCtrlPointY[j] , vecCtrlPointZ[j] );
1019 std::string theName;
1020 //theName = _modelManager->createOutline( manModelContour, actualInstantVector );
1021 theName = kernelManager->createOutline( manModelContour, actualInstantVector );
1022 bool addedModel = theName.compare("") != 0;
1025 double spc[3];//Si no hay imagen pero hay contornos que spacing se pone por default
1026 _theViewPanel->getSpacing(spc);
1027 //Adding the manualContourControler to interface objects structure
1028 //Adding the manualViewContour to interface objects structure
1029 //_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.
1030 _theViewPanel->configureViewControlTo(theName, manModelContour, spc, typeofcontour);
1031 //_theViewPanel->getSceneManager()->configureViewControlTo( theName, manModelContour,spc, typeofcontour ) ;
1036 int wxContourMainFrame::GetImageDataSizeZ(){
1037 return _theViewPanel->GetImageDataSizeZ();
1040 void wxContourMainFrame::GetImageDataRange(double *range){
1041 _theViewPanel->GetImageDataRange(range);
1044 void wxContourMainFrame::onSegmentationAllSlice(int minZ,int maxZ,int isovalue,int sampling,int method){
1045 //JCP 20-10-08 Undo redo implementation
1047 //JCP 20-10-08 Undo redo implementation
1050 int x = _theViewPanel->GetX();
1051 int y = _theViewPanel->GetY();
1055 double totalZ = maxZ-minZ+1;
1056 for( z=minZ ; z<=maxZ ; z++ )
1058 porcent = 100.0* (z-minZ)/totalZ;
1059 tmpString.Printf(_T(" %d %c %d/%d %d"), (int)porcent , 37 , z-minZ+1, (int)totalZ,z );
1060 interfMainPanel::getInstance()->setLabelSegmentationPanelVTK(tmpString);
1061 //_staticTextSegmentation->SetLabel(tmpString);
1062 SegmentationOneSlice( x,y,z,isovalue, sampling,method );
1064 interfMainPanel::getInstance()->setLabelSegmentationPanelVTK(_T(" "));
1068 void wxContourMainFrame::showAxis(bool show){
1069 _theViewPanel->SetVisibleAxis(show);
1070 _theViewPanel->Refresh();
1074 void wxContourMainFrame::onRigidPressed(){
1075 std::vector<std::string> currentSelection = _theViewPanel->getSelectedObjects();
1076 int elementsSelected = currentSelection.size();
1078 if ( elementsSelected >= 1 ){
1079 //JCP 20-10-08 Undo redo implementation
1081 //JCP 20-10-08 Undo redo implementation
1083 std::vector<int> tempVector;
1084 _instantPanel->getInstant( tempVector );
1085 Instant instant(&tempVector);
1087 int i , size=currentSelection.size();
1088 for ( i=0 ; i<size ; i++ )
1090 kernelManager->changeContourOfManager(currentSelection[i], &instant);
1095 void wxContourMainFrame::onWidthOfContour(double width){
1097 _theViewPanel->removeSceneContours();
1098 _theViewPanel->SetWidthContour(width);
1100 //_theViewPanel->getSceneManager()->SetWidthContour( width );
1104 int wxContourMainFrame::getColorWindow(){
1105 return _theViewPanel->getColorWindow();
1107 int wxContourMainFrame::getWindowLevel(){
1108 return _theViewPanel->getWindowLevel();
1111 void wxContourMainFrame::onBrigthnessColorWindowLevel(int colorwindow,int windowlevel){
1112 _theViewPanel->onBrigthnessColorWindowLevel(colorwindow, windowlevel);
1118 void wxContourMainFrame::onInterpolation(bool interpolate){
1119 _theViewPanel->onInterpolation(interpolate);
1123 void wxContourMainFrame::onChangeInstant(std::string name,int actual){
1124 _instantPanel->setConceptValue( name, actual );
1127 void wxContourMainFrame::resetAppend(){
1128 kernelManager->resetAppend();
1132 void wxContourMainFrame::onSpreadAdd(){
1133 std::vector<double> vecX;
1134 std::vector<double> vecY;
1135 std::vector<double> vecZ;
1136 _theViewPanel->GetPointsOfActualContour(&vecX , &vecY , &vecZ );
1138 std::vector<int> tempVector;
1139 _instantPanel->getInstant( tempVector );
1141 std::string val = kernelManager->onSpreadAdd(&vecX , &vecY , &vecZ, tempVector);
1143 interfMainPanel::getInstance()->appendStringSpread(val);
1147 void wxContourMainFrame::onSpreadGo(int type){
1149 //JCP 20-10-08 Undo redo implementation
1151 //JCP 20-10-08 Undo redo implementation
1154 std::vector<double> vecCtrlPointX;
1155 std::vector<double> vecCtrlPointY;
1156 std::vector<double> vecCtrlPointZ;
1160 std::vector<int> tempVector;
1161 _instantPanel->getInstant( tempVector );
1164 kernelManager->getMaxMinZ(&minZ,&maxZ);
1165 //JSTG_16-07-08_----------------------------------------------------------------
1166 //_contourPropagation->setInterpolationNumber(maxZ-minZ+1);
1167 kernelManager->CalculeSplinePropagation();
1169 double totalZ = maxZ-minZ+1;
1172 //--------------------------------------------------------------------
1173 for ( z=(int)minZ ; z<=(int)maxZ ; z++ )
1175 porcent = 100.0* (z-minZ)/totalZ;
1176 int numero = (int)(z-minZ+1)/(int)totalZ;
1177 std::string stringtemp = " "+kernelManager->intToString(porcent)+"% "+kernelManager->intToString(numero)+" "+kernelManager->intToString(z);
1179 interfMainPanel::getInstance()->setStringSpread(stringtemp);
1181 int typeofcontour = 1;
1182 std::string theName;
1183 manualContourModel* manModelContour = kernelManager->GetPoints(z, type, &vecCtrlPointX,&vecCtrlPointY,&vecCtrlPointZ, theName,typeofcontour, tempVector);
1185 if( manModelContour!=NULL ){
1186 double spc[3];//Si no hay imagen pero hay contornos que spacing se pone por default
1187 this->_theViewPanel->getSpacing(spc);
1188 //Adding the manualContourControler to interface objects structure
1189 //Adding the manualViewContour to interface objects structure
1190 //_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.
1191 _theViewPanel->configureViewControlTo( theName, manModelContour,spc,typeofcontour ) ;
1196 int numero = (int)(z-minZ+1)/(int)totalZ;
1197 std::string stringtemp = " "+kernelManager->intToString(porcent)+"% "+kernelManager->intToString(numero)+" "+kernelManager->intToString(z);
1199 interfMainPanel::getInstance()->setStringSpread(stringtemp);
1201 //RefreshInterface();
1204 void wxContourMainFrame::getInstantVector(std::vector<int>& tempVector){
1208 std::vector<std::string> wxContourMainFrame::getOutlinesName(int slide){
1209 std::vector<int> tempVector;
1210 _instantPanel->getInstant(tempVector);
1211 //Asignation of slide number should be different ex by name
1212 tempVector[1]=slide;
1213 return kernelManager->getOutlinesNameAtInstant(tempVector);
1216 void wxContourMainFrame::onInformationContourLabels(int typeContourGroup,int selection,int minimumZ,int maximumZ){
1217 int maxContourGroup = 0;
1219 ContourExtractData *contourextractdata = new ContourExtractData();
1221 contourextractdata ->SetTypeOperation( typeContourGroup % 3 );
1223 std::vector<manualContourModel*> lstManConMod;
1224 std::vector<manualContourModel*> lstManConModTmp;
1225 std::vector<manualContourModel*> lstManConModExp;
1226 std::vector<double> pLstValue;
1227 std::vector<double> pLstValuePosX;
1228 std::vector<double> pLstValuePosY;
1229 std::vector<double> pLstValuePosZ;
1232 int resultGrayRangeCount;
1235 double resultAverage;
1236 double resultStandardeviation;
1238 std::vector<int> tempVector;
1239 _instantPanel->getInstant( tempVector );
1241 vtkImageData *imagedata = _theViewPanel->getImageData();
1242 int sizeZ = _theViewPanel->GetImageDataSizeZ();
1244 int ii,sizeLstContourThings;
1254 if (selection==0 ) // actual slice
1256 std::vector<int> tempVector;
1257 _instantPanel->getInstant( tempVector );
1258 int actualSlice = tempVector[1];
1262 else if (selection==2 ) // All slices
1267 else if (selection==1 ) // slice range
1274 totalZ = maxZ-minZ+1;
1275 contourextractdata->SetImage( imagedata);
1278 for ( z=minZ ; z<=maxZ ; z++ )
1281 porcent = 100.0* (z-minZ)/totalZ;
1282 tmpString.Printf(_T(" %d %c %d/%d %d"), (int)porcent , 37 , z-minZ+1, (int)totalZ ,z);
1284 interfMainPanel::getInstance()->setStringInfoPanel(tmpString);
1285 //_staticTextInformation->SetLabel(tmpString);
1287 //Extraction data from contours of each slice
1288 contourextractdata->SetZtoBeAnalys( z);
1291 Instant instant(&tempVector);
1292 std::vector<ContourThing**> lstContourThings = kernelManager->getOutlinesAtInstant( &instant );
1293 sizeLstContourThings = lstContourThings.size();
1295 lstManConMod.clear();
1296 for (ii=0 ; ii<sizeLstContourThings ; ii++)
1298 ContourThing **contourthing = lstContourThings[ii];
1299 lstManConMod.push_back( (*contourthing)->getModel() );
1301 lstManConModExp = kernelManager->ExploseEachModel( lstManConMod );
1304 wxString tempString;
1305 tempString.Printf(_T("%d - %d"),z, sizeLstContourThings);
1306 interfMainPanel::getInstance()->setRowLabelInfoPanel(z, tempString);
1307 //_grid->SetRowLabelValue(z, tempString );
1309 int iContourGroup,sizeContourGroup;
1310 if (typeContourGroup==3) // contour separete
1312 sizeContourGroup=lstManConModExp.size();
1313 if ( maxContourGroup<sizeContourGroup )
1315 maxContourGroup=sizeContourGroup;
1317 } else { // contour AND OR XOR
1326 for( iContourGroup=0 ; iContourGroup<sizeContourGroup ; iContourGroup++ ){
1327 lstManConModTmp.clear();
1328 if (typeContourGroup==3) // contour separete
1330 lstManConModTmp.push_back( lstManConModExp[iContourGroup]);
1331 } else { // contour AND OR XOR
1332 lstManConModTmp = lstManConModExp;
1335 contourextractdata->SetLstManualContourModel( lstManConModTmp );
1338 pLstValuePosX.clear();
1339 pLstValuePosY.clear();
1340 pLstValuePosZ.clear();
1341 contourextractdata->GetValuesInsideCrown( &pLstValue,
1345 // Statistics of each slice.
1346 contourextractdata->Statistics( &pLstValue,
1349 &resultGrayRangeCount,
1354 &resultStandardeviation);
1356 if (interfMainPanel::getInstance()->getNumberColsInformationPanel()<_numberOfVariablesStatistics*(iContourGroup+1) )
1358 interfMainPanel::getInstance()->appendColsInformationPanel(_numberOfVariablesStatistics);
1361 tmpIntA=_numberOfVariablesStatistics*iContourGroup ;
1363 tempString.Printf(_T("%d"),resultSize);
1364 interfMainPanel::getInstance()->setCellValueInfoPanel(z, tmpIntA, tempString);
1366 tempString.Printf(_T("%d"),resultGrayRangeCount);
1367 interfMainPanel::getInstance()->setCellValueInfoPanel(z, tmpIntA+1, tempString);
1369 tempString.Printf(_T("%f"),resultMin);
1370 interfMainPanel::getInstance()->setCellValueInfoPanel(z, tmpIntA+2, tempString);
1372 tempString.Printf(_T("%f"),resultMax);
1373 interfMainPanel::getInstance()->setCellValueInfoPanel(z, tmpIntA+3, tempString);
1375 tempString.Printf(_T("%f"),resultAverage);
1376 interfMainPanel::getInstance()->setCellValueInfoPanel(z, tmpIntA+4, tempString);
1378 tempString.Printf(_T("%f"),resultStandardeviation);
1379 interfMainPanel::getInstance()->setCellValueInfoPanel(z, tmpIntA+5, tempString);
1382 } // for iContourGroup
1386 wxString tmpTitleString;
1388 for ( iTitleGroup=0 ; iTitleGroup<maxContourGroup ; iTitleGroup++ )
1390 tmpIntB =_numberOfVariablesStatistics*iTitleGroup;
1391 tmpTitleString.Printf(_T("%d-Size Data"),iTitleGroup);
1392 interfMainPanel::getInstance()->setColLableInfoPanel(tmpIntB + 0, tmpTitleString);
1394 interfMainPanel::getInstance()->setColLableInfoPanel(tmpIntB + 0, tmpTitleString );
1395 interfMainPanel::getInstance()->setColLableInfoPanel( tmpIntB + 1, _T("Size Range") );
1396 interfMainPanel::getInstance()->setColLableInfoPanel( tmpIntB + 2, _T("Min") );
1397 interfMainPanel::getInstance()->setColLableInfoPanel( tmpIntB + 3, _T("Max") );
1398 interfMainPanel::getInstance()->setColLableInfoPanel( tmpIntB + 4, _T("Average") );
1399 interfMainPanel::getInstance()->setColLableInfoPanel( tmpIntB + 5, _T("St.Dev.") );
1400 interfMainPanel::getInstance()->setColLableInfoPanel( tmpIntB + 6, _T(" ") );
1403 interfMainPanel::getInstance()->setStringInfoPanel( _T("") );
1404 delete contourextractdata;
1407 void wxContourMainFrame::onSaveResults(std::string directory,std::string namefile, std::string filename, int typeContourGroup){
1408 SaveValuesXYZ( directory , namefile, typeContourGroup );
1409 SaveImageResult( directory , namefile, typeContourGroup);
1412 FILE *pFile=fopen(filename.c_str(),"w+");
1414 int sizeZ = _theViewPanel->GetImageDataSizeZ();
1417 int i,j,maxX,maxY=sizeZ;
1418 maxX= interfMainPanel::getInstance()->getNumberColsInformationPanel();//this->_grid->GetNumberCols();
1420 int iTitle,sizeTitle = (maxX / _numberOfVariablesStatistics);
1421 for ( iTitle=0; iTitle<sizeTitle ; iTitle++)
1423 fprintf(pFile,"-- \t %d-Size \t SizeRange \t Min \t Max \t Ave \t StDv \t" , iTitle,tmpString.c_str() );
1425 fprintf(pFile,"\n" );
1429 for ( j=0; j<maxY ; j++)
1431 fprintf(pFile,"%d\t" , j );
1432 for (i=0 ; i<maxX ; i++){
1433 tmpString = interfMainPanel::getInstance()->getCellValue(j, i);//_grid->GetCellValue( j , i );
1434 fprintf(pFile,"%s\t" , (const char *)(tmpString.mb_str()) );
1436 fprintf(pFile,"\n" );
1442 void wxContourMainFrame::SaveValuesXYZ(std::string directory,std::string namefile,int typeContourGroup)
1445 ContourExtractData *contourextractdata = new ContourExtractData();
1446 //int typeContourGroup = this->_radiolstboxContourGroup->GetSelection();
1447 contourextractdata ->SetTypeOperation( typeContourGroup % 3 );
1449 std::vector<manualContourModel*> lstManConMod;
1450 std::vector<manualContourModel*> lstManConModTmp;
1451 std::vector<manualContourModel*> lstManConModExp;
1452 std::vector<double> pLstValue;
1453 std::vector<double> pLstValuePosX;
1454 std::vector<double> pLstValuePosY;
1455 std::vector<double> pLstValuePosZ;
1457 std::vector<int> tempVector;
1458 _instantPanel->getInstant( tempVector );
1460 vtkImageData *imagedata = _theViewPanel->getSceneManager()->GetImageData();
1461 int sizeZ = _theViewPanel->getSceneManager()->GetImageDataSizeZ();
1463 int ii,sizeLstContourThings;
1470 minZ = 0;// _mbarrange->GetStart();
1471 maxZ = sizeZ;//_mbarrange->GetEnd();
1472 totalZ = maxZ-minZ+1;
1474 contourextractdata->SetImage( imagedata);
1477 for ( z=0 ; z<sizeZ ; z++)
1480 porcent = 100.0* (z-minZ)/totalZ;
1482 tmpString.Printf(_T("Saving Values"));
1483 tmpString.Printf(_T(" %d %c %d/%d %d"), (int)porcent , 37 , z-minZ+1, (int)totalZ ,z);
1484 interfMainPanel::getInstance()->setStringInfoPanel(tmpString);
1485 //_staticTextInformation->SetLabel(tmpString);
1488 //Extraction data from contours of each slice
1489 contourextractdata->SetZtoBeAnalys( z);
1492 Instant instant(&tempVector);
1493 std::vector<ContourThing**> lstContourThings = kernelManager->getOutlinesAtInstant(&instant);//this->_modelManager->getOutlinesAtInstant( &instant );
1494 sizeLstContourThings = lstContourThings.size();
1496 lstManConMod.clear();
1497 for (ii=0 ; ii<sizeLstContourThings ; ii++)
1499 ContourThing **contourthing = lstContourThings[ii];
1500 lstManConMod.push_back( (*contourthing)->getModel() );
1502 lstManConModExp = kernelManager->ExploseEachModel( lstManConMod );
1507 int iContourGroup,sizeContourGroup;
1508 if (typeContourGroup==3) // contour separete
1510 sizeContourGroup=lstManConModExp.size();
1511 } else { // contour AND OR XOR
1515 for( iContourGroup=0 ; iContourGroup<sizeContourGroup ; iContourGroup++ ){
1516 lstManConModTmp.clear();
1517 if (typeContourGroup==3) // contour separete
1519 lstManConModTmp.push_back( lstManConModExp[iContourGroup]);
1520 } else { // contour AND OR XOR
1521 lstManConModTmp = lstManConModExp;
1524 contourextractdata->SetLstManualContourModel( lstManConModTmp );
1527 pLstValuePosX.clear();
1528 pLstValuePosY.clear();
1529 pLstValuePosZ.clear();
1530 contourextractdata->GetValuesInsideCrown( &pLstValue,
1535 std::string temp = directory + "/" + namefile + "-slice";
1536 temp = temp + kernelManager->intToString(z) + "-cont" + kernelManager->intToString(iContourGroup);
1537 temp = temp + ".txt";
1539 // LG 14/01/09 : using crea
1540 wxString filename = crea::std2wx(temp);
1541 /*filename.Printf(_T("%s"),directory.c_str());
1542 filename.append(_T("\\"));
1543 filename.append(_T("%s"),namefile.c_str());
1544 filename.append(_T("-slice"));
1545 filename.append(_T("%d"),z);
1546 filename.append(_T("-cont"));
1547 filename.append(_T("%d"),iContourGroup);
1548 filename.append(_T(".txt"));*/
1549 // filename.Printf(temp.c_str());
1553 FILE *pFile=fopen((const char *)filename.mb_str(),"w+");
1554 fprintf(pFile,"value \t x \t y \t z\n" );
1555 int iLstValue,sizeLstValue=pLstValue.size();
1556 for (iLstValue=0 ; iLstValue<sizeLstValue ; iLstValue++ )
1558 fprintf(pFile,"%f\t %f\t %f\t %f\n", (float)pLstValue[iLstValue] , (float)pLstValuePosX[iLstValue], (float)pLstValuePosY[iLstValue], (float)z );
1561 } // for iContourGroup
1563 interfMainPanel::getInstance()->setStringInfoPanel(_T(""));
1564 //_staticTextInformation->SetLabel( _T("") );
1565 delete contourextractdata;
1568 void wxContourMainFrame::SaveImageResult(std::string directory,std::string namefile, int typeContourGroup)
1571 ContourExtractData *contourextractdata = new ContourExtractData( true );
1572 //int typeContourGroup = this->_radiolstboxContourGroup->GetSelection();
1573 if (typeContourGroup==3)
1577 contourextractdata ->SetTypeOperation( typeContourGroup % 3 );
1579 std::vector<manualContourModel*> lstManConMod;
1580 std::vector<manualContourModel*> lstManConModTmp;
1581 std::vector<manualContourModel*> lstManConModExp;
1583 std::vector<int> tempVector;
1584 _instantPanel->getInstant( tempVector );
1586 vtkImageData *imagedata = _theViewPanel->getImageData();
1587 int sizeZ = _theViewPanel->GetImageDataSizeZ();
1589 int ii,sizeLstContourThings;
1598 minZ = 0;// _mbarrange->GetStart();
1599 maxZ = sizeZ;//_mbarrange->GetEnd();
1600 totalZ = maxZ-minZ+1;
1602 contourextractdata->SetImage( imagedata);
1605 for ( z=0 ; z<sizeZ ; z++)
1608 porcent = 100.0* (z-minZ)/totalZ;
1609 tmpString.Printf(_T("Saving Values"));
1610 tmpString.Printf(_T("%d %c %d/%d %d"), (int)porcent , 37 , z-minZ+1, (int)totalZ ,z);
1611 interfMainPanel::getInstance()->setStringInfoPanel(tmpString);
1613 //Extraction data from contours of each slice
1614 contourextractdata->SetZtoBeAnalys( z);
1617 Instant instant(&tempVector);
1618 std::vector<ContourThing**> lstContourThings = kernelManager->getOutlinesAtInstant( &instant );
1619 sizeLstContourThings = lstContourThings.size();
1621 lstManConMod.clear();
1622 for (ii=0 ; ii<sizeLstContourThings ; ii++)
1624 ContourThing **contourthing = lstContourThings[ii];
1625 lstManConMod.push_back( (*contourthing)->getModel() );
1627 lstManConModExp = kernelManager->ExploseEachModel( lstManConMod );
1630 int iContourGroup,sizeContourGroup;
1631 if (typeContourGroup==3) // contour separete
1633 sizeContourGroup=lstManConModExp.size();
1634 } else { // contour AND OR XOR
1638 for( iContourGroup=0 ; iContourGroup<sizeContourGroup ; iContourGroup++ ){
1639 lstManConModTmp.clear();
1640 if (typeContourGroup==3) // contour separete
1642 lstManConModTmp.push_back( lstManConModExp[iContourGroup]);
1643 } else { // contour AND OR XOR
1644 lstManConModTmp = lstManConModExp;
1647 contourextractdata->SetLstManualContourModel( lstManConModTmp );
1650 // for (ii=0 ; ii<sizeLstContourThings ; ii++)
1652 // ContourThing **contourthing = lstContourThings[ii];
1653 // lstManConMod.push_back( (*contourthing)->getModel() );
1655 // contourextractdata->SetLstManualContourModel( lstManConMod );
1657 contourextractdata->CalculateImageResult(); // with actual Z
1659 } // for iContourGroup
1662 std::string temp = directory + "/" + namefile + "-Value.mhd";
1664 wxString filename = crea::std2wx(temp);
1666 // filename.Printf(_T(temp.c_str()));
1667 //filename.Printf(_T("%s\\%s-Value.mhd",directory.c_str(),namefile.c_str(),z);
1668 /*filename.Printf(_T("%s"),directory.c_str());
1669 filename.append(_T("\\"));
1670 filename.append(_T("%s"),namefile.c_str());
1671 filename.append(_T("-Value.mhd"));*/
1674 vtkMetaImageWriter *writerValueImage = vtkMetaImageWriter::New( );
1675 writerValueImage->SetInput( contourextractdata->GetVtkImageValueResult() );
1676 writerValueImage->SetFileName( (const char *)filename.mb_str() );
1677 writerValueImage->SetFileDimensionality( 3 );
1678 writerValueImage->Write( );
1681 // filename.Printf("%s\\%s-Mask.mhd",directory.c_str(),namefile.c_str(),z);
1682 temp = directory + "/" + namefile + "-Mask.mhd";
1684 // LG 14/01/09 : using crea
1685 filename = crea::std2wx(temp);
1686 // filename.Printf(_T(temp.c_str()));
1688 /*filename.Printf(_T("%s"),directory.c_str());
1689 filename.append(_T("\\"));
1690 filename.append(_T("%s"),namefile.c_str());
1691 filename.append(_T("-Mask.mhd"));*/
1693 vtkMetaImageWriter *writerMaskImage = vtkMetaImageWriter::New( );
1694 writerMaskImage->SetInput( contourextractdata->GetVtkImageMaskResult() );
1695 writerMaskImage->SetFileName( (const char *)filename.mb_str() );
1696 writerMaskImage->SetFileDimensionality( 3 );
1697 writerMaskImage->Write( );
1699 interfMainPanel::getInstance()->setStringInfoPanel( _T("") );
1700 delete contourextractdata;
1703 void wxContourMainFrame::onChangeInstantInstantPanel(std::string name,int value, int minshow, int maxshow){
1704 if( name.compare( _theViewPanel->getVerticalConceptName() ) == 0){
1705 _theViewPanel->setActualVertical( value);
1707 else if( name.compare( _theViewPanel->getHorizontalConceptName() ) == 0|| _instantPanel->getIfConceptCheckedAt( name, 0 ) ) {
1708 _theViewPanel->setHorizontalConcept( name, minshow, maxshow, minshow, maxshow, value);
1714 void wxContourMainFrame::onSnakePressed(){
1715 std::vector<double> vecX;
1716 std::vector<double> vecY;
1717 std::vector<double> vecZ;
1718 _theViewPanel->GetPointsOfActualContour( &vecX , &vecY , &vecZ );
1720 if (vecX.size()!=0){
1721 std::vector<int> tempVector;
1722 _instantPanel->getInstant( tempVector );
1723 int i,size=vecZ.size();
1724 int actualSlice = tempVector[1];
1725 for ( i=0 ; i<size ; i++ )
1727 vecZ[i] = actualSlice;
1730 wxDialog* dialog = new wxDialog(this, -1, wxString(_T("Snake")));
1731 wxPanel* panel = new wxPanel(dialog,-1);
1732 wxStaticText* sttext = new wxStaticText(panel, -1, wxString(_T("Panel para snake")));
1733 dialog->ShowModal();