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 "clitkImageCommon.h"
27 #include <itkLineConstIterator.h>
29 //--------------------------------------------------------------------
30 int main(int argc, char * argv[]) {
33 GGO(clitkImageExtractLine, args_info);
37 typedef float PixelType;
38 const unsigned int Dimension=3;
39 typedef itk::Image<PixelType, Dimension> ImageType;
42 if (args_info.firstIndex_given != Dimension) {
43 std::cerr << "Please give " << Dimension << "values to --firstIndex option" << std::endl;
46 if (args_info.lastIndex_given != Dimension) {
47 std::cerr << "Please give " << Dimension << "values to --lastIndex option" << std::endl;
52 ImageType::Pointer input = clitk::readImage<ImageType>(args_info.input_arg, args_info.verbose_flag);
54 // Get first and last index
55 typedef ImageType::IndexType IndexType;
58 ImageType::SpacingType spacing = input->GetSpacing();
60 for(unsigned int i=0; i<Dimension; i++) {
61 firstIndex[i] = args_info.firstIndex_arg[i];
62 lastIndex[i] = args_info.lastIndex_arg[i];
63 if (args_info.mm_flag) {
64 firstIndex[i] /= spacing[i];
65 lastIndex[i] /= spacing[i];
67 length += pow(lastIndex[i]*spacing[i]-firstIndex[i]*spacing[i],2);
69 length = sqrt(length);
72 std::vector<double> depth;
73 std::vector<double> values;
74 itk::LineConstIterator<ImageType> iter(input, firstIndex, lastIndex);
76 while (!iter.IsAtEnd()) {
77 values.push_back(iter.Get());
80 double step = length/values.size();
82 // If isocenter is used
83 double isoDistance = 0.0;
84 if (args_info.isocenter_given) { // isoCenter is in mm
86 for(unsigned int i=0; i<Dimension; i++) {
87 isoCenter[i] = args_info.isocenter_arg[i];
88 isoDistance += pow(isoCenter[i] - firstIndex[i]*spacing[i],2);
91 isoDistance = sqrt(isoDistance);
96 std::ofstream os(args_info.output_arg);
97 os << "# clitkImageExtractLine from " << args_info.input_arg << std::endl
98 << "# \t firstIndex = " << firstIndex << std::endl
99 << "# \t lastIndex = " << lastIndex << std::endl
100 << "# \t nb values = " << values.size() << std::endl
101 << "# \t length = " << length << std::endl
102 << "# \t step = " << step << std::endl;
103 if (args_info.depth_flag) {
104 double lg = -isoDistance;
105 for(unsigned int i=0; i<values.size(); i++) {
106 os << lg << " " << values[i] << std::endl;
112 for(unsigned int i=0; i<values.size(); i++) {
113 os << values[i] << std::endl;
118 // this is the end my friend
122 #endif //define CLITKIMAGEEXTRACTLINE_CXX