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::onReadImage(wxCommandEvent& event)
179 // creaImageIO::WxSimpleDlg w(0,_T("Select your image"),"creaContours_Descriptor.dscp","creatisContours DB");
181 printf("EED ColorLayerImageViewPanel::onReadImage ....WARNING... Read dlg. all images creaImageIO ... ???\n");
183 creaMaracasVisuKernel::OpenImageDialog diag = creaMaracasVisuKernel::OpenImageDialog();
184 _colorLayerImageView->SetImage( diag.getImageData() );
187 diag.getImageData()->GetSpacing(spc);
191 diag.getImageData()->GetWholeExtent(ext);
192 dim[0] = ext[1]-ext[0];
193 dim[1] = ext[3]-ext[2];
194 dim[2] = ext[5]-ext[4];
195 _sl_SliceImage->SetRange( 0 , dim[2] );
197 if ( (spc[0]!=_spcBase[0]) || (spc[1]!=_spcBase[1]) || (spc[2]!=_spcBase[2]) ||
198 (dim[0]!=_dimBase[0]) || (spc[1]!=_spcBase[1]) || (spc[2]!=_spcBase[2])
203 int typeOfTransformation;
204 wxString msg = _T("The image resolution of both images are not compatible. Do you want to tranform it? ");
205 wxDlgTransformByDimensionBySpacingByPixel dlg;
206 dlg.GetTransformType(this,msg,typeOfTransformation,transformOkDlg);
208 printf("EED ColorLayerImageViewPanel::onReadImage call dialog spc size,dim...???\n");
210 if (typeOfTransformation==0) // make dimensions equals
212 printf("EED ColorLayerImageViewPanel::onReadImage ...WARNNING.... dif size image spc*dim ofnew image ...???\n");
213 spc[0]=_spcBase[0]*_dimBase[0]/dim[0];
214 spc[1]=_spcBase[1]*_dimBase[1]/dim[1];
218 if (typeOfTransformation==1) // make spacing equals
220 spc[0] = ( _spcBase[0]/spc[0] ) * _spcOrg[0];
221 spc[1] = ( _spcBase[1]/spc[1] ) * _spcOrg[1];
222 spc[2] = ( _spcBase[2]/spc[2] ) * _spcOrg[2];
225 if (typeOfTransformation==2) // make spacing = 1
232 diag.getImageData()->SetSpacing(spc);
233 } // spc !_spcBase dim!__dimBase
235 if (_colorLayerImageView!=NULL)
237 _colorLayerImageView->onThreshold();
238 _colorLayerImageView->Refresh();
242 //----------------------------------------------------------------------------
243 void ColorLayerImageViewPanel::onThresholdChange(wxCommandEvent& event)
245 if (_colorLayerImageView!=NULL)
249 _colorLayerImageView->onThresholdChange();
250 _colorLayerImageView->Refresh();
251 //std::cout<< "Valor Min: " << minVal << " & Valor Max: " << maxVal << std::endl;
253 }//_colorLayerImageView
256 //----------------------------------------------------------------------------
257 void ColorLayerImageViewPanel::onThresholdShow(wxCommandEvent& event)
259 if (_colorLayerImageView!=NULL)
261 _thresholdGo = _cb_ShowHide->GetValue();
264 _colorLayerImageView->onThreshold();
266 _colorLayerImageView->onThresholdRemove( );
268 _colorLayerImageView->Refresh();
269 }//_colorLayerImageView
272 //----------------------------------------------------------------------------
273 void ColorLayerImageViewPanel::onThresholdStop()
275 if (_colorLayerImageView!=NULL)
279 _colorLayerImageView->onThresholdRemove( );
282 }//_colorLayerImageView
285 //----------------------------------------------------------------------------
286 void ColorLayerImageViewPanel::onThresholdInterpolation(wxCommandEvent& event)
288 if (_colorLayerImageView!=NULL)
290 _colorLayerImageView->onThresholdInterpolation(_interpolationCheckBox->GetValue());
291 _colorLayerImageView->Refresh();
292 }//_colorLayerImageView
295 //----------------------------------------------------------------------------
296 void ColorLayerImageViewPanel::onSliceFixDinamic(wxCommandEvent& event)
298 if (_colorLayerImageView!=NULL)
300 bool fixdin = _cb_SliceFixDinamic->GetValue();
301 _colorLayerImageView->SetSliceFixDinamic( fixdin );
304 _colorLayerImageView->SetZ2( _sl_SliceImage->GetValue() );
306 _sl_SliceImage->Enable(!fixdin);
307 _colorLayerImageView->onThreshold();
308 _colorLayerImageView->Refresh();
309 }//_colorLayerImageView
312 //----------------------------------------------------------------------------
313 void ColorLayerImageViewPanel::onSliceImage(wxScrollEvent& event)
315 if (_colorLayerImageView!=NULL)
317 _colorLayerImageView->SetZ2( _sl_SliceImage->GetValue() );
318 _colorLayerImageView->onThreshold();
319 _colorLayerImageView->Refresh();
320 }//_colorLayerImageView
323 //----------------------------------------------------------------------------
324 void ColorLayerImageViewPanel::onChangeOpacity(wxScrollEvent& event)
326 if (_colorLayerImageView!=NULL)
328 int opacity = _opacity->GetValue();
329 _colorLayerImageView->onThresholdChangeOpacity(opacity);
330 _colorLayerImageView->Refresh();
331 }//_colorLayerImageView
335 //----------------------------------------------------------------------------
336 bool ColorLayerImageViewPanel::IsVisible()