1 #ifndef _vvResamplerDialog_CXX
2 #define _vvResamplerDialog_CXX
4 /*=========================================================================
7 Module: $RCSfile: vvResamplerDialog.cxx,v $
9 Date: $Date: 2010/01/06 13:31:58 $
10 Version: $Revision: 1.1 $
11 Author : David Sarrut (david.sarrut@gmail.com)
14 Léon Bérard cancer center http://oncora1.lyon.fnclcc.fr
15 CREATIS-LRMN http://www.creatis.insa-lyon.fr
17 This program is free software: you can redistribute it and/or modify
18 it under the terms of the GNU General Public License as published by
19 the Free Software Foundation, version 3 of the License.
21 This program is distributed in the hope that it will be useful,
22 but WITHOUT ANY WARRANTY; without even the implied warranty of
23 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 GNU General Public License for more details.
26 You should have received a copy of the GNU General Public License
27 along with this program. If not, see <http://www.gnu.org/licenses/>.
29 =========================================================================*/
31 #include "vvResamplerDialog.h"
32 #include "clitkImageResampleGenericFilter.h"
36 #include <QMessageBox>
38 #define COLUMN_IMAGE_NAME 7
40 //====================================================================
41 vvResamplerDialog::vvResamplerDialog(QWidget * parent, Qt::WindowFlags f)
42 :QDialog(parent,f), Ui::vvResamplerDialog() {
48 // Connect signals & slots
49 connect(this, SIGNAL(accepted()), this, SLOT(Resample()));
50 connect(mImagesComboBox, SIGNAL(currentIndexChanged(QString)), this, SLOT(UpdateCurrentInputImage()));
52 connect(sizeRadioButton, SIGNAL(clicked()), this, SLOT(UpdateControlSizeAndSpacing()));
53 connect(scaleSizeRadioButton, SIGNAL(clicked()), this, SLOT(UpdateControlSizeAndSpacing()));
54 connect(isoSizeRadioButton, SIGNAL(clicked()), this, SLOT(UpdateControlSizeAndSpacing()));
55 connect(spacingRadioButton, SIGNAL(clicked()), this, SLOT(UpdateControlSizeAndSpacing()));
56 connect(scaleSpacingRadioButton, SIGNAL(clicked()), this, SLOT(UpdateControlSizeAndSpacing()));
57 connect(isoSpacingRadioButton, SIGNAL(clicked()), this, SLOT(UpdateControlSizeAndSpacing()));
59 connect(xSizeLineEdit, SIGNAL(textEdited(QString)),this,SLOT(ComputeNewSpacingFromSize()));
60 connect(ySizeLineEdit, SIGNAL(textEdited(QString)),this,SLOT(ComputeNewSpacingFromSize()));
61 connect(zSizeLineEdit, SIGNAL(textEdited(QString)),this,SLOT(ComputeNewSpacingFromSize()));
62 connect(xSpacingLineEdit, SIGNAL(textEdited(QString)),this,SLOT(ComputeNewSizeFromSpacing()));
63 connect(ySpacingLineEdit, SIGNAL(textEdited(QString)),this,SLOT(ComputeNewSizeFromSpacing()));
64 connect(zSpacingLineEdit, SIGNAL(textEdited(QString)),this,SLOT(ComputeNewSizeFromSpacing()));
65 connect(scaleSizeLineEdit,SIGNAL(textEdited(QString)),this,SLOT(ComputeNewSizeFromScale()));
66 connect(scaleSpacingLineEdit,SIGNAL(textEdited(QString)),this,SLOT(ComputeNewSpacingFromScale()));
67 connect(isoSizeLineEdit,SIGNAL(textEdited(QString)),this,SLOT(ComputeNewSizeFromIso()));
68 connect(isoSpacingLineEdit,SIGNAL(textEdited(QString)),this,SLOT(ComputeNewSpacingFromIso()));
70 connect(gaussianFilterCheckBox,SIGNAL(stateChanged(int)),this,SLOT(UpdateGaussianFilter()));
71 connect(interpolationComboBox,SIGNAL(currentIndexChanged(QString)),this,SLOT(UpdateInterpolation()));
73 //====================================================================
75 //====================================================================
76 void vvResamplerDialog::Init() {
79 mInputFileFormat = "";
84 mInputSpacing.resize(0);
85 mInputOrigin.resize(0);
86 mOutputSize.resize(0);
87 mOutputSpacing.resize(0);
89 xSizeLineEdit->setText("");
90 ySizeLineEdit->setText("");
91 zSizeLineEdit->setText("");
92 xSpacingLineEdit->setText("");
93 ySpacingLineEdit->setText("");
94 zSpacingLineEdit->setText("");
95 scaleSizeLineEdit->setText("");
96 scaleSpacingLineEdit->setText("");
98 sizeRadioButton->setChecked(0);
99 scaleSizeRadioButton->setChecked(0);
100 isoSizeRadioButton->setChecked(0);
101 spacingRadioButton->setChecked(0);
102 scaleSpacingRadioButton->setChecked(0);
103 isoSpacingRadioButton->setChecked(0);
105 gaussianFilterCheckBox->setCheckState(Qt::Unchecked);
107 xGaussianLineEdit->hide();
108 yGaussianLineEdit->hide();
109 zGaussianLineEdit->hide();
110 gaussianFilterLabel->hide();
112 bSplineLabel->hide();
113 bSplineOrderSpinBox->hide();
114 bLUTFactorLabel->hide();
119 qPalette.setColor(QPalette::Foreground, QColor(Qt::blue));
120 mInputFormatLabel->setPalette(qPalette);
121 mInputDimLabel->setPalette(qPalette);
122 mInputPixelTypeLabel->setPalette(qPalette);
123 mInputSizeLabel->setPalette(qPalette);
124 mInputSpacingLabel->setPalette(qPalette);
126 UpdateCurrentInputImage();
128 //====================================================================
130 //====================================================================
131 void vvResamplerDialog::UpdateCurrentInputImage() {
132 // Set current image & index
133 mCurrentIndex = mImagesComboBox->currentIndex();
134 if (mCurrentIndex == -1) {
135 mCurrentImage = NULL;
138 mCurrentImage = mSlicerManagers[mCurrentIndex]->GetSlicer(0)->GetImage();
139 if (mCurrentImage.IsNull()) return;
140 mInputFileName = mSlicerManagers[mCurrentIndex]->GetFileName().c_str();
142 // Set current information
143 mPixelType = mCurrentImage->GetScalarTypeAsString().c_str();
144 //ds ComponentType = mCurrentImageGetNumberOfScalarComponents();
145 mDimension = mCurrentImage->GetNumberOfDimensions();
147 // Copy size, spacing ...
148 mInputOrigin.resize(mDimension);
149 mInputSpacing.resize(mDimension);
150 mInputSize.resize(mDimension);
151 for (int i = 0; i < mDimension;i++) {
152 mInputOrigin[i] = mCurrentImage->GetOrigin()[i];
153 mInputSpacing[i] = mCurrentImage->GetSpacing()[i];
154 mInputSize[i] = mCurrentImage->GetSize()[i];
158 mInputFileFormat = itksys::SystemTools::GetFilenameLastExtension(mInputFileName.toStdString()).c_str();
161 mInputFormatLabel->setText(mInputFileFormat);
162 mInputSizeLabel->setText(GetVectorIntAsString(mInputSize));
163 mInputDimLabel->setText(QString::number(mDimension)+"D");
164 mInputSpacingLabel->setText(GetVectorDoubleAsString(mInputSpacing));
165 mInputPixelTypeLabel->setText(mPixelType);
166 mInputMemoryLabel->setText(GetSizeInBytes(mInputSize));
169 scaleSizeRadioButton->setChecked(true);
170 UpdateControlSizeAndSpacing();
171 scaleSizeLineEdit->setText("100");
172 ComputeNewSizeFromScale();
177 //====================================================================
179 //====================================================================
180 void vvResamplerDialog::UpdateOutputInfo() {
181 mOutputSizeLabel->setText(GetVectorIntAsString(mOutputSize));
182 mOutputSpacingLabel->setText(GetVectorDoubleAsString(mOutputSpacing));
183 mOutputMemoryLabel->setText(GetSizeInBytes(mOutputSize));
185 //====================================================================
187 //====================================================================
188 QString vvResamplerDialog::GetSizeInBytes(std::vector<int> & size) {
190 for (unsigned int i=0; i<size.size(); i++) t *= size[i];
191 t *= mCurrentImage->GetScalarSize()*mCurrentImage->GetNumberOfScalarComponents();
192 QString result = QString::number(t);
193 result += " bytes (";
194 if (t > 1000000000) {
196 result += QString::number(t);
199 else if (t > 1000000) {
201 result += QString::number(t);
206 result += QString::number(t);
211 //====================================================================
213 //====================================================================
214 QString vvResamplerDialog::GetVectorDoubleAsString(std::vector<double> vectorDouble) {
216 for (unsigned int i= 0; i<vectorDouble.size(); i++) {
219 result += QString::number(vectorDouble[i]);
223 //====================================================================
225 //====================================================================
226 QString vvResamplerDialog::GetVectorIntAsString(std::vector<int> vectorInt) {
228 for (unsigned int i= 0; i<vectorInt.size(); i++) {
231 result += QString::number(vectorInt[i]);
235 //====================================================================
237 //====================================================================
238 void vvResamplerDialog::FillSizeEdit(std::vector<int> size) {
239 xSizeLineEdit->setText(QString::number(size[0]));
240 ySizeLineEdit->setText(QString::number(size[1]));
242 zSizeLineEdit->setText(QString::number(size[2]));
244 //====================================================================
246 //====================================================================
247 void vvResamplerDialog::FillSpacingEdit(std::vector<double> spacing) {
248 xSpacingLineEdit->setText(QString::number(spacing[0]));
249 ySpacingLineEdit->setText(QString::number(spacing[1]));
250 if (spacing.size() > 2)
251 zSpacingLineEdit->setText(QString::number(spacing[2]));
253 //====================================================================
255 //====================================================================
256 void vvResamplerDialog::UpdateOutputSizeAndSpacing() {
257 mOutputSize.resize(mDimension);
258 mOutputSize = mInputSize;
259 mOutputSpacing.resize(mDimension);
260 mOutputSpacing = mInputSpacing;
261 mOutputSize[0] = (int)xSizeLineEdit->text().toDouble();
262 mOutputSize[1] = (int)ySizeLineEdit->text().toDouble();
264 mOutputSize[2] = (int)zSizeLineEdit->text().toDouble();
266 mOutputSpacing[0] = xSpacingLineEdit->text().toDouble();
267 mOutputSpacing[1] = ySpacingLineEdit->text().toDouble();
269 mOutputSpacing[2] = zSpacingLineEdit->text().toDouble();
273 //====================================================================
275 //====================================================================
276 void vvResamplerDialog::UpdateControlSizeAndSpacing() {
277 scaleSizeLineEdit->setText("");
278 scaleSpacingLineEdit->setText("");
279 isoSizeLineEdit->setText("");
280 isoSpacingLineEdit->setText("");
282 xSizeLineEdit->setReadOnly(1);
283 ySizeLineEdit->setReadOnly(1);
284 zSizeLineEdit->setReadOnly(1);
285 scaleSizeLineEdit->setReadOnly(1);
286 isoSizeLineEdit->setReadOnly(1);
288 xSpacingLineEdit->setReadOnly(1);
289 ySpacingLineEdit->setReadOnly(1);
290 zSpacingLineEdit->setReadOnly(1);
291 scaleSpacingLineEdit->setReadOnly(1);
292 isoSpacingLineEdit->setReadOnly(1);
294 if (sizeRadioButton->isChecked()) {
295 xSizeLineEdit->setReadOnly(0);
296 ySizeLineEdit->setReadOnly(0);
298 zSizeLineEdit->setReadOnly(0);
301 if (spacingRadioButton->isChecked()) {
302 xSpacingLineEdit->setReadOnly(0);
303 ySpacingLineEdit->setReadOnly(0);
305 zSpacingLineEdit->setReadOnly(0);
307 else if (scaleSizeRadioButton->isChecked())
308 scaleSizeLineEdit->setReadOnly(0);
309 else if (scaleSpacingRadioButton->isChecked())
310 scaleSpacingLineEdit->setReadOnly(0);
311 else if (isoSizeRadioButton->isChecked())
312 isoSizeLineEdit->setReadOnly(0);
313 else if (isoSpacingRadioButton->isChecked())
314 isoSpacingLineEdit->setReadOnly(0);
317 //====================================================================
319 //====================================================================
320 void vvResamplerDialog::ComputeNewSpacingFromSize() {
321 double newSpacing = mInputSpacing[0]*mInputSize[0];
322 xSpacingLineEdit->setText(QString::number(newSpacing/xSizeLineEdit->text().toDouble()));
323 newSpacing = mInputSpacing[1]*mInputSize[1];
324 ySpacingLineEdit->setText(QString::number(newSpacing/ySizeLineEdit->text().toDouble()));
327 newSpacing = mInputSpacing[2]*mInputSize[2];
328 zSpacingLineEdit->setText(QString::number(newSpacing/zSizeLineEdit->text().toDouble()));
330 UpdateOutputSizeAndSpacing();
332 //====================================================================
334 //====================================================================
335 void vvResamplerDialog::ComputeNewSizeFromSpacing() {
336 double newSize = mInputSpacing[0]*mInputSize[0];
337 xSizeLineEdit->setText(QString::number(newSize/xSpacingLineEdit->text().toDouble()));
338 newSize = mInputSpacing[1]*mInputSize[1];
339 ySizeLineEdit->setText(QString::number(newSize/ySpacingLineEdit->text().toDouble()));
342 newSize = mInputSpacing[2]*mInputSize[2];
343 zSizeLineEdit->setText(QString::number(newSize/zSpacingLineEdit->text().toDouble()));
345 UpdateOutputSizeAndSpacing();
347 //====================================================================
349 //====================================================================
350 void vvResamplerDialog::ComputeNewSpacingFromScale() {
351 xSpacingLineEdit->setText(QString::number(mInputSpacing[0]*scaleSpacingLineEdit->text().toDouble()/100));
352 ySpacingLineEdit->setText(QString::number(mInputSpacing[1]*scaleSpacingLineEdit->text().toDouble()/100));
354 zSpacingLineEdit->setText(QString::number(mInputSpacing[2]*scaleSpacingLineEdit->text().toDouble()/100));
355 ComputeNewSizeFromSpacing();
357 //====================================================================
359 //====================================================================
360 void vvResamplerDialog::ComputeNewSizeFromScale() {
361 xSizeLineEdit->setText(QString::number(mInputSize[0]*scaleSizeLineEdit->text().toDouble()/100));
362 ySizeLineEdit->setText(QString::number(mInputSize[1]*scaleSizeLineEdit->text().toDouble()/100));
364 zSizeLineEdit->setText(QString::number(mInputSize[2]*scaleSizeLineEdit->text().toDouble()/100));
365 ComputeNewSpacingFromSize();
367 //====================================================================
369 //====================================================================
370 void vvResamplerDialog::ComputeNewSpacingFromIso() {
371 xSpacingLineEdit->setText(QString::number(isoSpacingLineEdit->text().toDouble()));
372 ySpacingLineEdit->setText(QString::number(isoSpacingLineEdit->text().toDouble()));
374 zSpacingLineEdit->setText(QString::number(isoSpacingLineEdit->text().toDouble()));
375 ComputeNewSizeFromSpacing();
377 //====================================================================
379 //====================================================================
380 void vvResamplerDialog::ComputeNewSizeFromIso() {
381 xSizeLineEdit->setText(QString::number(isoSizeLineEdit->text().toDouble()));
382 ySizeLineEdit->setText(QString::number(isoSizeLineEdit->text().toDouble()));
384 zSizeLineEdit->setText(QString::number(isoSizeLineEdit->text().toDouble()));
385 ComputeNewSpacingFromSize();
387 //====================================================================
389 //====================================================================
390 void vvResamplerDialog::UpdateInterpolation() {
391 if (interpolationComboBox->currentText() == "BSpline") {
392 bSplineLabel->show();
393 bSplineOrderSpinBox->show();
394 bLUTFactorLabel->hide();
397 else if (interpolationComboBox->currentText() == "Blut (faster BSpline)") {
398 bSplineLabel->show();
399 bSplineOrderSpinBox->show();
400 bLUTFactorLabel->show();
404 bSplineLabel->hide();
405 bSplineOrderSpinBox->hide();
406 bLUTFactorLabel->hide();
410 //====================================================================
412 //====================================================================
413 void vvResamplerDialog::UpdateGaussianFilter() {
414 if (gaussianFilterCheckBox->isChecked()) {
415 gaussianFilterLabel->show();
416 xGaussianLineEdit->show();
417 yGaussianLineEdit->show();
419 zGaussianLineEdit->show();
422 gaussianFilterLabel->hide();
423 xGaussianLineEdit->hide();
424 yGaussianLineEdit->hide();
425 zGaussianLineEdit->hide();
428 //====================================================================
430 //====================================================================
431 void vvResamplerDialog::SetSlicerManagers(std::vector<vvSlicerManager*> & m,int current_image_index) {
433 for (unsigned int i = 0; i < mSlicerManagers.size(); i++) {
434 mImagesComboBox->addItem(mSlicerManagers[i]->GetFileName().c_str());
436 mImagesComboBox->setCurrentIndex(current_image_index);
438 //====================================================================
440 //====================================================================
441 void vvResamplerDialog::Resample() {
443 // Get resampler options
444 std::vector<double> sigma;
445 sigma.push_back(xGaussianLineEdit->text().toDouble());
446 sigma.push_back(yGaussianLineEdit->text().toDouble());
447 if (mDimension > 2) sigma.push_back(zGaussianLineEdit->text().toDouble());
450 // Create resampler filter
451 clitk::ImageResampleGenericFilter::Pointer filter = clitk::ImageResampleGenericFilter::New();
452 filter->SetOutputSize(mOutputSize);
453 filter->SetOutputSpacing(mOutputSpacing);
454 filter->SetInterpolationName(interpolationComboBox->currentText().toLower().toStdString());
456 if (interpolationComboBox->currentText() == "BSpline")
457 filter->SetBSplineOrder(bSplineOrderSpinBox->value());
458 else if (interpolationComboBox->currentText() == "Blut (faster BSpline)") {
459 filter->SetInterpolationName("blut");
460 filter->SetBSplineOrder(bSplineOrderSpinBox->value());
461 filter->SetBLUTSampling(bLUTSpinBox->value());
463 if (gaussianFilterCheckBox->isChecked())
464 filter->SetGaussianSigma(sigma);
465 // filter->SetOutputFileName(OutputFileName.toStdString());
466 filter->SetDefaultPixelValue(defaultPixelValueLineEdit->text().toDouble());
467 filter->SetInputVVImage(mCurrentImage);
471 mOutput = filter->GetOutputVVImage();
473 //====================================================================
474 std::string vvResamplerDialog::GetOutputFileName()
476 QFileInfo info(mImagesComboBox->currentText());
477 return (info.path().toStdString() + "/resampled_" + info.fileName().toStdString());
480 #endif /* end #define _vvResamplerDialog_CXX */