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_ActionCommandsID.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";
372 mkdir(stundoredo.c_str());
374 mkdir(stundoredo.c_str(),755);
376 stundoredo += "/cont";
378 //------------------------------------------------------------------------------------------------------------
379 wxContourEventHandler :: ~ wxContourEventHandler()
381 delete _actualInstant;
382 /*delete _theViewPanel;
383 delete _instantPanel;
385 delete _actualInstant;
387 delete _sceneManager;
388 delete _performingOperation;
392 //------------------------------------------------------------------------------------------------------------
393 // Configuration methods
394 //------------------------------------------------------------------------------------------------------------
396 bool wxContourEventHandler :: configureEventsHandling()
398 bool configured = true;
403 //------------------------------------------------------------------------------------------------------------
404 // Methods for capturing events
405 //------------------------------------------------------------------------------------------------------------
406 void wxContourEventHandler :: onProcessMessage( wxCommandEvent& event )
410 //------------------------------------------------------------------------------------------------------------
412 void wxContourEventHandler :: onActionButtonPressed( wxCommandEvent& event )
414 const char buttonTool = *(char *)event.GetClientData();
415 executeActionCommand( buttonTool );
417 //------------------------------------------------------------------------------------------------------------
418 void wxContourEventHandler :: onChangedDeep ( wxCommandEvent& event )
420 double val = _theViewPanel->getCurrentDeep();
421 _instantPanel->setConceptValue( "Axe Depth", (int)val );
422 _theViewPanel->setActualVertical( (int)val );
426 //------------------------------------------------------------------------------------------------------------
427 void wxContourEventHandler :: onChangeInstant( wxCommandEvent& event )
429 ConceptDataWrap * dataConcept = NULL;
430 if ( _theViewPanel->GetId() == event.GetId() )
432 dataConcept = (ConceptDataWrap *)event.GetClientData();
433 int value = dataConcept->getActualValue();
434 _instantPanel->setConceptValue( dataConcept->getName(), value );
438 dataConcept = _instantPanel->getLastConceptData();
439 if( dataConcept->getName().compare( _theViewPanel->getVerticalConceptName() ) )
441 _theViewPanel->setActualVertical( dataConcept->getActualValue());
442 //_theViewPanel->setVerticalConcept( dataConcept->getName(), dataConcept->getMinShowedValue()/*dataConcept->getMinValue()*/, /*dataConcept->getMaxValue()*/ dataConcept->getMaxShowedValue(), dataConcept->getMinShowedValue(), dataConcept->getMaxShowedValue(), dataConcept->getActualValue());
444 else if( dataConcept->getName().compare( _theViewPanel->getHorizontalConceptName() ) || _instantPanel->getIfConceptCheckedAt( dataConcept->getName(), 0 ) )
446 _theViewPanel->setHorizontalConcept( dataConcept->getName(), dataConcept->getMinShowedValue()/*dataConcept->getMinValue()*/, /*dataConcept->getMaxValue()*/ dataConcept->getMaxShowedValue(), dataConcept->getMinShowedValue(), dataConcept->getMaxShowedValue(), dataConcept->getActualValue());
451 //------------------------------------------------------------------------------------------------------------
453 void wxContourEventHandler :: onCreateMultipleROI( wxCommandEvent& event )
455 _creatingContoursActive = !_creatingContoursActive;
456 if( _creatingContoursActive )
461 //------------------------------------------------------------------------------------------------------------
462 void wxContourEventHandler :: onCreateROI( wxCommandEvent& event )
464 if( _creatingContoursActive )
470 //------------------------------------------------------------------------------------------------------------
471 void wxContourEventHandler :: onStopCreateROI( wxCommandEvent& event )
476 //------------------------------------------------------------------------------------------------------------
477 void wxContourEventHandler :: onDeleterROI( wxCommandEvent& event )
481 //------------------------------------------------------------------------------------------------------------
482 void wxContourEventHandler :: onSelectROI( wxCommandEvent& event )
486 //------------------------------------------------------------------------------------------------------------
489 void wxContourEventHandler :: onUnSelectROI( wxCommandEvent& event )
493 //------------------------------------------------------------------------------------------------------------
495 void wxContourEventHandler :: onManualHidedROI( wxCommandEvent& event )
499 //------------------------------------------------------------------------------------------------------------
501 void wxContourEventHandler :: onManualShowedROI( wxCommandEvent& event )
505 //------------------------------------------------------------------------------------------------------------
507 void wxContourEventHandler :: onEditingROI( wxCommandEvent& event )
511 //------------------------------------------------------------------------------------------------------------
513 void wxContourEventHandler :: onMovingROI( wxCommandEvent& event )
518 //------------------------------------------------------------------------------------------------------------
519 // Model management methods
520 //------------------------------------------------------------------------------------------------------------
522 void wxContourEventHandler::onSpreadReset( wxCommandEvent& event )
524 _wxtextctrlSpread->SetValue(wxString("",wxConvUTF8));
525 _contourPropagation->resetAppend();
528 //------------------------------------------------------------------------------------------------------------
529 void wxContourEventHandler::onSpreadAdd( wxCommandEvent& event )
531 std::vector<double> vecX;
532 std::vector<double> vecY;
533 std::vector<double> vecZ;
534 _sceneManager->GetPointsOfActualContour( &vecX , &vecY , &vecZ );
537 std::vector<int> tempVector;
538 _instantPanel->getInstant( tempVector );
539 int i,size=vecZ.size();
540 int actualSlice = tempVector[1];
541 for ( i=0 ; i<size ; i++ )
543 vecZ[i] = actualSlice;
546 _contourPropagation->appendContour(&vecX , &vecY , &vecZ);
548 //newstring.Printf("%s %d -",_wxtextctrlSpread->GetValue(), actualSlice );
549 newstring.append(wxString(_wxtextctrlSpread->GetValue(),wxConvUTF8));
550 newstring.append(wxString(" ",wxConvUTF8));
551 newstring.append(wxString(intToString(actualSlice).c_str(),wxConvUTF8));
552 _wxtextctrlSpread->SetValue(newstring);
558 //------------------------------------------------------------------------------------------------------------
559 void wxContourEventHandler::onSpreadGo( wxCommandEvent& event )
562 //JCP 20-10-08 Undo redo implementation
564 //JCP 20-10-08 Undo redo implementation
567 int typeMethodFindCtrlPoints=_spreadMethodRadiobox->GetSelection();
568 int typeofcontour = 1;
569 manualContourModel *manModelContour;
570 std::vector<double> vecCtrlPointX;
571 std::vector<double> vecCtrlPointY;
572 std::vector<double> vecCtrlPointZ;
578 std::vector<int> tempVector;
579 _instantPanel->getInstant( tempVector );
582 _contourPropagation->getMaxMinZ(&minZ,&maxZ);
583 //JSTG_16-07-08_----------------------------------------------------------------
584 //_contourPropagation->setInterpolationNumber(maxZ-minZ+1);
585 _contourPropagation->setInterpolationNumber(100);
586 _contourPropagation->CalculeSplinePropagation();
588 double totalZ = maxZ-minZ+1;
591 //--------------------------------------------------------------------
592 for ( z=(int)minZ ; z<=(int)maxZ ; z++ )
594 porcent = 100.0* (z-minZ)/totalZ;
595 int numero = (int)(z-minZ+1)/(int)totalZ;
596 std::string stringtemp = " "+intToString(porcent)+"% "+intToString(numero)+" "+intToString(z);
597 tmpString.Append(wxString(stringtemp.c_str(),wxConvUTF8));
599 //tmpString.Printf(" %d %c %d/%d %d", (int)porcent , 37 , (int)(z-minZ+1), (int)totalZ,z );
600 _staticTextSpread->SetLabel(tmpString);
602 if (_contourPropagation->ifSliceKeyContourExist(z)==false)
604 manModelContour = factoryManualContourModel( typeofcontour );
605 idTmp = _contourPropagation->FindIdWithZ(z);
606 if (typeMethodFindCtrlPoints==0) // Initial Points
608 _contourPropagation->GetInitialControlPoints( idTmp , &vecCtrlPointX,&vecCtrlPointY,&vecCtrlPointZ);
610 if (typeMethodFindCtrlPoints==1) // Automatique Method
612 _contourPropagation->GetControlPoints( idTmp ,&vecCtrlPointX,&vecCtrlPointY,&vecCtrlPointZ);
614 if (typeMethodFindCtrlPoints==2) // sampling
616 _contourPropagation->GetControlPoints( idTmp , 20.0 ,&vecCtrlPointX,&vecCtrlPointY,&vecCtrlPointZ);
618 //--------------------------------------------------------------------
619 sizeCtrPt = vecCtrlPointX.size();
620 for (j=0 ; j<sizeCtrPt ; j++)
622 //JSTG_16-07-08_----------------------------------------------------------------
623 manModelContour->AddPoint( vecCtrlPointX[j] , vecCtrlPointY[j] , -900 );
624 //--------------------------------------------------------------------
629 theName = _modelManager->createOutline( manModelContour, tempVector );
630 bool addedModel = theName.compare("") != 0;
633 double spc[3];//Si no hay imagen pero hay contornos que spacing se pone por default
634 this->_theViewPanel->getSpacing(spc);
635 //Adding the manualContourControler to interface objects structure
636 //Adding the manualViewContour to interface objects structure
637 //_sceneManager->setControlActiveStateOfALL( false );//This call is being done here because if the ROI is created underneath the previously created ROIS will still be active.
638 _sceneManager->configureViewControlTo( theName, manModelContour,spc,typeofcontour ) ;
640 }// ifSliceKeyContourExist
642 _staticTextSpread->SetLabel(wxString(" ",wxConvUTF8));
643 //RefreshInterface();
649 //------------------------------------------------------------------------------------------------------------
650 void wxContourEventHandler :: onSpread( )
652 if (_spreadFrame==NULL)
655 _spreadFrame = new wxFrame (_theViewPanel, -1,_T(" Spread "), wxDefaultPosition, wxDefaultSize, wxFRAME_TOOL_WINDOW|wxSYSTEM_MENU | wxCAPTION | wxCLIP_CHILDREN |wxFRAME_FLOAT_ON_PARENT );
657 wxSize sizepanel(250,400);
658 _spreadFrame->SetSize( sizepanel );
659 _spreadFrame->SetEventHandler( this );
660 wxPanel *panel = getSpreadPanel(_spreadFrame);
661 panel->SetSize(sizepanel);
662 /**new wxPanel(_spreadFrame,-1);
664 wxButton *spreadResetBtn = new wxButton(panel,-1,_T("Reset"),wxDefaultPosition, wxSize(80,35) );
665 wxButton *spreadAddBtn = new wxButton(panel,-1,_T("Add"),wxDefaultPosition, wxSize(80,35));
667 wxString lstOptions[3];
671 _spreadMethodRadiobox = new wxRadioBox(panel, -1, "Method (find ctrl. Points)", wxDefaultPosition, wxSize(200,45), 3 , lstOptions, 3, wxRA_SPECIFY_COLS);
672 _spreadMethodRadiobox->SetSelection(2);
674 wxButton *spreadGoBtn = new wxButton(panel,-1,_T("Go"),wxDefaultPosition, wxSize(80,35));
675 _staticTextSpread = new wxStaticText(panel,-1,_T(" "));
677 _wxtextctrlSpread = new wxTextCtrl(panel,-1, "",wxDefaultPosition, wxSize(200,150), wxTE_MULTILINE );
679 _spreadFrame->SetEventHandler( this );
680 Connect( spreadResetBtn->GetId(), wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &wxContourEventHandler::onSpreadReset );
681 Connect( spreadAddBtn->GetId(), wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &wxContourEventHandler::onSpreadAdd );
682 Connect( spreadGoBtn->GetId(), wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &wxContourEventHandler::onSpreadGo );
684 wxFlexGridSizer * sizer = new wxFlexGridSizer(1);
685 sizer -> Add( spreadResetBtn , 1, wxGROW );
686 sizer -> Add( spreadAddBtn , 1, wxGROW );
687 sizer -> Add( _spreadMethodRadiobox , 1, wxGROW );
688 sizer -> Add( spreadGoBtn , 1, wxGROW );
689 sizer -> Add( _staticTextSpread , 1, wxGROW );
690 sizer -> Add( _wxtextctrlSpread , 1, wxGROW );
693 panel->SetSizer( sizer );
694 panel->SetSize( sizepanel );
695 panel->SetAutoLayout( true );
697 _spreadFrame->Show();
699 if (_spreadFrame->IsShown()==true)
701 _spreadFrame->Show(false);
703 _spreadFrame->Show(true);
708 wxPanel* wxContourEventHandler::getSpreadPanel(wxWindow* parent){
709 //wxPanel *panel = new wxPanel(parent,-1);
711 _contourPropagation = new ContourPropagation();
713 wxPanel *panel = new wxPanel(parent,-1,wxDefaultPosition, wxDefaultSize,wxNO_BORDER, wxString("",wxConvUTF8));
715 wxButton *spreadResetBtn = new wxButton(panel,-1,_T("Reset"),wxDefaultPosition, wxDefaultSize );
716 wxButton *spreadAddBtn = new wxButton(panel,-1,_T("Add"),wxDefaultPosition, wxDefaultSize);
718 wxString lstOptions[3];
719 lstOptions[0]=_T("A");
720 lstOptions[1]=_T("B");
721 lstOptions[2]=_T("C");
722 _spreadMethodRadiobox = new wxRadioBox(panel, -1, _T("Method (find ctrl. Points)"), wxDefaultPosition, wxDefaultSize, 3 , lstOptions, 3, wxRA_SPECIFY_COLS);
723 _spreadMethodRadiobox->SetSelection(2);
725 wxButton *spreadGoBtn = new wxButton(panel,-1,_T("Go"),wxDefaultPosition, wxDefaultSize);
726 _staticTextSpread = new wxStaticText(panel,-1,_T(" "));
728 _wxtextctrlSpread = new wxTextCtrl(panel,-1, _T(""),wxDefaultPosition, wxDefaultSize, wxTE_MULTILINE );
731 Connect( spreadResetBtn->GetId(), wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &wxContourEventHandler::onSpreadReset );
732 Connect( spreadAddBtn->GetId(), wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &wxContourEventHandler::onSpreadAdd );
733 Connect( spreadGoBtn->GetId(), wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &wxContourEventHandler::onSpreadGo );
735 wxFlexGridSizer * sizer = new wxFlexGridSizer(1);
736 sizer -> Add( spreadResetBtn , 1, wxGROW );
737 sizer -> Add( spreadAddBtn , 1, wxGROW );
738 sizer -> Add( _spreadMethodRadiobox , 1, wxGROW );
739 sizer -> Add( spreadGoBtn , 1, wxGROW );
740 sizer -> Add( _staticTextSpread , 1, wxGROW );
741 sizer -> Add( _wxtextctrlSpread , 1, wxGROW );
744 panel->SetSizer( sizer );
745 //panel->SetSize( wxDefaultSize );
746 panel->SetAutoLayout( true );
751 //------------------------------------------------------------------------------------------------------------
752 void wxContourEventHandler::onSegmentationAllSlice( wxCommandEvent& event )
754 //JCP 20-10-08 Undo redo implementation
756 //JCP 20-10-08 Undo redo implementation
759 int x = this->_theViewPanel->GetX();
760 int y = this->_theViewPanel->GetY();
764 minZ=_mbarrange->GetStart();
765 maxZ=_mbarrange->GetEnd();
766 double totalZ = maxZ-minZ+1;
767 for( z=minZ ; z<=maxZ ; z++ )
769 porcent = 100.0* (z-minZ)/totalZ;
770 tmpString.Printf(_T(" %d %c %d/%d %d"), (int)porcent , 37 , z-minZ+1, (int)totalZ,z );
771 _staticTextSegmentation->SetLabel(tmpString);
772 SegmentationOneSlice( x,y,z );
774 _staticTextSegmentation->SetLabel(_T(" "));
780 //------------------------------------------------------------------------------------------------------------
781 void wxContourEventHandler::onSegmentationOneSlice( wxCommandEvent& event )
783 //JCP 20-10-08 Undo redo implementation
785 //JCP 20-10-08 Undo redo implementation
788 int x = this->_theViewPanel->GetX();
789 int y = this->_theViewPanel->GetY();
790 int z = this->_theViewPanel->GetZ();
791 SegmentationOneSlice( x,y,z );
796 //------------------------------------------------------------------------------------------------------------
797 void wxContourEventHandler::SegmentationOneSlice( int x, int y, int z )
799 int typeofcontour = 1;
800 //--Extracting Contour
801 vtkImageData *imagedata = _sceneManager->GetImageData();
802 // double *range = imagedata->GetScalarRange();
804 int isovalue = _isovalue->GetValue();
805 int sampling = _sampling->GetValue();
807 vtkImageReslice *imageReslice = vtkImageReslice::New();
810 // imagedata->GetSpacing(spc);
815 imageReslice->SetInput( imagedata );
816 imageReslice->SetInformationInput(imagedata);
817 imageReslice->SetResliceAxesDirectionCosines(1,0,0, 0,1,0 ,0,0,1);
818 imageReslice->SetResliceAxesOrigin(0,0,z);
819 imageReslice->SetOutputDimensionality(2);
820 imageReslice->SetInterpolationModeToLinear();
822 imagedata = imageReslice->GetOutput();
824 imagedata->UpdateInformation();
826 vtkContourFilter* cntVTK = vtkContourFilter::New( );
827 cntVTK->SetInput( imagedata );
829 cntVTK->SetNumberOfContours( 1 );
830 //cntVTK->SetValue( 0, vmin );
831 // cntVTK->SetValue( 0, (range[1]*thr/100) );
832 cntVTK->SetValue( 1, isovalue );
833 // cntVTK->SetValue( 1, vmax );
835 cntVTK->UpdateInformation();
837 vtkCleanPolyData* cpd = vtkCleanPolyData::New( );
838 cpd->SetInput( cntVTK->GetOutput( ) );
839 cpd->ConvertLinesToPointsOff( );
841 cpd->UpdateInformation();
843 vtkPolyDataConnectivityFilter* conn = vtkPolyDataConnectivityFilter::New( );
844 conn->SetExtractionModeToClosestPointRegion( );
845 //conn->SetMaxRecursionDepth( 3000 );
847 conn->SetInput( cpd->GetOutput( ) );
849 conn->SetClosestPoint( x, y, 0 );
851 conn->UpdateInformation();
853 vtkCleanPolyData* cpd2 = vtkCleanPolyData::New( );
854 cpd2->SetInput( conn->GetOutput( ) );
856 cpd2->UpdateInformation();
858 vtkStripper* vtkstripper = vtkStripper::New( );
859 vtkstripper->SetInput( cpd2->GetOutput() );
860 vtkstripper->Update();
861 vtkstripper->UpdateInformation();
864 vtkPolyData* polyDataResult = vtkstripper->GetOutput();
866 polyDataResult->Update( );
867 polyDataResult->UpdateInformation();
871 myfile.open ("c:/temp/example.txt");
873 polyDataResult->Print(myfile);
874 myfile << "-------------------------------------\n";
875 polyDataResult->GetLines()->Print(myfile);
885 //--Calculating control points
887 std::vector<double> vecX;
888 std::vector<double> vecY;
889 std::vector<double> vecZ;
891 std::vector<double> vecCtrlPointX;
892 std::vector<double> vecCtrlPointY;
893 std::vector<double> vecCtrlPointZ;
897 int ii,size=polyDataResult->GetNumberOfPoints();
899 for (ii=1;ii<=size;ii++)
901 id = polyDataResult->GetLines()->GetData()->GetValue(ii);
902 p = polyDataResult->GetPoint(id);
905 vecX.push_back( p[0] );
906 vecY.push_back( p[1] );
907 vecZ.push_back( -900 );
908 // vecZ.push_back( p[2] );
912 ExtractControlPoints2D *extractcontrolpoints2d = new ExtractControlPoints2D();
913 extractcontrolpoints2d->SetContour( &vecX , &vecY , &vecZ );
916 if (methodRadiobox->GetSelection()==0){
917 extractcontrolpoints2d->GetInitialControlPoints( &vecCtrlPointX , &vecCtrlPointY , &vecCtrlPointZ );
919 if (methodRadiobox->GetSelection()==1){
920 extractcontrolpoints2d->GetControlPoints( &vecCtrlPointX , &vecCtrlPointY , &vecCtrlPointZ );
922 if (methodRadiobox->GetSelection()==2){
923 extractcontrolpoints2d->SetSamplingControlPoints( sampling );
924 extractcontrolpoints2d->GetSamplingControlPoints( &vecCtrlPointX , &vecCtrlPointY , &vecCtrlPointZ );
927 //--Adding contour to the system
929 std::vector<int> actualInstantVector;
930 _instantPanel->getInstant( actualInstantVector );
931 actualInstantVector[1]=z;
933 int j,sizeCtrPt = vecCtrlPointX.size();
934 manualContourModel *manModelContour = factoryManualContourModel( typeofcontour );
935 manModelContour->SetNumberOfPointsSpline( ((sizeCtrPt/100)+1)*100 );
937 for (j=0 ; j<sizeCtrPt ; j++)
939 manModelContour->AddPoint( vecCtrlPointX[j] , vecCtrlPointY[j] , vecCtrlPointZ[j] );
942 theName = _modelManager->createOutline( manModelContour, actualInstantVector );
943 bool addedModel = theName.compare("") != 0;
946 double spc[3];//Si no hay imagen pero hay contornos que spacing se pone por default
947 this->_theViewPanel->getSpacing(spc);
948 //Adding the manualContourControler to interface objects structure
949 //Adding the manualViewContour to interface objects structure
950 //_sceneManager->setControlActiveStateOfALL( false );//This call is being done here because if the ROI is created underneath the previously created ROIS will still be active.
951 _sceneManager->configureViewControlTo( theName, manModelContour,spc, typeofcontour ) ;
956 //------------------------------------------------------------------------------------------------------------
957 void wxContourEventHandler :: onAutomatiqueSegmentation( )
959 if (_segmentationFrame==NULL)
962 /*int sizeZ = _sceneManager->GetImageDataSizeZ();
964 _sceneManager->GetImageDataRange(range);*/
967 wxSize sizePanel( 300, 470);
968 _segmentationFrame = new wxFrame (_theViewPanel, -1,_T(" Segmentation "), wxDefaultPosition, wxDefaultSize, wxFRAME_TOOL_WINDOW|wxSYSTEM_MENU | wxCAPTION | wxCLIP_CHILDREN |wxFRAME_FLOAT_ON_PARENT );
969 _segmentationFrame->SetSize( sizePanel );
970 wxPanel *panel = getSegmentationPanel(_segmentationFrame);
971 /*new wxPanel(_segmentationFrame,-1);
972 wxButton *segmentationOneSliceBtn = new wxButton(panel,-1,_T("Actual slice"), wxDefaultPosition, wxSize(200,35) );
973 wxButton *segmentationAllSliceBtn = new wxButton(panel,-1,_T("All slices") ,wxDefaultPosition, wxSize(200,35) );
974 _isovalue = new wxSlider(panel, -1, 40 , (int)(range[0]), (int)(range[1]), wxDefaultPosition, wxSize(200,35), wxSL_HORIZONTAL|wxSL_LABELS, wxDefaultValidator);
975 _sampling = new wxSlider(panel, -1, 20 , 4, 50, wxDefaultPosition, wxSize(200,35), wxSL_HORIZONTAL|wxSL_LABELS, wxDefaultValidator);
976 wxString lstOptions[3];
980 methodRadiobox = new wxRadioBox(panel, -1, "Method (find ctrl. Points)", wxDefaultPosition, wxSize(200,45), 3 , lstOptions, 3, wxRA_SPECIFY_COLS);
981 methodRadiobox->SetSelection(2);
982 _staticTextSegmentation = new wxStaticText(panel,-1,_T(" "));
985 _mbarrange = new mBarRange(panel,70, 65);
986 _mbarrange->SetMin(0);
987 _mbarrange->SetStart(0);
989 _mbarrange-> SetOrientation( true );
990 _mbarrange-> setActiveStateTo(true);
991 _mbarrange-> setVisibleLabels( true );
992 _mbarrange-> setDeviceEndMargin(10);
993 _mbarrange-> setRepresentedValues( 0 , sizeZ );
994 _mbarrange-> setDeviceBlitStart(10,10);
995 _mbarrange-> setIfWithActualDrawed( false );
996 _mbarrange-> SetStart( 0 );
997 _mbarrange-> SetEnd( sizeZ );
1000 // _segmentationFrame->SetEventHandler( this );
1001 segmentationOneSliceBtn->SetEventHandler( this );
1002 segmentationAllSliceBtn->SetEventHandler( this );
1003 Connect( segmentationOneSliceBtn->GetId(), wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &wxContourEventHandler::onSegmentationOneSlice );
1004 Connect( segmentationAllSliceBtn->GetId(), wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &wxContourEventHandler::onSegmentationAllSlice );
1006 wxFlexGridSizer * sizer = new wxFlexGridSizer(1);
1007 sizer -> Add( new wxStaticText(panel,-1,_T("Isovalue (Gray level)")) , 1, wxGROW );
1008 sizer -> Add( _isovalue , 1, wxGROW );
1009 sizer -> Add( methodRadiobox , 1, wxGROW );
1010 sizer -> Add( new wxStaticText(panel,-1,_T("Sampling (%)")) , 1, wxGROW );
1011 sizer -> Add( _sampling , 1, wxGROW );
1012 sizer -> Add( segmentationOneSliceBtn , 1, wxGROW );
1013 sizer -> Add( new wxStaticText(panel,-1,_T(" ")) , 1, wxGROW );
1014 sizer -> Add( _staticTextSegmentation , 1, wxGROW );
1015 sizer -> Add( segmentationAllSliceBtn , 1, wxGROW );
1016 sizer -> Add( _mbarrange , 1, wxGROW );
1018 panel->SetSizer( sizer );
1019 panel->SetSize( sizePanel );
1020 panel->SetAutoLayout( true );
1023 this->_theViewPanel->SetVisibleAxis(true);
1024 this->_theViewPanel->Refresh();
1025 _segmentationFrame->Show(true);
1026 //JCP 13-10-09 View the method getSegmentationPanel(), this two methods where moved to getSegmentationPanel
1027 //this->_theViewPanel->SetVisibleAxis(true);
1028 //this->_theViewPanel->Refresh();
1030 if (_segmentationFrame->IsShown()==true)
1032 _segmentationFrame->Show(false);
1033 this->_theViewPanel->SetVisibleAxis(false);
1034 this->_theViewPanel->Refresh();
1036 _segmentationFrame->Show(true);
1037 this->_theViewPanel->SetVisibleAxis(true);
1038 this->_theViewPanel->Refresh();
1043 void wxContourEventHandler::showAxis(bool show){
1044 this->_theViewPanel->SetVisibleAxis(show);
1045 this->_theViewPanel->Refresh();
1047 wxPanel* wxContourEventHandler::getSegmentationPanel(wxWindow* parent){
1048 int sizeZ = _sceneManager->GetImageDataSizeZ();
1050 _sceneManager->GetImageDataRange(range);
1052 wxPanel *panel = new wxPanel(parent,-1);
1053 wxButton *segmentationOneSliceBtn = new wxButton(panel,-1,_T("Actual slice"), wxDefaultPosition, wxSize(200,35) );
1054 wxButton *segmentationAllSliceBtn = new wxButton(panel,-1,_T("All slices") ,wxDefaultPosition, wxSize(200,35) );
1055 _isovalue = new wxSlider(panel, -1, 40 , (int)(range[0]), (int)(range[1]), wxDefaultPosition, wxSize(200,35), wxSL_HORIZONTAL|wxSL_LABELS, wxDefaultValidator);
1056 _sampling = new wxSlider(panel, -1, 20 , 4, 50, wxDefaultPosition, wxSize(200,35), wxSL_HORIZONTAL|wxSL_LABELS, wxDefaultValidator);
1057 wxString lstOptions[3];
1058 lstOptions[0]=_T("A");
1059 lstOptions[1]=_T("B");
1060 lstOptions[2]=_T("C");
1061 methodRadiobox = new wxRadioBox(panel, -1, _T("Method (find ctrl. Points)"), wxDefaultPosition, wxSize(200,45), 3 , lstOptions, 3, wxRA_SPECIFY_COLS);
1062 methodRadiobox->SetSelection(2);
1063 _staticTextSegmentation = new wxStaticText(panel,-1,_T(" "));
1066 _mbarrange = new mBarRange(panel,70, 65);
1067 _mbarrange->SetMin(0);
1068 _mbarrange->SetStart(0);
1070 _mbarrange-> SetOrientation( true );
1071 _mbarrange-> setActiveStateTo(true);
1072 _mbarrange-> setVisibleLabels( true );
1073 _mbarrange-> setDeviceEndMargin(10);
1074 _mbarrange-> setRepresentedValues( 0 , sizeZ );
1075 _mbarrange-> setDeviceBlitStart(10,10);
1076 _mbarrange-> setIfWithActualDrawed( false );
1077 _mbarrange-> SetStart( 0 );
1078 _mbarrange-> SetEnd( sizeZ );
1081 // _segmentationFrame->SetEventHandler( this );
1082 segmentationOneSliceBtn->SetEventHandler( this );
1083 segmentationAllSliceBtn->SetEventHandler( this );
1084 Connect( segmentationOneSliceBtn->GetId(), wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &wxContourEventHandler::onSegmentationOneSlice );
1085 Connect( segmentationAllSliceBtn->GetId(), wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &wxContourEventHandler::onSegmentationAllSlice );
1087 wxFlexGridSizer * sizer = new wxFlexGridSizer(1);
1088 sizer -> Add( new wxStaticText(panel,-1,_T("Isovalue (Gray level)")) , 1, wxGROW );
1089 sizer -> Add( _isovalue , 1, wxGROW );
1090 sizer -> Add( methodRadiobox , 1, wxGROW );
1091 sizer -> Add( new wxStaticText(panel,-1,_T("Sampling (%)")) , 1, wxGROW );
1092 sizer -> Add( _sampling , 1, wxGROW );
1093 sizer -> Add( segmentationOneSliceBtn , 1, wxGROW );
1094 sizer -> Add( new wxStaticText(panel,-1,_T(" ")) , 1, wxGROW );
1095 sizer -> Add( _staticTextSegmentation , 1, wxGROW );
1096 sizer -> Add( segmentationAllSliceBtn , 1, wxGROW );
1097 sizer -> Add( _mbarrange , 1, wxGROW );
1099 panel->SetSizer( sizer );
1100 // panel->SetSize( sizePanel );
1101 panel->SetSize( wxDefaultSize );
1102 panel->SetAutoLayout( true );
1107 void wxContourEventHandler :: onInterfaceTestFrame( )
1109 if (_TestFrame==NULL)
1111 _contourPropagation = new ContourPropagation();
1112 _TestFrame = new wxFrame (_theViewPanel, -1,_T(" Test Segmentation "), wxDefaultPosition, wxDefaultSize, wxFRAME_TOOL_WINDOW|wxSYSTEM_MENU | wxCAPTION | wxCLIP_CHILDREN |wxFRAME_FLOAT_ON_PARENT );
1113 wxSize sizepanel(200,300);
1114 _TestFrame->SetSize( sizepanel );
1115 wxPanel *panel = new wxPanel(_TestFrame,-1);
1116 wxButton *spreadResetBtn = new wxButton(panel,-1,_T("Reset"),wxDefaultPosition, wxSize(80,35) );
1117 wxButton *spreadAddBtn = new wxButton(panel,-1,_T("Add"),wxDefaultPosition, wxSize(80,35));
1118 wxButton *spreadGoBtn = new wxButton(panel,-1,_T("GoA"),wxDefaultPosition, wxSize(80,35));
1119 _wxtextctrlTest = new wxTextCtrl(panel,-1, _T(""),wxDefaultPosition, wxSize(200,150), wxTE_MULTILINE );
1121 _TestFrame->SetEventHandler( this );
1122 Connect( spreadResetBtn->GetId(), wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &wxContourEventHandler::onTestReset );
1123 Connect( spreadAddBtn->GetId(), wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &wxContourEventHandler::onTestAdd );
1124 Connect( spreadGoBtn->GetId(), wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &wxContourEventHandler::onTestGo );
1126 wxFlexGridSizer * sizer = new wxFlexGridSizer(1);
1127 sizer -> Add( spreadResetBtn , 1, wxGROW );
1128 sizer -> Add( spreadAddBtn , 1, wxGROW );
1129 sizer -> Add( spreadGoBtn , 1, wxGROW );
1130 sizer -> Add( _wxtextctrlTest , 1, wxGROW );
1132 panel->SetSizer( sizer );
1133 panel->SetSize( sizepanel );
1134 panel->SetAutoLayout( true );
1138 if (_TestFrame->IsShown()==true)
1140 _TestFrame->Show(false);
1142 _TestFrame->Show(true);
1147 void wxContourEventHandler::onTestReset( wxCommandEvent& event )
1149 _wxtextctrlTest->SetValue(_T(""));
1150 _contourPropagation->resetAppend();
1153 //------------------------------------------------------------------------------------------------------------
1154 void wxContourEventHandler::onTestAdd( wxCommandEvent& event )
1156 std::vector<double> vecX;
1157 std::vector<double> vecY;
1158 std::vector<double> vecZ;
1159 _sceneManager->GetPointsOfActualContour( &vecX , &vecY , &vecZ );
1161 if (vecX.size()!=0){
1162 std::vector<int> tempVector;
1163 _instantPanel->getInstant( tempVector );
1164 int i,size=vecZ.size();
1165 int actualSlice = tempVector[1];
1166 for ( i=0 ; i<size ; i++ )
1168 vecZ[i] = actualSlice;
1171 _contourPropagation->appendContour(&vecX , &vecY , &vecZ);
1173 newstring.append(_wxtextctrlTest->GetValue());
1174 newstring.append(_T(" "));
1175 newstring.append(wxString(intToString(actualSlice).c_str(),wxConvUTF8));
1176 //newstring.Printf(_T("%s %d -"),, );
1177 newstring.append(_T(" -"));
1178 _wxtextctrlTest->SetValue(newstring);
1182 //------------------------------------------------------------------------------------------------------------
1183 void wxContourEventHandler::onTestGo( wxCommandEvent& event )
1185 std::vector<double> vecX;
1186 std::vector<double> vecY;
1187 std::vector<double> vecZ;
1188 std::vector<int> size;
1190 std::vector<double> vecCtrlPointX;
1191 std::vector<double> vecCtrlPointY;
1192 std::vector<double> vecCtrlPointZ;
1194 //Getting the points of the actual contour
1196 _contourPropagation->GetKeyContours(&vecX , &vecY , &vecZ, &size);
1197 for(int i = 0; i < vecX.size();i++){
1201 /*std::vector<double> vecX1;
1202 std::vector<double> vecY1;
1203 std::vector<double> vecZ1;
1204 _sceneManager->GetPointsOfActualContour( &vecX1 , &vecY1 , &vecZ1 );
1206 std::ofstream file1;
1207 file1.open( "Temp.txt" );
1210 for(int i = 0; i < vecX.size(); i++){
1211 file1<<vecX[i] <<" X1 "<< vecX1[i] <<" Y "<<vecY[i] <<" Y1 "<< vecY1[i] <<" Z "<<vecZ[i] <<" Z1 "<< vecZ1[i]<<std::endl;
1219 //Setting the points of the contour
1221 ExtractControlPoints2D *extractcontrolpoints2d = new ExtractControlPoints2D();
1222 extractcontrolpoints2d->SetContour( &vecX , &vecY , &vecZ );
1224 //Getting the control points of the contour by method A
1226 extractcontrolpoints2d->GetInitialControlPoints( &vecCtrlPointX , &vecCtrlPointY , &vecCtrlPointZ );
1228 std::vector<int> actualInstantVector;
1229 _instantPanel->getInstant( actualInstantVector );
1230 actualInstantVector[1]= this->_theViewPanel->GetZ();
1236 //Adding the Contour to the scene
1238 manualContourModel *manModelContour = new manualContourModel();
1239 int j,sizeCtrPt = vecCtrlPointX.size();
1241 for (j=0 ; j<sizeCtrPt ; j++)
1243 manModelContour->AddPoint( vecCtrlPointX[j] , vecCtrlPointY[j] , vecCtrlPointZ[j] );
1245 std::string theName;
1246 theName = _modelManager->createOutline( manModelContour, actualInstantVector );
1247 bool addedModel = theName.compare("") != 0;
1250 double spc[3];//Si no hay imagen pero hay contornos que spacing se pone por default
1251 this->_theViewPanel->getSpacing(spc);
1252 //Adding the manualContourControler to interface objects structure
1253 //Adding the manualViewContour to interface objects structure
1254 //_sceneManager->setControlActiveStateOfALL( false );//This call is being done here because if the ROI is created underneath the previously created ROIS will still be active.
1255 _sceneManager->configureViewControlTo( theName, manModelContour,spc,1 ) ;
1260 //------------------------------------------------------------------------------------------------------------
1261 void wxContourEventHandler::FillGridWithContoursInformation()
1263 wxString tempString;
1265 _grid->SetColLabelValue(0, _T("A") );
1266 _grid->SetColLabelValue(1, _T("B") );
1267 _grid->SetColLabelValue(2, _T("C") );
1268 _grid->SetColLabelValue(3, _T("D") );
1269 _grid->SetColLabelValue(4, _T("E") );
1270 _grid->SetColLabelValue(5, _T("F") );
1272 std::vector<int> tempVector;
1273 _instantPanel->getInstant( tempVector );
1275 int z,sizeZ = _sceneManager->GetImageDataSizeZ();
1276 int ii,sizeLstContourThings;
1277 for ( z=0 ; z<sizeZ ; z++)
1280 Instant instant(&tempVector);
1281 std::vector<ContourThing**> lstContourThings = this->_modelManager->getOutlinesAtInstant( &instant );
1283 sizeLstContourThings = lstContourThings.size();
1284 tempString.Printf(_T("%d - %d"),z, sizeLstContourThings);
1285 _grid->SetRowLabelValue(z, tempString );
1287 for (ii=0 ; ii<sizeLstContourThings ; ii++)
1289 ContourThing **contourthing = lstContourThings[ii];
1290 tempString = wxString((*contourthing)->getName().c_str(),wxConvUTF8) ;
1291 _grid->SetCellValue( z, ii, tempString );
1298 //------------------------------------------------------------------------------------------------------------
1299 std::vector<manualContourModel*> wxContourEventHandler::ExploseEachModel( std::vector<manualContourModel*> lstManConMod )
1301 std::vector<manualContourModel*> lstTmp;
1302 std::vector<manualContourModel*> lstResult;
1304 int i,iSize=lstManConMod.size();
1305 for (i=0;i<iSize;i++)
1307 lstTmp = lstManConMod[i]->ExploseModel();
1308 jSize=lstTmp.size();
1309 for (j=0;j<jSize;j++)
1311 lstResult.push_back( lstTmp[j] );
1317 //------------------------------------------------------------------------------------------------------------
1318 void wxContourEventHandler::onExtractInformation( wxCommandEvent& event )
1321 int maxContourGroup = 0;
1325 ContourExtractData *contourextractdata = new ContourExtractData();
1326 int typeContourGroup = this->_radiolstboxContourGroup->GetSelection();
1327 contourextractdata ->SetTypeOperation( typeContourGroup % 3 );
1329 std::vector<manualContourModel*> lstManConMod;
1330 std::vector<manualContourModel*> lstManConModTmp;
1331 std::vector<manualContourModel*> lstManConModExp;
1332 std::vector<double> pLstValue;
1333 std::vector<double> pLstValuePosX;
1334 std::vector<double> pLstValuePosY;
1335 std::vector<double> pLstValuePosZ;
1338 int resultGrayRangeCount;
1341 double resultAverage;
1342 double resultStandardeviation;
1344 std::vector<int> tempVector;
1345 _instantPanel->getInstant( tempVector );
1347 vtkImageData *imagedata = _sceneManager->GetImageData();
1348 int sizeZ = _sceneManager->GetImageDataSizeZ();
1350 int ii,sizeLstContourThings;
1359 if (_informationRadiobox->GetSelection()==0 ) // actual slice
1361 std::vector<int> tempVector;
1362 _instantPanel->getInstant( tempVector );
1363 int actualSlice = tempVector[1];
1367 if (_informationRadiobox->GetSelection()==1 ) // slice range
1369 minZ = _mbarrangeSliceInformation->GetStart();
1370 maxZ = _mbarrangeSliceInformation->GetEnd();
1372 if (_informationRadiobox->GetSelection()==2 ) // All slices
1378 totalZ = maxZ-minZ+1;
1379 contourextractdata->SetImage( imagedata);
1382 for ( z=minZ ; z<=maxZ ; z++ )
1384 porcent = 100.0* (z-minZ)/totalZ;
1385 tmpString.Printf(_T(" %d %c %d/%d %d"), (int)porcent , 37 , z-minZ+1, (int)totalZ ,z);
1386 _staticTextInformation->SetLabel(tmpString);
1388 //Extraction data from contours of each slice
1389 contourextractdata->SetZtoBeAnalys( z);
1392 Instant instant(&tempVector);
1393 std::vector<ContourThing**> lstContourThings = this->_modelManager->getOutlinesAtInstant( &instant );
1394 sizeLstContourThings = lstContourThings.size();
1396 lstManConMod.clear();
1397 for (ii=0 ; ii<sizeLstContourThings ; ii++)
1399 ContourThing **contourthing = lstContourThings[ii];
1400 lstManConMod.push_back( (*contourthing)->getModel() );
1402 lstManConModExp = ExploseEachModel( lstManConMod );
1405 wxString tempString;
1406 tempString.Printf(_T("%d - %d"),z, sizeLstContourThings);
1407 _grid->SetRowLabelValue(z, tempString );
1409 int iContourGroup,sizeContourGroup;
1410 if (typeContourGroup==3) // contour separete
1412 sizeContourGroup=lstManConModExp.size();
1413 if ( maxContourGroup<sizeContourGroup )
1415 maxContourGroup=sizeContourGroup;
1417 } else { // contour AND OR XOR
1426 for( iContourGroup=0 ; iContourGroup<sizeContourGroup ; iContourGroup++ ){
1427 lstManConModTmp.clear();
1428 if (typeContourGroup==3) // contour separete
1430 lstManConModTmp.push_back( lstManConModExp[iContourGroup]);
1431 } else { // contour AND OR XOR
1432 lstManConModTmp = lstManConModExp;
1435 contourextractdata->SetLstManualContourModel( lstManConModTmp );
1438 pLstValuePosX.clear();
1439 pLstValuePosY.clear();
1440 pLstValuePosZ.clear();
1441 contourextractdata->GetValuesInsideCrown( &pLstValue,
1445 // Statistics of each slice.
1446 contourextractdata->Statistics( &pLstValue,
1447 _mbarrangeRangeInformation->GetStart(),
1448 _mbarrangeRangeInformation->GetEnd(),
1449 &resultGrayRangeCount,
1454 &resultStandardeviation);
1455 if (_grid->GetNumberCols()<_numberOfVariablesStatistics*(iContourGroup+1) )
1457 _grid->AppendCols(_numberOfVariablesStatistics);
1460 tmpIntA=_numberOfVariablesStatistics*iContourGroup ;
1462 tempString.Printf(_T("%d"),resultSize);
1463 _grid->SetCellValue( z, tmpIntA + 0, tempString );
1464 tempString.Printf(_T("%d"),resultGrayRangeCount);
1465 _grid->SetCellValue( z, tmpIntA + 1, tempString );
1466 tempString.Printf(_T("%f"),resultMin);
1467 _grid->SetCellValue( z, tmpIntA + 2, tempString );
1468 tempString.Printf(_T("%f"),resultMax);
1469 _grid->SetCellValue( z, tmpIntA + 3, tempString );
1470 tempString.Printf(_T("%f"),resultAverage);
1471 _grid->SetCellValue( z, tmpIntA + 4, tempString );
1472 tempString.Printf(_T("%f"),resultStandardeviation);
1473 _grid->SetCellValue( z, tmpIntA + 5, tempString );
1475 } // for iContourGroup
1479 wxString tmpTitleString;
1481 for ( iTitleGroup=0 ; iTitleGroup<maxContourGroup ; iTitleGroup++ )
1483 tmpIntB =_numberOfVariablesStatistics*iTitleGroup;
1484 tmpTitleString.Printf(_T("%d-Size Data"),iTitleGroup);
1485 _grid->SetColLabelValue( tmpIntB + 0, tmpTitleString );
1486 _grid->SetColLabelValue( tmpIntB + 1, _T("Size Range") );
1487 _grid->SetColLabelValue( tmpIntB + 2, _T("Min") );
1488 _grid->SetColLabelValue( tmpIntB + 3, _T("Max") );
1489 _grid->SetColLabelValue( tmpIntB + 4, _T("Average") );
1490 _grid->SetColLabelValue( tmpIntB + 5, _T("St.Dev.") );
1491 _grid->SetColLabelValue( tmpIntB + 6, _T(" ") );
1494 _staticTextInformation->SetLabel( _T("") );
1495 delete contourextractdata;
1499 //------------------------------------------------------------------------------------------------------------
1500 void wxContourEventHandler::SaveValuesXYZ(std::string directory,std::string namefile)
1503 ContourExtractData *contourextractdata = new ContourExtractData();
1504 int typeContourGroup = this->_radiolstboxContourGroup->GetSelection();
1505 contourextractdata ->SetTypeOperation( typeContourGroup % 3 );
1507 std::vector<manualContourModel*> lstManConMod;
1508 std::vector<manualContourModel*> lstManConModTmp;
1509 std::vector<manualContourModel*> lstManConModExp;
1510 std::vector<double> pLstValue;
1511 std::vector<double> pLstValuePosX;
1512 std::vector<double> pLstValuePosY;
1513 std::vector<double> pLstValuePosZ;
1515 std::vector<int> tempVector;
1516 _instantPanel->getInstant( tempVector );
1518 vtkImageData *imagedata = _sceneManager->GetImageData();
1519 int sizeZ = _sceneManager->GetImageDataSizeZ();
1521 int ii,sizeLstContourThings;
1528 minZ = 0;// _mbarrange->GetStart();
1529 maxZ = sizeZ;//_mbarrange->GetEnd();
1530 totalZ = maxZ-minZ+1;
1532 contourextractdata->SetImage( imagedata);
1535 for ( z=0 ; z<sizeZ ; z++)
1538 porcent = 100.0* (z-minZ)/totalZ;
1540 tmpString.Printf(_T("Saving Values"));
1541 tmpString.Printf(_T(" %d %c %d/%d %d"), (int)porcent , 37 , z-minZ+1, (int)totalZ ,z);
1542 _staticTextInformation->SetLabel(tmpString);
1545 //Extraction data from contours of each slice
1546 contourextractdata->SetZtoBeAnalys( z);
1549 Instant instant(&tempVector);
1550 std::vector<ContourThing**> lstContourThings = this->_modelManager->getOutlinesAtInstant( &instant );
1551 sizeLstContourThings = lstContourThings.size();
1553 lstManConMod.clear();
1554 for (ii=0 ; ii<sizeLstContourThings ; ii++)
1556 ContourThing **contourthing = lstContourThings[ii];
1557 lstManConMod.push_back( (*contourthing)->getModel() );
1559 lstManConModExp = ExploseEachModel( lstManConMod );
1564 int iContourGroup,sizeContourGroup;
1565 if (typeContourGroup==3) // contour separete
1567 sizeContourGroup=lstManConModExp.size();
1568 } else { // contour AND OR XOR
1572 for( iContourGroup=0 ; iContourGroup<sizeContourGroup ; iContourGroup++ ){
1573 lstManConModTmp.clear();
1574 if (typeContourGroup==3) // contour separete
1576 lstManConModTmp.push_back( lstManConModExp[iContourGroup]);
1577 } else { // contour AND OR XOR
1578 lstManConModTmp = lstManConModExp;
1581 contourextractdata->SetLstManualContourModel( lstManConModTmp );
1584 pLstValuePosX.clear();
1585 pLstValuePosY.clear();
1586 pLstValuePosZ.clear();
1587 contourextractdata->GetValuesInsideCrown( &pLstValue,
1593 filename.Printf(_T("%s"),directory.c_str());
1594 filename.Printf(_T("\\"));
1595 filename.Printf(_T("%s"),namefile.c_str());
1596 filename.Printf(_T("-slice"));
1597 filename.Printf(_T("%d"),z);
1598 filename.Printf(_T("-cont"));
1599 filename.Printf(_T("%d"),iContourGroup);
1600 filename.Printf(_T(".txt"));
1601 FILE *pFile=fopen((const char *)filename.mb_str(),"w+");
1602 fprintf(pFile,"value \t x \t y \t z\n" );
1603 int iLstValue,sizeLstValue=pLstValue.size();
1604 for (iLstValue=0 ; iLstValue<sizeLstValue ; iLstValue++ )
1606 fprintf(pFile,"%f\t %f\t %f\t %f\n", (float)pLstValue[iLstValue] , (float)pLstValuePosX[iLstValue], (float)pLstValuePosY[iLstValue], (float)z );
1609 } // for iContourGroup
1611 _staticTextInformation->SetLabel( _T("") );
1612 delete contourextractdata;
1616 //------------------------------------------------------------------------------------------------------------
1617 void wxContourEventHandler::SaveImageResult(std::string directory,std::string namefile)
1620 ContourExtractData *contourextractdata = new ContourExtractData( true );
1621 int typeContourGroup = this->_radiolstboxContourGroup->GetSelection();
1622 if (typeContourGroup==3)
1626 contourextractdata ->SetTypeOperation( typeContourGroup % 3 );
1628 std::vector<manualContourModel*> lstManConMod;
1629 std::vector<manualContourModel*> lstManConModTmp;
1630 std::vector<manualContourModel*> lstManConModExp;
1632 std::vector<int> tempVector;
1633 _instantPanel->getInstant( tempVector );
1635 vtkImageData *imagedata = _sceneManager->GetImageData();
1636 int sizeZ = _sceneManager->GetImageDataSizeZ();
1638 int ii,sizeLstContourThings;
1647 minZ = 0;// _mbarrange->GetStart();
1648 maxZ = sizeZ;//_mbarrange->GetEnd();
1649 totalZ = maxZ-minZ+1;
1651 contourextractdata->SetImage( imagedata);
1654 for ( z=0 ; z<sizeZ ; z++)
1657 porcent = 100.0* (z-minZ)/totalZ;
1658 tmpString.Printf(_T("Saving Values"));
1659 tmpString.Printf(_T("%d %c %d/%d %d"), (int)porcent , 37 , z-minZ+1, (int)totalZ ,z);
1660 _staticTextInformation->SetLabel(tmpString);
1662 //Extraction data from contours of each slice
1663 contourextractdata->SetZtoBeAnalys( z);
1666 Instant instant(&tempVector);
1667 std::vector<ContourThing**> lstContourThings = this->_modelManager->getOutlinesAtInstant( &instant );
1668 sizeLstContourThings = lstContourThings.size();
1670 lstManConMod.clear();
1671 for (ii=0 ; ii<sizeLstContourThings ; ii++)
1673 ContourThing **contourthing = lstContourThings[ii];
1674 lstManConMod.push_back( (*contourthing)->getModel() );
1676 lstManConModExp = ExploseEachModel( lstManConMod );
1679 int iContourGroup,sizeContourGroup;
1680 if (typeContourGroup==3) // contour separete
1682 sizeContourGroup=lstManConModExp.size();
1683 } else { // contour AND OR XOR
1687 for( iContourGroup=0 ; iContourGroup<sizeContourGroup ; iContourGroup++ ){
1688 lstManConModTmp.clear();
1689 if (typeContourGroup==3) // contour separete
1691 lstManConModTmp.push_back( lstManConModExp[iContourGroup]);
1692 } else { // contour AND OR XOR
1693 lstManConModTmp = lstManConModExp;
1696 contourextractdata->SetLstManualContourModel( lstManConModTmp );
1699 // for (ii=0 ; ii<sizeLstContourThings ; ii++)
1701 // ContourThing **contourthing = lstContourThings[ii];
1702 // lstManConMod.push_back( (*contourthing)->getModel() );
1704 // contourextractdata->SetLstManualContourModel( lstManConMod );
1706 contourextractdata->CalculateImageResult(); // with actual Z
1708 } // for iContourGroup
1713 //filename.Printf(_T("%s\\%s-Value.mhd",directory.c_str(),namefile.c_str(),z);
1714 filename.Printf(_T("%s"),directory.c_str());
1715 filename.Printf(_T("\\"));
1716 filename.Printf(_T("%s"),namefile.c_str());
1717 filename.Printf(_T("-Value.mhd"));
1720 vtkMetaImageWriter *writerValueImage = vtkMetaImageWriter::New( );
1721 writerValueImage->SetInput( contourextractdata->GetVtkImageValueResult() );
1722 writerValueImage->SetFileName( (const char *)filename.mb_str() );
1723 writerValueImage->SetFileDimensionality( 3 );
1724 writerValueImage->Write( );
1727 // filename.Printf("%s\\%s-Mask.mhd",directory.c_str(),namefile.c_str(),z);
1728 filename.Printf(_T("%s"),directory.c_str());
1729 filename.Printf(_T("\\"));
1730 filename.Printf(_T("%s"),namefile.c_str());
1731 filename.Printf(_T("-Mask.mhd"));
1732 vtkMetaImageWriter *writerMaskImage = vtkMetaImageWriter::New( );
1733 writerMaskImage->SetInput( contourextractdata->GetVtkImageMaskResult() );
1734 writerMaskImage->SetFileName( (const char *)filename.mb_str() );
1735 writerMaskImage->SetFileDimensionality( 3 );
1736 writerMaskImage->Write( );
1738 _staticTextInformation->SetLabel( _T("") );
1739 delete contourextractdata;
1743 //------------------------------------------------------------------------------------------------------------
1744 void wxContourEventHandler::onInformationContourLabels( wxCommandEvent& event )
1747 FillGridWithContoursInformation();
1751 //------------------------------------------------------------------------------------------------------------
1752 void wxContourEventHandler::onSaveResults( wxCommandEvent& event )
1754 wxFileDialog dialog(_InformationContourFrame, _T("Choose a file"), _T(""), _T(""), _T("*.txt"), wxSAVE );
1755 if (dialog.ShowModal() == wxID_OK)
1757 onExtractInformation( event );
1758 std::string directory=(const char *)(dialog.GetDirectory().mb_str());
1759 std::string namefile=(const char *)(dialog.GetFilename().mb_str());
1761 SaveValuesXYZ( directory , namefile );
1762 SaveImageResult( directory , namefile );
1764 std::string filename = (const char *)(dialog.GetPath().mb_str() );
1765 FILE *pFile=fopen(filename.c_str(),"w+");
1767 int sizeZ = _sceneManager->GetImageDataSizeZ();
1770 int i,j,maxX,maxY=sizeZ;
1771 maxX=this->_grid->GetNumberCols();
1773 int iTitle,sizeTitle = (maxX / _numberOfVariablesStatistics);
1774 for ( iTitle=0; iTitle<sizeTitle ; iTitle++)
1776 fprintf(pFile,"-- \t %d-Size \t SizeRange \t Min \t Max \t Ave \t StDv \t" , iTitle,tmpString.char_str() );
1778 fprintf(pFile,"\n" );
1782 for ( j=0; j<maxY ; j++)
1784 fprintf(pFile,"%d\t" , j );
1785 for (i=0 ; i<maxX ; i++){
1786 tmpString = _grid->GetCellValue( j , i );
1787 fprintf(pFile,"%s\t" , (const char *)(tmpString.mb_str()) );
1789 fprintf(pFile,"\n" );
1799 //------------------------------------------------------------------------------------------------------------
1800 void wxContourEventHandler::onInformationContourFrame()
1802 if (_InformationContourFrame==NULL)
1804 _InformationContourFrame = new wxFrame (_theViewPanel, -1,_T(" Information "), wxDefaultPosition, wxDefaultSize, wxFRAME_TOOL_WINDOW|wxSYSTEM_MENU | wxCAPTION | wxCLIP_CHILDREN |wxFRAME_FLOAT_ON_PARENT | wxRESIZE_BORDER );
1805 _InformationContourFrame->SetSize( wxSize(500,450) );
1806 wxSize sizepanel(200,300);
1807 wxPanel *panel = getInformationPanel(_InformationContourFrame);
1808 //JCP 13-10-09 Grouping the panel in a method
1809 /*new wxPanel(_InformationContourFrame,-1,wxDefaultPosition, wxDefaultSize,wxTAB_TRAVERSAL);
1811 wxString lstOptions[4];
1812 lstOptions[0]=_T("Actual Slice");
1813 lstOptions[1]=_T("Range Slices");
1814 lstOptions[2]=_T("All Slices");
1815 _informationRadiobox = new wxRadioBox(panel, -1, _T("Slice analysis"), wxDefaultPosition, wxSize(270,45), 3 , lstOptions, 3, wxRA_SPECIFY_COLS);
1817 wxString lstOptContOperation[5];
1818 lstOptContOperation[0]=_T("AND");
1819 lstOptContOperation[1]=_T("OR");
1820 lstOptContOperation[2]=_T("XOR");
1821 lstOptContOperation[3]=_T("ALL");
1822 _radiolstboxContourGroup = new wxRadioBox(panel, -1, _T("Contour group"), wxDefaultPosition, wxSize(270,45), 4 , lstOptContOperation, 4, wxRA_SPECIFY_COLS);
1824 wxButton *informationContourLabelsBtn = new wxButton(panel,-1,_T("Contour labels"),wxDefaultPosition, wxSize(140,35) );
1825 informationContourLabelsBtn->SetEventHandler( this );
1826 Connect( informationContourLabelsBtn->GetId(), wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &wxContourEventHandler::onInformationContourLabels );
1828 wxButton *statisticsContourBtn = new wxButton(panel,-1,_T("Contour statistics"),wxDefaultPosition, wxSize(140,35) );
1829 statisticsContourBtn->SetEventHandler( this );
1830 Connect( statisticsContourBtn->GetId(), wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &wxContourEventHandler::onExtractInformation );
1832 wxButton *saveResultsBtn = new wxButton(panel,-1,_T("Save statistics results"),wxDefaultPosition, wxSize(140,35) );
1833 saveResultsBtn->SetEventHandler( this );
1834 Connect( saveResultsBtn->GetId(), wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &wxContourEventHandler::onSaveResults );
1837 int sizeZ = this->_sceneManager->GetImageDataSizeZ();
1838 _mbarrangeSliceInformation = new mBarRange(panel,65,65);
1839 _mbarrangeSliceInformation->SetMin(0);
1840 _mbarrangeSliceInformation->SetStart(0);
1841 _mbarrangeSliceInformation-> SetOrientation( true );
1842 _mbarrangeSliceInformation-> setActiveStateTo(true);
1843 _mbarrangeSliceInformation-> setVisibleLabels( true );
1844 _mbarrangeSliceInformation-> setDeviceEndMargin(10);
1845 _mbarrangeSliceInformation-> setRepresentedValues( 0 , sizeZ-1 );
1846 _mbarrangeSliceInformation-> setDeviceBlitStart(10,10);
1847 _mbarrangeSliceInformation-> setIfWithActualDrawed( false );
1848 _mbarrangeSliceInformation-> SetStart( 0 );
1849 _mbarrangeSliceInformation-> SetEnd( sizeZ-1 );
1853 this->_sceneManager->GetImageDataRange(range);
1854 _mbarrangeRangeInformation = new mBarRange(panel,65,65);
1855 _mbarrangeRangeInformation->SetMin(0);
1856 _mbarrangeRangeInformation->SetStart(0);
1857 _mbarrangeRangeInformation-> SetOrientation( true );
1858 _mbarrangeRangeInformation-> setActiveStateTo(true);
1859 _mbarrangeRangeInformation-> setVisibleLabels( true );
1860 _mbarrangeRangeInformation-> setDeviceEndMargin(10);
1861 _mbarrangeRangeInformation-> setRepresentedValues( range[0] , range[1] );
1862 _mbarrangeRangeInformation-> setDeviceBlitStart(10,10);
1863 _mbarrangeRangeInformation-> setIfWithActualDrawed( false );
1864 _mbarrangeRangeInformation-> SetStart( range[0] );
1865 _mbarrangeRangeInformation-> SetEnd( range[1] );
1868 _staticTextInformation = new wxStaticText(panel,-1,_T(" "));
1871 // wxButton *XXXXXXXBtn = new wxButton(panel,-1,_T("Statistics"),wxDefaultPosition, wxSize(180,35) );
1872 // XXXXXXXBtn->SetEventHandler( this );
1873 // Connect( XXXXXXXBtn->GetId(), wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &wxContourEventHandler::onXXXXX );
1876 _grid = new wxGrid( panel,
1879 wxSize( 100, 100 ) );
1881 int i,gridCol=10,gridRow=sizeZ;
1882 _grid->CreateGrid( 0, 0 );
1883 _grid->AppendRows(gridRow);
1884 _grid->AppendCols(gridCol);
1886 for (i=0;i<gridRow;i++)
1888 _grid->SetRowLabelValue(i, _T(" ") );
1890 // _grid->SetColLabelSize(0);
1893 FillGridWithContoursInformation();
1895 wxFlexGridSizer * sizerA = new wxFlexGridSizer(10);
1896 sizerA->Add( _informationRadiobox , 1, wxALL ,2 );
1897 sizerA->Add( _radiolstboxContourGroup , 1, wxALL ,2 );
1899 wxFlexGridSizer * sizerB = new wxFlexGridSizer(10);
1900 sizerB->Add( informationContourLabelsBtn , 1, wxALL ,2 );
1901 sizerB->Add( statisticsContourBtn , 1, wxALL ,2 );
1902 sizerB->Add( saveResultsBtn , 1, wxALL ,2 );
1904 wxFlexGridSizer * sizer = new wxFlexGridSizer(1);
1905 sizer->AddGrowableCol(0);
1906 sizer->AddGrowableRow(7);
1907 sizer->Add( sizerA , 1, wxALL , 0 );
1908 sizer->Add( new wxStaticText(panel ,-1,_T("Slice Range")) , 1, wxALL , 0 );
1909 sizer->Add( _mbarrangeSliceInformation , 1, wxALL|wxGROW , 2 );
1910 sizer->Add( new wxStaticText(panel ,-1,_T("Gray Range")) , 1, wxALL , 0 );
1911 sizer->Add( _mbarrangeRangeInformation , 1, wxALL|wxGROW , 2 );
1912 sizer->Add( sizerB , 1, wxALL , 0 );
1913 sizer->Add( _staticTextInformation , 1, wxALL , 0 );
1914 sizer->Add( _grid , 1, wxEXPAND , 0 );
1918 panel->SetSizer( sizer );
1919 panel->SetSize( wxSize(1500,1500) );
1920 //panel->SetBackgroundColour( wxColour(100,100,100) );
1921 panel->SetAutoLayout( true );
1924 wxBoxSizer * sizerPanel = new wxBoxSizer(wxHORIZONTAL);
1926 // sizerPanel->AddGrowableCol(0);
1927 // sizerPanel->AddGrowableRow(0);
1930 //sizerPanel -> Add( sizer , 1, wxEXPAND ,0);
1931 sizerPanel -> Add( panel->GetSizer() , 1, wxEXPAND ,0);
1936 _InformationContourFrame->SetSizer( sizerPanel );
1937 _InformationContourFrame->SetAutoLayout( true );
1938 _InformationContourFrame->Layout();
1940 _InformationContourFrame->Show();
1942 if (_InformationContourFrame->IsShown()==true)
1944 _InformationContourFrame->Show(false);
1946 FillGridWithContoursInformation();
1947 _InformationContourFrame->Show(true);
1952 wxPanel* wxContourEventHandler::getInformationPanel(wxWindow* parent){
1953 wxPanel *panel = new wxPanel(parent,-1,wxDefaultPosition, wxDefaultSize,wxTAB_TRAVERSAL);
1955 wxString lstOptions[4];
1956 lstOptions[0]=_T("Actual Slice");
1957 lstOptions[1]=_T("Range Slices");
1958 lstOptions[2]=_T("All Slices");
1959 _informationRadiobox = new wxRadioBox(panel, -1, _T("Slice analysis"), wxDefaultPosition, wxSize(270,45), 3 , lstOptions, 3, wxRA_SPECIFY_COLS);
1961 wxString lstOptContOperation[5];
1962 lstOptContOperation[0]=_T("AND");
1963 lstOptContOperation[1]=_T("OR");
1964 lstOptContOperation[2]=_T("XOR");
1965 lstOptContOperation[3]=_T("ALL");
1966 _radiolstboxContourGroup = new wxRadioBox(panel, -1, _T("Contour group"), wxDefaultPosition, wxSize(270,45), 4 , lstOptContOperation, 4, wxRA_SPECIFY_COLS);
1968 wxButton *informationContourLabelsBtn = new wxButton(panel,-1,_T("Contour labels"),wxDefaultPosition, wxSize(140,35) );
1969 informationContourLabelsBtn->SetEventHandler( this );
1970 Connect( informationContourLabelsBtn->GetId(), wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &wxContourEventHandler::onInformationContourLabels );
1972 wxButton *statisticsContourBtn = new wxButton(panel,-1,_T("Contour statistics"),wxDefaultPosition, wxSize(140,35) );
1973 statisticsContourBtn->SetEventHandler( this );
1974 Connect( statisticsContourBtn->GetId(), wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &wxContourEventHandler::onExtractInformation );
1976 wxButton *saveResultsBtn = new wxButton(panel,-1,_T("Save statistics results"),wxDefaultPosition, wxSize(140,35) );
1977 saveResultsBtn->SetEventHandler( this );
1978 Connect( saveResultsBtn->GetId(), wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &wxContourEventHandler::onSaveResults );
1981 int sizeZ = this->_sceneManager->GetImageDataSizeZ();
1982 _mbarrangeSliceInformation = new mBarRange(panel,65,65);
1983 _mbarrangeSliceInformation->SetMin(0);
1984 _mbarrangeSliceInformation->SetStart(0);
1985 _mbarrangeSliceInformation-> SetOrientation( true );
1986 _mbarrangeSliceInformation-> setActiveStateTo(true);
1987 _mbarrangeSliceInformation-> setVisibleLabels( true );
1988 _mbarrangeSliceInformation-> setDeviceEndMargin(10);
1989 _mbarrangeSliceInformation-> setRepresentedValues( 0 , sizeZ-1 );
1990 _mbarrangeSliceInformation-> setDeviceBlitStart(10,10);
1991 _mbarrangeSliceInformation-> setIfWithActualDrawed( false );
1992 _mbarrangeSliceInformation-> SetStart( 0 );
1993 _mbarrangeSliceInformation-> SetEnd( sizeZ-1 );
1997 this->_sceneManager->GetImageDataRange(range);
1998 _mbarrangeRangeInformation = new mBarRange(panel,65,65);
1999 _mbarrangeRangeInformation->SetMin(0);
2000 _mbarrangeRangeInformation->SetStart(0);
2001 _mbarrangeRangeInformation-> SetOrientation( true );
2002 _mbarrangeRangeInformation-> setActiveStateTo(true);
2003 _mbarrangeRangeInformation-> setVisibleLabels( true );
2004 _mbarrangeRangeInformation-> setDeviceEndMargin(10);
2005 _mbarrangeRangeInformation-> setRepresentedValues( range[0] , range[1] );
2006 _mbarrangeRangeInformation-> setDeviceBlitStart(10,10);
2007 _mbarrangeRangeInformation-> setIfWithActualDrawed( false );
2008 _mbarrangeRangeInformation-> SetStart( range[0] );
2009 _mbarrangeRangeInformation-> SetEnd( range[1] );
2012 _staticTextInformation = new wxStaticText(panel,-1,_T(" "));
2015 // wxButton *XXXXXXXBtn = new wxButton(panel,-1,_T("Statistics"),wxDefaultPosition, wxSize(180,35) );
2016 // XXXXXXXBtn->SetEventHandler( this );
2017 // Connect( XXXXXXXBtn->GetId(), wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &wxContourEventHandler::onXXXXX );
2020 _grid = new wxGrid( panel,
2023 wxSize( 100, 100 ) );
2025 int i,gridCol=10,gridRow=sizeZ;
2026 _grid->CreateGrid( 0, 0 );
2027 _grid->AppendRows(gridRow);
2028 _grid->AppendCols(gridCol);
2030 for (i=0;i<gridRow;i++)
2032 _grid->SetRowLabelValue(i, _T(" ") );
2034 // _grid->SetColLabelSize(0);
2037 FillGridWithContoursInformation();
2039 wxFlexGridSizer * sizerA = new wxFlexGridSizer(10);
2040 sizerA->Add( _informationRadiobox , 1, wxALL ,2 );
2041 sizerA->Add( _radiolstboxContourGroup , 1, wxALL ,2 );
2043 wxFlexGridSizer * sizerB = new wxFlexGridSizer(10);
2044 sizerB->Add( informationContourLabelsBtn , 1, wxALL ,2 );
2045 sizerB->Add( statisticsContourBtn , 1, wxALL ,2 );
2046 sizerB->Add( saveResultsBtn , 1, wxALL ,2 );
2048 wxFlexGridSizer * sizer = new wxFlexGridSizer(1);
2049 sizer->AddGrowableCol(0);
2050 sizer->AddGrowableRow(7);
2051 sizer->Add( sizerA , 1, wxALL , 0 );
2052 sizer->Add( new wxStaticText(panel ,-1,_T("Slice Range")) , 1, wxALL , 0 );
2053 sizer->Add( _mbarrangeSliceInformation , 1, wxALL|wxGROW , 2 );
2054 sizer->Add( new wxStaticText(panel ,-1,_T("Gray Range")) , 1, wxALL , 0 );
2055 sizer->Add( _mbarrangeRangeInformation , 1, wxALL|wxGROW , 2 );
2056 sizer->Add( sizerB , 1, wxALL , 0 );
2057 sizer->Add( _staticTextInformation , 1, wxALL , 0 );
2058 sizer->Add( _grid , 1, wxEXPAND , 0 );
2062 panel->SetSizer( sizer );
2063 panel->SetSize( wxSize(1500,1500) );
2064 //panel->SetBackgroundColour( wxColour(100,100,100) );
2065 panel->SetAutoLayout( true );
2069 //------------------------------------------------------------------------------------------------------------
2070 void wxContourEventHandler :: onSpreadInDepth( std::vector<std::string> & keyNamesVector )
2074 //------------------------------------------------------------------------------------------------------------
2075 void wxContourEventHandler :: onOutline_Union_Of( std::vector<std::string> & keyNamesVector )
2079 //------------------------------------------------------------------------------------------------------------
2080 void wxContourEventHandler :: onOutline_Intersection_Of( std::vector<std::string> & keyNamesVector )
2084 //------------------------------------------------------------------------------------------------------------
2085 void wxContourEventHandler :: onOutline_Combination_Of( std::vector<std::string> & keyNamesVector )
2089 //------------------------------------------------------------------------------------------------------------
2090 void wxContourEventHandler :: onOutline_Fragmentation_Of( std::vector<std::string> & keyNamesVector )
2094 //------------------------------------------------------------------------------------------------------------
2095 void wxContourEventHandler :: onOutline_Agrupation_Of( std::vector<std::string> & keyNamesVector )
2099 //------------------------------------------------------------------------------------------------------------
2100 void wxContourEventHandler :: onCopyOutlines( std::vector<std::string> & keyNamesVector )
2102 std::vector<int> tempVector;
2103 _instantPanel->getInstant( tempVector );
2104 _performingOperation->reset();
2105 _performingOperation->setStartCommand( (char)wxContour_ActionCommandsID::COPY_TOOL );
2106 _performingOperation->setStartOperationInstantVector( tempVector );
2107 _performingOperation->setKeyNamesOperationElems( keyNamesVector );
2110 //------------------------------------------------------------------------------------------------------------
2111 void wxContourEventHandler :: onPasteOutlines( )
2113 char theStartCommand = _performingOperation->getStartCommand();
2114 if ( theStartCommand == wxContour_ActionCommandsID::COPY_TOOL )
2116 //JCP 20-10-08 Undo redo implementation
2118 //JCP 20-10-08 Undo redo implementation
2121 std::vector<int> tempVector;
2122 _instantPanel->getInstant( tempVector );
2123 _performingOperation->setEndOperationInstantVector ( tempVector );
2124 std::vector<std::string> elems = _performingOperation->getKeyNamesOperationElems();
2125 int i,size = elems.size();
2126 for( i=0; i<size; i++ )
2128 createCopyContourOf( elems[i], tempVector, i>0 );
2135 //------------------------------------------------------------------------------------------------------------
2136 void wxContourEventHandler :: onShowOutlines( std::vector<std::string> & keyNamesVector )
2140 //------------------------------------------------------------------------------------------------------------
2141 void wxContourEventHandler :: onHideOutlines( std::vector<std::string> & keyNamesVector )
2145 //------------------------------------------------------------------------------------------------------------
2146 void wxContourEventHandler :: onSelectOutlines( std::vector<std::string> & keyNamesVector )
2148 //if( keyNamesVector.empty() )
2150 _sceneManager->drawSelectionROI( );
2154 int ok = keyNamesVector.size();
2155 _sceneManager->selectObjects( keyNamesVector );
2156 std::string name = keyNamesVector[0];
2159 _sceneManager->drawSelectionROI( );
2160 std::vector<std::string> currentSelection = _sceneManager->getSelectedObjects();
2161 int ok = currentSelection.size();
2162 _sceneManager->selectObjects( currentSelection );*/
2164 //------------------------------------------------------------------------------------------------------------
2165 void wxContourEventHandler :: onEditOutlines( std::vector<std::string> & keyNamesVector )
2169 //------------------------------------------------------------------------------------------------------------
2171 //------------------------------------------------------------------------------------------------------------
2172 void wxContourEventHandler :: deleteContour( std::string theKeyName )
2174 manualContourModel * cModel;
2175 manualViewBaseContour * cViewer;
2176 manualContourBaseControler * cControler;
2178 ContourWrap_ViewControl *conwrapviewControl = _sceneManager->getContourWrap_ViewControlOf( theKeyName );
2179 cControler = conwrapviewControl->getControler();
2180 int ispartofstaticlst= _modelManager->IsPartOfStaticList(theKeyName);
2181 if ((cControler!=NULL) && (cControler->IsEditable()==false) && (ispartofstaticlst==-1) )
2183 _sceneManager->removeFromScene( theKeyName );
2184 cModel = _modelManager->getOutlineByKeyName(theKeyName)->getModel();
2185 _modelManager->removeOutline( theKeyName );
2186 cViewer = conwrapviewControl->getViewer();
2187 _sceneManager->removeWrap( theKeyName );
2189 //FILE *ff = fopen("c:/temp/wxVtkBaseView_SceneManagerStadistics.txt","a+");
2190 //fprintf(ff,"EED wxContourEventHandler::deleteContours() \n" );
2191 //fprintf(ff," %s %p\n",keyNamesVector[i].c_str(), cControler );
2199 //------------------------------------------------------------------------------------------------------------
2200 void wxContourEventHandler :: deleteContours( std::vector<std::string> keyNamesVector )
2202 int i,size=keyNamesVector.size();
2203 for (i=0;i<size;i++)
2205 deleteContour( keyNamesVector[i] );
2209 //------------------------------------------------------------------------------------------------------------
2210 void wxContourEventHandler :: deleteAllContours( )
2213 std::vector<int> tempVector;
2214 _instantPanel->getInstant( tempVector );
2216 //JCP --08-09-2008 When using a diferent interface the _mbarrangeDeleteAll might not be initialize
2217 // the values in GetStart and GetEnd will then not be initialize also.
2218 // We use instead the values given when initializing the _deletepanel.
2220 //int minZ = _mbarrangeDeleteAll->GetStart();
2221 //int maxZ = _mbarrangeDeleteAll->GetEnd();
2225 maxZ = _sceneManager->GetImageDataSizeZ();
2229 _sceneManager->removeSceneContours( );
2230 _modelManager->removeAllOutlines();
2231 _sceneManager->removeAllOutlines();
2234 if ( (minZ==0) && (maxZ==_mbarrangeDeleteAll->GetMax() ))
2236 _sceneManager->removeSceneContours( );
2237 _modelManager->removeAllOutlines();
2238 _sceneManager->removeAllOutlines();
2241 for ( z=minZ ; z<=maxZ ; z++)
2244 Instant instant(&tempVector);
2245 std::vector<ContourThing**> lstContourThings = this->_modelManager->getOutlinesAtInstant( &instant );
2247 sizeLstContourThings = lstContourThings.size();
2248 for (ii=0 ; ii<sizeLstContourThings ; ii++)
2250 ContourThing **contourthing = lstContourThings[ii];
2251 deleteContour( (*contourthing)->getName() );
2258 //------------------------------------------------------------------------------------------------------------
2259 void wxContourEventHandler::openContours( FILE *pFile, bool staticContour )
2262 fscanf(pFile,"%s",tmp); // NumberOfContours
2263 fscanf(pFile,"%s",tmp); // ##
2264 int numberOfContours = atoi(tmp);
2266 std::vector<int> instantVector;
2267 int typeContourModel;
2268 manualContourModel *manModelContour;
2272 for (i=0;i<numberOfContours;i++)
2274 instantVector.clear();
2275 fscanf(pFile,"%s",tmp); // Instant
2277 fscanf(pFile,"%s",tmp); // 1
2278 instantVector.push_back( atoi(tmp) );
2279 fscanf(pFile,"%s",tmp); // 2
2280 instantVector.push_back( atoi(tmp) );
2281 fscanf(pFile,"%s",tmp); // 3
2282 instantVector.push_back( atoi(tmp) );
2283 fscanf(pFile,"%s",tmp); // 4
2284 instantVector.push_back( atoi(tmp) );
2285 fscanf(pFile,"%s",tmp); // 5
2286 instantVector.push_back( atoi(tmp) );
2287 fscanf(pFile,"%s",tmp); // 6
2288 instantVector.push_back( atoi(tmp) );
2291 fscanf(pFile,"%s",tmp); // TypeContourModel
2292 fscanf(pFile,"%s",tmp); // ##
2293 typeContourModel = atoi(tmp);
2295 manModelContour = factoryManualContourModel(typeContourModel);
2296 manModelContour->Open(pFile);
2298 fscanf(pFile,"%s",tmp); // TypeView
2299 fscanf(pFile,"%s",tmp); // ##
2300 typeView = atoi(tmp);
2308 std::string theName;
2309 theName = _modelManager->createOutline( manModelContour, instantVector );
2310 bool addedModel = theName.compare("") != 0;
2313 double spc[3];//Si no hay imagen pero hay contornos que spacing se pone por default
2314 this->_theViewPanel->getSpacing(spc);
2315 //Adding the manualContourControler to interface objects structure
2316 //Adding the manualViewContour to interface objects structure
2317 //_sceneManager->setControlActiveStateOfALL( false );//This call is being done here because if the ROI is created underneath the previously created ROIS will still be active.
2318 _sceneManager->configureViewControlTo( theName, manModelContour,spc , typeView) ;
2321 if (staticContour==true)
2323 Instant instant(&instantVector);
2324 changeContourOfManager( theName , &instant );
2327 }// for numberOfContours
2333 //------------------------------------------------------------------------------------------------------------
2334 void wxContourEventHandler::openFileWithContours()
2337 wxFileDialog dialog(NULL, _T("Choose a file"), _T(""), _T(""), _T("*.roi"), wxOPEN );
2338 if (dialog.ShowModal() == wxID_OK)
2340 fileNameContourROI = (const char *)(dialog.GetPath().mb_str());
2341 FILE *pFile=fopen(fileNameContourROI.c_str(),"r+");
2343 fscanf(pFile,"%s",tmp); // --CreaContour--
2345 fscanf(pFile,"%s",tmp); // Version
2346 fscanf(pFile,"%s",tmp); // 1.0.1
2347 std::string version(tmp);
2349 openContours(pFile,false);
2350 if (version!="1.0.0"){
2351 openContours(pFile,true);
2353 // _sceneManager->openFileWithContours(ff);
2357 _sceneManager->removeSceneContours();
2359 //updateInstantOutlines();
2363 //------------------------------------------------------------------------------------------------------------
2364 void wxContourEventHandler::saveFileWithContours( std::string filename )
2366 FILE *pFile=fopen(filename.c_str(),"w+");
2367 std::vector< std::string > lstNameThings;
2368 int i,sizeLstNameThings;
2370 fprintf(pFile,"--CreaContour--\n");
2371 fprintf(pFile,"Version %s\n", "1.0.1" );
2374 lstNameThings = _modelManager->GetLstNameThings();
2375 sizeLstNameThings = lstNameThings.size();
2376 fprintf(pFile,"NumberOfContours %d\n", sizeLstNameThings );
2377 for (i=0 ; i<sizeLstNameThings ; i++)
2379 _modelManager->SaveThingName( pFile, lstNameThings[i] );
2380 _sceneManager->SaveThingName( pFile, lstNameThings[i] );
2383 //-- Contours Statics
2384 lstNameThings = _modelManager->GetLstNameThingsStatic();
2385 sizeLstNameThings = lstNameThings.size();
2386 fprintf(pFile,"NumberOfContoursStatic %d\n", sizeLstNameThings );
2387 for (i=0 ; i<sizeLstNameThings ; i++)
2389 _modelManager->SaveThingName( pFile, lstNameThings[i] );
2390 _sceneManager->SaveThingName( pFile, lstNameThings[i] );
2396 //----------------------------------------------------------
2398 void wxContourEventHandler::saveFileWithContours()
2400 wxFileDialog dialog(NULL, _T("Choose a file"), _T(""), _T(""), _T("*.roi"), wxSAVE );
2401 if (dialog.ShowModal() == wxID_OK)
2403 fileNameContourROI = (const char *)(dialog.GetPath().mb_str());
2404 saveFileWithContours( fileNameContourROI );
2408 //------------------------------------------------------------------------------------------------------------
2409 void wxContourEventHandler :: saveFileWithContoursAutomatique()
2411 if (fileNameContourROI=="")
2413 saveFileWithContours();
2415 saveFileWithContours(fileNameContourROI);
2420 //------------------------------------------------------------------------------------------------------------
2421 void wxContourEventHandler :: createCopyContourOf ( std::string anExistingKName, std::vector<int> &instantNoTouchData, bool append )
2423 std::string cloneName = _modelManager->createCopyContourOf( anExistingKName, instantNoTouchData );
2424 manualContourModel * manualModel = _modelManager->getOutlineByKeyName( cloneName )->getModel();
2425 _sceneManager->createCopyContourOf( anExistingKName, cloneName, manualModel , append );
2429 //------------------------------------------------------------------------------------------------------------
2430 manualContourModel * wxContourEventHandler::factoryManualContourModel(int typeContour)
2432 manualContourModel *manModelContour=NULL;
2437 manModelContour = new manualContourModel();
2443 manModelContour = new manualContourModel();
2449 manModelContour = new manualContourModelRoi();
2455 manModelContour = new manualContourModelCircle();
2461 manualContourModelBullEye *manModelContourBullEye = new manualContourModelBullEye();
2462 manModelContour = manModelContourBullEye;
2463 if (_panelBullEyeOptions!=NULL){
2464 int iCrown,sizeCrowns,iSector,sizeSectors;
2465 double radioA,radioB,ang,angDelta ;
2466 sizeCrowns = _panelBullEyeOptions->GetNumberOfCrowns();
2467 for ( iCrown=0 ; iCrown<sizeCrowns ; iCrown++ )
2469 sizeSectors = _panelBullEyeOptions->GetNumberOfSections(iCrown);
2470 radioB = _panelBullEyeOptions->GetRadioOfCrown(iCrown);
2471 if (iCrown==sizeCrowns-1)
2475 radioA = _panelBullEyeOptions->GetRadioOfCrown(iCrown+1);
2477 radioA=radioA/100.0;
2478 radioB=radioB/100.0;
2479 for ( iSector=0 ; iSector<sizeSectors ; iSector++ )
2481 ang = _panelBullEyeOptions->GetAngOfCrownSection(iCrown,iSector);
2482 angDelta= _panelBullEyeOptions->GetAngDeltaOfCrownSection(iCrown);
2483 manModelContourBullEye->AddSector(radioA,radioB,ang,angDelta);
2486 } // if _panelBullEyeOptions
2487 }// if typeContour==4
2489 return manModelContour;
2492 //------------------------------------------------------------------------------------------------------------
2493 void wxContourEventHandler :: createContour( int typeContour )
2495 //Creating the manualContourModel and including in the model
2496 manualContourModel * manModelContour = factoryManualContourModel(typeContour);
2497 std::vector<int> instantVector;
2498 _instantPanel->getInstant( instantVector );
2499 std::string theName;
2500 theName= _modelManager->createOutline( manModelContour, instantVector );
2501 bool addedModel = theName.compare("") != 0;
2504 double spc[3];//Si no hay imagen pero hay contornos que spacing se pone por default
2505 this->_theViewPanel->getSpacing(spc);
2506 //Adding the manualContourControler to interface objects structure
2507 //Adding the manualViewContour to interface objects structure
2508 //_sceneManager->setControlActiveStateOfALL( false );//This call is being done here because if the ROI is created underneath the previously created ROIS will still be active.
2509 _sceneManager->configureViewControlTo( theName, manModelContour,spc , typeContour) ;
2513 //FILE *ff = fopen("c:/temp/wxVtkBaseView_SceneManagerStadistics.txt","a+");
2514 //fprintf(ff,"EED wxContourEventHandler::createContour() \n" );
2515 //fprintf(ff," %s\n %p ",theName.c_str() , );
2520 manualContourModel * wxContourEventHandler::factoryManualContourModel(PanelBullEyeOptions* panel){
2522 manualContourModelBullEye *manModelContourBullEye = new manualContourModelBullEye();
2523 manualContourModel *manModelContour=NULL;
2524 manModelContour = manModelContourBullEye;
2526 int iCrown,sizeCrowns,iSector,sizeSectors;
2527 double radioA,radioB,ang,angDelta ;
2528 sizeCrowns = panel->GetNumberOfCrowns();
2529 for ( iCrown=0 ; iCrown<sizeCrowns ; iCrown++ )
2531 sizeSectors = panel->GetNumberOfSections(iCrown);
2532 radioB = panel->GetRadioOfCrown(iCrown);
2533 if (iCrown==sizeCrowns-1)
2537 radioA = panel->GetRadioOfCrown(iCrown+1);
2539 radioA=radioA/100.0;
2540 radioB=radioB/100.0;
2541 for ( iSector=0 ; iSector<sizeSectors ; iSector++ )
2543 ang = panel->GetAngOfCrownSection(iCrown,iSector);
2544 angDelta= panel->GetAngDeltaOfCrownSection(iCrown);
2545 manModelContourBullEye->AddSector(radioA,radioB,ang,angDelta);
2548 } // if _panelBullEyeOptions
2550 return manModelContour;
2553 void wxContourEventHandler :: createContourBullsEye(PanelBullEyeOptions* panel )
2555 //Creating the manualContourModel and including in the model
2556 manualContourModel * manModelContour = factoryManualContourModel(panel );
2557 std::vector<int> instantVector;
2558 _instantPanel->getInstant( instantVector );
2559 std::string theName;
2560 theName= _modelManager->createOutline( manModelContour, instantVector );
2561 bool addedModel = theName.compare("") != 0;
2564 double spc[3];//Si no hay imagen pero hay contornos que spacing se pone por default
2565 this->_theViewPanel->getSpacing(spc);
2566 //Adding the manualContourControler to interface objects structure
2567 //Adding the manualViewContour to interface objects structure
2568 //_sceneManager->setControlActiveStateOfALL( false );//This call is being done here because if the ROI is created underneath the previously created ROIS will still be active.
2569 _sceneManager->configureViewControlTo( theName, manModelContour,spc , 4) ;
2573 //FILE *ff = fopen("c:/temp/wxVtkBaseView_SceneManagerStadistics.txt","a+");
2574 //fprintf(ff,"EED wxContourEventHandler::createContour() \n" );
2575 //fprintf(ff," %s\n %p ",theName.c_str() , );
2581 //------------------------------------------------------------------------------------------------------------
2582 // Attributes getters and setters
2583 //------------------------------------------------------------------------------------------------------------
2585 void wxContourEventHandler :: setModelManager( OutlineModelManager * theModelManager )
2587 _modelManager = theModelManager;
2588 _workSpace = _modelManager->getContourWorkspace();
2590 //------------------------------------------------------------------------------------------------------------
2591 void wxContourEventHandler :: setViewPanel( wxContourViewPanel * theViewPanel )
2593 _theViewPanel = theViewPanel;
2594 _theViewPanel->setWxEventHandler( this );
2597 this->_theViewPanel->getSpacing(spc);
2598 _sceneManager = new wxVtkBaseView_SceneManager ( this->_theViewPanel->getWxVtkBaseView(), this, spc );
2600 Connect( _theViewPanel->GetId(), wxINSTANT_CHANGE, (wxObjectEventFunction) (wxCommandEventFunction) &wxContourEventHandler::onChangeInstant );
2601 Connect( wxID_ANY, wxEVT_START_CREATE_MULT_ROI, (wxObjectEventFunction) (wxCommandEventFunction) &wxContourEventHandler::onCreateMultipleROI );
2602 Connect( wxID_ANY, wxEVT_START_CREATE_ROI, (wxObjectEventFunction) (wxCommandEventFunction) &wxContourEventHandler::onCreateROI );
2603 Connect( wxID_ANY, wxEVT_STOP_CREATE_ROI, (wxObjectEventFunction) (wxCommandEventFunction) &wxContourEventHandler::onStopCreateROI );
2604 Connect( wxID_ANY, wxEVT_CHANGED_DEEP, (wxObjectEventFunction) (wxCommandEventFunction) &wxContourEventHandler::onChangedDeep );
2605 Connect( wxID_ANY, wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &wxContourEventHandler :: onActionButtonPressed );
2610 //------------------------------------------------------------------------------------------------------------
2611 void wxContourEventHandler :: setInstantChooserPanel( wxInstantChooserPanel * theInstantChooserPanel )
2613 _instantPanel = theInstantChooserPanel;
2614 _instantPanel->setWxEventHandler( this );
2616 Connect( _instantPanel->GetId(), wxINSTANT_CHOOSER_CHANGE, (wxObjectEventFunction) (wxCommandEventFunction) &wxContourEventHandler::onChangeInstant );
2618 std::vector<int> vect;
2619 _instantPanel->getInstant( vect );
2620 _actualInstant = new Instant( &vect );
2622 if( _modelManager!=NULL )
2624 std::vector<std::string> conceptNameVect;
2625 std::vector<int> conceptSizeVect;
2626 _modelManager-> getConceptsInformation(conceptNameVect, conceptSizeVect);
2628 int max = conceptNameVect.size();
2631 if( conceptNameVect[i].compare("Axe Depth") == 0 )
2633 _instantPanel->addConcept( conceptNameVect[i], 0, conceptSizeVect[i], 1);
2635 _instantPanel->addConcept( conceptNameVect[i], 1, conceptSizeVect[i], 1);
2639 //Should be configured later, or abort program, because Model -NEEDS- to be added before chooserPanel
2641 if( _theViewPanel!=NULL )
2643 double val = _theViewPanel->getCurrentDeep();
2644 _instantPanel->setConceptValue( "Axe Depth", (int)val );
2645 ConceptDataWrap * data = _instantPanel->getConceptDataOf( "Axe Depth" );
2647 _theViewPanel->setVerticalConcept( "Axe Depth", data->getMinValue(), data->getMaxValue(), data->getMinShowedValue(), data->getMaxShowedValue(), data->getActualValue() );
2649 //Should be configured later, or abort program, because ViewPanel -NEEDS- to be added before chooserPanel
2654 //------------------------------------------------------------------------------------------------------------
2655 void wxContourEventHandler :: setButtonsBar( wxContour_ButtonsBar * theButtonsBar )
2657 _buttonsBar = theButtonsBar;
2658 _buttonsBar->setWxEventHandler( this );
2659 Connect( _buttonsBar->GetId(), wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &wxContourEventHandler:: onActionButtonPressed );
2661 //------------------------------------------------------------------------------------------------------------
2662 void wxContourEventHandler :: setGrid( wxContour_Grid * theGridPanel )
2664 _gridPanel = theGridPanel;
2666 //------------------------------------------------------------------------------------------------------------
2667 void wxContourEventHandler :: setDrawToolsPanel( wxContour_DrawToolsPanel * theDrawToolsPanel )
2669 _drawToolsPanel = theDrawToolsPanel;
2671 //------------------------------------------------------------------------------------------------------------
2672 void wxContourEventHandler :: setOperationsToolsPanel( wxContour_OperationsToolsPanel * theOperationsToolsPanel )
2674 _operationsToolsPanel = theOperationsToolsPanel;
2676 //------------------------------------------------------------------------------------------------------------
2677 void wxContourEventHandler :: setAutomaticFormsPanel( wxContour_AutomaticFormsToolsPanel * theAutoFormsPanel )
2679 _autoFormsPanel = theAutoFormsPanel;
2682 void wxContourEventHandler :: setStandardToolsPanel( wxContour_StandardToolsPanel * theStandardToolsPanel )
2684 _standardToolsPanel= theStandardToolsPanel;
2686 //------------------------------------------------------------------------------------------------------------
2687 void wxContourEventHandler :: setEditionToolsPanel( wxContour_EdtionToolsPanel * theEditionToolsPanel )
2689 _editionToolsPanel = theEditionToolsPanel;
2692 //------------------------------------------------------------------------------------------------------------
2693 void wxContourEventHandler :: setListViewPanel( wxContour_ListViewPanel * theListViewPanel )
2695 _listViewPanel = theListViewPanel;
2697 //------------------------------------------------------------------------------------------------------------
2698 // Other functional methods
2699 //------------------------------------------------------------------------------------------------------------
2702 //------------------------------------------------------------------------------------------------------------
2703 void wxContourEventHandler::onDeleteContour( wxCommandEvent& event )
2706 //JCP 20-10-08 Undo redo implementation
2708 //JCP 20-10-08 Undo redo implementation
2711 int i,size=_sceneManager->getSelectedObjects().size();
2714 std::string keyName = _sceneManager->getSelectedObjects()[i];
2715 int ispartofstaticlist = this->_modelManager->IsPartOfStaticList( keyName );
2716 if ( ispartofstaticlist>=0 )
2718 std::vector<int> tempVector;
2719 _instantPanel->getInstant( tempVector );
2720 Instant instant(&tempVector);
2721 this->_modelManager->ChangeContourOfList(keyName, &instant);
2725 std::vector<std::string> lstKeyName;
2726 std::vector<std::string> lstKeyNameActualSlice;
2727 std::vector<std::string> lstKeyNameToBeErase;
2729 lstKeyNameToBeErase = _sceneManager->getSelectedObjects();
2730 lstKeyNameActualSlice = _sceneManager->GetlstContoursNameActualSlice();
2731 int k,kSize=lstKeyNameToBeErase.size();
2732 int j,jSize=lstKeyNameActualSlice.size();
2734 for (k=0;k<kSize; k++)
2737 for (j=0;j<jSize; j++)
2739 if (lstKeyNameToBeErase[k]==lstKeyNameActualSlice[j])
2746 lstKeyName.push_back( lstKeyNameToBeErase[k] );
2750 deleteContours( lstKeyName );
2755 //------------------------------------------------------------------------------------------------------------
2756 void wxContourEventHandler::onDeleteContoursActSlice( wxCommandEvent& event )
2758 //JCP 20-10-08 Undo redo implementation
2760 //JCP 20-10-08 Undo redo implementation
2761 deleteContours( (std::vector<std::string>)_sceneManager->GetlstContoursNameActualSlice() );
2766 //------------------------------------------------------------------------------------------------------------
2767 void wxContourEventHandler::onDeleteAllContours( wxCommandEvent& event )
2769 //JCP 20-10-08 Undo redo implementation
2771 //JCP 20-10-08 Undo redo implementation
2772 deleteAllContours( );
2777 //------------------------------------------------------------------------------------------------------------
2778 void wxContourEventHandler :: onDeleteFrame( )
2780 if (_deleteFrame==NULL)
2782 _deleteFrame = new wxFrame (_theViewPanel, -1,_T(" Delete Contour "), wxDefaultPosition, wxDefaultSize, wxFRAME_TOOL_WINDOW|wxSYSTEM_MENU | wxCAPTION | wxCLIP_CHILDREN |wxFRAME_FLOAT_ON_PARENT );
2784 wxSize sizepanel(width,230);
2785 _deleteFrame->SetSize( sizepanel );
2786 wxPanel *panel = new wxPanel(_deleteFrame,-1);
2787 wxButton *deleteContourBtn = new wxButton(panel,-1,_T("Delete contour selected"),wxDefaultPosition, wxSize(width-10,35) );
2788 wxButton *deleteContoursActSliceBtn = new wxButton(panel,-1,_T("Delete contours of actual slice"),wxDefaultPosition, wxSize(width-10,35));
2789 wxButton *deleteAllContoursBtn = new wxButton(panel,-1,_T("Delete all contours"),wxDefaultPosition, wxSize(width-10,35));
2791 int sizeZ = _sceneManager->GetImageDataSizeZ();
2792 _mbarrangeDeleteAll = new mBarRange(panel,70, 65);
2793 _mbarrangeDeleteAll->SetMin(0);
2794 _mbarrangeDeleteAll->SetStart(0);
2796 _mbarrangeDeleteAll-> SetOrientation( true );
2797 _mbarrangeDeleteAll-> setActiveStateTo(true);
2798 _mbarrangeDeleteAll-> setVisibleLabels( true );
2799 _mbarrangeDeleteAll-> setDeviceEndMargin(10);
2800 _mbarrangeDeleteAll-> setRepresentedValues( 0 , sizeZ );
2801 _mbarrangeDeleteAll-> setDeviceBlitStart(10,10);
2802 _mbarrangeDeleteAll-> setIfWithActualDrawed( false );
2803 _mbarrangeDeleteAll-> SetStart( 0 );
2804 _mbarrangeDeleteAll-> SetEnd( sizeZ );
2807 _deleteFrame->SetEventHandler( this );
2808 Connect( deleteContourBtn->GetId() , wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &wxContourEventHandler::onDeleteContour );
2809 Connect( deleteContoursActSliceBtn->GetId() , wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &wxContourEventHandler::onDeleteContoursActSlice );
2810 Connect( deleteAllContoursBtn->GetId() , wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &wxContourEventHandler::onDeleteAllContours );
2812 wxFlexGridSizer * sizer = new wxFlexGridSizer(1);
2813 sizer -> Add( deleteContourBtn , 1, wxGROW );
2814 sizer -> Add( deleteContoursActSliceBtn , 1, wxGROW );
2815 sizer -> Add( deleteAllContoursBtn , 1, wxGROW );
2816 sizer -> Add( _mbarrangeDeleteAll , 1, wxGROW );
2818 panel->SetSizer( sizer );
2819 panel->SetSize( sizepanel );
2820 panel->SetAutoLayout( true );
2822 _deleteFrame->Show(true);
2824 if (_deleteFrame->IsShown()==true)
2826 _deleteFrame->Show(false);
2828 _deleteFrame->Show(true);
2834 //------------------------------------------------------------------------------------------------------------
2835 void wxContourEventHandler::onCreateContourSpline( wxCommandEvent& event )
2838 //JCP 20-10-08 Undo redo implementation
2840 //JCP 20-10-08 Undo redo implementation
2847 //------------------------------------------------------------------------------------------------------------
2848 void wxContourEventHandler::onCreateContourRectangle( wxCommandEvent& event )
2851 //JCP 20-10-08 Undo redo implementation
2853 //JCP 20-10-08 Undo redo implementation
2859 //------------------------------------------------------------------------------------------------------------
2860 void wxContourEventHandler::onCreateContourCircle( wxCommandEvent& event )
2862 //JCP 20-10-08 Undo redo implementation
2864 //JCP 20-10-08 Undo redo implementation
2869 //------------------------------------------------------------------------------------------------------------
2870 void wxContourEventHandler::onCreateContourBullEye( wxCommandEvent& event )
2872 //JCP 20-10-08 Undo redo implementation
2874 //JCP 20-10-08 Undo redo implementation
2883 //------------------------------------------------------------------------------------------------------------
2884 void wxContourEventHandler :: onCreateContourFrame( )
2886 if (_createContourFrame==NULL)
2888 _createContourFrame = new wxFrame (_theViewPanel, -1,_T(" New Contour "), wxDefaultPosition, wxDefaultSize, wxFRAME_TOOL_WINDOW|wxSYSTEM_MENU | wxCAPTION | wxCLIP_CHILDREN |wxFRAME_FLOAT_ON_PARENT | wxRESIZE_BORDER );
2889 wxSize sizepanel(490,600);
2890 _createContourFrame->SetSize( sizepanel );
2891 wxPanel *panel = new wxPanel(_createContourFrame,-1);
2892 wxButton *newContourSplineBtn = new wxButton(panel,-1,_T("Interpolation B-spline (close)"),wxDefaultPosition, wxSize(180,35) );
2893 newContourSplineBtn->SetToolTip(_T("CTRL-N"));
2894 wxButton *newContourRectangleBtn = new wxButton(panel,-1,_T("Rectangle"),wxDefaultPosition, wxSize(180,35));
2895 wxButton *newContourCircleBtn = new wxButton(panel,-1,_T("Circle"),wxDefaultPosition, wxSize(180,35));
2896 wxButton *newContourStarBtn = new wxButton(panel,-1,_T("Bull eye"),wxDefaultPosition, wxSize(180,35));
2898 _panelBullEyeOptions = new PanelBullEyeOptions(panel, wxSize(100,200));
2900 _createContourFrame->SetEventHandler( this );
2901 Connect( newContourSplineBtn->GetId() , wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &wxContourEventHandler::onCreateContourSpline );
2902 Connect( newContourRectangleBtn->GetId() , wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &wxContourEventHandler::onCreateContourRectangle );
2903 Connect( newContourCircleBtn->GetId() , wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &wxContourEventHandler::onCreateContourCircle );
2904 Connect( newContourStarBtn->GetId() , wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &wxContourEventHandler::onCreateContourBullEye );
2906 wxFlexGridSizer * sizer = new wxFlexGridSizer(1);
2907 sizer -> Add( newContourSplineBtn , 1, wxGROW );
2908 sizer -> Add( newContourRectangleBtn , 1, wxGROW );
2909 sizer -> Add( newContourCircleBtn , 1, wxGROW );
2910 sizer -> Add( newContourStarBtn , 1, wxGROW );
2911 sizer -> Add( _panelBullEyeOptions , 1, wxGROW );
2913 panel->SetSizer( sizer );
2914 panel->SetSize( sizepanel );
2915 panel->SetAutoLayout( true );
2917 _createContourFrame->Show(true);
2919 if (_createContourFrame->IsShown()==true)
2921 _createContourFrame->Show(false);
2923 _createContourFrame->Show(true);
2929 //------------------------------------------------------------------------
2930 void wxContourEventHandler::RefreshInterface()
2933 wxVtk2DBaseView *wxvtk2dbaseview = (wxVtk2DBaseView*)this->_theViewPanel->getWxVtkBaseView();
2934 wxvtk2dbaseview->Refresh();
2937 //------------------------------------------------------------------------
2938 void wxContourEventHandler::onWidthOfContour(wxScrollEvent& event){
2939 _sceneManager->removeSceneContours();
2940 double width = (double)_withOfContourLine->GetValue() / 2.0;
2941 _sceneManager->SetWidthContour( width );
2946 //------------------------------------------------------------------------
2948 void wxContourEventHandler::onBrigthnessColorWindowLevel(wxScrollEvent& event){
2949 int colorwindow = _brithtnessColorLevel->GetValue();
2950 int windowlevel = _brithtnessWindowLevel->GetValue();
2951 wxVtk2DBaseView *wxvtk2dbaseview = (wxVtk2DBaseView*)this->_theViewPanel->getWxVtkBaseView();
2952 vtkImageViewer2 *imageviewer = wxvtk2dbaseview->_imageViewer2XYZ->GetVtkImageViewer2();
2953 imageviewer->SetColorWindow(colorwindow);
2954 imageviewer->SetColorLevel(windowlevel);
2955 // wxvtk2dbaseview->Refresh();
2959 void wxContourEventHandler::OnInterpolation(wxCommandEvent& event)
2961 wxVtk2DBaseView *wxvtk2dbaseview = (wxVtk2DBaseView*)this->_theViewPanel->getWxVtkBaseView();
2962 vtkImageViewer2 *imageviewer = wxvtk2dbaseview->_imageViewer2XYZ->GetVtkImageViewer2();
2963 if (_interpolationCheckBox->GetValue()==true)
2965 imageviewer->GetImageActor()->InterpolateOn();
2967 imageviewer->GetImageActor()->InterpolateOff();
2973 //------------------------------------------------------------------------------------------------------------
2974 void wxContourEventHandler :: onInterfaceConfigurationFrame( )
2976 if (_interfaceConfigurationFrame==NULL)
2978 _interfaceConfigurationFrame = new wxFrame (_theViewPanel, -1,_T(" Interface Configuration "), wxDefaultPosition, wxDefaultSize, wxFRAME_TOOL_WINDOW|wxSYSTEM_MENU | wxCAPTION | wxCLIP_CHILDREN |wxFRAME_FLOAT_ON_PARENT );
2979 wxSize sizepanel(190,400);
2980 _interfaceConfigurationFrame->SetSize( sizepanel );
2981 _interfaceConfigurationFrame->SetEventHandler( this );
2982 wxPanel* panel = getConfigurationPanel(_interfaceConfigurationFrame);
2983 panel->SetSize(sizepanel);
2984 _interfaceConfigurationFrame->Show(true);
2986 if (_interfaceConfigurationFrame->IsShown()==true)
2988 _interfaceConfigurationFrame->Show(false);
2990 _interfaceConfigurationFrame->Show(true);
2998 wxPanel* wxContourEventHandler :: getConfigurationPanel(wxWindow* parent){
3000 /*wxPanel *panel = new wxPanel(parent,-1);
3001 _withOfContourLine = new wxSlider(panel, -1, 1 , 1, 10, wxDefaultPosition, wxSize(180,40), wxSL_HORIZONTAL|wxSL_LABELS, wxDefaultValidator);
3004 this->_sceneManager->GetImageDataRange(range);
3006 wxVtk2DBaseView *wxvtk2dbaseview = (wxVtk2DBaseView*)this->_theViewPanel->getWxVtkBaseView();
3007 vtkImageViewer2 *imageviewer = wxvtk2dbaseview->_imageViewer2XYZ->GetVtkImageViewer2();
3008 int colorwindow = (int)imageviewer->GetWindowLevel()->GetLevel();
3009 int windowlevel = (int)imageviewer->GetWindowLevel()->GetWindow();
3011 _brithtnessWindowLevel = new wxSlider(panel, -1, windowlevel , 1, range[1], wxDefaultPosition, wxSize(180,40), wxSL_HORIZONTAL|wxSL_LABELS, wxDefaultValidator);
3012 _brithtnessColorLevel = new wxSlider(panel, -1, colorwindow , 1, range[1], wxDefaultPosition, wxSize(180,40), wxSL_HORIZONTAL|wxSL_LABELS, wxDefaultValidator);
3014 _interpolationCheckBox = new wxCheckBox(panel, -1, _T("Image interpolation") );
3015 _interpolationCheckBox->SetValue(true);
3017 _interfaceConfigurationFrame->SetEventHandler( this );
3019 Connect( _withOfContourLine->GetId() , wxEVT_SCROLL_CHANGED , (wxObjectEventFunction) &wxContourEventHandler::onWidthOfContour );
3020 Connect( _withOfContourLine->GetId() , wxEVT_SCROLL_THUMBTRACK , (wxObjectEventFunction) &wxContourEventHandler::onWidthOfContour );
3022 Connect( _brithtnessWindowLevel->GetId() , wxEVT_SCROLL_CHANGED , (wxObjectEventFunction) &wxContourEventHandler::onBrigthnessColorWindowLevel );
3023 Connect( _brithtnessWindowLevel->GetId() , wxEVT_SCROLL_THUMBTRACK , (wxObjectEventFunction) &wxContourEventHandler::onBrigthnessColorWindowLevel );
3024 Connect( _brithtnessColorLevel->GetId() , wxEVT_SCROLL_CHANGED , (wxObjectEventFunction) &wxContourEventHandler::onBrigthnessColorWindowLevel );
3025 Connect( _brithtnessColorLevel->GetId() , wxEVT_SCROLL_THUMBTRACK , (wxObjectEventFunction) &wxContourEventHandler::onBrigthnessColorWindowLevel );
3026 Connect( _interpolationCheckBox->GetId() , wxEVT_COMMAND_CHECKBOX_CLICKED , (wxObjectEventFunction) &wxContourEventHandler::OnInterpolation );
3028 wxFlexGridSizer * sizer = new wxFlexGridSizer(1);
3029 sizer -> Add( new wxStaticText(panel,-1,_T("Contour width")) , 1, wxGROW );
3030 sizer -> Add( _withOfContourLine , 1, wxGROW );
3031 sizer -> Add( new wxStaticText(panel,-1,_T(" ")) , 1, wxGROW );
3032 sizer -> Add( new wxStaticText(panel,-1,_T(" ")) , 1, wxGROW );
3033 sizer -> Add( new wxStaticText(panel,-1,_T("Brightness of the image")) , 1, wxGROW );
3034 sizer -> Add( new wxStaticText(panel,-1,_T("--Window level--")) , 1, wxGROW );
3035 sizer -> Add( _brithtnessWindowLevel , 1, wxGROW );
3036 sizer -> Add( new wxStaticText(panel,-1,_T("--Color level--")) , 1, wxGROW );
3037 sizer -> Add( _brithtnessColorLevel, 1, wxGROW );
3038 sizer -> Add( new wxStaticText(panel,-1,_T(" ")) , 1, wxGROW );
3039 sizer -> Add( new wxStaticText(panel,-1,_T(" ")) , 1, wxGROW );
3040 sizer -> Add( _interpolationCheckBox , 1, wxGROW );
3042 panel->SetSizer( sizer );
3044 //panel->SetSize( sizepanel );
3046 panel->SetAutoLayout( true );
3051 wxPanel *panel = new wxPanel(parent,-1,wxDefaultPosition, wxDefaultSize,wxNO_BORDER, wxString(_T("")));
3052 _withOfContourLine = new wxSlider(panel, -1, 1 , 1, 10, wxDefaultPosition, wxDefaultSize, wxSL_HORIZONTAL|wxSL_LABELS, wxDefaultValidator);
3055 this->_sceneManager->GetImageDataRange(range);
3057 wxVtk2DBaseView *wxvtk2dbaseview = (wxVtk2DBaseView*)this->_theViewPanel->getWxVtkBaseView();
3058 vtkImageViewer2 *imageviewer = wxvtk2dbaseview->_imageViewer2XYZ->GetVtkImageViewer2();
3059 int colorwindow = (int)imageviewer->GetWindowLevel()->GetLevel();
3060 int windowlevel = (int)imageviewer->GetWindowLevel()->GetWindow();
3062 _brithtnessWindowLevel = new wxSlider(panel, -1, windowlevel , 1, range[1], wxDefaultPosition, wxDefaultSize, wxSL_HORIZONTAL|wxSL_LABELS, wxDefaultValidator);
3063 _brithtnessColorLevel = new wxSlider(panel, -1, colorwindow , 1, range[1], wxDefaultPosition, wxDefaultSize, wxSL_HORIZONTAL|wxSL_LABELS, wxDefaultValidator);
3065 _interpolationCheckBox = new wxCheckBox(panel, -1, _T("Image interpolation") );
3066 _interpolationCheckBox->SetValue(true);
3068 Connect( _withOfContourLine->GetId() , wxEVT_SCROLL_CHANGED , (wxObjectEventFunction) &wxContourEventHandler::onWidthOfContour );
3069 Connect( _withOfContourLine->GetId() , wxEVT_SCROLL_THUMBTRACK , (wxObjectEventFunction) &wxContourEventHandler::onWidthOfContour );
3071 Connect( _brithtnessWindowLevel->GetId() , wxEVT_SCROLL_CHANGED , (wxObjectEventFunction) &wxContourEventHandler::onBrigthnessColorWindowLevel );
3072 Connect( _brithtnessWindowLevel->GetId() , wxEVT_SCROLL_THUMBTRACK , (wxObjectEventFunction) &wxContourEventHandler::onBrigthnessColorWindowLevel );
3073 Connect( _brithtnessColorLevel->GetId() , wxEVT_SCROLL_CHANGED , (wxObjectEventFunction) &wxContourEventHandler::onBrigthnessColorWindowLevel );
3074 Connect( _brithtnessColorLevel->GetId() , wxEVT_SCROLL_THUMBTRACK , (wxObjectEventFunction) &wxContourEventHandler::onBrigthnessColorWindowLevel );
3075 Connect( _interpolationCheckBox->GetId() , wxEVT_COMMAND_CHECKBOX_CLICKED , (wxObjectEventFunction) &wxContourEventHandler::OnInterpolation );
3077 wxFlexGridSizer * sizer = new wxFlexGridSizer(1);
3078 sizer -> Add( new wxStaticText(panel,-1,_T("Contour width")) , 1, wxGROW );
3079 sizer -> Add( _withOfContourLine , 1, wxGROW );
3080 sizer -> Add( new wxStaticText(panel,-1,_T(" ")) , 1, wxGROW );
3081 sizer -> Add( new wxStaticText(panel,-1,_T(" ")) , 1, wxGROW );
3082 sizer -> Add( new wxStaticText(panel,-1,_T("Brightness of the image")) , 1, wxGROW );
3083 sizer -> Add( new wxStaticText(panel,-1,_T("--Window level--")) , 1, wxGROW );
3084 sizer -> Add( _brithtnessWindowLevel , 1, wxGROW );
3085 sizer -> Add( new wxStaticText(panel,-1,_T("--Color level--")) , 1, wxGROW );
3086 sizer -> Add( _brithtnessColorLevel, 1, wxGROW );
3087 sizer -> Add( new wxStaticText(panel,-1,_T(" ")) , 1, wxGROW );
3088 sizer -> Add( new wxStaticText(panel,-1,_T(" ")) , 1, wxGROW );
3089 sizer -> Add( _interpolationCheckBox , 1, wxGROW );
3091 panel->SetSizer( sizer );
3093 //panel->SetSize( sizepanel );
3095 panel->SetAutoLayout( true );
3105 //------------------------------------------------------------------
3106 void wxContourEventHandler :: changeContourOfManager(std::string keyName, Instant *instant)
3108 this->_modelManager->ChangeContourOfList(keyName, instant);
3111 //------------------------------------------------------------------
3112 void wxContourEventHandler :: changeContoursOfManager( std::vector<std::string> & keyNamesVector )
3115 //JCP 20-10-08 Undo redo implementation
3117 //JCP 20-10-08 Undo redo implementation
3119 std::vector<int> tempVector;
3120 _instantPanel->getInstant( tempVector );
3121 Instant instant(&tempVector);
3123 int i , size=keyNamesVector.size();
3124 for ( i=0 ; i<size ; i++ )
3126 changeContourOfManager(keyNamesVector[i], &instant);
3133 //------------------------------------------------------------------
3134 void wxContourEventHandler :: executeActionCommand( const char toolCommand )
3136 std::vector<std::string> currentSelection = _sceneManager->getSelectedObjects();
3137 int elementsSelected = currentSelection.size();
3138 if( toolCommand == (wxContour_ActionCommandsID::CREATE_TOOL) )
3140 onCreateContourFrame();
3142 if( toolCommand == (wxContour_ActionCommandsID::CREATE_CONTOUR_KEY) )
3146 else if( toolCommand == wxContour_ActionCommandsID::DELETE_TOOL )
3150 else if( toolCommand == wxContour_ActionCommandsID::DELETE_KEY )
3152 deleteContours( currentSelection );
3154 else if( toolCommand == wxContour_ActionCommandsID::SAVE_TOOL )
3156 saveFileWithContours( );
3158 else if( toolCommand == wxContour_ActionCommandsID::SAVE_KEY )
3160 saveFileWithContoursAutomatique( );
3162 else if( toolCommand == wxContour_ActionCommandsID::OPEN_TOOL )
3164 openFileWithContours( );
3166 else if( toolCommand == wxContour_ActionCommandsID::CHANGE_TOOL )
3168 if ( elementsSelected >= 1 )
3170 changeContoursOfManager( currentSelection );
3174 else if( toolCommand == wxContour_ActionCommandsID::HIDE_TOOL )
3176 if ( elementsSelected >= 1 )
3178 onHideOutlines( currentSelection );
3181 else if( toolCommand == wxContour_ActionCommandsID::SHOW_TOOL )
3183 if ( elementsSelected >= 1 )
3185 onShowOutlines( currentSelection );
3188 else if( toolCommand == wxContour_ActionCommandsID::COPY_TOOL )
3190 if ( elementsSelected >= 1 )
3192 onCopyOutlines( currentSelection );
3195 else if( toolCommand == wxContour_ActionCommandsID::PASTE_TOOL )
3199 else if( toolCommand == wxContour_ActionCommandsID::SPREAD_TOOL )
3203 else if( toolCommand == wxContour_ActionCommandsID::AUTOMATIQUESEGMENTATION_TOOL )
3205 onAutomatiqueSegmentation( );
3208 else if( toolCommand == wxContour_ActionCommandsID::SELECT_TOOL )
3210 onSelectOutlines( currentSelection );
3213 else if( toolCommand == wxContour_ActionCommandsID::EDIT_TOOL )
3215 if ( elementsSelected >= 1 )
3217 onEditOutlines( currentSelection );
3220 else if( toolCommand == wxContour_ActionCommandsID::UNDO_TOOL )
3224 else if( toolCommand == wxContour_ActionCommandsID::REDO_TOOL )
3228 else if( toolCommand == wxContour_ActionCommandsID::INFORMATIONCONTOUR_TOOL )
3230 onInformationContourFrame();
3232 else if( toolCommand == wxContour_ActionCommandsID::INTERFACECONFIGURATION_TOOL )
3234 onInterfaceConfigurationFrame();
3236 else if( toolCommand == wxContour_ActionCommandsID::TEST_TOOL )
3238 onInterfaceTestFrame();
3245 //------------------------------------------------------------------------------------------------------------
3246 // Getting information methods
3247 //------------------------------------------------------------------------------------------------------------
3251 //------------------------------------------------------------------------------------------------------------
3253 //------------------------------------------------------------------------------------------------------------
3255 void wxContourEventHandler :: updateInstantOutlines()
3257 std::vector<NameWrapper *> namesWrapping = _modelManager->getActualInstantOutlines();
3258 int size = namesWrapping.size();
3259 _sceneManager->removeSceneContours();
3260 for( int i=0; i<size; i++)
3262 _sceneManager->addToScene(namesWrapping[i]->getKeyName(), true, true, true, false, false );
3265 //------------------------------------------------------------------------------------------------------------
3266 void wxContourEventHandler :: updateInstantImageData()
3270 //------------------------------------------------------------------------------------------------------------
3272 void wxContourEventHandler :: updateInstantAxes()
3276 //------------------------------------------------------------------------------------------------------------
3277 void wxContourEventHandler :: changeInstant()
3279 std::vector<int> instantVect;
3280 _instantPanel->getInstant( instantVect );
3281 Instant * theInstant = new Instant ( &instantVect );
3282 //if( !theInstant->isEquals( _actualInstant ))
3284 //Setting the actual instant
3285 _actualInstant = theInstant;
3286 _modelManager->setInstant( _actualInstant );
3288 updateInstantOutlines();
3289 updateInstantImageData();
3290 updateInstantAxes();
3292 //Searching the elements at the specified instant
3295 std::map<std::string, ContourWrap_ViewControl *> :: iterator iter;
3296 iter = contours_ViewControl->find("Outline 0");
3297 (iter->second)->getViewer()->RemoveCompleteContourActor();*/
3301 void wxContourEventHandler :: saveState(){
3307 //itoa(inundo, str, 10);
3308 std::string str = intToString(inundo);
3311 std::string temp = stundoredo + str + ".roi";
3312 saveFileWithContours(temp);
3317 void wxContourEventHandler ::loadState(std::string filename){
3320 FILE *pFile=fopen(filename.c_str(),"r+");
3322 fscanf(pFile,"%s",tmp); // --CreaContour--
3324 fscanf(pFile,"%s",tmp); // Version
3325 fscanf(pFile,"%s",tmp); // 1.0.1
3326 std::string version(tmp);
3328 deleteAllContours();
3330 openContours(pFile,false);
3331 if (version!="1.0.0"){
3332 openContours(pFile,true);
3337 //_sceneManager->removeSceneContours();
3341 void wxContourEventHandler :: onREDO()
3348 //itoa(inundo, str, 10);
3349 std::string str = intToString(inundo);
3352 std::string temp = stundoredo + str + ".roi";
3360 //------------------------------------------------------------------------------------------------------------
3361 void wxContourEventHandler :: onUNDO()
3367 //itoa(inundo, str, 10);
3368 std::string str = intToString(inundo);
3370 std::string temp = stundoredo + str + ".roi";
3371 saveFileWithContours(temp);
3378 //itoa(inundo, str, 10);
3379 std::string str = intToString(inundo);
3382 std::string temp = stundoredo + str + ".roi";
3388 void wxContourEventHandler :: getValuesXYZ(double **vectx, double **vecty, double **vectz, std::vector<int>* size){
3392 ContourExtractData *contourextractdata = new ContourExtractData();
3393 int typeContourGroup = this->_radiolstboxContourGroup->GetSelection();
3394 contourextractdata ->SetTypeOperation( typeContourGroup % 3 );
3396 std::vector<manualContourModel*> lstManConMod;
3397 std::vector<manualContourModel*> lstManConModTmp;
3398 std::vector<manualContourModel*> lstManConModExp;
3399 std::vector<double> pLstValue;
3400 std::vector<double> pLstValuePosX;
3401 std::vector<double> pLstValuePosY;
3402 std::vector<double> pLstValuePosZ;
3404 std::vector<int> tempVector;
3405 _instantPanel->getInstant( tempVector );
3407 vtkImageData *imagedata = _sceneManager->GetImageData();
3408 int sizeZ = _sceneManager->GetImageDataSizeZ();
3410 int ii,sizeLstContourThings;
3417 minZ = 0;// _mbarrange->GetStart();
3418 maxZ = sizeZ;//_mbarrange->GetEnd();
3419 totalZ = maxZ-minZ+1;
3421 contourextractdata->SetImage( imagedata);
3424 vectx = new double *[sizeZ];
3425 vecty = new double *[sizeZ];
3426 vectz = new double *[sizeZ];
3427 for ( z=0 ; z<sizeZ ; z++)
3430 porcent = 100.0* (z-minZ)/totalZ;
3432 //Extraction data from contours of each slice
3433 contourextractdata->SetZtoBeAnalys( z);
3436 Instant instant(&tempVector);
3437 std::vector<ContourThing**> lstContourThings = this->_modelManager->getOutlinesAtInstant( &instant );
3438 sizeLstContourThings = lstContourThings.size();
3440 lstManConMod.clear();
3441 for (ii=0 ; ii<sizeLstContourThings ; ii++)
3443 ContourThing **contourthing = lstContourThings[ii];
3444 lstManConMod.push_back( (*contourthing)->getModel() );
3446 lstManConModExp = ExploseEachModel( lstManConMod );
3451 int iContourGroup,sizeContourGroup;
3452 if (typeContourGroup==3) // contour separete
3454 sizeContourGroup=lstManConModExp.size();
3455 } else { // contour AND OR XOR
3459 for( iContourGroup=0 ; iContourGroup<sizeContourGroup ; iContourGroup++ ){
3460 lstManConModTmp.clear();
3461 if (typeContourGroup==3) // contour separete
3463 lstManConModTmp.push_back( lstManConModExp[iContourGroup]);
3464 } else { // contour AND OR XOR
3465 lstManConModTmp = lstManConModExp;
3468 contourextractdata->SetLstManualContourModel( lstManConModTmp );
3471 pLstValuePosX.clear();
3472 pLstValuePosY.clear();
3473 pLstValuePosZ.clear();
3474 contourextractdata->GetValuesInsideCrown( &pLstValue,
3480 int iLstValue,sizeLstValue=pLstValue.size();
3482 //We initialize the pointers
3483 size->push_back(sizeLstValue);
3484 vectx[sizeZ] = new double[sizeLstValue];
3485 vecty[sizeZ] = new double[sizeLstValue];
3486 vectz[sizeZ] = new double[sizeLstValue];
3488 for (iLstValue=0 ; iLstValue<sizeLstValue ; iLstValue++ )
3491 vectx[sizeZ][iLstValue] = pLstValuePosX[iLstValue];
3492 vecty[sizeZ][iLstValue] = pLstValuePosY[iLstValue];
3493 vectz[sizeZ][iLstValue] = pLstValuePosZ[iLstValue];
3496 //The size of the contour is saved
3501 } // for iContourGroup
3503 //_staticTextInformation->SetLabel( _T("") );
3504 delete contourextractdata;
3509 void wxContourEventHandler :: getMaskValue(vtkImageData* mask, vtkImageData* value){
3513 ContourExtractData *contourextractdata = new ContourExtractData( true );
3514 int typeContourGroup = this->_radiolstboxContourGroup->GetSelection();
3515 if (typeContourGroup==3)
3519 contourextractdata ->SetTypeOperation( typeContourGroup % 3 );
3521 std::vector<manualContourModel*> lstManConMod;
3522 std::vector<manualContourModel*> lstManConModTmp;
3523 std::vector<manualContourModel*> lstManConModExp;
3525 std::vector<int> tempVector;
3526 _instantPanel->getInstant( tempVector );
3528 vtkImageData *imagedata = _sceneManager->GetImageData();
3529 int sizeZ = _sceneManager->GetImageDataSizeZ();
3531 int ii,sizeLstContourThings;
3540 minZ = 0;// _mbarrange->GetStart();
3541 maxZ = sizeZ;//_mbarrange->GetEnd();
3542 totalZ = maxZ-minZ+1;
3544 contourextractdata->SetImage( imagedata);
3547 for ( z=0 ; z<sizeZ ; z++)
3550 porcent = 100.0* (z-minZ)/totalZ;
3551 tmpString.Printf(_T("Saving Values"));
3552 tmpString.Printf(_T(" %d %c %d/%d %d"), (int)porcent , 37 , z-minZ+1, (int)totalZ ,z);
3553 _staticTextInformation->SetLabel(tmpString);
3555 //Extraction data from contours of each slice
3556 contourextractdata->SetZtoBeAnalys( z);
3559 Instant instant(&tempVector);
3560 std::vector<ContourThing**> lstContourThings = this->_modelManager->getOutlinesAtInstant( &instant );
3561 sizeLstContourThings = lstContourThings.size();
3563 lstManConMod.clear();
3564 for (ii=0 ; ii<sizeLstContourThings ; ii++)
3566 ContourThing **contourthing = lstContourThings[ii];
3567 lstManConMod.push_back( (*contourthing)->getModel() );
3569 lstManConModExp = ExploseEachModel( lstManConMod );
3572 int iContourGroup,sizeContourGroup;
3573 if (typeContourGroup==3) // contour separete
3575 sizeContourGroup=lstManConModExp.size();
3576 } else { // contour AND OR XOR
3580 for( iContourGroup=0 ; iContourGroup<sizeContourGroup ; iContourGroup++ ){
3581 lstManConModTmp.clear();
3582 if (typeContourGroup==3) // contour separete
3584 lstManConModTmp.push_back( lstManConModExp[iContourGroup]);
3585 } else { // contour AND OR XOR
3586 lstManConModTmp = lstManConModExp;
3589 contourextractdata->SetLstManualContourModel( lstManConModTmp );
3592 contourextractdata->CalculateImageResult(); // with actual Z
3594 } // for iContourGroup
3600 value = contourextractdata->GetVtkImageValueResult();
3603 mask = contourextractdata->GetVtkImageMaskResult();
3605 delete contourextractdata;
3609 wxPanel* wxContourEventHandler::getSegmentationPanelITK(wxWindow* parent){
3611 int sizeZ = _sceneManager->GetImageDataSizeZ();
3613 _sceneManager->GetImageDataRange(range);
3615 wxPanel *panel = new wxPanel(parent,-1);
3616 wxButton *segmentationOneSliceBtn = new wxButton(panel,-1,_T("Actual slice"), wxDefaultPosition, wxSize(200,35) );
3617 wxButton *segmentationAllSliceBtn = new wxButton(panel,-1,_T("All slices") ,wxDefaultPosition, wxSize(200,35) );
3618 _isovalue = new wxSlider(panel, -1, 40 , (int)(range[0]), (int)(range[1]), wxDefaultPosition, wxSize(200,35), wxSL_HORIZONTAL|wxSL_LABELS, wxDefaultValidator);
3619 _sampling = new wxSlider(panel, -1, 20 , 4, 50, wxDefaultPosition, wxSize(200,35), wxSL_HORIZONTAL|wxSL_LABELS, wxDefaultValidator);
3620 wxString lstOptions[3];
3621 lstOptions[0]=_T("A");
3622 lstOptions[1]=_T("B");
3623 lstOptions[2]=_T("C");
3624 methodRadiobox = new wxRadioBox(panel, -1, _T("Method (find ctrl. Points)"), wxDefaultPosition, wxSize(200,45), 3 , lstOptions, 3, wxRA_SPECIFY_COLS);
3625 methodRadiobox->SetSelection(2);
3626 _staticTextSegmentation = new wxStaticText(panel,-1,_T(" "));
3629 _mbarrange = new mBarRange(panel,70, 65);
3630 _mbarrange->SetMin(0);
3631 _mbarrange->SetStart(0);
3633 _mbarrange-> SetOrientation( true );
3634 _mbarrange-> setActiveStateTo(true);
3635 _mbarrange-> setVisibleLabels( true );
3636 _mbarrange-> setDeviceEndMargin(10);
3637 _mbarrange-> setRepresentedValues( 0 , sizeZ );
3638 _mbarrange-> setDeviceBlitStart(10,10);
3639 _mbarrange-> setIfWithActualDrawed( false );
3640 _mbarrange-> SetStart( 0 );
3641 _mbarrange-> SetEnd( sizeZ );
3644 // _segmentationFrame->SetEventHandler( this );
3645 segmentationOneSliceBtn->SetEventHandler( this );
3646 segmentationAllSliceBtn->SetEventHandler( this );
3647 Connect( segmentationOneSliceBtn->GetId(), wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &wxContourEventHandler::onSegmentationOneSliceITK );
3648 Connect( segmentationAllSliceBtn->GetId(), wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &wxContourEventHandler::onSegmentationAllSliceITK );
3650 wxFlexGridSizer * sizer = new wxFlexGridSizer(1);
3651 sizer -> Add( new wxStaticText(panel,-1,_T("Isovalue (Gray level)")) , 1, wxGROW );
3652 sizer -> Add( _isovalue , 1, wxGROW );
3653 sizer -> Add( methodRadiobox , 1, wxGROW );
3654 sizer -> Add( new wxStaticText(panel,-1,_T("Sampling (%)")) , 1, wxGROW );
3655 sizer -> Add( _sampling , 1, wxGROW );
3656 sizer -> Add( segmentationOneSliceBtn , 1, wxGROW );
3657 sizer -> Add( new wxStaticText(panel,-1,_T(" ")) , 1, wxGROW );
3658 sizer -> Add( _staticTextSegmentation , 1, wxGROW );
3659 sizer -> Add( segmentationAllSliceBtn , 1, wxGROW );
3660 sizer -> Add( _mbarrange , 1, wxGROW );
3662 panel->SetSizer( sizer );
3663 // panel->SetSize( sizePanel );
3664 panel->SetSize( wxDefaultSize );
3665 panel->SetAutoLayout( true );
3672 void wxContourEventHandler::onSegmentationAllSliceITK( wxCommandEvent& event ){
3673 //TODO implementar el método para todos los slices ver ayuda en onSegmentationAllSlice
3675 void wxContourEventHandler::onSegmentationOneSliceITK( wxCommandEvent& event ){
3676 //TODO implementar el método de segmentación en ITK ver ayuda en onSegmentationOneSlice y el método
3677 // SegmentationOneSlice(x, y, z) que es la implementación del método en VTK
3679 //JCP 20-10-08 Undo redo implementation
3681 //JCP 20-10-08 Undo redo implementation
3684 int x = this->_theViewPanel->GetX();
3685 int y = this->_theViewPanel->GetY();
3686 int z = this->_theViewPanel->GetZ();
3687 //SegmentationOneSlice( x,y,z );
3690 void wxContourEventHandler::onSnakePressed(wxWindow* parent){
3692 std::vector<double> vecX;
3693 std::vector<double> vecY;
3694 std::vector<double> vecZ;
3695 _sceneManager->GetPointsOfActualContour( &vecX , &vecY , &vecZ );
3697 if (vecX.size()!=0){
3698 std::vector<int> tempVector;
3699 _instantPanel->getInstant( tempVector );
3700 int i,size=vecZ.size();
3701 int actualSlice = tempVector[1];
3702 for ( i=0 ; i<size ; i++ )
3704 vecZ[i] = actualSlice;
3707 wxDialog* dialog = new wxDialog(parent, -1, wxString(_T("Snake")));
3708 wxPanel* panel = new wxPanel(dialog,-1);
3709 wxStaticText* sttext = new wxStaticText(panel, -1, wxString(_T("Panel para snake")));
3710 dialog->ShowModal();
3715 void wxContourEventHandler::checkInformationPanel(){
3716 if (_InformationContourFrame==NULL){
3717 onInformationContourFrame();
3718 _InformationContourFrame->Show(false);
3722 std::string wxContourEventHandler::intToString(int num){
3724 for(int k = num; k == 0; k++){
3725 char temp = k % 10 + 48;
3727 result = temp + result;