Point Cloud Library (PCL)  1.8.1
openni_shift_to_depth_conversion.h
1 /*
2  * Software License Agreement (BSD License)
3  *
4  * Point Cloud Library (PCL) - www.pointclouds.org
5  * Copyright (c) 2011 Willow Garage, Inc.
6  * Copyright (c) 2012-, Open Perception, Inc.
7  *
8  * All rights reserved.
9  *
10  * Redistribution and use in source and binary forms, with or without
11  * modification, are permitted provided that the following conditions
12  * are met:
13  *
14  * * Redistributions of source code must retain the above copyright
15  * notice, this list of conditions and the following disclaimer.
16  * * Redistributions in binary form must reproduce the above
17  * copyright notice, this list of conditions and the following
18  * disclaimer in the documentation and/or other materials provided
19  * with the distribution.
20  * * Neither the name of the copyright holder(s) nor the names of its
21  * contributors may be used to endorse or promote products derived
22  * from this software without specific prior written permission.
23  *
24  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
25  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
26  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
27  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
28  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
29  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
30  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
31  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
32  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
33  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
34  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
35  * POSSIBILITY OF SUCH DAMAGE.
36  *
37  */
38 #include <pcl/pcl_config.h>
39 #ifdef HAVE_OPENNI
40 
41 #ifndef __OPENNI_SHIFT_TO_DEPTH_CONVERSION
42 #define __OPENNI_SHIFT_TO_DEPTH_CONVERSION
43 
44 #include <stdint.h>
45 #include <vector>
46 #include <limits>
47 
48 namespace openni_wrapper
49 {
50  /** \brief This class provides conversion of the openni 11-bit shift data to depth;
51  */
52  class PCL_EXPORTS ShiftToDepthConverter
53  {
54  public:
55  /** \brief Constructor. */
56  ShiftToDepthConverter () : init_(false) {}
57 
58  /** \brief Destructor. */
59  virtual ~ShiftToDepthConverter () {};
60 
61  /** \brief This method generates a look-up table to convert openni shift values to depth
62  */
63  void
65  {
66  // lookup of 11 bit shift values
67  const std::size_t table_size = 1<<10;
68 
69  lookupTable_.clear();
70  lookupTable_.resize(table_size);
71 
72  // constants taken from openni driver
73  static const int16_t nConstShift = 800;
74  static const double nParamCoeff = 4.000000;
75  static const double dPlanePixelSize = 0.104200;
76  static const double nShiftScale = 10.000000;
77  static const double dPlaneDsr = 120.000000;
78  static const double dPlaneDcl = 7.500000;
79 
80  std::size_t i;
81  double dFixedRefX;
82  double dMetric;
83 
84  for (i=0; i<table_size; ++i)
85  {
86  // shift to depth calculation from opnni
87  dFixedRefX = (static_cast<double>(i - nConstShift) / nParamCoeff)-0.375;
88  dMetric = dFixedRefX * dPlanePixelSize;
89  lookupTable_[i] = static_cast<float>((nShiftScale * ((dMetric * dPlaneDsr / (dPlaneDcl - dMetric)) + dPlaneDsr) ) / 1000.0f);
90  }
91 
92  init_ = true;
93  }
94 
95  /** \brief Generate a look-up table for converting openni shift values to depth
96  */
97  inline float
98  shiftToDepth (uint16_t shift_val)
99  {
100  assert (init_);
101 
102  static const float bad_point = std::numeric_limits<float>::quiet_NaN ();
103 
104  float ret = bad_point;
105 
106  // lookup depth value in shift lookup table
107  if (shift_val<lookupTable_.size())
108  ret = lookupTable_[shift_val];
109 
110  return ret;
111  }
112 
113  inline bool isInitialized() const
114  {
115  return init_;
116  }
117 
118  protected:
119  std::vector<float> lookupTable_;
120  bool init_;
121  } ;
122 }
123 
124 #endif
125 #endif //__OPENNI_SHIFT_TO_DEPTH_CONVERSION
float shiftToDepth(uint16_t shift_val)
Generate a look-up table for converting openni shift values to depth.
void generateLookupTable()
This method generates a look-up table to convert openni shift values to depth.
This class provides conversion of the openni 11-bit shift data to depth;.