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