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://oncora1.lyon.fnclcc.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 #ifndef CLITKIMAGEEXTRACTLINE_CXX
19 #define CLITKIMAGEEXTRACTLINE_CXX
21 -------------------------------------------------
22 * @file clitkImageExtractLine.cxx
23 * @author David Sarrut <David.Sarrut@creatis.insa-lyon.fr>
24 * @date 23 Feb 2008 08:37:53
25 -------------------------------------------------*/
28 #include "clitkImageExtractLine_ggo.h"
30 #include "clitkImageCommon.h"
31 #include <itkLineConstIterator.h>
33 //--------------------------------------------------------------------
34 int main(int argc, char * argv[])
38 GGO(clitkImageExtractLine, args_info);
42 typedef float PixelType;
43 const unsigned int Dimension=3;
44 typedef itk::Image<PixelType, Dimension> ImageType;
47 if (args_info.firstIndex_given != Dimension) {
48 std::cerr << "Please give " << Dimension << "values to --firstIndex option" << std::endl;
51 if (args_info.lastIndex_given != Dimension) {
52 std::cerr << "Please give " << Dimension << "values to --lastIndex option" << std::endl;
57 ImageType::Pointer input = clitk::readImage<ImageType>(args_info.input_arg, args_info.verbose_flag);
59 // Get first and last index
60 typedef ImageType::IndexType IndexType;
63 ImageType::SpacingType spacing = input->GetSpacing();
65 for(unsigned int i=0; i<Dimension; i++) {
66 firstIndex[i] = args_info.firstIndex_arg[i];
67 lastIndex[i] = args_info.lastIndex_arg[i];
68 if (args_info.mm_flag) {
69 firstIndex[i] /= spacing[i];
70 lastIndex[i] /= spacing[i];
72 length += pow(lastIndex[i]*spacing[i]-firstIndex[i]*spacing[i],2);
74 length = sqrt(length);
77 std::vector<double> depth;
78 std::vector<double> values;
79 itk::LineConstIterator<ImageType> iter(input, firstIndex, lastIndex);
81 while (!iter.IsAtEnd()) {
82 values.push_back(iter.Get());
85 double step = length/values.size();
87 // If isocenter is used
88 double isoDistance = 0.0;
89 if (args_info.isocenter_given) { // isoCenter is in mm
91 for(unsigned int i=0; i<Dimension; i++) {
92 isoCenter[i] = args_info.isocenter_arg[i];
93 isoDistance += pow(isoCenter[i] - firstIndex[i]*spacing[i],2);
96 isoDistance = sqrt(isoDistance);
101 std::ofstream os(args_info.output_arg);
102 os << "# clitkImageExtractLine from " << args_info.input_arg << std::endl
103 << "# \t firstIndex = " << firstIndex << std::endl
104 << "# \t lastIndex = " << lastIndex << std::endl
105 << "# \t nb values = " << values.size() << std::endl
106 << "# \t length = " << length << std::endl
107 << "# \t step = " << step << std::endl;
108 if (args_info.depth_flag) {
109 double lg = -isoDistance;
110 for(unsigned int i=0; i<values.size(); i++) {
111 os << lg << " " << values[i] << std::endl;
116 for(unsigned int i=0; i<values.size(); i++) {
117 os << values[i] << std::endl;
122 // this is the end my friend
126 #endif //define CLITKIMAGEEXTRACTLINE_CXX