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 ======================================================================-====*/
18 #include "vvToolImageArithm.h"
20 #include "clitkImageArithmGenericFilter.h"
21 #include <QMessageBox>
23 //------------------------------------------------------------------------------
24 // Create the tool and automagically (I like this word) insert it in
25 // the main window menu.
26 ADD_TOOL(vvToolImageArithm);
27 //------------------------------------------------------------------------------
29 //------------------------------------------------------------------------------
30 vvToolImageArithm::vvToolImageArithm(vvMainWindowBase * parent, Qt::WindowFlags f)
31 :vvToolWidgetBase(parent, f),
32 vvToolBase<vvToolImageArithm>(parent),
33 Ui::vvToolImageArithm() {
35 Ui_vvToolImageArithm::setupUi(mToolWidget);
38 mFilter = new clitk::ImageArithmGenericFilter<args_info_clitkImageArithm>;
40 // Set how many inputs are needed for this tool
41 AddInputSelector("Select first image (A)", mFilter);
42 AddInputSelector("Select second image (B)", mFilter, true);
44 //------------------------------------------------------------------------------
47 //------------------------------------------------------------------------------
48 vvToolImageArithm::~vvToolImageArithm() {
50 //------------------------------------------------------------------------------
53 //------------------------------------------------------------------------------
54 void vvToolImageArithm::Initialize() {
55 SetToolName("ImageArithm");
56 SetToolMenuName("ImageArithm");
57 SetToolIconFilename(":/new/prefix1/icons/cross.png");
58 SetToolTip("Perform simple arithmetic operations on one or two images.");
59 SetToolExperimental(true);
61 //------------------------------------------------------------------------------
64 //------------------------------------------------------------------------------
65 void vvToolImageArithm::InputIsSelected(std::vector<vvSlicerManager *> & l) {
69 mGroupBoxOneInput->setEnabled(false);
70 mGroupBoxTwoInputs->setEnabled(true);
72 //------------------------------------------------------------------------------
75 //------------------------------------------------------------------------------
76 void vvToolImageArithm::InputIsSelected(vvSlicerManager * l) {
79 // DD("Single input");
80 mGroupBoxTwoInputs->setEnabled(false);
81 mGroupBoxOneInput->setEnabled(true);
83 //------------------------------------------------------------------------------
86 //------------------------------------------------------------------------------
87 void vvToolImageArithm::GetArgsInfoFromGUI() {
88 // DD("GetArgsInfoFromGUI");
89 mArgsInfo.input1_given = false;
91 mArgsInfo.input2_given = true;
92 mArgsInfo.input2_arg = new char; // need to indicate that there are two inputs
93 mArgsInfo.scalar_given = false;
94 if (radioButtonSum->isChecked()) mArgsInfo.operation_arg = 0;
95 if (radioButtonMultiply->isChecked()) mArgsInfo.operation_arg = 1;
96 if (radioButtonDivide->isChecked()) mArgsInfo.operation_arg = 2;
97 if (radioButtonMax->isChecked()) mArgsInfo.operation_arg = 3;
98 if (radioButtonMin->isChecked()) mArgsInfo.operation_arg = 4;
99 if (radioButtonAbsDiff->isChecked()) mArgsInfo.operation_arg = 5;
100 if (radioButtonSquaredDiff->isChecked()) mArgsInfo.operation_arg = 6;
103 mArgsInfo.input2_given = false;
104 mArgsInfo.scalar_given = true;
105 if (radioButtonSumV->isChecked()) mArgsInfo.operation_arg = 0;
106 if (radioButtonMultiplyV->isChecked()) mArgsInfo.operation_arg = 1;
107 if (radioButtonInverseV->isChecked()) mArgsInfo.operation_arg = 2;
108 if (radioButtonMaxV->isChecked()) mArgsInfo.operation_arg = 3;
109 if (radioButtonMinV->isChecked()) mArgsInfo.operation_arg = 4;
110 if (radioButtonAbsDiffV->isChecked()) mArgsInfo.operation_arg = 5;
111 if (radioButtonSquaredDiffV->isChecked()) mArgsInfo.operation_arg = 6;
112 if (radioButtonLogV->isChecked()) mArgsInfo.operation_arg = 7;
113 if (radioButtonExpV->isChecked()) mArgsInfo.operation_arg = 8;
114 if (radioButtonSqrtV->isChecked()) mArgsInfo.operation_arg = 9;
115 mArgsInfo.scalar_given = true;
116 mArgsInfo.scalar_arg = mValueSpinBox->value();
118 mArgsInfo.output_given = false;
119 mArgsInfo.verbose_flag = false;
120 mArgsInfo.setFloatOutput_flag = mCheckBoxUseFloatOutputType->isChecked();
121 mArgsInfo.imagetypes_flag = false;
123 //------------------------------------------------------------------------------
126 //------------------------------------------------------------------------------
127 void vvToolImageArithm::apply() {
128 if (!mCurrentSlicerManager) close();
129 QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
130 GetArgsInfoFromGUI();
132 std::vector<vvImage::Pointer> inputs;
135 inputs.push_back(mInput1->GetImage());
136 inputs.push_back(mInput2->GetImage());
139 if (inputs[0]->GetScalarTypeAsString() != inputs[1]->GetScalarTypeAsString()) {
140 std::cerr << "Sorry inputs should have the same pixeltype." << std::endl;
141 std::cerr << "Input1 = " << inputs[0]->GetScalarTypeAsString() << std::endl;
142 std::cerr << "Input2 = " << inputs[1]->GetScalarTypeAsString() << std::endl;
143 QApplication::restoreOverrideCursor();
144 QMessageBox::information(this, "Wrong image type","Sorry, could not perform operation. Please select inputs with same pixe type.");
151 inputs.push_back(mInput1->GetImage());
156 clitk::ImageArithmGenericFilter<args_info_clitkImageArithm>::Pointer filter =
157 clitk::ImageArithmGenericFilter<args_info_clitkImageArithm>::New();
158 filter->SetInputVVImages(inputs);
159 filter->SetArgsInfo(mArgsInfo);
160 filter->EnableReadOnDisk(false);
161 filter->EnableOverwriteInputImage(false);
165 vvImage::Pointer output = filter->GetOutputVVImage();
166 std::ostringstream osstream;
167 osstream << "Arithm_" << mArgsInfo.operation_arg << "_ "
168 << mCurrentSlicerManager->GetSlicer(0)->GetFileName() << ".mhd";
169 AddImage(output,osstream.str());
170 QApplication::restoreOverrideCursor();
173 //------------------------------------------------------------------------------