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://oncora1.lyon.fnclcc.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() {
36 Ui_vvToolImageArithm::setupUi(mToolWidget);
39 mFilter = new clitk::ImageArithmGenericFilter<args_info_clitkImageArithm>;
41 // Set how many inputs are needed for this tool
42 AddInputSelector("Select first image (A)", mFilter);
43 AddInputSelector("Select second image (B)", mFilter, true);
45 //------------------------------------------------------------------------------
48 //------------------------------------------------------------------------------
49 vvToolImageArithm::~vvToolImageArithm() {
51 //------------------------------------------------------------------------------
54 //------------------------------------------------------------------------------
55 void vvToolImageArithm::Initialize() {
56 SetToolName("ImageArithm");
57 SetToolMenuName("ImageArithm");
58 SetToolIconFilename(":/common/icons/arithm.png");
59 SetToolTip("Perform simple arithmetic operations on one or two images.");
60 SetToolExperimental(false);
62 //------------------------------------------------------------------------------
65 //------------------------------------------------------------------------------
66 void vvToolImageArithm::InputIsSelected(std::vector<vvSlicerManager *> & l) {
70 mGroupBoxOneInput->setEnabled(false);
71 mGroupBoxTwoInputs->setEnabled(true);
73 //------------------------------------------------------------------------------
76 //------------------------------------------------------------------------------
77 void vvToolImageArithm::InputIsSelected(vvSlicerManager * l) {
80 // DD("Single input");
81 mGroupBoxTwoInputs->setEnabled(false);
82 mGroupBoxOneInput->setEnabled(true);
84 //------------------------------------------------------------------------------
87 //------------------------------------------------------------------------------
88 void vvToolImageArithm::GetArgsInfoFromGUI() {
89 // DD("GetArgsInfoFromGUI");
90 mArgsInfo.input1_given = false;
92 mArgsInfo.input2_given = true;
93 mArgsInfo.input2_arg = new char; // need to indicate that there are two inputs
94 mArgsInfo.scalar_given = false;
95 if (radioButtonSum->isChecked()) mArgsInfo.operation_arg = 0;
96 if (radioButtonMultiply->isChecked()) mArgsInfo.operation_arg = 1;
97 if (radioButtonDivide->isChecked()) mArgsInfo.operation_arg = 2;
98 if (radioButtonMax->isChecked()) mArgsInfo.operation_arg = 3;
99 if (radioButtonMin->isChecked()) mArgsInfo.operation_arg = 4;
100 if (radioButtonAbsDiff->isChecked()) mArgsInfo.operation_arg = 5;
101 if (radioButtonSquaredDiff->isChecked()) mArgsInfo.operation_arg = 6;
104 mArgsInfo.input2_given = false;
105 mArgsInfo.scalar_given = true;
106 if (radioButtonSumV->isChecked()) mArgsInfo.operation_arg = 0;
107 if (radioButtonMultiplyV->isChecked()) mArgsInfo.operation_arg = 1;
108 if (radioButtonInverseV->isChecked()) mArgsInfo.operation_arg = 2;
109 if (radioButtonMaxV->isChecked()) mArgsInfo.operation_arg = 3;
110 if (radioButtonMinV->isChecked()) mArgsInfo.operation_arg = 4;
111 if (radioButtonAbsDiffV->isChecked()) mArgsInfo.operation_arg = 5;
112 if (radioButtonSquaredDiffV->isChecked()) mArgsInfo.operation_arg = 6;
113 if (radioButtonLogV->isChecked()) mArgsInfo.operation_arg = 7;
114 if (radioButtonExpV->isChecked()) mArgsInfo.operation_arg = 8;
115 if (radioButtonSqrtV->isChecked()) mArgsInfo.operation_arg = 9;
116 mArgsInfo.scalar_given = true;
117 mArgsInfo.scalar_arg = mValueSpinBox->value();
119 mArgsInfo.output_given = false;
120 mArgsInfo.verbose_flag = false;
121 mArgsInfo.setFloatOutput_flag = mCheckBoxUseFloatOutputType->isChecked();
122 mArgsInfo.imagetypes_flag = false;
124 //------------------------------------------------------------------------------
127 //------------------------------------------------------------------------------
128 void vvToolImageArithm::apply() {
129 if (!mCurrentSlicerManager) close();
130 QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
131 GetArgsInfoFromGUI();
133 std::vector<vvImage::Pointer> inputs;
136 inputs.push_back(mInput1->GetImage());
137 inputs.push_back(mInput2->GetImage());
140 if (inputs[0]->GetScalarTypeAsString() != inputs[1]->GetScalarTypeAsString()) {
141 std::cerr << "Sorry inputs should have the same pixeltype." << std::endl;
142 std::cerr << "Input1 = " << inputs[0]->GetScalarTypeAsString() << std::endl;
143 std::cerr << "Input2 = " << inputs[1]->GetScalarTypeAsString() << std::endl;
144 QApplication::restoreOverrideCursor();
145 QMessageBox::information(this, "Wrong image type","Sorry, could not perform operation. Please select inputs with same pixe type.");
152 inputs.push_back(mInput1->GetImage());
157 clitk::ImageArithmGenericFilter<args_info_clitkImageArithm>::Pointer filter =
158 clitk::ImageArithmGenericFilter<args_info_clitkImageArithm>::New();
159 filter->SetInputVVImages(inputs);
160 filter->SetArgsInfo(mArgsInfo);
161 filter->EnableReadOnDisk(false);
162 filter->EnableOverwriteInputImage(false);
166 vvImage::Pointer output = filter->GetOutputVVImage();
167 std::ostringstream osstream;
168 osstream << "Arithm_" << mArgsInfo.operation_arg << "_ "
169 << mCurrentSlicerManager->GetSlicer(0)->GetFileName() << ".mhd";
170 AddImage(output,osstream.str());
171 QApplication::restoreOverrideCursor();
174 //------------------------------------------------------------------------------