Orfeo Toolbox  4.0
itkNeighborhood.h
Go to the documentation of this file.
1 /*=========================================================================
2  *
3  * Copyright Insight Software Consortium
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0.txt
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  *=========================================================================*/
18 #ifndef __itkNeighborhood_h
19 #define __itkNeighborhood_h
20 
21 #include <iostream>
23 #include "itkIndent.h"
24 #include "itkSliceIterator.h"
25 #include "vnl/vnl_vector.h"
26 #include "itkOffset.h"
27 #include <vector>
28 
29 namespace itk
30 {
53 template< typename TPixel, unsigned int VDimension = 2,
54  typename TAllocator = NeighborhoodAllocator< TPixel > >
56 {
57 public:
59  typedef Neighborhood Self;
60 
62  typedef TAllocator AllocatorType;
63 
65  itkStaticConstMacro(NeighborhoodDimension, unsigned int, VDimension);
66 
68  typedef TPixel PixelType;
69 
75 
77  typedef::itk::Size< VDimension > SizeType;
79 
81  typedef::itk::Size< VDimension > RadiusType;
82 
85 
88 
90  typedef unsigned int DimensionValueType;
91 
95 
98  {
99  m_Radius.Fill(0);
100  m_Size.Fill(0);
101  for ( DimensionValueType i = 0; i < VDimension; i++ )
102  {
103  m_StrideTable[i] = 0;
104  }
105  }
106 
108  virtual ~Neighborhood() {}
109 
111  Neighborhood(const Self & other);
112 
114  Self & operator=(const Self & other);
115 
117  bool
118  operator==(const Self & other) const
119  {
120  return ( m_Radius == other.m_Radius
121  && m_Size == other.m_Size
122  && m_DataBuffer == other.m_DataBuffer );
123  }
124 
126  bool operator!=(const Self & other) const
127  {
128  return ( m_Radius != other.m_Radius
129  || m_Size != other.m_Size
130  || m_DataBuffer != other.m_DataBuffer );
131  }
132 
134  const SizeType GetRadius() const
135  { return m_Radius; }
136 
140  { return m_Radius[n]; }
141 
145  { return m_Size[n]; }
146 
149  { return m_Size; }
150 
155  { return ( axis < VDimension ) ? m_StrideTable[axis] : 0; }
156 
159  { return m_DataBuffer.end(); }
161  { return m_DataBuffer.begin(); }
163  { return m_DataBuffer.end(); }
165  { return m_DataBuffer.begin(); }
166 
169  { return m_DataBuffer.size(); }
170 
173  { return m_DataBuffer[i]; }
174  const TPixel & operator[](NeighborIndexType i) const
175  { return m_DataBuffer[i]; }
177  { return m_DataBuffer[i]; }
178 
180  TPixel GetCenterValue() const
181  { return ( this->operator[]( ( this->Size() ) >> 1 ) ); }
182 
185  void SetRadius(const SizeType &);
186 
189  void SetRadius(const SizeValueType *rad)
190  {
191  SizeType s;
192  std::copy(rad,
193  rad+VDimension,
194  s.m_Size);
195  this->SetRadius(s);
196  }
197 
201  void SetRadius(const SizeValueType);
202 
204  void Print(std::ostream & os) const
205  { this->PrintSelf( os, Indent(0) ); }
206 
209  { return m_DataBuffer; }
211  { return m_DataBuffer; }
212 
214  TPixel & operator[](const OffsetType & o)
215  { return this->operator[]( this->GetNeighborhoodIndex(o) ); }
216  const TPixel & operator[](const OffsetType & o) const
217  { return this->operator[]( this->GetNeighborhoodIndex(o) ); }
218 
222  { return m_OffsetTable[i]; }
223 
224  virtual NeighborIndexType GetNeighborhoodIndex(const OffsetType &) const;
225 
227  {
228  return static_cast< NeighborIndexType >( this->Size() / 2 );
229  }
230 
231  std::slice GetSlice(unsigned int) const;
232 
233 protected:
235  void SetSize()
236  {
237  for ( DimensionValueType i = 0; i < VDimension; ++i )
238  {
239  m_Size[i] = m_Radius[i] * 2 + 1;
240  }
241  }
242 
244  virtual void Allocate(NeighborIndexType i)
245  { m_DataBuffer.set_size(i); }
246 
248  virtual void PrintSelf(std::ostream &, Indent) const;
249 
251  virtual void ComputeNeighborhoodStrideTable();
252 
255  virtual void ComputeNeighborhoodOffsetTable();
256 
257 private:
261 
265 
268 
272 
274  std::vector< OffsetType > m_OffsetTable;
275 };
276 
277 template< typename TPixel, unsigned int VDimension, typename TContainer >
278 std::ostream & operator<<(std::ostream & os, const Neighborhood< TPixel, VDimension, TContainer > & neighborhood)
279 {
280  os << "Neighborhood:" << std::endl;
281  os << " Radius:" << neighborhood.GetRadius() << std::endl;
282  os << " Size:" << neighborhood.GetSize() << std::endl;
283  os << " DataBuffer:" << neighborhood.GetBufferReference() << std::endl;
284 
285  return os;
286 }
287 } // namespace itk
288 
289 #ifndef ITK_MANUAL_INSTANTIATION
290 #include "itkNeighborhood.hxx"
291 #endif
292 
293 /*
294 #ifndef ITK_MANUAL_INSTANTIATION
295 #include "itkNeighborhood.hxx"
296 #endif
297 */
298 
299 #endif

Generated at Sat Mar 8 2014 15:16:48 for Orfeo Toolbox with doxygen 1.8.3.1