From: dsarrut Date: Wed, 24 Mar 2010 13:02:59 +0000 (+0000) Subject: - new vv tool X-Git-Tag: v1.2.0~751 X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=commitdiff_plain;h=c0e046877aff811d428dd616ce40197080c962a2;p=clitk.git - new vv tool --- diff --git a/vv/qt_ui/vvToolImageArithm.ui b/vv/qt_ui/vvToolImageArithm.ui new file mode 100644 index 0000000..7535a36 --- /dev/null +++ b/vv/qt_ui/vvToolImageArithm.ui @@ -0,0 +1,236 @@ + + + vvToolImageArithm + + + + 0 + 0 + 424 + 345 + + + + Form + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + Set output pixel type to float + + + false + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + + + Operation with two images + + + + + + Sum A+B + + + true + + + + + + + Multiply A*B + + + + + + + Divide A/B + + + + + + + Min [A,B] + + + + + + + Max [A,B] + + + + + + + Absolute difference |A-B| + + + + + + + Squared difference (A-B)² + + + + + + + + + + Operation on a single image + + + + + + + + + 11 + 50 + false + + + + QFrame::NoFrame + + + Value (v) + + + + + + + 999999999.000000000000000 + + + + + + + + + Sum A(x)+v + + + true + + + + + + + Multiply A(x)*v + + + + + + + Inverse v/A(x) + + + + + + + Max [ A(x), v ] + + + + + + + Min [ A(x),v ] + + + + + + + Absolute difference |A(x)-v| + + + + + + + Squared difference (A(x)-v)² + + + + + + + Log A(x) (don't use v) + + + + + + + Exp A(x) (don't use v) + + + + + + + Sqrt A(x) (don't use v) + + + + + + + + + + + + + diff --git a/vv/vvToolImageArithm.cxx b/vv/vvToolImageArithm.cxx new file mode 100644 index 0000000..1079730 --- /dev/null +++ b/vv/vvToolImageArithm.cxx @@ -0,0 +1,182 @@ +/*========================================================================= + + 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 . + + =========================================================================*/ + +#include "vvToolImageArithm.h" +#include "vvSlicer.h" +#include "clitkImageArithmGenericFilter.h" +#include + +//------------------------------------------------------------------------------ +// 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(parent), + Ui::vvToolImageArithm() { + // Setup the UI + Ui_vvToolImageArithm::setupUi(mToolWidget); + + // Main filter + mFilter = new clitk::ImageArithmGenericFilter; + + // 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 & 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 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::Pointer filter = + clitk::ImageArithmGenericFilter::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(); +} +//------------------------------------------------------------------------------ diff --git a/vv/vvToolImageArithm.h b/vv/vvToolImageArithm.h new file mode 100644 index 0000000..907cb6d --- /dev/null +++ b/vv/vvToolImageArithm.h @@ -0,0 +1,68 @@ +/*========================================================================= + + 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 . + + =========================================================================*/ + +#ifndef VVTOOLImageArithm_H +#define VVTOOLImageArithm_H + +#include + +#include "vvToolBase.h" +#include "vvToolWidgetBase.h" +#include "ui_vvToolImageArithm.h" +#include "clitkImageArithm_ggo.h" + +//------------------------------------------------------------------------------ +class vvToolImageArithm: + public vvToolWidgetBase, + public vvToolBase, + 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 & 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 +