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 //EED 2017-09-16 Migration wxWidgets 2.8 to 3.0
965 #if wxMAJOR_VERSION <= 2
966 wxFileDialog dialog(NULL, _T("Choose a file"), _T(""), _T(""), _T("*.roi"), wxOPEN );
968 wxFileDialog dialog(NULL, _T("Choose a file"), _T(""), _T(""), _T("*.roi"), wxFD_OPEN );
970 if (dialog.ShowModal() == wxID_OK)
972 fileNameContourROI = (const char *)(dialog.GetPath().mb_str());
976 onLoadContours(fileNameContourROI,true);
980 void wxContourMainFrame::SetZForAllContours(int pz)
982 printf("EED wxContourMainFrame::SetZForAllContours\n");
986 std::vector< std::string > lstNameThings;
987 int i,sizeLstNameThings;
988 int ii,sizeLstPoints;
990 lstNameThings = kernelManager->GetLstNameThings();
991 sizeLstNameThings = lstNameThings.size();
992 for (i=0 ; i<sizeLstNameThings ; i++)
994 printf("EED wxContourMainFrame::SetZForAllContours contour=%d \n", i );
995 manualBaseModel * manualModel = kernelManager->getOutlineByKeyName(lstNameThings[i]);
996 sizeLstPoints = manualModel->GetSizeLstPoints();
997 for (ii=0 ; ii<sizeLstPoints ; ii++)
999 manualModel->GetManualPoint(ii)->SetPointZ(-900);
1000 }// for ii list of points
1001 }// for i list of Things
1003 //-- Static Contours
1005 lstNameThings = kernelManager->GetLstNameThingsStatic();
1006 sizeLstNameThings = lstNameThings.size();
1007 for (i=0 ; i<sizeLstNameThings ; i++)
1009 manualBaseModel * manualModel = kernelManager->getOutlineByKeyName(lstNameThings[i]);
1010 sizeLstPoints = manualModel->GetSizeLstPoints();
1011 for (ii=0 ; ii<sizeLstPoints ; ii++)
1013 manualModel->GetManualPoint(ii)->SetPointZ(-900);
1014 }// for ii list of points
1015 }// for i list of static things
1018 void wxContourMainFrame::onLoadContours(std::string fileNameContourROI, bool interactiveInterface)
1022 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();
1096 void wxContourMainFrame::onImport()
1098 std::string filename, filenamecontours;
1099 //EED 2017-09-16 Migration wxWidgets 2.8 to 3.0
1100 #if wxMAJOR_VERSION <= 2
1101 wxFileDialog dialog(NULL, _T("Choose a XML Osirix File"), _T(""), _T(""), _T("*.xml"), wxOPEN );
1103 wxFileDialog dialog(NULL, _T("Choose a XML Osirix File"), _T(""), _T(""), _T("*.xml"), wxFD_OPEN );
1105 if (dialog.ShowModal() == wxID_OK)
1107 filename = dialog.GetPath().mb_str();
1108 filenamecontours = kernelManager->parseOsirixFile(filename);
1110 if(filenamecontours.compare("") != 0){
1111 onLoadContours(filenamecontours,true);
1116 void wxContourMainFrame::onTest()
1118 std::string filename, filenamecontours;
1119 //EED 2017-09-16 Migration wxWidgets 2.8 to 3.0
1120 #if wxMAJOR_VERSION <= 2
1121 wxFileDialog dialog(NULL, _T("Choose a File"), _T(""), _T(""), _T("*.*"), wxOPEN );
1123 wxFileDialog dialog(NULL, _T("Choose a File"), _T(""), _T(""), _T("*.*"), wxFD_OPEN );
1126 if (dialog.ShowModal() == wxID_OK)
1128 filename = dialog.GetPath().mb_str();
1129 std::cout << "This is the filename: " << filename << std::endl;
1135 void wxContourMainFrame::onSave(){
1136 //CMRU 03-09-09-----------------------------------------------------------------------------------------------
1137 if(GetFileLocation().empty())
1139 //------------------------------------------------------------------------------------------------------------
1140 //EED 2017-09-16 Migration wxWidgets 2.8 to 3.0
1141 #if wxMAJOR_VERSION <= 2
1142 wxFileDialog dialog(NULL, _T("Choose a file"), _T(""), _T(""), _T("*.roi"), wxSAVE );
1144 wxFileDialog dialog(NULL, _T("Choose a file"), _T(""), _T(""), _T("*.roi"), wxFD_SAVE );
1146 if (dialog.ShowModal() == wxID_OK)
1148 std::string fileNameContourROI = (const char *)(dialog.GetPath().mb_str());
1149 kernelManager->setCurrentFileName(fileNameContourROI);
1150 saveFileWithContours( fileNameContourROI );
1153 //CMRU 03-09-09-----------------------------------------------------------------------------------------------
1156 std::cout<<"Nombre del archivo: "<<GetFileLocation()<<std::endl;
1157 std::string fileNameContourROI = GetFileLocation();
1158 std::cout<<"Nombre del archivo: "<<fileNameContourROI<<std::endl;
1159 kernelManager->setCurrentFileName(fileNameContourROI);
1160 saveFileWithContours( fileNameContourROI);
1162 //------------------------------------------------------------------------------------------------------------
1166 void wxContourMainFrame::saveFileWithContours( std::string filename )
1169 FILE *pFile=fopen(filename.c_str(),"w+");
1171 //CMRU 03-09-09-----------------------------------------------------------------------------------------------
1172 filename.append("data");
1173 std::cout<<"Nombre del archivo: "<<filename<<std::endl;
1174 FILE *pFileData=fopen(filename.c_str(),"w+");
1175 //------------------------------------------------------------------------------------------------------------
1177 std::vector< std::string > lstNameThings;
1178 int i,sizeLstNameThings;
1180 fprintf(pFile,"--CreaContour--\n");
1181 fprintf(pFile,"Version %s\n", "1.0.3" );
1183 //CMRU 03-09-09-----------------------------------------------------------------------------------------------
1184 fprintf(pFileData,"--CreaContour--\n");
1185 fprintf(pFileData,"Version %s\n", "1.0.3" );
1186 fprintf(pFileData,"OnePixelSize %f\n", _onePixelSize);
1188 //------------------------------------------------------------------------------------------------------------
1190 vtkImageData *image = _images[0];
1193 image->GetDimensions(dimRange);
1195 fprintf(pFile,"ImageDimensions %d %d %d\n", dimRange[0], dimRange[1], dimRange[2] );
1198 image->GetSpacing(spaRange);
1200 fprintf(pFile,"ImageSpacing %f %f %f\n", spaRange[0], spaRange[1], spaRange[2] );
1204 lstNameThings = kernelManager->GetLstNameThings();
1205 sizeLstNameThings = lstNameThings.size();
1206 fprintf(pFile,"NumberOfContours %d\n", sizeLstNameThings );
1208 //CMRU 03-09-09-----------------------------------------------------------------------------------------------
1209 fprintf(pFileData,"NumberOfContours %d\n", sizeLstNameThings );
1210 //------------------------------------------------------------------------------------------------------------
1219 for (i=0 ; i<sizeLstNameThings ; i++)
1221 //CMRU 03-09-09-----------------------------------------------------------------------------------------------
1222 manualBaseModel * manualModel = kernelManager->getOutlineByKeyName(lstNameThings[i]);
1225 // double sizeInPixel = manualModel ->GetPathSize( );
1226 double sizeInPixel = manualModel ->GetPathSize( spc );
1228 double realContourSize = sizeInPixel*_onePixelSize;
1229 manualModel ->SetRealSize(realContourSize);
1230 //------------------------------------------------------------------------------------------------------------
1232 //int size= kernelManager->GetLstNameThings().size();
1234 kernelManager->SaveThingName( pFile, pFileData, lstNameThings[i] );
1235 _theViewPanel->getSceneManager()->SaveThingName( pFile, lstNameThings[i] );
1238 //-- Static Contours
1240 // fprintf(pFile,"ImageDimensions %d %d %d\n", dimRange[0], dimRange[1], dimRange[2] );
1241 // fprintf(pFile,"ImageSpacing %f %f %f\n", spaRange[0], spaRange[1], spaRange[2] );
1243 lstNameThings = kernelManager->GetLstNameThingsStatic();
1244 sizeLstNameThings = lstNameThings.size();
1245 fprintf(pFile,"NumberOfContoursStatic %d\n", sizeLstNameThings );
1247 //CMRU 03-09-09-----------------------------------------------------------------------------------------------
1248 fprintf(pFileData,"NumberOfContoursStatic %d\n", sizeLstNameThings );
1249 //------------------------------------------------------------------------------------------------------------
1251 for (i=0 ; i<sizeLstNameThings ; i++)
1253 kernelManager->SaveThingName( pFile, pFileData, lstNameThings[i] );
1254 _theViewPanel->getSceneManager()->SaveThingName( pFile, lstNameThings[i] );
1262 void wxContourMainFrame::readDimSpc(FILE *pFile, bool interactiveOption)
1266 double imageSpac[3];
1267 vtkImageData *image = _images[0];
1268 image->GetDimensions(imageDim);
1269 image->GetSpacing(imageSpac);
1271 fscanf(pFile,"%s",tmp); // ImageDimensions
1272 fscanf(pFile,"%s",tmp); // X
1273 _tmpReadFileImageDim[0] = atoi(tmp);
1274 fscanf(pFile,"%s",tmp); // Y
1275 _tmpReadFileImageDim[1] = atoi(tmp);
1276 fscanf(pFile,"%s",tmp); // Z
1277 _tmpReadFileImageDim[2] = atoi(tmp);
1279 fscanf(pFile,"%s",tmp); // ImageSpacing
1280 fscanf(pFile,"%s",tmp); // X
1281 _tmpReadFileImageSpac[0] = atof(tmp);
1282 fscanf(pFile,"%s",tmp); // Y
1283 _tmpReadFileImageSpac[1] = atof(tmp);
1284 fscanf(pFile,"%s",tmp); // Z
1285 _tmpReadFileImageSpac[2] = atof(tmp);
1288 if (interactiveOption==true)
1290 //Compare Spacing and Dims in X and Y (Necessary in Z?) - Just for Version 2
1291 if (imageDim[0]!=_tmpReadFileImageDim[0] || imageDim[1]!=_tmpReadFileImageDim[1] || imageSpac[0]!=_tmpReadFileImageSpac[0] || imageSpac[1]!=_tmpReadFileImageSpac[1])
1293 wxDialog* dial = new wxDialog (this,-1,_T("Tools"),wxDefaultPosition, wxSize(460,360));
1294 wxSizer* buttonsSizer = dial->CreateSeparatedButtonSizer(wxOK|wxCANCEL);
1295 wxBoxSizer *dialSizer = new wxBoxSizer(wxVERTICAL);
1297 wxString lstOptOperation[2];
1298 lstOptOperation[0]=_T("By Dimension");
1299 lstOptOperation[1]=_T("By Spacing");
1300 wxRadioBox * radioOpts = new wxRadioBox(dial, -1, _T("Type of Transformation"), wxDefaultPosition, wxSize(270,45), 2 , lstOptOperation, 2, wxRA_SPECIFY_COLS);
1302 dialSizer->Add( new wxStaticText(dial,-1,_T("The image resolution is not compatible with the ")) , 0, wxGROW );
1303 dialSizer->Add( new wxStaticText(dial,-1,_T("selected Roi file. Do you want to tranform it?")) , 0, wxGROW );
1304 dialSizer->Add( new wxStaticText(dial,-1,_T(" ")) , 0, wxGROW );
1305 dialSizer->Add(radioOpts,0,wxGROW);
1306 dialSizer->Add( new wxStaticText(dial,-1,_T(" ")) , 0, wxGROW );
1307 dialSizer->Add(buttonsSizer,0,wxGROW);
1308 dial->SetSizer(dialSizer, true);
1312 int _tmpReadFileTypeOfTransformation = -1;
1313 //EED bool transform = false;
1315 if (dial->GetReturnCode() == wxID_OK)
1317 _tmpReadFileTypeOfTransformation = radioOpts->GetSelection();
1321 } // if interactiveOption
1328 void wxContourMainFrame::openContours( FILE *pFile, FILE *pFileData, bool staticContour )
1333 vtkImageData *image = _images[0];
1336 double imageSpac[3];
1337 image->GetDimensions(imageDim);
1338 image->GetSpacing(imageSpac);
1341 fscanf(pFile,"%s",tmp); // NumberOfContours
1342 fscanf(pFile,"%s",tmp); // ##
1343 int numberOfContours = atoi(tmp);
1345 std::vector<int> instantVector;
1346 int typeContourModel;
1347 manualBaseModel *manModelContour;
1351 if (compatible==true)
1354 for (i=0;i<numberOfContours;i++)
1356 instantVector.clear();
1357 fscanf(pFile,"%s",tmp); // Instant
1359 fscanf(pFile,"%s",tmp); // 1
1360 instantVector.push_back( atoi(tmp) );
1361 fscanf(pFile,"%s",tmp); // 2
1362 instantVector.push_back( atoi(tmp) );
1363 fscanf(pFile,"%s",tmp); // 3
1364 instantVector.push_back( atoi(tmp) );
1365 fscanf(pFile,"%s",tmp); // 4
1366 instantVector.push_back( atoi(tmp) );
1367 fscanf(pFile,"%s",tmp); // 5
1368 instantVector.push_back( atoi(tmp) );
1369 fscanf(pFile,"%s",tmp); // 6
1370 instantVector.push_back( atoi(tmp) );
1373 fscanf(pFile,"%s",tmp); // TypeContourModel
1374 fscanf(pFile,"%s",tmp); // ##
1375 typeContourModel = atoi(tmp);
1377 manModelContour = kernelManager->factoryManualContourModel(typeContourModel);
1378 manModelContour->Open(pFile);
1379 if(pFileData != NULL)
1381 manModelContour->OpenData(pFileData);
1384 fscanf(pFile,"%s",tmp); // TypeView
1385 fscanf(pFile,"%s",tmp); // ##
1386 typeView = atoi(tmp);
1388 std::string theName;
1389 theName = kernelManager->createOutline( manModelContour, instantVector );
1390 bool addedModel = theName.compare("") != 0;
1393 double spc[3];//Si no hay imagen pero hay contornos que spacing se pone por default
1394 _theViewPanel->getSpacing(spc);
1395 //Adding the manualContourControler to interface objects structure
1396 //Adding the manualViewContour to interface objects structure
1397 //_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.
1398 _theViewPanel->getSceneManager()->configureViewControlTo( theName, manModelContour,spc , typeView) ;
1401 if (staticContour) //StaticContours (will appear in all slices)
1403 Instant instant(&instantVector);
1404 kernelManager->changeContourOfManager( theName , &instant );
1407 }// for numberOfContours
1410 else if (compatible==false)
1415 for (i=0;i<numberOfContours;i++)
1417 instantVector.clear();
1418 fscanf(pFile,"%s",tmp); // Instant
1420 fscanf(pFile,"%s",tmp); // 1
1421 instantVector.push_back( atoi(tmp) );
1422 fscanf(pFile,"%s",tmp); // 2
1423 instantVector.push_back( atoi(tmp) );
1424 fscanf(pFile,"%s",tmp); // 3
1425 instantVector.push_back( atoi(tmp) );
1426 fscanf(pFile,"%s",tmp); // 4
1427 instantVector.push_back( atoi(tmp) );
1428 fscanf(pFile,"%s",tmp); // 5
1429 instantVector.push_back( atoi(tmp) );
1430 fscanf(pFile,"%s",tmp); // 6
1431 instantVector.push_back( atoi(tmp) );
1433 fscanf(pFile,"%s",tmp); // TypeContourModel
1434 fscanf(pFile,"%s",tmp); // ##
1435 typeContourModel = atoi(tmp);
1437 manModelContour = kernelManager->factoryManualContourModel(typeContourModel);
1438 manModelContour->Open(pFile);
1439 if(pFileData != NULL)
1441 manModelContour->OpenData(pFileData);
1444 if (_tmpReadFileTypeOfTransformation==-1){
1446 } else if (_tmpReadFileTypeOfTransformation==0){
1447 double transX, transY;
1448 transX = (double) imageDim[0]/_tmpReadFileImageDim[0];
1449 transY = (double) imageDim[1]/_tmpReadFileImageDim[1];
1450 manModelContour->Transform_Ax_Plus_B(transX,0,transY,0);
1451 } else if (_tmpReadFileTypeOfTransformation==1) {
1452 double transX, transY;
1453 transX = (double) _tmpReadFileImageSpac[0]/imageDim[0];
1454 transY = (double) _tmpReadFileImageSpac[1]/imageDim[1];
1455 manModelContour->Transform_Ax_Plus_B(transX,0,transY,0);
1458 fscanf(pFile,"%s",tmp); // TypeView
1459 fscanf(pFile,"%s",tmp); // ##
1460 typeView = atoi(tmp);
1462 std::string theName;
1463 theName = kernelManager->createOutline( manModelContour, instantVector );
1464 bool addedModel = theName.compare("") != 0;
1467 double spc[3];//Si no hay imagen pero hay contornos que spacing se pone por default
1468 _theViewPanel->getSpacing(spc);
1469 //Adding the manualContourControler to interface objects structure
1470 //Adding the manualViewContour to interface objects structure
1471 //_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.
1472 _theViewPanel->getSceneManager()->configureViewControlTo( theName, manModelContour,spc , typeView) ;
1475 if (staticContour) //StaticContours (will appear in all slices)
1477 Instant instant(&instantVector);
1478 kernelManager->changeContourOfManager( theName , &instant );
1480 }// for numberOfContours
1486 void wxContourMainFrame::RefreshInterface(){
1488 _theViewPanel->RefreshInterface();
1489 //wxVtk2DBaseView *wxvtk2dbaseview = (wxVtk2DBaseView*)this->_theViewPanel->getWxVtkBaseView();
1490 //wxvtk2dbaseview->Refresh();
1493 vtkImageData* wxContourMainFrame::getImageData(){
1494 return _theViewPanel->getImageData();
1497 void wxContourMainFrame::onSegmentationOneSliceITK(wxString distance, wxString sigma, wxString alfa, wxString beta, wxString propagation, wxString iterations, wxString inflation)
1499 //JCP 20-10-08 Undo redo implementation
1501 //JCP 20-10-08 Undo redo implementation
1504 int x = _theViewPanel->GetX();
1505 int y = _theViewPanel->GetY();
1506 int z = _theViewPanel->GetZ();
1507 SegmentationOneSliceITK( x,y,z,distance, sigma, alfa, beta, propagation, iterations, inflation);
1511 void wxContourMainFrame::SegmentationOneSliceITK(int x, int y, int z, wxString distanc, wxString sigm, wxString alf, wxString bet, wxString prop, wxString iter, wxString inflation)
1513 int typeofcontour = 1;
1515 vtkImageData *imagedata = getImageData();
1517 //Tipo de pixeles a utilizar internamente en ITK
1518 typedef float InternalPixelType;
1519 const unsigned int Dimension = 2;
1520 typedef itk::Image< InternalPixelType, Dimension > InternalImageType;
1522 //Tipo de pixeles de salida 1
1523 typedef unsigned char OutputPixelType;
1524 typedef itk::Image< OutputPixelType, Dimension > OutputImageType;
1526 //Tipo de pixeles de salida 2
1527 typedef unsigned short OutputPixelType2;
1528 typedef itk::Image< OutputPixelType2, Dimension > OutputImageType2;
1530 //DefiniciÛn del thresholder
1531 typedef itk::BinaryThresholdImageFilter<
1533 OutputImageType > ThresholdingFilterType;
1535 //DefiniciÛn del primer filtro de conversiÛn de pixeles
1536 typedef itk::CastImageFilter<
1537 OutputImageType, OutputImageType2 > CastFilterType;
1539 //DefiniciÛn del segundo tipo de conversiÛn de pixeles
1540 typedef itk::CastImageFilter<
1541 OutputImageType2, InternalImageType > CastFilterType2;
1543 //Tercer tipo de conversiÛn
1544 typedef itk::RescaleIntensityImageFilter<
1546 OutputImageType > CastFilterType3;
1548 //Cuarto tipo de conversiÛn
1549 typedef itk::RescaleIntensityImageFilter<
1551 OutputImageType > CastFilterType4;
1553 ThresholdingFilterType::Pointer thresholder = ThresholdingFilterType::New();
1555 thresholder->SetLowerThreshold( 0.0 );
1556 thresholder->SetUpperThreshold( 128 );
1558 thresholder->SetOutsideValue( 255 );
1559 thresholder->SetInsideValue( 0 );
1561 //DefinciÛn de conexiÛnes entre VTK e ITK y el writer
1562 typedef itk::VTKImageToImageFilter<OutputImageType2> ConnectorType;
1563 typedef itk::ImageToVTKImageFilter<OutputImageType> ConnectorType2;
1564 //EED10JUIN2011 typedef itk::ImageFileWriter< OutputImageType > WriterType;
1566 ConnectorType::Pointer connector= ConnectorType::New();
1567 ConnectorType2::Pointer connector2= ConnectorType2::New();
1570 CastFilterType::Pointer filter=CastFilterType::New();
1571 CastFilterType2::Pointer filter2=CastFilterType2::New();
1573 connector->SetInput( imagedata );
1574 filter2->SetInput(connector->GetOutput());
1576 typedef itk::CurvatureAnisotropicDiffusionImageFilter<
1578 InternalImageType > SmoothingFilterType;
1580 SmoothingFilterType::Pointer smoothing = SmoothingFilterType::New();
1582 typedef itk::GradientMagnitudeRecursiveGaussianImageFilter<
1584 InternalImageType > GradientFilterType;
1586 typedef itk::SigmoidImageFilter<
1588 InternalImageType > SigmoidFilterType;
1590 GradientFilterType::Pointer gradientMagnitude = GradientFilterType::New();
1592 SigmoidFilterType::Pointer sigmoid = SigmoidFilterType::New();
1594 sigmoid->SetOutputMinimum( 0.0 );
1595 sigmoid->SetOutputMaximum( 255.0 );
1598 typedef itk::FastMarchingImageFilter<
1600 InternalImageType > FastMarchingFilterType;
1603 FastMarchingFilterType::Pointer fastMarching = FastMarchingFilterType::New();
1605 printf("EED wxContourMainFrame::SegmentationOneSliceITK Skypping this code. Not compiling GeodesicActiveContourLevelSetImageFilter in fedora 17 with ITK 3.20.1 \n ");
1607 > - > - > - > - > - > - > - > - > - > - > - > - > - > - > - > - Not compiling GeodesicActiveContourLevelSetImageFilter in fedora 17 with ITK 3.20.1
1610 typedef itk::GeodesicActiveContourLevelSetImageFilter< InternalImageType,
1611 InternalImageType > GeodesicActiveContourFilterType;
1612 GeodesicActiveContourFilterType::Pointer geodesicActiveContour =
1613 GeodesicActiveContourFilterType::New();
1615 typedef itk::ZeroCrossingImageFilter<
1617 InternalImageType > ZeroCrossingFilterType;
1618 ZeroCrossingFilterType::Pointer zeroCrossing =
1619 ZeroCrossingFilterType::New();
1621 const double propagationScaling = atof( crea::wx2std(prop).c_str() );
1623 geodesicActiveContour->SetPropagationScaling( propagationScaling );
1624 geodesicActiveContour->SetCurvatureScaling( 1.0 );
1625 geodesicActiveContour->SetAdvectionScaling( 1.0 );
1627 geodesicActiveContour->SetMaximumRMSError( 0.02 );
1628 int it=atoi( crea::wx2std(iter).c_str() );
1629 geodesicActiveContour->SetNumberOfIterations( it );
1631 smoothing->SetInput( filter2->GetOutput() );
1632 gradientMagnitude->SetInput( smoothing->GetOutput() );
1633 sigmoid->SetInput( gradientMagnitude->GetOutput() );
1634 fastMarching->SetInput( sigmoid->GetOutput() );
1635 geodesicActiveContour->SetInput( fastMarching->GetOutput() );
1636 geodesicActiveContour->SetFeatureImage( sigmoid->GetOutput() );
1638 zeroCrossing->SetInput( geodesicActiveContour->GetOutput() );
1639 //thresholder->SetInput( zeroCrossing->GetOutput() );
1640 thresholder->SetInput( geodesicActiveContour->GetOutput() );
1641 connector2->SetInput( thresholder->GetOutput() );
1643 < - < - < - < - < - < - < - < - < - < - < - < - < - < - < - < - < - < - < - < -
1649 smoothing->SetTimeStep( 0.125 );
1650 smoothing->SetNumberOfIterations( 5 );
1651 smoothing->SetConductanceParameter( 9.0 );
1654 const double sigma = atof( crea::wx2std(sigm).c_str() );
1655 gradientMagnitude->SetSigma( sigma );
1657 const double alpha = atof( crea::wx2std(alf).c_str() );
1658 const double beta = atof( crea::wx2std(bet).c_str() );
1660 sigmoid->SetAlpha( alpha );
1661 sigmoid->SetBeta( beta );
1663 typedef FastMarchingFilterType::NodeContainer NodeContainer;
1664 typedef FastMarchingFilterType::NodeType NodeType;
1666 NodeContainer::Pointer seeds = NodeContainer::New();
1668 InternalImageType::IndexType seedPosition;
1669 seedPosition[0] = x;
1670 seedPosition[1] = y;
1672 const double initialDistance = atof( crea::wx2std(distanc).c_str() );
1676 const double seedValue = - initialDistance;
1678 node.SetValue( seedValue );
1679 node.SetIndex( seedPosition );
1681 seeds->Initialize();
1682 seeds->InsertElement( 0, node );
1684 fastMarching->SetTrialPoints( seeds );
1686 fastMarching->SetSpeedConstant( 1.0 );
1688 fastMarching->SetOutputSize(
1689 connector->GetOutput()->GetBufferedRegion().GetSize() );
1691 fastMarching->SetStoppingValue( 800 );
1695 connector2->Update();
1696 vtkImageData *idata = connector2->GetOutput();
1698 vtkMarchingContourFilter* cntVTK = vtkMarchingContourFilter::New( );
1700 cntVTK->SetInput( idata );
1702 cntVTK->SetNumberOfContours( 1 );
1703 cntVTK->SetValue( 0, 255 );
1705 cntVTK->UpdateInformation();
1707 vtkCleanPolyData* cpd = vtkCleanPolyData::New( );
1708 cpd->SetInput( cntVTK->GetOutput( ) );
1710 cpd->UpdateInformation();
1712 vtkPolyDataConnectivityFilter* conn = vtkPolyDataConnectivityFilter::New( );
1713 conn->SetExtractionModeToLargestRegion( );
1714 conn->SetInput( cpd->GetOutput( ) );
1716 conn->UpdateInformation();
1718 vtkStripper* vtkstripper = vtkStripper::New( );
1719 vtkstripper->SetInput( conn->GetOutput() );
1720 vtkstripper->Update();
1721 vtkstripper->UpdateInformation();
1723 vtkPolyData* polyDataResult = cntVTK->GetOutput();
1724 //std::cout<<"Points "<<polyDataResult->GetNumberOfPoints()<<std::endl;
1725 polyDataResult->Update( );
1726 polyDataResult->UpdateInformation();
1731 myfile.open ("C:/Creatis/example.txt");
1733 polyDataResult->Print(myfile);
1734 myfile << "-------------------------------------\n";
1735 polyDataResult->GetLines()->Print(myfile);
1743 //--Calculating control points
1745 std::vector<double> vecX;
1746 std::vector<double> vecY;
1747 std::vector<double> vecXo;
1748 std::vector<double> vecYo;
1749 std::vector<double>::iterator vecXoi;
1750 std::vector<double>::iterator vecYoi;
1751 std::vector<double> vecZ;
1753 std::vector<double> vecCtrlPointX;
1754 std::vector<double> vecCtrlPointY;
1755 std::vector<double> vecCtrlPointZ;
1761 int ii,size=polyDataResult->GetNumberOfPoints();
1763 myfile.open ("C:/Creatis/example2.txt");
1765 size=polyDataResult->GetNumberOfPoints();
1766 for (ii=0;ii<size;ii++)
1773 p = polyDataResult->GetPoint(ii);
1776 /*if(fabs(yAct-y)>20)
1778 if((xAct-x)>1 || (xAct-x)<-1)
1780 vecX.push_back( p[0] );
1781 vecY.push_back( p[1] );
1782 myfile <<p[0]<<","<<p[1]<<"\n";
1783 std::cout<<" x Anterior "<<xAct<<" x actual "<<x<<std::endl;
1784 std::cout<<" y Anterior "<<yAct<<" y actual "<<y<<std::endl;
1785 std::cout<<" x "<<p[0]<<" y "<<p[1]<<std::endl;
1786 vecZ.push_back( 900 );
1792 vecXo.push_back(p[0]);
1793 vecYo.push_back(p[1]);
1797 else*/ if(fabs(xAct-x)>11)
1799 vecXo.push_back(p[0]);
1800 vecYo.push_back(p[1]);
1804 vecX.push_back( p[0] );
1805 myfile <<p[0]<<","<<p[1]<<"\n";
1806 //std::cout<<" x Anterior "<<xAct<<" x actual "<<x<<std::endl;
1807 //std::cout<<" y Anterior "<<yAct<<" y actual "<<y<<std::endl;
1808 //std::cout<<" x "<<p[0]<<" y "<<p[1]<<std::endl;
1809 vecY.push_back( p[1] );
1810 vecZ.push_back( 900 );
1818 while(!vecXo.empty())
1820 vecX.push_back(vecXo.back());
1821 //std::cout<<" x Siguiente "<<vecXo.back();
1823 vecZ.push_back( 900 );
1825 while(!vecYo.empty())
1827 vecY.push_back(vecYo.back());
1832 /*for(int l=0;l<vecX.size();l++)
1836 vecXo.push_back(p[0]);
1837 vecYo.push_back(p[1]);
1848 ExtractControlPoints2D *extractcontrolpoints2d = new ExtractControlPoints2D();
1850 extractcontrolpoints2d->SetContour( &vecX , &vecY , &vecZ );
1854 extractcontrolpoints2d->GetInitialControlPoints( &vecCtrlPointX , &vecCtrlPointY , &vecCtrlPointZ );
1856 else if (method==1){
1857 extractcontrolpoints2d->GetControlPoints( &vecCtrlPointX , &vecCtrlPointY , &vecCtrlPointZ );
1859 else if (method==2){
1860 extractcontrolpoints2d->SetSamplingControlPoints( 15 );
1861 extractcontrolpoints2d->GetSamplingControlPoints( &vecCtrlPointX , &vecCtrlPointY , &vecCtrlPointZ );
1863 //--Adding contour to the system
1865 std::vector<int> actualInstantVector;
1866 _instantPanel->getInstant( actualInstantVector );
1867 actualInstantVector[1]=z;
1869 int j,sizeCtrPt = vecCtrlPointX.size();
1871 manualBaseModel *manModelContour = kernelManager->factoryManualContourModel( typeofcontour );
1872 manModelContour->SetNumberOfPointsSpline( ((sizeCtrPt/100)+1)*100 );
1874 for (j=0 ; j<sizeCtrPt ; j++)
1876 manModelContour->AddPoint( vecCtrlPointX[j] , vecCtrlPointY[j] , vecCtrlPointZ[j] );
1878 std::string theName;
1879 //theName = _modelManager->createOutline( manModelContour, actualInstantVector );
1880 theName = kernelManager->createOutline( manModelContour, actualInstantVector );
1881 bool addedModel = theName.compare("") != 0;
1884 double spc[3];//Si no hay imagen pero hay contornos que spacing se pone por default
1885 _theViewPanel->getSpacing(spc);
1886 //Adding the manualContourControler to interface objects structure
1887 //Adding the manualViewContour to interface objects structure
1888 //_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.
1889 _theViewPanel->configureViewControlTo(theName, manModelContour, spc, typeofcontour);
1890 //_theViewPanel->getSceneManager()->configureViewControlTo( theName, manModelContour,spc, typeofcontour ) ;
1897 WriterType::Pointer writer = WriterType::New();
1898 CastFilterType3::Pointer caster = CastFilterType3::New();
1900 caster->SetInput( gradientMagnitude->GetOutput() );
1901 writer->SetInput( caster->GetOutput() );
1902 writer->SetFileName("Gradient Magnitude.png");
1903 caster->SetOutputMinimum( 0 );
1904 caster->SetOutputMaximum( 255 );
1907 CastFilterType3::Pointer caster2 = CastFilterType3::New();
1908 WriterType::Pointer writer2 = WriterType::New();
1910 caster2->SetInput( sigmoid->GetOutput() );
1911 writer2->SetInput( caster2->GetOutput() );
1912 writer2->SetFileName("Sigmoid.png");
1913 caster2->SetOutputMinimum( 0 );
1914 caster2->SetOutputMaximum( 255 );
1917 CastFilterType3::Pointer caster3 = CastFilterType3::New();
1918 WriterType::Pointer writer3 = WriterType::New();
1920 caster3->SetInput( fastMarching->GetOutput() );
1921 writer3->SetInput( caster3->GetOutput() );
1922 writer3->SetFileName("FastMarching.bmp");
1923 caster3->SetOutputMinimum( 0 );
1924 caster3->SetOutputMaximum( 255 );
1927 CastFilterType3::Pointer caster4 = CastFilterType3::New();
1928 WriterType::Pointer writer4 = WriterType::New();
1930 caster4->SetInput( geodesicActiveContour->GetOutput() );
1931 writer4->SetInput( caster4->GetOutput() );
1932 writer4->SetFileName("GeodesicActiveContour.png");
1933 caster4->SetOutputMinimum( 0 );
1934 caster4->SetOutputMaximum( 255 );
1937 CastFilterType3::Pointer caster5 = CastFilterType3::New();
1938 WriterType::Pointer writer5 = WriterType::New();
1940 caster5->SetInput( zeroCrossing->GetOutput() );
1941 writer5->SetInput( caster5->GetOutput() );
1942 writer5->SetFileName("ZeroCrossing.bmp");
1943 caster5->SetOutputMinimum( 0 );
1944 caster5->SetOutputMaximum( 255 );
1948 catch( itk::ExceptionObject & excep )
1950 std::cerr << "Exception caught !" << std::endl;
1951 std::cerr << excep << std::endl;
1955 void wxContourMainFrame::onSegmentationOneSlice(int isovalue,int sampling,int method){
1957 //JCP 20-10-08 Undo redo implementation
1959 //JCP 20-10-08 Undo redo implementation
1962 int x = _theViewPanel->GetX();
1963 int y = _theViewPanel->GetY();
1964 int z = _theViewPanel->GetZ();
1965 SegmentationOneSlice( x,y,z,isovalue, sampling, method );
1970 void wxContourMainFrame::SegmentationOneSlice( int x, int y, int z, int isovalue, int sampling, int method )
1972 int typeofcontour = 1;
1973 //--Extracting Contour
1974 //vtkImageData *imagedata = _theViewPanel->getSceneManager()->GetImageData();
1975 vtkImageData *imagedata = getImageData();
1976 // double *range = imagedata->GetScalarRange();
1979 vtkImageReslice *imageReslice = vtkImageReslice::New();
1982 // imagedata->GetSpacing(spc);
1987 imageReslice->SetInput( imagedata );
1988 imageReslice->SetInformationInput(imagedata);
1989 imageReslice->SetResliceAxesDirectionCosines(1,0,0, 0,1,0 ,0,0,1);
1990 imageReslice->SetResliceAxesOrigin(0,0,z);
1991 imageReslice->SetOutputDimensionality(2);
1992 imageReslice->SetInterpolationModeToLinear();
1994 imagedata = imageReslice->GetOutput();
1995 imagedata->Update();
1996 imagedata->UpdateInformation();
1998 vtkContourFilter* cntVTK = vtkContourFilter::New( );
1999 cntVTK->SetInput( imagedata );
2001 cntVTK->SetNumberOfContours( 1 );
2002 //cntVTK->SetValue( 0, vmin );
2003 // cntVTK->SetValue( 0, (range[1]*thr/100) );
2004 cntVTK->SetValue( 1, isovalue );
2005 // cntVTK->SetValue( 1, vmax );
2007 cntVTK->UpdateInformation();
2009 vtkCleanPolyData* cpd = vtkCleanPolyData::New( );
2010 cpd->SetInput( cntVTK->GetOutput( ) );
2011 cpd->ConvertLinesToPointsOff( );
2013 cpd->UpdateInformation();
2015 vtkPolyDataConnectivityFilter* conn = vtkPolyDataConnectivityFilter::New( );
2016 conn->SetExtractionModeToClosestPointRegion( );
2017 //conn->SetMaxRecursionDepth( 3000 );
2019 conn->SetInput( cpd->GetOutput( ) );
2021 conn->SetClosestPoint( x, y, 0 );
2023 conn->UpdateInformation();
2025 vtkCleanPolyData* cpd2 = vtkCleanPolyData::New( );
2026 cpd2->SetInput( conn->GetOutput( ) );
2028 cpd2->UpdateInformation();
2030 vtkStripper* vtkstripper = vtkStripper::New( );
2031 vtkstripper->SetInput( cpd2->GetOutput() );
2032 vtkstripper->Update();
2033 vtkstripper->UpdateInformation();
2036 vtkPolyData* polyDataResult = vtkstripper->GetOutput();
2038 polyDataResult->Update( );
2039 polyDataResult->UpdateInformation();
2043 myfile.open ("c:/temp/example.txt");
2045 polyDataResult->Print(myfile);
2046 myfile << "-------------------------------------\n";
2047 polyDataResult->GetLines()->Print(myfile);
2057 //--Calculating control points
2059 std::vector<double> vecX;
2060 std::vector<double> vecY;
2061 std::vector<double> vecZ;
2063 std::vector<double> vecCtrlPointX;
2064 std::vector<double> vecCtrlPointY;
2065 std::vector<double> vecCtrlPointZ;
2069 int ii,size=polyDataResult->GetNumberOfPoints();
2071 for (ii=1;ii<=size;ii++)
2073 id = polyDataResult->GetLines()->GetData()->GetValue(ii);
2074 p = polyDataResult->GetPoint(id);
2077 vecX.push_back( p[0] );
2078 vecY.push_back( p[1] );
2079 vecZ.push_back( 900 );
2080 // vecZ.push_back( p[2] );
2084 ExtractControlPoints2D *extractcontrolpoints2d = new ExtractControlPoints2D();
2085 extractcontrolpoints2d->SetContour( &vecX , &vecY , &vecZ );
2088 /*if (methodRadiobox->GetSelection()==0){
2089 extractcontrolpoints2d->GetInitialControlPoints( &vecCtrlPointX , &vecCtrlPointY , &vecCtrlPointZ );
2091 if (methodRadiobox->GetSelection()==1){
2092 extractcontrolpoints2d->GetControlPoints( &vecCtrlPointX , &vecCtrlPointY , &vecCtrlPointZ );
2094 if (methodRadiobox->GetSelection()==2){
2095 extractcontrolpoints2d->SetSamplingControlPoints( sampling );
2096 extractcontrolpoints2d->GetSamplingControlPoints( &vecCtrlPointX , &vecCtrlPointY , &vecCtrlPointZ );
2100 extractcontrolpoints2d->GetInitialControlPoints( &vecCtrlPointX , &vecCtrlPointY , &vecCtrlPointZ );
2102 else if (method==1){
2103 extractcontrolpoints2d->GetControlPoints( &vecCtrlPointX , &vecCtrlPointY , &vecCtrlPointZ );
2105 else if (method==2){
2106 extractcontrolpoints2d->SetSamplingControlPoints( sampling );
2107 extractcontrolpoints2d->GetSamplingControlPoints( &vecCtrlPointX , &vecCtrlPointY , &vecCtrlPointZ );
2110 //--Adding contour to the system
2112 std::vector<int> actualInstantVector;
2113 _instantPanel->getInstant( actualInstantVector );
2114 actualInstantVector[1]=z;
2116 int j,sizeCtrPt = vecCtrlPointX.size();
2117 manualBaseModel *manModelContour = kernelManager->factoryManualContourModel( typeofcontour );
2118 manModelContour->SetNumberOfPointsSpline( ((sizeCtrPt/100)+1)*100 );
2120 for (j=0 ; j<sizeCtrPt ; j++)
2122 manModelContour->AddPoint( vecCtrlPointX[j] , vecCtrlPointY[j] , vecCtrlPointZ[j] );
2124 std::string theName;
2125 //theName = _modelManager->createOutline( manModelContour, actualInstantVector );
2126 theName = kernelManager->createOutline( manModelContour, actualInstantVector );
2127 bool addedModel = theName.compare("") != 0;
2130 double spc[3];//Si no hay imagen pero hay contornos que spacing se pone por default
2131 _theViewPanel->getSpacing(spc);
2132 //Adding the manualContourControler to interface objects structure
2133 //Adding the manualViewContour to interface objects structure
2134 //_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.
2135 _theViewPanel->configureViewControlTo(theName, manModelContour, spc, typeofcontour);
2136 //_theViewPanel->getSceneManager()->configureViewControlTo( theName, manModelContour,spc, typeofcontour ) ;
2140 int wxContourMainFrame::GetImageDataSizeZ(){
2141 return _theViewPanel->GetImageDataSizeZ();
2144 void wxContourMainFrame::GetImageDataRange(double *range){
2145 _theViewPanel->GetImageDataRange(range);
2148 void wxContourMainFrame::onSegmentationAllSlice(int minZ,int maxZ,int isovalue,int sampling,int method){
2149 //JCP 20-10-08 Undo redo implementation
2151 //JCP 20-10-08 Undo redo implementation
2154 int x = _theViewPanel->GetX();
2155 int y = _theViewPanel->GetY();
2159 double totalZ = maxZ-minZ+1;
2160 for( z=minZ ; z<=maxZ ; z++ )
2162 porcent = 100.0* (z-minZ)/totalZ;
2163 tmpString.Printf(_T(" %d %c %d/%d %d"), (int)porcent , 37 , z-minZ+1, (int)totalZ,z );
2164 interfMainPanel::getInstance()->setLabelSegmentationPanelVTK(tmpString);
2165 //_staticTextSegmentation->SetLabel(tmpString);
2166 SegmentationOneSlice( x,y,z,isovalue, sampling,method );
2168 interfMainPanel::getInstance()->setLabelSegmentationPanelVTK(_T(" "));
2173 //Creates a reference line to be used as the axis of the mirroring
2174 void wxContourMainFrame::referenceLine()
2176 if (_refLineControl==NULL)
2181 vtkImageData *vtkimagedata = _theViewPanel->getImageData();
2182 vtkimagedata->GetSpacing(spc);
2184 wxVtkBaseView * viewer2D = _theViewPanel->getWxVtkBaseView();
2186 _refLineControl = new manualLineControler();
2187 _refLineModel = new manualContourModelLine();
2188 _refLineView = new manualViewLine();
2189 _refLineView->SetModel( _refLineModel );
2190 _refLineView->SetWxVtkBaseView( viewer2D );
2191 _refLineView->SetRange( 2 );
2192 _refLineView->SetZ( 1200 );
2194 _refLineView->SetSpacing(spc);
2196 _refLineView->SetColorNormalContour(0, 0, 1);
2197 _refLineView->SetColorEditContour(0, 0.5, 0.5);
2198 _refLineView->SetWidthLine(4);
2200 _refLineControl->SetModelView( _refLineModel , _refLineView );
2201 vtkInteractorStyleBaseView* style = (vtkInteractorStyleBaseView*)viewer2D->GetInteractorStyleBaseView();
2202 style->AddInteractorStyleMaracas( _refLineControl );
2203 _refLineModel->SetCloseContour(false);
2204 _refLineControl->CreateNewManualContour();
2206 //AD: Inicializar el mirroring con una linea ya pintada
2208 double z = _refLineControl->GetZ();
2211 image->GetDimensions(imageDim);
2212 double x = (double) imageDim[0]/2;
2213 double y1 = (double) (imageDim[1]/2)+15;
2214 double y2 = (double) (imageDim[1]/2)-15;
2216 _refLineControl->AddPoint(x,y1,z);
2217 _refLineControl->AddPoint(x,y2,z);
2218 _refLineControl->SetCompleteCreation(true);
2220 _refLineModel->AddPoint(x,y1,z);
2221 _refLineModel->AddPoint(x,y2,z);
2222 _refLineModel->UpdateSpline();
2224 _refLineView->UpdateViewPoint(0);
2225 _refLineView->UpdateViewPoint(1);
2228 _refLineControl->SetActive(true);
2229 _refLineView->RefreshContour();
2233 //Hides the referenceLine
2234 void wxContourMainFrame::refLineHide()
2236 if (_refLineControl!=NULL)
2238 if (_refLineControl->GetActive())
2240 _refLineView->RemoveCompleteContourActor();
2241 _refLineControl->SetEditable(false);
2242 _refLineControl->SetActive(false);
2249 //Shows the referenceLine
2250 void wxContourMainFrame::refLineShow()
2252 if (_refLineControl!=NULL)
2254 if (_refLineControl->GetActive()==false)
2256 wxVtkBaseView * viewer2D = _theViewPanel->getWxVtkBaseView();
2258 _refLineView->SetModel( _refLineModel );
2259 _refLineView->SetWxVtkBaseView( viewer2D );
2260 _refLineView->SetRange( 2 );
2261 _refLineView->SetZ( 1200 );
2263 _refLineControl->SetModelView( _refLineModel , _refLineView );
2264 vtkInteractorStyleBaseView* style = (vtkInteractorStyleBaseView*)viewer2D->GetInteractorStyleBaseView();
2265 style->AddInteractorStyleMaracas( _refLineControl );
2266 _refLineControl->CreateNewManualContour();
2267 _refLineControl->SetActive(true);
2268 _refLineView->RefreshContour();
2275 void wxContourMainFrame::refLineChangeWidth(int width)
2277 _refLineView->SetWidthLine(width);
2278 _refLineView->RefreshContour();
2284 void wxContourMainFrame::onMirror()
2287 std::vector<std::string> currentSelection = _theViewPanel->getSelectedObjects();
2288 std::vector<std::string> filterCurrentSelection;
2290 std::vector<int> tempVector;
2291 _instantPanel->getInstant( tempVector );
2292 _performingOperation->reset();
2293 _performingOperation->setStartCommand( COPY );
2294 _performingOperation->setStartOperationInstantVector( tempVector );
2295 _performingOperation->setKeyNamesOperationElems( currentSelection );
2297 char theStartCommand = _performingOperation->getStartCommand();
2298 if ( theStartCommand == COPY )
2300 //JCP 20-10-08 Undo redo implementation
2302 //JCP 20-10-08 Undo redo implementation
2303 std::vector<int> tempVector;
2304 _instantPanel->getInstant( tempVector );
2305 _performingOperation->setEndOperationInstantVector ( tempVector );
2306 std::vector<std::string> elems = _performingOperation->getKeyNamesOperationElems();
2307 int i,size = elems.size();
2308 for( i=0; i<size; i++ )
2310 createMirrorContourOf( elems[i], tempVector, i>0 );
2314 //deleteContour( _refName );
2319 void wxContourMainFrame::showAxis(bool show)
2321 _theViewPanel->SetVisibleAxis(show);
2322 _theViewPanel->Refresh();
2326 void wxContourMainFrame::onRigidPressed(){
2327 std::vector<std::string> currentSelection = _theViewPanel->getSelectedObjects();
2328 int elementsSelected = currentSelection.size();
2330 if ( elementsSelected >= 1 ){
2331 //JCP 20-10-08 Undo redo implementation
2333 //JCP 20-10-08 Undo redo implementation
2335 std::vector<int> tempVector;
2336 _instantPanel->getInstant( tempVector );
2337 Instant instant(&tempVector);
2339 int i , size=currentSelection.size();
2340 for ( i=0 ; i<size ; i++ )
2342 kernelManager->changeContourOfManager(currentSelection[i], &instant);
2347 void wxContourMainFrame::onWidthOfContour(double width){
2349 _theViewPanel->removeSceneContours();
2350 _theViewPanel->SetWidthContour(width);
2352 //_theViewPanel->getSceneManager()->SetWidthContour( width );
2357 int wxContourMainFrame::getColorWindow()
2361 vtkImageData * img = getImageData();
2362 img->GetScalarRange(range);
2364 std::cout<<"Val 1: "<<range[0]<<" Val 2: "<<range[1]<<std::endl;
2366 return (int)range[1];
2368 return _theViewPanel->getColorWindow();
2371 int wxContourMainFrame::getWindowLevel()
2375 vtkImageData * img = getImageData();
2376 img->GetScalarRange(range);
2378 std::cout<<"Val 1: "<<range[0]<<" Val 2: "<<range[1]<<std::endl;
2380 return (int)range[1];
2382 return _theViewPanel->getWindowLevel();
2385 void wxContourMainFrame::onBrigthnessColorWindowLevel(int colorwindow,int windowlevel){
2386 _theViewPanel->onBrigthnessColorWindowLevel(colorwindow, windowlevel);
2391 void wxContourMainFrame::onInterpolation(bool interpolate){
2392 _theViewPanel->onInterpolation(interpolate);
2396 void wxContourMainFrame::onChangeInstant(std::string name,int actual){
2397 _instantPanel->setConceptValue( name, actual );
2401 void wxContourMainFrame::resetAppend(){
2402 kernelManager->resetAppend();
2407 void wxContourMainFrame::onSpreadAdd(){
2408 std::vector<double> vecX;
2409 std::vector<double> vecY;
2410 std::vector<double> vecZ;
2411 _theViewPanel->GetPointsOfActualContour(&vecX , &vecY , &vecZ );
2412 std::vector<int> tempVector;
2413 _instantPanel->getInstant( tempVector );
2414 std::string val = kernelManager->onSpreadAdd(&vecX , &vecY , &vecZ, tempVector);
2415 interfMainPanel::getInstance()->appendStringSpread(val);
2419 void wxContourMainFrame::onSpreadAddAll(){
2421 std::vector<int> tempVector;
2422 _instantPanel->getInstant( tempVector );
2425 maxZ = interfMainPanel::getInstance()->GetImageDataSizeZ();
2427 int sizeLstContourThings;
2428 for ( z=minZ ; z<=maxZ ; z++ )
2431 Instant instant(&tempVector);
2432 std::vector<ContourThing**> lstContourThings = kernelManager->getOutlinesAtInstant( &instant );
2433 sizeLstContourThings = lstContourThings.size();
2434 if (sizeLstContourThings>=1)
2436 std::vector<double> vecX;
2437 std::vector<double> vecY;
2438 std::vector<double> vecZ;
2439 ContourThing **contourthing = lstContourThings[0];
2440 manualBaseModel *cModel = (*contourthing)->getModel();
2441 int i,size = cModel->GetNumberOfPointsSpline();
2443 for (i=0; i<size; i++)
2445 cModel->GetSpline_i_Point(i, &x, &y, &z);
2450 std::string val = kernelManager->onSpreadAdd(&vecX , &vecY , &vecZ, tempVector);
2451 interfMainPanel::getInstance()->appendStringSpread(val);
2452 }// if sizeLstContourThings
2457 void wxContourMainFrame::onSpreadGo(int type){
2458 //JCP 20-10-08 Undo redo implementation
2460 //JCP 20-10-08 Undo redo implementation
2462 std::vector<double> vecCtrlPointX;
2463 std::vector<double> vecCtrlPointY;
2464 std::vector<double> vecCtrlPointZ;
2468 std::vector<int> tempVector;
2469 _instantPanel->getInstant( tempVector );
2472 kernelManager->getMaxMinZ(&minZ,&maxZ);
2473 //JSTG_16-07-08_----------------------------------------------------------------
2474 //_contourPropagation->setInterpolationNumber(maxZ-minZ+1);
2475 kernelManager->CalculeSplinePropagation();
2477 double totalZ = maxZ-minZ+1;
2480 //--------------------------------------------------------------------
2481 for ( z=(int)minZ ; z<=(int)maxZ ; z++ )
2483 porcent = 100.0* (z-minZ)/totalZ;
2484 int numero = (int)(z-minZ+1)/(int)totalZ;
2485 std::string stringtemp = " "+kernelManager->intToString(porcent)+"% "+kernelManager->intToString(numero)+" "+kernelManager->intToString(z);
2487 interfMainPanel::getInstance()->setStringSpread(stringtemp);
2489 int typeofcontour = 1;
2490 std::string theName;
2491 manualBaseModel* manModelContour = kernelManager->GetPoints(z, type, &vecCtrlPointX,&vecCtrlPointY,&vecCtrlPointZ, theName,typeofcontour, tempVector);
2493 if( manModelContour!=NULL ){
2494 double spc[3];//Si no hay imagen pero hay contornos que spacing se pone por default
2495 this->_theViewPanel->getSpacing(spc);
2496 //Adding the manualContourControler to interface objects structure
2497 //Adding the manualViewContour to interface objects structure
2498 //_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.
2499 _theViewPanel->configureViewControlTo( theName, manModelContour,spc,typeofcontour ) ;
2504 int numero = (int)(z-minZ+1)/(int)totalZ;
2505 std::string stringtemp = " "+kernelManager->intToString(porcent)+"% "+kernelManager->intToString(numero)+" "+kernelManager->intToString(z);
2507 interfMainPanel::getInstance()->setStringSpread(stringtemp);
2509 //RefreshInterface();
2512 void wxContourMainFrame::getInstantVector(std::vector<int>& tempVector){
2516 std::vector<std::string> wxContourMainFrame::getOutlinesName(int slide){
2517 std::vector<int> tempVector;
2518 _instantPanel->getInstant(tempVector);
2519 //Asignation of slide number should be different ex by name
2520 tempVector[1]=slide;
2521 return kernelManager->getOutlinesNameAtInstant(tempVector);
2525 void wxContourMainFrame::SetScalarRange(int grayRangeMin, int grayRangeMax)
2527 _contourextractdata->SetScalarRange(grayRangeMin,grayRangeMax);
2531 void wxContourMainFrame::onInformationContourLabels(int typeContourGroup,int selection,int minimumZ,int maximumZ,int grayRangeMin, int grayRangeMax)
2534 wxString tempString;
2535 int maxContourGroup = 0;
2537 _contourextractdata ->SetTypeOperation( typeContourGroup % 3 );
2539 std::vector<manualBaseModel*> lstManConMod;
2540 std::vector<manualBaseModel*> lstManConModTmp;
2541 std::vector<manualBaseModel*> lstManConModExp;
2542 std::vector<double> pLstValue;
2543 std::vector<double> pLstValuePosX;
2544 std::vector<double> pLstValuePosY;
2545 std::vector<double> pLstValuePosZ;
2548 int resultGrayRangeCount;
2551 double resultAverage;
2552 double resultStandardeviation;
2554 std::vector<int> tempVector;
2555 _instantPanel->getInstant( tempVector );
2558 int ii,sizeLstContourThings;
2567 if (selection==0 ) // actual slice
2569 int actualSlice = tempVector[1];
2572 } else { // slice range
2578 totalZ = maxZ-minZ+1;
2580 _contourextractdata->InitVolumeStatistics();
2583 for ( z=minZ ; z<=maxZ ; z++ )
2586 porcent = 100.0* (z-minZ)/totalZ;
2587 tmpString.Printf(_T(" %d %c %d/%d %d"), (int)porcent , 37 , z-minZ+1, (int)totalZ ,z);
2589 interfMainPanel::getInstance()->setStringInfoPanel(tmpString);
2590 //_staticTextInformation->SetLabel(tmpString);
2592 //Extraction data from contours of each slice
2593 _contourextractdata->SetZtoBeAnalys(z);
2596 Instant instant(&tempVector);
2597 std::vector<ContourThing**> lstContourThings = kernelManager->getOutlinesAtInstant( &instant );
2598 sizeLstContourThings = lstContourThings.size();
2600 lstManConMod.clear();
2601 for (ii=0 ; ii<sizeLstContourThings ; ii++)
2603 ContourThing **contourthing = lstContourThings[ii];
2604 lstManConMod.push_back( (*contourthing)->getModel() );
2607 lstManConModExp = kernelManager->ExploseEachModel( lstManConMod );
2609 tempString.Printf(_T("%d - %d"),z, sizeLstContourThings);
2610 interfMainPanel::getInstance()->setRowLabelInfoPanel(z, tempString);
2611 //_grid->SetRowLabelValue(z, tempString );
2613 int iContourGroup,sizeContourGroup;
2614 if (typeContourGroup==3) // contour separete
2616 sizeContourGroup=lstManConModExp.size();
2617 if ( maxContourGroup<sizeContourGroup )
2619 maxContourGroup=sizeContourGroup;
2621 } else { // contour AND OR XOR
2628 for( iContourGroup=0 ; iContourGroup<sizeContourGroup ; iContourGroup++ ){
2629 lstManConModTmp.clear();
2633 if (typeContourGroup==3) // contour separete
2635 lstManConModTmp.push_back( lstManConModExp[iContourGroup]);
2636 } else { // contour AND OR XOR
2637 lstManConModTmp = lstManConModExp;
2640 _contourextractdata->SetLstManualContourModel( lstManConModTmp );
2641 _contourextractdata->SetScalarRange(grayRangeMin,grayRangeMax);
2644 pLstValuePosX.clear();
2645 pLstValuePosY.clear();
2646 pLstValuePosZ.clear();
2650 _contourextractdata->GetValuesInsideCrown( &numberOfPixels,
2656 resultSize=numberOfPixels;
2657 // Statistics of each slice.
2658 _contourextractdata->Statistics( &pLstValue,
2661 &resultGrayRangeCount,
2666 &resultStandardeviation);
2668 if (interfMainPanel::getInstance()->getNumberColsInformationPanel()<_numberOfVariablesStatistics*(iContourGroup+1) )
2670 interfMainPanel::getInstance()->appendColsInformationPanel(_numberOfVariablesStatistics);
2673 tmpIntA=_numberOfVariablesStatistics*iContourGroup ;
2675 tempString.Printf(_T("%d"),numberOfPixels);
2677 interfMainPanel::getInstance()->setCellValueInfoPanel(z, tmpIntA, tempString);
2679 tempString.Printf(_T("%d"),resultGrayRangeCount);
2680 interfMainPanel::getInstance()->setCellValueInfoPanel(z, tmpIntA+1, tempString);
2682 tempString.Printf(_T("%f"),resultMin);
2683 interfMainPanel::getInstance()->setCellValueInfoPanel(z, tmpIntA+2, tempString);
2685 tempString.Printf(_T("%f"),resultMax);
2686 interfMainPanel::getInstance()->setCellValueInfoPanel(z, tmpIntA+3, tempString);
2688 tempString.Printf(_T("%f"),resultAverage);
2689 interfMainPanel::getInstance()->setCellValueInfoPanel(z, tmpIntA+4, tempString);
2691 tempString.Printf(_T("%f"),resultStandardeviation);
2692 interfMainPanel::getInstance()->setCellValueInfoPanel(z, tmpIntA+5, tempString);
2695 } // for iContourGroup
2698 // Print Volume Statistics
2701 int vol_rCountRange;
2703 double vol_minValue;
2704 double vol_maxValue;
2706 double vol_standardeviation;
2708 if (selection!=0 ) // actual slice
2711 _contourextractdata->GetVolumeStatistics(&vol_rCountRange, &vol_rsize,
2712 &vol_minValue, &vol_maxValue,
2713 &vol_average, &vol_standardeviation);
2715 interfMainPanel::getInstance()->setRowLabelInfoPanel(maxZ+2, _T("Total:"));
2717 tempString.Printf(_T("%d"),vol_rsize);
2718 interfMainPanel::getInstance()->setCellValueInfoPanel(maxZ+2, 0, tempString);
2720 tempString.Printf(_T("%d"),vol_rCountRange);
2721 interfMainPanel::getInstance()->setCellValueInfoPanel(maxZ+2, 1, tempString);
2723 tempString.Printf(_T("%f"),vol_minValue);
2724 interfMainPanel::getInstance()->setCellValueInfoPanel(maxZ+2, 2, tempString);
2726 tempString.Printf(_T("%f"),vol_maxValue);
2727 interfMainPanel::getInstance()->setCellValueInfoPanel(maxZ+2, 3, tempString);
2729 tempString.Printf(_T("%f"),vol_average);
2730 interfMainPanel::getInstance()->setCellValueInfoPanel(maxZ+2, 4, tempString);
2732 tempString.Printf(_T("%f"),vol_standardeviation);
2733 interfMainPanel::getInstance()->setCellValueInfoPanel(maxZ+2, 5, tempString);
2735 //-----------------------------------------
2738 wxString tmpTitleString;
2740 for ( iTitleGroup=0 ; iTitleGroup<maxContourGroup ; iTitleGroup++ )
2742 tmpIntB =_numberOfVariablesStatistics*iTitleGroup;
2743 tmpTitleString.Printf(_T("%d-Size Data"),iTitleGroup);
2744 interfMainPanel::getInstance()->setColLableInfoPanel(tmpIntB + 0, tmpTitleString);
2746 interfMainPanel::getInstance()->setColLableInfoPanel(tmpIntB + 0, tmpTitleString );
2747 interfMainPanel::getInstance()->setColLableInfoPanel( tmpIntB + 1, _T("Size Range") );
2748 interfMainPanel::getInstance()->setColLableInfoPanel( tmpIntB + 2, _T("Min") );
2749 interfMainPanel::getInstance()->setColLableInfoPanel( tmpIntB + 3, _T("Max") );
2750 interfMainPanel::getInstance()->setColLableInfoPanel( tmpIntB + 4, _T("Average") );
2751 interfMainPanel::getInstance()->setColLableInfoPanel( tmpIntB + 5, _T("St.Dev.") );
2752 interfMainPanel::getInstance()->setColLableInfoPanel( tmpIntB + 6, _T(" ") );
2754 interfMainPanel::getInstance()->setStringInfoPanel( _T("") );
2758 void wxContourMainFrame::onSaveResults(std::string directory,std::string namefile, std::string filename,
2759 int typeContourGroup, int selection, int minZ, int maxZ, bool XYZValues, bool contourImage, bool statistics)
2763 SaveValuesXYZ( directory , namefile, typeContourGroup );
2768 vtkImageData * mask;
2769 vtkImageData * value;
2770 this->getMaskValue(&mask, &value, typeContourGroup,selection,minZ,maxZ);
2771 this->SaveImageResult( directory , namefile, mask, value);
2776 std::ostringstream name;
2777 name << filename << ".xls";
2780 FILE *pFile=fopen(name.str().c_str(),"w+");
2786 // int sizeZ = _theViewPanel->GetImageDataSizeZ();
2787 // int maxY=sizeZ+2;
2789 maxX= interfMainPanel::getInstance()->getNumberColsInformationPanel();//this->_grid->GetNumberCols();
2792 int iTitle,sizeTitle = (maxX / _numberOfVariablesStatistics);
2793 for ( iTitle=0; iTitle<sizeTitle ; iTitle++)
2795 // fprintf(pFile,"-- \t %d-Size \t SizeRange \t Min \t Max \t Ave \t StDv \t" , iTitle,tmpString.c_str() );
2796 fprintf(pFile,"slice\t %d-Size \t SizeRange \t Min \t Max \t Ave \t StDv \t" , iTitle );
2798 fprintf(pFile,"\n\n" );
2802 if (selection==0 ) // actual slice
2804 std::vector<int> tempVector;
2805 _instantPanel->getInstant( tempVector );
2806 int actualSlice = tempVector[1];
2812 for ( j=minZ; j<=maxZ ; j++)
2814 fprintf(pFile,"%d\t" , j );
2815 for (i=0 ; i<maxX ; i++){
2816 tmpString = interfMainPanel::getInstance()->getCellValue(j, i);//_grid->GetCellValue( j , i );
2817 fprintf(pFile,"%s\t" , (const char *)(tmpString.mb_str()) );
2819 fprintf(pFile,"\n" );
2823 // Total of stadistics.....
2826 fprintf(pFile,"\n Total:\t" );
2827 for (i=0 ; i<maxX ; i++){
2828 tmpString = interfMainPanel::getInstance()->getCellValue(maxZ+2, i);//_grid->GetCellValue( maxZ+2 , i );
2829 fprintf(pFile,"%s\t" , (const char *)(tmpString.mb_str()) );
2831 fprintf(pFile,"\n" );
2839 void wxContourMainFrame::SaveValuesXYZ(std::string directory,std::string namefile,int typeContourGroup)
2843 //int typeContourGroup = this->_radiolstboxContourGroup->GetSelection();
2844 _contourextractdata ->SetTypeOperation( typeContourGroup % 3 );
2846 std::vector<manualBaseModel*> lstManConMod;
2847 std::vector<manualBaseModel*> lstManConModTmp;
2848 std::vector<manualBaseModel*> lstManConModExp;
2849 std::vector<double> pLstValue;
2850 std::vector<double> pLstValuePosX;
2851 std::vector<double> pLstValuePosY;
2852 std::vector<double> pLstValuePosZ;
2854 std::vector<int> tempVector;
2855 _instantPanel->getInstant( tempVector );
2857 int sizeZ = _theViewPanel->getSceneManager()->GetImageDataSizeZ();
2859 int ii,sizeLstContourThings;
2866 minZ = 0;// _mbarrange->GetStart();
2867 maxZ = sizeZ;//_mbarrange->GetEnd();
2868 totalZ = maxZ-minZ+1;
2872 for ( z=0 ; z<sizeZ ; z++)
2875 porcent = 100.0* (z-minZ)/totalZ;
2877 tmpString.Printf(_T("Saving Values"));
2878 tmpString.Printf(_T(" %d %c %d/%d %d"), (int)porcent , 37 , z-minZ+1, (int)totalZ ,z);
2879 interfMainPanel::getInstance()->setStringInfoPanel(tmpString);
2880 //_staticTextInformation->SetLabel(tmpString);
2883 //Extraction data from contours of each slice
2884 _contourextractdata->SetZtoBeAnalys( z);
2887 Instant instant(&tempVector);
2888 std::vector<ContourThing**> lstContourThings = kernelManager->getOutlinesAtInstant(&instant);//this->_modelManager->getOutlinesAtInstant( &instant );
2889 sizeLstContourThings = lstContourThings.size();
2891 lstManConMod.clear();
2892 for (ii=0 ; ii<sizeLstContourThings ; ii++)
2894 ContourThing **contourthing = lstContourThings[ii];
2895 lstManConMod.push_back( (*contourthing)->getModel() );
2897 lstManConModExp = kernelManager->ExploseEachModel( lstManConMod );
2902 int iContourGroup,sizeContourGroup;
2903 if (typeContourGroup==3) // contour separete
2905 sizeContourGroup=lstManConModExp.size();
2906 } else { // contour AND OR XOR
2910 for( iContourGroup=0 ; iContourGroup<sizeContourGroup ; iContourGroup++ ){
2911 lstManConModTmp.clear();
2912 if (typeContourGroup==3) // contour separete
2914 lstManConModTmp.push_back( lstManConModExp[iContourGroup]);
2915 } else { // contour AND OR XOR
2916 lstManConModTmp = lstManConModExp;
2919 _contourextractdata->SetLstManualContourModel( lstManConModTmp );
2922 pLstValuePosX.clear();
2923 pLstValuePosY.clear();
2924 pLstValuePosZ.clear();
2926 _contourextractdata->GetValuesInsideCrown( &numberOfPixels,
2932 std::string temp = directory + "/" + namefile + "-slice";
2933 temp = temp + kernelManager->intToString(z) + "-cont" + kernelManager->intToString(iContourGroup);
2934 temp = temp + ".txt";
2936 // LG 14/01/09 : using crea
2937 wxString filename = crea::std2wx(temp);
2938 /*filename.Printf(_T("%s"),directory.c_str());
2939 filename.append(_T("\\"));
2940 filename.append(_T("%s"),namefile.c_str());
2941 filename.append(_T("-slice"));
2942 filename.append(_T("%d"),z);
2943 filename.append(_T("-cont"));
2944 filename.append(_T("%d"),iContourGroup);
2945 filename.append(_T(".txt"));*/
2946 // filename.Printf(temp.c_str());
2950 FILE *pFile=fopen((const char *)filename.mb_str(),"w+");
2951 fprintf(pFile,"value \t x \t y \t z\n" );
2952 int iLstValue,sizeLstValue=pLstValue.size();
2953 for (iLstValue=0 ; iLstValue<sizeLstValue ; iLstValue++ )
2955 fprintf(pFile,"%f\t %f\t %f\t %f\n", (float)pLstValue[iLstValue] , (float)pLstValuePosX[iLstValue], (float)pLstValuePosY[iLstValue], (float)z );
2958 } // for iContourGroup
2960 interfMainPanel::getInstance()->setStringInfoPanel(_T(""));
2961 //_staticTextInformation->SetLabel( _T("") );
2965 void wxContourMainFrame::getMaskValue(vtkImageData ** mask,vtkImageData ** value,int typeContourGroup, int selection, int minZ, int maxZ){
2968 //int typeContourGroup = this->_radiolstboxContourGroup->GetSelection();
2969 if (typeContourGroup==3)
2973 _contourextractdata ->SetTypeOperation( typeContourGroup % 3 );
2975 std::vector<manualBaseModel*> lstManConMod;
2976 std::vector<manualBaseModel*> lstManConModTmp;
2977 std::vector<manualBaseModel*> lstManConModExp;
2979 std::vector<int> tempVector;
2980 _instantPanel->getInstant( tempVector );
2982 vtkImageData *imagedata = _theViewPanel->getImageData();
2984 imagedata->GetExtent(ext);
2985 int sizeZimage = ext[5]-ext[4]+1;
2987 int ii,sizeLstContourThings;
2996 if (selection==0 ) // actual slice
2998 int actualSlice = tempVector[1];
3006 // cleanning image before range
3007 for (z=0; z<minZ; z++){
3008 _contourextractdata->ResetImageResult(z);
3010 // cleanning image after range
3011 for (z=maxZ+1; z<sizeZimage; z++){
3012 _contourextractdata->ResetImageResult(z);
3017 for ( z=minZ ; z<=maxZ ; z++)
3020 porcent = 100.0* (z-minZ)/totalZ;
3021 tmpString.Printf(_T("Saving Values"));
3022 tmpString.Printf(_T("%d %c %d/%d %d"), (int)porcent , 37 , z-minZ+1, (int)totalZ ,z);
3023 interfMainPanel::getInstance()->setStringInfoPanel(tmpString);
3025 //Extraction data from contours of each slice
3026 _contourextractdata->SetZtoBeAnalys( z);
3029 Instant instant(&tempVector);
3030 std::vector<ContourThing**> lstContourThings = kernelManager->getOutlinesAtInstant( &instant );
3031 sizeLstContourThings = lstContourThings.size();
3033 lstManConMod.clear();
3034 for (ii=0 ; ii<sizeLstContourThings ; ii++)
3036 ContourThing **contourthing = lstContourThings[ii];
3037 lstManConMod.push_back( (*contourthing)->getModel() );
3039 lstManConModExp = kernelManager->ExploseEachModel( lstManConMod );
3042 int iContourGroup,sizeContourGroup;
3043 if (typeContourGroup==3) // contour separete
3045 sizeContourGroup=lstManConModExp.size();
3046 } else { // contour AND OR XOR
3050 for( iContourGroup=0 ; iContourGroup<sizeContourGroup ; iContourGroup++ ){
3051 lstManConModTmp.clear();
3052 if (typeContourGroup==3) // contour separete
3054 lstManConModTmp.push_back( lstManConModExp[iContourGroup]);
3055 } else { // contour AND OR XOR
3056 lstManConModTmp = lstManConModExp;
3059 _contourextractdata->SetLstManualContourModel( lstManConModTmp );
3060 _contourextractdata->CalculateImageResult(); // with actual Z
3062 } // for iContourGroup
3065 (*value) = _contourextractdata->GetVtkImageValueResult();
3066 (*mask) = _contourextractdata->GetVtkImageMaskResult();
3070 void wxContourMainFrame::SaveImageResult(std::string directory,std::string namefile, vtkImageData* mask,vtkImageData* value)
3074 kernelManager->GetSpacing(spc,0); // returns the spacing of the first image
3076 std::string temp = directory + "/" + namefile + "-image-Value.mhd";
3078 wxString filename = crea::std2wx(temp);
3082 vtkImageChangeInformation *valueChInfo = vtkImageChangeInformation::New();
3083 valueChInfo->SetInput(value);
3084 valueChInfo->SetSpacingScale(spc);
3085 vtkMetaImageWriter *writerValueImage = vtkMetaImageWriter::New( );
3086 writerValueImage->SetInput( valueChInfo->GetOutput() );
3087 writerValueImage->SetFileName( (const char *)filename.mb_str() );
3088 writerValueImage->SetFileDimensionality( 3 );
3089 writerValueImage->SetCompression(false);
3090 writerValueImage->Write( );
3093 temp = directory + "/" + namefile + "-image-Mask.mhd";
3095 // LG 14/01/09 : using crea
3096 filename = crea::std2wx(temp);
3097 // filename.Printf(_T(temp.c_str()));
3100 vtkImageChangeInformation *maskChInfo = vtkImageChangeInformation::New();
3101 maskChInfo->SetInput(mask);
3102 maskChInfo->SetSpacingScale(spc);
3103 vtkMetaImageWriter *writerMaskImage = vtkMetaImageWriter::New( );
3104 writerMaskImage->SetInput( maskChInfo->GetOutput() );
3105 writerMaskImage->SetFileName( (const char *)filename.mb_str() );
3106 writerMaskImage->SetFileDimensionality( 3 );
3107 writerMaskImage->SetCompression(false);
3108 writerMaskImage->Write( );
3110 interfMainPanel::getInstance()->setStringInfoPanel( _T("") );
3116 void wxContourMainFrame::onChangeInstantInstantPanel(std::string name,int value, int minshow, int maxshow){
3117 if( name.compare( _theViewPanel->getVerticalConceptName() ) == 0){
3118 _theViewPanel->setActualVertical( value);
3120 else if( name.compare( _theViewPanel->getHorizontalConceptName() ) == 0|| _instantPanel->getIfConceptCheckedAt( name, 0 ) ) {
3121 _theViewPanel->setHorizontalConcept( name, minshow, maxshow, minshow, maxshow, value);
3127 void wxContourMainFrame::onSnakePressed(){
3128 std::vector<double> vecX;
3129 std::vector<double> vecY;
3130 std::vector<double> vecZ;
3131 _theViewPanel->GetPointsOfActualContour( &vecX , &vecY , &vecZ );
3133 if (vecX.size()!=0){
3134 std::vector<int> tempVector;
3135 _instantPanel->getInstant( tempVector );
3136 int i,size=vecZ.size();
3137 int actualSlice = tempVector[1];
3138 for ( i=0 ; i<size ; i++ )
3140 vecZ[i] = actualSlice;
3143 wxDialog* dialog = new wxDialog(this, -1, wxString(_T("Snake")));
3144 wxPanel* panel = new wxPanel(dialog,-1);
3145 // wxStaticText* sttext = new wxStaticText(panel, -1, wxString(_T("Panel para snake")));
3146 new wxStaticText(panel, -1, wxString(_T("Panel para snake")));
3147 dialog->ShowModal();
3152 void wxContourMainFrame::saveFileWithContoursAutomatique(){
3153 std::string filename = kernelManager->getCurrentFileName();
3154 if(filename.compare("")!=0){
3155 saveFileWithContours(filename);
3160 void wxContourMainFrame::ShowToolsPanel(bool show){
3161 _pannew->Show(show);
3166 void wxContourMainFrame::SetContourGroup(int contourGroup)
3168 _contourGroup = contourGroup;
3172 wxPanel *wxContourMainFrame::getMaskImageViewPanel(wxWindow *parent)
3175 if (_viewMaskImagePanel==NULL)
3177 _contourextractdata = new ContourExtractData(true);
3178 _contourextractdata->SetImage( _theViewPanel->getImageData() );
3180 // _theViewPanel->getImageData()->GetScalarRange(range);
3181 //int min = (int)floor (range[0]);
3182 //int max = (int)ceil (range[1]);
3185 _viewMaskImagePanel = new ThresholdImageViewPanel( parent, -1, -1 , 0);
3186 _viewMaskImage = new ThresholdImageView();
3187 _viewMaskImage->SetImage(_contourextractdata->GetVtkImageMaskResult() );
3188 _viewMaskImage->SetminMaxValue( min, max);
3189 _viewMaskImage->SetBaseColor( 0,0,1 );
3190 _viewMaskImagePanel->SetThresholdImageView( _viewMaskImage );
3191 _viewMaskImage->SetwxVtkBaseView( _theViewPanel->getWxVtkBaseView() );
3193 return _viewMaskImagePanel;
3197 wxPanel *wxContourMainFrame::getColorLayerImageViewPanel(wxWindow *parent)
3199 if (_viewColorLayerImagePanel==NULL)
3202 _theViewPanel->getImageData()->GetScalarRange(range);
3203 int min = (int)floor (range[0]);
3204 int max = (int)ceil (range[1]);
3205 _viewColorLayerImagePanel = new ColorLayerImageViewPanel( parent, min, max, 100, 1);
3206 _viewColorLayerImagePanel->GetColorLayerImageViewManager()->SetwxVtkBaseView( 0 , _theViewPanel->getWxVtkBaseView() );
3208 return _viewColorLayerImagePanel;
3212 wxPanel *wxContourMainFrame::getThresholdImageViewPanel(wxWindow *parent)
3214 if (_viewThresholdImagePanel==NULL)
3217 _theViewPanel->getImageData()->GetScalarRange(range);
3218 int min = (int)floor (range[0]);
3219 int max = (int)ceil (range[1]);
3220 _viewThresholdImagePanel = new ThresholdImageViewPanel( parent, min, max , 1);
3221 _viewThresholdImage = new ThresholdImageView();
3222 _viewThresholdImage->SetImage( _theViewPanel->getImageData() );
3223 _viewThresholdImage->SetminMaxValue( min, max);
3224 _viewThresholdImage->SetBaseColor( 1,0,0 );
3225 _viewThresholdImagePanel->SetThresholdImageView( _viewThresholdImage );
3226 _viewThresholdImage->SetwxVtkBaseView( _theViewPanel->getWxVtkBaseView() );
3228 return _viewThresholdImagePanel;
3231 //CMRU 17-08-09-----------------------------------------------------------------------------------------------
3232 int wxContourMainFrame::getType ()
3235 std::vector<std::string> currentSelection = _theViewPanel->getSelectedObjects();
3237 if(!currentSelection.empty())
3239 std::string cloneName = currentSelection [0];
3240 manualBaseModel * manualModel = kernelManager->getOutlineByKeyName(cloneName);
3241 tipo = manualModel-> GetTypeModel();
3246 double wxContourMainFrame::getContourSizeInPixels()
3248 double contourSize = 0;
3250 std::vector<std::string> currentSelection = _theViewPanel->getSelectedObjects(); if(!currentSelection.empty())
3251 if(!currentSelection.empty())
3253 std::string cloneName = currentSelection [0];
3255 manualBaseModel * manualModel = kernelManager->getOutlineByKeyName(cloneName);//_modelManager->getOutlineByKeyName( cloneName )->getModel();
3258 // contourSize = manualModel->GetPathSize();
3263 contourSize = manualModel->GetPathSize( spc );
3268 manualBaseModel * wxContourMainFrame::getContour ()
3270 std::vector<std::string> currentSelection = _theViewPanel->getSelectedObjects();
3272 if(!currentSelection.empty())
3274 std::string cloneName = currentSelection [0];
3275 manualBaseModel * manualModel = kernelManager->getOutlineByKeyName(cloneName);//_modelManager->getOutlineByKeyName( cloneName )->getModel();
3280 void wxContourMainFrame::onPrintLabel (wxString label, manualBaseModel* manualModel)
3282 std::string labelAscii(label.ToAscii());
3283 int pos = labelAscii.find(" ");
3287 for (j=0 ; pos != string::npos;j++)
3289 labelAscii.replace( pos, 1, "_" );
3290 pos= labelAscii.find(" ");
3293 manualModel -> SetLabel(labelAscii);
3295 void wxContourMainFrame::onInsertCalculation(manualBaseModel* manualModel)
3298 // double sizeInPixel = manualModel ->GetPathSize( );
3303 double sizeInPixel = manualModel ->GetPathSize( spc );
3305 double onePixelRealSize = interfMainPanel::getInstance()->GetPixelValue();;
3306 double realContourSize = sizeInPixel*onePixelRealSize;
3307 manualModel ->SetRealSize(realContourSize);
3310 double wxContourMainFrame::onePixelSize( double value)
3312 return _onePixelSize = value;
3315 std::string wxContourMainFrame::GetFileLocation()
3317 return _fileLocation;
3320 void wxContourMainFrame::SetFileLocation(std::string newFileLocation)
3322 _fileLocation = newFileLocation;
3323 std::cout<<"GETFILELOCATION:"<<_fileLocation<<std::endl;
3325 //------------------------------------------------------------------------------------------------------------
3334 void wxContourMainFrame::FlipSelectedContours(int flipDirection)
3336 printf("EED wxContourMainFrame::FlipSelectedContours flipDirection=%d \n", flipDirection );
3338 (std::vector<std::string>)_theViewPanel->getSceneManager()->getSelectedObjects() ,
3344 void wxContourMainFrame::FlipActualSliceContours(int flipDirection)
3346 printf("EED wxContourMainFrame::FlipActualSliceContours flipDirection=%d \n", flipDirection );
3348 (std::vector<std::string>)_theViewPanel->getSceneManager()->GetlstContoursNameActualSlice() ,
3353 void wxContourMainFrame::FlipAllContours(int flipDirection)
3355 printf("EED wxContourMainFrame::FlipAllContours flipDirection=%d \n", flipDirection );
3357 kernelManager->GetLstNameThings() ,
3362 void wxContourMainFrame::FlipLstOfContours(std::vector<std::string> lstNameThings, int flipDirection)
3365 getImageData()->GetExtent(ext);
3366 int sizeX = ext[1]-ext[0];
3367 int sizeY = ext[3]-ext[2];
3370 int i,sizeLstNameThings;
3371 int ii,sizeLstPoints;
3373 sizeLstNameThings = lstNameThings.size();
3374 for (i=0 ; i<sizeLstNameThings ; i++)
3376 printf("EED wxContourMainFrame::FlipAllContours contour=%d \n", i );
3377 manualBaseModel * manualModel = kernelManager->getOutlineByKeyName(lstNameThings[i]);
3378 if (flipDirection==0)
3380 manualModel->Transform_Ax_Plus_B(-1,sizeX,1,0 );
3382 manualModel->Transform_Ax_Plus_B(1,0,-1,sizeY );
3384 }// for i list of Things
3386 //-- Static Contours
3388 lstNameThings = kernelManager->GetLstNameThingsStatic();
3389 sizeLstNameThings = lstNameThings.size();
3390 for (i=0 ; i<sizeLstNameThings ; i++)
3392 manualBaseModel * manualModel = kernelManager->getOutlineByKeyName(lstNameThings[i]);
3393 if (flipDirection==0)
3395 manualModel->Transform_Ax_Plus_B(-1,sizeX,1,0 );
3397 manualModel->Transform_Ax_Plus_B(1,0,-1,sizeY );
3399 }// for i list of static things
3402 void wxContourMainFrame::FlipContours(int typeContourFlip, int flipDirection)
3404 printf("EED wxContourMainFrame::FlipContours( %d , %d ) \n",typeContourFlip, flipDirection );
3408 if (typeContourFlip==0) //
3410 FlipSelectedContours(flipDirection);
3413 if (typeContourFlip==1) //
3415 FlipActualSliceContours(flipDirection);
3418 if (typeContourFlip==2) //
3420 FlipAllContours(flipDirection);