ITK  4.9.0
Insight Segmentation and Registration Toolkit
itkMembershipSample.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 itkMembershipSample_h
19 #define itkMembershipSample_h
20 
21 #include "itksys/hash_map.hxx"
22 #include "itkSubsample.h"
23 
24 namespace itk
25 {
26 namespace Statistics
27 {
55 template< typename TSample >
57 {
58 public:
64 
66  itkTypeMacro(MembershipSample, DataObject);
67  itkNewMacro(Self);
69 
72  typedef TSample SampleType;
73  typedef typename SampleType::MeasurementVectorType MeasurementVectorType;
74  typedef typename SampleType::MeasurementType MeasurementType;
75  typedef typename SampleType::InstanceIdentifier InstanceIdentifier;
76  typedef typename SampleType::ConstPointer SampleConstPointer;
77 
78  typedef typename SampleType::AbsoluteFrequencyType AbsoluteFrequencyType;
79  typedef typename SampleType::TotalAbsoluteFrequencyType TotalAbsoluteFrequencyType;
80 
84  typedef std::vector< ClassLabelType > UniqueClassLabelsType;
85 
88  typedef itksys::hash_map< InstanceIdentifier, ClassLabelType > ClassLabelHolderType;
89 
95 
97  itkSetConstObjectMacro(Sample, SampleType);
98  itkGetConstObjectMacro(Sample, SampleType);
100 
102  void SetNumberOfClasses(unsigned int numberOfClasses);
103 
105  itkGetConstMacro(NumberOfClasses, unsigned int);
106 
111  void AddInstance(const ClassLabelType & classLabel, const InstanceIdentifier & id);
112 
115  unsigned int GetClassLabel(const InstanceIdentifier & id) const;
116 
119  const ClassSampleType * GetClassSample(const ClassLabelType & classLabel) const;
120 
124 
128 
132  const unsigned int & dimension);
133 
136 
139 
141  virtual void Graft(const DataObject *thatObject) ITK_OVERRIDE;
142 
143 // void PrintSelf(std::ostream& os, Indent indent) const;
144 
146  {
147  friend class MembershipSample;
148 
149 public:
150 
151  ConstIterator(const Self *sample)
152  {
153  *this = sample->Begin();
154  }
155 
157  {
158  m_Sample = iter.m_Sample;
161  }
162 
164  {
165  m_Sample = iter.m_Sample;
168  return *this;
169  }
170 
171  bool operator!=(const ConstIterator & it)
172  {
174  }
175 
176  bool operator==(const ConstIterator & it)
177  {
179  }
180 
182  {
184  return *this;
185  }
186 
188  {
189  return m_Sample->GetFrequency(m_InstanceIdentifier);
190  }
191 
193  {
194  return m_Sample->GetMeasurementVector(m_InstanceIdentifier);
195  }
196 
198  {
199  return m_InstanceIdentifier;
200  }
201 
202  unsigned int GetClassLabel() const
203  {
205  }
206 
207 protected:
208  // Purposely not implemented
209  ConstIterator();
210 
211  // Only to be called from the MembershipSample
213  const Self *memberSample, InstanceIdentifier iid):
214  m_Sample( memberSample->GetSample() ), m_MembershipSample(memberSample), m_InstanceIdentifier(iid)
215  {}
216 
217  //typename SampleType::ConstIterator m_Iter;
218  const TSample * m_Sample;
221  };
222 
223  class Iterator:public ConstIterator
224  {
225  friend class MembershipSample;
226 
227 public:
228 
229  Iterator(Self *sample):ConstIterator(sample)
230  {}
231 
232  Iterator(const Iterator & iter):ConstIterator(iter)
233  {}
234 
235  Iterator & operator=(const Iterator & iter)
236  {
237  this->ConstIterator::operator=(iter);
238  return *this;
239  }
240 
241 protected:
242  // To ensure const-correctness these method must not be in the public API.
243  // The are purposly not implemented, since they should never be called.
244  Iterator();
245  Iterator(const Self *sample);
246  Iterator(const ConstIterator & it);
247  ConstIterator & operator=(const ConstIterator & it);
248 
249  // Only to be called from the MembershipSample
250  Iterator(Self *memberSample,
251  InstanceIdentifier iid):
252  ConstIterator(memberSample, iid)
253  {}
254 
255 private:
256  };
257 
261  {
262  Iterator iter(this, 0);
263 
264  return iter;
265  }
266 
270  {
271  Iterator iter( this, m_Sample->Size() );
272 
273  return iter;
274  }
275 
277  {
278  ConstIterator iter(this, 0);
279 
280  return iter;
281  }
282 
284  {
285  ConstIterator iter( this, m_Sample->Size() );
286 
287  return iter;
288  }
289 
290 protected:
292  virtual ~MembershipSample() {}
293  virtual void PrintSelf(std::ostream & os, Indent indent) const ITK_OVERRIDE;
294 
295 private:
296  MembershipSample(const Self &) ITK_DELETE_FUNCTION;
297  void operator=(const Self &) ITK_DELETE_FUNCTION;
298 
301  int GetInternalClassLabel(const ClassLabelType classLabel) const;
302 
307  unsigned int m_NumberOfClasses;
308 }; // end of class
309 } // end of namespace Statistics
310 } // end of namespace itk
311 
312 #ifndef ITK_MANUAL_INSTANTIATION
313 #include "itkMembershipSample.hxx"
314 #endif
315 
316 #endif
virtual void Graft(const DataObject *thatObject) override
SampleType::AbsoluteFrequencyType AbsoluteFrequencyType
SampleType::MeasurementType MeasurementType
unsigned int GetClassLabel(const InstanceIdentifier &id) const
std::vector< ClassSamplePointer > m_ClassSamples
const MeasurementVectorType & GetMeasurementVector(const InstanceIdentifier &id) const
void SetNumberOfClasses(unsigned int numberOfClasses)
SampleType::MeasurementVectorType MeasurementVectorType
Subsample< SampleType > ClassSampleType
itksys::hash_map< InstanceIdentifier, ClassLabelType > ClassLabelHolderType
This class stores a subset of instance identifiers from another sample object. You can create a subsa...
Definition: itkSubsample.h:41
Container for storing the instance-identifiers of other sample with their associated class labels...
virtual const SampleType * GetSample() const
UniqueClassLabelsType m_UniqueClassLabels
MeasurementType GetMeasurement(const InstanceIdentifier &id, const unsigned int &dimension)
SampleType::TotalAbsoluteFrequencyType TotalAbsoluteFrequencyType
Iterator & operator=(const Iterator &iter)
SizeValueType IdentifierType
Definition: itkIntTypes.h:147
ConstIterator & operator=(const ConstIterator &iter)
int GetInternalClassLabel(const ClassLabelType classLabel) const
SmartPointer< const Self > ConstPointer
Iterator(Self *memberSample, InstanceIdentifier iid)
ConstIterator(const Self *memberSample, InstanceIdentifier iid)
TotalAbsoluteFrequencyType GetTotalFrequency() const
std::vector< ClassLabelType > UniqueClassLabelsType
SampleType::ConstPointer SampleConstPointer
A collection of measurements for statistical analysis.
Definition: itkSample.h:61
Control indentation during Print() invocation.
Definition: itkIndent.h:49
ClassSampleType::Pointer ClassSamplePointer
const ClassLabelHolderType GetClassLabelHolder() const
const MeasurementVectorType & GetMeasurementVector() const
SampleType::InstanceIdentifier InstanceIdentifier
const ClassSampleType * GetClassSample(const ClassLabelType &classLabel) const
Base class for all data objects in ITK.
void AddInstance(const ClassLabelType &classLabel, const InstanceIdentifier &id)
AbsoluteFrequencyType GetFrequency(const InstanceIdentifier &id) const
ClassSampleType::ConstPointer ClassSampleConstPointer
virtual void PrintSelf(std::ostream &os, Indent indent) const override