KWStyle - itkPeriodicBoundaryCondition.txx
 
Matrix View
Description

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

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