1 /*=========================================================================
2 Program: vv http://www.creatis.insa-lyon.fr/rio/vv
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
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.
13 It is distributed under dual licence
15 - BSD See included LICENSE.txt file
16 - CeCILL-B http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
17 ===========================================================================**/
19 #include "vvToolImageArithm.h"
21 #include "clitkImageArithmGenericFilter.h"
22 #include <QMessageBox>
24 //------------------------------------------------------------------------------
25 // Create the tool and automagically (I like this word) insert it in
26 // the main window menu.
27 ADD_TOOL(vvToolImageArithm);
28 //------------------------------------------------------------------------------
30 //------------------------------------------------------------------------------
31 vvToolImageArithm::vvToolImageArithm(vvMainWindowBase * parent, Qt::WindowFlags f)
32 :vvToolWidgetBase(parent, f),
33 vvToolBase<vvToolImageArithm>(parent),
34 Ui::vvToolImageArithm()
37 Ui_vvToolImageArithm::setupUi(mToolWidget);
40 mFilter = new clitk::ImageArithmGenericFilter<args_info_clitkImageArithm>;
42 // Set how many inputs are needed for this tool
43 AddInputSelector("Select first image (A)", mFilter);
44 AddInputSelector("Select second image (B)", mFilter, true);
46 //------------------------------------------------------------------------------
49 //------------------------------------------------------------------------------
50 vvToolImageArithm::~vvToolImageArithm()
53 //------------------------------------------------------------------------------
56 //------------------------------------------------------------------------------
57 void vvToolImageArithm::Initialize()
59 SetToolName("ImageArithm");
60 SetToolMenuName("ImageArithm");
61 SetToolIconFilename(":/common/icons/arithm.png");
62 SetToolTip("Perform simple arithmetic operations on one or two images.");
63 SetToolExperimental(false);
65 //------------------------------------------------------------------------------
68 //------------------------------------------------------------------------------
69 void vvToolImageArithm::InputIsSelected(std::vector<vvSlicerManager *> & l)
74 mGroupBoxOneInput->setEnabled(false);
75 mGroupBoxTwoInputs->setEnabled(true);
77 //------------------------------------------------------------------------------
80 //------------------------------------------------------------------------------
81 void vvToolImageArithm::InputIsSelected(vvSlicerManager * l)
85 mGroupBoxTwoInputs->setEnabled(false);
86 mGroupBoxOneInput->setEnabled(true);
88 //------------------------------------------------------------------------------
91 //------------------------------------------------------------------------------
92 void vvToolImageArithm::GetArgsInfoFromGUI()
94 mArgsInfo.input1_given = false;
96 mArgsInfo.input2_given = true;
97 mArgsInfo.input2_arg = new char; // need to indicate that there are two inputs
98 mArgsInfo.scalar_given = false;
99 if (radioButtonSum->isChecked()) mArgsInfo.operation_arg = 0;
100 if (radioButtonMultiply->isChecked()) mArgsInfo.operation_arg = 1;
101 if (radioButtonDivide->isChecked()) mArgsInfo.operation_arg = 2;
102 if (radioButtonMax->isChecked()) mArgsInfo.operation_arg = 3;
103 if (radioButtonMin->isChecked()) mArgsInfo.operation_arg = 4;
104 if (radioButtonAbsDiff->isChecked()) mArgsInfo.operation_arg = 5;
105 if (radioButtonSquaredDiff->isChecked()) mArgsInfo.operation_arg = 6;
106 if (radioButtonDifference->isChecked()) mArgsInfo.operation_arg = 7;
107 if (radioButtonRelativeDiff->isChecked()) mArgsInfo.operation_arg = 8;
109 mArgsInfo.input2_given = false;
110 mArgsInfo.scalar_given = true;
111 if (radioButtonSumV->isChecked()) mArgsInfo.operation_arg = 0;
112 if (radioButtonMultiplyV->isChecked()) mArgsInfo.operation_arg = 1;
113 if (radioButtonInverseV->isChecked()) mArgsInfo.operation_arg = 2;
114 if (radioButtonMaxV->isChecked()) mArgsInfo.operation_arg = 3;
115 if (radioButtonMinV->isChecked()) mArgsInfo.operation_arg = 4;
116 if (radioButtonAbsDiffV->isChecked()) mArgsInfo.operation_arg = 5;
117 if (radioButtonSquaredDiffV->isChecked()) mArgsInfo.operation_arg = 6;
118 if (radioButtonLogAlone->isChecked()) mArgsInfo.operation_arg = 7;
119 if (radioButtonExpAlone->isChecked()) mArgsInfo.operation_arg = 8;
120 if (radioButtonSqrtV->isChecked()) mArgsInfo.operation_arg = 9;
121 if (radioButtonDivideV->isChecked()) mArgsInfo.operation_arg = 11;
122 if (radioButtonNormalize->isChecked()) mArgsInfo.operation_arg = 12;
123 if (radioButtonLogV->isChecked()) mArgsInfo.operation_arg = 13;
124 mArgsInfo.scalar_given = true;
125 mArgsInfo.scalar_arg = mValueSpinBox->value();
127 mArgsInfo.output_given = false;
128 mArgsInfo.verbose_flag = false;
129 mArgsInfo.setFloatOutput_flag = mCheckBoxUseFloatOutputType->isChecked();
130 mArgsInfo.imagetypes_flag = false;
132 //------------------------------------------------------------------------------
135 //------------------------------------------------------------------------------
136 void vvToolImageArithm::apply()
138 if (!mCurrentSlicerManager) close();
139 QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
140 GetArgsInfoFromGUI();
142 std::vector<vvImage::Pointer> inputs;
145 inputs.push_back(mInput1->GetImage());
146 inputs.push_back(mInput2->GetImage());
149 if (inputs[0]->GetScalarTypeAsITKString() != inputs[1]->GetScalarTypeAsITKString()) {
150 std::cerr << "Sorry inputs should have the same pixeltype." << std::endl;
151 std::cerr << "Input1 = " << inputs[0]->GetScalarTypeAsITKString() << std::endl;
152 std::cerr << "Input2 = " << inputs[1]->GetScalarTypeAsITKString() << std::endl;
153 QApplication::restoreOverrideCursor();
154 QMessageBox::information(this, "Wrong image type","Sorry, could not perform operation. Please select inputs with same pixel type.");
160 if (!mInput1->GetImage()->HaveSameSizeAndSpacingThan(mInput2->GetImage())) {
161 std::cerr << "Sorry inputs should have the same size and spacing." << std::endl;
162 QApplication::restoreOverrideCursor();
163 QMessageBox::information(this, "Wrong images size","Sorry, could not perform operation. Please select inputs with same size and spacing.");
169 inputs.push_back(mInput1->GetImage());
173 clitk::ImageArithmGenericFilter<args_info_clitkImageArithm>::Pointer filter =
174 clitk::ImageArithmGenericFilter<args_info_clitkImageArithm>::New();
175 filter->SetInputVVImages(inputs);
176 filter->SetArgsInfo(mArgsInfo);
177 filter->EnableReadOnDisk(false);
178 filter->EnableOverwriteInputImage(false);
182 vvImage::Pointer output = filter->GetOutputVVImage();
183 std::ostringstream osstream;
184 osstream << "Arithm_" << mArgsInfo.operation_arg << "_ "
185 << mCurrentSlicerManager->GetSlicer(0)->GetFileName() << ".mhd";
186 AddImage(output,osstream.str());
187 QApplication::restoreOverrideCursor();
190 //------------------------------------------------------------------------------