]> Creatis software - creaMaracasVisu.git/blob - lib/maracasVisuLib/src/interface/wxWindows/widgets/ThresholdImageView/ColorLayerImageViewPanel.cxx
eb38e0966c00663226f01f21cfcd55284522aab8
[creaMaracasVisu.git] / lib / maracasVisuLib / src / interface / wxWindows / widgets / ThresholdImageView / ColorLayerImageViewPanel.cxx
1 /*# ---------------------------------------------------------------------
2 #
3 # Copyright (c) CREATIS (Centre de Recherche en Acquisition et Traitement de l'Image
4 #                        pour la Sant�)
5 # Authors : Eduardo Davila, Frederic Cervenansky, Claire Mouton
6 # Previous Authors : Laurent Guigues, Jean-Pierre Roux
7 # CreaTools website : www.creatis.insa-lyon.fr/site/fr/creatools_accueil
8 #
9 #  This software is governed by the CeCILL-B license under French law and
10 #  abiding by the rules of distribution of free software. You can  use,
11 #  modify and/ or redistribute the software under the terms of the CeCILL-B
12 #  license as circulated by CEA, CNRS and INRIA at the following URL
13 #  http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
14 #  or in the file LICENSE.txt.
15 #
16 #  As a counterpart to the access to the source code and  rights to copy,
17 #  modify and redistribute granted by the license, users are provided only
18 #  with a limited warranty  and the software's author,  the holder of the
19 #  economic rights,  and the successive licensors  have only  limited
20 #  liability.
21 #
22 #  The fact that you are presently reading this means that you have had
23 #  knowledge of the CeCILL-B license and that you accept its terms.
24 # ------------------------------------------------------------------------ */
25
26 /**
27  *  \file
28  *  \brief ClassThresholdImageViewPanel .
29  */
30
31
32 #include "ColorLayerImageViewPanel.h"
33 #include "OpenImageDialog.h"
34
35
36 //---------------------------------------------------------
37 //---------------------------------------------------------
38 //---------------------------------------------------------
39
40 wxDlgTransformByDimensionBySpacingByPixel::wxDlgTransformByDimensionBySpacingByPixel()
41 {
42 }
43
44 wxDlgTransformByDimensionBySpacingByPixel::~wxDlgTransformByDimensionBySpacingByPixel()
45 {
46 }
47
48
49 void wxDlgTransformByDimensionBySpacingByPixel::GetTransformType(wxWindow *parent , wxString message,int &typeOfTransformation,bool &dlgWxOK)
50 {
51         wxDialog* dial          = new wxDialog (parent,-1,_T("Tools"),wxDefaultPosition, wxSize(590,190));
52         wxSizer* buttonsSizer   = dial->CreateSeparatedButtonSizer(wxOK|wxCANCEL);
53         wxBoxSizer *dialSizer   = new wxBoxSizer(wxVERTICAL);
54
55         wxString lstOptOperation[3];
56         lstOptOperation[0]=_T("By Dimension");
57         lstOptOperation[1]=_T("By Spacing");
58         lstOptOperation[2]=_T("By Pixel");
59         wxRadioBox * radioOpts = new wxRadioBox(dial, -1, _T("Type of Transformation"), wxDefaultPosition, wxSize(270,45), 3 , lstOptOperation,  3, wxRA_SPECIFY_COLS);
60
61         dialSizer->Add( new wxStaticText(dial,-1,message)  , 0, wxGROW );
62         //      dialSizer->Add( new wxStaticText(dial,-1,_T("selected Roi file. Do you want to tranform it?"))  , 0, wxGROW );
63         dialSizer->Add( new wxStaticText(dial,-1,_T(" "))  , 0, wxGROW );
64         dialSizer->Add(radioOpts,0,wxGROW);
65         dialSizer->Add( new wxStaticText(dial,-1,_T(" "))  , 0, wxGROW );
66         dialSizer->Add(buttonsSizer,0,wxGROW);
67         dial->SetSizer(dialSizer, true);
68         dial->Layout();
69         dial->ShowModal();
70
71         typeOfTransformation    = -1;
72         dlgWxOK                 = false;
73
74         if (dial->GetReturnCode() == wxID_OK)
75         {
76                 typeOfTransformation    = radioOpts->GetSelection() + 1;
77                 dlgWxOK                 = true;
78         }
79 }
80
81
82 //---------------------------------------------------------
83 //---------------------------------------------------------
84 //---------------------------------------------------------
85
86
87 /**
88  ** Begin of the threshold panel
89  **/
90 ColorLayerImageViewPanel::ColorLayerImageViewPanel(wxWindow* parent, int min, int max, int type)
91 : wxPanel(parent, -1, wxDefaultPosition, wxDefaultSize, wxBORDER_SUNKEN)
92 {
93         printf("EED ColorLayerImageViewPanel::ColorLayerImageViewPanel start \n");
94
95         _spcBase[0] = _spcBase[1] = _spcBase[2] = 0;
96         _dimBase[0] = _dimBase[1] = _dimBase[2] = 0;
97
98 //EED01 _colorLayerImageView            = new ColorLayerImageView();
99         _colorLayerImageViewManager     = new ColorLayerImageViewManager();
100
101         _btn_ReadImage                  = new wxButton(this, wxID_ANY, _T("Read Image") );
102         _thresholdGo                    = true;
103         _cb_ShowHide                    = new wxCheckBox(this, wxID_ANY, _T("Show/Hide Layer") );
104         _cb_ShowHide->SetValue(_thresholdGo);
105
106         _cb_SliceFixDinamic = new wxCheckBox(this, wxID_ANY, _T("Fixed/Dynamic Slice") );
107         _cb_SliceFixDinamic->SetValue(true);
108
109         _sl_SliceImageX = new wxSlider(this, wxID_ANY, 0, 1000, 1000, wxDefaultPosition, wxDefaultSize, wxSL_HORIZONTAL|wxSL_LABELS, wxDefaultValidator);
110         _sl_SliceImageY = new wxSlider(this, wxID_ANY, 0, 1000, 1000, wxDefaultPosition, wxDefaultSize, wxSL_HORIZONTAL|wxSL_LABELS, wxDefaultValidator);
111         _sl_SliceImageZ = new wxSlider(this, wxID_ANY, 0, 1000, 1000, wxDefaultPosition, wxDefaultSize, wxSL_HORIZONTAL|wxSL_LABELS, wxDefaultValidator);
112         _sl_SliceImageX->Enable(false);
113         _sl_SliceImageY->Enable(false);
114         _sl_SliceImageZ->Enable(false);
115
116         _interpolationCheckBox = new wxCheckBox(this, -1, _T("Image Interpolation") );
117         _interpolationCheckBox->SetValue(true);
118         _opacity = new wxSlider(this, wxID_ANY, 6, 1, 10, wxDefaultPosition, wxDefaultSize, wxSL_HORIZONTAL|wxSL_LABELS, wxDefaultValidator);
119
120         if (type==0)
121         {
122         }
123
124         if (type==1)
125         {
126         }
127
128
129         Connect( _btn_ReadImage->GetId(), wxEVT_COMMAND_BUTTON_CLICKED  , (wxObjectEventFunction) &ColorLayerImageViewPanel::onReadImage );
130         Connect( _cb_ShowHide->GetId(), wxEVT_COMMAND_CHECKBOX_CLICKED  , (wxObjectEventFunction) &ColorLayerImageViewPanel::onThresholdShow );
131         Connect( _interpolationCheckBox->GetId(), wxEVT_COMMAND_CHECKBOX_CLICKED, (wxObjectEventFunction) &ColorLayerImageViewPanel::onThresholdInterpolation );
132         Connect( _opacity->GetId(), wxEVT_SCROLL_THUMBTRACK, (wxObjectEventFunction) &ColorLayerImageViewPanel::onChangeOpacity );
133         Connect( _cb_SliceFixDinamic->GetId(), wxEVT_COMMAND_CHECKBOX_CLICKED, (wxObjectEventFunction) &ColorLayerImageViewPanel::onSliceFixDinamic );
134
135         Connect( _sl_SliceImageX->GetId(), wxEVT_SCROLL_THUMBTRACK      , (wxObjectEventFunction) &ColorLayerImageViewPanel::onSliceImage );
136         Connect( _sl_SliceImageX->GetId(), wxEVT_SCROLL_LINEUP          , (wxObjectEventFunction) &ColorLayerImageViewPanel::onSliceImage );
137         Connect( _sl_SliceImageX->GetId(), wxEVT_SCROLL_LINEDOWN        , (wxObjectEventFunction) &ColorLayerImageViewPanel::onSliceImage );
138         Connect( _sl_SliceImageX->GetId(), wxEVT_SCROLL_PAGEUP          , (wxObjectEventFunction) &ColorLayerImageViewPanel::onSliceImage );
139         Connect( _sl_SliceImageX->GetId(), wxEVT_SCROLL_PAGEDOWN        , (wxObjectEventFunction) &ColorLayerImageViewPanel::onSliceImage );
140
141         Connect( _sl_SliceImageY->GetId(), wxEVT_SCROLL_THUMBTRACK      , (wxObjectEventFunction) &ColorLayerImageViewPanel::onSliceImage );
142         Connect( _sl_SliceImageY->GetId(), wxEVT_SCROLL_LINEUP          , (wxObjectEventFunction) &ColorLayerImageViewPanel::onSliceImage );
143         Connect( _sl_SliceImageY->GetId(), wxEVT_SCROLL_LINEDOWN        , (wxObjectEventFunction) &ColorLayerImageViewPanel::onSliceImage );
144         Connect( _sl_SliceImageY->GetId(), wxEVT_SCROLL_PAGEUP          , (wxObjectEventFunction) &ColorLayerImageViewPanel::onSliceImage );
145         Connect( _sl_SliceImageY->GetId(), wxEVT_SCROLL_PAGEDOWN        , (wxObjectEventFunction) &ColorLayerImageViewPanel::onSliceImage );
146
147         Connect( _sl_SliceImageZ->GetId(), wxEVT_SCROLL_THUMBTRACK      , (wxObjectEventFunction) &ColorLayerImageViewPanel::onSliceImage );
148         Connect( _sl_SliceImageZ->GetId(), wxEVT_SCROLL_LINEUP          , (wxObjectEventFunction) &ColorLayerImageViewPanel::onSliceImage );
149         Connect( _sl_SliceImageZ->GetId(), wxEVT_SCROLL_LINEDOWN        , (wxObjectEventFunction) &ColorLayerImageViewPanel::onSliceImage );
150         Connect( _sl_SliceImageZ->GetId(), wxEVT_SCROLL_PAGEUP          , (wxObjectEventFunction) &ColorLayerImageViewPanel::onSliceImage );
151         Connect( _sl_SliceImageZ->GetId(), wxEVT_SCROLL_PAGEDOWN        , (wxObjectEventFunction) &ColorLayerImageViewPanel::onSliceImage );
152
153
154
155         wxFlexGridSizer * sizer         = new wxFlexGridSizer(1);
156         if (type==1)
157         {
158                 sizer -> Add( new wxStaticText(this,-1,_T("Color Image Layer"))  , 1, wxGROW );
159                 sizer -> Add( _btn_ReadImage, 1, wxGROW );
160                 sizer -> Add( new wxStaticText(this,-1,_T(" "))  , 1, wxGROW );
161         }
162         sizer -> Add( new wxStaticText(this,-1,_T("Opacity Level"))  , 1, wxGROW );
163         sizer -> Add( _opacity, 1, wxGROW );
164         sizer -> Add( new wxStaticText(this,-1,_T(" "))  , 1, wxGROW );
165         sizer -> Add( _cb_ShowHide, 1, wxGROW );
166         sizer -> Add( new wxStaticText(this,-1,_T(" "))  , 1, wxGROW );
167         sizer -> Add( _interpolationCheckBox, 1, wxGROW );
168
169         sizer -> Add( new wxStaticText(this,-1,_T(" "))  , 1, wxGROW );
170         sizer -> Add( new wxStaticText(this,-1,_T("Slice "))  , 1, wxGROW );
171         sizer -> Add( _sl_SliceImageX, 1, wxGROW );
172         sizer -> Add( _sl_SliceImageY, 1, wxGROW );
173         sizer -> Add( _sl_SliceImageZ, 1, wxGROW );
174         sizer -> Add( _cb_SliceFixDinamic, 1, wxGROW );
175
176         this->SetSizer( sizer );
177         this->SetAutoLayout( true );
178         this->Layout();
179      
180         //CM Sets the default fitting mode to Pixel mode.
181         _fitting_mode = 3;
182         // EO CM
183 }
184
185 //----------------------------------------------------------------------------
186 ColorLayerImageViewPanel::~ColorLayerImageViewPanel()
187 {
188 }
189
190
191 //EED01  
192 //EED01  //----------------------------------------------------------------------------
193 //EED01  void ColorLayerImageViewPanel::SetColorLayerImageView(ColorLayerImageView* colorLayerImageView)
194 //EED01  {
195 //EED01         _colorLayerImageView = colorLayerImageView;
196 //EED01  }
197 //EED01  
198 //EED01  //----------------------------------------------------------------------------
199 //EED01  ColorLayerImageView* ColorLayerImageViewPanel::GetColorLayerImageView()
200 //EED01  {
201 //EED01         return _colorLayerImageView;
202 //EED01  }
203
204
205 ColorLayerImageViewManager* ColorLayerImageViewPanel::GetColorLayerImageViewManager()
206 {
207    return _colorLayerImageViewManager;
208 }
209
210
211 // This is the new spacing of the background image  (1,1,1)
212 void ColorLayerImageViewPanel::SetBaseSpacing(double spc[3])
213 {
214         _spcBase[0] = spc[0];
215         _spcBase[1] = spc[1];
216         _spcBase[2] = spc[2];
217
218         _spcBase[0] = 1;
219         _spcBase[1] = 1;
220         _spcBase[2] = 1;
221 }
222
223 // This is the Original spacing of the background image
224 void ColorLayerImageViewPanel::SetOriginalSpacing(double spc[3])
225 {
226         _spcOrg[0] = spc[0];
227         _spcOrg[1] = spc[1];
228         _spcOrg[2] = spc[2];
229 }
230
231 // This is the size in pixels of the background image
232 void ColorLayerImageViewPanel::SetBaseDimension(int dim[3])
233 {
234         _dimBase[0] = dim[0];
235         _dimBase[1] = dim[1];
236         _dimBase[2] = dim[2];
237 }
238
239 //----------------------------------------------------------------------------
240 void ColorLayerImageViewPanel::SetImage(vtkImageData *img)
241 {
242     if (img!=NULL)
243     {
244         _colorLayerImageViewManager->SetImage( img );
245
246         double spc[3];
247         img->GetSpacing(spc);
248
249         int dim[3];
250         int ext[6];
251         img->GetWholeExtent(ext);
252         dim[0] = ext[1]-ext[0];
253         dim[1] = ext[3]-ext[2];
254         dim[2] = ext[5]-ext[4];
255         _sl_SliceImageX->SetRange( 0 , dim[0] );
256         _sl_SliceImageY->SetRange( 0 , dim[1] );
257         _sl_SliceImageZ->SetRange( 0 , dim[2] );
258
259         if ( (spc[0]!=_spcBase[0]) || (spc[1]!=_spcBase[1]) || (spc[2]!=_spcBase[2]) ||
260              (dim[0]!=_dimBase[0]) || (spc[1]!=_spcBase[1]) || (spc[2]!=_spcBase[2])
261             )
262         {
263           // CM
264           int typeOfTransformation;     
265           // In case of the option is set to create a dialog box.
266           if (_fitting_mode == -1)
267             {
268               bool transformOkDlg;
269               wxString msg = _T("The image resolution of both images are not compatible. Do you want to tranform it? ");
270               wxDlgTransformByDimensionBySpacingByPixel dlg;
271               dlg.GetTransformType(this,msg,typeOfTransformation,transformOkDlg);
272               // CM Reset the default value (Pixel i.e. 3) if the dialog box returned an inappropriate value.
273               if (transformOkDlg == false)
274                 typeOfTransformation = 3;
275             }
276           else
277             typeOfTransformation = _fitting_mode;
278           //EO CM
279
280           printf("EED ColorLayerImageViewPanel::onReadImage call dialog spc size,dim...???\n");
281
282             if (typeOfTransformation==1)  // make dimensions equals
283             {
284                 printf("EED ColorLayerImageViewPanel::onReadImage ...WARNNING.... dif size image spc*dim ofnew image ...???\n");
285                 spc[0]=_spcBase[0]*_dimBase[0]/dim[0];
286                 spc[1]=_spcBase[1]*_dimBase[1]/dim[1];
287                 spc[2] = 1;
288             }
289
290             if (typeOfTransformation==2)  // make spacing equals
291             {
292                 spc[0] = ( _spcBase[0]/spc[0] ) * _spcOrg[0];
293                 spc[1] = ( _spcBase[1]/spc[1] ) * _spcOrg[1];
294                 spc[2] = ( _spcBase[2]/spc[2] ) * _spcOrg[2];
295             }
296
297             if (typeOfTransformation==3)  // make spacing = 1
298             {
299                 spc[0] = 1;
300                 spc[1] = 1;
301                 spc[2] = 1;
302             }
303
304             img->SetSpacing(spc);
305         } // spc !_spcBase   dim!__dimBase
306
307 //EED01        if (_colorLayerImageView!=NULL)
308 //EED01        {
309 //EED01            _colorLayerImageView->onThreshold();
310                 if (_active==true)
311                 {
312                     _colorLayerImageViewManager->onThreshold();
313                     RefreshView();
314                 }
315 //EED01        }
316
317
318     }
319 }
320
321
322 void ColorLayerImageViewPanel::RefreshView()
323 {
324 //EED01         _colorLayerImageView->Refresh();
325         _colorLayerImageViewManager->Refresh();
326 }
327
328 //----------------------------------------------------------------------------
329 void ColorLayerImageViewPanel::SetFittingMode(int fitting_mode)
330 {
331   // CM Sets the fitting mode if an appropriate value is provided.
332   if (fitting_mode == -1 || fitting_mode == 1 || fitting_mode == 2 || fitting_mode == 3)
333     {
334       _fitting_mode = fitting_mode;
335     }
336   //Otherwise, an exception should be thrown (value 0 is fine, it corresponds to an empty field i.e. the default value is kept).
337   else if (fitting_mode != 0)
338     std::cout << "CM ERROR!!! The fitting mode provided has an inappropriate value. It should be an int between -1 ; 1 ; 2 ; 3, but its value is :" << fitting_mode << ". The default value will be set instead, i.e. Pixel transformation (3)." <<  std::endl;
339   //EO CM
340 }
341
342 //----------------------------------------------------------------------------
343 int ColorLayerImageViewPanel::GetFittingMode()
344 {
345   return _fitting_mode;
346 }
347
348 //----------------------------------------------------------------------------
349 void ColorLayerImageViewPanel::onReadImage(wxCommandEvent& event)
350 {
351 // EED ???
352 //      creaImageIO::WxSimpleDlg w(0,_T("Select your image"),"creaContours_Descriptor.dscp","creatisContours DB");
353 //      w.ShowModal();
354         printf("EED ColorLayerImageViewPanel::onReadImage ....WARNING... Read dlg. all images creaImageIO ... ???\n");
355
356         creaMaracasVisuKernel::OpenImageDialog diag = creaMaracasVisuKernel::OpenImageDialog();
357         SetImage( diag.getImageData() );
358 }
359
360 //----------------------------------------------------------------------------
361 void ColorLayerImageViewPanel::onThresholdChange(wxCommandEvent& event)
362 {
363 //EED01 if (_colorLayerImageView!=NULL)
364 //EED01 {
365                 if (_thresholdGo)
366                 {
367 //EED01                  _colorLayerImageView->onThresholdChange();
368                  _colorLayerImageViewManager->onThresholdChange();
369                  RefreshView();
370                 //std::cout<< "Valor Min: " << minVal << " & Valor Max: " << maxVal  << std::endl;
371           } // _thresholdGo
372 //EED01 }//_colorLayerImageView
373 }
374
375 //----------------------------------------------------------------------------
376 void ColorLayerImageViewPanel::onThresholdShow(wxCommandEvent& event)
377 {
378 //EED01 if (_colorLayerImageView!=NULL)
379 //EED01 {
380         _thresholdGo = _cb_ShowHide->GetValue();
381         if (_thresholdGo)
382         {
383 //EED01            _colorLayerImageView->onThreshold();
384                     _colorLayerImageViewManager->onThreshold();
385         }else{
386 //EED01            _colorLayerImageView->onThresholdRemove( );
387                     _colorLayerImageViewManager->onThresholdRemove( );
388         }
389              RefreshView();
390 //EED01 }//_colorLayerImageView
391 }
392
393 //----------------------------------------------------------------------------
394 void ColorLayerImageViewPanel::onThresholdStop()
395 {
396 //EED01 if (_colorLayerImageView!=NULL)
397 //EED01 {
398                 if (_thresholdGo)
399                 {
400 //EED01             _colorLayerImageView->onThresholdRemove( );
401                     _colorLayerImageViewManager->onThresholdRemove( );
402                     _thresholdGo=false;
403                 }
404 //EED01 }//_colorLayerImageView
405 }
406
407 //----------------------------------------------------------------------------
408 void ColorLayerImageViewPanel::onThresholdInterpolation(wxCommandEvent& event)
409 {
410 //EED01 if (_colorLayerImageView!=NULL)
411 //EED01 {
412 //EED01         _colorLayerImageView->onThresholdInterpolation(_interpolationCheckBox->GetValue());
413                 _colorLayerImageViewManager->onThresholdInterpolation(_interpolationCheckBox->GetValue());
414                 RefreshView();
415 //EED01 }//_colorLayerImageView
416 }
417
418 //----------------------------------------------------------------------------
419 void ColorLayerImageViewPanel::onSliceFixDinamic(wxCommandEvent& event)
420 {
421 //EED01 if (_colorLayerImageView!=NULL)
422 //EED01 {
423         bool fixdin = _cb_SliceFixDinamic->GetValue();
424 //EED01        _colorLayerImageView->SetSliceFixDynamic( fixdin );
425         _colorLayerImageViewManager->SetSliceFixDynamic( fixdin );
426         if (fixdin==false)
427         {
428 //EED01            _colorLayerImageView->SetZ2( _sl_SliceImage->GetValue() );
429             _colorLayerImageViewManager->SetX2( _sl_SliceImageX->GetValue() );
430             _colorLayerImageViewManager->SetY2( _sl_SliceImageY->GetValue() );
431             _colorLayerImageViewManager->SetZ2( _sl_SliceImageZ->GetValue() );
432         }
433         _sl_SliceImageX->Enable(!fixdin);
434         _sl_SliceImageY->Enable(!fixdin);
435         _sl_SliceImageZ->Enable(!fixdin);
436 //EED01        _colorLayerImageView->onThreshold();
437         _colorLayerImageViewManager->onThreshold();
438         RefreshView();
439 //EED01 }//_colorLayerImageView
440 }
441
442 //----------------------------------------------------------------------------
443 void ColorLayerImageViewPanel::onSliceImage(wxScrollEvent& event)
444 {
445 //EED01 if (_colorLayerImageView!=NULL)
446 //EED01 {
447 //EED01        _colorLayerImageView->SetZ2( _sl_SliceImage->GetValue() );
448 //EED01        _colorLayerImageView->onThreshold();
449 //EED01 RefreshView();
450          _colorLayerImageViewManager->SetX2( _sl_SliceImageX->GetValue() );
451          _colorLayerImageViewManager->SetY2( _sl_SliceImageY->GetValue() );
452          _colorLayerImageViewManager->SetZ2( _sl_SliceImageZ->GetValue() );
453          _colorLayerImageViewManager->onThreshold();
454         RefreshView();
455 //EED01 }//_colorLayerImageView
456 }
457
458 //----------------------------------------------------------------------------
459 void ColorLayerImageViewPanel::onChangeOpacity(wxScrollEvent& event)
460 {
461 //EED01 if (_colorLayerImageView!=NULL)
462 //EED01 {
463         int opacity = _opacity->GetValue();
464 //EED01        _colorLayerImageView->onThresholdChangeOpacity(opacity);
465         _colorLayerImageViewManager->onThresholdChangeOpacity(opacity);
466         RefreshView();
467 //EED01 }//_colorLayerImageView
468 }
469
470
471 //----------------------------------------------------------------------------
472 bool ColorLayerImageViewPanel::IsVisible()
473 {
474         return _thresholdGo;
475 }
476
477 //----------------------------------------------------------------------------
478 void ColorLayerImageViewPanel::SetActive(bool active)
479 {
480       _active=active;
481       _cb_ShowHide->SetValue( _active );
482 }
483
484
485 // EOF
486