ITK  4.2.0
Insight Segmentation and Registration Toolkit
itkJointDomainImageToListSampleAdaptor.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 __itkJointDomainImageToListSampleAdaptor_h
19 #define __itkJointDomainImageToListSampleAdaptor_h
20 
21 #include "itkPoint.h"
22 #include "itkPixelTraits.h"
24 #include "itkImageRegionIterator.h"
25 #include "itkListSample.h"
26 
27 namespace itk
28 {
29 namespace Statistics
30 {
39 template< class TImage >
44 
45  itkStaticConstMacro(ImageDimension, unsigned int, TImage::ImageDimension);
46  itkStaticConstMacro(Dimension,
47  unsigned int,
48  TImage::ImageDimension
50 
51  typedef float CoordinateRepType;
55 
58 }; // end of ImageJointDomainTraits
59 
90 template< class TImage >
92  public ListSample< typename ImageJointDomainTraits< TImage >::MeasurementVectorType >
93 {
94 public:
95 
98 
99  typedef ListSample<
101 
104 
106 
112 
115 
117  itkNewMacro(Self);
118 
120  itkStaticConstMacro(MeasurementVectorSize, unsigned int,
121  ImageJointDomainTraitsType::Dimension);
122 
123  typedef typename Superclass::MeasurementVectorSizeType MeasurementVectorSizeType;
124 
127  typedef typename Superclass::AbsoluteFrequencyType AbsoluteFrequencyType;
128  typedef typename Superclass::TotalAbsoluteFrequencyType TotalAbsoluteFrequencyType;
129  typedef typename Superclass::InstanceIdentifier InstanceIdentifier;
130 
132  typedef TImage ImageType;
135 
136  typedef typename ImageType::Pointer ImagePointer;
137  typedef typename ImageType::ConstPointer ImageConstPointer;
138  typedef typename ImageType::PixelType PixelType;
139  typedef typename ImageType::PixelContainerConstPointer PixelContainerConstPointer;
140  typedef typename ImageType::IndexType ImageIndexType;
141  typedef typename ImageType::SizeType ImageSizeType;
142  typedef typename ImageType::RegionType ImageRegionType;
144 
146  void SetImage(const TImage *image);
147 
149  const TImage * GetImage() const;
150 
152  InstanceIdentifier Size() const;
153 
155  AbsoluteFrequencyType GetFrequency(InstanceIdentifier id) const;
156 
158  TotalAbsoluteFrequencyType GetTotalFrequency() const;
159 
160  itkStaticConstMacro(RangeDomainDimension, unsigned int,
162 
164  itkGetStaticConstMacro(RangeDomainDimension) > RangeDomainMeasurementVectorType;
165 
166  typedef std::vector< InstanceIdentifier > InstanceIdentifierVectorType;
168 
170  void SetNormalizationFactors(NormalizationFactorsType & factors);
171 
174  const MeasurementVectorType & GetMeasurementVector(InstanceIdentifier id) const;
175 
177  itkSetMacro(UsePixelContainer, bool);
178  itkGetConstMacro(UsePixelContainer, bool);
179  itkBooleanMacro(UsePixelContainer);
181 
182  // void PrintSelf(std::ostream& os, Indent indent) const;
183 
189  {
191 public:
192 
194  {
195  *this = adaptor->Begin();
196  }
197 
199  {
200  m_InstanceIdentifier = iter.m_InstanceIdentifier;
201  m_Adaptor = iter.m_Adaptor;
202  }
203 
204  ConstIterator & operator=(const ConstIterator & iter)
205  {
206  m_InstanceIdentifier = iter.m_InstanceIdentifier;
207  return *this;
208  }
209 
210  AbsoluteFrequencyType GetFrequency() const
211  {
212  return 1;
213  }
214 
215  const MeasurementVectorType & GetMeasurementVector() const
216  {
217  m_MeasurementVectorCache = m_Adaptor->GetMeasurementVector(m_InstanceIdentifier);
218  return this->m_MeasurementVectorCache;
219  }
220 
221  InstanceIdentifier GetInstanceIdentifier() const
222  {
223  return m_InstanceIdentifier;
224  }
225 
226  ConstIterator & operator++()
227  {
228  ++m_InstanceIdentifier;
229  return *this;
230  }
231 
232  bool operator!=(const ConstIterator & it)
233  {
234  return ( m_InstanceIdentifier != it.m_InstanceIdentifier );
235  }
236 
237  bool operator==(const ConstIterator & it)
238  {
239  return ( m_InstanceIdentifier == it.m_InstanceIdentifier );
240  }
241 
242 protected:
243  // This method should only be available to the ListSample class
246  InstanceIdentifier iid)
247  {
248  m_Adaptor = adaptor;
249  m_InstanceIdentifier = iid;
250  }
251 
252  // This method is purposely not implemented
253  ConstIterator();
254 private:
258  };
259 
264  class Iterator:public ConstIterator
265  {
267 public:
268 
269  Iterator(Self *adaptor):ConstIterator(adaptor)
270  {}
271 
272  Iterator(const Iterator & iter):ConstIterator(iter)
273  {}
274 
275  Iterator & operator=(const Iterator & iter)
276  {
277  this->ConstIterator::operator=(iter);
278  return *this;
279  }
280 
281 protected:
282  // To ensure const-correctness these method must not be in the public API.
283  // The are purposly not implemented, since they should never be called.
284  Iterator();
285  Iterator(const Self *adaptor);
286  Iterator(const ConstIterator & it);
287  ConstIterator & operator=(const ConstIterator & it);
288 
291  InstanceIdentifier iid):ConstIterator(adaptor, iid)
292  {}
293 
294 private:
295  };
296 
298  Iterator Begin()
299  {
300  Iterator iter(this, 0);
301 
302  return iter;
303  }
304 
306  Iterator End()
307  {
308  Iterator iter( this, m_Image->GetPixelContainer()->Size() );
309 
310  return iter;
311  }
312 
314  ConstIterator Begin() const
315  {
316  ConstIterator iter(this, 0);
317 
318  return iter;
319  }
320 
322  ConstIterator End() const
323  {
324  ConstIterator iter( this, m_Image->GetPixelContainer()->Size() );
325 
326  return iter;
327  }
328 
329 protected:
332  void PrintSelf(std::ostream & os, Indent indent) const;
333 
334 private:
335  JointDomainImageToListSampleAdaptor(const Self &); //purposely not implemented
336  void operator=(const Self &); //purposely not implemented
337 
345 
347 }; // end of class JointDomainImageToListSampleAdaptor
348 } // end of namespace Statistics
349 } // end of namespace itk
350 
351 #ifndef ITK_MANUAL_INSTANTIATION
352 #include "itkJointDomainImageToListSampleAdaptor.hxx"
353 #endif
354 
355 #endif
356