]> Creatis software - clitk.git/commitdiff
Plastimatch tool
authordsarrut <dsarrut>
Wed, 7 Jul 2010 07:09:18 +0000 (07:09 +0000)
committerdsarrut <dsarrut>
Wed, 7 Jul 2010 07:09:18 +0000 (07:09 +0000)
vv/qt_ui/vvToolPlastimatch.ui [new file with mode: 0644]
vv/vvToolPlastimatch.cxx [new file with mode: 0644]
vv/vvToolPlastimatch.h [new file with mode: 0644]

diff --git a/vv/qt_ui/vvToolPlastimatch.ui b/vv/qt_ui/vvToolPlastimatch.ui
new file mode 100644 (file)
index 0000000..d63fe23
--- /dev/null
@@ -0,0 +1,51 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ui version="4.0">
+ <class>vvToolPlastimatch</class>
+ <widget class="QWidget" name="vvToolPlastimatch">
+  <property name="geometry">
+   <rect>
+    <x>0</x>
+    <y>0</y>
+    <width>400</width>
+    <height>300</height>
+   </rect>
+  </property>
+  <property name="windowTitle">
+   <string>Form</string>
+  </property>
+  <layout class="QGridLayout" name="gridLayout">
+   <item row="0" column="0">
+    <layout class="QVBoxLayout" name="verticalLayout">
+     <item>
+      <widget class="QLabel" name="dimensionStaticLabel_5">
+       <property name="sizePolicy">
+        <sizepolicy hsizetype="Fixed" vsizetype="Fixed">
+         <horstretch>0</horstretch>
+         <verstretch>0</verstretch>
+        </sizepolicy>
+       </property>
+       <property name="text">
+        <string>Plastimatch</string>
+       </property>
+      </widget>
+     </item>
+     <item>
+      <widget class="QLabel" name="dimensionStaticLabel_6">
+       <property name="sizePolicy">
+        <sizepolicy hsizetype="Fixed" vsizetype="Fixed">
+         <horstretch>0</horstretch>
+         <verstretch>0</verstretch>
+        </sizepolicy>
+       </property>
+       <property name="text">
+        <string>Put options here ...</string>
+       </property>
+      </widget>
+     </item>
+    </layout>
+   </item>
+  </layout>
+ </widget>
+ <resources/>
+ <connections/>
+</ui>
diff --git a/vv/vvToolPlastimatch.cxx b/vv/vvToolPlastimatch.cxx
new file mode 100644 (file)
index 0000000..466d43e
--- /dev/null
@@ -0,0 +1,211 @@
+/*=========================================================================
+  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
+  ======================================================================-====*/
+
+// vv
+#include "vvToolPlastimatch.h"
+#include "vvSlicerManager.h"
+#include "vvSlicer.h"
+#include "vvToolInputSelectorWidget.h"
+
+// Plastimatch 
+// PUT INCLUDE HERE
+
+// qt
+#include <QMessageBox>
+
+//------------------------------------------------------------------------------
+// Create the tool and automagically (I like this word) insert it in
+// the main window menu.
+ADD_TOOL(vvToolPlastimatch);
+//------------------------------------------------------------------------------
+
+
+//------------------------------------------------------------------------------
+void vvToolPlastimatch::Initialize()
+{
+  SetToolName("Plastimatch");
+  SetToolMenuName("Plastimatch");
+  SetToolIconFilename(":/common/icons/plastimatch.png");
+  SetToolTip("Image registration with Plastimatch (G. Sharp).");
+  SetToolExperimental(true);
+}
+//------------------------------------------------------------------------------
+
+
+//------------------------------------------------------------------------------
+vvToolPlastimatch::vvToolPlastimatch(vvMainWindowBase * parent, Qt::WindowFlags f)
+  :vvToolWidgetBase(parent,f),
+   vvToolBase<vvToolPlastimatch>(parent),
+   Ui::vvToolPlastimatch()
+{
+  // GUI Initialization
+  Ui_vvToolPlastimatch::setupUi(mToolWidget);
+
+  // Connect signals & slots
+  // TODO
+
+  // Set how many inputs are needed for this tool
+  AddInputSelector("Select fixed (reference) image");
+  AddInputSelector("Select moving image");
+}
+//------------------------------------------------------------------------------
+
+
+//------------------------------------------------------------------------------
+vvToolPlastimatch::~vvToolPlastimatch()
+{
+}
+//------------------------------------------------------------------------------
+
+
+//------------------------------------------------------------------------------
+bool vvToolPlastimatch::close()
+{
+  return vvToolWidgetBase::close();
+}
+//------------------------------------------------------------------------------
+
+
+//------------------------------------------------------------------------------
+void vvToolPlastimatch::closeEvent(QCloseEvent *event) {
+  event->accept();
+}
+//------------------------------------------------------------------------------
+
+
+//------------------------------------------------------------------------------
+void vvToolPlastimatch::reject()
+{
+  DD("vvToolPlastimatch::reject");
+  return vvToolWidgetBase::reject();
+}
+//------------------------------------------------------------------------------
+
+
+//------------------------------------------------------------------------------
+void vvToolPlastimatch::InputIsSelected(std::vector<vvSlicerManager *> & m)
+{
+  DD("vvToolPlastimatch::InputIsSelected");
+
+  // Get input images (vvImage)
+  m_InputSlicerManagers = m;
+  m_Fixed = m[0]->GetImage();
+  m_Moving = m[1]->GetImage();
+
+  // Check image
+  if (m_Fixed->GetNumberOfDimensions() != 3) {
+    QMessageBox::information(this, tr("Error"), tr("Sorry, fixed image should be 3D"));
+    close();
+    return;
+  }
+  if (m_Moving->GetNumberOfDimensions() != 3) {
+    QMessageBox::information(this, tr("Errror"), tr("Sorry, moving image should be 3D"));
+    close();
+    return;
+  }
+
+  // We cannot used vvImageToITK directly because we need to cast to
+  // float before
+
+  // Convert input to float
+  m_FixedVTK = m_Fixed->GetFirstVTKImageData();
+  m_MovingVTK = m_Moving->GetFirstVTKImageData();
+  DD(m_Fixed->GetScalarTypeAsITKString());
+  if (m_Fixed->GetScalarTypeAsITKString() != "float") {
+    DD("Cast input");
+    m_FixedVTK = CopyAndCastToFloatFrom(m_Fixed->GetFirstVTKImageData());
+    m_MovingVTK = CopyAndCastToFloatFrom(m_Moving->GetFirstVTKImageData());
+  }
+
+  // Convert vtk to itk
+  typedef itk::Image<float, 3> FloatImageType;
+  m_FixedITK = ItkImageFromVtk<3, float>(m_FixedVTK);
+  m_MovingITK = ItkImageFromVtk<3, float>(m_MovingVTK);
+  
+  m_FixedITK->Print(std::cout);
+  m_MovingITK->Print(std::cout);  
+}
+//------------------------------------------------------------------------------
+
+
+//------------------------------------------------------------------------------
+void vvToolPlastimatch::GetOptionsFromGUI()
+{
+  DD("vvToolPlastimatch::GetOptionsFromGUI");
+
+
+}
+//------------------------------------------------------------------------------
+
+
+//------------------------------------------------------------------------------
+void vvToolPlastimatch::apply()
+{
+  DD("vvToolPlastimatch::apply");
+
+  if (!mCurrentSlicerManager) close();
+  QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
+  GetOptionsFromGUI();
+
+  // Create the command string
+  char *command_string =
+    "[STAGE]\n"
+    "xform=bspline\n"
+    "max_its=30\n"
+    "grid_spac=100 100 100\n"
+    "res=4 4 2\n"
+    ;
+
+  // Prepare the registration
+  /*
+  Plm_registration_context *prc = plm_registration_context_create ();
+  plm_registration_set_fixed (prc, m_FixedITK);
+  plm_registration_set_moving (prc, m_MovingITK);
+  plm_registration_set_command_string (prc, command_string);
+
+
+  // Run the registration
+  plm_registration_execute (prc);
+  if (plm_registration_get_status (prc) != 0) {
+    // Handle error 
+  }
+
+  // Get registration outputs
+  plm_registration_get_warped_image (prc, &m_WarpedImageITK);
+  plm_registration_get_vector_field (prc, &m_DeformationField);
+
+  // Free the memory
+  plm_registration_context_destroy (prc);
+  */
+
+  // Get warped output and display it
+  m_WarpedImage = vvImageFromITK<3, float>(m_WarpedImageITK);
+  std::ostringstream osstream;
+  osstream << "plm_warped_" << m_InputSlicerManagers[1]->GetFileName() << ".mhd";
+  AddImage(m_WarpedImage, osstream.str());
+
+  // Get DVF 
+  DD("TODO get and display DVF");
+
+  // End
+  QApplication::restoreOverrideCursor();
+  close();
+}
+//------------------------------------------------------------------------------
+
+
diff --git a/vv/vvToolPlastimatch.h b/vv/vvToolPlastimatch.h
new file mode 100644 (file)
index 0000000..eed47f2
--- /dev/null
@@ -0,0 +1,74 @@
+/*=========================================================================
+  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 VVTOOLPLASTIMATCH_H
+#define VVTOOLPLASTIMATCH_H
+
+#include <QtDesigner/QDesignerExportWidget>
+
+#include "vvToolBase.h"
+#include "vvToolWidgetBase.h"
+#include "vvImageContour.h"
+#include "ui_vvToolPlastimatch.h"
+
+#include "clitkBinarizeImage_ggo.h"
+
+//------------------------------------------------------------------------------
+class vvToolPlastimatch:
+  public vvToolWidgetBase,
+  public vvToolBase<vvToolPlastimatch>, 
+  private Ui::vvToolPlastimatch 
+{
+  Q_OBJECT
+    public:
+  vvToolPlastimatch(vvMainWindowBase * parent=0, Qt::WindowFlags f=0);
+  ~vvToolPlastimatch();
+
+  //-----------------------------------------------------
+  static void Initialize();
+  void GetOptionsFromGUI();
+  virtual void InputIsSelected(std::vector<vvSlicerManager *> & m);
+
+  //-----------------------------------------------------
+  public slots:
+  virtual void apply();
+  virtual bool close();
+  virtual void reject();
+
+ protected:
+  virtual void closeEvent(QCloseEvent *event);
+  Ui::vvToolPlastimatch ui;
+  std::vector<vvSlicerManager *> m_InputSlicerManagers;
+
+  typedef itk::Image<float, 3>           FloatImageType;
+  typedef itk::Vector<float, 3>          FloatVectorType;
+  typedef itk::Image<FloatVectorType, 3> DeformationFieldType;  
+  vvImage::Pointer              m_Fixed;
+  vvImage::Pointer              m_Moving;
+  vtkImageData *                m_FixedVTK;
+  vtkImageData *                m_MovingVTK;
+  FloatImageType::ConstPointer  m_FixedITK;
+  FloatImageType::ConstPointer  m_MovingITK;  
+  DeformationFieldType::Pointer m_DeformationField;
+  FloatImageType::Pointer       m_WarpedImageITK;
+  vvImage::Pointer              m_WarpedImage;
+
+}; // end class vvToolPlastimatch
+//------------------------------------------------------------------------------
+
+#endif
+