ITK  4.3.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 < class TImage, class 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 
100  typedef typename Superclass::AbsoluteFrequencyType AbsoluteFrequencyType;
101  typedef typename Superclass::TotalAbsoluteFrequencyType TotalAbsoluteFrequencyType;
102  typedef typename Superclass::MeasurementVectorSizeType MeasurementVectorSizeType;
103  typedef typename Superclass::InstanceIdentifier InstanceIdentifier;
104 
106  void SetImage(const TImage* image);
107 
109  const TImage* GetImage() const;
110 
112  void SetRadius(const NeighborhoodRadiusType& radius);
113 
115  NeighborhoodRadiusType GetRadius() const;
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 
136  virtual const MeasurementVectorType & GetMeasurementVector(InstanceIdentifier id) const;
137 
139  AbsoluteFrequencyType GetFrequency(InstanceIdentifier id) const;
140 
142  TotalAbsoluteFrequencyType GetTotalFrequency() const;
143 
149  {
151  public:
152 
154  {
155  *this = adaptor->Begin();
156  }
157 
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 
171  AbsoluteFrequencyType GetFrequency() const
172  {
173  return 1;
174  }
175 
176  const MeasurementVectorType & GetMeasurementVector() const
177  {
178  return this->m_MeasurementVectorCache;
179  }
180 
181  InstanceIdentifier GetInstanceIdentifier() const
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  // 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);
258  ConstIterator& operator=(const ConstIterator& it);
259 
260  private:
261  };
262 
264  Iterator Begin()
265  {
266  NeighborhoodIteratorType nIterator( m_Radius, m_Image, m_Region);
267  nIterator.GoToBegin();
268  Iterator iter(nIterator, 0);
269  return iter;
270  }
272 
274  Iterator End()
275  {
276  NeighborhoodIteratorType nIterator( m_Radius, m_Image, m_Region);
277  nIterator.GoToEnd();
278  Iterator iter(nIterator, m_Region.GetNumberOfPixels());
279  return iter;
280  }
282 
283 
285  ConstIterator Begin() const
286  {
287  NeighborhoodIteratorType nIterator( m_Radius, m_Image, m_Region);
288  nIterator.GoToBegin();
289  ConstIterator iter(nIterator, 0);
290  return iter;
291  }
293 
295  ConstIterator End() const
296  {
297  NeighborhoodIteratorType nIterator( m_Radius, m_Image, m_Region);
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
337