]> 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::SetImage(vtkImageData *img)
177 {
178     if (img!=NULL)
179     {
180         _colorLayerImageView->SetImage( img );
181
182         double spc[3];
183         img->GetSpacing(spc);
184
185         int dim[3];
186         int ext[6];
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] );
192
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])
195             )
196         {
197
198             bool transformOkDlg;
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);
203
204     printf("EED ColorLayerImageViewPanel::onReadImage call dialog spc size,dim...???\n");
205
206             if (typeOfTransformation==0)  // make dimensions equals
207             {
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];
211                 spc[2] = 1;
212             }
213
214             if (typeOfTransformation==1)  // make spacing equals
215             {
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];
219             }
220
221             if (typeOfTransformation==2)  // make spacing = 1
222             {
223                 spc[0] = 1;
224                 spc[1] = 1;
225                 spc[2] = 1;
226             }
227
228             img->SetSpacing(spc);
229         } // spc !_spcBase   dim!__dimBase
230
231         if (_colorLayerImageView!=NULL)
232         {
233             _colorLayerImageView->onThreshold();
234             _colorLayerImageView->Refresh();
235         }
236
237
238     }
239 }
240
241 //----------------------------------------------------------------------------
242 void ColorLayerImageViewPanel::onReadImage(wxCommandEvent& event)
243 {
244 // EED ???
245 //      creaImageIO::WxSimpleDlg w(0,_T("Select your image"),"creaContours_Descriptor.dscp","creatisContours DB");
246 //      w.ShowModal();
247         printf("EED ColorLayerImageViewPanel::onReadImage ....WARNING... Read dlg. all images creaImageIO ... ???\n");
248
249         creaMaracasVisuKernel::OpenImageDialog diag = creaMaracasVisuKernel::OpenImageDialog();
250         SetImage( diag.getImageData() );
251 }
252
253 //----------------------------------------------------------------------------
254 void ColorLayerImageViewPanel::onThresholdChange(wxCommandEvent& event)
255 {
256         if (_colorLayerImageView!=NULL)
257         {
258         if (_thresholdGo)
259         {
260             _colorLayerImageView->onThresholdChange();
261             _colorLayerImageView->Refresh();
262             //std::cout<< "Valor Min: " << minVal << " & Valor Max: " << maxVal  << std::endl;
263         } // _threshold
264         }//_colorLayerImageView
265 }
266
267 //----------------------------------------------------------------------------
268 void ColorLayerImageViewPanel::onThresholdShow(wxCommandEvent& event)
269 {
270         if (_colorLayerImageView!=NULL)
271         {
272         _thresholdGo = _cb_ShowHide->GetValue();
273         if (_thresholdGo)
274         {
275             _colorLayerImageView->onThreshold();
276         }else{
277             _colorLayerImageView->onThresholdRemove( );
278         }
279         _colorLayerImageView->Refresh();
280         }//_colorLayerImageView
281 }
282
283 //----------------------------------------------------------------------------
284 void ColorLayerImageViewPanel::onThresholdStop()
285 {
286         if (_colorLayerImageView!=NULL)
287         {
288         if (_thresholdGo)
289         {
290             _colorLayerImageView->onThresholdRemove( );
291             _thresholdGo=false;
292         }
293         }//_colorLayerImageView
294 }
295
296 //----------------------------------------------------------------------------
297 void ColorLayerImageViewPanel::onThresholdInterpolation(wxCommandEvent& event)
298 {
299         if (_colorLayerImageView!=NULL)
300         {
301         _colorLayerImageView->onThresholdInterpolation(_interpolationCheckBox->GetValue());
302         _colorLayerImageView->Refresh();
303         }//_colorLayerImageView
304 }
305
306 //----------------------------------------------------------------------------
307 void ColorLayerImageViewPanel::onSliceFixDinamic(wxCommandEvent& event)
308 {
309         if (_colorLayerImageView!=NULL)
310         {
311         bool fixdin = _cb_SliceFixDinamic->GetValue();
312         _colorLayerImageView->SetSliceFixDinamic( fixdin );
313         if (fixdin==false)
314         {
315             _colorLayerImageView->SetZ2( _sl_SliceImage->GetValue() );
316         }
317         _sl_SliceImage->Enable(!fixdin);
318         _colorLayerImageView->onThreshold();
319         _colorLayerImageView->Refresh();
320         }//_colorLayerImageView
321 }
322
323 //----------------------------------------------------------------------------
324 void ColorLayerImageViewPanel::onSliceImage(wxScrollEvent& event)
325 {
326         if (_colorLayerImageView!=NULL)
327         {
328         _colorLayerImageView->SetZ2( _sl_SliceImage->GetValue() );
329         _colorLayerImageView->onThreshold();
330         _colorLayerImageView->Refresh();
331         }//_colorLayerImageView
332 }
333
334 //----------------------------------------------------------------------------
335 void ColorLayerImageViewPanel::onChangeOpacity(wxScrollEvent& event)
336 {
337         if (_colorLayerImageView!=NULL)
338         {
339         int opacity = _opacity->GetValue();
340         _colorLayerImageView->onThresholdChangeOpacity(opacity);
341         _colorLayerImageView->Refresh();
342         }//_colorLayerImageView
343 }
344
345
346 //----------------------------------------------------------------------------
347 bool ColorLayerImageViewPanel::IsVisible()
348 {
349         return _thresholdGo;
350 }
351
352
353
354 // EOF
355