1 /*=========================================================================
2 Program: vv http://www.creatis.insa-lyon.fr/rio/vv
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
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.
13 It is distributed under dual licence
15 - BSD See included LICENSE.txt file
16 - CeCILL-B http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
17 ===========================================================================**/
18 #ifndef CLITKIMAGEEXTRACTLINE_CXX
19 #define CLITKIMAGEEXTRACTLINE_CXX
21 -------------------------------------------------
22 * @file clitkImageExtractLine.cxx
23 * @author David Sarrut <David.Sarrut@creatis.insa-lyon.fr>
24 * @date 23 Feb 2008 08:37:53
25 * @modified by Loïc Grevillot <Loic.Grevillot@creatis.insa-lyon.fr>
27 * Option -I added, in order to integrate plans perpendicular to a line
29 -------------------------------------------------*/
32 #include "clitkImageExtractLine_ggo.h"
34 #include "clitkImageCommon.h"
35 #include "clitkCommon.h"
36 #include <itkLineConstIterator.h>
38 //--------------------------------------------------------------------
39 int main(int argc, char * argv[])
43 GGO(clitkImageExtractLine, args_info);
47 typedef float PixelType;
48 const unsigned int Dimension=3;
49 typedef itk::Image<PixelType, Dimension> ImageType;
50 typedef itk::Size<Dimension> SizeType;
53 if (args_info.firstIndex_given != Dimension) {
54 std::cerr << "Please give " << Dimension << "values to --firstIndex option" << std::endl;
57 if (args_info.lastIndex_given != Dimension) {
58 std::cerr << "Please give " << Dimension << "values to --lastIndex option" << std::endl;
63 ImageType::Pointer input = clitk::readImage<ImageType>(args_info.input_arg, args_info.verbose_flag);
65 // Get first and last index
66 typedef ImageType::IndexType IndexType;
69 ImageType::SpacingType spacing = input->GetSpacing();
71 for(unsigned int i=0; i<Dimension; i++) {
72 firstIndex[i] = args_info.firstIndex_arg[i];
73 lastIndex[i] = args_info.lastIndex_arg[i];
74 if (args_info.mm_flag) {
75 firstIndex[i] /= spacing[i];
76 lastIndex[i] /= spacing[i];
78 length += pow(lastIndex[i]*spacing[i]-firstIndex[i]*spacing[i],2);
80 length = sqrt(length);
83 // std::vector<double> depth;
84 // std::vector<double> values;
85 // itk::LineConstIterator<ImageType> iter(input, firstIndex, lastIndex);
87 // while (!iter.IsAtEnd()) {
88 // values.push_back(iter.Get());
91 // double step = length/values.size();
93 std::vector<double> depth;
94 std::vector<double> values;
95 itk::LineConstIterator<ImageType> iter(input, firstIndex, lastIndex);
98 // args_info.integral_arg=0, so, it does not compute the integral
99 if (args_info.integral_arg==0){
101 while (!iter.IsAtEnd()) {
102 values.push_back(iter.Get());
106 // args_info.integral_arg=1, so, it computes the integral
107 if (args_info.integral_arg!=0){
109 if (args_info.integralAxis_arg==0){
114 else if (args_info.integralAxis_arg==1){
119 else if (args_info.integralAxis_arg==2){
124 else {std::cout<<"Wrong axis"<<std::endl;
128 length=(lastIndex[b]-firstIndex[b])*spacing[b];
130 std::cout<<"The line is extracted along axis "<<args_info.integralAxis_arg<<std::endl;
131 std::cout<<"The line is integrated between "<<args_info.firstIndex_arg[a]<<" and "<<args_info.lastIndex_arg[a]<<" along axis "<<a<<std::endl;
132 std::cout<<"The line is integrated between "<<args_info.firstIndex_arg[c]<<" and "<<args_info.lastIndex_arg[c]<<" along axis "<<c<<std::endl;
135 dim=input->GetLargestPossibleRegion().GetSize();
139 std::vector<double> val(dim[b]);
140 for (uint i=0; i<dim[b]; i++)
145 for (int i=args_info.firstIndex_arg[a]; i<args_info.lastIndex_arg[a]; i++){
146 for (int j=args_info.firstIndex_arg[c]; j<args_info.lastIndex_arg[c]; j++){
147 // std::cout<<"i "<<i<<" j "<<j<<std::endl;
153 // std::cout<<"A"<<std::endl;
154 itk::LineConstIterator<ImageType> iter(input, firstIndex, lastIndex);
156 // std::cout<<"B"<<std::endl;
159 // std::cout<<"C"<<std::endl;
160 while (!iter.IsAtEnd()) {
161 // std::cout<<"D "<<k<<std::endl;
169 for (unsigned int i=0; i<dim[b]; i++){
170 values.push_back(val[i]);
174 double step = length/values.size();
177 // If isocenter is used
178 double isoDistance = 0.0;
179 if (args_info.isocenter_given) { // isoCenter is in mm
181 for(unsigned int i=0; i<Dimension; i++) {
182 isoCenter[i] = args_info.isocenter_arg[i];
183 isoDistance += pow(isoCenter[i] - firstIndex[i]*spacing[i],2);
186 isoDistance = sqrt(isoDistance);
191 std::ofstream os(args_info.output_arg);
192 os << "# clitkImageExtractLine from " << args_info.input_arg << std::endl
193 << "# \t firstIndex = " << firstIndex << std::endl
194 << "# \t lastIndex = " << lastIndex << std::endl
195 << "# \t nb values = " << values.size() << std::endl
196 << "# \t length = " << length << std::endl
197 << "# \t step = " << step << std::endl;
198 if (args_info.depth_flag) {
199 double lg = -isoDistance;
200 for(unsigned int i=0; i<values.size(); i++) {
201 os << lg << " " << values[i] << std::endl;
206 for(unsigned int i=0; i<values.size(); i++) {
207 os << values[i] << std::endl;
212 // this is the end my friend
216 #endif //define CLITKIMAGEEXTRACTLINE_CXX