]> Creatis software - clitk.git/blob - tools/clitkProfileImageGenericFilter.cxx
02394d3ca60231943e534a5d036dcf0911cd224a
[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 #include <itkPoint.h>
35
36 #include <clitkCommon.h>
37
38
39
40 namespace clitk
41 {
42
43 //--------------------------------------------------------------------
44 ProfileImageGenericFilter::ProfileImageGenericFilter():
45   ImageToImageGenericFilter<Self>("ProfileImage")
46 {
47   InitializeImageType<2>();
48   InitializeImageType<3>();
49   InitializeImageType<4>();
50 }
51 //--------------------------------------------------------------------
52
53
54 //--------------------------------------------------------------------
55 template<unsigned int Dim>
56 void ProfileImageGenericFilter::InitializeImageType()
57 {
58   ADD_DEFAULT_IMAGE_TYPES(Dim);
59 }
60 //--------------------------------------------------------------------
61
62
63 //--------------------------------------------------------------------
64 vtkFloatArray* ProfileImageGenericFilter::GetArrayX()
65 {
66   return(mArrayX);
67 }
68 //--------------------------------------------------------------------
69
70
71 //--------------------------------------------------------------------
72 vtkFloatArray* ProfileImageGenericFilter::GetArrayY()
73 {
74   return(mArrayY);
75 }
76 //--------------------------------------------------------------------
77
78
79 //--------------------------------------------------------------------
80 vtkFloatArray* ProfileImageGenericFilter::GetCoord()
81 {
82   return(mCoord);
83 }
84 //--------------------------------------------------------------------
85
86
87 //--------------------------------------------------------------------
88 void ProfileImageGenericFilter::SetArgsInfo(const args_info_type & a)
89 {
90   mArgsInfo=a;
91   if (mArgsInfo.verbose_given)
92     SetIOVerbose(mArgsInfo.verbose_flag);
93   if (mArgsInfo.imagetypes_given && mArgsInfo.imagetypes_flag)
94     this->PrintAvailableImageTypes();
95
96   if (mArgsInfo.input_given) {
97     SetInputFilename(mArgsInfo.input_arg);
98   }
99   if (mArgsInfo.output_given) {
100     SetOutputFilename(mArgsInfo.output_arg);
101   }
102 }
103 //--------------------------------------------------------------------
104
105
106 //--------------------------------------------------------------------
107 // Update with the number of dimensions and the pixeltype
108 //--------------------------------------------------------------------
109 template<class InputImageType>
110 void
111 ProfileImageGenericFilter::UpdateWithInputImageType()
112 {
113
114   // Reading input
115   typename InputImageType::Pointer input = this->template GetInput<InputImageType>(0);
116   typedef typename InputImageType::PixelType PixelType;
117   typedef typename InputImageType::IndexType IndexType;
118
119   mArrayX = vtkSmartPointer<vtkFloatArray>::New();
120   mArrayY = vtkSmartPointer<vtkFloatArray>::New();
121   mCoord = vtkSmartPointer<vtkFloatArray>::New();
122   mCoord->SetNumberOfComponents(InputImageType::ImageDimension);
123   
124   /*typename InputImageType::Pointer outputImage;
125   outputImage = InputImageType::New();
126  
127   outputImage->SetRegions(input->GetLargestPossibleRegion());
128   outputImage->Allocate();
129   outputImage->FillBuffer(0); */
130   
131   //Iterator
132   IndexType pointBegin, pointEnd;
133   
134   for (int i = 0; i < mArgsInfo.point1_given; ++i) {
135     pointBegin[i] = mArgsInfo.point1_arg[i];
136     pointEnd[i] = mArgsInfo.point2_arg[i];
137   }
138   
139   itk::LineConstIterator<InputImageType> itProfile(input, pointBegin, pointEnd);
140   itProfile.GoToBegin();
141   int lineNumber(1);
142   double *tuple;
143   double distance;
144   tuple = new double[InputImageType::ImageDimension];
145   itk::Point<double, InputImageType::ImageDimension> transformedFirstPoint;
146   itk::Point<double, InputImageType::ImageDimension> transformedCurrentPoint;
147   
148   input->TransformIndexToPhysicalPoint(itProfile.GetIndex(), transformedFirstPoint);
149   
150   while (!itProfile.IsAtEnd())
151   {    
152     // Fill in the table the intensity value
153     mArrayY->InsertNextTuple1(itProfile.Get());
154         
155     for (int i=0; i<InputImageType::ImageDimension; ++i) {
156         tuple[i] = itProfile.GetIndex()[i];
157     }
158
159     input->TransformIndexToPhysicalPoint(itProfile.GetIndex(), transformedCurrentPoint);
160     distance = transformedFirstPoint.EuclideanDistanceTo(transformedCurrentPoint);
161
162     // Fill in the table the distance value
163     mArrayX->InsertNextTuple1(distance);
164     
165     // Fille in the table the voxel coordinate value
166     mCoord->InsertNextTuple(tuple);
167     ++lineNumber;
168     ++itProfile;
169   }
170   
171   /*
172   itk::LineIterator<InputImageType> otProfile(outputImage, pointBegin, pointEnd);
173   otProfile.GoToBegin();  
174   while (!otProfile.IsAtEnd())
175   {    
176     otProfile.Set(1.0);
177     ++otProfile;
178   }
179   
180   this->template SetNextOutput<InputImageType>(outputImage): */
181   
182   delete [] tuple;
183 }
184 //--------------------------------------------------------------------
185
186
187 }//end clitk
188
189 #endif  //#define clitkProfileImageGenericFilter_cxx