]> Creatis software - creaMaracasVisu.git/blob - lib/maracasVisuLib/src/interface/wxWindows/widgets/ThresholdImageView/ThresholdImageViewPanel.cxx
4ad0d443b5905cf79e675603ef5782e573186fec
[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)
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         _interpolationCheckBox = new wxCheckBox(this, -1, _T("Image interpolation") );
23         _interpolationCheckBox->SetValue(true); 
24         _opacity = new wxSlider(this, wxID_ANY, 6, 1, 10, wxDefaultPosition, wxDefaultSize, wxSL_HORIZONTAL|wxSL_LABELS, wxDefaultValidator);
25         _thresholdGo = false;
26         
27         double range[2];
28 //      interfMainPanel::getInstance()->getImageRange(range);
29         
30         int min = (int)floor (range[0]);
31         int max = (int)ceil (range[1]);
32         
33         _mBarThreshold  =  new mBarRange(this,70,65);
34         _mBarThreshold->SetMin(0);
35         _mBarThreshold->SetStart(0);
36         _mBarThreshold-> SetOrientation( true );
37         _mBarThreshold-> setActiveStateTo(true);
38         _mBarThreshold-> setVisibleLabels( true );
39         _mBarThreshold-> setDeviceEndMargin(10);
40         _mBarThreshold-> setRepresentedValues( min , max );
41         _mBarThreshold-> setDeviceBlitStart(10,10); 
42         _mBarThreshold-> setIfWithActualDrawed( false );
43         _mBarThreshold-> SetStart( min );
44         _mBarThreshold-> SetEnd( max );  
45         
46         Connect( thresholdGoBtn->GetId(), wxEVT_COMMAND_BUTTON_CLICKED , (wxObjectEventFunction) &ThresholdImageViewPanel::onThresholdGo ); 
47         Connect( _interpolationCheckBox->GetId(), wxEVT_COMMAND_CHECKBOX_CLICKED, (wxObjectEventFunction) &ThresholdImageViewPanel::onThresholdInterpolation );
48         
49         wxFlexGridSizer * sizer         = new wxFlexGridSizer(1);
50         sizer -> Add( new wxStaticText(this,-1,_T("Image Threshold"))  , 1, wxGROW );
51         sizer -> Add( _mBarThreshold, 1, wxGROW );
52         sizer -> Add( new wxStaticText(this,-1,_T(" "))  , 1, wxGROW );
53         sizer -> Add( new wxStaticText(this,-1,_T("Opacity Level"))  , 1, wxGROW );
54         sizer -> Add( _opacity, 1, wxGROW );
55         sizer -> Add( new wxStaticText(this,-1,_T(" "))  , 1, wxGROW );
56         sizer -> Add( thresholdGoBtn, 1, wxGROW );
57         sizer -> Add( new wxStaticText(this,-1,_T(" "))  , 1, wxGROW );
58         sizer -> Add( _interpolationCheckBox, 1, wxGROW );
59         
60         this->SetSizer( sizer );
61         this->SetAutoLayout( true );
62         this->Layout();
63 }
64
65 //----------------------------------------------------------------------------
66 ThresholdImageViewPanel::~ThresholdImageViewPanel(){
67 }
68
69
70 //----------------------------------------------------------------------------
71 void ThresholdImageViewPanel::SetThresholdImageView(ThresholdImageView* thresholdImageView)
72 {
73         _thresholdImageView = thresholdImageView;
74 }
75
76
77 //----------------------------------------------------------------------------
78 void ThresholdImageViewPanel::onThresholdChange(wxCommandEvent& event)
79 {
80         if (_thresholdGo)
81         {
82                 _thresholdImageView->onThresholdChange();
83                 
84                 //std::cout<< "Valor Min: " << minVal << " & Valor Max: " << maxVal  << std::endl;
85         }
86 }
87
88 //----------------------------------------------------------------------------
89 void ThresholdImageViewPanel::onThresholdGo(wxCommandEvent& event)
90 {
91         if (!_thresholdGo)
92         {
93                 _thresholdImageView->onThreshold();
94                 _thresholdGo=true;
95         }
96         else
97         {       
98                 _thresholdImageView->onThresholdRemove( );
99                 _thresholdGo=false;             
100         }
101 }
102
103 //----------------------------------------------------------------------------
104 void ThresholdImageViewPanel::onThresholdStop()
105 {
106         if (_thresholdGo)
107         {       
108                 _thresholdImageView->onThresholdRemove( );
109                 _thresholdGo=false;             
110         }
111 }
112
113 //----------------------------------------------------------------------------
114 void ThresholdImageViewPanel::onThresholdInstantChange(double range[])
115 {
116         range[0] = _mBarThreshold->GetStart();
117         range[1] = _mBarThreshold->GetEnd();
118 }
119
120 //----------------------------------------------------------------------------
121 void ThresholdImageViewPanel::onThresholdInterpolation(wxCommandEvent& event)
122 {
123         _thresholdImageView->onThresholdInterpolation(_interpolationCheckBox->GetValue());
124 }
125
126 //----------------------------------------------------------------------------
127 void ThresholdImageViewPanel::onChangeOpacity(wxScrollEvent& event)
128 {
129         int opacity = _opacity->GetValue();
130         _thresholdImageView->onThresholdChangeOpacity(opacity);
131 }
132
133
134
135 BEGIN_EVENT_TABLE(ThresholdImageViewPanel, wxPanel)
136   EVT_COMMAND(wxID_ANY, wxEVT_TSBAR_START, ThresholdImageViewPanel::onThresholdChange)
137   EVT_COMMAND(wxID_ANY, wxEVT_TSBAR_END, ThresholdImageViewPanel::onThresholdChange)
138   EVT_COMMAND(wxID_ANY, wxEVT_TSBAR_MOVED, ThresholdImageViewPanel::onThresholdChange)  
139   EVT_SCROLL(ThresholdImageViewPanel::onChangeOpacity)
140 END_EVENT_TABLE()
141
142
143
144 // EOF
145