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.
debug.hh
Go to the documentation of this file.
1 #ifndef DEBUG_HH
2 #define DEBUG_HH
3 
4 namespace TooN {
5 
6 namespace Internal
7 {
8 
9 
10 
11  #if defined TOON_CHECK_BOUNDS || defined TOON_TEST_INTERNALS
12  static inline void check_index(int s, int i)
13  {
14  if(i<0 || i >= s)
15  {
16  #ifdef TOON_TEST_INTERNALS
17  throw Internal::BadIndex();
18  #else
19  std::cerr << "Toon index out of range" << std::endl;
20  std::abort();
21  #endif
22  }
23  }
24  #else
25  static inline void check_index(int, int){}
29  #endif
30 
31  #if defined TOON_INITIALIZE_SNAN
32  template<class P> static void debug_initialize(P* data, int n)
33  {
34  using std::numeric_limits;
35  for(int i=0; i < n; i++)
36  data[i] = numeric_limits<P>::signaling_NaN();
37  }
38  #elif defined TOON_INITIALIZE_QNAN || defined TOON_INITIALIZE_NAN
39  template<class P> static void debug_initialize(P* data, int n)
40  {
41  using std::numeric_limits;
42  for(int i=0; i < n; i++)
43  data[i] = numeric_limits<P>::quiet_NaN();
44  }
45  #elif defined TOON_INITIALIZE_VAL
46  template<class P> static void debug_initialize(P* data, int n)
47  {
48  for(int i=0; i < n; i++)
49  data[i] = TOON_INITIALIZE_VAL;
50  }
51  #elif defined TOON_INITIALIZE_RANDOM
52  union intbits
53  {
54  unsigned long i;
55  char c[4];
56  };
57 
58  template<class P> union datafail
59  {
60  int i;
61  P p;
62  };
63 
64 
65  template<class P> static void debug_initialize(P* data, int n)
66  {
67  //Get a random seed. Precision limited to 1 second.
68  static intbits random = { ((std::time(NULL) & 0xffffffff) *1664525L + 1013904223L)& 0xffffffff};
69  unsigned char* cdata = reinterpret_cast<unsigned char*>(data);
70 
71  size_t bytes = sizeof(P)*n, i=0;
72 
73  //Do nothing except for noisy failure with non-POD types.
74  datafail<P> d={0};
75  bytes+=d.i;
76 
77  switch(bytes & 0x3 )
78  {
79  for(i=0; i < bytes;)
80  {
81  //Really evil random number generator from NR.
82  //About 4x faster than Mersenne twister. Good quality
83  //is not needed, since it's only used to shake up the program
84  //state to test for uninitialized values. Also, it doesn't disturb
85  //the standard library random number generator.
86 
87  case 0:
88  cdata[i++] = random.c[0];
89  case 3:
90  cdata[i++] = random.c[1];
91  case 2:
92  cdata[i++] = random.c[2];
93  case 1:
94  cdata[i++] = random.c[3];
95  random.i = (1664525L * random.i + 1013904223L) & 0xffffffff;
96  }
97  }
98  }
99  #else
100  template<class P> static void debug_initialize(P*, int)
104  {
105  }
106  #endif
107 
108 
109 }
110 
111 }
112 
113 #endif
114 
Everything lives inside this namespace.
Definition: allocator.hh:48
static void debug_initialize(P *, int)
Definition: debug.hh:103
static void check_index(int, int)
Definition: debug.hh:28