1 /*=========================================================================
4 Module: $RCSfile: vvToolImageArithm.cxx,v $
6 Date: $Date: 2010/03/24 13:02:59 $
7 Version: $Revision: 1.1 $
8 Author : David Sarrut (david.sarrut@creatis.insa-lyon.fr)
11 Léon Bérard cancer center http://oncora1.lyon.fnclcc.fr
12 CREATIS 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 "vvToolImageArithm.h"
30 #include "clitkImageArithmGenericFilter.h"
31 #include <QMessageBox>
33 //------------------------------------------------------------------------------
34 // Create the tool and automagically (I like this word) insert it in
35 // the main window menu.
36 ADD_TOOL(vvToolImageArithm);
37 //------------------------------------------------------------------------------
39 //------------------------------------------------------------------------------
40 vvToolImageArithm::vvToolImageArithm(vvMainWindowBase * parent, Qt::WindowFlags f)
41 :vvToolWidgetBase(parent, f),
42 vvToolBase<vvToolImageArithm>(parent),
43 Ui::vvToolImageArithm() {
45 Ui_vvToolImageArithm::setupUi(mToolWidget);
48 mFilter = new clitk::ImageArithmGenericFilter<args_info_clitkImageArithm>;
50 // Set how many inputs are needed for this tool
51 AddInputSelector("Select first image (A)", mFilter);
52 AddInputSelector("Select second image (B)", mFilter, true);
54 //------------------------------------------------------------------------------
57 //------------------------------------------------------------------------------
58 vvToolImageArithm::~vvToolImageArithm() {
60 //------------------------------------------------------------------------------
63 //------------------------------------------------------------------------------
64 void vvToolImageArithm::Initialize() {
65 SetToolName("ImageArithm");
66 SetToolMenuName("ImageArithm");
67 SetToolIconFilename(":/new/prefix1/icons/cross.png");
68 SetToolTip("Perform simple arithmetic operations on one or two images.");
70 //------------------------------------------------------------------------------
73 //------------------------------------------------------------------------------
74 void vvToolImageArithm::InputIsSelected(std::vector<vvSlicerManager *> & l) {
78 mGroupBoxOneInput->setEnabled(false);
79 mGroupBoxTwoInputs->setEnabled(true);
81 //------------------------------------------------------------------------------
84 //------------------------------------------------------------------------------
85 void vvToolImageArithm::InputIsSelected(vvSlicerManager * l) {
88 // DD("Single input");
89 mGroupBoxTwoInputs->setEnabled(false);
90 mGroupBoxOneInput->setEnabled(true);
92 //------------------------------------------------------------------------------
95 //------------------------------------------------------------------------------
96 void vvToolImageArithm::GetArgsInfoFromGUI() {
97 // DD("GetArgsInfoFromGUI");
98 mArgsInfo.input1_given = false;
100 mArgsInfo.input2_given = true;
101 mArgsInfo.input2_arg = new char; // need to indicate that there are two inputs
102 mArgsInfo.scalar_given = false;
103 if (radioButtonSum->isChecked()) mArgsInfo.operation_arg = 0;
104 if (radioButtonMultiply->isChecked()) mArgsInfo.operation_arg = 1;
105 if (radioButtonDivide->isChecked()) mArgsInfo.operation_arg = 2;
106 if (radioButtonMax->isChecked()) mArgsInfo.operation_arg = 3;
107 if (radioButtonMin->isChecked()) mArgsInfo.operation_arg = 4;
108 if (radioButtonAbsDiff->isChecked()) mArgsInfo.operation_arg = 5;
109 if (radioButtonSquaredDiff->isChecked()) mArgsInfo.operation_arg = 6;
112 mArgsInfo.input2_given = false;
113 mArgsInfo.scalar_given = true;
114 if (radioButtonSumV->isChecked()) mArgsInfo.operation_arg = 0;
115 if (radioButtonMultiplyV->isChecked()) mArgsInfo.operation_arg = 1;
116 if (radioButtonInverseV->isChecked()) mArgsInfo.operation_arg = 2;
117 if (radioButtonMaxV->isChecked()) mArgsInfo.operation_arg = 3;
118 if (radioButtonMinV->isChecked()) mArgsInfo.operation_arg = 4;
119 if (radioButtonAbsDiffV->isChecked()) mArgsInfo.operation_arg = 5;
120 if (radioButtonSquaredDiffV->isChecked()) mArgsInfo.operation_arg = 6;
121 if (radioButtonLogV->isChecked()) mArgsInfo.operation_arg = 7;
122 if (radioButtonExpV->isChecked()) mArgsInfo.operation_arg = 8;
123 if (radioButtonSqrtV->isChecked()) mArgsInfo.operation_arg = 9;
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() {
137 if (!mCurrentSlicerManager) close();
138 QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
139 GetArgsInfoFromGUI();
141 std::vector<vvImage::Pointer> inputs;
144 inputs.push_back(mInput1->GetImage());
145 inputs.push_back(mInput2->GetImage());
148 if (inputs[0]->GetScalarTypeAsString() != inputs[1]->GetScalarTypeAsString()) {
149 std::cerr << "Sorry inputs should have the same pixeltype." << std::endl;
150 std::cerr << "Input1 = " << inputs[0]->GetScalarTypeAsString() << std::endl;
151 std::cerr << "Input2 = " << inputs[1]->GetScalarTypeAsString() << std::endl;
152 QApplication::restoreOverrideCursor();
153 QMessageBox::information(this, "Wrong image type","Sorry, could not perform operation. Please select inputs with same pixe type.");
160 inputs.push_back(mInput1->GetImage());
165 clitk::ImageArithmGenericFilter<args_info_clitkImageArithm>::Pointer filter =
166 clitk::ImageArithmGenericFilter<args_info_clitkImageArithm>::New();
167 filter->SetInputVVImages(inputs);
168 filter->SetArgsInfo(mArgsInfo);
169 filter->EnableReadOnDisk(false);
170 filter->EnableOverwriteInputImage(false);
174 vvImage::Pointer output = filter->GetOutputVVImage();
175 std::ostringstream osstream;
176 osstream << "Arithm_" << mArgsInfo.operation_arg << "_ "
177 << mCurrentSlicerManager->GetSlicer(0)->GetFileName() << ".mhd";
178 AddImage(output,osstream.str());
179 QApplication::restoreOverrideCursor();
182 //------------------------------------------------------------------------------