From: dsarrut Date: Mon, 28 Mar 2011 10:45:48 +0000 (+0000) Subject: Romulo: X-Git-Tag: v1.2.0~99 X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=commitdiff_plain;h=7dd4f61d0341af69d3c6ddfb115a219bc54284c3;p=clitk.git Romulo: - Tool now supports files in pts (Jef) and txt (VV) formats (-t/--type option) --- diff --git a/tools/clitkTransformLandmarks.cxx b/tools/clitkTransformLandmarks.cxx index 4d42408..4db65a5 100644 --- a/tools/clitkTransformLandmarks.cxx +++ b/tools/clitkTransformLandmarks.cxx @@ -9,10 +9,18 @@ typedef itk::Matrix MatrixType; typedef itk::Point PointType; typedef std::vector PointArrayType; +typedef itk::FixedArray TxtDataType; +typedef std::vector TxtDataArrayType; + + +void read_points_txt(const std::string& fileName, PointArrayType& points, TxtDataArrayType& data); +void write_points_txt(const std::string& fileName, const PointArrayType& points, const TxtDataArrayType& data); + +void read_points_pts(const std::string& fileName, PointArrayType& points); +void write_points_pts(const std::string& fileName, const PointArrayType& points); -void read_points(const std::string& fileName, PointArrayType& points); void transform_points(const PointArrayType& input, const MatrixType& matrix, PointArrayType& output); -void write_points(const std::string& fileName, const PointArrayType& points); + bool verbose = false; @@ -21,19 +29,31 @@ int main(int argc, char** argv) GGO(clitkTransformLandmarks, args_info); verbose = args_info.verbose_flag; - PointArrayType inputPoints; - read_points(args_info.input_arg, inputPoints); - MatrixType matrix = clitk::ReadMatrix3D(args_info.matrix_arg); + TxtDataArrayType data; + PointArrayType inputPoints; + if (strcmp(args_info.type_arg, "txt") == 0) { + read_points_txt(args_info.input_arg, inputPoints, data); + } + else { + read_points_pts(args_info.input_arg, inputPoints); + } + PointArrayType outputPoints; transform_points(inputPoints, matrix, outputPoints); + + if (strcmp(args_info.type_arg, "txt") == 0) { + write_points_txt(args_info.output_arg, outputPoints, data); + } + else { + write_points_pts(args_info.output_arg, outputPoints); + } - write_points(args_info.output_arg, outputPoints); return 0; } -void read_points(const std::string& fileName, PointArrayType& points) +void read_points_txt(const std::string& fileName, PointArrayType& points, TxtDataArrayType& data) { std::ifstream landmarksFile(fileName.c_str()); if (landmarksFile.fail()) { @@ -48,38 +68,81 @@ void read_points(const std::string& fileName, PointArrayType& points) exit(-3); } - int id = 0; - PointType point; - point.Fill(1); + PointType p; + p.Fill(1); + + TxtDataType d; - std::istringstream linestr; while (!landmarksFile.eof()) { - std::getline(landmarksFile, line); - if (verbose) std::cout << "line " << line << std::endl; + // read id, x, y, z, d1, d2 + landmarksFile >> d[0] >> p[0] >> p[1] >> p[2] >> d[1];// >> d[2]; + if (landmarksFile.fail()) + break; - 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); + if (verbose){ + std::cout << "point " << p << std::endl; + std::cout << "data " << " " << d[0] << " " << d[1] << std::endl; } + + points.push_back(p); + data.push_back(d); } } -void transform_points(const PointArrayType& input, const MatrixType& matrix, PointArrayType& output) +void write_points_txt(const std::string& fileName, const PointArrayType& points, const TxtDataArrayType& data) { - for (size_t i = 0; i < input.size(); i++) { - output.push_back(matrix * input[i]); + std::ofstream landmarksFile(fileName.c_str()); + + landmarksFile << "LANDMARKS1" << std::endl; + for (size_t i = 0; i < points.size(); i++) + landmarksFile << data[i][0] << " " << points[i][0] << " " << points[i][1] << " " << points[i][2] << " " << data[i][1] << " " << std::endl; +} + +void read_points_pts(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("#X") != 0) { + std::cout << "ERROR: invalid landmarks file '" << fileName << "'" << std::endl; + exit(-3); + } + + PointType p; + p.Fill(1); + + while (!landmarksFile.eof()) { + // read id, x, y, z, d1, d2 + landmarksFile >> p[0] >> p[1] >> p[2]; + if (landmarksFile.fail()) + break; + + if (verbose){ + std::cout << "point " << p << std::endl; + } + + points.push_back(p); } } -void write_points(const std::string& fileName, const PointArrayType& points) +void write_points_pts(const std::string& fileName, const PointArrayType& points) { std::ofstream landmarksFile(fileName.c_str()); - landmarksFile << "LANDMARKS1" << std::endl; + landmarksFile << "#X\tY\tZ" << std::endl; for (size_t i = 0; i < points.size(); i++) - landmarksFile << i << " " << points[i][0] << " " << points[i][1] << " " << points[i][2] << " " << "0" << " " << std::endl; -} \ No newline at end of file + landmarksFile << points[i][0] << "\t" << points[i][1] << "\t" << points[i][2] << "\t" << std::endl; +} + +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]); + } +} + diff --git a/tools/clitkTransformLandmarks.ggo b/tools/clitkTransformLandmarks.ggo index c9eac33..71186ef 100644 --- a/tools/clitkTransformLandmarks.ggo +++ b/tools/clitkTransformLandmarks.ggo @@ -8,6 +8,7 @@ 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 -option "output" o "Output landmarks filename" string yes +option "output" o "Output landmarks filename" string yes +option "type" t "Landmarks type ('pts' for Jef; 'txt' for VV)" string no default="txt"