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