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 * \brief ClassThresholdImageViewPanel .
32 #include "ColorLayerImageViewPanel.h"
33 #include "OpenImageDialog.h"
36 //---------------------------------------------------------
37 //---------------------------------------------------------
38 //---------------------------------------------------------
40 wxDlgTransformByDimensionBySpacingByPixel::wxDlgTransformByDimensionBySpacingByPixel()
44 wxDlgTransformByDimensionBySpacingByPixel::~wxDlgTransformByDimensionBySpacingByPixel()
49 void wxDlgTransformByDimensionBySpacingByPixel::GetTransformType(wxWindow *parent , wxString message,int &typeOfTransformation,bool &dlgWxOK)
51 wxDialog* dial = new wxDialog (parent,-1,_T("Tools"),wxDefaultPosition, wxSize(590,190));
52 wxSizer* buttonsSizer = dial->CreateSeparatedButtonSizer(wxOK|wxCANCEL);
53 wxBoxSizer *dialSizer = new wxBoxSizer(wxVERTICAL);
55 wxString lstOptOperation[3];
56 lstOptOperation[0]=_T("By Dimension");
57 lstOptOperation[1]=_T("By Spacing");
58 lstOptOperation[2]=_T("By Pixel");
59 wxRadioBox * radioOpts = new wxRadioBox(dial, -1, _T("Type of Transformation"), wxDefaultPosition, wxSize(270,45), 3 , lstOptOperation, 3, wxRA_SPECIFY_COLS);
61 dialSizer->Add( new wxStaticText(dial,-1,message) , 0, wxGROW );
62 // dialSizer->Add( new wxStaticText(dial,-1,_T("selected Roi file. Do you want to tranform it?")) , 0, wxGROW );
63 dialSizer->Add( new wxStaticText(dial,-1,_T(" ")) , 0, wxGROW );
64 dialSizer->Add(radioOpts,0,wxGROW);
65 dialSizer->Add( new wxStaticText(dial,-1,_T(" ")) , 0, wxGROW );
66 dialSizer->Add(buttonsSizer,0,wxGROW);
67 dial->SetSizer(dialSizer, true);
71 typeOfTransformation = -1;
74 if (dial->GetReturnCode() == wxID_OK)
76 typeOfTransformation = radioOpts->GetSelection() + 1;
82 //---------------------------------------------------------
83 //---------------------------------------------------------
84 //---------------------------------------------------------
88 ** Begin of the threshold panel
90 ColorLayerImageViewPanel::ColorLayerImageViewPanel(wxWindow* parent, int min, int max, int type)
91 : wxPanel(parent, -1, wxDefaultPosition, wxDefaultSize, wxBORDER_SUNKEN)
93 printf("EED ColorLayerImageViewPanel::ColorLayerImageViewPanel start \n");
95 _spcBase[0] = _spcBase[1] = _spcBase[2] = 0;
96 _dimBase[0] = _dimBase[1] = _dimBase[2] = 0;
98 _colorLayerImageView = new ColorLayerImageView();
99 _btn_ReadImage = new wxButton(this, wxID_ANY, _T("Read Image") );
101 _cb_ShowHide = new wxCheckBox(this, wxID_ANY, _T("Show/Hide Layer") );
102 _cb_ShowHide->SetValue(_thresholdGo);
104 _cb_SliceFixDinamic = new wxCheckBox(this, wxID_ANY, _T("Fixed/Dynamic Slice") );
105 _cb_SliceFixDinamic->SetValue(true);
107 _sl_SliceImage = new wxSlider(this, wxID_ANY, 0, 1000, 1000, wxDefaultPosition, wxDefaultSize, wxSL_HORIZONTAL|wxSL_LABELS, wxDefaultValidator);
108 _sl_SliceImage->Enable(false);
110 _interpolationCheckBox = new wxCheckBox(this, -1, _T("Image Interpolation") );
111 _interpolationCheckBox->SetValue(true);
112 _opacity = new wxSlider(this, wxID_ANY, 6, 1, 10, wxDefaultPosition, wxDefaultSize, wxSL_HORIZONTAL|wxSL_LABELS, wxDefaultValidator);
123 Connect( _btn_ReadImage->GetId(), wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &ColorLayerImageViewPanel::onReadImage );
124 Connect( _cb_ShowHide->GetId(), wxEVT_COMMAND_CHECKBOX_CLICKED , (wxObjectEventFunction) &ColorLayerImageViewPanel::onThresholdShow );
125 Connect( _interpolationCheckBox->GetId(), wxEVT_COMMAND_CHECKBOX_CLICKED, (wxObjectEventFunction) &ColorLayerImageViewPanel::onThresholdInterpolation );
126 Connect( _opacity->GetId(), wxEVT_SCROLL_THUMBTRACK, (wxObjectEventFunction) &ColorLayerImageViewPanel::onChangeOpacity );
127 Connect( _cb_SliceFixDinamic->GetId(), wxEVT_COMMAND_CHECKBOX_CLICKED, (wxObjectEventFunction) &ColorLayerImageViewPanel::onSliceFixDinamic );
128 Connect( _sl_SliceImage->GetId(), wxEVT_SCROLL_THUMBTRACK , (wxObjectEventFunction) &ColorLayerImageViewPanel::onSliceImage );
129 Connect( _sl_SliceImage->GetId(), wxEVT_SCROLL_LINEUP , (wxObjectEventFunction) &ColorLayerImageViewPanel::onSliceImage );
130 Connect( _sl_SliceImage->GetId(), wxEVT_SCROLL_LINEDOWN , (wxObjectEventFunction) &ColorLayerImageViewPanel::onSliceImage );
131 Connect( _sl_SliceImage->GetId(), wxEVT_SCROLL_PAGEUP , (wxObjectEventFunction) &ColorLayerImageViewPanel::onSliceImage );
132 Connect( _sl_SliceImage->GetId(), wxEVT_SCROLL_PAGEDOWN , (wxObjectEventFunction) &ColorLayerImageViewPanel::onSliceImage );
135 wxFlexGridSizer * sizer = new wxFlexGridSizer(1);
138 sizer -> Add( new wxStaticText(this,-1,_T("Color Image Layer")) , 1, wxGROW );
139 sizer -> Add( _btn_ReadImage, 1, wxGROW );
140 sizer -> Add( new wxStaticText(this,-1,_T(" ")) , 1, wxGROW );
142 sizer -> Add( new wxStaticText(this,-1,_T("Opacity Level")) , 1, wxGROW );
143 sizer -> Add( _opacity, 1, wxGROW );
144 sizer -> Add( new wxStaticText(this,-1,_T(" ")) , 1, wxGROW );
145 sizer -> Add( _cb_ShowHide, 1, wxGROW );
146 sizer -> Add( new wxStaticText(this,-1,_T(" ")) , 1, wxGROW );
147 sizer -> Add( _interpolationCheckBox, 1, wxGROW );
149 sizer -> Add( new wxStaticText(this,-1,_T(" ")) , 1, wxGROW );
150 sizer -> Add( new wxStaticText(this,-1,_T("Slice ")) , 1, wxGROW );
151 sizer -> Add( _sl_SliceImage, 1, wxGROW );
152 sizer -> Add( _cb_SliceFixDinamic, 1, wxGROW );
154 this->SetSizer( sizer );
155 this->SetAutoLayout( true );
158 //CM Sets the default fitting mode to Pixel mode.
163 //----------------------------------------------------------------------------
164 ColorLayerImageViewPanel::~ColorLayerImageViewPanel()
169 //----------------------------------------------------------------------------
170 void ColorLayerImageViewPanel::SetColorLayerImageView(ColorLayerImageView* colorLayerImageView)
172 _colorLayerImageView = colorLayerImageView;
175 //----------------------------------------------------------------------------
176 ColorLayerImageView* ColorLayerImageViewPanel::GetColorLayerImageView()
178 return _colorLayerImageView;
182 // This is the new spacing of the background image (1,1,1)
183 void ColorLayerImageViewPanel::SetBaseSpacing(double spc[3])
185 _spcBase[0] = spc[0];
186 _spcBase[1] = spc[1];
187 _spcBase[2] = spc[2];
194 // This is the Original spacing of the background image
195 void ColorLayerImageViewPanel::SetOriginalSpacing(double spc[3])
202 // This is the size in pixels of the background image
203 void ColorLayerImageViewPanel::SetBaseDimension(int dim[3])
205 _dimBase[0] = dim[0];
206 _dimBase[1] = dim[1];
207 _dimBase[2] = dim[2];
210 //----------------------------------------------------------------------------
211 void ColorLayerImageViewPanel::SetImage(vtkImageData *img)
215 _colorLayerImageView->SetImage( img );
218 img->GetSpacing(spc);
222 img->GetWholeExtent(ext);
223 dim[0] = ext[1]-ext[0];
224 dim[1] = ext[3]-ext[2];
225 dim[2] = ext[5]-ext[4];
226 _sl_SliceImage->SetRange( 0 , dim[2] );
228 if ( (spc[0]!=_spcBase[0]) || (spc[1]!=_spcBase[1]) || (spc[2]!=_spcBase[2]) ||
229 (dim[0]!=_dimBase[0]) || (spc[1]!=_spcBase[1]) || (spc[2]!=_spcBase[2])
233 int typeOfTransformation;
234 // In case of the option is set to create a dialog box.
235 if (_fitting_mode == -1)
238 wxString msg = _T("The image resolution of both images are not compatible. Do you want to tranform it? ");
239 wxDlgTransformByDimensionBySpacingByPixel dlg;
240 dlg.GetTransformType(this,msg,typeOfTransformation,transformOkDlg);
241 // CM Reset the default value (Pixel i.e. 3) if the dialog box returned an inappropriate value.
242 if (transformOkDlg == false)
243 typeOfTransformation = 3;
246 typeOfTransformation = _fitting_mode;
249 printf("EED ColorLayerImageViewPanel::onReadImage call dialog spc size,dim...???\n");
251 if (typeOfTransformation==1) // make dimensions equals
253 printf("EED ColorLayerImageViewPanel::onReadImage ...WARNNING.... dif size image spc*dim ofnew image ...???\n");
254 spc[0]=_spcBase[0]*_dimBase[0]/dim[0];
255 spc[1]=_spcBase[1]*_dimBase[1]/dim[1];
259 if (typeOfTransformation==2) // make spacing equals
261 spc[0] = ( _spcBase[0]/spc[0] ) * _spcOrg[0];
262 spc[1] = ( _spcBase[1]/spc[1] ) * _spcOrg[1];
263 spc[2] = ( _spcBase[2]/spc[2] ) * _spcOrg[2];
266 if (typeOfTransformation==3) // make spacing = 1
273 img->SetSpacing(spc);
274 } // spc !_spcBase dim!__dimBase
276 if (_colorLayerImageView!=NULL)
278 _colorLayerImageView->onThreshold();
279 _colorLayerImageView->Refresh();
286 //----------------------------------------------------------------------------
287 void ColorLayerImageViewPanel::SetFittingMode(int fitting_mode)
289 // CM Sets the fitting mode if an appropriate value is provided.
290 if (fitting_mode == -1 || fitting_mode == 1 || fitting_mode == 2 || fitting_mode == 3)
292 _fitting_mode = fitting_mode;
294 //Otherwise, an exception should be thrown (value 0 is fine, it corresponds to an empty field i.e. the default value is kept).
295 else if (fitting_mode != 0)
296 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;
300 //----------------------------------------------------------------------------
301 int ColorLayerImageViewPanel::GetFittingMode()
303 return _fitting_mode;
306 //----------------------------------------------------------------------------
307 void ColorLayerImageViewPanel::onReadImage(wxCommandEvent& event)
310 // creaImageIO::WxSimpleDlg w(0,_T("Select your image"),"creaContours_Descriptor.dscp","creatisContours DB");
312 printf("EED ColorLayerImageViewPanel::onReadImage ....WARNING... Read dlg. all images creaImageIO ... ???\n");
314 creaMaracasVisuKernel::OpenImageDialog diag = creaMaracasVisuKernel::OpenImageDialog();
315 SetImage( diag.getImageData() );
318 //----------------------------------------------------------------------------
319 void ColorLayerImageViewPanel::onThresholdChange(wxCommandEvent& event)
321 if (_colorLayerImageView!=NULL)
325 _colorLayerImageView->onThresholdChange();
326 _colorLayerImageView->Refresh();
327 //std::cout<< "Valor Min: " << minVal << " & Valor Max: " << maxVal << std::endl;
329 }//_colorLayerImageView
332 //----------------------------------------------------------------------------
333 void ColorLayerImageViewPanel::onThresholdShow(wxCommandEvent& event)
335 if (_colorLayerImageView!=NULL)
337 _thresholdGo = _cb_ShowHide->GetValue();
340 _colorLayerImageView->onThreshold();
342 _colorLayerImageView->onThresholdRemove( );
344 _colorLayerImageView->Refresh();
345 }//_colorLayerImageView
348 //----------------------------------------------------------------------------
349 void ColorLayerImageViewPanel::onThresholdStop()
351 if (_colorLayerImageView!=NULL)
355 _colorLayerImageView->onThresholdRemove( );
358 }//_colorLayerImageView
361 //----------------------------------------------------------------------------
362 void ColorLayerImageViewPanel::onThresholdInterpolation(wxCommandEvent& event)
364 if (_colorLayerImageView!=NULL)
366 _colorLayerImageView->onThresholdInterpolation(_interpolationCheckBox->GetValue());
367 _colorLayerImageView->Refresh();
368 }//_colorLayerImageView
371 //----------------------------------------------------------------------------
372 void ColorLayerImageViewPanel::onSliceFixDinamic(wxCommandEvent& event)
374 if (_colorLayerImageView!=NULL)
376 bool fixdin = _cb_SliceFixDinamic->GetValue();
377 _colorLayerImageView->SetSliceFixDynamic( fixdin );
380 _colorLayerImageView->SetZ2( _sl_SliceImage->GetValue() );
382 _sl_SliceImage->Enable(!fixdin);
383 _colorLayerImageView->onThreshold();
384 _colorLayerImageView->Refresh();
385 }//_colorLayerImageView
388 //----------------------------------------------------------------------------
389 void ColorLayerImageViewPanel::onSliceImage(wxScrollEvent& event)
391 if (_colorLayerImageView!=NULL)
393 _colorLayerImageView->SetZ2( _sl_SliceImage->GetValue() );
394 _colorLayerImageView->onThreshold();
395 _colorLayerImageView->Refresh();
396 }//_colorLayerImageView
399 //----------------------------------------------------------------------------
400 void ColorLayerImageViewPanel::onChangeOpacity(wxScrollEvent& event)
402 if (_colorLayerImageView!=NULL)
404 int opacity = _opacity->GetValue();
405 _colorLayerImageView->onThresholdChangeOpacity(opacity);
406 _colorLayerImageView->Refresh();
407 }//_colorLayerImageView
411 //----------------------------------------------------------------------------
412 bool ColorLayerImageViewPanel::IsVisible()