Orfeo Toolbox  3.16
itkNeighborhood.h
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Program: Insight Segmentation & Registration Toolkit
4  Module: $RCSfile: itkNeighborhood.h,v $
5  Language: C++
6  Date: $Date: 2009-04-05 10:56:46 $
7  Version: $Revision: 1.48 $
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 __itkNeighborhood_h
18 #define __itkNeighborhood_h
19 
20 #include <iostream>
22 #include "itkSize.h"
23 #include "itkIndent.h"
24 #include "itkSliceIterator.h"
25 #include "vnl/vnl_vector.h"
26 #include "itkOffset.h"
27 #include <vector>
28 #include <stdlib.h>
29 #include <string.h>
30 
31 namespace itk {
32 
54 template<class TPixel, unsigned int VDimension = 2,
55  class TAllocator = NeighborhoodAllocator<TPixel> >
57 {
58 public:
60  typedef Neighborhood Self;
61 
63  typedef TAllocator AllocatorType;
64 
66  itkStaticConstMacro(NeighborhoodDimension, unsigned int, VDimension);
67 
69  typedef TPixel PixelType;
70 
76 
78  typedef ::itk::Size<VDimension> SizeType;
80 
82  typedef ::itk::Size<VDimension> RadiusType;
83 
86 
89 
92  {
93  m_Radius.Fill(0);
94  m_Size.Fill(0);
95  for (unsigned int i = 0; i < VDimension; i++)
96  {
97  m_StrideTable[i] = 0;
98  }
99  }
100 
102  virtual ~Neighborhood() {}
103 
105  Neighborhood(const Self& other);
106 
108  Self &operator=(const Self& other);
109 
111  bool
112  operator==(const Self& other) const
113  {
114  return (m_Radius == other.m_Radius &&
115  m_Size == other.m_Size &&
116  m_DataBuffer == other.m_DataBuffer);
117  }
118 
120  bool operator!=(const Self& other) const
121  {
122  return (m_Radius != other.m_Radius ||
123  m_Size != other.m_Size ||
124  m_DataBuffer != other.m_DataBuffer);
125  }
126 
128  const SizeType GetRadius() const
129  { return m_Radius; }
130 
133  unsigned long GetRadius(const unsigned long n) const
134  { return m_Radius[n]; }
135 
138  unsigned long GetSize(const unsigned long n) const
139  { return m_Size[n]; }
140 
142  SizeType GetSize() const
143  { return m_Size; }
144 
148  unsigned GetStride(const unsigned axis) const
149  { return m_StrideTable[axis]; }
150 
152  Iterator End()
153  { return m_DataBuffer.end(); }
154  Iterator Begin()
155  { return m_DataBuffer.begin(); }
156  ConstIterator End() const
157  { return m_DataBuffer.end(); }
158  ConstIterator Begin() const
159  { return m_DataBuffer.begin(); }
160 
162  unsigned int Size() const
163  { return m_DataBuffer.size(); }
164 
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]; }
172 
174  TPixel GetCenterValue() const
175  { return (this->operator[]((this->Size())>>1)); }
176 
179  void SetRadius(const SizeType &);
180 
183  void SetRadius(const unsigned long *rad)
184  {
185  SizeType s;
186  memcpy(s.m_Size, rad, sizeof(unsigned long) * VDimension);
187  this->SetRadius(s);
188  }
189 
193  void SetRadius(const unsigned long);
194 
196  void Print(std::ostream& os) const
197  { this->PrintSelf(os, Indent(0)); }
198 
200  AllocatorType &GetBufferReference()
201  { return m_DataBuffer; }
202  const AllocatorType &GetBufferReference() const
203  { return m_DataBuffer; }
204 
206  TPixel &operator[](const OffsetType &o)
207  { return this->operator[](this->GetNeighborhoodIndex(o)); }
208  const TPixel &operator[](const OffsetType &o) const
209  { return this->operator[](this->GetNeighborhoodIndex(o)); }
210 
213  OffsetType GetOffset(unsigned int i) const
214  { return m_OffsetTable[i]; }
215 
216  virtual unsigned int GetNeighborhoodIndex(const OffsetType &) const;
217 
218  unsigned int GetCenterNeighborhoodIndex() const
219  {
220  return static_cast<unsigned int>(this->Size()/2);
221  }
222 
223  std::slice GetSlice(unsigned int) const;
224 
225 protected:
227  void SetSize()
228  {
229  for (unsigned int i=0; i<VDimension; ++i)
230  {
231  m_Size[i] = m_Radius[i]*2+1;
232  }
233  }
234 
236  virtual void Allocate(unsigned int i)
237  { m_DataBuffer.set_size(i); }
238 
240  virtual void PrintSelf(std::ostream&, Indent) const;
241 
243  virtual void ComputeNeighborhoodStrideTable();
244 
247  virtual void ComputeNeighborhoodOffsetTable();
248 
249 private:
253 
257 
260 
263  unsigned int m_StrideTable[VDimension];
264 
266  std::vector<OffsetType> m_OffsetTable;
267 
268 };
269 
270 template <class TPixel, unsigned int VDimension, class TContainer>
271 std::ostream & operator<<(std::ostream &os, const Neighborhood<TPixel,VDimension,TContainer> &neighborhood)
272 {
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;
277 
278  return os;
279 }
280 
281 } // namespace itk
282 
283 // Define instantiation macro for this template.
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 > \
287  Neighborhood##y; } \
288  }
289 
290 #if ITK_TEMPLATE_EXPLICIT
291 # include "Templates/itkNeighborhood+-.h"
292 #endif
293 
294 #if ITK_TEMPLATE_TXX
295 # include "itkNeighborhood.txx"
296 #endif
297 
298 /*
299 #ifndef ITK_MANUAL_INSTANTIATION
300 #include "itkNeighborhood.txx"
301 #endif
302 */
303 
304 #endif

Generated at Sat May 18 2013 23:56:42 for Orfeo Toolbox with doxygen 1.8.3.1