]> Creatis software - clitk.git/commitdiff
First version of PointRigidRegistration
authorDominik Spincwyk <dspinczyk@lepiote.clb.loc>
Mon, 3 Feb 2014 14:44:27 +0000 (15:44 +0100)
committerDominik Spincwyk <dspinczyk@lepiote.clb.loc>
Mon, 3 Feb 2014 14:44:27 +0000 (15:44 +0100)
tools/CMakeLists.txt
tools/clitkPointRigidRegistration.cxx [new file with mode: 0644]
tools/clitkPointRigidRegistration.ggo [new file with mode: 0644]

index 144fa6f2dda79953c40a04e44feb81a89cc48e10..de8952712c00fb9279cf89755d2c9deabcfd6642 100644 (file)
@@ -36,6 +36,11 @@ IF (CLITK_BUILD_TOOLS)
   #   )
   SET(TOOLS_INSTALL clitkDicomInfo)
 
+  WRAP_GGO(clitkPointRigidRegistration_GGO_C clitkPointRigidRegistration.ggo)
+  ADD_EXECUTABLE(clitkPointRigidRegistration clitkPointRigidRegistration.cxx ${clitkPointRigidRegistration_GGO_C})
+  TARGET_LINK_LIBRARIES(clitkPointRigidRegistration clitkCommon)
+  SET(TOOLS_INSTALL ${TOOLS_INSTALL} clitkPointRigidRegistration)
+
   WRAP_GGO(clitkDicom2Image_GGO_C clitkDicom2Image.ggo)
   ADD_EXECUTABLE(clitkDicom2Image clitkDicom2Image.cxx ${clitkDicom2Image_GGO_C})
   TARGET_LINK_LIBRARIES(clitkDicom2Image clitkCommon)
@@ -300,11 +305,6 @@ IF (CLITK_BUILD_TOOLS)
   TARGET_LINK_LIBRARIES(clitkImageUncertainty clitkCommon ${ITK_LIBRARIES})
   SET(TOOLS_INSTALL ${TOOLS_INSTALL} clitkImageUncertainty)
 
-  WRAP_GGO(clitkNormalizeImageFilter_GGO_C clitkNormalizeImageFilter.ggo)
-  ADD_EXECUTABLE(clitkNormalizeImageFilter clitkNormalizeImageFilter.cxx ${clitkNormalizeImageFilter_GGO_C})
-  TARGET_LINK_LIBRARIES(clitkNormalizeImageFilter clitkCommon )
-  SET(TOOLS_INSTALL ${TOOLS_INSTALL} clitkNormalizeImageFilter)
-
   WRAP_GGO(clitkImageGradientMagnitude_GGO_C clitkImageGradientMagnitude.ggo)
   ADD_EXECUTABLE(clitkImageGradientMagnitude clitkImageGradientMagnitude.cxx ${clitkImageGradientMagnitude_GGO_C})
   TARGET_LINK_LIBRARIES(clitkImageGradientMagnitude clitkCommon )
@@ -315,15 +315,6 @@ IF (CLITK_BUILD_TOOLS)
   TARGET_LINK_LIBRARIES(clitkImageLaplacian clitkCommon )
   SET(TOOLS_INSTALL ${TOOLS_INSTALL} clitkImageLaplacian)
 
-  WRAP_GGO(clitkImageIntensityWindowing_GGO_C clitkImageIntensityWindowing.ggo)
-  ADD_EXECUTABLE(clitkImageIntensityWindowing clitkImageIntensityWindowing.cxx ${clitkImageIntensityWindowing_GGO_C})
-  TARGET_LINK_LIBRARIES(clitkImageIntensityWindowing clitkCommon )
-  SET(TOOLS_INSTALL ${TOOLS_INSTALL} clitkImageIntensityWindowing)
-
-  WRAP_GGO(clitkBlurImage_GGO_C clitkBlurImage.ggo)
-  ADD_EXECUTABLE(clitkBlurImage clitkBlurImage.cxx ${clitkBlurImage_GGO_C})
-  TARGET_LINK_LIBRARIES(clitkBlurImage clitkCommon )
-  SET(TOOLS_INSTALL ${TOOLS_INSTALL} clitkBlurImage)
 
   #=========================================================
   option(CLITK_USE_ROOT "Build experimental tools using root" OFF)
diff --git a/tools/clitkPointRigidRegistration.cxx b/tools/clitkPointRigidRegistration.cxx
new file mode 100644 (file)
index 0000000..e66edd2
--- /dev/null
@@ -0,0 +1,253 @@
+/*=========================================================================
+  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://www.centreleonberard.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
+===========================================================================**/
+
+/* =================================================
+ * @file   clitkPointRigidRegistrationGenericFilter.txx
+ * @author xxx <xxx@creatis.insa-lyon.fr>
+ * @date   29 June 2029
+ *
+ * @brief PointRigidRegistration an image
+ *
+ ===================================================*/
+
+// clitk
+#include "clitkPointRigidRegistration_ggo.h"
+#include "clitkPointRigidRegistrationGenericFilter.h"
+
+//paste from RigidRegistration
+#include "itkImageFileReader.h"
+#include "itkImageFileWriter.h"
+#include "itkImage.h"
+#include "itkVector.h"
+#include "itkResampleImageFilter.h"
+#include "itkLandmarkBasedTransformInitializer.h"
+#include "itkRigid2DTransform.h"
+#include "itkVersorRigid3DTransform.h"
+#include <iostream>
+
+//paste from /home/dspinczyk/dev/clitk_superbuild_Agata/Source/clitk/common/clitkTransformUtilities.h
+#include "itkMatrix.h"
+#include "itkArray.h"
+#include "itkPoint.h"
+#include "clitkImageCommon.h"
+#include "clitkCommon.h"
+//#define VTK_EXCLUDE_STRSTREAM_HEADERS
+#include <vtkMatrix4x4.h>
+#include <vtkSmartPointer.h>
+
+//for open file for reading
+#include "clitkIO.h"
+#include "clitkImageCommon.h"
+#include "clitkCommon.h"
+
+
+//--------------------------------------------------------------------
+int main(int argc, char * argv[])
+{
+
+  // Init command line
+  GGO(clitkPointRigidRegistration, args_info);
+  CLITK_INIT;
+
+
+
+
+  // Iinit itk
+  // read input file
+  //open stream to reading
+  std::ifstream is;
+  clitk::openFileForReading(is, args_info.input_arg);
+
+
+
+  //pojedyncza zaczytana wartosc
+  double x = 0;
+  //clitk::skipComment(is);
+  is >> x;
+
+  //typ piksela - bo wykorzystujemy strukture itk::Image
+  typedef   unsigned char  PixelType;
+
+
+
+
+
+    //Ddefinicja typu obrazu: zawiera rozmiar danych, typ piksela
+    //rozmiarowosc danych
+    unsigned int Dimension_temp = (unsigned int)x;
+
+
+
+        if (Dimension_temp==2)
+        {
+            const     unsigned int   Dimension = 2;
+            typedef   itk::Image< PixelType, Dimension > ImageType;
+            typedef   float          VectorComponentType;
+            typedef   itk::Vector< VectorComponentType, Dimension >    VectorType;
+            //Typ LandmarkBasedTransormInitializer
+            typedef itk::Rigid2DTransform< double > Rigid2DTransformType;
+            typedef itk::LandmarkBasedTransformInitializer< Rigid2DTransformType,ImageType, ImageType>
+                LandmarkBasedTransformInitializerType;
+
+            LandmarkBasedTransformInitializerType::Pointer landmarkBasedTransformInitializer = LandmarkBasedTransformInitializerType::New();
+
+            //  Create source and target landmarks.
+            typedef LandmarkBasedTransformInitializerType::LandmarkPointContainer     LandmarkContainerType;
+            typedef LandmarkBasedTransformInitializerType::LandmarkPointType          LandmarkPointType;
+
+            //bufory na zaczyt wspolrzedncyh
+            LandmarkContainerType imageLandmarks;
+            LandmarkContainerType trackerLandmarks;
+
+            //bufory na pojedyncze punkty
+            LandmarkPointType imagePoint; // dane z CT
+            LandmarkPointType trackerPoint; //dane z tracking system
+
+            is >> x;
+
+
+            while (is && !is.eof()) {
+                trackerPoint[0] = x;
+                is >> trackerPoint[1];
+                //is >> trackerPoint[2];
+
+                is >> imagePoint[0];
+                is >> imagePoint[1];
+                //is >> imagePoint[2];
+
+                imageLandmarks.push_back(imagePoint );
+                trackerLandmarks.push_back(trackerPoint );
+
+
+              is >> x;
+            }
+
+            is.close();
+
+            landmarkBasedTransformInitializer->SetFixedLandmarks( imageLandmarks);
+            landmarkBasedTransformInitializer->SetMovingLandmarks( trackerLandmarks);
+
+            Rigid2DTransformType::Pointer transform = Rigid2DTransformType::New();
+
+            transform->SetIdentity();
+
+            // Versor rotacji i macierz translacji
+            landmarkBasedTransformInitializer->SetTransform(transform);
+            landmarkBasedTransformInitializer->InitializeTransform();
+
+            Rigid2DTransformType::MatrixType matrix = transform->GetMatrix();
+            Rigid2DTransformType::OffsetType offset = transform->GetOffset();
+
+            // Write result
+              std::ofstream out;
+              clitk::openFileForWriting(out, args_info.output_arg);
+
+              out << matrix[0][0] << ' ' << matrix[0][1] << ' ' << offset[0] << std::endl;
+              out << matrix[1][0] << ' ' << matrix[1][1] << ' ' << offset[1] << std::endl;
+              out << 0.0  << ' ' << 0.0 << ' ' << 1.0;
+              out.close();
+
+
+        }
+        else if (Dimension_temp==3)
+        {
+
+            std::cout << "to ja";
+            const     unsigned int   Dimension = 3;
+            typedef   itk::Image< PixelType, Dimension > ImageType;
+            typedef   float          VectorComponentType;
+            typedef   itk::Vector< VectorComponentType, Dimension >    VectorType;
+            //Typ LandmarkBasedTransormInitializer
+            typedef itk::VersorRigid3DTransform< double > Rigid3DTransformType;
+            typedef itk::LandmarkBasedTransformInitializer< Rigid3DTransformType,ImageType, ImageType>
+                LandmarkBasedTransformInitializerType;
+
+            LandmarkBasedTransformInitializerType::Pointer landmarkBasedTransformInitializer = LandmarkBasedTransformInitializerType::New();
+
+            //  Create source and target landmarks.
+            typedef LandmarkBasedTransformInitializerType::LandmarkPointContainer     LandmarkContainerType;
+            typedef LandmarkBasedTransformInitializerType::LandmarkPointType          LandmarkPointType;
+
+            //bufory na zaczyt wspolrzedncyh
+            LandmarkContainerType imageLandmarks;
+            LandmarkContainerType trackerLandmarks;
+
+            //bufory na pojedyncze punkty
+            LandmarkPointType imagePoint; // dane z CT
+            LandmarkPointType trackerPoint; //dane z tracking system
+
+            is >> x;
+
+            while (is && !is.eof()) {
+                trackerPoint[0] = x;
+                is >> trackerPoint[1];
+                is >> trackerPoint[2];
+
+                is >> imagePoint[0];
+                is >> imagePoint[1];
+                is >> imagePoint[2];
+
+                imageLandmarks.push_back(imagePoint );
+                trackerLandmarks.push_back(trackerPoint );
+
+                is >> x;
+            }
+
+            is.close();
+
+            landmarkBasedTransformInitializer->SetFixedLandmarks( imageLandmarks);
+            landmarkBasedTransformInitializer->SetMovingLandmarks( trackerLandmarks);
+
+            Rigid3DTransformType::Pointer transform = Rigid3DTransformType::New();
+
+            transform->SetIdentity();
+
+            // Versor rotacji i macierz translacji
+            landmarkBasedTransformInitializer->SetTransform(transform);
+            landmarkBasedTransformInitializer->InitializeTransform();
+
+            Rigid3DTransformType::MatrixType matrix = transform->GetMatrix();
+            Rigid3DTransformType::OffsetType offset = transform->GetOffset();
+
+            // Write result
+              std::ofstream out;
+              clitk::openFileForWriting(out, args_info.output_arg);
+
+              out << matrix[0][0] << ' ' << matrix[0][1] << ' ' << matrix[0][2] << ' '<< offset[0] << std::endl;
+              out << matrix[1][0] << ' ' << matrix[1][1] << ' ' << matrix[1][2] << ' '<< offset[1] << std::endl;
+              out << matrix[2][0] << ' ' << matrix[2][1] << ' ' << matrix[2][2] << ' '<< offset[2] << std::endl;
+              out << 0.0  << ' ' << 0.0 << ' ' << 0.0 << ' ' << 1.0;
+              out.close();
+
+
+
+        }
+        else
+        {
+              is.close();
+              return EXIT_FAILURE;
+
+        }
+
+
+
+
+
+  return EXIT_SUCCESS;
+}// end main
+//--------------------------------------------------------------------
diff --git a/tools/clitkPointRigidRegistration.ggo b/tools/clitkPointRigidRegistration.ggo
new file mode 100644 (file)
index 0000000..311ea29
--- /dev/null
@@ -0,0 +1,13 @@
+#File clitkPointRigidRegistration.ggo
+package "clitkPointRigidRegistration"
+version "1.0"
+purpose "Finding the rigid transformation between two cartesian coordinate systems\n
+based on corresponding points positions"
+
+option "config"                -       "Config file"                     string        optional
+option "verbose"       v       "Verbose"                         flag          off
+
+
+
+option "input"         i       "Corresponding points' positions filename"                string        required
+option "output"        o       "Output transformation filename"                  string        required