]> 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 //---------------------------------------------------------
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         _spcBase[0] = _spcBase[1] = _spcBase[2] = 0;
71         _dimBase[0] = _dimBase[1] = _dimBase[2] = 0;
72
73         _colorLayerImageView    = new ColorLayerImageView();
74         _btn_ReadImage                  = new wxButton(this, wxID_ANY, _T("Read Image") );
75         _thresholdGo                    = true;
76         _cb_ShowHide                    = new wxCheckBox(this, wxID_ANY, _T("Show/Hide layer") );
77         _cb_ShowHide->SetValue(_thresholdGo);
78
79         _cb_SliceFixDinamic = new wxCheckBox(this, wxID_ANY, _T("Slice Fix/Dinamic") );
80         _cb_SliceFixDinamic->SetValue(true);
81
82         _sl_SliceImage = new wxSlider(this, wxID_ANY, 0, 1000, 1000, wxDefaultPosition, wxDefaultSize, wxSL_HORIZONTAL|wxSL_LABELS, wxDefaultValidator);
83         _sl_SliceImage->Enable(false);
84
85         _interpolationCheckBox = new wxCheckBox(this, -1, _T("Image interpolation") );
86         _interpolationCheckBox->SetValue(true);
87         _opacity = new wxSlider(this, wxID_ANY, 6, 1, 10, wxDefaultPosition, wxDefaultSize, wxSL_HORIZONTAL|wxSL_LABELS, wxDefaultValidator);
88
89         if (type==0)
90         {
91         }
92
93         if (type==1)
94         {
95         }
96
97
98         Connect( _btn_ReadImage->GetId(), wxEVT_COMMAND_BUTTON_CLICKED  , (wxObjectEventFunction) &ColorLayerImageViewPanel::onReadImage );
99         Connect( _cb_ShowHide->GetId(), wxEVT_COMMAND_CHECKBOX_CLICKED , (wxObjectEventFunction) &ColorLayerImageViewPanel::onThresholdShow );
100         Connect( _interpolationCheckBox->GetId(), wxEVT_COMMAND_CHECKBOX_CLICKED, (wxObjectEventFunction) &ColorLayerImageViewPanel::onThresholdInterpolation );
101         Connect( _opacity->GetId(), wxEVT_SCROLL_THUMBTRACK, (wxObjectEventFunction) &ColorLayerImageViewPanel::onChangeOpacity );
102         Connect( _cb_SliceFixDinamic->GetId(), wxEVT_COMMAND_CHECKBOX_CLICKED, (wxObjectEventFunction) &ColorLayerImageViewPanel::onSliceFixDinamic );
103         Connect( _sl_SliceImage->GetId(), wxEVT_SCROLL_THUMBTRACK       , (wxObjectEventFunction) &ColorLayerImageViewPanel::onSliceImage );
104         Connect( _sl_SliceImage->GetId(), wxEVT_SCROLL_LINEUP           , (wxObjectEventFunction) &ColorLayerImageViewPanel::onSliceImage );
105         Connect( _sl_SliceImage->GetId(), wxEVT_SCROLL_LINEDOWN         , (wxObjectEventFunction) &ColorLayerImageViewPanel::onSliceImage );
106         Connect( _sl_SliceImage->GetId(), wxEVT_SCROLL_PAGEUP           , (wxObjectEventFunction) &ColorLayerImageViewPanel::onSliceImage );
107         Connect( _sl_SliceImage->GetId(), wxEVT_SCROLL_PAGEDOWN         , (wxObjectEventFunction) &ColorLayerImageViewPanel::onSliceImage );
108
109
110         wxFlexGridSizer * sizer         = new wxFlexGridSizer(1);
111         if (type==1)
112         {
113                 sizer -> Add( new wxStaticText(this,-1,_T("Color Image Layer"))  , 1, wxGROW );
114                 sizer -> Add( _btn_ReadImage, 1, wxGROW );
115                 sizer -> Add( new wxStaticText(this,-1,_T(" "))  , 1, wxGROW );
116         }
117         sizer -> Add( new wxStaticText(this,-1,_T("Opacity Level"))  , 1, wxGROW );
118         sizer -> Add( _opacity, 1, wxGROW );
119         sizer -> Add( new wxStaticText(this,-1,_T(" "))  , 1, wxGROW );
120         sizer -> Add( _cb_ShowHide, 1, wxGROW );
121         sizer -> Add( new wxStaticText(this,-1,_T(" "))  , 1, wxGROW );
122         sizer -> Add( _interpolationCheckBox, 1, wxGROW );
123
124         sizer -> Add( new wxStaticText(this,-1,_T(" "))  , 1, wxGROW );
125         sizer -> Add( new wxStaticText(this,-1,_T("Slice "))  , 1, wxGROW );
126         sizer -> Add( _sl_SliceImage, 1, wxGROW );
127         sizer -> Add( _cb_SliceFixDinamic, 1, wxGROW );
128
129         this->SetSizer( sizer );
130         this->SetAutoLayout( true );
131         this->Layout();
132 }
133
134 //----------------------------------------------------------------------------
135 ColorLayerImageViewPanel::~ColorLayerImageViewPanel()
136 {
137 }
138
139
140 //----------------------------------------------------------------------------
141 void ColorLayerImageViewPanel::SetColorLayerImageView(ColorLayerImageView* colorLayerImageView)
142 {
143         _colorLayerImageView = colorLayerImageView;
144 }
145
146 //----------------------------------------------------------------------------
147 ColorLayerImageView* ColorLayerImageViewPanel::GetColorLayerImageView()
148 {
149         return _colorLayerImageView;
150 }
151
152
153 // This is the new spacing of the background image  (1,1,1)
154 void ColorLayerImageViewPanel::SetBaseSpacing(double spc[3])
155 {
156         _spcBase[0] = spc[0];
157         _spcBase[1] = spc[1];
158         _spcBase[2] = spc[2];
159
160         _spcBase[0] = 1;
161         _spcBase[1] = 1;
162         _spcBase[2] = 1;
163 }
164
165 // This is the Original spacing of the background image
166 void ColorLayerImageViewPanel::SetOriginalSpacing(double spc[3])
167 {
168         _spcOrg[0] = spc[0];
169         _spcOrg[1] = spc[1];
170         _spcOrg[2] = spc[2];
171 }
172
173 // This is the size in pixels of the background image
174 void ColorLayerImageViewPanel::SetBaseDimension(int dim[3])
175 {
176         _dimBase[0] = dim[0];
177         _dimBase[1] = dim[1];
178         _dimBase[2] = dim[2];
179 }
180
181 //----------------------------------------------------------------------------
182 void ColorLayerImageViewPanel::SetImage(vtkImageData *img)
183 {
184     if (img!=NULL)
185     {
186         _colorLayerImageView->SetImage( img );
187
188         double spc[3];
189         img->GetSpacing(spc);
190
191         int dim[3];
192         int ext[6];
193         img->GetWholeExtent(ext);
194         dim[0] = ext[1]-ext[0];
195         dim[1] = ext[3]-ext[2];
196         dim[2] = ext[5]-ext[4];
197         _sl_SliceImage->SetRange( 0 , dim[2] );
198
199         if ( (spc[0]!=_spcBase[0]) || (spc[1]!=_spcBase[1]) || (spc[2]!=_spcBase[2]) ||
200              (dim[0]!=_dimBase[0]) || (spc[1]!=_spcBase[1]) || (spc[2]!=_spcBase[2])
201             )
202         {
203
204             bool transformOkDlg;
205             int typeOfTransformation;
206             wxString msg = _T("The image resolution of both images are not compatible. Do you want to tranform it? ");
207             wxDlgTransformByDimensionBySpacingByPixel dlg;
208             dlg.GetTransformType(this,msg,typeOfTransformation,transformOkDlg);
209
210     printf("EED ColorLayerImageViewPanel::onReadImage call dialog spc size,dim...???\n");
211
212             if (typeOfTransformation==0)  // make dimensions equals
213             {
214                 printf("EED ColorLayerImageViewPanel::onReadImage ...WARNNING.... dif size image spc*dim ofnew image ...???\n");
215                 spc[0]=_spcBase[0]*_dimBase[0]/dim[0];
216                 spc[1]=_spcBase[1]*_dimBase[1]/dim[1];
217                 spc[2] = 1;
218             }
219
220             if (typeOfTransformation==1)  // make spacing equals
221             {
222                 spc[0] = ( _spcBase[0]/spc[0] ) * _spcOrg[0];
223                 spc[1] = ( _spcBase[1]/spc[1] ) * _spcOrg[1];
224                 spc[2] = ( _spcBase[2]/spc[2] ) * _spcOrg[2];
225             }
226
227             if (typeOfTransformation==2)  // make spacing = 1
228             {
229                 spc[0] = 1;
230                 spc[1] = 1;
231                 spc[2] = 1;
232             }
233
234             img->SetSpacing(spc);
235         } // spc !_spcBase   dim!__dimBase
236
237         if (_colorLayerImageView!=NULL)
238         {
239             _colorLayerImageView->onThreshold();
240             _colorLayerImageView->Refresh();
241         }
242
243
244     }
245 }
246
247 //----------------------------------------------------------------------------
248 void ColorLayerImageViewPanel::onReadImage(wxCommandEvent& event)
249 {
250 // EED ???
251 //      creaImageIO::WxSimpleDlg w(0,_T("Select your image"),"creaContours_Descriptor.dscp","creatisContours DB");
252 //      w.ShowModal();
253         printf("EED ColorLayerImageViewPanel::onReadImage ....WARNING... Read dlg. all images creaImageIO ... ???\n");
254
255         creaMaracasVisuKernel::OpenImageDialog diag = creaMaracasVisuKernel::OpenImageDialog();
256         SetImage( diag.getImageData() );
257 }
258
259 //----------------------------------------------------------------------------
260 void ColorLayerImageViewPanel::onThresholdChange(wxCommandEvent& event)
261 {
262         if (_colorLayerImageView!=NULL)
263         {
264         if (_thresholdGo)
265         {
266             _colorLayerImageView->onThresholdChange();
267             _colorLayerImageView->Refresh();
268             //std::cout<< "Valor Min: " << minVal << " & Valor Max: " << maxVal  << std::endl;
269         } // _threshold
270         }//_colorLayerImageView
271 }
272
273 //----------------------------------------------------------------------------
274 void ColorLayerImageViewPanel::onThresholdShow(wxCommandEvent& event)
275 {
276         if (_colorLayerImageView!=NULL)
277         {
278         _thresholdGo = _cb_ShowHide->GetValue();
279         if (_thresholdGo)
280         {
281             _colorLayerImageView->onThreshold();
282         }else{
283             _colorLayerImageView->onThresholdRemove( );
284         }
285         _colorLayerImageView->Refresh();
286         }//_colorLayerImageView
287 }
288
289 //----------------------------------------------------------------------------
290 void ColorLayerImageViewPanel::onThresholdStop()
291 {
292         if (_colorLayerImageView!=NULL)
293         {
294         if (_thresholdGo)
295         {
296             _colorLayerImageView->onThresholdRemove( );
297             _thresholdGo=false;
298         }
299         }//_colorLayerImageView
300 }
301
302 //----------------------------------------------------------------------------
303 void ColorLayerImageViewPanel::onThresholdInterpolation(wxCommandEvent& event)
304 {
305         if (_colorLayerImageView!=NULL)
306         {
307         _colorLayerImageView->onThresholdInterpolation(_interpolationCheckBox->GetValue());
308         _colorLayerImageView->Refresh();
309         }//_colorLayerImageView
310 }
311
312 //----------------------------------------------------------------------------
313 void ColorLayerImageViewPanel::onSliceFixDinamic(wxCommandEvent& event)
314 {
315         if (_colorLayerImageView!=NULL)
316         {
317         bool fixdin = _cb_SliceFixDinamic->GetValue();
318         _colorLayerImageView->SetSliceFixDinamic( fixdin );
319         if (fixdin==false)
320         {
321             _colorLayerImageView->SetZ2( _sl_SliceImage->GetValue() );
322         }
323         _sl_SliceImage->Enable(!fixdin);
324         _colorLayerImageView->onThreshold();
325         _colorLayerImageView->Refresh();
326         }//_colorLayerImageView
327 }
328
329 //----------------------------------------------------------------------------
330 void ColorLayerImageViewPanel::onSliceImage(wxScrollEvent& event)
331 {
332         if (_colorLayerImageView!=NULL)
333         {
334         _colorLayerImageView->SetZ2( _sl_SliceImage->GetValue() );
335         _colorLayerImageView->onThreshold();
336         _colorLayerImageView->Refresh();
337         }//_colorLayerImageView
338 }
339
340 //----------------------------------------------------------------------------
341 void ColorLayerImageViewPanel::onChangeOpacity(wxScrollEvent& event)
342 {
343         if (_colorLayerImageView!=NULL)
344         {
345         int opacity = _opacity->GetValue();
346         _colorLayerImageView->onThresholdChangeOpacity(opacity);
347         _colorLayerImageView->Refresh();
348         }//_colorLayerImageView
349 }
350
351
352 //----------------------------------------------------------------------------
353 bool ColorLayerImageViewPanel::IsVisible()
354 {
355         return _thresholdGo;
356 }
357
358
359
360 // EOF
361