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,525),wxRESIZE_BORDER);
60 wxSizer* buttonsSizer = dial->CreateSeparatedButtonSizer(wxOK);
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");
68 lstOptOperation[0]=_T("Adapt spacing of the Layer Image");
69 lstOptOperation[1]=_T("Keep the spacing of the Layer Image");
70 lstOptOperation[2]=_T("Use the same spacing of the Base Image");
72 wxRadioBox * radioOpts = new wxRadioBox(dial, -1, _T("Type of spacing transformation"), wxDefaultPosition, wxSize(250,160), 3 , lstOptOperation, 1, wxRA_SPECIFY_COLS);
75 wxString strBaseSpc(str);
80 strBaseSpc.Printf(wxT("Base spacing: %f %f %f") , baseSpc[0],baseSpc[1],baseSpc[2] );
81 strLayerSpc.Printf(wxT("Layer spacing: %f %f %f") , layerSpc[0],layerSpc[1],layerSpc[2] );
82 strBaseDim.Printf(wxT("Base dimension: %d %d %d") , baseDim[0],baseDim[1],baseDim[2] );
83 strLayerDim.Printf(wxT("Layer dimension: %d %d %d") , layerDim[0],layerDim[1],layerDim[2] );
85 dialSizer->Add( new wxStaticText(dial,-1,_T(" ") ) , 0, wxGROW );
86 dialSizer->Add( new wxStaticText(dial,-1, strBaseSpc ) , 0, wxGROW );
87 dialSizer->Add( new wxStaticText(dial,-1, strLayerSpc ) , 0, wxGROW );
88 dialSizer->Add( new wxStaticText(dial,-1,_T(" ") ) , 0, wxGROW );
89 dialSizer->Add( new wxStaticText(dial,-1, strBaseDim ) , 0, wxGROW );
90 dialSizer->Add( new wxStaticText(dial,-1, strLayerDim ) , 0, wxGROW );
91 dialSizer->Add( new wxStaticText(dial,-1,_T(" ") ) , 0, wxGROW );
92 dialSizer->Add( new wxStaticText(dial,-1,message ) , 0, wxGROW );
93 dialSizer->Add( new wxStaticText(dial,-1,_T(" ") ) , 0, wxGROW );
94 dialSizer->Add(radioOpts,0,wxGROW);
95 dialSizer->Add( new wxStaticText(dial,-1,_T(" ") ) , 0, wxGROW );
96 dialSizer->Add(buttonsSizer,0,wxGROW);
97 dial->SetSizer(dialSizer, true);
101 typeOfTransformation = -1;
104 printf("EED wxDlgTransformByDimensionBySpacingByPixel::GetTransformType AAA\n");
106 if (dial->GetReturnCode() == wxID_OK)
108 typeOfTransformation = radioOpts->GetSelection() + 1;
109 printf("EED wxDlgTransformByDimensionBySpacingByPixel::GetTransformType BBB %d\n",typeOfTransformation);
115 //---------------------------------------------------------
116 //---------------------------------------------------------
117 //---------------------------------------------------------
121 ** Begin of the threshold panel
123 ColorLayerImageViewPanel::ColorLayerImageViewPanel(wxWindow* parent, int min, int max,int opacity, int type)
124 //: wxPanel(parent, -1, wxDefaultPosition, wxSize(600,100), wxBORDER_SUNKEN)
125 : wxPanel(parent, -1, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL)
127 _spcBase[0] = _spcBase[1] = _spcBase[2] = 0;
128 _dimBase[0] = _dimBase[1] = _dimBase[2] = 0;
130 _sl_SliceImageX = NULL;
131 _sl_SliceImageY = NULL;
132 _sl_SliceImageZ = NULL;
134 _histogramMinMaxLevel = NULL;
135 wxFlexGridSizer * sizer = NULL;
136 _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, opacity, 0, 100, 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 );
208 sizer = new wxFlexGridSizer(2);
209 _interpolationCheckBox = new wxCheckBox(this, -1, _T("Interpolate") );
210 _interpolationCheckBox->SetValue(true);
211 _opacity = new wxSlider(this, wxID_ANY, opacity, 0, 100, wxDefaultPosition, wxDefaultSize, wxSL_HORIZONTAL|wxSL_LABELS, wxDefaultValidator);
212 Connect( _interpolationCheckBox->GetId(), wxEVT_COMMAND_CHECKBOX_CLICKED, (wxObjectEventFunction) &ColorLayerImageViewPanel::onThresholdInterpolation );
213 Connect( _opacity->GetId(), wxEVT_SCROLL_THUMBTRACK, (wxObjectEventFunction) &ColorLayerImageViewPanel::onChangeOpacity );
214 // sizer -> Add( new wxStaticText(this,-1,_T("Opacity Level")) , 1, wxEXPAND );
215 sizer -> Add( _opacity , 1, wxGROW );
216 sizer -> Add( _interpolationCheckBox , 1, wxGROW );
217 sizer->AddGrowableCol(0);
221 this->SetSizer( sizer );
222 // this->SetAutoLayout( true );
225 //CM Sets the default fitting mode to Pixel mode.
230 //----------------------------------------------------------------------------
231 ColorLayerImageViewPanel::~ColorLayerImageViewPanel()
235 //----------------------------------------------------------------------------
236 ColorLayerImageViewManager* ColorLayerImageViewPanel::GetColorLayerImageViewManager()
238 return _colorLayerImageViewManager;
241 //----------------------------------------------------------------------------
242 void ColorLayerImageViewPanel::SetImage(vtkImageData *img)
246 if (_histogramMinMaxLevel!=NULL)
248 _histogramMinMaxLevel->Configure( img );
250 _colorLayerImageViewManager->SetImage( img );
251 double spcOriginalLayer[3];
252 int dimensionOriginalLayer[3];
254 int dimensionBase[3];
256 GetColorLayerImageViewManager()->GetSpcOriginalLayer(0,spcOriginalLayer);
257 GetColorLayerImageViewManager()->GetDimensionOriginalLayer(0,dimensionOriginalLayer);
258 GetColorLayerImageViewManager()->GetSpcBase(0,spcBase);
259 GetColorLayerImageViewManager()->GetDimensionBase(0,dimensionBase);
260 if (_sl_SliceImageX!=NULL)
262 _sl_SliceImageX->SetRange( 0 , dimensionOriginalLayer[0] );
263 _sl_SliceImageY->SetRange( 0 , dimensionOriginalLayer[1] );
264 _sl_SliceImageZ->SetRange( 0 , dimensionOriginalLayer[2] );
267 if ( (spcOriginalLayer[0]!=spcBase[0]) ||
268 (spcOriginalLayer[1]!=spcBase[1]) ||
269 (spcOriginalLayer[2]!=spcBase[2]) ||
270 (dimensionOriginalLayer[0]!=dimensionBase[0]) ||
271 (dimensionOriginalLayer[1]!=dimensionBase[1]) ||
272 (dimensionOriginalLayer[2]!=dimensionBase[2])
276 int typeOfTransformation;
277 // In case of the option is set to create a dialog box.
278 if (_fitting_mode == -1)
281 wxString msg = _T("The image resolution of both images are not compatible. How do you want to tranform it? ");
282 wxDlgTransformByDimensionBySpacingByPixel dlg;
283 dlg.GetTransformType(this , spcBase , spcOriginalLayer , dimensionBase ,dimensionOriginalLayer ,msg,typeOfTransformation,transformOkDlg);
284 // CM Reset the default value (Pixel i.e. 3) if the dialog box returned an inappropriate value.
285 if (transformOkDlg == false)
287 typeOfTransformation = 3;
290 typeOfTransformation = _fitting_mode;
291 } // _fitting_mode -1
294 if (typeOfTransformation==1) // Adapt spacing
296 newSpc[0] = spcBase[0] * dimensionBase[0] / dimensionOriginalLayer[0];
297 newSpc[1] = spcBase[1] * dimensionBase[1] / dimensionOriginalLayer[1];
298 newSpc[2] = spcBase[2] * dimensionBase[2] / dimensionOriginalLayer[2];
301 if (typeOfTransformation==2) // keep spacing of the Layer Image
303 newSpc[0] = spcOriginalLayer[0];
304 newSpc[1] = spcOriginalLayer[1];
305 newSpc[2] = spcOriginalLayer[2];
308 if (typeOfTransformation==3) // Use the spacing of the Base Image
310 newSpc[0] = spcBase[0];
311 newSpc[1] = spcBase[1];
312 newSpc[2] = spcBase[2];
314 GetColorLayerImageViewManager()->SetNewSpacingLayer(newSpc);
316 newSpc[0] = spcOriginalLayer[0];
317 newSpc[1] = spcOriginalLayer[1];
318 newSpc[2] = spcOriginalLayer[2];
319 } // spc !_spcBase dim!__dimBase
321 GetColorLayerImageViewManager()->SetNewSpacingLayer(newSpc);
327 _colorLayerImageViewManager->onThreshold();
332 void ColorLayerImageViewPanel::RefreshView()
334 //EED01 _colorLayerImageView->Refresh();
335 _colorLayerImageViewManager->Refresh();
338 //----------------------------------------------------------------------------
339 void ColorLayerImageViewPanel::SetFittingMode(int fitting_mode)
341 // CM Sets the fitting mode if an appropriate value is provided.
342 if (fitting_mode == -1 || fitting_mode == 1 || fitting_mode == 2 || fitting_mode == 3)
344 _fitting_mode = fitting_mode;
346 //Otherwise, an exception should be thrown (value 0 is fine, it corresponds to an empty field i.e. the default value is kept).
347 else if (fitting_mode != 0)
348 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;
352 //----------------------------------------------------------------------------
353 int ColorLayerImageViewPanel::GetFittingMode()
355 return _fitting_mode;
358 //----------------------------------------------------------------------------
359 void ColorLayerImageViewPanel::onReadImage(wxCommandEvent& event)
362 // creaImageIO::WxSimpleDlg w(0,_T("Select your image"),"creaContours_Descriptor.dscp","creatisContours DB");
364 printf("EED ColorLayerImageViewPanel::onReadImage ....WARNING... Read dlg. all images creaImageIO ... ???\n");
373 creaMaracasVisuKernel::OpenImageDialog diag = creaMaracasVisuKernel::OpenImageDialog();
374 vtkImageChangeInformation *change = vtkImageChangeInformation::New();
375 vtkImageData *img = diag.getImageData();
376 img -> GetExtent( ext );
377 img -> GetSpacing( spc );
378 change -> SetInputData( img );
379 change -> SetOutputSpacing( spc[0] , spc[1] , spc [2] );
380 change -> SetOutputExtentStart(0,0,0);
381 change -> SetOutputOrigin( origin );
382 change -> Modified(); //important
383 change -> Update(); //important
384 SetImage( change->GetOutput() );
385 _colorLayerImageViewManager->onThreshold();
389 //----------------------------------------------------------------------------
390 void ColorLayerImageViewPanel::onThresholdChange(wxCommandEvent& event)
394 _colorLayerImageViewManager->onThresholdChange();
396 //std::cout<< "Valor Min: " << minVal << " & Valor Max: " << maxVal << std::endl;
400 //----------------------------------------------------------------------------
401 void ColorLayerImageViewPanel::onThresholdShow(wxCommandEvent& event)
403 _thresholdGo = _cb_ShowHide->GetValue();
404 _active = _thresholdGo;
407 _colorLayerImageViewManager->onThreshold();
409 _colorLayerImageViewManager->onThresholdRemove( );
414 //----------------------------------------------------------------------------
415 void ColorLayerImageViewPanel::onThresholdStop()
419 _colorLayerImageViewManager->onThresholdRemove( );
424 //----------------------------------------------------------------------------
425 void ColorLayerImageViewPanel::onThresholdInterpolation(wxCommandEvent& event)
427 _colorLayerImageViewManager->onThresholdInterpolation(_interpolationCheckBox->GetValue());
431 //----------------------------------------------------------------------------
432 void ColorLayerImageViewPanel::onSliceFixDinamic(wxCommandEvent& event)
434 bool fixdin = _cb_SliceFixDinamic->GetValue();
435 _colorLayerImageViewManager->SetSliceFixDynamic( fixdin );
438 _colorLayerImageViewManager->SetX2( _sl_SliceImageX->GetValue() );
439 _colorLayerImageViewManager->SetY2( _sl_SliceImageY->GetValue() );
440 _colorLayerImageViewManager->SetZ2( _sl_SliceImageZ->GetValue() );
442 _sl_SliceImageX->Enable(!fixdin);
443 _sl_SliceImageY->Enable(!fixdin);
444 _sl_SliceImageZ->Enable(!fixdin);
445 _colorLayerImageViewManager->onThreshold();
449 //----------------------------------------------------------------------------
450 void ColorLayerImageViewPanel::onSliceImage(wxScrollEvent& event)
452 _colorLayerImageViewManager->SetX2( _sl_SliceImageX->GetValue() );
453 _colorLayerImageViewManager->SetY2( _sl_SliceImageY->GetValue() );
454 _colorLayerImageViewManager->SetZ2( _sl_SliceImageZ->GetValue() );
455 _colorLayerImageViewManager->onThreshold();
459 //----------------------------------------------------------------------------
460 void ColorLayerImageViewPanel::ChangeOpacity()
462 int opacity = _opacity->GetValue();
463 _colorLayerImageViewManager->onThresholdChangeOpacity(opacity);
467 //----------------------------------------------------------------------------
468 void ColorLayerImageViewPanel::onChangeOpacity(wxScrollEvent& event)
471 // int opacity = _opacity->GetValue();
472 // _colorLayerImageViewManager->onThresholdChangeOpacity(opacity);
477 //----------------------------------------------------------------------------
478 bool ColorLayerImageViewPanel::IsVisible()
483 //----------------------------------------------------------------------------
484 void ColorLayerImageViewPanel::SetActive(bool active)
487 if (_cb_ShowHide!=NULL)
489 _cb_ShowHide->SetValue( _active );