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>
107 //------------------------------------------------------------------------------------------------------------
108 //------------------------------------------------------------------------------------------------------------
109 //------------------------------------------------------------------------------------------------------------
111 PanelBullEyeOptions::PanelBullEyeOptions (wxWindow * parent, wxSize size) :
112 wxPanel(parent, -1, wxDefaultPosition, size)
117 wxSize sizepanel(190,300);
118 wxPanel *panel = this;
121 wxString lstOptions[2];
122 lstOptions[0]="General options";
123 lstOptions[1]="Detail options";
124 _radioboxBullEyeGenOpt = new wxRadioBox(panel, -1, "General/Detail options", wxDefaultPosition, wxSize(200,45), 2 , lstOptions, 2, wxRA_SPECIFY_COLS);
125 _radioboxBullEyeGenOpt->SetSelection(0);
127 _spinctrlBullEyeNumOfCrowns = new wxSpinCtrl( panel , -1,_T("B"),wxDefaultPosition, wxSize(40,20) );
128 _spinctrlBullEyeNumOfCrowns->SetRange(1,_maxLevels);
129 _spinctrlBullEyeNumOfCrowns->SetValue(3);
131 _spinctrlBullEyeNumOfSec = new wxSpinCtrl( panel , -1,_T("A"),wxDefaultPosition, wxSize(40,20) );
132 _spinctrlBullEyeNumOfSec->SetRange(1,_maxSections);
133 _spinctrlBullEyeNumOfSec->SetValue(5);
136 _sliderBullEyeAngle = new wxSlider( panel , -1 ,0,0,180, wxDefaultPosition, wxSize(200,35), wxSL_HORIZONTAL|wxSL_LABELS, wxDefaultValidator);
138 wxFlexGridSizer * sizerGeneralOptions = new wxFlexGridSizer(10);
140 wxFlexGridSizer * sizerGeneralOptionsA = new wxFlexGridSizer(1);
141 wxFlexGridSizer * sizerGeneralOptionsB = new wxFlexGridSizer(1);
142 wxFlexGridSizer * sizerGeneralOptionsC = new wxFlexGridSizer(1);
143 sizerGeneralOptionsA -> Add( new wxStaticText(panel,-1,_T("Crowns")) , 1, wxGROW );
144 sizerGeneralOptionsA -> Add( _spinctrlBullEyeNumOfCrowns , 1/*, wxGROW*/ );
145 sizerGeneralOptionsB -> Add( new wxStaticText(panel,-1,_T("Sections")) , 1, wxGROW );
146 sizerGeneralOptionsB -> Add( _spinctrlBullEyeNumOfSec , 1/*, wxGROW*/ );
147 sizerGeneralOptionsC -> Add( new wxStaticText(panel,-1,_T(" Angle")) , 1, wxGROW );
148 sizerGeneralOptionsC -> Add( _sliderBullEyeAngle , 1/*, wxGROW*/ );
150 sizerGeneralOptions -> Add( sizerGeneralOptionsA , 1/*, wxGROW*/ );
151 sizerGeneralOptions -> Add( new wxStaticText(panel,-1,_T(" ")) , 1, wxGROW );
152 sizerGeneralOptions -> Add( sizerGeneralOptionsB , 1/*, wxGROW*/ );
153 sizerGeneralOptions -> Add( new wxStaticText(panel,-1,_T(" ")) , 1, wxGROW );
154 sizerGeneralOptions -> Add( sizerGeneralOptionsC , 1/*, wxGROW*/ );
157 wxSpinCtrl *tmpSpinSection;
158 wxSlider *tmpSliderRadio;
159 wxSlider *tmpSliderAng;
161 wxFlexGridSizer * sizerDetailOptions = new wxFlexGridSizer(6);
163 sizerDetailOptions -> Add( new wxStaticText(panel,-1,_T("Crown ")) , 1, wxGROW );
164 sizerDetailOptions -> Add( new wxStaticText(panel,-1,_T(" Sections ")) , 1, wxGROW );
165 sizerDetailOptions -> Add( new wxStaticText(panel,-1,_T(" ")) , 1, wxGROW );
166 sizerDetailOptions -> Add( new wxStaticText(panel,-1,_T(" Radio %")) , 1, wxGROW );
167 sizerDetailOptions -> Add( new wxStaticText(panel,-1,_T(" ")) , 1, wxGROW );
168 sizerDetailOptions -> Add( new wxStaticText(panel,-1,_T(" Angle")) , 1, wxGROW );
170 wxString tmpwxstring;
172 for (i=0;i<_maxLevels;i++){
173 tmpSpinSection = new wxSpinCtrl( panel , -1,_T(""),wxDefaultPosition, wxSize(40,20) );
174 tmpSliderRadio = new wxSlider( panel , -1 ,0,0,100, wxDefaultPosition, wxSize(110,35), wxSL_HORIZONTAL|wxSL_LABELS, wxDefaultValidator);
175 tmpSliderAng = new wxSlider( panel , -1 ,0,0,180, wxDefaultPosition, wxSize(200,35), wxSL_HORIZONTAL|wxSL_LABELS, wxDefaultValidator);
177 tmpSpinSection ->SetRange(1,_maxSections);
179 tmpwxstring.Printf(_T(" %d. "),i+1);
180 sizerDetailOptions -> Add( new wxStaticText(panel,-1,tmpwxstring) , 1, wxGROW );
181 sizerDetailOptions -> Add( tmpSpinSection, 1 );
182 sizerDetailOptions -> Add( new wxStaticText(panel,-1,_T(" ")) , 1, wxGROW );
183 sizerDetailOptions -> Add( tmpSliderRadio, 1, wxGROW );
184 sizerDetailOptions -> Add( new wxStaticText(panel,-1,_T(" ")) , 1, wxGROW );
185 sizerDetailOptions -> Add( tmpSliderAng, 1, wxGROW );
187 tmpSpinSection -> SetValue(5);
188 tmpSliderRadio -> SetValue( 100-(double)((i)*100.0/_maxLevels) );
189 tmpSliderAng -> SetValue(0);
191 Connect( tmpSliderRadio->GetId(), wxEVT_SCROLL_THUMBRELEASE , (wxObjectEventFunction) &PanelBullEyeOptions::onRefreshPanel );
192 Connect( tmpSliderRadio->GetId(), wxEVT_SCROLL_CHANGED , (wxObjectEventFunction) &PanelBullEyeOptions::onRefreshPanel );
194 _lstBullEyeDetailNumOfSec.push_back( tmpSpinSection );
195 _lstBullEyeDetailRadio.push_back( tmpSliderRadio );
196 _lstBullEyeDetailAngle.push_back( tmpSliderAng );
200 wxFlexGridSizer * sizer = new wxFlexGridSizer(1);
201 sizer -> Add( new wxStaticText(panel,-1,_T("")) , 1, wxGROW );
202 sizer -> Add( new wxStaticText(panel,-1,_T("")) , 1, wxGROW );
203 sizer -> Add( _radioboxBullEyeGenOpt , 1, wxGROW );
204 sizer -> Add( new wxStaticText(panel,-1,_T("")) , 1, wxGROW );
205 sizer -> Add( new wxStaticText(panel,-1,_T(" -- Bull Eye general options --")) , 1, wxGROW );
206 sizer -> Add( new wxStaticText(panel,-1,_T("")) , 1, wxGROW );
207 sizer -> Add( sizerGeneralOptions , 1, wxGROW );
208 sizer -> Add( new wxStaticText(panel,-1,_T("")) , 1, wxGROW );
209 sizer -> Add( new wxStaticText(panel,-1,_T("")) , 1, wxGROW );
210 sizer -> Add( new wxStaticText(panel,-1,_T(" -- Bull Eye detail options --")) , 1, wxGROW );
211 sizer -> Add( new wxStaticText(panel,-1,_T("")) , 1, wxGROW );
212 sizer -> Add( sizerDetailOptions , 1, wxGROW );
214 Connect( _radioboxBullEyeGenOpt->GetId(), wxEVT_COMMAND_RADIOBOX_SELECTED , (wxObjectEventFunction) &PanelBullEyeOptions::onRefreshPanel );
215 Connect( _spinctrlBullEyeNumOfCrowns->GetId(), wxEVT_COMMAND_TEXT_UPDATED , (wxObjectEventFunction) &PanelBullEyeOptions::onRefreshPanel );
217 panel->SetSizer( sizer );
218 panel->SetSize( sizepanel );
219 panel->SetAutoLayout( true );
226 //------------------------------------------------------------------------------------------------------------
227 PanelBullEyeOptions::~PanelBullEyeOptions()
231 //------------------------------------------------------------------------------------------------------------
232 void PanelBullEyeOptions::onRefreshPanel( wxCommandEvent& event )
237 //------------------------------------------------------------------------------------------------------------
238 void PanelBullEyeOptions::RefreshPanel()
242 if (this->_radioboxBullEyeGenOpt->GetSelection()==0){
243 for (i=0; i<_maxLevels; i++)
245 _lstBullEyeDetailNumOfSec[i] -> Enable(false);
246 _lstBullEyeDetailRadio[i] -> Enable(false);
247 _lstBullEyeDetailAngle[i] -> Enable(false);
250 int spinSelec = _spinctrlBullEyeNumOfCrowns->GetValue();
251 for (i=0; i<_maxLevels; i++)
253 ok = (i < spinSelec);
254 _lstBullEyeDetailNumOfSec[i] -> Enable(ok);
255 _lstBullEyeDetailRadio[i] -> Enable(ok);
256 _lstBullEyeDetailAngle[i] -> Enable(ok);
259 if (_lstBullEyeDetailRadio[i]->GetValue() > _lstBullEyeDetailRadio[i-1]->GetValue())
261 _lstBullEyeDetailRadio[i]->SetValue( _lstBullEyeDetailRadio[i-1]->GetValue() );
268 //------------------------------------------------------------------------------------------------------------
269 int PanelBullEyeOptions::GetNumberOfCrowns()
271 return this->_spinctrlBullEyeNumOfCrowns->GetValue();
274 //------------------------------------------------------------------------------------------------------------
275 int PanelBullEyeOptions::GetNumberOfSections(int nCrown)
278 if (this->_radioboxBullEyeGenOpt->GetSelection()==0)
280 result = this->_spinctrlBullEyeNumOfSec->GetValue();
282 result = this->_lstBullEyeDetailNumOfSec[nCrown]->GetValue();
287 //------------------------------------------------------------------------------------------------------------
288 int PanelBullEyeOptions::GetRadioOfCrown(int nCrown)
292 if (this->_radioboxBullEyeGenOpt->GetSelection()==0)
294 sizeCrowns = (double)( this->_spinctrlBullEyeNumOfCrowns->GetValue() );
295 result = 100.0 * (nCrown+1)/sizeCrowns ;
297 result = this->_lstBullEyeDetailRadio[nCrown]->GetValue();
302 //------------------------------------------------------------------------------------------------------------
303 double PanelBullEyeOptions::GetAngOfCrownSection(int nCrown,int section)
306 if (this->_radioboxBullEyeGenOpt->GetSelection()==0)
308 angle = this->_sliderBullEyeAngle->GetValue();
310 angle = this->_lstBullEyeDetailAngle[nCrown]->GetValue();
312 double numOfSec = (double)GetNumberOfSections(nCrown);
313 double deltaSec = GetAngDeltaOfCrownSection(nCrown);
314 return angle + section*deltaSec ;
317 //------------------------------------------------------------------------------------------------------------
318 double PanelBullEyeOptions::GetAngDeltaOfCrownSection(int nCrown)
320 double numOfSec = (double)GetNumberOfSections(nCrown);
321 return 360.0/numOfSec;
326 //------------------------------------------------------------------------------------------------------------
327 //------------------------------------------------------------------------------------------------------------
328 //------------------------------------------------------------------------------------------------------------
331 //------------------------------------------------------------------------------------------------------------
332 // Constructors & Destructors
333 //------------------------------------------------------------------------------------------------------------
335 wxContourEventHandler ::wxContourEventHandler()
338 _creatingContoursActive = false;
339 _theViewPanel = NULL;
340 _modelManager = NULL;
341 _instantPanel = NULL;
344 _drawToolsPanel = NULL;
345 _operationsToolsPanel = NULL;
346 _autoFormsPanel = NULL;
347 _standardToolsPanel = NULL;
348 _editionToolsPanel = NULL;
349 _listViewPanel = NULL;
350 _sceneManager = NULL;
351 _actualInstant = NULL;
352 _performingOperation = new PerformingOperation();
354 // EED Interface and Spread
356 _segmentationFrame = NULL;
357 _contourPropagation = NULL;
358 _createContourFrame = NULL;
360 _InformationContourFrame = NULL;
361 _interfaceConfigurationFrame = NULL;
363 _wxtextctrlTest = NULL;
364 _panelBullEyeOptions = NULL;
366 fileNameContourROI = "";
367 _numberOfVariablesStatistics=6+1;
369 //------------------------------------------------------------------------------------------------------------
370 wxContourEventHandler :: ~ wxContourEventHandler()
372 delete _actualInstant;
373 /*delete _theViewPanel;
374 delete _instantPanel;
376 delete _actualInstant;
378 delete _sceneManager;
379 delete _performingOperation;
381 //------------------------------------------------------------------------------------------------------------
382 // Configuration methods
383 //------------------------------------------------------------------------------------------------------------
385 bool wxContourEventHandler :: configureEventsHandling()
387 bool configured = true;
392 //------------------------------------------------------------------------------------------------------------
393 // Methods for capturing events
394 //------------------------------------------------------------------------------------------------------------
395 void wxContourEventHandler :: onProcessMessage( wxCommandEvent& event )
399 //------------------------------------------------------------------------------------------------------------
401 void wxContourEventHandler :: onActionButtonPressed( wxCommandEvent& event )
403 const char buttonTool = *(char *)event.GetClientData();
404 executeActionCommand( buttonTool );
406 //------------------------------------------------------------------------------------------------------------
407 void wxContourEventHandler :: onChangedDeep ( wxCommandEvent& event )
409 double val = _theViewPanel->getCurrentDeep();
410 _instantPanel->setConceptValue( "Axe Depth", (int)val );
411 _theViewPanel->setActualVertical( (int)val );
415 //------------------------------------------------------------------------------------------------------------
416 void wxContourEventHandler :: onChangeInstant( wxCommandEvent& event )
418 ConceptDataWrap * dataConcept = NULL;
419 if ( _theViewPanel->GetId() == event.GetId() )
421 dataConcept = (ConceptDataWrap *)event.GetClientData();
422 int value = dataConcept->getActualValue();
423 _instantPanel->setConceptValue( dataConcept->getName(), value );
427 dataConcept = _instantPanel->getLastConceptData();
428 if( dataConcept->getName().compare( _theViewPanel->getVerticalConceptName() ) )
430 _theViewPanel->setActualVertical( dataConcept->getActualValue());
431 //_theViewPanel->setVerticalConcept( dataConcept->getName(), dataConcept->getMinShowedValue()/*dataConcept->getMinValue()*/, /*dataConcept->getMaxValue()*/ dataConcept->getMaxShowedValue(), dataConcept->getMinShowedValue(), dataConcept->getMaxShowedValue(), dataConcept->getActualValue());
433 else if( dataConcept->getName().compare( _theViewPanel->getHorizontalConceptName() ) || _instantPanel->getIfConceptCheckedAt( dataConcept->getName(), 0 ) )
435 _theViewPanel->setHorizontalConcept( dataConcept->getName(), dataConcept->getMinShowedValue()/*dataConcept->getMinValue()*/, /*dataConcept->getMaxValue()*/ dataConcept->getMaxShowedValue(), dataConcept->getMinShowedValue(), dataConcept->getMaxShowedValue(), dataConcept->getActualValue());
440 //------------------------------------------------------------------------------------------------------------
442 void wxContourEventHandler :: onCreateMultipleROI( wxCommandEvent& event )
444 _creatingContoursActive = !_creatingContoursActive;
445 if( _creatingContoursActive )
450 //------------------------------------------------------------------------------------------------------------
451 void wxContourEventHandler :: onCreateROI( wxCommandEvent& event )
453 if( _creatingContoursActive )
459 //------------------------------------------------------------------------------------------------------------
460 void wxContourEventHandler :: onStopCreateROI( wxCommandEvent& event )
465 //------------------------------------------------------------------------------------------------------------
466 void wxContourEventHandler :: onDeleterROI( wxCommandEvent& event )
470 //------------------------------------------------------------------------------------------------------------
471 void wxContourEventHandler :: onSelectROI( wxCommandEvent& event )
475 //------------------------------------------------------------------------------------------------------------
478 void wxContourEventHandler :: onUnSelectROI( wxCommandEvent& event )
482 //------------------------------------------------------------------------------------------------------------
484 void wxContourEventHandler :: onManualHidedROI( wxCommandEvent& event )
488 //------------------------------------------------------------------------------------------------------------
490 void wxContourEventHandler :: onManualShowedROI( wxCommandEvent& event )
494 //------------------------------------------------------------------------------------------------------------
496 void wxContourEventHandler :: onEditingROI( wxCommandEvent& event )
500 //------------------------------------------------------------------------------------------------------------
502 void wxContourEventHandler :: onMovingROI( wxCommandEvent& event )
507 //------------------------------------------------------------------------------------------------------------
508 // Model management methods
509 //------------------------------------------------------------------------------------------------------------
511 void wxContourEventHandler::onSpreadReset( wxCommandEvent& event )
513 _wxtextctrlSpread->SetValue("");
514 _contourPropagation->resetAppend();
517 //------------------------------------------------------------------------------------------------------------
518 void wxContourEventHandler::onSpreadAdd( wxCommandEvent& event )
520 std::vector<double> vecX;
521 std::vector<double> vecY;
522 std::vector<double> vecZ;
523 _sceneManager->GetPointsOfActualContour( &vecX , &vecY , &vecZ );
526 std::vector<int> tempVector;
527 _instantPanel->getInstant( tempVector );
528 int i,size=vecZ.size();
529 int actualSlice = tempVector[1];
530 for ( i=0 ; i<size ; i++ )
532 vecZ[i] = actualSlice;
535 _contourPropagation->appendContour(&vecX , &vecY , &vecZ);
537 newstring.Printf("%s %d -",_wxtextctrlSpread->GetValue(), actualSlice );
538 _wxtextctrlSpread->SetValue(newstring);
542 //------------------------------------------------------------------------------------------------------------
543 void wxContourEventHandler::onSpreadGo( wxCommandEvent& event )
546 int typeMethodFindCtrlPoints=_spreadMethodRadiobox->GetSelection();
547 int typeofcontour = 1;
548 manualContourModel *manModelContour;
549 std::vector<double> vecCtrlPointX;
550 std::vector<double> vecCtrlPointY;
551 std::vector<double> vecCtrlPointZ;
557 std::vector<int> tempVector;
558 _instantPanel->getInstant( tempVector );
561 _contourPropagation->getMaxMinZ(&minZ,&maxZ);
562 //JSTG_16-07-08_----------------------------------------------------------------
563 //_contourPropagation->setInterpolationNumber(maxZ-minZ+1);
564 _contourPropagation->setInterpolationNumber(100);
565 _contourPropagation->CalculeSplinePropagation();
567 double totalZ = maxZ-minZ+1;
570 //--------------------------------------------------------------------
571 for ( z=minZ ; z<=maxZ ; z++ )
573 porcent = 100.0* (z-minZ)/totalZ;
574 tmpString.Printf(" %d %c %d/%d %d", (int)porcent , 37 , (int)(z-minZ+1), (int)totalZ,z );
575 _staticTextSpread->SetLabel(tmpString);
577 if (_contourPropagation->ifSliceKeyContourExist(z)==false)
579 manModelContour = factoryManualContourModel( typeofcontour );
580 idTmp = _contourPropagation->FindIdWithZ(z);
581 if (typeMethodFindCtrlPoints==0) // Initial Points
583 _contourPropagation->GetInitialControlPoints( idTmp , &vecCtrlPointX,&vecCtrlPointY,&vecCtrlPointZ);
585 if (typeMethodFindCtrlPoints==1) // Automatique Method
587 _contourPropagation->GetControlPoints( idTmp ,&vecCtrlPointX,&vecCtrlPointY,&vecCtrlPointZ);
589 if (typeMethodFindCtrlPoints==2) // sampling
591 _contourPropagation->GetControlPoints( idTmp , 20.0 ,&vecCtrlPointX,&vecCtrlPointY,&vecCtrlPointZ);
593 //--------------------------------------------------------------------
594 sizeCtrPt = vecCtrlPointX.size();
595 for (j=0 ; j<sizeCtrPt ; j++)
597 //JSTG_16-07-08_----------------------------------------------------------------
598 manModelContour->AddPoint( vecCtrlPointX[j] , vecCtrlPointY[j] , -900 );
599 //--------------------------------------------------------------------
604 theName = _modelManager->createOutline( manModelContour, tempVector );
605 bool addedModel = theName.compare("") != 0;
608 double spc[3];//Si no hay imagen pero hay contornos que spacing se pone por default
609 this->_theViewPanel->getSpacing(spc);
610 //Adding the manualContourControler to interface objects structure
611 //Adding the manualViewContour to interface objects structure
612 //_sceneManager->setControlActiveStateOfALL( false );//This call is being done here because if the ROI is created underneath the previously created ROIS will still be active.
613 _sceneManager->configureViewControlTo( theName, manModelContour,spc,typeofcontour ) ;
615 }// ifSliceKeyContourExist
617 _staticTextSpread->SetLabel(" ");
621 //------------------------------------------------------------------------------------------------------------
622 void wxContourEventHandler :: onSpread( )
624 if (_spreadFrame==NULL)
626 _contourPropagation = new ContourPropagation();
627 _spreadFrame = new wxFrame (_theViewPanel, -1,_T(" Spread "), wxDefaultPosition, wxDefaultSize, wxFRAME_TOOL_WINDOW|wxSYSTEM_MENU | wxCAPTION | wxCLIP_CHILDREN |wxFRAME_FLOAT_ON_PARENT );
628 wxSize sizepanel(250,400);
629 _spreadFrame->SetSize( sizepanel );
630 wxPanel *panel = new wxPanel(_spreadFrame,-1);
632 wxButton *spreadResetBtn = new wxButton(panel,-1,_T("Reset"),wxDefaultPosition, wxSize(80,35) );
633 wxButton *spreadAddBtn = new wxButton(panel,-1,_T("Add"),wxDefaultPosition, wxSize(80,35));
635 wxString lstOptions[3];
639 _spreadMethodRadiobox = new wxRadioBox(panel, -1, "Method (find ctrl. Points)", wxDefaultPosition, wxSize(200,45), 3 , lstOptions, 3, wxRA_SPECIFY_COLS);
640 _spreadMethodRadiobox->SetSelection(2);
642 wxButton *spreadGoBtn = new wxButton(panel,-1,_T("Go"),wxDefaultPosition, wxSize(80,35));
643 _staticTextSpread = new wxStaticText(panel,-1,_T(" "));
645 _wxtextctrlSpread = new wxTextCtrl(panel,-1, "",wxDefaultPosition, wxSize(200,150), wxTE_MULTILINE );
647 _spreadFrame->SetEventHandler( this );
648 Connect( spreadResetBtn->GetId(), wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &wxContourEventHandler::onSpreadReset );
649 Connect( spreadAddBtn->GetId(), wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &wxContourEventHandler::onSpreadAdd );
650 Connect( spreadGoBtn->GetId(), wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &wxContourEventHandler::onSpreadGo );
652 wxFlexGridSizer * sizer = new wxFlexGridSizer(1);
653 sizer -> Add( spreadResetBtn , 1, wxGROW );
654 sizer -> Add( spreadAddBtn , 1, wxGROW );
655 sizer -> Add( _spreadMethodRadiobox , 1, wxGROW );
656 sizer -> Add( spreadGoBtn , 1, wxGROW );
657 sizer -> Add( _staticTextSpread , 1, wxGROW );
658 sizer -> Add( _wxtextctrlSpread , 1, wxGROW );
661 panel->SetSizer( sizer );
662 panel->SetSize( sizepanel );
663 panel->SetAutoLayout( true );
665 _spreadFrame->Show();
667 if (_spreadFrame->IsShown()==true)
669 _spreadFrame->Show(false);
671 _spreadFrame->Show(true);
677 //------------------------------------------------------------------------------------------------------------
678 void wxContourEventHandler::onSegmentationAllSlice( wxCommandEvent& event )
681 int x = this->_theViewPanel->GetX();
682 int y = this->_theViewPanel->GetY();
686 minZ=_mbarrange->GetStart();
687 maxZ=_mbarrange->GetEnd();
688 double totalZ = maxZ-minZ+1;
689 for( z=minZ ; z<=maxZ ; z++ )
691 porcent = 100.0* (z-minZ)/totalZ;
692 tmpString.Printf(" %d %c %d/%d %d", (int)porcent , 37 , z-minZ+1, (int)totalZ,z );
693 _staticTextSegmentation->SetLabel(tmpString);
694 SegmentationOneSlice( x,y,z );
696 _staticTextSegmentation->SetLabel(" ");
700 //------------------------------------------------------------------------------------------------------------
701 void wxContourEventHandler::onSegmentationOneSlice( wxCommandEvent& event )
704 int x = this->_theViewPanel->GetX();
705 int y = this->_theViewPanel->GetY();
706 int z = this->_theViewPanel->GetZ();
707 SegmentationOneSlice( x,y,z );
710 //------------------------------------------------------------------------------------------------------------
711 void wxContourEventHandler::SegmentationOneSlice( int x, int y, int z )
713 int typeofcontour = 1;
714 //--Extracting Contour
715 vtkImageData *imagedata = _sceneManager->GetImageData();
716 // double *range = imagedata->GetScalarRange();
718 int isovalue = _isovalue->GetValue();
719 int sampling = _sampling->GetValue();
721 vtkImageReslice *imageReslice = vtkImageReslice::New();
724 // imagedata->GetSpacing(spc);
729 imageReslice->SetInput( imagedata );
730 imageReslice->SetInformationInput(imagedata);
731 imageReslice->SetResliceAxesDirectionCosines(1,0,0, 0,1,0 ,0,0,1);
732 imageReslice->SetResliceAxesOrigin(0,0,z);
733 imageReslice->SetOutputDimensionality(2);
734 imageReslice->SetInterpolationModeToLinear();
736 imagedata = imageReslice->GetOutput();
738 imagedata->UpdateInformation();
740 vtkContourFilter* cntVTK = vtkContourFilter::New( );
741 cntVTK->SetInput( imagedata );
743 cntVTK->SetNumberOfContours( 1 );
744 //cntVTK->SetValue( 0, vmin );
745 // cntVTK->SetValue( 0, (range[1]*thr/100) );
746 cntVTK->SetValue( 1, isovalue );
747 // cntVTK->SetValue( 1, vmax );
749 cntVTK->UpdateInformation();
751 vtkCleanPolyData* cpd = vtkCleanPolyData::New( );
752 cpd->SetInput( cntVTK->GetOutput( ) );
753 cpd->ConvertLinesToPointsOff( );
755 cpd->UpdateInformation();
757 vtkPolyDataConnectivityFilter* conn = vtkPolyDataConnectivityFilter::New( );
758 conn->SetExtractionModeToClosestPointRegion( );
759 //conn->SetMaxRecursionDepth( 3000 );
761 conn->SetInput( cpd->GetOutput( ) );
763 conn->SetClosestPoint( x, y, 0 );
765 conn->UpdateInformation();
767 vtkCleanPolyData* cpd2 = vtkCleanPolyData::New( );
768 cpd2->SetInput( conn->GetOutput( ) );
770 cpd2->UpdateInformation();
772 vtkStripper* vtkstripper = vtkStripper::New( );
773 vtkstripper->SetInput( cpd2->GetOutput() );
774 vtkstripper->Update();
775 vtkstripper->UpdateInformation();
778 vtkPolyData* polyDataResult = vtkstripper->GetOutput();
780 polyDataResult->Update( );
781 polyDataResult->UpdateInformation();
785 myfile.open ("c:/temp/example.txt");
787 polyDataResult->Print(myfile);
788 myfile << "-------------------------------------\n";
789 polyDataResult->GetLines()->Print(myfile);
799 //--Calculating control points
801 std::vector<double> vecX;
802 std::vector<double> vecY;
803 std::vector<double> vecZ;
805 std::vector<double> vecCtrlPointX;
806 std::vector<double> vecCtrlPointY;
807 std::vector<double> vecCtrlPointZ;
811 int ii,size=polyDataResult->GetNumberOfPoints();
813 for (ii=1;ii<=size;ii++)
815 id = polyDataResult->GetLines()->GetData()->GetValue(ii);
816 p = polyDataResult->GetPoint(id);
819 vecX.push_back( p[0] );
820 vecY.push_back( p[1] );
821 vecZ.push_back( -900 );
822 // vecZ.push_back( p[2] );
826 ExtractControlPoints2D *extractcontrolpoints2d = new ExtractControlPoints2D();
827 extractcontrolpoints2d->SetContour( &vecX , &vecY , &vecZ );
830 if (methodRadiobox->GetSelection()==0){
831 extractcontrolpoints2d->GetInitialControlPoints( &vecCtrlPointX , &vecCtrlPointY , &vecCtrlPointZ );
833 if (methodRadiobox->GetSelection()==1){
834 extractcontrolpoints2d->GetControlPoints( &vecCtrlPointX , &vecCtrlPointY , &vecCtrlPointZ );
836 if (methodRadiobox->GetSelection()==2){
837 extractcontrolpoints2d->SetSamplingControlPoints( sampling );
838 extractcontrolpoints2d->GetSamplingControlPoints( &vecCtrlPointX , &vecCtrlPointY , &vecCtrlPointZ );
841 //--Adding contour to the system
843 std::vector<int> actualInstantVector;
844 _instantPanel->getInstant( actualInstantVector );
845 actualInstantVector[1]=z;
847 int j,sizeCtrPt = vecCtrlPointX.size();
848 manualContourModel *manModelContour = factoryManualContourModel( typeofcontour );
849 manModelContour->SetNumberOfPointsSpline( ((sizeCtrPt/100)+1)*100 );
851 for (j=0 ; j<sizeCtrPt ; j++)
853 manModelContour->AddPoint( vecCtrlPointX[j] , vecCtrlPointY[j] , vecCtrlPointZ[j] );
856 theName = _modelManager->createOutline( manModelContour, actualInstantVector );
857 bool addedModel = theName.compare("") != 0;
860 double spc[3];//Si no hay imagen pero hay contornos que spacing se pone por default
861 this->_theViewPanel->getSpacing(spc);
862 //Adding the manualContourControler to interface objects structure
863 //Adding the manualViewContour to interface objects structure
864 //_sceneManager->setControlActiveStateOfALL( false );//This call is being done here because if the ROI is created underneath the previously created ROIS will still be active.
865 _sceneManager->configureViewControlTo( theName, manModelContour,spc, typeofcontour ) ;
870 //------------------------------------------------------------------------------------------------------------
871 void wxContourEventHandler :: onAutomatiqueSegmentation( )
873 if (_segmentationFrame==NULL)
875 int sizeZ = _sceneManager->GetImageDataSizeZ();
877 _sceneManager->GetImageDataRange(range);
879 wxSize sizePanel( 300, 470);
880 _segmentationFrame = new wxFrame (_theViewPanel, -1,_T(" Segmentation "), wxDefaultPosition, wxDefaultSize, wxFRAME_TOOL_WINDOW|wxSYSTEM_MENU | wxCAPTION | wxCLIP_CHILDREN |wxFRAME_FLOAT_ON_PARENT );
881 _segmentationFrame->SetSize( sizePanel );
882 wxPanel *panel = new wxPanel(_segmentationFrame,-1);
883 wxButton *segmentationOneSliceBtn = new wxButton(panel,-1,_T("Actual slice"), wxDefaultPosition, wxSize(200,35) );
884 wxButton *segmentationAllSliceBtn = new wxButton(panel,-1,_T("All slices") ,wxDefaultPosition, wxSize(200,35) );
885 _isovalue = new wxSlider(panel, -1, 40 , (int)(range[0]), (int)(range[1]), wxDefaultPosition, wxSize(200,35), wxSL_HORIZONTAL|wxSL_LABELS, wxDefaultValidator);
886 _sampling = new wxSlider(panel, -1, 20 , 4, 50, wxDefaultPosition, wxSize(200,35), wxSL_HORIZONTAL|wxSL_LABELS, wxDefaultValidator);
887 wxString lstOptions[3];
891 methodRadiobox = new wxRadioBox(panel, -1, "Method (find ctrl. Points)", wxDefaultPosition, wxSize(200,45), 3 , lstOptions, 3, wxRA_SPECIFY_COLS);
892 methodRadiobox->SetSelection(2);
893 _staticTextSegmentation = new wxStaticText(panel,-1,_T(" "));
896 _mbarrange = new mBarRange(panel,70, 65);
897 _mbarrange->SetMin(0);
898 _mbarrange->SetStart(0);
900 _mbarrange-> SetOrientation( true );
901 _mbarrange-> setActiveStateTo(true);
902 _mbarrange-> setVisibleLabels( true );
903 _mbarrange-> setDeviceEndMargin(10);
904 _mbarrange-> setRepresentedValues( 0 , sizeZ );
905 _mbarrange-> setDeviceBlitStart(10,10);
906 _mbarrange-> setIfWithActualDrawed( false );
907 _mbarrange-> SetStart( 0 );
908 _mbarrange-> SetEnd( sizeZ );
911 // _segmentationFrame->SetEventHandler( this );
912 segmentationOneSliceBtn->SetEventHandler( this );
913 segmentationAllSliceBtn->SetEventHandler( this );
914 Connect( segmentationOneSliceBtn->GetId(), wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &wxContourEventHandler::onSegmentationOneSlice );
915 Connect( segmentationAllSliceBtn->GetId(), wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &wxContourEventHandler::onSegmentationAllSlice );
917 wxFlexGridSizer * sizer = new wxFlexGridSizer(1);
918 sizer -> Add( new wxStaticText(panel,-1,_T("Isovalue (Gray level)")) , 1, wxGROW );
919 sizer -> Add( _isovalue , 1, wxGROW );
920 sizer -> Add( methodRadiobox , 1, wxGROW );
921 sizer -> Add( new wxStaticText(panel,-1,_T("Sampling (%)")) , 1, wxGROW );
922 sizer -> Add( _sampling , 1, wxGROW );
923 sizer -> Add( segmentationOneSliceBtn , 1, wxGROW );
924 sizer -> Add( new wxStaticText(panel,-1,_T(" ")) , 1, wxGROW );
925 sizer -> Add( _staticTextSegmentation , 1, wxGROW );
926 sizer -> Add( segmentationAllSliceBtn , 1, wxGROW );
927 sizer -> Add( _mbarrange , 1, wxGROW );
929 panel->SetSizer( sizer );
930 panel->SetSize( sizePanel );
931 panel->SetAutoLayout( true );
933 _segmentationFrame->Show(true);
934 this->_theViewPanel->SetVisibleAxis(true);
935 this->_theViewPanel->Refresh();
937 if (_segmentationFrame->IsShown()==true)
939 _segmentationFrame->Show(false);
940 this->_theViewPanel->SetVisibleAxis(false);
941 this->_theViewPanel->Refresh();
943 _segmentationFrame->Show(true);
944 this->_theViewPanel->SetVisibleAxis(true);
945 this->_theViewPanel->Refresh();
950 void wxContourEventHandler :: onInterfaceTestFrame( )
952 if (_TestFrame==NULL)
954 _contourPropagation = new ContourPropagation();
955 _TestFrame = new wxFrame (_theViewPanel, -1,_T(" Test Segmentation "), wxDefaultPosition, wxDefaultSize, wxFRAME_TOOL_WINDOW|wxSYSTEM_MENU | wxCAPTION | wxCLIP_CHILDREN |wxFRAME_FLOAT_ON_PARENT );
956 wxSize sizepanel(200,300);
957 _TestFrame->SetSize( sizepanel );
958 wxPanel *panel = new wxPanel(_TestFrame,-1);
959 wxButton *spreadResetBtn = new wxButton(panel,-1,_T("Reset"),wxDefaultPosition, wxSize(80,35) );
960 wxButton *spreadAddBtn = new wxButton(panel,-1,_T("Add"),wxDefaultPosition, wxSize(80,35));
961 wxButton *spreadGoBtn = new wxButton(panel,-1,_T("GoA"),wxDefaultPosition, wxSize(80,35));
962 _wxtextctrlTest = new wxTextCtrl(panel,-1, "",wxDefaultPosition, wxSize(200,150), wxTE_MULTILINE );
964 _TestFrame->SetEventHandler( this );
965 Connect( spreadResetBtn->GetId(), wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &wxContourEventHandler::onTestReset );
966 Connect( spreadAddBtn->GetId(), wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &wxContourEventHandler::onTestAdd );
967 Connect( spreadGoBtn->GetId(), wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &wxContourEventHandler::onTestGo );
969 wxFlexGridSizer * sizer = new wxFlexGridSizer(1);
970 sizer -> Add( spreadResetBtn , 1, wxGROW );
971 sizer -> Add( spreadAddBtn , 1, wxGROW );
972 sizer -> Add( spreadGoBtn , 1, wxGROW );
973 sizer -> Add( _wxtextctrlTest , 1, wxGROW );
975 panel->SetSizer( sizer );
976 panel->SetSize( sizepanel );
977 panel->SetAutoLayout( true );
981 if (_TestFrame->IsShown()==true)
983 _TestFrame->Show(false);
985 _TestFrame->Show(true);
990 void wxContourEventHandler::onTestReset( wxCommandEvent& event )
992 _wxtextctrlTest->SetValue("");
993 _contourPropagation->resetAppend();
996 //------------------------------------------------------------------------------------------------------------
997 void wxContourEventHandler::onTestAdd( wxCommandEvent& event )
999 std::vector<double> vecX;
1000 std::vector<double> vecY;
1001 std::vector<double> vecZ;
1002 _sceneManager->GetPointsOfActualContour( &vecX , &vecY , &vecZ );
1004 if (vecX.size()!=0){
1005 std::vector<int> tempVector;
1006 _instantPanel->getInstant( tempVector );
1007 int i,size=vecZ.size();
1008 int actualSlice = tempVector[1];
1009 for ( i=0 ; i<size ; i++ )
1011 vecZ[i] = actualSlice;
1014 _contourPropagation->appendContour(&vecX , &vecY , &vecZ);
1016 newstring.Printf("%s %d -",_wxtextctrlTest->GetValue(), actualSlice );
1017 _wxtextctrlTest->SetValue(newstring);
1021 //------------------------------------------------------------------------------------------------------------
1022 void wxContourEventHandler::onTestGo( wxCommandEvent& event )
1024 std::vector<double> vecX;
1025 std::vector<double> vecY;
1026 std::vector<double> vecZ;
1027 std::vector<int> size;
1029 std::vector<double> vecCtrlPointX;
1030 std::vector<double> vecCtrlPointY;
1031 std::vector<double> vecCtrlPointZ;
1033 //Getting the points of the actual contour
1035 _contourPropagation->GetKeyContours(&vecX , &vecY , &vecZ, &size);
1036 for(int i = 0; i < vecX.size();i++){
1040 /*std::vector<double> vecX1;
1041 std::vector<double> vecY1;
1042 std::vector<double> vecZ1;
1043 _sceneManager->GetPointsOfActualContour( &vecX1 , &vecY1 , &vecZ1 );
1045 std::ofstream file1;
1046 file1.open( "Temp.txt" );
1049 for(int i = 0; i < vecX.size(); i++){
1050 file1<<vecX[i] <<" X1 "<< vecX1[i] <<" Y "<<vecY[i] <<" Y1 "<< vecY1[i] <<" Z "<<vecZ[i] <<" Z1 "<< vecZ1[i]<<std::endl;
1058 //Setting the points of the contour
1060 ExtractControlPoints2D *extractcontrolpoints2d = new ExtractControlPoints2D();
1061 extractcontrolpoints2d->SetContour( &vecX , &vecY , &vecZ );
1063 //Getting the control points of the contour by method A
1065 extractcontrolpoints2d->GetInitialControlPoints( &vecCtrlPointX , &vecCtrlPointY , &vecCtrlPointZ );
1067 std::vector<int> actualInstantVector;
1068 _instantPanel->getInstant( actualInstantVector );
1069 actualInstantVector[1]= this->_theViewPanel->GetZ();
1071 //Adding the Contour to the scene
1073 manualContourModel *manModelContour = new manualContourModel();
1074 int j,sizeCtrPt = vecCtrlPointX.size();
1076 for (j=0 ; j<sizeCtrPt ; j++)
1078 manModelContour->AddPoint( vecCtrlPointX[j] , vecCtrlPointY[j] , vecCtrlPointZ[j] );
1080 std::string theName;
1081 theName = _modelManager->createOutline( manModelContour, actualInstantVector );
1082 bool addedModel = theName.compare("") != 0;
1085 double spc[3];//Si no hay imagen pero hay contornos que spacing se pone por default
1086 this->_theViewPanel->getSpacing(spc);
1087 //Adding the manualContourControler to interface objects structure
1088 //Adding the manualViewContour to interface objects structure
1089 //_sceneManager->setControlActiveStateOfALL( false );//This call is being done here because if the ROI is created underneath the previously created ROIS will still be active.
1090 _sceneManager->configureViewControlTo( theName, manModelContour,spc,1 ) ;
1095 //------------------------------------------------------------------------------------------------------------
1096 void wxContourEventHandler::FillGridWithContoursInformation()
1098 wxString tempString;
1100 _grid->SetColLabelValue(0, _T("A") );
1101 _grid->SetColLabelValue(1, _T("B") );
1102 _grid->SetColLabelValue(2, _T("C") );
1103 _grid->SetColLabelValue(3, _T("D") );
1104 _grid->SetColLabelValue(4, _T("E") );
1105 _grid->SetColLabelValue(5, _T("F") );
1107 std::vector<int> tempVector;
1108 _instantPanel->getInstant( tempVector );
1110 int z,sizeZ = _sceneManager->GetImageDataSizeZ();
1111 int ii,sizeLstContourThings;
1112 for ( z=0 ; z<sizeZ ; z++)
1115 Instant instant(&tempVector);
1116 std::vector<ContourThing**> lstContourThings = this->_modelManager->getOutlinesAtInstant( &instant );
1118 sizeLstContourThings = lstContourThings.size();
1119 tempString.Printf("%d - %d",z, sizeLstContourThings);
1120 _grid->SetRowLabelValue(z, tempString );
1122 for (ii=0 ; ii<sizeLstContourThings ; ii++)
1124 ContourThing **contourthing = lstContourThings[ii];
1125 tempString = (*contourthing)->getName().c_str() ;
1126 _grid->SetCellValue( z, ii, tempString );
1133 //------------------------------------------------------------------------------------------------------------
1134 std::vector<manualContourModel*> wxContourEventHandler::ExploseEachModel( std::vector<manualContourModel*> lstManConMod )
1136 std::vector<manualContourModel*> lstTmp;
1137 std::vector<manualContourModel*> lstResult;
1139 int i,iSize=lstManConMod.size();
1140 for (i=0;i<iSize;i++)
1142 lstTmp = lstManConMod[i]->ExploseModel();
1143 jSize=lstTmp.size();
1144 for (j=0;j<jSize;j++)
1146 lstResult.push_back( lstTmp[j] );
1152 //------------------------------------------------------------------------------------------------------------
1153 void wxContourEventHandler::onExtractInformation( wxCommandEvent& event )
1156 int maxContourGroup = 0;
1160 ContourExtractData *contourextractdata = new ContourExtractData();
1161 int typeContourGroup = this->_radiolstboxContourGroup->GetSelection();
1162 contourextractdata ->SetTypeOperation( typeContourGroup % 3 );
1164 std::vector<manualContourModel*> lstManConMod;
1165 std::vector<manualContourModel*> lstManConModTmp;
1166 std::vector<manualContourModel*> lstManConModExp;
1167 std::vector<double> pLstValue;
1168 std::vector<double> pLstValuePosX;
1169 std::vector<double> pLstValuePosY;
1170 std::vector<double> pLstValuePosZ;
1173 int resultGrayRangeCount;
1176 double resultAverage;
1177 double resultStandardeviation;
1179 std::vector<int> tempVector;
1180 _instantPanel->getInstant( tempVector );
1182 vtkImageData *imagedata = _sceneManager->GetImageData();
1183 int sizeZ = _sceneManager->GetImageDataSizeZ();
1185 int ii,sizeLstContourThings;
1194 if (_informationRadiobox->GetSelection()==0 ) // actual slice
1196 std::vector<int> tempVector;
1197 _instantPanel->getInstant( tempVector );
1198 int actualSlice = tempVector[1];
1202 if (_informationRadiobox->GetSelection()==1 ) // slice range
1204 minZ = _mbarrangeSliceInformation->GetStart();
1205 maxZ = _mbarrangeSliceInformation->GetEnd();
1207 if (_informationRadiobox->GetSelection()==2 ) // All slices
1213 totalZ = maxZ-minZ+1;
1214 contourextractdata->SetImage( imagedata);
1217 for ( z=minZ ; z<=maxZ ; z++ )
1219 porcent = 100.0* (z-minZ)/totalZ;
1220 tmpString.Printf(" %d %c %d/%d %d", (int)porcent , 37 , z-minZ+1, (int)totalZ ,z);
1221 _staticTextInformation->SetLabel(tmpString);
1223 //Extraction data from contours of each slice
1224 contourextractdata->SetZtoBeAnalys( z);
1227 Instant instant(&tempVector);
1228 std::vector<ContourThing**> lstContourThings = this->_modelManager->getOutlinesAtInstant( &instant );
1229 sizeLstContourThings = lstContourThings.size();
1231 lstManConMod.clear();
1232 for (ii=0 ; ii<sizeLstContourThings ; ii++)
1234 ContourThing **contourthing = lstContourThings[ii];
1235 lstManConMod.push_back( (*contourthing)->getModel() );
1237 lstManConModExp = ExploseEachModel( lstManConMod );
1240 wxString tempString;
1241 tempString.Printf("%d - %d",z, sizeLstContourThings);
1242 _grid->SetRowLabelValue(z, tempString );
1244 int iContourGroup,sizeContourGroup;
1245 if (typeContourGroup==3) // contour separete
1247 sizeContourGroup=lstManConModExp.size();
1248 if ( maxContourGroup<sizeContourGroup )
1250 maxContourGroup=sizeContourGroup;
1252 } else { // contour AND OR XOR
1261 for( iContourGroup=0 ; iContourGroup<sizeContourGroup ; iContourGroup++ ){
1262 lstManConModTmp.clear();
1263 if (typeContourGroup==3) // contour separete
1265 lstManConModTmp.push_back( lstManConModExp[iContourGroup]);
1266 } else { // contour AND OR XOR
1267 lstManConModTmp = lstManConModExp;
1270 contourextractdata->SetLstManualContourModel( lstManConModTmp );
1273 pLstValuePosX.clear();
1274 pLstValuePosY.clear();
1275 pLstValuePosZ.clear();
1276 contourextractdata->GetValuesInsideCrown( &pLstValue,
1280 // Statistics of each slice.
1281 contourextractdata->Statistics( &pLstValue,
1282 _mbarrangeRangeInformation->GetStart(),
1283 _mbarrangeRangeInformation->GetEnd(),
1284 &resultGrayRangeCount,
1289 &resultStandardeviation);
1290 if (_grid->GetNumberCols()<_numberOfVariablesStatistics*(iContourGroup+1) )
1292 _grid->AppendCols(_numberOfVariablesStatistics);
1295 tmpIntA=_numberOfVariablesStatistics*iContourGroup ;
1297 tempString.Printf("%d",resultSize);
1298 _grid->SetCellValue( z, tmpIntA + 0, tempString );
1299 tempString.Printf("%d",resultGrayRangeCount);
1300 _grid->SetCellValue( z, tmpIntA + 1, tempString );
1301 tempString.Printf("%f",resultMin);
1302 _grid->SetCellValue( z, tmpIntA + 2, tempString );
1303 tempString.Printf("%f",resultMax);
1304 _grid->SetCellValue( z, tmpIntA + 3, tempString );
1305 tempString.Printf("%f",resultAverage);
1306 _grid->SetCellValue( z, tmpIntA + 4, tempString );
1307 tempString.Printf("%f",resultStandardeviation);
1308 _grid->SetCellValue( z, tmpIntA + 5, tempString );
1310 } // for iContourGroup
1314 wxString tmpTitleString;
1316 for ( iTitleGroup=0 ; iTitleGroup<maxContourGroup ; iTitleGroup++ )
1318 tmpIntB =_numberOfVariablesStatistics*iTitleGroup;
1319 tmpTitleString.Printf(_T("%d-Size Data"),iTitleGroup);
1320 _grid->SetColLabelValue( tmpIntB + 0, tmpTitleString );
1321 _grid->SetColLabelValue( tmpIntB + 1, _T("Size Range") );
1322 _grid->SetColLabelValue( tmpIntB + 2, _T("Min") );
1323 _grid->SetColLabelValue( tmpIntB + 3, _T("Max") );
1324 _grid->SetColLabelValue( tmpIntB + 4, _T("Average") );
1325 _grid->SetColLabelValue( tmpIntB + 5, _T("St.Dev.") );
1326 _grid->SetColLabelValue( tmpIntB + 6, _T(" ") );
1329 _staticTextInformation->SetLabel( _T("") );
1330 delete contourextractdata;
1334 //------------------------------------------------------------------------------------------------------------
1335 void wxContourEventHandler::SaveValuesXYZ(std::string directory,std::string namefile)
1338 ContourExtractData *contourextractdata = new ContourExtractData();
1339 int typeContourGroup = this->_radiolstboxContourGroup->GetSelection();
1340 contourextractdata ->SetTypeOperation( typeContourGroup % 3 );
1342 std::vector<manualContourModel*> lstManConMod;
1343 std::vector<manualContourModel*> lstManConModTmp;
1344 std::vector<manualContourModel*> lstManConModExp;
1345 std::vector<double> pLstValue;
1346 std::vector<double> pLstValuePosX;
1347 std::vector<double> pLstValuePosY;
1348 std::vector<double> pLstValuePosZ;
1350 std::vector<int> tempVector;
1351 _instantPanel->getInstant( tempVector );
1353 vtkImageData *imagedata = _sceneManager->GetImageData();
1354 int sizeZ = _sceneManager->GetImageDataSizeZ();
1356 int ii,sizeLstContourThings;
1363 minZ = 0;// _mbarrange->GetStart();
1364 maxZ = sizeZ;//_mbarrange->GetEnd();
1365 totalZ = maxZ-minZ+1;
1367 contourextractdata->SetImage( imagedata);
1370 for ( z=0 ; z<sizeZ ; z++)
1373 porcent = 100.0* (z-minZ)/totalZ;
1374 tmpString.Printf("Saving Values %d %c %d/%d %d", (int)porcent , 37 , z-minZ+1, (int)totalZ ,z);
1375 _staticTextInformation->SetLabel(tmpString);
1378 //Extraction data from contours of each slice
1379 contourextractdata->SetZtoBeAnalys( z);
1382 Instant instant(&tempVector);
1383 std::vector<ContourThing**> lstContourThings = this->_modelManager->getOutlinesAtInstant( &instant );
1384 sizeLstContourThings = lstContourThings.size();
1386 lstManConMod.clear();
1387 for (ii=0 ; ii<sizeLstContourThings ; ii++)
1389 ContourThing **contourthing = lstContourThings[ii];
1390 lstManConMod.push_back( (*contourthing)->getModel() );
1392 lstManConModExp = ExploseEachModel( lstManConMod );
1397 int iContourGroup,sizeContourGroup;
1398 if (typeContourGroup==3) // contour separete
1400 sizeContourGroup=lstManConModExp.size();
1401 } else { // contour AND OR XOR
1405 for( iContourGroup=0 ; iContourGroup<sizeContourGroup ; iContourGroup++ ){
1406 lstManConModTmp.clear();
1407 if (typeContourGroup==3) // contour separete
1409 lstManConModTmp.push_back( lstManConModExp[iContourGroup]);
1410 } else { // contour AND OR XOR
1411 lstManConModTmp = lstManConModExp;
1414 contourextractdata->SetLstManualContourModel( lstManConModTmp );
1417 pLstValuePosX.clear();
1418 pLstValuePosY.clear();
1419 pLstValuePosZ.clear();
1420 contourextractdata->GetValuesInsideCrown( &pLstValue,
1426 filename.Printf("%s\\%s-slice%d-cont%d.txt",directory.c_str(),namefile.c_str(),z,iContourGroup);
1427 FILE *pFile=fopen((const char *)filename.mb_str(),"w+");
1428 fprintf(pFile,"value \t x \t y \t z\n" );
1429 int iLstValue,sizeLstValue=pLstValue.size();
1430 for (iLstValue=0 ; iLstValue<sizeLstValue ; iLstValue++ )
1432 fprintf(pFile,"%f\t %f\t %f\t %f\n", (float)pLstValue[iLstValue] , (float)pLstValuePosX[iLstValue], (float)pLstValuePosY[iLstValue], (float)z );
1435 } // for iContourGroup
1437 _staticTextInformation->SetLabel( _T("") );
1438 delete contourextractdata;
1442 //------------------------------------------------------------------------------------------------------------
1443 void wxContourEventHandler::SaveImageResult(std::string directory,std::string namefile)
1446 ContourExtractData *contourextractdata = new ContourExtractData( true );
1447 int typeContourGroup = this->_radiolstboxContourGroup->GetSelection();
1448 if (typeContourGroup==3)
1452 contourextractdata ->SetTypeOperation( typeContourGroup % 3 );
1454 std::vector<manualContourModel*> lstManConMod;
1455 std::vector<manualContourModel*> lstManConModTmp;
1456 std::vector<manualContourModel*> lstManConModExp;
1458 std::vector<int> tempVector;
1459 _instantPanel->getInstant( tempVector );
1461 vtkImageData *imagedata = _sceneManager->GetImageData();
1462 int sizeZ = _sceneManager->GetImageDataSizeZ();
1464 int ii,sizeLstContourThings;
1473 minZ = 0;// _mbarrange->GetStart();
1474 maxZ = sizeZ;//_mbarrange->GetEnd();
1475 totalZ = maxZ-minZ+1;
1477 contourextractdata->SetImage( imagedata);
1480 for ( z=0 ; z<sizeZ ; z++)
1483 porcent = 100.0* (z-minZ)/totalZ;
1484 tmpString.Printf("Saving Values %d %c %d/%d %d", (int)porcent , 37 , z-minZ+1, (int)totalZ ,z);
1485 _staticTextInformation->SetLabel(tmpString);
1487 //Extraction data from contours of each slice
1488 contourextractdata->SetZtoBeAnalys( z);
1491 Instant instant(&tempVector);
1492 std::vector<ContourThing**> lstContourThings = this->_modelManager->getOutlinesAtInstant( &instant );
1493 sizeLstContourThings = lstContourThings.size();
1495 lstManConMod.clear();
1496 for (ii=0 ; ii<sizeLstContourThings ; ii++)
1498 ContourThing **contourthing = lstContourThings[ii];
1499 lstManConMod.push_back( (*contourthing)->getModel() );
1501 lstManConModExp = ExploseEachModel( lstManConMod );
1504 int iContourGroup,sizeContourGroup;
1505 if (typeContourGroup==3) // contour separete
1507 sizeContourGroup=lstManConModExp.size();
1508 } else { // contour AND OR XOR
1512 for( iContourGroup=0 ; iContourGroup<sizeContourGroup ; iContourGroup++ ){
1513 lstManConModTmp.clear();
1514 if (typeContourGroup==3) // contour separete
1516 lstManConModTmp.push_back( lstManConModExp[iContourGroup]);
1517 } else { // contour AND OR XOR
1518 lstManConModTmp = lstManConModExp;
1521 contourextractdata->SetLstManualContourModel( lstManConModTmp );
1524 // for (ii=0 ; ii<sizeLstContourThings ; ii++)
1526 // ContourThing **contourthing = lstContourThings[ii];
1527 // lstManConMod.push_back( (*contourthing)->getModel() );
1529 // contourextractdata->SetLstManualContourModel( lstManConMod );
1531 contourextractdata->CalculateImageResult(); // with actual Z
1533 } // for iContourGroup
1538 filename.Printf("%s\\%s-Value.mhd",directory.c_str(),namefile.c_str(),z);
1541 vtkMetaImageWriter *writerValueImage = vtkMetaImageWriter::New( );
1542 writerValueImage->SetInput( contourextractdata->GetVtkImageValueResult() );
1543 writerValueImage->SetFileName( (const char *)filename.mb_str() );
1544 writerValueImage->SetFileDimensionality( 3 );
1545 writerValueImage->Write( );
1548 filename.Printf("%s\\%s-Mask.mhd",directory.c_str(),namefile.c_str(),z);
1549 vtkMetaImageWriter *writerMaskImage = vtkMetaImageWriter::New( );
1550 writerMaskImage->SetInput( contourextractdata->GetVtkImageMaskResult() );
1551 writerMaskImage->SetFileName( (const char *)filename.mb_str() );
1552 writerMaskImage->SetFileDimensionality( 3 );
1553 writerMaskImage->Write( );
1555 _staticTextInformation->SetLabel( _T("") );
1556 delete contourextractdata;
1560 //------------------------------------------------------------------------------------------------------------
1561 void wxContourEventHandler::onInformationContourLabels( wxCommandEvent& event )
1564 FillGridWithContoursInformation();
1568 //------------------------------------------------------------------------------------------------------------
1569 void wxContourEventHandler::onSaveResults( wxCommandEvent& event )
1571 wxFileDialog dialog(_InformationContourFrame, _T("Choose a file"), _T(""), _T(""), _T("*.txt"), wxSAVE );
1572 if (dialog.ShowModal() == wxID_OK)
1574 onExtractInformation( event );
1575 std::string directory=(const char *)(dialog.GetDirectory().mb_str());
1576 std::string namefile=(const char *)(dialog.GetFilename().mb_str());
1578 SaveValuesXYZ( directory , namefile );
1579 SaveImageResult( directory , namefile );
1581 std::string filename = (const char *)(dialog.GetPath().mb_str() );
1582 FILE *pFile=fopen(filename.c_str(),"w+");
1584 int sizeZ = _sceneManager->GetImageDataSizeZ();
1587 int i,j,maxX,maxY=sizeZ;
1588 maxX=this->_grid->GetNumberCols();
1590 int iTitle,sizeTitle = (maxX / _numberOfVariablesStatistics);
1591 for ( iTitle=0; iTitle<sizeTitle ; iTitle++)
1593 fprintf(pFile,"-- \t %d-Size \t SizeRange \t Min \t Max \t Ave \t StDv \t" , iTitle,tmpString.char_str() );
1595 fprintf(pFile,"\n" );
1599 for ( j=0; j<maxY ; j++)
1601 fprintf(pFile,"%d\t" , j );
1602 for (i=0 ; i<maxX ; i++){
1603 tmpString = _grid->GetCellValue( j , i );
1604 fprintf(pFile,"%s\t" , (const char *)(tmpString.mb_str()) );
1606 fprintf(pFile,"\n" );
1616 //------------------------------------------------------------------------------------------------------------
1617 void wxContourEventHandler::onInformationContourFrame()
1619 if (_InformationContourFrame==NULL)
1621 _InformationContourFrame = new wxFrame (_theViewPanel, -1,_T(" Information "), wxDefaultPosition, wxDefaultSize, wxFRAME_TOOL_WINDOW|wxSYSTEM_MENU | wxCAPTION | wxCLIP_CHILDREN |wxFRAME_FLOAT_ON_PARENT | wxRESIZE_BORDER );
1622 _InformationContourFrame->SetSize( wxSize(500,450) );
1623 wxSize sizepanel(200,300);
1624 wxPanel *panel = new wxPanel(_InformationContourFrame,-1,wxDefaultPosition, wxDefaultSize,wxTAB_TRAVERSAL);
1626 wxString lstOptions[4];
1627 lstOptions[0]=_T("Actual Slice");
1628 lstOptions[1]=_T("Range Slices");
1629 lstOptions[2]=_T("All Slices");
1630 _informationRadiobox = new wxRadioBox(panel, -1, _T("Slice analysis"), wxDefaultPosition, wxSize(270,45), 3 , lstOptions, 3, wxRA_SPECIFY_COLS);
1632 wxString lstOptContOperation[5];
1633 lstOptContOperation[0]=_T("AND");
1634 lstOptContOperation[1]=_T("OR");
1635 lstOptContOperation[2]=_T("XOR");
1636 lstOptContOperation[3]=_T("ALL");
1637 _radiolstboxContourGroup = new wxRadioBox(panel, -1, _T("Contour group"), wxDefaultPosition, wxSize(270,45), 4 , lstOptContOperation, 4, wxRA_SPECIFY_COLS);
1639 wxButton *informationContourLabelsBtn = new wxButton(panel,-1,_T("Contour labels"),wxDefaultPosition, wxSize(140,35) );
1640 informationContourLabelsBtn->SetEventHandler( this );
1641 Connect( informationContourLabelsBtn->GetId(), wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &wxContourEventHandler::onInformationContourLabels );
1643 wxButton *statisticsContourBtn = new wxButton(panel,-1,_T("Contour statistics"),wxDefaultPosition, wxSize(140,35) );
1644 statisticsContourBtn->SetEventHandler( this );
1645 Connect( statisticsContourBtn->GetId(), wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &wxContourEventHandler::onExtractInformation );
1647 wxButton *saveResultsBtn = new wxButton(panel,-1,_T("Save statistics results"),wxDefaultPosition, wxSize(140,35) );
1648 saveResultsBtn->SetEventHandler( this );
1649 Connect( saveResultsBtn->GetId(), wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &wxContourEventHandler::onSaveResults );
1652 int sizeZ = this->_sceneManager->GetImageDataSizeZ();
1653 _mbarrangeSliceInformation = new mBarRange(panel,65,65);
1654 _mbarrangeSliceInformation->SetMin(0);
1655 _mbarrangeSliceInformation->SetStart(0);
1656 _mbarrangeSliceInformation-> SetOrientation( true );
1657 _mbarrangeSliceInformation-> setActiveStateTo(true);
1658 _mbarrangeSliceInformation-> setVisibleLabels( true );
1659 _mbarrangeSliceInformation-> setDeviceEndMargin(10);
1660 _mbarrangeSliceInformation-> setRepresentedValues( 0 , sizeZ-1 );
1661 _mbarrangeSliceInformation-> setDeviceBlitStart(10,10);
1662 _mbarrangeSliceInformation-> setIfWithActualDrawed( false );
1663 _mbarrangeSliceInformation-> SetStart( 0 );
1664 _mbarrangeSliceInformation-> SetEnd( sizeZ-1 );
1668 this->_sceneManager->GetImageDataRange(range);
1669 _mbarrangeRangeInformation = new mBarRange(panel,65,65);
1670 _mbarrangeRangeInformation->SetMin(0);
1671 _mbarrangeRangeInformation->SetStart(0);
1672 _mbarrangeRangeInformation-> SetOrientation( true );
1673 _mbarrangeRangeInformation-> setActiveStateTo(true);
1674 _mbarrangeRangeInformation-> setVisibleLabels( true );
1675 _mbarrangeRangeInformation-> setDeviceEndMargin(10);
1676 _mbarrangeRangeInformation-> setRepresentedValues( range[0] , range[1] );
1677 _mbarrangeRangeInformation-> setDeviceBlitStart(10,10);
1678 _mbarrangeRangeInformation-> setIfWithActualDrawed( false );
1679 _mbarrangeRangeInformation-> SetStart( range[0] );
1680 _mbarrangeRangeInformation-> SetEnd( range[1] );
1683 _staticTextInformation = new wxStaticText(panel,-1,_T(" "));
1686 // wxButton *XXXXXXXBtn = new wxButton(panel,-1,_T("Statistics"),wxDefaultPosition, wxSize(180,35) );
1687 // XXXXXXXBtn->SetEventHandler( this );
1688 // Connect( XXXXXXXBtn->GetId(), wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &wxContourEventHandler::onXXXXX );
1691 _grid = new wxGrid( panel,
1694 wxSize( 100, 100 ) );
1696 int i,gridCol=10,gridRow=sizeZ;
1697 _grid->CreateGrid( 0, 0 );
1698 _grid->AppendRows(gridRow);
1699 _grid->AppendCols(gridCol);
1701 for (i=0;i<gridRow;i++)
1703 _grid->SetRowLabelValue(i, _T(" ") );
1705 // _grid->SetColLabelSize(0);
1708 FillGridWithContoursInformation();
1710 wxFlexGridSizer * sizerA = new wxFlexGridSizer(10);
1711 sizerA->Add( _informationRadiobox , 1, wxALL ,2 );
1712 sizerA->Add( _radiolstboxContourGroup , 1, wxALL ,2 );
1714 wxFlexGridSizer * sizerB = new wxFlexGridSizer(10);
1715 sizerB->Add( informationContourLabelsBtn , 1, wxALL ,2 );
1716 sizerB->Add( statisticsContourBtn , 1, wxALL ,2 );
1717 sizerB->Add( saveResultsBtn , 1, wxALL ,2 );
1719 wxFlexGridSizer * sizer = new wxFlexGridSizer(1);
1720 sizer->AddGrowableCol(0);
1721 sizer->AddGrowableRow(7);
1722 sizer->Add( sizerA , 1, wxALL , 0 );
1723 sizer->Add( new wxStaticText(panel ,-1,_T("Slice Range")) , 1, wxALL , 0 );
1724 sizer->Add( _mbarrangeSliceInformation , 1, wxALL|wxGROW , 2 );
1725 sizer->Add( new wxStaticText(panel ,-1,_T("Gray Range")) , 1, wxALL , 0 );
1726 sizer->Add( _mbarrangeRangeInformation , 1, wxALL|wxGROW , 2 );
1727 sizer->Add( sizerB , 1, wxALL , 0 );
1728 sizer->Add( _staticTextInformation , 1, wxALL , 0 );
1729 sizer->Add( _grid , 1, wxEXPAND , 0 );
1733 panel->SetSizer( sizer );
1734 panel->SetSize( wxSize(1500,1500) );
1735 //panel->SetBackgroundColour( wxColour(100,100,100) );
1736 panel->SetAutoLayout( true );
1739 wxBoxSizer * sizerPanel = new wxBoxSizer(wxHORIZONTAL);
1740 sizerPanel -> Add( panel , 1, wxEXPAND ,0);
1741 _InformationContourFrame->SetSizer( sizerPanel );
1742 _InformationContourFrame->SetAutoLayout( true );
1743 _InformationContourFrame->Layout();
1745 _InformationContourFrame->Show();
1747 if (_InformationContourFrame->IsShown()==true)
1749 _InformationContourFrame->Show(false);
1751 FillGridWithContoursInformation();
1752 _InformationContourFrame->Show(true);
1758 //------------------------------------------------------------------------------------------------------------
1759 void wxContourEventHandler :: onSpreadInDepth( std::vector<std::string> & keyNamesVector )
1763 //------------------------------------------------------------------------------------------------------------
1764 void wxContourEventHandler :: onOutline_Union_Of( std::vector<std::string> & keyNamesVector )
1768 //------------------------------------------------------------------------------------------------------------
1769 void wxContourEventHandler :: onOutline_Intersection_Of( std::vector<std::string> & keyNamesVector )
1773 //------------------------------------------------------------------------------------------------------------
1774 void wxContourEventHandler :: onOutline_Combination_Of( std::vector<std::string> & keyNamesVector )
1778 //------------------------------------------------------------------------------------------------------------
1779 void wxContourEventHandler :: onOutline_Fragmentation_Of( std::vector<std::string> & keyNamesVector )
1783 //------------------------------------------------------------------------------------------------------------
1784 void wxContourEventHandler :: onOutline_Agrupation_Of( std::vector<std::string> & keyNamesVector )
1788 //------------------------------------------------------------------------------------------------------------
1789 void wxContourEventHandler :: onCopyOutlines( std::vector<std::string> & keyNamesVector )
1791 std::vector<int> tempVector;
1792 _instantPanel->getInstant( tempVector );
1793 _performingOperation->reset();
1794 _performingOperation->setStartCommand( (char)wxContour_ActionCommandsID::COPY_TOOL );
1795 _performingOperation->setStartOperationInstantVector( tempVector );
1796 _performingOperation->setKeyNamesOperationElems( keyNamesVector );
1799 //------------------------------------------------------------------------------------------------------------
1800 void wxContourEventHandler :: onPasteOutlines( )
1802 char theStartCommand = _performingOperation->getStartCommand();
1803 if ( theStartCommand == wxContour_ActionCommandsID::COPY_TOOL )
1805 std::vector<int> tempVector;
1806 _instantPanel->getInstant( tempVector );
1807 _performingOperation->setEndOperationInstantVector ( tempVector );
1808 std::vector<std::string> elems = _performingOperation->getKeyNamesOperationElems();
1809 int i,size = elems.size();
1810 for( i=0; i<size; i++ )
1812 createCopyContourOf( elems[i], tempVector, i>0 );
1817 //------------------------------------------------------------------------------------------------------------
1818 void wxContourEventHandler :: onShowOutlines( std::vector<std::string> & keyNamesVector )
1822 //------------------------------------------------------------------------------------------------------------
1823 void wxContourEventHandler :: onHideOutlines( std::vector<std::string> & keyNamesVector )
1827 //------------------------------------------------------------------------------------------------------------
1828 void wxContourEventHandler :: onSelectOutlines( std::vector<std::string> & keyNamesVector )
1830 //if( keyNamesVector.empty() )
1832 _sceneManager->drawSelectionROI( );
1836 int ok = keyNamesVector.size();
1837 _sceneManager->selectObjects( keyNamesVector );
1838 std::string name = keyNamesVector[0];
1841 _sceneManager->drawSelectionROI( );
1842 std::vector<std::string> currentSelection = _sceneManager->getSelectedObjects();
1843 int ok = currentSelection.size();
1844 _sceneManager->selectObjects( currentSelection );*/
1846 //------------------------------------------------------------------------------------------------------------
1847 void wxContourEventHandler :: onEditOutlines( std::vector<std::string> & keyNamesVector )
1851 //------------------------------------------------------------------------------------------------------------
1852 void wxContourEventHandler :: onREDO()
1856 //------------------------------------------------------------------------------------------------------------
1857 void wxContourEventHandler :: onUNDO()
1861 //------------------------------------------------------------------------------------------------------------
1862 void wxContourEventHandler :: deleteContour( std::string theKeyName )
1864 manualContourModel * cModel;
1865 manualViewBaseContour * cViewer;
1866 manualContourBaseControler * cControler;
1868 ContourWrap_ViewControl *conwrapviewControl = _sceneManager->getContourWrap_ViewControlOf( theKeyName );
1869 cControler = conwrapviewControl->getControler();
1870 int ispartofstaticlst= _modelManager->IsPartOfStaticList(theKeyName);
1871 if ((cControler!=NULL) && (cControler->IsEditable()==false) && (ispartofstaticlst==-1) )
1873 _sceneManager->removeFromScene( theKeyName );
1874 cModel = _modelManager->getOutlineByKeyName(theKeyName)->getModel();
1875 _modelManager->removeOutline( theKeyName );
1876 cViewer = conwrapviewControl->getViewer();
1877 _sceneManager->removeWrap( theKeyName );
1879 //FILE *ff = fopen("c:/temp/wxVtkBaseView_SceneManagerStadistics.txt","a+");
1880 //fprintf(ff,"EED wxContourEventHandler::deleteContours() \n" );
1881 //fprintf(ff," %s %p\n",keyNamesVector[i].c_str(), cControler );
1889 //------------------------------------------------------------------------------------------------------------
1890 void wxContourEventHandler :: deleteContours( std::vector<std::string> & keyNamesVector )
1892 int i,size=keyNamesVector.size();
1893 for (i=0;i<size;i++)
1895 deleteContour( keyNamesVector[i] );
1899 //------------------------------------------------------------------------------------------------------------
1900 void wxContourEventHandler :: deleteAllContours( )
1903 std::vector<int> tempVector;
1904 _instantPanel->getInstant( tempVector );
1905 int minZ = _mbarrangeDeleteAll->GetStart();
1906 int maxZ = _mbarrangeDeleteAll->GetEnd();
1908 int ii,sizeLstContourThings;
1910 if ( (minZ==0) && (maxZ==_mbarrangeDeleteAll->GetMax() ))
1912 _sceneManager->removeSceneContours( );
1913 _modelManager->removeAllOutlines();
1914 _sceneManager->removeAllOutlines();
1917 for ( z=minZ ; z<=maxZ ; z++)
1920 Instant instant(&tempVector);
1921 std::vector<ContourThing**> lstContourThings = this->_modelManager->getOutlinesAtInstant( &instant );
1923 sizeLstContourThings = lstContourThings.size();
1924 for (ii=0 ; ii<sizeLstContourThings ; ii++)
1926 ContourThing **contourthing = lstContourThings[ii];
1927 deleteContour( (*contourthing)->getName() );
1933 //------------------------------------------------------------------------------------------------------------
1934 void wxContourEventHandler::openContours( FILE *pFile, bool staticContour )
1937 fscanf(pFile,"%s",tmp); // NumberOfContours
1938 fscanf(pFile,"%s",tmp); // ##
1939 int numberOfContours = atoi(tmp);
1941 std::vector<int> instantVector;
1942 int typeContourModel;
1943 manualContourModel *manModelContour;
1947 for (i=0;i<numberOfContours;i++)
1949 instantVector.clear();
1950 fscanf(pFile,"%s",tmp); // Instant
1952 fscanf(pFile,"%s",tmp); // 1
1953 instantVector.push_back( atoi(tmp) );
1954 fscanf(pFile,"%s",tmp); // 2
1955 instantVector.push_back( atoi(tmp) );
1956 fscanf(pFile,"%s",tmp); // 3
1957 instantVector.push_back( atoi(tmp) );
1958 fscanf(pFile,"%s",tmp); // 4
1959 instantVector.push_back( atoi(tmp) );
1960 fscanf(pFile,"%s",tmp); // 5
1961 instantVector.push_back( atoi(tmp) );
1962 fscanf(pFile,"%s",tmp); // 6
1963 instantVector.push_back( atoi(tmp) );
1966 fscanf(pFile,"%s",tmp); // TypeContourModel
1967 fscanf(pFile,"%s",tmp); // ##
1968 typeContourModel = atoi(tmp);
1970 manModelContour = factoryManualContourModel(typeContourModel);
1971 manModelContour->Open(pFile);
1973 fscanf(pFile,"%s",tmp); // TypeView
1974 fscanf(pFile,"%s",tmp); // ##
1975 typeView = atoi(tmp);
1983 std::string theName;
1984 theName = _modelManager->createOutline( manModelContour, instantVector );
1985 bool addedModel = theName.compare("") != 0;
1988 double spc[3];//Si no hay imagen pero hay contornos que spacing se pone por default
1989 this->_theViewPanel->getSpacing(spc);
1990 //Adding the manualContourControler to interface objects structure
1991 //Adding the manualViewContour to interface objects structure
1992 //_sceneManager->setControlActiveStateOfALL( false );//This call is being done here because if the ROI is created underneath the previously created ROIS will still be active.
1993 _sceneManager->configureViewControlTo( theName, manModelContour,spc , typeView) ;
1996 if (staticContour==true)
1998 Instant instant(&instantVector);
1999 changeContourOfManager( theName , &instant );
2002 }// for numberOfContours
2008 //------------------------------------------------------------------------------------------------------------
2009 void wxContourEventHandler::openFileWithContours()
2012 wxFileDialog dialog(NULL, _T("Choose a file"), _T(""), _T(""), _T("*.roi"), wxOPEN );
2013 if (dialog.ShowModal() == wxID_OK)
2015 fileNameContourROI = (const char *)(dialog.GetPath().mb_str());
2016 FILE *pFile=fopen(fileNameContourROI.c_str(),"r+");
2018 fscanf(pFile,"%s",tmp); // --CreaContour--
2020 fscanf(pFile,"%s",tmp); // Version
2021 fscanf(pFile,"%s",tmp); // 1.0.1
2022 std::string version(tmp);
2024 openContours(pFile,false);
2025 if (version!="1.0.0"){
2026 openContours(pFile,true);
2028 // _sceneManager->openFileWithContours(ff);
2032 _sceneManager->removeSceneContours();
2034 //updateInstantOutlines();
2038 //------------------------------------------------------------------------------------------------------------
2039 void wxContourEventHandler::saveFileWithContours( std::string filename )
2041 FILE *pFile=fopen(filename.c_str(),"w+");
2042 std::vector< std::string > lstNameThings;
2043 int i,sizeLstNameThings;
2045 fprintf(pFile,"--CreaContour--\n");
2046 fprintf(pFile,"Version %s\n", "1.0.1" );
2049 lstNameThings = _modelManager->GetLstNameThings();
2050 sizeLstNameThings = lstNameThings.size();
2051 fprintf(pFile,"NumberOfContours %d\n", sizeLstNameThings );
2052 for (i=0 ; i<sizeLstNameThings ; i++)
2054 _modelManager->SaveThingName( pFile, lstNameThings[i] );
2055 _sceneManager->SaveThingName( pFile, lstNameThings[i] );
2058 //-- Contours Statics
2059 lstNameThings = _modelManager->GetLstNameThingsStatic();
2060 sizeLstNameThings = lstNameThings.size();
2061 fprintf(pFile,"NumberOfContoursStatic %d\n", sizeLstNameThings );
2062 for (i=0 ; i<sizeLstNameThings ; i++)
2064 _modelManager->SaveThingName( pFile, lstNameThings[i] );
2065 _sceneManager->SaveThingName( pFile, lstNameThings[i] );
2071 //----------------------------------------------------------
2073 void wxContourEventHandler::saveFileWithContours()
2075 wxFileDialog dialog(NULL, _T("Choose a file"), _T(""), _T(""), _T("*.roi"), wxSAVE );
2076 if (dialog.ShowModal() == wxID_OK)
2078 fileNameContourROI = (const char *)(dialog.GetPath().mb_str());
2079 saveFileWithContours( fileNameContourROI );
2083 //------------------------------------------------------------------------------------------------------------
2084 void wxContourEventHandler :: saveFileWithContoursAutomatique()
2086 if (fileNameContourROI=="")
2088 saveFileWithContours();
2090 saveFileWithContours(fileNameContourROI);
2095 //------------------------------------------------------------------------------------------------------------
2096 void wxContourEventHandler :: createCopyContourOf ( std::string anExistingKName, std::vector<int> &instantNoTouchData, bool append )
2098 std::string cloneName = _modelManager->createCopyContourOf( anExistingKName, instantNoTouchData );
2099 manualContourModel * manualModel = _modelManager->getOutlineByKeyName( cloneName )->getModel();
2100 _sceneManager->createCopyContourOf( anExistingKName, cloneName, manualModel , append );
2104 //------------------------------------------------------------------------------------------------------------
2105 manualContourModel * wxContourEventHandler::factoryManualContourModel(int typeContour)
2107 manualContourModel *manModelContour=NULL;
2112 manModelContour = new manualContourModel();
2118 manModelContour = new manualContourModel();
2124 manModelContour = new manualContourModelRoi();
2130 manModelContour = new manualContourModelCircle();
2136 manualContourModelBullEye *manModelContourBullEye = new manualContourModelBullEye();
2137 manModelContour = manModelContourBullEye;
2138 if (_panelBullEyeOptions!=NULL){
2139 int iCrown,sizeCrowns,iSector,sizeSectors;
2140 double radioA,radioB,ang,angDelta ;
2141 sizeCrowns = _panelBullEyeOptions->GetNumberOfCrowns();
2142 for ( iCrown=0 ; iCrown<sizeCrowns ; iCrown++ )
2144 sizeSectors = _panelBullEyeOptions->GetNumberOfSections(iCrown);
2145 radioB = _panelBullEyeOptions->GetRadioOfCrown(iCrown);
2146 if (iCrown==sizeCrowns-1)
2150 radioA = _panelBullEyeOptions->GetRadioOfCrown(iCrown+1);
2152 radioA=radioA/100.0;
2153 radioB=radioB/100.0;
2154 for ( iSector=0 ; iSector<sizeSectors ; iSector++ )
2156 ang = _panelBullEyeOptions->GetAngOfCrownSection(iCrown,iSector);
2157 angDelta= _panelBullEyeOptions->GetAngDeltaOfCrownSection(iCrown);
2158 manModelContourBullEye->AddSector(radioA,radioB,ang,angDelta);
2161 } // if _panelBullEyeOptions
2162 }// if typeContour==4
2164 return manModelContour;
2167 //------------------------------------------------------------------------------------------------------------
2168 void wxContourEventHandler :: createContour( int typeContour )
2170 //Creating the manualContourModel and including in the model
2171 manualContourModel * manModelContour = factoryManualContourModel(typeContour);
2172 std::vector<int> instantVector;
2173 _instantPanel->getInstant( instantVector );
2174 std::string theName;
2175 theName= _modelManager->createOutline( manModelContour, instantVector );
2176 bool addedModel = theName.compare("") != 0;
2179 double spc[3];//Si no hay imagen pero hay contornos que spacing se pone por default
2180 this->_theViewPanel->getSpacing(spc);
2181 //Adding the manualContourControler to interface objects structure
2182 //Adding the manualViewContour to interface objects structure
2183 //_sceneManager->setControlActiveStateOfALL( false );//This call is being done here because if the ROI is created underneath the previously created ROIS will still be active.
2184 _sceneManager->configureViewControlTo( theName, manModelContour,spc , typeContour) ;
2188 //FILE *ff = fopen("c:/temp/wxVtkBaseView_SceneManagerStadistics.txt","a+");
2189 //fprintf(ff,"EED wxContourEventHandler::createContour() \n" );
2190 //fprintf(ff," %s\n %p ",theName.c_str() , );
2196 //------------------------------------------------------------------------------------------------------------
2197 // Attributes getters and setters
2198 //------------------------------------------------------------------------------------------------------------
2200 void wxContourEventHandler :: setModelManager( OutlineModelManager * theModelManager )
2202 _modelManager = theModelManager;
2203 _workSpace = _modelManager->getContourWorkspace();
2205 //------------------------------------------------------------------------------------------------------------
2206 void wxContourEventHandler :: setViewPanel( wxContourViewPanel * theViewPanel )
2208 _theViewPanel = theViewPanel;
2209 _theViewPanel->setWxEventHandler( this );
2212 this->_theViewPanel->getSpacing(spc);
2213 _sceneManager = new wxVtkBaseView_SceneManager ( this->_theViewPanel->getWxVtkBaseView(), this, spc );
2215 Connect( _theViewPanel->GetId(), wxINSTANT_CHANGE, (wxObjectEventFunction) (wxCommandEventFunction) &wxContourEventHandler::onChangeInstant );
2216 Connect( wxID_ANY, wxEVT_START_CREATE_MULT_ROI, (wxObjectEventFunction) (wxCommandEventFunction) &wxContourEventHandler::onCreateMultipleROI );
2217 Connect( wxID_ANY, wxEVT_START_CREATE_ROI, (wxObjectEventFunction) (wxCommandEventFunction) &wxContourEventHandler::onCreateROI );
2218 Connect( wxID_ANY, wxEVT_STOP_CREATE_ROI, (wxObjectEventFunction) (wxCommandEventFunction) &wxContourEventHandler::onStopCreateROI );
2219 Connect( wxID_ANY, wxEVT_CHANGED_DEEP, (wxObjectEventFunction) (wxCommandEventFunction) &wxContourEventHandler::onChangedDeep );
2220 Connect( wxID_ANY, wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &wxContourEventHandler :: onActionButtonPressed );
2225 //------------------------------------------------------------------------------------------------------------
2226 void wxContourEventHandler :: setInstantChooserPanel( wxInstantChooserPanel * theInstantChooserPanel )
2228 _instantPanel = theInstantChooserPanel;
2229 _instantPanel->setWxEventHandler( this );
2231 Connect( _instantPanel->GetId(), wxINSTANT_CHOOSER_CHANGE, (wxObjectEventFunction) (wxCommandEventFunction) &wxContourEventHandler::onChangeInstant );
2233 std::vector<int> vect;
2234 _instantPanel->getInstant( vect );
2235 _actualInstant = new Instant( &vect );
2237 if( _modelManager!=NULL )
2239 std::vector<std::string> conceptNameVect;
2240 std::vector<int> conceptSizeVect;
2241 _modelManager-> getConceptsInformation(conceptNameVect, conceptSizeVect);
2243 int max = conceptNameVect.size();
2246 if( conceptNameVect[i].compare("Axe Depth") == 0 )
2248 _instantPanel->addConcept( conceptNameVect[i], 0, conceptSizeVect[i], 1);
2250 _instantPanel->addConcept( conceptNameVect[i], 1, conceptSizeVect[i], 1);
2254 //Should be configured later, or abort program, because Model -NEEDS- to be added before chooserPanel
2256 if( _theViewPanel!=NULL )
2258 double val = _theViewPanel->getCurrentDeep();
2259 _instantPanel->setConceptValue( "Axe Depth", (int)val );
2260 ConceptDataWrap * data = _instantPanel->getConceptDataOf( "Axe Depth" );
2262 _theViewPanel->setVerticalConcept( "Axe Depth", data->getMinValue(), data->getMaxValue(), data->getMinShowedValue(), data->getMaxShowedValue(), data->getActualValue() );
2264 //Should be configured later, or abort program, because ViewPanel -NEEDS- to be added before chooserPanel
2269 //------------------------------------------------------------------------------------------------------------
2270 void wxContourEventHandler :: setButtonsBar( wxContour_ButtonsBar * theButtonsBar )
2272 _buttonsBar = theButtonsBar;
2273 _buttonsBar->setWxEventHandler( this );
2274 Connect( _buttonsBar->GetId(), wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &wxContourEventHandler:: onActionButtonPressed );
2276 //------------------------------------------------------------------------------------------------------------
2277 void wxContourEventHandler :: setGrid( wxContour_Grid * theGridPanel )
2279 _gridPanel = theGridPanel;
2281 //------------------------------------------------------------------------------------------------------------
2282 void wxContourEventHandler :: setDrawToolsPanel( wxContour_DrawToolsPanel * theDrawToolsPanel )
2284 _drawToolsPanel = theDrawToolsPanel;
2286 //------------------------------------------------------------------------------------------------------------
2287 void wxContourEventHandler :: setOperationsToolsPanel( wxContour_OperationsToolsPanel * theOperationsToolsPanel )
2289 _operationsToolsPanel = theOperationsToolsPanel;
2291 //------------------------------------------------------------------------------------------------------------
2292 void wxContourEventHandler :: setAutomaticFormsPanel( wxContour_AutomaticFormsToolsPanel * theAutoFormsPanel )
2294 _autoFormsPanel = theAutoFormsPanel;
2297 void wxContourEventHandler :: setStandardToolsPanel( wxContour_StandardToolsPanel * theStandardToolsPanel )
2299 _standardToolsPanel= theStandardToolsPanel;
2301 //------------------------------------------------------------------------------------------------------------
2302 void wxContourEventHandler :: setEditionToolsPanel( wxContour_EdtionToolsPanel * theEditionToolsPanel )
2304 _editionToolsPanel = theEditionToolsPanel;
2307 //------------------------------------------------------------------------------------------------------------
2308 void wxContourEventHandler :: setListViewPanel( wxContour_ListViewPanel * theListViewPanel )
2310 _listViewPanel = theListViewPanel;
2312 //------------------------------------------------------------------------------------------------------------
2313 // Other functional methods
2314 //------------------------------------------------------------------------------------------------------------
2317 //------------------------------------------------------------------------------------------------------------
2318 void wxContourEventHandler::onDeleteContour( wxCommandEvent& event )
2320 int i,size=_sceneManager->getSelectedObjects().size();
2323 std::string keyName = _sceneManager->getSelectedObjects()[i];
2324 int ispartofstaticlist = this->_modelManager->IsPartOfStaticList( keyName );
2325 if ( ispartofstaticlist>=0 )
2327 std::vector<int> tempVector;
2328 _instantPanel->getInstant( tempVector );
2329 Instant instant(&tempVector);
2330 this->_modelManager->ChangeContourOfList(keyName, &instant);
2334 std::vector<std::string> lstKeyName;
2335 std::vector<std::string> lstKeyNameActualSlice;
2336 std::vector<std::string> lstKeyNameToBeErase;
2338 lstKeyNameToBeErase = _sceneManager->getSelectedObjects();
2339 lstKeyNameActualSlice = _sceneManager->GetlstContoursNameActualSlice();
2340 int k,kSize=lstKeyNameToBeErase.size();
2341 int j,jSize=lstKeyNameActualSlice.size();
2343 for (k=0;k<kSize; k++)
2346 for (j=0;j<jSize; j++)
2348 if (lstKeyNameToBeErase[k]==lstKeyNameActualSlice[j])
2355 lstKeyName.push_back( lstKeyNameToBeErase[k] );
2359 deleteContours( lstKeyName );
2362 //------------------------------------------------------------------------------------------------------------
2363 void wxContourEventHandler::onDeleteContoursActSlice( wxCommandEvent& event )
2365 deleteContours( _sceneManager->GetlstContoursNameActualSlice() );
2368 //------------------------------------------------------------------------------------------------------------
2369 void wxContourEventHandler::onDeleteAllContours( wxCommandEvent& event )
2371 deleteAllContours( );
2374 //------------------------------------------------------------------------------------------------------------
2375 void wxContourEventHandler :: onDeleteFrame( )
2377 if (_deleteFrame==NULL)
2379 _deleteFrame = new wxFrame (_theViewPanel, -1,_T(" Delete Contour "), wxDefaultPosition, wxDefaultSize, wxFRAME_TOOL_WINDOW|wxSYSTEM_MENU | wxCAPTION | wxCLIP_CHILDREN |wxFRAME_FLOAT_ON_PARENT );
2381 wxSize sizepanel(width,230);
2382 _deleteFrame->SetSize( sizepanel );
2383 wxPanel *panel = new wxPanel(_deleteFrame,-1);
2384 wxButton *deleteContourBtn = new wxButton(panel,-1,_T("Delete contour selected"),wxDefaultPosition, wxSize(width-10,35) );
2385 wxButton *deleteContoursActSliceBtn = new wxButton(panel,-1,_T("Delete contours of actual slice"),wxDefaultPosition, wxSize(width-10,35));
2386 wxButton *deleteAllContoursBtn = new wxButton(panel,-1,_T("Delete all contours"),wxDefaultPosition, wxSize(width-10,35));
2388 int sizeZ = _sceneManager->GetImageDataSizeZ();
2389 _mbarrangeDeleteAll = new mBarRange(panel,70, 65);
2390 _mbarrangeDeleteAll->SetMin(0);
2391 _mbarrangeDeleteAll->SetStart(0);
2393 _mbarrangeDeleteAll-> SetOrientation( true );
2394 _mbarrangeDeleteAll-> setActiveStateTo(true);
2395 _mbarrangeDeleteAll-> setVisibleLabels( true );
2396 _mbarrangeDeleteAll-> setDeviceEndMargin(10);
2397 _mbarrangeDeleteAll-> setRepresentedValues( 0 , sizeZ );
2398 _mbarrangeDeleteAll-> setDeviceBlitStart(10,10);
2399 _mbarrangeDeleteAll-> setIfWithActualDrawed( false );
2400 _mbarrangeDeleteAll-> SetStart( 0 );
2401 _mbarrangeDeleteAll-> SetEnd( sizeZ );
2404 _deleteFrame->SetEventHandler( this );
2405 Connect( deleteContourBtn->GetId() , wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &wxContourEventHandler::onDeleteContour );
2406 Connect( deleteContoursActSliceBtn->GetId() , wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &wxContourEventHandler::onDeleteContoursActSlice );
2407 Connect( deleteAllContoursBtn->GetId() , wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &wxContourEventHandler::onDeleteAllContours );
2409 wxFlexGridSizer * sizer = new wxFlexGridSizer(1);
2410 sizer -> Add( deleteContourBtn , 1, wxGROW );
2411 sizer -> Add( deleteContoursActSliceBtn , 1, wxGROW );
2412 sizer -> Add( deleteAllContoursBtn , 1, wxGROW );
2413 sizer -> Add( _mbarrangeDeleteAll , 1, wxGROW );
2415 panel->SetSizer( sizer );
2416 panel->SetSize( sizepanel );
2417 panel->SetAutoLayout( true );
2419 _deleteFrame->Show(true);
2421 if (_deleteFrame->IsShown()==true)
2423 _deleteFrame->Show(false);
2425 _deleteFrame->Show(true);
2431 //------------------------------------------------------------------------------------------------------------
2432 void wxContourEventHandler::onCreateContourSpline( wxCommandEvent& event )
2437 //------------------------------------------------------------------------------------------------------------
2438 void wxContourEventHandler::onCreateContourRectangle( wxCommandEvent& event )
2443 //------------------------------------------------------------------------------------------------------------
2444 void wxContourEventHandler::onCreateContourCircle( wxCommandEvent& event )
2448 //------------------------------------------------------------------------------------------------------------
2449 void wxContourEventHandler::onCreateContourBullEye( wxCommandEvent& event )
2456 //------------------------------------------------------------------------------------------------------------
2457 void wxContourEventHandler :: onCreateContourFrame( )
2459 if (_createContourFrame==NULL)
2461 _createContourFrame = new wxFrame (_theViewPanel, -1,_T(" New Contour "), wxDefaultPosition, wxDefaultSize, wxFRAME_TOOL_WINDOW|wxSYSTEM_MENU | wxCAPTION | wxCLIP_CHILDREN |wxFRAME_FLOAT_ON_PARENT | wxRESIZE_BORDER );
2462 wxSize sizepanel(490,600);
2463 _createContourFrame->SetSize( sizepanel );
2464 wxPanel *panel = new wxPanel(_createContourFrame,-1);
2465 wxButton *newContourSplineBtn = new wxButton(panel,-1,_T("Interpolation B-spline (close)"),wxDefaultPosition, wxSize(180,35) );
2466 newContourSplineBtn->SetToolTip(_T("CTRL-N"));
2467 wxButton *newContourRectangleBtn = new wxButton(panel,-1,_T("Rectangle"),wxDefaultPosition, wxSize(180,35));
2468 wxButton *newContourCircleBtn = new wxButton(panel,-1,_T("Circle"),wxDefaultPosition, wxSize(180,35));
2469 wxButton *newContourStarBtn = new wxButton(panel,-1,_T("Bull eye"),wxDefaultPosition, wxSize(180,35));
2471 _panelBullEyeOptions = new PanelBullEyeOptions(panel, wxSize(100,200));
2473 _createContourFrame->SetEventHandler( this );
2474 Connect( newContourSplineBtn->GetId() , wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &wxContourEventHandler::onCreateContourSpline );
2475 Connect( newContourRectangleBtn->GetId() , wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &wxContourEventHandler::onCreateContourRectangle );
2476 Connect( newContourCircleBtn->GetId() , wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &wxContourEventHandler::onCreateContourCircle );
2477 Connect( newContourStarBtn->GetId() , wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &wxContourEventHandler::onCreateContourBullEye );
2479 wxFlexGridSizer * sizer = new wxFlexGridSizer(1);
2480 sizer -> Add( newContourSplineBtn , 1, wxGROW );
2481 sizer -> Add( newContourRectangleBtn , 1, wxGROW );
2482 sizer -> Add( newContourCircleBtn , 1, wxGROW );
2483 sizer -> Add( newContourStarBtn , 1, wxGROW );
2484 sizer -> Add( _panelBullEyeOptions , 1, wxGROW );
2486 panel->SetSizer( sizer );
2487 panel->SetSize( sizepanel );
2488 panel->SetAutoLayout( true );
2490 _createContourFrame->Show(true);
2492 if (_createContourFrame->IsShown()==true)
2494 _createContourFrame->Show(false);
2496 _createContourFrame->Show(true);
2502 //------------------------------------------------------------------------
2503 void wxContourEventHandler::RefreshInterface()
2506 wxVtk2DBaseView *wxvtk2dbaseview = (wxVtk2DBaseView*)this->_theViewPanel->getWxVtkBaseView();
2507 wxvtk2dbaseview->Refresh();
2510 //------------------------------------------------------------------------
2511 void wxContourEventHandler::onWidthOfContour(wxScrollEvent& event){
2512 _sceneManager->removeSceneContours();
2513 double width = (double)_withOfContourLine->GetValue() / 2.0;
2514 _sceneManager->SetWidthContour( width );
2519 //------------------------------------------------------------------------
2521 void wxContourEventHandler::onBrigthnessColorWindowLevel(wxScrollEvent& event){
2522 int colorwindow = _brithtnessColorLevel->GetValue();
2523 int windowlevel = _brithtnessWindowLevel->GetValue();
2524 wxVtk2DBaseView *wxvtk2dbaseview = (wxVtk2DBaseView*)this->_theViewPanel->getWxVtkBaseView();
2525 vtkImageViewer2 *imageviewer = wxvtk2dbaseview->_imageViewer2XYZ->GetVtkImageViewer2();
2526 imageviewer->SetColorWindow(colorwindow);
2527 imageviewer->SetColorLevel(windowlevel);
2528 // wxvtk2dbaseview->Refresh();
2532 void wxContourEventHandler::OnInterpolation(wxCommandEvent& event)
2534 wxVtk2DBaseView *wxvtk2dbaseview = (wxVtk2DBaseView*)this->_theViewPanel->getWxVtkBaseView();
2535 vtkImageViewer2 *imageviewer = wxvtk2dbaseview->_imageViewer2XYZ->GetVtkImageViewer2();
2536 if (_interpolationCheckBox->GetValue()==true)
2538 imageviewer->GetImageActor()->InterpolateOn();
2540 imageviewer->GetImageActor()->InterpolateOff();
2546 //------------------------------------------------------------------------------------------------------------
2547 void wxContourEventHandler :: onInterfaceConfigurationFrame( )
2549 if (_interfaceConfigurationFrame==NULL)
2551 _interfaceConfigurationFrame = new wxFrame (_theViewPanel, -1,_T(" Interface Configuration "), wxDefaultPosition, wxDefaultSize, wxFRAME_TOOL_WINDOW|wxSYSTEM_MENU | wxCAPTION | wxCLIP_CHILDREN |wxFRAME_FLOAT_ON_PARENT );
2552 wxSize sizepanel(190,400);
2553 _interfaceConfigurationFrame->SetSize( sizepanel );
2554 wxPanel *panel = new wxPanel(_interfaceConfigurationFrame,-1);
2555 _withOfContourLine = new wxSlider(panel, -1, 1 , 1, 10, wxDefaultPosition, wxSize(180,40), wxSL_HORIZONTAL|wxSL_LABELS, wxDefaultValidator);
2558 this->_sceneManager->GetImageDataRange(range);
2560 wxVtk2DBaseView *wxvtk2dbaseview = (wxVtk2DBaseView*)this->_theViewPanel->getWxVtkBaseView();
2561 vtkImageViewer2 *imageviewer = wxvtk2dbaseview->_imageViewer2XYZ->GetVtkImageViewer2();
2562 int colorwindow = (int)imageviewer->GetWindowLevel()->GetLevel();
2563 int windowlevel = (int)imageviewer->GetWindowLevel()->GetWindow();
2565 _brithtnessWindowLevel = new wxSlider(panel, -1, windowlevel , 1, range[1], wxDefaultPosition, wxSize(180,40), wxSL_HORIZONTAL|wxSL_LABELS, wxDefaultValidator);
2566 _brithtnessColorLevel = new wxSlider(panel, -1, colorwindow , 1, range[1], wxDefaultPosition, wxSize(180,40), wxSL_HORIZONTAL|wxSL_LABELS, wxDefaultValidator);
2568 _interpolationCheckBox = new wxCheckBox(panel, -1, _T("Image interpolation") );
2569 _interpolationCheckBox->SetValue(true);
2571 _interfaceConfigurationFrame->SetEventHandler( this );
2573 Connect( _withOfContourLine->GetId() , wxEVT_SCROLL_CHANGED , (wxObjectEventFunction) &wxContourEventHandler::onWidthOfContour );
2574 Connect( _withOfContourLine->GetId() , wxEVT_SCROLL_THUMBTRACK , (wxObjectEventFunction) &wxContourEventHandler::onWidthOfContour );
2576 Connect( _brithtnessWindowLevel->GetId() , wxEVT_SCROLL_CHANGED , (wxObjectEventFunction) &wxContourEventHandler::onBrigthnessColorWindowLevel );
2577 Connect( _brithtnessWindowLevel->GetId() , wxEVT_SCROLL_THUMBTRACK , (wxObjectEventFunction) &wxContourEventHandler::onBrigthnessColorWindowLevel );
2578 Connect( _brithtnessColorLevel->GetId() , wxEVT_SCROLL_CHANGED , (wxObjectEventFunction) &wxContourEventHandler::onBrigthnessColorWindowLevel );
2579 Connect( _brithtnessColorLevel->GetId() , wxEVT_SCROLL_THUMBTRACK , (wxObjectEventFunction) &wxContourEventHandler::onBrigthnessColorWindowLevel );
2580 Connect( _interpolationCheckBox->GetId() , wxEVT_COMMAND_CHECKBOX_CLICKED , (wxObjectEventFunction) &wxContourEventHandler::OnInterpolation );
2582 wxFlexGridSizer * sizer = new wxFlexGridSizer(1);
2583 sizer -> Add( new wxStaticText(panel,-1,_T("Contour width")) , 1, wxGROW );
2584 sizer -> Add( _withOfContourLine , 1, wxGROW );
2585 sizer -> Add( new wxStaticText(panel,-1,_T(" ")) , 1, wxGROW );
2586 sizer -> Add( new wxStaticText(panel,-1,_T(" ")) , 1, wxGROW );
2587 sizer -> Add( new wxStaticText(panel,-1,_T("Brightness of the image")) , 1, wxGROW );
2588 sizer -> Add( new wxStaticText(panel,-1,_T("--Window level--")) , 1, wxGROW );
2589 sizer -> Add( _brithtnessWindowLevel , 1, wxGROW );
2590 sizer -> Add( new wxStaticText(panel,-1,_T("--Color level--")) , 1, wxGROW );
2591 sizer -> Add( _brithtnessColorLevel, 1, wxGROW );
2592 sizer -> Add( new wxStaticText(panel,-1,_T(" ")) , 1, wxGROW );
2593 sizer -> Add( new wxStaticText(panel,-1,_T(" ")) , 1, wxGROW );
2594 sizer -> Add( _interpolationCheckBox , 1, wxGROW );
2596 panel->SetSizer( sizer );
2597 panel->SetSize( sizepanel );
2598 panel->SetAutoLayout( true );
2600 _interfaceConfigurationFrame->Show(true);
2602 if (_interfaceConfigurationFrame->IsShown()==true)
2604 _interfaceConfigurationFrame->Show(false);
2606 _interfaceConfigurationFrame->Show(true);
2614 //------------------------------------------------------------------
2615 void wxContourEventHandler :: changeContourOfManager(std::string keyName, Instant *instant)
2617 this->_modelManager->ChangeContourOfList(keyName, instant);
2620 //------------------------------------------------------------------
2621 void wxContourEventHandler :: changeContoursOfManager( std::vector<std::string> & keyNamesVector )
2624 std::vector<int> tempVector;
2625 _instantPanel->getInstant( tempVector );
2626 Instant instant(&tempVector);
2628 int i , size=keyNamesVector.size();
2629 for ( i=0 ; i<size ; i++ )
2631 changeContourOfManager(keyNamesVector[i], &instant);
2636 //------------------------------------------------------------------
2637 void wxContourEventHandler :: executeActionCommand( const char toolCommand )
2639 std::vector<std::string> currentSelection = _sceneManager->getSelectedObjects();
2640 int elementsSelected = currentSelection.size();
2641 if( toolCommand == (wxContour_ActionCommandsID::CREATE_TOOL) )
2643 onCreateContourFrame();
2645 if( toolCommand == (wxContour_ActionCommandsID::CREATE_CONTOUR_KEY) )
2649 else if( toolCommand == wxContour_ActionCommandsID::DELETE_TOOL )
2653 else if( toolCommand == wxContour_ActionCommandsID::DELETE_KEY )
2655 deleteContours( currentSelection );
2657 else if( toolCommand == wxContour_ActionCommandsID::SAVE_TOOL )
2659 saveFileWithContours( );
2661 else if( toolCommand == wxContour_ActionCommandsID::SAVE_KEY )
2663 saveFileWithContoursAutomatique( );
2665 else if( toolCommand == wxContour_ActionCommandsID::OPEN_TOOL )
2667 openFileWithContours( );
2669 else if( toolCommand == wxContour_ActionCommandsID::CHANGE_TOOL )
2671 if ( elementsSelected >= 1 )
2673 changeContoursOfManager( currentSelection );
2677 else if( toolCommand == wxContour_ActionCommandsID::HIDE_TOOL )
2679 if ( elementsSelected >= 1 )
2681 onHideOutlines( currentSelection );
2684 else if( toolCommand == wxContour_ActionCommandsID::SHOW_TOOL )
2686 if ( elementsSelected >= 1 )
2688 onShowOutlines( currentSelection );
2691 else if( toolCommand == wxContour_ActionCommandsID::COPY_TOOL )
2693 if ( elementsSelected >= 1 )
2695 onCopyOutlines( currentSelection );
2698 else if( toolCommand == wxContour_ActionCommandsID::PASTE_TOOL )
2702 else if( toolCommand == wxContour_ActionCommandsID::SPREAD_TOOL )
2706 else if( toolCommand == wxContour_ActionCommandsID::AUTOMATIQUESEGMENTATION_TOOL )
2708 onAutomatiqueSegmentation( );
2711 else if( toolCommand == wxContour_ActionCommandsID::SELECT_TOOL )
2713 onSelectOutlines( currentSelection );
2716 else if( toolCommand == wxContour_ActionCommandsID::EDIT_TOOL )
2718 if ( elementsSelected >= 1 )
2720 onEditOutlines( currentSelection );
2723 else if( toolCommand == wxContour_ActionCommandsID::UNDO_TOOL )
2727 else if( toolCommand == wxContour_ActionCommandsID::REDO_TOOL )
2731 else if( toolCommand == wxContour_ActionCommandsID::INFORMATIONCONTOUR_TOOL )
2733 onInformationContourFrame();
2735 else if( toolCommand == wxContour_ActionCommandsID::INTERFACECONFIGURATION_TOOL )
2737 onInterfaceConfigurationFrame();
2739 else if( toolCommand == wxContour_ActionCommandsID::TEST_TOOL )
2741 onInterfaceTestFrame();
2748 //------------------------------------------------------------------------------------------------------------
2749 // Getting information methods
2750 //------------------------------------------------------------------------------------------------------------
2754 //------------------------------------------------------------------------------------------------------------
2756 //------------------------------------------------------------------------------------------------------------
2758 void wxContourEventHandler :: updateInstantOutlines()
2760 std::vector<NameWrapper *> namesWrapping = _modelManager->getActualInstantOutlines();
2761 int size = namesWrapping.size();
2762 _sceneManager->removeSceneContours();
2763 for( int i=0; i<size; i++)
2765 _sceneManager->addToScene(namesWrapping[i]->getKeyName(), true, true, true, false, false );
2768 //------------------------------------------------------------------------------------------------------------
2769 void wxContourEventHandler :: updateInstantImageData()
2773 //------------------------------------------------------------------------------------------------------------
2775 void wxContourEventHandler :: updateInstantAxes()
2779 //------------------------------------------------------------------------------------------------------------
2780 void wxContourEventHandler :: changeInstant()
2782 std::vector<int> instantVect;
2783 _instantPanel->getInstant( instantVect );
2784 Instant * theInstant = new Instant ( &instantVect );
2785 //if( !theInstant->isEquals( _actualInstant ))
2787 //Setting the actual instant
2788 _actualInstant = theInstant;
2789 _modelManager->setInstant( _actualInstant );
2791 updateInstantOutlines();
2792 updateInstantImageData();
2793 updateInstantAxes();
2795 //Searching the elements at the specified instant
2798 std::map<std::string, ContourWrap_ViewControl *> :: iterator iter;
2799 iter = contours_ViewControl->find("Outline 0");
2800 (iter->second)->getViewer()->RemoveCompleteContourActor();*/