]> Creatis software - clitk.git/commitdiff
added an option to transform vtk meshes with tool clitkTransformLandmarks
authorrblanc <rblanc33@gmail.com>
Wed, 15 May 2013 15:01:10 +0000 (17:01 +0200)
committerrblanc <rblanc33@gmail.com>
Wed, 15 May 2013 15:01:10 +0000 (17:01 +0200)
common/clitkTransformUtilities.h
tools/clitkTransformLandmarks.cxx
tools/clitkTransformLandmarks.ggo

index 3bdf22026ee0ab969a5fe8f6274db3a0fd4fa2e3..cbc30b97ac806aa0cd3c91d531dc4cac082bd2e8 100644 (file)
@@ -23,7 +23,8 @@
 #include "itkPoint.h"
 #include "clitkImageCommon.h"
 #include "clitkCommon.h"
+#include <vtkMatrix4x4.h>
+#include <vtkSmartPointer.h>
  
 namespace clitk
 {
@@ -278,6 +279,29 @@ namespace clitk
     return matrix; 
   }
  
+  inline vtkMatrix4x4* ReadVTKMatrix3D(std::string fileName) {
+    // read input matrix
+    std::ifstream is;
+    openFileForReading(is, fileName);
+    std::vector<double> nb;
+    double x;
+    skipComment(is);
+    is >> x;
+    while (!is.eof()) {
+      nb.push_back(x);
+      skipComment(is);
+      is >> x;
+    }
+
+    vtkSmartPointer<vtkMatrix4x4> matrix = vtkSmartPointer<vtkMatrix4x4>::New();
+    unsigned int index=0;
+    for (unsigned int i=0;i<4;i++)
+      for (unsigned int j=0;j<4;j++)
+         matrix->SetElement(i,j, nb[index++]);
+
+    return matrix;
+  }
+
   inline itk::Matrix<double, 3, 3> ReadMatrix2D(std::string fileName)
   {
     // read input matrix
index 86745a419363ad9d97194b0e9ccdf921c39ee39e..df5dbe8e390521e8705019f14dea0defd66db44c 100644 (file)
 #include <iostream>
 #include <fstream>
 
+#include <vtkSmartPointer.h>
+#include <vtkPoints.h>
+#include <vtkPolyData.h>
+#include "vtkPolyDataReader.h"
+#include "vtkPolyDataWriter.h"
+#include <vtkTransform.h>
+#include <vtkTransformFilter.h>
+
 typedef itk::Matrix<double, 4, 4> MatrixType;
 typedef itk::Point<double, 4> PointType;
 typedef std::vector<PointType> PointArrayType;
@@ -52,6 +60,32 @@ int main(int argc, char** argv)
   if (strcmp(args_info.type_arg, "txt") == 0) {
     read_points_txt(args_info.input_arg, inputPoints, data);
   }
+  else if (strcmp(args_info.type_arg, "vtk") == 0) {
+    vtkSmartPointer<vtkPolyDataReader> reader = vtkSmartPointer<vtkPolyDataReader>::New();
+    reader->SetFileName(args_info.input_arg);
+    reader->Update();
+    vtkSmartPointer<vtkPolyDataWriter> writer = vtkSmartPointer<vtkPolyDataWriter>::New();
+    writer->SetFileName( args_info.output_arg );
+
+    if (args_info.matrix_given) {
+      vtkSmartPointer<vtkTransformFilter> transformFilter = vtkSmartPointer<vtkTransformFilter>::New();
+      vtkSmartPointer<vtkTransform> transform = vtkSmartPointer<vtkTransform>::New();
+      vtkMatrix4x4* matrix = clitk::ReadVTKMatrix3D(args_info.matrix_arg);
+      vtkSmartPointer<vtkMatrix4x4> matrixT = vtkSmartPointer<vtkMatrix4x4>::New();
+      vtkMatrix4x4::Invert(matrix, matrixT); //not sure why, but this seems necessary for using the same .mat as when loading file with vv (probably due to the inversion trick performed in the vv reader...)
+      transform->SetMatrix(matrixT);
+      transformFilter->SetInputConnection(reader->GetOutputPort());
+      transformFilter->SetTransform(transform);
+      writer->SetInputConnection(transformFilter->GetOutputPort());
+
+    }
+    else { //just write the output
+      writer->SetInputConnection( reader->GetOutputPort() );
+    }
+
+    writer->Write();
+    return 0;
+  }
   else {
     read_points_pts(args_info.input_arg, inputPoints);
   }
index c731c23086539cfdecd138621afd6b8a6c0606a9..47722240c6d67134cfdc4f3a5eea100e44c2aa94 100644 (file)
@@ -10,6 +10,6 @@ option "input"    i "Input landmarks filename"      string    yes
 option "matrix"   m "Input 4x4 matrix filename ('.mat' file)"      string    no
 option "spacing"   s "If given, applies the given spacing (x,y,z) to the input points."      double    no multiple  default="1"
 option "output"                o       "Output landmarks filename"                     string          yes
-option "type"          t       "Landmarks type ('pts' for Jef; 'txt' for VV)"          string          no              default="txt" 
+option "type"          t       "Landmarks type ('pts' for Jef; 'txt' for VV ; 'vtk' for vtk meshes)"           string          no              default="txt"