--- /dev/null
+<?xml version="1.0" encoding="UTF-8"?>
+<ui version="4.0">
+ <class>vvToolImageArithm</class>
+ <widget class="QWidget" name="vvToolImageArithm">
+ <property name="geometry">
+ <rect>
+ <x>0</x>
+ <y>0</y>
+ <width>424</width>
+ <height>345</height>
+ </rect>
+ </property>
+ <property name="windowTitle">
+ <string>Form</string>
+ </property>
+ <layout class="QVBoxLayout" name="verticalLayout_3">
+ <item>
+ <layout class="QHBoxLayout" name="horizontalLayout_2">
+ <item>
+ <spacer name="horizontalSpacer">
+ <property name="orientation">
+ <enum>Qt::Horizontal</enum>
+ </property>
+ <property name="sizeHint" stdset="0">
+ <size>
+ <width>40</width>
+ <height>20</height>
+ </size>
+ </property>
+ </spacer>
+ </item>
+ <item>
+ <widget class="QCheckBox" name="mCheckBoxUseFloatOutputType">
+ <property name="text">
+ <string>Set output pixel type to float</string>
+ </property>
+ <property name="checked">
+ <bool>false</bool>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <spacer name="horizontalSpacer_2">
+ <property name="orientation">
+ <enum>Qt::Horizontal</enum>
+ </property>
+ <property name="sizeHint" stdset="0">
+ <size>
+ <width>40</width>
+ <height>20</height>
+ </size>
+ </property>
+ </spacer>
+ </item>
+ </layout>
+ </item>
+ <item>
+ <layout class="QHBoxLayout" name="horizontalLayout_3">
+ <item>
+ <widget class="QGroupBox" name="mGroupBoxTwoInputs">
+ <property name="title">
+ <string>Operation with two images</string>
+ </property>
+ <layout class="QVBoxLayout" name="verticalLayout">
+ <item>
+ <widget class="QRadioButton" name="radioButtonSum">
+ <property name="text">
+ <string>Sum A+B</string>
+ </property>
+ <property name="checked">
+ <bool>true</bool>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QRadioButton" name="radioButtonMultiply">
+ <property name="text">
+ <string>Multiply A*B</string>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QRadioButton" name="radioButtonDivide">
+ <property name="text">
+ <string>Divide A/B</string>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QRadioButton" name="radioButtonMin">
+ <property name="text">
+ <string>Min [A,B]</string>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QRadioButton" name="radioButtonMax">
+ <property name="text">
+ <string>Max [A,B]</string>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QRadioButton" name="radioButtonAbsDiff">
+ <property name="text">
+ <string>Absolute difference |A-B|</string>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QRadioButton" name="radioButtonSquaredDiff">
+ <property name="text">
+ <string>Squared difference (A-B)²</string>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </widget>
+ </item>
+ <item>
+ <widget class="QGroupBox" name="mGroupBoxOneInput">
+ <property name="title">
+ <string>Operation on a single image</string>
+ </property>
+ <layout class="QVBoxLayout" name="verticalLayout_2">
+ <item>
+ <layout class="QHBoxLayout" name="horizontalLayout">
+ <item>
+ <widget class="QLabel" name="mLabelInputInfo">
+ <property name="font">
+ <font>
+ <pointsize>11</pointsize>
+ <weight>50</weight>
+ <bold>false</bold>
+ </font>
+ </property>
+ <property name="frameShape">
+ <enum>QFrame::NoFrame</enum>
+ </property>
+ <property name="text">
+ <string>Value (v)</string>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QDoubleSpinBox" name="mValueSpinBox">
+ <property name="maximum">
+ <double>999999999.000000000000000</double>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </item>
+ <item>
+ <widget class="QRadioButton" name="radioButtonSumV">
+ <property name="text">
+ <string>Sum A(x)+v</string>
+ </property>
+ <property name="checked">
+ <bool>true</bool>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QRadioButton" name="radioButtonMultiplyV">
+ <property name="text">
+ <string>Multiply A(x)*v</string>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QRadioButton" name="radioButtonInverseV">
+ <property name="text">
+ <string>Inverse v/A(x)</string>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QRadioButton" name="radioButtonMaxV">
+ <property name="text">
+ <string>Max [ A(x), v ]</string>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QRadioButton" name="radioButtonMinV">
+ <property name="text">
+ <string>Min [ A(x),v ]</string>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QRadioButton" name="radioButtonAbsDiffV">
+ <property name="text">
+ <string>Absolute difference |A(x)-v|</string>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QRadioButton" name="radioButtonSquaredDiffV">
+ <property name="text">
+ <string>Squared difference (A(x)-v)²</string>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QRadioButton" name="radioButtonLogV">
+ <property name="text">
+ <string>Log A(x) (don't use v)</string>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QRadioButton" name="radioButtonExpV">
+ <property name="text">
+ <string>Exp A(x) (don't use v)</string>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QRadioButton" name="radioButtonSqrtV">
+ <property name="text">
+ <string>Sqrt A(x) (don't use v)</string>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </widget>
+ </item>
+ </layout>
+ </item>
+ </layout>
+ </widget>
+ <resources/>
+ <connections/>
+</ui>
--- /dev/null
+/*=========================================================================
+
+ Program: vv
+ Module: $RCSfile: vvToolImageArithm.cxx,v $
+ Language: C++
+ Date: $Date: 2010/03/24 13:02:59 $
+ Version: $Revision: 1.1 $
+ Author : David Sarrut (david.sarrut@creatis.insa-lyon.fr)
+
+ Copyright (C) 2010
+ Léon Bérard cancer center http://oncora1.lyon.fnclcc.fr
+ CREATIS http://www.creatis.insa-lyon.fr
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, version 3 of the License.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+ =========================================================================*/
+
+#include "vvToolImageArithm.h"
+#include "vvSlicer.h"
+#include "clitkImageArithmGenericFilter.h"
+#include <QMessageBox>
+
+//------------------------------------------------------------------------------
+// Create the tool and automagically (I like this word) insert it in
+// the main window menu.
+ADD_TOOL(vvToolImageArithm);
+//------------------------------------------------------------------------------
+
+//------------------------------------------------------------------------------
+vvToolImageArithm::vvToolImageArithm(vvMainWindowBase * parent, Qt::WindowFlags f)
+ :vvToolWidgetBase(parent, f),
+ vvToolBase<vvToolImageArithm>(parent),
+ Ui::vvToolImageArithm() {
+ // Setup the UI
+ Ui_vvToolImageArithm::setupUi(mToolWidget);
+
+ // Main filter
+ mFilter = new clitk::ImageArithmGenericFilter<args_info_clitkImageArithm>;
+
+ // Set how many inputs are needed for this tool
+ AddInputSelector("Select first image (A)", mFilter);
+ AddInputSelector("Select second image (B)", mFilter, true);
+}
+//------------------------------------------------------------------------------
+
+
+//------------------------------------------------------------------------------
+vvToolImageArithm::~vvToolImageArithm() {
+}
+//------------------------------------------------------------------------------
+
+
+//------------------------------------------------------------------------------
+void vvToolImageArithm::Initialize() {
+ SetToolName("ImageArithm");
+ SetToolMenuName("ImageArithm");
+ SetToolIconFilename(":/new/prefix1/icons/cross.png");
+ SetToolTip("Perform simple arithmetic operations on one or two images.");
+}
+//------------------------------------------------------------------------------
+
+
+//------------------------------------------------------------------------------
+void vvToolImageArithm::InputIsSelected(std::vector<vvSlicerManager *> & l) {
+ mInput1 = l[0];
+ mInput2 = l[1];
+ mTwoInputs = true;
+ mGroupBoxOneInput->setEnabled(false);
+ mGroupBoxTwoInputs->setEnabled(true);
+}
+//------------------------------------------------------------------------------
+
+
+//------------------------------------------------------------------------------
+void vvToolImageArithm::InputIsSelected(vvSlicerManager * l) {
+ mInput1 = l;
+ mTwoInputs = false;
+ // DD("Single input");
+ mGroupBoxTwoInputs->setEnabled(false);
+ mGroupBoxOneInput->setEnabled(true);
+}
+//------------------------------------------------------------------------------
+
+
+//------------------------------------------------------------------------------
+void vvToolImageArithm::GetArgsInfoFromGUI() {
+ // DD("GetArgsInfoFromGUI");
+ mArgsInfo.input1_given = false;
+ if (mTwoInputs) {
+ mArgsInfo.input2_given = true;
+ mArgsInfo.input2_arg = new char; // need to indicate that there are two inputs
+ mArgsInfo.scalar_given = false;
+ if (radioButtonSum->isChecked()) mArgsInfo.operation_arg = 0;
+ if (radioButtonMultiply->isChecked()) mArgsInfo.operation_arg = 1;
+ if (radioButtonDivide->isChecked()) mArgsInfo.operation_arg = 2;
+ if (radioButtonMax->isChecked()) mArgsInfo.operation_arg = 3;
+ if (radioButtonMin->isChecked()) mArgsInfo.operation_arg = 4;
+ if (radioButtonAbsDiff->isChecked()) mArgsInfo.operation_arg = 5;
+ if (radioButtonSquaredDiff->isChecked()) mArgsInfo.operation_arg = 6;
+ }
+ else {
+ mArgsInfo.input2_given = false;
+ mArgsInfo.scalar_given = true;
+ if (radioButtonSumV->isChecked()) mArgsInfo.operation_arg = 0;
+ if (radioButtonMultiplyV->isChecked()) mArgsInfo.operation_arg = 1;
+ if (radioButtonInverseV->isChecked()) mArgsInfo.operation_arg = 2;
+ if (radioButtonMaxV->isChecked()) mArgsInfo.operation_arg = 3;
+ if (radioButtonMinV->isChecked()) mArgsInfo.operation_arg = 4;
+ if (radioButtonAbsDiffV->isChecked()) mArgsInfo.operation_arg = 5;
+ if (radioButtonSquaredDiffV->isChecked()) mArgsInfo.operation_arg = 6;
+ if (radioButtonLogV->isChecked()) mArgsInfo.operation_arg = 7;
+ if (radioButtonExpV->isChecked()) mArgsInfo.operation_arg = 8;
+ if (radioButtonSqrtV->isChecked()) mArgsInfo.operation_arg = 9;
+ mArgsInfo.scalar_given = true;
+ mArgsInfo.scalar_arg = mValueSpinBox->value();
+ }
+ mArgsInfo.output_given = false;
+ mArgsInfo.verbose_flag = false;
+ mArgsInfo.setFloatOutput_flag = mCheckBoxUseFloatOutputType->isChecked();
+ mArgsInfo.imagetypes_flag = false;
+}
+//------------------------------------------------------------------------------
+
+
+//------------------------------------------------------------------------------
+void vvToolImageArithm::apply() {
+ if (!mCurrentSlicerManager) close();
+ QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
+ GetArgsInfoFromGUI();
+
+ std::vector<vvImage::Pointer> inputs;
+ if (mTwoInputs) {
+ // Input
+ inputs.push_back(mInput1->GetImage());
+ inputs.push_back(mInput2->GetImage());
+
+ // Check input type
+ if (inputs[0]->GetScalarTypeAsString() != inputs[1]->GetScalarTypeAsString()) {
+ std::cerr << "Sorry inputs should have the same pixeltype." << std::endl;
+ std::cerr << "Input1 = " << inputs[0]->GetScalarTypeAsString() << std::endl;
+ std::cerr << "Input2 = " << inputs[1]->GetScalarTypeAsString() << std::endl;
+ QApplication::restoreOverrideCursor();
+ QMessageBox::information(this, "Wrong image type","Sorry, could not perform operation. Please select inputs with same pixe type.");
+ close();
+ return;
+ }
+ }
+ else {
+ // Input
+ inputs.push_back(mInput1->GetImage());
+ DD("Single input");
+ }
+
+ // Main filter
+ clitk::ImageArithmGenericFilter<args_info_clitkImageArithm>::Pointer filter =
+ clitk::ImageArithmGenericFilter<args_info_clitkImageArithm>::New();
+ filter->SetInputVVImages(inputs);
+ filter->SetArgsInfo(mArgsInfo);
+ filter->EnableReadOnDisk(false);
+ filter->EnableOverwriteInputImage(false);
+ filter->Update();
+
+ // Output
+ vvImage::Pointer output = filter->GetOutputVVImage();
+ std::ostringstream osstream;
+ osstream << "Arithm_" << mArgsInfo.operation_arg << "_ "
+ << mCurrentSlicerManager->GetSlicer(0)->GetFileName() << ".mhd";
+ AddImage(output,osstream.str());
+ QApplication::restoreOverrideCursor();
+ close();
+}
+//------------------------------------------------------------------------------
--- /dev/null
+/*=========================================================================
+
+ Program: vv
+ Module: $RCSfile: vvToolImageArithm.h,v $
+ Language: C++
+ Date: $Date: 2010/03/24 13:02:59 $
+ Version: $Revision: 1.1 $
+ Author : David Sarrut (david.sarrut@creatis.insa-lyon.fr)
+
+ Copyright (C) 2010
+ Léon Bérard cancer center http://oncora1.lyon.fnclcc.fr
+ CREATIS http://www.creatis.insa-lyon.fr
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, version 3 of the License.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+ =========================================================================*/
+
+#ifndef VVTOOLImageArithm_H
+#define VVTOOLImageArithm_H
+
+#include <QtDesigner/QDesignerExportWidget>
+
+#include "vvToolBase.h"
+#include "vvToolWidgetBase.h"
+#include "ui_vvToolImageArithm.h"
+#include "clitkImageArithm_ggo.h"
+
+//------------------------------------------------------------------------------
+class vvToolImageArithm:
+ public vvToolWidgetBase,
+ public vvToolBase<vvToolImageArithm>,
+ private Ui::vvToolImageArithm
+{
+ Q_OBJECT
+ public:
+ vvToolImageArithm(vvMainWindowBase* parent=0, Qt::WindowFlags f=0);
+ ~vvToolImageArithm();
+
+ static void Initialize();
+ void GetArgsInfoFromGUI();
+ virtual void InputIsSelected(std::vector<vvSlicerManager *> & m);
+ virtual void InputIsSelected(vvSlicerManager * m);
+
+public slots:
+ virtual void apply();
+
+ protected:
+ Ui::vvToolImageArithm ui;
+ vvSlicerManager * mInput1;
+ vvSlicerManager * mInput2;
+ args_info_clitkImageArithm mArgsInfo;
+ bool mTwoInputs;
+
+}; // end class vvToolImageArithm
+//------------------------------------------------------------------------------
+
+#endif
+