3 * \brief ClassThresholdImageViewPanel .
7 #include "ColorLayerImageViewPanel.h"
8 #include "OpenImageDialog.h"
11 //---------------------------------------------------------
12 //---------------------------------------------------------
13 //---------------------------------------------------------
15 wxDlgTransformByDimensionBySpacingByPixel::wxDlgTransformByDimensionBySpacingByPixel()
19 wxDlgTransformByDimensionBySpacingByPixel::~wxDlgTransformByDimensionBySpacingByPixel()
24 void wxDlgTransformByDimensionBySpacingByPixel::GetTransformType(wxWindow *parent , wxString message,int &typeOfTransformation,bool &dlgWxOK)
26 wxDialog* dial = new wxDialog (parent,-1,_T("Tools"),wxDefaultPosition, wxSize(590,190));
27 wxSizer* buttonsSizer = dial->CreateSeparatedButtonSizer(wxOK|wxCANCEL);
28 wxBoxSizer *dialSizer = new wxBoxSizer(wxVERTICAL);
30 wxString lstOptOperation[3];
31 lstOptOperation[0]=_T("By Dimension");
32 lstOptOperation[1]=_T("By Spacing");
33 lstOptOperation[2]=_T("By Pixel");
34 wxRadioBox * radioOpts = new wxRadioBox(dial, -1, _T("Type of Transformation"), wxDefaultPosition, wxSize(270,45), 3 , lstOptOperation, 3, wxRA_SPECIFY_COLS);
36 dialSizer->Add( new wxStaticText(dial,-1,message) , 0, wxGROW );
37 // dialSizer->Add( new wxStaticText(dial,-1,_T("selected Roi file. Do you want to tranform it?")) , 0, wxGROW );
38 dialSizer->Add( new wxStaticText(dial,-1,_T(" ")) , 0, wxGROW );
39 dialSizer->Add(radioOpts,0,wxGROW);
40 dialSizer->Add( new wxStaticText(dial,-1,_T(" ")) , 0, wxGROW );
41 dialSizer->Add(buttonsSizer,0,wxGROW);
42 dial->SetSizer(dialSizer, true);
46 typeOfTransformation = -1;
49 if (dial->GetReturnCode() == wxID_OK)
51 typeOfTransformation = radioOpts->GetSelection();
57 //---------------------------------------------------------
58 //---------------------------------------------------------
59 //---------------------------------------------------------
63 ** Begin of the threshold panel
65 ColorLayerImageViewPanel::ColorLayerImageViewPanel(wxWindow* parent, int min, int max, int type)
66 : wxPanel(parent, -1, wxDefaultPosition, wxDefaultSize, wxBORDER_SUNKEN)
68 printf("EED ColorLayerImageViewPanel::ColorLayerImageViewPanel start \n");
70 _spcBase[0] = _spcBase[1] = _spcBase[2] = 0;
71 _dimBase[0] = _dimBase[1] = _dimBase[2] = 0;
73 _colorLayerImageView = new ColorLayerImageView();
74 _btn_ReadImage = new wxButton(this, wxID_ANY, _T("Read Image") );
76 _cb_ShowHide = new wxCheckBox(this, wxID_ANY, _T("Show/Hide Layer") );
77 _cb_ShowHide->SetValue(_thresholdGo);
79 _cb_SliceFixDinamic = new wxCheckBox(this, wxID_ANY, _T("Fixed/Dynamic Slice") );
80 _cb_SliceFixDinamic->SetValue(true);
82 _sl_SliceImage = new wxSlider(this, wxID_ANY, 0, 1000, 1000, wxDefaultPosition, wxDefaultSize, wxSL_HORIZONTAL|wxSL_LABELS, wxDefaultValidator);
83 _sl_SliceImage->Enable(false);
85 _interpolationCheckBox = new wxCheckBox(this, -1, _T("Image Interpolation") );
86 _interpolationCheckBox->SetValue(true);
87 _opacity = new wxSlider(this, wxID_ANY, 6, 1, 10, wxDefaultPosition, wxDefaultSize, wxSL_HORIZONTAL|wxSL_LABELS, wxDefaultValidator);
98 Connect( _btn_ReadImage->GetId(), wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &ColorLayerImageViewPanel::onReadImage );
99 Connect( _cb_ShowHide->GetId(), wxEVT_COMMAND_CHECKBOX_CLICKED , (wxObjectEventFunction) &ColorLayerImageViewPanel::onThresholdShow );
100 Connect( _interpolationCheckBox->GetId(), wxEVT_COMMAND_CHECKBOX_CLICKED, (wxObjectEventFunction) &ColorLayerImageViewPanel::onThresholdInterpolation );
101 Connect( _opacity->GetId(), wxEVT_SCROLL_THUMBTRACK, (wxObjectEventFunction) &ColorLayerImageViewPanel::onChangeOpacity );
102 Connect( _cb_SliceFixDinamic->GetId(), wxEVT_COMMAND_CHECKBOX_CLICKED, (wxObjectEventFunction) &ColorLayerImageViewPanel::onSliceFixDinamic );
103 Connect( _sl_SliceImage->GetId(), wxEVT_SCROLL_THUMBTRACK , (wxObjectEventFunction) &ColorLayerImageViewPanel::onSliceImage );
104 Connect( _sl_SliceImage->GetId(), wxEVT_SCROLL_LINEUP , (wxObjectEventFunction) &ColorLayerImageViewPanel::onSliceImage );
105 Connect( _sl_SliceImage->GetId(), wxEVT_SCROLL_LINEDOWN , (wxObjectEventFunction) &ColorLayerImageViewPanel::onSliceImage );
106 Connect( _sl_SliceImage->GetId(), wxEVT_SCROLL_PAGEUP , (wxObjectEventFunction) &ColorLayerImageViewPanel::onSliceImage );
107 Connect( _sl_SliceImage->GetId(), wxEVT_SCROLL_PAGEDOWN , (wxObjectEventFunction) &ColorLayerImageViewPanel::onSliceImage );
110 wxFlexGridSizer * sizer = new wxFlexGridSizer(1);
113 sizer -> Add( new wxStaticText(this,-1,_T("Color Image Layer")) , 1, wxGROW );
114 sizer -> Add( _btn_ReadImage, 1, wxGROW );
115 sizer -> Add( new wxStaticText(this,-1,_T(" ")) , 1, wxGROW );
117 sizer -> Add( new wxStaticText(this,-1,_T("Opacity Level")) , 1, wxGROW );
118 sizer -> Add( _opacity, 1, wxGROW );
119 sizer -> Add( new wxStaticText(this,-1,_T(" ")) , 1, wxGROW );
120 sizer -> Add( _cb_ShowHide, 1, wxGROW );
121 sizer -> Add( new wxStaticText(this,-1,_T(" ")) , 1, wxGROW );
122 sizer -> Add( _interpolationCheckBox, 1, wxGROW );
124 sizer -> Add( new wxStaticText(this,-1,_T(" ")) , 1, wxGROW );
125 sizer -> Add( new wxStaticText(this,-1,_T("Slice ")) , 1, wxGROW );
126 sizer -> Add( _sl_SliceImage, 1, wxGROW );
127 sizer -> Add( _cb_SliceFixDinamic, 1, wxGROW );
129 this->SetSizer( sizer );
130 this->SetAutoLayout( true );
134 //----------------------------------------------------------------------------
135 ColorLayerImageViewPanel::~ColorLayerImageViewPanel()
140 //----------------------------------------------------------------------------
141 void ColorLayerImageViewPanel::SetColorLayerImageView(ColorLayerImageView* colorLayerImageView)
143 _colorLayerImageView = colorLayerImageView;
146 //----------------------------------------------------------------------------
147 ColorLayerImageView* ColorLayerImageViewPanel::GetColorLayerImageView()
149 return _colorLayerImageView;
153 // This is the new spacing of the background image (1,1,1)
154 void ColorLayerImageViewPanel::SetBaseSpacing(double spc[3])
156 _spcBase[0] = spc[0];
157 _spcBase[1] = spc[1];
158 _spcBase[2] = spc[2];
165 // This is the Original spacing of the background image
166 void ColorLayerImageViewPanel::SetOriginalSpacing(double spc[3])
173 // This is the size in pixels of the background image
174 void ColorLayerImageViewPanel::SetBaseDimension(int dim[3])
176 _dimBase[0] = dim[0];
177 _dimBase[1] = dim[1];
178 _dimBase[2] = dim[2];
181 //----------------------------------------------------------------------------
182 void ColorLayerImageViewPanel::SetImage(vtkImageData *img)
186 _colorLayerImageView->SetImage( img );
189 img->GetSpacing(spc);
193 img->GetWholeExtent(ext);
194 dim[0] = ext[1]-ext[0];
195 dim[1] = ext[3]-ext[2];
196 dim[2] = ext[5]-ext[4];
197 _sl_SliceImage->SetRange( 0 , dim[2] );
199 if ( (spc[0]!=_spcBase[0]) || (spc[1]!=_spcBase[1]) || (spc[2]!=_spcBase[2]) ||
200 (dim[0]!=_dimBase[0]) || (spc[1]!=_spcBase[1]) || (spc[2]!=_spcBase[2])
205 int typeOfTransformation;
206 wxString msg = _T("The image resolution of both images are not compatible. Do you want to tranform it? ");
207 wxDlgTransformByDimensionBySpacingByPixel dlg;
208 dlg.GetTransformType(this,msg,typeOfTransformation,transformOkDlg);
210 printf("EED ColorLayerImageViewPanel::onReadImage call dialog spc size,dim...???\n");
212 if (typeOfTransformation==0) // make dimensions equals
214 printf("EED ColorLayerImageViewPanel::onReadImage ...WARNNING.... dif size image spc*dim ofnew image ...???\n");
215 spc[0]=_spcBase[0]*_dimBase[0]/dim[0];
216 spc[1]=_spcBase[1]*_dimBase[1]/dim[1];
220 if (typeOfTransformation==1) // make spacing equals
222 spc[0] = ( _spcBase[0]/spc[0] ) * _spcOrg[0];
223 spc[1] = ( _spcBase[1]/spc[1] ) * _spcOrg[1];
224 spc[2] = ( _spcBase[2]/spc[2] ) * _spcOrg[2];
227 if (typeOfTransformation==2) // make spacing = 1
234 img->SetSpacing(spc);
235 } // spc !_spcBase dim!__dimBase
237 if (_colorLayerImageView!=NULL)
239 _colorLayerImageView->onThreshold();
240 _colorLayerImageView->Refresh();
247 //----------------------------------------------------------------------------
248 void ColorLayerImageViewPanel::onReadImage(wxCommandEvent& event)
251 // creaImageIO::WxSimpleDlg w(0,_T("Select your image"),"creaContours_Descriptor.dscp","creatisContours DB");
253 printf("EED ColorLayerImageViewPanel::onReadImage ....WARNING... Read dlg. all images creaImageIO ... ???\n");
255 creaMaracasVisuKernel::OpenImageDialog diag = creaMaracasVisuKernel::OpenImageDialog();
256 SetImage( diag.getImageData() );
259 //----------------------------------------------------------------------------
260 void ColorLayerImageViewPanel::onThresholdChange(wxCommandEvent& event)
262 if (_colorLayerImageView!=NULL)
266 _colorLayerImageView->onThresholdChange();
267 _colorLayerImageView->Refresh();
268 //std::cout<< "Valor Min: " << minVal << " & Valor Max: " << maxVal << std::endl;
270 }//_colorLayerImageView
273 //----------------------------------------------------------------------------
274 void ColorLayerImageViewPanel::onThresholdShow(wxCommandEvent& event)
276 if (_colorLayerImageView!=NULL)
278 _thresholdGo = _cb_ShowHide->GetValue();
281 _colorLayerImageView->onThreshold();
283 _colorLayerImageView->onThresholdRemove( );
285 _colorLayerImageView->Refresh();
286 }//_colorLayerImageView
289 //----------------------------------------------------------------------------
290 void ColorLayerImageViewPanel::onThresholdStop()
292 if (_colorLayerImageView!=NULL)
296 _colorLayerImageView->onThresholdRemove( );
299 }//_colorLayerImageView
302 //----------------------------------------------------------------------------
303 void ColorLayerImageViewPanel::onThresholdInterpolation(wxCommandEvent& event)
305 if (_colorLayerImageView!=NULL)
307 _colorLayerImageView->onThresholdInterpolation(_interpolationCheckBox->GetValue());
308 _colorLayerImageView->Refresh();
309 }//_colorLayerImageView
312 //----------------------------------------------------------------------------
313 void ColorLayerImageViewPanel::onSliceFixDinamic(wxCommandEvent& event)
315 if (_colorLayerImageView!=NULL)
317 bool fixdin = _cb_SliceFixDinamic->GetValue();
318 _colorLayerImageView->SetSliceFixDynamic( fixdin );
321 _colorLayerImageView->SetZ2( _sl_SliceImage->GetValue() );
323 _sl_SliceImage->Enable(!fixdin);
324 _colorLayerImageView->onThreshold();
325 _colorLayerImageView->Refresh();
326 }//_colorLayerImageView
329 //----------------------------------------------------------------------------
330 void ColorLayerImageViewPanel::onSliceImage(wxScrollEvent& event)
332 if (_colorLayerImageView!=NULL)
334 _colorLayerImageView->SetZ2( _sl_SliceImage->GetValue() );
335 _colorLayerImageView->onThreshold();
336 _colorLayerImageView->Refresh();
337 }//_colorLayerImageView
340 //----------------------------------------------------------------------------
341 void ColorLayerImageViewPanel::onChangeOpacity(wxScrollEvent& event)
343 if (_colorLayerImageView!=NULL)
345 int opacity = _opacity->GetValue();
346 _colorLayerImageView->onThresholdChangeOpacity(opacity);
347 _colorLayerImageView->Refresh();
348 }//_colorLayerImageView
352 //----------------------------------------------------------------------------
353 bool ColorLayerImageViewPanel::IsVisible()