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"
34 #include <wx/string.h>
36 //---------------------------------------------------------
37 //---------------------------------------------------------
38 //---------------------------------------------------------
40 wxDlgTransformByDimensionBySpacingByPixel::wxDlgTransformByDimensionBySpacingByPixel()
44 wxDlgTransformByDimensionBySpacingByPixel::~wxDlgTransformByDimensionBySpacingByPixel()
49 void wxDlgTransformByDimensionBySpacingByPixel::GetTransformType(
56 int &typeOfTransformation,
59 wxDialog* dial = new wxDialog (parent,-1,_T("Tools"),wxDefaultPosition, wxSize(500,550),wxRESIZE_BORDER);
60 wxSizer* buttonsSizer = dial->CreateSeparatedButtonSizer(wxOK|wxCANCEL);
61 wxBoxSizer *dialSizer = new wxBoxSizer(wxVERTICAL);
63 wxString lstOptOperation[3];
64 lstOptOperation[0]=_T("By Dimension");
65 lstOptOperation[1]=_T("By Spacing");
66 lstOptOperation[2]=_T("By Pixel");
67 wxRadioBox * radioOpts = new wxRadioBox(dial, -1, _T("Type of Transformation"), wxDefaultPosition, wxSize(250,90), 3 , lstOptOperation, 3, wxRA_SPECIFY_COLS);
70 wxString strBaseSpc(str);
75 strBaseSpc.Printf(wxT("Base spacing: %f %f %f"), baseSpc[0],baseSpc[1],baseSpc[2] );
76 strLayerSpc.Printf(wxT("Layer spacing: %f %f %f"), layerSpc[0],layerSpc[1],layerSpc[2] );
77 strBaseDim.Printf(wxT("Base dimension: %d %d %d"), baseDim[0],baseDim[1],baseDim[2] );
78 strLayerDim.Printf(wxT("Layer dimension: %d %d %d"), layerDim[0],layerDim[1],layerDim[2] );
80 dialSizer->Add( new wxStaticText(dial,-1,message ) , 0, wxGROW );
81 dialSizer->Add( new wxStaticText(dial,-1,_T(" ") ) , 0, wxGROW );
82 dialSizer->Add( new wxStaticText(dial,-1, strBaseSpc ) , 0, wxGROW );
83 dialSizer->Add( new wxStaticText(dial,-1, strLayerSpc ) , 0, wxGROW );
84 dialSizer->Add( new wxStaticText(dial,-1,_T(" ") ) , 0, wxGROW );
85 dialSizer->Add( new wxStaticText(dial,-1, strBaseDim ) , 0, wxGROW );
86 dialSizer->Add( new wxStaticText(dial,-1, strLayerDim ) , 0, wxGROW );
87 dialSizer->Add( new wxStaticText(dial,-1,_T(" ") ) , 0, wxGROW );
88 dialSizer->Add( new wxStaticText(dial,-1,message ) , 0, wxGROW );
89 dialSizer->Add( new wxStaticText(dial,-1,_T(" ") ) , 0, wxGROW );
90 dialSizer->Add(radioOpts,0,wxGROW);
91 dialSizer->Add( new wxStaticText(dial,-1,_T(" ") ) , 0, wxGROW );
92 dialSizer->Add(buttonsSizer,0,wxGROW);
93 dial->SetSizer(dialSizer, true);
97 typeOfTransformation = -1;
100 if (dial->GetReturnCode() == wxID_OK)
102 typeOfTransformation = radioOpts->GetSelection() + 1;
108 //---------------------------------------------------------
109 //---------------------------------------------------------
110 //---------------------------------------------------------
114 ** Begin of the threshold panel
116 ColorLayerImageViewPanel::ColorLayerImageViewPanel(wxWindow* parent, int min, int max, int type)
117 //: wxPanel(parent, -1, wxDefaultPosition, wxSize(600,100), wxBORDER_SUNKEN)
119 : wxPanel(parent, -1, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL)
124 _spcBase[0] = _spcBase[1] = _spcBase[2] = 0;
125 _dimBase[0] = _dimBase[1] = _dimBase[2] = 0;
128 _sl_SliceImageX = NULL;
129 _sl_SliceImageY = NULL;
130 _sl_SliceImageZ = NULL;
132 _histogramMinMaxLevel = NULL;
134 wxFlexGridSizer * sizer = NULL;
135 _colorLayerImageViewManager = new ColorLayerImageViewManager();
139 sizer = new wxFlexGridSizer(1);
140 _btn_ReadImage = new wxButton(this, wxID_ANY, _T("Read Image") );
142 _cb_ShowHide = new wxCheckBox(this, wxID_ANY, _T("Show/Hide Layer") );
143 _cb_ShowHide->SetValue(_thresholdGo);
144 _cb_SliceFixDinamic = new wxCheckBox(this, wxID_ANY, _T("Fixed/Dynamic Slice") );
145 _cb_SliceFixDinamic->SetValue(true);
146 _sl_SliceImageX = new wxSlider(this, wxID_ANY, 0, 1000, 1000,
147 wxDefaultPosition, wxDefaultSize, wxSL_HORIZONTAL|wxSL_LABELS, wxDefaultValidator);
148 _sl_SliceImageY = new wxSlider(this, wxID_ANY, 0, 1000, 1000,
149 wxDefaultPosition, wxDefaultSize, wxSL_HORIZONTAL|wxSL_LABELS, wxDefaultValidator);
150 _sl_SliceImageZ = new wxSlider(this, wxID_ANY, 0, 1000, 1000,
151 wxDefaultPosition, wxDefaultSize, wxSL_HORIZONTAL|wxSL_LABELS, wxDefaultValidator);
152 _sl_SliceImageX->Enable(false);
153 _sl_SliceImageY->Enable(false);
154 _sl_SliceImageZ->Enable(false);
155 _interpolationCheckBox = new wxCheckBox(this, -1, _T("Interpole") );
156 _interpolationCheckBox->SetValue(true);
157 _opacity = new wxSlider(this, wxID_ANY, 6, 1, 10, wxDefaultPosition, wxDefaultSize, wxSL_HORIZONTAL|wxSL_LABELS, wxDefaultValidator);
159 // _histogram = new Histogram( this , -1, wxPoint(0,0), wxSize(400,400), /*wxNO_BORDER*/ wxBORDER_DEFAULT );
160 // _histogramMinMaxLevel = new HistogramMinMaxLevel( (HistogramBase*)_histogram );
162 Connect( _btn_ReadImage->GetId(), wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &ColorLayerImageViewPanel::onReadImage );
163 Connect( _cb_ShowHide->GetId(), wxEVT_COMMAND_CHECKBOX_CLICKED , (wxObjectEventFunction) &ColorLayerImageViewPanel::onThresholdShow );
164 Connect( _interpolationCheckBox->GetId(), wxEVT_COMMAND_CHECKBOX_CLICKED, (wxObjectEventFunction) &ColorLayerImageViewPanel::onThresholdInterpolation );
165 Connect( _opacity->GetId(), wxEVT_SCROLL_THUMBTRACK, (wxObjectEventFunction) &ColorLayerImageViewPanel::onChangeOpacity );
166 Connect( _cb_SliceFixDinamic->GetId(), wxEVT_COMMAND_CHECKBOX_CLICKED, (wxObjectEventFunction) &ColorLayerImageViewPanel::onSliceFixDinamic );
168 Connect( _sl_SliceImageX->GetId(), wxEVT_SCROLL_THUMBTRACK , (wxObjectEventFunction) &ColorLayerImageViewPanel::onSliceImage );
169 Connect( _sl_SliceImageX->GetId(), wxEVT_SCROLL_LINEUP , (wxObjectEventFunction) &ColorLayerImageViewPanel::onSliceImage );
170 Connect( _sl_SliceImageX->GetId(), wxEVT_SCROLL_LINEDOWN , (wxObjectEventFunction) &ColorLayerImageViewPanel::onSliceImage );
171 Connect( _sl_SliceImageX->GetId(), wxEVT_SCROLL_PAGEUP , (wxObjectEventFunction) &ColorLayerImageViewPanel::onSliceImage );
172 Connect( _sl_SliceImageX->GetId(), wxEVT_SCROLL_PAGEDOWN , (wxObjectEventFunction) &ColorLayerImageViewPanel::onSliceImage );
174 Connect( _sl_SliceImageY->GetId(), wxEVT_SCROLL_THUMBTRACK , (wxObjectEventFunction) &ColorLayerImageViewPanel::onSliceImage );
175 Connect( _sl_SliceImageY->GetId(), wxEVT_SCROLL_LINEUP , (wxObjectEventFunction) &ColorLayerImageViewPanel::onSliceImage );
176 Connect( _sl_SliceImageY->GetId(), wxEVT_SCROLL_LINEDOWN , (wxObjectEventFunction) &ColorLayerImageViewPanel::onSliceImage );
177 Connect( _sl_SliceImageY->GetId(), wxEVT_SCROLL_PAGEUP , (wxObjectEventFunction) &ColorLayerImageViewPanel::onSliceImage );
178 Connect( _sl_SliceImageY->GetId(), wxEVT_SCROLL_PAGEDOWN , (wxObjectEventFunction) &ColorLayerImageViewPanel::onSliceImage );
180 Connect( _sl_SliceImageZ->GetId(), wxEVT_SCROLL_THUMBTRACK , (wxObjectEventFunction) &ColorLayerImageViewPanel::onSliceImage );
181 Connect( _sl_SliceImageZ->GetId(), wxEVT_SCROLL_LINEUP , (wxObjectEventFunction) &ColorLayerImageViewPanel::onSliceImage );
182 Connect( _sl_SliceImageZ->GetId(), wxEVT_SCROLL_LINEDOWN , (wxObjectEventFunction) &ColorLayerImageViewPanel::onSliceImage );
183 Connect( _sl_SliceImageZ->GetId(), wxEVT_SCROLL_PAGEUP , (wxObjectEventFunction) &ColorLayerImageViewPanel::onSliceImage );
184 Connect( _sl_SliceImageZ->GetId(), wxEVT_SCROLL_PAGEDOWN , (wxObjectEventFunction) &ColorLayerImageViewPanel::onSliceImage );
186 sizer -> Add( new wxStaticText(this,-1,_T("Color Image Layer")) , 1, wxGROW );
187 sizer -> Add( _btn_ReadImage , 1, wxGROW );
188 sizer -> Add( new wxStaticText(this,-1,_T(" ")) , 1, wxGROW );
189 sizer -> Add( new wxStaticText(this,-1,_T("Opacity Level")) , 1, wxGROW );
190 sizer -> Add( _opacity , 1, wxGROW );
191 sizer -> Add( new wxStaticText(this,-1,_T(" ")) , 1, wxGROW );
192 sizer -> Add( _cb_ShowHide , 1, wxGROW );
193 sizer -> Add( new wxStaticText(this,-1,_T(" ")) , 1, wxGROW );
194 sizer -> Add( _interpolationCheckBox , 1, wxGROW );
196 sizer -> Add( new wxStaticText(this,-1,_T(" ")) , 1, wxGROW );
197 sizer -> Add( new wxStaticText(this,-1,_T("Slice ")) , 1, wxGROW );
198 sizer -> Add( _sl_SliceImageX , 1, wxGROW );
199 sizer -> Add( _sl_SliceImageY , 1, wxGROW );
200 sizer -> Add( _sl_SliceImageZ , 1, wxGROW );
201 sizer -> Add( _cb_SliceFixDinamic , 1, wxGROW );
202 // sizer -> Add( _histogramMinMaxLevel->GetWindow() , 1, wxGROW );
209 sizer = new wxFlexGridSizer(2);
210 _interpolationCheckBox = new wxCheckBox(this, -1, _T("Interpolate") );
211 _interpolationCheckBox->SetValue(true);
212 _opacity = new wxSlider(this, wxID_ANY, 6, 0, 10, wxDefaultPosition, wxSize(2,40), wxSL_HORIZONTAL|wxSL_LABELS, wxDefaultValidator);
214 Connect( _interpolationCheckBox->GetId(), wxEVT_COMMAND_CHECKBOX_CLICKED, (wxObjectEventFunction) &ColorLayerImageViewPanel::onThresholdInterpolation );
215 Connect( _opacity->GetId(), wxEVT_SCROLL_THUMBTRACK, (wxObjectEventFunction) &ColorLayerImageViewPanel::onChangeOpacity );
216 // sizer -> Add( new wxStaticText(this,-1,_T("Opacity Level")) , 1, wxEXPAND );
217 sizer -> Add( _opacity , 1, wxGROW );
218 sizer -> Add( _interpolationCheckBox , 1, wxGROW );
219 sizer->AddGrowableCol(0);
224 this->SetSizer( sizer );
225 // this->SetAutoLayout( true );
228 //CM Sets the default fitting mode to Pixel mode.
233 //----------------------------------------------------------------------------
234 ColorLayerImageViewPanel::~ColorLayerImageViewPanel()
239 //----------------------------------------------------------------------------
240 ColorLayerImageViewManager* ColorLayerImageViewPanel::GetColorLayerImageViewManager()
242 return _colorLayerImageViewManager;
246 //----------------------------------------------------------------------------
247 // This is the new spacing of the background image (1,1,1)
248 void ColorLayerImageViewPanel::SetBaseSpacing(double spc[3])
250 _spcBase[0] = spc[0];
251 _spcBase[1] = spc[1];
252 _spcBase[2] = spc[2];
259 //----------------------------------------------------------------------------
260 // This is the Original spacing of the background image
261 void ColorLayerImageViewPanel::SetOriginalSpacing(double spc[3])
268 //----------------------------------------------------------------------------
269 // This is the size in pixels of the background image
270 void ColorLayerImageViewPanel::SetBaseDimension(int dim[3])
272 _dimBase[0] = dim[0];
273 _dimBase[1] = dim[1];
274 _dimBase[2] = dim[2];
277 //----------------------------------------------------------------------------
278 void ColorLayerImageViewPanel::SetImage(vtkImageData *img)
282 if (_histogramMinMaxLevel!=NULL)
284 _histogramMinMaxLevel->Configure( img );
286 _colorLayerImageViewManager->SetImage( img );
289 img->GetSpacing(spc);
293 img->GetWholeExtent(ext);
294 dim[0] = ext[1]-ext[0];
295 dim[1] = ext[3]-ext[2];
296 dim[2] = ext[5]-ext[4];
299 if (_sl_SliceImageX!=NULL)
301 _sl_SliceImageX->SetRange( 0 , dim[0] );
302 _sl_SliceImageY->SetRange( 0 , dim[1] );
303 _sl_SliceImageZ->SetRange( 0 , dim[2] );
306 //printf("EED ColorLayerImageViewPanel::SetImage UUPPSS----------------------\n" );
307 //printf("EED ColorLayerImageViewPanel::SetImage UUPPSS----------------------\n" );
308 //printf("EED ColorLayerImageViewPanel::SetImage UUPPSS----------------------\n" );
309 //printf("EED ColorLayerImageViewPanel::SetImage UUPPSS----------------------\n" );
310 //printf(" Here I have to analyse the spacing and size image to calculate new spacingvv\n" );
311 //printf(" I need the caracteristics of the base image\n" );
312 // GetColorLayerImageViewManager()->GetwxVtkBaseView(0);
315 if ( (spc[0]!=_spcBase[0]) || (spc[1]!=_spcBase[1]) || (spc[2]!=_spcBase[2]) ||
316 (dim[0]!=_dimBase[0]) || (spc[1]!=_spcBase[1]) || (spc[2]!=_spcBase[2])
320 int typeOfTransformation;
321 // In case of the option is set to create a dialog box.
322 if (_fitting_mode == -1)
325 wxString msg = _T("The image resolution of both images are not compatible. Do you want to tranform it? ");
326 wxDlgTransformByDimensionBySpacingByPixel dlg;
327 dlg.GetTransformType(this,_spcBase,spc,_dimBase,dim,msg,typeOfTransformation,transformOkDlg);
328 // CM Reset the default value (Pixel i.e. 3) if the dialog box returned an inappropriate value.
329 if (transformOkDlg == false)
331 typeOfTransformation = 3;
334 typeOfTransformation = _fitting_mode;
335 } // _fitting_mode -1
338 if (typeOfTransformation==1) // make dimensions equals
340 printf("EED ColorLayerImageViewPanel::onReadImage ...WARNNING.... dif size image spc*dim ofnew image ...???\n");
341 spc[0]=_spcBase[0]*_dimBase[0]/dim[0];
342 spc[1]=_spcBase[1]*_dimBase[1]/dim[1];
346 if (typeOfTransformation==2) // make spacing equals
348 spc[0] = ( _spcBase[0]/spc[0] ) * _spcOrg[0];
349 spc[1] = ( _spcBase[1]/spc[1] ) * _spcOrg[1];
350 spc[2] = ( _spcBase[2]/spc[2] ) * _spcOrg[2];
353 if (typeOfTransformation==3) // make spacing = 1
360 img->SetSpacing(spc);
361 } // spc !_spcBase dim!__dimBase
366 _colorLayerImageViewManager->onThreshold();
373 void ColorLayerImageViewPanel::RefreshView()
375 //EED01 _colorLayerImageView->Refresh();
376 _colorLayerImageViewManager->Refresh();
379 //----------------------------------------------------------------------------
380 void ColorLayerImageViewPanel::SetFittingMode(int fitting_mode)
382 // CM Sets the fitting mode if an appropriate value is provided.
383 if (fitting_mode == -1 || fitting_mode == 1 || fitting_mode == 2 || fitting_mode == 3)
385 _fitting_mode = fitting_mode;
387 //Otherwise, an exception should be thrown (value 0 is fine, it corresponds to an empty field i.e. the default value is kept).
388 else if (fitting_mode != 0)
389 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;
393 //----------------------------------------------------------------------------
394 int ColorLayerImageViewPanel::GetFittingMode()
396 return _fitting_mode;
399 //----------------------------------------------------------------------------
400 void ColorLayerImageViewPanel::onReadImage(wxCommandEvent& event)
403 // creaImageIO::WxSimpleDlg w(0,_T("Select your image"),"creaContours_Descriptor.dscp","creatisContours DB");
405 printf("EED ColorLayerImageViewPanel::onReadImage ....WARNING... Read dlg. all images creaImageIO ... ???\n");
407 creaMaracasVisuKernel::OpenImageDialog diag = creaMaracasVisuKernel::OpenImageDialog();
408 SetImage( diag.getImageData() );
411 //----------------------------------------------------------------------------
412 void ColorLayerImageViewPanel::onThresholdChange(wxCommandEvent& event)
416 _colorLayerImageViewManager->onThresholdChange();
418 //std::cout<< "Valor Min: " << minVal << " & Valor Max: " << maxVal << std::endl;
422 //----------------------------------------------------------------------------
423 void ColorLayerImageViewPanel::onThresholdShow(wxCommandEvent& event)
425 _thresholdGo = _cb_ShowHide->GetValue();
426 _active = _thresholdGo;
429 _colorLayerImageViewManager->onThreshold();
431 _colorLayerImageViewManager->onThresholdRemove( );
436 //----------------------------------------------------------------------------
437 void ColorLayerImageViewPanel::onThresholdStop()
441 _colorLayerImageViewManager->onThresholdRemove( );
446 //----------------------------------------------------------------------------
447 void ColorLayerImageViewPanel::onThresholdInterpolation(wxCommandEvent& event)
449 _colorLayerImageViewManager->onThresholdInterpolation(_interpolationCheckBox->GetValue());
453 //----------------------------------------------------------------------------
454 void ColorLayerImageViewPanel::onSliceFixDinamic(wxCommandEvent& event)
456 bool fixdin = _cb_SliceFixDinamic->GetValue();
457 _colorLayerImageViewManager->SetSliceFixDynamic( fixdin );
460 _colorLayerImageViewManager->SetX2( _sl_SliceImageX->GetValue() );
461 _colorLayerImageViewManager->SetY2( _sl_SliceImageY->GetValue() );
462 _colorLayerImageViewManager->SetZ2( _sl_SliceImageZ->GetValue() );
464 _sl_SliceImageX->Enable(!fixdin);
465 _sl_SliceImageY->Enable(!fixdin);
466 _sl_SliceImageZ->Enable(!fixdin);
467 _colorLayerImageViewManager->onThreshold();
471 //----------------------------------------------------------------------------
472 void ColorLayerImageViewPanel::onSliceImage(wxScrollEvent& event)
474 _colorLayerImageViewManager->SetX2( _sl_SliceImageX->GetValue() );
475 _colorLayerImageViewManager->SetY2( _sl_SliceImageY->GetValue() );
476 _colorLayerImageViewManager->SetZ2( _sl_SliceImageZ->GetValue() );
477 _colorLayerImageViewManager->onThreshold();
481 //----------------------------------------------------------------------------
482 void ColorLayerImageViewPanel::onChangeOpacity(wxScrollEvent& event)
484 int opacity = _opacity->GetValue();
485 _colorLayerImageViewManager->onThresholdChangeOpacity(opacity);
490 //----------------------------------------------------------------------------
491 bool ColorLayerImageViewPanel::IsVisible()
496 //----------------------------------------------------------------------------
497 void ColorLayerImageViewPanel::SetActive(bool active)
500 if (_cb_ShowHide!=NULL)
502 _cb_ShowHide->SetValue( _active );