]> Creatis software - clitk.git/blob - vv/vvIntensityValueSlider.cxx
- binarize tool
[clitk.git] / vv / vvIntensityValueSlider.cxx
1 /*=========================================================================
2
3   Program:   vv
4   Module:    $RCSfile: vvIntensityValueSlider.cxx,v $
5   Language:  C++
6   Date:      $Date: 2010/01/29 13:54:37 $
7   Version:   $Revision: 1.1 $
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   
38   // Connect signals & slots
39   connect(mSpinBox, SIGNAL(valueChanged(double)), this, SLOT(valueChangedFromSpinBox(double)));
40   connect(mSlider, SIGNAL(valueChanged(int)), this, SLOT(valueChangedFromSlider(int)));
41 }
42 //------------------------------------------------------------------------------
43
44
45 //------------------------------------------------------------------------------
46 vvIntensityValueSlider::~vvIntensityValueSlider() {
47   // DD("Delete vvIntensityValueSlider");
48 }
49 //------------------------------------------------------------------------------
50
51
52 //------------------------------------------------------------------------------
53 void vvIntensityValueSlider::valueChangedFromSpinBox(double v) {
54   //  DD("valueChangedFromSpinBox");
55   //   DD(v);
56   mSlider->setValue(v);
57   mValue = v;
58   emit valueChanged(v);
59 }
60 //------------------------------------------------------------------------------
61
62
63 //------------------------------------------------------------------------------
64 void vvIntensityValueSlider::valueChangedFromSlider(int v) {
65   //   DD("valueChangedFromSlider");
66   //   DD(v);
67   //   DD(v*mSliderFactor);
68   mSpinBox->setValue(v*mSliderFactor);
69   //  emit valueChanged(v*mSliderFactor);
70 }
71 //------------------------------------------------------------------------------
72
73
74 //------------------------------------------------------------------------------
75 void vvIntensityValueSlider::SetText(QString t) {
76   mLabel->setText(t);
77 }
78 //------------------------------------------------------------------------------
79
80
81 //------------------------------------------------------------------------------
82 void vvIntensityValueSlider::SetImage(vvImage * im) { 
83   mImage = im; 
84   Update(); 
85 }
86 //------------------------------------------------------------------------------
87
88
89 //------------------------------------------------------------------------------
90 void vvIntensityValueSlider::SetValue(double d) { 
91   mSpinBox->setValue(d);
92 }
93 //------------------------------------------------------------------------------
94
95
96 //------------------------------------------------------------------------------
97 void vvIntensityValueSlider::SetMaximum(double max) {
98   mSlider->setMaximum(max);
99   mSpinBox->setMaximum(max);
100   if (mValue > max) { SetValue(max); }
101   QString tip = QString("Min = %1    Max = %2").arg(mSpinBox->minimum()).arg(max);
102   setToolTip(tip);
103 }
104 //------------------------------------------------------------------------------
105
106
107 //------------------------------------------------------------------------------
108 void vvIntensityValueSlider::SetMinimum(double min) {
109   mSlider->setMinimum(min);
110   mSpinBox->setMinimum(min);
111   if (mValue < min) { SetValue(min); }
112   QString tip = QString("Min = %1    Max = %2").arg(min).arg(mSpinBox->maximum());
113   setToolTip(tip);
114 }
115 //------------------------------------------------------------------------------
116
117
118 //------------------------------------------------------------------------------
119 void vvIntensityValueSlider::Update() {
120   DD(mImage->GetScalarTypeAsString());
121   DD(mImage->GetFirstVTKImageData()->GetScalarTypeMax());
122   DD(mImage->GetFirstVTKImageData()->GetScalarTypeMin());
123
124   // double max = mImage->GetFirstVTKImageData()->GetScalarTypeMax();
125 //   double min = mImage->GetFirstVTKImageData()->GetScalarTypeMin();
126     
127   if (mImage->IsScalarTypeInteger()) {
128
129     mSpinBox->setSingleStep(1.0);
130     mSpinBox->setDecimals(0);
131     mSliderFactor = 1.0;
132
133     double range[2];
134     mImage->GetFirstVTKImageData()->GetScalarRange(range);
135     mMin = range[0];
136     mMax = range[1];
137     DD(mMax);
138     DD(mMin);
139     mSlider->setMaximum(mMax);
140     mSlider->setMinimum(mMin);
141     mSpinBox->setMaximum(mMax);
142     mSpinBox->setMinimum(mMin);
143
144     QString tip = QString("Min = %1    Max = %2").arg(mMin).arg(mMax);
145     setToolTip(tip);
146   }
147   else {
148     std::cerr << "NO floating point image yet !!" << std::endl;
149     exit(0);
150   }
151 }
152
153 //------------------------------------------------------------------------------