]> Creatis software - creaMaracasVisu.git/blob - lib/maracasVisuLib/src/interface/wxWindows/widgets/ThresholdImageView/ThresholdImageViewPanel.cxx
no message
[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         
61         wxFlexGridSizer * sizer         = new wxFlexGridSizer(1);
62         if (type==1)
63         {
64                 sizer -> Add( new wxStaticText(this,-1,_T("Image Threshold"))  , 1, wxGROW );
65                 sizer -> Add( _mBarThreshold, 1, wxGROW );
66                 sizer -> Add( new wxStaticText(this,-1,_T(" "))  , 1, wxGROW );
67         }
68         sizer -> Add( new wxStaticText(this,-1,_T("Opacity Level"))  , 1, wxGROW );
69         sizer -> Add( _opacity, 1, wxGROW );
70         sizer -> Add( new wxStaticText(this,-1,_T(" "))  , 1, wxGROW );
71         sizer -> Add( _cb_ShowHide, 1, wxGROW );
72         sizer -> Add( new wxStaticText(this,-1,_T(" "))  , 1, wxGROW );
73         sizer -> Add( _interpolationCheckBox, 1, wxGROW );
74         
75         this->SetSizer( sizer );
76         this->SetAutoLayout( true );
77         this->Layout();
78 }
79
80 //----------------------------------------------------------------------------
81 ThresholdImageViewPanel::~ThresholdImageViewPanel()
82 {
83 }
84
85
86 //----------------------------------------------------------------------------
87 void ThresholdImageViewPanel::SetThresholdImageView(ThresholdImageView* thresholdImageView)
88 {
89         _thresholdImageView = thresholdImageView;
90 }
91
92
93 //----------------------------------------------------------------------------
94 void ThresholdImageViewPanel::onThresholdChange(wxCommandEvent& event)
95 {
96         if (_thresholdGo)
97         {
98                 _thresholdImageView->SetminMaxValue( _mBarThreshold->GetStart(), _mBarThreshold->GetEnd() );
99                 _thresholdImageView->onThresholdChange();
100                 _thresholdImageView->GetwxVtkBaseView()->Refresh();
101                 //std::cout<< "Valor Min: " << minVal << " & Valor Max: " << maxVal  << std::endl;
102         }
103 }
104
105 //----------------------------------------------------------------------------
106 void ThresholdImageViewPanel::onThresholdShow(wxCommandEvent& event)
107 {
108         _thresholdGo = _cb_ShowHide->GetValue();
109         if (_thresholdGo)
110         {
111                 _thresholdImageView->onThreshold();
112         }
113         else
114         {       
115                 _thresholdImageView->onThresholdRemove( );
116         }
117         _thresholdImageView->GetwxVtkBaseView()->Refresh();
118 }
119
120 //----------------------------------------------------------------------------
121 void ThresholdImageViewPanel::onThresholdStop()
122 {
123         if (_thresholdGo)
124         {       
125                 _thresholdImageView->onThresholdRemove( );
126                 _thresholdGo=false;             
127         }
128 }
129
130 //----------------------------------------------------------------------------
131 void ThresholdImageViewPanel::onThresholdInterpolation(wxCommandEvent& event)
132 {
133         _thresholdImageView->onThresholdInterpolation(_interpolationCheckBox->GetValue());
134         _thresholdImageView->GetwxVtkBaseView()->Refresh();
135
136 }
137
138 //----------------------------------------------------------------------------
139 void ThresholdImageViewPanel::onChangeOpacity(wxScrollEvent& event)
140 {
141         int opacity = _opacity->GetValue();
142         _thresholdImageView->onThresholdChangeOpacity(opacity);
143         _thresholdImageView->GetwxVtkBaseView()->Refresh();
144 }
145
146
147 //----------------------------------------------------------------------------
148 bool ThresholdImageViewPanel::IsVisible()
149 {
150         return _thresholdGo;
151 }
152
153
154 BEGIN_EVENT_TABLE(ThresholdImageViewPanel, wxPanel)
155   EVT_COMMAND(wxID_ANY, wxEVT_TSBAR_START, ThresholdImageViewPanel::onThresholdChange)
156   EVT_COMMAND(wxID_ANY, wxEVT_TSBAR_END, ThresholdImageViewPanel::onThresholdChange)
157   EVT_COMMAND(wxID_ANY, wxEVT_TSBAR_MOVED, ThresholdImageViewPanel::onThresholdChange)  
158   EVT_SCROLL(ThresholdImageViewPanel::onChangeOpacity)
159 END_EVENT_TABLE()
160
161
162
163 // EOF
164