00001 /* 00002 * Software License Agreement (BSD License) 00003 * 00004 * Point Cloud Library (PCL) - www.pointclouds.org 00005 * Copyright (c) 2011 Willow Garage, Inc. 00006 * Copyright (c) 2012-, Open Perception, Inc. 00007 * 00008 * All rights reserved. 00009 * 00010 * Redistribution and use in source and binary forms, with or without 00011 * modification, are permitted provided that the following conditions 00012 * are met: 00013 * 00014 * * Redistributions of source code must retain the above copyright 00015 * notice, this list of conditions and the following disclaimer. 00016 * * Redistributions in binary form must reproduce the above 00017 * copyright notice, this list of conditions and the following 00018 * disclaimer in the documentation and/or other materials provided 00019 * with the distribution. 00020 * * Neither the name of the copyright holder(s) nor the names of its 00021 * contributors may be used to endorse or promote products derived 00022 * from this software without specific prior written permission. 00023 * 00024 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 00025 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 00026 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 00027 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 00028 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 00029 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 00030 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 00031 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 00032 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 00033 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 00034 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 00035 * POSSIBILITY OF SUCH DAMAGE. 00036 * 00037 */ 00038 #include <pcl/pcl_config.h> 00039 #ifdef HAVE_OPENNI 00040 00041 #ifndef __OPENNI_SHIFT_TO_DEPTH_CONVERSION 00042 #define __OPENNI_SHIFT_TO_DEPTH_CONVERSION 00043 00044 #include <stdint.h> 00045 #include <vector> 00046 #include <limits> 00047 00048 namespace openni_wrapper 00049 { 00050 /** \brief This class provides conversion of the openni 11-bit shift data to depth; 00051 */ 00052 class PCL_EXPORTS ShiftToDepthConverter 00053 { 00054 public: 00055 /** \brief Constructor. */ 00056 ShiftToDepthConverter () : init_(false) {} 00057 00058 /** \brief Destructor. */ 00059 virtual ~ShiftToDepthConverter () {}; 00060 00061 /** \brief This method generates a look-up table to convert openni shift values to depth 00062 */ 00063 void 00064 generateLookupTable () 00065 { 00066 // lookup of 11 bit shift values 00067 const std::size_t table_size = 1<<10; 00068 00069 lookupTable_.clear(); 00070 lookupTable_.resize(table_size); 00071 00072 // constants taken from openni driver 00073 static const int16_t nConstShift = 800; 00074 static const double nParamCoeff = 4.000000; 00075 static const double dPlanePixelSize = 0.104200; 00076 static const double nShiftScale = 10.000000; 00077 static const double dPlaneDsr = 120.000000; 00078 static const double dPlaneDcl = 7.500000; 00079 00080 std::size_t i; 00081 double dFixedRefX; 00082 double dMetric; 00083 00084 for (i=0; i<table_size; ++i) 00085 { 00086 // shift to depth calculation from opnni 00087 dFixedRefX = (static_cast<double>(i - nConstShift) / nParamCoeff)-0.375; 00088 dMetric = dFixedRefX * dPlanePixelSize; 00089 lookupTable_[i] = static_cast<float>((nShiftScale * ((dMetric * dPlaneDsr / (dPlaneDcl - dMetric)) + dPlaneDsr) ) / 1000.0f); 00090 } 00091 00092 init_ = true; 00093 } 00094 00095 /** \brief Generate a look-up table for converting openni shift values to depth 00096 */ 00097 inline float 00098 shiftToDepth (uint16_t shift_val) 00099 { 00100 assert (init_); 00101 00102 static const float bad_point = std::numeric_limits<float>::quiet_NaN (); 00103 00104 float ret = bad_point; 00105 00106 // lookup depth value in shift lookup table 00107 if (shift_val<lookupTable_.size()) 00108 ret = lookupTable_[shift_val]; 00109 00110 return ret; 00111 } 00112 00113 inline bool isInitialized() const 00114 { 00115 return init_; 00116 } 00117 00118 protected: 00119 std::vector<float> lookupTable_; 00120 bool init_; 00121 } ; 00122 } 00123 00124 #endif 00125 #endif //__OPENNI_SHIFT_TO_DEPTH_CONVERSION
Except where otherwise noted, the PointClouds.org web pages are licensed under Creative Commons Attribution 3.0.
Pages generated on Wed Mar 25 00:24:30 2015