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