1 /*# ---------------------------------------------------------------------
3 # Copyright (c) CREATIS (Centre de Recherche en Acquisition et Traitement de l'Image
5 # Authors : Eduardo Davila, Frederic Cervenansky, Claire Mouton
6 # Previous Authors : Laurent Guigues, Jean-Pierre Roux
7 # CreaTools website : www.creatis.insa-lyon.fr/site/fr/creatools_accueil
9 # This software is governed by the CeCILL-B license under French law and
10 # abiding by the rules of distribution of free software. You can use,
11 # modify and/ or redistribute the software under the terms of the CeCILL-B
12 # license as circulated by CEA, CNRS and INRIA at the following URL
13 # http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
14 # or in the file LICENSE.txt.
16 # As a counterpart to the access to the source code and rights to copy,
17 # modify and redistribute granted by the license, users are provided only
18 # with a limited warranty and the software's author, the holder of the
19 # economic rights, and the successive licensors have only limited
22 # The fact that you are presently reading this means that you have had
23 # knowledge of the CeCILL-B license and that you accept its terms.
24 # ------------------------------------------------------------------------ */
26 //----------------------------------------------------------------------------------------------------------------
27 // Class definition include
28 //----------------------------------------------------------------------------------------------------------------
29 #include "wxContourMainFrame.h"
33 //----------------------------------------------------------------------------------------------------------------
35 //----------------------------------------------------------------------------------------------------------------
38 #include "NameWrapper.h"
39 #include "wx/artprov.h"
40 #include "ConceptDataWrap.h"
46 //----------------------------------------------------------------------------------------------------------------
47 // Class implementation
48 //----------------------------------------------------------------------------------------------------------------
49 /** @file wxContourMainFrame.cxx */
51 //------------------------------------------------------------------------------------------------------------
52 // Constructors & Destructors
53 //------------------------------------------------------------------------------------------------------------
55 wxContourMainFrame* wxContourMainFrame:: instance = NULL;
56 char wxContourMainFrame::COPY = 'C';
58 wxContourMainFrame :: wxContourMainFrame(wxWindow* parent, wxWindowID id,const wxString& title,const wxPoint& pos,const wxSize& size,long style)
59 //: wxPanel(parent, id, title, pos, size, style)
60 //: wxWindow(parent, id, pos, size, style)
61 : wxPanel(parent, id, pos, size, style)
63 m_mgr.SetManagedWindow(this);
65 _creatingContoursActive = false;
67 // _modelManager = NULL;
69 // _buttonsBar = NULL;
71 // _drawToolsPanel = NULL;
72 // _operationsToolsPanel = NULL;
73 //_autoFormsPanel = NULL;
74 // _standardToolsPanel = NULL;
75 // _editionToolsPanel = NULL;
76 // _listViewPanel = NULL;
77 // _sceneManager = NULL;
78 //_actualInstant = NULL;
79 _numberOfVariablesStatistics = 6+1;
81 _refLineControl = NULL;
84 // _actorPresent = false;
86 // set up default notebook style
87 // m_notebook_style =wxAUI_NB_TAB_SPLIT | wxAUI_NB_TAB_EXTERNAL_MOVE | wxNO_BORDER;
88 // m_notebook_theme = 0;
89 //wxContour_ActionCommandsID a;
91 _contourextractdata = NULL;
92 _viewMaskImage = NULL;
93 _viewMaskImagePanel = NULL;
94 _viewThresholdImage = NULL;
95 _viewThresholdImagePanel = NULL;
96 _viewColorLayerImagePanel = NULL;
99 wxContourMainFrame :: wxContourMainFrame(wxWindow* parent, wxWindowID id,const wxString& title,const wxPoint& pos,const wxSize& size,std::vector<vtkImageData*> images, long style,std::string datadir)
100 : wxPanel(parent, id, pos, size, style)
102 m_mgr.SetManagedWindow(this);
104 _creatingContoursActive = false;
105 _theViewPanel = NULL;
107 _instantPanel = NULL;
108 _refLineControl = NULL;
109 _refLineModel = NULL;
111 // _actorPresent = false;
112 _viewMaskImage = NULL;
113 _viewMaskImagePanel = NULL;
114 _viewThresholdImage = NULL;
115 _viewThresholdImagePanel = NULL;
116 _viewColorLayerImagePanel = NULL;
118 // set up default notebook style
119 m_notebook_style =wxAUI_NB_TAB_SPLIT | wxAUI_NB_TAB_EXTERNAL_MOVE | wxNO_BORDER;
120 m_notebook_theme = 0;
121 //wxContour_ActionCommandsID a;
122 _numberOfVariablesStatistics = 7;
130 _pannew = interfMainPanel::getInstance(this,datadir+"/data/Icons");//, eventHandler);
131 _performingOperation = new PerformingOperation();
133 if(images.size() > 0)
135 this->setVectImages(images);
138 _contourextractdata = NULL;
141 void wxContourMainFrame::setVectImages(std::vector<vtkImageData*> imgs)
146 #if defined(__GNUC__)
147 std::string str_home(getenv("HOME"));
148 #elif defined(_WIN32)
149 std::string str_home(getenv("USERPROFILE"));
151 std::string strCreaContourDataTmp = str_home + "/.creaContourDataTemp/";
153 std::vector<std::string> conceptNameVect;
154 std::vector<int> conceptSizeVect;
156 notebook = this->createNotebook();
159 kernelManager = new KernelManagerContour( imgs , _datadir+"/data/" , strCreaContourDataTmp );
162 _instantPanel = new wxInstantChooserPanel( notebook, "Instant Chooser", true, false, "c" );
163 _theViewPanel = new wxContourViewPanel( kernelManager->getSourceImage(), notebook );
165 //-------------------------------------------------------------
166 kernelManager->getConceptsInformation(conceptNameVect, conceptSizeVect);
167 _instantPanel->addConcepts(conceptNameVect, conceptSizeVect);
170 double val = _theViewPanel->getCurrentDeep();
171 _instantPanel->setConceptValue( "Axe Depth", (int)val );
172 //JCP _instantPanel->setConceptValue("time", num de imagenes);
173 ConceptDataWrap * data = _instantPanel->getConceptDataOf( "Axe Depth" );
174 //*******************changeInstant();
175 _theViewPanel->setVerticalConcept( "Axe Depth", data->getMinValue(), data->getMaxValue(), data->getMinShowedValue(), data->getMaxShowedValue(), data->getActualValue() );
177 this->configurePanels( );
182 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 )
184 if(instance == NULL){
185 instance = new wxContourMainFrame(parent, id, title, pos, size, images, style,datadir);
190 std::vector<vtkImageData*> wxContourMainFrame ::getVectImages()
192 return kernelManager->getVectImages();
195 wxContourMainFrame* wxContourMainFrame :: getInstance()
200 void wxContourMainFrame :: resetInstance()
205 wxContourMainFrame :: ~wxContourMainFrame()
207 delete _contourextractdata;
210 interfMainPanel::resetInstance();
211 delete kernelManager;
213 //_pannew->Destroy();
219 //El problema al cerrar la aplicacion puede estar asociado
220 //a que wxAUINotebook esta en la aplicacion
221 //principal (wxContourGUIExample)tambien
222 //EED???? delete _theViewPanel;
223 //EED???? delete _instantPanel;
224 //EED???? delete _buttonsBar;
225 //EED???? delete _actualInstant;
226 //EED???? delete _sceneManager;
230 //------------------------------------------------------------------------------------------------------------
231 // Creational and initialization methods using WxAui
232 //------------------------------------------------------------------------------------------------------------
234 wxAuiNotebook * wxContourMainFrame :: createNotebook()
236 wxSize client_size = GetClientSize();
237 wxAuiNotebook* noteBook = new wxAuiNotebook(this, -1, wxPoint(client_size.x, client_size.y), wxSize(430,200), m_notebook_style);
238 wxBitmap page_bmp = wxArtProvider::GetBitmap(wxART_NORMAL_FILE, wxART_OTHER, wxSize(16,16));
243 //------------------------------------------------------------------------------------------------------------
244 // Creational and initialization methods
245 //------------------------------------------------------------------------------------------------------------
246 bool wxContourMainFrame :: configurePanels( )
248 bool configured = _theViewPanel!=NULL;
250 configured &= _theViewPanel!=NULL;
251 if( _theViewPanel!=NULL )
253 notebook->AddPage( _theViewPanel, wxT(" View ") );
260 notebook->AddPage( _instantPanel, wxT("Instant Page") );
264 m_mgr.AddPane(notebook, wxAuiPaneInfo().Name(wxT("notebook_content")).CenterPane().PaneBorder(false));
267 SetMinSize(wxSize(300,300));
273 bool wxContourMainFrame::addNewPanel(wxPanel* panel)
275 bool configured = panel!=NULL;
276 configured &= panel!=NULL;
280 notebook->AddPage( panel, wxT(" Viewer "), true );
286 //------------------------------------------------------------------------------------------------------------
287 // Attributes getters and setters
288 //------------------------------------------------------------------------------------------------------------
292 void wxContourMainFrame :: setInstantChooserPanel( wxInstantChooserPanel * theInstantChooserPanel )
294 _instantPanel = theInstantChooserPanel;
297 // void wxContourMainFrame :: setButtonsBar( wxContour_ButtonsBar * theButtonsBar )
299 // _buttonsBar = theButtonsBar;
302 // void wxContourMainFrame :: setGrid( wxContour_Grid * theGridPanel )
304 // _gridPanel = theGridPanel;
307 // void wxContourMainFrame :: setDrawToolsPanel( wxContour_DrawToolsPanel * theDrawToolsPanel )
309 // _drawToolsPanel = theDrawToolsPanel;
312 // void wxContourMainFrame :: setOperationsToolsPanel( wxContour_OperationsToolsPanel * theOperationsToolsPanel )
314 // _operationsToolsPanel = theOperationsToolsPanel;
317 // void wxContourMainFrame :: setAutomaticFormsPanel( wxContour_AutomaticFormsToolsPanel * theAutoFormsPanel )
319 // _autoFormsPanel = theAutoFormsPanel;
322 // void wxContourMainFrame :: setStandardToolsPanel( wxContour_StandardToolsPanel * theStandardToolsPanel )
324 // _standardToolsPanel= theStandardToolsPanel;
327 // void wxContourMainFrame :: setEditionToolsPanel( wxContour_EdtionToolsPanel * theEditionToolsPanel )
329 // _editionToolsPanel = theEditionToolsPanel;
332 // void wxContourMainFrame :: setListViewPanel( wxContour_ListViewPanel * theListViewPanel )
334 // _listViewPanel = theListViewPanel;
339 void wxContourMainFrame::onCreateContourSpline( ){
341 //JCP 20-10-08 Undo redo implementation
343 //JCP 20-10-08 Undo redo implementation
347 void wxContourMainFrame::onCreateContourRectangle( ){
348 //JCP 20-10-08 Undo redo implementation
350 //JCP 20-10-08 Undo redo implementation
353 void wxContourMainFrame::onCreateContourCircle( ){
354 //JCP 20-10-08 Undo redo implementation
356 //JCP 20-10-08 Undo redo implementation
360 void wxContourMainFrame::onCreateContourLine( ){
361 //JCP 20-10-08 Undo redo implementation
363 //JCP 20-10-08 Undo redo implementation
367 // RaC 09-09 --------------------------------------
368 void wxContourMainFrame::onCreateContourPoints( ){
369 //JCP 20-10-08 Undo redo implementation
371 //JCP 20-10-08 Undo redo implementation
374 // RaC 09-09 --------------------------------------
376 // RaC 10-09 --------------------------------------
377 void wxContourMainFrame::onCreateContourPolygon( ){
378 //JCP 20-10-08 Undo redo implementation
380 //JCP 20-10-08 Undo redo implementation
383 // RaC 10-09 --------------------------------------
385 //------------------------------------------------------------------------------------------------------------
387 void wxContourMainFrame :: onCreateContourBullEye(wxPanel* panel )
389 //Creating the manualBaseModel and including in the model
390 manualBaseModel * manModelContour = factoryManualContourModel(panel );
392 std::vector<int> instantVector;
393 _instantPanel->getInstant( instantVector );
394 std::string theName = kernelManager->createOutline(manModelContour, instantVector);
396 /*std::vector<int> instantVector;
397 _instantPanel->getInstant( instantVector );
399 theName= _modelManager->createOutline( manModelContour, instantVector );*/
400 bool addedModel = theName.compare("") != 0;//??
404 double spc[3];//Si no hay imagen pero hay contornos que spacing se pone por default
405 _theViewPanel->getSpacing(spc);
406 //Adding the manualContourControler to interface objects structure
407 //Adding the manualViewContour to interface objects structure
408 //_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.
409 _theViewPanel->getSceneManager()->configureViewControlTo( theName, manModelContour,spc , 4) ;
412 void wxContourMainFrame :: createContour( int typeContour )
414 //Creating the manualContourModel and including in the model
415 manualBaseModel * manModelContour = kernelManager->factoryManualContourModel(typeContour);
417 std::vector<int> instantVector;
418 _instantPanel->getInstant( instantVector );
419 std::string theName = kernelManager->createOutline(manModelContour, instantVector);
421 /*std::vector<int> instantVector;
422 _instantPanel->getInstant( instantVector );
424 theName= _modelManager->createOutline( manModelContour, instantVector );*/
425 bool addedModel = theName.compare("") != 0;//??
428 double spc[3];//Si no hay imagen pero hay contornos que spacing se pone por default
429 _theViewPanel->getSpacing(spc);
430 //Adding the manualContourControler to interface objects structure
431 //Adding the manualViewContour to interface objects structure
432 //_sceneManager->setControlActiveStateOfALL( false );//This call is being done here because if the ROI is created underneath the previously created ROIS will still be active.
433 _theViewPanel->getSceneManager()->configureViewControlTo( theName, manModelContour,spc , typeContour) ;
437 manualBaseModel * wxContourMainFrame::factoryManualContourModel(wxPanel* panel){
439 manualContourModelBullEye *manModelContourBullEye = new manualContourModelBullEye();
440 manualBaseModel *manModelContour=NULL;
441 manModelContour = manModelContourBullEye;
443 int iCrown,sizeCrowns,iSector,sizeSectors;
444 double radioA,radioB,ang,angDelta ;
445 sizeCrowns = ((PanelBullEyeOptions*)panel)->GetNumberOfCrowns();
446 for ( iCrown=0 ; iCrown<sizeCrowns ; iCrown++ )
448 sizeSectors = ((PanelBullEyeOptions*)panel)->GetNumberOfSections(iCrown);
449 radioB = ((PanelBullEyeOptions*)panel)->GetRadioOfCrown(iCrown);
450 if (iCrown==sizeCrowns-1)
454 radioA = ((PanelBullEyeOptions*)panel)->GetRadioOfCrown(iCrown+1);
458 for ( iSector=0 ; iSector<sizeSectors ; iSector++ )
460 ang = ((PanelBullEyeOptions*)panel)->GetAngOfCrownSection(iCrown,iSector);
461 angDelta= ((PanelBullEyeOptions*)panel)->GetAngDeltaOfCrownSection(iCrown);
462 manModelContourBullEye->AddSector(radioA,radioB,ang,angDelta);
465 } // if _panelBullEyeOptions
467 return manModelContour;
469 void wxContourMainFrame :: saveState(){
471 std::string temp = kernelManager->saveState();
472 saveFileWithContours(temp);
475 void wxContourMainFrame::onDeleteContour(){
476 //JCP 20-10-08 Undo redo implementation
478 //JCP 20-10-08 Undo redo implementation
480 std::vector<std::string> lstKeyNameToBeErase;
481 lstKeyNameToBeErase = _theViewPanel->getSceneManager()->getSelectedObjects();
482 deleteContours( lstKeyNameToBeErase );
484 int i,size=_sceneManager->getSelectedObjects().size();
487 std::string keyName = _sceneManager->getSelectedObjects()[i];
488 int ispartofstaticlist = this->_modelManager->IsPartOfStaticList( keyName );
489 if ( ispartofstaticlist>=0 )
491 std::vector<int> tempVector;
492 _instantPanel->getInstant( tempVector );
493 Instant instant(&tempVector);
494 this->_modelManager->ChangeContourOfList(keyName, &instant);
498 std::vector<std::string> lstKeyName;
499 std::vector<std::string> lstKeyNameActualSlice;
500 std::vector<std::string> lstKeyNameToBeErase;
502 lstKeyNameToBeErase = _sceneManager->getSelectedObjects();
503 lstKeyNameActualSlice = _sceneManager->GetlstContoursNameActualSlice();
504 int k,kSize=lstKeyNameToBeErase.size();
505 int j,jSize=lstKeyNameActualSlice.size();
507 for (k=0;k<kSize; k++)
510 for (j=0;j<jSize; j++)
512 if (lstKeyNameToBeErase[k]==lstKeyNameActualSlice[j])
519 lstKeyName.push_back( lstKeyNameToBeErase[k] );
523 deleteContours( lstKeyName );
527 void wxContourMainFrame :: deleteContours( std::vector<std::string> keyNamesVector )
529 int i,size=keyNamesVector.size();
532 deleteContour( keyNamesVector[i] );
536 void wxContourMainFrame :: deleteContour( std::string theKeyName ){
538 manualContourModel * cModel;
539 manualViewBaseContour * cViewer;
540 manualContourBaseControler * cControler;
542 ContourWrap_ViewControl *conwrapviewControl = _theViewPanel->getSceneManager()->getContourWrap_ViewControlOf( theKeyName );
543 cControler = conwrapviewControl->getControler();*/
546 bool isedit = _theViewPanel->isEditableCControler(theKeyName);
547 bool ispartofstaticlst = kernelManager->IsPartOfStaticList(theKeyName);
549 if (isedit && ispartofstaticlst)
551 _theViewPanel->removeFromScene(theKeyName);
553 kernelManager->deleteCModel(theKeyName);
554 //_theViewPanel->getSceneManager()->removeFromScene( theKeyName );
555 //cViewer = conwrapviewControl->getViewer();
556 //_theViewPanel->getSceneManager()->removeWrap( theKeyName );
557 //cControler* conwrapviewControl->getControler();
560 // delete cControler;
565 void wxContourMainFrame::onDeleteContoursActSlice(){
566 //JCP 20-10-08 Undo redo implementation
568 //JCP 20-10-08 Undo redo implementation
569 deleteContours( (std::vector<std::string>)_theViewPanel->getSceneManager()->GetlstContoursNameActualSlice() );
571 void wxContourMainFrame::onDeleteAllContours(){
572 //JCP 20-10-08 Undo redo implementation
576 void wxContourMainFrame::deleteAllContours(){
577 //JCP 20-10-08 Undo redo implementation
580 std::vector<int> tempVector;
581 _instantPanel->getInstant( tempVector );
583 //JCP --08-09-2008 When using a diferent interface the _mbarrangeDeleteAll might not be initialize
584 // the values in GetStart and GetEnd will then not be initialize also.
585 // We use instead the values given when initializing the _deletepanel.
587 //int minZ = _mbarrangeDeleteAll->GetStart();
588 //int maxZ = _mbarrangeDeleteAll->GetEnd();
592 maxZ = _theViewPanel->getSceneManager()->GetImageDataSizeZ();
596 _theViewPanel->getSceneManager()->removeSceneContours( );
597 _theViewPanel->getSceneManager()->removeAllOutlines();
598 kernelManager->removeAllOutlines();
601 if ( (minZ==0) && (maxZ==_mbarrangeDeleteAll->GetMax() ))
603 _theViewPanel->getSceneManager()->removeSceneContours( );
604 _modelManager->removeAllOutlines();
605 _theViewPanel->getSceneManager()->removeAllOutlines();
608 for ( z=minZ ; z<=maxZ ; z++)
611 Instant instant(&tempVector);
612 std::vector<ContourThing**> lstContourThings = this->_modelManager->getOutlinesAtInstant( &instant );
614 sizeLstContourThings = lstContourThings.size();
615 for (ii=0 ; ii<sizeLstContourThings ; ii++)
617 ContourThing **contourthing = lstContourThings[ii];
618 deleteContour( (*contourthing)->getName() );
625 void wxContourMainFrame::setConceptValue( std::string name, int value ){
626 _instantPanel->setConceptValue(name, value);
630 ConceptDataWrap* wxContourMainFrame::getLastConceptData(){
631 return _instantPanel->getLastConceptData();
635 bool wxContourMainFrame::getIfConceptCheckedAt( std::string name, int pos ){
636 return _instantPanel->getIfConceptCheckedAt( name, pos );
641 void wxContourMainFrame::ShowResultImages(int typeContourGroup, int selection, int minZ, int maxZ)
644 vtkImageData * value;
645 this->getMaskValue(&mask, &value, typeContourGroup, selection, minZ, maxZ);
647 std::vector<int> nTypeView;
648 nTypeView.push_back(5);
649 nTypeView.push_back(1);
650 nTypeView.push_back(2);
651 nTypeView.push_back(0);
653 wxFrame *frame = new wxFrame(this, -1,_T("Result image extracted.."),wxDefaultPosition,wxSize(600,600), wxDEFAULT_FRAME_STYLE|wxSTAY_ON_TOP);
654 wxAuiManager *m_mgr_noteBookViewerResult = new wxAuiManager();
655 m_mgr_noteBookViewerResult->SetManagedWindow(frame);
657 wxAuiNotebook* noteBookViewerResult = new wxAuiNotebook(frame, -1, wxPoint(600, 600), wxSize(430,200), m_notebook_style);
658 m_mgr_noteBookViewerResult->AddPane(noteBookViewerResult, wxAuiPaneInfo().Name(wxT("notebook_content")).CenterPane().PaneBorder(false));
660 wxPanel *panelViewer1 = new wxMaracas_N_ViewersWidget(noteBookViewerResult, value,&nTypeView);
661 wxPanel *panelViewer2 = new wxMaracas_N_ViewersWidget(noteBookViewerResult, mask,&nTypeView);
664 noteBookViewerResult->AddPage( panelViewer1, wxT("Image result") );
665 noteBookViewerResult->AddPage( panelViewer2, wxT("Mask result") );
666 m_mgr_noteBookViewerResult->Update();
673 void wxContourMainFrame::changeInstant()
675 std::vector<int> instantVect;
676 _instantPanel->getInstant( instantVect );
677 int actualSlice = instantVect[1];
679 kernelManager->setInstant(instantVect);
681 // Refresh Mask image
682 if(_viewMaskImage!=NULL){
683 _viewMaskImage->SetZ(actualSlice);
684 if (_viewMaskImagePanel->IsVisible()==true)
686 vtkImageData *mask, *value;
687 getMaskValue(&mask,&value, _contourGroup , 0, -1, -1);
688 _viewMaskImage->onThreshold();
692 // Refresh Threshold image
693 if(_viewThresholdImage!=NULL){
694 _viewThresholdImage->SetZ(actualSlice);
695 if (_viewThresholdImagePanel->IsVisible()==true){
696 _viewThresholdImage->onThreshold();
701 updateInstantOutlines();
702 updateInstantImageData();
708 void wxContourMainFrame :: updateInstantOutlines()
710 _theViewPanel->removeSceneContours();
711 _theViewPanel->addNameWrapperToScene();
713 //for( int i=0; i<size; i++)
715 // _theViewPanel->getSceneManager()->addToScene(namesWrapping[i]->getKeyName(), true, true, true, false, false );
719 int wxContourMainFrame::getNamesWrappingSize(){
720 return kernelManager->getNamesWrappingSize();
722 std::string wxContourMainFrame::getNameWrapping(int i){
723 return kernelManager->getNameWrapping(i);
726 void wxContourMainFrame::updateInstantImageData()
728 std::vector<int> inst;
729 _instantPanel->getInstant(inst);
731 vtkImageData* img = kernelManager->getImageAtInstant(inst);
733 _theViewPanel->changeImage(img);
736 int z = _instantPanel->getConceptDataOf("Axe Depth")->getActualValue();
737 _theViewPanel->setImageSlice(z);
741 void wxContourMainFrame::updateInstantAxes()
746 void wxContourMainFrame::onChangeDeep(int val){
747 _instantPanel->setConceptValue( "Axe Depth", (int)val );
752 void wxContourMainFrame::onCopy(){
753 std::vector<std::string> currentSelection = _theViewPanel->getSelectedObjects();
755 std::vector<int> tempVector;
756 _instantPanel->getInstant( tempVector );
757 _performingOperation->reset();
758 _performingOperation->setStartCommand( COPY );
759 _performingOperation->setStartOperationInstantVector( tempVector );
760 _performingOperation->setKeyNamesOperationElems( currentSelection );
763 void wxContourMainFrame::onPaste(){
766 char theStartCommand = _performingOperation->getStartCommand();
767 if ( theStartCommand == COPY )
769 //JCP 20-10-08 Undo redo implementation
771 //JCP 20-10-08 Undo redo implementation
772 std::vector<int> tempVector;
773 _instantPanel->getInstant( tempVector );
774 _performingOperation->setEndOperationInstantVector ( tempVector );
775 std::vector<std::string> elems = _performingOperation->getKeyNamesOperationElems();
776 int i,size = elems.size();
777 for( i=0; i<size; i++ )
779 createCopyContourOf( elems[i], tempVector, i>0 );
783 void wxContourMainFrame::onUndo(){
784 std::string filename;
785 if(kernelManager->onUndoSaveFile(filename)){
786 saveFileWithContours(filename);
788 if(kernelManager->onUndo(filename)){
792 void wxContourMainFrame::onRedo(){
793 std::string filename;
794 if(kernelManager->onRedo(filename)){
799 void wxContourMainFrame :: createCopyContourOf ( std::string anExistingKName, std::vector<int> &instantNoTouchData, bool append )
801 std::string cloneName = kernelManager->createCopyContourOf( anExistingKName, instantNoTouchData );
802 manualBaseModel * manualModel = kernelManager->getOutlineByKeyName(cloneName);//_modelManager->getOutlineByKeyName( cloneName )->getModel();
803 _theViewPanel->getSceneManager()->createCopyContourOf( anExistingKName, cloneName, manualModel , append );
806 ///AD: 03-09 Copy the object and apply the given transformation
807 void wxContourMainFrame :: createMirrorContourOf ( std::string anExistingKName, std::vector<int> &instantNoTouchData, bool append )
809 std::string cloneName = kernelManager->createCopyContourOf( anExistingKName, instantNoTouchData );
810 manualBaseModel * manualModel = kernelManager->getOutlineByKeyName(cloneName);
812 manualPoint * refPoint1 = _refLineModel->GetManualPoint(0);
813 manualPoint * refPoint2 = _refLineModel->GetManualPoint(1);
815 double pnt1X = refPoint1->GetX();
816 double pnt1Y = refPoint1->GetY();
817 // double pnt1Z = refPoint1->GetZ();
818 double pnt2X = refPoint2->GetX();
819 double pnt2Y = refPoint2->GetY();
820 // double pnt2Z = refPoint2->GetZ();
822 double angle = (atan2(pnt2Y - pnt1Y, pnt2X - pnt1X) * 180 / 3.1415926535897932384626433832795)+90;
823 vtkTransform *t = vtkTransform::New();
827 t->Translate(-pnt1X, -pnt1Y, 0);
831 t->Translate(pnt1X, pnt1Y, 0);
834 int i,size=manualModel->GetSizeLstPoints();
837 manualPoint * mp = manualModel->GetManualPoint(i);
843 t->TransformPoint( vecIn, vecOut );
844 mp->SetPointX( vecOut[0] );
845 mp->SetPointY( vecOut[1] );
846 mp->SetPointZ( vecOut[2] );
849 _theViewPanel->getSceneManager()->createCopyContourOf( anExistingKName, cloneName, manualModel , append );
853 void wxContourMainFrame ::loadState(std::string filename){
856 onLoadContours(filename,false);
860 FILE *pFile=fopen(filename.c_str(),"r+");
862 fscanf(pFile,"%s",tmp); // --CreaContour--
864 fscanf(pFile,"%s",tmp); // Version
865 fscanf(pFile,"%s",tmp); // 1.0.3 || 1.0.2 || 1.0.1 || 1.0.0
869 loadContours(pFile, false);
870 loadContours(pFile, true);
879 void wxContourMainFrame::loadContours( FILE *pFile, bool staticContour )
883 if (staticContour==false)
885 fscanf(pFile,"%s",tmp); // ImageDimensions
886 fscanf(pFile,"%s",tmp); // X
887 fscanf(pFile,"%s",tmp); // Y
888 fscanf(pFile,"%s",tmp); // Z
890 fscanf(pFile,"%s",tmp); // ImageSpacing
891 fscanf(pFile,"%s",tmp); // X
892 fscanf(pFile,"%s",tmp); // Y
893 fscanf(pFile,"%s",tmp); // Z
896 fscanf(pFile,"%s",tmp); // NumberOfContours
897 fscanf(pFile,"%s",tmp); // ##
898 int numberOfContours = atoi(tmp);
900 std::vector<int> instantVector;
901 int typeContourModel;
902 manualBaseModel *manModelContour;
906 for (i=0;i<numberOfContours;i++)
908 instantVector.clear();
909 fscanf(pFile,"%s",tmp); // Instant
910 fscanf(pFile,"%s",tmp); // 1
911 instantVector.push_back( atoi(tmp) );
912 fscanf(pFile,"%s",tmp); // 2
913 instantVector.push_back( atoi(tmp) );
914 fscanf(pFile,"%s",tmp); // 3
915 instantVector.push_back( atoi(tmp) );
916 fscanf(pFile,"%s",tmp); // 4
917 instantVector.push_back( atoi(tmp) );
918 fscanf(pFile,"%s",tmp); // 5
919 instantVector.push_back( atoi(tmp) );
920 fscanf(pFile,"%s",tmp); // 6
921 instantVector.push_back( atoi(tmp) );
923 fscanf(pFile,"%s",tmp); // TypeContourModel
924 fscanf(pFile,"%s",tmp); // ##
925 typeContourModel = atoi(tmp);
927 manModelContour = kernelManager->factoryManualContourModel(typeContourModel);
928 manModelContour->Open(pFile);
930 fscanf(pFile,"%s",tmp); // TypeView
931 fscanf(pFile,"%s",tmp); // ##
932 typeView = atoi(tmp);
935 theName = kernelManager->createOutline( manModelContour, instantVector );
936 bool addedModel = theName.compare("") != 0;
939 double spc[3];//Si no hay imagen pero hay contornos que spacing se pone por default
940 _theViewPanel->getSpacing(spc);
941 //Adding the manualContourControler to interface objects structure
942 //Adding the manualViewContour to interface objects structure
943 //_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.
944 _theViewPanel->getSceneManager()->configureViewControlTo( theName, manModelContour,spc , typeView) ;
947 if (staticContour==true)
949 Instant instant(&instantVector);
950 kernelManager->changeContourOfManager( theName , &instant );
952 }// for numberOfContours
957 void wxContourMainFrame::onLoad()
959 std::string fileNameContourROI = GetFileLocation();
960 //CMRU 03-09-09-----------------------------------------------------------------------------------------------
961 if(GetFileLocation().empty())
963 //------------------------------------------------------------------------------------------------------------
964 wxFileDialog dialog(NULL, _T("Choose a file"), _T(""), _T(""), _T("*.roi"), wxOPEN );
965 if (dialog.ShowModal() == wxID_OK)
967 fileNameContourROI = (const char *)(dialog.GetPath().mb_str());
971 onLoadContours(fileNameContourROI,true);
975 void wxContourMainFrame::SetZForAllContours(int pz)
977 printf("EED wxContourMainFrame::SetZForAllContours\n");
981 std::vector< std::string > lstNameThings;
982 int i,sizeLstNameThings;
983 int ii,sizeLstPoints;
985 lstNameThings = kernelManager->GetLstNameThings();
986 sizeLstNameThings = lstNameThings.size();
987 for (i=0 ; i<sizeLstNameThings ; i++)
989 printf("EED wxContourMainFrame::SetZForAllContours contour=%d \n", i );
990 manualBaseModel * manualModel = kernelManager->getOutlineByKeyName(lstNameThings[i]);
991 sizeLstPoints = manualModel->GetSizeLstPoints();
992 for (ii=0 ; ii<sizeLstPoints ; ii++)
994 manualModel->GetManualPoint(ii)->SetPointZ(-900);
995 }// for ii list of points
996 }// for i list of Things
1000 lstNameThings = kernelManager->GetLstNameThingsStatic();
1001 sizeLstNameThings = lstNameThings.size();
1002 for (i=0 ; i<sizeLstNameThings ; i++)
1004 manualBaseModel * manualModel = kernelManager->getOutlineByKeyName(lstNameThings[i]);
1005 sizeLstPoints = manualModel->GetSizeLstPoints();
1006 for (ii=0 ; ii<sizeLstPoints ; ii++)
1008 manualModel->GetManualPoint(ii)->SetPointZ(-900);
1009 }// for ii list of points
1010 }// for i list of static things
1015 void wxContourMainFrame::onLoadContours(std::string fileNameContourROI, bool interactiveInterface)
1020 FILE *pFile =fopen(fileNameContourROI.c_str(),"r+");
1023 //CMRU 03-09-09- ----------------------------------------------------------------------------------------------
1026 //------------------------------------------------------------------------------------------------------------
1027 fileNameContourROI.append("data");
1028 FILE *pFileData=fopen(fileNameContourROI.c_str(),"r+");
1029 if(pFileData != NULL)
1031 fscanf(pFileData,"%s",tmpD); // --CreaContour--
1032 fscanf(pFileData,"%s",tmpD); // Version
1033 fscanf(pFileData,"%s",tmpD); // 1.0.3 || 1.0.2 || 1.0.1 || 1.0.0
1035 fscanf(pFileData,"%s",tmpD); // onePixelSize
1036 fscanf(pFileData,"%s",tmpD); // #
1037 _onePixelSize = atof(tmpD);
1038 fscanf(pFileData,"%s",tmpD); // NumberOfContours
1039 fscanf(pFileData,"%s",tmpD); // #
1042 fscanf(pFile,"%s",tmp); // --CreaContour--
1044 fscanf(pFile,"%s",tmp); // Version
1045 fscanf(pFile,"%s",tmp); // 1.0.3 || 1.0.2 || 1.0.1 || 1.0.0
1046 std::string version(tmp);
1049 printf("EED wxContourMainFrame::onLoadContours version%s \n", version.c_str() );
1053 _tmpReadFileTypeOfTransformation=-1;
1054 if (version=="1.0.3")
1056 readDimSpc(pFile,interactiveInterface); // DimSpc interactive ON
1057 openContours(pFile,pFileData,false);
1058 openContours(pFile,pFileData,true); //Load StaticContours
1061 if (version=="1.0.2")
1064 readDimSpc(pFile,interactiveInterface); // DimSpc interactive ON
1065 openContours(pFile,pFileData,false);
1066 readDimSpc(pFile,false); // DimSpc interactive OFF
1067 openContours(pFile,pFileData,true); // Load StaticContours
1068 SetZForAllContours(-900);
1072 else if (version=="1.0.1")
1074 openContours(pFile,pFileData,false); //Skips ImageDimensions and ImageSpacing
1075 openContours(pFile,pFileData,true); //Load StaticContours, skips ImageDimensions and ImageSpacing
1079 else if (version=="1.0.0")
1081 openContours(pFile,pFileData,false); //Skips ImageDimensions and ImageSpacing
1086 if(pFileData != NULL)
1091 _theViewPanel->getSceneManager()->removeSceneContours();
1097 void wxContourMainFrame::onImport(){
1098 std::string filename, filenamecontours;
1099 wxFileDialog dialog(NULL, _T("Choose a XML Osirix File"), _T(""), _T(""), _T("*.xml"), wxOPEN );
1101 if (dialog.ShowModal() == wxID_OK)
1103 filename = dialog.GetPath().mb_str();
1104 filenamecontours = kernelManager->parseOsirixFile(filename);
1106 if(filenamecontours.compare("") != 0){
1107 onLoadContours(filenamecontours,true);
1112 void wxContourMainFrame::onTest(){
1113 std::string filename, filenamecontours;
1114 wxFileDialog dialog(NULL, _T("Choose a File"), _T(""), _T(""), _T("*.*"), wxOPEN );
1116 if (dialog.ShowModal() == wxID_OK)
1118 filename = dialog.GetPath().mb_str();
1119 std::cout << "This is the filename: " << filename << std::endl;
1125 void wxContourMainFrame::onSave(){
1126 //CMRU 03-09-09-----------------------------------------------------------------------------------------------
1127 if(GetFileLocation().empty())
1129 //------------------------------------------------------------------------------------------------------------
1130 wxFileDialog dialog(NULL, _T("Choose a file"), _T(""), _T(""), _T("*.roi"), wxSAVE );
1131 if (dialog.ShowModal() == wxID_OK)
1133 std::string fileNameContourROI = (const char *)(dialog.GetPath().mb_str());
1134 kernelManager->setCurrentFileName(fileNameContourROI);
1135 saveFileWithContours( fileNameContourROI );
1138 //CMRU 03-09-09-----------------------------------------------------------------------------------------------
1141 std::cout<<"Nombre del archivo: "<<GetFileLocation()<<std::endl;
1142 std::string fileNameContourROI = GetFileLocation();
1143 std::cout<<"Nombre del archivo: "<<fileNameContourROI<<std::endl;
1144 kernelManager->setCurrentFileName(fileNameContourROI);
1145 saveFileWithContours( fileNameContourROI);
1147 //------------------------------------------------------------------------------------------------------------
1151 void wxContourMainFrame::saveFileWithContours( std::string filename )
1154 FILE *pFile=fopen(filename.c_str(),"w+");
1156 //CMRU 03-09-09-----------------------------------------------------------------------------------------------
1157 filename.append("data");
1158 std::cout<<"Nombre del archivo: "<<filename<<std::endl;
1159 FILE *pFileData=fopen(filename.c_str(),"w+");
1160 //------------------------------------------------------------------------------------------------------------
1162 std::vector< std::string > lstNameThings;
1163 int i,sizeLstNameThings;
1165 fprintf(pFile,"--CreaContour--\n");
1166 fprintf(pFile,"Version %s\n", "1.0.3" );
1168 //CMRU 03-09-09-----------------------------------------------------------------------------------------------
1169 fprintf(pFileData,"--CreaContour--\n");
1170 fprintf(pFileData,"Version %s\n", "1.0.3" );
1171 fprintf(pFileData,"OnePixelSize %f\n", _onePixelSize);
1173 //------------------------------------------------------------------------------------------------------------
1175 vtkImageData *image = _images[0];
1178 image->GetDimensions(dimRange);
1180 fprintf(pFile,"ImageDimensions %d %d %d\n", dimRange[0], dimRange[1], dimRange[2] );
1183 image->GetSpacing(spaRange);
1185 fprintf(pFile,"ImageSpacing %f %f %f\n", spaRange[0], spaRange[1], spaRange[2] );
1189 lstNameThings = kernelManager->GetLstNameThings();
1190 sizeLstNameThings = lstNameThings.size();
1191 fprintf(pFile,"NumberOfContours %d\n", sizeLstNameThings );
1193 //CMRU 03-09-09-----------------------------------------------------------------------------------------------
1194 fprintf(pFileData,"NumberOfContours %d\n", sizeLstNameThings );
1195 //------------------------------------------------------------------------------------------------------------
1204 for (i=0 ; i<sizeLstNameThings ; i++)
1206 //CMRU 03-09-09-----------------------------------------------------------------------------------------------
1207 manualBaseModel * manualModel = kernelManager->getOutlineByKeyName(lstNameThings[i]);
1210 // double sizeInPixel = manualModel ->GetPathSize( );
1211 double sizeInPixel = manualModel ->GetPathSize( spc );
1213 double realContourSize = sizeInPixel*_onePixelSize;
1214 manualModel ->SetRealSize(realContourSize);
1215 //------------------------------------------------------------------------------------------------------------
1217 //int size= kernelManager->GetLstNameThings().size();
1219 kernelManager->SaveThingName( pFile, pFileData, lstNameThings[i] );
1220 _theViewPanel->getSceneManager()->SaveThingName( pFile, lstNameThings[i] );
1223 //-- Static Contours
1225 // fprintf(pFile,"ImageDimensions %d %d %d\n", dimRange[0], dimRange[1], dimRange[2] );
1226 // fprintf(pFile,"ImageSpacing %f %f %f\n", spaRange[0], spaRange[1], spaRange[2] );
1228 lstNameThings = kernelManager->GetLstNameThingsStatic();
1229 sizeLstNameThings = lstNameThings.size();
1230 fprintf(pFile,"NumberOfContoursStatic %d\n", sizeLstNameThings );
1232 //CMRU 03-09-09-----------------------------------------------------------------------------------------------
1233 fprintf(pFileData,"NumberOfContoursStatic %d\n", sizeLstNameThings );
1234 //------------------------------------------------------------------------------------------------------------
1236 for (i=0 ; i<sizeLstNameThings ; i++)
1238 kernelManager->SaveThingName( pFile, pFileData, lstNameThings[i] );
1239 _theViewPanel->getSceneManager()->SaveThingName( pFile, lstNameThings[i] );
1247 void wxContourMainFrame::readDimSpc(FILE *pFile, bool interactiveOption)
1251 double imageSpac[3];
1252 vtkImageData *image = _images[0];
1253 image->GetDimensions(imageDim);
1254 image->GetSpacing(imageSpac);
1256 fscanf(pFile,"%s",tmp); // ImageDimensions
1257 fscanf(pFile,"%s",tmp); // X
1258 _tmpReadFileImageDim[0] = atoi(tmp);
1259 fscanf(pFile,"%s",tmp); // Y
1260 _tmpReadFileImageDim[1] = atoi(tmp);
1261 fscanf(pFile,"%s",tmp); // Z
1262 _tmpReadFileImageDim[2] = atoi(tmp);
1264 fscanf(pFile,"%s",tmp); // ImageSpacing
1265 fscanf(pFile,"%s",tmp); // X
1266 _tmpReadFileImageSpac[0] = atof(tmp);
1267 fscanf(pFile,"%s",tmp); // Y
1268 _tmpReadFileImageSpac[1] = atof(tmp);
1269 fscanf(pFile,"%s",tmp); // Z
1270 _tmpReadFileImageSpac[2] = atof(tmp);
1273 if (interactiveOption==true)
1275 //Compare Spacing and Dims in X and Y (Necessary in Z?) - Just for Version 2
1276 if (imageDim[0]!=_tmpReadFileImageDim[0] || imageDim[1]!=_tmpReadFileImageDim[1] || imageSpac[0]!=_tmpReadFileImageSpac[0] || imageSpac[1]!=_tmpReadFileImageSpac[1])
1278 wxDialog* dial = new wxDialog (this,-1,_T("Tools"),wxDefaultPosition, wxSize(460,360));
1279 wxSizer* buttonsSizer = dial->CreateSeparatedButtonSizer(wxOK|wxCANCEL);
1280 wxBoxSizer *dialSizer = new wxBoxSizer(wxVERTICAL);
1282 wxString lstOptOperation[2];
1283 lstOptOperation[0]=_T("By Dimension");
1284 lstOptOperation[1]=_T("By Spacing");
1285 wxRadioBox * radioOpts = new wxRadioBox(dial, -1, _T("Type of Transformation"), wxDefaultPosition, wxSize(270,45), 2 , lstOptOperation, 2, wxRA_SPECIFY_COLS);
1287 dialSizer->Add( new wxStaticText(dial,-1,_T("The image resolution is not compatible with the ")) , 0, wxGROW );
1288 dialSizer->Add( new wxStaticText(dial,-1,_T("selected Roi file. Do you want to tranform it?")) , 0, wxGROW );
1289 dialSizer->Add( new wxStaticText(dial,-1,_T(" ")) , 0, wxGROW );
1290 dialSizer->Add(radioOpts,0,wxGROW);
1291 dialSizer->Add( new wxStaticText(dial,-1,_T(" ")) , 0, wxGROW );
1292 dialSizer->Add(buttonsSizer,0,wxGROW);
1293 dial->SetSizer(dialSizer, true);
1297 int _tmpReadFileTypeOfTransformation = -1;
1298 //EED bool transform = false;
1300 if (dial->GetReturnCode() == wxID_OK)
1302 _tmpReadFileTypeOfTransformation = radioOpts->GetSelection();
1306 } // if interactiveOption
1313 void wxContourMainFrame::openContours( FILE *pFile, FILE *pFileData, bool staticContour )
1318 vtkImageData *image = _images[0];
1321 double imageSpac[3];
1322 image->GetDimensions(imageDim);
1323 image->GetSpacing(imageSpac);
1326 fscanf(pFile,"%s",tmp); // NumberOfContours
1327 fscanf(pFile,"%s",tmp); // ##
1328 int numberOfContours = atoi(tmp);
1330 std::vector<int> instantVector;
1331 int typeContourModel;
1332 manualBaseModel *manModelContour;
1336 if (compatible==true)
1339 for (i=0;i<numberOfContours;i++)
1341 instantVector.clear();
1342 fscanf(pFile,"%s",tmp); // Instant
1344 fscanf(pFile,"%s",tmp); // 1
1345 instantVector.push_back( atoi(tmp) );
1346 fscanf(pFile,"%s",tmp); // 2
1347 instantVector.push_back( atoi(tmp) );
1348 fscanf(pFile,"%s",tmp); // 3
1349 instantVector.push_back( atoi(tmp) );
1350 fscanf(pFile,"%s",tmp); // 4
1351 instantVector.push_back( atoi(tmp) );
1352 fscanf(pFile,"%s",tmp); // 5
1353 instantVector.push_back( atoi(tmp) );
1354 fscanf(pFile,"%s",tmp); // 6
1355 instantVector.push_back( atoi(tmp) );
1358 fscanf(pFile,"%s",tmp); // TypeContourModel
1359 fscanf(pFile,"%s",tmp); // ##
1360 typeContourModel = atoi(tmp);
1362 manModelContour = kernelManager->factoryManualContourModel(typeContourModel);
1363 manModelContour->Open(pFile);
1364 if(pFileData != NULL)
1366 manModelContour->OpenData(pFileData);
1369 fscanf(pFile,"%s",tmp); // TypeView
1370 fscanf(pFile,"%s",tmp); // ##
1371 typeView = atoi(tmp);
1373 std::string theName;
1374 theName = kernelManager->createOutline( manModelContour, instantVector );
1375 bool addedModel = theName.compare("") != 0;
1378 double spc[3];//Si no hay imagen pero hay contornos que spacing se pone por default
1379 _theViewPanel->getSpacing(spc);
1380 //Adding the manualContourControler to interface objects structure
1381 //Adding the manualViewContour to interface objects structure
1382 //_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.
1383 _theViewPanel->getSceneManager()->configureViewControlTo( theName, manModelContour,spc , typeView) ;
1386 if (staticContour) //StaticContours (will appear in all slices)
1388 Instant instant(&instantVector);
1389 kernelManager->changeContourOfManager( theName , &instant );
1392 }// for numberOfContours
1395 else if (compatible==false)
1400 for (i=0;i<numberOfContours;i++)
1402 instantVector.clear();
1403 fscanf(pFile,"%s",tmp); // Instant
1405 fscanf(pFile,"%s",tmp); // 1
1406 instantVector.push_back( atoi(tmp) );
1407 fscanf(pFile,"%s",tmp); // 2
1408 instantVector.push_back( atoi(tmp) );
1409 fscanf(pFile,"%s",tmp); // 3
1410 instantVector.push_back( atoi(tmp) );
1411 fscanf(pFile,"%s",tmp); // 4
1412 instantVector.push_back( atoi(tmp) );
1413 fscanf(pFile,"%s",tmp); // 5
1414 instantVector.push_back( atoi(tmp) );
1415 fscanf(pFile,"%s",tmp); // 6
1416 instantVector.push_back( atoi(tmp) );
1418 fscanf(pFile,"%s",tmp); // TypeContourModel
1419 fscanf(pFile,"%s",tmp); // ##
1420 typeContourModel = atoi(tmp);
1422 manModelContour = kernelManager->factoryManualContourModel(typeContourModel);
1423 manModelContour->Open(pFile);
1424 if(pFileData != NULL)
1426 manModelContour->OpenData(pFileData);
1429 if (_tmpReadFileTypeOfTransformation==-1){
1431 } else if (_tmpReadFileTypeOfTransformation==0){
1432 double transX, transY;
1433 transX = (double) imageDim[0]/_tmpReadFileImageDim[0];
1434 transY = (double) imageDim[1]/_tmpReadFileImageDim[1];
1435 manModelContour->Transform_Ax_Plus_B(transX,0,transY,0);
1436 } else if (_tmpReadFileTypeOfTransformation==1) {
1437 double transX, transY;
1438 transX = (double) _tmpReadFileImageSpac[0]/imageDim[0];
1439 transY = (double) _tmpReadFileImageSpac[1]/imageDim[1];
1440 manModelContour->Transform_Ax_Plus_B(transX,0,transY,0);
1443 fscanf(pFile,"%s",tmp); // TypeView
1444 fscanf(pFile,"%s",tmp); // ##
1445 typeView = atoi(tmp);
1447 std::string theName;
1448 theName = kernelManager->createOutline( manModelContour, instantVector );
1449 bool addedModel = theName.compare("") != 0;
1452 double spc[3];//Si no hay imagen pero hay contornos que spacing se pone por default
1453 _theViewPanel->getSpacing(spc);
1454 //Adding the manualContourControler to interface objects structure
1455 //Adding the manualViewContour to interface objects structure
1456 //_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.
1457 _theViewPanel->getSceneManager()->configureViewControlTo( theName, manModelContour,spc , typeView) ;
1460 if (staticContour) //StaticContours (will appear in all slices)
1462 Instant instant(&instantVector);
1463 kernelManager->changeContourOfManager( theName , &instant );
1465 }// for numberOfContours
1471 void wxContourMainFrame::RefreshInterface(){
1473 _theViewPanel->RefreshInterface();
1474 //wxVtk2DBaseView *wxvtk2dbaseview = (wxVtk2DBaseView*)this->_theViewPanel->getWxVtkBaseView();
1475 //wxvtk2dbaseview->Refresh();
1478 vtkImageData* wxContourMainFrame::getImageData(){
1479 return _theViewPanel->getImageData();
1482 void wxContourMainFrame::onSegmentationOneSliceITK(wxString distance, wxString sigma, wxString alfa, wxString beta, wxString propagation, wxString iterations, wxString inflation)
1484 //JCP 20-10-08 Undo redo implementation
1486 //JCP 20-10-08 Undo redo implementation
1489 int x = _theViewPanel->GetX();
1490 int y = _theViewPanel->GetY();
1491 int z = _theViewPanel->GetZ();
1492 SegmentationOneSliceITK( x,y,z,distance, sigma, alfa, beta, propagation, iterations, inflation);
1496 void wxContourMainFrame::SegmentationOneSliceITK(int x, int y, int z, wxString distanc, wxString sigm, wxString alf, wxString bet, wxString prop, wxString iter, wxString inflation)
1498 int typeofcontour = 1;
1500 vtkImageData *imagedata = getImageData();
1502 //Tipo de pixeles a utilizar internamente en ITK
1503 typedef float InternalPixelType;
1504 const unsigned int Dimension = 2;
1505 typedef itk::Image< InternalPixelType, Dimension > InternalImageType;
1507 //Tipo de pixeles de salida 1
1508 typedef unsigned char OutputPixelType;
1509 typedef itk::Image< OutputPixelType, Dimension > OutputImageType;
1511 //Tipo de pixeles de salida 2
1512 typedef unsigned short OutputPixelType2;
1513 typedef itk::Image< OutputPixelType2, Dimension > OutputImageType2;
1515 //DefiniciÛn del thresholder
1516 typedef itk::BinaryThresholdImageFilter<
1518 OutputImageType > ThresholdingFilterType;
1520 //DefiniciÛn del primer filtro de conversiÛn de pixeles
1521 typedef itk::CastImageFilter<
1522 OutputImageType, OutputImageType2 > CastFilterType;
1524 //DefiniciÛn del segundo tipo de conversiÛn de pixeles
1525 typedef itk::CastImageFilter<
1526 OutputImageType2, InternalImageType > CastFilterType2;
1528 //Tercer tipo de conversiÛn
1529 typedef itk::RescaleIntensityImageFilter<
1531 OutputImageType > CastFilterType3;
1533 //Cuarto tipo de conversiÛn
1534 typedef itk::RescaleIntensityImageFilter<
1536 OutputImageType > CastFilterType4;
1538 ThresholdingFilterType::Pointer thresholder = ThresholdingFilterType::New();
1540 thresholder->SetLowerThreshold( 0.0 );
1541 thresholder->SetUpperThreshold( 128 );
1543 thresholder->SetOutsideValue( 255 );
1544 thresholder->SetInsideValue( 0 );
1546 //DefinciÛn de conexiÛnes entre VTK e ITK y el writer
1547 typedef itk::VTKImageToImageFilter<OutputImageType2> ConnectorType;
1548 typedef itk::ImageToVTKImageFilter<OutputImageType> ConnectorType2;
1549 //EED10JUIN2011 typedef itk::ImageFileWriter< OutputImageType > WriterType;
1551 ConnectorType::Pointer connector= ConnectorType::New();
1552 ConnectorType2::Pointer connector2= ConnectorType2::New();
1555 CastFilterType::Pointer filter=CastFilterType::New();
1556 CastFilterType2::Pointer filter2=CastFilterType2::New();
1558 connector->SetInput( imagedata );
1559 filter2->SetInput(connector->GetOutput());
1561 typedef itk::CurvatureAnisotropicDiffusionImageFilter<
1563 InternalImageType > SmoothingFilterType;
1565 SmoothingFilterType::Pointer smoothing = SmoothingFilterType::New();
1567 typedef itk::GradientMagnitudeRecursiveGaussianImageFilter<
1569 InternalImageType > GradientFilterType;
1571 typedef itk::SigmoidImageFilter<
1573 InternalImageType > SigmoidFilterType;
1575 GradientFilterType::Pointer gradientMagnitude = GradientFilterType::New();
1577 SigmoidFilterType::Pointer sigmoid = SigmoidFilterType::New();
1579 sigmoid->SetOutputMinimum( 0.0 );
1580 sigmoid->SetOutputMaximum( 255.0 );
1583 typedef itk::FastMarchingImageFilter<
1585 InternalImageType > FastMarchingFilterType;
1588 FastMarchingFilterType::Pointer fastMarching = FastMarchingFilterType::New();
1590 printf("EED wxContourMainFrame::SegmentationOneSliceITK Skypping this code. Not compiling GeodesicActiveContourLevelSetImageFilter in fedora 17 with ITK 3.20.1 \n ");
1592 > - > - > - > - > - > - > - > - > - > - > - > - > - > - > - > - Not compiling GeodesicActiveContourLevelSetImageFilter in fedora 17 with ITK 3.20.1
1595 typedef itk::GeodesicActiveContourLevelSetImageFilter< InternalImageType,
1596 InternalImageType > GeodesicActiveContourFilterType;
1597 GeodesicActiveContourFilterType::Pointer geodesicActiveContour =
1598 GeodesicActiveContourFilterType::New();
1600 typedef itk::ZeroCrossingImageFilter<
1602 InternalImageType > ZeroCrossingFilterType;
1603 ZeroCrossingFilterType::Pointer zeroCrossing =
1604 ZeroCrossingFilterType::New();
1606 const double propagationScaling = atof( crea::wx2std(prop).c_str() );
1608 geodesicActiveContour->SetPropagationScaling( propagationScaling );
1609 geodesicActiveContour->SetCurvatureScaling( 1.0 );
1610 geodesicActiveContour->SetAdvectionScaling( 1.0 );
1612 geodesicActiveContour->SetMaximumRMSError( 0.02 );
1613 int it=atoi( crea::wx2std(iter).c_str() );
1614 geodesicActiveContour->SetNumberOfIterations( it );
1616 smoothing->SetInput( filter2->GetOutput() );
1617 gradientMagnitude->SetInput( smoothing->GetOutput() );
1618 sigmoid->SetInput( gradientMagnitude->GetOutput() );
1619 fastMarching->SetInput( sigmoid->GetOutput() );
1620 geodesicActiveContour->SetInput( fastMarching->GetOutput() );
1621 geodesicActiveContour->SetFeatureImage( sigmoid->GetOutput() );
1623 zeroCrossing->SetInput( geodesicActiveContour->GetOutput() );
1624 //thresholder->SetInput( zeroCrossing->GetOutput() );
1625 thresholder->SetInput( geodesicActiveContour->GetOutput() );
1626 connector2->SetInput( thresholder->GetOutput() );
1628 < - < - < - < - < - < - < - < - < - < - < - < - < - < - < - < - < - < - < - < -
1634 smoothing->SetTimeStep( 0.125 );
1635 smoothing->SetNumberOfIterations( 5 );
1636 smoothing->SetConductanceParameter( 9.0 );
1639 const double sigma = atof( crea::wx2std(sigm).c_str() );
1640 gradientMagnitude->SetSigma( sigma );
1642 const double alpha = atof( crea::wx2std(alf).c_str() );
1643 const double beta = atof( crea::wx2std(bet).c_str() );
1645 sigmoid->SetAlpha( alpha );
1646 sigmoid->SetBeta( beta );
1648 typedef FastMarchingFilterType::NodeContainer NodeContainer;
1649 typedef FastMarchingFilterType::NodeType NodeType;
1651 NodeContainer::Pointer seeds = NodeContainer::New();
1653 InternalImageType::IndexType seedPosition;
1654 seedPosition[0] = x;
1655 seedPosition[1] = y;
1657 const double initialDistance = atof( crea::wx2std(distanc).c_str() );
1661 const double seedValue = - initialDistance;
1663 node.SetValue( seedValue );
1664 node.SetIndex( seedPosition );
1666 seeds->Initialize();
1667 seeds->InsertElement( 0, node );
1669 fastMarching->SetTrialPoints( seeds );
1671 fastMarching->SetSpeedConstant( 1.0 );
1673 fastMarching->SetOutputSize(
1674 connector->GetOutput()->GetBufferedRegion().GetSize() );
1676 fastMarching->SetStoppingValue( 800 );
1680 connector2->Update();
1681 vtkImageData *idata = connector2->GetOutput();
1683 vtkMarchingContourFilter* cntVTK = vtkMarchingContourFilter::New( );
1685 cntVTK->SetNumberOfContours( 1 );
1686 cntVTK->SetValue( 0, 255 );
1687 //EED 2017-01-01 Migration VTK7
1688 #if VTK_MAJOR_VERSION <= 5
1689 cntVTK->SetInput( idata );
1691 cntVTK->UpdateInformation();
1693 cntVTK->SetInputData( idata );
1696 vtkCleanPolyData* cpd = vtkCleanPolyData::New( );
1698 //EED 2017-01-01 Migration VTK7
1699 #if VTK_MAJOR_VERSION <= 5
1700 cpd->SetInput( cntVTK->GetOutput( ) );
1702 cpd->UpdateInformation();
1704 cpd->SetInputData( cntVTK->GetOutput( ) );
1708 vtkPolyDataConnectivityFilter* conn = vtkPolyDataConnectivityFilter::New( );
1709 conn->SetExtractionModeToLargestRegion( );
1710 //EED 2017-01-01 Migration VTK7
1711 #if VTK_MAJOR_VERSION <= 5
1712 conn->SetInput( cpd->GetOutput( ) );
1714 conn->UpdateInformation();
1716 conn->SetInputData( cpd->GetOutput( ) );
1720 vtkStripper* vtkstripper = vtkStripper::New( );
1722 //EED 2017-01-01 Migration VTK7
1723 #if VTK_MAJOR_VERSION <= 5
1724 vtkstripper->SetInput( conn->GetOutput() );
1725 vtkstripper->Update();
1726 vtkstripper->UpdateInformation();
1728 vtkstripper->SetInputData( conn->GetOutput() );
1732 vtkPolyData* polyDataResult = cntVTK->GetOutput();
1733 //std::cout<<"Points "<<polyDataResult->GetNumberOfPoints()<<std::endl;
1735 //EED 2017-01-01 Migration VTK7
1736 #if VTK_MAJOR_VERSION <= 5
1737 polyDataResult->Update( );
1738 polyDataResult->UpdateInformation();
1746 myfile.open ("C:/Creatis/example.txt");
1748 polyDataResult->Print(myfile);
1749 myfile << "-------------------------------------\n";
1750 polyDataResult->GetLines()->Print(myfile);
1758 //--Calculating control points
1760 std::vector<double> vecX;
1761 std::vector<double> vecY;
1762 std::vector<double> vecXo;
1763 std::vector<double> vecYo;
1764 std::vector<double>::iterator vecXoi;
1765 std::vector<double>::iterator vecYoi;
1766 std::vector<double> vecZ;
1768 std::vector<double> vecCtrlPointX;
1769 std::vector<double> vecCtrlPointY;
1770 std::vector<double> vecCtrlPointZ;
1776 int ii,size=polyDataResult->GetNumberOfPoints();
1778 myfile.open ("C:/Creatis/example2.txt");
1780 size=polyDataResult->GetNumberOfPoints();
1781 for (ii=0;ii<size;ii++)
1788 p = polyDataResult->GetPoint(ii);
1791 /*if(fabs(yAct-y)>20)
1793 if((xAct-x)>1 || (xAct-x)<-1)
1795 vecX.push_back( p[0] );
1796 vecY.push_back( p[1] );
1797 myfile <<p[0]<<","<<p[1]<<"\n";
1798 std::cout<<" x Anterior "<<xAct<<" x actual "<<x<<std::endl;
1799 std::cout<<" y Anterior "<<yAct<<" y actual "<<y<<std::endl;
1800 std::cout<<" x "<<p[0]<<" y "<<p[1]<<std::endl;
1801 vecZ.push_back( 900 );
1807 vecXo.push_back(p[0]);
1808 vecYo.push_back(p[1]);
1812 else*/ if(fabs(xAct-x)>11)
1814 vecXo.push_back(p[0]);
1815 vecYo.push_back(p[1]);
1819 vecX.push_back( p[0] );
1820 myfile <<p[0]<<","<<p[1]<<"\n";
1821 //std::cout<<" x Anterior "<<xAct<<" x actual "<<x<<std::endl;
1822 //std::cout<<" y Anterior "<<yAct<<" y actual "<<y<<std::endl;
1823 //std::cout<<" x "<<p[0]<<" y "<<p[1]<<std::endl;
1824 vecY.push_back( p[1] );
1825 vecZ.push_back( 900 );
1833 while(!vecXo.empty())
1835 vecX.push_back(vecXo.back());
1836 //std::cout<<" x Siguiente "<<vecXo.back();
1838 vecZ.push_back( 900 );
1840 while(!vecYo.empty())
1842 vecY.push_back(vecYo.back());
1847 /*for(int l=0;l<vecX.size();l++)
1851 vecXo.push_back(p[0]);
1852 vecYo.push_back(p[1]);
1863 ExtractControlPoints2D *extractcontrolpoints2d = new ExtractControlPoints2D();
1865 extractcontrolpoints2d->SetContour( &vecX , &vecY , &vecZ );
1869 extractcontrolpoints2d->GetInitialControlPoints( &vecCtrlPointX , &vecCtrlPointY , &vecCtrlPointZ );
1871 else if (method==1){
1872 extractcontrolpoints2d->GetControlPoints( &vecCtrlPointX , &vecCtrlPointY , &vecCtrlPointZ );
1874 else if (method==2){
1875 extractcontrolpoints2d->SetSamplingControlPoints( 15 );
1876 extractcontrolpoints2d->GetSamplingControlPoints( &vecCtrlPointX , &vecCtrlPointY , &vecCtrlPointZ );
1878 //--Adding contour to the system
1880 std::vector<int> actualInstantVector;
1881 _instantPanel->getInstant( actualInstantVector );
1882 actualInstantVector[1]=z;
1884 int j,sizeCtrPt = vecCtrlPointX.size();
1886 manualBaseModel *manModelContour = kernelManager->factoryManualContourModel( typeofcontour );
1887 manModelContour->SetNumberOfPointsSpline( ((sizeCtrPt/100)+1)*100 );
1889 for (j=0 ; j<sizeCtrPt ; j++)
1891 manModelContour->AddPoint( vecCtrlPointX[j] , vecCtrlPointY[j] , vecCtrlPointZ[j] );
1893 std::string theName;
1894 //theName = _modelManager->createOutline( manModelContour, actualInstantVector );
1895 theName = kernelManager->createOutline( manModelContour, actualInstantVector );
1896 bool addedModel = theName.compare("") != 0;
1899 double spc[3];//Si no hay imagen pero hay contornos que spacing se pone por default
1900 _theViewPanel->getSpacing(spc);
1901 //Adding the manualContourControler to interface objects structure
1902 //Adding the manualViewContour to interface objects structure
1903 //_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.
1904 _theViewPanel->configureViewControlTo(theName, manModelContour, spc, typeofcontour);
1905 //_theViewPanel->getSceneManager()->configureViewControlTo( theName, manModelContour,spc, typeofcontour ) ;
1912 WriterType::Pointer writer = WriterType::New();
1913 CastFilterType3::Pointer caster = CastFilterType3::New();
1915 caster->SetInput( gradientMagnitude->GetOutput() );
1916 writer->SetInput( caster->GetOutput() );
1917 writer->SetFileName("Gradient Magnitude.png");
1918 caster->SetOutputMinimum( 0 );
1919 caster->SetOutputMaximum( 255 );
1922 CastFilterType3::Pointer caster2 = CastFilterType3::New();
1923 WriterType::Pointer writer2 = WriterType::New();
1925 caster2->SetInput( sigmoid->GetOutput() );
1926 writer2->SetInput( caster2->GetOutput() );
1927 writer2->SetFileName("Sigmoid.png");
1928 caster2->SetOutputMinimum( 0 );
1929 caster2->SetOutputMaximum( 255 );
1932 CastFilterType3::Pointer caster3 = CastFilterType3::New();
1933 WriterType::Pointer writer3 = WriterType::New();
1935 caster3->SetInput( fastMarching->GetOutput() );
1936 writer3->SetInput( caster3->GetOutput() );
1937 writer3->SetFileName("FastMarching.bmp");
1938 caster3->SetOutputMinimum( 0 );
1939 caster3->SetOutputMaximum( 255 );
1942 CastFilterType3::Pointer caster4 = CastFilterType3::New();
1943 WriterType::Pointer writer4 = WriterType::New();
1945 caster4->SetInput( geodesicActiveContour->GetOutput() );
1946 writer4->SetInput( caster4->GetOutput() );
1947 writer4->SetFileName("GeodesicActiveContour.png");
1948 caster4->SetOutputMinimum( 0 );
1949 caster4->SetOutputMaximum( 255 );
1952 CastFilterType3::Pointer caster5 = CastFilterType3::New();
1953 WriterType::Pointer writer5 = WriterType::New();
1955 caster5->SetInput( zeroCrossing->GetOutput() );
1956 writer5->SetInput( caster5->GetOutput() );
1957 writer5->SetFileName("ZeroCrossing.bmp");
1958 caster5->SetOutputMinimum( 0 );
1959 caster5->SetOutputMaximum( 255 );
1963 catch( itk::ExceptionObject & excep )
1965 std::cerr << "Exception caught !" << std::endl;
1966 std::cerr << excep << std::endl;
1970 void wxContourMainFrame::onSegmentationOneSlice(int isovalue,int sampling,int method){
1972 //JCP 20-10-08 Undo redo implementation
1974 //JCP 20-10-08 Undo redo implementation
1977 int x = _theViewPanel->GetX();
1978 int y = _theViewPanel->GetY();
1979 int z = _theViewPanel->GetZ();
1980 SegmentationOneSlice( x,y,z,isovalue, sampling, method );
1985 void wxContourMainFrame::SegmentationOneSlice( int x, int y, int z, int isovalue, int sampling, int method )
1987 int typeofcontour = 1;
1988 //--Extracting Contour
1989 //vtkImageData *imagedata = _theViewPanel->getSceneManager()->GetImageData();
1990 vtkImageData *imagedata = getImageData();
1991 // double *range = imagedata->GetScalarRange();
1994 vtkImageReslice *imageReslice = vtkImageReslice::New();
1997 // imagedata->GetSpacing(spc);
2002 //EED 2017-01-01 Migration VTK7
2003 #if VTK_MAJOR_VERSION <= 5
2004 imageReslice->SetInput( imagedata );
2006 imageReslice->SetInputData( imagedata );
2008 imageReslice->SetInformationInput(imagedata);
2009 imageReslice->SetResliceAxesDirectionCosines(1,0,0, 0,1,0 ,0,0,1);
2010 imageReslice->SetResliceAxesOrigin(0,0,z);
2011 imageReslice->SetOutputDimensionality(2);
2012 imageReslice->SetInterpolationModeToLinear();
2014 //EED 2017-01-01 Migration VTK7
2015 #if VTK_MAJOR_VERSION <= 5
2018 imageReslice->Update();
2021 imagedata = imageReslice->GetOutput();
2022 //EED 2017-01-01 Migration VTK7
2023 #if VTK_MAJOR_VERSION <= 5
2024 imagedata->Update();
2025 imagedata->UpdateInformation();
2030 vtkContourFilter* cntVTK = vtkContourFilter::New( );
2031 //EED 2017-01-01 Migration VTK7
2032 #if VTK_MAJOR_VERSION <= 5
2033 cntVTK->SetInput( imagedata );
2035 cntVTK->SetInputData( imagedata );
2038 cntVTK->SetNumberOfContours( 1 );
2039 //cntVTK->SetValue( 0, vmin );
2040 // cntVTK->SetValue( 0, (range[1]*thr/100) );
2041 cntVTK->SetValue( 1, isovalue );
2042 // cntVTK->SetValue( 1, vmax );
2044 cntVTK->UpdateInformation();
2046 vtkCleanPolyData* cpd = vtkCleanPolyData::New( );
2047 //EED 2017-01-01 Migration VTK7
2048 #if VTK_MAJOR_VERSION <= 5
2049 cpd->SetInput( cntVTK->GetOutput( ) );
2051 cpd->SetInputData( cntVTK->GetOutput( ) );
2053 cpd->ConvertLinesToPointsOff( );
2055 cpd->UpdateInformation();
2057 vtkPolyDataConnectivityFilter* conn = vtkPolyDataConnectivityFilter::New( );
2058 conn->SetExtractionModeToClosestPointRegion( );
2059 //conn->SetMaxRecursionDepth( 3000 );
2061 //EED 2017-01-01 Migration VTK7
2062 #if VTK_MAJOR_VERSION <= 5
2063 conn->SetInput( cpd->GetOutput( ) );
2065 conn->SetInputData( cpd->GetOutput( ) );
2068 conn->SetClosestPoint( x, y, 0 );
2070 conn->UpdateInformation();
2072 vtkCleanPolyData* cpd2 = vtkCleanPolyData::New( );
2073 //EED 2017-01-01 Migration VTK7
2074 #if VTK_MAJOR_VERSION <= 5
2075 cpd2->SetInput( conn->GetOutput( ) );
2077 cpd2->SetInputData( conn->GetOutput( ) );
2080 cpd2->UpdateInformation();
2082 vtkStripper* vtkstripper = vtkStripper::New( );
2083 //EED 2017-01-01 Migration VTK7
2084 #if VTK_MAJOR_VERSION <= 5
2085 vtkstripper->SetInput( cpd2->GetOutput() );
2087 vtkstripper->SetInputData( cpd2->GetOutput() );
2089 vtkstripper->Update();
2090 vtkstripper->UpdateInformation();
2093 vtkPolyData* polyDataResult = vtkstripper->GetOutput();
2095 //EED 2017-01-01 Migration VTK7
2096 #if VTK_MAJOR_VERSION <= 5
2097 polyDataResult->Update( );
2098 polyDataResult->UpdateInformation();
2105 myfile.open ("c:/temp/example.txt");
2107 polyDataResult->Print(myfile);
2108 myfile << "-------------------------------------\n";
2109 polyDataResult->GetLines()->Print(myfile);
2119 //--Calculating control points
2121 std::vector<double> vecX;
2122 std::vector<double> vecY;
2123 std::vector<double> vecZ;
2125 std::vector<double> vecCtrlPointX;
2126 std::vector<double> vecCtrlPointY;
2127 std::vector<double> vecCtrlPointZ;
2131 int ii,size=polyDataResult->GetNumberOfPoints();
2133 for (ii=1;ii<=size;ii++)
2135 id = polyDataResult->GetLines()->GetData()->GetValue(ii);
2136 p = polyDataResult->GetPoint(id);
2139 vecX.push_back( p[0] );
2140 vecY.push_back( p[1] );
2141 vecZ.push_back( 900 );
2142 // vecZ.push_back( p[2] );
2146 ExtractControlPoints2D *extractcontrolpoints2d = new ExtractControlPoints2D();
2147 extractcontrolpoints2d->SetContour( &vecX , &vecY , &vecZ );
2150 /*if (methodRadiobox->GetSelection()==0){
2151 extractcontrolpoints2d->GetInitialControlPoints( &vecCtrlPointX , &vecCtrlPointY , &vecCtrlPointZ );
2153 if (methodRadiobox->GetSelection()==1){
2154 extractcontrolpoints2d->GetControlPoints( &vecCtrlPointX , &vecCtrlPointY , &vecCtrlPointZ );
2156 if (methodRadiobox->GetSelection()==2){
2157 extractcontrolpoints2d->SetSamplingControlPoints( sampling );
2158 extractcontrolpoints2d->GetSamplingControlPoints( &vecCtrlPointX , &vecCtrlPointY , &vecCtrlPointZ );
2162 extractcontrolpoints2d->GetInitialControlPoints( &vecCtrlPointX , &vecCtrlPointY , &vecCtrlPointZ );
2164 else if (method==1){
2165 extractcontrolpoints2d->GetControlPoints( &vecCtrlPointX , &vecCtrlPointY , &vecCtrlPointZ );
2167 else if (method==2){
2168 extractcontrolpoints2d->SetSamplingControlPoints( sampling );
2169 extractcontrolpoints2d->GetSamplingControlPoints( &vecCtrlPointX , &vecCtrlPointY , &vecCtrlPointZ );
2172 //--Adding contour to the system
2174 std::vector<int> actualInstantVector;
2175 _instantPanel->getInstant( actualInstantVector );
2176 actualInstantVector[1]=z;
2178 int j,sizeCtrPt = vecCtrlPointX.size();
2179 manualBaseModel *manModelContour = kernelManager->factoryManualContourModel( typeofcontour );
2180 manModelContour->SetNumberOfPointsSpline( ((sizeCtrPt/100)+1)*100 );
2182 for (j=0 ; j<sizeCtrPt ; j++)
2184 manModelContour->AddPoint( vecCtrlPointX[j] , vecCtrlPointY[j] , vecCtrlPointZ[j] );
2186 std::string theName;
2187 //theName = _modelManager->createOutline( manModelContour, actualInstantVector );
2188 theName = kernelManager->createOutline( manModelContour, actualInstantVector );
2189 bool addedModel = theName.compare("") != 0;
2192 double spc[3];//Si no hay imagen pero hay contornos que spacing se pone por default
2193 _theViewPanel->getSpacing(spc);
2194 //Adding the manualContourControler to interface objects structure
2195 //Adding the manualViewContour to interface objects structure
2196 //_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.
2197 _theViewPanel->configureViewControlTo(theName, manModelContour, spc, typeofcontour);
2198 //_theViewPanel->getSceneManager()->configureViewControlTo( theName, manModelContour,spc, typeofcontour ) ;
2202 int wxContourMainFrame::GetImageDataSizeZ(){
2203 return _theViewPanel->GetImageDataSizeZ();
2206 void wxContourMainFrame::GetImageDataRange(double *range){
2207 _theViewPanel->GetImageDataRange(range);
2210 void wxContourMainFrame::onSegmentationAllSlice(int minZ,int maxZ,int isovalue,int sampling,int method){
2211 //JCP 20-10-08 Undo redo implementation
2213 //JCP 20-10-08 Undo redo implementation
2216 int x = _theViewPanel->GetX();
2217 int y = _theViewPanel->GetY();
2221 double totalZ = maxZ-minZ+1;
2222 for( z=minZ ; z<=maxZ ; z++ )
2224 porcent = 100.0* (z-minZ)/totalZ;
2225 tmpString.Printf(_T(" %d %c %d/%d %d"), (int)porcent , 37 , z-minZ+1, (int)totalZ,z );
2226 interfMainPanel::getInstance()->setLabelSegmentationPanelVTK(tmpString);
2227 //_staticTextSegmentation->SetLabel(tmpString);
2228 SegmentationOneSlice( x,y,z,isovalue, sampling,method );
2230 interfMainPanel::getInstance()->setLabelSegmentationPanelVTK(_T(" "));
2235 //Creates a reference line to be used as the axis of the mirroring
2236 void wxContourMainFrame::referenceLine()
2238 if (_refLineControl==NULL)
2243 vtkImageData *vtkimagedata = _theViewPanel->getImageData();
2244 vtkimagedata->GetSpacing(spc);
2246 wxVtkBaseView * viewer2D = _theViewPanel->getWxVtkBaseView();
2248 _refLineControl = new manualLineControler();
2249 _refLineModel = new manualContourModelLine();
2250 _refLineView = new manualViewLine();
2251 _refLineView->SetModel( _refLineModel );
2252 _refLineView->SetWxVtkBaseView( viewer2D );
2253 _refLineView->SetRange( 2 );
2254 _refLineView->SetZ( 1200 );
2256 _refLineView->SetSpacing(spc);
2258 _refLineView->SetColorNormalContour(0, 0, 1);
2259 _refLineView->SetColorEditContour(0, 0.5, 0.5);
2260 _refLineView->SetWidthLine(4);
2262 _refLineControl->SetModelView( _refLineModel , _refLineView );
2263 vtkInteractorStyleBaseView* style = (vtkInteractorStyleBaseView*)viewer2D->GetInteractorStyleBaseView();
2264 style->AddInteractorStyleMaracas( _refLineControl );
2265 _refLineModel->SetCloseContour(false);
2266 _refLineControl->CreateNewManualContour();
2268 //AD: Inicializar el mirroring con una linea ya pintada
2270 double z = _refLineControl->GetZ();
2273 image->GetDimensions(imageDim);
2274 double x = (double) imageDim[0]/2;
2275 double y1 = (double) (imageDim[1]/2)+15;
2276 double y2 = (double) (imageDim[1]/2)-15;
2278 _refLineControl->AddPoint(x,y1,z);
2279 _refLineControl->AddPoint(x,y2,z);
2280 _refLineControl->SetCompleteCreation(true);
2282 _refLineModel->AddPoint(x,y1,z);
2283 _refLineModel->AddPoint(x,y2,z);
2284 _refLineModel->UpdateSpline();
2286 _refLineView->UpdateViewPoint(0);
2287 _refLineView->UpdateViewPoint(1);
2290 _refLineControl->SetActive(true);
2291 _refLineView->RefreshContour();
2295 //Hides the referenceLine
2296 void wxContourMainFrame::refLineHide()
2298 if (_refLineControl!=NULL)
2300 if (_refLineControl->GetActive())
2302 _refLineView->RemoveCompleteContourActor();
2303 _refLineControl->SetEditable(false);
2304 _refLineControl->SetActive(false);
2311 //Shows the referenceLine
2312 void wxContourMainFrame::refLineShow()
2314 if (_refLineControl!=NULL)
2316 if (_refLineControl->GetActive()==false)
2318 wxVtkBaseView * viewer2D = _theViewPanel->getWxVtkBaseView();
2320 _refLineView->SetModel( _refLineModel );
2321 _refLineView->SetWxVtkBaseView( viewer2D );
2322 _refLineView->SetRange( 2 );
2323 _refLineView->SetZ( 1200 );
2325 _refLineControl->SetModelView( _refLineModel , _refLineView );
2326 vtkInteractorStyleBaseView* style = (vtkInteractorStyleBaseView*)viewer2D->GetInteractorStyleBaseView();
2327 style->AddInteractorStyleMaracas( _refLineControl );
2328 _refLineControl->CreateNewManualContour();
2329 _refLineControl->SetActive(true);
2330 _refLineView->RefreshContour();
2337 void wxContourMainFrame::refLineChangeWidth(int width)
2339 _refLineView->SetWidthLine(width);
2340 _refLineView->RefreshContour();
2346 void wxContourMainFrame::onMirror()
2349 std::vector<std::string> currentSelection = _theViewPanel->getSelectedObjects();
2350 std::vector<std::string> filterCurrentSelection;
2352 std::vector<int> tempVector;
2353 _instantPanel->getInstant( tempVector );
2354 _performingOperation->reset();
2355 _performingOperation->setStartCommand( COPY );
2356 _performingOperation->setStartOperationInstantVector( tempVector );
2357 _performingOperation->setKeyNamesOperationElems( currentSelection );
2359 char theStartCommand = _performingOperation->getStartCommand();
2360 if ( theStartCommand == COPY )
2362 //JCP 20-10-08 Undo redo implementation
2364 //JCP 20-10-08 Undo redo implementation
2365 std::vector<int> tempVector;
2366 _instantPanel->getInstant( tempVector );
2367 _performingOperation->setEndOperationInstantVector ( tempVector );
2368 std::vector<std::string> elems = _performingOperation->getKeyNamesOperationElems();
2369 int i,size = elems.size();
2370 for( i=0; i<size; i++ )
2372 createMirrorContourOf( elems[i], tempVector, i>0 );
2376 //deleteContour( _refName );
2381 void wxContourMainFrame::showAxis(bool show)
2383 _theViewPanel->SetVisibleAxis(show);
2384 _theViewPanel->Refresh();
2388 void wxContourMainFrame::onRigidPressed(){
2389 std::vector<std::string> currentSelection = _theViewPanel->getSelectedObjects();
2390 int elementsSelected = currentSelection.size();
2392 if ( elementsSelected >= 1 ){
2393 //JCP 20-10-08 Undo redo implementation
2395 //JCP 20-10-08 Undo redo implementation
2397 std::vector<int> tempVector;
2398 _instantPanel->getInstant( tempVector );
2399 Instant instant(&tempVector);
2401 int i , size=currentSelection.size();
2402 for ( i=0 ; i<size ; i++ )
2404 kernelManager->changeContourOfManager(currentSelection[i], &instant);
2409 void wxContourMainFrame::onWidthOfContour(double width){
2411 _theViewPanel->removeSceneContours();
2412 _theViewPanel->SetWidthContour(width);
2414 //_theViewPanel->getSceneManager()->SetWidthContour( width );
2419 int wxContourMainFrame::getColorWindow()
2423 vtkImageData * img = getImageData();
2424 img->GetScalarRange(range);
2426 std::cout<<"Val 1: "<<range[0]<<" Val 2: "<<range[1]<<std::endl;
2428 return (int)range[1];
2430 return _theViewPanel->getColorWindow();
2433 int wxContourMainFrame::getWindowLevel()
2437 vtkImageData * img = getImageData();
2438 img->GetScalarRange(range);
2440 std::cout<<"Val 1: "<<range[0]<<" Val 2: "<<range[1]<<std::endl;
2442 return (int)range[1];
2444 return _theViewPanel->getWindowLevel();
2447 void wxContourMainFrame::onBrigthnessColorWindowLevel(int colorwindow,int windowlevel){
2448 _theViewPanel->onBrigthnessColorWindowLevel(colorwindow, windowlevel);
2453 void wxContourMainFrame::onInterpolation(bool interpolate){
2454 _theViewPanel->onInterpolation(interpolate);
2458 void wxContourMainFrame::onChangeInstant(std::string name,int actual){
2459 _instantPanel->setConceptValue( name, actual );
2463 void wxContourMainFrame::resetAppend(){
2464 kernelManager->resetAppend();
2469 void wxContourMainFrame::onSpreadAdd(){
2470 std::vector<double> vecX;
2471 std::vector<double> vecY;
2472 std::vector<double> vecZ;
2473 _theViewPanel->GetPointsOfActualContour(&vecX , &vecY , &vecZ );
2474 std::vector<int> tempVector;
2475 _instantPanel->getInstant( tempVector );
2476 std::string val = kernelManager->onSpreadAdd(&vecX , &vecY , &vecZ, tempVector);
2477 interfMainPanel::getInstance()->appendStringSpread(val);
2481 void wxContourMainFrame::onSpreadAddAll(){
2483 std::vector<int> tempVector;
2484 _instantPanel->getInstant( tempVector );
2487 maxZ = interfMainPanel::getInstance()->GetImageDataSizeZ();
2489 int sizeLstContourThings;
2490 for ( z=minZ ; z<=maxZ ; z++ )
2493 Instant instant(&tempVector);
2494 std::vector<ContourThing**> lstContourThings = kernelManager->getOutlinesAtInstant( &instant );
2495 sizeLstContourThings = lstContourThings.size();
2496 if (sizeLstContourThings>=1)
2498 std::vector<double> vecX;
2499 std::vector<double> vecY;
2500 std::vector<double> vecZ;
2501 ContourThing **contourthing = lstContourThings[0];
2502 manualBaseModel *cModel = (*contourthing)->getModel();
2503 int i,size = cModel->GetNumberOfPointsSpline();
2505 for (i=0; i<size; i++)
2507 cModel->GetSpline_i_Point(i, &x, &y, &z);
2512 std::string val = kernelManager->onSpreadAdd(&vecX , &vecY , &vecZ, tempVector);
2513 interfMainPanel::getInstance()->appendStringSpread(val);
2514 }// if sizeLstContourThings
2519 void wxContourMainFrame::onSpreadGo(int type){
2520 //JCP 20-10-08 Undo redo implementation
2522 //JCP 20-10-08 Undo redo implementation
2524 std::vector<double> vecCtrlPointX;
2525 std::vector<double> vecCtrlPointY;
2526 std::vector<double> vecCtrlPointZ;
2530 std::vector<int> tempVector;
2531 _instantPanel->getInstant( tempVector );
2534 kernelManager->getMaxMinZ(&minZ,&maxZ);
2535 //JSTG_16-07-08_----------------------------------------------------------------
2536 //_contourPropagation->setInterpolationNumber(maxZ-minZ+1);
2537 kernelManager->CalculeSplinePropagation();
2539 double totalZ = maxZ-minZ+1;
2542 //--------------------------------------------------------------------
2543 for ( z=(int)minZ ; z<=(int)maxZ ; z++ )
2545 porcent = 100.0* (z-minZ)/totalZ;
2546 int numero = (int)(z-minZ+1)/(int)totalZ;
2547 std::string stringtemp = " "+kernelManager->intToString(porcent)+"% "+kernelManager->intToString(numero)+" "+kernelManager->intToString(z);
2549 interfMainPanel::getInstance()->setStringSpread(stringtemp);
2551 int typeofcontour = 1;
2552 std::string theName;
2553 manualBaseModel* manModelContour = kernelManager->GetPoints(z, type, &vecCtrlPointX,&vecCtrlPointY,&vecCtrlPointZ, theName,typeofcontour, tempVector);
2555 if( manModelContour!=NULL ){
2556 double spc[3];//Si no hay imagen pero hay contornos que spacing se pone por default
2557 this->_theViewPanel->getSpacing(spc);
2558 //Adding the manualContourControler to interface objects structure
2559 //Adding the manualViewContour to interface objects structure
2560 //_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.
2561 _theViewPanel->configureViewControlTo( theName, manModelContour,spc,typeofcontour ) ;
2566 int numero = (int)(z-minZ+1)/(int)totalZ;
2567 std::string stringtemp = " "+kernelManager->intToString(porcent)+"% "+kernelManager->intToString(numero)+" "+kernelManager->intToString(z);
2569 interfMainPanel::getInstance()->setStringSpread(stringtemp);
2571 //RefreshInterface();
2574 void wxContourMainFrame::getInstantVector(std::vector<int>& tempVector){
2578 std::vector<std::string> wxContourMainFrame::getOutlinesName(int slide){
2579 std::vector<int> tempVector;
2580 _instantPanel->getInstant(tempVector);
2581 //Asignation of slide number should be different ex by name
2582 tempVector[1]=slide;
2583 return kernelManager->getOutlinesNameAtInstant(tempVector);
2587 void wxContourMainFrame::SetScalarRange(int grayRangeMin, int grayRangeMax)
2589 _contourextractdata->SetScalarRange(grayRangeMin,grayRangeMax);
2593 void wxContourMainFrame::onInformationContourLabels(int typeContourGroup,int selection,int minimumZ,int maximumZ,int grayRangeMin, int grayRangeMax)
2596 wxString tempString;
2597 int maxContourGroup = 0;
2599 _contourextractdata ->SetTypeOperation( typeContourGroup % 3 );
2601 std::vector<manualBaseModel*> lstManConMod;
2602 std::vector<manualBaseModel*> lstManConModTmp;
2603 std::vector<manualBaseModel*> lstManConModExp;
2604 std::vector<double> pLstValue;
2605 std::vector<double> pLstValuePosX;
2606 std::vector<double> pLstValuePosY;
2607 std::vector<double> pLstValuePosZ;
2610 int resultGrayRangeCount;
2613 double resultAverage;
2614 double resultStandardeviation;
2616 std::vector<int> tempVector;
2617 _instantPanel->getInstant( tempVector );
2620 int ii,sizeLstContourThings;
2629 if (selection==0 ) // actual slice
2631 int actualSlice = tempVector[1];
2634 } else { // slice range
2640 totalZ = maxZ-minZ+1;
2642 _contourextractdata->InitVolumeStatistics();
2645 for ( z=minZ ; z<=maxZ ; z++ )
2648 porcent = 100.0* (z-minZ)/totalZ;
2649 tmpString.Printf(_T(" %d %c %d/%d %d"), (int)porcent , 37 , z-minZ+1, (int)totalZ ,z);
2651 interfMainPanel::getInstance()->setStringInfoPanel(tmpString);
2652 //_staticTextInformation->SetLabel(tmpString);
2654 //Extraction data from contours of each slice
2655 _contourextractdata->SetZtoBeAnalys(z);
2658 Instant instant(&tempVector);
2659 std::vector<ContourThing**> lstContourThings = kernelManager->getOutlinesAtInstant( &instant );
2660 sizeLstContourThings = lstContourThings.size();
2662 lstManConMod.clear();
2663 for (ii=0 ; ii<sizeLstContourThings ; ii++)
2665 ContourThing **contourthing = lstContourThings[ii];
2666 lstManConMod.push_back( (*contourthing)->getModel() );
2669 lstManConModExp = kernelManager->ExploseEachModel( lstManConMod );
2671 tempString.Printf(_T("%d - %d"),z, sizeLstContourThings);
2672 interfMainPanel::getInstance()->setRowLabelInfoPanel(z, tempString);
2673 //_grid->SetRowLabelValue(z, tempString );
2675 int iContourGroup,sizeContourGroup;
2676 if (typeContourGroup==3) // contour separete
2678 sizeContourGroup=lstManConModExp.size();
2679 if ( maxContourGroup<sizeContourGroup )
2681 maxContourGroup=sizeContourGroup;
2683 } else { // contour AND OR XOR
2690 for( iContourGroup=0 ; iContourGroup<sizeContourGroup ; iContourGroup++ ){
2691 lstManConModTmp.clear();
2695 if (typeContourGroup==3) // contour separete
2697 lstManConModTmp.push_back( lstManConModExp[iContourGroup]);
2698 } else { // contour AND OR XOR
2699 lstManConModTmp = lstManConModExp;
2702 _contourextractdata->SetLstManualContourModel( lstManConModTmp );
2703 _contourextractdata->SetScalarRange(grayRangeMin,grayRangeMax);
2706 pLstValuePosX.clear();
2707 pLstValuePosY.clear();
2708 pLstValuePosZ.clear();
2712 _contourextractdata->GetValuesInsideCrown( &numberOfPixels,
2718 resultSize=numberOfPixels;
2719 // Statistics of each slice.
2720 _contourextractdata->Statistics( &pLstValue,
2723 &resultGrayRangeCount,
2728 &resultStandardeviation);
2730 if (interfMainPanel::getInstance()->getNumberColsInformationPanel()<_numberOfVariablesStatistics*(iContourGroup+1) )
2732 interfMainPanel::getInstance()->appendColsInformationPanel(_numberOfVariablesStatistics);
2735 tmpIntA=_numberOfVariablesStatistics*iContourGroup ;
2737 tempString.Printf(_T("%d"),numberOfPixels);
2739 interfMainPanel::getInstance()->setCellValueInfoPanel(z, tmpIntA, tempString);
2741 tempString.Printf(_T("%d"),resultGrayRangeCount);
2742 interfMainPanel::getInstance()->setCellValueInfoPanel(z, tmpIntA+1, tempString);
2744 tempString.Printf(_T("%f"),resultMin);
2745 interfMainPanel::getInstance()->setCellValueInfoPanel(z, tmpIntA+2, tempString);
2747 tempString.Printf(_T("%f"),resultMax);
2748 interfMainPanel::getInstance()->setCellValueInfoPanel(z, tmpIntA+3, tempString);
2750 tempString.Printf(_T("%f"),resultAverage);
2751 interfMainPanel::getInstance()->setCellValueInfoPanel(z, tmpIntA+4, tempString);
2753 tempString.Printf(_T("%f"),resultStandardeviation);
2754 interfMainPanel::getInstance()->setCellValueInfoPanel(z, tmpIntA+5, tempString);
2757 } // for iContourGroup
2760 // Print Volume Statistics
2763 int vol_rCountRange;
2765 double vol_minValue;
2766 double vol_maxValue;
2768 double vol_standardeviation;
2770 if (selection!=0 ) // actual slice
2773 _contourextractdata->GetVolumeStatistics(&vol_rCountRange, &vol_rsize,
2774 &vol_minValue, &vol_maxValue,
2775 &vol_average, &vol_standardeviation);
2777 interfMainPanel::getInstance()->setRowLabelInfoPanel(maxZ+2, _T("Total:"));
2779 tempString.Printf(_T("%d"),vol_rsize);
2780 interfMainPanel::getInstance()->setCellValueInfoPanel(maxZ+2, 0, tempString);
2782 tempString.Printf(_T("%d"),vol_rCountRange);
2783 interfMainPanel::getInstance()->setCellValueInfoPanel(maxZ+2, 1, tempString);
2785 tempString.Printf(_T("%f"),vol_minValue);
2786 interfMainPanel::getInstance()->setCellValueInfoPanel(maxZ+2, 2, tempString);
2788 tempString.Printf(_T("%f"),vol_maxValue);
2789 interfMainPanel::getInstance()->setCellValueInfoPanel(maxZ+2, 3, tempString);
2791 tempString.Printf(_T("%f"),vol_average);
2792 interfMainPanel::getInstance()->setCellValueInfoPanel(maxZ+2, 4, tempString);
2794 tempString.Printf(_T("%f"),vol_standardeviation);
2795 interfMainPanel::getInstance()->setCellValueInfoPanel(maxZ+2, 5, tempString);
2797 //-----------------------------------------
2800 wxString tmpTitleString;
2802 for ( iTitleGroup=0 ; iTitleGroup<maxContourGroup ; iTitleGroup++ )
2804 tmpIntB =_numberOfVariablesStatistics*iTitleGroup;
2805 tmpTitleString.Printf(_T("%d-Size Data"),iTitleGroup);
2806 interfMainPanel::getInstance()->setColLableInfoPanel(tmpIntB + 0, tmpTitleString);
2808 interfMainPanel::getInstance()->setColLableInfoPanel(tmpIntB + 0, tmpTitleString );
2809 interfMainPanel::getInstance()->setColLableInfoPanel( tmpIntB + 1, _T("Size Range") );
2810 interfMainPanel::getInstance()->setColLableInfoPanel( tmpIntB + 2, _T("Min") );
2811 interfMainPanel::getInstance()->setColLableInfoPanel( tmpIntB + 3, _T("Max") );
2812 interfMainPanel::getInstance()->setColLableInfoPanel( tmpIntB + 4, _T("Average") );
2813 interfMainPanel::getInstance()->setColLableInfoPanel( tmpIntB + 5, _T("St.Dev.") );
2814 interfMainPanel::getInstance()->setColLableInfoPanel( tmpIntB + 6, _T(" ") );
2816 interfMainPanel::getInstance()->setStringInfoPanel( _T("") );
2820 void wxContourMainFrame::onSaveResults(std::string directory,std::string namefile, std::string filename,
2821 int typeContourGroup, int selection, int minZ, int maxZ, bool XYZValues, bool contourImage, bool statistics)
2825 SaveValuesXYZ( directory , namefile, typeContourGroup );
2830 vtkImageData * mask;
2831 vtkImageData * value;
2832 this->getMaskValue(&mask, &value, typeContourGroup,selection,minZ,maxZ);
2833 this->SaveImageResult( directory , namefile, mask, value);
2838 std::ostringstream name;
2839 name << filename << ".xls";
2842 FILE *pFile=fopen(name.str().c_str(),"w+");
2848 // int sizeZ = _theViewPanel->GetImageDataSizeZ();
2849 // int maxY=sizeZ+2;
2851 maxX= interfMainPanel::getInstance()->getNumberColsInformationPanel();//this->_grid->GetNumberCols();
2854 int iTitle,sizeTitle = (maxX / _numberOfVariablesStatistics);
2855 for ( iTitle=0; iTitle<sizeTitle ; iTitle++)
2857 // fprintf(pFile,"-- \t %d-Size \t SizeRange \t Min \t Max \t Ave \t StDv \t" , iTitle,tmpString.c_str() );
2858 fprintf(pFile,"slice\t %d-Size \t SizeRange \t Min \t Max \t Ave \t StDv \t" , iTitle );
2860 fprintf(pFile,"\n\n" );
2864 if (selection==0 ) // actual slice
2866 std::vector<int> tempVector;
2867 _instantPanel->getInstant( tempVector );
2868 int actualSlice = tempVector[1];
2874 for ( j=minZ; j<=maxZ ; j++)
2876 fprintf(pFile,"%d\t" , j );
2877 for (i=0 ; i<maxX ; i++){
2878 tmpString = interfMainPanel::getInstance()->getCellValue(j, i);//_grid->GetCellValue( j , i );
2879 fprintf(pFile,"%s\t" , (const char *)(tmpString.mb_str()) );
2881 fprintf(pFile,"\n" );
2885 // Total of stadistics.....
2888 fprintf(pFile,"\n Total:\t" );
2889 for (i=0 ; i<maxX ; i++){
2890 tmpString = interfMainPanel::getInstance()->getCellValue(maxZ+2, i);//_grid->GetCellValue( maxZ+2 , i );
2891 fprintf(pFile,"%s\t" , (const char *)(tmpString.mb_str()) );
2893 fprintf(pFile,"\n" );
2901 void wxContourMainFrame::SaveValuesXYZ(std::string directory,std::string namefile,int typeContourGroup)
2905 //int typeContourGroup = this->_radiolstboxContourGroup->GetSelection();
2906 _contourextractdata ->SetTypeOperation( typeContourGroup % 3 );
2908 std::vector<manualBaseModel*> lstManConMod;
2909 std::vector<manualBaseModel*> lstManConModTmp;
2910 std::vector<manualBaseModel*> lstManConModExp;
2911 std::vector<double> pLstValue;
2912 std::vector<double> pLstValuePosX;
2913 std::vector<double> pLstValuePosY;
2914 std::vector<double> pLstValuePosZ;
2916 std::vector<int> tempVector;
2917 _instantPanel->getInstant( tempVector );
2919 int sizeZ = _theViewPanel->getSceneManager()->GetImageDataSizeZ();
2921 int ii,sizeLstContourThings;
2928 minZ = 0;// _mbarrange->GetStart();
2929 maxZ = sizeZ;//_mbarrange->GetEnd();
2930 totalZ = maxZ-minZ+1;
2934 for ( z=0 ; z<sizeZ ; z++)
2937 porcent = 100.0* (z-minZ)/totalZ;
2939 tmpString.Printf(_T("Saving Values"));
2940 tmpString.Printf(_T(" %d %c %d/%d %d"), (int)porcent , 37 , z-minZ+1, (int)totalZ ,z);
2941 interfMainPanel::getInstance()->setStringInfoPanel(tmpString);
2942 //_staticTextInformation->SetLabel(tmpString);
2945 //Extraction data from contours of each slice
2946 _contourextractdata->SetZtoBeAnalys( z);
2949 Instant instant(&tempVector);
2950 std::vector<ContourThing**> lstContourThings = kernelManager->getOutlinesAtInstant(&instant);//this->_modelManager->getOutlinesAtInstant( &instant );
2951 sizeLstContourThings = lstContourThings.size();
2953 lstManConMod.clear();
2954 for (ii=0 ; ii<sizeLstContourThings ; ii++)
2956 ContourThing **contourthing = lstContourThings[ii];
2957 lstManConMod.push_back( (*contourthing)->getModel() );
2959 lstManConModExp = kernelManager->ExploseEachModel( lstManConMod );
2964 int iContourGroup,sizeContourGroup;
2965 if (typeContourGroup==3) // contour separete
2967 sizeContourGroup=lstManConModExp.size();
2968 } else { // contour AND OR XOR
2972 for( iContourGroup=0 ; iContourGroup<sizeContourGroup ; iContourGroup++ ){
2973 lstManConModTmp.clear();
2974 if (typeContourGroup==3) // contour separete
2976 lstManConModTmp.push_back( lstManConModExp[iContourGroup]);
2977 } else { // contour AND OR XOR
2978 lstManConModTmp = lstManConModExp;
2981 _contourextractdata->SetLstManualContourModel( lstManConModTmp );
2984 pLstValuePosX.clear();
2985 pLstValuePosY.clear();
2986 pLstValuePosZ.clear();
2988 _contourextractdata->GetValuesInsideCrown( &numberOfPixels,
2994 std::string temp = directory + "/" + namefile + "-slice";
2995 temp = temp + kernelManager->intToString(z) + "-cont" + kernelManager->intToString(iContourGroup);
2996 temp = temp + ".txt";
2998 // LG 14/01/09 : using crea
2999 wxString filename = crea::std2wx(temp);
3000 /*filename.Printf(_T("%s"),directory.c_str());
3001 filename.append(_T("\\"));
3002 filename.append(_T("%s"),namefile.c_str());
3003 filename.append(_T("-slice"));
3004 filename.append(_T("%d"),z);
3005 filename.append(_T("-cont"));
3006 filename.append(_T("%d"),iContourGroup);
3007 filename.append(_T(".txt"));*/
3008 // filename.Printf(temp.c_str());
3012 FILE *pFile=fopen((const char *)filename.mb_str(),"w+");
3013 fprintf(pFile,"value \t x \t y \t z\n" );
3014 int iLstValue,sizeLstValue=pLstValue.size();
3015 for (iLstValue=0 ; iLstValue<sizeLstValue ; iLstValue++ )
3017 fprintf(pFile,"%f\t %f\t %f\t %f\n", (float)pLstValue[iLstValue] , (float)pLstValuePosX[iLstValue], (float)pLstValuePosY[iLstValue], (float)z );
3020 } // for iContourGroup
3022 interfMainPanel::getInstance()->setStringInfoPanel(_T(""));
3023 //_staticTextInformation->SetLabel( _T("") );
3027 void wxContourMainFrame::getMaskValue(vtkImageData ** mask,vtkImageData ** value,int typeContourGroup, int selection, int minZ, int maxZ){
3030 //int typeContourGroup = this->_radiolstboxContourGroup->GetSelection();
3031 if (typeContourGroup==3)
3035 _contourextractdata ->SetTypeOperation( typeContourGroup % 3 );
3037 std::vector<manualBaseModel*> lstManConMod;
3038 std::vector<manualBaseModel*> lstManConModTmp;
3039 std::vector<manualBaseModel*> lstManConModExp;
3041 std::vector<int> tempVector;
3042 _instantPanel->getInstant( tempVector );
3044 vtkImageData *imagedata = _theViewPanel->getImageData();
3046 imagedata->GetExtent(ext);
3047 int sizeZimage = ext[5]-ext[4]+1;
3049 int ii,sizeLstContourThings;
3058 if (selection==0 ) // actual slice
3060 int actualSlice = tempVector[1];
3068 // cleanning image before range
3069 for (z=0; z<minZ; z++){
3070 _contourextractdata->ResetImageResult(z);
3072 // cleanning image after range
3073 for (z=maxZ+1; z<sizeZimage; z++){
3074 _contourextractdata->ResetImageResult(z);
3079 for ( z=minZ ; z<=maxZ ; z++)
3082 porcent = 100.0* (z-minZ)/totalZ;
3083 tmpString.Printf(_T("Saving Values"));
3084 tmpString.Printf(_T("%d %c %d/%d %d"), (int)porcent , 37 , z-minZ+1, (int)totalZ ,z);
3085 interfMainPanel::getInstance()->setStringInfoPanel(tmpString);
3087 //Extraction data from contours of each slice
3088 _contourextractdata->SetZtoBeAnalys( z);
3091 Instant instant(&tempVector);
3092 std::vector<ContourThing**> lstContourThings = kernelManager->getOutlinesAtInstant( &instant );
3093 sizeLstContourThings = lstContourThings.size();
3095 lstManConMod.clear();
3096 for (ii=0 ; ii<sizeLstContourThings ; ii++)
3098 ContourThing **contourthing = lstContourThings[ii];
3099 lstManConMod.push_back( (*contourthing)->getModel() );
3101 lstManConModExp = kernelManager->ExploseEachModel( lstManConMod );
3104 int iContourGroup,sizeContourGroup;
3105 if (typeContourGroup==3) // contour separete
3107 sizeContourGroup=lstManConModExp.size();
3108 } else { // contour AND OR XOR
3112 for( iContourGroup=0 ; iContourGroup<sizeContourGroup ; iContourGroup++ ){
3113 lstManConModTmp.clear();
3114 if (typeContourGroup==3) // contour separete
3116 lstManConModTmp.push_back( lstManConModExp[iContourGroup]);
3117 } else { // contour AND OR XOR
3118 lstManConModTmp = lstManConModExp;
3121 _contourextractdata->SetLstManualContourModel( lstManConModTmp );
3122 _contourextractdata->CalculateImageResult(); // with actual Z
3124 } // for iContourGroup
3127 (*value) = _contourextractdata->GetVtkImageValueResult();
3128 (*mask) = _contourextractdata->GetVtkImageMaskResult();
3132 void wxContourMainFrame::SaveImageResult(std::string directory,std::string namefile, vtkImageData* mask,vtkImageData* value)
3136 kernelManager->GetSpacing(spc,0); // returns the spacing of the first image
3138 std::string temp = directory + "/" + namefile + "-image-Value.mhd";
3140 wxString filename = crea::std2wx(temp);
3144 vtkImageChangeInformation *valueChInfo = vtkImageChangeInformation::New();
3145 //EED 2017-01-01 Migration VTK7
3146 #if VTK_MAJOR_VERSION <= 5
3147 valueChInfo->SetInput(value);
3149 valueChInfo->SetInputData(value);
3151 valueChInfo->SetSpacingScale(spc);
3152 vtkMetaImageWriter *writerValueImage = vtkMetaImageWriter::New( );
3154 //EED 2017-01-01 Migration VTK7
3155 #if VTK_MAJOR_VERSION <= 5
3156 writerValueImage->SetInput( valueChInfo->GetOutput() );
3158 writerValueImage->SetInputData( valueChInfo->GetOutput() );
3160 writerValueImage->SetFileName( (const char *)filename.mb_str() );
3161 writerValueImage->SetFileDimensionality( 3 );
3162 writerValueImage->SetCompression(false);
3163 writerValueImage->Write( );
3166 temp = directory + "/" + namefile + "-image-Mask.mhd";
3168 // LG 14/01/09 : using crea
3169 filename = crea::std2wx(temp);
3170 // filename.Printf(_T(temp.c_str()));
3173 vtkImageChangeInformation *maskChInfo = vtkImageChangeInformation::New();
3174 //EED 2017-01-01 Migration VTK7
3175 #if VTK_MAJOR_VERSION <= 5
3176 maskChInfo->SetInput(mask);
3178 maskChInfo->SetInputData(mask);
3180 maskChInfo->SetSpacingScale(spc);
3181 vtkMetaImageWriter *writerMaskImage = vtkMetaImageWriter::New( );
3183 //EED 2017-01-01 Migration VTK7
3184 #if VTK_MAJOR_VERSION <= 5
3185 writerMaskImage->SetInput( maskChInfo->GetOutput() );
3187 writerMaskImage->SetInputData( maskChInfo->GetOutput() );
3190 writerMaskImage->SetFileName( (const char *)filename.mb_str() );
3191 writerMaskImage->SetFileDimensionality( 3 );
3192 writerMaskImage->SetCompression(false);
3193 writerMaskImage->Write( );
3195 interfMainPanel::getInstance()->setStringInfoPanel( _T("") );
3201 void wxContourMainFrame::onChangeInstantInstantPanel(std::string name,int value, int minshow, int maxshow){
3202 if( name.compare( _theViewPanel->getVerticalConceptName() ) == 0){
3203 _theViewPanel->setActualVertical( value);
3205 else if( name.compare( _theViewPanel->getHorizontalConceptName() ) == 0|| _instantPanel->getIfConceptCheckedAt( name, 0 ) ) {
3206 _theViewPanel->setHorizontalConcept( name, minshow, maxshow, minshow, maxshow, value);
3212 void wxContourMainFrame::onSnakePressed(){
3213 std::vector<double> vecX;
3214 std::vector<double> vecY;
3215 std::vector<double> vecZ;
3216 _theViewPanel->GetPointsOfActualContour( &vecX , &vecY , &vecZ );
3218 if (vecX.size()!=0){
3219 std::vector<int> tempVector;
3220 _instantPanel->getInstant( tempVector );
3221 int i,size=vecZ.size();
3222 int actualSlice = tempVector[1];
3223 for ( i=0 ; i<size ; i++ )
3225 vecZ[i] = actualSlice;
3228 wxDialog* dialog = new wxDialog(this, -1, wxString(_T("Snake")));
3229 wxPanel* panel = new wxPanel(dialog,-1);
3230 // wxStaticText* sttext = new wxStaticText(panel, -1, wxString(_T("Panel para snake")));
3231 new wxStaticText(panel, -1, wxString(_T("Panel para snake")));
3232 dialog->ShowModal();
3237 void wxContourMainFrame::saveFileWithContoursAutomatique(){
3238 std::string filename = kernelManager->getCurrentFileName();
3239 if(filename.compare("")!=0){
3240 saveFileWithContours(filename);
3245 void wxContourMainFrame::ShowToolsPanel(bool show){
3246 _pannew->Show(show);
3251 void wxContourMainFrame::SetContourGroup(int contourGroup)
3253 _contourGroup = contourGroup;
3257 wxPanel *wxContourMainFrame::getMaskImageViewPanel(wxWindow *parent)
3260 if (_viewMaskImagePanel==NULL)
3262 _contourextractdata = new ContourExtractData(true);
3263 _contourextractdata->SetImage( _theViewPanel->getImageData() );
3265 // _theViewPanel->getImageData()->GetScalarRange(range);
3266 //int min = (int)floor (range[0]);
3267 //int max = (int)ceil (range[1]);
3270 _viewMaskImagePanel = new ThresholdImageViewPanel( parent, -1, -1 , 0);
3271 _viewMaskImage = new ThresholdImageView();
3272 _viewMaskImage->SetImage(_contourextractdata->GetVtkImageMaskResult() );
3273 _viewMaskImage->SetminMaxValue( min, max);
3274 _viewMaskImage->SetBaseColor( 0,0,1 );
3275 _viewMaskImagePanel->SetThresholdImageView( _viewMaskImage );
3276 _viewMaskImage->SetwxVtkBaseView( _theViewPanel->getWxVtkBaseView() );
3278 return _viewMaskImagePanel;
3282 wxPanel *wxContourMainFrame::getColorLayerImageViewPanel(wxWindow *parent)
3284 if (_viewColorLayerImagePanel==NULL)
3287 _theViewPanel->getImageData()->GetScalarRange(range);
3288 int min = (int)floor (range[0]);
3289 int max = (int)ceil (range[1]);
3290 _viewColorLayerImagePanel = new ColorLayerImageViewPanel( parent, min, max, 100, 1);
3291 _viewColorLayerImagePanel->GetColorLayerImageViewManager()->SetwxVtkBaseView( 0 , _theViewPanel->getWxVtkBaseView() );
3293 return _viewColorLayerImagePanel;
3297 wxPanel *wxContourMainFrame::getThresholdImageViewPanel(wxWindow *parent)
3299 if (_viewThresholdImagePanel==NULL)
3302 _theViewPanel->getImageData()->GetScalarRange(range);
3303 int min = (int)floor (range[0]);
3304 int max = (int)ceil (range[1]);
3305 _viewThresholdImagePanel = new ThresholdImageViewPanel( parent, min, max , 1);
3306 _viewThresholdImage = new ThresholdImageView();
3307 _viewThresholdImage->SetImage( _theViewPanel->getImageData() );
3308 _viewThresholdImage->SetminMaxValue( min, max);
3309 _viewThresholdImage->SetBaseColor( 1,0,0 );
3310 _viewThresholdImagePanel->SetThresholdImageView( _viewThresholdImage );
3311 _viewThresholdImage->SetwxVtkBaseView( _theViewPanel->getWxVtkBaseView() );
3313 return _viewThresholdImagePanel;
3316 //CMRU 17-08-09-----------------------------------------------------------------------------------------------
3317 int wxContourMainFrame::getType ()
3320 std::vector<std::string> currentSelection = _theViewPanel->getSelectedObjects();
3322 if(!currentSelection.empty())
3324 std::string cloneName = currentSelection [0];
3325 manualBaseModel * manualModel = kernelManager->getOutlineByKeyName(cloneName);
3326 tipo = manualModel-> GetTypeModel();
3331 double wxContourMainFrame::getContourSizeInPixels()
3333 double contourSize = 0;
3335 std::vector<std::string> currentSelection = _theViewPanel->getSelectedObjects(); if(!currentSelection.empty())
3336 if(!currentSelection.empty())
3338 std::string cloneName = currentSelection [0];
3340 manualBaseModel * manualModel = kernelManager->getOutlineByKeyName(cloneName);//_modelManager->getOutlineByKeyName( cloneName )->getModel();
3343 // contourSize = manualModel->GetPathSize();
3348 contourSize = manualModel->GetPathSize( spc );
3353 manualBaseModel * wxContourMainFrame::getContour ()
3355 std::vector<std::string> currentSelection = _theViewPanel->getSelectedObjects();
3357 if(!currentSelection.empty())
3359 std::string cloneName = currentSelection [0];
3360 manualBaseModel * manualModel = kernelManager->getOutlineByKeyName(cloneName);//_modelManager->getOutlineByKeyName( cloneName )->getModel();
3365 void wxContourMainFrame::onPrintLabel (wxString label, manualBaseModel* manualModel)
3367 std::string labelAscii(label.ToAscii());
3368 int pos = labelAscii.find(" ");
3372 for (j=0 ; pos != string::npos;j++)
3374 labelAscii.replace( pos, 1, "_" );
3375 pos= labelAscii.find(" ");
3378 manualModel -> SetLabel(labelAscii);
3380 void wxContourMainFrame::onInsertCalculation(manualBaseModel* manualModel)
3383 // double sizeInPixel = manualModel ->GetPathSize( );
3388 double sizeInPixel = manualModel ->GetPathSize( spc );
3390 double onePixelRealSize = interfMainPanel::getInstance()->GetPixelValue();;
3391 double realContourSize = sizeInPixel*onePixelRealSize;
3392 manualModel ->SetRealSize(realContourSize);
3395 double wxContourMainFrame::onePixelSize( double value)
3397 return _onePixelSize = value;
3400 std::string wxContourMainFrame::GetFileLocation()
3402 return _fileLocation;
3405 void wxContourMainFrame::SetFileLocation(std::string newFileLocation)
3407 _fileLocation = newFileLocation;
3408 std::cout<<"GETFILELOCATION:"<<_fileLocation<<std::endl;
3410 //------------------------------------------------------------------------------------------------------------
3419 void wxContourMainFrame::FlipSelectedContours(int flipDirection)
3421 printf("EED wxContourMainFrame::FlipSelectedContours flipDirection=%d \n", flipDirection );
3423 (std::vector<std::string>)_theViewPanel->getSceneManager()->getSelectedObjects() ,
3429 void wxContourMainFrame::FlipActualSliceContours(int flipDirection)
3431 printf("EED wxContourMainFrame::FlipActualSliceContours flipDirection=%d \n", flipDirection );
3433 (std::vector<std::string>)_theViewPanel->getSceneManager()->GetlstContoursNameActualSlice() ,
3438 void wxContourMainFrame::FlipAllContours(int flipDirection)
3440 printf("EED wxContourMainFrame::FlipAllContours flipDirection=%d \n", flipDirection );
3442 kernelManager->GetLstNameThings() ,
3447 void wxContourMainFrame::FlipLstOfContours(std::vector<std::string> lstNameThings, int flipDirection)
3450 getImageData()->GetExtent(ext);
3451 int sizeX = ext[1]-ext[0];
3452 int sizeY = ext[3]-ext[2];
3455 int i,sizeLstNameThings;
3456 int ii,sizeLstPoints;
3458 sizeLstNameThings = lstNameThings.size();
3459 for (i=0 ; i<sizeLstNameThings ; i++)
3461 printf("EED wxContourMainFrame::FlipAllContours contour=%d \n", i );
3462 manualBaseModel * manualModel = kernelManager->getOutlineByKeyName(lstNameThings[i]);
3463 if (flipDirection==0)
3465 manualModel->Transform_Ax_Plus_B(-1,sizeX,1,0 );
3467 manualModel->Transform_Ax_Plus_B(1,0,-1,sizeY );
3469 }// for i list of Things
3471 //-- Static Contours
3473 lstNameThings = kernelManager->GetLstNameThingsStatic();
3474 sizeLstNameThings = lstNameThings.size();
3475 for (i=0 ; i<sizeLstNameThings ; i++)
3477 manualBaseModel * manualModel = kernelManager->getOutlineByKeyName(lstNameThings[i]);
3478 if (flipDirection==0)
3480 manualModel->Transform_Ax_Plus_B(-1,sizeX,1,0 );
3482 manualModel->Transform_Ax_Plus_B(1,0,-1,sizeY );
3484 }// for i list of static things
3487 void wxContourMainFrame::FlipContours(int typeContourFlip, int flipDirection)
3489 printf("EED wxContourMainFrame::FlipContours( %d , %d ) \n",typeContourFlip, flipDirection );
3493 if (typeContourFlip==0) //
3495 FlipSelectedContours(flipDirection);
3498 if (typeContourFlip==1) //
3500 FlipActualSliceContours(flipDirection);
3503 if (typeContourFlip==2) //
3505 FlipAllContours(flipDirection);