1 /*# ---------------------------------------------------------------------
3 # Copyright (c) CREATIS (Centre de Recherche en Acquisition et Traitement de l'Image
5 # Authors : Eduardo Davila, Frederic Cervenansky, Claire Mouton
6 # Previous Authors : Laurent Guigues, Jean-Pierre Roux
7 # CreaTools website : www.creatis.insa-lyon.fr/site/fr/creatools_accueil
9 # This software is governed by the CeCILL-B license under French law and
10 # abiding by the rules of distribution of free software. You can use,
11 # modify and/ or redistribute the software under the terms of the CeCILL-B
12 # license as circulated by CEA, CNRS and INRIA at the following URL
13 # http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
14 # or in the file LICENSE.txt.
16 # As a counterpart to the access to the source code and rights to copy,
17 # modify and redistribute granted by the license, users are provided only
18 # with a limited warranty and the software's author, the holder of the
19 # economic rights, and the successive licensors have only limited
22 # The fact that you are presently reading this means that you have had
23 # knowledge of the CeCILL-B license and that you accept its terms.
24 # ------------------------------------------------------------------------ */
28 /* Diagrama de Secuaencia de cambiar un instante
29 wxContourEventHandler :: changeInstant()
30 OutlineModelManager :: ->setInstant( _actualInstant );
31 OutlineModelManager :: updateToActualInstant()
32 OutlineModelManager :: getOutlinesAtInstant(Instant * anInstant, bool ifAnnotate)
33 OutlineModelManager :: annotateOutlinesWrap(std::vector<std::string> kNamesVector, std::vector<ContourThing **> theOutlinesVector)
34 wxContourEventHandler :: updateInstantOutlines()
35 OutlineModelManager :: getActualInstantOutlines ()
36 wxVtkBaseView_SceneManager :: addToScene( std::vector< std::string> theKeyNameVector, bool append, bool visualization, bool control, bool ifActive, bool ifShowCtrlPoints )
37 wxVtkBaseView_SceneManager :: addToScene( std::string theKeyName, bool append, bool visualization, bool control, bool ifActive, bool ifShowCtrlPoints )
38 wxVtkBaseView_SceneManager :: getContourWrap_ViewControlOf
40 void wxVtkBaseView_SceneManager :: addToScene( std::string theKeyName, ContourWrap_ViewControl * contourWRP, bool append, bool visualization, bool control, bool ifActive, bool ifShowCtrlPoints )
46 \mainpage NDimension with wxWidgets and maracas
48 \section intro Introduction
50 This is the introduction.
59 node [shape=record, fontname=Helvetica, fontsize=10];
61 _wxContourGUIExample [ label="wxContourGUIExample" URL="\ref wxContourGUIExample"];
62 _wxContourEventHandler [ label="wxContourEventHandler" URL="\ref wxContourEventHandler"];
64 _OutlineModelManager [ label="OutlineModelManager" URL="\ref OutlineModelManager"];
65 _wxInstantChooserPanel [ label="wxInstantChooserPanel" URL="\ref wxInstantChooserPanel"];
66 _wxContourViewPanel [ label="wxContourViewPanel" URL="\ref wxContourViewPanel"];
67 _wxContour_ButtonsBar [ label="wxContour_ButtonsBar" URL="\ref wxContour_ButtonsBar"];
68 _OutlineModelManager [ label="OutlineModelManager" URL="\ref OutlineModelManager"];
69 _wxVtkBaseView_SceneManager [ label="wxVtkBaseView_SceneManager" URL="\ref wxVtkBaseView_SceneManager"];
70 _SomeEnvironment [ label="SomeEnvironment" URL="\ref SomeEnvironment"];
73 _wxContourGUIExample -> _wxContourEventHandler [ arrowhead="open", style="dashed" ];
74 _wxContourGUIExample -> _OutlineModelManager [ arrowhead="open", style="dashed" ];
75 _wxContourGUIExample -> _wxInstantChooserPanel [ arrowhead="open", style="dashed" ];
76 _wxContourGUIExample -> _wxContourViewPanel [ arrowhead="open", style="dashed" ];
77 _wxContourGUIExample -> _wxContour_ButtonsBar [ arrowhead="open", style="dashed" ];
78 _wxContourViewPanel -> wxMaracas_N_ViewersWidget [ arrowhead="open", style="dashed" ];
79 _wxContourEventHandler -> _OutlineModelManager [ arrowhead="open", style="dashed" ];
80 _wxContourEventHandler -> _wxVtkBaseView_SceneManager [ arrowhead="open", style="dashed" ];
81 _OutlineModelManager -> _SomeEnvironment [ arrowhead="open", style="dashed" ];
93 //----------------------------------------------------------------------------------------------------------------
94 // Class definition include
95 //----------------------------------------------------------------------------------------------------------------
96 #include "wxContourEventHandler.h"
97 #include <wx/filedlg.h>
98 #include <wx/spinctrl.h>
102 //----------------------------------------------------------------------------------------------------------------
103 // Class implementation
104 //----------------------------------------------------------------------------------------------------------------
105 /** @file wxContourEventHandler.cxx */
108 //------------------------------------------------------------------------------------------------------------
110 //------------------------------------------------------------------------------------------------------------
112 #include "wxContour_ActionCommandsID.h"
113 #include "NameWrapper.h"
114 #include "ConceptDataWrap.h"
115 #include "OutlineGroup.h"
117 #include <manualContour.h>
118 #include "Contour/ContourExtractData.h"
119 #include "ImageSourceThing.h"
120 #include "PanelBullEyeOptions.h"
123 #include <vtkContourFilter.h>
124 #include <vtkCleanPolyData.h>
125 #include <vtkPolyDataConnectivityFilter.h>
126 #include <vtkStripper.h>
127 #include <vtkImageReslice.h>
128 #include <vtkMetaImageWriter.h>
129 #include <vtkImageMapToWindowLevelColors.h>
133 //------------------------------------------------------------------------------------------------------------
134 //------------------------------------------------------------------------------------------------------------
135 //------------------------------------------------------------------------------------------------------------
137 PanelBullEyeOptions::PanelBullEyeOptions (wxWindow * parent, wxSize size) :
138 wxPanel(parent, -1, wxDefaultPosition, size)
143 wxSize sizepanel(190,300);
144 wxPanel *panel = this;
147 wxString lstOptions[2];
148 lstOptions[0]= wxString("General options",wxConvUTF8);
149 lstOptions[1]= wxString("Detail options",wxConvUTF8);
150 _radioboxBullEyeGenOpt = new wxRadioBox(panel, -1, wxString("General/Detail options",wxConvUTF8), wxDefaultPosition, wxSize(200,45), 2 , lstOptions, 2, wxRA_SPECIFY_COLS);
151 _radioboxBullEyeGenOpt->SetSelection(0);
153 _spinctrlBullEyeNumOfCrowns = new wxSpinCtrl( panel , -1,_T("B"),wxDefaultPosition, wxSize(40,20) );
154 _spinctrlBullEyeNumOfCrowns->SetRange(1,_maxLevels);
155 _spinctrlBullEyeNumOfCrowns->SetValue(3);
157 _spinctrlBullEyeNumOfSec = new wxSpinCtrl( panel , -1,_T("A"),wxDefaultPosition, wxSize(40,20) );
158 _spinctrlBullEyeNumOfSec->SetRange(1,_maxSections);
159 _spinctrlBullEyeNumOfSec->SetValue(5);
162 _sliderBullEyeAngle = new wxSlider( panel , -1 ,0,0,180, wxDefaultPosition, wxSize(200,35), wxSL_HORIZONTAL|wxSL_LABELS, wxDefaultValidator);
164 wxFlexGridSizer * sizerGeneralOptions = new wxFlexGridSizer(10);
166 wxFlexGridSizer * sizerGeneralOptionsA = new wxFlexGridSizer(1);
167 wxFlexGridSizer * sizerGeneralOptionsB = new wxFlexGridSizer(1);
168 wxFlexGridSizer * sizerGeneralOptionsC = new wxFlexGridSizer(1);
169 sizerGeneralOptionsA -> Add( new wxStaticText(panel,-1,_T("Crowns")) , 1, wxGROW );
170 sizerGeneralOptionsA -> Add( _spinctrlBullEyeNumOfCrowns , 1/*, wxGROW );
171 sizerGeneralOptionsB -> Add( new wxStaticText(panel,-1,_T("Sections")) , 1, wxGROW );
172 sizerGeneralOptionsB -> Add( _spinctrlBullEyeNumOfSec , 1/*, wxGROW );
173 sizerGeneralOptionsC -> Add( new wxStaticText(panel,-1,_T(" Angle")) , 1, wxGROW );
174 sizerGeneralOptionsC -> Add( _sliderBullEyeAngle , 1/*, wxGROW );
176 sizerGeneralOptions -> Add( sizerGeneralOptionsA , 1/*, wxGROW );
177 sizerGeneralOptions -> Add( new wxStaticText(panel,-1,_T(" ")) , 1, wxGROW );
178 sizerGeneralOptions -> Add( sizerGeneralOptionsB , 1/*, wxGROW );
179 sizerGeneralOptions -> Add( new wxStaticText(panel,-1,_T(" ")) , 1, wxGROW );
180 sizerGeneralOptions -> Add( sizerGeneralOptionsC , 1/*, wxGROW );
183 wxSpinCtrl *tmpSpinSection;
184 wxSlider *tmpSliderRadio;
185 wxSlider *tmpSliderAng;
187 wxFlexGridSizer * sizerDetailOptions = new wxFlexGridSizer(6);
189 sizerDetailOptions -> Add( new wxStaticText(panel,-1,_T("Crown ")) , 1, wxGROW );
190 sizerDetailOptions -> Add( new wxStaticText(panel,-1,_T(" Sections ")) , 1, wxGROW );
191 sizerDetailOptions -> Add( new wxStaticText(panel,-1,_T(" ")) , 1, wxGROW );
192 sizerDetailOptions -> Add( new wxStaticText(panel,-1,_T(" Radio %")) , 1, wxGROW );
193 sizerDetailOptions -> Add( new wxStaticText(panel,-1,_T(" ")) , 1, wxGROW );
194 sizerDetailOptions -> Add( new wxStaticText(panel,-1,_T(" Angle")) , 1, wxGROW );
196 wxString tmpwxstring;
198 for (i=0;i<_maxLevels;i++){
199 tmpSpinSection = new wxSpinCtrl( panel , -1,_T(""),wxDefaultPosition, wxSize(40,20) );
200 tmpSliderRadio = new wxSlider( panel , -1 ,0,0,100, wxDefaultPosition, wxSize(110,35), wxSL_HORIZONTAL|wxSL_LABELS, wxDefaultValidator);
201 tmpSliderAng = new wxSlider( panel , -1 ,0,0,180, wxDefaultPosition, wxSize(200,35), wxSL_HORIZONTAL|wxSL_LABELS, wxDefaultValidator);
203 tmpSpinSection ->SetRange(1,_maxSections);
205 tmpwxstring.Printf(_T(" %d. "),i+1);
206 sizerDetailOptions -> Add( new wxStaticText(panel,-1,tmpwxstring) , 1, wxGROW );
207 sizerDetailOptions -> Add( tmpSpinSection, 1 );
208 sizerDetailOptions -> Add( new wxStaticText(panel,-1,_T(" ")) , 1, wxGROW );
209 sizerDetailOptions -> Add( tmpSliderRadio, 1, wxGROW );
210 sizerDetailOptions -> Add( new wxStaticText(panel,-1,_T(" ")) , 1, wxGROW );
211 sizerDetailOptions -> Add( tmpSliderAng, 1, wxGROW );
213 tmpSpinSection -> SetValue(5);
214 tmpSliderRadio -> SetValue( 100-(double)((i)*100.0/_maxLevels) );
215 tmpSliderAng -> SetValue(0);
217 Connect( tmpSliderRadio->GetId(), wxEVT_SCROLL_THUMBRELEASE , (wxObjectEventFunction) &PanelBullEyeOptions::onRefreshPanel );
218 Connect( tmpSliderRadio->GetId(), wxEVT_SCROLL_CHANGED , (wxObjectEventFunction) &PanelBullEyeOptions::onRefreshPanel );
220 _lstBullEyeDetailNumOfSec.push_back( tmpSpinSection );
221 _lstBullEyeDetailRadio.push_back( tmpSliderRadio );
222 _lstBullEyeDetailAngle.push_back( tmpSliderAng );
226 wxFlexGridSizer * sizer = new wxFlexGridSizer(1);
227 sizer -> Add( new wxStaticText(panel,-1,_T("")) , 1, wxGROW );
228 sizer -> Add( new wxStaticText(panel,-1,_T("")) , 1, wxGROW );
229 sizer -> Add( _radioboxBullEyeGenOpt , 1, wxGROW );
230 sizer -> Add( new wxStaticText(panel,-1,_T("")) , 1, wxGROW );
231 sizer -> Add( new wxStaticText(panel,-1,_T(" -- Bull Eye general options --")) , 1, wxGROW );
232 sizer -> Add( new wxStaticText(panel,-1,_T("")) , 1, wxGROW );
233 sizer -> Add( sizerGeneralOptions , 1, wxGROW );
234 sizer -> Add( new wxStaticText(panel,-1,_T("")) , 1, wxGROW );
235 sizer -> Add( new wxStaticText(panel,-1,_T("")) , 1, wxGROW );
236 sizer -> Add( new wxStaticText(panel,-1,_T(" -- Bull Eye detail options --")) , 1, wxGROW );
237 sizer -> Add( new wxStaticText(panel,-1,_T("")) , 1, wxGROW );
238 sizer -> Add( sizerDetailOptions , 1, wxGROW );
240 Connect( _radioboxBullEyeGenOpt->GetId(), wxEVT_COMMAND_RADIOBOX_SELECTED , (wxObjectEventFunction) &PanelBullEyeOptions::onRefreshPanel );
241 Connect( _spinctrlBullEyeNumOfCrowns->GetId(), wxEVT_COMMAND_TEXT_UPDATED , (wxObjectEventFunction) &PanelBullEyeOptions::onRefreshPanel );
243 panel->SetSizer( sizer );
244 panel->SetSize( sizepanel );
245 panel->SetAutoLayout( true );
252 //------------------------------------------------------------------------------------------------------------
253 PanelBullEyeOptions::~PanelBullEyeOptions()
257 //------------------------------------------------------------------------------------------------------------
258 void PanelBullEyeOptions::onRefreshPanel( wxCommandEvent& event )
263 //------------------------------------------------------------------------------------------------------------
264 void PanelBullEyeOptions::RefreshPanel()
268 if (this->_radioboxBullEyeGenOpt->GetSelection()==0){
269 for (i=0; i<_maxLevels; i++)
271 _lstBullEyeDetailNumOfSec[i] -> Enable(false);
272 _lstBullEyeDetailRadio[i] -> Enable(false);
273 _lstBullEyeDetailAngle[i] -> Enable(false);
276 int spinSelec = _spinctrlBullEyeNumOfCrowns->GetValue();
277 for (i=0; i<_maxLevels; i++)
279 ok = (i < spinSelec);
280 _lstBullEyeDetailNumOfSec[i] -> Enable(ok);
281 _lstBullEyeDetailRadio[i] -> Enable(ok);
282 _lstBullEyeDetailAngle[i] -> Enable(ok);
285 if (_lstBullEyeDetailRadio[i]->GetValue() > _lstBullEyeDetailRadio[i-1]->GetValue())
287 _lstBullEyeDetailRadio[i]->SetValue( _lstBullEyeDetailRadio[i-1]->GetValue() );
294 //------------------------------------------------------------------------------------------------------------
295 int PanelBullEyeOptions::GetNumberOfCrowns()
297 return this->_spinctrlBullEyeNumOfCrowns->GetValue();
300 //------------------------------------------------------------------------------------------------------------
301 int PanelBullEyeOptions::GetNumberOfSections(int nCrown)
304 if (this->_radioboxBullEyeGenOpt->GetSelection()==0)
306 result = this->_spinctrlBullEyeNumOfSec->GetValue();
308 result = this->_lstBullEyeDetailNumOfSec[nCrown]->GetValue();
313 //------------------------------------------------------------------------------------------------------------
314 int PanelBullEyeOptions::GetRadioOfCrown(int nCrown)
318 if (this->_radioboxBullEyeGenOpt->GetSelection()==0)
320 sizeCrowns = (double)( this->_spinctrlBullEyeNumOfCrowns->GetValue() );
321 result = 100.0 * (nCrown+1)/sizeCrowns ;
323 result = this->_lstBullEyeDetailRadio[nCrown]->GetValue();
328 //------------------------------------------------------------------------------------------------------------
329 double PanelBullEyeOptions::GetAngOfCrownSection(int nCrown,int section)
332 if (this->_radioboxBullEyeGenOpt->GetSelection()==0)
334 angle = this->_sliderBullEyeAngle->GetValue();
336 angle = this->_lstBullEyeDetailAngle[nCrown]->GetValue();
338 double numOfSec = (double)GetNumberOfSections(nCrown);
339 double deltaSec = GetAngDeltaOfCrownSection(nCrown);
340 return angle + section*deltaSec ;
343 //------------------------------------------------------------------------------------------------------------
344 double PanelBullEyeOptions::GetAngDeltaOfCrownSection(int nCrown)
346 double numOfSec = (double)GetNumberOfSections(nCrown);
347 return 360.0/numOfSec;
352 //------------------------------------------------------------------------------------------------------------
353 //------------------------------------------------------------------------------------------------------------
354 //------------------------------------------------------------------------------------------------------------
357 //------------------------------------------------------------------------------------------------------------
358 // Constructors & Destructors
359 //------------------------------------------------------------------------------------------------------------
361 wxContourEventHandler ::wxContourEventHandler()
364 _creatingContoursActive = false;
365 _theViewPanel = NULL;
366 _modelManager = NULL;
367 _instantPanel = NULL;
370 _drawToolsPanel = NULL;
371 _operationsToolsPanel = NULL;
372 _autoFormsPanel = NULL;
373 _standardToolsPanel = NULL;
374 _editionToolsPanel = NULL;
375 _listViewPanel = NULL;
376 _sceneManager = NULL;
377 _actualInstant = NULL;
378 _performingOperation = new PerformingOperation();
380 // EED Interface and Spread
382 _segmentationFrame = NULL;
383 _contourPropagation = NULL;
384 _createContourFrame = NULL;
386 _InformationContourFrame = NULL;
387 _interfaceConfigurationFrame = NULL;
389 _wxtextctrlTest = NULL;
390 _panelBullEyeOptions = NULL;
392 fileNameContourROI = "";
393 _numberOfVariablesStatistics=6+1;
397 stundoredo = "data/temp";
399 mkdir(stundoredo.c_str());
401 mkdir(stundoredo.c_str(),755);
403 stundoredo += "/cont";
405 //------------------------------------------------------------------------------------------------------------
406 wxContourEventHandler :: ~ wxContourEventHandler()
408 delete _actualInstant;
409 /*delete _theViewPanel;
410 delete _instantPanel;
412 delete _actualInstant;
414 delete _sceneManager;
415 delete _performingOperation;
419 //------------------------------------------------------------------------------------------------------------
420 // Configuration methods
421 //------------------------------------------------------------------------------------------------------------
423 bool wxContourEventHandler :: configureEventsHandling()
425 bool configured = true;
430 //------------------------------------------------------------------------------------------------------------
431 // Methods for capturing events
432 //------------------------------------------------------------------------------------------------------------
433 void wxContourEventHandler :: onProcessMessage( wxCommandEvent& event )
437 //------------------------------------------------------------------------------------------------------------
439 void wxContourEventHandler :: onActionButtonPressed( wxCommandEvent& event )
441 const char buttonTool = *(char *)event.GetClientData();
442 executeActionCommand( buttonTool );
444 //------------------------------------------------------------------------------------------------------------
445 void wxContourEventHandler :: onChangedDeep ( wxCommandEvent& event )
447 double val = _theViewPanel->getCurrentDeep();
448 _instantPanel->setConceptValue( "Axe Depth", (int)val );
449 _theViewPanel->setActualVertical( (int)val );
453 //------------------------------------------------------------------------------------------------------------
454 void wxContourEventHandler :: onChangeInstant( wxCommandEvent& event )
456 ConceptDataWrap * dataConcept = NULL;
457 if ( _theViewPanel->GetId() == event.GetId() )
459 dataConcept = (ConceptDataWrap *)event.GetClientData();
460 int value = dataConcept->getActualValue();
461 _instantPanel->setConceptValue( dataConcept->getName(), value );
465 dataConcept = _instantPanel->getLastConceptData();
466 if( dataConcept->getName().compare( _theViewPanel->getVerticalConceptName() ) == 0)
468 _theViewPanel->setActualVertical( dataConcept->getActualValue());
469 //_theViewPanel->setVerticalConcept( dataConcept->getName(), dataConcept->getMinShowedValue()/*dataConcept->getMinValue()*/, /*dataConcept->getMaxValue()*/ dataConcept->getMaxShowedValue(), dataConcept->getMinShowedValue(), dataConcept->getMaxShowedValue(), dataConcept->getActualValue());
471 else if( dataConcept->getName().compare( _theViewPanel->getHorizontalConceptName() ) == 0|| _instantPanel->getIfConceptCheckedAt( dataConcept->getName(), 0 ) )
473 _theViewPanel->setHorizontalConcept( dataConcept->getName(), dataConcept->getMinShowedValue()/*dataConcept->getMinValue()*/, /*dataConcept->getMaxValue()*/ dataConcept->getMaxShowedValue(), dataConcept->getMinShowedValue(), dataConcept->getMaxShowedValue(), dataConcept->getActualValue());
478 //------------------------------------------------------------------------------------------------------------
480 void wxContourEventHandler :: onCreateMultipleROI( wxCommandEvent& event )
482 _creatingContoursActive = !_creatingContoursActive;
483 if( _creatingContoursActive )
488 //------------------------------------------------------------------------------------------------------------
489 void wxContourEventHandler :: onCreateROI( wxCommandEvent& event )
491 if( _creatingContoursActive )
497 //------------------------------------------------------------------------------------------------------------
498 void wxContourEventHandler :: onStopCreateROI( wxCommandEvent& event )
503 //------------------------------------------------------------------------------------------------------------
504 void wxContourEventHandler :: onDeleterROI( wxCommandEvent& event )
508 //------------------------------------------------------------------------------------------------------------
509 void wxContourEventHandler :: onSelectROI( wxCommandEvent& event )
513 //------------------------------------------------------------------------------------------------------------
516 void wxContourEventHandler :: onUnSelectROI( wxCommandEvent& event )
520 //------------------------------------------------------------------------------------------------------------
522 void wxContourEventHandler :: onManualHidedROI( wxCommandEvent& event )
526 //------------------------------------------------------------------------------------------------------------
528 void wxContourEventHandler :: onManualShowedROI( wxCommandEvent& event )
532 //------------------------------------------------------------------------------------------------------------
534 void wxContourEventHandler :: onEditingROI( wxCommandEvent& event )
538 //------------------------------------------------------------------------------------------------------------
540 void wxContourEventHandler :: onMovingROI( wxCommandEvent& event )
545 //------------------------------------------------------------------------------------------------------------
546 // Model management methods
547 //------------------------------------------------------------------------------------------------------------
549 void wxContourEventHandler::onSpreadReset( wxCommandEvent& event )
551 _wxtextctrlSpread->SetValue(wxString("",wxConvUTF8));
552 _contourPropagation->resetAppend();
555 //------------------------------------------------------------------------------------------------------------
556 void wxContourEventHandler::onSpreadAdd( wxCommandEvent& event )
558 std::vector<double> vecX;
559 std::vector<double> vecY;
560 std::vector<double> vecZ;
561 _theViewPanel->getSceneManager()->GetPointsOfActualContour( &vecX , &vecY , &vecZ );
564 std::vector<int> tempVector;
565 _instantPanel->getInstant( tempVector );
566 int i,size=vecZ.size();
567 int actualSlice = tempVector[1];
568 for ( i=0 ; i<size ; i++ )
570 vecZ[i] = actualSlice;
573 _contourPropagation->appendContour(&vecX , &vecY , &vecZ);
575 //newstring.Printf("%s %d -",_wxtextctrlSpread->GetValue(), actualSlice );
576 newstring.append(wxString(_wxtextctrlSpread->GetValue(),wxConvUTF8));
577 newstring.append(wxString(" ",wxConvUTF8));
578 newstring.append(wxString(intToString(actualSlice).c_str(),wxConvUTF8));
579 _wxtextctrlSpread->SetValue(newstring);
585 //------------------------------------------------------------------------------------------------------------
586 void wxContourEventHandler::onSpreadGo( wxCommandEvent& event )
589 //JCP 20-10-08 Undo redo implementation
591 //JCP 20-10-08 Undo redo implementation
594 int typeMethodFindCtrlPoints=_spreadMethodRadiobox->GetSelection();
595 int typeofcontour = 1;
596 manualContourModel *manModelContour;
597 std::vector<double> vecCtrlPointX;
598 std::vector<double> vecCtrlPointY;
599 std::vector<double> vecCtrlPointZ;
605 std::vector<int> tempVector;
606 _instantPanel->getInstant( tempVector );
609 _contourPropagation->getMaxMinZ(&minZ,&maxZ);
610 //JSTG_16-07-08_----------------------------------------------------------------
611 //_contourPropagation->setInterpolationNumber(maxZ-minZ+1);
612 _contourPropagation->setInterpolationNumber(100);
613 _contourPropagation->CalculeSplinePropagation();
615 double totalZ = maxZ-minZ+1;
618 //--------------------------------------------------------------------
619 for ( z=(int)minZ ; z<=(int)maxZ ; z++ )
621 porcent = 100.0* (z-minZ)/totalZ;
622 int numero = (int)(z-minZ+1)/(int)totalZ;
623 std::string stringtemp = " "+intToString(porcent)+"% "+intToString(numero)+" "+intToString(z);
624 tmpString.Append(wxString(stringtemp.c_str(),wxConvUTF8));
626 //tmpString.Printf(" %d %c %d/%d %d", (int)porcent , 37 , (int)(z-minZ+1), (int)totalZ,z );
627 _staticTextSpread->SetLabel(tmpString);
629 if (_contourPropagation->ifSliceKeyContourExist(z)==false)
631 manModelContour = factoryManualContourModel( typeofcontour );
632 idTmp = _contourPropagation->FindIdWithZ(z);
633 if (typeMethodFindCtrlPoints==0) // Initial Points
635 _contourPropagation->GetInitialControlPoints( idTmp , &vecCtrlPointX,&vecCtrlPointY,&vecCtrlPointZ);
637 if (typeMethodFindCtrlPoints==1) // Automatique Method
639 _contourPropagation->GetControlPoints( idTmp ,&vecCtrlPointX,&vecCtrlPointY,&vecCtrlPointZ);
641 if (typeMethodFindCtrlPoints==2) // sampling
643 _contourPropagation->GetControlPoints( idTmp , 20.0 ,&vecCtrlPointX,&vecCtrlPointY,&vecCtrlPointZ);
645 //--------------------------------------------------------------------
646 sizeCtrPt = vecCtrlPointX.size();
647 for (j=0 ; j<sizeCtrPt ; j++)
649 //JSTG_16-07-08_----------------------------------------------------------------
650 manModelContour->AddPoint( vecCtrlPointX[j] , vecCtrlPointY[j] , -900 );
651 //--------------------------------------------------------------------
656 theName = _modelManager->createOutline( manModelContour, tempVector );
657 bool addedModel = theName.compare("") != 0;
660 double spc[3];//Si no hay imagen pero hay contornos que spacing se pone por default
661 this->_theViewPanel->getSpacing(spc);
662 //Adding the manualContourControler to interface objects structure
663 //Adding the manualViewContour to interface objects structure
664 //_theViewPanel->getSceneManager()->setControlActiveStateOfALL( false );//This call is being done here because if the ROI is created underneath the previously created ROIS will still be active.
665 _theViewPanel->getSceneManager()->configureViewControlTo( theName, manModelContour,spc,typeofcontour ) ;
667 }// ifSliceKeyContourExist
669 _staticTextSpread->SetLabel(wxString(" ",wxConvUTF8));
670 //RefreshInterface();
676 //------------------------------------------------------------------------------------------------------------
677 void wxContourEventHandler :: onSpread( )
679 if (_spreadFrame==NULL)
682 _spreadFrame = new wxFrame (_theViewPanel, -1,_T(" Spread "), wxDefaultPosition, wxDefaultSize, wxFRAME_TOOL_WINDOW|wxSYSTEM_MENU | wxCAPTION | wxCLIP_CHILDREN |wxFRAME_FLOAT_ON_PARENT );
684 wxSize sizepanel(250,400);
685 _spreadFrame->SetSize( sizepanel );
686 _spreadFrame->SetEventHandler( this );
687 wxPanel *panel = getSpreadPanel(_spreadFrame);
688 panel->SetSize(sizepanel);
689 /**new wxPanel(_spreadFrame,-1);
691 wxButton *spreadResetBtn = new wxButton(panel,-1,_T("Reset"),wxDefaultPosition, wxSize(80,35) );
692 wxButton *spreadAddBtn = new wxButton(panel,-1,_T("Add"),wxDefaultPosition, wxSize(80,35));
694 wxString lstOptions[3];
698 _spreadMethodRadiobox = new wxRadioBox(panel, -1, "Method (find ctrl. Points)", wxDefaultPosition, wxSize(200,45), 3 , lstOptions, 3, wxRA_SPECIFY_COLS);
699 _spreadMethodRadiobox->SetSelection(2);
701 wxButton *spreadGoBtn = new wxButton(panel,-1,_T("Go"),wxDefaultPosition, wxSize(80,35));
702 _staticTextSpread = new wxStaticText(panel,-1,_T(" "));
704 _wxtextctrlSpread = new wxTextCtrl(panel,-1, "",wxDefaultPosition, wxSize(200,150), wxTE_MULTILINE );
706 _spreadFrame->SetEventHandler( this );
707 Connect( spreadResetBtn->GetId(), wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &wxContourEventHandler::onSpreadReset );
708 Connect( spreadAddBtn->GetId(), wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &wxContourEventHandler::onSpreadAdd );
709 Connect( spreadGoBtn->GetId(), wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &wxContourEventHandler::onSpreadGo );
711 wxFlexGridSizer * sizer = new wxFlexGridSizer(1);
712 sizer -> Add( spreadResetBtn , 1, wxGROW );
713 sizer -> Add( spreadAddBtn , 1, wxGROW );
714 sizer -> Add( _spreadMethodRadiobox , 1, wxGROW );
715 sizer -> Add( spreadGoBtn , 1, wxGROW );
716 sizer -> Add( _staticTextSpread , 1, wxGROW );
717 sizer -> Add( _wxtextctrlSpread , 1, wxGROW );
720 panel->SetSizer( sizer );
721 panel->SetSize( sizepanel );
722 panel->SetAutoLayout( true );
724 _spreadFrame->Show();
726 if (_spreadFrame->IsShown()==true)
728 _spreadFrame->Show(false);
730 _spreadFrame->Show(true);
735 wxPanel* wxContourEventHandler::getSpreadPanel(wxWindow* parent){
736 //wxPanel *panel = new wxPanel(parent,-1);
738 _contourPropagation = new ContourPropagation();
740 wxPanel *panel = new wxPanel(parent,-1,wxDefaultPosition, wxDefaultSize,wxNO_BORDER, wxString("",wxConvUTF8));
742 wxButton *spreadResetBtn = new wxButton(panel,-1,_T("Reset"),wxDefaultPosition, wxDefaultSize );
743 wxButton *spreadAddBtn = new wxButton(panel,-1,_T("Add"),wxDefaultPosition, wxDefaultSize);
745 wxString lstOptions[3];
746 lstOptions[0]=_T("A");
747 lstOptions[1]=_T("B");
748 lstOptions[2]=_T("C");
749 _spreadMethodRadiobox = new wxRadioBox(panel, -1, _T("Method (find ctrl. Points)"), wxDefaultPosition, wxDefaultSize, 3 , lstOptions, 3, wxRA_SPECIFY_COLS);
750 _spreadMethodRadiobox->SetSelection(2);
752 wxButton *spreadGoBtn = new wxButton(panel,-1,_T("Go"),wxDefaultPosition, wxDefaultSize);
753 _staticTextSpread = new wxStaticText(panel,-1,_T(" "));
755 _wxtextctrlSpread = new wxTextCtrl(panel,-1, _T(""),wxDefaultPosition, wxDefaultSize, wxTE_MULTILINE );
758 Connect( spreadResetBtn->GetId(), wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &wxContourEventHandler::onSpreadReset );
759 Connect( spreadAddBtn->GetId(), wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &wxContourEventHandler::onSpreadAdd );
760 Connect( spreadGoBtn->GetId(), wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &wxContourEventHandler::onSpreadGo );
762 wxFlexGridSizer * sizer = new wxFlexGridSizer(1);
763 sizer -> Add( spreadResetBtn , 1, wxGROW );
764 sizer -> Add( spreadAddBtn , 1, wxGROW );
765 sizer -> Add( _spreadMethodRadiobox , 1, wxGROW );
766 sizer -> Add( spreadGoBtn , 1, wxGROW );
767 sizer -> Add( _staticTextSpread , 1, wxGROW );
768 sizer -> Add( _wxtextctrlSpread , 1, wxGROW );
771 panel->SetSizer( sizer );
772 //panel->SetSize( wxDefaultSize );
773 panel->SetAutoLayout( true );
778 //------------------------------------------------------------------------------------------------------------
779 void wxContourEventHandler::onSegmentationAllSlice( wxCommandEvent& event )
781 //JCP 20-10-08 Undo redo implementation
783 //JCP 20-10-08 Undo redo implementation
786 int x = this->_theViewPanel->GetX();
787 int y = this->_theViewPanel->GetY();
791 minZ=_mbarrange->GetStart();
792 maxZ=_mbarrange->GetEnd();
793 double totalZ = maxZ-minZ+1;
794 for( z=minZ ; z<=maxZ ; z++ )
796 porcent = 100.0* (z-minZ)/totalZ;
797 tmpString.Printf(_T(" %d %c %d/%d %d"), (int)porcent , 37 , z-minZ+1, (int)totalZ,z );
798 _staticTextSegmentation->SetLabel(tmpString);
799 SegmentationOneSlice( x,y,z );
801 _staticTextSegmentation->SetLabel(_T(" "));
807 //------------------------------------------------------------------------------------------------------------
808 void wxContourEventHandler::onSegmentationOneSlice( wxCommandEvent& event )
810 //JCP 20-10-08 Undo redo implementation
812 //JCP 20-10-08 Undo redo implementation
815 int x = this->_theViewPanel->GetX();
816 int y = this->_theViewPanel->GetY();
817 int z = this->_theViewPanel->GetZ();
818 SegmentationOneSlice( x,y,z );
823 //------------------------------------------------------------------------------------------------------------
824 void wxContourEventHandler::SegmentationOneSlice( int x, int y, int z )
826 int typeofcontour = 1;
827 //--Extracting Contour
828 vtkImageData *imagedata = _theViewPanel->getSceneManager()->GetImageData();
829 // double *range = imagedata->GetScalarRange();
831 int isovalue = _isovalue->GetValue();
832 int sampling = _sampling->GetValue();
834 vtkImageReslice *imageReslice = vtkImageReslice::New();
837 // imagedata->GetSpacing(spc);
842 imageReslice->SetInput( imagedata );
843 imageReslice->SetInformationInput(imagedata);
844 imageReslice->SetResliceAxesDirectionCosines(1,0,0, 0,1,0 ,0,0,1);
845 imageReslice->SetResliceAxesOrigin(0,0,z);
846 imageReslice->SetOutputDimensionality(2);
847 imageReslice->SetInterpolationModeToLinear();
849 imagedata = imageReslice->GetOutput();
851 imagedata->UpdateInformation();
853 vtkContourFilter* cntVTK = vtkContourFilter::New( );
854 cntVTK->SetInput( imagedata );
856 cntVTK->SetNumberOfContours( 1 );
857 //cntVTK->SetValue( 0, vmin );
858 // cntVTK->SetValue( 0, (range[1]*thr/100) );
859 cntVTK->SetValue( 1, isovalue );
860 // cntVTK->SetValue( 1, vmax );
862 cntVTK->UpdateInformation();
864 vtkCleanPolyData* cpd = vtkCleanPolyData::New( );
865 cpd->SetInput( cntVTK->GetOutput( ) );
866 cpd->ConvertLinesToPointsOff( );
868 cpd->UpdateInformation();
870 vtkPolyDataConnectivityFilter* conn = vtkPolyDataConnectivityFilter::New( );
871 conn->SetExtractionModeToClosestPointRegion( );
872 //conn->SetMaxRecursionDepth( 3000 );
874 conn->SetInput( cpd->GetOutput( ) );
876 conn->SetClosestPoint( x, y, 0 );
878 conn->UpdateInformation();
880 vtkCleanPolyData* cpd2 = vtkCleanPolyData::New( );
881 cpd2->SetInput( conn->GetOutput( ) );
883 cpd2->UpdateInformation();
885 vtkStripper* vtkstripper = vtkStripper::New( );
886 vtkstripper->SetInput( cpd2->GetOutput() );
887 vtkstripper->Update();
888 vtkstripper->UpdateInformation();
891 vtkPolyData* polyDataResult = vtkstripper->GetOutput();
893 polyDataResult->Update( );
894 polyDataResult->UpdateInformation();
898 myfile.open ("c:/temp/example.txt");
900 polyDataResult->Print(myfile);
901 myfile << "-------------------------------------\n";
902 polyDataResult->GetLines()->Print(myfile);
912 //--Calculating control points
914 std::vector<double> vecX;
915 std::vector<double> vecY;
916 std::vector<double> vecZ;
918 std::vector<double> vecCtrlPointX;
919 std::vector<double> vecCtrlPointY;
920 std::vector<double> vecCtrlPointZ;
924 int ii,size=polyDataResult->GetNumberOfPoints();
926 for (ii=1;ii<=size;ii++)
928 id = polyDataResult->GetLines()->GetData()->GetValue(ii);
929 p = polyDataResult->GetPoint(id);
932 vecX.push_back( p[0] );
933 vecY.push_back( p[1] );
934 vecZ.push_back( -900 );
935 // vecZ.push_back( p[2] );
939 ExtractControlPoints2D *extractcontrolpoints2d = new ExtractControlPoints2D();
940 extractcontrolpoints2d->SetContour( &vecX , &vecY , &vecZ );
943 if (methodRadiobox->GetSelection()==0){
944 extractcontrolpoints2d->GetInitialControlPoints( &vecCtrlPointX , &vecCtrlPointY , &vecCtrlPointZ );
946 if (methodRadiobox->GetSelection()==1){
947 extractcontrolpoints2d->GetControlPoints( &vecCtrlPointX , &vecCtrlPointY , &vecCtrlPointZ );
949 if (methodRadiobox->GetSelection()==2){
950 extractcontrolpoints2d->SetSamplingControlPoints( sampling );
951 extractcontrolpoints2d->GetSamplingControlPoints( &vecCtrlPointX , &vecCtrlPointY , &vecCtrlPointZ );
954 //--Adding contour to the system
956 std::vector<int> actualInstantVector;
957 _instantPanel->getInstant( actualInstantVector );
958 actualInstantVector[1]=z;
960 int j,sizeCtrPt = vecCtrlPointX.size();
961 manualContourModel *manModelContour = factoryManualContourModel( typeofcontour );
962 manModelContour->SetNumberOfPointsSpline( ((sizeCtrPt/100)+1)*100 );
964 for (j=0 ; j<sizeCtrPt ; j++)
966 manModelContour->AddPoint( vecCtrlPointX[j] , vecCtrlPointY[j] , vecCtrlPointZ[j] );
969 theName = _modelManager->createOutline( manModelContour, actualInstantVector );
970 bool addedModel = theName.compare("") != 0;
973 double spc[3];//Si no hay imagen pero hay contornos que spacing se pone por default
974 this->_theViewPanel->getSpacing(spc);
975 //Adding the manualContourControler to interface objects structure
976 //Adding the manualViewContour to interface objects structure
977 //_theViewPanel->getSceneManager()->setControlActiveStateOfALL( false );//This call is being done here because if the ROI is created underneath the previously created ROIS will still be active.
978 _theViewPanel->getSceneManager()->configureViewControlTo( theName, manModelContour,spc, typeofcontour ) ;
983 //------------------------------------------------------------------------------------------------------------
984 void wxContourEventHandler :: onAutomatiqueSegmentation( )
986 if (_segmentationFrame==NULL)
989 /*int sizeZ = _theViewPanel->getSceneManager()->GetImageDataSizeZ();
991 _theViewPanel->getSceneManager()->GetImageDataRange(range);*/
994 wxSize sizePanel( 300, 470);
995 _segmentationFrame = new wxFrame (_theViewPanel, -1,_T(" Segmentation "), wxDefaultPosition, wxDefaultSize, wxFRAME_TOOL_WINDOW|wxSYSTEM_MENU | wxCAPTION | wxCLIP_CHILDREN |wxFRAME_FLOAT_ON_PARENT );
996 _segmentationFrame->SetSize( sizePanel );
997 wxPanel *panel = getSegmentationPanel(_segmentationFrame);
998 /*new wxPanel(_segmentationFrame,-1);
999 wxButton *segmentationOneSliceBtn = new wxButton(panel,-1,_T("Actual slice"), wxDefaultPosition, wxSize(200,35) );
1000 wxButton *segmentationAllSliceBtn = new wxButton(panel,-1,_T("All slices") ,wxDefaultPosition, wxSize(200,35) );
1001 _isovalue = new wxSlider(panel, -1, 40 , (int)(range[0]), (int)(range[1]), wxDefaultPosition, wxSize(200,35), wxSL_HORIZONTAL|wxSL_LABELS, wxDefaultValidator);
1002 _sampling = new wxSlider(panel, -1, 20 , 4, 50, wxDefaultPosition, wxSize(200,35), wxSL_HORIZONTAL|wxSL_LABELS, wxDefaultValidator);
1003 wxString lstOptions[3];
1007 methodRadiobox = new wxRadioBox(panel, -1, "Method (find ctrl. Points)", wxDefaultPosition, wxSize(200,45), 3 , lstOptions, 3, wxRA_SPECIFY_COLS);
1008 methodRadiobox->SetSelection(2);
1009 _staticTextSegmentation = new wxStaticText(panel,-1,_T(" "));
1012 _mbarrange = new mBarRange(panel,70, 65);
1013 _mbarrange->SetMin(0);
1014 _mbarrange->SetStart(0);
1016 _mbarrange-> SetOrientation( true );
1017 _mbarrange-> setActiveStateTo(true);
1018 _mbarrange-> setVisibleLabels( true );
1019 _mbarrange-> setDeviceEndMargin(10);
1020 _mbarrange-> setRepresentedValues( 0 , sizeZ );
1021 _mbarrange-> setDeviceBlitStart(10,10);
1022 _mbarrange-> setIfWithActualDrawed( false );
1023 _mbarrange-> SetStart( 0 );
1024 _mbarrange-> SetEnd( sizeZ );
1027 // _segmentationFrame->SetEventHandler( this );
1028 segmentationOneSliceBtn->SetEventHandler( this );
1029 segmentationAllSliceBtn->SetEventHandler( this );
1030 Connect( segmentationOneSliceBtn->GetId(), wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &wxContourEventHandler::onSegmentationOneSlice );
1031 Connect( segmentationAllSliceBtn->GetId(), wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &wxContourEventHandler::onSegmentationAllSlice );
1033 wxFlexGridSizer * sizer = new wxFlexGridSizer(1);
1034 sizer -> Add( new wxStaticText(panel,-1,_T("Isovalue (Gray level)")) , 1, wxGROW );
1035 sizer -> Add( _isovalue , 1, wxGROW );
1036 sizer -> Add( methodRadiobox , 1, wxGROW );
1037 sizer -> Add( new wxStaticText(panel,-1,_T("Sampling (%)")) , 1, wxGROW );
1038 sizer -> Add( _sampling , 1, wxGROW );
1039 sizer -> Add( segmentationOneSliceBtn , 1, wxGROW );
1040 sizer -> Add( new wxStaticText(panel,-1,_T(" ")) , 1, wxGROW );
1041 sizer -> Add( _staticTextSegmentation , 1, wxGROW );
1042 sizer -> Add( segmentationAllSliceBtn , 1, wxGROW );
1043 sizer -> Add( _mbarrange , 1, wxGROW );
1045 panel->SetSizer( sizer );
1046 panel->SetSize( sizePanel );
1047 panel->SetAutoLayout( true );
1050 this->_theViewPanel->SetVisibleAxis(true);
1051 this->_theViewPanel->Refresh();
1052 _segmentationFrame->Show(true);
1053 //JCP 13-10-09 View the method getSegmentationPanel(), this two methods where moved to getSegmentationPanel
1054 //this->_theViewPanel->SetVisibleAxis(true);
1055 //this->_theViewPanel->Refresh();
1057 if (_segmentationFrame->IsShown()==true)
1059 _segmentationFrame->Show(false);
1060 this->_theViewPanel->SetVisibleAxis(false);
1061 this->_theViewPanel->Refresh();
1063 _segmentationFrame->Show(true);
1064 this->_theViewPanel->SetVisibleAxis(true);
1065 this->_theViewPanel->Refresh();
1070 void wxContourEventHandler::showAxis(bool show){
1071 this->_theViewPanel->SetVisibleAxis(show);
1072 this->_theViewPanel->Refresh();
1074 wxPanel* wxContourEventHandler::getSegmentationPanel(wxWindow* parent){
1075 int sizeZ = _theViewPanel->getSceneManager()->GetImageDataSizeZ();
1077 _theViewPanel->getSceneManager()->GetImageDataRange(range);
1079 wxPanel *panel = new wxPanel(parent,-1);
1080 wxButton *segmentationOneSliceBtn = new wxButton(panel,-1,_T("Actual slice"), wxDefaultPosition, wxSize(200,35) );
1081 wxButton *segmentationAllSliceBtn = new wxButton(panel,-1,_T("All slices") ,wxDefaultPosition, wxSize(200,35) );
1082 _isovalue = new wxSlider(panel, -1, 40 , (int)(range[0]), (int)(range[1]), wxDefaultPosition, wxSize(200,35), wxSL_HORIZONTAL|wxSL_LABELS, wxDefaultValidator);
1083 _sampling = new wxSlider(panel, -1, 20 , 4, 50, wxDefaultPosition, wxSize(200,35), wxSL_HORIZONTAL|wxSL_LABELS, wxDefaultValidator);
1084 wxString lstOptions[3];
1085 lstOptions[0]=_T("A");
1086 lstOptions[1]=_T("B");
1087 lstOptions[2]=_T("C");
1088 methodRadiobox = new wxRadioBox(panel, -1, _T("Method (find ctrl. Points)"), wxDefaultPosition, wxSize(200,45), 3 , lstOptions, 3, wxRA_SPECIFY_COLS);
1089 methodRadiobox->SetSelection(2);
1090 _staticTextSegmentation = new wxStaticText(panel,-1,_T(" "));
1093 _mbarrange = new mBarRange(panel,70, 65);
1094 _mbarrange->SetMin(0);
1095 _mbarrange->SetStart(0);
1097 _mbarrange-> SetOrientation( true );
1098 _mbarrange-> setActiveStateTo(true);
1099 _mbarrange-> setVisibleLabels( true );
1100 _mbarrange-> setDeviceEndMargin(10);
1101 _mbarrange-> setRepresentedValues( 0 , sizeZ );
1102 _mbarrange-> setDeviceBlitStart(10,10);
1103 _mbarrange-> setIfWithActualDrawed( false );
1104 _mbarrange-> SetStart( 0 );
1105 _mbarrange-> SetEnd( sizeZ );
1108 // _segmentationFrame->SetEventHandler( this );
1109 segmentationOneSliceBtn->SetEventHandler( this );
1110 segmentationAllSliceBtn->SetEventHandler( this );
1111 Connect( segmentationOneSliceBtn->GetId(), wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &wxContourEventHandler::onSegmentationOneSlice );
1112 Connect( segmentationAllSliceBtn->GetId(), wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &wxContourEventHandler::onSegmentationAllSlice );
1114 wxFlexGridSizer * sizer = new wxFlexGridSizer(1);
1115 sizer -> Add( new wxStaticText(panel,-1,_T("Isovalue (Gray level)")) , 1, wxGROW );
1116 sizer -> Add( _isovalue , 1, wxGROW );
1117 sizer -> Add( methodRadiobox , 1, wxGROW );
1118 sizer -> Add( new wxStaticText(panel,-1,_T("Sampling (%)")) , 1, wxGROW );
1119 sizer -> Add( _sampling , 1, wxGROW );
1120 sizer -> Add( segmentationOneSliceBtn , 1, wxGROW );
1121 sizer -> Add( new wxStaticText(panel,-1,_T(" ")) , 1, wxGROW );
1122 sizer -> Add( _staticTextSegmentation , 1, wxGROW );
1123 sizer -> Add( segmentationAllSliceBtn , 1, wxGROW );
1124 sizer -> Add( _mbarrange , 1, wxGROW );
1126 panel->SetSizer( sizer );
1127 // panel->SetSize( sizePanel );
1128 panel->SetSize( wxDefaultSize );
1129 panel->SetAutoLayout( true );
1134 void wxContourEventHandler :: onInterfaceTestFrame( )
1136 if (_TestFrame==NULL)
1138 _contourPropagation = new ContourPropagation();
1139 _TestFrame = new wxFrame (_theViewPanel, -1,_T(" Test Segmentation "), wxDefaultPosition, wxDefaultSize, wxFRAME_TOOL_WINDOW|wxSYSTEM_MENU | wxCAPTION | wxCLIP_CHILDREN |wxFRAME_FLOAT_ON_PARENT );
1140 wxSize sizepanel(200,300);
1141 _TestFrame->SetSize( sizepanel );
1142 wxPanel *panel = new wxPanel(_TestFrame,-1);
1143 wxButton *spreadResetBtn = new wxButton(panel,-1,_T("Reset"),wxDefaultPosition, wxSize(80,35) );
1144 wxButton *spreadAddBtn = new wxButton(panel,-1,_T("Add"),wxDefaultPosition, wxSize(80,35));
1145 wxButton *spreadGoBtn = new wxButton(panel,-1,_T("GoA"),wxDefaultPosition, wxSize(80,35));
1146 _wxtextctrlTest = new wxTextCtrl(panel,-1, _T(""),wxDefaultPosition, wxSize(200,150), wxTE_MULTILINE );
1148 _TestFrame->SetEventHandler( this );
1149 Connect( spreadResetBtn->GetId(), wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &wxContourEventHandler::onTestReset );
1150 Connect( spreadAddBtn->GetId(), wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &wxContourEventHandler::onTestAdd );
1151 Connect( spreadGoBtn->GetId(), wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &wxContourEventHandler::onTestGo );
1153 wxFlexGridSizer * sizer = new wxFlexGridSizer(1);
1154 sizer -> Add( spreadResetBtn , 1, wxGROW );
1155 sizer -> Add( spreadAddBtn , 1, wxGROW );
1156 sizer -> Add( spreadGoBtn , 1, wxGROW );
1157 sizer -> Add( _wxtextctrlTest , 1, wxGROW );
1159 panel->SetSizer( sizer );
1160 panel->SetSize( sizepanel );
1161 panel->SetAutoLayout( true );
1165 if (_TestFrame->IsShown()==true)
1167 _TestFrame->Show(false);
1169 _TestFrame->Show(true);
1174 void wxContourEventHandler::onTestReset( wxCommandEvent& event )
1176 _wxtextctrlTest->SetValue(_T(""));
1177 _contourPropagation->resetAppend();
1180 //------------------------------------------------------------------------------------------------------------
1181 void wxContourEventHandler::onTestAdd( wxCommandEvent& event )
1183 std::vector<double> vecX;
1184 std::vector<double> vecY;
1185 std::vector<double> vecZ;
1186 _theViewPanel->getSceneManager()->GetPointsOfActualContour( &vecX , &vecY , &vecZ );
1188 if (vecX.size()!=0){
1189 std::vector<int> tempVector;
1190 _instantPanel->getInstant( tempVector );
1191 int i,size=vecZ.size();
1192 int actualSlice = tempVector[1];
1193 for ( i=0 ; i<size ; i++ )
1195 vecZ[i] = actualSlice;
1198 _contourPropagation->appendContour(&vecX , &vecY , &vecZ);
1200 newstring.append(_wxtextctrlTest->GetValue());
1201 newstring.append(_T(" "));
1202 newstring.append(wxString(intToString(actualSlice).c_str(),wxConvUTF8));
1203 //newstring.Printf(_T("%s %d -"),, );
1204 newstring.append(_T(" -"));
1205 _wxtextctrlTest->SetValue(newstring);
1209 //------------------------------------------------------------------------------------------------------------
1210 void wxContourEventHandler::onTestGo( wxCommandEvent& event )
1212 std::vector<double> vecX;
1213 std::vector<double> vecY;
1214 std::vector<double> vecZ;
1215 std::vector<int> size;
1217 std::vector<double> vecCtrlPointX;
1218 std::vector<double> vecCtrlPointY;
1219 std::vector<double> vecCtrlPointZ;
1221 //Getting the points of the actual contour
1223 _contourPropagation->GetKeyContours(&vecX , &vecY , &vecZ, &size);
1224 for(int i = 0; i < vecX.size();i++){
1228 /*std::vector<double> vecX1;
1229 std::vector<double> vecY1;
1230 std::vector<double> vecZ1;
1231 _theViewPanel->getSceneManager()->GetPointsOfActualContour( &vecX1 , &vecY1 , &vecZ1 );
1233 std::ofstream file1;
1234 file1.open( "Temp.txt" );
1237 for(int i = 0; i < vecX.size(); i++){
1238 file1<<vecX[i] <<" X1 "<< vecX1[i] <<" Y "<<vecY[i] <<" Y1 "<< vecY1[i] <<" Z "<<vecZ[i] <<" Z1 "<< vecZ1[i]<<std::endl;
1246 //Setting the points of the contour
1248 ExtractControlPoints2D *extractcontrolpoints2d = new ExtractControlPoints2D();
1249 extractcontrolpoints2d->SetContour( &vecX , &vecY , &vecZ );
1251 //Getting the control points of the contour by method A
1253 extractcontrolpoints2d->GetInitialControlPoints( &vecCtrlPointX , &vecCtrlPointY , &vecCtrlPointZ );
1255 std::vector<int> actualInstantVector;
1256 _instantPanel->getInstant( actualInstantVector );
1257 actualInstantVector[1]= this->_theViewPanel->GetZ();
1263 //Adding the Contour to the scene
1265 manualContourModel *manModelContour = new manualContourModel();
1266 int j,sizeCtrPt = vecCtrlPointX.size();
1268 for (j=0 ; j<sizeCtrPt ; j++)
1270 manModelContour->AddPoint( vecCtrlPointX[j] , vecCtrlPointY[j] , vecCtrlPointZ[j] );
1272 std::string theName;
1273 theName = _modelManager->createOutline( manModelContour, actualInstantVector );
1274 bool addedModel = theName.compare("") != 0;
1277 double spc[3];//Si no hay imagen pero hay contornos que spacing se pone por default
1278 this->_theViewPanel->getSpacing(spc);
1279 //Adding the manualContourControler to interface objects structure
1280 //Adding the manualViewContour to interface objects structure
1281 //_theViewPanel->getSceneManager()->setControlActiveStateOfALL( false );//This call is being done here because if the ROI is created underneath the previously created ROIS will still be active.
1282 _theViewPanel->getSceneManager()->configureViewControlTo( theName, manModelContour,spc,1 ) ;
1287 //------------------------------------------------------------------------------------------------------------
1288 void wxContourEventHandler::FillGridWithContoursInformation()
1290 wxString tempString;
1292 _grid->SetColLabelValue(0, _T("A") );
1293 _grid->SetColLabelValue(1, _T("B") );
1294 _grid->SetColLabelValue(2, _T("C") );
1295 _grid->SetColLabelValue(3, _T("D") );
1296 _grid->SetColLabelValue(4, _T("E") );
1297 _grid->SetColLabelValue(5, _T("F") );
1299 std::vector<int> tempVector;
1300 _instantPanel->getInstant( tempVector );
1302 int z,sizeZ = _theViewPanel->getSceneManager()->GetImageDataSizeZ();
1303 int ii,sizeLstContourThings;
1304 for ( z=0 ; z<sizeZ ; z++)
1307 Instant instant(&tempVector);
1308 std::vector<ContourThing**> lstContourThings = this->_modelManager->getOutlinesAtInstant( &instant );
1310 sizeLstContourThings = lstContourThings.size();
1311 tempString.Printf(_T("%d - %d"),z, sizeLstContourThings);
1312 _grid->SetRowLabelValue(z, tempString );
1314 for (ii=0 ; ii<sizeLstContourThings ; ii++)
1316 ContourThing **contourthing = lstContourThings[ii];
1317 tempString = wxString((*contourthing)->getName().c_str(),wxConvUTF8) ;
1318 _grid->SetCellValue( z, ii, tempString );
1325 //------------------------------------------------------------------------------------------------------------
1326 std::vector<manualContourModel*> wxContourEventHandler::ExploseEachModel( std::vector<manualContourModel*> lstManConMod )
1328 std::vector<manualContourModel*> lstTmp;
1329 std::vector<manualContourModel*> lstResult;
1331 int i,iSize=lstManConMod.size();
1332 for (i=0;i<iSize;i++)
1334 lstTmp = lstManConMod[i]->ExploseModel();
1335 jSize=lstTmp.size();
1336 for (j=0;j<jSize;j++)
1338 lstResult.push_back( lstTmp[j] );
1344 //------------------------------------------------------------------------------------------------------------
1345 void wxContourEventHandler::onExtractInformation( wxCommandEvent& event )
1348 int maxContourGroup = 0;
1352 ContourExtractData *contourextractdata = new ContourExtractData();
1353 int typeContourGroup = this->_radiolstboxContourGroup->GetSelection();
1354 contourextractdata ->SetTypeOperation( typeContourGroup % 3 );
1356 std::vector<manualContourModel*> lstManConMod;
1357 std::vector<manualContourModel*> lstManConModTmp;
1358 std::vector<manualContourModel*> lstManConModExp;
1359 std::vector<double> pLstValue;
1360 std::vector<double> pLstValuePosX;
1361 std::vector<double> pLstValuePosY;
1362 std::vector<double> pLstValuePosZ;
1365 int resultGrayRangeCount;
1368 double resultAverage;
1369 double resultStandardeviation;
1371 std::vector<int> tempVector;
1372 _instantPanel->getInstant( tempVector );
1374 vtkImageData *imagedata = _theViewPanel->getSceneManager()->GetImageData();
1375 int sizeZ = _theViewPanel->getSceneManager()->GetImageDataSizeZ();
1377 int ii,sizeLstContourThings;
1386 if (_informationRadiobox->GetSelection()==0 ) // actual slice
1388 std::vector<int> tempVector;
1389 _instantPanel->getInstant( tempVector );
1390 int actualSlice = tempVector[1];
1394 if (_informationRadiobox->GetSelection()==1 ) // slice range
1396 minZ = _mbarrangeSliceInformation->GetStart();
1397 maxZ = _mbarrangeSliceInformation->GetEnd();
1399 if (_informationRadiobox->GetSelection()==2 ) // All slices
1405 totalZ = maxZ-minZ+1;
1406 contourextractdata->SetImage( imagedata);
1409 for ( z=minZ ; z<=maxZ ; z++ )
1411 porcent = 100.0* (z-minZ)/totalZ;
1412 tmpString.Printf(_T(" %d %c %d/%d %d"), (int)porcent , 37 , z-minZ+1, (int)totalZ ,z);
1413 _staticTextInformation->SetLabel(tmpString);
1415 //Extraction data from contours of each slice
1416 contourextractdata->SetZtoBeAnalys( z);
1419 Instant instant(&tempVector);
1420 std::vector<ContourThing**> lstContourThings = this->_modelManager->getOutlinesAtInstant( &instant );
1421 sizeLstContourThings = lstContourThings.size();
1423 lstManConMod.clear();
1424 for (ii=0 ; ii<sizeLstContourThings ; ii++)
1426 ContourThing **contourthing = lstContourThings[ii];
1427 lstManConMod.push_back( (*contourthing)->getModel() );
1429 lstManConModExp = ExploseEachModel( lstManConMod );
1432 wxString tempString;
1433 tempString.Printf(_T("%d - %d"),z, sizeLstContourThings);
1434 _grid->SetRowLabelValue(z, tempString );
1436 int iContourGroup,sizeContourGroup;
1437 if (typeContourGroup==3) // contour separete
1439 sizeContourGroup=lstManConModExp.size();
1440 if ( maxContourGroup<sizeContourGroup )
1442 maxContourGroup=sizeContourGroup;
1444 } else { // contour AND OR XOR
1453 for( iContourGroup=0 ; iContourGroup<sizeContourGroup ; iContourGroup++ ){
1454 lstManConModTmp.clear();
1455 if (typeContourGroup==3) // contour separete
1457 lstManConModTmp.push_back( lstManConModExp[iContourGroup]);
1458 } else { // contour AND OR XOR
1459 lstManConModTmp = lstManConModExp;
1462 contourextractdata->SetLstManualContourModel( lstManConModTmp );
1465 pLstValuePosX.clear();
1466 pLstValuePosY.clear();
1467 pLstValuePosZ.clear();
1468 contourextractdata->GetValuesInsideCrown( &pLstValue,
1472 // Statistics of each slice.
1473 contourextractdata->Statistics( &pLstValue,
1474 _mbarrangeRangeInformation->GetStart(),
1475 _mbarrangeRangeInformation->GetEnd(),
1476 &resultGrayRangeCount,
1481 &resultStandardeviation);
1482 if (_grid->GetNumberCols()<_numberOfVariablesStatistics*(iContourGroup+1) )
1484 _grid->AppendCols(_numberOfVariablesStatistics);
1487 tmpIntA=_numberOfVariablesStatistics*iContourGroup ;
1489 tempString.Printf(_T("%d"),resultSize);
1490 _grid->SetCellValue( z, tmpIntA + 0, tempString );
1491 tempString.Printf(_T("%d"),resultGrayRangeCount);
1492 _grid->SetCellValue( z, tmpIntA + 1, tempString );
1493 tempString.Printf(_T("%f"),resultMin);
1494 _grid->SetCellValue( z, tmpIntA + 2, tempString );
1495 tempString.Printf(_T("%f"),resultMax);
1496 _grid->SetCellValue( z, tmpIntA + 3, tempString );
1497 tempString.Printf(_T("%f"),resultAverage);
1498 _grid->SetCellValue( z, tmpIntA + 4, tempString );
1499 tempString.Printf(_T("%f"),resultStandardeviation);
1500 _grid->SetCellValue( z, tmpIntA + 5, tempString );
1502 } // for iContourGroup
1506 wxString tmpTitleString;
1508 for ( iTitleGroup=0 ; iTitleGroup<maxContourGroup ; iTitleGroup++ )
1510 tmpIntB =_numberOfVariablesStatistics*iTitleGroup;
1511 tmpTitleString.Printf(_T("%d-Size Data"),iTitleGroup);
1512 _grid->SetColLabelValue( tmpIntB + 0, tmpTitleString );
1513 _grid->SetColLabelValue( tmpIntB + 1, _T("Size Range") );
1514 _grid->SetColLabelValue( tmpIntB + 2, _T("Min") );
1515 _grid->SetColLabelValue( tmpIntB + 3, _T("Max") );
1516 _grid->SetColLabelValue( tmpIntB + 4, _T("Average") );
1517 _grid->SetColLabelValue( tmpIntB + 5, _T("St.Dev.") );
1518 _grid->SetColLabelValue( tmpIntB + 6, _T(" ") );
1521 _staticTextInformation->SetLabel( _T("") );
1522 delete contourextractdata;
1526 //------------------------------------------------------------------------------------------------------------
1527 void wxContourEventHandler::SaveValuesXYZ(std::string directory,std::string namefile)
1530 ContourExtractData *contourextractdata = new ContourExtractData();
1531 int typeContourGroup = this->_radiolstboxContourGroup->GetSelection();
1532 contourextractdata ->SetTypeOperation( typeContourGroup % 3 );
1534 std::vector<manualContourModel*> lstManConMod;
1535 std::vector<manualContourModel*> lstManConModTmp;
1536 std::vector<manualContourModel*> lstManConModExp;
1537 std::vector<double> pLstValue;
1538 std::vector<double> pLstValuePosX;
1539 std::vector<double> pLstValuePosY;
1540 std::vector<double> pLstValuePosZ;
1542 std::vector<int> tempVector;
1543 _instantPanel->getInstant( tempVector );
1545 vtkImageData *imagedata = _theViewPanel->getSceneManager()->GetImageData();
1546 int sizeZ = _theViewPanel->getSceneManager()->GetImageDataSizeZ();
1548 int ii,sizeLstContourThings;
1555 minZ = 0;// _mbarrange->GetStart();
1556 maxZ = sizeZ;//_mbarrange->GetEnd();
1557 totalZ = maxZ-minZ+1;
1559 contourextractdata->SetImage( imagedata);
1562 for ( z=0 ; z<sizeZ ; z++)
1565 porcent = 100.0* (z-minZ)/totalZ;
1567 tmpString.Printf(_T("Saving Values"));
1568 tmpString.Printf(_T(" %d %c %d/%d %d"), (int)porcent , 37 , z-minZ+1, (int)totalZ ,z);
1569 _staticTextInformation->SetLabel(tmpString);
1572 //Extraction data from contours of each slice
1573 contourextractdata->SetZtoBeAnalys( z);
1576 Instant instant(&tempVector);
1577 std::vector<ContourThing**> lstContourThings = this->_modelManager->getOutlinesAtInstant( &instant );
1578 sizeLstContourThings = lstContourThings.size();
1580 lstManConMod.clear();
1581 for (ii=0 ; ii<sizeLstContourThings ; ii++)
1583 ContourThing **contourthing = lstContourThings[ii];
1584 lstManConMod.push_back( (*contourthing)->getModel() );
1586 lstManConModExp = ExploseEachModel( lstManConMod );
1591 int iContourGroup,sizeContourGroup;
1592 if (typeContourGroup==3) // contour separete
1594 sizeContourGroup=lstManConModExp.size();
1595 } else { // contour AND OR XOR
1599 for( iContourGroup=0 ; iContourGroup<sizeContourGroup ; iContourGroup++ ){
1600 lstManConModTmp.clear();
1601 if (typeContourGroup==3) // contour separete
1603 lstManConModTmp.push_back( lstManConModExp[iContourGroup]);
1604 } else { // contour AND OR XOR
1605 lstManConModTmp = lstManConModExp;
1608 contourextractdata->SetLstManualContourModel( lstManConModTmp );
1611 pLstValuePosX.clear();
1612 pLstValuePosY.clear();
1613 pLstValuePosZ.clear();
1614 contourextractdata->GetValuesInsideCrown( &pLstValue,
1620 filename.Printf(_T("%s"),directory.c_str());
1621 filename.Printf(_T("\\"));
1622 filename.Printf(_T("%s"),namefile.c_str());
1623 filename.Printf(_T("-slice"));
1624 filename.Printf(_T("%d"),z);
1625 filename.Printf(_T("-cont"));
1626 filename.Printf(_T("%d"),iContourGroup);
1627 filename.Printf(_T(".txt"));
1628 FILE *pFile=fopen((const char *)filename.mb_str(),"w+");
1629 fprintf(pFile,"value \t x \t y \t z\n" );
1630 int iLstValue,sizeLstValue=pLstValue.size();
1631 for (iLstValue=0 ; iLstValue<sizeLstValue ; iLstValue++ )
1633 fprintf(pFile,"%f\t %f\t %f\t %f\n", (float)pLstValue[iLstValue] , (float)pLstValuePosX[iLstValue], (float)pLstValuePosY[iLstValue], (float)z );
1636 } // for iContourGroup
1638 _staticTextInformation->SetLabel( _T("") );
1639 delete contourextractdata;
1643 //------------------------------------------------------------------------------------------------------------
1644 void wxContourEventHandler::SaveImageResult(std::string directory,std::string namefile)
1647 ContourExtractData *contourextractdata = new ContourExtractData( true );
1648 int typeContourGroup = this->_radiolstboxContourGroup->GetSelection();
1649 if (typeContourGroup==3)
1653 contourextractdata ->SetTypeOperation( typeContourGroup % 3 );
1655 std::vector<manualContourModel*> lstManConMod;
1656 std::vector<manualContourModel*> lstManConModTmp;
1657 std::vector<manualContourModel*> lstManConModExp;
1659 std::vector<int> tempVector;
1660 _instantPanel->getInstant( tempVector );
1662 vtkImageData *imagedata = _theViewPanel->getSceneManager()->GetImageData();
1663 int sizeZ = _theViewPanel->getSceneManager()->GetImageDataSizeZ();
1665 int ii,sizeLstContourThings;
1674 minZ = 0;// _mbarrange->GetStart();
1675 maxZ = sizeZ;//_mbarrange->GetEnd();
1676 totalZ = maxZ-minZ+1;
1678 contourextractdata->SetImage( imagedata);
1681 for ( z=0 ; z<sizeZ ; z++)
1684 porcent = 100.0* (z-minZ)/totalZ;
1685 tmpString.Printf(_T("Saving Values"));
1686 tmpString.Printf(_T("%d %c %d/%d %d"), (int)porcent , 37 , z-minZ+1, (int)totalZ ,z);
1687 _staticTextInformation->SetLabel(tmpString);
1689 //Extraction data from contours of each slice
1690 contourextractdata->SetZtoBeAnalys( z);
1693 Instant instant(&tempVector);
1694 std::vector<ContourThing**> lstContourThings = this->_modelManager->getOutlinesAtInstant( &instant );
1695 sizeLstContourThings = lstContourThings.size();
1697 lstManConMod.clear();
1698 for (ii=0 ; ii<sizeLstContourThings ; ii++)
1700 ContourThing **contourthing = lstContourThings[ii];
1701 lstManConMod.push_back( (*contourthing)->getModel() );
1703 lstManConModExp = ExploseEachModel( lstManConMod );
1706 int iContourGroup,sizeContourGroup;
1707 if (typeContourGroup==3) // contour separete
1709 sizeContourGroup=lstManConModExp.size();
1710 } else { // contour AND OR XOR
1714 for( iContourGroup=0 ; iContourGroup<sizeContourGroup ; iContourGroup++ ){
1715 lstManConModTmp.clear();
1716 if (typeContourGroup==3) // contour separete
1718 lstManConModTmp.push_back( lstManConModExp[iContourGroup]);
1719 } else { // contour AND OR XOR
1720 lstManConModTmp = lstManConModExp;
1723 contourextractdata->SetLstManualContourModel( lstManConModTmp );
1726 // for (ii=0 ; ii<sizeLstContourThings ; ii++)
1728 // ContourThing **contourthing = lstContourThings[ii];
1729 // lstManConMod.push_back( (*contourthing)->getModel() );
1731 // contourextractdata->SetLstManualContourModel( lstManConMod );
1733 contourextractdata->CalculateImageResult(); // with actual Z
1735 } // for iContourGroup
1740 //filename.Printf(_T("%s\\%s-Value.mhd",directory.c_str(),namefile.c_str(),z);
1741 filename.Printf(_T("%s"),directory.c_str());
1742 filename.Printf(_T("\\"));
1743 filename.Printf(_T("%s"),namefile.c_str());
1744 filename.Printf(_T("-Value.mhd"));
1747 vtkMetaImageWriter *writerValueImage = vtkMetaImageWriter::New( );
1748 writerValueImage->SetInput( contourextractdata->GetVtkImageValueResult() );
1749 writerValueImage->SetFileName( (const char *)filename.mb_str() );
1750 writerValueImage->SetFileDimensionality( 3 );
1751 writerValueImage->Write( );
1754 // filename.Printf("%s\\%s-Mask.mhd",directory.c_str(),namefile.c_str(),z);
1755 filename.Printf(_T("%s"),directory.c_str());
1756 filename.Printf(_T("\\"));
1757 filename.Printf(_T("%s"),namefile.c_str());
1758 filename.Printf(_T("-Mask.mhd"));
1759 vtkMetaImageWriter *writerMaskImage = vtkMetaImageWriter::New( );
1760 writerMaskImage->SetInput( contourextractdata->GetVtkImageMaskResult() );
1761 writerMaskImage->SetFileName( (const char *)filename.mb_str() );
1762 writerMaskImage->SetFileDimensionality( 3 );
1763 writerMaskImage->Write( );
1765 _staticTextInformation->SetLabel( _T("") );
1766 delete contourextractdata;
1770 //------------------------------------------------------------------------------------------------------------
1771 void wxContourEventHandler::onInformationContourLabels( wxCommandEvent& event )
1774 FillGridWithContoursInformation();
1778 //------------------------------------------------------------------------------------------------------------
1779 void wxContourEventHandler::onSaveResults( wxCommandEvent& event )
1781 wxFileDialog dialog(_InformationContourFrame, _T("Choose a file"), _T(""), _T(""), _T("*.txt"), wxSAVE );
1782 if (dialog.ShowModal() == wxID_OK)
1784 onExtractInformation( event );
1785 std::string directory=(const char *)(dialog.GetDirectory().mb_str());
1786 std::string namefile=(const char *)(dialog.GetFilename().mb_str());
1788 SaveValuesXYZ( directory , namefile );
1789 SaveImageResult( directory , namefile );
1791 std::string filename = (const char *)(dialog.GetPath().mb_str() );
1792 FILE *pFile=fopen(filename.c_str(),"w+");
1794 int sizeZ = _theViewPanel->getSceneManager()->GetImageDataSizeZ();
1797 int i,j,maxX,maxY=sizeZ;
1798 maxX=this->_grid->GetNumberCols();
1800 int iTitle,sizeTitle = (maxX / _numberOfVariablesStatistics);
1801 for ( iTitle=0; iTitle<sizeTitle ; iTitle++)
1803 fprintf(pFile,"-- \t %d-Size \t SizeRange \t Min \t Max \t Ave \t StDv \t" , iTitle,tmpString.c_str() );
1805 fprintf(pFile,"\n" );
1809 for ( j=0; j<maxY ; j++)
1811 fprintf(pFile,"%d\t" , j );
1812 for (i=0 ; i<maxX ; i++){
1813 tmpString = _grid->GetCellValue( j , i );
1814 fprintf(pFile,"%s\t" , (const char *)(tmpString.mb_str()) );
1816 fprintf(pFile,"\n" );
1826 //------------------------------------------------------------------------------------------------------------
1827 void wxContourEventHandler::onInformationContourFrame()
1829 if (_InformationContourFrame==NULL)
1831 _InformationContourFrame = new wxFrame (_theViewPanel, -1,_T(" Information "), wxDefaultPosition, wxDefaultSize, wxFRAME_TOOL_WINDOW|wxSYSTEM_MENU | wxCAPTION | wxCLIP_CHILDREN |wxFRAME_FLOAT_ON_PARENT | wxRESIZE_BORDER );
1832 _InformationContourFrame->SetSize( wxSize(500,450) );
1833 wxSize sizepanel(200,300);
1834 wxPanel *panel = getInformationPanel(_InformationContourFrame);
1835 //JCP 13-10-09 Grouping the panel in a method
1836 /*new wxPanel(_InformationContourFrame,-1,wxDefaultPosition, wxDefaultSize,wxTAB_TRAVERSAL);
1838 wxString lstOptions[4];
1839 lstOptions[0]=_T("Actual Slice");
1840 lstOptions[1]=_T("Range Slices");
1841 lstOptions[2]=_T("All Slices");
1842 _informationRadiobox = new wxRadioBox(panel, -1, _T("Slice analysis"), wxDefaultPosition, wxSize(270,45), 3 , lstOptions, 3, wxRA_SPECIFY_COLS);
1844 wxString lstOptContOperation[5];
1845 lstOptContOperation[0]=_T("AND");
1846 lstOptContOperation[1]=_T("OR");
1847 lstOptContOperation[2]=_T("XOR");
1848 lstOptContOperation[3]=_T("ALL");
1849 _radiolstboxContourGroup = new wxRadioBox(panel, -1, _T("Contour group"), wxDefaultPosition, wxSize(270,45), 4 , lstOptContOperation, 4, wxRA_SPECIFY_COLS);
1851 wxButton *informationContourLabelsBtn = new wxButton(panel,-1,_T("Contour labels"),wxDefaultPosition, wxSize(140,35) );
1852 informationContourLabelsBtn->SetEventHandler( this );
1853 Connect( informationContourLabelsBtn->GetId(), wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &wxContourEventHandler::onInformationContourLabels );
1855 wxButton *statisticsContourBtn = new wxButton(panel,-1,_T("Contour statistics"),wxDefaultPosition, wxSize(140,35) );
1856 statisticsContourBtn->SetEventHandler( this );
1857 Connect( statisticsContourBtn->GetId(), wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &wxContourEventHandler::onExtractInformation );
1859 wxButton *saveResultsBtn = new wxButton(panel,-1,_T("Save statistics results"),wxDefaultPosition, wxSize(140,35) );
1860 saveResultsBtn->SetEventHandler( this );
1861 Connect( saveResultsBtn->GetId(), wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &wxContourEventHandler::onSaveResults );
1864 int sizeZ = this->_theViewPanel->getSceneManager()->GetImageDataSizeZ();
1865 _mbarrangeSliceInformation = new mBarRange(panel,65,65);
1866 _mbarrangeSliceInformation->SetMin(0);
1867 _mbarrangeSliceInformation->SetStart(0);
1868 _mbarrangeSliceInformation-> SetOrientation( true );
1869 _mbarrangeSliceInformation-> setActiveStateTo(true);
1870 _mbarrangeSliceInformation-> setVisibleLabels( true );
1871 _mbarrangeSliceInformation-> setDeviceEndMargin(10);
1872 _mbarrangeSliceInformation-> setRepresentedValues( 0 , sizeZ-1 );
1873 _mbarrangeSliceInformation-> setDeviceBlitStart(10,10);
1874 _mbarrangeSliceInformation-> setIfWithActualDrawed( false );
1875 _mbarrangeSliceInformation-> SetStart( 0 );
1876 _mbarrangeSliceInformation-> SetEnd( sizeZ-1 );
1880 this->_theViewPanel->getSceneManager()->GetImageDataRange(range);
1881 _mbarrangeRangeInformation = new mBarRange(panel,65,65);
1882 _mbarrangeRangeInformation->SetMin(0);
1883 _mbarrangeRangeInformation->SetStart(0);
1884 _mbarrangeRangeInformation-> SetOrientation( true );
1885 _mbarrangeRangeInformation-> setActiveStateTo(true);
1886 _mbarrangeRangeInformation-> setVisibleLabels( true );
1887 _mbarrangeRangeInformation-> setDeviceEndMargin(10);
1888 _mbarrangeRangeInformation-> setRepresentedValues( range[0] , range[1] );
1889 _mbarrangeRangeInformation-> setDeviceBlitStart(10,10);
1890 _mbarrangeRangeInformation-> setIfWithActualDrawed( false );
1891 _mbarrangeRangeInformation-> SetStart( range[0] );
1892 _mbarrangeRangeInformation-> SetEnd( range[1] );
1895 _staticTextInformation = new wxStaticText(panel,-1,_T(" "));
1898 // wxButton *XXXXXXXBtn = new wxButton(panel,-1,_T("Statistics"),wxDefaultPosition, wxSize(180,35) );
1899 // XXXXXXXBtn->SetEventHandler( this );
1900 // Connect( XXXXXXXBtn->GetId(), wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &wxContourEventHandler::onXXXXX );
1903 _grid = new wxGrid( panel,
1906 wxSize( 100, 100 ) );
1908 int i,gridCol=10,gridRow=sizeZ;
1909 _grid->CreateGrid( 0, 0 );
1910 _grid->AppendRows(gridRow);
1911 _grid->AppendCols(gridCol);
1913 for (i=0;i<gridRow;i++)
1915 _grid->SetRowLabelValue(i, _T(" ") );
1917 // _grid->SetColLabelSize(0);
1920 FillGridWithContoursInformation();
1922 wxFlexGridSizer * sizerA = new wxFlexGridSizer(10);
1923 sizerA->Add( _informationRadiobox , 1, wxALL ,2 );
1924 sizerA->Add( _radiolstboxContourGroup , 1, wxALL ,2 );
1926 wxFlexGridSizer * sizerB = new wxFlexGridSizer(10);
1927 sizerB->Add( informationContourLabelsBtn , 1, wxALL ,2 );
1928 sizerB->Add( statisticsContourBtn , 1, wxALL ,2 );
1929 sizerB->Add( saveResultsBtn , 1, wxALL ,2 );
1931 wxFlexGridSizer * sizer = new wxFlexGridSizer(1);
1932 sizer->AddGrowableCol(0);
1933 sizer->AddGrowableRow(7);
1934 sizer->Add( sizerA , 1, wxALL , 0 );
1935 sizer->Add( new wxStaticText(panel ,-1,_T("Slice Range")) , 1, wxALL , 0 );
1936 sizer->Add( _mbarrangeSliceInformation , 1, wxALL|wxGROW , 2 );
1937 sizer->Add( new wxStaticText(panel ,-1,_T("Gray Range")) , 1, wxALL , 0 );
1938 sizer->Add( _mbarrangeRangeInformation , 1, wxALL|wxGROW , 2 );
1939 sizer->Add( sizerB , 1, wxALL , 0 );
1940 sizer->Add( _staticTextInformation , 1, wxALL , 0 );
1941 sizer->Add( _grid , 1, wxEXPAND , 0 );
1945 panel->SetSizer( sizer );
1946 panel->SetSize( wxSize(1500,1500) );
1947 //panel->SetBackgroundColour( wxColour(100,100,100) );
1948 panel->SetAutoLayout( true );
1951 wxBoxSizer * sizerPanel = new wxBoxSizer(wxHORIZONTAL);
1953 // sizerPanel->AddGrowableCol(0);
1954 // sizerPanel->AddGrowableRow(0);
1957 //sizerPanel -> Add( sizer , 1, wxEXPAND ,0);
1958 sizerPanel -> Add( panel->GetSizer() , 1, wxEXPAND ,0);
1963 _InformationContourFrame->SetSizer( sizerPanel );
1964 _InformationContourFrame->SetAutoLayout( true );
1965 _InformationContourFrame->Layout();
1967 _InformationContourFrame->Show();
1969 if (_InformationContourFrame->IsShown()==true)
1971 _InformationContourFrame->Show(false);
1973 FillGridWithContoursInformation();
1974 _InformationContourFrame->Show(true);
1979 wxPanel* wxContourEventHandler::getInformationPanel(wxWindow* parent){
1980 wxPanel *panel = new wxPanel(parent,-1,wxDefaultPosition, wxDefaultSize,wxTAB_TRAVERSAL);
1982 wxString lstOptions[4];
1983 lstOptions[0]=_T("Actual Slice");
1984 lstOptions[1]=_T("Range Slices");
1985 lstOptions[2]=_T("All Slices");
1986 _informationRadiobox = new wxRadioBox(panel, -1, _T("Slice analysis"), wxDefaultPosition, wxSize(270,45), 3 , lstOptions, 3, wxRA_SPECIFY_COLS);
1988 wxString lstOptContOperation[5];
1989 lstOptContOperation[0]=_T("AND");
1990 lstOptContOperation[1]=_T("OR");
1991 lstOptContOperation[2]=_T("XOR");
1992 lstOptContOperation[3]=_T("ALL");
1993 _radiolstboxContourGroup = new wxRadioBox(panel, -1, _T("Contour group"), wxDefaultPosition, wxSize(270,45), 4 , lstOptContOperation, 4, wxRA_SPECIFY_COLS);
1995 wxButton *informationContourLabelsBtn = new wxButton(panel,-1,_T("Contour labels"),wxDefaultPosition, wxSize(140,35) );
1996 informationContourLabelsBtn->SetEventHandler( this );
1997 Connect( informationContourLabelsBtn->GetId(), wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &wxContourEventHandler::onInformationContourLabels );
1999 wxButton *statisticsContourBtn = new wxButton(panel,-1,_T("Contour statistics"),wxDefaultPosition, wxSize(140,35) );
2000 statisticsContourBtn->SetEventHandler( this );
2001 Connect( statisticsContourBtn->GetId(), wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &wxContourEventHandler::onExtractInformation );
2003 wxButton *saveResultsBtn = new wxButton(panel,-1,_T("Save statistics results"),wxDefaultPosition, wxSize(140,35) );
2004 saveResultsBtn->SetEventHandler( this );
2005 Connect( saveResultsBtn->GetId(), wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &wxContourEventHandler::onSaveResults );
2008 int sizeZ = this->_theViewPanel->getSceneManager()->GetImageDataSizeZ();
2009 _mbarrangeSliceInformation = new mBarRange(panel,65,65);
2010 _mbarrangeSliceInformation->SetMin(0);
2011 _mbarrangeSliceInformation->SetStart(0);
2012 _mbarrangeSliceInformation-> SetOrientation( true );
2013 _mbarrangeSliceInformation-> setActiveStateTo(true);
2014 _mbarrangeSliceInformation-> setVisibleLabels( true );
2015 _mbarrangeSliceInformation-> setDeviceEndMargin(10);
2016 _mbarrangeSliceInformation-> setRepresentedValues( 0 , sizeZ-1 );
2017 _mbarrangeSliceInformation-> setDeviceBlitStart(10,10);
2018 _mbarrangeSliceInformation-> setIfWithActualDrawed( false );
2019 _mbarrangeSliceInformation-> SetStart( 0 );
2020 _mbarrangeSliceInformation-> SetEnd( sizeZ-1 );
2024 this->_theViewPanel->getSceneManager()->GetImageDataRange(range);
2025 _mbarrangeRangeInformation = new mBarRange(panel,65,65);
2026 _mbarrangeRangeInformation->SetMin(0);
2027 _mbarrangeRangeInformation->SetStart(0);
2028 _mbarrangeRangeInformation-> SetOrientation( true );
2029 _mbarrangeRangeInformation-> setActiveStateTo(true);
2030 _mbarrangeRangeInformation-> setVisibleLabels( true );
2031 _mbarrangeRangeInformation-> setDeviceEndMargin(10);
2032 _mbarrangeRangeInformation-> setRepresentedValues( range[0] , range[1] );
2033 _mbarrangeRangeInformation-> setDeviceBlitStart(10,10);
2034 _mbarrangeRangeInformation-> setIfWithActualDrawed( false );
2035 _mbarrangeRangeInformation-> SetStart( range[0] );
2036 _mbarrangeRangeInformation-> SetEnd( range[1] );
2039 _staticTextInformation = new wxStaticText(panel,-1,_T(" "));
2042 // wxButton *XXXXXXXBtn = new wxButton(panel,-1,_T("Statistics"),wxDefaultPosition, wxSize(180,35) );
2043 // XXXXXXXBtn->SetEventHandler( this );
2044 // Connect( XXXXXXXBtn->GetId(), wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &wxContourEventHandler::onXXXXX );
2047 _grid = new wxGrid( panel,
2050 wxSize( 100, 100 ) );
2052 int i,gridCol=10,gridRow=sizeZ;
2053 _grid->CreateGrid( 0, 0 );
2054 _grid->AppendRows(gridRow);
2055 _grid->AppendCols(gridCol);
2057 for (i=0;i<gridRow;i++)
2059 _grid->SetRowLabelValue(i, _T(" ") );
2061 // _grid->SetColLabelSize(0);
2064 FillGridWithContoursInformation();
2066 wxFlexGridSizer * sizerA = new wxFlexGridSizer(10);
2067 sizerA->Add( _informationRadiobox , 1, wxALL ,2 );
2068 sizerA->Add( _radiolstboxContourGroup , 1, wxALL ,2 );
2070 wxFlexGridSizer * sizerB = new wxFlexGridSizer(10);
2071 sizerB->Add( informationContourLabelsBtn , 1, wxALL ,2 );
2072 sizerB->Add( statisticsContourBtn , 1, wxALL ,2 );
2073 sizerB->Add( saveResultsBtn , 1, wxALL ,2 );
2075 wxFlexGridSizer * sizer = new wxFlexGridSizer(1);
2076 sizer->AddGrowableCol(0);
2077 sizer->AddGrowableRow(7);
2078 sizer->Add( sizerA , 1, wxALL , 0 );
2079 sizer->Add( new wxStaticText(panel ,-1,_T("Slice Range")) , 1, wxALL , 0 );
2080 sizer->Add( _mbarrangeSliceInformation , 1, wxALL|wxGROW , 2 );
2081 sizer->Add( new wxStaticText(panel ,-1,_T("Gray Range")) , 1, wxALL , 0 );
2082 sizer->Add( _mbarrangeRangeInformation , 1, wxALL|wxGROW , 2 );
2083 sizer->Add( sizerB , 1, wxALL , 0 );
2084 sizer->Add( _staticTextInformation , 1, wxALL , 0 );
2085 sizer->Add( _grid , 1, wxEXPAND , 0 );
2089 panel->SetSizer( sizer );
2090 panel->SetSize( wxSize(1500,1500) );
2091 //panel->SetBackgroundColour( wxColour(100,100,100) );
2092 panel->SetAutoLayout( true );
2096 //------------------------------------------------------------------------------------------------------------
2097 void wxContourEventHandler :: onSpreadInDepth( std::vector<std::string> & keyNamesVector )
2101 //------------------------------------------------------------------------------------------------------------
2102 void wxContourEventHandler :: onOutline_Union_Of( std::vector<std::string> & keyNamesVector )
2106 //------------------------------------------------------------------------------------------------------------
2107 void wxContourEventHandler :: onOutline_Intersection_Of( std::vector<std::string> & keyNamesVector )
2111 //------------------------------------------------------------------------------------------------------------
2112 void wxContourEventHandler :: onOutline_Combination_Of( std::vector<std::string> & keyNamesVector )
2116 //------------------------------------------------------------------------------------------------------------
2117 void wxContourEventHandler :: onOutline_Fragmentation_Of( std::vector<std::string> & keyNamesVector )
2121 //------------------------------------------------------------------------------------------------------------
2122 void wxContourEventHandler :: onOutline_Agrupation_Of( std::vector<std::string> & keyNamesVector )
2126 //------------------------------------------------------------------------------------------------------------
2127 void wxContourEventHandler :: onCopyOutlines( std::vector<std::string> & keyNamesVector )
2129 std::vector<int> tempVector;
2130 _instantPanel->getInstant( tempVector );
2131 _performingOperation->reset();
2132 _performingOperation->setStartCommand( (char)wxContour_ActionCommandsID::COPY_TOOL );
2133 _performingOperation->setStartOperationInstantVector( tempVector );
2134 _performingOperation->setKeyNamesOperationElems( keyNamesVector );
2137 //------------------------------------------------------------------------------------------------------------
2138 void wxContourEventHandler :: onPasteOutlines( )
2140 char theStartCommand = _performingOperation->getStartCommand();
2141 if ( theStartCommand == wxContour_ActionCommandsID::COPY_TOOL )
2143 //JCP 20-10-08 Undo redo implementation
2145 //JCP 20-10-08 Undo redo implementation
2148 std::vector<int> tempVector;
2149 _instantPanel->getInstant( tempVector );
2150 _performingOperation->setEndOperationInstantVector ( tempVector );
2151 std::vector<std::string> elems = _performingOperation->getKeyNamesOperationElems();
2152 int i,size = elems.size();
2153 for( i=0; i<size; i++ )
2155 createCopyContourOf( elems[i], tempVector, i>0 );
2162 //------------------------------------------------------------------------------------------------------------
2163 void wxContourEventHandler :: onShowOutlines( std::vector<std::string> & keyNamesVector )
2167 //------------------------------------------------------------------------------------------------------------
2168 void wxContourEventHandler :: onHideOutlines( std::vector<std::string> & keyNamesVector )
2172 //------------------------------------------------------------------------------------------------------------
2173 void wxContourEventHandler :: onSelectOutlines( std::vector<std::string> & keyNamesVector )
2175 //if( keyNamesVector.empty() )
2177 _theViewPanel->getSceneManager()->drawSelectionROI( );
2181 int ok = keyNamesVector.size();
2182 _theViewPanel->getSceneManager()->selectObjects( keyNamesVector );
2183 std::string name = keyNamesVector[0];
2186 _theViewPanel->getSceneManager()->drawSelectionROI( );
2187 std::vector<std::string> currentSelection = _theViewPanel->getSceneManager()->getSelectedObjects();
2188 int ok = currentSelection.size();
2189 _theViewPanel->getSceneManager()->selectObjects( currentSelection );*/
2191 //------------------------------------------------------------------------------------------------------------
2192 void wxContourEventHandler :: onEditOutlines( std::vector<std::string> & keyNamesVector )
2196 //------------------------------------------------------------------------------------------------------------
2198 //------------------------------------------------------------------------------------------------------------
2199 void wxContourEventHandler :: deleteContour( std::string theKeyName )
2201 manualContourModel * cModel;
2202 manualViewBaseContour * cViewer;
2203 manualContourBaseControler * cControler;
2205 ContourWrap_ViewControl *conwrapviewControl = _theViewPanel->getSceneManager()->getContourWrap_ViewControlOf( theKeyName );
2206 cControler = conwrapviewControl->getControler();
2207 int ispartofstaticlst= _modelManager->IsPartOfStaticList(theKeyName);
2208 if ((cControler!=NULL) && (cControler->IsEditable()==false) && (ispartofstaticlst==-1) )
2210 _theViewPanel->getSceneManager()->removeFromScene( theKeyName );
2211 cModel = _modelManager->getOutlineByKeyName(theKeyName)->getModel();
2212 _modelManager->removeOutline( theKeyName );
2213 cViewer = conwrapviewControl->getViewer();
2214 _theViewPanel->getSceneManager()->removeWrap( theKeyName );
2216 //FILE *ff = fopen("c:/temp/wxVtkBaseView_SceneManagerStadistics.txt","a+");
2217 //fprintf(ff,"EED wxContourEventHandler::deleteContours() \n" );
2218 //fprintf(ff," %s %p\n",keyNamesVector[i].c_str(), cControler );
2226 //------------------------------------------------------------------------------------------------------------
2227 void wxContourEventHandler :: deleteContours( std::vector<std::string> keyNamesVector )
2229 int i,size=keyNamesVector.size();
2230 for (i=0;i<size;i++)
2232 deleteContour( keyNamesVector[i] );
2236 //------------------------------------------------------------------------------------------------------------
2237 void wxContourEventHandler :: deleteAllContours( )
2240 std::vector<int> tempVector;
2241 _instantPanel->getInstant( tempVector );
2243 //JCP --08-09-2008 When using a diferent interface the _mbarrangeDeleteAll might not be initialize
2244 // the values in GetStart and GetEnd will then not be initialize also.
2245 // We use instead the values given when initializing the _deletepanel.
2247 //int minZ = _mbarrangeDeleteAll->GetStart();
2248 //int maxZ = _mbarrangeDeleteAll->GetEnd();
2252 maxZ = _theViewPanel->getSceneManager()->GetImageDataSizeZ();
2256 _theViewPanel->getSceneManager()->removeSceneContours( );
2257 _modelManager->removeAllOutlines();
2258 _theViewPanel->getSceneManager()->removeAllOutlines();
2261 if ( (minZ==0) && (maxZ==_mbarrangeDeleteAll->GetMax() ))
2263 _theViewPanel->getSceneManager()->removeSceneContours( );
2264 _modelManager->removeAllOutlines();
2265 _theViewPanel->getSceneManager()->removeAllOutlines();
2268 for ( z=minZ ; z<=maxZ ; z++)
2271 Instant instant(&tempVector);
2272 std::vector<ContourThing**> lstContourThings = this->_modelManager->getOutlinesAtInstant( &instant );
2274 sizeLstContourThings = lstContourThings.size();
2275 for (ii=0 ; ii<sizeLstContourThings ; ii++)
2277 ContourThing **contourthing = lstContourThings[ii];
2278 deleteContour( (*contourthing)->getName() );
2285 //------------------------------------------------------------------------------------------------------------
2286 void wxContourEventHandler::openContours( FILE *pFile, bool staticContour )
2289 fscanf(pFile,"%s",tmp); // NumberOfContours
2290 fscanf(pFile,"%s",tmp); // ##
2291 int numberOfContours = atoi(tmp);
2293 std::vector<int> instantVector;
2294 int typeContourModel;
2295 manualContourModel *manModelContour;
2299 for (i=0;i<numberOfContours;i++)
2301 instantVector.clear();
2302 fscanf(pFile,"%s",tmp); // Instant
2304 fscanf(pFile,"%s",tmp); // 1
2305 instantVector.push_back( atoi(tmp) );
2306 fscanf(pFile,"%s",tmp); // 2
2307 instantVector.push_back( atoi(tmp) );
2308 fscanf(pFile,"%s",tmp); // 3
2309 instantVector.push_back( atoi(tmp) );
2310 fscanf(pFile,"%s",tmp); // 4
2311 instantVector.push_back( atoi(tmp) );
2312 fscanf(pFile,"%s",tmp); // 5
2313 instantVector.push_back( atoi(tmp) );
2314 fscanf(pFile,"%s",tmp); // 6
2315 instantVector.push_back( atoi(tmp) );
2318 fscanf(pFile,"%s",tmp); // TypeContourModel
2319 fscanf(pFile,"%s",tmp); // ##
2320 typeContourModel = atoi(tmp);
2322 manModelContour = factoryManualContourModel(typeContourModel);
2323 manModelContour->Open(pFile);
2325 fscanf(pFile,"%s",tmp); // TypeView
2326 fscanf(pFile,"%s",tmp); // ##
2327 typeView = atoi(tmp);
2335 std::string theName;
2336 theName = _modelManager->createOutline( manModelContour, instantVector );
2337 bool addedModel = theName.compare("") != 0;
2340 double spc[3];//Si no hay imagen pero hay contornos que spacing se pone por default
2341 this->_theViewPanel->getSpacing(spc);
2342 //Adding the manualContourControler to interface objects structure
2343 //Adding the manualViewContour to interface objects structure
2344 //_theViewPanel->getSceneManager()->setControlActiveStateOfALL( false );//This call is being done here because if the ROI is created underneath the previously created ROIS will still be active.
2345 _theViewPanel->getSceneManager()->configureViewControlTo( theName, manModelContour,spc , typeView) ;
2348 if (staticContour==true)
2350 Instant instant(&instantVector);
2351 changeContourOfManager( theName , &instant );
2354 }// for numberOfContours
2360 //------------------------------------------------------------------------------------------------------------
2361 void wxContourEventHandler::openFileWithContours()
2364 wxFileDialog dialog(NULL, _T("Choose a file"), _T(""), _T(""), _T("*.roi"), wxOPEN );
2365 if (dialog.ShowModal() == wxID_OK)
2367 fileNameContourROI = (const char *)(dialog.GetPath().mb_str());
2368 FILE *pFile=fopen(fileNameContourROI.c_str(),"r+");
2370 fscanf(pFile,"%s",tmp); // --CreaContour--
2372 fscanf(pFile,"%s",tmp); // Version
2373 fscanf(pFile,"%s",tmp); // 1.0.1
2374 std::string version(tmp);
2376 openContours(pFile,false);
2377 if (version!="1.0.0"){
2378 openContours(pFile,true);
2380 // _theViewPanel->getSceneManager()->openFileWithContours(ff);
2384 _theViewPanel->getSceneManager()->removeSceneContours();
2386 //updateInstantOutlines();
2390 //------------------------------------------------------------------------------------------------------------
2391 void wxContourEventHandler::saveFileWithContours( std::string filename )
2393 FILE *pFile=fopen(filename.c_str(),"w+");
2394 std::vector< std::string > lstNameThings;
2395 int i,sizeLstNameThings;
2397 fprintf(pFile,"--CreaContour--\n");
2398 fprintf(pFile,"Version %s\n", "1.0.1" );
2401 lstNameThings = _modelManager->GetLstNameThings();
2402 sizeLstNameThings = lstNameThings.size();
2403 fprintf(pFile,"NumberOfContours %d\n", sizeLstNameThings );
2404 for (i=0 ; i<sizeLstNameThings ; i++)
2406 _modelManager->SaveThingName( pFile, lstNameThings[i] );
2407 _theViewPanel->getSceneManager()->SaveThingName( pFile, lstNameThings[i] );
2410 //-- Contours Statics
2411 lstNameThings = _modelManager->GetLstNameThingsStatic();
2412 sizeLstNameThings = lstNameThings.size();
2413 fprintf(pFile,"NumberOfContoursStatic %d\n", sizeLstNameThings );
2414 for (i=0 ; i<sizeLstNameThings ; i++)
2416 _modelManager->SaveThingName( pFile, lstNameThings[i] );
2417 _theViewPanel->getSceneManager()->SaveThingName( pFile, lstNameThings[i] );
2423 //----------------------------------------------------------
2425 void wxContourEventHandler::saveFileWithContours()
2427 wxFileDialog dialog(NULL, _T("Choose a file"), _T(""), _T(""), _T("*.roi"), wxSAVE );
2428 if (dialog.ShowModal() == wxID_OK)
2430 fileNameContourROI = (const char *)(dialog.GetPath().mb_str());
2431 saveFileWithContours( fileNameContourROI );
2435 //------------------------------------------------------------------------------------------------------------
2436 void wxContourEventHandler :: saveFileWithContoursAutomatique()
2438 if (fileNameContourROI=="")
2440 saveFileWithContours();
2442 saveFileWithContours(fileNameContourROI);
2447 //------------------------------------------------------------------------------------------------------------
2448 void wxContourEventHandler :: createCopyContourOf ( std::string anExistingKName, std::vector<int> &instantNoTouchData, bool append )
2450 std::string cloneName = _modelManager->createCopyContourOf( anExistingKName, instantNoTouchData );
2451 manualContourModel * manualModel = _modelManager->getOutlineByKeyName( cloneName )->getModel();
2452 _theViewPanel->getSceneManager()->createCopyContourOf( anExistingKName, cloneName, manualModel , append );
2456 //------------------------------------------------------------------------------------------------------------
2457 manualContourModel * wxContourEventHandler::factoryManualContourModel(int typeContour)
2459 manualContourModel *manModelContour=NULL;
2464 manModelContour = new manualContourModel();
2470 manModelContour = new manualContourModel();
2476 manModelContour = new manualContourModelRoi();
2482 manModelContour = new manualContourModelCircle();
2488 manualContourModelBullEye *manModelContourBullEye = new manualContourModelBullEye();
2489 manModelContour = manModelContourBullEye;
2490 if (_panelBullEyeOptions!=NULL){
2491 int iCrown,sizeCrowns,iSector,sizeSectors;
2492 double radioA,radioB,ang,angDelta ;
2493 sizeCrowns = _panelBullEyeOptions->GetNumberOfCrowns();
2494 for ( iCrown=0 ; iCrown<sizeCrowns ; iCrown++ )
2496 sizeSectors = _panelBullEyeOptions->GetNumberOfSections(iCrown);
2497 radioB = _panelBullEyeOptions->GetRadioOfCrown(iCrown);
2498 if (iCrown==sizeCrowns-1)
2502 radioA = _panelBullEyeOptions->GetRadioOfCrown(iCrown+1);
2504 radioA=radioA/100.0;
2505 radioB=radioB/100.0;
2506 for ( iSector=0 ; iSector<sizeSectors ; iSector++ )
2508 ang = _panelBullEyeOptions->GetAngOfCrownSection(iCrown,iSector);
2509 angDelta= _panelBullEyeOptions->GetAngDeltaOfCrownSection(iCrown);
2510 manModelContourBullEye->AddSector(radioA,radioB,ang,angDelta);
2513 } // if _panelBullEyeOptions
2514 }// if typeContour==4
2516 return manModelContour;
2519 //------------------------------------------------------------------------------------------------------------
2520 void wxContourEventHandler :: createContour( int typeContour )
2522 //Creating the manualContourModel and including in the model
2523 manualContourModel * manModelContour = factoryManualContourModel(typeContour);
2524 std::vector<int> instantVector;
2525 _instantPanel->getInstant( instantVector );
2526 std::string theName;
2527 theName= _modelManager->createOutline( manModelContour, instantVector );
2528 bool addedModel = theName.compare("") != 0;//??
2531 double spc[3];//Si no hay imagen pero hay contornos que spacing se pone por default
2532 this->_theViewPanel->getSpacing(spc);
2533 //Adding the manualContourControler to interface objects structure
2534 //Adding the manualViewContour to interface objects structure
2535 //_theViewPanel->getSceneManager()->setControlActiveStateOfALL( false );//This call is being done here because if the ROI is created underneath the previously created ROIS will still be active.
2536 _theViewPanel->getSceneManager()->configureViewControlTo( theName, manModelContour,spc , typeContour) ;
2540 //FILE *ff = fopen("c:/temp/wxVtkBaseView_SceneManagerStadistics.txt","a+");
2541 //fprintf(ff,"EED wxContourEventHandler::createContour() \n" );
2542 //fprintf(ff," %s\n %p ",theName.c_str() , );
2547 manualContourModel * wxContourEventHandler::factoryManualContourModel(PanelBullEyeOptions* panel){
2549 manualContourModelBullEye *manModelContourBullEye = new manualContourModelBullEye();
2550 manualContourModel *manModelContour=NULL;
2551 manModelContour = manModelContourBullEye;
2553 int iCrown,sizeCrowns,iSector,sizeSectors;
2554 double radioA,radioB,ang,angDelta ;
2555 sizeCrowns = panel->GetNumberOfCrowns();
2556 for ( iCrown=0 ; iCrown<sizeCrowns ; iCrown++ )
2558 sizeSectors = panel->GetNumberOfSections(iCrown);
2559 radioB = panel->GetRadioOfCrown(iCrown);
2560 if (iCrown==sizeCrowns-1)
2564 radioA = panel->GetRadioOfCrown(iCrown+1);
2566 radioA=radioA/100.0;
2567 radioB=radioB/100.0;
2568 for ( iSector=0 ; iSector<sizeSectors ; iSector++ )
2570 ang = panel->GetAngOfCrownSection(iCrown,iSector);
2571 angDelta= panel->GetAngDeltaOfCrownSection(iCrown);
2572 manModelContourBullEye->AddSector(radioA,radioB,ang,angDelta);
2575 } // if _panelBullEyeOptions
2577 return manModelContour;
2580 void wxContourEventHandler :: createContourBullsEye(PanelBullEyeOptions* panel )
2582 //Creating the manualContourModel and including in the model
2583 manualContourModel * manModelContour = factoryManualContourModel(panel );
2584 std::vector<int> instantVector;
2585 _instantPanel->getInstant( instantVector );
2586 std::string theName;
2587 theName= _modelManager->createOutline( manModelContour, instantVector );
2588 bool addedModel = theName.compare("") != 0;
2591 double spc[3];//Si no hay imagen pero hay contornos que spacing se pone por default
2592 this->_theViewPanel->getSpacing(spc);
2593 //Adding the manualContourControler to interface objects structure
2594 //Adding the manualViewContour to interface objects structure
2595 //_theViewPanel->getSceneManager()->setControlActiveStateOfALL( false );//This call is being done here because if the ROI is created underneath the previously created ROIS will still be active.
2596 _theViewPanel->getSceneManager()->configureViewControlTo( theName, manModelContour,spc , 4) ;
2600 //FILE *ff = fopen("c:/temp/wxVtkBaseView_SceneManagerStadistics.txt","a+");
2601 //fprintf(ff,"EED wxContourEventHandler::createContour() \n" );
2602 //fprintf(ff," %s\n %p ",theName.c_str() , );
2608 //------------------------------------------------------------------------------------------------------------
2609 // Attributes getters and setters
2610 //------------------------------------------------------------------------------------------------------------
2612 void wxContourEventHandler :: setModelManager( OutlineModelManager * theModelManager )
2614 _modelManager = theModelManager;
2615 _workSpace = _modelManager->getContourWorkspace();
2617 //------------------------------------------------------------------------------------------------------------
2618 void wxContourEventHandler :: setViewPanel( wxContourViewPanel * theViewPanel )
2620 _theViewPanel = theViewPanel;
2621 //_theViewPanel->setWxEventHandler( this );
2624 this->_theViewPanel->getSpacing(spc);
2625 _sceneManager = new wxVtkBaseView_SceneManager ( this->_theViewPanel->getWxVtkBaseView(), this, spc );
2627 Connect( _theViewPanel->GetId(), wxINSTANT_CHANGE, (wxObjectEventFunction) (wxCommandEventFunction) &wxContourEventHandler::onChangeInstant );
2628 Connect( wxID_ANY, wxEVT_START_CREATE_MULT_ROI, (wxObjectEventFunction) (wxCommandEventFunction) &wxContourEventHandler::onCreateMultipleROI );
2629 Connect( wxID_ANY, wxEVT_START_CREATE_ROI, (wxObjectEventFunction) (wxCommandEventFunction) &wxContourEventHandler::onCreateROI );
2630 Connect( wxID_ANY, wxEVT_STOP_CREATE_ROI, (wxObjectEventFunction) (wxCommandEventFunction) &wxContourEventHandler::onStopCreateROI );
2631 Connect( wxID_ANY, wxEVT_CHANGED_DEEP, (wxObjectEventFunction) (wxCommandEventFunction) &wxContourEventHandler::onChangedDeep );
2632 Connect( wxID_ANY, wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &wxContourEventHandler :: onActionButtonPressed ); */
2637 //------------------------------------------------------------------------------------------------------------
2638 void wxContourEventHandler :: setInstantChooserPanel( wxInstantChooserPanel * theInstantChooserPanel )
2640 _instantPanel = theInstantChooserPanel;
2641 //_instantPanel->setWxEventHandler( this );
2643 //Connect( _instantPanel->GetId(), wxINSTANT_CHOOSER_CHANGE, (wxObjectEventFunction) (wxCommandEventFunction) &wxContourEventHandler::onChangeInstant );
2645 std::vector<int> vect;
2646 _instantPanel->getInstant( vect );
2647 _actualInstant = new Instant( &vect );
2649 if( _modelManager!=NULL )
2651 std::vector<std::string> conceptNameVect;
2652 std::vector<int> conceptSizeVect;
2653 _modelManager-> getConceptsInformation(conceptNameVect, conceptSizeVect);
2655 int max = conceptNameVect.size();
2658 if( conceptNameVect[i].compare("Axe Depth") == 0 )
2660 _instantPanel->addConcept( conceptNameVect[i], 0, conceptSizeVect[i], 1);
2662 _instantPanel->addConcept( conceptNameVect[i], 1, conceptSizeVect[i], 1);
2666 //Should be configured later, or abort program, because Model -NEEDS- to be added before chooserPanel
2668 if( _theViewPanel!=NULL )
2670 double val = _theViewPanel->getCurrentDeep();
2671 _instantPanel->setConceptValue( "Axe Depth", (int)val );
2672 //JCP _instantPanel->setConceptValue("time", num de imagenes);
2673 ConceptDataWrap * data = _instantPanel->getConceptDataOf( "Axe Depth" );
2675 _theViewPanel->setVerticalConcept( "Axe Depth", data->getMinValue(), data->getMaxValue(), data->getMinShowedValue(), data->getMaxShowedValue(), data->getActualValue() );
2677 //Should be configured later, or abort program, because ViewPanel -NEEDS- to be added before chooserPanel
2682 //------------------------------------------------------------------------------------------------------------
2683 void wxContourEventHandler :: setButtonsBar( wxContour_ButtonsBar * theButtonsBar )
2685 _buttonsBar = theButtonsBar;
2686 _buttonsBar->setWxEventHandler( this );
2687 Connect( _buttonsBar->GetId(), wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &wxContourEventHandler:: onActionButtonPressed );
2689 //------------------------------------------------------------------------------------------------------------
2690 void wxContourEventHandler :: setGrid( wxContour_Grid * theGridPanel )
2692 _gridPanel = theGridPanel;
2694 //------------------------------------------------------------------------------------------------------------
2695 void wxContourEventHandler :: setDrawToolsPanel( wxContour_DrawToolsPanel * theDrawToolsPanel )
2697 _drawToolsPanel = theDrawToolsPanel;
2699 //------------------------------------------------------------------------------------------------------------
2700 void wxContourEventHandler :: setOperationsToolsPanel( wxContour_OperationsToolsPanel * theOperationsToolsPanel )
2702 _operationsToolsPanel = theOperationsToolsPanel;
2704 //------------------------------------------------------------------------------------------------------------
2705 void wxContourEventHandler :: setAutomaticFormsPanel( wxContour_AutomaticFormsToolsPanel * theAutoFormsPanel )
2707 _autoFormsPanel = theAutoFormsPanel;
2710 void wxContourEventHandler :: setStandardToolsPanel( wxContour_StandardToolsPanel * theStandardToolsPanel )
2712 _standardToolsPanel= theStandardToolsPanel;
2714 //------------------------------------------------------------------------------------------------------------
2715 void wxContourEventHandler :: setEditionToolsPanel( wxContour_EdtionToolsPanel * theEditionToolsPanel )
2717 _editionToolsPanel = theEditionToolsPanel;
2720 //------------------------------------------------------------------------------------------------------------
2721 void wxContourEventHandler :: setListViewPanel( wxContour_ListViewPanel * theListViewPanel )
2723 _listViewPanel = theListViewPanel;
2725 //------------------------------------------------------------------------------------------------------------
2726 // Other functional methods
2727 //------------------------------------------------------------------------------------------------------------
2730 //------------------------------------------------------------------------------------------------------------
2731 void wxContourEventHandler::onDeleteContour( wxCommandEvent& event )
2734 //JCP 20-10-08 Undo redo implementation
2736 //JCP 20-10-08 Undo redo implementation
2739 int i,size=_theViewPanel->getSceneManager()->getSelectedObjects().size();
2742 std::string keyName = _theViewPanel->getSceneManager()->getSelectedObjects()[i];
2743 int ispartofstaticlist = this->_modelManager->IsPartOfStaticList( keyName );
2744 if ( ispartofstaticlist>=0 )
2746 std::vector<int> tempVector;
2747 _instantPanel->getInstant( tempVector );
2748 Instant instant(&tempVector);
2749 this->_modelManager->ChangeContourOfList(keyName, &instant);
2753 std::vector<std::string> lstKeyName;
2754 std::vector<std::string> lstKeyNameActualSlice;
2755 std::vector<std::string> lstKeyNameToBeErase;
2757 lstKeyNameToBeErase = _theViewPanel->getSceneManager()->getSelectedObjects();
2758 lstKeyNameActualSlice = _theViewPanel->getSceneManager()->GetlstContoursNameActualSlice();
2759 int k,kSize=lstKeyNameToBeErase.size();
2760 int j,jSize=lstKeyNameActualSlice.size();
2762 for (k=0;k<kSize; k++)
2765 for (j=0;j<jSize; j++)
2767 if (lstKeyNameToBeErase[k]==lstKeyNameActualSlice[j])
2774 lstKeyName.push_back( lstKeyNameToBeErase[k] );
2778 deleteContours( lstKeyName );
2783 //------------------------------------------------------------------------------------------------------------
2784 void wxContourEventHandler::onDeleteContoursActSlice( wxCommandEvent& event )
2786 //JCP 20-10-08 Undo redo implementation
2788 //JCP 20-10-08 Undo redo implementation
2789 deleteContours( (std::vector<std::string>)_theViewPanel->getSceneManager()->GetlstContoursNameActualSlice() );
2794 //------------------------------------------------------------------------------------------------------------
2795 void wxContourEventHandler::onDeleteAllContours( wxCommandEvent& event )
2797 //JCP 20-10-08 Undo redo implementation
2799 //JCP 20-10-08 Undo redo implementation
2800 deleteAllContours( );
2805 //------------------------------------------------------------------------------------------------------------
2806 void wxContourEventHandler :: onDeleteFrame( )
2808 if (_deleteFrame==NULL)
2810 _deleteFrame = new wxFrame (_theViewPanel, -1,_T(" Delete Contour "), wxDefaultPosition, wxDefaultSize, wxFRAME_TOOL_WINDOW|wxSYSTEM_MENU | wxCAPTION | wxCLIP_CHILDREN |wxFRAME_FLOAT_ON_PARENT );
2812 wxSize sizepanel(width,230);
2813 _deleteFrame->SetSize( sizepanel );
2814 wxPanel *panel = new wxPanel(_deleteFrame,-1);
2815 wxButton *deleteContourBtn = new wxButton(panel,-1,_T("Delete contour selected"),wxDefaultPosition, wxSize(width-10,35) );
2816 wxButton *deleteContoursActSliceBtn = new wxButton(panel,-1,_T("Delete contours of actual slice"),wxDefaultPosition, wxSize(width-10,35));
2817 wxButton *deleteAllContoursBtn = new wxButton(panel,-1,_T("Delete all contours"),wxDefaultPosition, wxSize(width-10,35));
2819 int sizeZ = _theViewPanel->getSceneManager()->GetImageDataSizeZ();
2820 _mbarrangeDeleteAll = new mBarRange(panel,70, 65);
2821 _mbarrangeDeleteAll->SetMin(0);
2822 _mbarrangeDeleteAll->SetStart(0);
2824 _mbarrangeDeleteAll-> SetOrientation( true );
2825 _mbarrangeDeleteAll-> setActiveStateTo(true);
2826 _mbarrangeDeleteAll-> setVisibleLabels( true );
2827 _mbarrangeDeleteAll-> setDeviceEndMargin(10);
2828 _mbarrangeDeleteAll-> setRepresentedValues( 0 , sizeZ );
2829 _mbarrangeDeleteAll-> setDeviceBlitStart(10,10);
2830 _mbarrangeDeleteAll-> setIfWithActualDrawed( false );
2831 _mbarrangeDeleteAll-> SetStart( 0 );
2832 _mbarrangeDeleteAll-> SetEnd( sizeZ );
2835 _deleteFrame->SetEventHandler( this );
2836 Connect( deleteContourBtn->GetId() , wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &wxContourEventHandler::onDeleteContour );
2837 Connect( deleteContoursActSliceBtn->GetId() , wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &wxContourEventHandler::onDeleteContoursActSlice );
2838 Connect( deleteAllContoursBtn->GetId() , wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &wxContourEventHandler::onDeleteAllContours );
2840 wxFlexGridSizer * sizer = new wxFlexGridSizer(1);
2841 sizer -> Add( deleteContourBtn , 1, wxGROW );
2842 sizer -> Add( deleteContoursActSliceBtn , 1, wxGROW );
2843 sizer -> Add( deleteAllContoursBtn , 1, wxGROW );
2844 sizer -> Add( _mbarrangeDeleteAll , 1, wxGROW );
2846 panel->SetSizer( sizer );
2847 panel->SetSize( sizepanel );
2848 panel->SetAutoLayout( true );
2850 _deleteFrame->Show(true);
2852 if (_deleteFrame->IsShown()==true)
2854 _deleteFrame->Show(false);
2856 _deleteFrame->Show(true);
2862 //------------------------------------------------------------------------------------------------------------
2863 void wxContourEventHandler::onCreateContourSpline( wxCommandEvent& event )
2866 //JCP 20-10-08 Undo redo implementation
2868 //JCP 20-10-08 Undo redo implementation
2875 //------------------------------------------------------------------------------------------------------------
2876 void wxContourEventHandler::onCreateContourRectangle( wxCommandEvent& event )
2879 //JCP 20-10-08 Undo redo implementation
2881 //JCP 20-10-08 Undo redo implementation
2887 //------------------------------------------------------------------------------------------------------------
2888 void wxContourEventHandler::onCreateContourCircle( wxCommandEvent& event )
2890 //JCP 20-10-08 Undo redo implementation
2892 //JCP 20-10-08 Undo redo implementation
2897 //------------------------------------------------------------------------------------------------------------
2898 void wxContourEventHandler::onCreateContourBullEye( wxCommandEvent& event )
2900 //JCP 20-10-08 Undo redo implementation
2902 //JCP 20-10-08 Undo redo implementation
2909 //------------------------------------------------------------------------------------------------------------
2910 void wxContourEventHandler :: onCreateContourFrame( )
2912 if (_createContourFrame==NULL)
2914 _createContourFrame = new wxFrame (_theViewPanel, -1,_T(" New Contour "), wxDefaultPosition, wxDefaultSize, wxFRAME_TOOL_WINDOW|wxSYSTEM_MENU | wxCAPTION | wxCLIP_CHILDREN |wxFRAME_FLOAT_ON_PARENT | wxRESIZE_BORDER );
2915 wxSize sizepanel(490,600);
2916 _createContourFrame->SetSize( sizepanel );
2917 wxPanel *panel = new wxPanel(_createContourFrame,-1);
2918 wxButton *newContourSplineBtn = new wxButton(panel,-1,_T("Interpolation B-spline (close)"),wxDefaultPosition, wxSize(180,35) );
2919 newContourSplineBtn->SetToolTip(_T("CTRL-N"));
2920 wxButton *newContourRectangleBtn = new wxButton(panel,-1,_T("Rectangle"),wxDefaultPosition, wxSize(180,35));
2921 wxButton *newContourCircleBtn = new wxButton(panel,-1,_T("Circle"),wxDefaultPosition, wxSize(180,35));
2922 wxButton *newContourStarBtn = new wxButton(panel,-1,_T("Bull eye"),wxDefaultPosition, wxSize(180,35));
2924 _panelBullEyeOptions = new PanelBullEyeOptions(panel, wxSize(100,200));
2926 _createContourFrame->SetEventHandler( this );
2927 Connect( newContourSplineBtn->GetId() , wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &wxContourEventHandler::onCreateContourSpline );
2928 Connect( newContourRectangleBtn->GetId() , wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &wxContourEventHandler::onCreateContourRectangle );
2929 Connect( newContourCircleBtn->GetId() , wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &wxContourEventHandler::onCreateContourCircle );
2930 Connect( newContourStarBtn->GetId() , wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &wxContourEventHandler::onCreateContourBullEye );
2932 wxFlexGridSizer * sizer = new wxFlexGridSizer(1);
2933 sizer -> Add( newContourSplineBtn , 1, wxGROW );
2934 sizer -> Add( newContourRectangleBtn , 1, wxGROW );
2935 sizer -> Add( newContourCircleBtn , 1, wxGROW );
2936 sizer -> Add( newContourStarBtn , 1, wxGROW );
2937 sizer -> Add( _panelBullEyeOptions , 1, wxGROW );
2939 panel->SetSizer( sizer );
2940 panel->SetSize( sizepanel );
2941 panel->SetAutoLayout( true );
2943 _createContourFrame->Show(true);
2945 if (_createContourFrame->IsShown()==true)
2947 _createContourFrame->Show(false);
2949 _createContourFrame->Show(true);
2955 //------------------------------------------------------------------------
2956 void wxContourEventHandler::RefreshInterface()
2959 wxVtk2DBaseView *wxvtk2dbaseview = (wxVtk2DBaseView*)this->_theViewPanel->getWxVtkBaseView();
2960 wxvtk2dbaseview->Refresh();
2963 //------------------------------------------------------------------------
2964 void wxContourEventHandler::onWidthOfContour(wxScrollEvent& event){
2965 _theViewPanel->getSceneManager()->removeSceneContours();
2966 double width = (double)_withOfContourLine->GetValue() / 2.0;
2967 _theViewPanel->getSceneManager()->SetWidthContour( width );
2972 //------------------------------------------------------------------------
2974 void wxContourEventHandler::onBrigthnessColorWindowLevel(wxScrollEvent& event){
2975 int colorwindow = _brithtnessColorLevel->GetValue();
2976 int windowlevel = _brithtnessWindowLevel->GetValue();
2977 wxVtk2DBaseView *wxvtk2dbaseview = (wxVtk2DBaseView*)this->_theViewPanel->getWxVtkBaseView();
2978 vtkImageViewer2 *imageviewer = wxvtk2dbaseview->_imageViewer2XYZ->GetVtkImageViewer2();
2979 imageviewer->SetColorWindow(colorwindow);
2980 imageviewer->SetColorLevel(windowlevel);
2981 // wxvtk2dbaseview->Refresh();
2985 void wxContourEventHandler::OnInterpolation(wxCommandEvent& event)
2987 wxVtk2DBaseView *wxvtk2dbaseview = (wxVtk2DBaseView*)this->_theViewPanel->getWxVtkBaseView();
2988 vtkImageViewer2 *imageviewer = wxvtk2dbaseview->_imageViewer2XYZ->GetVtkImageViewer2();
2989 if (_interpolationCheckBox->GetValue()==true)
2991 imageviewer->GetImageActor()->InterpolateOn();
2993 imageviewer->GetImageActor()->InterpolateOff();
2999 //------------------------------------------------------------------------------------------------------------
3000 void wxContourEventHandler :: onInterfaceConfigurationFrame( )
3002 if (_interfaceConfigurationFrame==NULL)
3004 _interfaceConfigurationFrame = new wxFrame (_theViewPanel, -1,_T(" Interface Configuration "), wxDefaultPosition, wxDefaultSize, wxFRAME_TOOL_WINDOW|wxSYSTEM_MENU | wxCAPTION | wxCLIP_CHILDREN |wxFRAME_FLOAT_ON_PARENT );
3005 wxSize sizepanel(190,400);
3006 _interfaceConfigurationFrame->SetSize( sizepanel );
3007 _interfaceConfigurationFrame->SetEventHandler( this );
3008 wxPanel* panel = getConfigurationPanel(_interfaceConfigurationFrame);
3009 panel->SetSize(sizepanel);
3010 _interfaceConfigurationFrame->Show(true);
3012 if (_interfaceConfigurationFrame->IsShown()==true)
3014 _interfaceConfigurationFrame->Show(false);
3016 _interfaceConfigurationFrame->Show(true);
3024 wxPanel* wxContourEventHandler :: getConfigurationPanel(wxWindow* parent){
3026 /*wxPanel *panel = new wxPanel(parent,-1);
3027 _withOfContourLine = new wxSlider(panel, -1, 1 , 1, 10, wxDefaultPosition, wxSize(180,40), wxSL_HORIZONTAL|wxSL_LABELS, wxDefaultValidator);
3030 this->_theViewPanel->getSceneManager()->GetImageDataRange(range);
3032 wxVtk2DBaseView *wxvtk2dbaseview = (wxVtk2DBaseView*)this->_theViewPanel->getWxVtkBaseView();
3033 vtkImageViewer2 *imageviewer = wxvtk2dbaseview->_imageViewer2XYZ->GetVtkImageViewer2();
3034 int colorwindow = (int)imageviewer->GetWindowLevel()->GetLevel();
3035 int windowlevel = (int)imageviewer->GetWindowLevel()->GetWindow();
3037 _brithtnessWindowLevel = new wxSlider(panel, -1, windowlevel , 1, range[1], wxDefaultPosition, wxSize(180,40), wxSL_HORIZONTAL|wxSL_LABELS, wxDefaultValidator);
3038 _brithtnessColorLevel = new wxSlider(panel, -1, colorwindow , 1, range[1], wxDefaultPosition, wxSize(180,40), wxSL_HORIZONTAL|wxSL_LABELS, wxDefaultValidator);
3040 _interpolationCheckBox = new wxCheckBox(panel, -1, _T("Image interpolation") );
3041 _interpolationCheckBox->SetValue(true);
3043 _interfaceConfigurationFrame->SetEventHandler( this );
3045 Connect( _withOfContourLine->GetId() , wxEVT_SCROLL_CHANGED , (wxObjectEventFunction) &wxContourEventHandler::onWidthOfContour );
3046 Connect( _withOfContourLine->GetId() , wxEVT_SCROLL_THUMBTRACK , (wxObjectEventFunction) &wxContourEventHandler::onWidthOfContour );
3048 Connect( _brithtnessWindowLevel->GetId() , wxEVT_SCROLL_CHANGED , (wxObjectEventFunction) &wxContourEventHandler::onBrigthnessColorWindowLevel );
3049 Connect( _brithtnessWindowLevel->GetId() , wxEVT_SCROLL_THUMBTRACK , (wxObjectEventFunction) &wxContourEventHandler::onBrigthnessColorWindowLevel );
3050 Connect( _brithtnessColorLevel->GetId() , wxEVT_SCROLL_CHANGED , (wxObjectEventFunction) &wxContourEventHandler::onBrigthnessColorWindowLevel );
3051 Connect( _brithtnessColorLevel->GetId() , wxEVT_SCROLL_THUMBTRACK , (wxObjectEventFunction) &wxContourEventHandler::onBrigthnessColorWindowLevel );
3052 Connect( _interpolationCheckBox->GetId() , wxEVT_COMMAND_CHECKBOX_CLICKED , (wxObjectEventFunction) &wxContourEventHandler::OnInterpolation );
3054 wxFlexGridSizer * sizer = new wxFlexGridSizer(1);
3055 sizer -> Add( new wxStaticText(panel,-1,_T("Contour width")) , 1, wxGROW );
3056 sizer -> Add( _withOfContourLine , 1, wxGROW );
3057 sizer -> Add( new wxStaticText(panel,-1,_T(" ")) , 1, wxGROW );
3058 sizer -> Add( new wxStaticText(panel,-1,_T(" ")) , 1, wxGROW );
3059 sizer -> Add( new wxStaticText(panel,-1,_T("Brightness of the image")) , 1, wxGROW );
3060 sizer -> Add( new wxStaticText(panel,-1,_T("--Window level--")) , 1, wxGROW );
3061 sizer -> Add( _brithtnessWindowLevel , 1, wxGROW );
3062 sizer -> Add( new wxStaticText(panel,-1,_T("--Color level--")) , 1, wxGROW );
3063 sizer -> Add( _brithtnessColorLevel, 1, wxGROW );
3064 sizer -> Add( new wxStaticText(panel,-1,_T(" ")) , 1, wxGROW );
3065 sizer -> Add( new wxStaticText(panel,-1,_T(" ")) , 1, wxGROW );
3066 sizer -> Add( _interpolationCheckBox , 1, wxGROW );
3068 panel->SetSizer( sizer );
3070 //panel->SetSize( sizepanel );
3072 panel->SetAutoLayout( true );
3077 wxPanel *panel = new wxPanel(parent,-1,wxDefaultPosition, wxDefaultSize,wxNO_BORDER, wxString(_T("")));
3078 _withOfContourLine = new wxSlider(panel, -1, 1 , 1, 10, wxDefaultPosition, wxDefaultSize, wxSL_HORIZONTAL|wxSL_LABELS, wxDefaultValidator);
3081 this->_theViewPanel->getSceneManager()->GetImageDataRange(range);
3083 wxVtk2DBaseView *wxvtk2dbaseview = (wxVtk2DBaseView*)this->_theViewPanel->getWxVtkBaseView();
3084 vtkImageViewer2 *imageviewer = wxvtk2dbaseview->_imageViewer2XYZ->GetVtkImageViewer2();
3085 int colorwindow = (int)imageviewer->GetWindowLevel()->GetLevel();
3086 int windowlevel = (int)imageviewer->GetWindowLevel()->GetWindow();
3088 _brithtnessWindowLevel = new wxSlider(panel, -1, windowlevel , 1, range[1], wxDefaultPosition, wxDefaultSize, wxSL_HORIZONTAL|wxSL_LABELS, wxDefaultValidator);
3089 _brithtnessColorLevel = new wxSlider(panel, -1, colorwindow , 1, range[1], wxDefaultPosition, wxDefaultSize, wxSL_HORIZONTAL|wxSL_LABELS, wxDefaultValidator);
3091 _interpolationCheckBox = new wxCheckBox(panel, -1, _T("Image interpolation") );
3092 _interpolationCheckBox->SetValue(true);
3094 Connect( _withOfContourLine->GetId() , wxEVT_SCROLL_CHANGED , (wxObjectEventFunction) &wxContourEventHandler::onWidthOfContour );
3095 Connect( _withOfContourLine->GetId() , wxEVT_SCROLL_THUMBTRACK , (wxObjectEventFunction) &wxContourEventHandler::onWidthOfContour );
3097 Connect( _brithtnessWindowLevel->GetId() , wxEVT_SCROLL_CHANGED , (wxObjectEventFunction) &wxContourEventHandler::onBrigthnessColorWindowLevel );
3098 Connect( _brithtnessWindowLevel->GetId() , wxEVT_SCROLL_THUMBTRACK , (wxObjectEventFunction) &wxContourEventHandler::onBrigthnessColorWindowLevel );
3099 Connect( _brithtnessColorLevel->GetId() , wxEVT_SCROLL_CHANGED , (wxObjectEventFunction) &wxContourEventHandler::onBrigthnessColorWindowLevel );
3100 Connect( _brithtnessColorLevel->GetId() , wxEVT_SCROLL_THUMBTRACK , (wxObjectEventFunction) &wxContourEventHandler::onBrigthnessColorWindowLevel );
3101 Connect( _interpolationCheckBox->GetId() , wxEVT_COMMAND_CHECKBOX_CLICKED , (wxObjectEventFunction) &wxContourEventHandler::OnInterpolation );
3103 wxFlexGridSizer * sizer = new wxFlexGridSizer(1);
3104 sizer -> Add( new wxStaticText(panel,-1,_T("Contour width")) , 1, wxGROW );
3105 sizer -> Add( _withOfContourLine , 1, wxGROW );
3106 sizer -> Add( new wxStaticText(panel,-1,_T(" ")) , 1, wxGROW );
3107 sizer -> Add( new wxStaticText(panel,-1,_T(" ")) , 1, wxGROW );
3108 sizer -> Add( new wxStaticText(panel,-1,_T("Brightness of the image")) , 1, wxGROW );
3109 sizer -> Add( new wxStaticText(panel,-1,_T("--Window level--")) , 1, wxGROW );
3110 sizer -> Add( _brithtnessWindowLevel , 1, wxGROW );
3111 sizer -> Add( new wxStaticText(panel,-1,_T("--Color level--")) , 1, wxGROW );
3112 sizer -> Add( _brithtnessColorLevel, 1, wxGROW );
3113 sizer -> Add( new wxStaticText(panel,-1,_T(" ")) , 1, wxGROW );
3114 sizer -> Add( new wxStaticText(panel,-1,_T(" ")) , 1, wxGROW );
3115 sizer -> Add( _interpolationCheckBox , 1, wxGROW );
3117 panel->SetSizer( sizer );
3119 //panel->SetSize( sizepanel );
3121 panel->SetAutoLayout( true );
3131 //------------------------------------------------------------------
3132 void wxContourEventHandler :: changeContourOfManager(std::string keyName, Instant *instant)
3134 this->_modelManager->ChangeContourOfList(keyName, instant);
3137 //------------------------------------------------------------------
3138 void wxContourEventHandler :: changeContoursOfManager( std::vector<std::string> & keyNamesVector )
3141 //JCP 20-10-08 Undo redo implementation
3143 //JCP 20-10-08 Undo redo implementation
3145 std::vector<int> tempVector;
3146 _instantPanel->getInstant( tempVector );
3147 Instant instant(&tempVector);
3149 int i , size=keyNamesVector.size();
3150 for ( i=0 ; i<size ; i++ )
3152 changeContourOfManager(keyNamesVector[i], &instant);
3159 //------------------------------------------------------------------
3160 void wxContourEventHandler :: executeActionCommand( const char toolCommand )
3162 std::vector<std::string> currentSelection = _theViewPanel->getSceneManager()->getSelectedObjects();
3163 int elementsSelected = currentSelection.size();
3164 if( toolCommand == (wxContour_ActionCommandsID::CREATE_TOOL) )
3166 onCreateContourFrame();
3168 if( toolCommand == (wxContour_ActionCommandsID::CREATE_CONTOUR_KEY) )
3172 else if( toolCommand == wxContour_ActionCommandsID::DELETE_TOOL )
3176 else if( toolCommand == wxContour_ActionCommandsID::DELETE_KEY )
3178 deleteContours( currentSelection );
3180 else if( toolCommand == wxContour_ActionCommandsID::SAVE_TOOL )
3182 saveFileWithContours( );
3184 else if( toolCommand == wxContour_ActionCommandsID::SAVE_KEY )
3186 saveFileWithContoursAutomatique( );
3188 else if( toolCommand == wxContour_ActionCommandsID::OPEN_TOOL )
3190 openFileWithContours( );
3192 else if( toolCommand == wxContour_ActionCommandsID::CHANGE_TOOL )
3194 if ( elementsSelected >= 1 )
3196 changeContoursOfManager( currentSelection );
3200 else if( toolCommand == wxContour_ActionCommandsID::HIDE_TOOL )
3202 if ( elementsSelected >= 1 )
3204 onHideOutlines( currentSelection );
3207 else if( toolCommand == wxContour_ActionCommandsID::SHOW_TOOL )
3209 if ( elementsSelected >= 1 )
3211 onShowOutlines( currentSelection );
3214 else if( toolCommand == wxContour_ActionCommandsID::COPY_TOOL )
3216 if ( elementsSelected >= 1 )
3218 onCopyOutlines( currentSelection );
3221 else if( toolCommand == wxContour_ActionCommandsID::PASTE_TOOL )
3225 else if( toolCommand == wxContour_ActionCommandsID::SPREAD_TOOL )
3229 else if( toolCommand == wxContour_ActionCommandsID::AUTOMATIQUESEGMENTATION_TOOL )
3231 onAutomatiqueSegmentation( );
3234 else if( toolCommand == wxContour_ActionCommandsID::SELECT_TOOL )
3236 onSelectOutlines( currentSelection );
3239 else if( toolCommand == wxContour_ActionCommandsID::EDIT_TOOL )
3241 if ( elementsSelected >= 1 )
3243 onEditOutlines( currentSelection );
3246 else if( toolCommand == wxContour_ActionCommandsID::UNDO_TOOL )
3250 else if( toolCommand == wxContour_ActionCommandsID::REDO_TOOL )
3254 else if( toolCommand == wxContour_ActionCommandsID::INFORMATIONCONTOUR_TOOL )
3256 onInformationContourFrame();
3258 else if( toolCommand == wxContour_ActionCommandsID::INTERFACECONFIGURATION_TOOL )
3260 onInterfaceConfigurationFrame();
3262 else if( toolCommand == wxContour_ActionCommandsID::TEST_TOOL )
3264 onInterfaceTestFrame();
3271 //------------------------------------------------------------------------------------------------------------
3272 // Getting information methods
3273 //------------------------------------------------------------------------------------------------------------
3277 //------------------------------------------------------------------------------------------------------------
3279 //------------------------------------------------------------------------------------------------------------
3281 void wxContourEventHandler :: updateInstantOutlines()
3283 std::vector<NameWrapper *> namesWrapping = _modelManager->getActualInstantOutlines();
3284 int size = namesWrapping.size();
3285 _theViewPanel->getSceneManager()->removeSceneContours();
3286 for( int i=0; i<size; i++)
3288 _theViewPanel->getSceneManager()->addToScene(namesWrapping[i]->getKeyName(), true, true, true, false, false );
3291 //------------------------------------------------------------------------------------------------------------
3292 void wxContourEventHandler :: updateInstantImageData()
3294 wxContourMainFrame * instance = wxContourMainFrame::getInstance();
3295 if(instance != NULL){
3297 std::string conceptname;
3298 val = _instantPanel->getConceptValue(conceptname);
3300 if(conceptname.compare("time")==0){
3301 std::vector<vtkImageData*> imgvect = instance->getVectImages();
3302 for(int i = 0; i < imgvect.size(); i++){
3303 //_instantPanel->getI
3305 //ImageSourceThing* imgsoth = new ImageSourceThing();
3306 //_modelManager->addImageSource(
3310 //------------------------------------------------------------------------------------------------------------
3312 void wxContourEventHandler :: updateInstantAxes()
3316 //------------------------------------------------------------------------------------------------------------
3317 void wxContourEventHandler :: changeInstant()
3319 std::vector<int> instantVect;
3320 _instantPanel->getInstant( instantVect );
3321 Instant * theInstant = new Instant ( &instantVect );
3322 //if( !theInstant->isEquals( _actualInstant ))
3324 //Setting the actual instant
3325 _actualInstant = theInstant;
3326 _modelManager->setInstant( _actualInstant );
3328 updateInstantOutlines();
3329 updateInstantImageData();
3330 updateInstantAxes();
3333 //Searching the elements at the specified instant
3336 std::map<std::string, ContourWrap_ViewControl *> :: iterator iter;
3337 iter = contours_ViewControl->find("Outline 0");
3338 (iter->second)->getViewer()->RemoveCompleteContourActor();*/
3342 void wxContourEventHandler :: saveState(){
3348 //itoa(inundo, str, 10);
3349 std::string str = intToString(inundo);
3352 std::string temp = stundoredo + str + ".roi";
3353 saveFileWithContours(temp);
3358 void wxContourEventHandler ::loadState(std::string filename){
3361 FILE *pFile=fopen(filename.c_str(),"r+");
3363 fscanf(pFile,"%s",tmp); // --CreaContour--
3365 fscanf(pFile,"%s",tmp); // Version
3366 fscanf(pFile,"%s",tmp); // 1.0.1
3367 std::string version(tmp);
3369 deleteAllContours();
3371 openContours(pFile,false);
3372 if (version!="1.0.0"){
3373 openContours(pFile,true);
3378 //_theViewPanel->getSceneManager()->removeSceneContours();
3382 void wxContourEventHandler :: onREDO()
3389 //itoa(inundo, str, 10);
3390 std::string str = intToString(inundo);
3393 std::string temp = stundoredo + str + ".roi";
3401 //------------------------------------------------------------------------------------------------------------
3402 void wxContourEventHandler :: onUNDO()
3408 //itoa(inundo, str, 10);
3409 std::string str = intToString(inundo);
3411 std::string temp = stundoredo + str + ".roi";
3412 saveFileWithContours(temp);
3419 //itoa(inundo, str, 10);
3420 std::string str = intToString(inundo);
3423 std::string temp = stundoredo + str + ".roi";
3429 void wxContourEventHandler :: getValuesXYZ(double **vectx, double **vecty, double **vectz, std::vector<int>* size){
3433 ContourExtractData *contourextractdata = new ContourExtractData();
3434 int typeContourGroup = this->_radiolstboxContourGroup->GetSelection();
3435 contourextractdata ->SetTypeOperation( typeContourGroup % 3 );
3437 std::vector<manualContourModel*> lstManConMod;
3438 std::vector<manualContourModel*> lstManConModTmp;
3439 std::vector<manualContourModel*> lstManConModExp;
3440 std::vector<double> pLstValue;
3441 std::vector<double> pLstValuePosX;
3442 std::vector<double> pLstValuePosY;
3443 std::vector<double> pLstValuePosZ;
3445 std::vector<int> tempVector;
3446 _instantPanel->getInstant( tempVector );
3448 vtkImageData *imagedata = _theViewPanel->getSceneManager()->GetImageData();
3449 int sizeZ = _theViewPanel->getSceneManager()->GetImageDataSizeZ();
3451 int ii,sizeLstContourThings;
3458 minZ = 0;// _mbarrange->GetStart();
3459 maxZ = sizeZ;//_mbarrange->GetEnd();
3460 totalZ = maxZ-minZ+1;
3462 contourextractdata->SetImage( imagedata);
3465 vectx = new double *[sizeZ];
3466 vecty = new double *[sizeZ];
3467 vectz = new double *[sizeZ];
3468 for ( z=0 ; z<sizeZ ; z++)
3471 porcent = 100.0* (z-minZ)/totalZ;
3473 //Extraction data from contours of each slice
3474 contourextractdata->SetZtoBeAnalys( z);
3477 Instant instant(&tempVector);
3478 std::vector<ContourThing**> lstContourThings = this->_modelManager->getOutlinesAtInstant( &instant );
3479 sizeLstContourThings = lstContourThings.size();
3481 lstManConMod.clear();
3482 for (ii=0 ; ii<sizeLstContourThings ; ii++)
3484 ContourThing **contourthing = lstContourThings[ii];
3485 lstManConMod.push_back( (*contourthing)->getModel() );
3487 lstManConModExp = ExploseEachModel( lstManConMod );
3492 int iContourGroup,sizeContourGroup;
3493 if (typeContourGroup==3) // contour separete
3495 sizeContourGroup=lstManConModExp.size();
3496 } else { // contour AND OR XOR
3500 for( iContourGroup=0 ; iContourGroup<sizeContourGroup ; iContourGroup++ ){
3501 lstManConModTmp.clear();
3502 if (typeContourGroup==3) // contour separete
3504 lstManConModTmp.push_back( lstManConModExp[iContourGroup]);
3505 } else { // contour AND OR XOR
3506 lstManConModTmp = lstManConModExp;
3509 contourextractdata->SetLstManualContourModel( lstManConModTmp );
3512 pLstValuePosX.clear();
3513 pLstValuePosY.clear();
3514 pLstValuePosZ.clear();
3515 contourextractdata->GetValuesInsideCrown( &pLstValue,
3521 int iLstValue,sizeLstValue=pLstValue.size();
3523 //We initialize the pointers
3524 size->push_back(sizeLstValue);
3525 vectx[sizeZ] = new double[sizeLstValue];
3526 vecty[sizeZ] = new double[sizeLstValue];
3527 vectz[sizeZ] = new double[sizeLstValue];
3529 for (iLstValue=0 ; iLstValue<sizeLstValue ; iLstValue++ )
3532 vectx[sizeZ][iLstValue] = pLstValuePosX[iLstValue];
3533 vecty[sizeZ][iLstValue] = pLstValuePosY[iLstValue];
3534 vectz[sizeZ][iLstValue] = pLstValuePosZ[iLstValue];
3537 //The size of the contour is saved
3542 } // for iContourGroup
3544 //_staticTextInformation->SetLabel( _T("") );
3545 delete contourextractdata;
3550 void wxContourEventHandler :: getMaskValue(vtkImageData* mask, vtkImageData* value){
3554 ContourExtractData *contourextractdata = new ContourExtractData( true );
3555 int typeContourGroup = this->_radiolstboxContourGroup->GetSelection();
3556 if (typeContourGroup==3)
3560 contourextractdata ->SetTypeOperation( typeContourGroup % 3 );
3562 std::vector<manualContourModel*> lstManConMod;
3563 std::vector<manualContourModel*> lstManConModTmp;
3564 std::vector<manualContourModel*> lstManConModExp;
3566 std::vector<int> tempVector;
3567 _instantPanel->getInstant( tempVector );
3569 vtkImageData *imagedata = _theViewPanel->getSceneManager()->GetImageData();
3570 int sizeZ = _theViewPanel->getSceneManager()->GetImageDataSizeZ();
3572 int ii,sizeLstContourThings;
3581 minZ = 0;// _mbarrange->GetStart();
3582 maxZ = sizeZ;//_mbarrange->GetEnd();
3583 totalZ = maxZ-minZ+1;
3585 contourextractdata->SetImage( imagedata);
3588 for ( z=0 ; z<sizeZ ; z++)
3591 porcent = 100.0* (z-minZ)/totalZ;
3592 tmpString.Printf(_T("Saving Values"));
3593 tmpString.Printf(_T(" %d %c %d/%d %d"), (int)porcent , 37 , z-minZ+1, (int)totalZ ,z);
3594 _staticTextInformation->SetLabel(tmpString);
3596 //Extraction data from contours of each slice
3597 contourextractdata->SetZtoBeAnalys( z);
3600 Instant instant(&tempVector);
3601 std::vector<ContourThing**> lstContourThings = this->_modelManager->getOutlinesAtInstant( &instant );
3602 sizeLstContourThings = lstContourThings.size();
3604 lstManConMod.clear();
3605 for (ii=0 ; ii<sizeLstContourThings ; ii++)
3607 ContourThing **contourthing = lstContourThings[ii];
3608 lstManConMod.push_back( (*contourthing)->getModel() );
3610 lstManConModExp = ExploseEachModel( lstManConMod );
3613 int iContourGroup,sizeContourGroup;
3614 if (typeContourGroup==3) // contour separete
3616 sizeContourGroup=lstManConModExp.size();
3617 } else { // contour AND OR XOR
3621 for( iContourGroup=0 ; iContourGroup<sizeContourGroup ; iContourGroup++ ){
3622 lstManConModTmp.clear();
3623 if (typeContourGroup==3) // contour separete
3625 lstManConModTmp.push_back( lstManConModExp[iContourGroup]);
3626 } else { // contour AND OR XOR
3627 lstManConModTmp = lstManConModExp;
3630 contourextractdata->SetLstManualContourModel( lstManConModTmp );
3633 contourextractdata->CalculateImageResult(); // with actual Z
3635 } // for iContourGroup
3641 value = contourextractdata->GetVtkImageValueResult();
3644 mask = contourextractdata->GetVtkImageMaskResult();
3646 delete contourextractdata;
3650 wxPanel* wxContourEventHandler::getSegmentationPanelITK(wxWindow* parent){
3652 int sizeZ = _theViewPanel->getSceneManager()->GetImageDataSizeZ();
3654 _theViewPanel->getSceneManager()->GetImageDataRange(range);
3656 wxPanel *panel = new wxPanel(parent,-1);
3657 wxButton *segmentationOneSliceBtn = new wxButton(panel,-1,_T("Actual slice"), wxDefaultPosition, wxSize(200,35) );
3658 wxButton *segmentationAllSliceBtn = new wxButton(panel,-1,_T("All slices") ,wxDefaultPosition, wxSize(200,35) );
3659 _isovalue = new wxSlider(panel, -1, 40 , (int)(range[0]), (int)(range[1]), wxDefaultPosition, wxSize(200,35), wxSL_HORIZONTAL|wxSL_LABELS, wxDefaultValidator);
3660 _sampling = new wxSlider(panel, -1, 20 , 4, 50, wxDefaultPosition, wxSize(200,35), wxSL_HORIZONTAL|wxSL_LABELS, wxDefaultValidator);
3661 wxString lstOptions[3];
3662 lstOptions[0]=_T("A");
3663 lstOptions[1]=_T("B");
3664 lstOptions[2]=_T("C");
3665 methodRadiobox = new wxRadioBox(panel, -1, _T("Method (find ctrl. Points)"), wxDefaultPosition, wxSize(200,45), 3 , lstOptions, 3, wxRA_SPECIFY_COLS);
3666 methodRadiobox->SetSelection(2);
3667 _staticTextSegmentation = new wxStaticText(panel,-1,_T(" "));
3670 _mbarrange = new mBarRange(panel,70, 65);
3671 _mbarrange->SetMin(0);
3672 _mbarrange->SetStart(0);
3674 _mbarrange-> SetOrientation( true );
3675 _mbarrange-> setActiveStateTo(true);
3676 _mbarrange-> setVisibleLabels( true );
3677 _mbarrange-> setDeviceEndMargin(10);
3678 _mbarrange-> setRepresentedValues( 0 , sizeZ );
3679 _mbarrange-> setDeviceBlitStart(10,10);
3680 _mbarrange-> setIfWithActualDrawed( false );
3681 _mbarrange-> SetStart( 0 );
3682 _mbarrange-> SetEnd( sizeZ );
3685 // _segmentationFrame->SetEventHandler( this );
3686 segmentationOneSliceBtn->SetEventHandler( this );
3687 segmentationAllSliceBtn->SetEventHandler( this );
3688 Connect( segmentationOneSliceBtn->GetId(), wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &wxContourEventHandler::onSegmentationOneSliceITK );
3689 Connect( segmentationAllSliceBtn->GetId(), wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &wxContourEventHandler::onSegmentationAllSliceITK );
3691 wxFlexGridSizer * sizer = new wxFlexGridSizer(1);
3692 sizer -> Add( new wxStaticText(panel,-1,_T("Isovalue (Gray level)")) , 1, wxGROW );
3693 sizer -> Add( _isovalue , 1, wxGROW );
3694 sizer -> Add( methodRadiobox , 1, wxGROW );
3695 sizer -> Add( new wxStaticText(panel,-1,_T("Sampling (%)")) , 1, wxGROW );
3696 sizer -> Add( _sampling , 1, wxGROW );
3697 sizer -> Add( segmentationOneSliceBtn , 1, wxGROW );
3698 sizer -> Add( new wxStaticText(panel,-1,_T(" ")) , 1, wxGROW );
3699 sizer -> Add( _staticTextSegmentation , 1, wxGROW );
3700 sizer -> Add( segmentationAllSliceBtn , 1, wxGROW );
3701 sizer -> Add( _mbarrange , 1, wxGROW );
3703 panel->SetSizer( sizer );
3704 // panel->SetSize( sizePanel );
3705 panel->SetSize( wxDefaultSize );
3706 panel->SetAutoLayout( true );
3713 void wxContourEventHandler::onSegmentationAllSliceITK( wxCommandEvent& event ){
3714 //TODO implementar el m�todo para todos los slices ver ayuda en onSegmentationAllSlice
3716 void wxContourEventHandler::onSegmentationOneSliceITK( wxCommandEvent& event ){
3717 //TODO implementar el m�todo de segmentaci�n en ITK ver ayuda en onSegmentationOneSlice y el m�todo
3718 // SegmentationOneSlice(x, y, z) que es la implementaci�n del m�todo en VTK
3720 //JCP 20-10-08 Undo redo implementation
3722 //JCP 20-10-08 Undo redo implementation
3725 int x = this->_theViewPanel->GetX();
3726 int y = this->_theViewPanel->GetY();
3727 int z = this->_theViewPanel->GetZ();
3728 //SegmentationOneSlice( x,y,z );
3731 void wxContourEventHandler::onSnakePressed(wxWindow* parent){
3733 std::vector<double> vecX;
3734 std::vector<double> vecY;
3735 std::vector<double> vecZ;
3736 _theViewPanel->getSceneManager()->GetPointsOfActualContour( &vecX , &vecY , &vecZ );
3738 if (vecX.size()!=0){
3739 std::vector<int> tempVector;
3740 _instantPanel->getInstant( tempVector );
3741 int i,size=vecZ.size();
3742 int actualSlice = tempVector[1];
3743 for ( i=0 ; i<size ; i++ )
3745 vecZ[i] = actualSlice;
3748 wxDialog* dialog = new wxDialog(parent, -1, wxString(_T("Snake")));
3749 wxPanel* panel = new wxPanel(dialog,-1);
3750 wxStaticText* sttext = new wxStaticText(panel, -1, wxString(_T("Panel para snake")));
3751 dialog->ShowModal();
3756 void wxContourEventHandler::checkInformationPanel(){
3757 if (_InformationContourFrame==NULL){
3758 onInformationContourFrame();
3759 _InformationContourFrame->Show(false);
3763 std::string wxContourEventHandler::intToString(int num){
3770 char temp = k % 10 + 48;
3772 result = temp + result;