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