#include "itkPoint.h"
#include "clitkImageCommon.h"
#include "clitkCommon.h"
-
+#include <vtkMatrix4x4.h>
+#include <vtkSmartPointer.h>
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
#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;
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);
}
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"