]> Creatis software - clitk.git/blob - vv/vvIntensityValueSlider.cxx
binarize
[clitk.git] / vv / vvIntensityValueSlider.cxx
1 /*=========================================================================
2
3   Program:   vv
4   Module:    $RCSfile: vvIntensityValueSlider.cxx,v $
5   Language:  C++
6   Date:      $Date: 2010/02/07 12:00:59 $
7   Version:   $Revision: 1.2 $
8   Author :   David Sarrut (david.sarrut@creatis.insa-lyon.fr)
9
10   Copyright (C) 2008
11   Léon Bérard cancer center http://oncora1.lyon.fnclcc.fr
12   CREATIS-LRMN http://www.creatis.insa-lyon.fr
13
14   This program is free software: you can redistribute it and/or modify
15   it under the terms of the GNU General Public License as published by
16   the Free Software Foundation, version 3 of the License.
17
18   This program is distributed in the hope that it will be useful,
19   but WITHOUT ANY WARRANTY; without even the implied warranty of
20   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
21   GNU General Public License for more details.
22
23   You should have received a copy of the GNU General Public License
24   along with this program.  If not, see <http://www.gnu.org/licenses/>.
25
26   =========================================================================*/
27
28 #include "vvIntensityValueSlider.h"
29 #include "clitkCommon.h"
30
31 //------------------------------------------------------------------------------
32 vvIntensityValueSlider::vvIntensityValueSlider(QWidget * parent, Qt::WindowFlags f)
33   :QWidget(parent,f),  Ui::vvIntensityValueSlider() 
34 {
35   // GUI Initialization
36   setupUi(this);  
37   mValue = 0;
38   SetMaximum(1000);
39   SetMinimum(-1000);
40   
41   // Connect signals & slots
42   connect(mSpinBox, SIGNAL(valueChanged(double)), this, SLOT(valueChangedFromSpinBox(double)));
43   connect(mSlider, SIGNAL(valueChanged(int)), this, SLOT(valueChangedFromSlider(int)));
44 }
45 //------------------------------------------------------------------------------
46
47
48 //------------------------------------------------------------------------------
49 vvIntensityValueSlider::~vvIntensityValueSlider() {
50   // DD("Delete vvIntensityValueSlider");
51 }
52 //------------------------------------------------------------------------------
53
54
55 //------------------------------------------------------------------------------
56 void vvIntensityValueSlider::valueChangedFromSpinBox(double v) {
57   //  DD("valueChangedFromSpinBox");
58   //   DD(v);
59   mSlider->setValue(v);
60   mValue = v;
61   emit valueChanged(v);
62 }
63 //------------------------------------------------------------------------------
64
65
66 //------------------------------------------------------------------------------
67 void vvIntensityValueSlider::valueChangedFromSlider(int v) {
68   //   DD("valueChangedFromSlider");
69   //   DD(v);
70   //   DD(v*mSliderFactor);
71   mSpinBox->setValue(v*mSliderFactor);
72   //  emit valueChanged(v*mSliderFactor);
73 }
74 //------------------------------------------------------------------------------
75
76
77 //------------------------------------------------------------------------------
78 void vvIntensityValueSlider::SetText(QString t) {
79   mLabel->setText(t);
80 }
81 //------------------------------------------------------------------------------
82
83
84 //------------------------------------------------------------------------------
85 void vvIntensityValueSlider::SetImage(vvImage * im) { 
86   mImage = im; 
87   Update(); 
88 }
89 //------------------------------------------------------------------------------
90
91
92 //------------------------------------------------------------------------------
93 void vvIntensityValueSlider::SetValue(double d) { 
94   mSpinBox->setValue(d);
95 }
96 //------------------------------------------------------------------------------
97
98
99 //------------------------------------------------------------------------------
100 void vvIntensityValueSlider::SetMaximum(double max) {
101   mSlider->setMaximum(max);
102   mSpinBox->setMaximum(max);
103   if (mValue > max) { SetValue(max); }
104   QString tip = QString("Min = %1    Max = %2").arg(mSpinBox->minimum()).arg(max);
105   setToolTip(tip);
106 }
107 //------------------------------------------------------------------------------
108
109
110 //------------------------------------------------------------------------------
111 void vvIntensityValueSlider::SetMinimum(double min) {
112   mSlider->setMinimum(min);
113   mSpinBox->setMinimum(min);
114   if (mValue < min) { SetValue(min); }
115   QString tip = QString("Min = %1    Max = %2").arg(min).arg(mSpinBox->maximum());
116   setToolTip(tip);
117 }
118 //------------------------------------------------------------------------------
119
120
121 //------------------------------------------------------------------------------
122 void vvIntensityValueSlider::Update() {
123   DD(mImage->GetScalarTypeAsString());
124   DD(mImage->GetFirstVTKImageData()->GetScalarTypeMax());
125   DD(mImage->GetFirstVTKImageData()->GetScalarTypeMin());
126
127   // double max = mImage->GetFirstVTKImageData()->GetScalarTypeMax();
128 //   double min = mImage->GetFirstVTKImageData()->GetScalarTypeMin();
129     
130   if (mImage->IsScalarTypeInteger()) {
131
132     mSpinBox->setSingleStep(1.0);
133     mSpinBox->setDecimals(0);
134     mSliderFactor = 1.0;
135
136     double range[2];
137     mImage->GetFirstVTKImageData()->GetScalarRange(range);
138     mMin = range[0];
139     mMax = range[1];
140     DD(mMax);
141     DD(mMin);
142     mSlider->setMaximum(mMax);
143     mSlider->setMinimum(mMin);
144     mSpinBox->setMaximum(mMax);
145     mSpinBox->setMinimum(mMin);
146
147     QString tip = QString("Min = %1    Max = %2").arg(mMin).arg(mMax);
148     setToolTip(tip);
149   }
150   else {
151     std::cerr << "NO floating point image yet !!" << std::endl;
152     exit(0);
153   }
154 }
155
156 //------------------------------------------------------------------------------