]> Creatis software - clitk.git/blob - vv/vvOverlayPanel.cxx
solved bug 519 (Fusion flickering)
[clitk.git] / vv / vvOverlayPanel.cxx
1 /*=========================================================================
2   Program:   vv                     http://www.creatis.insa-lyon.fr/rio/vv
3
4   Authors belong to:
5   - University of LYON              http://www.universite-lyon.fr/
6   - Léon Bérard cancer center       http://www.centreleonberard.fr
7   - CREATIS CNRS laboratory         http://www.creatis.insa-lyon.fr
8
9   This software is distributed WITHOUT ANY WARRANTY; without even
10   the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
11   PURPOSE.  See the copyright notices for more information.
12
13   It is distributed under dual licence
14
15   - BSD        See included LICENSE.txt file
16   - CeCILL-B   http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
17 ===========================================================================**/
18 #ifndef _vvOverlayPanel_CXX
19 #define _vvOverlayPanel_CXX
20 #include "vvOverlayPanel.h"
21
22 #include <QtGui>
23 #include <Qt>
24 #include "QTreePushButton.h"
25 #include <QColorDialog>
26
27 #include <vtksys/SystemTools.hxx>
28
29 //====================================================================
30 vvOverlayPanel::vvOverlayPanel(QWidget * parent):QWidget(parent)
31 {
32   setupUi(this);
33
34   vFFrame->hide();
35   compareFrame->hide();
36   fusionFrame->hide();
37   subSamplingSpinBox->setEnabled(0);
38   scaleSpinBox->setEnabled(0);
39   lutCheckBox->hide();
40   lutCheckBox->setEnabled(0);
41   connect(subSamplingSpinBox,SIGNAL(editingFinished()),this,SLOT(setVFProperty()));
42   connect(scaleSpinBox,SIGNAL(editingFinished()),this,SLOT(setVFProperty()));
43   connect(lutCheckBox,SIGNAL(clicked()),this,SLOT(setVFProperty()));
44   connect(vfWidthSpinBox,SIGNAL(editingFinished()),this,SLOT(setVFProperty()));
45   connect(vfColorButton,SIGNAL(clicked()),this,SLOT(VFColorChangeRequest()));
46   connect(colorHorizontalSlider,SIGNAL(valueChanged(int)),this,SLOT(setOverlayProperty()));
47   connect(opacityHorizontalSlider,SIGNAL(valueChanged(int)),this,SLOT(setFusionProperty()));
48   connect(thresOpacityHorizontalSlider,SIGNAL(valueChanged(int)),this,SLOT(setFusionProperty()));
49   connect(fusionColorMapComboBox,SIGNAL(currentIndexChanged(int)),this,SLOT(setFusionProperty()));
50   connect(windowSpinBox,SIGNAL(valueChanged(double)),this,SLOT(setFusionProperty()));
51   connect(levelSpinBox,SIGNAL(valueChanged(double)),this,SLOT(setFusionProperty()));
52   
53   disableFusionSignals = false;
54 }
55
56 void vvOverlayPanel::getCurrentImageName(QString name)
57 {
58   QString filename = "<b>Current image : </b>";
59   filename += vtksys::SystemTools::GetFilenameWithoutExtension(name.toStdString()).c_str();
60   currentImageLabel->setText(filename.toStdString().c_str());
61 }
62
63 void vvOverlayPanel::getVFProperty(int subsampling, int scale, int log)
64 {
65   if (subsampling != -1) {
66     vFFrame->show();
67     vFFrame->setEnabled(1);
68     subSamplingSpinBox->setEnabled(1);
69     subSamplingSpinBox->setValue(subsampling);
70     scaleSpinBox->setEnabled(1);
71     scaleSpinBox->setValue(scale);
72     lutCheckBox->setEnabled(1);
73     if (log > 0)
74       lutCheckBox->setCheckState(Qt::Checked);
75     else
76       lutCheckBox->setCheckState(Qt::Unchecked);
77   } else {
78     vFFrame->hide();
79     vFFrame->setEnabled(0);
80     subSamplingSpinBox->setEnabled(0);
81     subSamplingSpinBox->setValue(0);
82     scaleSpinBox->setEnabled(0);
83     scaleSpinBox->setValue(0);
84     lutCheckBox->setEnabled(0);
85     lutCheckBox->setCheckState(Qt::Unchecked);
86   }
87 }
88
89 void vvOverlayPanel::getVFName(QString name)
90 {
91   QString filename = "<b>Deformation Field : </b>";
92   filename += vtksys::SystemTools::GetFilenameWithoutExtension(name.toStdString()).c_str();
93   vectorFieldNameLabel->setText(filename.toStdString().c_str());
94 }
95
96 void vvOverlayPanel::setVFProperty()
97 {
98   QColor color(vfColorButton->palette().color(QPalette::Background));
99   emit VFPropertyUpdated(subSamplingSpinBox->value(),
100                          scaleSpinBox->value(),
101                          lutCheckBox->checkState(),
102                          vfWidthSpinBox->value(),
103                          color.redF(), color.greenF(), color.blueF());
104 }
105
106 void vvOverlayPanel::getCurrentVectorInfo(int visibility, double x,double y,double z, double value)
107 {
108   QString motion = "<b>Displacement : </b>";
109   QString motionValue = "<b>Length : </b>";
110   if (visibility) {
111     motion += QString::number(x,'f',1) + " ";
112     motion += QString::number(y,'f',1) + " ";
113     motion += QString::number(z,'f',1) + " ";
114
115     motionValue += QString::number(value,'f',1);
116   }
117   coordinatesLabel->setText(motion);
118   normLabel->setText(motionValue);
119 }
120
121 void vvOverlayPanel::getOverlayName(QString name)
122 {
123   QString filename = "<b>Compare with : </b>";
124   filename += vtksys::SystemTools::GetFilenameWithoutExtension(name.toStdString()).c_str();
125   imageComparedLabel->setText(filename.toStdString().c_str());
126 }
127
128 void vvOverlayPanel::getOverlayProperty(int value)
129 {
130   if (value > -1) {
131     compareFrame->show();
132     compareFrame->setEnabled(1);
133     colorHorizontalSlider->setEnabled(1);
134     colorHorizontalSlider->setValue(value);
135   } else {
136     compareFrame->hide();
137     compareFrame->setEnabled(0);
138     colorHorizontalSlider->setEnabled(0);
139     colorHorizontalSlider->setValue(0);
140   }
141 }
142
143 void vvOverlayPanel::setOverlayProperty()
144 {
145   emit OverlayPropertyUpdated(colorHorizontalSlider->value());
146 }
147
148 void vvOverlayPanel::getCurrentOverlayInfo(int visibility,double valueOver, double valueRef)
149 {
150   QString refValue = "<b>Pixel value in image 1 : </b>";
151   QString overlayValue = "<b>Pixel value in image 2 : </b>";
152   QString diffValue = "<b>Pixel difference : </b>";
153   if (visibility) {
154     refValue += QString::number(valueRef);
155     overlayValue += QString::number(valueOver);
156     diffValue += QString::number(valueRef - valueOver);
157   }
158   refValueLabel->setText(refValue);
159   valueLabel->setText(overlayValue);
160   diffValueLabel->setText(diffValue);
161 }
162 void vvOverlayPanel::getFusionName(QString name)
163 {
164   QString filename = "<b>Fusion with : </b>";
165   filename += vtksys::SystemTools::GetFilenameWithoutExtension(name.toStdString()).c_str();
166   dataFusionnedLabel->setText(filename.toStdString().c_str());
167 }
168
169 void vvOverlayPanel::getFusionProperty(int opacity, int thresOpacity, int colormap, double window, double level)
170 {
171   if (opacity > -1) {
172     //first disable signals generated by each setValue() call
173     disableFusionSignals = true;
174     fusionFrame->show();
175     fusionFrame->setEnabled(1);
176     fusionColorMapComboBox->setEnabled(1);
177     fusionColorMapComboBox->setCurrentIndex(colormap);
178     opacityHorizontalSlider->setEnabled(1);
179     opacityHorizontalSlider->setValue(opacity);
180     thresOpacityHorizontalSlider->setEnabled(1);
181     thresOpacityHorizontalSlider->setValue(thresOpacity);
182     windowSpinBox->setEnabled(1);
183     levelSpinBox->setEnabled(1);
184     windowSpinBox->setValue(window);
185     levelSpinBox->setValue(level);
186     
187     // re-enable signals and trigger slot function
188     disableFusionSignals = false;
189     setFusionProperty();
190   } else {
191     fusionFrame->hide();
192     fusionFrame->setEnabled(0);
193     opacityHorizontalSlider->setEnabled(0);
194     opacityHorizontalSlider->setValue(0);
195     thresOpacityHorizontalSlider->setEnabled(0);
196     thresOpacityHorizontalSlider->setValue(0);
197     fusionColorMapComboBox->setEnabled(0);
198     fusionColorMapComboBox->setCurrentIndex(-1);
199     windowSpinBox->setEnabled(0);
200     levelSpinBox->setEnabled(0);
201   }
202 }
203
204 void vvOverlayPanel::setFusionProperty()
205 {
206   if (disableFusionSignals)
207     return;
208   
209   emit FusionPropertyUpdated(opacityHorizontalSlider->value(), thresOpacityHorizontalSlider->value(), fusionColorMapComboBox->currentIndex(),
210                              windowSpinBox->value(), levelSpinBox->value());
211 }
212
213 void vvOverlayPanel::getCurrentFusionInfo(int visibility,double value)
214 {
215   QString fusionValue = "<b>Pixel value in image 2 : </b>";
216   if (visibility) {
217     fusionValue += QString::number(value,'f',1);
218   }
219   valueFusionnedLabel->setText(fusionValue);
220 }
221
222 void vvOverlayPanel::VFColorChangeRequest()
223 {
224   QColor color(vfColorButton->palette().color(QPalette::Background));
225   color = QColorDialog::getColor(color, this, "Choose the new color of the vector field");
226   //vfColorButton->palette().setColor(QPalette::Background, color); SR: Not working?
227   vfColorButton->setStyleSheet("* { background-color: " + color.name() + "; border: 0px }");
228   this->setVFProperty();
229 }
230
231 #endif /* end #define _vvOverlayPanel_CXX */
232