SLAMflex SE  0.1.0
SLAMflex provides detection and tracking of dominant planes for smartphone devices. This plane can then be used to show AR content relative to the plane orientation. The detection of plane is performed in the field of view of the smartphone camera. In subsequent frames it is tracked. The interface returns the plane position and orientation.
pixel_operations.h
Go to the documentation of this file.
1 /*
2  This file is part of the CVD Library.
3 
4  Copyright (C) 2005 The Authors
5 
6  This library is free software; you can redistribute it and/or
7  modify it under the terms of the GNU Lesser General Public
8  License as published by the Free Software Foundation; either
9  version 2.1 of the License, or (at your option) any later version.
10 
11  This library is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  Lesser General Public License for more details.
15 
16  You should have received a copy of the GNU Lesser General Public
17  License along with this library; if not, write to the Free Software
18  Foundation, Inc.,
19  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 */
21 
22 #ifndef CVD_PIXEL_OPERATIONS_H_
23 #define CVD_PIXEL_OPERATIONS_H_
24 
25 #include <cmath>
26 #include "pixel_traits.h"
27 #include "convert_pixel_types.h"
28 #include "builtin_components.h"
29 #include "rgb_components.h"
30 
31 namespace CVD {
32 
33  namespace Pixel {
34 
35 
36 // operations::assign<DestType>(dest,src)
37 template <class T, unsigned int N = Component<T>::count> struct operations {
38  inline static void assign(T & lhs, const T & rhs) { memcpy(&lhs, &rhs, sizeof(T)); }
39  template <class S> inline static void assign(T & lhs, const S & rhs) { for (unsigned int i=0; i<N; i++) Component<T>::get(lhs,i) = (typename Component<T>::type)Component<S>::get(rhs,i); }
40  template <class S> inline static void add(T & lhs, const S & rhs) { for (unsigned int i=0;i<N;++i) Component<T>::get(lhs,i) += Component<S>::get(rhs,i); }
41  template <class S> inline static void subtract(T & lhs, const S & rhs) { for (unsigned int i=0;i<N;++i) Component<T>::get(lhs,i) -= Component<S>::get(rhs,i); }
42  template <class S> inline static void multiply(T & lhs, const S& rhs) { for (unsigned int i=0;i<N;++i) Component<T>::get(lhs,i) = (typename Component<T>::type)(Component<T>::get(lhs,i)*rhs); }
43  template <class S> inline static void divide(T & lhs, const S& rhs) { for (unsigned int i=0;i<N;++i) Component<T>::get(lhs,i) = (typename Component<T>::type)(Component<T>::get(lhs,i)/rhs); }
44  inline static bool equal(const T & a, const T & b) { return memcmp(&a,&b,sizeof(T)) == 0; }
45  inline static void zero(T & t) { memset(&t, 0, sizeof(T)); }
46 };
47 
48 template <class T> struct operations<T,1> {
49  template <class S> inline static void assign(T& lhs, const S& rhs) { lhs = (T)rhs; }
50  template <class S> inline static void add(T& lhs, const S& rhs) { lhs += rhs; }
51  template <class S> inline static void subtract(T& lhs, const S& rhs) { lhs -= rhs; }
52  template <class S> inline static void multiply(T& lhs, const S& rhs) { lhs = (T)(lhs*rhs); }
53  template <class S> inline static void divide(T& lhs, const S& rhs) { lhs = (T)(lhs/rhs); }
54  inline static bool equal(const T& a, const T& b) { return a == b; }
55  inline static void zero(T& t) { t = T(); }
56 };
57 
58 template <class T, unsigned int N=Pixel::Component<T>::count>
59 struct difference {
60  typedef typename Pixel::Component<T>::type TComp;
62  static inline diff_type avgabs(const T& a, const T& b) {
63  diff_type sum = diff_type();
64  for (unsigned int i=0; i<N; i++)
65  sum += std::abs((diff_type)Pixel::Component<T>::get(a,i) - Pixel::Component<T>::get(b,i));
66  return sum/N;
67  }
68  static inline diff_type avg(const T& a, const T& b) {
69  diff_type sum = diff_type();
70  for (unsigned int i=0; i<N; i++)
71  sum += (diff_type)Pixel::Component<T>::get(a,i) - Pixel::Component<T>::get(b,i);
72  return sum/N;
73  }
74 };
75 
76 template <class T>
77 struct difference<T, 1> {
78  typedef typename Pixel::Component<T>::type TComp;
80  static inline diff_type avgabs(const T& a, const T& b) {
81  return CVD::abs((diff_type)Pixel::Component<T>::get(a,0) - Pixel::Component<T>::get(b,0));
82  }
83  static inline diff_type avg(const T& a, const T& b) {
84  return (diff_type)Pixel::Component<T>::get(a,0) - (diff_type)Pixel::Component<T>::get(b,0);
85  }
86 };
87 
88 };
89 
90 };
91 
92 #endif
static void add(T &lhs, const S &rhs)
static const P & get(const P &pixel, size_t)
static void divide(T &lhs, const S &rhs)
static void subtract(T &lhs, const S &rhs)
static void multiply(T &lhs, const S &rhs)
static void subtract(T &lhs, const S &rhs)
static void divide(T &lhs, const S &rhs)
static void add(T &lhs, const S &rhs)
static void assign(T &lhs, const T &rhs)
static void assign(T &lhs, const S &rhs)
Definition: abs.h:24
static diff_type avgabs(const T &a, const T &b)
T abs(T t)
Definition: abs.h:30
static void multiply(T &lhs, const S &rhs)
Pixel::Component< T >::type TComp
Pixel::traits< TComp >::wider_type diff_type
static void zero(T &t)
Pixel::traits< TComp >::wider_type diff_type
static bool equal(const T &a, const T &b)
static diff_type avg(const T &a, const T &b)
static bool equal(const T &a, const T &b)
static diff_type avgabs(const T &a, const T &b)
static void assign(T &lhs, const S &rhs)
Pixel::Component< T >::type TComp
static diff_type avg(const T &a, const T &b)