]> Creatis software - creaMaracasVisu.git/blob - lib/maracasVisuLib/src/interface/wxWindows/widgets/ThresholdImageView/ColorLayerImageViewPanel.cxx
*** empty log message ***
[creaMaracasVisu.git] / lib / maracasVisuLib / src / interface / wxWindows / widgets / ThresholdImageView / ColorLayerImageViewPanel.cxx
1
2
3 /**
4  *  \file
5  *  \brief ClassThresholdImageViewPanel .
6  */
7
8
9 #include "ColorLayerImageViewPanel.h"
10 #include "OpenImageDialog.h"
11
12
13 wxDlgTransformByDimensionBySpacingByPixel::wxDlgTransformByDimensionBySpacingByPixel()
14 {
15 }
16
17 wxDlgTransformByDimensionBySpacingByPixel::~wxDlgTransformByDimensionBySpacingByPixel()
18 {
19 }
20
21
22 void wxDlgTransformByDimensionBySpacingByPixel::GetTransformType(wxWindow *parent , wxString message,int &typeOfTransformation,bool &dlgWxOK)
23 {
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);
27
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);
33
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);
41         dial->Layout();
42         dial->ShowModal();
43
44         typeOfTransformation    = -1;
45         dlgWxOK                                 = false;
46
47         if (dial->GetReturnCode() == wxID_OK)
48         {
49                 typeOfTransformation    = radioOpts->GetSelection();
50                 dlgWxOK                         = true;
51         }
52 }
53
54 //---------------------------------------------------------
55
56
57
58 /**
59  ** Begin of the threshold panel
60  **/
61 ColorLayerImageViewPanel::ColorLayerImageViewPanel(wxWindow* parent, int min, int max, int type)
62 : wxPanel(parent, -1, wxDefaultPosition, wxDefaultSize, wxBORDER_SUNKEN)
63 {
64         _spcBase[0] = _spcBase[1] = _spcBase[2] = 0;
65         _dimBase[0] = _dimBase[1] = _dimBase[2] = 0;
66
67         _colorLayerImageView    = new ColorLayerImageView();
68         _btn_ReadImage                  = new wxButton(this, wxID_ANY, _T("Read Image") );
69         _thresholdGo                    = true;
70         _cb_ShowHide                    = new wxCheckBox(this, wxID_ANY, _T("Show/Hide layer") );
71         _cb_ShowHide->SetValue(_thresholdGo);
72
73         _cb_SliceFixDinamic = new wxCheckBox(this, wxID_ANY, _T("Slice Fix/Dinamic") );
74         _cb_SliceFixDinamic->SetValue(true);
75
76         _sl_SliceImage = new wxSlider(this, wxID_ANY, 0, 1000, 1000, wxDefaultPosition, wxDefaultSize, wxSL_HORIZONTAL|wxSL_LABELS, wxDefaultValidator);
77         _sl_SliceImage->Enable(false);
78
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);
82
83         if (type==0)
84         {
85         }
86
87         if (type==1)
88         {
89         }
90
91
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 );
102
103
104         wxFlexGridSizer * sizer         = new wxFlexGridSizer(1);
105         if (type==1)
106         {
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 );
110         }
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 );
117
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 );
122
123         this->SetSizer( sizer );
124         this->SetAutoLayout( true );
125         this->Layout();
126 }
127
128 //----------------------------------------------------------------------------
129 ColorLayerImageViewPanel::~ColorLayerImageViewPanel()
130 {
131 }
132
133
134 //----------------------------------------------------------------------------
135 void ColorLayerImageViewPanel::SetColorLayerImageView(ColorLayerImageView* colorLayerImageView)
136 {
137         _colorLayerImageView = colorLayerImageView;
138 }
139
140 //----------------------------------------------------------------------------
141 ColorLayerImageView* ColorLayerImageViewPanel::GetColorLayerImageView()
142 {
143         return _colorLayerImageView;
144 }
145
146
147 // This is the new spacing of the background image  (1,1,1)
148 void ColorLayerImageViewPanel::SetBaseSpacing(double spc[3])
149 {
150         _spcBase[0] = spc[0];
151         _spcBase[1] = spc[1];
152         _spcBase[2] = spc[2];
153
154         _spcBase[0] = 1;
155         _spcBase[1] = 1;
156         _spcBase[2] = 1;
157 }
158
159 // This is the Original spacing of the background image
160 void ColorLayerImageViewPanel::SetOriginalSpacing(double spc[3])
161 {
162         _spcOrg[0] = spc[0];
163         _spcOrg[1] = spc[1];
164         _spcOrg[2] = spc[2];
165 }
166
167 // This is the size in pixels of the background image
168 void ColorLayerImageViewPanel::SetBaseDimension(int dim[3])
169 {
170         _dimBase[0] = dim[0];
171         _dimBase[1] = dim[1];
172         _dimBase[2] = dim[2];
173 }
174
175 //----------------------------------------------------------------------------
176 void ColorLayerImageViewPanel::onReadImage(wxCommandEvent& event)
177 {
178 // EED ???
179 //      creaImageIO::WxSimpleDlg w(0,_T("Select your image"),"creaContours_Descriptor.dscp","creatisContours DB");
180 //      w.ShowModal();
181         printf("EED ColorLayerImageViewPanel::onReadImage ....WARNING... Read dlg. all images creaImageIO ... ???\n");
182
183         creaMaracasVisuKernel::OpenImageDialog diag = creaMaracasVisuKernel::OpenImageDialog();
184         _colorLayerImageView->SetImage( diag.getImageData() );
185
186         double spc[3];
187         diag.getImageData()->GetSpacing(spc);
188
189         int dim[3];
190         int ext[6];
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] );
196
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])
199                 )
200         {
201
202                 bool transformOkDlg;
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);
207
208 printf("EED ColorLayerImageViewPanel::onReadImage call dialog spc size,dim...???\n");
209
210                 if (typeOfTransformation==0)  // make dimensions equals
211                 {
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];
215                         spc[2] = 1;
216                 }
217
218                 if (typeOfTransformation==1)  // make spacing equals
219                 {
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];
223                 }
224
225                 if (typeOfTransformation==2)  // make spacing = 1
226                 {
227                         spc[0] = 1;
228                         spc[1] = 1;
229                         spc[2] = 1;
230                 }
231
232                 diag.getImageData()->SetSpacing(spc);
233         } // spc !_spcBase   dim!__dimBase
234
235         if (_colorLayerImageView!=NULL)
236         {
237         _colorLayerImageView->onThreshold();
238         _colorLayerImageView->Refresh();
239         }
240 }
241
242 //----------------------------------------------------------------------------
243 void ColorLayerImageViewPanel::onThresholdChange(wxCommandEvent& event)
244 {
245         if (_colorLayerImageView!=NULL)
246         {
247         if (_thresholdGo)
248         {
249             _colorLayerImageView->onThresholdChange();
250             _colorLayerImageView->Refresh();
251             //std::cout<< "Valor Min: " << minVal << " & Valor Max: " << maxVal  << std::endl;
252         } // _threshold
253         }//_colorLayerImageView
254 }
255
256 //----------------------------------------------------------------------------
257 void ColorLayerImageViewPanel::onThresholdShow(wxCommandEvent& event)
258 {
259         if (_colorLayerImageView!=NULL)
260         {
261         _thresholdGo = _cb_ShowHide->GetValue();
262         if (_thresholdGo)
263         {
264             _colorLayerImageView->onThreshold();
265         }else{
266             _colorLayerImageView->onThresholdRemove( );
267         }
268         _colorLayerImageView->Refresh();
269         }//_colorLayerImageView
270 }
271
272 //----------------------------------------------------------------------------
273 void ColorLayerImageViewPanel::onThresholdStop()
274 {
275         if (_colorLayerImageView!=NULL)
276         {
277         if (_thresholdGo)
278         {
279             _colorLayerImageView->onThresholdRemove( );
280             _thresholdGo=false;
281         }
282         }//_colorLayerImageView
283 }
284
285 //----------------------------------------------------------------------------
286 void ColorLayerImageViewPanel::onThresholdInterpolation(wxCommandEvent& event)
287 {
288         if (_colorLayerImageView!=NULL)
289         {
290         _colorLayerImageView->onThresholdInterpolation(_interpolationCheckBox->GetValue());
291         _colorLayerImageView->Refresh();
292         }//_colorLayerImageView
293 }
294
295 //----------------------------------------------------------------------------
296 void ColorLayerImageViewPanel::onSliceFixDinamic(wxCommandEvent& event)
297 {
298         if (_colorLayerImageView!=NULL)
299         {
300         bool fixdin = _cb_SliceFixDinamic->GetValue();
301         _colorLayerImageView->SetSliceFixDinamic( fixdin );
302         if (fixdin==false)
303         {
304             _colorLayerImageView->SetZ2( _sl_SliceImage->GetValue() );
305         }
306         _sl_SliceImage->Enable(!fixdin);
307         _colorLayerImageView->onThreshold();
308         _colorLayerImageView->Refresh();
309         }//_colorLayerImageView
310 }
311
312 //----------------------------------------------------------------------------
313 void ColorLayerImageViewPanel::onSliceImage(wxScrollEvent& event)
314 {
315         if (_colorLayerImageView!=NULL)
316         {
317         _colorLayerImageView->SetZ2( _sl_SliceImage->GetValue() );
318         _colorLayerImageView->onThreshold();
319         _colorLayerImageView->Refresh();
320         }//_colorLayerImageView
321 }
322
323 //----------------------------------------------------------------------------
324 void ColorLayerImageViewPanel::onChangeOpacity(wxScrollEvent& event)
325 {
326         if (_colorLayerImageView!=NULL)
327         {
328         int opacity = _opacity->GetValue();
329         _colorLayerImageView->onThresholdChangeOpacity(opacity);
330         _colorLayerImageView->Refresh();
331         }//_colorLayerImageView
332 }
333
334
335 //----------------------------------------------------------------------------
336 bool ColorLayerImageViewPanel::IsVisible()
337 {
338         return _thresholdGo;
339 }
340
341
342
343 // EOF
344