Subversion Repositories seema-scanner

Rev

Rev 167 | Rev 207 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 167 Rev 182
Line -... Line 1...
-
 
1
//
-
 
2
// Line Shifting Structured Light
-
 
3
//
-
 
4
// This implementation closely follows Jens Guhring "Dense 3D surface acquisition by structured light using off-the-shelf components" (2000).
-
 
5
//
-
 
6
 
1
#include "AlgorithmLineShift.h"
7
#include "AlgorithmLineShift.h"
2
#include <cmath>
8
#include <cmath>
3
#include "cvtools.h"
9
#include "cvtools.h"
-
 
10
#include "algorithmtools.h"
4
 
11
 
5
#include <opencv2/imgproc/imgproc.hpp>
12
#include <opencv2/imgproc/imgproc.hpp>
6
 
13
 
7
#ifndef log2f
-
 
8
#define log2f(x) (log(x)/log(2.0))
-
 
9
#endif
-
 
10
 
-
 
11
static unsigned int nLineShifts = 8; // number of columns over which each line is shifted
14
static unsigned int nLineShifts = 8; // number of columns over which each line is shifted
12
 
15
 
13
/*
-
 
14
 * The purpose of this function is to convert an unsigned
-
 
15
 * binary number to reflected binary Gray code.
-
 
16
 *
-
 
17
 * The operator >> is shift right. The operator ^ is exclusive or.
-
 
18
 * Source: http://en.wikipedia.org/wiki/Gray_code
-
 
19
 */
-
 
20
static unsigned int binaryToGray(unsigned int num) {
-
 
21
    return (num >> 1) ^ num;
-
 
22
}
-
 
23
 
-
 
24
/*
-
 
25
 * From Wikipedia: http://en.wikipedia.org/wiki/Gray_code
-
 
26
 * The purpose of this function is to convert a reflected binary
-
 
27
 * Gray code number to a binary number.
-
 
28
 */
-
 
29
static unsigned int grayToBinary(unsigned int num){
-
 
30
    unsigned int mask;
-
 
31
    for(mask = num >> 1; mask != 0; mask = mask >> 1)
-
 
32
        num = num ^ mask;
-
 
33
    return num;
-
 
34
}
-
 
35
 
-
 
36
/*
-
 
37
 * Return the Nth bit of an unsigned integer number
-
 
38
 */
-
 
39
static bool getBit(int decimal, int N){
-
 
40
 
-
 
41
    return decimal & 1 << (N-1);
-
 
42
}
-
 
43
 
-
 
44
///*
-
 
45
// * Return the number of bits set in an integer
-
 
46
// */
-
 
47
//static int countBits(int n) {
-
 
48
//  unsigned int c; // c accumulates the total bits set in v
-
 
49
//  for (c = 0; n>0; c++)
-
 
50
//    n &= n - 1; // clear the least significant bit set
-
 
51
//  return c;
-
 
52
//}
-
 
53
 
-
 
54
///*
-
 
55
// * Return the position of the least significant bit that is set
-
 
56
// */
-
 
57
//static int leastSignificantBitSet(int x){
-
 
58
//  if(x == 0)
-
 
59
//      return 0;
-
 
60
 
-
 
61
//  int val = 1;
-
 
62
//  while(x>>=1)
-
 
63
//      val++;
-
 
64
 
-
 
65
//  return val;
-
 
66
//}
-
 
67
 
-
 
68
static inline unsigned int powi(int num, unsigned int exponent){
-
 
69
 
-
 
70
    if(exponent == 0)
-
 
71
        return 1;
-
 
72
 
-
 
73
    float res = num;
-
 
74
    for(unsigned int i=0; i<exponent-1; i++)
-
 
75
        res *= num;
-
 
76
 
-
 
77
    return res;
-
 
78
}
-
 
79
 
-
 
80
static inline unsigned int twopowi(unsigned int exponent){
-
 
81
 
-
 
82
    return 1 << exponent;
-
 
83
}
-
 
84
 
-
 
85
// Algorithm
16
// Algorithm
86
AlgorithmLineShift::AlgorithmLineShift(unsigned int _screenCols, unsigned int _screenRows) : Algorithm(_screenCols, _screenRows){
17
AlgorithmLineShift::AlgorithmLineShift(unsigned int _screenCols, unsigned int _screenRows) : Algorithm(_screenCols, _screenRows){
87
 
18
 
88
    int nTotalBits = ceilf(log2f((float)screenCols));
19
    int nTotalBits = ceilf(log2f((float)screenCols));
89
 
20