]> 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  ** Begin of the threshold panel
15  **/
16 ColorLayerImageViewPanel::ColorLayerImageViewPanel(wxWindow* parent, int min, int max, int type)
17 : wxPanel(parent, -1, wxDefaultPosition, wxDefaultSize, wxBORDER_SUNKEN)
18 {
19         _colorLayerImageView = new ColorLayerImageView();
20
21         _btn_ReadImage = new wxButton(this, wxID_ANY, _T("Read Image") );
22         
23
24         _thresholdGo = true;
25         _cb_ShowHide = new wxCheckBox(this, wxID_ANY, _T("Show/Hide layer") );
26         _cb_ShowHide->SetValue(_thresholdGo);
27
28         _cb_SliceFixDinamic = new wxCheckBox(this, wxID_ANY, _T("Slice Fix/Dinamic") );
29         _cb_SliceFixDinamic->SetValue(true);
30
31         _sl_SliceImage = new wxSlider(this, wxID_ANY, 0, 1000, 1000, wxDefaultPosition, wxDefaultSize, wxSL_HORIZONTAL|wxSL_LABELS, wxDefaultValidator);
32         _sl_SliceImage->Enable(false);
33
34         _interpolationCheckBox = new wxCheckBox(this, -1, _T("Image interpolation") );
35         _interpolationCheckBox->SetValue(true); 
36         _opacity = new wxSlider(this, wxID_ANY, 6, 1, 10, wxDefaultPosition, wxDefaultSize, wxSL_HORIZONTAL|wxSL_LABELS, wxDefaultValidator);
37         
38         if (type==0)
39         {
40         }
41         
42         if (type==1)
43         {
44         }
45         
46         
47         Connect( _btn_ReadImage->GetId(), wxEVT_COMMAND_BUTTON_CLICKED  , (wxObjectEventFunction) &ColorLayerImageViewPanel::onReadImage ); 
48         Connect( _cb_ShowHide->GetId(), wxEVT_COMMAND_CHECKBOX_CLICKED , (wxObjectEventFunction) &ColorLayerImageViewPanel::onThresholdShow ); 
49         Connect( _interpolationCheckBox->GetId(), wxEVT_COMMAND_CHECKBOX_CLICKED, (wxObjectEventFunction) &ColorLayerImageViewPanel::onThresholdInterpolation );
50         Connect( _opacity->GetId(), wxEVT_SCROLL_THUMBTRACK, (wxObjectEventFunction) &ColorLayerImageViewPanel::onChangeOpacity );
51         Connect( _cb_SliceFixDinamic->GetId(), wxEVT_COMMAND_CHECKBOX_CLICKED, (wxObjectEventFunction) &ColorLayerImageViewPanel::onSliceFixDinamic );
52         Connect( _sl_SliceImage->GetId(), wxEVT_SCROLL_THUMBTRACK       , (wxObjectEventFunction) &ColorLayerImageViewPanel::onSliceImage );
53         Connect( _sl_SliceImage->GetId(), wxEVT_SCROLL_LINEUP           , (wxObjectEventFunction) &ColorLayerImageViewPanel::onSliceImage );
54         Connect( _sl_SliceImage->GetId(), wxEVT_SCROLL_LINEDOWN         , (wxObjectEventFunction) &ColorLayerImageViewPanel::onSliceImage );
55         Connect( _sl_SliceImage->GetId(), wxEVT_SCROLL_PAGEUP           , (wxObjectEventFunction) &ColorLayerImageViewPanel::onSliceImage );
56         Connect( _sl_SliceImage->GetId(), wxEVT_SCROLL_PAGEDOWN         , (wxObjectEventFunction) &ColorLayerImageViewPanel::onSliceImage );
57
58
59         wxFlexGridSizer * sizer         = new wxFlexGridSizer(1);
60         if (type==1)
61         {
62                 sizer -> Add( new wxStaticText(this,-1,_T("Color Image Layer"))  , 1, wxGROW );
63                 sizer -> Add( _btn_ReadImage, 1, wxGROW );
64                 sizer -> Add( new wxStaticText(this,-1,_T(" "))  , 1, wxGROW );
65         }
66         sizer -> Add( new wxStaticText(this,-1,_T("Opacity Level"))  , 1, wxGROW );
67         sizer -> Add( _opacity, 1, wxGROW );
68         sizer -> Add( new wxStaticText(this,-1,_T(" "))  , 1, wxGROW );
69         sizer -> Add( _cb_ShowHide, 1, wxGROW );
70         sizer -> Add( new wxStaticText(this,-1,_T(" "))  , 1, wxGROW );
71         sizer -> Add( _interpolationCheckBox, 1, wxGROW );
72
73         sizer -> Add( new wxStaticText(this,-1,_T(" "))  , 1, wxGROW );
74         sizer -> Add( new wxStaticText(this,-1,_T("Slice "))  , 1, wxGROW );
75         sizer -> Add( _sl_SliceImage, 1, wxGROW );
76         sizer -> Add( _cb_SliceFixDinamic, 1, wxGROW );
77
78         this->SetSizer( sizer );
79         this->SetAutoLayout( true );
80         this->Layout();
81 }
82
83 //----------------------------------------------------------------------------
84 ColorLayerImageViewPanel::~ColorLayerImageViewPanel()
85 {
86 }
87
88
89 //----------------------------------------------------------------------------
90 void ColorLayerImageViewPanel::SetColorLayerImageView(ColorLayerImageView* colorLayerImageView)
91 {
92         _colorLayerImageView = colorLayerImageView;
93 }
94
95 //----------------------------------------------------------------------------
96 void ColorLayerImageViewPanel::onReadImage(wxCommandEvent& event)
97 {
98 // EED ???
99 //      creaImageIO::WxSimpleDlg w(0,_T("Select your image"),"creaContours_Descriptor.dscp","creatisContours DB"); 
100 //      w.ShowModal(); 
101
102         creaMaracasVisuKernel::OpenImageDialog diag = creaMaracasVisuKernel::OpenImageDialog();
103         _colorLayerImageView->SetImage( diag.getImageData() );
104
105         int ext[6];
106         diag.getImageData()->GetWholeExtent(ext);
107         _sl_SliceImage->SetRange( 0 , ext[5]-ext[4] );
108
109         _colorLayerImageView->onThreshold();
110         _colorLayerImageView->GetwxVtkBaseView()->Refresh();
111 }
112
113
114 //----------------------------------------------------------------------------
115 void ColorLayerImageViewPanel::onThresholdChange(wxCommandEvent& event)
116 {
117         if (_thresholdGo)
118         {
119                 _colorLayerImageView->onThresholdChange();
120                 _colorLayerImageView->GetwxVtkBaseView()->Refresh();
121                 //std::cout<< "Valor Min: " << minVal << " & Valor Max: " << maxVal  << std::endl;
122         }
123 }
124
125 //----------------------------------------------------------------------------
126 void ColorLayerImageViewPanel::onThresholdShow(wxCommandEvent& event)
127 {
128         _thresholdGo = _cb_ShowHide->GetValue();
129         if (_thresholdGo)
130         {
131                 _colorLayerImageView->onThreshold();
132         }
133         else
134         {       
135                 _colorLayerImageView->onThresholdRemove( );
136         }
137         _colorLayerImageView->GetwxVtkBaseView()->Refresh();
138 }
139
140 //----------------------------------------------------------------------------
141 void ColorLayerImageViewPanel::onThresholdStop()
142 {
143         if (_thresholdGo)
144         {       
145                 _colorLayerImageView->onThresholdRemove( );
146                 _thresholdGo=false;             
147         }
148 }
149
150 //----------------------------------------------------------------------------
151 void ColorLayerImageViewPanel::onThresholdInterpolation(wxCommandEvent& event)
152 {
153         _colorLayerImageView->onThresholdInterpolation(_interpolationCheckBox->GetValue());
154         _colorLayerImageView->GetwxVtkBaseView()->Refresh();
155
156 }
157
158 //----------------------------------------------------------------------------
159 void ColorLayerImageViewPanel::onSliceFixDinamic(wxCommandEvent& event)
160 {
161         bool fixdin = _cb_SliceFixDinamic->GetValue();
162         _colorLayerImageView->SetSliceFixDinamic( fixdin );
163         if (fixdin==false)
164         {
165                 _colorLayerImageView->SetZ2( _sl_SliceImage->GetValue() );
166         }
167         _sl_SliceImage->Enable(!fixdin);
168         _colorLayerImageView->onThreshold();
169         _colorLayerImageView->GetwxVtkBaseView()->Refresh();
170 }
171
172 //----------------------------------------------------------------------------
173 void ColorLayerImageViewPanel::onSliceImage(wxScrollEvent& event)
174 {
175         _colorLayerImageView->SetZ2( _sl_SliceImage->GetValue() );
176         _colorLayerImageView->onThreshold();
177         _colorLayerImageView->GetwxVtkBaseView()->Refresh();
178 }
179
180 //----------------------------------------------------------------------------
181 void ColorLayerImageViewPanel::onChangeOpacity(wxScrollEvent& event)
182 {
183         int opacity = _opacity->GetValue();
184         _colorLayerImageView->onThresholdChangeOpacity(opacity);
185         _colorLayerImageView->GetwxVtkBaseView()->Refresh();
186 }
187
188
189 //----------------------------------------------------------------------------
190 bool ColorLayerImageViewPanel::IsVisible()
191 {
192         return _thresholdGo;
193 }
194
195
196
197 // EOF
198