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);
615 int z = _instantPanel->getConceptDataOf("Axe Depth")->getActualValue();
616 _theViewPanel->setImageSlice(z);
619 void wxContourMainFrame::updateInstantAxes(){
622 void wxContourMainFrame::onChangeDeep(int val){
623 _instantPanel->setConceptValue( "Axe Depth", (int)val );
628 void wxContourMainFrame::onCopy(){
629 std::vector<std::string> currentSelection = _theViewPanel->getSelectedObjects();
631 std::vector<int> tempVector;
632 _instantPanel->getInstant( tempVector );
633 _performingOperation->reset();
634 _performingOperation->setStartCommand( COPY );
635 _performingOperation->setStartOperationInstantVector( tempVector );
636 _performingOperation->setKeyNamesOperationElems( currentSelection );
638 void wxContourMainFrame::onPaste(){
641 char theStartCommand = _performingOperation->getStartCommand();
642 if ( theStartCommand == COPY )
644 //JCP 20-10-08 Undo redo implementation
646 //JCP 20-10-08 Undo redo implementation
647 std::vector<int> tempVector;
648 _instantPanel->getInstant( tempVector );
649 _performingOperation->setEndOperationInstantVector ( tempVector );
650 std::vector<std::string> elems = _performingOperation->getKeyNamesOperationElems();
651 int i,size = elems.size();
652 for( i=0; i<size; i++ )
654 createCopyContourOf( elems[i], tempVector, i>0 );
658 void wxContourMainFrame::onUndo(){
659 std::string filename;
660 if(kernelManager->onUndoSaveFile(filename)){
661 saveFileWithContours(filename);
663 if(kernelManager->onUndo(filename)){
667 void wxContourMainFrame::onRedo(){
668 std::string filename;
669 if(kernelManager->onRedo(filename)){
674 void wxContourMainFrame :: createCopyContourOf ( std::string anExistingKName, std::vector<int> &instantNoTouchData, bool append ){
675 std::string cloneName = kernelManager->createCopyContourOf( anExistingKName, instantNoTouchData );
676 manualContourModel * manualModel = kernelManager->getOutlineByKeyName(cloneName);//_modelManager->getOutlineByKeyName( cloneName )->getModel();
677 _theViewPanel->getSceneManager()->createCopyContourOf( anExistingKName, cloneName, manualModel , append );
680 void wxContourMainFrame ::loadState(std::string filename){
682 FILE *pFile=fopen(filename.c_str(),"r+");
684 fscanf(pFile,"%s",tmp); // --CreaContour--
686 fscanf(pFile,"%s",tmp); // Version
687 fscanf(pFile,"%s",tmp); // 1.0.1
688 std::string version(tmp);
692 openContours(pFile,false);
693 if (version!="1.0.0"){
694 openContours(pFile,true);
699 //_theViewPanel->getSceneManager()->removeSceneContours();
704 void wxContourMainFrame::onLoad(){
706 wxFileDialog dialog(NULL, _T("Choose a file"), _T(""), _T(""), _T("*.roi"), wxOPEN );
707 if (dialog.ShowModal() == wxID_OK)
709 std::string fileNameContourROI = (const char *)(dialog.GetPath().mb_str());
710 FILE *pFile=fopen(fileNameContourROI.c_str(),"r+");
712 fscanf(pFile,"%s",tmp); // --CreaContour--
714 fscanf(pFile,"%s",tmp); // Version
715 fscanf(pFile,"%s",tmp); // 1.0.1
716 std::string version(tmp);
718 openContours(pFile,false);
719 if (version!="1.0.0"){
720 openContours(pFile,true);
722 // _theViewPanel->getSceneManager()->openFileWithContours(ff);
726 _theViewPanel->getSceneManager()->removeSceneContours();
729 void wxContourMainFrame::onSave(){
730 wxFileDialog dialog(NULL, _T("Choose a file"), _T(""), _T(""), _T("*.roi"), wxSAVE );
731 if (dialog.ShowModal() == wxID_OK)
733 std::string fileNameContourROI = (const char *)(dialog.GetPath().mb_str());
734 saveFileWithContours( fileNameContourROI );
737 void wxContourMainFrame::saveFileWithContours( std::string filename ){
739 FILE *pFile=fopen(filename.c_str(),"w+");
740 std::vector< std::string > lstNameThings;
741 int i,sizeLstNameThings;
743 fprintf(pFile,"--CreaContour--\n");
744 fprintf(pFile,"Version %s\n", "1.0.1" );
747 lstNameThings = kernelManager->GetLstNameThings();
748 sizeLstNameThings = lstNameThings.size();
749 fprintf(pFile,"NumberOfContours %d\n", sizeLstNameThings );
750 for (i=0 ; i<sizeLstNameThings ; i++)
752 kernelManager->SaveThingName( pFile, lstNameThings[i] );
753 _theViewPanel->getSceneManager()->SaveThingName( pFile, lstNameThings[i] );
756 //-- Contours Statics
757 lstNameThings = kernelManager->GetLstNameThingsStatic();
758 sizeLstNameThings = lstNameThings.size();
759 fprintf(pFile,"NumberOfContoursStatic %d\n", sizeLstNameThings );
760 for (i=0 ; i<sizeLstNameThings ; i++)
762 kernelManager->SaveThingName( pFile, lstNameThings[i] );
763 _theViewPanel->getSceneManager()->SaveThingName( pFile, lstNameThings[i] );
768 void wxContourMainFrame::openContours( FILE *pFile, bool staticContour ){
770 fscanf(pFile,"%s",tmp); // NumberOfContours
771 fscanf(pFile,"%s",tmp); // ##
772 int numberOfContours = atoi(tmp);
774 std::vector<int> instantVector;
775 int typeContourModel;
776 manualContourModel *manModelContour;
780 for (i=0;i<numberOfContours;i++)
782 instantVector.clear();
783 fscanf(pFile,"%s",tmp); // Instant
785 fscanf(pFile,"%s",tmp); // 1
786 instantVector.push_back( atoi(tmp) );
787 fscanf(pFile,"%s",tmp); // 2
788 instantVector.push_back( atoi(tmp) );
789 fscanf(pFile,"%s",tmp); // 3
790 instantVector.push_back( atoi(tmp) );
791 fscanf(pFile,"%s",tmp); // 4
792 instantVector.push_back( atoi(tmp) );
793 fscanf(pFile,"%s",tmp); // 5
794 instantVector.push_back( atoi(tmp) );
795 fscanf(pFile,"%s",tmp); // 6
796 instantVector.push_back( atoi(tmp) );
799 fscanf(pFile,"%s",tmp); // TypeContourModel
800 fscanf(pFile,"%s",tmp); // ##
801 typeContourModel = atoi(tmp);
803 manModelContour = kernelManager->factoryManualContourModel(typeContourModel);
804 manModelContour->Open(pFile);
806 fscanf(pFile,"%s",tmp); // TypeView
807 fscanf(pFile,"%s",tmp); // ##
808 typeView = atoi(tmp);
817 theName = kernelManager->createOutline( manModelContour, instantVector );
818 bool addedModel = theName.compare("") != 0;
821 double spc[3];//Si no hay imagen pero hay contornos que spacing se pone por default
822 _theViewPanel->getSpacing(spc);
823 //Adding the manualContourControler to interface objects structure
824 //Adding the manualViewContour to interface objects structure
825 //_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.
826 _theViewPanel->getSceneManager()->configureViewControlTo( theName, manModelContour,spc , typeView) ;
829 if (staticContour==true)
831 Instant instant(&instantVector);
832 kernelManager->changeContourOfManager( theName , &instant );
835 }// for numberOfContours
839 void wxContourMainFrame::RefreshInterface(){
841 _theViewPanel->RefreshInterface();
842 //wxVtk2DBaseView *wxvtk2dbaseview = (wxVtk2DBaseView*)this->_theViewPanel->getWxVtkBaseView();
843 //wxvtk2dbaseview->Refresh();
846 vtkImageData* wxContourMainFrame::getImageData(){
847 return _theViewPanel->getImageData();
850 void wxContourMainFrame::onSegmentationOneSlice(int isovalue,int sampling,int method){
852 //JCP 20-10-08 Undo redo implementation
854 //JCP 20-10-08 Undo redo implementation
857 int x = _theViewPanel->GetX();
858 int y = _theViewPanel->GetY();
859 int z = _theViewPanel->GetZ();
860 SegmentationOneSlice( x,y,z,isovalue, sampling, method );
864 void wxContourMainFrame::SegmentationOneSlice( int x, int y, int z, int isovalue, int sampling, int method )
866 int typeofcontour = 1;
867 //--Extracting Contour
868 //vtkImageData *imagedata = _theViewPanel->getSceneManager()->GetImageData();
869 vtkImageData *imagedata = getImageData();
870 // double *range = imagedata->GetScalarRange();
873 vtkImageReslice *imageReslice = vtkImageReslice::New();
876 // imagedata->GetSpacing(spc);
881 imageReslice->SetInput( imagedata );
882 imageReslice->SetInformationInput(imagedata);
883 imageReslice->SetResliceAxesDirectionCosines(1,0,0, 0,1,0 ,0,0,1);
884 imageReslice->SetResliceAxesOrigin(0,0,z);
885 imageReslice->SetOutputDimensionality(2);
886 imageReslice->SetInterpolationModeToLinear();
888 imagedata = imageReslice->GetOutput();
890 imagedata->UpdateInformation();
892 vtkContourFilter* cntVTK = vtkContourFilter::New( );
893 cntVTK->SetInput( imagedata );
895 cntVTK->SetNumberOfContours( 1 );
896 //cntVTK->SetValue( 0, vmin );
897 // cntVTK->SetValue( 0, (range[1]*thr/100) );
898 cntVTK->SetValue( 1, isovalue );
899 // cntVTK->SetValue( 1, vmax );
901 cntVTK->UpdateInformation();
903 vtkCleanPolyData* cpd = vtkCleanPolyData::New( );
904 cpd->SetInput( cntVTK->GetOutput( ) );
905 cpd->ConvertLinesToPointsOff( );
907 cpd->UpdateInformation();
909 vtkPolyDataConnectivityFilter* conn = vtkPolyDataConnectivityFilter::New( );
910 conn->SetExtractionModeToClosestPointRegion( );
911 //conn->SetMaxRecursionDepth( 3000 );
913 conn->SetInput( cpd->GetOutput( ) );
915 conn->SetClosestPoint( x, y, 0 );
917 conn->UpdateInformation();
919 vtkCleanPolyData* cpd2 = vtkCleanPolyData::New( );
920 cpd2->SetInput( conn->GetOutput( ) );
922 cpd2->UpdateInformation();
924 vtkStripper* vtkstripper = vtkStripper::New( );
925 vtkstripper->SetInput( cpd2->GetOutput() );
926 vtkstripper->Update();
927 vtkstripper->UpdateInformation();
930 vtkPolyData* polyDataResult = vtkstripper->GetOutput();
932 polyDataResult->Update( );
933 polyDataResult->UpdateInformation();
937 myfile.open ("c:/temp/example.txt");
939 polyDataResult->Print(myfile);
940 myfile << "-------------------------------------\n";
941 polyDataResult->GetLines()->Print(myfile);
951 //--Calculating control points
953 std::vector<double> vecX;
954 std::vector<double> vecY;
955 std::vector<double> vecZ;
957 std::vector<double> vecCtrlPointX;
958 std::vector<double> vecCtrlPointY;
959 std::vector<double> vecCtrlPointZ;
963 int ii,size=polyDataResult->GetNumberOfPoints();
965 for (ii=1;ii<=size;ii++)
967 id = polyDataResult->GetLines()->GetData()->GetValue(ii);
968 p = polyDataResult->GetPoint(id);
971 vecX.push_back( p[0] );
972 vecY.push_back( p[1] );
973 vecZ.push_back( -900 );
974 // vecZ.push_back( p[2] );
978 ExtractControlPoints2D *extractcontrolpoints2d = new ExtractControlPoints2D();
979 extractcontrolpoints2d->SetContour( &vecX , &vecY , &vecZ );
982 /*if (methodRadiobox->GetSelection()==0){
983 extractcontrolpoints2d->GetInitialControlPoints( &vecCtrlPointX , &vecCtrlPointY , &vecCtrlPointZ );
985 if (methodRadiobox->GetSelection()==1){
986 extractcontrolpoints2d->GetControlPoints( &vecCtrlPointX , &vecCtrlPointY , &vecCtrlPointZ );
988 if (methodRadiobox->GetSelection()==2){
989 extractcontrolpoints2d->SetSamplingControlPoints( sampling );
990 extractcontrolpoints2d->GetSamplingControlPoints( &vecCtrlPointX , &vecCtrlPointY , &vecCtrlPointZ );
994 extractcontrolpoints2d->GetInitialControlPoints( &vecCtrlPointX , &vecCtrlPointY , &vecCtrlPointZ );
997 extractcontrolpoints2d->GetControlPoints( &vecCtrlPointX , &vecCtrlPointY , &vecCtrlPointZ );
1000 extractcontrolpoints2d->SetSamplingControlPoints( sampling );
1001 extractcontrolpoints2d->GetSamplingControlPoints( &vecCtrlPointX , &vecCtrlPointY , &vecCtrlPointZ );
1004 //--Adding contour to the system
1006 std::vector<int> actualInstantVector;
1007 _instantPanel->getInstant( actualInstantVector );
1008 actualInstantVector[1]=z;
1010 int j,sizeCtrPt = vecCtrlPointX.size();
1011 manualContourModel *manModelContour = kernelManager->factoryManualContourModel( typeofcontour );
1012 manModelContour->SetNumberOfPointsSpline( ((sizeCtrPt/100)+1)*100 );
1014 for (j=0 ; j<sizeCtrPt ; j++)
1016 manModelContour->AddPoint( vecCtrlPointX[j] , vecCtrlPointY[j] , vecCtrlPointZ[j] );
1018 std::string theName;
1019 //theName = _modelManager->createOutline( manModelContour, actualInstantVector );
1020 theName = kernelManager->createOutline( manModelContour, actualInstantVector );
1021 bool addedModel = theName.compare("") != 0;
1024 double spc[3];//Si no hay imagen pero hay contornos que spacing se pone por default
1025 _theViewPanel->getSpacing(spc);
1026 //Adding the manualContourControler to interface objects structure
1027 //Adding the manualViewContour to interface objects structure
1028 //_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.
1029 _theViewPanel->configureViewControlTo(theName, manModelContour, spc, typeofcontour);
1030 //_theViewPanel->getSceneManager()->configureViewControlTo( theName, manModelContour,spc, typeofcontour ) ;
1035 int wxContourMainFrame::GetImageDataSizeZ(){
1036 return _theViewPanel->GetImageDataSizeZ();
1039 void wxContourMainFrame::GetImageDataRange(double *range){
1040 _theViewPanel->GetImageDataRange(range);
1043 void wxContourMainFrame::onSegmentationAllSlice(int minZ,int maxZ,int isovalue,int sampling,int method){
1044 //JCP 20-10-08 Undo redo implementation
1046 //JCP 20-10-08 Undo redo implementation
1049 int x = _theViewPanel->GetX();
1050 int y = _theViewPanel->GetY();
1054 double totalZ = maxZ-minZ+1;
1055 for( z=minZ ; z<=maxZ ; z++ )
1057 porcent = 100.0* (z-minZ)/totalZ;
1058 tmpString.Printf(_T(" %d %c %d/%d %d"), (int)porcent , 37 , z-minZ+1, (int)totalZ,z );
1059 interfMainPanel::getInstance()->setLabelSegmentationPanelVTK(tmpString);
1060 //_staticTextSegmentation->SetLabel(tmpString);
1061 SegmentationOneSlice( x,y,z,isovalue, sampling,method );
1063 interfMainPanel::getInstance()->setLabelSegmentationPanelVTK(_T(" "));
1067 void wxContourMainFrame::showAxis(bool show){
1068 _theViewPanel->SetVisibleAxis(show);
1069 _theViewPanel->Refresh();
1073 void wxContourMainFrame::onRigidPressed(){
1074 std::vector<std::string> currentSelection = _theViewPanel->getSelectedObjects();
1075 int elementsSelected = currentSelection.size();
1077 if ( elementsSelected >= 1 ){
1078 //JCP 20-10-08 Undo redo implementation
1080 //JCP 20-10-08 Undo redo implementation
1082 std::vector<int> tempVector;
1083 _instantPanel->getInstant( tempVector );
1084 Instant instant(&tempVector);
1086 int i , size=currentSelection.size();
1087 for ( i=0 ; i<size ; i++ )
1089 kernelManager->changeContourOfManager(currentSelection[i], &instant);
1094 void wxContourMainFrame::onWidthOfContour(double width){
1096 _theViewPanel->removeSceneContours();
1097 _theViewPanel->SetWidthContour(width);
1099 //_theViewPanel->getSceneManager()->SetWidthContour( width );
1103 int wxContourMainFrame::getColorWindow(){
1104 return _theViewPanel->getColorWindow();
1106 int wxContourMainFrame::getWindowLevel(){
1107 return _theViewPanel->getWindowLevel();
1110 void wxContourMainFrame::onBrigthnessColorWindowLevel(int colorwindow,int windowlevel){
1111 _theViewPanel->onBrigthnessColorWindowLevel(colorwindow, windowlevel);
1117 void wxContourMainFrame::onInterpolation(bool interpolate){
1118 _theViewPanel->onInterpolation(interpolate);
1122 void wxContourMainFrame::onChangeInstant(std::string name,int actual){
1123 _instantPanel->setConceptValue( name, actual );
1126 void wxContourMainFrame::resetAppend(){
1127 kernelManager->resetAppend();
1131 void wxContourMainFrame::onSpreadAdd(){
1132 std::vector<double> vecX;
1133 std::vector<double> vecY;
1134 std::vector<double> vecZ;
1135 _theViewPanel->GetPointsOfActualContour(&vecX , &vecY , &vecZ );
1137 std::vector<int> tempVector;
1138 _instantPanel->getInstant( tempVector );
1140 std::string val = kernelManager->onSpreadAdd(&vecX , &vecY , &vecZ, tempVector);
1142 interfMainPanel::getInstance()->appendStringSpread(val);
1146 void wxContourMainFrame::onSpreadGo(int type){
1148 //JCP 20-10-08 Undo redo implementation
1150 //JCP 20-10-08 Undo redo implementation
1153 std::vector<double> vecCtrlPointX;
1154 std::vector<double> vecCtrlPointY;
1155 std::vector<double> vecCtrlPointZ;
1159 std::vector<int> tempVector;
1160 _instantPanel->getInstant( tempVector );
1163 kernelManager->getMaxMinZ(&minZ,&maxZ);
1164 //JSTG_16-07-08_----------------------------------------------------------------
1165 //_contourPropagation->setInterpolationNumber(maxZ-minZ+1);
1166 kernelManager->CalculeSplinePropagation();
1168 double totalZ = maxZ-minZ+1;
1171 //--------------------------------------------------------------------
1172 for ( z=(int)minZ ; z<=(int)maxZ ; z++ )
1174 porcent = 100.0* (z-minZ)/totalZ;
1175 int numero = (int)(z-minZ+1)/(int)totalZ;
1176 std::string stringtemp = " "+kernelManager->intToString(porcent)+"% "+kernelManager->intToString(numero)+" "+kernelManager->intToString(z);
1178 interfMainPanel::getInstance()->setStringSpread(stringtemp);
1180 int typeofcontour = 1;
1181 std::string theName;
1182 manualContourModel* manModelContour = kernelManager->GetPoints(z, type, &vecCtrlPointX,&vecCtrlPointY,&vecCtrlPointZ, theName,typeofcontour, tempVector);
1184 if( manModelContour!=NULL ){
1185 double spc[3];//Si no hay imagen pero hay contornos que spacing se pone por default
1186 this->_theViewPanel->getSpacing(spc);
1187 //Adding the manualContourControler to interface objects structure
1188 //Adding the manualViewContour to interface objects structure
1189 //_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.
1190 _theViewPanel->configureViewControlTo( theName, manModelContour,spc,typeofcontour ) ;
1195 int numero = (int)(z-minZ+1)/(int)totalZ;
1196 std::string stringtemp = " "+kernelManager->intToString(porcent)+"% "+kernelManager->intToString(numero)+" "+kernelManager->intToString(z);
1198 interfMainPanel::getInstance()->setStringSpread(stringtemp);
1200 //RefreshInterface();
1203 void wxContourMainFrame::getInstantVector(std::vector<int>& tempVector){
1207 std::vector<std::string> wxContourMainFrame::getOutlinesName(int slide){
1208 std::vector<int> tempVector;
1209 _instantPanel->getInstant(tempVector);
1210 //Asignation of slide number should be different ex by name
1211 tempVector[1]=slide;
1212 return kernelManager->getOutlinesNameAtInstant(tempVector);
1215 void wxContourMainFrame::onInformationContourLabels(int typeContourGroup,int selection,int minimumZ,int maximumZ){
1216 int maxContourGroup = 0;
1218 ContourExtractData *contourextractdata = new ContourExtractData();
1220 contourextractdata ->SetTypeOperation( typeContourGroup % 3 );
1222 std::vector<manualContourModel*> lstManConMod;
1223 std::vector<manualContourModel*> lstManConModTmp;
1224 std::vector<manualContourModel*> lstManConModExp;
1225 std::vector<double> pLstValue;
1226 std::vector<double> pLstValuePosX;
1227 std::vector<double> pLstValuePosY;
1228 std::vector<double> pLstValuePosZ;
1231 int resultGrayRangeCount;
1234 double resultAverage;
1235 double resultStandardeviation;
1237 std::vector<int> tempVector;
1238 _instantPanel->getInstant( tempVector );
1240 vtkImageData *imagedata = _theViewPanel->getImageData();
1241 int sizeZ = _theViewPanel->GetImageDataSizeZ();
1243 int ii,sizeLstContourThings;
1253 if (selection==0 ) // actual slice
1255 std::vector<int> tempVector;
1256 _instantPanel->getInstant( tempVector );
1257 int actualSlice = tempVector[1];
1261 else if (selection==2 ) // All slices
1266 else if (selection==1 ) // slice range
1273 totalZ = maxZ-minZ+1;
1274 contourextractdata->SetImage( imagedata);
1277 for ( z=minZ ; z<=maxZ ; z++ )
1280 porcent = 100.0* (z-minZ)/totalZ;
1281 tmpString.Printf(_T(" %d %c %d/%d %d"), (int)porcent , 37 , z-minZ+1, (int)totalZ ,z);
1283 interfMainPanel::getInstance()->setStringInfoPanel(tmpString);
1284 //_staticTextInformation->SetLabel(tmpString);
1286 //Extraction data from contours of each slice
1287 contourextractdata->SetZtoBeAnalys( z);
1290 Instant instant(&tempVector);
1291 std::vector<ContourThing**> lstContourThings = kernelManager->getOutlinesAtInstant( &instant );
1292 sizeLstContourThings = lstContourThings.size();
1294 lstManConMod.clear();
1295 for (ii=0 ; ii<sizeLstContourThings ; ii++)
1297 ContourThing **contourthing = lstContourThings[ii];
1298 lstManConMod.push_back( (*contourthing)->getModel() );
1300 lstManConModExp = kernelManager->ExploseEachModel( lstManConMod );
1303 wxString tempString;
1304 tempString.Printf(_T("%d - %d"),z, sizeLstContourThings);
1305 interfMainPanel::getInstance()->setRowLabelInfoPanel(z, tempString);
1306 //_grid->SetRowLabelValue(z, tempString );
1308 int iContourGroup,sizeContourGroup;
1309 if (typeContourGroup==3) // contour separete
1311 sizeContourGroup=lstManConModExp.size();
1312 if ( maxContourGroup<sizeContourGroup )
1314 maxContourGroup=sizeContourGroup;
1316 } else { // contour AND OR XOR
1325 for( iContourGroup=0 ; iContourGroup<sizeContourGroup ; iContourGroup++ ){
1326 lstManConModTmp.clear();
1327 if (typeContourGroup==3) // contour separete
1329 lstManConModTmp.push_back( lstManConModExp[iContourGroup]);
1330 } else { // contour AND OR XOR
1331 lstManConModTmp = lstManConModExp;
1334 contourextractdata->SetLstManualContourModel( lstManConModTmp );
1337 pLstValuePosX.clear();
1338 pLstValuePosY.clear();
1339 pLstValuePosZ.clear();
1340 contourextractdata->GetValuesInsideCrown( &pLstValue,
1344 // Statistics of each slice.
1345 contourextractdata->Statistics( &pLstValue,
1348 &resultGrayRangeCount,
1353 &resultStandardeviation);
1355 if (interfMainPanel::getInstance()->getNumberColsInformationPanel()<_numberOfVariablesStatistics*(iContourGroup+1) )
1357 interfMainPanel::getInstance()->appendColsInformationPanel(_numberOfVariablesStatistics);
1360 tmpIntA=_numberOfVariablesStatistics*iContourGroup ;
1362 tempString.Printf(_T("%d"),resultSize);
1363 interfMainPanel::getInstance()->setCellValueInfoPanel(z, tmpIntA, tempString);
1365 tempString.Printf(_T("%d"),resultGrayRangeCount);
1366 interfMainPanel::getInstance()->setCellValueInfoPanel(z, tmpIntA+1, tempString);
1368 tempString.Printf(_T("%f"),resultMin);
1369 interfMainPanel::getInstance()->setCellValueInfoPanel(z, tmpIntA+2, tempString);
1371 tempString.Printf(_T("%f"),resultMax);
1372 interfMainPanel::getInstance()->setCellValueInfoPanel(z, tmpIntA+3, tempString);
1374 tempString.Printf(_T("%f"),resultAverage);
1375 interfMainPanel::getInstance()->setCellValueInfoPanel(z, tmpIntA+4, tempString);
1377 tempString.Printf(_T("%f"),resultStandardeviation);
1378 interfMainPanel::getInstance()->setCellValueInfoPanel(z, tmpIntA+5, tempString);
1381 } // for iContourGroup
1385 wxString tmpTitleString;
1387 for ( iTitleGroup=0 ; iTitleGroup<maxContourGroup ; iTitleGroup++ )
1389 tmpIntB =_numberOfVariablesStatistics*iTitleGroup;
1390 tmpTitleString.Printf(_T("%d-Size Data"),iTitleGroup);
1391 interfMainPanel::getInstance()->setColLableInfoPanel(tmpIntB + 0, tmpTitleString);
1393 interfMainPanel::getInstance()->setColLableInfoPanel(tmpIntB + 0, tmpTitleString );
1394 interfMainPanel::getInstance()->setColLableInfoPanel( tmpIntB + 1, _T("Size Range") );
1395 interfMainPanel::getInstance()->setColLableInfoPanel( tmpIntB + 2, _T("Min") );
1396 interfMainPanel::getInstance()->setColLableInfoPanel( tmpIntB + 3, _T("Max") );
1397 interfMainPanel::getInstance()->setColLableInfoPanel( tmpIntB + 4, _T("Average") );
1398 interfMainPanel::getInstance()->setColLableInfoPanel( tmpIntB + 5, _T("St.Dev.") );
1399 interfMainPanel::getInstance()->setColLableInfoPanel( tmpIntB + 6, _T(" ") );
1402 interfMainPanel::getInstance()->setStringInfoPanel( _T("") );
1403 delete contourextractdata;
1406 void wxContourMainFrame::onSaveResults(std::string directory,std::string namefile, std::string filename, int typeContourGroup){
1407 SaveValuesXYZ( directory , namefile, typeContourGroup );
1408 SaveImageResult( directory , namefile, typeContourGroup);
1411 FILE *pFile=fopen(filename.c_str(),"w+");
1413 int sizeZ = _theViewPanel->GetImageDataSizeZ();
1416 int i,j,maxX,maxY=sizeZ;
1417 maxX= interfMainPanel::getInstance()->getNumberColsInformationPanel();//this->_grid->GetNumberCols();
1419 int iTitle,sizeTitle = (maxX / _numberOfVariablesStatistics);
1420 for ( iTitle=0; iTitle<sizeTitle ; iTitle++)
1422 fprintf(pFile,"-- \t %d-Size \t SizeRange \t Min \t Max \t Ave \t StDv \t" , iTitle,tmpString.c_str() );
1424 fprintf(pFile,"\n" );
1428 for ( j=0; j<maxY ; j++)
1430 fprintf(pFile,"%d\t" , j );
1431 for (i=0 ; i<maxX ; i++){
1432 tmpString = interfMainPanel::getInstance()->getCellValue(j, i);//_grid->GetCellValue( j , i );
1433 fprintf(pFile,"%s\t" , (const char *)(tmpString.mb_str()) );
1435 fprintf(pFile,"\n" );
1441 void wxContourMainFrame::SaveValuesXYZ(std::string directory,std::string namefile,int typeContourGroup)
1444 ContourExtractData *contourextractdata = new ContourExtractData();
1445 //int typeContourGroup = this->_radiolstboxContourGroup->GetSelection();
1446 contourextractdata ->SetTypeOperation( typeContourGroup % 3 );
1448 std::vector<manualContourModel*> lstManConMod;
1449 std::vector<manualContourModel*> lstManConModTmp;
1450 std::vector<manualContourModel*> lstManConModExp;
1451 std::vector<double> pLstValue;
1452 std::vector<double> pLstValuePosX;
1453 std::vector<double> pLstValuePosY;
1454 std::vector<double> pLstValuePosZ;
1456 std::vector<int> tempVector;
1457 _instantPanel->getInstant( tempVector );
1459 vtkImageData *imagedata = _theViewPanel->getSceneManager()->GetImageData();
1460 int sizeZ = _theViewPanel->getSceneManager()->GetImageDataSizeZ();
1462 int ii,sizeLstContourThings;
1469 minZ = 0;// _mbarrange->GetStart();
1470 maxZ = sizeZ;//_mbarrange->GetEnd();
1471 totalZ = maxZ-minZ+1;
1473 contourextractdata->SetImage( imagedata);
1476 for ( z=0 ; z<sizeZ ; z++)
1479 porcent = 100.0* (z-minZ)/totalZ;
1481 tmpString.Printf(_T("Saving Values"));
1482 tmpString.Printf(_T(" %d %c %d/%d %d"), (int)porcent , 37 , z-minZ+1, (int)totalZ ,z);
1483 interfMainPanel::getInstance()->setStringInfoPanel(tmpString);
1484 //_staticTextInformation->SetLabel(tmpString);
1487 //Extraction data from contours of each slice
1488 contourextractdata->SetZtoBeAnalys( z);
1491 Instant instant(&tempVector);
1492 std::vector<ContourThing**> lstContourThings = kernelManager->getOutlinesAtInstant(&instant);//this->_modelManager->getOutlinesAtInstant( &instant );
1493 sizeLstContourThings = lstContourThings.size();
1495 lstManConMod.clear();
1496 for (ii=0 ; ii<sizeLstContourThings ; ii++)
1498 ContourThing **contourthing = lstContourThings[ii];
1499 lstManConMod.push_back( (*contourthing)->getModel() );
1501 lstManConModExp = kernelManager->ExploseEachModel( lstManConMod );
1506 int iContourGroup,sizeContourGroup;
1507 if (typeContourGroup==3) // contour separete
1509 sizeContourGroup=lstManConModExp.size();
1510 } else { // contour AND OR XOR
1514 for( iContourGroup=0 ; iContourGroup<sizeContourGroup ; iContourGroup++ ){
1515 lstManConModTmp.clear();
1516 if (typeContourGroup==3) // contour separete
1518 lstManConModTmp.push_back( lstManConModExp[iContourGroup]);
1519 } else { // contour AND OR XOR
1520 lstManConModTmp = lstManConModExp;
1523 contourextractdata->SetLstManualContourModel( lstManConModTmp );
1526 pLstValuePosX.clear();
1527 pLstValuePosY.clear();
1528 pLstValuePosZ.clear();
1529 contourextractdata->GetValuesInsideCrown( &pLstValue,
1534 std::string temp = directory + "/" + namefile + "-slice";
1535 temp = temp + kernelManager->intToString(z) + "-cont" + kernelManager->intToString(iContourGroup);
1536 temp = temp + ".txt";
1539 /*filename.Printf(_T("%s"),directory.c_str());
1540 filename.append(_T("\\"));
1541 filename.append(_T("%s"),namefile.c_str());
1542 filename.append(_T("-slice"));
1543 filename.append(_T("%d"),z);
1544 filename.append(_T("-cont"));
1545 filename.append(_T("%d"),iContourGroup);
1546 filename.append(_T(".txt"));*/
1547 filename.Printf(temp.c_str());
1548 FILE *pFile=fopen((const char *)filename.mb_str(),"w+");
1549 fprintf(pFile,"value \t x \t y \t z\n" );
1550 int iLstValue,sizeLstValue=pLstValue.size();
1551 for (iLstValue=0 ; iLstValue<sizeLstValue ; iLstValue++ )
1553 fprintf(pFile,"%f\t %f\t %f\t %f\n", (float)pLstValue[iLstValue] , (float)pLstValuePosX[iLstValue], (float)pLstValuePosY[iLstValue], (float)z );
1556 } // for iContourGroup
1558 interfMainPanel::getInstance()->setStringInfoPanel(_T(""));
1559 //_staticTextInformation->SetLabel( _T("") );
1560 delete contourextractdata;
1563 void wxContourMainFrame::SaveImageResult(std::string directory,std::string namefile, int typeContourGroup)
1566 ContourExtractData *contourextractdata = new ContourExtractData( true );
1567 //int typeContourGroup = this->_radiolstboxContourGroup->GetSelection();
1568 if (typeContourGroup==3)
1572 contourextractdata ->SetTypeOperation( typeContourGroup % 3 );
1574 std::vector<manualContourModel*> lstManConMod;
1575 std::vector<manualContourModel*> lstManConModTmp;
1576 std::vector<manualContourModel*> lstManConModExp;
1578 std::vector<int> tempVector;
1579 _instantPanel->getInstant( tempVector );
1581 vtkImageData *imagedata = _theViewPanel->getImageData();
1582 int sizeZ = _theViewPanel->GetImageDataSizeZ();
1584 int ii,sizeLstContourThings;
1593 minZ = 0;// _mbarrange->GetStart();
1594 maxZ = sizeZ;//_mbarrange->GetEnd();
1595 totalZ = maxZ-minZ+1;
1597 contourextractdata->SetImage( imagedata);
1600 for ( z=0 ; z<sizeZ ; z++)
1603 porcent = 100.0* (z-minZ)/totalZ;
1604 tmpString.Printf(_T("Saving Values"));
1605 tmpString.Printf(_T("%d %c %d/%d %d"), (int)porcent , 37 , z-minZ+1, (int)totalZ ,z);
1606 interfMainPanel::getInstance()->setStringInfoPanel(tmpString);
1608 //Extraction data from contours of each slice
1609 contourextractdata->SetZtoBeAnalys( z);
1612 Instant instant(&tempVector);
1613 std::vector<ContourThing**> lstContourThings = kernelManager->getOutlinesAtInstant( &instant );
1614 sizeLstContourThings = lstContourThings.size();
1616 lstManConMod.clear();
1617 for (ii=0 ; ii<sizeLstContourThings ; ii++)
1619 ContourThing **contourthing = lstContourThings[ii];
1620 lstManConMod.push_back( (*contourthing)->getModel() );
1622 lstManConModExp = kernelManager->ExploseEachModel( lstManConMod );
1625 int iContourGroup,sizeContourGroup;
1626 if (typeContourGroup==3) // contour separete
1628 sizeContourGroup=lstManConModExp.size();
1629 } else { // contour AND OR XOR
1633 for( iContourGroup=0 ; iContourGroup<sizeContourGroup ; iContourGroup++ ){
1634 lstManConModTmp.clear();
1635 if (typeContourGroup==3) // contour separete
1637 lstManConModTmp.push_back( lstManConModExp[iContourGroup]);
1638 } else { // contour AND OR XOR
1639 lstManConModTmp = lstManConModExp;
1642 contourextractdata->SetLstManualContourModel( lstManConModTmp );
1645 // for (ii=0 ; ii<sizeLstContourThings ; ii++)
1647 // ContourThing **contourthing = lstContourThings[ii];
1648 // lstManConMod.push_back( (*contourthing)->getModel() );
1650 // contourextractdata->SetLstManualContourModel( lstManConMod );
1652 contourextractdata->CalculateImageResult(); // with actual Z
1654 } // for iContourGroup
1657 std::string temp = directory + "/" + namefile + "-Value.mhd";
1660 filename.Printf(_T(temp.c_str()));
1661 //filename.Printf(_T("%s\\%s-Value.mhd",directory.c_str(),namefile.c_str(),z);
1662 /*filename.Printf(_T("%s"),directory.c_str());
1663 filename.append(_T("\\"));
1664 filename.append(_T("%s"),namefile.c_str());
1665 filename.append(_T("-Value.mhd"));*/
1668 vtkMetaImageWriter *writerValueImage = vtkMetaImageWriter::New( );
1669 writerValueImage->SetInput( contourextractdata->GetVtkImageValueResult() );
1670 writerValueImage->SetFileName( (const char *)filename.mb_str() );
1671 writerValueImage->SetFileDimensionality( 3 );
1672 writerValueImage->Write( );
1675 // filename.Printf("%s\\%s-Mask.mhd",directory.c_str(),namefile.c_str(),z);
1676 temp = directory + "/" + namefile + "-Mask.mhd";
1678 filename.Printf(_T(temp.c_str()));
1680 /*filename.Printf(_T("%s"),directory.c_str());
1681 filename.append(_T("\\"));
1682 filename.append(_T("%s"),namefile.c_str());
1683 filename.append(_T("-Mask.mhd"));*/
1685 vtkMetaImageWriter *writerMaskImage = vtkMetaImageWriter::New( );
1686 writerMaskImage->SetInput( contourextractdata->GetVtkImageMaskResult() );
1687 writerMaskImage->SetFileName( (const char *)filename.mb_str() );
1688 writerMaskImage->SetFileDimensionality( 3 );
1689 writerMaskImage->Write( );
1691 interfMainPanel::getInstance()->setStringInfoPanel( _T("") );
1692 delete contourextractdata;
1695 void wxContourMainFrame::onChangeInstantInstantPanel(std::string name,int value, int minshow, int maxshow){
1696 if( name.compare( _theViewPanel->getVerticalConceptName() ) == 0){
1697 _theViewPanel->setActualVertical( value);
1699 else if( name.compare( _theViewPanel->getHorizontalConceptName() ) == 0|| _instantPanel->getIfConceptCheckedAt( name, 0 ) ) {
1700 _theViewPanel->setHorizontalConcept( name, minshow, maxshow, minshow, maxshow, value);
1706 void wxContourMainFrame::onSnakePressed(){
1707 std::vector<double> vecX;
1708 std::vector<double> vecY;
1709 std::vector<double> vecZ;
1710 _theViewPanel->GetPointsOfActualContour( &vecX , &vecY , &vecZ );
1712 if (vecX.size()!=0){
1713 std::vector<int> tempVector;
1714 _instantPanel->getInstant( tempVector );
1715 int i,size=vecZ.size();
1716 int actualSlice = tempVector[1];
1717 for ( i=0 ; i<size ; i++ )
1719 vecZ[i] = actualSlice;
1722 wxDialog* dialog = new wxDialog(this, -1, wxString(_T("Snake")));
1723 wxPanel* panel = new wxPanel(dialog,-1);
1724 wxStaticText* sttext = new wxStaticText(panel, -1, wxString(_T("Panel para snake")));
1725 dialog->ShowModal();