ITK  4.9.0
Insight Segmentation and Registration Toolkit
itkImageToNeighborhoodSampleAdaptor.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 itkImageToNeighborhoodSampleAdaptor_h
19 #define itkImageToNeighborhoodSampleAdaptor_h
20 
21 #include <typeinfo>
22 #include <vector>
23 #include <iostream>
24 
25 #include "itkImage.h"
26 #include "itkListSample.h"
27 #include "itkSmartPointer.h"
29 #include "itkMacro.h"
32 
33 namespace itk {
34 namespace Statistics {
35 
51  template < typename TImage, typename TBoundaryCondition >
53  public ListSample< std::vector< ConstNeighborhoodIterator< TImage, TBoundaryCondition > > >
54 {
55 public:
58 
61 
64 
67 
69  itkNewMacro(Self);
70 
72  typedef TImage ImageType;
73  typedef typename ImageType::Pointer ImagePointer;
74  typedef typename ImageType::ConstPointer ImageConstPointer;
75  typedef typename ImageType::IndexType IndexType;
76  typedef typename ImageType::OffsetType OffsetType;
78  typedef typename ImageType::PixelType PixelType;
79  typedef typename ImageType::PixelContainerConstPointer PixelContainerConstPointer;
80  typedef typename ImageType::RegionType RegionType;
81  typedef typename RegionType::OffsetTableType OffsetTableType;
82  typedef typename ImageType::SizeType SizeType;
84 
92 
95  typedef typename std::vector< ConstNeighborhoodIterator< TImage, TBoundaryCondition > >
97  typedef typename MeasurementVectorType::value_type ValueType;
99 
104 
106  void SetImage(const TImage* image);
107 
109  const TImage* GetImage() const;
110 
112  void SetRadius(const NeighborhoodRadiusType& radius);
113 
116 
118  void SetRegion(const RegionType& region);
119 
121  RegionType GetRegion() const;
122 
123  void SetUseImageRegion(const bool& flag);
124 
126  itkGetConstMacro( UseImageRegion, bool );
127 
129  itkBooleanMacro( UseImageRegion );
130 
131 
133  InstanceIdentifier Size() const ITK_OVERRIDE;
134 
136  virtual const MeasurementVectorType & GetMeasurementVector(InstanceIdentifier id) const ITK_OVERRIDE;
137 
140 
142  TotalAbsoluteFrequencyType GetTotalFrequency() const ITK_OVERRIDE;
143 
149  {
151  public:
152 
154  {
155  *this = adaptor->Begin();
156  }
157 
158  ConstIterator(const ConstIterator &iter)
159  {
160  m_MeasurementVectorCache = iter.m_MeasurementVectorCache;
161  m_InstanceIdentifier = iter.m_InstanceIdentifier;
162  }
163 
164  ConstIterator& operator=( const ConstIterator & iter )
165  {
166  m_MeasurementVectorCache = iter.m_MeasurementVectorCache;
167  m_InstanceIdentifier = iter.m_InstanceIdentifier;
168  return *this;
169  }
170 
172  {
173  return 1;
174  }
175 
177  {
178  return this->m_MeasurementVectorCache;
179  }
180 
182  {
183  return m_InstanceIdentifier;
184  }
185 
186  ConstIterator& operator++()
187  {
188  ++(m_MeasurementVectorCache[0]);
189  ++m_InstanceIdentifier;
190  return *this;
191  }
192 
193  bool operator!=(const ConstIterator &it)
194  {
195  return (m_MeasurementVectorCache[0] != it.m_MeasurementVectorCache[0]);
196  }
197 
198  bool operator==(const ConstIterator &it)
199  {
200  return (m_MeasurementVectorCache[0] == it.m_MeasurementVectorCache[0]);
201  }
202 
203  protected:
204  // This method should only be available to the ListSample class
207  InstanceIdentifier iid)
208  {
209  this->m_MeasurementVectorCache.clear();
210  this->m_MeasurementVectorCache.push_back(iter);
211  m_InstanceIdentifier = iid;
212  }
213 
214  ConstIterator() ITK_DELETE_FUNCTION;
215 
216  private:
217  mutable MeasurementVectorType m_MeasurementVectorCache;
218  InstanceIdentifier m_InstanceIdentifier;
219  };
220 
225  class Iterator : public ConstIterator
226  {
227 
229 
230  public:
231 
232  Iterator(Self * adaptor):ConstIterator(adaptor)
233  {
234  }
235 
236  Iterator(const Iterator &iter):ConstIterator( iter )
237  {
238  }
239 
240  Iterator& operator =(const Iterator & iter)
241  {
242  this->ConstIterator::operator=( iter );
243  return *this;
244  }
245 
246 #if !(defined(_MSC_VER) && (_MSC_VER <= 1200))
247  protected:
248 #endif
249  // To ensure const-correctness these method must not be in the public API.
250  // The are not implemented, since they should never be called.
251  Iterator() ITK_DELETE_FUNCTION;
252  Iterator(const Self * adaptor) ITK_DELETE_FUNCTION;
253  Iterator(const ConstIterator & it) ITK_DELETE_FUNCTION;
254  ConstIterator& operator=(const ConstIterator& it) ITK_DELETE_FUNCTION;
255 
256  //This copy constructor is actually used in Iterator Begin()!
257  Iterator(NeighborhoodIteratorType iter, InstanceIdentifier iid):ConstIterator( iter, iid )
258  {
259  }
260 
261  private:
262  };
263 
266  {
268  nIterator.GoToBegin();
269  Iterator iter(nIterator, 0);
270  return iter;
271  }
273 
276  {
278  nIterator.GoToEnd();
279  Iterator iter(nIterator, m_Region.GetNumberOfPixels());
280  return iter;
281  }
283 
284 
286  ConstIterator Begin() const
287  {
289  nIterator.GoToBegin();
290  ConstIterator iter(nIterator, 0);
291  return iter;
292  }
294 
296  ConstIterator End() const
297  {
299  nIterator.GoToEnd();
300  ConstIterator iter(nIterator, m_Region.GetNumberOfPixels());
301  return iter;
302  }
304 
305 protected:
308  void PrintSelf(std::ostream& os, Indent indent) const ITK_OVERRIDE;
309 
310 private:
311  ImageToNeighborhoodSampleAdaptor(const Self&) ITK_DELETE_FUNCTION;
312  void operator=(const Self&) ITK_DELETE_FUNCTION;
313 
322 
323 }; // end of class ImageToNeighborhoodSampleAdaptor
324 
325 } // end of namespace Statistics
326 
327 template <typename TImage, typename TBoundaryCondition>
328  std::ostream & operator<<(std::ostream &os,
329  const std::vector< itk::ConstNeighborhoodIterator<TImage, TBoundaryCondition> > &mv);
330 
331 } // end of namespace itk
332 
333 #ifndef ITK_MANUAL_INSTANTIATION
334 #include "itkImageToNeighborhoodSampleAdaptor.hxx"
335 #endif
336 
337 #endif
ConstIterator(NeighborhoodIteratorType iter, InstanceIdentifier iid)
ConstNeighborhoodIterator< TImage, TBoundaryCondition > NeighborhoodIteratorType
void PrintSelf(std::ostream &os, Indent indent) const override
InstanceIdentifier Size() const override
signed long OffsetValueType
Definition: itkIntTypes.h:154
A light-weight container object for storing an N-dimensional neighborhood of values.
std::vector< ConstNeighborhoodIterator< TImage, TBoundaryCondition > > MeasurementVectorType
virtual const MeasurementVectorType & GetMeasurementVector(InstanceIdentifier id) const override
void SetRadius(const NeighborhoodRadiusType &radius)
void operator=(const Self &) ITK_DELETE_FUNCTION
Const version of NeighborhoodIterator, defining iteration of a local N-dimensional neighborhood of pi...
TotalAbsoluteFrequencyType GetTotalFrequency() const override
void SetRegion(const RegionType &region)
A multi-dimensional iterator templated over image type that walks pixels within a region and is speci...
NeighborhoodRadiusType GetRadius() const
ListSample< std::vector< ConstNeighborhoodIterator< TImage, TBoundaryCondition > > > Superclass
This class is the native implementation of the a Sample with an STL container.
Definition: itkListSample.h:51
Control indentation during Print() invocation.
Definition: itkIndent.h:49
This class provides ListSample interface to ITK Image.
NeighborhoodIterator< TImage, TBoundaryCondition > NonConstNeighborhoodIteratorType
Base class for all data objects in ITK.
Defines iteration of a local N-dimensional neighborhood of pixels across an itk::Image.
AbsoluteFrequencyType GetFrequency(InstanceIdentifier id) const override