3 * \brief ClassThresholdImageViewPanel .
7 #include "ColorLayerImageViewPanel.h"
8 #include "OpenImageDialog.h"
11 //---------------------------------------------------------
12 //---------------------------------------------------------
13 //---------------------------------------------------------
15 wxDlgTransformByDimensionBySpacingByPixel::wxDlgTransformByDimensionBySpacingByPixel()
19 wxDlgTransformByDimensionBySpacingByPixel::~wxDlgTransformByDimensionBySpacingByPixel()
24 void wxDlgTransformByDimensionBySpacingByPixel::GetTransformType(wxWindow *parent , wxString message,int &typeOfTransformation,bool &dlgWxOK)
26 wxDialog* dial = new wxDialog (parent,-1,_T("Tools"),wxDefaultPosition, wxSize(590,190));
27 wxSizer* buttonsSizer = dial->CreateSeparatedButtonSizer(wxOK|wxCANCEL);
28 wxBoxSizer *dialSizer = new wxBoxSizer(wxVERTICAL);
30 wxString lstOptOperation[3];
31 lstOptOperation[0]=_T("By Dimension");
32 lstOptOperation[1]=_T("By Spacing");
33 lstOptOperation[2]=_T("By Pixel");
34 wxRadioBox * radioOpts = new wxRadioBox(dial, -1, _T("Type of Transformation"), wxDefaultPosition, wxSize(270,45), 3 , lstOptOperation, 3, wxRA_SPECIFY_COLS);
36 dialSizer->Add( new wxStaticText(dial,-1,message) , 0, wxGROW );
37 // dialSizer->Add( new wxStaticText(dial,-1,_T("selected Roi file. Do you want to tranform it?")) , 0, wxGROW );
38 dialSizer->Add( new wxStaticText(dial,-1,_T(" ")) , 0, wxGROW );
39 dialSizer->Add(radioOpts,0,wxGROW);
40 dialSizer->Add( new wxStaticText(dial,-1,_T(" ")) , 0, wxGROW );
41 dialSizer->Add(buttonsSizer,0,wxGROW);
42 dial->SetSizer(dialSizer, true);
46 typeOfTransformation = -1;
49 if (dial->GetReturnCode() == wxID_OK)
51 typeOfTransformation = radioOpts->GetSelection() + 1;
57 //---------------------------------------------------------
58 //---------------------------------------------------------
59 //---------------------------------------------------------
63 ** Begin of the threshold panel
65 ColorLayerImageViewPanel::ColorLayerImageViewPanel(wxWindow* parent, int min, int max, int type)
66 : wxPanel(parent, -1, wxDefaultPosition, wxDefaultSize, wxBORDER_SUNKEN)
68 printf("EED ColorLayerImageViewPanel::ColorLayerImageViewPanel start \n");
70 _spcBase[0] = _spcBase[1] = _spcBase[2] = 0;
71 _dimBase[0] = _dimBase[1] = _dimBase[2] = 0;
73 _colorLayerImageView = new ColorLayerImageView();
74 _btn_ReadImage = new wxButton(this, wxID_ANY, _T("Read Image") );
76 _cb_ShowHide = new wxCheckBox(this, wxID_ANY, _T("Show/Hide Layer") );
77 _cb_ShowHide->SetValue(_thresholdGo);
79 _cb_SliceFixDinamic = new wxCheckBox(this, wxID_ANY, _T("Fixed/Dynamic Slice") );
80 _cb_SliceFixDinamic->SetValue(true);
82 _sl_SliceImage = new wxSlider(this, wxID_ANY, 0, 1000, 1000, wxDefaultPosition, wxDefaultSize, wxSL_HORIZONTAL|wxSL_LABELS, wxDefaultValidator);
83 _sl_SliceImage->Enable(false);
85 _interpolationCheckBox = new wxCheckBox(this, -1, _T("Image Interpolation") );
86 _interpolationCheckBox->SetValue(true);
87 _opacity = new wxSlider(this, wxID_ANY, 6, 1, 10, wxDefaultPosition, wxDefaultSize, wxSL_HORIZONTAL|wxSL_LABELS, wxDefaultValidator);
98 Connect( _btn_ReadImage->GetId(), wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &ColorLayerImageViewPanel::onReadImage );
99 Connect( _cb_ShowHide->GetId(), wxEVT_COMMAND_CHECKBOX_CLICKED , (wxObjectEventFunction) &ColorLayerImageViewPanel::onThresholdShow );
100 Connect( _interpolationCheckBox->GetId(), wxEVT_COMMAND_CHECKBOX_CLICKED, (wxObjectEventFunction) &ColorLayerImageViewPanel::onThresholdInterpolation );
101 Connect( _opacity->GetId(), wxEVT_SCROLL_THUMBTRACK, (wxObjectEventFunction) &ColorLayerImageViewPanel::onChangeOpacity );
102 Connect( _cb_SliceFixDinamic->GetId(), wxEVT_COMMAND_CHECKBOX_CLICKED, (wxObjectEventFunction) &ColorLayerImageViewPanel::onSliceFixDinamic );
103 Connect( _sl_SliceImage->GetId(), wxEVT_SCROLL_THUMBTRACK , (wxObjectEventFunction) &ColorLayerImageViewPanel::onSliceImage );
104 Connect( _sl_SliceImage->GetId(), wxEVT_SCROLL_LINEUP , (wxObjectEventFunction) &ColorLayerImageViewPanel::onSliceImage );
105 Connect( _sl_SliceImage->GetId(), wxEVT_SCROLL_LINEDOWN , (wxObjectEventFunction) &ColorLayerImageViewPanel::onSliceImage );
106 Connect( _sl_SliceImage->GetId(), wxEVT_SCROLL_PAGEUP , (wxObjectEventFunction) &ColorLayerImageViewPanel::onSliceImage );
107 Connect( _sl_SliceImage->GetId(), wxEVT_SCROLL_PAGEDOWN , (wxObjectEventFunction) &ColorLayerImageViewPanel::onSliceImage );
110 wxFlexGridSizer * sizer = new wxFlexGridSizer(1);
113 sizer -> Add( new wxStaticText(this,-1,_T("Color Image Layer")) , 1, wxGROW );
114 sizer -> Add( _btn_ReadImage, 1, wxGROW );
115 sizer -> Add( new wxStaticText(this,-1,_T(" ")) , 1, wxGROW );
117 sizer -> Add( new wxStaticText(this,-1,_T("Opacity Level")) , 1, wxGROW );
118 sizer -> Add( _opacity, 1, wxGROW );
119 sizer -> Add( new wxStaticText(this,-1,_T(" ")) , 1, wxGROW );
120 sizer -> Add( _cb_ShowHide, 1, wxGROW );
121 sizer -> Add( new wxStaticText(this,-1,_T(" ")) , 1, wxGROW );
122 sizer -> Add( _interpolationCheckBox, 1, wxGROW );
124 sizer -> Add( new wxStaticText(this,-1,_T(" ")) , 1, wxGROW );
125 sizer -> Add( new wxStaticText(this,-1,_T("Slice ")) , 1, wxGROW );
126 sizer -> Add( _sl_SliceImage, 1, wxGROW );
127 sizer -> Add( _cb_SliceFixDinamic, 1, wxGROW );
129 this->SetSizer( sizer );
130 this->SetAutoLayout( true );
133 //CM Sets the default fitting mode to Pixel mode.
138 //----------------------------------------------------------------------------
139 ColorLayerImageViewPanel::~ColorLayerImageViewPanel()
144 //----------------------------------------------------------------------------
145 void ColorLayerImageViewPanel::SetColorLayerImageView(ColorLayerImageView* colorLayerImageView)
147 _colorLayerImageView = colorLayerImageView;
150 //----------------------------------------------------------------------------
151 ColorLayerImageView* ColorLayerImageViewPanel::GetColorLayerImageView()
153 return _colorLayerImageView;
157 // This is the new spacing of the background image (1,1,1)
158 void ColorLayerImageViewPanel::SetBaseSpacing(double spc[3])
160 _spcBase[0] = spc[0];
161 _spcBase[1] = spc[1];
162 _spcBase[2] = spc[2];
169 // This is the Original spacing of the background image
170 void ColorLayerImageViewPanel::SetOriginalSpacing(double spc[3])
177 // This is the size in pixels of the background image
178 void ColorLayerImageViewPanel::SetBaseDimension(int dim[3])
180 _dimBase[0] = dim[0];
181 _dimBase[1] = dim[1];
182 _dimBase[2] = dim[2];
185 //----------------------------------------------------------------------------
186 void ColorLayerImageViewPanel::SetImage(vtkImageData *img)
190 _colorLayerImageView->SetImage( img );
193 img->GetSpacing(spc);
197 img->GetWholeExtent(ext);
198 dim[0] = ext[1]-ext[0];
199 dim[1] = ext[3]-ext[2];
200 dim[2] = ext[5]-ext[4];
201 _sl_SliceImage->SetRange( 0 , dim[2] );
203 if ( (spc[0]!=_spcBase[0]) || (spc[1]!=_spcBase[1]) || (spc[2]!=_spcBase[2]) ||
204 (dim[0]!=_dimBase[0]) || (spc[1]!=_spcBase[1]) || (spc[2]!=_spcBase[2])
208 int typeOfTransformation;
209 // In case of the option is set to create a dialog box.
210 if (_fitting_mode == -1)
213 wxString msg = _T("The image resolution of both images are not compatible. Do you want to tranform it? ");
214 wxDlgTransformByDimensionBySpacingByPixel dlg;
215 dlg.GetTransformType(this,msg,typeOfTransformation,transformOkDlg);
216 // CM Reset the default value (Pixel i.e. 3) if the dialog box returned an inappropriate value.
217 if (transformOkDlg == false)
218 typeOfTransformation = 3;
221 typeOfTransformation = _fitting_mode;
224 printf("EED ColorLayerImageViewPanel::onReadImage call dialog spc size,dim...???\n");
226 if (typeOfTransformation==1) // make dimensions equals
228 printf("EED ColorLayerImageViewPanel::onReadImage ...WARNNING.... dif size image spc*dim ofnew image ...???\n");
229 spc[0]=_spcBase[0]*_dimBase[0]/dim[0];
230 spc[1]=_spcBase[1]*_dimBase[1]/dim[1];
234 if (typeOfTransformation==2) // make spacing equals
236 spc[0] = ( _spcBase[0]/spc[0] ) * _spcOrg[0];
237 spc[1] = ( _spcBase[1]/spc[1] ) * _spcOrg[1];
238 spc[2] = ( _spcBase[2]/spc[2] ) * _spcOrg[2];
241 if (typeOfTransformation==3) // make spacing = 1
248 img->SetSpacing(spc);
249 } // spc !_spcBase dim!__dimBase
251 if (_colorLayerImageView!=NULL)
253 _colorLayerImageView->onThreshold();
254 _colorLayerImageView->Refresh();
261 //----------------------------------------------------------------------------
262 void ColorLayerImageViewPanel::SetFittingMode(int fitting_mode)
264 // CM Sets the fitting mode if an appropriate value is provided.
265 if (fitting_mode == -1 || fitting_mode == 1 || fitting_mode == 2 || fitting_mode == 3)
267 _fitting_mode = fitting_mode;
269 //Otherwise, an exception should be thrown (value 0 is fine, it corresponds to an empty field i.e. the default value is kept).
270 else if (fitting_mode != 0)
271 std::cout << "CM ERROR!!! The fitting mode provided has an inappropriate value. It should be an int between -1 ; 1 ; 2 ; 3, but its value is :" << fitting_mode << ". The default value will be set instead, i.e. Pixel transformation (3)." << std::endl;
275 //----------------------------------------------------------------------------
276 int ColorLayerImageViewPanel::GetFittingMode()
278 return _fitting_mode;
281 //----------------------------------------------------------------------------
282 void ColorLayerImageViewPanel::onReadImage(wxCommandEvent& event)
285 // creaImageIO::WxSimpleDlg w(0,_T("Select your image"),"creaContours_Descriptor.dscp","creatisContours DB");
287 printf("EED ColorLayerImageViewPanel::onReadImage ....WARNING... Read dlg. all images creaImageIO ... ???\n");
289 creaMaracasVisuKernel::OpenImageDialog diag = creaMaracasVisuKernel::OpenImageDialog();
290 SetImage( diag.getImageData() );
293 //----------------------------------------------------------------------------
294 void ColorLayerImageViewPanel::onThresholdChange(wxCommandEvent& event)
296 if (_colorLayerImageView!=NULL)
300 _colorLayerImageView->onThresholdChange();
301 _colorLayerImageView->Refresh();
302 //std::cout<< "Valor Min: " << minVal << " & Valor Max: " << maxVal << std::endl;
304 }//_colorLayerImageView
307 //----------------------------------------------------------------------------
308 void ColorLayerImageViewPanel::onThresholdShow(wxCommandEvent& event)
310 if (_colorLayerImageView!=NULL)
312 _thresholdGo = _cb_ShowHide->GetValue();
315 _colorLayerImageView->onThreshold();
317 _colorLayerImageView->onThresholdRemove( );
319 _colorLayerImageView->Refresh();
320 }//_colorLayerImageView
323 //----------------------------------------------------------------------------
324 void ColorLayerImageViewPanel::onThresholdStop()
326 if (_colorLayerImageView!=NULL)
330 _colorLayerImageView->onThresholdRemove( );
333 }//_colorLayerImageView
336 //----------------------------------------------------------------------------
337 void ColorLayerImageViewPanel::onThresholdInterpolation(wxCommandEvent& event)
339 if (_colorLayerImageView!=NULL)
341 _colorLayerImageView->onThresholdInterpolation(_interpolationCheckBox->GetValue());
342 _colorLayerImageView->Refresh();
343 }//_colorLayerImageView
346 //----------------------------------------------------------------------------
347 void ColorLayerImageViewPanel::onSliceFixDinamic(wxCommandEvent& event)
349 if (_colorLayerImageView!=NULL)
351 bool fixdin = _cb_SliceFixDinamic->GetValue();
352 _colorLayerImageView->SetSliceFixDynamic( fixdin );
355 _colorLayerImageView->SetZ2( _sl_SliceImage->GetValue() );
357 _sl_SliceImage->Enable(!fixdin);
358 _colorLayerImageView->onThreshold();
359 _colorLayerImageView->Refresh();
360 }//_colorLayerImageView
363 //----------------------------------------------------------------------------
364 void ColorLayerImageViewPanel::onSliceImage(wxScrollEvent& event)
366 if (_colorLayerImageView!=NULL)
368 _colorLayerImageView->SetZ2( _sl_SliceImage->GetValue() );
369 _colorLayerImageView->onThreshold();
370 _colorLayerImageView->Refresh();
371 }//_colorLayerImageView
374 //----------------------------------------------------------------------------
375 void ColorLayerImageViewPanel::onChangeOpacity(wxScrollEvent& event)
377 if (_colorLayerImageView!=NULL)
379 int opacity = _opacity->GetValue();
380 _colorLayerImageView->onThresholdChangeOpacity(opacity);
381 _colorLayerImageView->Refresh();
382 }//_colorLayerImageView
386 //----------------------------------------------------------------------------
387 bool ColorLayerImageViewPanel::IsVisible()