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(" ")) , 0, wxGROW );
63 dialSizer->Add(radioOpts,0,wxGROW);
64 dialSizer->Add( new wxStaticText(dial,-1,_T(" ")) , 0, wxGROW );
65 dialSizer->Add(buttonsSizer,0,wxGROW);
66 dial->SetSizer(dialSizer, true);
70 typeOfTransformation = -1;
73 if (dial->GetReturnCode() == wxID_OK)
75 typeOfTransformation = radioOpts->GetSelection() + 1;
81 //---------------------------------------------------------
82 //---------------------------------------------------------
83 //---------------------------------------------------------
87 ** Begin of the threshold panel
89 ColorLayerImageViewPanel::ColorLayerImageViewPanel(wxWindow* parent, int min, int max, int type)
90 //: wxPanel(parent, -1, wxDefaultPosition, wxSize(600,100), wxBORDER_SUNKEN)
92 : wxPanel(parent, -1, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL)
96 printf("EED ColorLayerImageViewPanel::ColorLayerImageViewPanel Start\n");
98 _spcBase[0] = _spcBase[1] = _spcBase[2] = 0;
99 _dimBase[0] = _dimBase[1] = _dimBase[2] = 0;
102 _sl_SliceImageX = NULL;
103 _sl_SliceImageY = NULL;
104 _sl_SliceImageZ = NULL;
106 _histogramMinMaxLevel = NULL;
108 wxFlexGridSizer * sizer = NULL;
109 _colorLayerImageViewManager = new ColorLayerImageViewManager();
113 sizer = new wxFlexGridSizer(1);
114 _btn_ReadImage = new wxButton(this, wxID_ANY, _T("Read Image") );
116 _cb_ShowHide = new wxCheckBox(this, wxID_ANY, _T("Show/Hide Layer") );
117 _cb_ShowHide->SetValue(_thresholdGo);
118 _cb_SliceFixDinamic = new wxCheckBox(this, wxID_ANY, _T("Fixed/Dynamic Slice") );
119 _cb_SliceFixDinamic->SetValue(true);
120 _sl_SliceImageX = new wxSlider(this, wxID_ANY, 0, 1000, 1000,
121 wxDefaultPosition, wxDefaultSize, wxSL_HORIZONTAL|wxSL_LABELS, wxDefaultValidator);
122 _sl_SliceImageY = new wxSlider(this, wxID_ANY, 0, 1000, 1000,
123 wxDefaultPosition, wxDefaultSize, wxSL_HORIZONTAL|wxSL_LABELS, wxDefaultValidator);
124 _sl_SliceImageZ = new wxSlider(this, wxID_ANY, 0, 1000, 1000,
125 wxDefaultPosition, wxDefaultSize, wxSL_HORIZONTAL|wxSL_LABELS, wxDefaultValidator);
126 _sl_SliceImageX->Enable(false);
127 _sl_SliceImageY->Enable(false);
128 _sl_SliceImageZ->Enable(false);
129 _interpolationCheckBox = new wxCheckBox(this, -1, _T("Interpole") );
130 _interpolationCheckBox->SetValue(true);
131 _opacity = new wxSlider(this, wxID_ANY, 6, 1, 10, wxDefaultPosition, wxDefaultSize, wxSL_HORIZONTAL|wxSL_LABELS, wxDefaultValidator);
133 // _histogram = new Histogram( this , -1, wxPoint(0,0), wxSize(400,400), /*wxNO_BORDER*/ wxBORDER_DEFAULT );
134 // _histogramMinMaxLevel = new HistogramMinMaxLevel( (HistogramBase*)_histogram );
136 Connect( _btn_ReadImage->GetId(), wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &ColorLayerImageViewPanel::onReadImage );
137 Connect( _cb_ShowHide->GetId(), wxEVT_COMMAND_CHECKBOX_CLICKED , (wxObjectEventFunction) &ColorLayerImageViewPanel::onThresholdShow );
138 Connect( _interpolationCheckBox->GetId(), wxEVT_COMMAND_CHECKBOX_CLICKED, (wxObjectEventFunction) &ColorLayerImageViewPanel::onThresholdInterpolation );
139 Connect( _opacity->GetId(), wxEVT_SCROLL_THUMBTRACK, (wxObjectEventFunction) &ColorLayerImageViewPanel::onChangeOpacity );
140 Connect( _cb_SliceFixDinamic->GetId(), wxEVT_COMMAND_CHECKBOX_CLICKED, (wxObjectEventFunction) &ColorLayerImageViewPanel::onSliceFixDinamic );
142 Connect( _sl_SliceImageX->GetId(), wxEVT_SCROLL_THUMBTRACK , (wxObjectEventFunction) &ColorLayerImageViewPanel::onSliceImage );
143 Connect( _sl_SliceImageX->GetId(), wxEVT_SCROLL_LINEUP , (wxObjectEventFunction) &ColorLayerImageViewPanel::onSliceImage );
144 Connect( _sl_SliceImageX->GetId(), wxEVT_SCROLL_LINEDOWN , (wxObjectEventFunction) &ColorLayerImageViewPanel::onSliceImage );
145 Connect( _sl_SliceImageX->GetId(), wxEVT_SCROLL_PAGEUP , (wxObjectEventFunction) &ColorLayerImageViewPanel::onSliceImage );
146 Connect( _sl_SliceImageX->GetId(), wxEVT_SCROLL_PAGEDOWN , (wxObjectEventFunction) &ColorLayerImageViewPanel::onSliceImage );
148 Connect( _sl_SliceImageY->GetId(), wxEVT_SCROLL_THUMBTRACK , (wxObjectEventFunction) &ColorLayerImageViewPanel::onSliceImage );
149 Connect( _sl_SliceImageY->GetId(), wxEVT_SCROLL_LINEUP , (wxObjectEventFunction) &ColorLayerImageViewPanel::onSliceImage );
150 Connect( _sl_SliceImageY->GetId(), wxEVT_SCROLL_LINEDOWN , (wxObjectEventFunction) &ColorLayerImageViewPanel::onSliceImage );
151 Connect( _sl_SliceImageY->GetId(), wxEVT_SCROLL_PAGEUP , (wxObjectEventFunction) &ColorLayerImageViewPanel::onSliceImage );
152 Connect( _sl_SliceImageY->GetId(), wxEVT_SCROLL_PAGEDOWN , (wxObjectEventFunction) &ColorLayerImageViewPanel::onSliceImage );
154 Connect( _sl_SliceImageZ->GetId(), wxEVT_SCROLL_THUMBTRACK , (wxObjectEventFunction) &ColorLayerImageViewPanel::onSliceImage );
155 Connect( _sl_SliceImageZ->GetId(), wxEVT_SCROLL_LINEUP , (wxObjectEventFunction) &ColorLayerImageViewPanel::onSliceImage );
156 Connect( _sl_SliceImageZ->GetId(), wxEVT_SCROLL_LINEDOWN , (wxObjectEventFunction) &ColorLayerImageViewPanel::onSliceImage );
157 Connect( _sl_SliceImageZ->GetId(), wxEVT_SCROLL_PAGEUP , (wxObjectEventFunction) &ColorLayerImageViewPanel::onSliceImage );
158 Connect( _sl_SliceImageZ->GetId(), wxEVT_SCROLL_PAGEDOWN , (wxObjectEventFunction) &ColorLayerImageViewPanel::onSliceImage );
160 sizer -> Add( new wxStaticText(this,-1,_T("Color Image Layer")) , 1, wxGROW );
161 sizer -> Add( _btn_ReadImage , 1, wxGROW );
162 sizer -> Add( new wxStaticText(this,-1,_T(" ")) , 1, wxGROW );
163 sizer -> Add( new wxStaticText(this,-1,_T("Opacity Level")) , 1, wxGROW );
164 sizer -> Add( _opacity , 1, wxGROW );
165 sizer -> Add( new wxStaticText(this,-1,_T(" ")) , 1, wxGROW );
166 sizer -> Add( _cb_ShowHide , 1, wxGROW );
167 sizer -> Add( new wxStaticText(this,-1,_T(" ")) , 1, wxGROW );
168 sizer -> Add( _interpolationCheckBox , 1, wxGROW );
170 sizer -> Add( new wxStaticText(this,-1,_T(" ")) , 1, wxGROW );
171 sizer -> Add( new wxStaticText(this,-1,_T("Slice ")) , 1, wxGROW );
172 sizer -> Add( _sl_SliceImageX , 1, wxGROW );
173 sizer -> Add( _sl_SliceImageY , 1, wxGROW );
174 sizer -> Add( _sl_SliceImageZ , 1, wxGROW );
175 sizer -> Add( _cb_SliceFixDinamic , 1, wxGROW );
176 // sizer -> Add( _histogramMinMaxLevel->GetWindow() , 1, wxGROW );
183 sizer = new wxFlexGridSizer(2);
184 _interpolationCheckBox = new wxCheckBox(this, -1, _T("Interpolate") );
185 _interpolationCheckBox->SetValue(true);
186 _opacity = new wxSlider(this, wxID_ANY, 6, 0, 10, wxDefaultPosition, wxSize(2,40), wxSL_HORIZONTAL|wxSL_LABELS, wxDefaultValidator);
188 Connect( _interpolationCheckBox->GetId(), wxEVT_COMMAND_CHECKBOX_CLICKED, (wxObjectEventFunction) &ColorLayerImageViewPanel::onThresholdInterpolation );
189 Connect( _opacity->GetId(), wxEVT_SCROLL_THUMBTRACK, (wxObjectEventFunction) &ColorLayerImageViewPanel::onChangeOpacity );
190 // sizer -> Add( new wxStaticText(this,-1,_T("Opacity Level")) , 1, wxEXPAND );
191 sizer -> Add( _opacity , 1, wxGROW );
192 sizer -> Add( _interpolationCheckBox , 1, wxGROW );
193 sizer->AddGrowableCol(0);
198 this->SetSizer( sizer );
199 // this->SetAutoLayout( true );
202 //CM Sets the default fitting mode to Pixel mode.
207 //----------------------------------------------------------------------------
208 ColorLayerImageViewPanel::~ColorLayerImageViewPanel()
213 //----------------------------------------------------------------------------
214 ColorLayerImageViewManager* ColorLayerImageViewPanel::GetColorLayerImageViewManager()
216 return _colorLayerImageViewManager;
220 //----------------------------------------------------------------------------
221 // This is the new spacing of the background image (1,1,1)
222 void ColorLayerImageViewPanel::SetBaseSpacing(double spc[3])
224 _spcBase[0] = spc[0];
225 _spcBase[1] = spc[1];
226 _spcBase[2] = spc[2];
233 //----------------------------------------------------------------------------
234 // This is the Original spacing of the background image
235 void ColorLayerImageViewPanel::SetOriginalSpacing(double spc[3])
242 //----------------------------------------------------------------------------
243 // This is the size in pixels of the background image
244 void ColorLayerImageViewPanel::SetBaseDimension(int dim[3])
246 _dimBase[0] = dim[0];
247 _dimBase[1] = dim[1];
248 _dimBase[2] = dim[2];
251 //----------------------------------------------------------------------------
252 void ColorLayerImageViewPanel::SetImage(vtkImageData *img)
256 if (_histogramMinMaxLevel!=NULL)
258 _histogramMinMaxLevel->Configure( img );
260 _colorLayerImageViewManager->SetImage( img );
263 img->GetSpacing(spc);
267 img->GetWholeExtent(ext);
268 dim[0] = ext[1]-ext[0];
269 dim[1] = ext[3]-ext[2];
270 dim[2] = ext[5]-ext[4];
273 if (_sl_SliceImageX!=NULL)
275 _sl_SliceImageX->SetRange( 0 , dim[0] );
276 _sl_SliceImageY->SetRange( 0 , dim[1] );
277 _sl_SliceImageZ->SetRange( 0 , dim[2] );
280 if ( (spc[0]!=_spcBase[0]) || (spc[1]!=_spcBase[1]) || (spc[2]!=_spcBase[2]) ||
281 (dim[0]!=_dimBase[0]) || (spc[1]!=_spcBase[1]) || (spc[2]!=_spcBase[2])
285 int typeOfTransformation;
286 // In case of the option is set to create a dialog box.
287 if (_fitting_mode == -1)
290 wxString msg = _T("The image resolution of both images are not compatible. Do you want to tranform it? ");
291 wxDlgTransformByDimensionBySpacingByPixel dlg;
292 dlg.GetTransformType(this,msg,typeOfTransformation,transformOkDlg);
293 // CM Reset the default value (Pixel i.e. 3) if the dialog box returned an inappropriate value.
294 if (transformOkDlg == false)
295 typeOfTransformation = 3;
298 typeOfTransformation = _fitting_mode;
300 if (typeOfTransformation==1) // make dimensions equals
302 printf("EED ColorLayerImageViewPanel::onReadImage ...WARNNING.... dif size image spc*dim ofnew image ...???\n");
303 spc[0]=_spcBase[0]*_dimBase[0]/dim[0];
304 spc[1]=_spcBase[1]*_dimBase[1]/dim[1];
308 if (typeOfTransformation==2) // make spacing equals
310 spc[0] = ( _spcBase[0]/spc[0] ) * _spcOrg[0];
311 spc[1] = ( _spcBase[1]/spc[1] ) * _spcOrg[1];
312 spc[2] = ( _spcBase[2]/spc[2] ) * _spcOrg[2];
315 if (typeOfTransformation==3) // make spacing = 1
322 img->SetSpacing(spc);
323 } // spc !_spcBase dim!__dimBase
328 _colorLayerImageViewManager->onThreshold();
335 void ColorLayerImageViewPanel::RefreshView()
337 //EED01 _colorLayerImageView->Refresh();
338 _colorLayerImageViewManager->Refresh();
341 //----------------------------------------------------------------------------
342 void ColorLayerImageViewPanel::SetFittingMode(int fitting_mode)
344 // CM Sets the fitting mode if an appropriate value is provided.
345 if (fitting_mode == -1 || fitting_mode == 1 || fitting_mode == 2 || fitting_mode == 3)
347 _fitting_mode = fitting_mode;
349 //Otherwise, an exception should be thrown (value 0 is fine, it corresponds to an empty field i.e. the default value is kept).
350 else if (fitting_mode != 0)
351 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;
355 //----------------------------------------------------------------------------
356 int ColorLayerImageViewPanel::GetFittingMode()
358 return _fitting_mode;
361 //----------------------------------------------------------------------------
362 void ColorLayerImageViewPanel::onReadImage(wxCommandEvent& event)
365 // creaImageIO::WxSimpleDlg w(0,_T("Select your image"),"creaContours_Descriptor.dscp","creatisContours DB");
367 printf("EED ColorLayerImageViewPanel::onReadImage ....WARNING... Read dlg. all images creaImageIO ... ???\n");
369 creaMaracasVisuKernel::OpenImageDialog diag = creaMaracasVisuKernel::OpenImageDialog();
370 SetImage( diag.getImageData() );
373 //----------------------------------------------------------------------------
374 void ColorLayerImageViewPanel::onThresholdChange(wxCommandEvent& event)
378 _colorLayerImageViewManager->onThresholdChange();
380 //std::cout<< "Valor Min: " << minVal << " & Valor Max: " << maxVal << std::endl;
384 //----------------------------------------------------------------------------
385 void ColorLayerImageViewPanel::onThresholdShow(wxCommandEvent& event)
387 _thresholdGo = _cb_ShowHide->GetValue();
388 _active = _thresholdGo;
391 _colorLayerImageViewManager->onThreshold();
393 _colorLayerImageViewManager->onThresholdRemove( );
398 //----------------------------------------------------------------------------
399 void ColorLayerImageViewPanel::onThresholdStop()
403 _colorLayerImageViewManager->onThresholdRemove( );
408 //----------------------------------------------------------------------------
409 void ColorLayerImageViewPanel::onThresholdInterpolation(wxCommandEvent& event)
411 _colorLayerImageViewManager->onThresholdInterpolation(_interpolationCheckBox->GetValue());
415 //----------------------------------------------------------------------------
416 void ColorLayerImageViewPanel::onSliceFixDinamic(wxCommandEvent& event)
418 bool fixdin = _cb_SliceFixDinamic->GetValue();
419 _colorLayerImageViewManager->SetSliceFixDynamic( fixdin );
422 _colorLayerImageViewManager->SetX2( _sl_SliceImageX->GetValue() );
423 _colorLayerImageViewManager->SetY2( _sl_SliceImageY->GetValue() );
424 _colorLayerImageViewManager->SetZ2( _sl_SliceImageZ->GetValue() );
426 _sl_SliceImageX->Enable(!fixdin);
427 _sl_SliceImageY->Enable(!fixdin);
428 _sl_SliceImageZ->Enable(!fixdin);
429 _colorLayerImageViewManager->onThreshold();
433 //----------------------------------------------------------------------------
434 void ColorLayerImageViewPanel::onSliceImage(wxScrollEvent& event)
436 _colorLayerImageViewManager->SetX2( _sl_SliceImageX->GetValue() );
437 _colorLayerImageViewManager->SetY2( _sl_SliceImageY->GetValue() );
438 _colorLayerImageViewManager->SetZ2( _sl_SliceImageZ->GetValue() );
439 _colorLayerImageViewManager->onThreshold();
443 //----------------------------------------------------------------------------
444 void ColorLayerImageViewPanel::onChangeOpacity(wxScrollEvent& event)
446 int opacity = _opacity->GetValue();
447 _colorLayerImageViewManager->onThresholdChangeOpacity(opacity);
452 //----------------------------------------------------------------------------
453 bool ColorLayerImageViewPanel::IsVisible()
458 //----------------------------------------------------------------------------
459 void ColorLayerImageViewPanel::SetActive(bool active)
462 if (_cb_ShowHide!=NULL)
464 _cb_ShowHide->SetValue( _active );