00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
#ifndef __itkMembershipSample_h
00018
#define __itkMembershipSample_h
00019
00020
#include "itk_hash_map.h"
00021
#include "itkSample.h"
00022
#include "itkSubsample.h"
00023
00024
#include "itkExceptionObject.h"
00025
00026
namespace itk{
00027
namespace Statistics{
00028
00050
template<
class TSample >
00051 class ITK_EXPORT MembershipSample :
00052
public Sample< typename TSample::MeasurementVectorType >
00053 {
00054
public:
00056 typedef MembershipSample
Self;
00057 typedef Sample< typename TSample::MeasurementVectorType > Superclass ;
00058 typedef SmartPointer< Self > Pointer ;
00059 typedef SmartPointer< const Self > ConstPointer ;
00060
00062
itkTypeMacro(MembershipSample,
Sample);
00063
itkNewMacro(
Self) ;
00064
00067
typedef typename TSample::MeasurementVectorType
MeasurementVectorType;
00068 typedef typename TSample::MeasurementType
MeasurementType;
00069 typedef typename TSample::InstanceIdentifier
InstanceIdentifier;
00070 typedef typename TSample::FrequencyType
FrequencyType ;
00071
00072
00073
00075
itkStaticConstMacro(MeasurementVectorSize,
unsigned int,
00076 TSample::MeasurementVectorSize);
00077
00080
typedef std::vector< unsigned int >
UniqueClassLabelsType ;
00081
00084
typedef itk::hash_map< InstanceIdentifier, unsigned int> ClassLabelHolderType ;
00085
00088
typedef Subsample< TSample > ClassSampleType ;
00089 typedef typename ClassSampleType::Pointer
ClassSamplePointer;
00090 typedef typename ClassSampleType::ConstPointer
ClassSampleConstPointer;
00091
00093
void SetSample(
const TSample* sample) ;
00094
00096
const TSample* GetSample() const;
00097
00099
void SetNumberOfClasses(
unsigned int numberOfClasses) ;
00100
00102
unsigned int GetNumberOfClasses() const ;
00103
00108
void AddInstance(const
unsigned int &classLabel, const
InstanceIdentifier &
id) ;
00111
unsigned int GetClassLabel(const
InstanceIdentifier &
id) const ;
00112
00115
int GetInternalClassLabel(const
unsigned int classLabel ) const ;
00116
00119
unsigned int GetClassSampleSize(const
unsigned int &classLabel) const ;
00120
00123 const
ClassSampleType* GetClassSample(const
unsigned int &classLabel) const ;
00124
00127
ClassLabelHolderType* GetClassLabels()
00128 {
return &m_ClassLabelHolder ; }
00129
00131
unsigned int Size(
void) const ;
00132
00135 const
MeasurementVectorType & GetMeasurementVector(const
InstanceIdentifier &
id) const;
00136
00139
MeasurementType GetMeasurement(const
InstanceIdentifier &
id,
00140 const
unsigned int &dimension) ;
00141
00143
FrequencyType GetFrequency(const
InstanceIdentifier &
id) const ;
00144
00146
FrequencyType GetTotalFrequency() const ;
00147
00148
void Resize(
unsigned int n)
00149 {
00150 m_ClassLabelHolder.resize(n) ;
00151 }
00152
00153
00154
class ConstIterator
00155 {
00156 public:
00157
ConstIterator(
InstanceIdentifier id,
const Self* membershipSample)
00158 :m_Id(id), m_MembershipSample(membershipSample),
00159 m_Sample(membershipSample->GetSample())
00160 {}
00161
00162
FrequencyType GetFrequency()
const
00163
{
return m_Sample->GetFrequency(m_Id) ; }
00164
00165
const MeasurementVectorType & GetMeasurementVector()
const
00166
{
return m_Sample->GetMeasurementVector(m_Id) ; }
00167
00168
InstanceIdentifier GetInstanceIdentifier()
const
00169
{
return m_Id ; }
00170
00171
void SetClassLabel(
unsigned int classLabel)
00172 { m_MembershipSample->AddInstance(classLabel, m_Id) ; }
00173
00174
unsigned int GetClassLabel()
const
00175
{
return m_MembershipSample->GetClassLabel(m_Id) ; }
00176
00177
ConstIterator& operator++()
00178 {
00179 ++m_Id ;
00180
return *
this ;
00181 }
00182
00183
bool operator!=(
const ConstIterator& it)
00184 {
00185 if (m_Id != it.m_Id ||
00186 m_MembershipSample != it.m_MembershipSample ||
00187 m_Sample != it.m_Sample)
00188 {
00189
return true ;
00190 }
00191
else
00192 {
00193
return false ;
00194 }
00195 }
00196
00197
bool operator==(
const ConstIterator& it)
00198 {
00199 if (m_Id == it.m_Id &&
00200 m_MembershipSample == it.m_MembershipSample &&
00201 m_Sample == it.m_Sample)
00202 {
00203
return true ;
00204 }
00205
else
00206 {
00207
return false ;
00208 }
00209 }
00210
00211 ConstIterator& operator=(
const ConstIterator& it)
00212 {
00213 m_Id = it.m_Id;
00214 m_MembershipSample = it.m_MembershipSample ;
00215 m_Sample = it.m_Sample ;
00216
return *
this ;
00217 }
00218
00219
ConstIterator(
const ConstIterator& it)
00220 {
00221 m_Id = it.m_Id;
00222 m_MembershipSample = it.m_MembershipSample ;
00223 m_Sample = it.m_Sample ;
00224 }
00225
00226
private:
00227
00228
InstanceIdentifier m_Id ;
00229
00230
const Self* m_MembershipSample ;
00231
const TSample* m_Sample ;
00232 } ;
00233
00234 ConstIterator Begin()
const
00235
{
00236 ConstIterator iter(0,
this) ;
00237
return iter;
00238 }
00239
00240 ConstIterator End()
const
00241
{
00242 ConstIterator iter(this->Size(),
this) ;
00243
return iter;
00244 }
00245
00246
protected:
00247 MembershipSample() ;
00248
virtual ~MembershipSample() {}
00249
void PrintSelf(std::ostream& os,
Indent indent)
const;
00250
00251
private:
00252 MembershipSample(
const Self&) ;
00253
void operator=(
const Self&) ;
00254
00255
const TSample* m_Sample ;
00256
unsigned int m_CurrentClassLabel ;
00257
UniqueClassLabelsType m_UniqueClassLabels ;
00258
ClassLabelHolderType m_ClassLabelHolder ;
00259
unsigned int m_NumberOfClasses ;
00260 std::vector< unsigned int > m_ClassSampleSizes ;
00261 std::vector< ClassSamplePointer > m_ClassSamples ;
00262 } ;
00263
00264
00265 }
00266 }
00267
00268
00269
#ifndef ITK_MANUAL_INSTANTIATION
00270
#include "itkMembershipSample.txx"
00271
#endif
00272
00273
#endif
00274
00275
00276
00277
00278
00279
00280