]> Creatis software - clitk.git/blob - tools/clitkProfileImageGenericFilter.cxx
Add the profile display and the saving a text file
[clitk.git] / tools / clitkProfileImageGenericFilter.cxx
1 /*=========================================================================
2   Program:   vv                     http://www.creatis.insa-lyon.fr/rio/vv
3
4   Authors belong to:
5   - University of LYON              http://www.universite-lyon.fr/
6   - Léon Bérard cancer center       http://www.centreleonberard.fr
7   - CREATIS CNRS laboratory         http://www.creatis.insa-lyon.fr
8
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.
12
13   It is distributed under dual licence
14
15   - BSD        See included LICENSE.txt file
16   - CeCILL-B   http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
17 ===========================================================================**/
18 #ifndef clitkProfileImageGenericFilter_cxx
19 #define clitkProfileImageGenericFilter_cxx
20
21 /* =================================================
22  * @file   clitkProfileImageGenericFilter.cxx
23  * @author Thomas Baudier <thomas.baudier@creatis.insa-lyon.fr>
24  * @date   22 dec 2015
25  *
26  * @brief
27  *
28  ===================================================*/
29
30 #include "clitkProfileImageGenericFilter.h"
31
32 // itk include
33 #include <itkLineIterator.h>
34
35 #include <clitkCommon.h>
36
37
38
39 namespace clitk
40 {
41
42 //--------------------------------------------------------------------
43 ProfileImageGenericFilter::ProfileImageGenericFilter():
44   ImageToImageGenericFilter<Self>("ProfileImage")
45 {
46   InitializeImageType<2>();
47   InitializeImageType<3>();
48   InitializeImageType<4>();
49 }
50 //--------------------------------------------------------------------
51
52
53 //--------------------------------------------------------------------
54 template<unsigned int Dim>
55 void ProfileImageGenericFilter::InitializeImageType()
56 {
57   ADD_DEFAULT_IMAGE_TYPES(Dim);
58 }
59 //--------------------------------------------------------------------
60
61
62 //--------------------------------------------------------------------
63 vtkFloatArray* ProfileImageGenericFilter::GetArrayX()
64 {
65   return(mArrayX);
66 }
67 //--------------------------------------------------------------------
68
69
70 //--------------------------------------------------------------------
71 vtkFloatArray* ProfileImageGenericFilter::GetArrayY()
72 {
73   return(mArrayY);
74 }
75 //--------------------------------------------------------------------
76
77
78 //--------------------------------------------------------------------
79 vtkFloatArray* ProfileImageGenericFilter::GetCoord()
80 {
81   return(mCoord);
82 }
83 //--------------------------------------------------------------------
84
85
86 //--------------------------------------------------------------------
87 void ProfileImageGenericFilter::SetArgsInfo(const args_info_type & a)
88 {
89   mArgsInfo=a;
90   if (mArgsInfo.verbose_given)
91     SetIOVerbose(mArgsInfo.verbose_flag);
92   if (mArgsInfo.imagetypes_given && mArgsInfo.imagetypes_flag)
93     this->PrintAvailableImageTypes();
94
95   if (mArgsInfo.input_given) {
96     SetInputFilename(mArgsInfo.input_arg);
97   }
98   if (mArgsInfo.output_given) {
99     SetOutputFilename(mArgsInfo.output_arg);
100   }
101 }
102 //--------------------------------------------------------------------
103
104
105 //--------------------------------------------------------------------
106 // Update with the number of dimensions and the pixeltype
107 //--------------------------------------------------------------------
108 template<class InputImageType>
109 void
110 ProfileImageGenericFilter::UpdateWithInputImageType()
111 {
112
113   // Reading input
114   typename InputImageType::Pointer input = this->template GetInput<InputImageType>(0);
115   typedef typename InputImageType::PixelType PixelType;
116   typedef typename InputImageType::IndexType IndexType;
117
118   mArrayX = vtkSmartPointer<vtkFloatArray>::New();
119   mArrayY = vtkSmartPointer<vtkFloatArray>::New();
120   mCoord = vtkSmartPointer<vtkFloatArray>::New();
121   mCoord->SetNumberOfComponents(InputImageType::ImageDimension);
122   
123   //Iterator
124   IndexType pointBegin, pointEnd;
125   
126   for (int i = 0; i < mArgsInfo.point1_given; ++i) {
127     pointBegin[i] = mArgsInfo.point1_arg[i];
128     pointEnd[i] = mArgsInfo.point2_arg[i];
129   }
130   
131   itk::LineConstIterator<InputImageType> itProfile(input, pointBegin, pointEnd);
132   itProfile.GoToBegin();
133   int lineNumber(1);
134   double *tuple;
135   tuple = new double[InputImageType::ImageDimension];
136   
137   while (!itProfile.IsAtEnd())
138   {    
139     // Fill in the table
140     mArrayX->InsertNextTuple1(lineNumber);
141     mArrayY->InsertNextTuple1(itProfile.Get());
142         
143     for (int i=0; i<InputImageType::ImageDimension; ++i) {
144         tuple[i] = itProfile.GetIndex()[i];
145     }
146     
147     mCoord->InsertNextTuple(tuple);
148     ++lineNumber;
149     ++itProfile;
150   }
151   
152   delete [] tuple;
153 }
154 //--------------------------------------------------------------------
155
156
157 }//end clitk
158
159 #endif  //#define clitkProfileImageGenericFilter_cxx