1 /*=========================================================================
2 Program: vv http://www.creatis.insa-lyon.fr/rio/vv
5 - University of LYON http://www.universite-lyon.fr/
6 - Léon Bérard cancer center http://www.centreleonberard.fr
7 - CREATIS CNRS laboratory http://www.creatis.insa-lyon.fr
9 This software is distributed WITHOUT ANY WARRANTY; without even
10 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
11 PURPOSE. See the copyright notices for more information.
13 It is distributed under dual licence
15 - BSD See included LICENSE.txt file
16 - CeCILL-B http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
17 ===========================================================================*/
18 #include "clitkMaskLandmarks_ggo.h"
25 #include <clitkCommon.h>
26 #include <clitkImageCommon.h>
28 typedef itk::Point<double, 3> PointType;
29 typedef std::vector<PointType> PointArrayType;
31 static void read_points_pts(const std::string& fileName, PointArrayType& points, bool verbose)
33 std::ifstream landmarksFile(fileName.c_str());
34 if (landmarksFile.fail())
36 std::cerr << "ERROR: could not open '" << fileName << "'" << std::endl;
41 std::getline(landmarksFile, line);
42 if (line.find("#X") != 0)
44 std::cerr << "ERROR: invalid landmarks file '" << fileName << "'" << std::endl;
49 while (!landmarksFile.eof())
51 landmarksFile >> p[0] >> p[1] >> p[2];
52 if (landmarksFile.fail())
55 std::cout << "point " << p << std::endl;
60 void write_points_pts(const std::string& fileName, const PointArrayType& points, bool verbose)
62 std::ofstream landmarksFile(fileName.c_str());
64 landmarksFile << "#X\tY\tZ" << std::endl;
65 for (size_t i = 0; i < points.size(); i++)
66 landmarksFile << points[i][0] << "\t" << points[i][1] << "\t" << points[i][2] << "\t" << std::endl;
69 int main(int argc, char** argv)
71 typedef itk::Image<unsigned char, 3> MaskType;
72 typedef MaskType::Pointer MaskPointer;
73 GGO(clitkMaskLandmarks, args_info);
75 if (args_info.input_given != args_info.output_given)
77 std::cerr << "The number of inputs must be equal to the number of outputs" << std::endl;;
81 std::vector<PointArrayType> inputs(args_info.input_given);
82 for (unsigned i = 0; i < args_info.input_given; ++i)
84 read_points_pts(args_info.input_arg[i], inputs[i], args_info.verbose_flag);
85 if (inputs[i].size() != inputs[0].size())
87 std::cerr << "All input files must contain the same amount of points" << std::endl;
92 MaskPointer mask = clitk::readImage<MaskType>(args_info.mask_arg, args_info.verbose_flag);
93 std::vector<PointArrayType> outputs(args_info.input_given);
94 for (unsigned i = 0; i < inputs[0].size(); ++i)
96 MaskType::IndexType idx;
97 if (mask->TransformPhysicalPointToIndex(inputs[0][i], idx) && (*mask)[idx])
98 for (unsigned j = 0; j < args_info.input_given; j++)
99 outputs[j].push_back(inputs[j][i]);
102 for (unsigned i = 0; i < args_info.input_given; ++i)
103 write_points_pts(args_info.output_arg[i], outputs[i], args_info.verbose_flag);