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