libcvd
builtin_components.h
1 #ifndef CVD_BUILTIN_TRAITS_H_
2 #define CVD_BUILTIN_TRAITS_H_
3 
4 #include <cstddef>
5 #include <limits>
6 
7 #if defined(CVD_HAVE_TOON)
8 #include <TooN/TooN.h>
9 #endif
10 
11 namespace CVD
12 {
13 namespace Pixel
14 {
15 
16  //The "Component" class gives us information about the pixel components,
17  //ie how many components there are and whay the type is.
18 
19  //We use a 2 layer thing here so that Component is only properly defined
20  //for builtin types, unless explicitly overridden.
21 
22  template <class P, int spp>
24  {
25  template <bool x>
27  static const int fail = sizeof(component_base_only_for_basic_types<false>);
28  };
29 
30  template <class P>
31  struct component_base<P, 1>
32  {
33  };
34 
35  //template <class P, int primitive = std::numeric_limits<P>::is_specialized> struct Component;
36 
37  template <class P>
38  struct Component
39  {
40  typedef P type;
41  static const size_t count = 1;
42 
43  static const P& get(const P& pixel, size_t)
44  {
45  return pixel;
46  }
47 
48  static P& get(P& pixel, size_t)
49  {
50  return pixel;
51  }
52  };
53 
54  template <class P, int I>
55  struct Component<P[I]>
56  {
57  typedef P type;
58  static const size_t count = I;
59 
60  static const P& get(const P pixel[I], size_t i)
61  {
62  return pixel[i];
63  }
64 
65  static inline P& get(P pixel[I], size_t i)
66  {
67  return pixel[i];
68  }
69  };
70 
71 #if defined(CVD_HAVE_TOON)
72  template <int N, typename P>
73  struct Component<TooN::Vector<N, P>>
74  {
75  typedef P type;
76  static const size_t count = N;
77 
78  static inline const P& get(const TooN::Vector<N, P>& pixel, size_t i)
79  {
80  return pixel[i];
81  }
82 
83  static inline P& get(TooN::Vector<N, P>& pixel, size_t i)
84  {
85  return pixel[i];
86  }
87  };
88 
89  template <int N, int M, typename P>
90  struct Component<TooN::Matrix<N, M, P>>
91  {
92  typedef P type;
93  static const size_t count = N * M;
94 
95  static const P& get(const TooN::Matrix<N, M, P>& pixel, size_t i)
96  {
97  return pixel[i / M][i % M];
98  }
99 
100  static inline P& get(TooN::Matrix<N, M, P>& pixel, size_t i)
101  {
102  return pixel[i / M][i % M];
103  }
104  };
105 #endif
106 
107 }
108 }
109 
110 #endif
All classes and functions are within the CVD namespace.
Definition: argb.h:6
Definition: builtin_components.h:23
Definition: builtin_components.h:38