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 "clitkCommon.h"
32 #include <itkLineConstIterator.h>
34 //--------------------------------------------------------------------
35 int main(int argc, char * argv[])
39 GGO(clitkImageExtractLine, args_info);
43 typedef float PixelType;
44 const unsigned int Dimension=3;
45 typedef itk::Image<PixelType, Dimension> ImageType;
48 if (args_info.firstIndex_given != Dimension) {
49 std::cerr << "Please give " << Dimension << "values to --firstIndex option" << std::endl;
52 if (args_info.lastIndex_given != Dimension) {
53 std::cerr << "Please give " << Dimension << "values to --lastIndex option" << std::endl;
58 ImageType::Pointer input = clitk::readImage<ImageType>(args_info.input_arg, args_info.verbose_flag);
60 // Get first and last index
61 typedef ImageType::IndexType IndexType;
64 ImageType::SpacingType spacing = input->GetSpacing();
66 for(unsigned int i=0; i<Dimension; i++) {
67 firstIndex[i] = args_info.firstIndex_arg[i];
68 lastIndex[i] = args_info.lastIndex_arg[i];
69 if (args_info.mm_flag) {
70 firstIndex[i] /= spacing[i];
71 lastIndex[i] /= spacing[i];
73 length += pow(lastIndex[i]*spacing[i]-firstIndex[i]*spacing[i],2);
75 length = sqrt(length);
78 std::vector<double> depth;
79 std::vector<double> values;
80 itk::LineConstIterator<ImageType> iter(input, firstIndex, lastIndex);
82 while (!iter.IsAtEnd()) {
83 values.push_back(iter.Get());
86 double step = length/values.size();
88 // If isocenter is used
89 double isoDistance = 0.0;
90 if (args_info.isocenter_given) { // isoCenter is in mm
92 for(unsigned int i=0; i<Dimension; i++) {
93 isoCenter[i] = args_info.isocenter_arg[i];
94 isoDistance += pow(isoCenter[i] - firstIndex[i]*spacing[i],2);
97 isoDistance = sqrt(isoDistance);
102 std::ofstream os(args_info.output_arg);
103 os << "# clitkImageExtractLine from " << args_info.input_arg << std::endl
104 << "# \t firstIndex = " << firstIndex << std::endl
105 << "# \t lastIndex = " << lastIndex << std::endl
106 << "# \t nb values = " << values.size() << std::endl
107 << "# \t length = " << length << std::endl
108 << "# \t step = " << step << std::endl;
109 if (args_info.depth_flag) {
110 double lg = -isoDistance;
111 for(unsigned int i=0; i<values.size(); i++) {
112 os << lg << " " << values[i] << std::endl;
117 for(unsigned int i=0; i<values.size(); i++) {
118 os << values[i] << std::endl;
123 // this is the end my friend
127 #endif //define CLITKIMAGEEXTRACTLINE_CXX