]> Creatis software - clitk.git/commitdiff
- convert tool
authordsarrut <dsarrut>
Mon, 29 Mar 2010 11:25:21 +0000 (11:25 +0000)
committerdsarrut <dsarrut>
Mon, 29 Mar 2010 11:25:21 +0000 (11:25 +0000)
vv/icons/1b.png [new file with mode: 0644]
vv/icons/2b.png [new file with mode: 0644]
vv/icons/4b.png [new file with mode: 0644]
vv/icons/8b.png [new file with mode: 0644]
vv/icons/arithm.png [new file with mode: 0644]
vv/icons/green-arrow.png [new file with mode: 0644]
vv/vvToolConvert.cxx [new file with mode: 0644]
vv/vvToolConvert.h [new file with mode: 0644]

diff --git a/vv/icons/1b.png b/vv/icons/1b.png
new file mode 100644 (file)
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 (file)
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 (file)
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 (file)
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 (file)
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 (file)
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 (file)
index 0000000..5184ee2
--- /dev/null
@@ -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 <QMenu>
+#include <QApplication>
+#include <QMessageBox>
+#include <vtkImageData.h>
+
+//------------------------------------------------------------------------------
+// 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<std::string> vvToolConvert::mListOfPixelTypeNames;
+std::vector<std::string> vvToolConvert::mListOfPixelTypeIcons;
+std::map<std::string, QAction*> vvToolConvert::mMapOfPixelType;
+
+//------------------------------------------------------------------------------
+vvToolConvert::vvToolConvert(vvMainWindowBase * parent, Qt::WindowFlags f):
+  vvToolBase<vvToolConvert>(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; i<mListOfPixelTypeNames.size(); i++) {
+    std::string & s = mListOfPixelTypeNames[i];
+    mMapOfPixelType[s] = m->addAction(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<QAction*>(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 (file)
index 0000000..b8e4afc
--- /dev/null
@@ -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<vvToolConvert>
+{
+  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<std::string> mListOfPixelTypeNames;
+  static std::vector<std::string> mListOfPixelTypeIcons;
+  static std::map<std::string, QAction*> mMapOfPixelType;
+  static QAction * a;
+  static QAction * b;
+
+}; // end class vvToolConvert
+//------------------------------------------------------------------------------
+
+#endif
+