1 /*-------------------------------------------------------------------------
3 Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
4 l'Image). All rights reserved. See Doc/License.txt or
5 http://www.creatis.insa-lyon.fr/Public/Gdcm/License.html for details.
7 This software is distributed WITHOUT ANY WARRANTY; without even
8 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
9 PURPOSE. See the above copyright notices for more information.
11 -------------------------------------------------------------------------*/
13 #ifndef CLITKIMAGEEXTRACTLINE_CXX
14 #define CLITKIMAGEEXTRACTLINE_CXX
17 -------------------------------------------------
18 * @file clitkImageExtractLine.cxx
19 * @author David Sarrut <David.Sarrut@creatis.insa-lyon.fr>
20 * @date 23 Feb 2008 08:37:53
21 -------------------------------------------------*/
24 #include "clitkImageExtractLine_ggo.h"
26 #include <itkLineConstIterator.h>
28 //--------------------------------------------------------------------
29 int main(int argc, char * argv[]) {
32 GGO(clitkImageExtractLine, args_info);
36 typedef float PixelType;
37 const unsigned int Dimension=3;
38 typedef itk::Image<PixelType, Dimension> ImageType;
41 if (args_info.firstIndex_given != Dimension) {
42 std::cerr << "Please give " << Dimension << "values to --firstIndex option" << std::endl;
45 if (args_info.lastIndex_given != Dimension) {
46 std::cerr << "Please give " << Dimension << "values to --lastIndex option" << std::endl;
51 ImageType::Pointer input = clitk::readImage<ImageType>(args_info.input_arg, args_info.verbose_flag);
53 // Get first and last index
54 typedef ImageType::IndexType IndexType;
57 ImageType::SpacingType spacing = input->GetSpacing();
59 for(unsigned int i=0; i<Dimension; i++) {
60 firstIndex[i] = args_info.firstIndex_arg[i];
61 lastIndex[i] = args_info.lastIndex_arg[i];
62 if (args_info.mm_flag) {
63 firstIndex[i] /= spacing[i];
64 lastIndex[i] /= spacing[i];
66 length += pow(lastIndex[i]*spacing[i]-firstIndex[i]*spacing[i],2);
68 length = sqrt(length);
71 std::vector<double> depth;
72 std::vector<double> values;
73 itk::LineConstIterator<ImageType> iter(input, firstIndex, lastIndex);
75 while (!iter.IsAtEnd()) {
76 values.push_back(iter.Get());
79 double step = length/values.size();
81 // If isocenter is used
82 double isoDistance = 0.0;
83 if (args_info.isocenter_given) { // isoCenter is in mm
85 for(unsigned int i=0; i<Dimension; i++) {
86 isoCenter[i] = args_info.isocenter_arg[i];
87 isoDistance += pow(isoCenter[i] - firstIndex[i]*spacing[i],2);
90 isoDistance = sqrt(isoDistance);
95 std::ofstream os(args_info.output_arg);
96 os << "# clitkImageExtractLine from " << args_info.input_arg << std::endl
97 << "# \t firstIndex = " << firstIndex << std::endl
98 << "# \t lastIndex = " << lastIndex << std::endl
99 << "# \t nb values = " << values.size() << std::endl
100 << "# \t length = " << length << std::endl
101 << "# \t step = " << step << std::endl;
102 if (args_info.depth_flag) {
103 double lg = -isoDistance;
104 for(unsigned int i=0; i<values.size(); i++) {
105 os << lg << " " << values[i] << std::endl;
111 for(unsigned int i=0; i<values.size(); i++) {
112 os << values[i] << std::endl;
117 // this is the end my friend
121 #endif //define CLITKIMAGEEXTRACTLINE_CXX