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