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