]> Creatis software - creaMaracasVisu.git/blob - lib/maracasVisuLib/src/interface/wxWindows/widgets/ThresholdImageView/ColorLayerImageViewPanel.cxx
no 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 // This is the new spacing of the background image  (1,1,1)
141 void ColorLayerImageViewPanel::SetBaseSpacing(double spc[3])
142 {
143         _spcBase[0] = spc[0];
144         _spcBase[1] = spc[1];
145         _spcBase[2] = spc[2];
146         
147         _spcBase[0] = 1;
148         _spcBase[1] = 1;
149         _spcBase[2] = 1;
150 }
151
152 // This is the Original spacing of the background image
153 void ColorLayerImageViewPanel::SetOriginalSpacing(double spc[3])
154 {
155         _spcOrg[0] = spc[0];
156         _spcOrg[1] = spc[1];
157         _spcOrg[2] = spc[2];
158 }
159
160 // This is the size in pixels of the background image
161 void ColorLayerImageViewPanel::SetBaseDimension(int dim[3])
162 {
163         _dimBase[0] = dim[0];
164         _dimBase[1] = dim[1];
165         _dimBase[2] = dim[2];
166 }
167
168 //----------------------------------------------------------------------------
169 void ColorLayerImageViewPanel::onReadImage(wxCommandEvent& event)
170 {
171 // EED ???
172 //      creaImageIO::WxSimpleDlg w(0,_T("Select your image"),"creaContours_Descriptor.dscp","creatisContours DB"); 
173 //      w.ShowModal(); 
174         printf("EED ColorLayerImageViewPanel::onReadImage ....WARNING... Read dlg. all images creaImageIO ... ???\n");
175
176         creaMaracasVisuKernel::OpenImageDialog diag = creaMaracasVisuKernel::OpenImageDialog();
177         _colorLayerImageView->SetImage( diag.getImageData() );
178
179         double spc[3];
180         diag.getImageData()->GetSpacing(spc);
181         
182         int dim[3];
183         int ext[6];
184         diag.getImageData()->GetWholeExtent(ext);
185         dim[0] = ext[1]-ext[0];
186         dim[1] = ext[3]-ext[2];
187         dim[2] = ext[5]-ext[4];
188         _sl_SliceImage->SetRange( 0 , dim[2] );
189                 
190         if ( (spc[0]!=_spcBase[0]) || (spc[1]!=_spcBase[1]) || (spc[2]!=_spcBase[2]) ||         
191                  (dim[0]!=_dimBase[0]) || (spc[1]!=_spcBase[1]) || (spc[2]!=_spcBase[2]) 
192                 )
193         {
194                 
195                 bool transformOkDlg;
196                 int typeOfTransformation;
197                 wxString msg = _T("The image resolution of both images are not compatible. Do you want to tranform it? ");
198             wxDlgTransformByDimensionBySpacingByPixel dlg;
199                 dlg.GetTransformType(this,msg,typeOfTransformation,transformOkDlg);
200                 
201 printf("EED ColorLayerImageViewPanel::onReadImage call dialog spc size,dim...???\n");
202                 
203                 if (typeOfTransformation==0)  // make dimensions equals 
204                 {
205                         printf("EED ColorLayerImageViewPanel::onReadImage ...WARNNING.... dif size image spc*dim ofnew image ...???\n");
206                         spc[0]=_spcBase[0]*_dimBase[0]/dim[0];
207                         spc[1]=_spcBase[1]*_dimBase[1]/dim[1];
208                         spc[2] = 1;
209                 }
210                 
211                 if (typeOfTransformation==1)  // make spacing equals
212                 {
213                         spc[0] = ( _spcBase[0]/spc[0] ) * _spcOrg[0];
214                         spc[1] = ( _spcBase[1]/spc[1] ) * _spcOrg[1];
215                         spc[2] = ( _spcBase[2]/spc[2] ) * _spcOrg[2];
216                 }
217                 
218                 if (typeOfTransformation==2)  // make spacing = 1
219                 {
220                         spc[0] = 1;
221                         spc[1] = 1;
222                         spc[2] = 1;
223                 }
224                 
225                 diag.getImageData()->SetSpacing(spc);
226         } // spc !_spcBase   dim!__dimBase
227         
228         _colorLayerImageView->onThreshold();
229         _colorLayerImageView->GetwxVtkBaseView()->Refresh();
230 }
231
232 //----------------------------------------------------------------------------
233 void ColorLayerImageViewPanel::onThresholdChange(wxCommandEvent& event)
234 {
235         if (_thresholdGo)
236         {
237                 _colorLayerImageView->onThresholdChange();
238                 _colorLayerImageView->GetwxVtkBaseView()->Refresh();
239                 //std::cout<< "Valor Min: " << minVal << " & Valor Max: " << maxVal  << std::endl;
240         }
241 }
242
243 //----------------------------------------------------------------------------
244 void ColorLayerImageViewPanel::onThresholdShow(wxCommandEvent& event)
245 {
246         _thresholdGo = _cb_ShowHide->GetValue();
247         if (_thresholdGo)
248         {
249                 _colorLayerImageView->onThreshold();
250         }
251         else
252         {       
253                 _colorLayerImageView->onThresholdRemove( );
254         }
255         _colorLayerImageView->GetwxVtkBaseView()->Refresh();
256 }
257
258 //----------------------------------------------------------------------------
259 void ColorLayerImageViewPanel::onThresholdStop()
260 {
261         if (_thresholdGo)
262         {       
263                 _colorLayerImageView->onThresholdRemove( );
264                 _thresholdGo=false;             
265         }
266 }
267
268 //----------------------------------------------------------------------------
269 void ColorLayerImageViewPanel::onThresholdInterpolation(wxCommandEvent& event)
270 {
271         _colorLayerImageView->onThresholdInterpolation(_interpolationCheckBox->GetValue());
272         _colorLayerImageView->GetwxVtkBaseView()->Refresh();
273
274 }
275
276 //----------------------------------------------------------------------------
277 void ColorLayerImageViewPanel::onSliceFixDinamic(wxCommandEvent& event)
278 {
279         bool fixdin = _cb_SliceFixDinamic->GetValue();
280         _colorLayerImageView->SetSliceFixDinamic( fixdin );
281         if (fixdin==false)
282         {
283                 _colorLayerImageView->SetZ2( _sl_SliceImage->GetValue() );
284         }
285         _sl_SliceImage->Enable(!fixdin);
286         _colorLayerImageView->onThreshold();
287         _colorLayerImageView->GetwxVtkBaseView()->Refresh();
288 }
289
290 //----------------------------------------------------------------------------
291 void ColorLayerImageViewPanel::onSliceImage(wxScrollEvent& event)
292 {
293         _colorLayerImageView->SetZ2( _sl_SliceImage->GetValue() );
294         _colorLayerImageView->onThreshold();
295         _colorLayerImageView->GetwxVtkBaseView()->Refresh();
296 }
297
298 //----------------------------------------------------------------------------
299 void ColorLayerImageViewPanel::onChangeOpacity(wxScrollEvent& event)
300 {
301         int opacity = _opacity->GetValue();
302         _colorLayerImageView->onThresholdChangeOpacity(opacity);
303         _colorLayerImageView->GetwxVtkBaseView()->Refresh();
304 }
305
306
307 //----------------------------------------------------------------------------
308 bool ColorLayerImageViewPanel::IsVisible()
309 {
310         return _thresholdGo;
311 }
312
313
314
315 // EOF
316