CEDRIC  Revision_backup-2009-02
Feature.h
Go to the documentation of this file.
1 /******************************************************************************
2  *
3  * Copyright (C) 2008 Max Hermann
4  *
5  * This file is part of the "CEDRIC Event Display" application.
6  *
7  *****************************************************************************/
8 
9 #ifndef REDUKT_FEATURE_H
10 #define REDUKT_FEATURE_H
11 
12 #include <assert.h>
13 
17 {
18 public:
19  virtual int dim() const =0;
20  virtual float operator [] ( int i ) const =0;
21  virtual float& operator [] ( int i ) =0;
22 };
23 
25 template<int DIM>
26 class Feature : public AbstractFeature
27 {
28 public:
29  enum { Dimension = DIM };
30 
33  {
34  for( int i=0; i < DIM; ++i )
35  m_center[i] = 0.f;
36  }
37 
39  Feature( const Feature& other ): AbstractFeature()
40  {
41  for( int i=0; i < DIM; ++i )
42  m_center[i] = other[i];
43  // or: memcpy( m_center, other.m_center, N*sizeof(float) );
44  }
45 
47  Feature& operator = ( const Feature& other )
48  {
49  if( &other != this )
50  {
51  for( int i=0; i < DIM; ++i )
52  m_center[i] = other[i];
53  // or: memcpy( m_center, other.m_center, N*sizeof(float) );
54  }
55  return *this;
56  }
57 
59  int dim() const { return DIM; }
60 
61  float operator [] ( int i ) const
62  {
63  assert( (i>=0) && (i<DIM) );
64  return m_center[i];
65  }
66 
67  float& operator [] ( int i )
68  {
69  assert( (i>=0) && (i<DIM) );
70  return m_center[i];
71  }
73 
74 protected:
75  float m_center[DIM];
76 };
77 
79 class Feature1D: public Feature<1>
80 {
81 public:
82  Feature1D( float x )
83  {
84  m_center[0] = x;
85  }
86 };
87 
89 class Feature2D: public Feature<2>
90 {
91 public:
92  Feature2D( float x, float y )
93  {
94  m_center[0] = x;
95  m_center[1] = y;
96  }
97 };
98 
100 class Feature3D: public Feature<3>
101 {
102 public:
103  Feature3D( float x, float y, float z )
104  {
105  m_center[0] = x;
106  m_center[1] = y;
107  m_center[2] = z;
108  }
109 };
110 
111 #endif // REDUKT_FEATURE_H
float operator[](int i) const
Definition: Feature.h:61
Feature3D(float x, float y, float z)
Definition: Feature.h:103
Specialized 2-dimensional feature.
Definition: Feature.h:89
float m_center[DIM]
Definition: Feature.h:75
virtual float operator[](int i) const =0
Definition: Feature.h:29
int dim() const
AbstractFeature implementation.
Definition: Feature.h:59
Feature(const Feature &other)
Copy constructor.
Definition: Feature.h:39
virtual int dim() const =0
Feature & operator=(const Feature &other)
Copy-assignment.
Definition: Feature.h:47
Specialized 1-dimensional feature.
Definition: Feature.h:79
Basic feature template.
Definition: Feature.h:26
Feature2D(float x, float y)
Definition: Feature.h:92
Specialized 2-dimensional feature.
Definition: Feature.h:100
Feature()
Default constructor initializes all components with 0.f.
Definition: Feature.h:32
Definition: Feature.h:16
Feature1D(float x)
Definition: Feature.h:82