1 //----------------------------------------------------------------------------------------------------------------
2 // Class definition include
3 //----------------------------------------------------------------------------------------------------------------
4 #include "wxContourMainFrame.h"
8 //----------------------------------------------------------------------------------------------------------------
10 //----------------------------------------------------------------------------------------------------------------
13 #include "NameWrapper.h"
14 #include "wx/artprov.h"
15 #include "ConceptDataWrap.h"
17 #include <manualContour.h>
18 //#include "ImageSourceThing.h"
19 //#include "wxContour_ActionCommandsID.h"
20 //#include "OutlineModelBuilder.h"
21 //#include "wxContourEventHandler.h"
24 //----------------------------------------------------------------------------------------------------------------
25 // Class implementation
26 //----------------------------------------------------------------------------------------------------------------
27 /** @file wxContourMainFrame.cxx */
29 //------------------------------------------------------------------------------------------------------------
30 // Constructors & Destructors
31 //------------------------------------------------------------------------------------------------------------
33 wxContourMainFrame* wxContourMainFrame:: instance = NULL;
34 char wxContourMainFrame::COPY = 'C';
36 wxContourMainFrame :: wxContourMainFrame(wxWindow* parent, wxWindowID id,const wxString& title,const wxPoint& pos,const wxSize& size,long style)
37 //: wxPanel(parent, id, title, pos, size, style)
38 //: wxWindow(parent, id, pos, size, style)
39 : wxPanel(parent, id, pos, size, style)
41 m_mgr.SetManagedWindow(this);
42 _creatingContoursActive = false;
44 // _modelManager = NULL;
46 // _buttonsBar = NULL;
48 // _drawToolsPanel = NULL;
49 // _operationsToolsPanel = NULL;
50 //_autoFormsPanel = NULL;
51 // _standardToolsPanel = NULL;
52 // _editionToolsPanel = NULL;
53 // _listViewPanel = NULL;
54 // _sceneManager = NULL;
55 //_actualInstant = NULL;
56 _numberOfVariablesStatistics = 6+1;
58 // set up default notebook style
59 // m_notebook_style =wxAUI_NB_TAB_SPLIT | wxAUI_NB_TAB_EXTERNAL_MOVE | wxNO_BORDER;
60 // m_notebook_theme = 0;
61 //wxContour_ActionCommandsID a;
65 wxContourMainFrame :: wxContourMainFrame(wxWindow* parent, wxWindowID id,const wxString& title,const wxPoint& pos,const wxSize& size,std::vector<vtkImageData*> images, long style,std::string datadir)
66 : wxPanel(parent, id, pos, size, style)
68 m_mgr.SetManagedWindow(this);
69 _creatingContoursActive = false;
71 // _modelManager = NULL;
73 // _buttonsBar = NULL;
75 // _drawToolsPanel = NULL;
76 // _operationsToolsPanel = NULL;
77 // _autoFormsPanel = NULL;
78 // _standardToolsPanel = NULL;
79 // _editionToolsPanel = NULL;
80 // _listViewPanel = NULL;
81 // _sceneManager = NULL;
82 //_actualInstant = NULL;
84 // set up default notebook style
85 m_notebook_style =wxAUI_NB_TAB_SPLIT | wxAUI_NB_TAB_EXTERNAL_MOVE | wxNO_BORDER;
87 //wxContour_ActionCommandsID a;
88 _numberOfVariablesStatistics = 6+1;
91 _performingOperation = new PerformingOperation();
97 kernelManager = new KernelManagerContour(images,datadir+"/data/");
98 //kernelManager->setVectImages(images);
99 //kernelManager->initializeEnvironment();
101 //vtkImageData* selectedimage = kernelManager->getVectImages()[0];
103 //-------------------------------------------------------------
105 /*frame = new wxContourMainFrame(_builder->getImSourceEnv(), _builder->getImSectionEnv(), _builder->getAxesEnv(), _builder->getContourEnv(),NULL, wxID_ANY, wxT("ROI Application Sample"), wxPoint(50,50), wxSize(800, 600));
108 //Creating the evtHandler of the panels
109 //wxContourEventHandler * eventHandler = new wxContourEventHandler();
111 //Creating the window that will show the panels
113 //Getting the parent for the panels ( using aui )
114 wxAuiNotebook * notebook = this->createNotebook();
117 //wxInstantChooserPanel * instantPanel = new wxInstantChooserPanel( notebook, "Instant Chooser", true);
119 std::vector<std::string> conceptNameVect;
120 std::vector<int> conceptSizeVect;
124 _instantPanel = new wxInstantChooserPanel( notebook, "Instant Chooser", true, false, "c" );
125 _theViewPanel = new wxContourViewPanel( kernelManager->getSourceImage(), notebook );
129 kernelManager->getConceptsInformation(conceptNameVect, conceptSizeVect);
130 _instantPanel->addConcepts(conceptNameVect, conceptSizeVect);
133 double val = _theViewPanel->getCurrentDeep();
134 _instantPanel->setConceptValue( "Axe Depth", (int)val );
135 //JCP _instantPanel->setConceptValue("time", num de imagenes);
136 ConceptDataWrap * data = _instantPanel->getConceptDataOf( "Axe Depth" );
137 //*******************changeInstant();
138 _theViewPanel->setVerticalConcept( "Axe Depth", data->getMinValue(), data->getMaxValue(), data->getMinShowedValue(), data->getMaxShowedValue(), data->getActualValue() );
140 //eventHandler->setModelManager( kernelManager->getOutlineModelManager() );
141 //eventHandler->setViewPanel( _theViewPanel );
142 //_theViewPanel->initializeScenceManager();
143 //eventHandler->setInstantChooserPanel( _instantPanel );
145 //bool successConfiuration = eventHandler->configureEventsHandling();
147 //successConfiuration &= this->configurePanels( notebook );
148 this->configurePanels( notebook );
150 interfMainPanel* pannew = interfMainPanel::getInstance(parent,datadir+"/data/Icons");//, eventHandler);
158 wxContourMainFrame* wxContourMainFrame :: getInstance(wxWindow* parent, wxWindowID id,const wxString& title,const wxPoint& pos,const wxSize& size,std::vector<vtkImageData*> images, long style,std::string datadir ){
159 if(instance == NULL){
160 instance = new wxContourMainFrame(parent, id, title, pos, size, images, style,datadir);
165 std::vector<vtkImageData*> wxContourMainFrame ::getVectImages(){
166 return kernelManager->getVectImages();
168 wxContourMainFrame* wxContourMainFrame :: getInstance(){
173 wxContourMainFrame :: ~wxContourMainFrame()
176 //El problema al cerrar la aplicacion puede estar asociado
177 //a que wxAUINotebook esta en la aplicacion
178 //principal (wxContourGUIExample)tambien
179 //EED???? delete _theViewPanel;
180 //EED???? delete _instantPanel;
181 //EED???? delete _buttonsBar;
182 //EED???? delete _actualInstant;
183 //EED???? delete _sceneManager;
187 //------------------------------------------------------------------------------------------------------------
188 // Creational and initialization methods using WxAui
189 //------------------------------------------------------------------------------------------------------------
191 wxAuiNotebook * wxContourMainFrame :: createNotebook()
193 wxSize client_size = GetClientSize();
194 wxAuiNotebook* noteBook = new wxAuiNotebook(this, -1, wxPoint(client_size.x, client_size.y), wxSize(430,200), m_notebook_style);
195 wxBitmap page_bmp = wxArtProvider::GetBitmap(wxART_NORMAL_FILE, wxART_OTHER, wxSize(16,16));
200 //------------------------------------------------------------------------------------------------------------
201 // Creational and initialization methods
202 //------------------------------------------------------------------------------------------------------------
203 bool wxContourMainFrame :: configurePanels(wxAuiNotebook* theNoteBook)
205 bool configured = _theViewPanel!=NULL;
207 configured &= _theViewPanel!=NULL;
208 if( _theViewPanel!=NULL )
210 theNoteBook->AddPage( _theViewPanel, wxT(" View ") );
217 theNoteBook->AddPage( _instantPanel, wxT("Instant Page") );
221 m_mgr.AddPane(theNoteBook, wxAuiPaneInfo().Name(wxT("notebook_content")).CenterPane().PaneBorder(false));
223 /* configured &= _buttonsBar!=NULL;
224 if( _buttonsBar!=NULL )
226 m_mgr.AddPane(_buttonsBar, wxAuiPaneInfo().
227 Name(wxT("TB")).Caption(wxT("Buttons Bar")).
229 LeftDockable( ).RightDockable( false ).CloseButton(false));
234 SetMinSize(wxSize(300,300));
239 void wxContourMainFrame :: setNotebook( wxAuiNotebook * noteBook )
244 //------------------------------------------------------------------------------------------------------------
245 // Attributes getters and setters
246 //------------------------------------------------------------------------------------------------------------
250 void wxContourMainFrame :: setInstantChooserPanel( wxInstantChooserPanel * theInstantChooserPanel )
252 _instantPanel = theInstantChooserPanel;
255 // void wxContourMainFrame :: setButtonsBar( wxContour_ButtonsBar * theButtonsBar )
257 // _buttonsBar = theButtonsBar;
260 // void wxContourMainFrame :: setGrid( wxContour_Grid * theGridPanel )
262 // _gridPanel = theGridPanel;
265 // void wxContourMainFrame :: setDrawToolsPanel( wxContour_DrawToolsPanel * theDrawToolsPanel )
267 // _drawToolsPanel = theDrawToolsPanel;
270 // void wxContourMainFrame :: setOperationsToolsPanel( wxContour_OperationsToolsPanel * theOperationsToolsPanel )
272 // _operationsToolsPanel = theOperationsToolsPanel;
275 // void wxContourMainFrame :: setAutomaticFormsPanel( wxContour_AutomaticFormsToolsPanel * theAutoFormsPanel )
277 // _autoFormsPanel = theAutoFormsPanel;
280 // void wxContourMainFrame :: setStandardToolsPanel( wxContour_StandardToolsPanel * theStandardToolsPanel )
282 // _standardToolsPanel= theStandardToolsPanel;
285 // void wxContourMainFrame :: setEditionToolsPanel( wxContour_EdtionToolsPanel * theEditionToolsPanel )
287 // _editionToolsPanel = theEditionToolsPanel;
290 // void wxContourMainFrame :: setListViewPanel( wxContour_ListViewPanel * theListViewPanel )
292 // _listViewPanel = theListViewPanel;
297 void wxContourMainFrame::onCreateContourSpline( ){
299 //JCP 20-10-08 Undo redo implementation
301 //JCP 20-10-08 Undo redo implementation
305 void wxContourMainFrame::onCreateContourRectangle( ){
306 //JCP 20-10-08 Undo redo implementation
308 //JCP 20-10-08 Undo redo implementation
311 void wxContourMainFrame::onCreateContourCircle( ){
312 //JCP 20-10-08 Undo redo implementation
314 //JCP 20-10-08 Undo redo implementation
318 void wxContourMainFrame::onCreateContourLine( ){
319 //JCP 20-10-08 Undo redo implementation
321 //JCP 20-10-08 Undo redo implementation
325 //------------------------------------------------------------------------------------------------------------
327 void wxContourMainFrame :: onCreateContourBullEye(wxPanel* panel )
329 //Creating the manualContourModel and including in the model
330 manualContourModel * manModelContour = factoryManualContourModel(panel );
332 std::vector<int> instantVector;
333 _instantPanel->getInstant( instantVector );
334 std::string theName = kernelManager->createOutline(manModelContour, instantVector);
336 /*std::vector<int> instantVector;
337 _instantPanel->getInstant( instantVector );
339 theName= _modelManager->createOutline( manModelContour, instantVector );*/
340 bool addedModel = theName.compare("") != 0;//??
344 double spc[3];//Si no hay imagen pero hay contornos que spacing se pone por default
345 _theViewPanel->getSpacing(spc);
346 //Adding the manualContourControler to interface objects structure
347 //Adding the manualViewContour to interface objects structure
348 //_theViewPanel->getSceneManager()->setControlActiveStateOfALL( false );//This call is being done here because if the ROI is created underneath the previously created ROIS will still be active.
349 _theViewPanel->getSceneManager()->configureViewControlTo( theName, manModelContour,spc , 4) ;
352 void wxContourMainFrame :: createContour( int typeContour )
354 //Creating the manualContourModel and including in the model
355 manualContourModel * manModelContour = kernelManager->factoryManualContourModel(typeContour);
358 std::vector<int> instantVector;
359 _instantPanel->getInstant( instantVector );
360 std::string theName = kernelManager->createOutline(manModelContour, instantVector);
362 /*std::vector<int> instantVector;
363 _instantPanel->getInstant( instantVector );
365 theName= _modelManager->createOutline( manModelContour, instantVector );*/
366 bool addedModel = theName.compare("") != 0;//??
369 double spc[3];//Si no hay imagen pero hay contornos que spacing se pone por default
370 _theViewPanel->getSpacing(spc);
371 //Adding the manualContourControler to interface objects structure
372 //Adding the manualViewContour to interface objects structure
373 //_sceneManager->setControlActiveStateOfALL( false );//This call is being done here because if the ROI is created underneath the previously created ROIS will still be active.
374 _theViewPanel->getSceneManager()->configureViewControlTo( theName, manModelContour,spc , typeContour) ;
378 manualContourModel * wxContourMainFrame::factoryManualContourModel(wxPanel* panel){
380 manualContourModelBullEye *manModelContourBullEye = new manualContourModelBullEye();
381 manualContourModel *manModelContour=NULL;
382 manModelContour = manModelContourBullEye;
384 int iCrown,sizeCrowns,iSector,sizeSectors;
385 double radioA,radioB,ang,angDelta ;
386 sizeCrowns = ((PanelBullEyeOptions*)panel)->GetNumberOfCrowns();
387 for ( iCrown=0 ; iCrown<sizeCrowns ; iCrown++ )
389 sizeSectors = ((PanelBullEyeOptions*)panel)->GetNumberOfSections(iCrown);
390 radioB = ((PanelBullEyeOptions*)panel)->GetRadioOfCrown(iCrown);
391 if (iCrown==sizeCrowns-1)
395 radioA = ((PanelBullEyeOptions*)panel)->GetRadioOfCrown(iCrown+1);
399 for ( iSector=0 ; iSector<sizeSectors ; iSector++ )
401 ang = ((PanelBullEyeOptions*)panel)->GetAngOfCrownSection(iCrown,iSector);
402 angDelta= ((PanelBullEyeOptions*)panel)->GetAngDeltaOfCrownSection(iCrown);
403 manModelContourBullEye->AddSector(radioA,radioB,ang,angDelta);
406 } // if _panelBullEyeOptions
408 return manModelContour;
410 void wxContourMainFrame :: saveState(){
412 std::string temp = kernelManager->saveState();
413 saveFileWithContours(temp);
416 void wxContourMainFrame::onDeleteContour(){
417 //JCP 20-10-08 Undo redo implementation
419 //JCP 20-10-08 Undo redo implementation
421 std::vector<std::string> lstKeyNameToBeErase;
422 lstKeyNameToBeErase = _theViewPanel->getSceneManager()->getSelectedObjects();
423 deleteContours( lstKeyNameToBeErase );
425 int i,size=_sceneManager->getSelectedObjects().size();
428 std::string keyName = _sceneManager->getSelectedObjects()[i];
429 int ispartofstaticlist = this->_modelManager->IsPartOfStaticList( keyName );
430 if ( ispartofstaticlist>=0 )
432 std::vector<int> tempVector;
433 _instantPanel->getInstant( tempVector );
434 Instant instant(&tempVector);
435 this->_modelManager->ChangeContourOfList(keyName, &instant);
439 std::vector<std::string> lstKeyName;
440 std::vector<std::string> lstKeyNameActualSlice;
441 std::vector<std::string> lstKeyNameToBeErase;
443 lstKeyNameToBeErase = _sceneManager->getSelectedObjects();
444 lstKeyNameActualSlice = _sceneManager->GetlstContoursNameActualSlice();
445 int k,kSize=lstKeyNameToBeErase.size();
446 int j,jSize=lstKeyNameActualSlice.size();
448 for (k=0;k<kSize; k++)
451 for (j=0;j<jSize; j++)
453 if (lstKeyNameToBeErase[k]==lstKeyNameActualSlice[j])
460 lstKeyName.push_back( lstKeyNameToBeErase[k] );
464 deleteContours( lstKeyName );
468 void wxContourMainFrame :: deleteContours( std::vector<std::string> keyNamesVector )
470 int i,size=keyNamesVector.size();
473 deleteContour( keyNamesVector[i] );
477 void wxContourMainFrame :: deleteContour( std::string theKeyName ){
478 /*manualContourModel * cModel;
479 manualViewBaseContour * cViewer;
480 manualContourBaseControler * cControler;
482 ContourWrap_ViewControl *conwrapviewControl = _theViewPanel->getSceneManager()->getContourWrap_ViewControlOf( theKeyName );
483 cControler = conwrapviewControl->getControler();*/
486 bool isedit = _theViewPanel->isEditableCControler(theKeyName);
487 bool ispartofstaticlst = kernelManager->IsPartOfStaticList(theKeyName);
489 if (isedit && ispartofstaticlst)
491 _theViewPanel->removeFromScene(theKeyName);
493 kernelManager->deleteCModel(theKeyName);
494 //_theViewPanel->getSceneManager()->removeFromScene( theKeyName );
495 //cViewer = conwrapviewControl->getViewer();
496 //_theViewPanel->getSceneManager()->removeWrap( theKeyName );
497 //cControler* conwrapviewControl->getControler();
499 //FILE *ff = fopen("c:/temp/wxVtkBaseView_SceneManagerStadistics.txt","a+");
500 //fprintf(ff,"EED wxContourEventHandler::deleteContours() \n" );
501 //fprintf(ff," %s %p\n",keyNamesVector[i].c_str(), cControler );
505 // delete cControler;
510 void wxContourMainFrame::onDeleteContoursActSlice(){
511 //JCP 20-10-08 Undo redo implementation
513 //JCP 20-10-08 Undo redo implementation
514 deleteContours( (std::vector<std::string>)_theViewPanel->getSceneManager()->GetlstContoursNameActualSlice() );
516 void wxContourMainFrame::onDeleteAllContours(){
517 //JCP 20-10-08 Undo redo implementation
521 void wxContourMainFrame::deleteAllContours(){
522 //JCP 20-10-08 Undo redo implementation
525 std::vector<int> tempVector;
526 _instantPanel->getInstant( tempVector );
528 //JCP --08-09-2008 When using a diferent interface the _mbarrangeDeleteAll might not be initialize
529 // the values in GetStart and GetEnd will then not be initialize also.
530 // We use instead the values given when initializing the _deletepanel.
532 //int minZ = _mbarrangeDeleteAll->GetStart();
533 //int maxZ = _mbarrangeDeleteAll->GetEnd();
537 maxZ = _theViewPanel->getSceneManager()->GetImageDataSizeZ();
541 _theViewPanel->getSceneManager()->removeSceneContours( );
542 _theViewPanel->getSceneManager()->removeAllOutlines();
543 kernelManager->removeAllOutlines();
546 if ( (minZ==0) && (maxZ==_mbarrangeDeleteAll->GetMax() ))
548 _theViewPanel->getSceneManager()->removeSceneContours( );
549 _modelManager->removeAllOutlines();
550 _theViewPanel->getSceneManager()->removeAllOutlines();
553 for ( z=minZ ; z<=maxZ ; z++)
556 Instant instant(&tempVector);
557 std::vector<ContourThing**> lstContourThings = this->_modelManager->getOutlinesAtInstant( &instant );
559 sizeLstContourThings = lstContourThings.size();
560 for (ii=0 ; ii<sizeLstContourThings ; ii++)
562 ContourThing **contourthing = lstContourThings[ii];
563 deleteContour( (*contourthing)->getName() );
570 void wxContourMainFrame::setConceptValue( std::string name, int value ){
571 _instantPanel->setConceptValue(name, value);
574 ConceptDataWrap* wxContourMainFrame::getLastConceptData(){
575 return _instantPanel->getLastConceptData();
577 bool wxContourMainFrame::getIfConceptCheckedAt( std::string name, int pos ){
578 return _instantPanel->getIfConceptCheckedAt( name, pos );
581 void wxContourMainFrame::changeInstant(){
582 std::vector<int> instantVect;
583 _instantPanel->getInstant( instantVect );
584 // Instant * theInstant = new Instant ( &instantVect );
586 //Setting the actual instant
587 //_actualInstant = theInstant;
589 kernelManager->setInstant(instantVect);
590 //_modelManager->setInstant( _actualInstant );
592 updateInstantOutlines();
593 updateInstantImageData();
598 void wxContourMainFrame :: updateInstantOutlines(){
600 _theViewPanel->removeSceneContours();
601 _theViewPanel->addNameWrapperToScene();
603 //for( int i=0; i<size; i++)
605 // _theViewPanel->getSceneManager()->addToScene(namesWrapping[i]->getKeyName(), true, true, true, false, false );
609 int wxContourMainFrame::getNamesWrappingSize(){
610 return kernelManager->getNamesWrappingSize();
612 std::string wxContourMainFrame::getNameWrapping(int i){
613 return kernelManager->getNameWrapping(i);
616 void wxContourMainFrame::updateInstantImageData(){
617 std::vector<int> inst;
618 _instantPanel->getInstant(inst);
620 vtkImageData* img = kernelManager->getImageAtInstant(inst);
622 _theViewPanel->changeImage(img);
625 int z = _instantPanel->getConceptDataOf("Axe Depth")->getActualValue();
626 _theViewPanel->setImageSlice(z);
629 void wxContourMainFrame::updateInstantAxes(){
632 void wxContourMainFrame::onChangeDeep(int val){
633 _instantPanel->setConceptValue( "Axe Depth", (int)val );
638 void wxContourMainFrame::onCopy(){
639 std::vector<std::string> currentSelection = _theViewPanel->getSelectedObjects();
641 std::vector<int> tempVector;
642 _instantPanel->getInstant( tempVector );
643 _performingOperation->reset();
644 _performingOperation->setStartCommand( COPY );
645 _performingOperation->setStartOperationInstantVector( tempVector );
646 _performingOperation->setKeyNamesOperationElems( currentSelection );
649 void wxContourMainFrame::onPaste(){
652 char theStartCommand = _performingOperation->getStartCommand();
653 if ( theStartCommand == COPY )
655 //JCP 20-10-08 Undo redo implementation
657 //JCP 20-10-08 Undo redo implementation
658 std::vector<int> tempVector;
659 _instantPanel->getInstant( tempVector );
660 _performingOperation->setEndOperationInstantVector ( tempVector );
661 std::vector<std::string> elems = _performingOperation->getKeyNamesOperationElems();
662 int i,size = elems.size();
663 for( i=0; i<size; i++ )
665 createCopyContourOf( elems[i], tempVector, i>0 );
669 void wxContourMainFrame::onUndo(){
670 std::string filename;
671 if(kernelManager->onUndoSaveFile(filename)){
672 saveFileWithContours(filename);
674 if(kernelManager->onUndo(filename)){
678 void wxContourMainFrame::onRedo(){
679 std::string filename;
680 if(kernelManager->onRedo(filename)){
685 void wxContourMainFrame :: createCopyContourOf ( std::string anExistingKName, std::vector<int> &instantNoTouchData, bool append )
687 std::string cloneName = kernelManager->createCopyContourOf( anExistingKName, instantNoTouchData );
688 manualContourModel * manualModel = kernelManager->getOutlineByKeyName(cloneName);//_modelManager->getOutlineByKeyName( cloneName )->getModel();
689 _theViewPanel->getSceneManager()->createCopyContourOf( anExistingKName, cloneName, manualModel , append );
692 ///AD: 03-09 Copy the object and apply the given transformation
693 void wxContourMainFrame :: createMirrorContourOf ( std::string anExistingKName, std::vector<int> &instantNoTouchData, bool append )
695 std::string cloneName = kernelManager->createCopyContourOf( anExistingKName, instantNoTouchData );
696 manualContourModel * manualModel = kernelManager->getOutlineByKeyName(cloneName);
697 manualContourModel * refModel = kernelManager->getOutlineByKeyName(_refName);
699 manualPoint * refPoint1 = refModel->GetManualPoint(0);
700 manualPoint * refPoint2 = refModel->GetManualPoint(1);
702 double pnt1X = refPoint1->GetX();
703 double pnt1Y = refPoint1->GetY();
704 double pnt2X = refPoint2->GetX();
705 double pnt2Y = refPoint2->GetY();
706 double angle = (atan2(pnt2Y - pnt1Y, pnt2X - pnt1X) * 180 / 3.1415926535897932384626433832795)+90;
707 printf("ang=%f\n",angle);
708 vtkTransform *t = vtkTransform::New();
712 t->Translate(-pnt1X, -pnt1Y, 0);
716 t->Translate(pnt1X, pnt1Y, 0);
719 int i,size=manualModel->GetSizeLstPoints();
722 manualPoint * mp = manualModel->GetManualPoint(i);
728 t->TransformPoint( vecIn, vecOut );
729 mp->SetPointX( vecOut[0] );
730 mp->SetPointY( vecOut[1] );
731 mp->SetPointZ( vecOut[2] );
734 _theViewPanel->getSceneManager()->createCopyContourOf( anExistingKName, cloneName, manualModel , append );
737 void wxContourMainFrame ::loadState(std::string filename){
739 FILE *pFile=fopen(filename.c_str(),"r+");
741 fscanf(pFile,"%s",tmp); // --CreaContour--
743 fscanf(pFile,"%s",tmp); // Version
744 fscanf(pFile,"%s",tmp); // 1.0.1
745 std::string version(tmp);
749 openContours(pFile,false);
750 if (version!="1.0.0"){
751 openContours(pFile,true);
756 //_theViewPanel->getSceneManager()->removeSceneContours();
761 void wxContourMainFrame::onLoad(){
763 wxFileDialog dialog(NULL, _T("Choose a file"), _T(""), _T(""), _T("*.roi"), wxOPEN );
764 if (dialog.ShowModal() == wxID_OK)
766 std::string fileNameContourROI = (const char *)(dialog.GetPath().mb_str());
767 FILE *pFile=fopen(fileNameContourROI.c_str(),"r+");
769 fscanf(pFile,"%s",tmp); // --CreaContour--
771 fscanf(pFile,"%s",tmp); // Version
772 fscanf(pFile,"%s",tmp); // 1.0.1
773 std::string version(tmp);
775 openContours(pFile,false);
776 if (version!="1.0.0"){
777 openContours(pFile,true);
779 // _theViewPanel->getSceneManager()->openFileWithContours(ff);
783 _theViewPanel->getSceneManager()->removeSceneContours();
786 void wxContourMainFrame::onSave(){
787 wxFileDialog dialog(NULL, _T("Choose a file"), _T(""), _T(""), _T("*.roi"), wxSAVE );
788 if (dialog.ShowModal() == wxID_OK)
790 std::string fileNameContourROI = (const char *)(dialog.GetPath().mb_str());
791 kernelManager->setCurrentFileName(fileNameContourROI);
792 saveFileWithContours( fileNameContourROI );
795 void wxContourMainFrame::saveFileWithContours( std::string filename ){
797 FILE *pFile=fopen(filename.c_str(),"w+");
798 std::vector< std::string > lstNameThings;
799 int i,sizeLstNameThings;
801 fprintf(pFile,"--CreaContour--\n");
802 fprintf(pFile,"Version %s\n", "1.0.1" );
805 lstNameThings = kernelManager->GetLstNameThings();
806 sizeLstNameThings = lstNameThings.size();
807 fprintf(pFile,"NumberOfContours %d\n", sizeLstNameThings );
808 for (i=0 ; i<sizeLstNameThings ; i++)
810 kernelManager->SaveThingName( pFile, lstNameThings[i] );
811 _theViewPanel->getSceneManager()->SaveThingName( pFile, lstNameThings[i] );
814 //-- Contours Statics
815 lstNameThings = kernelManager->GetLstNameThingsStatic();
816 sizeLstNameThings = lstNameThings.size();
817 fprintf(pFile,"NumberOfContoursStatic %d\n", sizeLstNameThings );
818 for (i=0 ; i<sizeLstNameThings ; i++)
820 kernelManager->SaveThingName( pFile, lstNameThings[i] );
821 _theViewPanel->getSceneManager()->SaveThingName( pFile, lstNameThings[i] );
826 void wxContourMainFrame::openContours( FILE *pFile, bool staticContour ){
828 fscanf(pFile,"%s",tmp); // NumberOfContours
829 fscanf(pFile,"%s",tmp); // ##
830 int numberOfContours = atoi(tmp);
832 std::vector<int> instantVector;
833 int typeContourModel;
834 manualContourModel *manModelContour;
838 for (i=0;i<numberOfContours;i++)
840 instantVector.clear();
841 fscanf(pFile,"%s",tmp); // Instant
843 fscanf(pFile,"%s",tmp); // 1
844 instantVector.push_back( atoi(tmp) );
845 fscanf(pFile,"%s",tmp); // 2
846 instantVector.push_back( atoi(tmp) );
847 fscanf(pFile,"%s",tmp); // 3
848 instantVector.push_back( atoi(tmp) );
849 fscanf(pFile,"%s",tmp); // 4
850 instantVector.push_back( atoi(tmp) );
851 fscanf(pFile,"%s",tmp); // 5
852 instantVector.push_back( atoi(tmp) );
853 fscanf(pFile,"%s",tmp); // 6
854 instantVector.push_back( atoi(tmp) );
857 fscanf(pFile,"%s",tmp); // TypeContourModel
858 fscanf(pFile,"%s",tmp); // ##
859 typeContourModel = atoi(tmp);
861 manModelContour = kernelManager->factoryManualContourModel(typeContourModel);
862 manModelContour->Open(pFile);
864 fscanf(pFile,"%s",tmp); // TypeView
865 fscanf(pFile,"%s",tmp); // ##
866 typeView = atoi(tmp);
875 theName = kernelManager->createOutline( manModelContour, instantVector );
876 bool addedModel = theName.compare("") != 0;
879 double spc[3];//Si no hay imagen pero hay contornos que spacing se pone por default
880 _theViewPanel->getSpacing(spc);
881 //Adding the manualContourControler to interface objects structure
882 //Adding the manualViewContour to interface objects structure
883 //_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.
884 _theViewPanel->getSceneManager()->configureViewControlTo( theName, manModelContour,spc , typeView) ;
887 if (staticContour==true)
889 Instant instant(&instantVector);
890 kernelManager->changeContourOfManager( theName , &instant );
893 }// for numberOfContours
897 void wxContourMainFrame::RefreshInterface(){
899 _theViewPanel->RefreshInterface();
900 //wxVtk2DBaseView *wxvtk2dbaseview = (wxVtk2DBaseView*)this->_theViewPanel->getWxVtkBaseView();
901 //wxvtk2dbaseview->Refresh();
904 vtkImageData* wxContourMainFrame::getImageData(){
905 return _theViewPanel->getImageData();
908 void wxContourMainFrame::onSegmentationOneSlice(int isovalue,int sampling,int method){
910 //JCP 20-10-08 Undo redo implementation
912 //JCP 20-10-08 Undo redo implementation
915 int x = _theViewPanel->GetX();
916 int y = _theViewPanel->GetY();
917 int z = _theViewPanel->GetZ();
918 SegmentationOneSlice( x,y,z,isovalue, sampling, method );
923 void wxContourMainFrame::SegmentationOneSlice( int x, int y, int z, int isovalue, int sampling, int method )
925 int typeofcontour = 1;
926 //--Extracting Contour
927 //vtkImageData *imagedata = _theViewPanel->getSceneManager()->GetImageData();
928 vtkImageData *imagedata = getImageData();
929 // double *range = imagedata->GetScalarRange();
932 vtkImageReslice *imageReslice = vtkImageReslice::New();
935 // imagedata->GetSpacing(spc);
940 imageReslice->SetInput( imagedata );
941 imageReslice->SetInformationInput(imagedata);
942 imageReslice->SetResliceAxesDirectionCosines(1,0,0, 0,1,0 ,0,0,1);
943 imageReslice->SetResliceAxesOrigin(0,0,z);
944 imageReslice->SetOutputDimensionality(2);
945 imageReslice->SetInterpolationModeToLinear();
947 imagedata = imageReslice->GetOutput();
949 imagedata->UpdateInformation();
951 vtkContourFilter* cntVTK = vtkContourFilter::New( );
952 cntVTK->SetInput( imagedata );
954 cntVTK->SetNumberOfContours( 1 );
955 //cntVTK->SetValue( 0, vmin );
956 // cntVTK->SetValue( 0, (range[1]*thr/100) );
957 cntVTK->SetValue( 1, isovalue );
958 // cntVTK->SetValue( 1, vmax );
960 cntVTK->UpdateInformation();
962 vtkCleanPolyData* cpd = vtkCleanPolyData::New( );
963 cpd->SetInput( cntVTK->GetOutput( ) );
964 cpd->ConvertLinesToPointsOff( );
966 cpd->UpdateInformation();
968 vtkPolyDataConnectivityFilter* conn = vtkPolyDataConnectivityFilter::New( );
969 conn->SetExtractionModeToClosestPointRegion( );
970 //conn->SetMaxRecursionDepth( 3000 );
972 conn->SetInput( cpd->GetOutput( ) );
974 conn->SetClosestPoint( x, y, 0 );
976 conn->UpdateInformation();
978 vtkCleanPolyData* cpd2 = vtkCleanPolyData::New( );
979 cpd2->SetInput( conn->GetOutput( ) );
981 cpd2->UpdateInformation();
983 vtkStripper* vtkstripper = vtkStripper::New( );
984 vtkstripper->SetInput( cpd2->GetOutput() );
985 vtkstripper->Update();
986 vtkstripper->UpdateInformation();
989 vtkPolyData* polyDataResult = vtkstripper->GetOutput();
991 polyDataResult->Update( );
992 polyDataResult->UpdateInformation();
996 myfile.open ("c:/temp/example.txt");
998 polyDataResult->Print(myfile);
999 myfile << "-------------------------------------\n";
1000 polyDataResult->GetLines()->Print(myfile);
1010 //--Calculating control points
1012 std::vector<double> vecX;
1013 std::vector<double> vecY;
1014 std::vector<double> vecZ;
1016 std::vector<double> vecCtrlPointX;
1017 std::vector<double> vecCtrlPointY;
1018 std::vector<double> vecCtrlPointZ;
1022 int ii,size=polyDataResult->GetNumberOfPoints();
1024 for (ii=1;ii<=size;ii++)
1026 id = polyDataResult->GetLines()->GetData()->GetValue(ii);
1027 p = polyDataResult->GetPoint(id);
1030 vecX.push_back( p[0] );
1031 vecY.push_back( p[1] );
1032 vecZ.push_back( -900 );
1033 // vecZ.push_back( p[2] );
1037 ExtractControlPoints2D *extractcontrolpoints2d = new ExtractControlPoints2D();
1038 extractcontrolpoints2d->SetContour( &vecX , &vecY , &vecZ );
1041 /*if (methodRadiobox->GetSelection()==0){
1042 extractcontrolpoints2d->GetInitialControlPoints( &vecCtrlPointX , &vecCtrlPointY , &vecCtrlPointZ );
1044 if (methodRadiobox->GetSelection()==1){
1045 extractcontrolpoints2d->GetControlPoints( &vecCtrlPointX , &vecCtrlPointY , &vecCtrlPointZ );
1047 if (methodRadiobox->GetSelection()==2){
1048 extractcontrolpoints2d->SetSamplingControlPoints( sampling );
1049 extractcontrolpoints2d->GetSamplingControlPoints( &vecCtrlPointX , &vecCtrlPointY , &vecCtrlPointZ );
1053 extractcontrolpoints2d->GetInitialControlPoints( &vecCtrlPointX , &vecCtrlPointY , &vecCtrlPointZ );
1055 else if (method==1){
1056 extractcontrolpoints2d->GetControlPoints( &vecCtrlPointX , &vecCtrlPointY , &vecCtrlPointZ );
1058 else if (method==2){
1059 extractcontrolpoints2d->SetSamplingControlPoints( sampling );
1060 extractcontrolpoints2d->GetSamplingControlPoints( &vecCtrlPointX , &vecCtrlPointY , &vecCtrlPointZ );
1063 //--Adding contour to the system
1065 std::vector<int> actualInstantVector;
1066 _instantPanel->getInstant( actualInstantVector );
1067 actualInstantVector[1]=z;
1069 int j,sizeCtrPt = vecCtrlPointX.size();
1070 manualContourModel *manModelContour = kernelManager->factoryManualContourModel( typeofcontour );
1071 manModelContour->SetNumberOfPointsSpline( ((sizeCtrPt/100)+1)*100 );
1073 for (j=0 ; j<sizeCtrPt ; j++)
1075 manModelContour->AddPoint( vecCtrlPointX[j] , vecCtrlPointY[j] , vecCtrlPointZ[j] );
1077 std::string theName;
1078 //theName = _modelManager->createOutline( manModelContour, actualInstantVector );
1079 theName = kernelManager->createOutline( manModelContour, actualInstantVector );
1080 bool addedModel = theName.compare("") != 0;
1083 double spc[3];//Si no hay imagen pero hay contornos que spacing se pone por default
1084 _theViewPanel->getSpacing(spc);
1085 //Adding the manualContourControler to interface objects structure
1086 //Adding the manualViewContour to interface objects structure
1087 //_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.
1088 _theViewPanel->configureViewControlTo(theName, manModelContour, spc, typeofcontour);
1089 //_theViewPanel->getSceneManager()->configureViewControlTo( theName, manModelContour,spc, typeofcontour ) ;
1094 int wxContourMainFrame::GetImageDataSizeZ(){
1095 return _theViewPanel->GetImageDataSizeZ();
1098 void wxContourMainFrame::GetImageDataRange(double *range){
1099 _theViewPanel->GetImageDataRange(range);
1102 void wxContourMainFrame::onSegmentationAllSlice(int minZ,int maxZ,int isovalue,int sampling,int method){
1103 //JCP 20-10-08 Undo redo implementation
1105 //JCP 20-10-08 Undo redo implementation
1108 int x = _theViewPanel->GetX();
1109 int y = _theViewPanel->GetY();
1113 double totalZ = maxZ-minZ+1;
1114 for( z=minZ ; z<=maxZ ; z++ )
1116 porcent = 100.0* (z-minZ)/totalZ;
1117 tmpString.Printf(_T(" %d %c %d/%d %d"), (int)porcent , 37 , z-minZ+1, (int)totalZ,z );
1118 interfMainPanel::getInstance()->setLabelSegmentationPanelVTK(tmpString);
1119 //_staticTextSegmentation->SetLabel(tmpString);
1120 SegmentationOneSlice( x,y,z,isovalue, sampling,method );
1122 interfMainPanel::getInstance()->setLabelSegmentationPanelVTK(_T(" "));
1127 //Creates a reference line to be used as the axis of the mirroring
1128 void wxContourMainFrame::referenceLine()
1134 vtkImageData *vtkimagedata = _theViewPanel->getImageData();
1135 vtkimagedata->UpdateInformation();
1136 vtkimagedata->SetUpdateExtent(vtkimagedata->GetWholeExtent());
1137 vtkimagedata->Update();
1138 vtkImageData _data = vtkimagedata;
1139 _data->GetSpacing(spc);
1140 //_vtkbasedata_1 = new vtkBaseData();
1141 //_vtkbasedata_1->SetMarImageData(marimagedata);
1142 //_imageviewer2D_1->SetVtkBaseData( _vtkbasedata_1 );
1143 //_imageviewer2D_1->Configure();
1147 manualContourControler _manContourControl_1 = new manualContourControler();
1148 manualContourModel _mContourModel_1 = new manualContourModel();
1149 manualViewContour _mViewContour_1 = new manualViewContour();
1150 _mViewContour_1->SetModel( _mContourModel_1 );
1151 // _mViewContour_1->SetWxVtkBaseView( _imageviewer2D_1 );
1152 _mViewContour_1->SetRange( 2 );
1153 _mViewContour_1->SetZ( 1200 );
1157 _mViewContour_1->SetSpacing(spc);
1161 _mViewContour_1->SetColorNormalContour(0, 0, 1);
1162 _mViewContour_1->SetColorEditContour(0, 0.5, 0.5);
1164 _manContourControl_1->SetModelView( _mContourModel_1 , _mViewContour_1 );
1165 // _imageviewer2D_1->GetInteractorStyleBaseView()->AddInteractorStyleMaracas( _manContourControl_1 );
1166 _manContourControl_1->CreateNewManualContour();
1167 _manContourControl_1->SetActive(false);
1168 _mViewContour_1->RefreshContour();
1171 // _manRoiControl = new manualRoiControler();
1172 // _mContourModel = new manualContourModel();
1173 // _mViewRoi = new manualViewRoi();
1174 _mViewRoi->SetModel( _mContourModel );
1175 _mViewRoi->SetWxVtkBaseView( _imageviewer2D_1 );
1176 _mViewRoi->SetRange( 2 );
1177 _mViewRoi->SetZ( 1200 );
1180 _mViewRoi->SetSpacing(spc);
1182 // _manRoiControl->SetModelView( _mContourModel , _mViewRoi );
1183 // _imageviewer2D_1->GetInteractorStyleBaseView()->AddInteractorStyleMaracas( _manRoiControl );
1184 // _manRoiControl->CreateNewManualContour();
1185 // _manRoiControl->SetActive(true);
1186 // _mViewRoi->RefreshContour();
1188 CreateNewPoint( 0,0);
1198 //Crea una linea de referencia
1199 manualContourModel * refLine = kernelManager->factoryManualContourModel(6);
1201 std::vector<int> instantVector;
1202 _instantPanel->getInstant( instantVector );
1203 std::string nameLine = kernelManager->createOutline(refLine, instantVector);
1204 bool addedModel = nameLine.compare("") != 0;
1208 _theViewPanel->getSpacing(spc);
1209 _theViewPanel->getSceneManager()->configureViewControlTo( nameLine, refLine,spc , 6);
1212 _refName = nameLine;
1217 void wxContourMainFrame::onMirror()
1220 std::vector<std::string> currentSelection = _theViewPanel->getSelectedObjects();
1221 std::vector<std::string> filterCurrentSelection;
1223 std::vector<std::string>::iterator iter;
1224 for (iter=currentSelection.begin(); iter!=currentSelection.end(); ++iter)
1226 //Diferente de la linea de referencia
1227 if ((_refName.compare(*iter))!=0)
1229 filterCurrentSelection.push_back(*iter);
1233 std::vector<int> tempVector;
1234 _instantPanel->getInstant( tempVector );
1235 _performingOperation->reset();
1236 _performingOperation->setStartCommand( COPY );
1237 _performingOperation->setStartOperationInstantVector( tempVector );
1238 _performingOperation->setKeyNamesOperationElems( filterCurrentSelection );
1241 char theStartCommand = _performingOperation->getStartCommand();
1242 if ( theStartCommand == COPY )
1244 //JCP 20-10-08 Undo redo implementation
1246 //JCP 20-10-08 Undo redo implementation
1247 std::vector<int> tempVector;
1248 _instantPanel->getInstant( tempVector );
1249 _performingOperation->setEndOperationInstantVector ( tempVector );
1250 std::vector<std::string> elems = _performingOperation->getKeyNamesOperationElems();
1251 int i,size = elems.size();
1252 for( i=0; i<size; i++ )
1254 createMirrorContourOf( elems[i], tempVector, i>0 );
1258 deleteContour( _refName );
1262 void wxContourMainFrame::showAxis(bool show){
1263 _theViewPanel->SetVisibleAxis(show);
1264 _theViewPanel->Refresh();
1268 void wxContourMainFrame::onRigidPressed(){
1269 std::vector<std::string> currentSelection = _theViewPanel->getSelectedObjects();
1270 int elementsSelected = currentSelection.size();
1272 if ( elementsSelected >= 1 ){
1273 //JCP 20-10-08 Undo redo implementation
1275 //JCP 20-10-08 Undo redo implementation
1277 std::vector<int> tempVector;
1278 _instantPanel->getInstant( tempVector );
1279 Instant instant(&tempVector);
1281 int i , size=currentSelection.size();
1282 for ( i=0 ; i<size ; i++ )
1284 kernelManager->changeContourOfManager(currentSelection[i], &instant);
1289 void wxContourMainFrame::onWidthOfContour(double width){
1291 _theViewPanel->removeSceneContours();
1292 _theViewPanel->SetWidthContour(width);
1294 //_theViewPanel->getSceneManager()->SetWidthContour( width );
1298 int wxContourMainFrame::getColorWindow(){
1299 return _theViewPanel->getColorWindow();
1301 int wxContourMainFrame::getWindowLevel(){
1302 return _theViewPanel->getWindowLevel();
1305 void wxContourMainFrame::onBrigthnessColorWindowLevel(int colorwindow,int windowlevel){
1306 _theViewPanel->onBrigthnessColorWindowLevel(colorwindow, windowlevel);
1312 void wxContourMainFrame::onInterpolation(bool interpolate){
1313 _theViewPanel->onInterpolation(interpolate);
1317 void wxContourMainFrame::onChangeInstant(std::string name,int actual){
1318 _instantPanel->setConceptValue( name, actual );
1321 void wxContourMainFrame::resetAppend(){
1322 kernelManager->resetAppend();
1326 void wxContourMainFrame::onSpreadAdd(){
1327 std::vector<double> vecX;
1328 std::vector<double> vecY;
1329 std::vector<double> vecZ;
1330 _theViewPanel->GetPointsOfActualContour(&vecX , &vecY , &vecZ );
1332 std::vector<int> tempVector;
1333 _instantPanel->getInstant( tempVector );
1335 std::string val = kernelManager->onSpreadAdd(&vecX , &vecY , &vecZ, tempVector);
1337 interfMainPanel::getInstance()->appendStringSpread(val);
1341 void wxContourMainFrame::onSpreadGo(int type){
1343 //JCP 20-10-08 Undo redo implementation
1345 //JCP 20-10-08 Undo redo implementation
1348 std::vector<double> vecCtrlPointX;
1349 std::vector<double> vecCtrlPointY;
1350 std::vector<double> vecCtrlPointZ;
1354 std::vector<int> tempVector;
1355 _instantPanel->getInstant( tempVector );
1358 kernelManager->getMaxMinZ(&minZ,&maxZ);
1359 //JSTG_16-07-08_----------------------------------------------------------------
1360 //_contourPropagation->setInterpolationNumber(maxZ-minZ+1);
1361 kernelManager->CalculeSplinePropagation();
1363 double totalZ = maxZ-minZ+1;
1366 //--------------------------------------------------------------------
1367 for ( z=(int)minZ ; z<=(int)maxZ ; z++ )
1369 porcent = 100.0* (z-minZ)/totalZ;
1370 int numero = (int)(z-minZ+1)/(int)totalZ;
1371 std::string stringtemp = " "+kernelManager->intToString(porcent)+"% "+kernelManager->intToString(numero)+" "+kernelManager->intToString(z);
1373 interfMainPanel::getInstance()->setStringSpread(stringtemp);
1375 int typeofcontour = 1;
1376 std::string theName;
1377 manualContourModel* manModelContour = kernelManager->GetPoints(z, type, &vecCtrlPointX,&vecCtrlPointY,&vecCtrlPointZ, theName,typeofcontour, tempVector);
1379 if( manModelContour!=NULL ){
1380 double spc[3];//Si no hay imagen pero hay contornos que spacing se pone por default
1381 this->_theViewPanel->getSpacing(spc);
1382 //Adding the manualContourControler to interface objects structure
1383 //Adding the manualViewContour to interface objects structure
1384 //_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.
1385 _theViewPanel->configureViewControlTo( theName, manModelContour,spc,typeofcontour ) ;
1390 int numero = (int)(z-minZ+1)/(int)totalZ;
1391 std::string stringtemp = " "+kernelManager->intToString(porcent)+"% "+kernelManager->intToString(numero)+" "+kernelManager->intToString(z);
1393 interfMainPanel::getInstance()->setStringSpread(stringtemp);
1395 //RefreshInterface();
1398 void wxContourMainFrame::getInstantVector(std::vector<int>& tempVector){
1402 std::vector<std::string> wxContourMainFrame::getOutlinesName(int slide){
1403 std::vector<int> tempVector;
1404 _instantPanel->getInstant(tempVector);
1405 //Asignation of slide number should be different ex by name
1406 tempVector[1]=slide;
1407 return kernelManager->getOutlinesNameAtInstant(tempVector);
1410 void wxContourMainFrame::onInformationContourLabels(int typeContourGroup,int selection,int minimumZ,int maximumZ){
1411 int maxContourGroup = 0;
1413 ContourExtractData *contourextractdata = new ContourExtractData();
1415 contourextractdata ->SetTypeOperation( typeContourGroup % 3 );
1417 std::vector<manualContourModel*> lstManConMod;
1418 std::vector<manualContourModel*> lstManConModTmp;
1419 std::vector<manualContourModel*> lstManConModExp;
1420 std::vector<double> pLstValue;
1421 std::vector<double> pLstValuePosX;
1422 std::vector<double> pLstValuePosY;
1423 std::vector<double> pLstValuePosZ;
1426 int resultGrayRangeCount;
1429 double resultAverage;
1430 double resultStandardeviation;
1432 std::vector<int> tempVector;
1433 _instantPanel->getInstant( tempVector );
1435 vtkImageData *imagedata = _theViewPanel->getImageData();
1436 int sizeZ = _theViewPanel->GetImageDataSizeZ();
1438 int ii,sizeLstContourThings;
1448 if (selection==0 ) // actual slice
1450 std::vector<int> tempVector;
1451 _instantPanel->getInstant( tempVector );
1452 int actualSlice = tempVector[1];
1456 else if (selection==2 ) // All slices
1461 else if (selection==1 ) // slice range
1468 totalZ = maxZ-minZ+1;
1469 contourextractdata->SetImage( imagedata);
1472 for ( z=minZ ; z<=maxZ ; z++ )
1475 porcent = 100.0* (z-minZ)/totalZ;
1476 tmpString.Printf(_T(" %d %c %d/%d %d"), (int)porcent , 37 , z-minZ+1, (int)totalZ ,z);
1478 interfMainPanel::getInstance()->setStringInfoPanel(tmpString);
1479 //_staticTextInformation->SetLabel(tmpString);
1481 //Extraction data from contours of each slice
1482 contourextractdata->SetZtoBeAnalys( z);
1485 Instant instant(&tempVector);
1486 std::vector<ContourThing**> lstContourThings = kernelManager->getOutlinesAtInstant( &instant );
1487 sizeLstContourThings = lstContourThings.size();
1489 lstManConMod.clear();
1490 for (ii=0 ; ii<sizeLstContourThings ; ii++)
1492 ContourThing **contourthing = lstContourThings[ii];
1493 lstManConMod.push_back( (*contourthing)->getModel() );
1495 lstManConModExp = kernelManager->ExploseEachModel( lstManConMod );
1498 wxString tempString;
1499 tempString.Printf(_T("%d - %d"),z, sizeLstContourThings);
1500 interfMainPanel::getInstance()->setRowLabelInfoPanel(z, tempString);
1501 //_grid->SetRowLabelValue(z, tempString );
1503 int iContourGroup,sizeContourGroup;
1504 if (typeContourGroup==3) // contour separete
1506 sizeContourGroup=lstManConModExp.size();
1507 if ( maxContourGroup<sizeContourGroup )
1509 maxContourGroup=sizeContourGroup;
1511 } else { // contour AND OR XOR
1520 for( iContourGroup=0 ; iContourGroup<sizeContourGroup ; iContourGroup++ ){
1521 lstManConModTmp.clear();
1522 if (typeContourGroup==3) // contour separete
1524 lstManConModTmp.push_back( lstManConModExp[iContourGroup]);
1525 } else { // contour AND OR XOR
1526 lstManConModTmp = lstManConModExp;
1529 contourextractdata->SetLstManualContourModel( lstManConModTmp );
1532 pLstValuePosX.clear();
1533 pLstValuePosY.clear();
1534 pLstValuePosZ.clear();
1535 contourextractdata->GetValuesInsideCrown( &pLstValue,
1539 // Statistics of each slice.
1540 contourextractdata->Statistics( &pLstValue,
1543 &resultGrayRangeCount,
1548 &resultStandardeviation);
1550 if (interfMainPanel::getInstance()->getNumberColsInformationPanel()<_numberOfVariablesStatistics*(iContourGroup+1) )
1552 interfMainPanel::getInstance()->appendColsInformationPanel(_numberOfVariablesStatistics);
1555 tmpIntA=_numberOfVariablesStatistics*iContourGroup ;
1557 tempString.Printf(_T("%d"),resultSize);
1558 interfMainPanel::getInstance()->setCellValueInfoPanel(z, tmpIntA, tempString);
1560 tempString.Printf(_T("%d"),resultGrayRangeCount);
1561 interfMainPanel::getInstance()->setCellValueInfoPanel(z, tmpIntA+1, tempString);
1563 tempString.Printf(_T("%f"),resultMin);
1564 interfMainPanel::getInstance()->setCellValueInfoPanel(z, tmpIntA+2, tempString);
1566 tempString.Printf(_T("%f"),resultMax);
1567 interfMainPanel::getInstance()->setCellValueInfoPanel(z, tmpIntA+3, tempString);
1569 tempString.Printf(_T("%f"),resultAverage);
1570 interfMainPanel::getInstance()->setCellValueInfoPanel(z, tmpIntA+4, tempString);
1572 tempString.Printf(_T("%f"),resultStandardeviation);
1573 interfMainPanel::getInstance()->setCellValueInfoPanel(z, tmpIntA+5, tempString);
1576 } // for iContourGroup
1580 wxString tmpTitleString;
1582 for ( iTitleGroup=0 ; iTitleGroup<maxContourGroup ; iTitleGroup++ )
1584 tmpIntB =_numberOfVariablesStatistics*iTitleGroup;
1585 tmpTitleString.Printf(_T("%d-Size Data"),iTitleGroup);
1586 interfMainPanel::getInstance()->setColLableInfoPanel(tmpIntB + 0, tmpTitleString);
1588 interfMainPanel::getInstance()->setColLableInfoPanel(tmpIntB + 0, tmpTitleString );
1589 interfMainPanel::getInstance()->setColLableInfoPanel( tmpIntB + 1, _T("Size Range") );
1590 interfMainPanel::getInstance()->setColLableInfoPanel( tmpIntB + 2, _T("Min") );
1591 interfMainPanel::getInstance()->setColLableInfoPanel( tmpIntB + 3, _T("Max") );
1592 interfMainPanel::getInstance()->setColLableInfoPanel( tmpIntB + 4, _T("Average") );
1593 interfMainPanel::getInstance()->setColLableInfoPanel( tmpIntB + 5, _T("St.Dev.") );
1594 interfMainPanel::getInstance()->setColLableInfoPanel( tmpIntB + 6, _T(" ") );
1597 interfMainPanel::getInstance()->setStringInfoPanel( _T("") );
1598 delete contourextractdata;
1601 void wxContourMainFrame::onSaveResults(std::string directory,std::string namefile, std::string filename, int typeContourGroup){
1602 SaveValuesXYZ( directory , namefile, typeContourGroup );
1603 SaveImageResult( directory , namefile, typeContourGroup);
1606 FILE *pFile=fopen(filename.c_str(),"w+");
1608 int sizeZ = _theViewPanel->GetImageDataSizeZ();
1611 int i,j,maxX,maxY=sizeZ;
1612 maxX= interfMainPanel::getInstance()->getNumberColsInformationPanel();//this->_grid->GetNumberCols();
1614 int iTitle,sizeTitle = (maxX / _numberOfVariablesStatistics);
1615 for ( iTitle=0; iTitle<sizeTitle ; iTitle++)
1617 fprintf(pFile,"-- \t %d-Size \t SizeRange \t Min \t Max \t Ave \t StDv \t" , iTitle,tmpString.c_str() );
1619 fprintf(pFile,"\n" );
1623 for ( j=0; j<maxY ; j++)
1625 fprintf(pFile,"%d\t" , j );
1626 for (i=0 ; i<maxX ; i++){
1627 tmpString = interfMainPanel::getInstance()->getCellValue(j, i);//_grid->GetCellValue( j , i );
1628 fprintf(pFile,"%s\t" , (const char *)(tmpString.mb_str()) );
1630 fprintf(pFile,"\n" );
1636 void wxContourMainFrame::SaveValuesXYZ(std::string directory,std::string namefile,int typeContourGroup)
1639 ContourExtractData *contourextractdata = new ContourExtractData();
1640 //int typeContourGroup = this->_radiolstboxContourGroup->GetSelection();
1641 contourextractdata ->SetTypeOperation( typeContourGroup % 3 );
1643 std::vector<manualContourModel*> lstManConMod;
1644 std::vector<manualContourModel*> lstManConModTmp;
1645 std::vector<manualContourModel*> lstManConModExp;
1646 std::vector<double> pLstValue;
1647 std::vector<double> pLstValuePosX;
1648 std::vector<double> pLstValuePosY;
1649 std::vector<double> pLstValuePosZ;
1651 std::vector<int> tempVector;
1652 _instantPanel->getInstant( tempVector );
1654 vtkImageData *imagedata = _theViewPanel->getSceneManager()->GetImageData();
1655 int sizeZ = _theViewPanel->getSceneManager()->GetImageDataSizeZ();
1657 int ii,sizeLstContourThings;
1664 minZ = 0;// _mbarrange->GetStart();
1665 maxZ = sizeZ;//_mbarrange->GetEnd();
1666 totalZ = maxZ-minZ+1;
1668 contourextractdata->SetImage( imagedata);
1671 for ( z=0 ; z<sizeZ ; z++)
1674 porcent = 100.0* (z-minZ)/totalZ;
1676 tmpString.Printf(_T("Saving Values"));
1677 tmpString.Printf(_T(" %d %c %d/%d %d"), (int)porcent , 37 , z-minZ+1, (int)totalZ ,z);
1678 interfMainPanel::getInstance()->setStringInfoPanel(tmpString);
1679 //_staticTextInformation->SetLabel(tmpString);
1682 //Extraction data from contours of each slice
1683 contourextractdata->SetZtoBeAnalys( z);
1686 Instant instant(&tempVector);
1687 std::vector<ContourThing**> lstContourThings = kernelManager->getOutlinesAtInstant(&instant);//this->_modelManager->getOutlinesAtInstant( &instant );
1688 sizeLstContourThings = lstContourThings.size();
1690 lstManConMod.clear();
1691 for (ii=0 ; ii<sizeLstContourThings ; ii++)
1693 ContourThing **contourthing = lstContourThings[ii];
1694 lstManConMod.push_back( (*contourthing)->getModel() );
1696 lstManConModExp = kernelManager->ExploseEachModel( lstManConMod );
1701 int iContourGroup,sizeContourGroup;
1702 if (typeContourGroup==3) // contour separete
1704 sizeContourGroup=lstManConModExp.size();
1705 } else { // contour AND OR XOR
1709 for( iContourGroup=0 ; iContourGroup<sizeContourGroup ; iContourGroup++ ){
1710 lstManConModTmp.clear();
1711 if (typeContourGroup==3) // contour separete
1713 lstManConModTmp.push_back( lstManConModExp[iContourGroup]);
1714 } else { // contour AND OR XOR
1715 lstManConModTmp = lstManConModExp;
1718 contourextractdata->SetLstManualContourModel( lstManConModTmp );
1721 pLstValuePosX.clear();
1722 pLstValuePosY.clear();
1723 pLstValuePosZ.clear();
1724 contourextractdata->GetValuesInsideCrown( &pLstValue,
1729 std::string temp = directory + "/" + namefile + "-slice";
1730 temp = temp + kernelManager->intToString(z) + "-cont" + kernelManager->intToString(iContourGroup);
1731 temp = temp + ".txt";
1733 // LG 14/01/09 : using crea
1734 wxString filename = crea::std2wx(temp);
1735 /*filename.Printf(_T("%s"),directory.c_str());
1736 filename.append(_T("\\"));
1737 filename.append(_T("%s"),namefile.c_str());
1738 filename.append(_T("-slice"));
1739 filename.append(_T("%d"),z);
1740 filename.append(_T("-cont"));
1741 filename.append(_T("%d"),iContourGroup);
1742 filename.append(_T(".txt"));*/
1743 // filename.Printf(temp.c_str());
1747 FILE *pFile=fopen((const char *)filename.mb_str(),"w+");
1748 fprintf(pFile,"value \t x \t y \t z\n" );
1749 int iLstValue,sizeLstValue=pLstValue.size();
1750 for (iLstValue=0 ; iLstValue<sizeLstValue ; iLstValue++ )
1752 fprintf(pFile,"%f\t %f\t %f\t %f\n", (float)pLstValue[iLstValue] , (float)pLstValuePosX[iLstValue], (float)pLstValuePosY[iLstValue], (float)z );
1755 } // for iContourGroup
1757 interfMainPanel::getInstance()->setStringInfoPanel(_T(""));
1758 //_staticTextInformation->SetLabel( _T("") );
1759 delete contourextractdata;
1762 void wxContourMainFrame::SaveImageResult(std::string directory,std::string namefile, int typeContourGroup)
1765 ContourExtractData *contourextractdata = new ContourExtractData( true );
1766 //int typeContourGroup = this->_radiolstboxContourGroup->GetSelection();
1767 if (typeContourGroup==3)
1771 contourextractdata ->SetTypeOperation( typeContourGroup % 3 );
1773 std::vector<manualContourModel*> lstManConMod;
1774 std::vector<manualContourModel*> lstManConModTmp;
1775 std::vector<manualContourModel*> lstManConModExp;
1777 std::vector<int> tempVector;
1778 _instantPanel->getInstant( tempVector );
1780 vtkImageData *imagedata = _theViewPanel->getImageData();
1781 int sizeZ = _theViewPanel->GetImageDataSizeZ();
1783 int ii,sizeLstContourThings;
1792 minZ = 0;// _mbarrange->GetStart();
1793 maxZ = sizeZ;//_mbarrange->GetEnd();
1794 totalZ = maxZ-minZ+1;
1796 contourextractdata->SetImage( imagedata);
1799 for ( z=0 ; z<sizeZ ; z++)
1802 porcent = 100.0* (z-minZ)/totalZ;
1803 tmpString.Printf(_T("Saving Values"));
1804 tmpString.Printf(_T("%d %c %d/%d %d"), (int)porcent , 37 , z-minZ+1, (int)totalZ ,z);
1805 interfMainPanel::getInstance()->setStringInfoPanel(tmpString);
1807 //Extraction data from contours of each slice
1808 contourextractdata->SetZtoBeAnalys( z);
1811 Instant instant(&tempVector);
1812 std::vector<ContourThing**> lstContourThings = kernelManager->getOutlinesAtInstant( &instant );
1813 sizeLstContourThings = lstContourThings.size();
1815 lstManConMod.clear();
1816 for (ii=0 ; ii<sizeLstContourThings ; ii++)
1818 ContourThing **contourthing = lstContourThings[ii];
1819 lstManConMod.push_back( (*contourthing)->getModel() );
1821 lstManConModExp = kernelManager->ExploseEachModel( lstManConMod );
1824 int iContourGroup,sizeContourGroup;
1825 if (typeContourGroup==3) // contour separete
1827 sizeContourGroup=lstManConModExp.size();
1828 } else { // contour AND OR XOR
1832 for( iContourGroup=0 ; iContourGroup<sizeContourGroup ; iContourGroup++ ){
1833 lstManConModTmp.clear();
1834 if (typeContourGroup==3) // contour separete
1836 lstManConModTmp.push_back( lstManConModExp[iContourGroup]);
1837 } else { // contour AND OR XOR
1838 lstManConModTmp = lstManConModExp;
1841 contourextractdata->SetLstManualContourModel( lstManConModTmp );
1844 // for (ii=0 ; ii<sizeLstContourThings ; ii++)
1846 // ContourThing **contourthing = lstContourThings[ii];
1847 // lstManConMod.push_back( (*contourthing)->getModel() );
1849 // contourextractdata->SetLstManualContourModel( lstManConMod );
1851 contourextractdata->CalculateImageResult(); // with actual Z
1853 } // for iContourGroup
1856 std::string temp = directory + "/" + namefile + "-Value.mhd";
1858 wxString filename = crea::std2wx(temp);
1860 // filename.Printf(_T(temp.c_str()));
1861 //filename.Printf(_T("%s\\%s-Value.mhd",directory.c_str(),namefile.c_str(),z);
1862 /*filename.Printf(_T("%s"),directory.c_str());
1863 filename.append(_T("\\"));
1864 filename.append(_T("%s"),namefile.c_str());
1865 filename.append(_T("-Value.mhd"));*/
1868 vtkMetaImageWriter *writerValueImage = vtkMetaImageWriter::New( );
1869 writerValueImage->SetInput( contourextractdata->GetVtkImageValueResult() );
1870 writerValueImage->SetFileName( (const char *)filename.mb_str() );
1871 writerValueImage->SetFileDimensionality( 3 );
1872 writerValueImage->Write( );
1875 // filename.Printf("%s\\%s-Mask.mhd",directory.c_str(),namefile.c_str(),z);
1876 temp = directory + "/" + namefile + "-Mask.mhd";
1878 // LG 14/01/09 : using crea
1879 filename = crea::std2wx(temp);
1880 // filename.Printf(_T(temp.c_str()));
1882 /*filename.Printf(_T("%s"),directory.c_str());
1883 filename.append(_T("\\"));
1884 filename.append(_T("%s"),namefile.c_str());
1885 filename.append(_T("-Mask.mhd"));*/
1887 vtkMetaImageWriter *writerMaskImage = vtkMetaImageWriter::New( );
1888 writerMaskImage->SetInput( contourextractdata->GetVtkImageMaskResult() );
1889 writerMaskImage->SetFileName( (const char *)filename.mb_str() );
1890 writerMaskImage->SetFileDimensionality( 3 );
1891 writerMaskImage->Write( );
1893 interfMainPanel::getInstance()->setStringInfoPanel( _T("") );
1894 delete contourextractdata;
1897 void wxContourMainFrame::onChangeInstantInstantPanel(std::string name,int value, int minshow, int maxshow){
1898 if( name.compare( _theViewPanel->getVerticalConceptName() ) == 0){
1899 _theViewPanel->setActualVertical( value);
1901 else if( name.compare( _theViewPanel->getHorizontalConceptName() ) == 0|| _instantPanel->getIfConceptCheckedAt( name, 0 ) ) {
1902 _theViewPanel->setHorizontalConcept( name, minshow, maxshow, minshow, maxshow, value);
1908 void wxContourMainFrame::onSnakePressed(){
1909 std::vector<double> vecX;
1910 std::vector<double> vecY;
1911 std::vector<double> vecZ;
1912 _theViewPanel->GetPointsOfActualContour( &vecX , &vecY , &vecZ );
1914 if (vecX.size()!=0){
1915 std::vector<int> tempVector;
1916 _instantPanel->getInstant( tempVector );
1917 int i,size=vecZ.size();
1918 int actualSlice = tempVector[1];
1919 for ( i=0 ; i<size ; i++ )
1921 vecZ[i] = actualSlice;
1924 wxDialog* dialog = new wxDialog(this, -1, wxString(_T("Snake")));
1925 wxPanel* panel = new wxPanel(dialog,-1);
1926 wxStaticText* sttext = new wxStaticText(panel, -1, wxString(_T("Panel para snake")));
1927 dialog->ShowModal();
1932 void wxContourMainFrame::saveFileWithContoursAutomatique(){
1933 std::string filename = kernelManager->getCurrentFileName();
1934 if(filename.compare("")!=0){
1935 saveFileWithContours(filename);