1 #ifndef CLITKIMAGEEXTRACTLINE_CXX
2 #define CLITKIMAGEEXTRACTLINE_CXX
4 -------------------------------------------------
5 * @file clitkImageExtractLine.cxx
6 * @author David Sarrut <David.Sarrut@creatis.insa-lyon.fr>
7 * @date 23 Feb 2008 08:37:53
8 -------------------------------------------------*/
11 #include "clitkImageExtractLine_ggo.h"
13 #include "clitkImageCommon.h"
14 #include <itkLineConstIterator.h>
16 //--------------------------------------------------------------------
17 int main(int argc, char * argv[]) {
20 GGO(clitkImageExtractLine, args_info);
24 typedef float PixelType;
25 const unsigned int Dimension=3;
26 typedef itk::Image<PixelType, Dimension> ImageType;
29 if (args_info.firstIndex_given != Dimension) {
30 std::cerr << "Please give " << Dimension << "values to --firstIndex option" << std::endl;
33 if (args_info.lastIndex_given != Dimension) {
34 std::cerr << "Please give " << Dimension << "values to --lastIndex option" << std::endl;
39 ImageType::Pointer input = clitk::readImage<ImageType>(args_info.input_arg, args_info.verbose_flag);
41 // Get first and last index
42 typedef ImageType::IndexType IndexType;
45 ImageType::SpacingType spacing = input->GetSpacing();
47 for(unsigned int i=0; i<Dimension; i++) {
48 firstIndex[i] = args_info.firstIndex_arg[i];
49 lastIndex[i] = args_info.lastIndex_arg[i];
50 if (args_info.mm_flag) {
51 firstIndex[i] /= spacing[i];
52 lastIndex[i] /= spacing[i];
54 length += pow(lastIndex[i]*spacing[i]-firstIndex[i]*spacing[i],2);
56 length = sqrt(length);
59 std::vector<double> depth;
60 std::vector<double> values;
61 itk::LineConstIterator<ImageType> iter(input, firstIndex, lastIndex);
63 while (!iter.IsAtEnd()) {
64 values.push_back(iter.Get());
67 double step = length/values.size();
69 // If isocenter is used
70 double isoDistance = 0.0;
71 if (args_info.isocenter_given) { // isoCenter is in mm
73 for(unsigned int i=0; i<Dimension; i++) {
74 isoCenter[i] = args_info.isocenter_arg[i];
75 isoDistance += pow(isoCenter[i] - firstIndex[i]*spacing[i],2);
78 isoDistance = sqrt(isoDistance);
83 std::ofstream os(args_info.output_arg);
84 os << "# clitkImageExtractLine from " << args_info.input_arg << std::endl
85 << "# \t firstIndex = " << firstIndex << std::endl
86 << "# \t lastIndex = " << lastIndex << std::endl
87 << "# \t nb values = " << values.size() << std::endl
88 << "# \t length = " << length << std::endl
89 << "# \t step = " << step << std::endl;
90 if (args_info.depth_flag) {
91 double lg = -isoDistance;
92 for(unsigned int i=0; i<values.size(); i++) {
93 os << lg << " " << values[i] << std::endl;
99 for(unsigned int i=0; i<values.size(); i++) {
100 os << values[i] << std::endl;
105 // this is the end my friend
109 #endif //define CLITKIMAGEEXTRACTLINE_CXX