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[]) {
37 GGO(clitkImageExtractLine, args_info);
41 typedef float PixelType;
42 const unsigned int Dimension=3;
43 typedef itk::Image<PixelType, Dimension> ImageType;
46 if (args_info.firstIndex_given != Dimension) {
47 std::cerr << "Please give " << Dimension << "values to --firstIndex option" << std::endl;
50 if (args_info.lastIndex_given != Dimension) {
51 std::cerr << "Please give " << Dimension << "values to --lastIndex option" << std::endl;
56 ImageType::Pointer input = clitk::readImage<ImageType>(args_info.input_arg, args_info.verbose_flag);
58 // Get first and last index
59 typedef ImageType::IndexType IndexType;
62 ImageType::SpacingType spacing = input->GetSpacing();
64 for(unsigned int i=0; i<Dimension; i++) {
65 firstIndex[i] = args_info.firstIndex_arg[i];
66 lastIndex[i] = args_info.lastIndex_arg[i];
67 if (args_info.mm_flag) {
68 firstIndex[i] /= spacing[i];
69 lastIndex[i] /= spacing[i];
71 length += pow(lastIndex[i]*spacing[i]-firstIndex[i]*spacing[i],2);
73 length = sqrt(length);
76 std::vector<double> depth;
77 std::vector<double> values;
78 itk::LineConstIterator<ImageType> iter(input, firstIndex, lastIndex);
80 while (!iter.IsAtEnd()) {
81 values.push_back(iter.Get());
84 double step = length/values.size();
86 // If isocenter is used
87 double isoDistance = 0.0;
88 if (args_info.isocenter_given) { // isoCenter is in mm
90 for(unsigned int i=0; i<Dimension; i++) {
91 isoCenter[i] = args_info.isocenter_arg[i];
92 isoDistance += pow(isoCenter[i] - firstIndex[i]*spacing[i],2);
95 isoDistance = sqrt(isoDistance);
100 std::ofstream os(args_info.output_arg);
101 os << "# clitkImageExtractLine from " << args_info.input_arg << std::endl
102 << "# \t firstIndex = " << firstIndex << std::endl
103 << "# \t lastIndex = " << lastIndex << std::endl
104 << "# \t nb values = " << values.size() << std::endl
105 << "# \t length = " << length << std::endl
106 << "# \t step = " << step << std::endl;
107 if (args_info.depth_flag) {
108 double lg = -isoDistance;
109 for(unsigned int i=0; i<values.size(); i++) {
110 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