]> Creatis software - creaMaracasVisu.git/blob - lib/maracasVisuLib/src/interface/wxWindows/widgets/ThresholdImageView/ThresholdImageViewPanel.cxx
c3e7bcf772573022a2c8152be00c513167522a25
[creaMaracasVisu.git] / lib / maracasVisuLib / src / interface / wxWindows / widgets / ThresholdImageView / ThresholdImageViewPanel.cxx
1  /*# ---------------------------------------------------------------------
2 #
3 # Copyright (c) CREATIS (Centre de Recherche en Acquisition et Traitement de l'Image
4 #                        pour la Sant�)
5 # Authors : Eduardo Davila, Frederic Cervenansky, Claire Mouton
6 # Previous Authors : Laurent Guigues, Jean-Pierre Roux
7 # CreaTools website : www.creatis.insa-lyon.fr/site/fr/creatools_accueil
8 #
9 #  This software is governed by the CeCILL-B license under French law and
10 #  abiding by the rules of distribution of free software. You can  use,
11 #  modify and/ or redistribute the software under the terms of the CeCILL-B
12 #  license as circulated by CEA, CNRS and INRIA at the following URL
13 #  http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
14 #  or in the file LICENSE.txt.
15 #
16 #  As a counterpart to the access to the source code and  rights to copy,
17 #  modify and redistribute granted by the license, users are provided only
18 #  with a limited warranty  and the software's author,  the holder of the
19 #  economic rights,  and the successive licensors  have only  limited
20 #  liability.
21 #
22 #  The fact that you are presently reading this means that you have had
23 #  knowledge of the CeCILL-B license and that you accept its terms.
24 # ------------------------------------------------------------------------ */
25
26
27
28 /**
29  *  \file 
30  *  \brief ClassThresholdImageViewPanel . 
31  */
32
33
34 #include "ThresholdImageViewPanel.h"
35
36
37
38 /**
39  ** Begin of the threshold panel
40  **/
41 ThresholdImageViewPanel::ThresholdImageViewPanel(wxWindow* parent, int min, int max, int type)
42 : wxPanel(parent, -1, wxDefaultPosition, wxDefaultSize, wxBORDER_SUNKEN)
43 {
44         _thresholdImageView = new ThresholdImageView();
45
46 //      wxButton *thresholdGoBtn = new wxButton(this,wxID_ANY,_T("Show/Hide Color"), wxDefaultPosition, wxSize(200,30) );
47         
48         _thresholdGo = true;
49         _cb_ShowHide = new wxCheckBox(this, wxID_ANY, _T("Show/Hide layer") );
50         _cb_ShowHide->SetValue(_thresholdGo);
51         
52         _interpolationCheckBox = new wxCheckBox(this, -1, _T("Image interpolation") );
53         _interpolationCheckBox->SetValue(true); 
54         _opacity = new wxSlider(this, wxID_ANY, 6, 1, 10, wxDefaultPosition, wxDefaultSize, wxSL_HORIZONTAL|wxSL_LABELS, wxDefaultValidator);
55         
56 //      double range[2];
57 //      interfMainPanel::getInstance()->getImageRange(range);
58         
59 //      int min = (int)floor (range[0]);
60 //      int max = (int)ceil (range[1]);
61
62         if (type==0)
63         {
64         }
65         
66         if (type==1)
67         {
68                 _mBarThreshold  =  new mBarRange(this,70,65);
69                 _mBarThreshold-> SetMin(0);
70                 _mBarThreshold-> SetStart(0);
71                 _mBarThreshold-> SetOrientation( true );
72                 _mBarThreshold-> setActiveStateTo(true);
73                 _mBarThreshold-> setVisibleLabels( true );
74                 _mBarThreshold-> setDeviceEndMargin(10);
75                 _mBarThreshold-> setRepresentedValues( min , max );
76                 _mBarThreshold-> setDeviceBlitStart(10,10); 
77                 _mBarThreshold-> setIfWithActualDrawed( false );
78                 _mBarThreshold-> SetStart( min );
79                 _mBarThreshold-> SetEnd( max );  
80         }
81         
82         
83         Connect( _cb_ShowHide->GetId(), wxEVT_COMMAND_CHECKBOX_CLICKED , (wxObjectEventFunction) &ThresholdImageViewPanel::onThresholdShow ); 
84         Connect( _interpolationCheckBox->GetId(), wxEVT_COMMAND_CHECKBOX_CLICKED, (wxObjectEventFunction) &ThresholdImageViewPanel::onThresholdInterpolation );
85         Connect( _opacity->GetId(), wxEVT_SCROLL_THUMBTRACK, (wxObjectEventFunction) &ThresholdImageViewPanel::onChangeOpacity );
86         
87         wxFlexGridSizer * sizer         = new wxFlexGridSizer(1);
88         if (type==1)
89         {
90                 sizer -> Add( new wxStaticText(this,-1,_T("Image Threshold"))  , 1, wxGROW );
91                 sizer -> Add( _mBarThreshold, 1, wxGROW );
92                 sizer -> Add( new wxStaticText(this,-1,_T(" "))  , 1, wxGROW );
93         }
94         sizer -> Add( new wxStaticText(this,-1,_T("Opacity Level"))  , 1, wxGROW );
95         sizer -> Add( _opacity, 1, wxGROW );
96         sizer -> Add( new wxStaticText(this,-1,_T(" "))  , 1, wxGROW );
97         sizer -> Add( _cb_ShowHide, 1, wxGROW );
98         sizer -> Add( new wxStaticText(this,-1,_T(" "))  , 1, wxGROW );
99         sizer -> Add( _interpolationCheckBox, 1, wxGROW );
100         
101         this->SetSizer( sizer );
102         this->SetAutoLayout( true );
103         this->Layout();
104 }
105
106 //----------------------------------------------------------------------------
107 ThresholdImageViewPanel::~ThresholdImageViewPanel()
108 {
109 }
110
111
112 //----------------------------------------------------------------------------
113 void ThresholdImageViewPanel::SetThresholdImageView(ThresholdImageView* thresholdImageView)
114 {
115         _thresholdImageView = thresholdImageView;
116 }
117
118
119 //----------------------------------------------------------------------------
120 void ThresholdImageViewPanel::onThresholdChange(wxCommandEvent& event)
121 {
122         if (_thresholdGo)
123         {
124                 _thresholdImageView->SetminMaxValue( _mBarThreshold->GetStart(), _mBarThreshold->GetEnd() );
125                 _thresholdImageView->onThresholdChange();
126                 _thresholdImageView->GetwxVtkBaseView()->Refresh();
127                 //std::cout<< "Valor Min: " << minVal << " & Valor Max: " << maxVal  << std::endl;
128         }
129 }
130
131 //----------------------------------------------------------------------------
132 void ThresholdImageViewPanel::onThresholdShow(wxCommandEvent& event)
133 {
134         _thresholdGo = _cb_ShowHide->GetValue();
135         if (_thresholdGo)
136         {
137                 _thresholdImageView->onThreshold();
138         }
139         else
140         {       
141                 _thresholdImageView->onThresholdRemove( );
142         }
143         _thresholdImageView->GetwxVtkBaseView()->Refresh();
144 }
145
146 //----------------------------------------------------------------------------
147 void ThresholdImageViewPanel::onThresholdStop()
148 {
149         if (_thresholdGo)
150         {       
151                 _thresholdImageView->onThresholdRemove( );
152                 _thresholdGo=false;             
153         }
154 }
155
156 //----------------------------------------------------------------------------
157 void ThresholdImageViewPanel::onThresholdInterpolation(wxCommandEvent& event)
158 {
159         _thresholdImageView->onThresholdInterpolation(_interpolationCheckBox->GetValue());
160         _thresholdImageView->GetwxVtkBaseView()->Refresh();
161
162 }
163
164 //----------------------------------------------------------------------------
165 void ThresholdImageViewPanel::onChangeOpacity(wxScrollEvent& event)
166 {
167         int opacity = _opacity->GetValue();
168         _thresholdImageView->onThresholdChangeOpacity(opacity);
169         _thresholdImageView->GetwxVtkBaseView()->Refresh();
170 }
171
172
173 //----------------------------------------------------------------------------
174 bool ThresholdImageViewPanel::IsVisible()
175 {
176         return _thresholdGo;
177 }
178
179
180 BEGIN_EVENT_TABLE(ThresholdImageViewPanel, wxPanel)
181   EVT_COMMAND(wxID_ANY, wxEVT_TSBAR_START, ThresholdImageViewPanel::onThresholdChange)
182   EVT_COMMAND(wxID_ANY, wxEVT_TSBAR_END, ThresholdImageViewPanel::onThresholdChange)
183   EVT_COMMAND(wxID_ANY, wxEVT_TSBAR_MOVED, ThresholdImageViewPanel::onThresholdChange)  
184
185 //EED Borrame
186 //  EVT_SCROLL(ThresholdImageViewPanel::onChangeOpacity)
187
188 END_EVENT_TABLE()
189
190
191
192 // EOF
193