ITK  4.6.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;
134 
137 
140 
143 
149  {
151  public:
152 
154  {
155  *this = adaptor->Begin();
156  }
157 
159  {
162  }
163 
165  {
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 
187  {
190  return *this;
191  }
192 
193  bool operator!=(const ConstIterator &it)
194  {
196  }
197 
198  bool operator==(const ConstIterator &it)
199  {
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  // This method is purposely not implemented
215  ConstIterator();
216 
217  private:
220  };
221 
226  class Iterator : public ConstIterator
227  {
228 
230 
231  public:
232 
233  Iterator(Self * adaptor):ConstIterator(adaptor)
234  {
235  }
236 
237  Iterator(const Iterator &iter):ConstIterator( iter )
238  {
239  }
240 
241  Iterator& operator =(const Iterator & iter)
242  {
243  this->ConstIterator::operator=( iter );
244  return *this;
245  }
246 
247 #if !(defined(_MSC_VER) && (_MSC_VER <= 1200))
248  protected:
249 #endif
250  // To ensure const-correctness these method must not be in the public API.
251  // The are purposly not implemented, since they should never be called.
252  Iterator();
253  Iterator(const Self * adaptor);
255  {
256  }
257  Iterator(const ConstIterator & it);
259 
260  private:
261  };
262 
265  {
267  nIterator.GoToBegin();
268  Iterator iter(nIterator, 0);
269  return iter;
270  }
272 
275  {
277  nIterator.GoToEnd();
278  Iterator iter(nIterator, m_Region.GetNumberOfPixels());
279  return iter;
280  }
282 
283 
286  {
288  nIterator.GoToBegin();
289  ConstIterator iter(nIterator, 0);
290  return iter;
291  }
293 
296  {
298  nIterator.GoToEnd();
299  ConstIterator iter(nIterator, m_Region.GetNumberOfPixels());
300  return iter;
301  }
303 
304 protected:
307  void PrintSelf(std::ostream& os, Indent indent) const;
308 
309 private:
310  ImageToNeighborhoodSampleAdaptor(const Self&); //purposely not implemented
311  void operator=(const Self&); //purposely not implemented
312 
321 
322 }; // end of class ImageToNeighborhoodSampleAdaptor
323 
324 } // end of namespace Statistics
325 
326 template <typename TImage, typename TBoundaryCondition>
327  std::ostream & operator<<(std::ostream &os,
329 
330 } // end of namespace itk
331 
332 #ifndef ITK_MANUAL_INSTANTIATION
333 #include "itkImageToNeighborhoodSampleAdaptor.hxx"
334 #endif
335 
336 #endif
ConstIterator(NeighborhoodIteratorType iter, InstanceIdentifier iid)
ConstNeighborhoodIterator< TImage, TBoundaryCondition > NeighborhoodIteratorType
signed long OffsetValueType
Definition: itkIntTypes.h:154
TotalAbsoluteFrequencyType GetTotalFrequency() const
A light-weight container object for storing an N-dimensional neighborhood of values.
std::vector< ConstNeighborhoodIterator< TImage, TBoundaryCondition > > MeasurementVectorType
std::ostream & operator<<(std::ostream &os, const Array< TValue > &arr)
Definition: itkArray.h:184
void SetRadius(const NeighborhoodRadiusType &radius)
Const version of NeighborhoodIterator, defining iteration of a local N-dimensional neighborhood of pi...
void SetRegion(const RegionType &region)
A multi-dimensional iterator templated over image type that walks pixels within a region and is speci...
AbsoluteFrequencyType GetFrequency(InstanceIdentifier id) const
NeighborhoodRadiusType GetRadius() const
virtual const MeasurementVectorType & GetMeasurementVector(InstanceIdentifier id) 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
Iterator(NeighborhoodIteratorType iter, InstanceIdentifier iid)
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.
void PrintSelf(std::ostream &os, Indent indent) const