17 #ifndef __itkNeighborhood_h
18 #define __itkNeighborhood_h
25 #include "vnl/vnl_vector.h"
54 template<
class TPixel,
unsigned int VDimension = 2,
55 class TAllocator = NeighborhoodAllocator<TPixel> >
66 itkStaticConstMacro(NeighborhoodDimension,
unsigned int, VDimension);
95 for (
unsigned int i = 0; i < VDimension; i++)
108 Self &operator=(
const Self& other);
114 return (m_Radius == other.
m_Radius &&
122 return (m_Radius != other.
m_Radius ||
133 unsigned long GetRadius(
const unsigned long n)
const
134 {
return m_Radius[n]; }
138 unsigned long GetSize(
const unsigned long n)
const
139 {
return m_Size[n]; }
148 unsigned GetStride(
const unsigned axis)
const
149 {
return m_StrideTable[axis]; }
153 {
return m_DataBuffer.end(); }
155 {
return m_DataBuffer.begin(); }
157 {
return m_DataBuffer.end(); }
159 {
return m_DataBuffer.begin(); }
163 {
return m_DataBuffer.size(); }
166 TPixel &operator[](
unsigned int i)
167 {
return m_DataBuffer[i]; }
168 const TPixel &operator[](
unsigned int i)
const
169 {
return m_DataBuffer[i]; }
170 TPixel &GetElement(
unsigned int i)
171 {
return m_DataBuffer[i]; }
174 TPixel GetCenterValue()
const
175 {
return (this->
operator[]((this->
Size())>>1)); }
179 void SetRadius(
const SizeType &);
183 void SetRadius(
const unsigned long *rad)
186 memcpy(s.
m_Size, rad,
sizeof(
unsigned long) * VDimension);
193 void SetRadius(
const unsigned long);
196 void Print(std::ostream& os)
const
197 { this->PrintSelf(os,
Indent(0)); }
201 {
return m_DataBuffer; }
203 {
return m_DataBuffer; }
207 {
return this->
operator[](this->GetNeighborhoodIndex(o)); }
209 {
return this->
operator[](this->GetNeighborhoodIndex(o)); }
214 {
return m_OffsetTable[i]; }
216 virtual unsigned int GetNeighborhoodIndex(
const OffsetType &)
const;
218 unsigned int GetCenterNeighborhoodIndex()
const
220 return static_cast<unsigned int>(this->
Size()/2);
223 std::slice GetSlice(
unsigned int)
const;
229 for (
unsigned int i=0; i<VDimension; ++i)
231 m_Size[i] = m_Radius[i]*2+1;
236 virtual void Allocate(
unsigned int i)
237 { m_DataBuffer.set_size(i); }
240 virtual void PrintSelf(std::ostream&,
Indent)
const;
243 virtual void ComputeNeighborhoodStrideTable();
247 virtual void ComputeNeighborhoodOffsetTable();
263 unsigned int m_StrideTable[VDimension];
270 template <
class TPixel,
unsigned int VDimension,
class TContainer>
271 std::ostream & operator<<(std::ostream &os, const Neighborhood<TPixel,VDimension,TContainer> &neighborhood)
273 os <<
"Neighborhood:" << std::endl;
274 os <<
" Radius:" << neighborhood.GetRadius() << std::endl;
275 os <<
" Size:" << neighborhood.GetSize() << std::endl;
276 os <<
" DataBuffer:" << neighborhood.GetBufferReference() << std::endl;
284 #define ITK_TEMPLATE_Neighborhood(_, EXPORT, x, y) namespace itk { \
285 _(2(class EXPORT Neighborhood< ITK_TEMPLATE_2 x >)) \
286 namespace Templates { typedef Neighborhood< ITK_TEMPLATE_2 x > \
290 #if ITK_TEMPLATE_EXPLICIT
291 # include "Templates/itkNeighborhood+-.h"