KWStyle - itkVectorLinearInterpolateImageFunction.txx
 
Matrix View
Description

1 /*=========================================================================
2
3   Program:   Insight Segmentation & Registration Toolkit
4   Module:    $RCSfile: itkVectorLinearInterpolateImageFunction.txx.html,v $
5   Language:  C++
6   Date:      $Date: 2006/01/17 19:15:49 $
7   Version:   $Revision: 1.4 $
8
9   Copyright (c) Insight Software Consortium. All rights reserved.
10   See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details.
11
12      This software is distributed WITHOUT ANY WARRANTY; without even 
13      the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
14      PURPOSE.  See the above copyright notices for more information.
15
16 =========================================================================*/
17 DEF #ifndef _itkVectorLinearInterpolateImageFunction_txx
18 DEF #define _itkVectorLinearInterpolateImageFunction_txx
19 #include "itkVectorLinearInterpolateImageFunction.h"
20
21 #include "vnl/vnl_math.h"
22
23 namespace itk
24 {
25
26 /**
27  * Define the number of neighbors
28  */
29 template<class TInputImage, class TCoordRep>
30 const unsigned long
31 VectorLinearInterpolateImageFunction< TInputImage, TCoordRep >
32 ::m_Neighbors = 1 << TInputImage::ImageDimension;
33
34
35 /**
36  * Constructor
37  */
38 template<class TInputImage, class TCoordRep>
39 VectorLinearInterpolateImageFunction< TInputImage, TCoordRep >
40 ::VectorLinearInterpolateImageFunction()
41 {
42
43 }
44
45
46 /**
47  * PrintSelf
48  */
49 template<class TInputImage, class TCoordRep>
50 void
51 VectorLinearInterpolateImageFunction< TInputImage, TCoordRep >
52 ::PrintSelf(std::ostream& os, Indent indent) const
53 {
54   this->Superclass::PrintSelf(os,indent);
55 }
56
57
58 /**
59  * Evaluate at image index position
60  */
61 template<class TInputImage, class TCoordRep>
62 typename VectorLinearInterpolateImageFunction< TInputImage, TCoordRep >
63 ::OutputType
64 VectorLinearInterpolateImageFunction< TInputImage, TCoordRep >
65 ::EvaluateAtContinuousIndex(
66   const ContinuousIndexType& index) const
67 {
68   unsigned int dim;  // index over dimension
69
70   /**
71    * Compute base index = closet index below point
72    * Compute distance from point to base index
73    */
74   signed long baseIndex[ImageDimension];
75   double distance[ImageDimension];
76
77   for( dim = 0; dim < ImageDimension; dim++ )
78     {
79     baseIndex[dim] = (long) floor( index[dim] );
80     distance[dim] = index[dim] - double( baseIndex[dim] );
81     }
82   
83   /**
84    * Interpolated value is the weight some of each of the surrounding
85    * neighbors. The weight for each neighbour is the fraction overlap
86    * of the neighbor pixel with respect to a pixel centered on point.
87    */
88   OutputType output;
89   output.Fill( 0.0 );
90
91   RealType totalOverlap = 0.0;
92
93   for( unsigned int counter = 0; counter < m_Neighbors; counter++ )
94     {
95
96     double overlap = 1.0;          // fraction overlap
97     unsigned int upper = counter;  // each bit indicates upper/lower neighbour
98     IndexType neighIndex;
99
100     // get neighbor index and overlap fraction
101     for( dim = 0; dim < ImageDimension; dim++ )
102       {
103
104       if ( upper & 1 )
105         {
106         neighIndex[dim] = baseIndex[dim] + 1;
107         overlap *= distance[dim];
108         }
109       else
110         {
111         neighIndex[dim] = baseIndex[dim];
112         overlap *= 1.0 - distance[dim];
113         }
114
115       upper >>= 1;
116
117       }
118     
119     // get neighbor value only if overlap is not zero
120     if( overlap )
121       {
122       const PixelType input = this->GetInputImage()->GetPixel( neighIndex );
123       for(unsigned int k = 0; k < Dimension; k++ )
124         {
125         output[k] += overlap * static_cast<RealType>( input[k] );
126         }
127       totalOverlap += overlap;
128       }
129
130     if( totalOverlap == 1.0 )
131       {
132       // finished
133       break;
134       }
135
136     }
137
138   return ( output );
139 }
140
141 // namespace itk
142
143 #endif
144

Generated by KWStyle 1.0b on Tuesday January,17 at 02:14:52PM
© Kitware Inc.