/*# --------------------------------------------------------------------- # # Copyright (c) CREATIS (Centre de Recherche en Acquisition et Traitement de l'Image # pour la Sant�) # Authors : Eduardo Davila, Frederic Cervenansky, Claire Mouton # Previous Authors : Laurent Guigues, Jean-Pierre Roux # CreaTools website : www.creatis.insa-lyon.fr/site/fr/creatools_accueil # # This software is governed by the CeCILL-B license under French law and # abiding by the rules of distribution of free software. You can use, # modify and/ or redistribute the software under the terms of the CeCILL-B # license as circulated by CEA, CNRS and INRIA at the following URL # http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html # or in the file LICENSE.txt. # # As a counterpart to the access to the source code and rights to copy, # modify and redistribute granted by the license, users are provided only # with a limited warranty and the software's author, the holder of the # economic rights, and the successive licensors have only limited # liability. # # The fact that you are presently reading this means that you have had # knowledge of the CeCILL-B license and that you accept its terms. # ------------------------------------------------------------------------ */ /* Diagrama de Secuaencia de cambiar un instante wxContourEventHandler :: changeInstant() OutlineModelManager :: ->setInstant( _actualInstant ); OutlineModelManager :: updateToActualInstant() OutlineModelManager :: getOutlinesAtInstant(Instant * anInstant, bool ifAnnotate) OutlineModelManager :: annotateOutlinesWrap(std::vector kNamesVector, std::vector theOutlinesVector) wxContourEventHandler :: updateInstantOutlines() OutlineModelManager :: getActualInstantOutlines () wxVtkBaseView_SceneManager :: addToScene( std::vector< std::string> theKeyNameVector, bool append, bool visualization, bool control, bool ifActive, bool ifShowCtrlPoints ) wxVtkBaseView_SceneManager :: addToScene( std::string theKeyName, bool append, bool visualization, bool control, bool ifActive, bool ifShowCtrlPoints ) wxVtkBaseView_SceneManager :: getContourWrap_ViewControlOf MAP find void wxVtkBaseView_SceneManager :: addToScene( std::string theKeyName, ContourWrap_ViewControl * contourWRP, bool append, bool visualization, bool control, bool ifActive, bool ifShowCtrlPoints ) */ /*! \mainpage NDimension with wxWidgets and maracas \section intro Introduction This is the introduction. \dot digraph example_0 { graph [ ratio=fill]; node [shape=record, fontname=Helvetica, fontsize=10]; _wxContourGUIExample [ label="wxContourGUIExample" URL="\ref wxContourGUIExample"]; _wxContourEventHandler [ label="wxContourEventHandler" URL="\ref wxContourEventHandler"]; _OutlineModelManager [ label="OutlineModelManager" URL="\ref OutlineModelManager"]; _wxInstantChooserPanel [ label="wxInstantChooserPanel" URL="\ref wxInstantChooserPanel"]; _wxContourViewPanel [ label="wxContourViewPanel" URL="\ref wxContourViewPanel"]; _wxContour_ButtonsBar [ label="wxContour_ButtonsBar" URL="\ref wxContour_ButtonsBar"]; _OutlineModelManager [ label="OutlineModelManager" URL="\ref OutlineModelManager"]; _wxVtkBaseView_SceneManager [ label="wxVtkBaseView_SceneManager" URL="\ref wxVtkBaseView_SceneManager"]; _SomeEnvironment [ label="SomeEnvironment" URL="\ref SomeEnvironment"]; _wxContourGUIExample -> _wxContourEventHandler [ arrowhead="open", style="dashed" ]; _wxContourGUIExample -> _OutlineModelManager [ arrowhead="open", style="dashed" ]; _wxContourGUIExample -> _wxInstantChooserPanel [ arrowhead="open", style="dashed" ]; _wxContourGUIExample -> _wxContourViewPanel [ arrowhead="open", style="dashed" ]; _wxContourGUIExample -> _wxContour_ButtonsBar [ arrowhead="open", style="dashed" ]; _wxContourViewPanel -> wxMaracas_N_ViewersWidget [ arrowhead="open", style="dashed" ]; _wxContourEventHandler -> _OutlineModelManager [ arrowhead="open", style="dashed" ]; _wxContourEventHandler -> _wxVtkBaseView_SceneManager [ arrowhead="open", style="dashed" ]; _OutlineModelManager -> _SomeEnvironment [ arrowhead="open", style="dashed" ]; } \enddot */ //---------------------------------------------------------------------------------------------------------------- // Class definition include //---------------------------------------------------------------------------------------------------------------- #include "wxContourEventHandler.h" #include #include #include #include //---------------------------------------------------------------------------------------------------------------- // Class implementation //---------------------------------------------------------------------------------------------------------------- /** @file wxContourEventHandler.cxx */ //------------------------------------------------------------------------------------------------------------ // Includes //------------------------------------------------------------------------------------------------------------ #include "wxContour_ActionCommandsID.h" #include "NameWrapper.h" #include "ConceptDataWrap.h" #include "OutlineGroup.h" #include #include "Contour/ContourExtractData.h" #include "ImageSourceThing.h" #include "PanelBullEyeOptions.h" #include #include #include #include #include #include #include //------------------------------------------------------------------------------------------------------------ //------------------------------------------------------------------------------------------------------------ //------------------------------------------------------------------------------------------------------------ /* PanelBullEyeOptions::PanelBullEyeOptions (wxWindow * parent, wxSize size) : wxPanel(parent, -1, wxDefaultPosition, size) { _maxLevels = 5; _maxSections = 10; wxSize sizepanel(190,300); wxPanel *panel = this; wxString lstOptions[2]; lstOptions[0]= wxString("General options",wxConvUTF8); lstOptions[1]= wxString("Detail options",wxConvUTF8); _radioboxBullEyeGenOpt = new wxRadioBox(panel, -1, wxString("General/Detail options",wxConvUTF8), wxDefaultPosition, wxSize(200,45), 2 , lstOptions, 2, wxRA_SPECIFY_COLS); _radioboxBullEyeGenOpt->SetSelection(0); _spinctrlBullEyeNumOfCrowns = new wxSpinCtrl( panel , -1,_T("B"),wxDefaultPosition, wxSize(40,20) ); _spinctrlBullEyeNumOfCrowns->SetRange(1,_maxLevels); _spinctrlBullEyeNumOfCrowns->SetValue(3); _spinctrlBullEyeNumOfSec = new wxSpinCtrl( panel , -1,_T("A"),wxDefaultPosition, wxSize(40,20) ); _spinctrlBullEyeNumOfSec->SetRange(1,_maxSections); _spinctrlBullEyeNumOfSec->SetValue(5); _sliderBullEyeAngle = new wxSlider( panel , -1 ,0,0,180, wxDefaultPosition, wxSize(200,35), wxSL_HORIZONTAL|wxSL_LABELS, wxDefaultValidator); wxFlexGridSizer * sizerGeneralOptions = new wxFlexGridSizer(10); wxFlexGridSizer * sizerGeneralOptionsA = new wxFlexGridSizer(1); wxFlexGridSizer * sizerGeneralOptionsB = new wxFlexGridSizer(1); wxFlexGridSizer * sizerGeneralOptionsC = new wxFlexGridSizer(1); sizerGeneralOptionsA -> Add( new wxStaticText(panel,-1,_T("Crowns")) , 1, wxGROW ); sizerGeneralOptionsA -> Add( _spinctrlBullEyeNumOfCrowns , 1/*, wxGROW ); sizerGeneralOptionsB -> Add( new wxStaticText(panel,-1,_T("Sections")) , 1, wxGROW ); sizerGeneralOptionsB -> Add( _spinctrlBullEyeNumOfSec , 1/*, wxGROW ); sizerGeneralOptionsC -> Add( new wxStaticText(panel,-1,_T(" Angle")) , 1, wxGROW ); sizerGeneralOptionsC -> Add( _sliderBullEyeAngle , 1/*, wxGROW ); sizerGeneralOptions -> Add( sizerGeneralOptionsA , 1/*, wxGROW ); sizerGeneralOptions -> Add( new wxStaticText(panel,-1,_T(" ")) , 1, wxGROW ); sizerGeneralOptions -> Add( sizerGeneralOptionsB , 1/*, wxGROW ); sizerGeneralOptions -> Add( new wxStaticText(panel,-1,_T(" ")) , 1, wxGROW ); sizerGeneralOptions -> Add( sizerGeneralOptionsC , 1/*, wxGROW ); wxSpinCtrl *tmpSpinSection; wxSlider *tmpSliderRadio; wxSlider *tmpSliderAng; wxFlexGridSizer * sizerDetailOptions = new wxFlexGridSizer(6); sizerDetailOptions -> Add( new wxStaticText(panel,-1,_T("Crown ")) , 1, wxGROW ); sizerDetailOptions -> Add( new wxStaticText(panel,-1,_T(" Sections ")) , 1, wxGROW ); sizerDetailOptions -> Add( new wxStaticText(panel,-1,_T(" ")) , 1, wxGROW ); sizerDetailOptions -> Add( new wxStaticText(panel,-1,_T(" Radio %")) , 1, wxGROW ); sizerDetailOptions -> Add( new wxStaticText(panel,-1,_T(" ")) , 1, wxGROW ); sizerDetailOptions -> Add( new wxStaticText(panel,-1,_T(" Angle")) , 1, wxGROW ); wxString tmpwxstring; int i; for (i=0;i<_maxLevels;i++){ tmpSpinSection = new wxSpinCtrl( panel , -1,_T(""),wxDefaultPosition, wxSize(40,20) ); tmpSliderRadio = new wxSlider( panel , -1 ,0,0,100, wxDefaultPosition, wxSize(110,35), wxSL_HORIZONTAL|wxSL_LABELS, wxDefaultValidator); tmpSliderAng = new wxSlider( panel , -1 ,0,0,180, wxDefaultPosition, wxSize(200,35), wxSL_HORIZONTAL|wxSL_LABELS, wxDefaultValidator); tmpSpinSection ->SetRange(1,_maxSections); tmpwxstring.Printf(_T(" %d. "),i+1); sizerDetailOptions -> Add( new wxStaticText(panel,-1,tmpwxstring) , 1, wxGROW ); sizerDetailOptions -> Add( tmpSpinSection, 1 ); sizerDetailOptions -> Add( new wxStaticText(panel,-1,_T(" ")) , 1, wxGROW ); sizerDetailOptions -> Add( tmpSliderRadio, 1, wxGROW ); sizerDetailOptions -> Add( new wxStaticText(panel,-1,_T(" ")) , 1, wxGROW ); sizerDetailOptions -> Add( tmpSliderAng, 1, wxGROW ); tmpSpinSection -> SetValue(5); tmpSliderRadio -> SetValue( 100-(double)((i)*100.0/_maxLevels) ); tmpSliderAng -> SetValue(0); Connect( tmpSliderRadio->GetId(), wxEVT_SCROLL_THUMBRELEASE , (wxObjectEventFunction) &PanelBullEyeOptions::onRefreshPanel ); Connect( tmpSliderRadio->GetId(), wxEVT_SCROLL_CHANGED , (wxObjectEventFunction) &PanelBullEyeOptions::onRefreshPanel ); _lstBullEyeDetailNumOfSec.push_back( tmpSpinSection ); _lstBullEyeDetailRadio.push_back( tmpSliderRadio ); _lstBullEyeDetailAngle.push_back( tmpSliderAng ); } //for wxFlexGridSizer * sizer = new wxFlexGridSizer(1); sizer -> Add( new wxStaticText(panel,-1,_T("")) , 1, wxGROW ); sizer -> Add( new wxStaticText(panel,-1,_T("")) , 1, wxGROW ); sizer -> Add( _radioboxBullEyeGenOpt , 1, wxGROW ); sizer -> Add( new wxStaticText(panel,-1,_T("")) , 1, wxGROW ); sizer -> Add( new wxStaticText(panel,-1,_T(" -- Bull Eye general options --")) , 1, wxGROW ); sizer -> Add( new wxStaticText(panel,-1,_T("")) , 1, wxGROW ); sizer -> Add( sizerGeneralOptions , 1, wxGROW ); sizer -> Add( new wxStaticText(panel,-1,_T("")) , 1, wxGROW ); sizer -> Add( new wxStaticText(panel,-1,_T("")) , 1, wxGROW ); sizer -> Add( new wxStaticText(panel,-1,_T(" -- Bull Eye detail options --")) , 1, wxGROW ); sizer -> Add( new wxStaticText(panel,-1,_T("")) , 1, wxGROW ); sizer -> Add( sizerDetailOptions , 1, wxGROW ); Connect( _radioboxBullEyeGenOpt->GetId(), wxEVT_COMMAND_RADIOBOX_SELECTED , (wxObjectEventFunction) &PanelBullEyeOptions::onRefreshPanel ); Connect( _spinctrlBullEyeNumOfCrowns->GetId(), wxEVT_COMMAND_TEXT_UPDATED , (wxObjectEventFunction) &PanelBullEyeOptions::onRefreshPanel ); panel->SetSizer( sizer ); panel->SetSize( sizepanel ); panel->SetAutoLayout( true ); panel->Layout(); RefreshPanel(); } //------------------------------------------------------------------------------------------------------------ PanelBullEyeOptions::~PanelBullEyeOptions() { } //------------------------------------------------------------------------------------------------------------ void PanelBullEyeOptions::onRefreshPanel( wxCommandEvent& event ) { RefreshPanel(); } //------------------------------------------------------------------------------------------------------------ void PanelBullEyeOptions::RefreshPanel() { int i; bool ok; if (this->_radioboxBullEyeGenOpt->GetSelection()==0){ for (i=0; i<_maxLevels; i++) { _lstBullEyeDetailNumOfSec[i] -> Enable(false); _lstBullEyeDetailRadio[i] -> Enable(false); _lstBullEyeDetailAngle[i] -> Enable(false); } // for } else { int spinSelec = _spinctrlBullEyeNumOfCrowns->GetValue(); for (i=0; i<_maxLevels; i++) { ok = (i < spinSelec); _lstBullEyeDetailNumOfSec[i] -> Enable(ok); _lstBullEyeDetailRadio[i] -> Enable(ok); _lstBullEyeDetailAngle[i] -> Enable(ok); if (i>0){ if (_lstBullEyeDetailRadio[i]->GetValue() > _lstBullEyeDetailRadio[i-1]->GetValue()) { _lstBullEyeDetailRadio[i]->SetValue( _lstBullEyeDetailRadio[i-1]->GetValue() ); } }// if i>0 } // for } // if } //------------------------------------------------------------------------------------------------------------ int PanelBullEyeOptions::GetNumberOfCrowns() { return this->_spinctrlBullEyeNumOfCrowns->GetValue(); } //------------------------------------------------------------------------------------------------------------ int PanelBullEyeOptions::GetNumberOfSections(int nCrown) { int result; if (this->_radioboxBullEyeGenOpt->GetSelection()==0) { result = this->_spinctrlBullEyeNumOfSec->GetValue(); } else { result = this->_lstBullEyeDetailNumOfSec[nCrown]->GetValue(); } return result; } //------------------------------------------------------------------------------------------------------------ int PanelBullEyeOptions::GetRadioOfCrown(int nCrown) { int result; double sizeCrowns; if (this->_radioboxBullEyeGenOpt->GetSelection()==0) { sizeCrowns = (double)( this->_spinctrlBullEyeNumOfCrowns->GetValue() ); result = 100.0 * (nCrown+1)/sizeCrowns ; } else { result = this->_lstBullEyeDetailRadio[nCrown]->GetValue(); } return result; } //------------------------------------------------------------------------------------------------------------ double PanelBullEyeOptions::GetAngOfCrownSection(int nCrown,int section) { double angle; if (this->_radioboxBullEyeGenOpt->GetSelection()==0) { angle = this->_sliderBullEyeAngle->GetValue(); } else { angle = this->_lstBullEyeDetailAngle[nCrown]->GetValue(); } double numOfSec = (double)GetNumberOfSections(nCrown); double deltaSec = GetAngDeltaOfCrownSection(nCrown); return angle + section*deltaSec ; } //------------------------------------------------------------------------------------------------------------ double PanelBullEyeOptions::GetAngDeltaOfCrownSection(int nCrown) { double numOfSec = (double)GetNumberOfSections(nCrown); return 360.0/numOfSec; } */ //------------------------------------------------------------------------------------------------------------ //------------------------------------------------------------------------------------------------------------ //------------------------------------------------------------------------------------------------------------ //------------------------------------------------------------------------------------------------------------ // Constructors & Destructors //------------------------------------------------------------------------------------------------------------ wxContourEventHandler ::wxContourEventHandler() :wxEvtHandler() { _creatingContoursActive = false; _theViewPanel = NULL; _modelManager = NULL; _instantPanel = NULL; _buttonsBar = NULL; _gridPanel = NULL; _drawToolsPanel = NULL; _operationsToolsPanel = NULL; _autoFormsPanel = NULL; _standardToolsPanel = NULL; _editionToolsPanel = NULL; _listViewPanel = NULL; _sceneManager = NULL; _actualInstant = NULL; _performingOperation = new PerformingOperation(); // EED Interface and Spread _spreadFrame = NULL; _segmentationFrame = NULL; _contourPropagation = NULL; _createContourFrame = NULL; _deleteFrame = NULL; _InformationContourFrame = NULL; _interfaceConfigurationFrame = NULL; _TestFrame = NULL; _wxtextctrlTest = NULL; _panelBullEyeOptions = NULL; fileNameContourROI = ""; _numberOfVariablesStatistics=6+1; inundo = 0; inredo = 0; stundoredo = "data/temp"; #if(WIN32) mkdir(stundoredo.c_str()); #else mkdir(stundoredo.c_str(),755); #endif stundoredo += "/cont"; } //------------------------------------------------------------------------------------------------------------ wxContourEventHandler :: ~ wxContourEventHandler() { delete _actualInstant; /*delete _theViewPanel; delete _instantPanel; delete _buttonsBar; delete _actualInstant; */ delete _sceneManager; delete _performingOperation; } //------------------------------------------------------------------------------------------------------------ // Configuration methods //------------------------------------------------------------------------------------------------------------ bool wxContourEventHandler :: configureEventsHandling() { bool configured = true; return configured; } //------------------------------------------------------------------------------------------------------------ // Methods for capturing events //------------------------------------------------------------------------------------------------------------ void wxContourEventHandler :: onProcessMessage( wxCommandEvent& event ) { } //------------------------------------------------------------------------------------------------------------ void wxContourEventHandler :: onActionButtonPressed( wxCommandEvent& event ) { const char buttonTool = *(char *)event.GetClientData(); executeActionCommand( buttonTool ); } //------------------------------------------------------------------------------------------------------------ void wxContourEventHandler :: onChangedDeep ( wxCommandEvent& event ) { double val = _theViewPanel->getCurrentDeep(); _instantPanel->setConceptValue( "Axe Depth", (int)val ); _theViewPanel->setActualVertical( (int)val ); changeInstant(); } //------------------------------------------------------------------------------------------------------------ void wxContourEventHandler :: onChangeInstant( wxCommandEvent& event ) { ConceptDataWrap * dataConcept = NULL; if ( _theViewPanel->GetId() == event.GetId() ) { dataConcept = (ConceptDataWrap *)event.GetClientData(); int value = dataConcept->getActualValue(); _instantPanel->setConceptValue( dataConcept->getName(), value ); } else { dataConcept = _instantPanel->getLastConceptData(); if( dataConcept->getName().compare( _theViewPanel->getVerticalConceptName() ) == 0) { _theViewPanel->setActualVertical( dataConcept->getActualValue()); //_theViewPanel->setVerticalConcept( dataConcept->getName(), dataConcept->getMinShowedValue()/*dataConcept->getMinValue()*/, /*dataConcept->getMaxValue()*/ dataConcept->getMaxShowedValue(), dataConcept->getMinShowedValue(), dataConcept->getMaxShowedValue(), dataConcept->getActualValue()); } else if( dataConcept->getName().compare( _theViewPanel->getHorizontalConceptName() ) == 0|| _instantPanel->getIfConceptCheckedAt( dataConcept->getName(), 0 ) ) { _theViewPanel->setHorizontalConcept( dataConcept->getName(), dataConcept->getMinShowedValue()/*dataConcept->getMinValue()*/, /*dataConcept->getMaxValue()*/ dataConcept->getMaxShowedValue(), dataConcept->getMinShowedValue(), dataConcept->getMaxShowedValue(), dataConcept->getActualValue()); } } changeInstant(); } //------------------------------------------------------------------------------------------------------------ void wxContourEventHandler :: onCreateMultipleROI( wxCommandEvent& event ) { _creatingContoursActive = !_creatingContoursActive; if( _creatingContoursActive ) { createContour(); } } //------------------------------------------------------------------------------------------------------------ void wxContourEventHandler :: onCreateROI( wxCommandEvent& event ) { if( _creatingContoursActive ) { createContour(); } } //------------------------------------------------------------------------------------------------------------ void wxContourEventHandler :: onStopCreateROI( wxCommandEvent& event ) { } //------------------------------------------------------------------------------------------------------------ void wxContourEventHandler :: onDeleterROI( wxCommandEvent& event ) { } //------------------------------------------------------------------------------------------------------------ void wxContourEventHandler :: onSelectROI( wxCommandEvent& event ) { } //------------------------------------------------------------------------------------------------------------ void wxContourEventHandler :: onUnSelectROI( wxCommandEvent& event ) { } //------------------------------------------------------------------------------------------------------------ void wxContourEventHandler :: onManualHidedROI( wxCommandEvent& event ) { } //------------------------------------------------------------------------------------------------------------ void wxContourEventHandler :: onManualShowedROI( wxCommandEvent& event ) { } //------------------------------------------------------------------------------------------------------------ void wxContourEventHandler :: onEditingROI( wxCommandEvent& event ) { } //------------------------------------------------------------------------------------------------------------ void wxContourEventHandler :: onMovingROI( wxCommandEvent& event ) { } //------------------------------------------------------------------------------------------------------------ // Model management methods //------------------------------------------------------------------------------------------------------------ void wxContourEventHandler::onSpreadReset( wxCommandEvent& event ) { _wxtextctrlSpread->SetValue(wxString("",wxConvUTF8)); _contourPropagation->resetAppend(); } //------------------------------------------------------------------------------------------------------------ void wxContourEventHandler::onSpreadAdd( wxCommandEvent& event ) { std::vector vecX; std::vector vecY; std::vector vecZ; _theViewPanel->getSceneManager()->GetPointsOfActualContour( &vecX , &vecY , &vecZ ); if (vecX.size()!=0){ std::vector tempVector; _instantPanel->getInstant( tempVector ); int i,size=vecZ.size(); int actualSlice = tempVector[1]; for ( i=0 ; iappendContour(&vecX , &vecY , &vecZ); wxString newstring; //newstring.Printf("%s %d -",_wxtextctrlSpread->GetValue(), actualSlice ); newstring.append(wxString(_wxtextctrlSpread->GetValue(),wxConvUTF8)); newstring.append(wxString(" ",wxConvUTF8)); newstring.append(wxString(intToString(actualSlice).c_str(),wxConvUTF8)); _wxtextctrlSpread->SetValue(newstring); } // if } //------------------------------------------------------------------------------------------------------------ void wxContourEventHandler::onSpreadGo( wxCommandEvent& event ) { //JCP 20-10-08 Undo redo implementation saveState(); //JCP 20-10-08 Undo redo implementation wxBusyCursor wait; int typeMethodFindCtrlPoints=_spreadMethodRadiobox->GetSelection(); int typeofcontour = 1; manualContourModel *manModelContour; std::vector vecCtrlPointX; std::vector vecCtrlPointY; std::vector vecCtrlPointZ; double minZ,maxZ; int z,j,sizeCtrPt; // double idTmp; int idTmp; std::vector tempVector; _instantPanel->getInstant( tempVector ); // tempVector[1]; _contourPropagation->getMaxMinZ(&minZ,&maxZ); //JSTG_16-07-08_---------------------------------------------------------------- //_contourPropagation->setInterpolationNumber(maxZ-minZ+1); _contourPropagation->setInterpolationNumber(100); _contourPropagation->CalculeSplinePropagation(); double totalZ = maxZ-minZ+1; double porcent; wxString tmpString; //-------------------------------------------------------------------- for ( z=(int)minZ ; z<=(int)maxZ ; z++ ) { porcent = 100.0* (z-minZ)/totalZ; int numero = (int)(z-minZ+1)/(int)totalZ; std::string stringtemp = " "+intToString(porcent)+"% "+intToString(numero)+" "+intToString(z); tmpString.Append(wxString(stringtemp.c_str(),wxConvUTF8)); //tmpString.Printf(" %d %c %d/%d %d", (int)porcent , 37 , (int)(z-minZ+1), (int)totalZ,z ); _staticTextSpread->SetLabel(tmpString); if (_contourPropagation->ifSliceKeyContourExist(z)==false) { manModelContour = factoryManualContourModel( typeofcontour ); idTmp = _contourPropagation->FindIdWithZ(z); if (typeMethodFindCtrlPoints==0) // Initial Points { _contourPropagation->GetInitialControlPoints( idTmp , &vecCtrlPointX,&vecCtrlPointY,&vecCtrlPointZ); } if (typeMethodFindCtrlPoints==1) // Automatique Method { _contourPropagation->GetControlPoints( idTmp ,&vecCtrlPointX,&vecCtrlPointY,&vecCtrlPointZ); } if (typeMethodFindCtrlPoints==2) // sampling { _contourPropagation->GetControlPoints( idTmp , 20.0 ,&vecCtrlPointX,&vecCtrlPointY,&vecCtrlPointZ); } //-------------------------------------------------------------------- sizeCtrPt = vecCtrlPointX.size(); for (j=0 ; jAddPoint( vecCtrlPointX[j] , vecCtrlPointY[j] , -900 ); //-------------------------------------------------------------------- } // for j tempVector[1]=z; std::string theName; theName = _modelManager->createOutline( manModelContour, tempVector ); bool addedModel = theName.compare("") != 0; if( addedModel ) { double spc[3];//Si no hay imagen pero hay contornos que spacing se pone por default this->_theViewPanel->getSpacing(spc); //Adding the manualContourControler to interface objects structure //Adding the manualViewContour to interface objects structure //_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. _theViewPanel->getSceneManager()->configureViewControlTo( theName, manModelContour,spc,typeofcontour ) ; } // if addedModel }// ifSliceKeyContourExist } // for z _staticTextSpread->SetLabel(wxString(" ",wxConvUTF8)); //RefreshInterface(); } //------------------------------------------------------------------------------------------------------------ void wxContourEventHandler :: onSpread( ) { if (_spreadFrame==NULL) { _spreadFrame = new wxFrame (_theViewPanel, -1,_T(" Spread "), wxDefaultPosition, wxDefaultSize, wxFRAME_TOOL_WINDOW|wxSYSTEM_MENU | wxCAPTION | wxCLIP_CHILDREN |wxFRAME_FLOAT_ON_PARENT ); wxSize sizepanel(250,400); _spreadFrame->SetSize( sizepanel ); _spreadFrame->SetEventHandler( this ); wxPanel *panel = getSpreadPanel(_spreadFrame); panel->SetSize(sizepanel); /**new wxPanel(_spreadFrame,-1); wxButton *spreadResetBtn = new wxButton(panel,-1,_T("Reset"),wxDefaultPosition, wxSize(80,35) ); wxButton *spreadAddBtn = new wxButton(panel,-1,_T("Add"),wxDefaultPosition, wxSize(80,35)); wxString lstOptions[3]; lstOptions[0]="A"; lstOptions[1]="B"; lstOptions[2]="C"; _spreadMethodRadiobox = new wxRadioBox(panel, -1, "Method (find ctrl. Points)", wxDefaultPosition, wxSize(200,45), 3 , lstOptions, 3, wxRA_SPECIFY_COLS); _spreadMethodRadiobox->SetSelection(2); wxButton *spreadGoBtn = new wxButton(panel,-1,_T("Go"),wxDefaultPosition, wxSize(80,35)); _staticTextSpread = new wxStaticText(panel,-1,_T(" ")); _wxtextctrlSpread = new wxTextCtrl(panel,-1, "",wxDefaultPosition, wxSize(200,150), wxTE_MULTILINE ); _spreadFrame->SetEventHandler( this ); Connect( spreadResetBtn->GetId(), wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &wxContourEventHandler::onSpreadReset ); Connect( spreadAddBtn->GetId(), wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &wxContourEventHandler::onSpreadAdd ); Connect( spreadGoBtn->GetId(), wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &wxContourEventHandler::onSpreadGo ); wxFlexGridSizer * sizer = new wxFlexGridSizer(1); sizer -> Add( spreadResetBtn , 1, wxGROW ); sizer -> Add( spreadAddBtn , 1, wxGROW ); sizer -> Add( _spreadMethodRadiobox , 1, wxGROW ); sizer -> Add( spreadGoBtn , 1, wxGROW ); sizer -> Add( _staticTextSpread , 1, wxGROW ); sizer -> Add( _wxtextctrlSpread , 1, wxGROW ); panel->SetSizer( sizer ); panel->SetSize( sizepanel ); panel->SetAutoLayout( true ); panel->Layout();**/ _spreadFrame->Show(); } else { if (_spreadFrame->IsShown()==true) { _spreadFrame->Show(false); } else { _spreadFrame->Show(true); } } } wxPanel* wxContourEventHandler::getSpreadPanel(wxWindow* parent){ //wxPanel *panel = new wxPanel(parent,-1); _contourPropagation = new ContourPropagation(); wxPanel *panel = new wxPanel(parent,-1,wxDefaultPosition, wxDefaultSize,wxNO_BORDER, wxString("",wxConvUTF8)); wxButton *spreadResetBtn = new wxButton(panel,-1,_T("Reset"),wxDefaultPosition, wxDefaultSize ); wxButton *spreadAddBtn = new wxButton(panel,-1,_T("Add"),wxDefaultPosition, wxDefaultSize); wxString lstOptions[3]; lstOptions[0]=_T("A"); lstOptions[1]=_T("B"); lstOptions[2]=_T("C"); _spreadMethodRadiobox = new wxRadioBox(panel, -1, _T("Method (find ctrl. Points)"), wxDefaultPosition, wxDefaultSize, 3 , lstOptions, 3, wxRA_SPECIFY_COLS); _spreadMethodRadiobox->SetSelection(2); wxButton *spreadGoBtn = new wxButton(panel,-1,_T("Go"),wxDefaultPosition, wxDefaultSize); _staticTextSpread = new wxStaticText(panel,-1,_T(" ")); _wxtextctrlSpread = new wxTextCtrl(panel,-1, _T(""),wxDefaultPosition, wxDefaultSize, wxTE_MULTILINE ); Connect( spreadResetBtn->GetId(), wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &wxContourEventHandler::onSpreadReset ); Connect( spreadAddBtn->GetId(), wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &wxContourEventHandler::onSpreadAdd ); Connect( spreadGoBtn->GetId(), wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &wxContourEventHandler::onSpreadGo ); wxFlexGridSizer * sizer = new wxFlexGridSizer(1); sizer -> Add( spreadResetBtn , 1, wxGROW ); sizer -> Add( spreadAddBtn , 1, wxGROW ); sizer -> Add( _spreadMethodRadiobox , 1, wxGROW ); sizer -> Add( spreadGoBtn , 1, wxGROW ); sizer -> Add( _staticTextSpread , 1, wxGROW ); sizer -> Add( _wxtextctrlSpread , 1, wxGROW ); panel->SetSizer( sizer ); //panel->SetSize( wxDefaultSize ); panel->SetAutoLayout( true ); panel->Layout(); return panel; } //------------------------------------------------------------------------------------------------------------ void wxContourEventHandler::onSegmentationAllSlice( wxCommandEvent& event ) { //JCP 20-10-08 Undo redo implementation saveState(); //JCP 20-10-08 Undo redo implementation wxBusyCursor wait; int x = this->_theViewPanel->GetX(); int y = this->_theViewPanel->GetY(); int z,minZ,maxZ; double porcent; wxString tmpString; minZ=_mbarrange->GetStart(); maxZ=_mbarrange->GetEnd(); double totalZ = maxZ-minZ+1; for( z=minZ ; z<=maxZ ; z++ ) { porcent = 100.0* (z-minZ)/totalZ; tmpString.Printf(_T(" %d %c %d/%d %d"), (int)porcent , 37 , z-minZ+1, (int)totalZ,z ); _staticTextSegmentation->SetLabel(tmpString); SegmentationOneSlice( x,y,z ); } _staticTextSegmentation->SetLabel(_T(" ")); RefreshInterface(); } //------------------------------------------------------------------------------------------------------------ void wxContourEventHandler::onSegmentationOneSlice( wxCommandEvent& event ) { //JCP 20-10-08 Undo redo implementation saveState(); //JCP 20-10-08 Undo redo implementation wxBusyCursor wait; int x = this->_theViewPanel->GetX(); int y = this->_theViewPanel->GetY(); int z = this->_theViewPanel->GetZ(); SegmentationOneSlice( x,y,z ); RefreshInterface(); } //------------------------------------------------------------------------------------------------------------ void wxContourEventHandler::SegmentationOneSlice( int x, int y, int z ) { int typeofcontour = 1; //--Extracting Contour vtkImageData *imagedata = _theViewPanel->getSceneManager()->GetImageData(); // double *range = imagedata->GetScalarRange(); // double thr = 1; int isovalue = _isovalue->GetValue(); int sampling = _sampling->GetValue(); vtkImageReslice *imageReslice = vtkImageReslice::New(); //EED // double spc[3]; // imagedata->GetSpacing(spc); // x = x*spc[0]; // y = y*spc[1]; // z = z*spc[3]; imageReslice->SetInput( imagedata ); imageReslice->SetInformationInput(imagedata); imageReslice->SetResliceAxesDirectionCosines(1,0,0, 0,1,0 ,0,0,1); imageReslice->SetResliceAxesOrigin(0,0,z); imageReslice->SetOutputDimensionality(2); imageReslice->SetInterpolationModeToLinear(); imagedata = imageReslice->GetOutput(); imagedata->Update(); imagedata->UpdateInformation(); vtkContourFilter* cntVTK = vtkContourFilter::New( ); cntVTK->SetInput( imagedata ); cntVTK->SetNumberOfContours( 1 ); //cntVTK->SetValue( 0, vmin ); // cntVTK->SetValue( 0, (range[1]*thr/100) ); cntVTK->SetValue( 1, isovalue ); // cntVTK->SetValue( 1, vmax ); cntVTK->Update( ); cntVTK->UpdateInformation(); vtkCleanPolyData* cpd = vtkCleanPolyData::New( ); cpd->SetInput( cntVTK->GetOutput( ) ); cpd->ConvertLinesToPointsOff( ); cpd->Update( ); cpd->UpdateInformation(); vtkPolyDataConnectivityFilter* conn = vtkPolyDataConnectivityFilter::New( ); conn->SetExtractionModeToClosestPointRegion( ); //conn->SetMaxRecursionDepth( 3000 ); conn->SetInput( cpd->GetOutput( ) ); conn->SetClosestPoint( x, y, 0 ); conn->Update( ); conn->UpdateInformation(); vtkCleanPolyData* cpd2 = vtkCleanPolyData::New( ); cpd2->SetInput( conn->GetOutput( ) ); cpd2->Update(); cpd2->UpdateInformation(); vtkStripper* vtkstripper = vtkStripper::New( ); vtkstripper->SetInput( cpd2->GetOutput() ); vtkstripper->Update(); vtkstripper->UpdateInformation(); vtkPolyData* polyDataResult = vtkstripper->GetOutput(); polyDataResult->Update( ); polyDataResult->UpdateInformation(); /* EED ofstream myfile; myfile.open ("c:/temp/example.txt"); myfile << "\n"; polyDataResult->Print(myfile); myfile << "-------------------------------------\n"; polyDataResult->GetLines()->Print(myfile); myfile.close(); */ cntVTK -> Delete(); cpd2 -> Delete(); cpd -> Delete(); conn -> Delete(); //--Calculating control points std::vector vecX; std::vector vecY; std::vector vecZ; std::vector vecCtrlPointX; std::vector vecCtrlPointY; std::vector vecCtrlPointZ; double *p; int ii,size=polyDataResult->GetNumberOfPoints(); int id; for (ii=1;ii<=size;ii++) { id = polyDataResult->GetLines()->GetData()->GetValue(ii); p = polyDataResult->GetPoint(id); double x=p[0]; double y=p[1]; vecX.push_back( p[0] ); vecY.push_back( p[1] ); vecZ.push_back( -900 ); // vecZ.push_back( p[2] ); } ExtractControlPoints2D *extractcontrolpoints2d = new ExtractControlPoints2D(); extractcontrolpoints2d->SetContour( &vecX , &vecY , &vecZ ); //PROOFS if (methodRadiobox->GetSelection()==0){ extractcontrolpoints2d->GetInitialControlPoints( &vecCtrlPointX , &vecCtrlPointY , &vecCtrlPointZ ); } if (methodRadiobox->GetSelection()==1){ extractcontrolpoints2d->GetControlPoints( &vecCtrlPointX , &vecCtrlPointY , &vecCtrlPointZ ); } if (methodRadiobox->GetSelection()==2){ extractcontrolpoints2d->SetSamplingControlPoints( sampling ); extractcontrolpoints2d->GetSamplingControlPoints( &vecCtrlPointX , &vecCtrlPointY , &vecCtrlPointZ ); } //--Adding contour to the system std::vector actualInstantVector; _instantPanel->getInstant( actualInstantVector ); actualInstantVector[1]=z; int j,sizeCtrPt = vecCtrlPointX.size(); manualContourModel *manModelContour = factoryManualContourModel( typeofcontour ); manModelContour->SetNumberOfPointsSpline( ((sizeCtrPt/100)+1)*100 ); if (sizeCtrPt>=3){ for (j=0 ; jAddPoint( vecCtrlPointX[j] , vecCtrlPointY[j] , vecCtrlPointZ[j] ); } // for std::string theName; theName = _modelManager->createOutline( manModelContour, actualInstantVector ); bool addedModel = theName.compare("") != 0; if( addedModel ) { double spc[3];//Si no hay imagen pero hay contornos que spacing se pone por default this->_theViewPanel->getSpacing(spc); //Adding the manualContourControler to interface objects structure //Adding the manualViewContour to interface objects structure //_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. _theViewPanel->getSceneManager()->configureViewControlTo( theName, manModelContour,spc, typeofcontour ) ; } // if addedModel } // if sizeCtrPt } //------------------------------------------------------------------------------------------------------------ void wxContourEventHandler :: onAutomatiqueSegmentation( ) { if (_segmentationFrame==NULL) { //JCP 13-10-09 /*int sizeZ = _theViewPanel->getSceneManager()->GetImageDataSizeZ(); double range[2]; _theViewPanel->getSceneManager()->GetImageDataRange(range);*/ //JCP 13-10-09 wxSize sizePanel( 300, 470); _segmentationFrame = new wxFrame (_theViewPanel, -1,_T(" Segmentation "), wxDefaultPosition, wxDefaultSize, wxFRAME_TOOL_WINDOW|wxSYSTEM_MENU | wxCAPTION | wxCLIP_CHILDREN |wxFRAME_FLOAT_ON_PARENT ); _segmentationFrame->SetSize( sizePanel ); wxPanel *panel = getSegmentationPanel(_segmentationFrame); /*new wxPanel(_segmentationFrame,-1); wxButton *segmentationOneSliceBtn = new wxButton(panel,-1,_T("Actual slice"), wxDefaultPosition, wxSize(200,35) ); wxButton *segmentationAllSliceBtn = new wxButton(panel,-1,_T("All slices") ,wxDefaultPosition, wxSize(200,35) ); _isovalue = new wxSlider(panel, -1, 40 , (int)(range[0]), (int)(range[1]), wxDefaultPosition, wxSize(200,35), wxSL_HORIZONTAL|wxSL_LABELS, wxDefaultValidator); _sampling = new wxSlider(panel, -1, 20 , 4, 50, wxDefaultPosition, wxSize(200,35), wxSL_HORIZONTAL|wxSL_LABELS, wxDefaultValidator); wxString lstOptions[3]; lstOptions[0]="A"; lstOptions[1]="B"; lstOptions[2]="C"; methodRadiobox = new wxRadioBox(panel, -1, "Method (find ctrl. Points)", wxDefaultPosition, wxSize(200,45), 3 , lstOptions, 3, wxRA_SPECIFY_COLS); methodRadiobox->SetSelection(2); _staticTextSegmentation = new wxStaticText(panel,-1,_T(" ")); _mbarrange = new mBarRange(panel,70, 65); _mbarrange->SetMin(0); _mbarrange->SetStart(0); _mbarrange-> SetOrientation( true ); _mbarrange-> setActiveStateTo(true); _mbarrange-> setVisibleLabels( true ); _mbarrange-> setDeviceEndMargin(10); _mbarrange-> setRepresentedValues( 0 , sizeZ ); _mbarrange-> setDeviceBlitStart(10,10); _mbarrange-> setIfWithActualDrawed( false ); _mbarrange-> SetStart( 0 ); _mbarrange-> SetEnd( sizeZ ); // _segmentationFrame->SetEventHandler( this ); segmentationOneSliceBtn->SetEventHandler( this ); segmentationAllSliceBtn->SetEventHandler( this ); Connect( segmentationOneSliceBtn->GetId(), wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &wxContourEventHandler::onSegmentationOneSlice ); Connect( segmentationAllSliceBtn->GetId(), wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &wxContourEventHandler::onSegmentationAllSlice ); wxFlexGridSizer * sizer = new wxFlexGridSizer(1); sizer -> Add( new wxStaticText(panel,-1,_T("Isovalue (Gray level)")) , 1, wxGROW ); sizer -> Add( _isovalue , 1, wxGROW ); sizer -> Add( methodRadiobox , 1, wxGROW ); sizer -> Add( new wxStaticText(panel,-1,_T("Sampling (%)")) , 1, wxGROW ); sizer -> Add( _sampling , 1, wxGROW ); sizer -> Add( segmentationOneSliceBtn , 1, wxGROW ); sizer -> Add( new wxStaticText(panel,-1,_T(" ")) , 1, wxGROW ); sizer -> Add( _staticTextSegmentation , 1, wxGROW ); sizer -> Add( segmentationAllSliceBtn , 1, wxGROW ); sizer -> Add( _mbarrange , 1, wxGROW ); panel->SetSizer( sizer ); panel->SetSize( sizePanel ); panel->SetAutoLayout( true ); panel->Layout();*/ this->_theViewPanel->SetVisibleAxis(true); this->_theViewPanel->Refresh(); _segmentationFrame->Show(true); //JCP 13-10-09 View the method getSegmentationPanel(), this two methods where moved to getSegmentationPanel //this->_theViewPanel->SetVisibleAxis(true); //this->_theViewPanel->Refresh(); } else { if (_segmentationFrame->IsShown()==true) { _segmentationFrame->Show(false); this->_theViewPanel->SetVisibleAxis(false); this->_theViewPanel->Refresh(); } else { _segmentationFrame->Show(true); this->_theViewPanel->SetVisibleAxis(true); this->_theViewPanel->Refresh(); } } } void wxContourEventHandler::showAxis(bool show){ this->_theViewPanel->SetVisibleAxis(show); this->_theViewPanel->Refresh(); } wxPanel* wxContourEventHandler::getSegmentationPanel(wxWindow* parent){ int sizeZ = _theViewPanel->getSceneManager()->GetImageDataSizeZ(); double range[2]; _theViewPanel->getSceneManager()->GetImageDataRange(range); wxPanel *panel = new wxPanel(parent,-1); wxButton *segmentationOneSliceBtn = new wxButton(panel,-1,_T("Actual slice"), wxDefaultPosition, wxSize(200,35) ); wxButton *segmentationAllSliceBtn = new wxButton(panel,-1,_T("All slices") ,wxDefaultPosition, wxSize(200,35) ); _isovalue = new wxSlider(panel, -1, 40 , (int)(range[0]), (int)(range[1]), wxDefaultPosition, wxSize(200,35), wxSL_HORIZONTAL|wxSL_LABELS, wxDefaultValidator); _sampling = new wxSlider(panel, -1, 20 , 4, 50, wxDefaultPosition, wxSize(200,35), wxSL_HORIZONTAL|wxSL_LABELS, wxDefaultValidator); wxString lstOptions[3]; lstOptions[0]=_T("A"); lstOptions[1]=_T("B"); lstOptions[2]=_T("C"); methodRadiobox = new wxRadioBox(panel, -1, _T("Method (find ctrl. Points)"), wxDefaultPosition, wxSize(200,45), 3 , lstOptions, 3, wxRA_SPECIFY_COLS); methodRadiobox->SetSelection(2); _staticTextSegmentation = new wxStaticText(panel,-1,_T(" ")); _mbarrange = new mBarRange(panel,70, 65); _mbarrange->SetMin(0); _mbarrange->SetStart(0); _mbarrange-> SetOrientation( true ); _mbarrange-> setActiveStateTo(true); _mbarrange-> setVisibleLabels( true ); _mbarrange-> setDeviceEndMargin(10); _mbarrange-> setRepresentedValues( 0 , sizeZ ); _mbarrange-> setDeviceBlitStart(10,10); _mbarrange-> setIfWithActualDrawed( false ); _mbarrange-> SetStart( 0 ); _mbarrange-> SetEnd( sizeZ ); // _segmentationFrame->SetEventHandler( this ); segmentationOneSliceBtn->SetEventHandler( this ); segmentationAllSliceBtn->SetEventHandler( this ); Connect( segmentationOneSliceBtn->GetId(), wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &wxContourEventHandler::onSegmentationOneSlice ); Connect( segmentationAllSliceBtn->GetId(), wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &wxContourEventHandler::onSegmentationAllSlice ); wxFlexGridSizer * sizer = new wxFlexGridSizer(1); sizer -> Add( new wxStaticText(panel,-1,_T("Isovalue (Gray level)")) , 1, wxGROW ); sizer -> Add( _isovalue , 1, wxGROW ); sizer -> Add( methodRadiobox , 1, wxGROW ); sizer -> Add( new wxStaticText(panel,-1,_T("Sampling (%)")) , 1, wxGROW ); sizer -> Add( _sampling , 1, wxGROW ); sizer -> Add( segmentationOneSliceBtn , 1, wxGROW ); sizer -> Add( new wxStaticText(panel,-1,_T(" ")) , 1, wxGROW ); sizer -> Add( _staticTextSegmentation , 1, wxGROW ); sizer -> Add( segmentationAllSliceBtn , 1, wxGROW ); sizer -> Add( _mbarrange , 1, wxGROW ); panel->SetSizer( sizer ); // panel->SetSize( sizePanel ); panel->SetSize( wxDefaultSize ); panel->SetAutoLayout( true ); panel->Layout(); return panel; } void wxContourEventHandler :: onInterfaceTestFrame( ) { if (_TestFrame==NULL) { _contourPropagation = new ContourPropagation(); _TestFrame = new wxFrame (_theViewPanel, -1,_T(" Test Segmentation "), wxDefaultPosition, wxDefaultSize, wxFRAME_TOOL_WINDOW|wxSYSTEM_MENU | wxCAPTION | wxCLIP_CHILDREN |wxFRAME_FLOAT_ON_PARENT ); wxSize sizepanel(200,300); _TestFrame->SetSize( sizepanel ); wxPanel *panel = new wxPanel(_TestFrame,-1); wxButton *spreadResetBtn = new wxButton(panel,-1,_T("Reset"),wxDefaultPosition, wxSize(80,35) ); wxButton *spreadAddBtn = new wxButton(panel,-1,_T("Add"),wxDefaultPosition, wxSize(80,35)); wxButton *spreadGoBtn = new wxButton(panel,-1,_T("GoA"),wxDefaultPosition, wxSize(80,35)); _wxtextctrlTest = new wxTextCtrl(panel,-1, _T(""),wxDefaultPosition, wxSize(200,150), wxTE_MULTILINE ); _TestFrame->SetEventHandler( this ); Connect( spreadResetBtn->GetId(), wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &wxContourEventHandler::onTestReset ); Connect( spreadAddBtn->GetId(), wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &wxContourEventHandler::onTestAdd ); Connect( spreadGoBtn->GetId(), wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &wxContourEventHandler::onTestGo ); wxFlexGridSizer * sizer = new wxFlexGridSizer(1); sizer -> Add( spreadResetBtn , 1, wxGROW ); sizer -> Add( spreadAddBtn , 1, wxGROW ); sizer -> Add( spreadGoBtn , 1, wxGROW ); sizer -> Add( _wxtextctrlTest , 1, wxGROW ); panel->SetSizer( sizer ); panel->SetSize( sizepanel ); panel->SetAutoLayout( true ); panel->Layout(); _TestFrame->Show(); } else { if (_TestFrame->IsShown()==true) { _TestFrame->Show(false); } else { _TestFrame->Show(true); } } } void wxContourEventHandler::onTestReset( wxCommandEvent& event ) { _wxtextctrlTest->SetValue(_T("")); _contourPropagation->resetAppend(); } //------------------------------------------------------------------------------------------------------------ void wxContourEventHandler::onTestAdd( wxCommandEvent& event ) { std::vector vecX; std::vector vecY; std::vector vecZ; _theViewPanel->getSceneManager()->GetPointsOfActualContour( &vecX , &vecY , &vecZ ); if (vecX.size()!=0){ std::vector tempVector; _instantPanel->getInstant( tempVector ); int i,size=vecZ.size(); int actualSlice = tempVector[1]; for ( i=0 ; iappendContour(&vecX , &vecY , &vecZ); wxString newstring; newstring.append(_wxtextctrlTest->GetValue()); newstring.append(_T(" ")); newstring.append(wxString(intToString(actualSlice).c_str(),wxConvUTF8)); //newstring.Printf(_T("%s %d -"),, ); newstring.append(_T(" -")); _wxtextctrlTest->SetValue(newstring); } // if } //------------------------------------------------------------------------------------------------------------ void wxContourEventHandler::onTestGo( wxCommandEvent& event ) { std::vector vecX; std::vector vecY; std::vector vecZ; std::vector size; std::vector vecCtrlPointX; std::vector vecCtrlPointY; std::vector vecCtrlPointZ; //Getting the points of the actual contour _contourPropagation->GetKeyContours(&vecX , &vecY , &vecZ, &size); for(int i = 0; i < vecX.size();i++){ vecZ[i] = -900; } /*std::vector vecX1; std::vector vecY1; std::vector vecZ1; _theViewPanel->getSceneManager()->GetPointsOfActualContour( &vecX1 , &vecY1 , &vecZ1 ); std::ofstream file1; file1.open( "Temp.txt" ); if(file1.is_open()) { for(int i = 0; i < vecX.size(); i++){ file1<SetContour( &vecX , &vecY , &vecZ ); //Getting the control points of the contour by method A extractcontrolpoints2d->GetInitialControlPoints( &vecCtrlPointX , &vecCtrlPointY , &vecCtrlPointZ ); std::vector actualInstantVector; _instantPanel->getInstant( actualInstantVector ); actualInstantVector[1]= this->_theViewPanel->GetZ(); //Adding the Contour to the scene manualContourModel *manModelContour = new manualContourModel(); int j,sizeCtrPt = vecCtrlPointX.size(); if (sizeCtrPt>=3){ for (j=0 ; jAddPoint( vecCtrlPointX[j] , vecCtrlPointY[j] , vecCtrlPointZ[j] ); } // for std::string theName; theName = _modelManager->createOutline( manModelContour, actualInstantVector ); bool addedModel = theName.compare("") != 0; if( addedModel ) { double spc[3];//Si no hay imagen pero hay contornos que spacing se pone por default this->_theViewPanel->getSpacing(spc); //Adding the manualContourControler to interface objects structure //Adding the manualViewContour to interface objects structure //_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. _theViewPanel->getSceneManager()->configureViewControlTo( theName, manModelContour,spc,1 ) ; } // if addedModel } // if sizeCtrPt } //------------------------------------------------------------------------------------------------------------ void wxContourEventHandler::FillGridWithContoursInformation() { wxString tempString; _grid->ClearGrid(); _grid->SetColLabelValue(0, _T("A") ); _grid->SetColLabelValue(1, _T("B") ); _grid->SetColLabelValue(2, _T("C") ); _grid->SetColLabelValue(3, _T("D") ); _grid->SetColLabelValue(4, _T("E") ); _grid->SetColLabelValue(5, _T("F") ); std::vector tempVector; _instantPanel->getInstant( tempVector ); int z,sizeZ = _theViewPanel->getSceneManager()->GetImageDataSizeZ(); int ii,sizeLstContourThings; for ( z=0 ; z lstContourThings = this->_modelManager->getOutlinesAtInstant( &instant ); sizeLstContourThings = lstContourThings.size(); tempString.Printf(_T("%d - %d"),z, sizeLstContourThings); _grid->SetRowLabelValue(z, tempString ); for (ii=0 ; iigetName().c_str(),wxConvUTF8) ; _grid->SetCellValue( z, ii, tempString ); } } } //------------------------------------------------------------------------------------------------------------ std::vector wxContourEventHandler::ExploseEachModel( std::vector lstManConMod ) { std::vector lstTmp; std::vector lstResult; int j,jSize; int i,iSize=lstManConMod.size(); for (i=0;iExploseModel(); jSize=lstTmp.size(); for (j=0;jClearGrid(); ContourExtractData *contourextractdata = new ContourExtractData(); int typeContourGroup = this->_radiolstboxContourGroup->GetSelection(); contourextractdata ->SetTypeOperation( typeContourGroup % 3 ); std::vector lstManConMod; std::vector lstManConModTmp; std::vector lstManConModExp; std::vector pLstValue; std::vector pLstValuePosX; std::vector pLstValuePosY; std::vector pLstValuePosZ; int resultSize; int resultGrayRangeCount; double resultMin; double resultMax; double resultAverage; double resultStandardeviation; std::vector tempVector; _instantPanel->getInstant( tempVector ); vtkImageData *imagedata = _theViewPanel->getSceneManager()->GetImageData(); int sizeZ = _theViewPanel->getSceneManager()->GetImageDataSizeZ(); int z; int ii,sizeLstContourThings; int minZ,maxZ; double totalZ; double porcent; wxString tmpString; if (_informationRadiobox->GetSelection()==0 ) // actual slice { std::vector tempVector; _instantPanel->getInstant( tempVector ); int actualSlice = tempVector[1]; minZ = actualSlice; maxZ = actualSlice; } if (_informationRadiobox->GetSelection()==1 ) // slice range { minZ = _mbarrangeSliceInformation->GetStart(); maxZ = _mbarrangeSliceInformation->GetEnd(); } if (_informationRadiobox->GetSelection()==2 ) // All slices { minZ = 0; maxZ = sizeZ-1; } totalZ = maxZ-minZ+1; contourextractdata->SetImage( imagedata); // For each slice.. for ( z=minZ ; z<=maxZ ; z++ ) { porcent = 100.0* (z-minZ)/totalZ; tmpString.Printf(_T(" %d %c %d/%d %d"), (int)porcent , 37 , z-minZ+1, (int)totalZ ,z); _staticTextInformation->SetLabel(tmpString); //Extraction data from contours of each slice contourextractdata->SetZtoBeAnalys( z); tempVector[1]=z; Instant instant(&tempVector); std::vector lstContourThings = this->_modelManager->getOutlinesAtInstant( &instant ); sizeLstContourThings = lstContourThings.size(); lstManConMod.clear(); for (ii=0 ; iigetModel() ); } lstManConModExp = ExploseEachModel( lstManConMod ); wxString tempString; tempString.Printf(_T("%d - %d"),z, sizeLstContourThings); _grid->SetRowLabelValue(z, tempString ); //EED004 int iContourGroup,sizeContourGroup; if (typeContourGroup==3) // contour separete { sizeContourGroup=lstManConModExp.size(); if ( maxContourGroupSetLstManualContourModel( lstManConModTmp ); pLstValue.clear(); pLstValuePosX.clear(); pLstValuePosY.clear(); pLstValuePosZ.clear(); contourextractdata->GetValuesInsideCrown( &pLstValue, &pLstValuePosX, &pLstValuePosY, &pLstValuePosZ); // Statistics of each slice. contourextractdata->Statistics( &pLstValue, _mbarrangeRangeInformation->GetStart(), _mbarrangeRangeInformation->GetEnd(), &resultGrayRangeCount, &resultSize, &resultMin, &resultMax, &resultAverage, &resultStandardeviation); if (_grid->GetNumberCols()<_numberOfVariablesStatistics*(iContourGroup+1) ) { _grid->AppendCols(_numberOfVariablesStatistics); } tmpIntA=_numberOfVariablesStatistics*iContourGroup ; tempString.Printf(_T("%d"),resultSize); _grid->SetCellValue( z, tmpIntA + 0, tempString ); tempString.Printf(_T("%d"),resultGrayRangeCount); _grid->SetCellValue( z, tmpIntA + 1, tempString ); tempString.Printf(_T("%f"),resultMin); _grid->SetCellValue( z, tmpIntA + 2, tempString ); tempString.Printf(_T("%f"),resultMax); _grid->SetCellValue( z, tmpIntA + 3, tempString ); tempString.Printf(_T("%f"),resultAverage); _grid->SetCellValue( z, tmpIntA + 4, tempString ); tempString.Printf(_T("%f"),resultStandardeviation); _grid->SetCellValue( z, tmpIntA + 5, tempString ); } // for iContourGroup } // for z int iTitleGroup; wxString tmpTitleString; int tmpIntB; for ( iTitleGroup=0 ; iTitleGroupSetColLabelValue( tmpIntB + 0, tmpTitleString ); _grid->SetColLabelValue( tmpIntB + 1, _T("Size Range") ); _grid->SetColLabelValue( tmpIntB + 2, _T("Min") ); _grid->SetColLabelValue( tmpIntB + 3, _T("Max") ); _grid->SetColLabelValue( tmpIntB + 4, _T("Average") ); _grid->SetColLabelValue( tmpIntB + 5, _T("St.Dev.") ); _grid->SetColLabelValue( tmpIntB + 6, _T(" ") ); } _staticTextInformation->SetLabel( _T("") ); delete contourextractdata; } //------------------------------------------------------------------------------------------------------------ void wxContourEventHandler::SaveValuesXYZ(std::string directory,std::string namefile) { wxBusyCursor wait; ContourExtractData *contourextractdata = new ContourExtractData(); int typeContourGroup = this->_radiolstboxContourGroup->GetSelection(); contourextractdata ->SetTypeOperation( typeContourGroup % 3 ); std::vector lstManConMod; std::vector lstManConModTmp; std::vector lstManConModExp; std::vector pLstValue; std::vector pLstValuePosX; std::vector pLstValuePosY; std::vector pLstValuePosZ; std::vector tempVector; _instantPanel->getInstant( tempVector ); vtkImageData *imagedata = _theViewPanel->getSceneManager()->GetImageData(); int sizeZ = _theViewPanel->getSceneManager()->GetImageDataSizeZ(); int z; int ii,sizeLstContourThings; int minZ,maxZ; double totalZ; double porcent; wxString tmpString; minZ = 0;// _mbarrange->GetStart(); maxZ = sizeZ;//_mbarrange->GetEnd(); totalZ = maxZ-minZ+1; contourextractdata->SetImage( imagedata); // For each slice.. for ( z=0 ; zSetLabel(tmpString); //Extraction data from contours of each slice contourextractdata->SetZtoBeAnalys( z); tempVector[1]=z; Instant instant(&tempVector); std::vector lstContourThings = this->_modelManager->getOutlinesAtInstant( &instant ); sizeLstContourThings = lstContourThings.size(); lstManConMod.clear(); for (ii=0 ; iigetModel() ); } lstManConModExp = ExploseEachModel( lstManConMod ); //EED004 int iContourGroup,sizeContourGroup; if (typeContourGroup==3) // contour separete { sizeContourGroup=lstManConModExp.size(); } else { // contour AND OR XOR sizeContourGroup=1; } for( iContourGroup=0 ; iContourGroupSetLstManualContourModel( lstManConModTmp ); pLstValue.clear(); pLstValuePosX.clear(); pLstValuePosY.clear(); pLstValuePosZ.clear(); contourextractdata->GetValuesInsideCrown( &pLstValue, &pLstValuePosX, &pLstValuePosY, &pLstValuePosZ); wxString filename; filename.Printf(_T("%s"),directory.c_str()); filename.Printf(_T("\\")); filename.Printf(_T("%s"),namefile.c_str()); filename.Printf(_T("-slice")); filename.Printf(_T("%d"),z); filename.Printf(_T("-cont")); filename.Printf(_T("%d"),iContourGroup); filename.Printf(_T(".txt")); FILE *pFile=fopen((const char *)filename.mb_str(),"w+"); fprintf(pFile,"value \t x \t y \t z\n" ); int iLstValue,sizeLstValue=pLstValue.size(); for (iLstValue=0 ; iLstValueSetLabel( _T("") ); delete contourextractdata; } //------------------------------------------------------------------------------------------------------------ void wxContourEventHandler::SaveImageResult(std::string directory,std::string namefile) { wxBusyCursor wait; ContourExtractData *contourextractdata = new ContourExtractData( true ); int typeContourGroup = this->_radiolstboxContourGroup->GetSelection(); if (typeContourGroup==3) { typeContourGroup=1; } contourextractdata ->SetTypeOperation( typeContourGroup % 3 ); std::vector lstManConMod; std::vector lstManConModTmp; std::vector lstManConModExp; std::vector tempVector; _instantPanel->getInstant( tempVector ); vtkImageData *imagedata = _theViewPanel->getSceneManager()->GetImageData(); int sizeZ = _theViewPanel->getSceneManager()->GetImageDataSizeZ(); int z; int ii,sizeLstContourThings; int minZ,maxZ; double totalZ; double porcent; wxString tmpString; minZ = 0;// _mbarrange->GetStart(); maxZ = sizeZ;//_mbarrange->GetEnd(); totalZ = maxZ-minZ+1; contourextractdata->SetImage( imagedata); // For each slice.. for ( z=0 ; zSetLabel(tmpString); //Extraction data from contours of each slice contourextractdata->SetZtoBeAnalys( z); tempVector[1]=z; Instant instant(&tempVector); std::vector lstContourThings = this->_modelManager->getOutlinesAtInstant( &instant ); sizeLstContourThings = lstContourThings.size(); lstManConMod.clear(); for (ii=0 ; iigetModel() ); } lstManConModExp = ExploseEachModel( lstManConMod ); int iContourGroup,sizeContourGroup; if (typeContourGroup==3) // contour separete { sizeContourGroup=lstManConModExp.size(); } else { // contour AND OR XOR sizeContourGroup=1; } for( iContourGroup=0 ; iContourGroupSetLstManualContourModel( lstManConModTmp ); // for (ii=0 ; iigetModel() ); // } // contourextractdata->SetLstManualContourModel( lstManConMod ); contourextractdata->CalculateImageResult(); // with actual Z } // for iContourGroup } // for z wxString filename; //filename.Printf(_T("%s\\%s-Value.mhd",directory.c_str(),namefile.c_str(),z); filename.Printf(_T("%s"),directory.c_str()); filename.Printf(_T("\\")); filename.Printf(_T("%s"),namefile.c_str()); filename.Printf(_T("-Value.mhd")); // Image Value vtkMetaImageWriter *writerValueImage = vtkMetaImageWriter::New( ); writerValueImage->SetInput( contourextractdata->GetVtkImageValueResult() ); writerValueImage->SetFileName( (const char *)filename.mb_str() ); writerValueImage->SetFileDimensionality( 3 ); writerValueImage->Write( ); // Image Mask // filename.Printf("%s\\%s-Mask.mhd",directory.c_str(),namefile.c_str(),z); filename.Printf(_T("%s"),directory.c_str()); filename.Printf(_T("\\")); filename.Printf(_T("%s"),namefile.c_str()); filename.Printf(_T("-Mask.mhd")); vtkMetaImageWriter *writerMaskImage = vtkMetaImageWriter::New( ); writerMaskImage->SetInput( contourextractdata->GetVtkImageMaskResult() ); writerMaskImage->SetFileName( (const char *)filename.mb_str() ); writerMaskImage->SetFileDimensionality( 3 ); writerMaskImage->Write( ); _staticTextInformation->SetLabel( _T("") ); delete contourextractdata; } //------------------------------------------------------------------------------------------------------------ void wxContourEventHandler::onInformationContourLabels( wxCommandEvent& event ) { wxBusyCursor wait; FillGridWithContoursInformation(); } //------------------------------------------------------------------------------------------------------------ void wxContourEventHandler::onSaveResults( wxCommandEvent& event ) { wxFileDialog dialog(_InformationContourFrame, _T("Choose a file"), _T(""), _T(""), _T("*.txt"), wxSAVE ); if (dialog.ShowModal() == wxID_OK) { onExtractInformation( event ); std::string directory=(const char *)(dialog.GetDirectory().mb_str()); std::string namefile=(const char *)(dialog.GetFilename().mb_str()); SaveValuesXYZ( directory , namefile ); SaveImageResult( directory , namefile ); std::string filename = (const char *)(dialog.GetPath().mb_str() ); FILE *pFile=fopen(filename.c_str(),"w+"); int sizeZ = _theViewPanel->getSceneManager()->GetImageDataSizeZ(); wxString tmpString; int i,j,maxX,maxY=sizeZ; maxX=this->_grid->GetNumberCols(); int iTitle,sizeTitle = (maxX / _numberOfVariablesStatistics); for ( iTitle=0; iTitleGetCellValue( j , i ); fprintf(pFile,"%s\t" , (const char *)(tmpString.mb_str()) ); } // for i fprintf(pFile,"\n" ); } // for j fclose(pFile); } // if ShowModal } //------------------------------------------------------------------------------------------------------------ void wxContourEventHandler::onInformationContourFrame() { if (_InformationContourFrame==NULL) { _InformationContourFrame = new wxFrame (_theViewPanel, -1,_T(" Information "), wxDefaultPosition, wxDefaultSize, wxFRAME_TOOL_WINDOW|wxSYSTEM_MENU | wxCAPTION | wxCLIP_CHILDREN |wxFRAME_FLOAT_ON_PARENT | wxRESIZE_BORDER ); _InformationContourFrame->SetSize( wxSize(500,450) ); wxSize sizepanel(200,300); wxPanel *panel = getInformationPanel(_InformationContourFrame); //JCP 13-10-09 Grouping the panel in a method /*new wxPanel(_InformationContourFrame,-1,wxDefaultPosition, wxDefaultSize,wxTAB_TRAVERSAL); wxString lstOptions[4]; lstOptions[0]=_T("Actual Slice"); lstOptions[1]=_T("Range Slices"); lstOptions[2]=_T("All Slices"); _informationRadiobox = new wxRadioBox(panel, -1, _T("Slice analysis"), wxDefaultPosition, wxSize(270,45), 3 , lstOptions, 3, wxRA_SPECIFY_COLS); wxString lstOptContOperation[5]; lstOptContOperation[0]=_T("AND"); lstOptContOperation[1]=_T("OR"); lstOptContOperation[2]=_T("XOR"); lstOptContOperation[3]=_T("ALL"); _radiolstboxContourGroup = new wxRadioBox(panel, -1, _T("Contour group"), wxDefaultPosition, wxSize(270,45), 4 , lstOptContOperation, 4, wxRA_SPECIFY_COLS); wxButton *informationContourLabelsBtn = new wxButton(panel,-1,_T("Contour labels"),wxDefaultPosition, wxSize(140,35) ); informationContourLabelsBtn->SetEventHandler( this ); Connect( informationContourLabelsBtn->GetId(), wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &wxContourEventHandler::onInformationContourLabels ); wxButton *statisticsContourBtn = new wxButton(panel,-1,_T("Contour statistics"),wxDefaultPosition, wxSize(140,35) ); statisticsContourBtn->SetEventHandler( this ); Connect( statisticsContourBtn->GetId(), wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &wxContourEventHandler::onExtractInformation ); wxButton *saveResultsBtn = new wxButton(panel,-1,_T("Save statistics results"),wxDefaultPosition, wxSize(140,35) ); saveResultsBtn->SetEventHandler( this ); Connect( saveResultsBtn->GetId(), wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &wxContourEventHandler::onSaveResults ); int sizeZ = this->_theViewPanel->getSceneManager()->GetImageDataSizeZ(); _mbarrangeSliceInformation = new mBarRange(panel,65,65); _mbarrangeSliceInformation->SetMin(0); _mbarrangeSliceInformation->SetStart(0); _mbarrangeSliceInformation-> SetOrientation( true ); _mbarrangeSliceInformation-> setActiveStateTo(true); _mbarrangeSliceInformation-> setVisibleLabels( true ); _mbarrangeSliceInformation-> setDeviceEndMargin(10); _mbarrangeSliceInformation-> setRepresentedValues( 0 , sizeZ-1 ); _mbarrangeSliceInformation-> setDeviceBlitStart(10,10); _mbarrangeSliceInformation-> setIfWithActualDrawed( false ); _mbarrangeSliceInformation-> SetStart( 0 ); _mbarrangeSliceInformation-> SetEnd( sizeZ-1 ); double range[2]; this->_theViewPanel->getSceneManager()->GetImageDataRange(range); _mbarrangeRangeInformation = new mBarRange(panel,65,65); _mbarrangeRangeInformation->SetMin(0); _mbarrangeRangeInformation->SetStart(0); _mbarrangeRangeInformation-> SetOrientation( true ); _mbarrangeRangeInformation-> setActiveStateTo(true); _mbarrangeRangeInformation-> setVisibleLabels( true ); _mbarrangeRangeInformation-> setDeviceEndMargin(10); _mbarrangeRangeInformation-> setRepresentedValues( range[0] , range[1] ); _mbarrangeRangeInformation-> setDeviceBlitStart(10,10); _mbarrangeRangeInformation-> setIfWithActualDrawed( false ); _mbarrangeRangeInformation-> SetStart( range[0] ); _mbarrangeRangeInformation-> SetEnd( range[1] ); _staticTextInformation = new wxStaticText(panel,-1,_T(" ")); // wxButton *XXXXXXXBtn = new wxButton(panel,-1,_T("Statistics"),wxDefaultPosition, wxSize(180,35) ); // XXXXXXXBtn->SetEventHandler( this ); // Connect( XXXXXXXBtn->GetId(), wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &wxContourEventHandler::onXXXXX ); _grid = new wxGrid( panel, wxID_ANY, wxPoint( 0, 0 ), wxSize( 100, 100 ) ); int i,gridCol=10,gridRow=sizeZ; _grid->CreateGrid( 0, 0 ); _grid->AppendRows(gridRow); _grid->AppendCols(gridCol); for (i=0;iSetRowLabelValue(i, _T(" ") ); } // _grid->SetColLabelSize(0); FillGridWithContoursInformation(); wxFlexGridSizer * sizerA = new wxFlexGridSizer(10); sizerA->Add( _informationRadiobox , 1, wxALL ,2 ); sizerA->Add( _radiolstboxContourGroup , 1, wxALL ,2 ); wxFlexGridSizer * sizerB = new wxFlexGridSizer(10); sizerB->Add( informationContourLabelsBtn , 1, wxALL ,2 ); sizerB->Add( statisticsContourBtn , 1, wxALL ,2 ); sizerB->Add( saveResultsBtn , 1, wxALL ,2 ); wxFlexGridSizer * sizer = new wxFlexGridSizer(1); sizer->AddGrowableCol(0); sizer->AddGrowableRow(7); sizer->Add( sizerA , 1, wxALL , 0 ); sizer->Add( new wxStaticText(panel ,-1,_T("Slice Range")) , 1, wxALL , 0 ); sizer->Add( _mbarrangeSliceInformation , 1, wxALL|wxGROW , 2 ); sizer->Add( new wxStaticText(panel ,-1,_T("Gray Range")) , 1, wxALL , 0 ); sizer->Add( _mbarrangeRangeInformation , 1, wxALL|wxGROW , 2 ); sizer->Add( sizerB , 1, wxALL , 0 ); sizer->Add( _staticTextInformation , 1, wxALL , 0 ); sizer->Add( _grid , 1, wxEXPAND , 0 ); panel->SetSizer( sizer ); panel->SetSize( wxSize(1500,1500) ); //panel->SetBackgroundColour( wxColour(100,100,100) ); panel->SetAutoLayout( true ); panel->Layout();*/ wxBoxSizer * sizerPanel = new wxBoxSizer(wxHORIZONTAL); // sizerPanel->AddGrowableCol(0); // sizerPanel->AddGrowableRow(0); //JCP 14-10-09 //sizerPanel -> Add( sizer , 1, wxEXPAND ,0); sizerPanel -> Add( panel->GetSizer() , 1, wxEXPAND ,0); //JCP 14-10-09 _InformationContourFrame->SetSizer( sizerPanel ); _InformationContourFrame->SetAutoLayout( true ); _InformationContourFrame->Layout(); _InformationContourFrame->Show(); } else { if (_InformationContourFrame->IsShown()==true) { _InformationContourFrame->Show(false); } else { FillGridWithContoursInformation(); _InformationContourFrame->Show(true); } } } wxPanel* wxContourEventHandler::getInformationPanel(wxWindow* parent){ wxPanel *panel = new wxPanel(parent,-1,wxDefaultPosition, wxDefaultSize,wxTAB_TRAVERSAL); wxString lstOptions[4]; lstOptions[0]=_T("Actual Slice"); lstOptions[1]=_T("Range Slices"); lstOptions[2]=_T("All Slices"); _informationRadiobox = new wxRadioBox(panel, -1, _T("Slice analysis"), wxDefaultPosition, wxSize(270,45), 3 , lstOptions, 3, wxRA_SPECIFY_COLS); wxString lstOptContOperation[5]; lstOptContOperation[0]=_T("AND"); lstOptContOperation[1]=_T("OR"); lstOptContOperation[2]=_T("XOR"); lstOptContOperation[3]=_T("ALL"); _radiolstboxContourGroup = new wxRadioBox(panel, -1, _T("Contour group"), wxDefaultPosition, wxSize(270,45), 4 , lstOptContOperation, 4, wxRA_SPECIFY_COLS); wxButton *informationContourLabelsBtn = new wxButton(panel,-1,_T("Contour labels"),wxDefaultPosition, wxSize(140,35) ); informationContourLabelsBtn->SetEventHandler( this ); Connect( informationContourLabelsBtn->GetId(), wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &wxContourEventHandler::onInformationContourLabels ); wxButton *statisticsContourBtn = new wxButton(panel,-1,_T("Contour statistics"),wxDefaultPosition, wxSize(140,35) ); statisticsContourBtn->SetEventHandler( this ); Connect( statisticsContourBtn->GetId(), wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &wxContourEventHandler::onExtractInformation ); wxButton *saveResultsBtn = new wxButton(panel,-1,_T("Save statistics results"),wxDefaultPosition, wxSize(140,35) ); saveResultsBtn->SetEventHandler( this ); Connect( saveResultsBtn->GetId(), wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &wxContourEventHandler::onSaveResults ); int sizeZ = this->_theViewPanel->getSceneManager()->GetImageDataSizeZ(); _mbarrangeSliceInformation = new mBarRange(panel,65,65); _mbarrangeSliceInformation->SetMin(0); _mbarrangeSliceInformation->SetStart(0); _mbarrangeSliceInformation-> SetOrientation( true ); _mbarrangeSliceInformation-> setActiveStateTo(true); _mbarrangeSliceInformation-> setVisibleLabels( true ); _mbarrangeSliceInformation-> setDeviceEndMargin(10); _mbarrangeSliceInformation-> setRepresentedValues( 0 , sizeZ-1 ); _mbarrangeSliceInformation-> setDeviceBlitStart(10,10); _mbarrangeSliceInformation-> setIfWithActualDrawed( false ); _mbarrangeSliceInformation-> SetStart( 0 ); _mbarrangeSliceInformation-> SetEnd( sizeZ-1 ); double range[2]; this->_theViewPanel->getSceneManager()->GetImageDataRange(range); _mbarrangeRangeInformation = new mBarRange(panel,65,65); _mbarrangeRangeInformation->SetMin(0); _mbarrangeRangeInformation->SetStart(0); _mbarrangeRangeInformation-> SetOrientation( true ); _mbarrangeRangeInformation-> setActiveStateTo(true); _mbarrangeRangeInformation-> setVisibleLabels( true ); _mbarrangeRangeInformation-> setDeviceEndMargin(10); _mbarrangeRangeInformation-> setRepresentedValues( range[0] , range[1] ); _mbarrangeRangeInformation-> setDeviceBlitStart(10,10); _mbarrangeRangeInformation-> setIfWithActualDrawed( false ); _mbarrangeRangeInformation-> SetStart( range[0] ); _mbarrangeRangeInformation-> SetEnd( range[1] ); _staticTextInformation = new wxStaticText(panel,-1,_T(" ")); // wxButton *XXXXXXXBtn = new wxButton(panel,-1,_T("Statistics"),wxDefaultPosition, wxSize(180,35) ); // XXXXXXXBtn->SetEventHandler( this ); // Connect( XXXXXXXBtn->GetId(), wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &wxContourEventHandler::onXXXXX ); _grid = new wxGrid( panel, wxID_ANY, wxPoint( 0, 0 ), wxSize( 100, 100 ) ); int i,gridCol=10,gridRow=sizeZ; _grid->CreateGrid( 0, 0 ); _grid->AppendRows(gridRow); _grid->AppendCols(gridCol); for (i=0;iSetRowLabelValue(i, _T(" ") ); } // _grid->SetColLabelSize(0); FillGridWithContoursInformation(); wxFlexGridSizer * sizerA = new wxFlexGridSizer(10); sizerA->Add( _informationRadiobox , 1, wxALL ,2 ); sizerA->Add( _radiolstboxContourGroup , 1, wxALL ,2 ); wxFlexGridSizer * sizerB = new wxFlexGridSizer(10); sizerB->Add( informationContourLabelsBtn , 1, wxALL ,2 ); sizerB->Add( statisticsContourBtn , 1, wxALL ,2 ); sizerB->Add( saveResultsBtn , 1, wxALL ,2 ); wxFlexGridSizer * sizer = new wxFlexGridSizer(1); sizer->AddGrowableCol(0); sizer->AddGrowableRow(7); sizer->Add( sizerA , 1, wxALL , 0 ); sizer->Add( new wxStaticText(panel ,-1,_T("Slice Range")) , 1, wxALL , 0 ); sizer->Add( _mbarrangeSliceInformation , 1, wxALL|wxGROW , 2 ); sizer->Add( new wxStaticText(panel ,-1,_T("Gray Range")) , 1, wxALL , 0 ); sizer->Add( _mbarrangeRangeInformation , 1, wxALL|wxGROW , 2 ); sizer->Add( sizerB , 1, wxALL , 0 ); sizer->Add( _staticTextInformation , 1, wxALL , 0 ); sizer->Add( _grid , 1, wxEXPAND , 0 ); panel->SetSizer( sizer ); panel->SetSize( wxSize(1500,1500) ); //panel->SetBackgroundColour( wxColour(100,100,100) ); panel->SetAutoLayout( true ); panel->Layout(); return panel; } //------------------------------------------------------------------------------------------------------------ void wxContourEventHandler :: onSpreadInDepth( std::vector & keyNamesVector ) { } //------------------------------------------------------------------------------------------------------------ void wxContourEventHandler :: onOutline_Union_Of( std::vector & keyNamesVector ) { } //------------------------------------------------------------------------------------------------------------ void wxContourEventHandler :: onOutline_Intersection_Of( std::vector & keyNamesVector ) { } //------------------------------------------------------------------------------------------------------------ void wxContourEventHandler :: onOutline_Combination_Of( std::vector & keyNamesVector ) { } //------------------------------------------------------------------------------------------------------------ void wxContourEventHandler :: onOutline_Fragmentation_Of( std::vector & keyNamesVector ) { } //------------------------------------------------------------------------------------------------------------ void wxContourEventHandler :: onOutline_Agrupation_Of( std::vector & keyNamesVector ) { } //------------------------------------------------------------------------------------------------------------ void wxContourEventHandler :: onCopyOutlines( std::vector & keyNamesVector ) { std::vector tempVector; _instantPanel->getInstant( tempVector ); _performingOperation->reset(); _performingOperation->setStartCommand( (char)wxContour_ActionCommandsID::COPY_TOOL ); _performingOperation->setStartOperationInstantVector( tempVector ); _performingOperation->setKeyNamesOperationElems( keyNamesVector ); } //------------------------------------------------------------------------------------------------------------ void wxContourEventHandler :: onPasteOutlines( ) { char theStartCommand = _performingOperation->getStartCommand(); if ( theStartCommand == wxContour_ActionCommandsID::COPY_TOOL ) { //JCP 20-10-08 Undo redo implementation saveState(); //JCP 20-10-08 Undo redo implementation std::vector tempVector; _instantPanel->getInstant( tempVector ); _performingOperation->setEndOperationInstantVector ( tempVector ); std::vector elems = _performingOperation->getKeyNamesOperationElems(); int i,size = elems.size(); for( i=0; i0 ); } } int fin = 0; } //------------------------------------------------------------------------------------------------------------ void wxContourEventHandler :: onShowOutlines( std::vector & keyNamesVector ) { } //------------------------------------------------------------------------------------------------------------ void wxContourEventHandler :: onHideOutlines( std::vector & keyNamesVector ) { } //------------------------------------------------------------------------------------------------------------ void wxContourEventHandler :: onSelectOutlines( std::vector & keyNamesVector ) { //if( keyNamesVector.empty() ) { _theViewPanel->getSceneManager()->drawSelectionROI( ); } /*else { int ok = keyNamesVector.size(); _theViewPanel->getSceneManager()->selectObjects( keyNamesVector ); std::string name = keyNamesVector[0]; }*/ /* _theViewPanel->getSceneManager()->drawSelectionROI( ); std::vector currentSelection = _theViewPanel->getSceneManager()->getSelectedObjects(); int ok = currentSelection.size(); _theViewPanel->getSceneManager()->selectObjects( currentSelection );*/ } //------------------------------------------------------------------------------------------------------------ void wxContourEventHandler :: onEditOutlines( std::vector & keyNamesVector ) { } //------------------------------------------------------------------------------------------------------------ //------------------------------------------------------------------------------------------------------------ void wxContourEventHandler :: deleteContour( std::string theKeyName ) { manualContourModel * cModel; manualViewBaseContour * cViewer; manualContourBaseControler * cControler; ContourWrap_ViewControl *conwrapviewControl = _theViewPanel->getSceneManager()->getContourWrap_ViewControlOf( theKeyName ); cControler = conwrapviewControl->getControler(); int ispartofstaticlst= _modelManager->IsPartOfStaticList(theKeyName); if ((cControler!=NULL) && (cControler->IsEditable()==false) && (ispartofstaticlst==-1) ) { _theViewPanel->getSceneManager()->removeFromScene( theKeyName ); cModel = _modelManager->getOutlineByKeyName(theKeyName)->getModel(); _modelManager->removeOutline( theKeyName ); cViewer = conwrapviewControl->getViewer(); _theViewPanel->getSceneManager()->removeWrap( theKeyName ); //EED Borrame //FILE *ff = fopen("c:/temp/wxVtkBaseView_SceneManagerStadistics.txt","a+"); //fprintf(ff,"EED wxContourEventHandler::deleteContours() \n" ); //fprintf(ff," %s %p\n",keyNamesVector[i].c_str(), cControler ); //fclose(ff); delete cModel; delete cViewer; delete cControler; } // if editable } //------------------------------------------------------------------------------------------------------------ void wxContourEventHandler :: deleteContours( std::vector keyNamesVector ) { int i,size=keyNamesVector.size(); for (i=0;i tempVector; _instantPanel->getInstant( tempVector ); //JCP --08-09-2008 When using a diferent interface the _mbarrangeDeleteAll might not be initialize // the values in GetStart and GetEnd will then not be initialize also. // We use instead the values given when initializing the _deletepanel. //int minZ = _mbarrangeDeleteAll->GetStart(); //int maxZ = _mbarrangeDeleteAll->GetEnd(); int minZ, maxZ; minZ = 0; maxZ = _theViewPanel->getSceneManager()->GetImageDataSizeZ(); //JCP --08-09-2008 _theViewPanel->getSceneManager()->removeSceneContours( ); _modelManager->removeAllOutlines(); _theViewPanel->getSceneManager()->removeAllOutlines(); //JCP --08-09-2008 /* if ( (minZ==0) && (maxZ==_mbarrangeDeleteAll->GetMax() )) { _theViewPanel->getSceneManager()->removeSceneContours( ); _modelManager->removeAllOutlines(); _theViewPanel->getSceneManager()->removeAllOutlines(); } else { for ( z=minZ ; z<=maxZ ; z++) { tempVector[1]=z; Instant instant(&tempVector); std::vector lstContourThings = this->_modelManager->getOutlinesAtInstant( &instant ); sizeLstContourThings = lstContourThings.size(); for (ii=0 ; iigetName() ); } //for ii }// for z } // if JCP --08-09-2008 */ } //------------------------------------------------------------------------------------------------------------ void wxContourEventHandler::openContours( FILE *pFile, bool staticContour ) { char tmp[255]; fscanf(pFile,"%s",tmp); // NumberOfContours fscanf(pFile,"%s",tmp); // ## int numberOfContours = atoi(tmp); std::vector instantVector; int typeContourModel; manualContourModel *manModelContour; int typeView; int i; for (i=0;iOpen(pFile); fscanf(pFile,"%s",tmp); // TypeView fscanf(pFile,"%s",tmp); // ## typeView = atoi(tmp); // if (typeView==1) // { // } std::string theName; theName = _modelManager->createOutline( manModelContour, instantVector ); bool addedModel = theName.compare("") != 0; if( addedModel ) { double spc[3];//Si no hay imagen pero hay contornos que spacing se pone por default this->_theViewPanel->getSpacing(spc); //Adding the manualContourControler to interface objects structure //Adding the manualViewContour to interface objects structure //_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. _theViewPanel->getSceneManager()->configureViewControlTo( theName, manModelContour,spc , typeView) ; } if (staticContour==true) { Instant instant(&instantVector); changeContourOfManager( theName , &instant ); } }// for numberOfContours } //------------------------------------------------------------------------------------------------------------ void wxContourEventHandler::openFileWithContours() { char tmp[255]; wxFileDialog dialog(NULL, _T("Choose a file"), _T(""), _T(""), _T("*.roi"), wxOPEN ); if (dialog.ShowModal() == wxID_OK) { fileNameContourROI = (const char *)(dialog.GetPath().mb_str()); FILE *pFile=fopen(fileNameContourROI.c_str(),"r+"); fscanf(pFile,"%s",tmp); // --CreaContour-- fscanf(pFile,"%s",tmp); // Version fscanf(pFile,"%s",tmp); // 1.0.1 std::string version(tmp); openContours(pFile,false); if (version!="1.0.0"){ openContours(pFile,true); } // _theViewPanel->getSceneManager()->openFileWithContours(ff); fclose(pFile); } _theViewPanel->getSceneManager()->removeSceneContours(); changeInstant(); //updateInstantOutlines(); } //------------------------------------------------------------------------------------------------------------ void wxContourEventHandler::saveFileWithContours( std::string filename ) { FILE *pFile=fopen(filename.c_str(),"w+"); std::vector< std::string > lstNameThings; int i,sizeLstNameThings; fprintf(pFile,"--CreaContour--\n"); fprintf(pFile,"Version %s\n", "1.0.1" ); // Normal Contours lstNameThings = _modelManager->GetLstNameThings(); sizeLstNameThings = lstNameThings.size(); fprintf(pFile,"NumberOfContours %d\n", sizeLstNameThings ); for (i=0 ; iSaveThingName( pFile, lstNameThings[i] ); _theViewPanel->getSceneManager()->SaveThingName( pFile, lstNameThings[i] ); }// for i //-- Contours Statics lstNameThings = _modelManager->GetLstNameThingsStatic(); sizeLstNameThings = lstNameThings.size(); fprintf(pFile,"NumberOfContoursStatic %d\n", sizeLstNameThings ); for (i=0 ; iSaveThingName( pFile, lstNameThings[i] ); _theViewPanel->getSceneManager()->SaveThingName( pFile, lstNameThings[i] ); }// for i fclose(pFile); } //---------------------------------------------------------- void wxContourEventHandler::saveFileWithContours() { wxFileDialog dialog(NULL, _T("Choose a file"), _T(""), _T(""), _T("*.roi"), wxSAVE ); if (dialog.ShowModal() == wxID_OK) { fileNameContourROI = (const char *)(dialog.GetPath().mb_str()); saveFileWithContours( fileNameContourROI ); } // if ShowModal } //------------------------------------------------------------------------------------------------------------ void wxContourEventHandler :: saveFileWithContoursAutomatique() { if (fileNameContourROI=="") { saveFileWithContours(); } else { saveFileWithContours(fileNameContourROI); } } //------------------------------------------------------------------------------------------------------------ void wxContourEventHandler :: createCopyContourOf ( std::string anExistingKName, std::vector &instantNoTouchData, bool append ) { std::string cloneName = _modelManager->createCopyContourOf( anExistingKName, instantNoTouchData ); manualContourModel * manualModel = _modelManager->getOutlineByKeyName( cloneName )->getModel(); _theViewPanel->getSceneManager()->createCopyContourOf( anExistingKName, cloneName, manualModel , append ); } //------------------------------------------------------------------------------------------------------------ manualContourModel * wxContourEventHandler::factoryManualContourModel(int typeContour) { manualContourModel *manModelContour=NULL; // spline if (typeContour==0) { manModelContour = new manualContourModel(); } // spline if (typeContour==1) { manModelContour = new manualContourModel(); } // rectangle if (typeContour==2) { manModelContour = new manualContourModelRoi(); } // circle if (typeContour==3) { manModelContour = new manualContourModelCircle(); } // BullEye / star if (typeContour==4) { manualContourModelBullEye *manModelContourBullEye = new manualContourModelBullEye(); manModelContour = manModelContourBullEye; if (_panelBullEyeOptions!=NULL){ int iCrown,sizeCrowns,iSector,sizeSectors; double radioA,radioB,ang,angDelta ; sizeCrowns = _panelBullEyeOptions->GetNumberOfCrowns(); for ( iCrown=0 ; iCrownGetNumberOfSections(iCrown); radioB = _panelBullEyeOptions->GetRadioOfCrown(iCrown); if (iCrown==sizeCrowns-1) { radioA = 0; } else { radioA = _panelBullEyeOptions->GetRadioOfCrown(iCrown+1); } radioA=radioA/100.0; radioB=radioB/100.0; for ( iSector=0 ; iSectorGetAngOfCrownSection(iCrown,iSector); angDelta= _panelBullEyeOptions->GetAngDeltaOfCrownSection(iCrown); manModelContourBullEye->AddSector(radioA,radioB,ang,angDelta); } // for iSector } // for iCrown } // if _panelBullEyeOptions }// if typeContour==4 return manModelContour; } //------------------------------------------------------------------------------------------------------------ void wxContourEventHandler :: createContour( int typeContour ) { //Creating the manualContourModel and including in the model manualContourModel * manModelContour = factoryManualContourModel(typeContour); std::vector instantVector; _instantPanel->getInstant( instantVector ); std::string theName; theName= _modelManager->createOutline( manModelContour, instantVector ); bool addedModel = theName.compare("") != 0;//?? if( addedModel ) { double spc[3];//Si no hay imagen pero hay contornos que spacing se pone por default this->_theViewPanel->getSpacing(spc); //Adding the manualContourControler to interface objects structure //Adding the manualViewContour to interface objects structure //_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. _theViewPanel->getSceneManager()->configureViewControlTo( theName, manModelContour,spc , typeContour) ; } //EED Borrame //FILE *ff = fopen("c:/temp/wxVtkBaseView_SceneManagerStadistics.txt","a+"); //fprintf(ff,"EED wxContourEventHandler::createContour() \n" ); //fprintf(ff," %s\n %p ",theName.c_str() , ); //fclose(ff); } manualContourModel * wxContourEventHandler::factoryManualContourModel(PanelBullEyeOptions* panel){ manualContourModelBullEye *manModelContourBullEye = new manualContourModelBullEye(); manualContourModel *manModelContour=NULL; manModelContour = manModelContourBullEye; if (panel!=NULL){ int iCrown,sizeCrowns,iSector,sizeSectors; double radioA,radioB,ang,angDelta ; sizeCrowns = panel->GetNumberOfCrowns(); for ( iCrown=0 ; iCrownGetNumberOfSections(iCrown); radioB = panel->GetRadioOfCrown(iCrown); if (iCrown==sizeCrowns-1) { radioA = 0; } else { radioA = panel->GetRadioOfCrown(iCrown+1); } radioA=radioA/100.0; radioB=radioB/100.0; for ( iSector=0 ; iSectorGetAngOfCrownSection(iCrown,iSector); angDelta= panel->GetAngDeltaOfCrownSection(iCrown); manModelContourBullEye->AddSector(radioA,radioB,ang,angDelta); } // for iSector } // for iCrown } // if _panelBullEyeOptions return manModelContour; } void wxContourEventHandler :: createContourBullsEye(PanelBullEyeOptions* panel ) { //Creating the manualContourModel and including in the model manualContourModel * manModelContour = factoryManualContourModel(panel ); std::vector instantVector; _instantPanel->getInstant( instantVector ); std::string theName; theName= _modelManager->createOutline( manModelContour, instantVector ); bool addedModel = theName.compare("") != 0; if( addedModel ) { double spc[3];//Si no hay imagen pero hay contornos que spacing se pone por default this->_theViewPanel->getSpacing(spc); //Adding the manualContourControler to interface objects structure //Adding the manualViewContour to interface objects structure //_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. _theViewPanel->getSceneManager()->configureViewControlTo( theName, manModelContour,spc , 4) ; } //EED Borrame //FILE *ff = fopen("c:/temp/wxVtkBaseView_SceneManagerStadistics.txt","a+"); //fprintf(ff,"EED wxContourEventHandler::createContour() \n" ); //fprintf(ff," %s\n %p ",theName.c_str() , ); //fclose(ff); } //------------------------------------------------------------------------------------------------------------ // Attributes getters and setters //------------------------------------------------------------------------------------------------------------ void wxContourEventHandler :: setModelManager( OutlineModelManager * theModelManager ) { _modelManager = theModelManager; _workSpace = _modelManager->getContourWorkspace(); } //------------------------------------------------------------------------------------------------------------ void wxContourEventHandler :: setViewPanel( wxContourViewPanel * theViewPanel ) { _theViewPanel = theViewPanel; //_theViewPanel->setWxEventHandler( this ); /*double spc[3]; this->_theViewPanel->getSpacing(spc); _sceneManager = new wxVtkBaseView_SceneManager ( this->_theViewPanel->getWxVtkBaseView(), this, spc ); Connect( _theViewPanel->GetId(), wxINSTANT_CHANGE, (wxObjectEventFunction) (wxCommandEventFunction) &wxContourEventHandler::onChangeInstant ); Connect( wxID_ANY, wxEVT_START_CREATE_MULT_ROI, (wxObjectEventFunction) (wxCommandEventFunction) &wxContourEventHandler::onCreateMultipleROI ); Connect( wxID_ANY, wxEVT_START_CREATE_ROI, (wxObjectEventFunction) (wxCommandEventFunction) &wxContourEventHandler::onCreateROI ); Connect( wxID_ANY, wxEVT_STOP_CREATE_ROI, (wxObjectEventFunction) (wxCommandEventFunction) &wxContourEventHandler::onStopCreateROI ); Connect( wxID_ANY, wxEVT_CHANGED_DEEP, (wxObjectEventFunction) (wxCommandEventFunction) &wxContourEventHandler::onChangedDeep ); Connect( wxID_ANY, wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &wxContourEventHandler :: onActionButtonPressed ); */ } //------------------------------------------------------------------------------------------------------------ void wxContourEventHandler :: setInstantChooserPanel( wxInstantChooserPanel * theInstantChooserPanel ) { _instantPanel = theInstantChooserPanel; //_instantPanel->setWxEventHandler( this ); //Connect( _instantPanel->GetId(), wxINSTANT_CHOOSER_CHANGE, (wxObjectEventFunction) (wxCommandEventFunction) &wxContourEventHandler::onChangeInstant ); std::vector vect; _instantPanel->getInstant( vect ); _actualInstant = new Instant( &vect ); if( _modelManager!=NULL ) { std::vector conceptNameVect; std::vector conceptSizeVect; _modelManager-> getConceptsInformation(conceptNameVect, conceptSizeVect); int i=0; int max = conceptNameVect.size(); for( ; iaddConcept( conceptNameVect[i], 0, conceptSizeVect[i], 1); } else { _instantPanel->addConcept( conceptNameVect[i], 1, conceptSizeVect[i], 1); } // if } // for } else { //Should be configured later, or abort program, because Model -NEEDS- to be added before chooserPanel } if( _theViewPanel!=NULL ) { double val = _theViewPanel->getCurrentDeep(); _instantPanel->setConceptValue( "Axe Depth", (int)val ); //JCP _instantPanel->setConceptValue("time", num de imagenes); ConceptDataWrap * data = _instantPanel->getConceptDataOf( "Axe Depth" ); changeInstant(); _theViewPanel->setVerticalConcept( "Axe Depth", data->getMinValue(), data->getMaxValue(), data->getMinShowedValue(), data->getMaxShowedValue(), data->getActualValue() ); } else { //Should be configured later, or abort program, because ViewPanel -NEEDS- to be added before chooserPanel }// if } //------------------------------------------------------------------------------------------------------------ void wxContourEventHandler :: setButtonsBar( wxContour_ButtonsBar * theButtonsBar ) { _buttonsBar = theButtonsBar; _buttonsBar->setWxEventHandler( this ); Connect( _buttonsBar->GetId(), wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &wxContourEventHandler:: onActionButtonPressed ); } //------------------------------------------------------------------------------------------------------------ void wxContourEventHandler :: setGrid( wxContour_Grid * theGridPanel ) { _gridPanel = theGridPanel; } //------------------------------------------------------------------------------------------------------------ void wxContourEventHandler :: setDrawToolsPanel( wxContour_DrawToolsPanel * theDrawToolsPanel ) { _drawToolsPanel = theDrawToolsPanel; } //------------------------------------------------------------------------------------------------------------ void wxContourEventHandler :: setOperationsToolsPanel( wxContour_OperationsToolsPanel * theOperationsToolsPanel ) { _operationsToolsPanel = theOperationsToolsPanel; } //------------------------------------------------------------------------------------------------------------ void wxContourEventHandler :: setAutomaticFormsPanel( wxContour_AutomaticFormsToolsPanel * theAutoFormsPanel ) { _autoFormsPanel = theAutoFormsPanel; } void wxContourEventHandler :: setStandardToolsPanel( wxContour_StandardToolsPanel * theStandardToolsPanel ) { _standardToolsPanel= theStandardToolsPanel; } //------------------------------------------------------------------------------------------------------------ void wxContourEventHandler :: setEditionToolsPanel( wxContour_EdtionToolsPanel * theEditionToolsPanel ) { _editionToolsPanel = theEditionToolsPanel; } //------------------------------------------------------------------------------------------------------------ void wxContourEventHandler :: setListViewPanel( wxContour_ListViewPanel * theListViewPanel ) { _listViewPanel = theListViewPanel; } //------------------------------------------------------------------------------------------------------------ // Other functional methods //------------------------------------------------------------------------------------------------------------ //------------------------------------------------------------------------------------------------------------ void wxContourEventHandler::onDeleteContour( wxCommandEvent& event ) { //JCP 20-10-08 Undo redo implementation saveState(); //JCP 20-10-08 Undo redo implementation int i,size=_theViewPanel->getSceneManager()->getSelectedObjects().size(); for(i=0;igetSceneManager()->getSelectedObjects()[i]; int ispartofstaticlist = this->_modelManager->IsPartOfStaticList( keyName ); if ( ispartofstaticlist>=0 ) { std::vector tempVector; _instantPanel->getInstant( tempVector ); Instant instant(&tempVector); this->_modelManager->ChangeContourOfList(keyName, &instant); } } std::vector lstKeyName; std::vector lstKeyNameActualSlice; std::vector lstKeyNameToBeErase; lstKeyNameToBeErase = _theViewPanel->getSceneManager()->getSelectedObjects(); lstKeyNameActualSlice = _theViewPanel->getSceneManager()->GetlstContoursNameActualSlice(); int k,kSize=lstKeyNameToBeErase.size(); int j,jSize=lstKeyNameActualSlice.size(); bool ok; for (k=0;k)_theViewPanel->getSceneManager()->GetlstContoursNameActualSlice() ); } //------------------------------------------------------------------------------------------------------------ void wxContourEventHandler::onDeleteAllContours( wxCommandEvent& event ) { //JCP 20-10-08 Undo redo implementation saveState(); //JCP 20-10-08 Undo redo implementation deleteAllContours( ); } //------------------------------------------------------------------------------------------------------------ void wxContourEventHandler :: onDeleteFrame( ) { if (_deleteFrame==NULL) { _deleteFrame = new wxFrame (_theViewPanel, -1,_T(" Delete Contour "), wxDefaultPosition, wxDefaultSize, wxFRAME_TOOL_WINDOW|wxSYSTEM_MENU | wxCAPTION | wxCLIP_CHILDREN |wxFRAME_FLOAT_ON_PARENT ); int width=300; wxSize sizepanel(width,230); _deleteFrame->SetSize( sizepanel ); wxPanel *panel = new wxPanel(_deleteFrame,-1); wxButton *deleteContourBtn = new wxButton(panel,-1,_T("Delete contour selected"),wxDefaultPosition, wxSize(width-10,35) ); wxButton *deleteContoursActSliceBtn = new wxButton(panel,-1,_T("Delete contours of actual slice"),wxDefaultPosition, wxSize(width-10,35)); wxButton *deleteAllContoursBtn = new wxButton(panel,-1,_T("Delete all contours"),wxDefaultPosition, wxSize(width-10,35)); int sizeZ = _theViewPanel->getSceneManager()->GetImageDataSizeZ(); _mbarrangeDeleteAll = new mBarRange(panel,70, 65); _mbarrangeDeleteAll->SetMin(0); _mbarrangeDeleteAll->SetStart(0); _mbarrangeDeleteAll-> SetOrientation( true ); _mbarrangeDeleteAll-> setActiveStateTo(true); _mbarrangeDeleteAll-> setVisibleLabels( true ); _mbarrangeDeleteAll-> setDeviceEndMargin(10); _mbarrangeDeleteAll-> setRepresentedValues( 0 , sizeZ ); _mbarrangeDeleteAll-> setDeviceBlitStart(10,10); _mbarrangeDeleteAll-> setIfWithActualDrawed( false ); _mbarrangeDeleteAll-> SetStart( 0 ); _mbarrangeDeleteAll-> SetEnd( sizeZ ); _deleteFrame->SetEventHandler( this ); Connect( deleteContourBtn->GetId() , wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &wxContourEventHandler::onDeleteContour ); Connect( deleteContoursActSliceBtn->GetId() , wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &wxContourEventHandler::onDeleteContoursActSlice ); Connect( deleteAllContoursBtn->GetId() , wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &wxContourEventHandler::onDeleteAllContours ); wxFlexGridSizer * sizer = new wxFlexGridSizer(1); sizer -> Add( deleteContourBtn , 1, wxGROW ); sizer -> Add( deleteContoursActSliceBtn , 1, wxGROW ); sizer -> Add( deleteAllContoursBtn , 1, wxGROW ); sizer -> Add( _mbarrangeDeleteAll , 1, wxGROW ); panel->SetSizer( sizer ); panel->SetSize( sizepanel ); panel->SetAutoLayout( true ); panel->Layout(); _deleteFrame->Show(true); } else { if (_deleteFrame->IsShown()==true) { _deleteFrame->Show(false); } else { _deleteFrame->Show(true); } } } //------------------------------------------------------------------------------------------------------------ void wxContourEventHandler::onCreateContourSpline( wxCommandEvent& event ) { //JCP 20-10-08 Undo redo implementation saveState(); //JCP 20-10-08 Undo redo implementation createContour( 1 ); } //------------------------------------------------------------------------------------------------------------ void wxContourEventHandler::onCreateContourRectangle( wxCommandEvent& event ) { //JCP 20-10-08 Undo redo implementation saveState(); //JCP 20-10-08 Undo redo implementation createContour( 2 ); } //------------------------------------------------------------------------------------------------------------ void wxContourEventHandler::onCreateContourCircle( wxCommandEvent& event ) { //JCP 20-10-08 Undo redo implementation saveState(); //JCP 20-10-08 Undo redo implementation createContour( 3 ); } //------------------------------------------------------------------------------------------------------------ void wxContourEventHandler::onCreateContourBullEye( wxCommandEvent& event ) { //JCP 20-10-08 Undo redo implementation saveState(); //JCP 20-10-08 Undo redo implementation createContour( 4 ); } //------------------------------------------------------------------------------------------------------------ void wxContourEventHandler :: onCreateContourFrame( ) { if (_createContourFrame==NULL) { _createContourFrame = new wxFrame (_theViewPanel, -1,_T(" New Contour "), wxDefaultPosition, wxDefaultSize, wxFRAME_TOOL_WINDOW|wxSYSTEM_MENU | wxCAPTION | wxCLIP_CHILDREN |wxFRAME_FLOAT_ON_PARENT | wxRESIZE_BORDER ); wxSize sizepanel(490,600); _createContourFrame->SetSize( sizepanel ); wxPanel *panel = new wxPanel(_createContourFrame,-1); wxButton *newContourSplineBtn = new wxButton(panel,-1,_T("Interpolation B-spline (close)"),wxDefaultPosition, wxSize(180,35) ); newContourSplineBtn->SetToolTip(_T("CTRL-N")); wxButton *newContourRectangleBtn = new wxButton(panel,-1,_T("Rectangle"),wxDefaultPosition, wxSize(180,35)); wxButton *newContourCircleBtn = new wxButton(panel,-1,_T("Circle"),wxDefaultPosition, wxSize(180,35)); wxButton *newContourStarBtn = new wxButton(panel,-1,_T("Bull eye"),wxDefaultPosition, wxSize(180,35)); _panelBullEyeOptions = new PanelBullEyeOptions(panel, wxSize(100,200)); _createContourFrame->SetEventHandler( this ); Connect( newContourSplineBtn->GetId() , wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &wxContourEventHandler::onCreateContourSpline ); Connect( newContourRectangleBtn->GetId() , wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &wxContourEventHandler::onCreateContourRectangle ); Connect( newContourCircleBtn->GetId() , wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &wxContourEventHandler::onCreateContourCircle ); Connect( newContourStarBtn->GetId() , wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &wxContourEventHandler::onCreateContourBullEye ); wxFlexGridSizer * sizer = new wxFlexGridSizer(1); sizer -> Add( newContourSplineBtn , 1, wxGROW ); sizer -> Add( newContourRectangleBtn , 1, wxGROW ); sizer -> Add( newContourCircleBtn , 1, wxGROW ); sizer -> Add( newContourStarBtn , 1, wxGROW ); sizer -> Add( _panelBullEyeOptions , 1, wxGROW ); panel->SetSizer( sizer ); panel->SetSize( sizepanel ); panel->SetAutoLayout( true ); panel->Layout(); _createContourFrame->Show(true); } else { if (_createContourFrame->IsShown()==true) { _createContourFrame->Show(false); } else { _createContourFrame->Show(true); } } } //------------------------------------------------------------------------ void wxContourEventHandler::RefreshInterface() { changeInstant(); wxVtk2DBaseView *wxvtk2dbaseview = (wxVtk2DBaseView*)this->_theViewPanel->getWxVtkBaseView(); wxvtk2dbaseview->Refresh(); } //------------------------------------------------------------------------ void wxContourEventHandler::onWidthOfContour(wxScrollEvent& event){ _theViewPanel->getSceneManager()->removeSceneContours(); double width = (double)_withOfContourLine->GetValue() / 2.0; _theViewPanel->getSceneManager()->SetWidthContour( width ); RefreshInterface(); } //------------------------------------------------------------------------ void wxContourEventHandler::onBrigthnessColorWindowLevel(wxScrollEvent& event){ int colorwindow = _brithtnessColorLevel->GetValue(); int windowlevel = _brithtnessWindowLevel->GetValue(); wxVtk2DBaseView *wxvtk2dbaseview = (wxVtk2DBaseView*)this->_theViewPanel->getWxVtkBaseView(); vtkImageViewer2 *imageviewer = wxvtk2dbaseview->_imageViewer2XYZ->GetVtkImageViewer2(); imageviewer->SetColorWindow(colorwindow); imageviewer->SetColorLevel(windowlevel); // wxvtk2dbaseview->Refresh(); RefreshInterface(); } void wxContourEventHandler::OnInterpolation(wxCommandEvent& event) { wxVtk2DBaseView *wxvtk2dbaseview = (wxVtk2DBaseView*)this->_theViewPanel->getWxVtkBaseView(); vtkImageViewer2 *imageviewer = wxvtk2dbaseview->_imageViewer2XYZ->GetVtkImageViewer2(); if (_interpolationCheckBox->GetValue()==true) { imageviewer->GetImageActor()->InterpolateOn(); } else { imageviewer->GetImageActor()->InterpolateOff(); } RefreshInterface(); } //------------------------------------------------------------------------------------------------------------ void wxContourEventHandler :: onInterfaceConfigurationFrame( ) { if (_interfaceConfigurationFrame==NULL) { _interfaceConfigurationFrame = new wxFrame (_theViewPanel, -1,_T(" Interface Configuration "), wxDefaultPosition, wxDefaultSize, wxFRAME_TOOL_WINDOW|wxSYSTEM_MENU | wxCAPTION | wxCLIP_CHILDREN |wxFRAME_FLOAT_ON_PARENT ); wxSize sizepanel(190,400); _interfaceConfigurationFrame->SetSize( sizepanel ); _interfaceConfigurationFrame->SetEventHandler( this ); wxPanel* panel = getConfigurationPanel(_interfaceConfigurationFrame); panel->SetSize(sizepanel); _interfaceConfigurationFrame->Show(true); } else { if (_interfaceConfigurationFrame->IsShown()==true) { _interfaceConfigurationFrame->Show(false); } else { _interfaceConfigurationFrame->Show(true); } } } //**JCP 13-10-08 wxPanel* wxContourEventHandler :: getConfigurationPanel(wxWindow* parent){ /*wxPanel *panel = new wxPanel(parent,-1); _withOfContourLine = new wxSlider(panel, -1, 1 , 1, 10, wxDefaultPosition, wxSize(180,40), wxSL_HORIZONTAL|wxSL_LABELS, wxDefaultValidator); double range[2]; this->_theViewPanel->getSceneManager()->GetImageDataRange(range); wxVtk2DBaseView *wxvtk2dbaseview = (wxVtk2DBaseView*)this->_theViewPanel->getWxVtkBaseView(); vtkImageViewer2 *imageviewer = wxvtk2dbaseview->_imageViewer2XYZ->GetVtkImageViewer2(); int colorwindow = (int)imageviewer->GetWindowLevel()->GetLevel(); int windowlevel = (int)imageviewer->GetWindowLevel()->GetWindow(); _brithtnessWindowLevel = new wxSlider(panel, -1, windowlevel , 1, range[1], wxDefaultPosition, wxSize(180,40), wxSL_HORIZONTAL|wxSL_LABELS, wxDefaultValidator); _brithtnessColorLevel = new wxSlider(panel, -1, colorwindow , 1, range[1], wxDefaultPosition, wxSize(180,40), wxSL_HORIZONTAL|wxSL_LABELS, wxDefaultValidator); _interpolationCheckBox = new wxCheckBox(panel, -1, _T("Image interpolation") ); _interpolationCheckBox->SetValue(true); _interfaceConfigurationFrame->SetEventHandler( this ); Connect( _withOfContourLine->GetId() , wxEVT_SCROLL_CHANGED , (wxObjectEventFunction) &wxContourEventHandler::onWidthOfContour ); Connect( _withOfContourLine->GetId() , wxEVT_SCROLL_THUMBTRACK , (wxObjectEventFunction) &wxContourEventHandler::onWidthOfContour ); Connect( _brithtnessWindowLevel->GetId() , wxEVT_SCROLL_CHANGED , (wxObjectEventFunction) &wxContourEventHandler::onBrigthnessColorWindowLevel ); Connect( _brithtnessWindowLevel->GetId() , wxEVT_SCROLL_THUMBTRACK , (wxObjectEventFunction) &wxContourEventHandler::onBrigthnessColorWindowLevel ); Connect( _brithtnessColorLevel->GetId() , wxEVT_SCROLL_CHANGED , (wxObjectEventFunction) &wxContourEventHandler::onBrigthnessColorWindowLevel ); Connect( _brithtnessColorLevel->GetId() , wxEVT_SCROLL_THUMBTRACK , (wxObjectEventFunction) &wxContourEventHandler::onBrigthnessColorWindowLevel ); Connect( _interpolationCheckBox->GetId() , wxEVT_COMMAND_CHECKBOX_CLICKED , (wxObjectEventFunction) &wxContourEventHandler::OnInterpolation ); wxFlexGridSizer * sizer = new wxFlexGridSizer(1); sizer -> Add( new wxStaticText(panel,-1,_T("Contour width")) , 1, wxGROW ); sizer -> Add( _withOfContourLine , 1, wxGROW ); sizer -> Add( new wxStaticText(panel,-1,_T(" ")) , 1, wxGROW ); sizer -> Add( new wxStaticText(panel,-1,_T(" ")) , 1, wxGROW ); sizer -> Add( new wxStaticText(panel,-1,_T("Brightness of the image")) , 1, wxGROW ); sizer -> Add( new wxStaticText(panel,-1,_T("--Window level--")) , 1, wxGROW ); sizer -> Add( _brithtnessWindowLevel , 1, wxGROW ); sizer -> Add( new wxStaticText(panel,-1,_T("--Color level--")) , 1, wxGROW ); sizer -> Add( _brithtnessColorLevel, 1, wxGROW ); sizer -> Add( new wxStaticText(panel,-1,_T(" ")) , 1, wxGROW ); sizer -> Add( new wxStaticText(panel,-1,_T(" ")) , 1, wxGROW ); sizer -> Add( _interpolationCheckBox , 1, wxGROW ); panel->SetSizer( sizer ); //JCP 13-10-08 //panel->SetSize( sizepanel ); //13-10-08 panel->SetAutoLayout( true ); panel->Layout(); return panel;*/ wxPanel *panel = new wxPanel(parent,-1,wxDefaultPosition, wxDefaultSize,wxNO_BORDER, wxString(_T(""))); _withOfContourLine = new wxSlider(panel, -1, 1 , 1, 10, wxDefaultPosition, wxDefaultSize, wxSL_HORIZONTAL|wxSL_LABELS, wxDefaultValidator); double range[2]; this->_theViewPanel->getSceneManager()->GetImageDataRange(range); wxVtk2DBaseView *wxvtk2dbaseview = (wxVtk2DBaseView*)this->_theViewPanel->getWxVtkBaseView(); vtkImageViewer2 *imageviewer = wxvtk2dbaseview->_imageViewer2XYZ->GetVtkImageViewer2(); int colorwindow = (int)imageviewer->GetWindowLevel()->GetLevel(); int windowlevel = (int)imageviewer->GetWindowLevel()->GetWindow(); _brithtnessWindowLevel = new wxSlider(panel, -1, windowlevel , 1, range[1], wxDefaultPosition, wxDefaultSize, wxSL_HORIZONTAL|wxSL_LABELS, wxDefaultValidator); _brithtnessColorLevel = new wxSlider(panel, -1, colorwindow , 1, range[1], wxDefaultPosition, wxDefaultSize, wxSL_HORIZONTAL|wxSL_LABELS, wxDefaultValidator); _interpolationCheckBox = new wxCheckBox(panel, -1, _T("Image interpolation") ); _interpolationCheckBox->SetValue(true); Connect( _withOfContourLine->GetId() , wxEVT_SCROLL_CHANGED , (wxObjectEventFunction) &wxContourEventHandler::onWidthOfContour ); Connect( _withOfContourLine->GetId() , wxEVT_SCROLL_THUMBTRACK , (wxObjectEventFunction) &wxContourEventHandler::onWidthOfContour ); Connect( _brithtnessWindowLevel->GetId() , wxEVT_SCROLL_CHANGED , (wxObjectEventFunction) &wxContourEventHandler::onBrigthnessColorWindowLevel ); Connect( _brithtnessWindowLevel->GetId() , wxEVT_SCROLL_THUMBTRACK , (wxObjectEventFunction) &wxContourEventHandler::onBrigthnessColorWindowLevel ); Connect( _brithtnessColorLevel->GetId() , wxEVT_SCROLL_CHANGED , (wxObjectEventFunction) &wxContourEventHandler::onBrigthnessColorWindowLevel ); Connect( _brithtnessColorLevel->GetId() , wxEVT_SCROLL_THUMBTRACK , (wxObjectEventFunction) &wxContourEventHandler::onBrigthnessColorWindowLevel ); Connect( _interpolationCheckBox->GetId() , wxEVT_COMMAND_CHECKBOX_CLICKED , (wxObjectEventFunction) &wxContourEventHandler::OnInterpolation ); wxFlexGridSizer * sizer = new wxFlexGridSizer(1); sizer -> Add( new wxStaticText(panel,-1,_T("Contour width")) , 1, wxGROW ); sizer -> Add( _withOfContourLine , 1, wxGROW ); sizer -> Add( new wxStaticText(panel,-1,_T(" ")) , 1, wxGROW ); sizer -> Add( new wxStaticText(panel,-1,_T(" ")) , 1, wxGROW ); sizer -> Add( new wxStaticText(panel,-1,_T("Brightness of the image")) , 1, wxGROW ); sizer -> Add( new wxStaticText(panel,-1,_T("--Window level--")) , 1, wxGROW ); sizer -> Add( _brithtnessWindowLevel , 1, wxGROW ); sizer -> Add( new wxStaticText(panel,-1,_T("--Color level--")) , 1, wxGROW ); sizer -> Add( _brithtnessColorLevel, 1, wxGROW ); sizer -> Add( new wxStaticText(panel,-1,_T(" ")) , 1, wxGROW ); sizer -> Add( new wxStaticText(panel,-1,_T(" ")) , 1, wxGROW ); sizer -> Add( _interpolationCheckBox , 1, wxGROW ); panel->SetSizer( sizer ); //JCP 13-10-08 //panel->SetSize( sizepanel ); //13-10-08 panel->SetAutoLayout( true ); panel->Layout(); return panel; } //**JCP 13-10-08 //------------------------------------------------------------------ void wxContourEventHandler :: changeContourOfManager(std::string keyName, Instant *instant) { this->_modelManager->ChangeContourOfList(keyName, instant); } //------------------------------------------------------------------ void wxContourEventHandler :: changeContoursOfManager( std::vector & keyNamesVector ) { //JCP 20-10-08 Undo redo implementation saveState(); //JCP 20-10-08 Undo redo implementation std::vector tempVector; _instantPanel->getInstant( tempVector ); Instant instant(&tempVector); int i , size=keyNamesVector.size(); for ( i=0 ; i currentSelection = _theViewPanel->getSceneManager()->getSelectedObjects(); int elementsSelected = currentSelection.size(); if( toolCommand == (wxContour_ActionCommandsID::CREATE_TOOL) ) { onCreateContourFrame(); } if( toolCommand == (wxContour_ActionCommandsID::CREATE_CONTOUR_KEY) ) { createContour(); } else if( toolCommand == wxContour_ActionCommandsID::DELETE_TOOL ) { onDeleteFrame( ); } else if( toolCommand == wxContour_ActionCommandsID::DELETE_KEY ) { deleteContours( currentSelection ); } else if( toolCommand == wxContour_ActionCommandsID::SAVE_TOOL ) { saveFileWithContours( ); } else if( toolCommand == wxContour_ActionCommandsID::SAVE_KEY ) { saveFileWithContoursAutomatique( ); } else if( toolCommand == wxContour_ActionCommandsID::OPEN_TOOL ) { openFileWithContours( ); } else if( toolCommand == wxContour_ActionCommandsID::CHANGE_TOOL ) { if ( elementsSelected >= 1 ) { changeContoursOfManager( currentSelection ); } } else if( toolCommand == wxContour_ActionCommandsID::HIDE_TOOL ) { if ( elementsSelected >= 1 ) { onHideOutlines( currentSelection ); } } else if( toolCommand == wxContour_ActionCommandsID::SHOW_TOOL ) { if ( elementsSelected >= 1 ) { onShowOutlines( currentSelection ); } } else if( toolCommand == wxContour_ActionCommandsID::COPY_TOOL ) { if ( elementsSelected >= 1 ) { onCopyOutlines( currentSelection ); } } else if( toolCommand == wxContour_ActionCommandsID::PASTE_TOOL ) { onPasteOutlines( ); } else if( toolCommand == wxContour_ActionCommandsID::SPREAD_TOOL ) { onSpread(); } else if( toolCommand == wxContour_ActionCommandsID::AUTOMATIQUESEGMENTATION_TOOL ) { onAutomatiqueSegmentation( ); } else if( toolCommand == wxContour_ActionCommandsID::SELECT_TOOL ) { onSelectOutlines( currentSelection ); } else if( toolCommand == wxContour_ActionCommandsID::EDIT_TOOL ) { if ( elementsSelected >= 1 ) { onEditOutlines( currentSelection ); } } else if( toolCommand == wxContour_ActionCommandsID::UNDO_TOOL ) { onUNDO(); } else if( toolCommand == wxContour_ActionCommandsID::REDO_TOOL ) { onREDO(); } else if( toolCommand == wxContour_ActionCommandsID::INFORMATIONCONTOUR_TOOL ) { onInformationContourFrame(); } else if( toolCommand == wxContour_ActionCommandsID::INTERFACECONFIGURATION_TOOL ) { onInterfaceConfigurationFrame(); } else if( toolCommand == wxContour_ActionCommandsID::TEST_TOOL ) { onInterfaceTestFrame(); } } //------------------------------------------------------------------------------------------------------------ // Getting information methods //------------------------------------------------------------------------------------------------------------ //------------------------------------------------------------------------------------------------------------ // Private methods //------------------------------------------------------------------------------------------------------------ void wxContourEventHandler :: updateInstantOutlines() { std::vector namesWrapping = _modelManager->getActualInstantOutlines(); int size = namesWrapping.size(); _theViewPanel->getSceneManager()->removeSceneContours(); for( int i=0; igetSceneManager()->addToScene(namesWrapping[i]->getKeyName(), true, true, true, false, false ); } } //------------------------------------------------------------------------------------------------------------ void wxContourEventHandler :: updateInstantImageData() { wxContourMainFrame * instance = wxContourMainFrame::getInstance(); if(instance != NULL){ int val; std::string conceptname; val = _instantPanel->getConceptValue(conceptname); if(conceptname.compare("time")==0){ std::vector imgvect = instance->getVectImages(); for(int i = 0; i < imgvect.size(); i++){ //_instantPanel->getI } //ImageSourceThing* imgsoth = new ImageSourceThing(); //_modelManager->addImageSource( } } } //------------------------------------------------------------------------------------------------------------ void wxContourEventHandler :: updateInstantAxes() { } //------------------------------------------------------------------------------------------------------------ void wxContourEventHandler :: changeInstant() { std::vector instantVect; _instantPanel->getInstant( instantVect ); Instant * theInstant = new Instant ( &instantVect ); //if( !theInstant->isEquals( _actualInstant )) { //Setting the actual instant _actualInstant = theInstant; _modelManager->setInstant( _actualInstant ); updateInstantOutlines(); updateInstantImageData(); updateInstantAxes(); //Searching the elements at the specified instant /* std::map :: iterator iter; iter = contours_ViewControl->find("Outline 0"); (iter->second)->getViewer()->RemoveCompleteContourActor();*/ } } void wxContourEventHandler :: saveState(){ inredo = 0; //char str[9000]; //itoa(inundo, str, 10); std::string str = intToString(inundo); std::string temp = stundoredo + str + ".roi"; saveFileWithContours(temp); inundo++; } void wxContourEventHandler ::loadState(std::string filename){ char tmp[255]; FILE *pFile=fopen(filename.c_str(),"r+"); fscanf(pFile,"%s",tmp); // --CreaContour-- fscanf(pFile,"%s",tmp); // Version fscanf(pFile,"%s",tmp); // 1.0.1 std::string version(tmp); deleteAllContours(); openContours(pFile,false); if (version!="1.0.0"){ openContours(pFile,true); } fclose(pFile); //_theViewPanel->getSceneManager()->removeSceneContours(); //changeInstant(); } void wxContourEventHandler :: onREDO() { if(inredo > 0){ inredo--; inundo++; //char str[9000]; //itoa(inundo, str, 10); std::string str = intToString(inundo); std::string temp = stundoredo + str + ".roi"; loadState(temp); } } //------------------------------------------------------------------------------------------------------------ void wxContourEventHandler :: onUNDO() { if(inundo>0){ if(inredo==0){ //char str[9000]; //itoa(inundo, str, 10); std::string str = intToString(inundo); std::string temp = stundoredo + str + ".roi"; saveFileWithContours(temp); } inredo++; inundo--; //char str[9000]; //itoa(inundo, str, 10); std::string str = intToString(inundo); std::string temp = stundoredo + str + ".roi"; loadState(temp); } } //JCP 21 - 10 - 09 void wxContourEventHandler :: getValuesXYZ(double **vectx, double **vecty, double **vectz, std::vector* size){ wxBusyCursor wait; ContourExtractData *contourextractdata = new ContourExtractData(); int typeContourGroup = this->_radiolstboxContourGroup->GetSelection(); contourextractdata ->SetTypeOperation( typeContourGroup % 3 ); std::vector lstManConMod; std::vector lstManConModTmp; std::vector lstManConModExp; std::vector pLstValue; std::vector pLstValuePosX; std::vector pLstValuePosY; std::vector pLstValuePosZ; std::vector tempVector; _instantPanel->getInstant( tempVector ); vtkImageData *imagedata = _theViewPanel->getSceneManager()->GetImageData(); int sizeZ = _theViewPanel->getSceneManager()->GetImageDataSizeZ(); int z; int ii,sizeLstContourThings; int minZ,maxZ; double totalZ; double porcent; wxString tmpString; minZ = 0;// _mbarrange->GetStart(); maxZ = sizeZ;//_mbarrange->GetEnd(); totalZ = maxZ-minZ+1; contourextractdata->SetImage( imagedata); // For each slice.. vectx = new double *[sizeZ]; vecty = new double *[sizeZ]; vectz = new double *[sizeZ]; for ( z=0 ; zSetZtoBeAnalys( z); tempVector[1]=z; Instant instant(&tempVector); std::vector lstContourThings = this->_modelManager->getOutlinesAtInstant( &instant ); sizeLstContourThings = lstContourThings.size(); lstManConMod.clear(); for (ii=0 ; iigetModel() ); } lstManConModExp = ExploseEachModel( lstManConMod ); //EED004 int iContourGroup,sizeContourGroup; if (typeContourGroup==3) // contour separete { sizeContourGroup=lstManConModExp.size(); } else { // contour AND OR XOR sizeContourGroup=1; } for( iContourGroup=0 ; iContourGroupSetLstManualContourModel( lstManConModTmp ); pLstValue.clear(); pLstValuePosX.clear(); pLstValuePosY.clear(); pLstValuePosZ.clear(); contourextractdata->GetValuesInsideCrown( &pLstValue, &pLstValuePosX, &pLstValuePosY, &pLstValuePosZ); int iLstValue,sizeLstValue=pLstValue.size(); //We initialize the pointers size->push_back(sizeLstValue); vectx[sizeZ] = new double[sizeLstValue]; vecty[sizeZ] = new double[sizeLstValue]; vectz[sizeZ] = new double[sizeLstValue]; for (iLstValue=0 ; iLstValueSetLabel( _T("") ); delete contourextractdata; } void wxContourEventHandler :: getMaskValue(vtkImageData* mask, vtkImageData* value){ wxBusyCursor wait; ContourExtractData *contourextractdata = new ContourExtractData( true ); int typeContourGroup = this->_radiolstboxContourGroup->GetSelection(); if (typeContourGroup==3) { typeContourGroup=1; } contourextractdata ->SetTypeOperation( typeContourGroup % 3 ); std::vector lstManConMod; std::vector lstManConModTmp; std::vector lstManConModExp; std::vector tempVector; _instantPanel->getInstant( tempVector ); vtkImageData *imagedata = _theViewPanel->getSceneManager()->GetImageData(); int sizeZ = _theViewPanel->getSceneManager()->GetImageDataSizeZ(); int z; int ii,sizeLstContourThings; int minZ,maxZ; double totalZ; double porcent; wxString tmpString; minZ = 0;// _mbarrange->GetStart(); maxZ = sizeZ;//_mbarrange->GetEnd(); totalZ = maxZ-minZ+1; contourextractdata->SetImage( imagedata); // For each slice.. for ( z=0 ; zSetLabel(tmpString); //Extraction data from contours of each slice contourextractdata->SetZtoBeAnalys( z); tempVector[1]=z; Instant instant(&tempVector); std::vector lstContourThings = this->_modelManager->getOutlinesAtInstant( &instant ); sizeLstContourThings = lstContourThings.size(); lstManConMod.clear(); for (ii=0 ; iigetModel() ); } lstManConModExp = ExploseEachModel( lstManConMod ); int iContourGroup,sizeContourGroup; if (typeContourGroup==3) // contour separete { sizeContourGroup=lstManConModExp.size(); } else { // contour AND OR XOR sizeContourGroup=1; } for( iContourGroup=0 ; iContourGroupSetLstManualContourModel( lstManConModTmp ); contourextractdata->CalculateImageResult(); // with actual Z } // for iContourGroup } // for z // Image Value value = contourextractdata->GetVtkImageValueResult(); // Image Mask mask = contourextractdata->GetVtkImageMaskResult(); delete contourextractdata; } wxPanel* wxContourEventHandler::getSegmentationPanelITK(wxWindow* parent){ int sizeZ = _theViewPanel->getSceneManager()->GetImageDataSizeZ(); double range[2]; _theViewPanel->getSceneManager()->GetImageDataRange(range); wxPanel *panel = new wxPanel(parent,-1); wxButton *segmentationOneSliceBtn = new wxButton(panel,-1,_T("Actual slice"), wxDefaultPosition, wxSize(200,35) ); wxButton *segmentationAllSliceBtn = new wxButton(panel,-1,_T("All slices") ,wxDefaultPosition, wxSize(200,35) ); _isovalue = new wxSlider(panel, -1, 40 , (int)(range[0]), (int)(range[1]), wxDefaultPosition, wxSize(200,35), wxSL_HORIZONTAL|wxSL_LABELS, wxDefaultValidator); _sampling = new wxSlider(panel, -1, 20 , 4, 50, wxDefaultPosition, wxSize(200,35), wxSL_HORIZONTAL|wxSL_LABELS, wxDefaultValidator); wxString lstOptions[3]; lstOptions[0]=_T("A"); lstOptions[1]=_T("B"); lstOptions[2]=_T("C"); methodRadiobox = new wxRadioBox(panel, -1, _T("Method (find ctrl. Points)"), wxDefaultPosition, wxSize(200,45), 3 , lstOptions, 3, wxRA_SPECIFY_COLS); methodRadiobox->SetSelection(2); _staticTextSegmentation = new wxStaticText(panel,-1,_T(" ")); _mbarrange = new mBarRange(panel,70, 65); _mbarrange->SetMin(0); _mbarrange->SetStart(0); _mbarrange-> SetOrientation( true ); _mbarrange-> setActiveStateTo(true); _mbarrange-> setVisibleLabels( true ); _mbarrange-> setDeviceEndMargin(10); _mbarrange-> setRepresentedValues( 0 , sizeZ ); _mbarrange-> setDeviceBlitStart(10,10); _mbarrange-> setIfWithActualDrawed( false ); _mbarrange-> SetStart( 0 ); _mbarrange-> SetEnd( sizeZ ); // _segmentationFrame->SetEventHandler( this ); segmentationOneSliceBtn->SetEventHandler( this ); segmentationAllSliceBtn->SetEventHandler( this ); Connect( segmentationOneSliceBtn->GetId(), wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &wxContourEventHandler::onSegmentationOneSliceITK ); Connect( segmentationAllSliceBtn->GetId(), wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &wxContourEventHandler::onSegmentationAllSliceITK ); wxFlexGridSizer * sizer = new wxFlexGridSizer(1); sizer -> Add( new wxStaticText(panel,-1,_T("Isovalue (Gray level)")) , 1, wxGROW ); sizer -> Add( _isovalue , 1, wxGROW ); sizer -> Add( methodRadiobox , 1, wxGROW ); sizer -> Add( new wxStaticText(panel,-1,_T("Sampling (%)")) , 1, wxGROW ); sizer -> Add( _sampling , 1, wxGROW ); sizer -> Add( segmentationOneSliceBtn , 1, wxGROW ); sizer -> Add( new wxStaticText(panel,-1,_T(" ")) , 1, wxGROW ); sizer -> Add( _staticTextSegmentation , 1, wxGROW ); sizer -> Add( segmentationAllSliceBtn , 1, wxGROW ); sizer -> Add( _mbarrange , 1, wxGROW ); panel->SetSizer( sizer ); // panel->SetSize( sizePanel ); panel->SetSize( wxDefaultSize ); panel->SetAutoLayout( true ); panel->Layout(); return panel; } void wxContourEventHandler::onSegmentationAllSliceITK( wxCommandEvent& event ){ //TODO implementar el m�todo para todos los slices ver ayuda en onSegmentationAllSlice } void wxContourEventHandler::onSegmentationOneSliceITK( wxCommandEvent& event ){ //TODO implementar el m�todo de segmentaci�n en ITK ver ayuda en onSegmentationOneSlice y el m�todo // SegmentationOneSlice(x, y, z) que es la implementaci�n del m�todo en VTK //JCP 20-10-08 Undo redo implementation saveState(); //JCP 20-10-08 Undo redo implementation wxBusyCursor wait; int x = this->_theViewPanel->GetX(); int y = this->_theViewPanel->GetY(); int z = this->_theViewPanel->GetZ(); //SegmentationOneSlice( x,y,z ); RefreshInterface(); } void wxContourEventHandler::onSnakePressed(wxWindow* parent){ std::vector vecX; std::vector vecY; std::vector vecZ; _theViewPanel->getSceneManager()->GetPointsOfActualContour( &vecX , &vecY , &vecZ ); if (vecX.size()!=0){ std::vector tempVector; _instantPanel->getInstant( tempVector ); int i,size=vecZ.size(); int actualSlice = tempVector[1]; for ( i=0 ; iShowModal(); } // if } void wxContourEventHandler::checkInformationPanel(){ if (_InformationContourFrame==NULL){ onInformationContourFrame(); _InformationContourFrame->Show(false); } } std::string wxContourEventHandler::intToString(int num){ std::string result; if(num == 0){ result = "0"; }else{ int k=num; while (k > 0){ char temp = k % 10 + 48; k = k / 10; result = temp + result; } } return result; } //JCP 21 - 10 - 09