5 * \brief ClassThresholdImageViewPanel .
9 #include "ColorLayerImageViewPanel.h"
10 #include "OpenImageDialog.h"
13 //---------------------------------------------------------
14 //---------------------------------------------------------
15 //---------------------------------------------------------
17 wxDlgTransformByDimensionBySpacingByPixel::wxDlgTransformByDimensionBySpacingByPixel()
21 wxDlgTransformByDimensionBySpacingByPixel::~wxDlgTransformByDimensionBySpacingByPixel()
26 void wxDlgTransformByDimensionBySpacingByPixel::GetTransformType(wxWindow *parent , wxString message,int &typeOfTransformation,bool &dlgWxOK)
28 wxDialog* dial = new wxDialog (parent,-1,_T("Tools"),wxDefaultPosition, wxSize(590,190));
29 wxSizer* buttonsSizer = dial->CreateSeparatedButtonSizer(wxOK|wxCANCEL);
30 wxBoxSizer *dialSizer = new wxBoxSizer(wxVERTICAL);
32 wxString lstOptOperation[3];
33 lstOptOperation[0]=_T("By Dimension");
34 lstOptOperation[1]=_T("By Spacing");
35 lstOptOperation[2]=_T("By Pixel");
36 wxRadioBox * radioOpts = new wxRadioBox(dial, -1, _T("Type of Transformation"), wxDefaultPosition, wxSize(270,45), 3 , lstOptOperation, 3, wxRA_SPECIFY_COLS);
38 dialSizer->Add( new wxStaticText(dial,-1,message) , 0, wxGROW );
39 // dialSizer->Add( new wxStaticText(dial,-1,_T("selected Roi file. Do you want to tranform it?")) , 0, wxGROW );
40 dialSizer->Add( new wxStaticText(dial,-1,_T(" ")) , 0, wxGROW );
41 dialSizer->Add(radioOpts,0,wxGROW);
42 dialSizer->Add( new wxStaticText(dial,-1,_T(" ")) , 0, wxGROW );
43 dialSizer->Add(buttonsSizer,0,wxGROW);
44 dial->SetSizer(dialSizer, true);
48 typeOfTransformation = -1;
51 if (dial->GetReturnCode() == wxID_OK)
53 typeOfTransformation = radioOpts->GetSelection();
59 //---------------------------------------------------------
60 //---------------------------------------------------------
61 //---------------------------------------------------------
65 ** Begin of the threshold panel
67 ColorLayerImageViewPanel::ColorLayerImageViewPanel(wxWindow* parent, int min, int max, int type)
68 : wxPanel(parent, -1, wxDefaultPosition, wxDefaultSize, wxBORDER_SUNKEN)
70 printf("EED ColorLayerImageViewPanel::ColorLayerImageViewPanel start \n");
72 _spcBase[0] = _spcBase[1] = _spcBase[2] = 0;
73 _dimBase[0] = _dimBase[1] = _dimBase[2] = 0;
75 _colorLayerImageView = new ColorLayerImageView();
76 _btn_ReadImage = new wxButton(this, wxID_ANY, _T("Read Image") );
78 _cb_ShowHide = new wxCheckBox(this, wxID_ANY, _T("Show/Hide layer") );
79 _cb_ShowHide->SetValue(_thresholdGo);
81 _cb_SliceFixDinamic = new wxCheckBox(this, wxID_ANY, _T("Slice Fix/Dinamic") );
82 _cb_SliceFixDinamic->SetValue(true);
84 _sl_SliceImage = new wxSlider(this, wxID_ANY, 0, 1000, 1000, wxDefaultPosition, wxDefaultSize, wxSL_HORIZONTAL|wxSL_LABELS, wxDefaultValidator);
85 _sl_SliceImage->Enable(false);
87 _interpolationCheckBox = new wxCheckBox(this, -1, _T("Image interpolation") );
88 _interpolationCheckBox->SetValue(true);
89 _opacity = new wxSlider(this, wxID_ANY, 6, 1, 10, wxDefaultPosition, wxDefaultSize, wxSL_HORIZONTAL|wxSL_LABELS, wxDefaultValidator);
100 Connect( _btn_ReadImage->GetId(), wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &ColorLayerImageViewPanel::onReadImage );
101 Connect( _cb_ShowHide->GetId(), wxEVT_COMMAND_CHECKBOX_CLICKED , (wxObjectEventFunction) &ColorLayerImageViewPanel::onThresholdShow );
102 Connect( _interpolationCheckBox->GetId(), wxEVT_COMMAND_CHECKBOX_CLICKED, (wxObjectEventFunction) &ColorLayerImageViewPanel::onThresholdInterpolation );
103 Connect( _opacity->GetId(), wxEVT_SCROLL_THUMBTRACK, (wxObjectEventFunction) &ColorLayerImageViewPanel::onChangeOpacity );
104 Connect( _cb_SliceFixDinamic->GetId(), wxEVT_COMMAND_CHECKBOX_CLICKED, (wxObjectEventFunction) &ColorLayerImageViewPanel::onSliceFixDinamic );
105 Connect( _sl_SliceImage->GetId(), wxEVT_SCROLL_THUMBTRACK , (wxObjectEventFunction) &ColorLayerImageViewPanel::onSliceImage );
106 Connect( _sl_SliceImage->GetId(), wxEVT_SCROLL_LINEUP , (wxObjectEventFunction) &ColorLayerImageViewPanel::onSliceImage );
107 Connect( _sl_SliceImage->GetId(), wxEVT_SCROLL_LINEDOWN , (wxObjectEventFunction) &ColorLayerImageViewPanel::onSliceImage );
108 Connect( _sl_SliceImage->GetId(), wxEVT_SCROLL_PAGEUP , (wxObjectEventFunction) &ColorLayerImageViewPanel::onSliceImage );
109 Connect( _sl_SliceImage->GetId(), wxEVT_SCROLL_PAGEDOWN , (wxObjectEventFunction) &ColorLayerImageViewPanel::onSliceImage );
112 wxFlexGridSizer * sizer = new wxFlexGridSizer(1);
115 sizer -> Add( new wxStaticText(this,-1,_T("Color Image Layer")) , 1, wxGROW );
116 sizer -> Add( _btn_ReadImage, 1, wxGROW );
117 sizer -> Add( new wxStaticText(this,-1,_T(" ")) , 1, wxGROW );
119 sizer -> Add( new wxStaticText(this,-1,_T("Opacity Level")) , 1, wxGROW );
120 sizer -> Add( _opacity, 1, wxGROW );
121 sizer -> Add( new wxStaticText(this,-1,_T(" ")) , 1, wxGROW );
122 sizer -> Add( _cb_ShowHide, 1, wxGROW );
123 sizer -> Add( new wxStaticText(this,-1,_T(" ")) , 1, wxGROW );
124 sizer -> Add( _interpolationCheckBox, 1, wxGROW );
126 sizer -> Add( new wxStaticText(this,-1,_T(" ")) , 1, wxGROW );
127 sizer -> Add( new wxStaticText(this,-1,_T("Slice ")) , 1, wxGROW );
128 sizer -> Add( _sl_SliceImage, 1, wxGROW );
129 sizer -> Add( _cb_SliceFixDinamic, 1, wxGROW );
131 this->SetSizer( sizer );
132 this->SetAutoLayout( true );
136 //----------------------------------------------------------------------------
137 ColorLayerImageViewPanel::~ColorLayerImageViewPanel()
142 //----------------------------------------------------------------------------
143 void ColorLayerImageViewPanel::SetColorLayerImageView(ColorLayerImageView* colorLayerImageView)
145 _colorLayerImageView = colorLayerImageView;
148 //----------------------------------------------------------------------------
149 ColorLayerImageView* ColorLayerImageViewPanel::GetColorLayerImageView()
151 return _colorLayerImageView;
155 // This is the new spacing of the background image (1,1,1)
156 void ColorLayerImageViewPanel::SetBaseSpacing(double spc[3])
158 _spcBase[0] = spc[0];
159 _spcBase[1] = spc[1];
160 _spcBase[2] = spc[2];
167 // This is the Original spacing of the background image
168 void ColorLayerImageViewPanel::SetOriginalSpacing(double spc[3])
175 // This is the size in pixels of the background image
176 void ColorLayerImageViewPanel::SetBaseDimension(int dim[3])
178 _dimBase[0] = dim[0];
179 _dimBase[1] = dim[1];
180 _dimBase[2] = dim[2];
183 //----------------------------------------------------------------------------
184 void ColorLayerImageViewPanel::SetImage(vtkImageData *img)
188 _colorLayerImageView->SetImage( img );
191 img->GetSpacing(spc);
195 img->GetWholeExtent(ext);
196 dim[0] = ext[1]-ext[0];
197 dim[1] = ext[3]-ext[2];
198 dim[2] = ext[5]-ext[4];
199 _sl_SliceImage->SetRange( 0 , dim[2] );
201 if ( (spc[0]!=_spcBase[0]) || (spc[1]!=_spcBase[1]) || (spc[2]!=_spcBase[2]) ||
202 (dim[0]!=_dimBase[0]) || (spc[1]!=_spcBase[1]) || (spc[2]!=_spcBase[2])
207 int typeOfTransformation;
208 wxString msg = _T("The image resolution of both images are not compatible. Do you want to tranform it? ");
209 wxDlgTransformByDimensionBySpacingByPixel dlg;
210 dlg.GetTransformType(this,msg,typeOfTransformation,transformOkDlg);
212 printf("EED ColorLayerImageViewPanel::onReadImage call dialog spc size,dim...???\n");
214 if (typeOfTransformation==0) // make dimensions equals
216 printf("EED ColorLayerImageViewPanel::onReadImage ...WARNNING.... dif size image spc*dim ofnew image ...???\n");
217 spc[0]=_spcBase[0]*_dimBase[0]/dim[0];
218 spc[1]=_spcBase[1]*_dimBase[1]/dim[1];
222 if (typeOfTransformation==1) // make spacing equals
224 spc[0] = ( _spcBase[0]/spc[0] ) * _spcOrg[0];
225 spc[1] = ( _spcBase[1]/spc[1] ) * _spcOrg[1];
226 spc[2] = ( _spcBase[2]/spc[2] ) * _spcOrg[2];
229 if (typeOfTransformation==2) // make spacing = 1
236 img->SetSpacing(spc);
237 } // spc !_spcBase dim!__dimBase
239 if (_colorLayerImageView!=NULL)
241 _colorLayerImageView->onThreshold();
242 _colorLayerImageView->Refresh();
249 //----------------------------------------------------------------------------
250 void ColorLayerImageViewPanel::onReadImage(wxCommandEvent& event)
253 // creaImageIO::WxSimpleDlg w(0,_T("Select your image"),"creaContours_Descriptor.dscp","creatisContours DB");
255 printf("EED ColorLayerImageViewPanel::onReadImage ....WARNING... Read dlg. all images creaImageIO ... ???\n");
257 creaMaracasVisuKernel::OpenImageDialog diag = creaMaracasVisuKernel::OpenImageDialog();
258 SetImage( diag.getImageData() );
261 //----------------------------------------------------------------------------
262 void ColorLayerImageViewPanel::onThresholdChange(wxCommandEvent& event)
264 if (_colorLayerImageView!=NULL)
268 _colorLayerImageView->onThresholdChange();
269 _colorLayerImageView->Refresh();
270 //std::cout<< "Valor Min: " << minVal << " & Valor Max: " << maxVal << std::endl;
272 }//_colorLayerImageView
275 //----------------------------------------------------------------------------
276 void ColorLayerImageViewPanel::onThresholdShow(wxCommandEvent& event)
278 if (_colorLayerImageView!=NULL)
280 _thresholdGo = _cb_ShowHide->GetValue();
283 _colorLayerImageView->onThreshold();
285 _colorLayerImageView->onThresholdRemove( );
287 _colorLayerImageView->Refresh();
288 }//_colorLayerImageView
291 //----------------------------------------------------------------------------
292 void ColorLayerImageViewPanel::onThresholdStop()
294 if (_colorLayerImageView!=NULL)
298 _colorLayerImageView->onThresholdRemove( );
301 }//_colorLayerImageView
304 //----------------------------------------------------------------------------
305 void ColorLayerImageViewPanel::onThresholdInterpolation(wxCommandEvent& event)
307 if (_colorLayerImageView!=NULL)
309 _colorLayerImageView->onThresholdInterpolation(_interpolationCheckBox->GetValue());
310 _colorLayerImageView->Refresh();
311 }//_colorLayerImageView
314 //----------------------------------------------------------------------------
315 void ColorLayerImageViewPanel::onSliceFixDinamic(wxCommandEvent& event)
317 if (_colorLayerImageView!=NULL)
319 bool fixdin = _cb_SliceFixDinamic->GetValue();
320 _colorLayerImageView->SetSliceFixDinamic( fixdin );
323 _colorLayerImageView->SetZ2( _sl_SliceImage->GetValue() );
325 _sl_SliceImage->Enable(!fixdin);
326 _colorLayerImageView->onThreshold();
327 _colorLayerImageView->Refresh();
328 }//_colorLayerImageView
331 //----------------------------------------------------------------------------
332 void ColorLayerImageViewPanel::onSliceImage(wxScrollEvent& event)
334 if (_colorLayerImageView!=NULL)
336 _colorLayerImageView->SetZ2( _sl_SliceImage->GetValue() );
337 _colorLayerImageView->onThreshold();
338 _colorLayerImageView->Refresh();
339 }//_colorLayerImageView
342 //----------------------------------------------------------------------------
343 void ColorLayerImageViewPanel::onChangeOpacity(wxScrollEvent& event)
345 if (_colorLayerImageView!=NULL)
347 int opacity = _opacity->GetValue();
348 _colorLayerImageView->onThresholdChangeOpacity(opacity);
349 _colorLayerImageView->Refresh();
350 }//_colorLayerImageView
354 //----------------------------------------------------------------------------
355 bool ColorLayerImageViewPanel::IsVisible()