5 * \brief ClassThresholdImageViewPanel .
9 #include "ColorLayerImageViewPanel.h"
10 #include "OpenImageDialog.h"
13 wxDlgTransformByDimensionBySpacingByPixel::wxDlgTransformByDimensionBySpacingByPixel()
17 wxDlgTransformByDimensionBySpacingByPixel::~wxDlgTransformByDimensionBySpacingByPixel()
22 void wxDlgTransformByDimensionBySpacingByPixel::GetTransformType(wxWindow *parent , wxString message,int &typeOfTransformation,bool &dlgWxOK)
24 wxDialog* dial = new wxDialog (parent,-1,_T("Tools"),wxDefaultPosition, wxSize(590,190));
25 wxSizer* buttonsSizer = dial->CreateSeparatedButtonSizer(wxOK|wxCANCEL);
26 wxBoxSizer *dialSizer = new wxBoxSizer(wxVERTICAL);
28 wxString lstOptOperation[3];
29 lstOptOperation[0]=_T("By Dimension");
30 lstOptOperation[1]=_T("By Spacing");
31 lstOptOperation[2]=_T("By Pixel");
32 wxRadioBox * radioOpts = new wxRadioBox(dial, -1, _T("Type of Transformation"), wxDefaultPosition, wxSize(270,45), 3 , lstOptOperation, 3, wxRA_SPECIFY_COLS);
34 dialSizer->Add( new wxStaticText(dial,-1,message) , 0, wxGROW );
35 // dialSizer->Add( new wxStaticText(dial,-1,_T("selected Roi file. Do you want to tranform it?")) , 0, wxGROW );
36 dialSizer->Add( new wxStaticText(dial,-1,_T(" ")) , 0, wxGROW );
37 dialSizer->Add(radioOpts,0,wxGROW);
38 dialSizer->Add( new wxStaticText(dial,-1,_T(" ")) , 0, wxGROW );
39 dialSizer->Add(buttonsSizer,0,wxGROW);
40 dial->SetSizer(dialSizer, true);
44 typeOfTransformation = -1;
47 if (dial->GetReturnCode() == wxID_OK)
49 typeOfTransformation = radioOpts->GetSelection();
54 //---------------------------------------------------------
59 ** Begin of the threshold panel
61 ColorLayerImageViewPanel::ColorLayerImageViewPanel(wxWindow* parent, int min, int max, int type)
62 : wxPanel(parent, -1, wxDefaultPosition, wxDefaultSize, wxBORDER_SUNKEN)
64 _spcBase[0] = _spcBase[1] = _spcBase[2] = 0;
65 _dimBase[0] = _dimBase[1] = _dimBase[2] = 0;
67 _colorLayerImageView = new ColorLayerImageView();
68 _btn_ReadImage = new wxButton(this, wxID_ANY, _T("Read Image") );
70 _cb_ShowHide = new wxCheckBox(this, wxID_ANY, _T("Show/Hide layer") );
71 _cb_ShowHide->SetValue(_thresholdGo);
73 _cb_SliceFixDinamic = new wxCheckBox(this, wxID_ANY, _T("Slice Fix/Dinamic") );
74 _cb_SliceFixDinamic->SetValue(true);
76 _sl_SliceImage = new wxSlider(this, wxID_ANY, 0, 1000, 1000, wxDefaultPosition, wxDefaultSize, wxSL_HORIZONTAL|wxSL_LABELS, wxDefaultValidator);
77 _sl_SliceImage->Enable(false);
79 _interpolationCheckBox = new wxCheckBox(this, -1, _T("Image interpolation") );
80 _interpolationCheckBox->SetValue(true);
81 _opacity = new wxSlider(this, wxID_ANY, 6, 1, 10, wxDefaultPosition, wxDefaultSize, wxSL_HORIZONTAL|wxSL_LABELS, wxDefaultValidator);
92 Connect( _btn_ReadImage->GetId(), wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &ColorLayerImageViewPanel::onReadImage );
93 Connect( _cb_ShowHide->GetId(), wxEVT_COMMAND_CHECKBOX_CLICKED , (wxObjectEventFunction) &ColorLayerImageViewPanel::onThresholdShow );
94 Connect( _interpolationCheckBox->GetId(), wxEVT_COMMAND_CHECKBOX_CLICKED, (wxObjectEventFunction) &ColorLayerImageViewPanel::onThresholdInterpolation );
95 Connect( _opacity->GetId(), wxEVT_SCROLL_THUMBTRACK, (wxObjectEventFunction) &ColorLayerImageViewPanel::onChangeOpacity );
96 Connect( _cb_SliceFixDinamic->GetId(), wxEVT_COMMAND_CHECKBOX_CLICKED, (wxObjectEventFunction) &ColorLayerImageViewPanel::onSliceFixDinamic );
97 Connect( _sl_SliceImage->GetId(), wxEVT_SCROLL_THUMBTRACK , (wxObjectEventFunction) &ColorLayerImageViewPanel::onSliceImage );
98 Connect( _sl_SliceImage->GetId(), wxEVT_SCROLL_LINEUP , (wxObjectEventFunction) &ColorLayerImageViewPanel::onSliceImage );
99 Connect( _sl_SliceImage->GetId(), wxEVT_SCROLL_LINEDOWN , (wxObjectEventFunction) &ColorLayerImageViewPanel::onSliceImage );
100 Connect( _sl_SliceImage->GetId(), wxEVT_SCROLL_PAGEUP , (wxObjectEventFunction) &ColorLayerImageViewPanel::onSliceImage );
101 Connect( _sl_SliceImage->GetId(), wxEVT_SCROLL_PAGEDOWN , (wxObjectEventFunction) &ColorLayerImageViewPanel::onSliceImage );
104 wxFlexGridSizer * sizer = new wxFlexGridSizer(1);
107 sizer -> Add( new wxStaticText(this,-1,_T("Color Image Layer")) , 1, wxGROW );
108 sizer -> Add( _btn_ReadImage, 1, wxGROW );
109 sizer -> Add( new wxStaticText(this,-1,_T(" ")) , 1, wxGROW );
111 sizer -> Add( new wxStaticText(this,-1,_T("Opacity Level")) , 1, wxGROW );
112 sizer -> Add( _opacity, 1, wxGROW );
113 sizer -> Add( new wxStaticText(this,-1,_T(" ")) , 1, wxGROW );
114 sizer -> Add( _cb_ShowHide, 1, wxGROW );
115 sizer -> Add( new wxStaticText(this,-1,_T(" ")) , 1, wxGROW );
116 sizer -> Add( _interpolationCheckBox, 1, wxGROW );
118 sizer -> Add( new wxStaticText(this,-1,_T(" ")) , 1, wxGROW );
119 sizer -> Add( new wxStaticText(this,-1,_T("Slice ")) , 1, wxGROW );
120 sizer -> Add( _sl_SliceImage, 1, wxGROW );
121 sizer -> Add( _cb_SliceFixDinamic, 1, wxGROW );
123 this->SetSizer( sizer );
124 this->SetAutoLayout( true );
128 //----------------------------------------------------------------------------
129 ColorLayerImageViewPanel::~ColorLayerImageViewPanel()
134 //----------------------------------------------------------------------------
135 void ColorLayerImageViewPanel::SetColorLayerImageView(ColorLayerImageView* colorLayerImageView)
137 _colorLayerImageView = colorLayerImageView;
140 //----------------------------------------------------------------------------
141 ColorLayerImageView* ColorLayerImageViewPanel::GetColorLayerImageView()
143 return _colorLayerImageView;
147 // This is the new spacing of the background image (1,1,1)
148 void ColorLayerImageViewPanel::SetBaseSpacing(double spc[3])
150 _spcBase[0] = spc[0];
151 _spcBase[1] = spc[1];
152 _spcBase[2] = spc[2];
159 // This is the Original spacing of the background image
160 void ColorLayerImageViewPanel::SetOriginalSpacing(double spc[3])
167 // This is the size in pixels of the background image
168 void ColorLayerImageViewPanel::SetBaseDimension(int dim[3])
170 _dimBase[0] = dim[0];
171 _dimBase[1] = dim[1];
172 _dimBase[2] = dim[2];
175 //----------------------------------------------------------------------------
176 void ColorLayerImageViewPanel::SetImage(vtkImageData *img)
180 _colorLayerImageView->SetImage( img );
183 img->GetSpacing(spc);
187 img->GetWholeExtent(ext);
188 dim[0] = ext[1]-ext[0];
189 dim[1] = ext[3]-ext[2];
190 dim[2] = ext[5]-ext[4];
191 _sl_SliceImage->SetRange( 0 , dim[2] );
193 if ( (spc[0]!=_spcBase[0]) || (spc[1]!=_spcBase[1]) || (spc[2]!=_spcBase[2]) ||
194 (dim[0]!=_dimBase[0]) || (spc[1]!=_spcBase[1]) || (spc[2]!=_spcBase[2])
199 int typeOfTransformation;
200 wxString msg = _T("The image resolution of both images are not compatible. Do you want to tranform it? ");
201 wxDlgTransformByDimensionBySpacingByPixel dlg;
202 dlg.GetTransformType(this,msg,typeOfTransformation,transformOkDlg);
204 printf("EED ColorLayerImageViewPanel::onReadImage call dialog spc size,dim...???\n");
206 if (typeOfTransformation==0) // make dimensions equals
208 printf("EED ColorLayerImageViewPanel::onReadImage ...WARNNING.... dif size image spc*dim ofnew image ...???\n");
209 spc[0]=_spcBase[0]*_dimBase[0]/dim[0];
210 spc[1]=_spcBase[1]*_dimBase[1]/dim[1];
214 if (typeOfTransformation==1) // make spacing equals
216 spc[0] = ( _spcBase[0]/spc[0] ) * _spcOrg[0];
217 spc[1] = ( _spcBase[1]/spc[1] ) * _spcOrg[1];
218 spc[2] = ( _spcBase[2]/spc[2] ) * _spcOrg[2];
221 if (typeOfTransformation==2) // make spacing = 1
228 img->SetSpacing(spc);
229 } // spc !_spcBase dim!__dimBase
231 if (_colorLayerImageView!=NULL)
233 _colorLayerImageView->onThreshold();
234 _colorLayerImageView->Refresh();
241 //----------------------------------------------------------------------------
242 void ColorLayerImageViewPanel::onReadImage(wxCommandEvent& event)
245 // creaImageIO::WxSimpleDlg w(0,_T("Select your image"),"creaContours_Descriptor.dscp","creatisContours DB");
247 printf("EED ColorLayerImageViewPanel::onReadImage ....WARNING... Read dlg. all images creaImageIO ... ???\n");
249 creaMaracasVisuKernel::OpenImageDialog diag = creaMaracasVisuKernel::OpenImageDialog();
250 SetImage( diag.getImageData() );
253 //----------------------------------------------------------------------------
254 void ColorLayerImageViewPanel::onThresholdChange(wxCommandEvent& event)
256 if (_colorLayerImageView!=NULL)
260 _colorLayerImageView->onThresholdChange();
261 _colorLayerImageView->Refresh();
262 //std::cout<< "Valor Min: " << minVal << " & Valor Max: " << maxVal << std::endl;
264 }//_colorLayerImageView
267 //----------------------------------------------------------------------------
268 void ColorLayerImageViewPanel::onThresholdShow(wxCommandEvent& event)
270 if (_colorLayerImageView!=NULL)
272 _thresholdGo = _cb_ShowHide->GetValue();
275 _colorLayerImageView->onThreshold();
277 _colorLayerImageView->onThresholdRemove( );
279 _colorLayerImageView->Refresh();
280 }//_colorLayerImageView
283 //----------------------------------------------------------------------------
284 void ColorLayerImageViewPanel::onThresholdStop()
286 if (_colorLayerImageView!=NULL)
290 _colorLayerImageView->onThresholdRemove( );
293 }//_colorLayerImageView
296 //----------------------------------------------------------------------------
297 void ColorLayerImageViewPanel::onThresholdInterpolation(wxCommandEvent& event)
299 if (_colorLayerImageView!=NULL)
301 _colorLayerImageView->onThresholdInterpolation(_interpolationCheckBox->GetValue());
302 _colorLayerImageView->Refresh();
303 }//_colorLayerImageView
306 //----------------------------------------------------------------------------
307 void ColorLayerImageViewPanel::onSliceFixDinamic(wxCommandEvent& event)
309 if (_colorLayerImageView!=NULL)
311 bool fixdin = _cb_SliceFixDinamic->GetValue();
312 _colorLayerImageView->SetSliceFixDinamic( fixdin );
315 _colorLayerImageView->SetZ2( _sl_SliceImage->GetValue() );
317 _sl_SliceImage->Enable(!fixdin);
318 _colorLayerImageView->onThreshold();
319 _colorLayerImageView->Refresh();
320 }//_colorLayerImageView
323 //----------------------------------------------------------------------------
324 void ColorLayerImageViewPanel::onSliceImage(wxScrollEvent& event)
326 if (_colorLayerImageView!=NULL)
328 _colorLayerImageView->SetZ2( _sl_SliceImage->GetValue() );
329 _colorLayerImageView->onThreshold();
330 _colorLayerImageView->Refresh();
331 }//_colorLayerImageView
334 //----------------------------------------------------------------------------
335 void ColorLayerImageViewPanel::onChangeOpacity(wxScrollEvent& event)
337 if (_colorLayerImageView!=NULL)
339 int opacity = _opacity->GetValue();
340 _colorLayerImageView->onThresholdChangeOpacity(opacity);
341 _colorLayerImageView->Refresh();
342 }//_colorLayerImageView
346 //----------------------------------------------------------------------------
347 bool ColorLayerImageViewPanel::IsVisible()