From: dsarrut Date: Fri, 25 Mar 2011 13:15:28 +0000 (+0000) Subject: Romulo: X-Git-Tag: v1.2.0~117 X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=commitdiff_plain;h=aba2595cd9d47d81d74e873f758877c56e9a79b7;p=clitk.git Romulo: - new tool: clitkTransformLandmarks Trasnform a set of landmarks with the given 4x4 matrix. Output to stdout. --- diff --git a/tools/CMakeLists.txt b/tools/CMakeLists.txt index 5454a12..8fdef8d 100644 --- a/tools/CMakeLists.txt +++ b/tools/CMakeLists.txt @@ -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 index 0000000..fc92886 --- /dev/null +++ b/tools/clitkTransformLandmarks.cxx @@ -0,0 +1,82 @@ +#include "clitkTransformLandmarks_ggo.h" + +#include "clitkTransformUtilities.h" +#include +#include +#include +#include + +typedef itk::Matrix MatrixType; +typedef itk::Point PointType; +typedef std::vector 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 index 0000000..3446c6a --- /dev/null +++ b/tools/clitkTransformLandmarks.ggo @@ -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 + +