Orfeo Toolbox  3.16
itkPeriodicBoundaryCondition.txx
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Program: Insight Segmentation & Registration Toolkit
4  Module: $RCSfile: itkPeriodicBoundaryCondition.txx,v $
5  Language: C++
6  Date: $Date: 2007-02-02 14:46:33 $
7  Version: $Revision: 1.8 $
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 #ifndef __itkPeriodicBoundaryCondition_txx
18 #define __itkPeriodicBoundaryCondition_txx
21 namespace itk
22 {
23 template<class TImage>
24 typename PeriodicBoundaryCondition<TImage>::PixelType
26 ::operator()(const OffsetType& point_index, const OffsetType& boundary_offset,
27  const NeighborhoodType *data) const
28 {
29  typedef typename OffsetType::OffsetValueType OffsetValueType;
30  const ConstNeighborhoodIterator<TImage> * iterator
31  = dynamic_cast<const ConstNeighborhoodIterator<TImage> *>(data);
32  typename TImage::PixelType *ptr;
33  int linear_index = 0;
34  unsigned int i;
35 
36  // Find the pointer of the closest boundary pixel
37 
38  // Return the value of the pixel at the closest boundary point.
39  for (i = 0; i < ImageDimension; ++i)
40  {
41  linear_index += (point_index[i] + boundary_offset[i]) * data->GetStride(i);
42  }
43  ptr = data->operator[](linear_index);
44 
45  // Wrap the pointer around the image in the necessary dimensions. If we have
46  // reached this point, we can assume that we are on the edge of the BUFFERED
47  // region of the image. Boundary conditions are only invoked if touching the
48  // actual memory boundary.
49 
50  // These are the step sizes for increments in each dimension of the image.
51  const typename TImage::OffsetValueType * offset_table
52  = iterator->GetImagePointer()->GetOffsetTable();
53 
54 
55  for (i = 0; i < ImageDimension; ++i)
56  {
57  if (boundary_offset[i] != 0)
58  { // If the neighborhood overlaps on the low edge, then wrap from the
59  // high edge of the image.
60  if (point_index[i] < static_cast<OffsetValueType>(iterator->GetRadius(i)))
61  {
62  ptr += iterator->GetImagePointer()->GetBufferedRegion().GetSize()[i] *
63  offset_table[i] - boundary_offset[i] * offset_table[i];
64  }
65  else // wrap from the low side of the image
66  {
67  ptr -= iterator->GetImagePointer()->GetBufferedRegion().GetSize()[i] *
68  offset_table[i] + boundary_offset[i] * offset_table[i];
69  }
70  }
71  }
72 
73  return *ptr;
74 }
75 
76 template<class TImage>
79 ::operator()(const OffsetType& point_index, const OffsetType& boundary_offset,
80  const NeighborhoodType *data,
81  const NeighborhoodAccessorFunctorType &neighborhoodAccessorFunctor) const
82 {
83  typedef typename OffsetType::OffsetValueType OffsetValueType;
84  const ConstNeighborhoodIterator<TImage> * iterator
85  = dynamic_cast<const ConstNeighborhoodIterator<TImage> *>(data);
86  typename TImage::PixelType *ptr;
87  int linear_index = 0;
88  unsigned int i;
89 
90  // Find the pointer of the closest boundary pixel
91  // std::cout << "Boundary offset = " << boundary_offset << std::endl;
92  // std::cout << "point index = " << point_index << std::endl;
93 
94 
95  // Return the value of the pixel at the closest boundary point.
96  for (i = 0; i < ImageDimension; ++i)
97  {
98  linear_index += (point_index[i] + boundary_offset[i]) * data->GetStride(i);
99  }
100  ptr = data->operator[](linear_index);
101 
102  // Wrap the pointer around the image in the necessary dimensions. If we have
103  // reached this point, we can assume that we are on the edge of the BUFFERED
104  // region of the image. Boundary conditions are only invoked if touching the
105  // actual memory boundary.
106 
107  // These are the step sizes for increments in each dimension of the image.
108  const typename TImage::OffsetValueType * offset_table
109  = iterator->GetImagePointer()->GetOffsetTable();
110 
111 
112  for (i = 0; i < ImageDimension; ++i)
113  {
114  if (boundary_offset[i] != 0)
115  { // If the neighborhood overlaps on the low edge, then wrap from the
116  // high edge of the image.
117  if (point_index[i] < static_cast<OffsetValueType>(iterator->GetRadius(i)))
118  {
119  ptr += iterator->GetImagePointer()->GetBufferedRegion().GetSize()[i] *
120  offset_table[i] - boundary_offset[i] * offset_table[i];
121  }
122  else // wrap from the low side of the image
123  {
124  ptr -= iterator->GetImagePointer()->GetBufferedRegion().GetSize()[i] *
125  offset_table[i] + boundary_offset[i] * offset_table[i];
126  }
127  }
128  }
129 
130  return neighborhoodAccessorFunctor.Get(ptr);
131 }
132 } // end namespace itk
133 
134 #endif

Generated at Sat Feb 2 2013 23:59:24 for Orfeo Toolbox with doxygen 1.8.1.1