]> Creatis software - creaMaracasVisu.git/blob - lib/maracasVisuLib/src/interface/wxWindows/widgets/ThresholdImageView/ColorLayerImageViewPanel.cxx
Documentation panel on the right of bbEditor as a menu option, for lake of use.
[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 //---------------------------------------------------------
14 //---------------------------------------------------------
15 //---------------------------------------------------------
16
17 wxDlgTransformByDimensionBySpacingByPixel::wxDlgTransformByDimensionBySpacingByPixel()
18 {
19 }
20
21 wxDlgTransformByDimensionBySpacingByPixel::~wxDlgTransformByDimensionBySpacingByPixel()
22 {
23 }
24
25
26 void wxDlgTransformByDimensionBySpacingByPixel::GetTransformType(wxWindow *parent , wxString message,int &typeOfTransformation,bool &dlgWxOK)
27 {
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);
31
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);
37
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);
45         dial->Layout();
46         dial->ShowModal();
47
48         typeOfTransformation    = -1;
49         dlgWxOK                                 = false;
50
51         if (dial->GetReturnCode() == wxID_OK)
52         {
53                 typeOfTransformation    = radioOpts->GetSelection();
54                 dlgWxOK                         = true;
55         }
56 }
57
58
59 //---------------------------------------------------------
60 //---------------------------------------------------------
61 //---------------------------------------------------------
62
63
64 /**
65  ** Begin of the threshold panel
66  **/
67 ColorLayerImageViewPanel::ColorLayerImageViewPanel(wxWindow* parent, int min, int max, int type)
68 : wxPanel(parent, -1, wxDefaultPosition, wxDefaultSize, wxBORDER_SUNKEN)
69 {
70         printf("EED ColorLayerImageViewPanel::ColorLayerImageViewPanel start \n");
71
72         _spcBase[0] = _spcBase[1] = _spcBase[2] = 0;
73         _dimBase[0] = _dimBase[1] = _dimBase[2] = 0;
74
75         _colorLayerImageView            = new ColorLayerImageView();
76         _btn_ReadImage                  = new wxButton(this, wxID_ANY, _T("Read Image") );
77         _thresholdGo                    = true;
78         _cb_ShowHide                    = new wxCheckBox(this, wxID_ANY, _T("Show/Hide layer") );
79         _cb_ShowHide->SetValue(_thresholdGo);
80
81         _cb_SliceFixDinamic = new wxCheckBox(this, wxID_ANY, _T("Slice Fix/Dinamic") );
82         _cb_SliceFixDinamic->SetValue(true);
83
84         _sl_SliceImage = new wxSlider(this, wxID_ANY, 0, 1000, 1000, wxDefaultPosition, wxDefaultSize, wxSL_HORIZONTAL|wxSL_LABELS, wxDefaultValidator);
85         _sl_SliceImage->Enable(false);
86
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);
90
91         if (type==0)
92         {
93         }
94
95         if (type==1)
96         {
97         }
98
99
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 );
110
111
112         wxFlexGridSizer * sizer         = new wxFlexGridSizer(1);
113         if (type==1)
114         {
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 );
118         }
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 );
125
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 );
130
131         this->SetSizer( sizer );
132         this->SetAutoLayout( true );
133         this->Layout();
134 }
135
136 //----------------------------------------------------------------------------
137 ColorLayerImageViewPanel::~ColorLayerImageViewPanel()
138 {
139 }
140
141
142 //----------------------------------------------------------------------------
143 void ColorLayerImageViewPanel::SetColorLayerImageView(ColorLayerImageView* colorLayerImageView)
144 {
145         _colorLayerImageView = colorLayerImageView;
146 }
147
148 //----------------------------------------------------------------------------
149 ColorLayerImageView* ColorLayerImageViewPanel::GetColorLayerImageView()
150 {
151         return _colorLayerImageView;
152 }
153
154
155 // This is the new spacing of the background image  (1,1,1)
156 void ColorLayerImageViewPanel::SetBaseSpacing(double spc[3])
157 {
158         _spcBase[0] = spc[0];
159         _spcBase[1] = spc[1];
160         _spcBase[2] = spc[2];
161
162         _spcBase[0] = 1;
163         _spcBase[1] = 1;
164         _spcBase[2] = 1;
165 }
166
167 // This is the Original spacing of the background image
168 void ColorLayerImageViewPanel::SetOriginalSpacing(double spc[3])
169 {
170         _spcOrg[0] = spc[0];
171         _spcOrg[1] = spc[1];
172         _spcOrg[2] = spc[2];
173 }
174
175 // This is the size in pixels of the background image
176 void ColorLayerImageViewPanel::SetBaseDimension(int dim[3])
177 {
178         _dimBase[0] = dim[0];
179         _dimBase[1] = dim[1];
180         _dimBase[2] = dim[2];
181 }
182
183 //----------------------------------------------------------------------------
184 void ColorLayerImageViewPanel::SetImage(vtkImageData *img)
185 {
186     if (img!=NULL)
187     {
188         _colorLayerImageView->SetImage( img );
189
190         double spc[3];
191         img->GetSpacing(spc);
192
193         int dim[3];
194         int ext[6];
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] );
200
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])
203             )
204         {
205
206             bool transformOkDlg;
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);
211
212     printf("EED ColorLayerImageViewPanel::onReadImage call dialog spc size,dim...???\n");
213
214             if (typeOfTransformation==0)  // make dimensions equals
215             {
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];
219                 spc[2] = 1;
220             }
221
222             if (typeOfTransformation==1)  // make spacing equals
223             {
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];
227             }
228
229             if (typeOfTransformation==2)  // make spacing = 1
230             {
231                 spc[0] = 1;
232                 spc[1] = 1;
233                 spc[2] = 1;
234             }
235
236             img->SetSpacing(spc);
237         } // spc !_spcBase   dim!__dimBase
238
239         if (_colorLayerImageView!=NULL)
240         {
241             _colorLayerImageView->onThreshold();
242             _colorLayerImageView->Refresh();
243         }
244
245
246     }
247 }
248
249 //----------------------------------------------------------------------------
250 void ColorLayerImageViewPanel::onReadImage(wxCommandEvent& event)
251 {
252 // EED ???
253 //      creaImageIO::WxSimpleDlg w(0,_T("Select your image"),"creaContours_Descriptor.dscp","creatisContours DB");
254 //      w.ShowModal();
255         printf("EED ColorLayerImageViewPanel::onReadImage ....WARNING... Read dlg. all images creaImageIO ... ???\n");
256
257         creaMaracasVisuKernel::OpenImageDialog diag = creaMaracasVisuKernel::OpenImageDialog();
258         SetImage( diag.getImageData() );
259 }
260
261 //----------------------------------------------------------------------------
262 void ColorLayerImageViewPanel::onThresholdChange(wxCommandEvent& event)
263 {
264         if (_colorLayerImageView!=NULL)
265         {
266         if (_thresholdGo)
267         {
268             _colorLayerImageView->onThresholdChange();
269             _colorLayerImageView->Refresh();
270             //std::cout<< "Valor Min: " << minVal << " & Valor Max: " << maxVal  << std::endl;
271         } // _threshold
272         }//_colorLayerImageView
273 }
274
275 //----------------------------------------------------------------------------
276 void ColorLayerImageViewPanel::onThresholdShow(wxCommandEvent& event)
277 {
278         if (_colorLayerImageView!=NULL)
279         {
280         _thresholdGo = _cb_ShowHide->GetValue();
281         if (_thresholdGo)
282         {
283             _colorLayerImageView->onThreshold();
284         }else{
285             _colorLayerImageView->onThresholdRemove( );
286         }
287         _colorLayerImageView->Refresh();
288         }//_colorLayerImageView
289 }
290
291 //----------------------------------------------------------------------------
292 void ColorLayerImageViewPanel::onThresholdStop()
293 {
294         if (_colorLayerImageView!=NULL)
295         {
296         if (_thresholdGo)
297         {
298             _colorLayerImageView->onThresholdRemove( );
299             _thresholdGo=false;
300         }
301         }//_colorLayerImageView
302 }
303
304 //----------------------------------------------------------------------------
305 void ColorLayerImageViewPanel::onThresholdInterpolation(wxCommandEvent& event)
306 {
307         if (_colorLayerImageView!=NULL)
308         {
309         _colorLayerImageView->onThresholdInterpolation(_interpolationCheckBox->GetValue());
310         _colorLayerImageView->Refresh();
311         }//_colorLayerImageView
312 }
313
314 //----------------------------------------------------------------------------
315 void ColorLayerImageViewPanel::onSliceFixDinamic(wxCommandEvent& event)
316 {
317         if (_colorLayerImageView!=NULL)
318         {
319         bool fixdin = _cb_SliceFixDinamic->GetValue();
320         _colorLayerImageView->SetSliceFixDinamic( fixdin );
321         if (fixdin==false)
322         {
323             _colorLayerImageView->SetZ2( _sl_SliceImage->GetValue() );
324         }
325         _sl_SliceImage->Enable(!fixdin);
326         _colorLayerImageView->onThreshold();
327         _colorLayerImageView->Refresh();
328         }//_colorLayerImageView
329 }
330
331 //----------------------------------------------------------------------------
332 void ColorLayerImageViewPanel::onSliceImage(wxScrollEvent& event)
333 {
334         if (_colorLayerImageView!=NULL)
335         {
336         _colorLayerImageView->SetZ2( _sl_SliceImage->GetValue() );
337         _colorLayerImageView->onThreshold();
338         _colorLayerImageView->Refresh();
339         }//_colorLayerImageView
340 }
341
342 //----------------------------------------------------------------------------
343 void ColorLayerImageViewPanel::onChangeOpacity(wxScrollEvent& event)
344 {
345         if (_colorLayerImageView!=NULL)
346         {
347         int opacity = _opacity->GetValue();
348         _colorLayerImageView->onThresholdChangeOpacity(opacity);
349         _colorLayerImageView->Refresh();
350         }//_colorLayerImageView
351 }
352
353
354 //----------------------------------------------------------------------------
355 bool ColorLayerImageViewPanel::IsVisible()
356 {
357         return _thresholdGo;
358 }
359
360
361
362 // EOF
363