1 #ifndef _vvResamplerDialog_CXX
2 #define _vvResamplerDialog_CXX
4 /*=========================================================================
8 Author : David Sarrut (david.sarrut@gmail.com)
11 Léon Bérard cancer center http://oncora1.lyon.fnclcc.fr
12 CREATIS-LRMN http://www.creatis.insa-lyon.fr
14 This program is free software: you can redistribute it and/or modify
15 it under the terms of the GNU General Public License as published by
16 the Free Software Foundation, version 3 of the License.
18 This program is distributed in the hope that it will be useful,
19 but WITHOUT ANY WARRANTY; without even the implied warranty of
20 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 GNU General Public License for more details.
23 You should have received a copy of the GNU General Public License
24 along with this program. If not, see <http://www.gnu.org/licenses/>.
26 =========================================================================*/
28 #include "vvResamplerDialog.h"
29 #include "clitkImageResampleGenericFilter.h"
33 #include <QMessageBox>
35 #define COLUMN_IMAGE_NAME 7
37 //====================================================================
38 vvResamplerDialog::vvResamplerDialog(QWidget * parent, Qt::WindowFlags f)
39 :QDialog(parent,f), Ui::vvResamplerDialog() {
45 // Connect signals & slots
46 connect(this, SIGNAL(accepted()), this, SLOT(Resample()));
47 connect(mImagesComboBox, SIGNAL(currentIndexChanged(QString)), this, SLOT(UpdateCurrentInputImage()));
49 connect(sizeRadioButton, SIGNAL(clicked()), this, SLOT(UpdateControlSizeAndSpacing()));
50 connect(scaleSizeRadioButton, SIGNAL(clicked()), this, SLOT(UpdateControlSizeAndSpacing()));
51 connect(isoSizeRadioButton, SIGNAL(clicked()), this, SLOT(UpdateControlSizeAndSpacing()));
52 connect(spacingRadioButton, SIGNAL(clicked()), this, SLOT(UpdateControlSizeAndSpacing()));
53 connect(scaleSpacingRadioButton, SIGNAL(clicked()), this, SLOT(UpdateControlSizeAndSpacing()));
54 connect(isoSpacingRadioButton, SIGNAL(clicked()), this, SLOT(UpdateControlSizeAndSpacing()));
56 connect(xSizeLineEdit, SIGNAL(textEdited(QString)),this,SLOT(ComputeNewSpacingFromSize()));
57 connect(ySizeLineEdit, SIGNAL(textEdited(QString)),this,SLOT(ComputeNewSpacingFromSize()));
58 connect(zSizeLineEdit, SIGNAL(textEdited(QString)),this,SLOT(ComputeNewSpacingFromSize()));
59 connect(xSpacingLineEdit, SIGNAL(textEdited(QString)),this,SLOT(ComputeNewSizeFromSpacing()));
60 connect(ySpacingLineEdit, SIGNAL(textEdited(QString)),this,SLOT(ComputeNewSizeFromSpacing()));
61 connect(zSpacingLineEdit, SIGNAL(textEdited(QString)),this,SLOT(ComputeNewSizeFromSpacing()));
62 connect(scaleSizeLineEdit,SIGNAL(textEdited(QString)),this,SLOT(ComputeNewSizeFromScale()));
63 connect(scaleSpacingLineEdit,SIGNAL(textEdited(QString)),this,SLOT(ComputeNewSpacingFromScale()));
64 connect(isoSizeLineEdit,SIGNAL(textEdited(QString)),this,SLOT(ComputeNewSizeFromIso()));
65 connect(isoSpacingLineEdit,SIGNAL(textEdited(QString)),this,SLOT(ComputeNewSpacingFromIso()));
67 connect(gaussianFilterCheckBox,SIGNAL(stateChanged(int)),this,SLOT(UpdateGaussianFilter()));
68 connect(interpolationComboBox,SIGNAL(currentIndexChanged(QString)),this,SLOT(UpdateInterpolation()));
70 //====================================================================
72 //====================================================================
73 void vvResamplerDialog::Init() {
76 mInputFileFormat = "";
81 mInputSpacing.resize(0);
82 mInputOrigin.resize(0);
83 mOutputSize.resize(0);
84 mOutputSpacing.resize(0);
86 xSizeLineEdit->setText("");
87 ySizeLineEdit->setText("");
88 zSizeLineEdit->setText("");
89 xSpacingLineEdit->setText("");
90 ySpacingLineEdit->setText("");
91 zSpacingLineEdit->setText("");
92 scaleSizeLineEdit->setText("");
93 scaleSpacingLineEdit->setText("");
95 sizeRadioButton->setChecked(0);
96 scaleSizeRadioButton->setChecked(0);
97 isoSizeRadioButton->setChecked(0);
98 spacingRadioButton->setChecked(0);
99 scaleSpacingRadioButton->setChecked(0);
100 isoSpacingRadioButton->setChecked(0);
102 gaussianFilterCheckBox->setCheckState(Qt::Unchecked);
104 xGaussianLineEdit->hide();
105 yGaussianLineEdit->hide();
106 zGaussianLineEdit->hide();
107 gaussianFilterLabel->hide();
109 bSplineLabel->hide();
110 bSplineOrderSpinBox->hide();
111 bLUTFactorLabel->hide();
116 qPalette.setColor(QPalette::Foreground, QColor(Qt::blue));
117 mInputFormatLabel->setPalette(qPalette);
118 mInputDimLabel->setPalette(qPalette);
119 mInputPixelTypeLabel->setPalette(qPalette);
120 mInputSizeLabel->setPalette(qPalette);
121 mInputSpacingLabel->setPalette(qPalette);
123 UpdateCurrentInputImage();
125 //====================================================================
127 //====================================================================
128 void vvResamplerDialog::UpdateCurrentInputImage() {
129 // Set current image & index
130 mCurrentIndex = mImagesComboBox->currentIndex();
131 if (mCurrentIndex == -1) {
132 mCurrentImage = NULL;
135 mCurrentImage = mSlicerManagers[mCurrentIndex]->GetSlicer(0)->GetImage();
136 if (mCurrentImage.IsNull()) return;
137 mInputFileName = mSlicerManagers[mCurrentIndex]->GetFileName().c_str();
139 // Set current information
140 mPixelType = mCurrentImage->GetScalarTypeAsString().c_str();
141 //ds ComponentType = mCurrentImageGetNumberOfScalarComponents();
142 mDimension = mCurrentImage->GetNumberOfDimensions();
144 // Copy size, spacing ...
145 mInputOrigin.resize(mDimension);
146 mInputSpacing.resize(mDimension);
147 mInputSize.resize(mDimension);
148 for (int i = 0; i < mDimension;i++) {
149 mInputOrigin[i] = mCurrentImage->GetOrigin()[i];
150 mInputSpacing[i] = mCurrentImage->GetSpacing()[i];
151 mInputSize[i] = mCurrentImage->GetSize()[i];
155 mInputFileFormat = itksys::SystemTools::GetFilenameLastExtension(mInputFileName.toStdString()).c_str();
158 mInputFormatLabel->setText(mInputFileFormat);
159 mInputSizeLabel->setText(GetVectorIntAsString(mInputSize));
160 mInputDimLabel->setText(QString::number(mDimension)+"D");
161 mInputSpacingLabel->setText(GetVectorDoubleAsString(mInputSpacing));
162 mInputPixelTypeLabel->setText(mPixelType);
163 mInputMemoryLabel->setText(GetSizeInBytes(mInputSize));
166 scaleSizeRadioButton->setChecked(true);
167 UpdateControlSizeAndSpacing();
168 scaleSizeLineEdit->setText("100");
169 ComputeNewSizeFromScale();
174 //====================================================================
176 //====================================================================
177 void vvResamplerDialog::UpdateOutputInfo() {
178 mOutputSizeLabel->setText(GetVectorIntAsString(mOutputSize));
179 mOutputSpacingLabel->setText(GetVectorDoubleAsString(mOutputSpacing));
180 mOutputMemoryLabel->setText(GetSizeInBytes(mOutputSize));
182 //====================================================================
184 //====================================================================
185 QString vvResamplerDialog::GetSizeInBytes(std::vector<int> & size) {
187 for (unsigned int i=0; i<size.size(); i++) t *= size[i];
188 t *= mCurrentImage->GetScalarSize()*mCurrentImage->GetNumberOfScalarComponents();
189 QString result = QString::number(t);
190 result += " bytes (";
191 if (t > 1000000000) {
193 result += QString::number(t);
196 else if (t > 1000000) {
198 result += QString::number(t);
203 result += QString::number(t);
208 //====================================================================
210 //====================================================================
211 QString vvResamplerDialog::GetVectorDoubleAsString(std::vector<double> vectorDouble) {
213 for (unsigned int i= 0; i<vectorDouble.size(); i++) {
216 result += QString::number(vectorDouble[i]);
220 //====================================================================
222 //====================================================================
223 QString vvResamplerDialog::GetVectorIntAsString(std::vector<int> vectorInt) {
225 for (unsigned int i= 0; i<vectorInt.size(); i++) {
228 result += QString::number(vectorInt[i]);
232 //====================================================================
234 //====================================================================
235 void vvResamplerDialog::FillSizeEdit(std::vector<int> size) {
236 xSizeLineEdit->setText(QString::number(size[0]));
237 ySizeLineEdit->setText(QString::number(size[1]));
239 zSizeLineEdit->setText(QString::number(size[2]));
241 //====================================================================
243 //====================================================================
244 void vvResamplerDialog::FillSpacingEdit(std::vector<double> spacing) {
245 xSpacingLineEdit->setText(QString::number(spacing[0]));
246 ySpacingLineEdit->setText(QString::number(spacing[1]));
247 if (spacing.size() > 2)
248 zSpacingLineEdit->setText(QString::number(spacing[2]));
250 //====================================================================
252 //====================================================================
253 void vvResamplerDialog::UpdateOutputSizeAndSpacing() {
254 mOutputSize.resize(mDimension);
255 mOutputSize = mInputSize;
256 mOutputSpacing.resize(mDimension);
257 mOutputSpacing = mInputSpacing;
258 mOutputSize[0] = (int)xSizeLineEdit->text().toDouble();
259 mOutputSize[1] = (int)ySizeLineEdit->text().toDouble();
261 mOutputSize[2] = (int)zSizeLineEdit->text().toDouble();
263 mOutputSpacing[0] = xSpacingLineEdit->text().toDouble();
264 mOutputSpacing[1] = ySpacingLineEdit->text().toDouble();
266 mOutputSpacing[2] = zSpacingLineEdit->text().toDouble();
270 //====================================================================
272 //====================================================================
273 void vvResamplerDialog::UpdateControlSizeAndSpacing() {
274 scaleSizeLineEdit->setText("");
275 scaleSpacingLineEdit->setText("");
276 isoSizeLineEdit->setText("");
277 isoSpacingLineEdit->setText("");
279 xSizeLineEdit->setReadOnly(1);
280 ySizeLineEdit->setReadOnly(1);
281 zSizeLineEdit->setReadOnly(1);
282 scaleSizeLineEdit->setReadOnly(1);
283 isoSizeLineEdit->setReadOnly(1);
285 xSpacingLineEdit->setReadOnly(1);
286 ySpacingLineEdit->setReadOnly(1);
287 zSpacingLineEdit->setReadOnly(1);
288 scaleSpacingLineEdit->setReadOnly(1);
289 isoSpacingLineEdit->setReadOnly(1);
291 if (sizeRadioButton->isChecked()) {
292 xSizeLineEdit->setReadOnly(0);
293 ySizeLineEdit->setReadOnly(0);
295 zSizeLineEdit->setReadOnly(0);
298 if (spacingRadioButton->isChecked()) {
299 xSpacingLineEdit->setReadOnly(0);
300 ySpacingLineEdit->setReadOnly(0);
302 zSpacingLineEdit->setReadOnly(0);
304 else if (scaleSizeRadioButton->isChecked())
305 scaleSizeLineEdit->setReadOnly(0);
306 else if (scaleSpacingRadioButton->isChecked())
307 scaleSpacingLineEdit->setReadOnly(0);
308 else if (isoSizeRadioButton->isChecked())
309 isoSizeLineEdit->setReadOnly(0);
310 else if (isoSpacingRadioButton->isChecked())
311 isoSpacingLineEdit->setReadOnly(0);
314 //====================================================================
316 //====================================================================
317 void vvResamplerDialog::ComputeNewSpacingFromSize() {
318 double newSpacing = mInputSpacing[0]*mInputSize[0];
319 xSpacingLineEdit->setText(QString::number(newSpacing/xSizeLineEdit->text().toDouble()));
320 newSpacing = mInputSpacing[1]*mInputSize[1];
321 ySpacingLineEdit->setText(QString::number(newSpacing/ySizeLineEdit->text().toDouble()));
324 newSpacing = mInputSpacing[2]*mInputSize[2];
325 zSpacingLineEdit->setText(QString::number(newSpacing/zSizeLineEdit->text().toDouble()));
327 UpdateOutputSizeAndSpacing();
329 //====================================================================
331 //====================================================================
332 void vvResamplerDialog::ComputeNewSizeFromSpacing() {
333 double newSize = mInputSpacing[0]*mInputSize[0];
334 xSizeLineEdit->setText(QString::number(newSize/xSpacingLineEdit->text().toDouble()));
335 newSize = mInputSpacing[1]*mInputSize[1];
336 ySizeLineEdit->setText(QString::number(newSize/ySpacingLineEdit->text().toDouble()));
339 newSize = mInputSpacing[2]*mInputSize[2];
340 zSizeLineEdit->setText(QString::number(newSize/zSpacingLineEdit->text().toDouble()));
342 UpdateOutputSizeAndSpacing();
344 //====================================================================
346 //====================================================================
347 void vvResamplerDialog::ComputeNewSpacingFromScale() {
348 xSpacingLineEdit->setText(QString::number(mInputSpacing[0]*scaleSpacingLineEdit->text().toDouble()/100));
349 ySpacingLineEdit->setText(QString::number(mInputSpacing[1]*scaleSpacingLineEdit->text().toDouble()/100));
351 zSpacingLineEdit->setText(QString::number(mInputSpacing[2]*scaleSpacingLineEdit->text().toDouble()/100));
352 ComputeNewSizeFromSpacing();
354 //====================================================================
356 //====================================================================
357 void vvResamplerDialog::ComputeNewSizeFromScale() {
358 xSizeLineEdit->setText(QString::number(mInputSize[0]*scaleSizeLineEdit->text().toDouble()/100));
359 ySizeLineEdit->setText(QString::number(mInputSize[1]*scaleSizeLineEdit->text().toDouble()/100));
361 zSizeLineEdit->setText(QString::number(mInputSize[2]*scaleSizeLineEdit->text().toDouble()/100));
362 ComputeNewSpacingFromSize();
364 //====================================================================
366 //====================================================================
367 void vvResamplerDialog::ComputeNewSpacingFromIso() {
368 xSpacingLineEdit->setText(QString::number(isoSpacingLineEdit->text().toDouble()));
369 ySpacingLineEdit->setText(QString::number(isoSpacingLineEdit->text().toDouble()));
371 zSpacingLineEdit->setText(QString::number(isoSpacingLineEdit->text().toDouble()));
372 ComputeNewSizeFromSpacing();
374 //====================================================================
376 //====================================================================
377 void vvResamplerDialog::ComputeNewSizeFromIso() {
378 xSizeLineEdit->setText(QString::number(isoSizeLineEdit->text().toDouble()));
379 ySizeLineEdit->setText(QString::number(isoSizeLineEdit->text().toDouble()));
381 zSizeLineEdit->setText(QString::number(isoSizeLineEdit->text().toDouble()));
382 ComputeNewSpacingFromSize();
384 //====================================================================
386 //====================================================================
387 void vvResamplerDialog::UpdateInterpolation() {
388 if (interpolationComboBox->currentText() == "BSpline") {
389 bSplineLabel->show();
390 bSplineOrderSpinBox->show();
391 bLUTFactorLabel->hide();
394 else if (interpolationComboBox->currentText() == "Blut (faster BSpline)") {
395 bSplineLabel->show();
396 bSplineOrderSpinBox->show();
397 bLUTFactorLabel->show();
401 bSplineLabel->hide();
402 bSplineOrderSpinBox->hide();
403 bLUTFactorLabel->hide();
407 //====================================================================
409 //====================================================================
410 void vvResamplerDialog::UpdateGaussianFilter() {
411 if (gaussianFilterCheckBox->isChecked()) {
412 gaussianFilterLabel->show();
413 xGaussianLineEdit->show();
414 yGaussianLineEdit->show();
416 zGaussianLineEdit->show();
419 gaussianFilterLabel->hide();
420 xGaussianLineEdit->hide();
421 yGaussianLineEdit->hide();
422 zGaussianLineEdit->hide();
425 //====================================================================
427 //====================================================================
428 void vvResamplerDialog::SetSlicerManagers(std::vector<vvSlicerManager*> & m,int current_image_index) {
430 for (unsigned int i = 0; i < mSlicerManagers.size(); i++) {
431 mImagesComboBox->addItem(mSlicerManagers[i]->GetFileName().c_str());
433 mImagesComboBox->setCurrentIndex(current_image_index);
435 //====================================================================
437 //====================================================================
438 void vvResamplerDialog::Resample() {
440 // Get resampler options
441 std::vector<double> sigma;
442 sigma.push_back(xGaussianLineEdit->text().toDouble());
443 sigma.push_back(yGaussianLineEdit->text().toDouble());
444 if (mDimension > 2) sigma.push_back(zGaussianLineEdit->text().toDouble());
447 // Create resampler filter
448 clitk::ImageResampleGenericFilter::Pointer filter = clitk::ImageResampleGenericFilter::New();
449 filter->SetOutputSize(mOutputSize);
450 filter->SetOutputSpacing(mOutputSpacing);
451 filter->SetInterpolationName(interpolationComboBox->currentText().toLower().toStdString());
453 if (interpolationComboBox->currentText() == "BSpline")
454 filter->SetBSplineOrder(bSplineOrderSpinBox->value());
455 else if (interpolationComboBox->currentText() == "Blut (faster BSpline)") {
456 filter->SetInterpolationName("blut");
457 filter->SetBSplineOrder(bSplineOrderSpinBox->value());
458 filter->SetBLUTSampling(bLUTSpinBox->value());
460 if (gaussianFilterCheckBox->isChecked())
461 filter->SetGaussianSigma(sigma);
462 // filter->SetOutputFileName(OutputFileName.toStdString());
463 filter->SetDefaultPixelValue(defaultPixelValueLineEdit->text().toDouble());
464 filter->SetInputVVImage(mCurrentImage);
468 mOutput = filter->GetOutputVVImage();
470 //====================================================================
471 std::string vvResamplerDialog::GetOutputFileName()
473 QFileInfo info(mImagesComboBox->currentText());
474 return (info.path().toStdString() + "/resampled_" + info.fileName().toStdString());
477 #endif /* end #define _vvResamplerDialog_CXX */