Point Cloud Library (PCL)  1.12.0
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 
39 #pragma once
40 
41 #include <pcl/pcl_config.h>
42 #ifdef HAVE_OPENNI2
43 
44 #include <vector>
45 #include <limits>
46 
47 namespace openni_wrapper
48 {
49  /** \brief This class provides conversion of the openni 11-bit shift data to depth;
50  */
51  class PCL_EXPORTS ShiftToDepthConverter
52  {
53  public:
54  /** \brief Constructor. */
55  ShiftToDepthConverter () : init_(false) {}
56 
57  /** \brief Destructor. */
58  virtual ~ShiftToDepthConverter () {};
59 
60  /** \brief This method generates a look-up table to convert openni shift values to depth
61  */
62  void
63  generateLookupTable ()
64  {
65  // lookup of 11 bit shift values
66  constexpr std::size_t table_size = 1<<10;
67 
68  lookupTable_.clear();
69  lookupTable_.resize(table_size);
70 
71  // constants taken from openni driver
72  constexpr std::int16_t nConstShift = 800;
73  constexpr double nParamCoeff = 4.000000;
74  constexpr double dPlanePixelSize = 0.104200;
75  constexpr double nShiftScale = 10.000000;
76  constexpr double dPlaneDsr = 120.000000;
77  constexpr double dPlaneDcl = 7.500000;
78 
79  for (std::size_t i=0; i<table_size; ++i)
80  {
81  // shift to depth calculation from opnni
82  double dFixedRefX = (static_cast<double>(i - nConstShift) / nParamCoeff)-0.375;
83  double dMetric = dFixedRefX * dPlanePixelSize;
84  lookupTable_[i] = static_cast<float>((nShiftScale * ((dMetric * dPlaneDsr / (dPlaneDcl - dMetric)) + dPlaneDsr) ) / 1000.0f);
85  }
86 
87  init_ = true;
88  }
89 
90  /** \brief Generate a look-up table for converting openni shift values to depth
91  */
92  inline float
93  shiftToDepth (std::uint16_t shift_val)
94  {
95  assert (init_);
96 
97  static const float bad_point = std::numeric_limits<float>::quiet_NaN ();
98 
99  float ret = bad_point;
100 
101  // lookup depth value in shift lookup table
102  if (shift_val<lookupTable_.size())
103  ret = lookupTable_[shift_val];
104 
105  return ret;
106  }
107 
108  inline bool isInitialized() const
109  {
110  return init_;
111  }
112 
113  protected:
114  std::vector<float> lookupTable_;
115  bool init_;
116  } ;
117 }
118 #endif
#define PCL_EXPORTS
Definition: pcl_macros.h:323