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)
123 printf("EED ColorLayerImageViewPanel::ColorLayerImageViewPanel Start\n");
125 _spcBase[0] = _spcBase[1] = _spcBase[2] = 0;
126 _dimBase[0] = _dimBase[1] = _dimBase[2] = 0;
129 _sl_SliceImageX = NULL;
130 _sl_SliceImageY = NULL;
131 _sl_SliceImageZ = NULL;
133 _histogramMinMaxLevel = NULL;
135 wxFlexGridSizer * sizer = NULL;
136 _colorLayerImageViewManager = new ColorLayerImageViewManager();
140 sizer = new wxFlexGridSizer(1);
141 _btn_ReadImage = new wxButton(this, wxID_ANY, _T("Read Image") );
143 _cb_ShowHide = new wxCheckBox(this, wxID_ANY, _T("Show/Hide Layer") );
144 _cb_ShowHide->SetValue(_thresholdGo);
145 _cb_SliceFixDinamic = new wxCheckBox(this, wxID_ANY, _T("Fixed/Dynamic Slice") );
146 _cb_SliceFixDinamic->SetValue(true);
147 _sl_SliceImageX = new wxSlider(this, wxID_ANY, 0, 1000, 1000,
148 wxDefaultPosition, wxDefaultSize, wxSL_HORIZONTAL|wxSL_LABELS, wxDefaultValidator);
149 _sl_SliceImageY = new wxSlider(this, wxID_ANY, 0, 1000, 1000,
150 wxDefaultPosition, wxDefaultSize, wxSL_HORIZONTAL|wxSL_LABELS, wxDefaultValidator);
151 _sl_SliceImageZ = new wxSlider(this, wxID_ANY, 0, 1000, 1000,
152 wxDefaultPosition, wxDefaultSize, wxSL_HORIZONTAL|wxSL_LABELS, wxDefaultValidator);
153 _sl_SliceImageX->Enable(false);
154 _sl_SliceImageY->Enable(false);
155 _sl_SliceImageZ->Enable(false);
156 _interpolationCheckBox = new wxCheckBox(this, -1, _T("Interpole") );
157 _interpolationCheckBox->SetValue(true);
158 _opacity = new wxSlider(this, wxID_ANY, 6, 1, 10, wxDefaultPosition, wxDefaultSize, wxSL_HORIZONTAL|wxSL_LABELS, wxDefaultValidator);
160 // _histogram = new Histogram( this , -1, wxPoint(0,0), wxSize(400,400), /*wxNO_BORDER*/ wxBORDER_DEFAULT );
161 // _histogramMinMaxLevel = new HistogramMinMaxLevel( (HistogramBase*)_histogram );
163 Connect( _btn_ReadImage->GetId(), wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &ColorLayerImageViewPanel::onReadImage );
164 Connect( _cb_ShowHide->GetId(), wxEVT_COMMAND_CHECKBOX_CLICKED , (wxObjectEventFunction) &ColorLayerImageViewPanel::onThresholdShow );
165 Connect( _interpolationCheckBox->GetId(), wxEVT_COMMAND_CHECKBOX_CLICKED, (wxObjectEventFunction) &ColorLayerImageViewPanel::onThresholdInterpolation );
166 Connect( _opacity->GetId(), wxEVT_SCROLL_THUMBTRACK, (wxObjectEventFunction) &ColorLayerImageViewPanel::onChangeOpacity );
167 Connect( _cb_SliceFixDinamic->GetId(), wxEVT_COMMAND_CHECKBOX_CLICKED, (wxObjectEventFunction) &ColorLayerImageViewPanel::onSliceFixDinamic );
169 Connect( _sl_SliceImageX->GetId(), wxEVT_SCROLL_THUMBTRACK , (wxObjectEventFunction) &ColorLayerImageViewPanel::onSliceImage );
170 Connect( _sl_SliceImageX->GetId(), wxEVT_SCROLL_LINEUP , (wxObjectEventFunction) &ColorLayerImageViewPanel::onSliceImage );
171 Connect( _sl_SliceImageX->GetId(), wxEVT_SCROLL_LINEDOWN , (wxObjectEventFunction) &ColorLayerImageViewPanel::onSliceImage );
172 Connect( _sl_SliceImageX->GetId(), wxEVT_SCROLL_PAGEUP , (wxObjectEventFunction) &ColorLayerImageViewPanel::onSliceImage );
173 Connect( _sl_SliceImageX->GetId(), wxEVT_SCROLL_PAGEDOWN , (wxObjectEventFunction) &ColorLayerImageViewPanel::onSliceImage );
175 Connect( _sl_SliceImageY->GetId(), wxEVT_SCROLL_THUMBTRACK , (wxObjectEventFunction) &ColorLayerImageViewPanel::onSliceImage );
176 Connect( _sl_SliceImageY->GetId(), wxEVT_SCROLL_LINEUP , (wxObjectEventFunction) &ColorLayerImageViewPanel::onSliceImage );
177 Connect( _sl_SliceImageY->GetId(), wxEVT_SCROLL_LINEDOWN , (wxObjectEventFunction) &ColorLayerImageViewPanel::onSliceImage );
178 Connect( _sl_SliceImageY->GetId(), wxEVT_SCROLL_PAGEUP , (wxObjectEventFunction) &ColorLayerImageViewPanel::onSliceImage );
179 Connect( _sl_SliceImageY->GetId(), wxEVT_SCROLL_PAGEDOWN , (wxObjectEventFunction) &ColorLayerImageViewPanel::onSliceImage );
181 Connect( _sl_SliceImageZ->GetId(), wxEVT_SCROLL_THUMBTRACK , (wxObjectEventFunction) &ColorLayerImageViewPanel::onSliceImage );
182 Connect( _sl_SliceImageZ->GetId(), wxEVT_SCROLL_LINEUP , (wxObjectEventFunction) &ColorLayerImageViewPanel::onSliceImage );
183 Connect( _sl_SliceImageZ->GetId(), wxEVT_SCROLL_LINEDOWN , (wxObjectEventFunction) &ColorLayerImageViewPanel::onSliceImage );
184 Connect( _sl_SliceImageZ->GetId(), wxEVT_SCROLL_PAGEUP , (wxObjectEventFunction) &ColorLayerImageViewPanel::onSliceImage );
185 Connect( _sl_SliceImageZ->GetId(), wxEVT_SCROLL_PAGEDOWN , (wxObjectEventFunction) &ColorLayerImageViewPanel::onSliceImage );
187 sizer -> Add( new wxStaticText(this,-1,_T("Color Image Layer")) , 1, wxGROW );
188 sizer -> Add( _btn_ReadImage , 1, wxGROW );
189 sizer -> Add( new wxStaticText(this,-1,_T(" ")) , 1, wxGROW );
190 sizer -> Add( new wxStaticText(this,-1,_T("Opacity Level")) , 1, wxGROW );
191 sizer -> Add( _opacity , 1, wxGROW );
192 sizer -> Add( new wxStaticText(this,-1,_T(" ")) , 1, wxGROW );
193 sizer -> Add( _cb_ShowHide , 1, wxGROW );
194 sizer -> Add( new wxStaticText(this,-1,_T(" ")) , 1, wxGROW );
195 sizer -> Add( _interpolationCheckBox , 1, wxGROW );
197 sizer -> Add( new wxStaticText(this,-1,_T(" ")) , 1, wxGROW );
198 sizer -> Add( new wxStaticText(this,-1,_T("Slice ")) , 1, wxGROW );
199 sizer -> Add( _sl_SliceImageX , 1, wxGROW );
200 sizer -> Add( _sl_SliceImageY , 1, wxGROW );
201 sizer -> Add( _sl_SliceImageZ , 1, wxGROW );
202 sizer -> Add( _cb_SliceFixDinamic , 1, wxGROW );
203 // sizer -> Add( _histogramMinMaxLevel->GetWindow() , 1, wxGROW );
210 sizer = new wxFlexGridSizer(2);
211 _interpolationCheckBox = new wxCheckBox(this, -1, _T("Interpolate") );
212 _interpolationCheckBox->SetValue(true);
213 _opacity = new wxSlider(this, wxID_ANY, 6, 0, 10, wxDefaultPosition, wxSize(2,40), wxSL_HORIZONTAL|wxSL_LABELS, wxDefaultValidator);
215 Connect( _interpolationCheckBox->GetId(), wxEVT_COMMAND_CHECKBOX_CLICKED, (wxObjectEventFunction) &ColorLayerImageViewPanel::onThresholdInterpolation );
216 Connect( _opacity->GetId(), wxEVT_SCROLL_THUMBTRACK, (wxObjectEventFunction) &ColorLayerImageViewPanel::onChangeOpacity );
217 // sizer -> Add( new wxStaticText(this,-1,_T("Opacity Level")) , 1, wxEXPAND );
218 sizer -> Add( _opacity , 1, wxGROW );
219 sizer -> Add( _interpolationCheckBox , 1, wxGROW );
220 sizer->AddGrowableCol(0);
225 this->SetSizer( sizer );
226 // this->SetAutoLayout( true );
229 //CM Sets the default fitting mode to Pixel mode.
234 //----------------------------------------------------------------------------
235 ColorLayerImageViewPanel::~ColorLayerImageViewPanel()
240 //----------------------------------------------------------------------------
241 ColorLayerImageViewManager* ColorLayerImageViewPanel::GetColorLayerImageViewManager()
243 return _colorLayerImageViewManager;
247 //----------------------------------------------------------------------------
248 // This is the new spacing of the background image (1,1,1)
249 void ColorLayerImageViewPanel::SetBaseSpacing(double spc[3])
251 _spcBase[0] = spc[0];
252 _spcBase[1] = spc[1];
253 _spcBase[2] = spc[2];
260 //----------------------------------------------------------------------------
261 // This is the Original spacing of the background image
262 void ColorLayerImageViewPanel::SetOriginalSpacing(double spc[3])
269 //----------------------------------------------------------------------------
270 // This is the size in pixels of the background image
271 void ColorLayerImageViewPanel::SetBaseDimension(int dim[3])
273 _dimBase[0] = dim[0];
274 _dimBase[1] = dim[1];
275 _dimBase[2] = dim[2];
278 //----------------------------------------------------------------------------
279 void ColorLayerImageViewPanel::SetImage(vtkImageData *img)
283 if (_histogramMinMaxLevel!=NULL)
285 _histogramMinMaxLevel->Configure( img );
287 _colorLayerImageViewManager->SetImage( img );
290 img->GetSpacing(spc);
294 img->GetWholeExtent(ext);
295 dim[0] = ext[1]-ext[0];
296 dim[1] = ext[3]-ext[2];
297 dim[2] = ext[5]-ext[4];
300 if (_sl_SliceImageX!=NULL)
302 _sl_SliceImageX->SetRange( 0 , dim[0] );
303 _sl_SliceImageY->SetRange( 0 , dim[1] );
304 _sl_SliceImageZ->SetRange( 0 , dim[2] );
307 printf("EED ColorLayerImageViewPanel::SetImage UUPPSS----------------------\n" );
308 printf("EED ColorLayerImageViewPanel::SetImage UUPPSS----------------------\n" );
309 printf("EED ColorLayerImageViewPanel::SetImage UUPPSS----------------------\n" );
310 printf("EED ColorLayerImageViewPanel::SetImage UUPPSS----------------------\n" );
311 printf(" Here I have to analyse the spacing and size image to calculate new spacingvv\n" );
312 printf(" I need the caracteristics of the base image\n" );
313 // GetColorLayerImageViewManager()->GetwxVtkBaseView(0);
316 if ( (spc[0]!=_spcBase[0]) || (spc[1]!=_spcBase[1]) || (spc[2]!=_spcBase[2]) ||
317 (dim[0]!=_dimBase[0]) || (spc[1]!=_spcBase[1]) || (spc[2]!=_spcBase[2])
321 int typeOfTransformation;
322 // In case of the option is set to create a dialog box.
323 if (_fitting_mode == -1)
326 wxString msg = _T("The image resolution of both images are not compatible. Do you want to tranform it? ");
327 wxDlgTransformByDimensionBySpacingByPixel dlg;
328 dlg.GetTransformType(this,_spcBase,spc,_dimBase,dim,msg,typeOfTransformation,transformOkDlg);
329 // CM Reset the default value (Pixel i.e. 3) if the dialog box returned an inappropriate value.
330 if (transformOkDlg == false)
332 typeOfTransformation = 3;
335 typeOfTransformation = _fitting_mode;
336 } // _fitting_mode -1
338 printf("EED ColorLayerImageViewPanel::SetImage %d\n", typeOfTransformation );
341 if (typeOfTransformation==1) // make dimensions equals
343 printf("EED ColorLayerImageViewPanel::onReadImage ...WARNNING.... dif size image spc*dim ofnew image ...???\n");
344 spc[0]=_spcBase[0]*_dimBase[0]/dim[0];
345 spc[1]=_spcBase[1]*_dimBase[1]/dim[1];
349 if (typeOfTransformation==2) // make spacing equals
351 spc[0] = ( _spcBase[0]/spc[0] ) * _spcOrg[0];
352 spc[1] = ( _spcBase[1]/spc[1] ) * _spcOrg[1];
353 spc[2] = ( _spcBase[2]/spc[2] ) * _spcOrg[2];
356 if (typeOfTransformation==3) // make spacing = 1
363 img->SetSpacing(spc);
364 } // spc !_spcBase dim!__dimBase
369 _colorLayerImageViewManager->onThreshold();
376 void ColorLayerImageViewPanel::RefreshView()
378 //EED01 _colorLayerImageView->Refresh();
379 _colorLayerImageViewManager->Refresh();
382 //----------------------------------------------------------------------------
383 void ColorLayerImageViewPanel::SetFittingMode(int fitting_mode)
385 // CM Sets the fitting mode if an appropriate value is provided.
386 if (fitting_mode == -1 || fitting_mode == 1 || fitting_mode == 2 || fitting_mode == 3)
388 _fitting_mode = fitting_mode;
390 //Otherwise, an exception should be thrown (value 0 is fine, it corresponds to an empty field i.e. the default value is kept).
391 else if (fitting_mode != 0)
392 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;
396 //----------------------------------------------------------------------------
397 int ColorLayerImageViewPanel::GetFittingMode()
399 return _fitting_mode;
402 //----------------------------------------------------------------------------
403 void ColorLayerImageViewPanel::onReadImage(wxCommandEvent& event)
406 // creaImageIO::WxSimpleDlg w(0,_T("Select your image"),"creaContours_Descriptor.dscp","creatisContours DB");
408 printf("EED ColorLayerImageViewPanel::onReadImage ....WARNING... Read dlg. all images creaImageIO ... ???\n");
410 creaMaracasVisuKernel::OpenImageDialog diag = creaMaracasVisuKernel::OpenImageDialog();
411 SetImage( diag.getImageData() );
414 //----------------------------------------------------------------------------
415 void ColorLayerImageViewPanel::onThresholdChange(wxCommandEvent& event)
419 _colorLayerImageViewManager->onThresholdChange();
421 //std::cout<< "Valor Min: " << minVal << " & Valor Max: " << maxVal << std::endl;
425 //----------------------------------------------------------------------------
426 void ColorLayerImageViewPanel::onThresholdShow(wxCommandEvent& event)
428 _thresholdGo = _cb_ShowHide->GetValue();
429 _active = _thresholdGo;
432 _colorLayerImageViewManager->onThreshold();
434 _colorLayerImageViewManager->onThresholdRemove( );
439 //----------------------------------------------------------------------------
440 void ColorLayerImageViewPanel::onThresholdStop()
444 _colorLayerImageViewManager->onThresholdRemove( );
449 //----------------------------------------------------------------------------
450 void ColorLayerImageViewPanel::onThresholdInterpolation(wxCommandEvent& event)
452 _colorLayerImageViewManager->onThresholdInterpolation(_interpolationCheckBox->GetValue());
456 //----------------------------------------------------------------------------
457 void ColorLayerImageViewPanel::onSliceFixDinamic(wxCommandEvent& event)
459 bool fixdin = _cb_SliceFixDinamic->GetValue();
460 _colorLayerImageViewManager->SetSliceFixDynamic( fixdin );
463 _colorLayerImageViewManager->SetX2( _sl_SliceImageX->GetValue() );
464 _colorLayerImageViewManager->SetY2( _sl_SliceImageY->GetValue() );
465 _colorLayerImageViewManager->SetZ2( _sl_SliceImageZ->GetValue() );
467 _sl_SliceImageX->Enable(!fixdin);
468 _sl_SliceImageY->Enable(!fixdin);
469 _sl_SliceImageZ->Enable(!fixdin);
470 _colorLayerImageViewManager->onThreshold();
474 //----------------------------------------------------------------------------
475 void ColorLayerImageViewPanel::onSliceImage(wxScrollEvent& event)
477 _colorLayerImageViewManager->SetX2( _sl_SliceImageX->GetValue() );
478 _colorLayerImageViewManager->SetY2( _sl_SliceImageY->GetValue() );
479 _colorLayerImageViewManager->SetZ2( _sl_SliceImageZ->GetValue() );
480 _colorLayerImageViewManager->onThreshold();
484 //----------------------------------------------------------------------------
485 void ColorLayerImageViewPanel::onChangeOpacity(wxScrollEvent& event)
487 int opacity = _opacity->GetValue();
488 _colorLayerImageViewManager->onThresholdChangeOpacity(opacity);
493 //----------------------------------------------------------------------------
494 bool ColorLayerImageViewPanel::IsVisible()
499 //----------------------------------------------------------------------------
500 void ColorLayerImageViewPanel::SetActive(bool active)
503 if (_cb_ShowHide!=NULL)
505 _cb_ShowHide->SetValue( _active );