]> Creatis software - clitk.git/blob - vv/vvOverlayPanel.cxx
Remove Propagation checkbox
[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   fusionShowLegendCheckBox->setChecked(false);
42   
43   connect(subSamplingSpinBox,SIGNAL(editingFinished()),this,SLOT(setVFProperty()));
44   connect(scaleSpinBox,SIGNAL(editingFinished()),this,SLOT(setVFProperty()));
45   connect(lutCheckBox,SIGNAL(clicked()),this,SLOT(setVFProperty()));
46   connect(vfWidthSpinBox,SIGNAL(editingFinished()),this,SLOT(setVFProperty()));
47   connect(vfColorButton,SIGNAL(clicked()),this,SLOT(VFColorChangeRequest()));
48   connect(colorHorizontalSlider,SIGNAL(valueChanged(int)),this,SLOT(setOverlayProperty()));
49   connect(opacityHorizontalSlider,SIGNAL(valueChanged(int)),this,SLOT(setFusionProperty()));
50   connect(thresOpacityHorizontalSlider,SIGNAL(valueChanged(int)),this,SLOT(setFusionProperty()));
51   connect(fusionColorMapComboBox,SIGNAL(currentIndexChanged(int)),this,SLOT(setFusionProperty()));
52   connect(fusionWindowSpinBox,SIGNAL(valueChanged(double)),this,SLOT(setFusionProperty()));
53   connect(fusionLevelSpinBox,SIGNAL(valueChanged(double)),this,SLOT(setFusionProperty()));
54   connect(fusionOpacitySpin,SIGNAL(valueChanged(double)),this,SLOT(setFusionSpinProperty()));
55   connect(fusionThresSpin,SIGNAL(valueChanged(double)),this,SLOT(setFusionSpinProperty()));
56   connect(fusionShowLegendCheckBox,SIGNAL(stateChanged(int)),this,SLOT(setFusionProperty()));
57   connect(overlayWindowSpinBox,SIGNAL(valueChanged(double)),this,SLOT(setOverlayProperty()));
58   connect(overlayLevelSpinBox,SIGNAL(valueChanged(double)),this,SLOT(setOverlayProperty()));
59   connect(overlayLinkCheckBox,SIGNAL(stateChanged(int)),this,SLOT(setOverlayProperty()));
60
61   disableFusionSignals = false;
62 }
63
64 void vvOverlayPanel::getCurrentImageName(QString name)
65 {
66   QString filename = "<b>Current image : </b>";
67   filename += vtksys::SystemTools::GetFilenameWithoutExtension(name.toStdString()).c_str();
68   currentImageLabel->setText(filename.toStdString().c_str());
69 }
70
71 void vvOverlayPanel::getVFProperty(int subsampling, int scale, int log)
72 {
73   if (subsampling != -1) {
74     vFFrame->show();
75     vFFrame->setEnabled(1);
76     subSamplingSpinBox->setEnabled(1);
77     subSamplingSpinBox->setValue(subsampling);
78     scaleSpinBox->setEnabled(1);
79     scaleSpinBox->setValue(scale);
80     lutCheckBox->setEnabled(1);
81     if (log > 0)
82       lutCheckBox->setCheckState(Qt::Checked);
83     else
84       lutCheckBox->setCheckState(Qt::Unchecked);
85   } else {
86     vFFrame->hide();
87     vFFrame->setEnabled(0);
88     subSamplingSpinBox->setEnabled(0);
89     subSamplingSpinBox->setValue(0);
90     scaleSpinBox->setEnabled(0);
91     scaleSpinBox->setValue(0);
92     lutCheckBox->setEnabled(0);
93     lutCheckBox->setCheckState(Qt::Unchecked);
94   }
95 }
96
97 void vvOverlayPanel::getVFName(QString name)
98 {
99   QString filename = "<b>Deformation Field : </b>";
100   filename += vtksys::SystemTools::GetFilenameWithoutExtension(name.toStdString()).c_str();
101   vectorFieldNameLabel->setText(filename.toStdString().c_str());
102 }
103
104 void vvOverlayPanel::setVFProperty()
105 {
106   QColor color(vfColorButton->palette().color(QPalette::Background));
107   emit VFPropertyUpdated(subSamplingSpinBox->value(),
108                          scaleSpinBox->value(),
109                          lutCheckBox->checkState(),
110                          vfWidthSpinBox->value(),
111                          color.redF(), color.greenF(), color.blueF());
112 }
113
114 void vvOverlayPanel::getCurrentVectorInfo(int visibility, double x,double y,double z, double value)
115 {
116   QString motion = "<b>Displacement : </b>";
117   QString motionValue = "<b>Length : </b>";
118   if (visibility) {
119     motion += QString::number(x,'f',1) + " ";
120     motion += QString::number(y,'f',1) + " ";
121     motion += QString::number(z,'f',1) + " ";
122
123     motionValue += QString::number(value,'f',1);
124   }
125   coordinatesLabel->setText(motion);
126   normLabel->setText(motionValue);
127 }
128
129 void vvOverlayPanel::getOverlayName(QString name)
130 {
131   QString filename = "<b>Compare with : </b>";
132   filename += vtksys::SystemTools::GetFilenameWithoutExtension(name.toStdString()).c_str();
133   imageComparedLabel->setText(filename.toStdString().c_str());
134 }
135
136 void vvOverlayPanel::getOverlayProperty(int color, int linked, double window, double level)
137 {
138   if (color > -1) {
139     compareFrame->show();
140     compareFrame->setEnabled(1);
141     colorHorizontalSlider->setEnabled(1);
142     colorHorizontalSlider->setValue(color);
143     overlayLinkCheckBox->setCheckState( (linked)?Qt::Checked:Qt::Unchecked );
144     overlayWindowSpinBox->setValue(window);
145     overlayLevelSpinBox->setValue(level);
146   } else {
147     compareFrame->hide();
148     compareFrame->setEnabled(0);
149     colorHorizontalSlider->setEnabled(0);
150     colorHorizontalSlider->setValue(0);
151   }
152 }
153
154 void vvOverlayPanel::setOverlayProperty()
155 {
156   overlayWindowSpinBox->setEnabled(!overlayLinkCheckBox->checkState());
157   overlayLevelSpinBox->setEnabled(!overlayLinkCheckBox->checkState());
158   emit OverlayPropertyUpdated(colorHorizontalSlider->value(),
159                               overlayLinkCheckBox->checkState(),
160                               overlayWindowSpinBox->value(),
161                               overlayLevelSpinBox->value());
162 }
163
164 void vvOverlayPanel::getCurrentOverlayInfo(int visibility,double valueOver, double valueRef)
165 {
166   QString refValue = "<b>Pixel value in image 1 : </b>";
167   QString overlayValue = "<b>Pixel value in image 2 : </b>";
168   QString diffValue = "<b>Pixel difference : </b>";
169   if (visibility) {
170     refValue += QString::number(valueRef);
171     overlayValue += QString::number(valueOver);
172     diffValue += QString::number(valueRef - valueOver);
173   }
174   refValueLabel->setText(refValue);
175   valueLabel->setText(overlayValue);
176   diffValueLabel->setText(diffValue);
177 }
178 void vvOverlayPanel::getFusionName(QString name)
179 {
180   QString filename = "<b>Fusion with : </b>";
181   filename += vtksys::SystemTools::GetFilenameWithoutExtension(name.toStdString()).c_str();
182   dataFusionnedLabel->setText(filename.toStdString().c_str());
183 }
184
185 void vvOverlayPanel::getFusionProperty(int opacity, int thresOpacity, int colormap, double window, double level)
186 {
187   if (opacity > -1) {
188     //first disable signals generated by each setValue() call
189     disableFusionSignals = true;
190     fusionFrame->show();
191     fusionFrame->setEnabled(1);
192     fusionColorMapComboBox->setEnabled(1);
193     fusionColorMapComboBox->setCurrentIndex(colormap);
194     opacityHorizontalSlider->setEnabled(1);
195     opacityHorizontalSlider->setValue(opacity);
196     thresOpacityHorizontalSlider->setEnabled(1);
197     thresOpacityHorizontalSlider->setValue(thresOpacity);
198     fusionOpacitySpin->setValue(opacity); 
199     fusionThresSpin->setValue(thresOpacity);
200     fusionWindowSpinBox->setEnabled(1);
201     fusionLevelSpinBox->setEnabled(1);
202     fusionWindowSpinBox->setValue(window);
203     fusionLevelSpinBox->setValue(level);
204     
205     // re-enable signals and trigger slot function
206     disableFusionSignals = false;
207     setFusionProperty();
208   } else {
209     fusionFrame->hide();
210     fusionFrame->setEnabled(0);
211     opacityHorizontalSlider->setEnabled(0);
212     opacityHorizontalSlider->setValue(0);
213     thresOpacityHorizontalSlider->setEnabled(0);
214     thresOpacityHorizontalSlider->setValue(0);
215     fusionOpacitySpin->setValue(0); 
216     fusionThresSpin->setValue(0);
217     fusionColorMapComboBox->setEnabled(0);
218     fusionColorMapComboBox->setCurrentIndex(-1);
219     fusionWindowSpinBox->setEnabled(0);
220     fusionLevelSpinBox->setEnabled(0);
221   }
222 }
223
224 void vvOverlayPanel::setFusionProperty()
225 {
226   if (disableFusionSignals)
227     return;
228   
229   fusionOpacitySpin->setValue(opacityHorizontalSlider->value()); 
230   fusionThresSpin->setValue(thresOpacityHorizontalSlider->value());
231
232   emit FusionPropertyUpdated(opacityHorizontalSlider->value(), thresOpacityHorizontalSlider->value(), fusionColorMapComboBox->currentIndex(),
233                              fusionWindowSpinBox->value(), fusionLevelSpinBox->value(), fusionShowLegendCheckBox->isChecked());
234 }
235
236 void vvOverlayPanel::setFusionSpinProperty()
237 {
238   opacityHorizontalSlider->setValue(fusionOpacitySpin->value()); 
239   thresOpacityHorizontalSlider->setValue(fusionThresSpin->value());
240 }
241
242 void vvOverlayPanel::getCurrentFusionInfo(int visibility,double value)
243 {
244   QString fusionValue = "<b>Pixel value in image 2 : </b>";
245   if (visibility) {
246     fusionValue += QString::number(value,'f',1);
247   }
248   valueFusionnedLabel->setText(fusionValue);
249 }
250
251 void vvOverlayPanel::VFColorChangeRequest()
252 {
253   QColor color(vfColorButton->palette().color(QPalette::Background));
254   color = QColorDialog::getColor(color, this, "Choose the new color of the vector field");
255   //vfColorButton->palette().setColor(QPalette::Background, color); SR: Not working?
256   if (color.isValid())
257     vfColorButton->setStyleSheet("* { background-color: " + color.name() + "; border: 0px }");
258   this->setVFProperty();
259 }
260
261
262
263 #endif /* end #define _vvOverlayPanel_CXX */
264