From: dsarrut Date: Mon, 29 Mar 2010 11:25:21 +0000 (+0000) Subject: - convert tool X-Git-Tag: v1.2.0~742 X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=commitdiff_plain;h=0ec1dda064e173f024248479bbfbe116de28f21b;p=clitk.git - convert tool --- diff --git a/vv/icons/1b.png b/vv/icons/1b.png new file mode 100644 index 0000000..3f9b776 Binary files /dev/null and b/vv/icons/1b.png differ diff --git a/vv/icons/2b.png b/vv/icons/2b.png new file mode 100644 index 0000000..0a50bf1 Binary files /dev/null and b/vv/icons/2b.png differ diff --git a/vv/icons/4b.png b/vv/icons/4b.png new file mode 100644 index 0000000..908f113 Binary files /dev/null and b/vv/icons/4b.png differ diff --git a/vv/icons/8b.png b/vv/icons/8b.png new file mode 100644 index 0000000..2736e97 Binary files /dev/null and b/vv/icons/8b.png differ diff --git a/vv/icons/arithm.png b/vv/icons/arithm.png new file mode 100644 index 0000000..e1ee09b Binary files /dev/null and b/vv/icons/arithm.png differ diff --git a/vv/icons/green-arrow.png b/vv/icons/green-arrow.png new file mode 100644 index 0000000..d46a502 Binary files /dev/null and b/vv/icons/green-arrow.png differ diff --git a/vv/vvToolConvert.cxx b/vv/vvToolConvert.cxx new file mode 100644 index 0000000..5184ee2 --- /dev/null +++ b/vv/vvToolConvert.cxx @@ -0,0 +1,135 @@ +/*========================================================================= + Program: vv http://www.creatis.insa-lyon.fr/rio/vv + + Authors belong to: + - University of LYON http://www.universite-lyon.fr/ + - Léon Bérard cancer center http://oncora1.lyon.fnclcc.fr + - CREATIS CNRS laboratory http://www.creatis.insa-lyon.fr + + This software is distributed WITHOUT ANY WARRANTY; without even + the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + PURPOSE. See the copyright notices for more information. + + It is distributed under dual licence + + - BSD See included LICENSE.txt file + - CeCILL-B http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html +======================================================================-====*/ + +#include "vvToolConvert.h" +#include "vvSlicer.h" +#include "clitkImageConvertGenericFilter.h" +#include +#include +#include +#include + +//------------------------------------------------------------------------------ +// Create the tool and automagically (I like this word) insert it in +// the main window menu. +ADD_TOOL(vvToolConvert); +//------------------------------------------------------------------------------ + +QAction * vvToolConvert::a = NULL; +QAction * vvToolConvert::b = NULL; +std::vector vvToolConvert::mListOfPixelTypeNames; +std::vector vvToolConvert::mListOfPixelTypeIcons; +std::map vvToolConvert::mMapOfPixelType; + +//------------------------------------------------------------------------------ +vvToolConvert::vvToolConvert(vvMainWindowBase * parent, Qt::WindowFlags f): + vvToolBase(parent) +{ +} +//------------------------------------------------------------------------------ + + +//------------------------------------------------------------------------------ +vvToolConvert::~vvToolConvert() { +} +//------------------------------------------------------------------------------ + + +//------------------------------------------------------------------------------ +void vvToolConvert::Initialize() { + SetToolName("Convert"); + SetToolMenuName("Convert with WidgetBase"); + SetToolIconFilename(":/common/icons/ducky.png"); + SetToolTip("Make 'foo' on an image."); + + // Create a menu to choose the convert image + QMenu * m = new QMenu(); + m->setTitle("Convert to "); + m->setIcon(QIcon(QString::fromUtf8(":/common/icons/green-arrow.png"))); + + mListOfPixelTypeNames.push_back("char"); + mListOfPixelTypeNames.push_back("unsigned_char"); + mListOfPixelTypeNames.push_back("short"); + mListOfPixelTypeNames.push_back("unsigned_short"); + mListOfPixelTypeNames.push_back("int"); + mListOfPixelTypeNames.push_back("float"); + mListOfPixelTypeNames.push_back("double"); + + mListOfPixelTypeIcons.push_back(":/common/icons/1b.png"); + mListOfPixelTypeIcons.push_back(":/common/icons/1b.png"); + mListOfPixelTypeIcons.push_back(":/common/icons/2b.png"); + mListOfPixelTypeIcons.push_back(":/common/icons/2b.png"); + mListOfPixelTypeIcons.push_back(":/common/icons/4b.png"); + mListOfPixelTypeIcons.push_back(":/common/icons/4b.png"); + mListOfPixelTypeIcons.push_back(":/common/icons/4b.png"); + mListOfPixelTypeIcons.push_back(":/common/icons/8b.png"); + + for(unsigned int i=0; iaddAction(QIcon(QString::fromUtf8(mListOfPixelTypeIcons[i].c_str())), + tr(s.c_str())); + m->addAction(mMapOfPixelType[s]); + } + + CREATOR(vvToolConvert)->addMenuToContextMenu(m); +} +//------------------------------------------------------------------------------ + + +//------------------------------------------------------------------------------ +void vvToolConvert::show() { + QApplication::setOverrideCursor(QCursor(Qt::WaitCursor)); + // Get action menu name + QAction * cc = dynamic_cast(mSender); + std::string type = cc->text().toStdString(); + // Get current image + int index = mMainWindowBase->GetSlicerManagerCurrentIndex(); + vvSlicerManager * m = mMainWindowBase->GetSlicerManagers()[index]; + assert(m != NULL); // Should no occur + + // Create filter and run ! + clitk::ImageConvertGenericFilter * filter = new clitk::ImageConvertGenericFilter; + filter->SetInputVVImage(m->GetImage()); + filter->SetOutputPixelType(type); + filter->EnableDisplayWarning(false); + filter->Update(); + + // Manage warning + if (filter->IsWarningOccur()) { + QApplication::restoreOverrideCursor(); + QMessageBox::warning(mMainWindowBase, "Warning", filter->GetWarning().c_str()); + QApplication::setOverrideCursor(QCursor(Qt::WaitCursor)); + } + + // Output + vvImage::Pointer output = filter->GetOutputVVImage(); + std::ostringstream osstream; + osstream << "Convert_" << type << "_" << m->GetSlicer(0)->GetFileName() << ".mhd"; + AddImage(output,osstream.str()); + QApplication::restoreOverrideCursor(); +} +//------------------------------------------------------------------------------ + + +//------------------------------------------------------------------------------ +void vvToolConvert::apply() { + // nothing !! +} +//------------------------------------------------------------------------------ + + diff --git a/vv/vvToolConvert.h b/vv/vvToolConvert.h new file mode 100644 index 0000000..b8e4afc --- /dev/null +++ b/vv/vvToolConvert.h @@ -0,0 +1,49 @@ +/*========================================================================= + Program: vv http://www.creatis.insa-lyon.fr/rio/vv + + Authors belong to: + - University of LYON http://www.universite-lyon.fr/ + - Léon Bérard cancer center http://oncora1.lyon.fnclcc.fr + - CREATIS CNRS laboratory http://www.creatis.insa-lyon.fr + + This software is distributed WITHOUT ANY WARRANTY; without even + the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + PURPOSE. See the copyright notices for more information. + + It is distributed under dual licence + + - BSD See included LICENSE.txt file + - CeCILL-B http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html +======================================================================-====*/ + +#ifndef VVTOOLCONVERT_H +#define VVTOOLCONVERT_H + +#include "vvToolBase.h" + +//------------------------------------------------------------------------------ +class vvToolConvert: public QObject, public vvToolBase +{ + Q_OBJECT + public: + vvToolConvert(vvMainWindowBase* parent, Qt::WindowFlags f=0); + ~vvToolConvert(); + + static void Initialize(); + +public slots: + virtual void apply(); + void show(); + + protected: + static std::vector mListOfPixelTypeNames; + static std::vector mListOfPixelTypeIcons; + static std::map mMapOfPixelType; + static QAction * a; + static QAction * b; + +}; // end class vvToolConvert +//------------------------------------------------------------------------------ + +#endif +