]> Creatis software - creaMaracasVisu.git/blob - lib/maracasVisuLib/src/interface/wxWindows/widgets/ThresholdImageView/ThresholdImageViewPanel.cxx
9ed31ca73c6da2a09e1816f969a0282872aca4ae
[creaMaracasVisu.git] / lib / maracasVisuLib / src / interface / wxWindows / widgets / ThresholdImageView / ThresholdImageViewPanel.cxx
1                                                                     
2
3 /**
4  *  \file 
5  *  \brief ClassThresholdImageViewPanel . 
6  */
7
8
9 #include "ThresholdImageViewPanel.h"
10
11
12
13 /**
14  ** Begin of the threshold panel
15  **/
16 ThresholdImageViewPanel::ThresholdImageViewPanel(wxWindow* parent, int min, int max, int type)
17 : wxPanel(parent, -1, wxDefaultPosition, wxDefaultSize, wxBORDER_SUNKEN)
18 {
19         _thresholdImageView = new ThresholdImageView();
20
21 //      wxButton *thresholdGoBtn = new wxButton(this,wxID_ANY,_T("Show/Hide Color"), wxDefaultPosition, wxSize(200,30) );
22         
23         _thresholdGo = true;
24         _cb_ShowHide = new wxCheckBox(this, wxID_ANY, _T("Show/Hide layer") );
25         _cb_ShowHide->SetValue(_thresholdGo);
26         
27         _interpolationCheckBox = new wxCheckBox(this, -1, _T("Image interpolation") );
28         _interpolationCheckBox->SetValue(true); 
29         _opacity = new wxSlider(this, wxID_ANY, 6, 1, 10, wxDefaultPosition, wxDefaultSize, wxSL_HORIZONTAL|wxSL_LABELS, wxDefaultValidator);
30         
31 //      double range[2];
32 //      interfMainPanel::getInstance()->getImageRange(range);
33         
34 //      int min = (int)floor (range[0]);
35 //      int max = (int)ceil (range[1]);
36
37         if (type==0)
38         {
39         }
40         
41         if (type==1)
42         {
43                 _mBarThreshold  =  new mBarRange(this,70,65);
44                 _mBarThreshold-> SetMin(0);
45                 _mBarThreshold-> SetStart(0);
46                 _mBarThreshold-> SetOrientation( true );
47                 _mBarThreshold-> setActiveStateTo(true);
48                 _mBarThreshold-> setVisibleLabels( true );
49                 _mBarThreshold-> setDeviceEndMargin(10);
50                 _mBarThreshold-> setRepresentedValues( min , max );
51                 _mBarThreshold-> setDeviceBlitStart(10,10); 
52                 _mBarThreshold-> setIfWithActualDrawed( false );
53                 _mBarThreshold-> SetStart( min );
54                 _mBarThreshold-> SetEnd( max );  
55         }
56         
57         
58         Connect( _cb_ShowHide->GetId(), wxEVT_COMMAND_CHECKBOX_CLICKED , (wxObjectEventFunction) &ThresholdImageViewPanel::onThresholdShow ); 
59         Connect( _interpolationCheckBox->GetId(), wxEVT_COMMAND_CHECKBOX_CLICKED, (wxObjectEventFunction) &ThresholdImageViewPanel::onThresholdInterpolation );
60         Connect( _opacity->GetId(), wxEVT_SCROLL_THUMBTRACK, (wxObjectEventFunction) &ThresholdImageViewPanel::onChangeOpacity );
61         
62         wxFlexGridSizer * sizer         = new wxFlexGridSizer(1);
63         if (type==1)
64         {
65                 sizer -> Add( new wxStaticText(this,-1,_T("Image Threshold"))  , 1, wxGROW );
66                 sizer -> Add( _mBarThreshold, 1, wxGROW );
67                 sizer -> Add( new wxStaticText(this,-1,_T(" "))  , 1, wxGROW );
68         }
69         sizer -> Add( new wxStaticText(this,-1,_T("Opacity Level"))  , 1, wxGROW );
70         sizer -> Add( _opacity, 1, wxGROW );
71         sizer -> Add( new wxStaticText(this,-1,_T(" "))  , 1, wxGROW );
72         sizer -> Add( _cb_ShowHide, 1, wxGROW );
73         sizer -> Add( new wxStaticText(this,-1,_T(" "))  , 1, wxGROW );
74         sizer -> Add( _interpolationCheckBox, 1, wxGROW );
75         
76         this->SetSizer( sizer );
77         this->SetAutoLayout( true );
78         this->Layout();
79 }
80
81 //----------------------------------------------------------------------------
82 ThresholdImageViewPanel::~ThresholdImageViewPanel()
83 {
84 }
85
86
87 //----------------------------------------------------------------------------
88 void ThresholdImageViewPanel::SetThresholdImageView(ThresholdImageView* thresholdImageView)
89 {
90         _thresholdImageView = thresholdImageView;
91 }
92
93
94 //----------------------------------------------------------------------------
95 void ThresholdImageViewPanel::onThresholdChange(wxCommandEvent& event)
96 {
97         if (_thresholdGo)
98         {
99                 _thresholdImageView->SetminMaxValue( _mBarThreshold->GetStart(), _mBarThreshold->GetEnd() );
100                 _thresholdImageView->onThresholdChange();
101                 _thresholdImageView->GetwxVtkBaseView()->Refresh();
102                 //std::cout<< "Valor Min: " << minVal << " & Valor Max: " << maxVal  << std::endl;
103         }
104 }
105
106 //----------------------------------------------------------------------------
107 void ThresholdImageViewPanel::onThresholdShow(wxCommandEvent& event)
108 {
109         _thresholdGo = _cb_ShowHide->GetValue();
110         if (_thresholdGo)
111         {
112                 _thresholdImageView->onThreshold();
113         }
114         else
115         {       
116                 _thresholdImageView->onThresholdRemove( );
117         }
118         _thresholdImageView->GetwxVtkBaseView()->Refresh();
119 }
120
121 //----------------------------------------------------------------------------
122 void ThresholdImageViewPanel::onThresholdStop()
123 {
124         if (_thresholdGo)
125         {       
126                 _thresholdImageView->onThresholdRemove( );
127                 _thresholdGo=false;             
128         }
129 }
130
131 //----------------------------------------------------------------------------
132 void ThresholdImageViewPanel::onThresholdInterpolation(wxCommandEvent& event)
133 {
134         _thresholdImageView->onThresholdInterpolation(_interpolationCheckBox->GetValue());
135         _thresholdImageView->GetwxVtkBaseView()->Refresh();
136
137 }
138
139 //----------------------------------------------------------------------------
140 void ThresholdImageViewPanel::onChangeOpacity(wxScrollEvent& event)
141 {
142         int opacity = _opacity->GetValue();
143         _thresholdImageView->onThresholdChangeOpacity(opacity);
144         _thresholdImageView->GetwxVtkBaseView()->Refresh();
145 }
146
147
148 //----------------------------------------------------------------------------
149 bool ThresholdImageViewPanel::IsVisible()
150 {
151         return _thresholdGo;
152 }
153
154
155 BEGIN_EVENT_TABLE(ThresholdImageViewPanel, wxPanel)
156   EVT_COMMAND(wxID_ANY, wxEVT_TSBAR_START, ThresholdImageViewPanel::onThresholdChange)
157   EVT_COMMAND(wxID_ANY, wxEVT_TSBAR_END, ThresholdImageViewPanel::onThresholdChange)
158   EVT_COMMAND(wxID_ANY, wxEVT_TSBAR_MOVED, ThresholdImageViewPanel::onThresholdChange)  
159
160 //EED Borrame
161 //  EVT_SCROLL(ThresholdImageViewPanel::onChangeOpacity)
162
163 END_EVENT_TABLE()
164
165
166
167 // EOF
168