3 /* Diagrama de Secuaencia de cambiar un instante
4 wxContourEventHandler :: changeInstant()
5 OutlineModelManager :: ->setInstant( _actualInstant );
6 OutlineModelManager :: updateToActualInstant()
7 OutlineModelManager :: getOutlinesAtInstant(Instant * anInstant, bool ifAnnotate)
8 OutlineModelManager :: annotateOutlinesWrap(std::vector<std::string> kNamesVector, std::vector<ContourThing **> theOutlinesVector)
9 wxContourEventHandler :: updateInstantOutlines()
10 OutlineModelManager :: getActualInstantOutlines ()
11 wxVtkBaseView_SceneManager :: addToScene( std::vector< std::string> theKeyNameVector, bool append, bool visualization, bool control, bool ifActive, bool ifShowCtrlPoints )
12 wxVtkBaseView_SceneManager :: addToScene( std::string theKeyName, bool append, bool visualization, bool control, bool ifActive, bool ifShowCtrlPoints )
13 wxVtkBaseView_SceneManager :: getContourWrap_ViewControlOf
15 void wxVtkBaseView_SceneManager :: addToScene( std::string theKeyName, ContourWrap_ViewControl * contourWRP, bool append, bool visualization, bool control, bool ifActive, bool ifShowCtrlPoints )
21 \mainpage NDimension with wxWidgets and maracas
23 \section intro Introduction
25 This is the introduction.
34 node [shape=record, fontname=Helvetica, fontsize=10];
36 _wxContourGUIExample [ label="wxContourGUIExample" URL="\ref wxContourGUIExample"];
37 _wxContourEventHandler [ label="wxContourEventHandler" URL="\ref wxContourEventHandler"];
39 _OutlineModelManager [ label="OutlineModelManager" URL="\ref OutlineModelManager"];
40 _wxInstantChooserPanel [ label="wxInstantChooserPanel" URL="\ref wxInstantChooserPanel"];
41 _wxContourViewPanel [ label="wxContourViewPanel" URL="\ref wxContourViewPanel"];
42 _wxContour_ButtonsBar [ label="wxContour_ButtonsBar" URL="\ref wxContour_ButtonsBar"];
43 _OutlineModelManager [ label="OutlineModelManager" URL="\ref OutlineModelManager"];
44 _wxVtkBaseView_SceneManager [ label="wxVtkBaseView_SceneManager" URL="\ref wxVtkBaseView_SceneManager"];
45 _SomeEnvironment [ label="SomeEnvironment" URL="\ref SomeEnvironment"];
48 _wxContourGUIExample -> _wxContourEventHandler [ arrowhead="open", style="dashed" ];
49 _wxContourGUIExample -> _OutlineModelManager [ arrowhead="open", style="dashed" ];
50 _wxContourGUIExample -> _wxInstantChooserPanel [ arrowhead="open", style="dashed" ];
51 _wxContourGUIExample -> _wxContourViewPanel [ arrowhead="open", style="dashed" ];
52 _wxContourGUIExample -> _wxContour_ButtonsBar [ arrowhead="open", style="dashed" ];
53 _wxContourViewPanel -> wxMaracas_N_ViewersWidget [ arrowhead="open", style="dashed" ];
54 _wxContourEventHandler -> _OutlineModelManager [ arrowhead="open", style="dashed" ];
55 _wxContourEventHandler -> _wxVtkBaseView_SceneManager [ arrowhead="open", style="dashed" ];
56 _OutlineModelManager -> _SomeEnvironment [ arrowhead="open", style="dashed" ];
68 //----------------------------------------------------------------------------------------------------------------
69 // Class definition include
70 //----------------------------------------------------------------------------------------------------------------
71 #include "wxContourEventHandler.h"
72 #include <wx/filedlg.h>
73 #include <wx/spinctrl.h>
77 //----------------------------------------------------------------------------------------------------------------
78 // Class implementation
79 //----------------------------------------------------------------------------------------------------------------
80 /** @file wxContourEventHandler.cxx */
83 //------------------------------------------------------------------------------------------------------------
85 //------------------------------------------------------------------------------------------------------------
87 #include "wxContour_ActionCommnadsID.h"
88 #include "NameWrapper.h"
89 #include "ConceptDataWrap.h"
90 #include "OutlineGroup.h"
92 #include <manualContour.h>
93 #include "Contour/ContourExtractData.h"
94 #include "ImageSourceThing.h"
96 #include "vtkImageData.h"
97 #include <vtkContourFilter.h>
98 #include <vtkCleanPolyData.h>
99 #include <vtkPolyDataConnectivityFilter.h>
100 #include <vtkStripper.h>
101 #include <vtkImageReslice.h>
102 #include <vtkMetaImageWriter.h>
103 #include <vtkImageMapToWindowLevelColors.h>
106 //------------------------------------------------------------------------------------------------------------
107 //------------------------------------------------------------------------------------------------------------
108 //------------------------------------------------------------------------------------------------------------
110 PanelBullEyeOptions::PanelBullEyeOptions (wxWindow * parent, wxSize size) :
111 wxPanel(parent, -1, wxDefaultPosition, size)
116 wxSize sizepanel(190,300);
117 wxPanel *panel = this;
120 wxString lstOptions[2];
121 lstOptions[0]= wxString("General options",wxConvUTF8);
122 lstOptions[1]= wxString("Detail options",wxConvUTF8);
123 _radioboxBullEyeGenOpt = new wxRadioBox(panel, -1, wxString("General/Detail options",wxConvUTF8), wxDefaultPosition, wxSize(200,45), 2 , lstOptions, 2, wxRA_SPECIFY_COLS);
124 _radioboxBullEyeGenOpt->SetSelection(0);
126 _spinctrlBullEyeNumOfCrowns = new wxSpinCtrl( panel , -1,_T("B"),wxDefaultPosition, wxSize(40,20) );
127 _spinctrlBullEyeNumOfCrowns->SetRange(1,_maxLevels);
128 _spinctrlBullEyeNumOfCrowns->SetValue(3);
130 _spinctrlBullEyeNumOfSec = new wxSpinCtrl( panel , -1,_T("A"),wxDefaultPosition, wxSize(40,20) );
131 _spinctrlBullEyeNumOfSec->SetRange(1,_maxSections);
132 _spinctrlBullEyeNumOfSec->SetValue(5);
135 _sliderBullEyeAngle = new wxSlider( panel , -1 ,0,0,180, wxDefaultPosition, wxSize(200,35), wxSL_HORIZONTAL|wxSL_LABELS, wxDefaultValidator);
137 wxFlexGridSizer * sizerGeneralOptions = new wxFlexGridSizer(10);
139 wxFlexGridSizer * sizerGeneralOptionsA = new wxFlexGridSizer(1);
140 wxFlexGridSizer * sizerGeneralOptionsB = new wxFlexGridSizer(1);
141 wxFlexGridSizer * sizerGeneralOptionsC = new wxFlexGridSizer(1);
142 sizerGeneralOptionsA -> Add( new wxStaticText(panel,-1,_T("Crowns")) , 1, wxGROW );
143 sizerGeneralOptionsA -> Add( _spinctrlBullEyeNumOfCrowns , 1/*, wxGROW*/ );
144 sizerGeneralOptionsB -> Add( new wxStaticText(panel,-1,_T("Sections")) , 1, wxGROW );
145 sizerGeneralOptionsB -> Add( _spinctrlBullEyeNumOfSec , 1/*, wxGROW*/ );
146 sizerGeneralOptionsC -> Add( new wxStaticText(panel,-1,_T(" Angle")) , 1, wxGROW );
147 sizerGeneralOptionsC -> Add( _sliderBullEyeAngle , 1/*, wxGROW*/ );
149 sizerGeneralOptions -> Add( sizerGeneralOptionsA , 1/*, wxGROW*/ );
150 sizerGeneralOptions -> Add( new wxStaticText(panel,-1,_T(" ")) , 1, wxGROW );
151 sizerGeneralOptions -> Add( sizerGeneralOptionsB , 1/*, wxGROW*/ );
152 sizerGeneralOptions -> Add( new wxStaticText(panel,-1,_T(" ")) , 1, wxGROW );
153 sizerGeneralOptions -> Add( sizerGeneralOptionsC , 1/*, wxGROW*/ );
156 wxSpinCtrl *tmpSpinSection;
157 wxSlider *tmpSliderRadio;
158 wxSlider *tmpSliderAng;
160 wxFlexGridSizer * sizerDetailOptions = new wxFlexGridSizer(6);
162 sizerDetailOptions -> Add( new wxStaticText(panel,-1,_T("Crown ")) , 1, wxGROW );
163 sizerDetailOptions -> Add( new wxStaticText(panel,-1,_T(" Sections ")) , 1, wxGROW );
164 sizerDetailOptions -> Add( new wxStaticText(panel,-1,_T(" ")) , 1, wxGROW );
165 sizerDetailOptions -> Add( new wxStaticText(panel,-1,_T(" Radio %")) , 1, wxGROW );
166 sizerDetailOptions -> Add( new wxStaticText(panel,-1,_T(" ")) , 1, wxGROW );
167 sizerDetailOptions -> Add( new wxStaticText(panel,-1,_T(" Angle")) , 1, wxGROW );
169 wxString tmpwxstring;
171 for (i=0;i<_maxLevels;i++){
172 tmpSpinSection = new wxSpinCtrl( panel , -1,_T(""),wxDefaultPosition, wxSize(40,20) );
173 tmpSliderRadio = new wxSlider( panel , -1 ,0,0,100, wxDefaultPosition, wxSize(110,35), wxSL_HORIZONTAL|wxSL_LABELS, wxDefaultValidator);
174 tmpSliderAng = new wxSlider( panel , -1 ,0,0,180, wxDefaultPosition, wxSize(200,35), wxSL_HORIZONTAL|wxSL_LABELS, wxDefaultValidator);
176 tmpSpinSection ->SetRange(1,_maxSections);
178 tmpwxstring.Printf(_T(" %d. "),i+1);
179 sizerDetailOptions -> Add( new wxStaticText(panel,-1,tmpwxstring) , 1, wxGROW );
180 sizerDetailOptions -> Add( tmpSpinSection, 1 );
181 sizerDetailOptions -> Add( new wxStaticText(panel,-1,_T(" ")) , 1, wxGROW );
182 sizerDetailOptions -> Add( tmpSliderRadio, 1, wxGROW );
183 sizerDetailOptions -> Add( new wxStaticText(panel,-1,_T(" ")) , 1, wxGROW );
184 sizerDetailOptions -> Add( tmpSliderAng, 1, wxGROW );
186 tmpSpinSection -> SetValue(5);
187 tmpSliderRadio -> SetValue( 100-(double)((i)*100.0/_maxLevels) );
188 tmpSliderAng -> SetValue(0);
190 Connect( tmpSliderRadio->GetId(), wxEVT_SCROLL_THUMBRELEASE , (wxObjectEventFunction) &PanelBullEyeOptions::onRefreshPanel );
191 Connect( tmpSliderRadio->GetId(), wxEVT_SCROLL_CHANGED , (wxObjectEventFunction) &PanelBullEyeOptions::onRefreshPanel );
193 _lstBullEyeDetailNumOfSec.push_back( tmpSpinSection );
194 _lstBullEyeDetailRadio.push_back( tmpSliderRadio );
195 _lstBullEyeDetailAngle.push_back( tmpSliderAng );
199 wxFlexGridSizer * sizer = new wxFlexGridSizer(1);
200 sizer -> Add( new wxStaticText(panel,-1,_T("")) , 1, wxGROW );
201 sizer -> Add( new wxStaticText(panel,-1,_T("")) , 1, wxGROW );
202 sizer -> Add( _radioboxBullEyeGenOpt , 1, wxGROW );
203 sizer -> Add( new wxStaticText(panel,-1,_T("")) , 1, wxGROW );
204 sizer -> Add( new wxStaticText(panel,-1,_T(" -- Bull Eye general options --")) , 1, wxGROW );
205 sizer -> Add( new wxStaticText(panel,-1,_T("")) , 1, wxGROW );
206 sizer -> Add( sizerGeneralOptions , 1, wxGROW );
207 sizer -> Add( new wxStaticText(panel,-1,_T("")) , 1, wxGROW );
208 sizer -> Add( new wxStaticText(panel,-1,_T("")) , 1, wxGROW );
209 sizer -> Add( new wxStaticText(panel,-1,_T(" -- Bull Eye detail options --")) , 1, wxGROW );
210 sizer -> Add( new wxStaticText(panel,-1,_T("")) , 1, wxGROW );
211 sizer -> Add( sizerDetailOptions , 1, wxGROW );
213 Connect( _radioboxBullEyeGenOpt->GetId(), wxEVT_COMMAND_RADIOBOX_SELECTED , (wxObjectEventFunction) &PanelBullEyeOptions::onRefreshPanel );
214 Connect( _spinctrlBullEyeNumOfCrowns->GetId(), wxEVT_COMMAND_TEXT_UPDATED , (wxObjectEventFunction) &PanelBullEyeOptions::onRefreshPanel );
216 panel->SetSizer( sizer );
217 panel->SetSize( sizepanel );
218 panel->SetAutoLayout( true );
225 //------------------------------------------------------------------------------------------------------------
226 PanelBullEyeOptions::~PanelBullEyeOptions()
230 //------------------------------------------------------------------------------------------------------------
231 void PanelBullEyeOptions::onRefreshPanel( wxCommandEvent& event )
236 //------------------------------------------------------------------------------------------------------------
237 void PanelBullEyeOptions::RefreshPanel()
241 if (this->_radioboxBullEyeGenOpt->GetSelection()==0){
242 for (i=0; i<_maxLevels; i++)
244 _lstBullEyeDetailNumOfSec[i] -> Enable(false);
245 _lstBullEyeDetailRadio[i] -> Enable(false);
246 _lstBullEyeDetailAngle[i] -> Enable(false);
249 int spinSelec = _spinctrlBullEyeNumOfCrowns->GetValue();
250 for (i=0; i<_maxLevels; i++)
252 ok = (i < spinSelec);
253 _lstBullEyeDetailNumOfSec[i] -> Enable(ok);
254 _lstBullEyeDetailRadio[i] -> Enable(ok);
255 _lstBullEyeDetailAngle[i] -> Enable(ok);
258 if (_lstBullEyeDetailRadio[i]->GetValue() > _lstBullEyeDetailRadio[i-1]->GetValue())
260 _lstBullEyeDetailRadio[i]->SetValue( _lstBullEyeDetailRadio[i-1]->GetValue() );
267 //------------------------------------------------------------------------------------------------------------
268 int PanelBullEyeOptions::GetNumberOfCrowns()
270 return this->_spinctrlBullEyeNumOfCrowns->GetValue();
273 //------------------------------------------------------------------------------------------------------------
274 int PanelBullEyeOptions::GetNumberOfSections(int nCrown)
277 if (this->_radioboxBullEyeGenOpt->GetSelection()==0)
279 result = this->_spinctrlBullEyeNumOfSec->GetValue();
281 result = this->_lstBullEyeDetailNumOfSec[nCrown]->GetValue();
286 //------------------------------------------------------------------------------------------------------------
287 int PanelBullEyeOptions::GetRadioOfCrown(int nCrown)
291 if (this->_radioboxBullEyeGenOpt->GetSelection()==0)
293 sizeCrowns = (double)( this->_spinctrlBullEyeNumOfCrowns->GetValue() );
294 result = 100.0 * (nCrown+1)/sizeCrowns ;
296 result = this->_lstBullEyeDetailRadio[nCrown]->GetValue();
301 //------------------------------------------------------------------------------------------------------------
302 double PanelBullEyeOptions::GetAngOfCrownSection(int nCrown,int section)
305 if (this->_radioboxBullEyeGenOpt->GetSelection()==0)
307 angle = this->_sliderBullEyeAngle->GetValue();
309 angle = this->_lstBullEyeDetailAngle[nCrown]->GetValue();
311 double numOfSec = (double)GetNumberOfSections(nCrown);
312 double deltaSec = GetAngDeltaOfCrownSection(nCrown);
313 return angle + section*deltaSec ;
316 //------------------------------------------------------------------------------------------------------------
317 double PanelBullEyeOptions::GetAngDeltaOfCrownSection(int nCrown)
319 double numOfSec = (double)GetNumberOfSections(nCrown);
320 return 360.0/numOfSec;
325 //------------------------------------------------------------------------------------------------------------
326 //------------------------------------------------------------------------------------------------------------
327 //------------------------------------------------------------------------------------------------------------
330 //------------------------------------------------------------------------------------------------------------
331 // Constructors & Destructors
332 //------------------------------------------------------------------------------------------------------------
334 wxContourEventHandler ::wxContourEventHandler()
337 _creatingContoursActive = false;
338 _theViewPanel = NULL;
339 _modelManager = NULL;
340 _instantPanel = NULL;
343 _drawToolsPanel = NULL;
344 _operationsToolsPanel = NULL;
345 _autoFormsPanel = NULL;
346 _standardToolsPanel = NULL;
347 _editionToolsPanel = NULL;
348 _listViewPanel = NULL;
349 _sceneManager = NULL;
350 _actualInstant = NULL;
351 _performingOperation = new PerformingOperation();
353 // EED Interface and Spread
355 _segmentationFrame = NULL;
356 _contourPropagation = NULL;
357 _createContourFrame = NULL;
359 _InformationContourFrame = NULL;
360 _interfaceConfigurationFrame = NULL;
362 _wxtextctrlTest = NULL;
363 _panelBullEyeOptions = NULL;
365 fileNameContourROI = "";
366 _numberOfVariablesStatistics=6+1;
370 stundoredo = "data/temp";
371 mkdir(stundoredo.c_str(),755);
372 stundoredo += "/cont";
374 //------------------------------------------------------------------------------------------------------------
375 wxContourEventHandler :: ~ wxContourEventHandler()
377 delete _actualInstant;
378 /*delete _theViewPanel;
379 delete _instantPanel;
381 delete _actualInstant;
383 delete _sceneManager;
384 delete _performingOperation;
388 //------------------------------------------------------------------------------------------------------------
389 // Configuration methods
390 //------------------------------------------------------------------------------------------------------------
392 bool wxContourEventHandler :: configureEventsHandling()
394 bool configured = true;
399 //------------------------------------------------------------------------------------------------------------
400 // Methods for capturing events
401 //------------------------------------------------------------------------------------------------------------
402 void wxContourEventHandler :: onProcessMessage( wxCommandEvent& event )
406 //------------------------------------------------------------------------------------------------------------
408 void wxContourEventHandler :: onActionButtonPressed( wxCommandEvent& event )
410 const char buttonTool = *(char *)event.GetClientData();
411 executeActionCommand( buttonTool );
413 //------------------------------------------------------------------------------------------------------------
414 void wxContourEventHandler :: onChangedDeep ( wxCommandEvent& event )
416 double val = _theViewPanel->getCurrentDeep();
417 _instantPanel->setConceptValue( "Axe Depth", (int)val );
418 _theViewPanel->setActualVertical( (int)val );
422 //------------------------------------------------------------------------------------------------------------
423 void wxContourEventHandler :: onChangeInstant( wxCommandEvent& event )
425 ConceptDataWrap * dataConcept = NULL;
426 if ( _theViewPanel->GetId() == event.GetId() )
428 dataConcept = (ConceptDataWrap *)event.GetClientData();
429 int value = dataConcept->getActualValue();
430 _instantPanel->setConceptValue( dataConcept->getName(), value );
434 dataConcept = _instantPanel->getLastConceptData();
435 if( dataConcept->getName().compare( _theViewPanel->getVerticalConceptName() ) )
437 _theViewPanel->setActualVertical( dataConcept->getActualValue());
438 //_theViewPanel->setVerticalConcept( dataConcept->getName(), dataConcept->getMinShowedValue()/*dataConcept->getMinValue()*/, /*dataConcept->getMaxValue()*/ dataConcept->getMaxShowedValue(), dataConcept->getMinShowedValue(), dataConcept->getMaxShowedValue(), dataConcept->getActualValue());
440 else if( dataConcept->getName().compare( _theViewPanel->getHorizontalConceptName() ) || _instantPanel->getIfConceptCheckedAt( dataConcept->getName(), 0 ) )
442 _theViewPanel->setHorizontalConcept( dataConcept->getName(), dataConcept->getMinShowedValue()/*dataConcept->getMinValue()*/, /*dataConcept->getMaxValue()*/ dataConcept->getMaxShowedValue(), dataConcept->getMinShowedValue(), dataConcept->getMaxShowedValue(), dataConcept->getActualValue());
447 //------------------------------------------------------------------------------------------------------------
449 void wxContourEventHandler :: onCreateMultipleROI( wxCommandEvent& event )
451 _creatingContoursActive = !_creatingContoursActive;
452 if( _creatingContoursActive )
457 //------------------------------------------------------------------------------------------------------------
458 void wxContourEventHandler :: onCreateROI( wxCommandEvent& event )
460 if( _creatingContoursActive )
466 //------------------------------------------------------------------------------------------------------------
467 void wxContourEventHandler :: onStopCreateROI( wxCommandEvent& event )
472 //------------------------------------------------------------------------------------------------------------
473 void wxContourEventHandler :: onDeleterROI( wxCommandEvent& event )
477 //------------------------------------------------------------------------------------------------------------
478 void wxContourEventHandler :: onSelectROI( wxCommandEvent& event )
482 //------------------------------------------------------------------------------------------------------------
485 void wxContourEventHandler :: onUnSelectROI( wxCommandEvent& event )
489 //------------------------------------------------------------------------------------------------------------
491 void wxContourEventHandler :: onManualHidedROI( wxCommandEvent& event )
495 //------------------------------------------------------------------------------------------------------------
497 void wxContourEventHandler :: onManualShowedROI( wxCommandEvent& event )
501 //------------------------------------------------------------------------------------------------------------
503 void wxContourEventHandler :: onEditingROI( wxCommandEvent& event )
507 //------------------------------------------------------------------------------------------------------------
509 void wxContourEventHandler :: onMovingROI( wxCommandEvent& event )
514 //------------------------------------------------------------------------------------------------------------
515 // Model management methods
516 //------------------------------------------------------------------------------------------------------------
518 void wxContourEventHandler::onSpreadReset( wxCommandEvent& event )
520 _wxtextctrlSpread->SetValue(wxString("",wxConvUTF8));
521 _contourPropagation->resetAppend();
524 //------------------------------------------------------------------------------------------------------------
525 void wxContourEventHandler::onSpreadAdd( wxCommandEvent& event )
527 std::vector<double> vecX;
528 std::vector<double> vecY;
529 std::vector<double> vecZ;
530 _sceneManager->GetPointsOfActualContour( &vecX , &vecY , &vecZ );
533 std::vector<int> tempVector;
534 _instantPanel->getInstant( tempVector );
535 int i,size=vecZ.size();
536 int actualSlice = tempVector[1];
537 for ( i=0 ; i<size ; i++ )
539 vecZ[i] = actualSlice;
542 _contourPropagation->appendContour(&vecX , &vecY , &vecZ);
544 //newstring.Printf("%s %d -",_wxtextctrlSpread->GetValue(), actualSlice );
545 newstring.append(wxString(_wxtextctrlSpread->GetValue(),wxConvUTF8));
546 newstring.append(wxString(" ",wxConvUTF8));
547 newstring.append(wxString(intToString(actualSlice).c_str(),wxConvUTF8));
548 _wxtextctrlSpread->SetValue(newstring);
554 //------------------------------------------------------------------------------------------------------------
555 void wxContourEventHandler::onSpreadGo( wxCommandEvent& event )
558 //JCP 20-10-08 Undo redo implementation
560 //JCP 20-10-08 Undo redo implementation
563 int typeMethodFindCtrlPoints=_spreadMethodRadiobox->GetSelection();
564 int typeofcontour = 1;
565 manualContourModel *manModelContour;
566 std::vector<double> vecCtrlPointX;
567 std::vector<double> vecCtrlPointY;
568 std::vector<double> vecCtrlPointZ;
574 std::vector<int> tempVector;
575 _instantPanel->getInstant( tempVector );
578 _contourPropagation->getMaxMinZ(&minZ,&maxZ);
579 //JSTG_16-07-08_----------------------------------------------------------------
580 //_contourPropagation->setInterpolationNumber(maxZ-minZ+1);
581 _contourPropagation->setInterpolationNumber(100);
582 _contourPropagation->CalculeSplinePropagation();
584 double totalZ = maxZ-minZ+1;
587 //--------------------------------------------------------------------
588 for ( z=(int)minZ ; z<=(int)maxZ ; z++ )
590 porcent = 100.0* (z-minZ)/totalZ;
591 int numero = (int)(z-minZ+1)/(int)totalZ;
592 std::string stringtemp = " "+intToString(porcent)+"% "+intToString(numero)+" "+intToString(z);
593 tmpString.Append(wxString(stringtemp.c_str(),wxConvUTF8));
595 //tmpString.Printf(" %d %c %d/%d %d", (int)porcent , 37 , (int)(z-minZ+1), (int)totalZ,z );
596 _staticTextSpread->SetLabel(tmpString);
598 if (_contourPropagation->ifSliceKeyContourExist(z)==false)
600 manModelContour = factoryManualContourModel( typeofcontour );
601 idTmp = _contourPropagation->FindIdWithZ(z);
602 if (typeMethodFindCtrlPoints==0) // Initial Points
604 _contourPropagation->GetInitialControlPoints( idTmp , &vecCtrlPointX,&vecCtrlPointY,&vecCtrlPointZ);
606 if (typeMethodFindCtrlPoints==1) // Automatique Method
608 _contourPropagation->GetControlPoints( idTmp ,&vecCtrlPointX,&vecCtrlPointY,&vecCtrlPointZ);
610 if (typeMethodFindCtrlPoints==2) // sampling
612 _contourPropagation->GetControlPoints( idTmp , 20.0 ,&vecCtrlPointX,&vecCtrlPointY,&vecCtrlPointZ);
614 //--------------------------------------------------------------------
615 sizeCtrPt = vecCtrlPointX.size();
616 for (j=0 ; j<sizeCtrPt ; j++)
618 //JSTG_16-07-08_----------------------------------------------------------------
619 manModelContour->AddPoint( vecCtrlPointX[j] , vecCtrlPointY[j] , -900 );
620 //--------------------------------------------------------------------
625 theName = _modelManager->createOutline( manModelContour, tempVector );
626 bool addedModel = theName.compare("") != 0;
629 double spc[3];//Si no hay imagen pero hay contornos que spacing se pone por default
630 this->_theViewPanel->getSpacing(spc);
631 //Adding the manualContourControler to interface objects structure
632 //Adding the manualViewContour to interface objects structure
633 //_sceneManager->setControlActiveStateOfALL( false );//This call is being done here because if the ROI is created underneath the previously created ROIS will still be active.
634 _sceneManager->configureViewControlTo( theName, manModelContour,spc,typeofcontour ) ;
636 }// ifSliceKeyContourExist
638 _staticTextSpread->SetLabel(wxString(" ",wxConvUTF8));
639 //RefreshInterface();
645 //------------------------------------------------------------------------------------------------------------
646 void wxContourEventHandler :: onSpread( )
648 if (_spreadFrame==NULL)
651 _spreadFrame = new wxFrame (_theViewPanel, -1,_T(" Spread "), wxDefaultPosition, wxDefaultSize, wxFRAME_TOOL_WINDOW|wxSYSTEM_MENU | wxCAPTION | wxCLIP_CHILDREN |wxFRAME_FLOAT_ON_PARENT );
653 wxSize sizepanel(250,400);
654 _spreadFrame->SetSize( sizepanel );
655 _spreadFrame->SetEventHandler( this );
656 wxPanel *panel = getSpreadPanel(_spreadFrame);
657 panel->SetSize(sizepanel);
658 /**new wxPanel(_spreadFrame,-1);
660 wxButton *spreadResetBtn = new wxButton(panel,-1,_T("Reset"),wxDefaultPosition, wxSize(80,35) );
661 wxButton *spreadAddBtn = new wxButton(panel,-1,_T("Add"),wxDefaultPosition, wxSize(80,35));
663 wxString lstOptions[3];
667 _spreadMethodRadiobox = new wxRadioBox(panel, -1, "Method (find ctrl. Points)", wxDefaultPosition, wxSize(200,45), 3 , lstOptions, 3, wxRA_SPECIFY_COLS);
668 _spreadMethodRadiobox->SetSelection(2);
670 wxButton *spreadGoBtn = new wxButton(panel,-1,_T("Go"),wxDefaultPosition, wxSize(80,35));
671 _staticTextSpread = new wxStaticText(panel,-1,_T(" "));
673 _wxtextctrlSpread = new wxTextCtrl(panel,-1, "",wxDefaultPosition, wxSize(200,150), wxTE_MULTILINE );
675 _spreadFrame->SetEventHandler( this );
676 Connect( spreadResetBtn->GetId(), wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &wxContourEventHandler::onSpreadReset );
677 Connect( spreadAddBtn->GetId(), wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &wxContourEventHandler::onSpreadAdd );
678 Connect( spreadGoBtn->GetId(), wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &wxContourEventHandler::onSpreadGo );
680 wxFlexGridSizer * sizer = new wxFlexGridSizer(1);
681 sizer -> Add( spreadResetBtn , 1, wxGROW );
682 sizer -> Add( spreadAddBtn , 1, wxGROW );
683 sizer -> Add( _spreadMethodRadiobox , 1, wxGROW );
684 sizer -> Add( spreadGoBtn , 1, wxGROW );
685 sizer -> Add( _staticTextSpread , 1, wxGROW );
686 sizer -> Add( _wxtextctrlSpread , 1, wxGROW );
689 panel->SetSizer( sizer );
690 panel->SetSize( sizepanel );
691 panel->SetAutoLayout( true );
693 _spreadFrame->Show();
695 if (_spreadFrame->IsShown()==true)
697 _spreadFrame->Show(false);
699 _spreadFrame->Show(true);
704 wxPanel* wxContourEventHandler::getSpreadPanel(wxWindow* parent){
705 //wxPanel *panel = new wxPanel(parent,-1);
707 _contourPropagation = new ContourPropagation();
709 wxPanel *panel = new wxPanel(parent,-1,wxDefaultPosition, wxDefaultSize,wxNO_BORDER, wxString("",wxConvUTF8));
711 wxButton *spreadResetBtn = new wxButton(panel,-1,_T("Reset"),wxDefaultPosition, wxDefaultSize );
712 wxButton *spreadAddBtn = new wxButton(panel,-1,_T("Add"),wxDefaultPosition, wxDefaultSize);
714 wxString lstOptions[3];
715 lstOptions[0]=_T("A");
716 lstOptions[1]=_T("B");
717 lstOptions[2]=_T("C");
718 _spreadMethodRadiobox = new wxRadioBox(panel, -1, _T("Method (find ctrl. Points)"), wxDefaultPosition, wxDefaultSize, 3 , lstOptions, 3, wxRA_SPECIFY_COLS);
719 _spreadMethodRadiobox->SetSelection(2);
721 wxButton *spreadGoBtn = new wxButton(panel,-1,_T("Go"),wxDefaultPosition, wxDefaultSize);
722 _staticTextSpread = new wxStaticText(panel,-1,_T(" "));
724 _wxtextctrlSpread = new wxTextCtrl(panel,-1, _T(""),wxDefaultPosition, wxDefaultSize, wxTE_MULTILINE );
727 Connect( spreadResetBtn->GetId(), wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &wxContourEventHandler::onSpreadReset );
728 Connect( spreadAddBtn->GetId(), wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &wxContourEventHandler::onSpreadAdd );
729 Connect( spreadGoBtn->GetId(), wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &wxContourEventHandler::onSpreadGo );
731 wxFlexGridSizer * sizer = new wxFlexGridSizer(1);
732 sizer -> Add( spreadResetBtn , 1, wxGROW );
733 sizer -> Add( spreadAddBtn , 1, wxGROW );
734 sizer -> Add( _spreadMethodRadiobox , 1, wxGROW );
735 sizer -> Add( spreadGoBtn , 1, wxGROW );
736 sizer -> Add( _staticTextSpread , 1, wxGROW );
737 sizer -> Add( _wxtextctrlSpread , 1, wxGROW );
740 panel->SetSizer( sizer );
741 //panel->SetSize( wxDefaultSize );
742 panel->SetAutoLayout( true );
747 //------------------------------------------------------------------------------------------------------------
748 void wxContourEventHandler::onSegmentationAllSlice( wxCommandEvent& event )
750 //JCP 20-10-08 Undo redo implementation
752 //JCP 20-10-08 Undo redo implementation
755 int x = this->_theViewPanel->GetX();
756 int y = this->_theViewPanel->GetY();
760 minZ=_mbarrange->GetStart();
761 maxZ=_mbarrange->GetEnd();
762 double totalZ = maxZ-minZ+1;
763 for( z=minZ ; z<=maxZ ; z++ )
765 porcent = 100.0* (z-minZ)/totalZ;
766 tmpString.Printf(_T(" %d %c %d/%d %d"), (int)porcent , 37 , z-minZ+1, (int)totalZ,z );
767 _staticTextSegmentation->SetLabel(tmpString);
768 SegmentationOneSlice( x,y,z );
770 _staticTextSegmentation->SetLabel(_T(" "));
776 //------------------------------------------------------------------------------------------------------------
777 void wxContourEventHandler::onSegmentationOneSlice( wxCommandEvent& event )
779 //JCP 20-10-08 Undo redo implementation
781 //JCP 20-10-08 Undo redo implementation
784 int x = this->_theViewPanel->GetX();
785 int y = this->_theViewPanel->GetY();
786 int z = this->_theViewPanel->GetZ();
787 SegmentationOneSlice( x,y,z );
792 //------------------------------------------------------------------------------------------------------------
793 void wxContourEventHandler::SegmentationOneSlice( int x, int y, int z )
795 int typeofcontour = 1;
796 //--Extracting Contour
797 vtkImageData *imagedata = _sceneManager->GetImageData();
798 // double *range = imagedata->GetScalarRange();
800 int isovalue = _isovalue->GetValue();
801 int sampling = _sampling->GetValue();
803 vtkImageReslice *imageReslice = vtkImageReslice::New();
806 // imagedata->GetSpacing(spc);
811 imageReslice->SetInput( imagedata );
812 imageReslice->SetInformationInput(imagedata);
813 imageReslice->SetResliceAxesDirectionCosines(1,0,0, 0,1,0 ,0,0,1);
814 imageReslice->SetResliceAxesOrigin(0,0,z);
815 imageReslice->SetOutputDimensionality(2);
816 imageReslice->SetInterpolationModeToLinear();
818 imagedata = imageReslice->GetOutput();
820 imagedata->UpdateInformation();
822 vtkContourFilter* cntVTK = vtkContourFilter::New( );
823 cntVTK->SetInput( imagedata );
825 cntVTK->SetNumberOfContours( 1 );
826 //cntVTK->SetValue( 0, vmin );
827 // cntVTK->SetValue( 0, (range[1]*thr/100) );
828 cntVTK->SetValue( 1, isovalue );
829 // cntVTK->SetValue( 1, vmax );
831 cntVTK->UpdateInformation();
833 vtkCleanPolyData* cpd = vtkCleanPolyData::New( );
834 cpd->SetInput( cntVTK->GetOutput( ) );
835 cpd->ConvertLinesToPointsOff( );
837 cpd->UpdateInformation();
839 vtkPolyDataConnectivityFilter* conn = vtkPolyDataConnectivityFilter::New( );
840 conn->SetExtractionModeToClosestPointRegion( );
841 //conn->SetMaxRecursionDepth( 3000 );
843 conn->SetInput( cpd->GetOutput( ) );
845 conn->SetClosestPoint( x, y, 0 );
847 conn->UpdateInformation();
849 vtkCleanPolyData* cpd2 = vtkCleanPolyData::New( );
850 cpd2->SetInput( conn->GetOutput( ) );
852 cpd2->UpdateInformation();
854 vtkStripper* vtkstripper = vtkStripper::New( );
855 vtkstripper->SetInput( cpd2->GetOutput() );
856 vtkstripper->Update();
857 vtkstripper->UpdateInformation();
860 vtkPolyData* polyDataResult = vtkstripper->GetOutput();
862 polyDataResult->Update( );
863 polyDataResult->UpdateInformation();
867 myfile.open ("c:/temp/example.txt");
869 polyDataResult->Print(myfile);
870 myfile << "-------------------------------------\n";
871 polyDataResult->GetLines()->Print(myfile);
881 //--Calculating control points
883 std::vector<double> vecX;
884 std::vector<double> vecY;
885 std::vector<double> vecZ;
887 std::vector<double> vecCtrlPointX;
888 std::vector<double> vecCtrlPointY;
889 std::vector<double> vecCtrlPointZ;
893 int ii,size=polyDataResult->GetNumberOfPoints();
895 for (ii=1;ii<=size;ii++)
897 id = polyDataResult->GetLines()->GetData()->GetValue(ii);
898 p = polyDataResult->GetPoint(id);
901 vecX.push_back( p[0] );
902 vecY.push_back( p[1] );
903 vecZ.push_back( -900 );
904 // vecZ.push_back( p[2] );
908 ExtractControlPoints2D *extractcontrolpoints2d = new ExtractControlPoints2D();
909 extractcontrolpoints2d->SetContour( &vecX , &vecY , &vecZ );
912 if (methodRadiobox->GetSelection()==0){
913 extractcontrolpoints2d->GetInitialControlPoints( &vecCtrlPointX , &vecCtrlPointY , &vecCtrlPointZ );
915 if (methodRadiobox->GetSelection()==1){
916 extractcontrolpoints2d->GetControlPoints( &vecCtrlPointX , &vecCtrlPointY , &vecCtrlPointZ );
918 if (methodRadiobox->GetSelection()==2){
919 extractcontrolpoints2d->SetSamplingControlPoints( sampling );
920 extractcontrolpoints2d->GetSamplingControlPoints( &vecCtrlPointX , &vecCtrlPointY , &vecCtrlPointZ );
923 //--Adding contour to the system
925 std::vector<int> actualInstantVector;
926 _instantPanel->getInstant( actualInstantVector );
927 actualInstantVector[1]=z;
929 int j,sizeCtrPt = vecCtrlPointX.size();
930 manualContourModel *manModelContour = factoryManualContourModel( typeofcontour );
931 manModelContour->SetNumberOfPointsSpline( ((sizeCtrPt/100)+1)*100 );
933 for (j=0 ; j<sizeCtrPt ; j++)
935 manModelContour->AddPoint( vecCtrlPointX[j] , vecCtrlPointY[j] , vecCtrlPointZ[j] );
938 theName = _modelManager->createOutline( manModelContour, actualInstantVector );
939 bool addedModel = theName.compare("") != 0;
942 double spc[3];//Si no hay imagen pero hay contornos que spacing se pone por default
943 this->_theViewPanel->getSpacing(spc);
944 //Adding the manualContourControler to interface objects structure
945 //Adding the manualViewContour to interface objects structure
946 //_sceneManager->setControlActiveStateOfALL( false );//This call is being done here because if the ROI is created underneath the previously created ROIS will still be active.
947 _sceneManager->configureViewControlTo( theName, manModelContour,spc, typeofcontour ) ;
952 //------------------------------------------------------------------------------------------------------------
953 void wxContourEventHandler :: onAutomatiqueSegmentation( )
955 if (_segmentationFrame==NULL)
958 /*int sizeZ = _sceneManager->GetImageDataSizeZ();
960 _sceneManager->GetImageDataRange(range);*/
963 wxSize sizePanel( 300, 470);
964 _segmentationFrame = new wxFrame (_theViewPanel, -1,_T(" Segmentation "), wxDefaultPosition, wxDefaultSize, wxFRAME_TOOL_WINDOW|wxSYSTEM_MENU | wxCAPTION | wxCLIP_CHILDREN |wxFRAME_FLOAT_ON_PARENT );
965 _segmentationFrame->SetSize( sizePanel );
966 wxPanel *panel = getSegmentationPanel(_segmentationFrame);
967 /*new wxPanel(_segmentationFrame,-1);
968 wxButton *segmentationOneSliceBtn = new wxButton(panel,-1,_T("Actual slice"), wxDefaultPosition, wxSize(200,35) );
969 wxButton *segmentationAllSliceBtn = new wxButton(panel,-1,_T("All slices") ,wxDefaultPosition, wxSize(200,35) );
970 _isovalue = new wxSlider(panel, -1, 40 , (int)(range[0]), (int)(range[1]), wxDefaultPosition, wxSize(200,35), wxSL_HORIZONTAL|wxSL_LABELS, wxDefaultValidator);
971 _sampling = new wxSlider(panel, -1, 20 , 4, 50, wxDefaultPosition, wxSize(200,35), wxSL_HORIZONTAL|wxSL_LABELS, wxDefaultValidator);
972 wxString lstOptions[3];
976 methodRadiobox = new wxRadioBox(panel, -1, "Method (find ctrl. Points)", wxDefaultPosition, wxSize(200,45), 3 , lstOptions, 3, wxRA_SPECIFY_COLS);
977 methodRadiobox->SetSelection(2);
978 _staticTextSegmentation = new wxStaticText(panel,-1,_T(" "));
981 _mbarrange = new mBarRange(panel,70, 65);
982 _mbarrange->SetMin(0);
983 _mbarrange->SetStart(0);
985 _mbarrange-> SetOrientation( true );
986 _mbarrange-> setActiveStateTo(true);
987 _mbarrange-> setVisibleLabels( true );
988 _mbarrange-> setDeviceEndMargin(10);
989 _mbarrange-> setRepresentedValues( 0 , sizeZ );
990 _mbarrange-> setDeviceBlitStart(10,10);
991 _mbarrange-> setIfWithActualDrawed( false );
992 _mbarrange-> SetStart( 0 );
993 _mbarrange-> SetEnd( sizeZ );
996 // _segmentationFrame->SetEventHandler( this );
997 segmentationOneSliceBtn->SetEventHandler( this );
998 segmentationAllSliceBtn->SetEventHandler( this );
999 Connect( segmentationOneSliceBtn->GetId(), wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &wxContourEventHandler::onSegmentationOneSlice );
1000 Connect( segmentationAllSliceBtn->GetId(), wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &wxContourEventHandler::onSegmentationAllSlice );
1002 wxFlexGridSizer * sizer = new wxFlexGridSizer(1);
1003 sizer -> Add( new wxStaticText(panel,-1,_T("Isovalue (Gray level)")) , 1, wxGROW );
1004 sizer -> Add( _isovalue , 1, wxGROW );
1005 sizer -> Add( methodRadiobox , 1, wxGROW );
1006 sizer -> Add( new wxStaticText(panel,-1,_T("Sampling (%)")) , 1, wxGROW );
1007 sizer -> Add( _sampling , 1, wxGROW );
1008 sizer -> Add( segmentationOneSliceBtn , 1, wxGROW );
1009 sizer -> Add( new wxStaticText(panel,-1,_T(" ")) , 1, wxGROW );
1010 sizer -> Add( _staticTextSegmentation , 1, wxGROW );
1011 sizer -> Add( segmentationAllSliceBtn , 1, wxGROW );
1012 sizer -> Add( _mbarrange , 1, wxGROW );
1014 panel->SetSizer( sizer );
1015 panel->SetSize( sizePanel );
1016 panel->SetAutoLayout( true );
1019 this->_theViewPanel->SetVisibleAxis(true);
1020 this->_theViewPanel->Refresh();
1021 _segmentationFrame->Show(true);
1022 //JCP 13-10-09 View the method getSegmentationPanel(), this two methods where moved to getSegmentationPanel
1023 //this->_theViewPanel->SetVisibleAxis(true);
1024 //this->_theViewPanel->Refresh();
1026 if (_segmentationFrame->IsShown()==true)
1028 _segmentationFrame->Show(false);
1029 this->_theViewPanel->SetVisibleAxis(false);
1030 this->_theViewPanel->Refresh();
1032 _segmentationFrame->Show(true);
1033 this->_theViewPanel->SetVisibleAxis(true);
1034 this->_theViewPanel->Refresh();
1039 void wxContourEventHandler::showAxis(bool show){
1040 this->_theViewPanel->SetVisibleAxis(show);
1041 this->_theViewPanel->Refresh();
1043 wxPanel* wxContourEventHandler::getSegmentationPanel(wxWindow* parent){
1044 int sizeZ = _sceneManager->GetImageDataSizeZ();
1046 _sceneManager->GetImageDataRange(range);
1048 wxPanel *panel = new wxPanel(parent,-1);
1049 wxButton *segmentationOneSliceBtn = new wxButton(panel,-1,_T("Actual slice"), wxDefaultPosition, wxSize(200,35) );
1050 wxButton *segmentationAllSliceBtn = new wxButton(panel,-1,_T("All slices") ,wxDefaultPosition, wxSize(200,35) );
1051 _isovalue = new wxSlider(panel, -1, 40 , (int)(range[0]), (int)(range[1]), wxDefaultPosition, wxSize(200,35), wxSL_HORIZONTAL|wxSL_LABELS, wxDefaultValidator);
1052 _sampling = new wxSlider(panel, -1, 20 , 4, 50, wxDefaultPosition, wxSize(200,35), wxSL_HORIZONTAL|wxSL_LABELS, wxDefaultValidator);
1053 wxString lstOptions[3];
1054 lstOptions[0]=_T("A");
1055 lstOptions[1]=_T("B");
1056 lstOptions[2]=_T("C");
1057 methodRadiobox = new wxRadioBox(panel, -1, _T("Method (find ctrl. Points)"), wxDefaultPosition, wxSize(200,45), 3 , lstOptions, 3, wxRA_SPECIFY_COLS);
1058 methodRadiobox->SetSelection(2);
1059 _staticTextSegmentation = new wxStaticText(panel,-1,_T(" "));
1062 _mbarrange = new mBarRange(panel,70, 65);
1063 _mbarrange->SetMin(0);
1064 _mbarrange->SetStart(0);
1066 _mbarrange-> SetOrientation( true );
1067 _mbarrange-> setActiveStateTo(true);
1068 _mbarrange-> setVisibleLabels( true );
1069 _mbarrange-> setDeviceEndMargin(10);
1070 _mbarrange-> setRepresentedValues( 0 , sizeZ );
1071 _mbarrange-> setDeviceBlitStart(10,10);
1072 _mbarrange-> setIfWithActualDrawed( false );
1073 _mbarrange-> SetStart( 0 );
1074 _mbarrange-> SetEnd( sizeZ );
1077 // _segmentationFrame->SetEventHandler( this );
1078 segmentationOneSliceBtn->SetEventHandler( this );
1079 segmentationAllSliceBtn->SetEventHandler( this );
1080 Connect( segmentationOneSliceBtn->GetId(), wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &wxContourEventHandler::onSegmentationOneSlice );
1081 Connect( segmentationAllSliceBtn->GetId(), wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &wxContourEventHandler::onSegmentationAllSlice );
1083 wxFlexGridSizer * sizer = new wxFlexGridSizer(1);
1084 sizer -> Add( new wxStaticText(panel,-1,_T("Isovalue (Gray level)")) , 1, wxGROW );
1085 sizer -> Add( _isovalue , 1, wxGROW );
1086 sizer -> Add( methodRadiobox , 1, wxGROW );
1087 sizer -> Add( new wxStaticText(panel,-1,_T("Sampling (%)")) , 1, wxGROW );
1088 sizer -> Add( _sampling , 1, wxGROW );
1089 sizer -> Add( segmentationOneSliceBtn , 1, wxGROW );
1090 sizer -> Add( new wxStaticText(panel,-1,_T(" ")) , 1, wxGROW );
1091 sizer -> Add( _staticTextSegmentation , 1, wxGROW );
1092 sizer -> Add( segmentationAllSliceBtn , 1, wxGROW );
1093 sizer -> Add( _mbarrange , 1, wxGROW );
1095 panel->SetSizer( sizer );
1096 // panel->SetSize( sizePanel );
1097 panel->SetSize( wxDefaultSize );
1098 panel->SetAutoLayout( true );
1103 void wxContourEventHandler :: onInterfaceTestFrame( )
1105 if (_TestFrame==NULL)
1107 _contourPropagation = new ContourPropagation();
1108 _TestFrame = new wxFrame (_theViewPanel, -1,_T(" Test Segmentation "), wxDefaultPosition, wxDefaultSize, wxFRAME_TOOL_WINDOW|wxSYSTEM_MENU | wxCAPTION | wxCLIP_CHILDREN |wxFRAME_FLOAT_ON_PARENT );
1109 wxSize sizepanel(200,300);
1110 _TestFrame->SetSize( sizepanel );
1111 wxPanel *panel = new wxPanel(_TestFrame,-1);
1112 wxButton *spreadResetBtn = new wxButton(panel,-1,_T("Reset"),wxDefaultPosition, wxSize(80,35) );
1113 wxButton *spreadAddBtn = new wxButton(panel,-1,_T("Add"),wxDefaultPosition, wxSize(80,35));
1114 wxButton *spreadGoBtn = new wxButton(panel,-1,_T("GoA"),wxDefaultPosition, wxSize(80,35));
1115 _wxtextctrlTest = new wxTextCtrl(panel,-1, _T(""),wxDefaultPosition, wxSize(200,150), wxTE_MULTILINE );
1117 _TestFrame->SetEventHandler( this );
1118 Connect( spreadResetBtn->GetId(), wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &wxContourEventHandler::onTestReset );
1119 Connect( spreadAddBtn->GetId(), wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &wxContourEventHandler::onTestAdd );
1120 Connect( spreadGoBtn->GetId(), wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &wxContourEventHandler::onTestGo );
1122 wxFlexGridSizer * sizer = new wxFlexGridSizer(1);
1123 sizer -> Add( spreadResetBtn , 1, wxGROW );
1124 sizer -> Add( spreadAddBtn , 1, wxGROW );
1125 sizer -> Add( spreadGoBtn , 1, wxGROW );
1126 sizer -> Add( _wxtextctrlTest , 1, wxGROW );
1128 panel->SetSizer( sizer );
1129 panel->SetSize( sizepanel );
1130 panel->SetAutoLayout( true );
1134 if (_TestFrame->IsShown()==true)
1136 _TestFrame->Show(false);
1138 _TestFrame->Show(true);
1143 void wxContourEventHandler::onTestReset( wxCommandEvent& event )
1145 _wxtextctrlTest->SetValue(_T(""));
1146 _contourPropagation->resetAppend();
1149 //------------------------------------------------------------------------------------------------------------
1150 void wxContourEventHandler::onTestAdd( wxCommandEvent& event )
1152 std::vector<double> vecX;
1153 std::vector<double> vecY;
1154 std::vector<double> vecZ;
1155 _sceneManager->GetPointsOfActualContour( &vecX , &vecY , &vecZ );
1157 if (vecX.size()!=0){
1158 std::vector<int> tempVector;
1159 _instantPanel->getInstant( tempVector );
1160 int i,size=vecZ.size();
1161 int actualSlice = tempVector[1];
1162 for ( i=0 ; i<size ; i++ )
1164 vecZ[i] = actualSlice;
1167 _contourPropagation->appendContour(&vecX , &vecY , &vecZ);
1169 newstring.append(_wxtextctrlTest->GetValue());
1170 newstring.append(_T(" "));
1171 newstring.append(wxString(intToString(actualSlice).c_str(),wxConvUTF8));
1172 //newstring.Printf(_T("%s %d -"),, );
1173 newstring.append(_T(" -"));
1174 _wxtextctrlTest->SetValue(newstring);
1178 //------------------------------------------------------------------------------------------------------------
1179 void wxContourEventHandler::onTestGo( wxCommandEvent& event )
1181 std::vector<double> vecX;
1182 std::vector<double> vecY;
1183 std::vector<double> vecZ;
1184 std::vector<int> size;
1186 std::vector<double> vecCtrlPointX;
1187 std::vector<double> vecCtrlPointY;
1188 std::vector<double> vecCtrlPointZ;
1190 //Getting the points of the actual contour
1192 _contourPropagation->GetKeyContours(&vecX , &vecY , &vecZ, &size);
1193 for(int i = 0; i < vecX.size();i++){
1197 /*std::vector<double> vecX1;
1198 std::vector<double> vecY1;
1199 std::vector<double> vecZ1;
1200 _sceneManager->GetPointsOfActualContour( &vecX1 , &vecY1 , &vecZ1 );
1202 std::ofstream file1;
1203 file1.open( "Temp.txt" );
1206 for(int i = 0; i < vecX.size(); i++){
1207 file1<<vecX[i] <<" X1 "<< vecX1[i] <<" Y "<<vecY[i] <<" Y1 "<< vecY1[i] <<" Z "<<vecZ[i] <<" Z1 "<< vecZ1[i]<<std::endl;
1215 //Setting the points of the contour
1217 ExtractControlPoints2D *extractcontrolpoints2d = new ExtractControlPoints2D();
1218 extractcontrolpoints2d->SetContour( &vecX , &vecY , &vecZ );
1220 //Getting the control points of the contour by method A
1222 extractcontrolpoints2d->GetInitialControlPoints( &vecCtrlPointX , &vecCtrlPointY , &vecCtrlPointZ );
1224 std::vector<int> actualInstantVector;
1225 _instantPanel->getInstant( actualInstantVector );
1226 actualInstantVector[1]= this->_theViewPanel->GetZ();
1232 //Adding the Contour to the scene
1234 manualContourModel *manModelContour = new manualContourModel();
1235 int j,sizeCtrPt = vecCtrlPointX.size();
1237 for (j=0 ; j<sizeCtrPt ; j++)
1239 manModelContour->AddPoint( vecCtrlPointX[j] , vecCtrlPointY[j] , vecCtrlPointZ[j] );
1241 std::string theName;
1242 theName = _modelManager->createOutline( manModelContour, actualInstantVector );
1243 bool addedModel = theName.compare("") != 0;
1246 double spc[3];//Si no hay imagen pero hay contornos que spacing se pone por default
1247 this->_theViewPanel->getSpacing(spc);
1248 //Adding the manualContourControler to interface objects structure
1249 //Adding the manualViewContour to interface objects structure
1250 //_sceneManager->setControlActiveStateOfALL( false );//This call is being done here because if the ROI is created underneath the previously created ROIS will still be active.
1251 _sceneManager->configureViewControlTo( theName, manModelContour,spc,1 ) ;
1256 //------------------------------------------------------------------------------------------------------------
1257 void wxContourEventHandler::FillGridWithContoursInformation()
1259 wxString tempString;
1261 _grid->SetColLabelValue(0, _T("A") );
1262 _grid->SetColLabelValue(1, _T("B") );
1263 _grid->SetColLabelValue(2, _T("C") );
1264 _grid->SetColLabelValue(3, _T("D") );
1265 _grid->SetColLabelValue(4, _T("E") );
1266 _grid->SetColLabelValue(5, _T("F") );
1268 std::vector<int> tempVector;
1269 _instantPanel->getInstant( tempVector );
1271 int z,sizeZ = _sceneManager->GetImageDataSizeZ();
1272 int ii,sizeLstContourThings;
1273 for ( z=0 ; z<sizeZ ; z++)
1276 Instant instant(&tempVector);
1277 std::vector<ContourThing**> lstContourThings = this->_modelManager->getOutlinesAtInstant( &instant );
1279 sizeLstContourThings = lstContourThings.size();
1280 tempString.Printf(_T("%d - %d"),z, sizeLstContourThings);
1281 _grid->SetRowLabelValue(z, tempString );
1283 for (ii=0 ; ii<sizeLstContourThings ; ii++)
1285 ContourThing **contourthing = lstContourThings[ii];
1286 tempString = wxString((*contourthing)->getName().c_str(),wxConvUTF8) ;
1287 _grid->SetCellValue( z, ii, tempString );
1294 //------------------------------------------------------------------------------------------------------------
1295 std::vector<manualContourModel*> wxContourEventHandler::ExploseEachModel( std::vector<manualContourModel*> lstManConMod )
1297 std::vector<manualContourModel*> lstTmp;
1298 std::vector<manualContourModel*> lstResult;
1300 int i,iSize=lstManConMod.size();
1301 for (i=0;i<iSize;i++)
1303 lstTmp = lstManConMod[i]->ExploseModel();
1304 jSize=lstTmp.size();
1305 for (j=0;j<jSize;j++)
1307 lstResult.push_back( lstTmp[j] );
1313 //------------------------------------------------------------------------------------------------------------
1314 void wxContourEventHandler::onExtractInformation( wxCommandEvent& event )
1317 int maxContourGroup = 0;
1321 ContourExtractData *contourextractdata = new ContourExtractData();
1322 int typeContourGroup = this->_radiolstboxContourGroup->GetSelection();
1323 contourextractdata ->SetTypeOperation( typeContourGroup % 3 );
1325 std::vector<manualContourModel*> lstManConMod;
1326 std::vector<manualContourModel*> lstManConModTmp;
1327 std::vector<manualContourModel*> lstManConModExp;
1328 std::vector<double> pLstValue;
1329 std::vector<double> pLstValuePosX;
1330 std::vector<double> pLstValuePosY;
1331 std::vector<double> pLstValuePosZ;
1334 int resultGrayRangeCount;
1337 double resultAverage;
1338 double resultStandardeviation;
1340 std::vector<int> tempVector;
1341 _instantPanel->getInstant( tempVector );
1343 vtkImageData *imagedata = _sceneManager->GetImageData();
1344 int sizeZ = _sceneManager->GetImageDataSizeZ();
1346 int ii,sizeLstContourThings;
1355 if (_informationRadiobox->GetSelection()==0 ) // actual slice
1357 std::vector<int> tempVector;
1358 _instantPanel->getInstant( tempVector );
1359 int actualSlice = tempVector[1];
1363 if (_informationRadiobox->GetSelection()==1 ) // slice range
1365 minZ = _mbarrangeSliceInformation->GetStart();
1366 maxZ = _mbarrangeSliceInformation->GetEnd();
1368 if (_informationRadiobox->GetSelection()==2 ) // All slices
1374 totalZ = maxZ-minZ+1;
1375 contourextractdata->SetImage( imagedata);
1378 for ( z=minZ ; z<=maxZ ; z++ )
1380 porcent = 100.0* (z-minZ)/totalZ;
1381 tmpString.Printf(_T(" %d %c %d/%d %d"), (int)porcent , 37 , z-minZ+1, (int)totalZ ,z);
1382 _staticTextInformation->SetLabel(tmpString);
1384 //Extraction data from contours of each slice
1385 contourextractdata->SetZtoBeAnalys( z);
1388 Instant instant(&tempVector);
1389 std::vector<ContourThing**> lstContourThings = this->_modelManager->getOutlinesAtInstant( &instant );
1390 sizeLstContourThings = lstContourThings.size();
1392 lstManConMod.clear();
1393 for (ii=0 ; ii<sizeLstContourThings ; ii++)
1395 ContourThing **contourthing = lstContourThings[ii];
1396 lstManConMod.push_back( (*contourthing)->getModel() );
1398 lstManConModExp = ExploseEachModel( lstManConMod );
1401 wxString tempString;
1402 tempString.Printf(_T("%d - %d"),z, sizeLstContourThings);
1403 _grid->SetRowLabelValue(z, tempString );
1405 int iContourGroup,sizeContourGroup;
1406 if (typeContourGroup==3) // contour separete
1408 sizeContourGroup=lstManConModExp.size();
1409 if ( maxContourGroup<sizeContourGroup )
1411 maxContourGroup=sizeContourGroup;
1413 } else { // contour AND OR XOR
1422 for( iContourGroup=0 ; iContourGroup<sizeContourGroup ; iContourGroup++ ){
1423 lstManConModTmp.clear();
1424 if (typeContourGroup==3) // contour separete
1426 lstManConModTmp.push_back( lstManConModExp[iContourGroup]);
1427 } else { // contour AND OR XOR
1428 lstManConModTmp = lstManConModExp;
1431 contourextractdata->SetLstManualContourModel( lstManConModTmp );
1434 pLstValuePosX.clear();
1435 pLstValuePosY.clear();
1436 pLstValuePosZ.clear();
1437 contourextractdata->GetValuesInsideCrown( &pLstValue,
1441 // Statistics of each slice.
1442 contourextractdata->Statistics( &pLstValue,
1443 _mbarrangeRangeInformation->GetStart(),
1444 _mbarrangeRangeInformation->GetEnd(),
1445 &resultGrayRangeCount,
1450 &resultStandardeviation);
1451 if (_grid->GetNumberCols()<_numberOfVariablesStatistics*(iContourGroup+1) )
1453 _grid->AppendCols(_numberOfVariablesStatistics);
1456 tmpIntA=_numberOfVariablesStatistics*iContourGroup ;
1458 tempString.Printf(_T("%d"),resultSize);
1459 _grid->SetCellValue( z, tmpIntA + 0, tempString );
1460 tempString.Printf(_T("%d"),resultGrayRangeCount);
1461 _grid->SetCellValue( z, tmpIntA + 1, tempString );
1462 tempString.Printf(_T("%f"),resultMin);
1463 _grid->SetCellValue( z, tmpIntA + 2, tempString );
1464 tempString.Printf(_T("%f"),resultMax);
1465 _grid->SetCellValue( z, tmpIntA + 3, tempString );
1466 tempString.Printf(_T("%f"),resultAverage);
1467 _grid->SetCellValue( z, tmpIntA + 4, tempString );
1468 tempString.Printf(_T("%f"),resultStandardeviation);
1469 _grid->SetCellValue( z, tmpIntA + 5, tempString );
1471 } // for iContourGroup
1475 wxString tmpTitleString;
1477 for ( iTitleGroup=0 ; iTitleGroup<maxContourGroup ; iTitleGroup++ )
1479 tmpIntB =_numberOfVariablesStatistics*iTitleGroup;
1480 tmpTitleString.Printf(_T("%d-Size Data"),iTitleGroup);
1481 _grid->SetColLabelValue( tmpIntB + 0, tmpTitleString );
1482 _grid->SetColLabelValue( tmpIntB + 1, _T("Size Range") );
1483 _grid->SetColLabelValue( tmpIntB + 2, _T("Min") );
1484 _grid->SetColLabelValue( tmpIntB + 3, _T("Max") );
1485 _grid->SetColLabelValue( tmpIntB + 4, _T("Average") );
1486 _grid->SetColLabelValue( tmpIntB + 5, _T("St.Dev.") );
1487 _grid->SetColLabelValue( tmpIntB + 6, _T(" ") );
1490 _staticTextInformation->SetLabel( _T("") );
1491 delete contourextractdata;
1495 //------------------------------------------------------------------------------------------------------------
1496 void wxContourEventHandler::SaveValuesXYZ(std::string directory,std::string namefile)
1499 ContourExtractData *contourextractdata = new ContourExtractData();
1500 int typeContourGroup = this->_radiolstboxContourGroup->GetSelection();
1501 contourextractdata ->SetTypeOperation( typeContourGroup % 3 );
1503 std::vector<manualContourModel*> lstManConMod;
1504 std::vector<manualContourModel*> lstManConModTmp;
1505 std::vector<manualContourModel*> lstManConModExp;
1506 std::vector<double> pLstValue;
1507 std::vector<double> pLstValuePosX;
1508 std::vector<double> pLstValuePosY;
1509 std::vector<double> pLstValuePosZ;
1511 std::vector<int> tempVector;
1512 _instantPanel->getInstant( tempVector );
1514 vtkImageData *imagedata = _sceneManager->GetImageData();
1515 int sizeZ = _sceneManager->GetImageDataSizeZ();
1517 int ii,sizeLstContourThings;
1524 minZ = 0;// _mbarrange->GetStart();
1525 maxZ = sizeZ;//_mbarrange->GetEnd();
1526 totalZ = maxZ-minZ+1;
1528 contourextractdata->SetImage( imagedata);
1531 for ( z=0 ; z<sizeZ ; z++)
1534 porcent = 100.0* (z-minZ)/totalZ;
1536 tmpString.Printf(_T("Saving Values"));
1537 tmpString.Printf(_T(" %d %c %d/%d %d"), (int)porcent , 37 , z-minZ+1, (int)totalZ ,z);
1538 _staticTextInformation->SetLabel(tmpString);
1541 //Extraction data from contours of each slice
1542 contourextractdata->SetZtoBeAnalys( z);
1545 Instant instant(&tempVector);
1546 std::vector<ContourThing**> lstContourThings = this->_modelManager->getOutlinesAtInstant( &instant );
1547 sizeLstContourThings = lstContourThings.size();
1549 lstManConMod.clear();
1550 for (ii=0 ; ii<sizeLstContourThings ; ii++)
1552 ContourThing **contourthing = lstContourThings[ii];
1553 lstManConMod.push_back( (*contourthing)->getModel() );
1555 lstManConModExp = ExploseEachModel( lstManConMod );
1560 int iContourGroup,sizeContourGroup;
1561 if (typeContourGroup==3) // contour separete
1563 sizeContourGroup=lstManConModExp.size();
1564 } else { // contour AND OR XOR
1568 for( iContourGroup=0 ; iContourGroup<sizeContourGroup ; iContourGroup++ ){
1569 lstManConModTmp.clear();
1570 if (typeContourGroup==3) // contour separete
1572 lstManConModTmp.push_back( lstManConModExp[iContourGroup]);
1573 } else { // contour AND OR XOR
1574 lstManConModTmp = lstManConModExp;
1577 contourextractdata->SetLstManualContourModel( lstManConModTmp );
1580 pLstValuePosX.clear();
1581 pLstValuePosY.clear();
1582 pLstValuePosZ.clear();
1583 contourextractdata->GetValuesInsideCrown( &pLstValue,
1589 filename.Printf(_T("%s"),directory.c_str());
1590 filename.Printf(_T("\\"));
1591 filename.Printf(_T("%s"),namefile.c_str());
1592 filename.Printf(_T("-slice"));
1593 filename.Printf(_T("%d"),z);
1594 filename.Printf(_T("-cont"));
1595 filename.Printf(_T("%d"),iContourGroup);
1596 filename.Printf(_T(".txt"));
1597 FILE *pFile=fopen((const char *)filename.mb_str(),"w+");
1598 fprintf(pFile,"value \t x \t y \t z\n" );
1599 int iLstValue,sizeLstValue=pLstValue.size();
1600 for (iLstValue=0 ; iLstValue<sizeLstValue ; iLstValue++ )
1602 fprintf(pFile,"%f\t %f\t %f\t %f\n", (float)pLstValue[iLstValue] , (float)pLstValuePosX[iLstValue], (float)pLstValuePosY[iLstValue], (float)z );
1605 } // for iContourGroup
1607 _staticTextInformation->SetLabel( _T("") );
1608 delete contourextractdata;
1612 //------------------------------------------------------------------------------------------------------------
1613 void wxContourEventHandler::SaveImageResult(std::string directory,std::string namefile)
1616 ContourExtractData *contourextractdata = new ContourExtractData( true );
1617 int typeContourGroup = this->_radiolstboxContourGroup->GetSelection();
1618 if (typeContourGroup==3)
1622 contourextractdata ->SetTypeOperation( typeContourGroup % 3 );
1624 std::vector<manualContourModel*> lstManConMod;
1625 std::vector<manualContourModel*> lstManConModTmp;
1626 std::vector<manualContourModel*> lstManConModExp;
1628 std::vector<int> tempVector;
1629 _instantPanel->getInstant( tempVector );
1631 vtkImageData *imagedata = _sceneManager->GetImageData();
1632 int sizeZ = _sceneManager->GetImageDataSizeZ();
1634 int ii,sizeLstContourThings;
1643 minZ = 0;// _mbarrange->GetStart();
1644 maxZ = sizeZ;//_mbarrange->GetEnd();
1645 totalZ = maxZ-minZ+1;
1647 contourextractdata->SetImage( imagedata);
1650 for ( z=0 ; z<sizeZ ; z++)
1653 porcent = 100.0* (z-minZ)/totalZ;
1654 tmpString.Printf(_T("Saving Values"));
1655 tmpString.Printf(_T("%d %c %d/%d %d"), (int)porcent , 37 , z-minZ+1, (int)totalZ ,z);
1656 _staticTextInformation->SetLabel(tmpString);
1658 //Extraction data from contours of each slice
1659 contourextractdata->SetZtoBeAnalys( z);
1662 Instant instant(&tempVector);
1663 std::vector<ContourThing**> lstContourThings = this->_modelManager->getOutlinesAtInstant( &instant );
1664 sizeLstContourThings = lstContourThings.size();
1666 lstManConMod.clear();
1667 for (ii=0 ; ii<sizeLstContourThings ; ii++)
1669 ContourThing **contourthing = lstContourThings[ii];
1670 lstManConMod.push_back( (*contourthing)->getModel() );
1672 lstManConModExp = ExploseEachModel( lstManConMod );
1675 int iContourGroup,sizeContourGroup;
1676 if (typeContourGroup==3) // contour separete
1678 sizeContourGroup=lstManConModExp.size();
1679 } else { // contour AND OR XOR
1683 for( iContourGroup=0 ; iContourGroup<sizeContourGroup ; iContourGroup++ ){
1684 lstManConModTmp.clear();
1685 if (typeContourGroup==3) // contour separete
1687 lstManConModTmp.push_back( lstManConModExp[iContourGroup]);
1688 } else { // contour AND OR XOR
1689 lstManConModTmp = lstManConModExp;
1692 contourextractdata->SetLstManualContourModel( lstManConModTmp );
1695 // for (ii=0 ; ii<sizeLstContourThings ; ii++)
1697 // ContourThing **contourthing = lstContourThings[ii];
1698 // lstManConMod.push_back( (*contourthing)->getModel() );
1700 // contourextractdata->SetLstManualContourModel( lstManConMod );
1702 contourextractdata->CalculateImageResult(); // with actual Z
1704 } // for iContourGroup
1709 //filename.Printf(_T("%s\\%s-Value.mhd",directory.c_str(),namefile.c_str(),z);
1710 filename.Printf(_T("%s"),directory.c_str());
1711 filename.Printf(_T("\\"));
1712 filename.Printf(_T("%s"),namefile.c_str());
1713 filename.Printf(_T("-Value.mhd"));
1716 vtkMetaImageWriter *writerValueImage = vtkMetaImageWriter::New( );
1717 writerValueImage->SetInput( contourextractdata->GetVtkImageValueResult() );
1718 writerValueImage->SetFileName( (const char *)filename.mb_str() );
1719 writerValueImage->SetFileDimensionality( 3 );
1720 writerValueImage->Write( );
1723 // filename.Printf("%s\\%s-Mask.mhd",directory.c_str(),namefile.c_str(),z);
1724 filename.Printf(_T("%s"),directory.c_str());
1725 filename.Printf(_T("\\"));
1726 filename.Printf(_T("%s"),namefile.c_str());
1727 filename.Printf(_T("-Mask.mhd"));
1728 vtkMetaImageWriter *writerMaskImage = vtkMetaImageWriter::New( );
1729 writerMaskImage->SetInput( contourextractdata->GetVtkImageMaskResult() );
1730 writerMaskImage->SetFileName( (const char *)filename.mb_str() );
1731 writerMaskImage->SetFileDimensionality( 3 );
1732 writerMaskImage->Write( );
1734 _staticTextInformation->SetLabel( _T("") );
1735 delete contourextractdata;
1739 //------------------------------------------------------------------------------------------------------------
1740 void wxContourEventHandler::onInformationContourLabels( wxCommandEvent& event )
1743 FillGridWithContoursInformation();
1747 //------------------------------------------------------------------------------------------------------------
1748 void wxContourEventHandler::onSaveResults( wxCommandEvent& event )
1750 wxFileDialog dialog(_InformationContourFrame, _T("Choose a file"), _T(""), _T(""), _T("*.txt"), wxSAVE );
1751 if (dialog.ShowModal() == wxID_OK)
1753 onExtractInformation( event );
1754 std::string directory=(const char *)(dialog.GetDirectory().mb_str());
1755 std::string namefile=(const char *)(dialog.GetFilename().mb_str());
1757 SaveValuesXYZ( directory , namefile );
1758 SaveImageResult( directory , namefile );
1760 std::string filename = (const char *)(dialog.GetPath().mb_str() );
1761 FILE *pFile=fopen(filename.c_str(),"w+");
1763 int sizeZ = _sceneManager->GetImageDataSizeZ();
1766 int i,j,maxX,maxY=sizeZ;
1767 maxX=this->_grid->GetNumberCols();
1769 int iTitle,sizeTitle = (maxX / _numberOfVariablesStatistics);
1770 for ( iTitle=0; iTitle<sizeTitle ; iTitle++)
1772 fprintf(pFile,"-- \t %d-Size \t SizeRange \t Min \t Max \t Ave \t StDv \t" , iTitle,tmpString.char_str() );
1774 fprintf(pFile,"\n" );
1778 for ( j=0; j<maxY ; j++)
1780 fprintf(pFile,"%d\t" , j );
1781 for (i=0 ; i<maxX ; i++){
1782 tmpString = _grid->GetCellValue( j , i );
1783 fprintf(pFile,"%s\t" , (const char *)(tmpString.mb_str()) );
1785 fprintf(pFile,"\n" );
1795 //------------------------------------------------------------------------------------------------------------
1796 void wxContourEventHandler::onInformationContourFrame()
1798 if (_InformationContourFrame==NULL)
1800 _InformationContourFrame = new wxFrame (_theViewPanel, -1,_T(" Information "), wxDefaultPosition, wxDefaultSize, wxFRAME_TOOL_WINDOW|wxSYSTEM_MENU | wxCAPTION | wxCLIP_CHILDREN |wxFRAME_FLOAT_ON_PARENT | wxRESIZE_BORDER );
1801 _InformationContourFrame->SetSize( wxSize(500,450) );
1802 wxSize sizepanel(200,300);
1803 wxPanel *panel = getInformationPanel(_InformationContourFrame);
1804 //JCP 13-10-09 Grouping the panel in a method
1805 /*new wxPanel(_InformationContourFrame,-1,wxDefaultPosition, wxDefaultSize,wxTAB_TRAVERSAL);
1807 wxString lstOptions[4];
1808 lstOptions[0]=_T("Actual Slice");
1809 lstOptions[1]=_T("Range Slices");
1810 lstOptions[2]=_T("All Slices");
1811 _informationRadiobox = new wxRadioBox(panel, -1, _T("Slice analysis"), wxDefaultPosition, wxSize(270,45), 3 , lstOptions, 3, wxRA_SPECIFY_COLS);
1813 wxString lstOptContOperation[5];
1814 lstOptContOperation[0]=_T("AND");
1815 lstOptContOperation[1]=_T("OR");
1816 lstOptContOperation[2]=_T("XOR");
1817 lstOptContOperation[3]=_T("ALL");
1818 _radiolstboxContourGroup = new wxRadioBox(panel, -1, _T("Contour group"), wxDefaultPosition, wxSize(270,45), 4 , lstOptContOperation, 4, wxRA_SPECIFY_COLS);
1820 wxButton *informationContourLabelsBtn = new wxButton(panel,-1,_T("Contour labels"),wxDefaultPosition, wxSize(140,35) );
1821 informationContourLabelsBtn->SetEventHandler( this );
1822 Connect( informationContourLabelsBtn->GetId(), wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &wxContourEventHandler::onInformationContourLabels );
1824 wxButton *statisticsContourBtn = new wxButton(panel,-1,_T("Contour statistics"),wxDefaultPosition, wxSize(140,35) );
1825 statisticsContourBtn->SetEventHandler( this );
1826 Connect( statisticsContourBtn->GetId(), wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &wxContourEventHandler::onExtractInformation );
1828 wxButton *saveResultsBtn = new wxButton(panel,-1,_T("Save statistics results"),wxDefaultPosition, wxSize(140,35) );
1829 saveResultsBtn->SetEventHandler( this );
1830 Connect( saveResultsBtn->GetId(), wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &wxContourEventHandler::onSaveResults );
1833 int sizeZ = this->_sceneManager->GetImageDataSizeZ();
1834 _mbarrangeSliceInformation = new mBarRange(panel,65,65);
1835 _mbarrangeSliceInformation->SetMin(0);
1836 _mbarrangeSliceInformation->SetStart(0);
1837 _mbarrangeSliceInformation-> SetOrientation( true );
1838 _mbarrangeSliceInformation-> setActiveStateTo(true);
1839 _mbarrangeSliceInformation-> setVisibleLabels( true );
1840 _mbarrangeSliceInformation-> setDeviceEndMargin(10);
1841 _mbarrangeSliceInformation-> setRepresentedValues( 0 , sizeZ-1 );
1842 _mbarrangeSliceInformation-> setDeviceBlitStart(10,10);
1843 _mbarrangeSliceInformation-> setIfWithActualDrawed( false );
1844 _mbarrangeSliceInformation-> SetStart( 0 );
1845 _mbarrangeSliceInformation-> SetEnd( sizeZ-1 );
1849 this->_sceneManager->GetImageDataRange(range);
1850 _mbarrangeRangeInformation = new mBarRange(panel,65,65);
1851 _mbarrangeRangeInformation->SetMin(0);
1852 _mbarrangeRangeInformation->SetStart(0);
1853 _mbarrangeRangeInformation-> SetOrientation( true );
1854 _mbarrangeRangeInformation-> setActiveStateTo(true);
1855 _mbarrangeRangeInformation-> setVisibleLabels( true );
1856 _mbarrangeRangeInformation-> setDeviceEndMargin(10);
1857 _mbarrangeRangeInformation-> setRepresentedValues( range[0] , range[1] );
1858 _mbarrangeRangeInformation-> setDeviceBlitStart(10,10);
1859 _mbarrangeRangeInformation-> setIfWithActualDrawed( false );
1860 _mbarrangeRangeInformation-> SetStart( range[0] );
1861 _mbarrangeRangeInformation-> SetEnd( range[1] );
1864 _staticTextInformation = new wxStaticText(panel,-1,_T(" "));
1867 // wxButton *XXXXXXXBtn = new wxButton(panel,-1,_T("Statistics"),wxDefaultPosition, wxSize(180,35) );
1868 // XXXXXXXBtn->SetEventHandler( this );
1869 // Connect( XXXXXXXBtn->GetId(), wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &wxContourEventHandler::onXXXXX );
1872 _grid = new wxGrid( panel,
1875 wxSize( 100, 100 ) );
1877 int i,gridCol=10,gridRow=sizeZ;
1878 _grid->CreateGrid( 0, 0 );
1879 _grid->AppendRows(gridRow);
1880 _grid->AppendCols(gridCol);
1882 for (i=0;i<gridRow;i++)
1884 _grid->SetRowLabelValue(i, _T(" ") );
1886 // _grid->SetColLabelSize(0);
1889 FillGridWithContoursInformation();
1891 wxFlexGridSizer * sizerA = new wxFlexGridSizer(10);
1892 sizerA->Add( _informationRadiobox , 1, wxALL ,2 );
1893 sizerA->Add( _radiolstboxContourGroup , 1, wxALL ,2 );
1895 wxFlexGridSizer * sizerB = new wxFlexGridSizer(10);
1896 sizerB->Add( informationContourLabelsBtn , 1, wxALL ,2 );
1897 sizerB->Add( statisticsContourBtn , 1, wxALL ,2 );
1898 sizerB->Add( saveResultsBtn , 1, wxALL ,2 );
1900 wxFlexGridSizer * sizer = new wxFlexGridSizer(1);
1901 sizer->AddGrowableCol(0);
1902 sizer->AddGrowableRow(7);
1903 sizer->Add( sizerA , 1, wxALL , 0 );
1904 sizer->Add( new wxStaticText(panel ,-1,_T("Slice Range")) , 1, wxALL , 0 );
1905 sizer->Add( _mbarrangeSliceInformation , 1, wxALL|wxGROW , 2 );
1906 sizer->Add( new wxStaticText(panel ,-1,_T("Gray Range")) , 1, wxALL , 0 );
1907 sizer->Add( _mbarrangeRangeInformation , 1, wxALL|wxGROW , 2 );
1908 sizer->Add( sizerB , 1, wxALL , 0 );
1909 sizer->Add( _staticTextInformation , 1, wxALL , 0 );
1910 sizer->Add( _grid , 1, wxEXPAND , 0 );
1914 panel->SetSizer( sizer );
1915 panel->SetSize( wxSize(1500,1500) );
1916 //panel->SetBackgroundColour( wxColour(100,100,100) );
1917 panel->SetAutoLayout( true );
1920 wxBoxSizer * sizerPanel = new wxBoxSizer(wxHORIZONTAL);
1922 // sizerPanel->AddGrowableCol(0);
1923 // sizerPanel->AddGrowableRow(0);
1926 //sizerPanel -> Add( sizer , 1, wxEXPAND ,0);
1927 sizerPanel -> Add( panel->GetSizer() , 1, wxEXPAND ,0);
1932 _InformationContourFrame->SetSizer( sizerPanel );
1933 _InformationContourFrame->SetAutoLayout( true );
1934 _InformationContourFrame->Layout();
1936 _InformationContourFrame->Show();
1938 if (_InformationContourFrame->IsShown()==true)
1940 _InformationContourFrame->Show(false);
1942 FillGridWithContoursInformation();
1943 _InformationContourFrame->Show(true);
1948 wxPanel* wxContourEventHandler::getInformationPanel(wxWindow* parent){
1949 wxPanel *panel = new wxPanel(parent,-1,wxDefaultPosition, wxDefaultSize,wxTAB_TRAVERSAL);
1951 wxString lstOptions[4];
1952 lstOptions[0]=_T("Actual Slice");
1953 lstOptions[1]=_T("Range Slices");
1954 lstOptions[2]=_T("All Slices");
1955 _informationRadiobox = new wxRadioBox(panel, -1, _T("Slice analysis"), wxDefaultPosition, wxSize(270,45), 3 , lstOptions, 3, wxRA_SPECIFY_COLS);
1957 wxString lstOptContOperation[5];
1958 lstOptContOperation[0]=_T("AND");
1959 lstOptContOperation[1]=_T("OR");
1960 lstOptContOperation[2]=_T("XOR");
1961 lstOptContOperation[3]=_T("ALL");
1962 _radiolstboxContourGroup = new wxRadioBox(panel, -1, _T("Contour group"), wxDefaultPosition, wxSize(270,45), 4 , lstOptContOperation, 4, wxRA_SPECIFY_COLS);
1964 wxButton *informationContourLabelsBtn = new wxButton(panel,-1,_T("Contour labels"),wxDefaultPosition, wxSize(140,35) );
1965 informationContourLabelsBtn->SetEventHandler( this );
1966 Connect( informationContourLabelsBtn->GetId(), wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &wxContourEventHandler::onInformationContourLabels );
1968 wxButton *statisticsContourBtn = new wxButton(panel,-1,_T("Contour statistics"),wxDefaultPosition, wxSize(140,35) );
1969 statisticsContourBtn->SetEventHandler( this );
1970 Connect( statisticsContourBtn->GetId(), wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &wxContourEventHandler::onExtractInformation );
1972 wxButton *saveResultsBtn = new wxButton(panel,-1,_T("Save statistics results"),wxDefaultPosition, wxSize(140,35) );
1973 saveResultsBtn->SetEventHandler( this );
1974 Connect( saveResultsBtn->GetId(), wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &wxContourEventHandler::onSaveResults );
1977 int sizeZ = this->_sceneManager->GetImageDataSizeZ();
1978 _mbarrangeSliceInformation = new mBarRange(panel,65,65);
1979 _mbarrangeSliceInformation->SetMin(0);
1980 _mbarrangeSliceInformation->SetStart(0);
1981 _mbarrangeSliceInformation-> SetOrientation( true );
1982 _mbarrangeSliceInformation-> setActiveStateTo(true);
1983 _mbarrangeSliceInformation-> setVisibleLabels( true );
1984 _mbarrangeSliceInformation-> setDeviceEndMargin(10);
1985 _mbarrangeSliceInformation-> setRepresentedValues( 0 , sizeZ-1 );
1986 _mbarrangeSliceInformation-> setDeviceBlitStart(10,10);
1987 _mbarrangeSliceInformation-> setIfWithActualDrawed( false );
1988 _mbarrangeSliceInformation-> SetStart( 0 );
1989 _mbarrangeSliceInformation-> SetEnd( sizeZ-1 );
1993 this->_sceneManager->GetImageDataRange(range);
1994 _mbarrangeRangeInformation = new mBarRange(panel,65,65);
1995 _mbarrangeRangeInformation->SetMin(0);
1996 _mbarrangeRangeInformation->SetStart(0);
1997 _mbarrangeRangeInformation-> SetOrientation( true );
1998 _mbarrangeRangeInformation-> setActiveStateTo(true);
1999 _mbarrangeRangeInformation-> setVisibleLabels( true );
2000 _mbarrangeRangeInformation-> setDeviceEndMargin(10);
2001 _mbarrangeRangeInformation-> setRepresentedValues( range[0] , range[1] );
2002 _mbarrangeRangeInformation-> setDeviceBlitStart(10,10);
2003 _mbarrangeRangeInformation-> setIfWithActualDrawed( false );
2004 _mbarrangeRangeInformation-> SetStart( range[0] );
2005 _mbarrangeRangeInformation-> SetEnd( range[1] );
2008 _staticTextInformation = new wxStaticText(panel,-1,_T(" "));
2011 // wxButton *XXXXXXXBtn = new wxButton(panel,-1,_T("Statistics"),wxDefaultPosition, wxSize(180,35) );
2012 // XXXXXXXBtn->SetEventHandler( this );
2013 // Connect( XXXXXXXBtn->GetId(), wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &wxContourEventHandler::onXXXXX );
2016 _grid = new wxGrid( panel,
2019 wxSize( 100, 100 ) );
2021 int i,gridCol=10,gridRow=sizeZ;
2022 _grid->CreateGrid( 0, 0 );
2023 _grid->AppendRows(gridRow);
2024 _grid->AppendCols(gridCol);
2026 for (i=0;i<gridRow;i++)
2028 _grid->SetRowLabelValue(i, _T(" ") );
2030 // _grid->SetColLabelSize(0);
2033 FillGridWithContoursInformation();
2035 wxFlexGridSizer * sizerA = new wxFlexGridSizer(10);
2036 sizerA->Add( _informationRadiobox , 1, wxALL ,2 );
2037 sizerA->Add( _radiolstboxContourGroup , 1, wxALL ,2 );
2039 wxFlexGridSizer * sizerB = new wxFlexGridSizer(10);
2040 sizerB->Add( informationContourLabelsBtn , 1, wxALL ,2 );
2041 sizerB->Add( statisticsContourBtn , 1, wxALL ,2 );
2042 sizerB->Add( saveResultsBtn , 1, wxALL ,2 );
2044 wxFlexGridSizer * sizer = new wxFlexGridSizer(1);
2045 sizer->AddGrowableCol(0);
2046 sizer->AddGrowableRow(7);
2047 sizer->Add( sizerA , 1, wxALL , 0 );
2048 sizer->Add( new wxStaticText(panel ,-1,_T("Slice Range")) , 1, wxALL , 0 );
2049 sizer->Add( _mbarrangeSliceInformation , 1, wxALL|wxGROW , 2 );
2050 sizer->Add( new wxStaticText(panel ,-1,_T("Gray Range")) , 1, wxALL , 0 );
2051 sizer->Add( _mbarrangeRangeInformation , 1, wxALL|wxGROW , 2 );
2052 sizer->Add( sizerB , 1, wxALL , 0 );
2053 sizer->Add( _staticTextInformation , 1, wxALL , 0 );
2054 sizer->Add( _grid , 1, wxEXPAND , 0 );
2058 panel->SetSizer( sizer );
2059 panel->SetSize( wxSize(1500,1500) );
2060 //panel->SetBackgroundColour( wxColour(100,100,100) );
2061 panel->SetAutoLayout( true );
2065 //------------------------------------------------------------------------------------------------------------
2066 void wxContourEventHandler :: onSpreadInDepth( std::vector<std::string> & keyNamesVector )
2070 //------------------------------------------------------------------------------------------------------------
2071 void wxContourEventHandler :: onOutline_Union_Of( std::vector<std::string> & keyNamesVector )
2075 //------------------------------------------------------------------------------------------------------------
2076 void wxContourEventHandler :: onOutline_Intersection_Of( std::vector<std::string> & keyNamesVector )
2080 //------------------------------------------------------------------------------------------------------------
2081 void wxContourEventHandler :: onOutline_Combination_Of( std::vector<std::string> & keyNamesVector )
2085 //------------------------------------------------------------------------------------------------------------
2086 void wxContourEventHandler :: onOutline_Fragmentation_Of( std::vector<std::string> & keyNamesVector )
2090 //------------------------------------------------------------------------------------------------------------
2091 void wxContourEventHandler :: onOutline_Agrupation_Of( std::vector<std::string> & keyNamesVector )
2095 //------------------------------------------------------------------------------------------------------------
2096 void wxContourEventHandler :: onCopyOutlines( std::vector<std::string> & keyNamesVector )
2098 std::vector<int> tempVector;
2099 _instantPanel->getInstant( tempVector );
2100 _performingOperation->reset();
2101 _performingOperation->setStartCommand( (char)wxContour_ActionCommnadsID::COPY_TOOL );
2102 _performingOperation->setStartOperationInstantVector( tempVector );
2103 _performingOperation->setKeyNamesOperationElems( keyNamesVector );
2106 //------------------------------------------------------------------------------------------------------------
2107 void wxContourEventHandler :: onPasteOutlines( )
2109 char theStartCommand = _performingOperation->getStartCommand();
2110 if ( theStartCommand == wxContour_ActionCommnadsID::COPY_TOOL )
2112 //JCP 20-10-08 Undo redo implementation
2114 //JCP 20-10-08 Undo redo implementation
2117 std::vector<int> tempVector;
2118 _instantPanel->getInstant( tempVector );
2119 _performingOperation->setEndOperationInstantVector ( tempVector );
2120 std::vector<std::string> elems = _performingOperation->getKeyNamesOperationElems();
2121 int i,size = elems.size();
2122 for( i=0; i<size; i++ )
2124 createCopyContourOf( elems[i], tempVector, i>0 );
2131 //------------------------------------------------------------------------------------------------------------
2132 void wxContourEventHandler :: onShowOutlines( std::vector<std::string> & keyNamesVector )
2136 //------------------------------------------------------------------------------------------------------------
2137 void wxContourEventHandler :: onHideOutlines( std::vector<std::string> & keyNamesVector )
2141 //------------------------------------------------------------------------------------------------------------
2142 void wxContourEventHandler :: onSelectOutlines( std::vector<std::string> & keyNamesVector )
2144 //if( keyNamesVector.empty() )
2146 _sceneManager->drawSelectionROI( );
2150 int ok = keyNamesVector.size();
2151 _sceneManager->selectObjects( keyNamesVector );
2152 std::string name = keyNamesVector[0];
2155 _sceneManager->drawSelectionROI( );
2156 std::vector<std::string> currentSelection = _sceneManager->getSelectedObjects();
2157 int ok = currentSelection.size();
2158 _sceneManager->selectObjects( currentSelection );*/
2160 //------------------------------------------------------------------------------------------------------------
2161 void wxContourEventHandler :: onEditOutlines( std::vector<std::string> & keyNamesVector )
2165 //------------------------------------------------------------------------------------------------------------
2167 //------------------------------------------------------------------------------------------------------------
2168 void wxContourEventHandler :: deleteContour( std::string theKeyName )
2170 manualContourModel * cModel;
2171 manualViewBaseContour * cViewer;
2172 manualContourBaseControler * cControler;
2174 ContourWrap_ViewControl *conwrapviewControl = _sceneManager->getContourWrap_ViewControlOf( theKeyName );
2175 cControler = conwrapviewControl->getControler();
2176 int ispartofstaticlst= _modelManager->IsPartOfStaticList(theKeyName);
2177 if ((cControler!=NULL) && (cControler->IsEditable()==false) && (ispartofstaticlst==-1) )
2179 _sceneManager->removeFromScene( theKeyName );
2180 cModel = _modelManager->getOutlineByKeyName(theKeyName)->getModel();
2181 _modelManager->removeOutline( theKeyName );
2182 cViewer = conwrapviewControl->getViewer();
2183 _sceneManager->removeWrap( theKeyName );
2185 //FILE *ff = fopen("c:/temp/wxVtkBaseView_SceneManagerStadistics.txt","a+");
2186 //fprintf(ff,"EED wxContourEventHandler::deleteContours() \n" );
2187 //fprintf(ff," %s %p\n",keyNamesVector[i].c_str(), cControler );
2195 //------------------------------------------------------------------------------------------------------------
2196 void wxContourEventHandler :: deleteContours( std::vector<std::string> keyNamesVector )
2198 int i,size=keyNamesVector.size();
2199 for (i=0;i<size;i++)
2201 deleteContour( keyNamesVector[i] );
2205 //------------------------------------------------------------------------------------------------------------
2206 void wxContourEventHandler :: deleteAllContours( )
2209 std::vector<int> tempVector;
2210 _instantPanel->getInstant( tempVector );
2212 //JCP --08-09-2008 When using a diferent interface the _mbarrangeDeleteAll might not be initialize
2213 // the values in GetStart and GetEnd will then not be initialize also.
2214 // We use instead the values given when initializing the _deletepanel.
2216 //int minZ = _mbarrangeDeleteAll->GetStart();
2217 //int maxZ = _mbarrangeDeleteAll->GetEnd();
2221 maxZ = _sceneManager->GetImageDataSizeZ();
2225 _sceneManager->removeSceneContours( );
2226 _modelManager->removeAllOutlines();
2227 _sceneManager->removeAllOutlines();
2230 if ( (minZ==0) && (maxZ==_mbarrangeDeleteAll->GetMax() ))
2232 _sceneManager->removeSceneContours( );
2233 _modelManager->removeAllOutlines();
2234 _sceneManager->removeAllOutlines();
2237 for ( z=minZ ; z<=maxZ ; z++)
2240 Instant instant(&tempVector);
2241 std::vector<ContourThing**> lstContourThings = this->_modelManager->getOutlinesAtInstant( &instant );
2243 sizeLstContourThings = lstContourThings.size();
2244 for (ii=0 ; ii<sizeLstContourThings ; ii++)
2246 ContourThing **contourthing = lstContourThings[ii];
2247 deleteContour( (*contourthing)->getName() );
2254 //------------------------------------------------------------------------------------------------------------
2255 void wxContourEventHandler::openContours( FILE *pFile, bool staticContour )
2258 fscanf(pFile,"%s",tmp); // NumberOfContours
2259 fscanf(pFile,"%s",tmp); // ##
2260 int numberOfContours = atoi(tmp);
2262 std::vector<int> instantVector;
2263 int typeContourModel;
2264 manualContourModel *manModelContour;
2268 for (i=0;i<numberOfContours;i++)
2270 instantVector.clear();
2271 fscanf(pFile,"%s",tmp); // Instant
2273 fscanf(pFile,"%s",tmp); // 1
2274 instantVector.push_back( atoi(tmp) );
2275 fscanf(pFile,"%s",tmp); // 2
2276 instantVector.push_back( atoi(tmp) );
2277 fscanf(pFile,"%s",tmp); // 3
2278 instantVector.push_back( atoi(tmp) );
2279 fscanf(pFile,"%s",tmp); // 4
2280 instantVector.push_back( atoi(tmp) );
2281 fscanf(pFile,"%s",tmp); // 5
2282 instantVector.push_back( atoi(tmp) );
2283 fscanf(pFile,"%s",tmp); // 6
2284 instantVector.push_back( atoi(tmp) );
2287 fscanf(pFile,"%s",tmp); // TypeContourModel
2288 fscanf(pFile,"%s",tmp); // ##
2289 typeContourModel = atoi(tmp);
2291 manModelContour = factoryManualContourModel(typeContourModel);
2292 manModelContour->Open(pFile);
2294 fscanf(pFile,"%s",tmp); // TypeView
2295 fscanf(pFile,"%s",tmp); // ##
2296 typeView = atoi(tmp);
2304 std::string theName;
2305 theName = _modelManager->createOutline( manModelContour, instantVector );
2306 bool addedModel = theName.compare("") != 0;
2309 double spc[3];//Si no hay imagen pero hay contornos que spacing se pone por default
2310 this->_theViewPanel->getSpacing(spc);
2311 //Adding the manualContourControler to interface objects structure
2312 //Adding the manualViewContour to interface objects structure
2313 //_sceneManager->setControlActiveStateOfALL( false );//This call is being done here because if the ROI is created underneath the previously created ROIS will still be active.
2314 _sceneManager->configureViewControlTo( theName, manModelContour,spc , typeView) ;
2317 if (staticContour==true)
2319 Instant instant(&instantVector);
2320 changeContourOfManager( theName , &instant );
2323 }// for numberOfContours
2329 //------------------------------------------------------------------------------------------------------------
2330 void wxContourEventHandler::openFileWithContours()
2333 wxFileDialog dialog(NULL, _T("Choose a file"), _T(""), _T(""), _T("*.roi"), wxOPEN );
2334 if (dialog.ShowModal() == wxID_OK)
2336 fileNameContourROI = (const char *)(dialog.GetPath().mb_str());
2337 FILE *pFile=fopen(fileNameContourROI.c_str(),"r+");
2339 fscanf(pFile,"%s",tmp); // --CreaContour--
2341 fscanf(pFile,"%s",tmp); // Version
2342 fscanf(pFile,"%s",tmp); // 1.0.1
2343 std::string version(tmp);
2345 openContours(pFile,false);
2346 if (version!="1.0.0"){
2347 openContours(pFile,true);
2349 // _sceneManager->openFileWithContours(ff);
2353 _sceneManager->removeSceneContours();
2355 //updateInstantOutlines();
2359 //------------------------------------------------------------------------------------------------------------
2360 void wxContourEventHandler::saveFileWithContours( std::string filename )
2362 FILE *pFile=fopen(filename.c_str(),"w+");
2363 std::vector< std::string > lstNameThings;
2364 int i,sizeLstNameThings;
2366 fprintf(pFile,"--CreaContour--\n");
2367 fprintf(pFile,"Version %s\n", "1.0.1" );
2370 lstNameThings = _modelManager->GetLstNameThings();
2371 sizeLstNameThings = lstNameThings.size();
2372 fprintf(pFile,"NumberOfContours %d\n", sizeLstNameThings );
2373 for (i=0 ; i<sizeLstNameThings ; i++)
2375 _modelManager->SaveThingName( pFile, lstNameThings[i] );
2376 _sceneManager->SaveThingName( pFile, lstNameThings[i] );
2379 //-- Contours Statics
2380 lstNameThings = _modelManager->GetLstNameThingsStatic();
2381 sizeLstNameThings = lstNameThings.size();
2382 fprintf(pFile,"NumberOfContoursStatic %d\n", sizeLstNameThings );
2383 for (i=0 ; i<sizeLstNameThings ; i++)
2385 _modelManager->SaveThingName( pFile, lstNameThings[i] );
2386 _sceneManager->SaveThingName( pFile, lstNameThings[i] );
2392 //----------------------------------------------------------
2394 void wxContourEventHandler::saveFileWithContours()
2396 wxFileDialog dialog(NULL, _T("Choose a file"), _T(""), _T(""), _T("*.roi"), wxSAVE );
2397 if (dialog.ShowModal() == wxID_OK)
2399 fileNameContourROI = (const char *)(dialog.GetPath().mb_str());
2400 saveFileWithContours( fileNameContourROI );
2404 //------------------------------------------------------------------------------------------------------------
2405 void wxContourEventHandler :: saveFileWithContoursAutomatique()
2407 if (fileNameContourROI=="")
2409 saveFileWithContours();
2411 saveFileWithContours(fileNameContourROI);
2416 //------------------------------------------------------------------------------------------------------------
2417 void wxContourEventHandler :: createCopyContourOf ( std::string anExistingKName, std::vector<int> &instantNoTouchData, bool append )
2419 std::string cloneName = _modelManager->createCopyContourOf( anExistingKName, instantNoTouchData );
2420 manualContourModel * manualModel = _modelManager->getOutlineByKeyName( cloneName )->getModel();
2421 _sceneManager->createCopyContourOf( anExistingKName, cloneName, manualModel , append );
2425 //------------------------------------------------------------------------------------------------------------
2426 manualContourModel * wxContourEventHandler::factoryManualContourModel(int typeContour)
2428 manualContourModel *manModelContour=NULL;
2433 manModelContour = new manualContourModel();
2439 manModelContour = new manualContourModel();
2445 manModelContour = new manualContourModelRoi();
2451 manModelContour = new manualContourModelCircle();
2457 manualContourModelBullEye *manModelContourBullEye = new manualContourModelBullEye();
2458 manModelContour = manModelContourBullEye;
2459 if (_panelBullEyeOptions!=NULL){
2460 int iCrown,sizeCrowns,iSector,sizeSectors;
2461 double radioA,radioB,ang,angDelta ;
2462 sizeCrowns = _panelBullEyeOptions->GetNumberOfCrowns();
2463 for ( iCrown=0 ; iCrown<sizeCrowns ; iCrown++ )
2465 sizeSectors = _panelBullEyeOptions->GetNumberOfSections(iCrown);
2466 radioB = _panelBullEyeOptions->GetRadioOfCrown(iCrown);
2467 if (iCrown==sizeCrowns-1)
2471 radioA = _panelBullEyeOptions->GetRadioOfCrown(iCrown+1);
2473 radioA=radioA/100.0;
2474 radioB=radioB/100.0;
2475 for ( iSector=0 ; iSector<sizeSectors ; iSector++ )
2477 ang = _panelBullEyeOptions->GetAngOfCrownSection(iCrown,iSector);
2478 angDelta= _panelBullEyeOptions->GetAngDeltaOfCrownSection(iCrown);
2479 manModelContourBullEye->AddSector(radioA,radioB,ang,angDelta);
2482 } // if _panelBullEyeOptions
2483 }// if typeContour==4
2485 return manModelContour;
2488 //------------------------------------------------------------------------------------------------------------
2489 void wxContourEventHandler :: createContour( int typeContour )
2491 //Creating the manualContourModel and including in the model
2492 manualContourModel * manModelContour = factoryManualContourModel(typeContour);
2493 std::vector<int> instantVector;
2494 _instantPanel->getInstant( instantVector );
2495 std::string theName;
2496 theName= _modelManager->createOutline( manModelContour, instantVector );
2497 bool addedModel = theName.compare("") != 0;
2500 double spc[3];//Si no hay imagen pero hay contornos que spacing se pone por default
2501 this->_theViewPanel->getSpacing(spc);
2502 //Adding the manualContourControler to interface objects structure
2503 //Adding the manualViewContour to interface objects structure
2504 //_sceneManager->setControlActiveStateOfALL( false );//This call is being done here because if the ROI is created underneath the previously created ROIS will still be active.
2505 _sceneManager->configureViewControlTo( theName, manModelContour,spc , typeContour) ;
2509 //FILE *ff = fopen("c:/temp/wxVtkBaseView_SceneManagerStadistics.txt","a+");
2510 //fprintf(ff,"EED wxContourEventHandler::createContour() \n" );
2511 //fprintf(ff," %s\n %p ",theName.c_str() , );
2516 manualContourModel * wxContourEventHandler::factoryManualContourModel(PanelBullEyeOptions* panel){
2518 manualContourModelBullEye *manModelContourBullEye = new manualContourModelBullEye();
2519 manualContourModel *manModelContour=NULL;
2520 manModelContour = manModelContourBullEye;
2522 int iCrown,sizeCrowns,iSector,sizeSectors;
2523 double radioA,radioB,ang,angDelta ;
2524 sizeCrowns = panel->GetNumberOfCrowns();
2525 for ( iCrown=0 ; iCrown<sizeCrowns ; iCrown++ )
2527 sizeSectors = panel->GetNumberOfSections(iCrown);
2528 radioB = panel->GetRadioOfCrown(iCrown);
2529 if (iCrown==sizeCrowns-1)
2533 radioA = panel->GetRadioOfCrown(iCrown+1);
2535 radioA=radioA/100.0;
2536 radioB=radioB/100.0;
2537 for ( iSector=0 ; iSector<sizeSectors ; iSector++ )
2539 ang = panel->GetAngOfCrownSection(iCrown,iSector);
2540 angDelta= panel->GetAngDeltaOfCrownSection(iCrown);
2541 manModelContourBullEye->AddSector(radioA,radioB,ang,angDelta);
2544 } // if _panelBullEyeOptions
2546 return manModelContour;
2549 void wxContourEventHandler :: createContourBullsEye(PanelBullEyeOptions* panel )
2551 //Creating the manualContourModel and including in the model
2552 manualContourModel * manModelContour = factoryManualContourModel(panel );
2553 std::vector<int> instantVector;
2554 _instantPanel->getInstant( instantVector );
2555 std::string theName;
2556 theName= _modelManager->createOutline( manModelContour, instantVector );
2557 bool addedModel = theName.compare("") != 0;
2560 double spc[3];//Si no hay imagen pero hay contornos que spacing se pone por default
2561 this->_theViewPanel->getSpacing(spc);
2562 //Adding the manualContourControler to interface objects structure
2563 //Adding the manualViewContour to interface objects structure
2564 //_sceneManager->setControlActiveStateOfALL( false );//This call is being done here because if the ROI is created underneath the previously created ROIS will still be active.
2565 _sceneManager->configureViewControlTo( theName, manModelContour,spc , 4) ;
2569 //FILE *ff = fopen("c:/temp/wxVtkBaseView_SceneManagerStadistics.txt","a+");
2570 //fprintf(ff,"EED wxContourEventHandler::createContour() \n" );
2571 //fprintf(ff," %s\n %p ",theName.c_str() , );
2577 //------------------------------------------------------------------------------------------------------------
2578 // Attributes getters and setters
2579 //------------------------------------------------------------------------------------------------------------
2581 void wxContourEventHandler :: setModelManager( OutlineModelManager * theModelManager )
2583 _modelManager = theModelManager;
2584 _workSpace = _modelManager->getContourWorkspace();
2586 //------------------------------------------------------------------------------------------------------------
2587 void wxContourEventHandler :: setViewPanel( wxContourViewPanel * theViewPanel )
2589 _theViewPanel = theViewPanel;
2590 _theViewPanel->setWxEventHandler( this );
2593 this->_theViewPanel->getSpacing(spc);
2594 _sceneManager = new wxVtkBaseView_SceneManager ( this->_theViewPanel->getWxVtkBaseView(), this, spc );
2596 Connect( _theViewPanel->GetId(), wxINSTANT_CHANGE, (wxObjectEventFunction) (wxCommandEventFunction) &wxContourEventHandler::onChangeInstant );
2597 Connect( wxID_ANY, wxEVT_START_CREATE_MULT_ROI, (wxObjectEventFunction) (wxCommandEventFunction) &wxContourEventHandler::onCreateMultipleROI );
2598 Connect( wxID_ANY, wxEVT_START_CREATE_ROI, (wxObjectEventFunction) (wxCommandEventFunction) &wxContourEventHandler::onCreateROI );
2599 Connect( wxID_ANY, wxEVT_STOP_CREATE_ROI, (wxObjectEventFunction) (wxCommandEventFunction) &wxContourEventHandler::onStopCreateROI );
2600 Connect( wxID_ANY, wxEVT_CHANGED_DEEP, (wxObjectEventFunction) (wxCommandEventFunction) &wxContourEventHandler::onChangedDeep );
2601 Connect( wxID_ANY, wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &wxContourEventHandler :: onActionButtonPressed );
2606 //------------------------------------------------------------------------------------------------------------
2607 void wxContourEventHandler :: setInstantChooserPanel( wxInstantChooserPanel * theInstantChooserPanel )
2609 _instantPanel = theInstantChooserPanel;
2610 _instantPanel->setWxEventHandler( this );
2612 Connect( _instantPanel->GetId(), wxINSTANT_CHOOSER_CHANGE, (wxObjectEventFunction) (wxCommandEventFunction) &wxContourEventHandler::onChangeInstant );
2614 std::vector<int> vect;
2615 _instantPanel->getInstant( vect );
2616 _actualInstant = new Instant( &vect );
2618 if( _modelManager!=NULL )
2620 std::vector<std::string> conceptNameVect;
2621 std::vector<int> conceptSizeVect;
2622 _modelManager-> getConceptsInformation(conceptNameVect, conceptSizeVect);
2624 int max = conceptNameVect.size();
2627 if( conceptNameVect[i].compare("Axe Depth") == 0 )
2629 _instantPanel->addConcept( conceptNameVect[i], 0, conceptSizeVect[i], 1);
2631 _instantPanel->addConcept( conceptNameVect[i], 1, conceptSizeVect[i], 1);
2635 //Should be configured later, or abort program, because Model -NEEDS- to be added before chooserPanel
2637 if( _theViewPanel!=NULL )
2639 double val = _theViewPanel->getCurrentDeep();
2640 _instantPanel->setConceptValue( "Axe Depth", (int)val );
2641 ConceptDataWrap * data = _instantPanel->getConceptDataOf( "Axe Depth" );
2643 _theViewPanel->setVerticalConcept( "Axe Depth", data->getMinValue(), data->getMaxValue(), data->getMinShowedValue(), data->getMaxShowedValue(), data->getActualValue() );
2645 //Should be configured later, or abort program, because ViewPanel -NEEDS- to be added before chooserPanel
2650 //------------------------------------------------------------------------------------------------------------
2651 void wxContourEventHandler :: setButtonsBar( wxContour_ButtonsBar * theButtonsBar )
2653 _buttonsBar = theButtonsBar;
2654 _buttonsBar->setWxEventHandler( this );
2655 Connect( _buttonsBar->GetId(), wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &wxContourEventHandler:: onActionButtonPressed );
2657 //------------------------------------------------------------------------------------------------------------
2658 void wxContourEventHandler :: setGrid( wxContour_Grid * theGridPanel )
2660 _gridPanel = theGridPanel;
2662 //------------------------------------------------------------------------------------------------------------
2663 void wxContourEventHandler :: setDrawToolsPanel( wxContour_DrawToolsPanel * theDrawToolsPanel )
2665 _drawToolsPanel = theDrawToolsPanel;
2667 //------------------------------------------------------------------------------------------------------------
2668 void wxContourEventHandler :: setOperationsToolsPanel( wxContour_OperationsToolsPanel * theOperationsToolsPanel )
2670 _operationsToolsPanel = theOperationsToolsPanel;
2672 //------------------------------------------------------------------------------------------------------------
2673 void wxContourEventHandler :: setAutomaticFormsPanel( wxContour_AutomaticFormsToolsPanel * theAutoFormsPanel )
2675 _autoFormsPanel = theAutoFormsPanel;
2678 void wxContourEventHandler :: setStandardToolsPanel( wxContour_StandardToolsPanel * theStandardToolsPanel )
2680 _standardToolsPanel= theStandardToolsPanel;
2682 //------------------------------------------------------------------------------------------------------------
2683 void wxContourEventHandler :: setEditionToolsPanel( wxContour_EdtionToolsPanel * theEditionToolsPanel )
2685 _editionToolsPanel = theEditionToolsPanel;
2688 //------------------------------------------------------------------------------------------------------------
2689 void wxContourEventHandler :: setListViewPanel( wxContour_ListViewPanel * theListViewPanel )
2691 _listViewPanel = theListViewPanel;
2693 //------------------------------------------------------------------------------------------------------------
2694 // Other functional methods
2695 //------------------------------------------------------------------------------------------------------------
2698 //------------------------------------------------------------------------------------------------------------
2699 void wxContourEventHandler::onDeleteContour( wxCommandEvent& event )
2702 //JCP 20-10-08 Undo redo implementation
2704 //JCP 20-10-08 Undo redo implementation
2707 int i,size=_sceneManager->getSelectedObjects().size();
2710 std::string keyName = _sceneManager->getSelectedObjects()[i];
2711 int ispartofstaticlist = this->_modelManager->IsPartOfStaticList( keyName );
2712 if ( ispartofstaticlist>=0 )
2714 std::vector<int> tempVector;
2715 _instantPanel->getInstant( tempVector );
2716 Instant instant(&tempVector);
2717 this->_modelManager->ChangeContourOfList(keyName, &instant);
2721 std::vector<std::string> lstKeyName;
2722 std::vector<std::string> lstKeyNameActualSlice;
2723 std::vector<std::string> lstKeyNameToBeErase;
2725 lstKeyNameToBeErase = _sceneManager->getSelectedObjects();
2726 lstKeyNameActualSlice = _sceneManager->GetlstContoursNameActualSlice();
2727 int k,kSize=lstKeyNameToBeErase.size();
2728 int j,jSize=lstKeyNameActualSlice.size();
2730 for (k=0;k<kSize; k++)
2733 for (j=0;j<jSize; j++)
2735 if (lstKeyNameToBeErase[k]==lstKeyNameActualSlice[j])
2742 lstKeyName.push_back( lstKeyNameToBeErase[k] );
2746 deleteContours( lstKeyName );
2751 //------------------------------------------------------------------------------------------------------------
2752 void wxContourEventHandler::onDeleteContoursActSlice( wxCommandEvent& event )
2754 //JCP 20-10-08 Undo redo implementation
2756 //JCP 20-10-08 Undo redo implementation
2757 deleteContours( (std::vector<std::string>)_sceneManager->GetlstContoursNameActualSlice() );
2762 //------------------------------------------------------------------------------------------------------------
2763 void wxContourEventHandler::onDeleteAllContours( wxCommandEvent& event )
2765 //JCP 20-10-08 Undo redo implementation
2767 //JCP 20-10-08 Undo redo implementation
2768 deleteAllContours( );
2773 //------------------------------------------------------------------------------------------------------------
2774 void wxContourEventHandler :: onDeleteFrame( )
2776 if (_deleteFrame==NULL)
2778 _deleteFrame = new wxFrame (_theViewPanel, -1,_T(" Delete Contour "), wxDefaultPosition, wxDefaultSize, wxFRAME_TOOL_WINDOW|wxSYSTEM_MENU | wxCAPTION | wxCLIP_CHILDREN |wxFRAME_FLOAT_ON_PARENT );
2780 wxSize sizepanel(width,230);
2781 _deleteFrame->SetSize( sizepanel );
2782 wxPanel *panel = new wxPanel(_deleteFrame,-1);
2783 wxButton *deleteContourBtn = new wxButton(panel,-1,_T("Delete contour selected"),wxDefaultPosition, wxSize(width-10,35) );
2784 wxButton *deleteContoursActSliceBtn = new wxButton(panel,-1,_T("Delete contours of actual slice"),wxDefaultPosition, wxSize(width-10,35));
2785 wxButton *deleteAllContoursBtn = new wxButton(panel,-1,_T("Delete all contours"),wxDefaultPosition, wxSize(width-10,35));
2787 int sizeZ = _sceneManager->GetImageDataSizeZ();
2788 _mbarrangeDeleteAll = new mBarRange(panel,70, 65);
2789 _mbarrangeDeleteAll->SetMin(0);
2790 _mbarrangeDeleteAll->SetStart(0);
2792 _mbarrangeDeleteAll-> SetOrientation( true );
2793 _mbarrangeDeleteAll-> setActiveStateTo(true);
2794 _mbarrangeDeleteAll-> setVisibleLabels( true );
2795 _mbarrangeDeleteAll-> setDeviceEndMargin(10);
2796 _mbarrangeDeleteAll-> setRepresentedValues( 0 , sizeZ );
2797 _mbarrangeDeleteAll-> setDeviceBlitStart(10,10);
2798 _mbarrangeDeleteAll-> setIfWithActualDrawed( false );
2799 _mbarrangeDeleteAll-> SetStart( 0 );
2800 _mbarrangeDeleteAll-> SetEnd( sizeZ );
2803 _deleteFrame->SetEventHandler( this );
2804 Connect( deleteContourBtn->GetId() , wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &wxContourEventHandler::onDeleteContour );
2805 Connect( deleteContoursActSliceBtn->GetId() , wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &wxContourEventHandler::onDeleteContoursActSlice );
2806 Connect( deleteAllContoursBtn->GetId() , wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &wxContourEventHandler::onDeleteAllContours );
2808 wxFlexGridSizer * sizer = new wxFlexGridSizer(1);
2809 sizer -> Add( deleteContourBtn , 1, wxGROW );
2810 sizer -> Add( deleteContoursActSliceBtn , 1, wxGROW );
2811 sizer -> Add( deleteAllContoursBtn , 1, wxGROW );
2812 sizer -> Add( _mbarrangeDeleteAll , 1, wxGROW );
2814 panel->SetSizer( sizer );
2815 panel->SetSize( sizepanel );
2816 panel->SetAutoLayout( true );
2818 _deleteFrame->Show(true);
2820 if (_deleteFrame->IsShown()==true)
2822 _deleteFrame->Show(false);
2824 _deleteFrame->Show(true);
2830 //------------------------------------------------------------------------------------------------------------
2831 void wxContourEventHandler::onCreateContourSpline( wxCommandEvent& event )
2834 //JCP 20-10-08 Undo redo implementation
2836 //JCP 20-10-08 Undo redo implementation
2843 //------------------------------------------------------------------------------------------------------------
2844 void wxContourEventHandler::onCreateContourRectangle( wxCommandEvent& event )
2847 //JCP 20-10-08 Undo redo implementation
2849 //JCP 20-10-08 Undo redo implementation
2855 //------------------------------------------------------------------------------------------------------------
2856 void wxContourEventHandler::onCreateContourCircle( wxCommandEvent& event )
2858 //JCP 20-10-08 Undo redo implementation
2860 //JCP 20-10-08 Undo redo implementation
2865 //------------------------------------------------------------------------------------------------------------
2866 void wxContourEventHandler::onCreateContourBullEye( wxCommandEvent& event )
2868 //JCP 20-10-08 Undo redo implementation
2870 //JCP 20-10-08 Undo redo implementation
2879 //------------------------------------------------------------------------------------------------------------
2880 void wxContourEventHandler :: onCreateContourFrame( )
2882 if (_createContourFrame==NULL)
2884 _createContourFrame = new wxFrame (_theViewPanel, -1,_T(" New Contour "), wxDefaultPosition, wxDefaultSize, wxFRAME_TOOL_WINDOW|wxSYSTEM_MENU | wxCAPTION | wxCLIP_CHILDREN |wxFRAME_FLOAT_ON_PARENT | wxRESIZE_BORDER );
2885 wxSize sizepanel(490,600);
2886 _createContourFrame->SetSize( sizepanel );
2887 wxPanel *panel = new wxPanel(_createContourFrame,-1);
2888 wxButton *newContourSplineBtn = new wxButton(panel,-1,_T("Interpolation B-spline (close)"),wxDefaultPosition, wxSize(180,35) );
2889 newContourSplineBtn->SetToolTip(_T("CTRL-N"));
2890 wxButton *newContourRectangleBtn = new wxButton(panel,-1,_T("Rectangle"),wxDefaultPosition, wxSize(180,35));
2891 wxButton *newContourCircleBtn = new wxButton(panel,-1,_T("Circle"),wxDefaultPosition, wxSize(180,35));
2892 wxButton *newContourStarBtn = new wxButton(panel,-1,_T("Bull eye"),wxDefaultPosition, wxSize(180,35));
2894 _panelBullEyeOptions = new PanelBullEyeOptions(panel, wxSize(100,200));
2896 _createContourFrame->SetEventHandler( this );
2897 Connect( newContourSplineBtn->GetId() , wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &wxContourEventHandler::onCreateContourSpline );
2898 Connect( newContourRectangleBtn->GetId() , wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &wxContourEventHandler::onCreateContourRectangle );
2899 Connect( newContourCircleBtn->GetId() , wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &wxContourEventHandler::onCreateContourCircle );
2900 Connect( newContourStarBtn->GetId() , wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &wxContourEventHandler::onCreateContourBullEye );
2902 wxFlexGridSizer * sizer = new wxFlexGridSizer(1);
2903 sizer -> Add( newContourSplineBtn , 1, wxGROW );
2904 sizer -> Add( newContourRectangleBtn , 1, wxGROW );
2905 sizer -> Add( newContourCircleBtn , 1, wxGROW );
2906 sizer -> Add( newContourStarBtn , 1, wxGROW );
2907 sizer -> Add( _panelBullEyeOptions , 1, wxGROW );
2909 panel->SetSizer( sizer );
2910 panel->SetSize( sizepanel );
2911 panel->SetAutoLayout( true );
2913 _createContourFrame->Show(true);
2915 if (_createContourFrame->IsShown()==true)
2917 _createContourFrame->Show(false);
2919 _createContourFrame->Show(true);
2925 //------------------------------------------------------------------------
2926 void wxContourEventHandler::RefreshInterface()
2929 wxVtk2DBaseView *wxvtk2dbaseview = (wxVtk2DBaseView*)this->_theViewPanel->getWxVtkBaseView();
2930 wxvtk2dbaseview->Refresh();
2933 //------------------------------------------------------------------------
2934 void wxContourEventHandler::onWidthOfContour(wxScrollEvent& event){
2935 _sceneManager->removeSceneContours();
2936 double width = (double)_withOfContourLine->GetValue() / 2.0;
2937 _sceneManager->SetWidthContour( width );
2942 //------------------------------------------------------------------------
2944 void wxContourEventHandler::onBrigthnessColorWindowLevel(wxScrollEvent& event){
2945 int colorwindow = _brithtnessColorLevel->GetValue();
2946 int windowlevel = _brithtnessWindowLevel->GetValue();
2947 wxVtk2DBaseView *wxvtk2dbaseview = (wxVtk2DBaseView*)this->_theViewPanel->getWxVtkBaseView();
2948 vtkImageViewer2 *imageviewer = wxvtk2dbaseview->_imageViewer2XYZ->GetVtkImageViewer2();
2949 imageviewer->SetColorWindow(colorwindow);
2950 imageviewer->SetColorLevel(windowlevel);
2951 // wxvtk2dbaseview->Refresh();
2955 void wxContourEventHandler::OnInterpolation(wxCommandEvent& event)
2957 wxVtk2DBaseView *wxvtk2dbaseview = (wxVtk2DBaseView*)this->_theViewPanel->getWxVtkBaseView();
2958 vtkImageViewer2 *imageviewer = wxvtk2dbaseview->_imageViewer2XYZ->GetVtkImageViewer2();
2959 if (_interpolationCheckBox->GetValue()==true)
2961 imageviewer->GetImageActor()->InterpolateOn();
2963 imageviewer->GetImageActor()->InterpolateOff();
2969 //------------------------------------------------------------------------------------------------------------
2970 void wxContourEventHandler :: onInterfaceConfigurationFrame( )
2972 if (_interfaceConfigurationFrame==NULL)
2974 _interfaceConfigurationFrame = new wxFrame (_theViewPanel, -1,_T(" Interface Configuration "), wxDefaultPosition, wxDefaultSize, wxFRAME_TOOL_WINDOW|wxSYSTEM_MENU | wxCAPTION | wxCLIP_CHILDREN |wxFRAME_FLOAT_ON_PARENT );
2975 wxSize sizepanel(190,400);
2976 _interfaceConfigurationFrame->SetSize( sizepanel );
2977 _interfaceConfigurationFrame->SetEventHandler( this );
2978 wxPanel* panel = getConfigurationPanel(_interfaceConfigurationFrame);
2979 panel->SetSize(sizepanel);
2980 _interfaceConfigurationFrame->Show(true);
2982 if (_interfaceConfigurationFrame->IsShown()==true)
2984 _interfaceConfigurationFrame->Show(false);
2986 _interfaceConfigurationFrame->Show(true);
2994 wxPanel* wxContourEventHandler :: getConfigurationPanel(wxWindow* parent){
2996 /*wxPanel *panel = new wxPanel(parent,-1);
2997 _withOfContourLine = new wxSlider(panel, -1, 1 , 1, 10, wxDefaultPosition, wxSize(180,40), wxSL_HORIZONTAL|wxSL_LABELS, wxDefaultValidator);
3000 this->_sceneManager->GetImageDataRange(range);
3002 wxVtk2DBaseView *wxvtk2dbaseview = (wxVtk2DBaseView*)this->_theViewPanel->getWxVtkBaseView();
3003 vtkImageViewer2 *imageviewer = wxvtk2dbaseview->_imageViewer2XYZ->GetVtkImageViewer2();
3004 int colorwindow = (int)imageviewer->GetWindowLevel()->GetLevel();
3005 int windowlevel = (int)imageviewer->GetWindowLevel()->GetWindow();
3007 _brithtnessWindowLevel = new wxSlider(panel, -1, windowlevel , 1, range[1], wxDefaultPosition, wxSize(180,40), wxSL_HORIZONTAL|wxSL_LABELS, wxDefaultValidator);
3008 _brithtnessColorLevel = new wxSlider(panel, -1, colorwindow , 1, range[1], wxDefaultPosition, wxSize(180,40), wxSL_HORIZONTAL|wxSL_LABELS, wxDefaultValidator);
3010 _interpolationCheckBox = new wxCheckBox(panel, -1, _T("Image interpolation") );
3011 _interpolationCheckBox->SetValue(true);
3013 _interfaceConfigurationFrame->SetEventHandler( this );
3015 Connect( _withOfContourLine->GetId() , wxEVT_SCROLL_CHANGED , (wxObjectEventFunction) &wxContourEventHandler::onWidthOfContour );
3016 Connect( _withOfContourLine->GetId() , wxEVT_SCROLL_THUMBTRACK , (wxObjectEventFunction) &wxContourEventHandler::onWidthOfContour );
3018 Connect( _brithtnessWindowLevel->GetId() , wxEVT_SCROLL_CHANGED , (wxObjectEventFunction) &wxContourEventHandler::onBrigthnessColorWindowLevel );
3019 Connect( _brithtnessWindowLevel->GetId() , wxEVT_SCROLL_THUMBTRACK , (wxObjectEventFunction) &wxContourEventHandler::onBrigthnessColorWindowLevel );
3020 Connect( _brithtnessColorLevel->GetId() , wxEVT_SCROLL_CHANGED , (wxObjectEventFunction) &wxContourEventHandler::onBrigthnessColorWindowLevel );
3021 Connect( _brithtnessColorLevel->GetId() , wxEVT_SCROLL_THUMBTRACK , (wxObjectEventFunction) &wxContourEventHandler::onBrigthnessColorWindowLevel );
3022 Connect( _interpolationCheckBox->GetId() , wxEVT_COMMAND_CHECKBOX_CLICKED , (wxObjectEventFunction) &wxContourEventHandler::OnInterpolation );
3024 wxFlexGridSizer * sizer = new wxFlexGridSizer(1);
3025 sizer -> Add( new wxStaticText(panel,-1,_T("Contour width")) , 1, wxGROW );
3026 sizer -> Add( _withOfContourLine , 1, wxGROW );
3027 sizer -> Add( new wxStaticText(panel,-1,_T(" ")) , 1, wxGROW );
3028 sizer -> Add( new wxStaticText(panel,-1,_T(" ")) , 1, wxGROW );
3029 sizer -> Add( new wxStaticText(panel,-1,_T("Brightness of the image")) , 1, wxGROW );
3030 sizer -> Add( new wxStaticText(panel,-1,_T("--Window level--")) , 1, wxGROW );
3031 sizer -> Add( _brithtnessWindowLevel , 1, wxGROW );
3032 sizer -> Add( new wxStaticText(panel,-1,_T("--Color level--")) , 1, wxGROW );
3033 sizer -> Add( _brithtnessColorLevel, 1, wxGROW );
3034 sizer -> Add( new wxStaticText(panel,-1,_T(" ")) , 1, wxGROW );
3035 sizer -> Add( new wxStaticText(panel,-1,_T(" ")) , 1, wxGROW );
3036 sizer -> Add( _interpolationCheckBox , 1, wxGROW );
3038 panel->SetSizer( sizer );
3040 //panel->SetSize( sizepanel );
3042 panel->SetAutoLayout( true );
3047 wxPanel *panel = new wxPanel(parent,-1,wxDefaultPosition, wxDefaultSize,wxNO_BORDER, wxString(_T("")));
3048 _withOfContourLine = new wxSlider(panel, -1, 1 , 1, 10, wxDefaultPosition, wxDefaultSize, wxSL_HORIZONTAL|wxSL_LABELS, wxDefaultValidator);
3051 this->_sceneManager->GetImageDataRange(range);
3053 wxVtk2DBaseView *wxvtk2dbaseview = (wxVtk2DBaseView*)this->_theViewPanel->getWxVtkBaseView();
3054 vtkImageViewer2 *imageviewer = wxvtk2dbaseview->_imageViewer2XYZ->GetVtkImageViewer2();
3055 int colorwindow = (int)imageviewer->GetWindowLevel()->GetLevel();
3056 int windowlevel = (int)imageviewer->GetWindowLevel()->GetWindow();
3058 _brithtnessWindowLevel = new wxSlider(panel, -1, windowlevel , 1, range[1], wxDefaultPosition, wxDefaultSize, wxSL_HORIZONTAL|wxSL_LABELS, wxDefaultValidator);
3059 _brithtnessColorLevel = new wxSlider(panel, -1, colorwindow , 1, range[1], wxDefaultPosition, wxDefaultSize, wxSL_HORIZONTAL|wxSL_LABELS, wxDefaultValidator);
3061 _interpolationCheckBox = new wxCheckBox(panel, -1, _T("Image interpolation") );
3062 _interpolationCheckBox->SetValue(true);
3064 Connect( _withOfContourLine->GetId() , wxEVT_SCROLL_CHANGED , (wxObjectEventFunction) &wxContourEventHandler::onWidthOfContour );
3065 Connect( _withOfContourLine->GetId() , wxEVT_SCROLL_THUMBTRACK , (wxObjectEventFunction) &wxContourEventHandler::onWidthOfContour );
3067 Connect( _brithtnessWindowLevel->GetId() , wxEVT_SCROLL_CHANGED , (wxObjectEventFunction) &wxContourEventHandler::onBrigthnessColorWindowLevel );
3068 Connect( _brithtnessWindowLevel->GetId() , wxEVT_SCROLL_THUMBTRACK , (wxObjectEventFunction) &wxContourEventHandler::onBrigthnessColorWindowLevel );
3069 Connect( _brithtnessColorLevel->GetId() , wxEVT_SCROLL_CHANGED , (wxObjectEventFunction) &wxContourEventHandler::onBrigthnessColorWindowLevel );
3070 Connect( _brithtnessColorLevel->GetId() , wxEVT_SCROLL_THUMBTRACK , (wxObjectEventFunction) &wxContourEventHandler::onBrigthnessColorWindowLevel );
3071 Connect( _interpolationCheckBox->GetId() , wxEVT_COMMAND_CHECKBOX_CLICKED , (wxObjectEventFunction) &wxContourEventHandler::OnInterpolation );
3073 wxFlexGridSizer * sizer = new wxFlexGridSizer(1);
3074 sizer -> Add( new wxStaticText(panel,-1,_T("Contour width")) , 1, wxGROW );
3075 sizer -> Add( _withOfContourLine , 1, wxGROW );
3076 sizer -> Add( new wxStaticText(panel,-1,_T(" ")) , 1, wxGROW );
3077 sizer -> Add( new wxStaticText(panel,-1,_T(" ")) , 1, wxGROW );
3078 sizer -> Add( new wxStaticText(panel,-1,_T("Brightness of the image")) , 1, wxGROW );
3079 sizer -> Add( new wxStaticText(panel,-1,_T("--Window level--")) , 1, wxGROW );
3080 sizer -> Add( _brithtnessWindowLevel , 1, wxGROW );
3081 sizer -> Add( new wxStaticText(panel,-1,_T("--Color level--")) , 1, wxGROW );
3082 sizer -> Add( _brithtnessColorLevel, 1, wxGROW );
3083 sizer -> Add( new wxStaticText(panel,-1,_T(" ")) , 1, wxGROW );
3084 sizer -> Add( new wxStaticText(panel,-1,_T(" ")) , 1, wxGROW );
3085 sizer -> Add( _interpolationCheckBox , 1, wxGROW );
3087 panel->SetSizer( sizer );
3089 //panel->SetSize( sizepanel );
3091 panel->SetAutoLayout( true );
3101 //------------------------------------------------------------------
3102 void wxContourEventHandler :: changeContourOfManager(std::string keyName, Instant *instant)
3104 this->_modelManager->ChangeContourOfList(keyName, instant);
3107 //------------------------------------------------------------------
3108 void wxContourEventHandler :: changeContoursOfManager( std::vector<std::string> & keyNamesVector )
3111 //JCP 20-10-08 Undo redo implementation
3113 //JCP 20-10-08 Undo redo implementation
3115 std::vector<int> tempVector;
3116 _instantPanel->getInstant( tempVector );
3117 Instant instant(&tempVector);
3119 int i , size=keyNamesVector.size();
3120 for ( i=0 ; i<size ; i++ )
3122 changeContourOfManager(keyNamesVector[i], &instant);
3129 //------------------------------------------------------------------
3130 void wxContourEventHandler :: executeActionCommand( const char toolCommand )
3132 std::vector<std::string> currentSelection = _sceneManager->getSelectedObjects();
3133 int elementsSelected = currentSelection.size();
3134 if( toolCommand == (wxContour_ActionCommnadsID::CREATE_TOOL) )
3136 onCreateContourFrame();
3138 if( toolCommand == (wxContour_ActionCommnadsID::CREATE_CONTOUR_KEY) )
3142 else if( toolCommand == wxContour_ActionCommnadsID::DELETE_TOOL )
3146 else if( toolCommand == wxContour_ActionCommnadsID::DELETE_KEY )
3148 deleteContours( currentSelection );
3150 else if( toolCommand == wxContour_ActionCommnadsID::SAVE_TOOL )
3152 saveFileWithContours( );
3154 else if( toolCommand == wxContour_ActionCommnadsID::SAVE_KEY )
3156 saveFileWithContoursAutomatique( );
3158 else if( toolCommand == wxContour_ActionCommnadsID::OPEN_TOOL )
3160 openFileWithContours( );
3162 else if( toolCommand == wxContour_ActionCommnadsID::CHANGE_TOOL )
3164 if ( elementsSelected >= 1 )
3166 changeContoursOfManager( currentSelection );
3170 else if( toolCommand == wxContour_ActionCommnadsID::HIDE_TOOL )
3172 if ( elementsSelected >= 1 )
3174 onHideOutlines( currentSelection );
3177 else if( toolCommand == wxContour_ActionCommnadsID::SHOW_TOOL )
3179 if ( elementsSelected >= 1 )
3181 onShowOutlines( currentSelection );
3184 else if( toolCommand == wxContour_ActionCommnadsID::COPY_TOOL )
3186 if ( elementsSelected >= 1 )
3188 onCopyOutlines( currentSelection );
3191 else if( toolCommand == wxContour_ActionCommnadsID::PASTE_TOOL )
3195 else if( toolCommand == wxContour_ActionCommnadsID::SPREAD_TOOL )
3199 else if( toolCommand == wxContour_ActionCommnadsID::AUTOMATIQUESEGMENTATION_TOOL )
3201 onAutomatiqueSegmentation( );
3204 else if( toolCommand == wxContour_ActionCommnadsID::SELECT_TOOL )
3206 onSelectOutlines( currentSelection );
3209 else if( toolCommand == wxContour_ActionCommnadsID::EDIT_TOOL )
3211 if ( elementsSelected >= 1 )
3213 onEditOutlines( currentSelection );
3216 else if( toolCommand == wxContour_ActionCommnadsID::UNDO_TOOL )
3220 else if( toolCommand == wxContour_ActionCommnadsID::REDO_TOOL )
3224 else if( toolCommand == wxContour_ActionCommnadsID::INFORMATIONCONTOUR_TOOL )
3226 onInformationContourFrame();
3228 else if( toolCommand == wxContour_ActionCommnadsID::INTERFACECONFIGURATION_TOOL )
3230 onInterfaceConfigurationFrame();
3232 else if( toolCommand == wxContour_ActionCommnadsID::TEST_TOOL )
3234 onInterfaceTestFrame();
3241 //------------------------------------------------------------------------------------------------------------
3242 // Getting information methods
3243 //------------------------------------------------------------------------------------------------------------
3247 //------------------------------------------------------------------------------------------------------------
3249 //------------------------------------------------------------------------------------------------------------
3251 void wxContourEventHandler :: updateInstantOutlines()
3253 std::vector<NameWrapper *> namesWrapping = _modelManager->getActualInstantOutlines();
3254 int size = namesWrapping.size();
3255 _sceneManager->removeSceneContours();
3256 for( int i=0; i<size; i++)
3258 _sceneManager->addToScene(namesWrapping[i]->getKeyName(), true, true, true, false, false );
3261 //------------------------------------------------------------------------------------------------------------
3262 void wxContourEventHandler :: updateInstantImageData()
3266 //------------------------------------------------------------------------------------------------------------
3268 void wxContourEventHandler :: updateInstantAxes()
3272 //------------------------------------------------------------------------------------------------------------
3273 void wxContourEventHandler :: changeInstant()
3275 std::vector<int> instantVect;
3276 _instantPanel->getInstant( instantVect );
3277 Instant * theInstant = new Instant ( &instantVect );
3278 //if( !theInstant->isEquals( _actualInstant ))
3280 //Setting the actual instant
3281 _actualInstant = theInstant;
3282 _modelManager->setInstant( _actualInstant );
3284 updateInstantOutlines();
3285 updateInstantImageData();
3286 updateInstantAxes();
3288 //Searching the elements at the specified instant
3291 std::map<std::string, ContourWrap_ViewControl *> :: iterator iter;
3292 iter = contours_ViewControl->find("Outline 0");
3293 (iter->second)->getViewer()->RemoveCompleteContourActor();*/
3297 void wxContourEventHandler :: saveState(){
3303 //itoa(inundo, str, 10);
3304 std::string str = intToString(inundo);
3307 std::string temp = stundoredo + str + ".roi";
3308 saveFileWithContours(temp);
3313 void wxContourEventHandler ::loadState(std::string filename){
3316 FILE *pFile=fopen(filename.c_str(),"r+");
3318 fscanf(pFile,"%s",tmp); // --CreaContour--
3320 fscanf(pFile,"%s",tmp); // Version
3321 fscanf(pFile,"%s",tmp); // 1.0.1
3322 std::string version(tmp);
3324 deleteAllContours();
3326 openContours(pFile,false);
3327 if (version!="1.0.0"){
3328 openContours(pFile,true);
3333 //_sceneManager->removeSceneContours();
3337 void wxContourEventHandler :: onREDO()
3344 //itoa(inundo, str, 10);
3345 std::string str = intToString(inundo);
3348 std::string temp = stundoredo + str + ".roi";
3356 //------------------------------------------------------------------------------------------------------------
3357 void wxContourEventHandler :: onUNDO()
3363 //itoa(inundo, str, 10);
3364 std::string str = intToString(inundo);
3366 std::string temp = stundoredo + str + ".roi";
3367 saveFileWithContours(temp);
3374 //itoa(inundo, str, 10);
3375 std::string str = intToString(inundo);
3378 std::string temp = stundoredo + str + ".roi";
3384 void wxContourEventHandler :: getValuesXYZ(double **vectx, double **vecty, double **vectz, std::vector<int>* size){
3388 ContourExtractData *contourextractdata = new ContourExtractData();
3389 int typeContourGroup = this->_radiolstboxContourGroup->GetSelection();
3390 contourextractdata ->SetTypeOperation( typeContourGroup % 3 );
3392 std::vector<manualContourModel*> lstManConMod;
3393 std::vector<manualContourModel*> lstManConModTmp;
3394 std::vector<manualContourModel*> lstManConModExp;
3395 std::vector<double> pLstValue;
3396 std::vector<double> pLstValuePosX;
3397 std::vector<double> pLstValuePosY;
3398 std::vector<double> pLstValuePosZ;
3400 std::vector<int> tempVector;
3401 _instantPanel->getInstant( tempVector );
3403 vtkImageData *imagedata = _sceneManager->GetImageData();
3404 int sizeZ = _sceneManager->GetImageDataSizeZ();
3406 int ii,sizeLstContourThings;
3413 minZ = 0;// _mbarrange->GetStart();
3414 maxZ = sizeZ;//_mbarrange->GetEnd();
3415 totalZ = maxZ-minZ+1;
3417 contourextractdata->SetImage( imagedata);
3420 vectx = new double *[sizeZ];
3421 vecty = new double *[sizeZ];
3422 vectz = new double *[sizeZ];
3423 for ( z=0 ; z<sizeZ ; z++)
3426 porcent = 100.0* (z-minZ)/totalZ;
3428 //Extraction data from contours of each slice
3429 contourextractdata->SetZtoBeAnalys( z);
3432 Instant instant(&tempVector);
3433 std::vector<ContourThing**> lstContourThings = this->_modelManager->getOutlinesAtInstant( &instant );
3434 sizeLstContourThings = lstContourThings.size();
3436 lstManConMod.clear();
3437 for (ii=0 ; ii<sizeLstContourThings ; ii++)
3439 ContourThing **contourthing = lstContourThings[ii];
3440 lstManConMod.push_back( (*contourthing)->getModel() );
3442 lstManConModExp = ExploseEachModel( lstManConMod );
3447 int iContourGroup,sizeContourGroup;
3448 if (typeContourGroup==3) // contour separete
3450 sizeContourGroup=lstManConModExp.size();
3451 } else { // contour AND OR XOR
3455 for( iContourGroup=0 ; iContourGroup<sizeContourGroup ; iContourGroup++ ){
3456 lstManConModTmp.clear();
3457 if (typeContourGroup==3) // contour separete
3459 lstManConModTmp.push_back( lstManConModExp[iContourGroup]);
3460 } else { // contour AND OR XOR
3461 lstManConModTmp = lstManConModExp;
3464 contourextractdata->SetLstManualContourModel( lstManConModTmp );
3467 pLstValuePosX.clear();
3468 pLstValuePosY.clear();
3469 pLstValuePosZ.clear();
3470 contourextractdata->GetValuesInsideCrown( &pLstValue,
3476 int iLstValue,sizeLstValue=pLstValue.size();
3478 //We initialize the pointers
3479 size->push_back(sizeLstValue);
3480 vectx[sizeZ] = new double[sizeLstValue];
3481 vecty[sizeZ] = new double[sizeLstValue];
3482 vectz[sizeZ] = new double[sizeLstValue];
3484 for (iLstValue=0 ; iLstValue<sizeLstValue ; iLstValue++ )
3487 vectx[sizeZ][iLstValue] = pLstValuePosX[iLstValue];
3488 vecty[sizeZ][iLstValue] = pLstValuePosY[iLstValue];
3489 vectz[sizeZ][iLstValue] = pLstValuePosZ[iLstValue];
3492 //The size of the contour is saved
3497 } // for iContourGroup
3499 //_staticTextInformation->SetLabel( _T("") );
3500 delete contourextractdata;
3505 void wxContourEventHandler :: getMaskValue(vtkImageData* mask, vtkImageData* value){
3509 ContourExtractData *contourextractdata = new ContourExtractData( true );
3510 int typeContourGroup = this->_radiolstboxContourGroup->GetSelection();
3511 if (typeContourGroup==3)
3515 contourextractdata ->SetTypeOperation( typeContourGroup % 3 );
3517 std::vector<manualContourModel*> lstManConMod;
3518 std::vector<manualContourModel*> lstManConModTmp;
3519 std::vector<manualContourModel*> lstManConModExp;
3521 std::vector<int> tempVector;
3522 _instantPanel->getInstant( tempVector );
3524 vtkImageData *imagedata = _sceneManager->GetImageData();
3525 int sizeZ = _sceneManager->GetImageDataSizeZ();
3527 int ii,sizeLstContourThings;
3536 minZ = 0;// _mbarrange->GetStart();
3537 maxZ = sizeZ;//_mbarrange->GetEnd();
3538 totalZ = maxZ-minZ+1;
3540 contourextractdata->SetImage( imagedata);
3543 for ( z=0 ; z<sizeZ ; z++)
3546 porcent = 100.0* (z-minZ)/totalZ;
3547 tmpString.Printf(_T("Saving Values"));
3548 tmpString.Printf(_T(" %d %c %d/%d %d"), (int)porcent , 37 , z-minZ+1, (int)totalZ ,z);
3549 _staticTextInformation->SetLabel(tmpString);
3551 //Extraction data from contours of each slice
3552 contourextractdata->SetZtoBeAnalys( z);
3555 Instant instant(&tempVector);
3556 std::vector<ContourThing**> lstContourThings = this->_modelManager->getOutlinesAtInstant( &instant );
3557 sizeLstContourThings = lstContourThings.size();
3559 lstManConMod.clear();
3560 for (ii=0 ; ii<sizeLstContourThings ; ii++)
3562 ContourThing **contourthing = lstContourThings[ii];
3563 lstManConMod.push_back( (*contourthing)->getModel() );
3565 lstManConModExp = ExploseEachModel( lstManConMod );
3568 int iContourGroup,sizeContourGroup;
3569 if (typeContourGroup==3) // contour separete
3571 sizeContourGroup=lstManConModExp.size();
3572 } else { // contour AND OR XOR
3576 for( iContourGroup=0 ; iContourGroup<sizeContourGroup ; iContourGroup++ ){
3577 lstManConModTmp.clear();
3578 if (typeContourGroup==3) // contour separete
3580 lstManConModTmp.push_back( lstManConModExp[iContourGroup]);
3581 } else { // contour AND OR XOR
3582 lstManConModTmp = lstManConModExp;
3585 contourextractdata->SetLstManualContourModel( lstManConModTmp );
3588 contourextractdata->CalculateImageResult(); // with actual Z
3590 } // for iContourGroup
3596 value = contourextractdata->GetVtkImageValueResult();
3599 mask = contourextractdata->GetVtkImageMaskResult();
3601 delete contourextractdata;
3605 wxPanel* wxContourEventHandler::getSegmentationPanelITK(wxWindow* parent){
3607 int sizeZ = _sceneManager->GetImageDataSizeZ();
3609 _sceneManager->GetImageDataRange(range);
3611 wxPanel *panel = new wxPanel(parent,-1);
3612 wxButton *segmentationOneSliceBtn = new wxButton(panel,-1,_T("Actual slice"), wxDefaultPosition, wxSize(200,35) );
3613 wxButton *segmentationAllSliceBtn = new wxButton(panel,-1,_T("All slices") ,wxDefaultPosition, wxSize(200,35) );
3614 _isovalue = new wxSlider(panel, -1, 40 , (int)(range[0]), (int)(range[1]), wxDefaultPosition, wxSize(200,35), wxSL_HORIZONTAL|wxSL_LABELS, wxDefaultValidator);
3615 _sampling = new wxSlider(panel, -1, 20 , 4, 50, wxDefaultPosition, wxSize(200,35), wxSL_HORIZONTAL|wxSL_LABELS, wxDefaultValidator);
3616 wxString lstOptions[3];
3617 lstOptions[0]=_T("A");
3618 lstOptions[1]=_T("B");
3619 lstOptions[2]=_T("C");
3620 methodRadiobox = new wxRadioBox(panel, -1, _T("Method (find ctrl. Points)"), wxDefaultPosition, wxSize(200,45), 3 , lstOptions, 3, wxRA_SPECIFY_COLS);
3621 methodRadiobox->SetSelection(2);
3622 _staticTextSegmentation = new wxStaticText(panel,-1,_T(" "));
3625 _mbarrange = new mBarRange(panel,70, 65);
3626 _mbarrange->SetMin(0);
3627 _mbarrange->SetStart(0);
3629 _mbarrange-> SetOrientation( true );
3630 _mbarrange-> setActiveStateTo(true);
3631 _mbarrange-> setVisibleLabels( true );
3632 _mbarrange-> setDeviceEndMargin(10);
3633 _mbarrange-> setRepresentedValues( 0 , sizeZ );
3634 _mbarrange-> setDeviceBlitStart(10,10);
3635 _mbarrange-> setIfWithActualDrawed( false );
3636 _mbarrange-> SetStart( 0 );
3637 _mbarrange-> SetEnd( sizeZ );
3640 // _segmentationFrame->SetEventHandler( this );
3641 segmentationOneSliceBtn->SetEventHandler( this );
3642 segmentationAllSliceBtn->SetEventHandler( this );
3643 Connect( segmentationOneSliceBtn->GetId(), wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &wxContourEventHandler::onSegmentationOneSliceITK );
3644 Connect( segmentationAllSliceBtn->GetId(), wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &wxContourEventHandler::onSegmentationAllSliceITK );
3646 wxFlexGridSizer * sizer = new wxFlexGridSizer(1);
3647 sizer -> Add( new wxStaticText(panel,-1,_T("Isovalue (Gray level)")) , 1, wxGROW );
3648 sizer -> Add( _isovalue , 1, wxGROW );
3649 sizer -> Add( methodRadiobox , 1, wxGROW );
3650 sizer -> Add( new wxStaticText(panel,-1,_T("Sampling (%)")) , 1, wxGROW );
3651 sizer -> Add( _sampling , 1, wxGROW );
3652 sizer -> Add( segmentationOneSliceBtn , 1, wxGROW );
3653 sizer -> Add( new wxStaticText(panel,-1,_T(" ")) , 1, wxGROW );
3654 sizer -> Add( _staticTextSegmentation , 1, wxGROW );
3655 sizer -> Add( segmentationAllSliceBtn , 1, wxGROW );
3656 sizer -> Add( _mbarrange , 1, wxGROW );
3658 panel->SetSizer( sizer );
3659 // panel->SetSize( sizePanel );
3660 panel->SetSize( wxDefaultSize );
3661 panel->SetAutoLayout( true );
3668 void wxContourEventHandler::onSegmentationAllSliceITK( wxCommandEvent& event ){
3669 //TODO implementar el método para todos los slices ver ayuda en onSegmentationAllSlice
3671 void wxContourEventHandler::onSegmentationOneSliceITK( wxCommandEvent& event ){
3672 //TODO implementar el método de segmentación en ITK ver ayuda en onSegmentationOneSlice y el método
3673 // SegmentationOneSlice(x, y, z) que es la implementación del método en VTK
3675 //JCP 20-10-08 Undo redo implementation
3677 //JCP 20-10-08 Undo redo implementation
3680 int x = this->_theViewPanel->GetX();
3681 int y = this->_theViewPanel->GetY();
3682 int z = this->_theViewPanel->GetZ();
3683 //SegmentationOneSlice( x,y,z );
3686 void wxContourEventHandler::onSnakePressed(wxWindow* parent){
3688 std::vector<double> vecX;
3689 std::vector<double> vecY;
3690 std::vector<double> vecZ;
3691 _sceneManager->GetPointsOfActualContour( &vecX , &vecY , &vecZ );
3693 if (vecX.size()!=0){
3694 std::vector<int> tempVector;
3695 _instantPanel->getInstant( tempVector );
3696 int i,size=vecZ.size();
3697 int actualSlice = tempVector[1];
3698 for ( i=0 ; i<size ; i++ )
3700 vecZ[i] = actualSlice;
3703 wxDialog* dialog = new wxDialog(parent, -1, wxString(_T("Snake")));
3704 wxPanel* panel = new wxPanel(dialog,-1);
3705 wxStaticText* sttext = new wxStaticText(panel, -1, wxString(_T("Panel para snake")));
3706 dialog->ShowModal();
3711 void wxContourEventHandler::checkInformationPanel(){
3712 if (_InformationContourFrame==NULL){
3713 onInformationContourFrame();
3714 _InformationContourFrame->Show(false);
3718 std::string wxContourEventHandler::intToString(int num){
3720 for(int k = num; k == 0; k++){
3721 char temp = k % 10 + 48;
3723 result = temp + result;