]> Creatis software - clitk.git/commitdiff
Romulo:
authordsarrut <dsarrut>
Fri, 25 Mar 2011 13:15:28 +0000 (13:15 +0000)
committerdsarrut <dsarrut>
Fri, 25 Mar 2011 13:15:28 +0000 (13:15 +0000)
- new tool: clitkTransformLandmarks
Trasnform a set of landmarks with the given 4x4 matrix. Output to stdout.

tools/CMakeLists.txt
tools/clitkTransformLandmarks.cxx [new file with mode: 0644]
tools/clitkTransformLandmarks.ggo [new file with mode: 0644]

index 5454a1204e2fb0befe474581ad73f879fd4ed58f..8fdef8ddadda73a84a7d4343596aa6fd8896195e 100644 (file)
@@ -244,4 +244,8 @@ IF (CLITK_BUILD_TOOLS)
     ADD_EXECUTABLE(clitkRelativePosition  clitkRelativePosition.cxx ${clitkRelativePosition_GGO_C})
     TARGET_LINK_LIBRARIES(clitkRelativePosition clitkCommon ITKIO)
 
+    WRAP_GGO(clitkTransformLandmarks_GGO_C clitkTransformLandmarks.ggo)
+    ADD_EXECUTABLE(clitkTransformLandmarks clitkTransformLandmarks.cxx ${clitkTransformLandmarks_GGO_C})
+    TARGET_LINK_LIBRARIES(clitkTransformLandmarks clitkCommon ITKIO)
+
 ENDIF(CLITK_BUILD_TOOLS)
diff --git a/tools/clitkTransformLandmarks.cxx b/tools/clitkTransformLandmarks.cxx
new file mode 100644 (file)
index 0000000..fc92886
--- /dev/null
@@ -0,0 +1,82 @@
+#include "clitkTransformLandmarks_ggo.h"
+
+#include "clitkTransformUtilities.h"
+#include <string>
+#include <vector>
+#include <iostream>
+#include <fstream>
+
+typedef itk::Matrix<double, 4, 4> MatrixType;
+typedef itk::Point<double, 4> PointType;
+typedef std::vector<PointType> PointArrayType;
+
+void read_points(const std::string& fileName, PointArrayType& points);
+void transform_points(const PointArrayType& input, const MatrixType& matrix, PointArrayType& output);
+void write_points(const PointArrayType& points);
+
+bool verbose = false;
+
+int main(int argc, char** argv)
+{
+  GGO(clitkTransformLandmarks, args_info);
+
+  PointArrayType inputPoints;
+  read_points(args_info.input_arg, inputPoints);
+  
+  MatrixType matrix = clitk::ReadMatrix3D(args_info.matrix_arg);
+
+  PointArrayType outputPoints;
+  transform_points(inputPoints, matrix, outputPoints);
+  
+  write_points(outputPoints);
+  return 0;
+}
+
+void read_points(const std::string& fileName, PointArrayType& points)
+{
+  std::ifstream landmarksFile(fileName.c_str());
+  if (landmarksFile.fail()) {
+    std::cout << "ERROR: could not open '" << fileName << "'" << std::endl;
+    exit(-2);
+  }
+  
+  std::string line;
+  std::getline(landmarksFile, line);
+  if (line.find("LANDMARKS") == std::string::npos) {
+    std::cout << "ERROR: invalid landmarks file '" << fileName << "'" << std::endl;
+    exit(-3);
+  }
+  
+  int id = 0;
+  PointType point;
+  point.Fill(1);
+  
+  std::istringstream linestr; 
+  while (!landmarksFile.eof()) {
+    std::getline(landmarksFile, line);
+    if (verbose) std::cout << "line " << line << std::endl;
+    
+    if (!line.empty()) {
+      linestr.str(line);
+      linestr >> id >> point[0] >> point[1] >> point[2];
+      
+      if (verbose) std::cout << "point " << point << std::endl;
+      
+      points.push_back(point);
+    }
+  }
+}
+
+void transform_points(const PointArrayType& input, const MatrixType& matrix, PointArrayType& output)
+{
+  for (size_t i = 0; i < input.size(); i++) {
+    output.push_back(matrix * input[i]);
+  }
+}
+
+void write_points(const PointArrayType& points) 
+{
+  std::cout << "LANDMARKS1" << std::endl;
+  for (size_t i = 0; i < points.size(); i++)
+    std::cout << i << " " << points[i][0] << " " << points[i][1] << " " << points[i][2] << " " << "0" << " " << std::endl;
+}
\ No newline at end of file
diff --git a/tools/clitkTransformLandmarks.ggo b/tools/clitkTransformLandmarks.ggo
new file mode 100644 (file)
index 0000000..3446c6a
--- /dev/null
@@ -0,0 +1,12 @@
+#File clitkTransformLandmarks.ggo
+package "clitkTransformLandmarks"
+version "1.0"
+purpose "Trasnform a set of landmarks with the given 4x4 matrix. Output to stdout."
+
+option "config"     - "Config file"       string    no
+option "verbose"    v     "Verbose"       flag    off
+
+option "input"    i "Input landmarks filename"      string    yes
+option "matrix"   m "Input 4x4 matrix filename ('.mat' file)"      string    yes
+
+