Point Cloud Library (PCL)  1.9.1
device.hpp
1 /*
2  * Software License Agreement (BSD License)
3  *
4  * Point Cloud Library (PCL) - www.pointclouds.org
5  * Copyright (c) 2011, Willow Garage, Inc.
6  *
7  * All rights reserved.
8  *
9  * Redistribution and use in source and binary forms, with or without
10  * modification, are permitted provided that the following conditions
11  * are met:
12  *
13  * * Redistributions of source code must retain the above copyright
14  * notice, this list of conditions and the following disclaimer.
15  * * Redistributions in binary form must reproduce the above
16  * copyright notice, this list of conditions and the following
17  * disclaimer in the documentation and/or other materials provided
18  * with the distribution.
19  * * Neither the name of Willow Garage, Inc. nor the names of its
20  * contributors may be used to endorse or promote products derived
21  * from this software without specific prior written permission.
22  *
23  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
24  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
25  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
26  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
27  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
28  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
29  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
30  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
31  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
33  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
34  * POSSIBILITY OF SUCH DAMAGE.
35  *
36  */
37 
38 #ifndef PCL_GPU_KINFU_DEVICE_HPP_
39 #define PCL_GPU_KINFU_DEVICE_HPP_
40 
41 //#include <pcl/gpu/utils/device/limits.hpp>
42 //#include <pcl/gpu/utils/device/vector_math.hpp>
43 #include "utils.hpp" //temporary reimplementing to release kinfu without pcl_gpu_utils
44 
45 #include "internal.h"
46 
47 namespace pcl
48 {
49  namespace device
50  {
51  #define INV_DIV 3.051850947599719e-5f
52 
53  __device__ __forceinline__ void
54  pack_tsdf (float tsdf, int weight, short2& value)
55  {
56  int fixedp = max (-DIVISOR, min (DIVISOR, __float2int_rz (tsdf * DIVISOR)));
57  //int fixedp = __float2int_rz(tsdf * DIVISOR);
58  value = make_short2 (fixedp, weight);
59  }
60 
61  __device__ __forceinline__ void
62  unpack_tsdf (short2 value, float& tsdf, int& weight)
63  {
64  weight = value.y;
65  tsdf = __int2float_rn (value.x) / DIVISOR; //*/ * INV_DIV;
66  }
67 
68  __device__ __forceinline__ float
69  unpack_tsdf (short2 value)
70  {
71  return static_cast<float>(value.x) / DIVISOR; //*/ * INV_DIV;
72  }
73 
74 
75  __device__ __forceinline__ float3
76  operator* (const Mat33& m, const float3& vec)
77  {
78  return make_float3 (dot (m.data[0], vec), dot (m.data[1], vec), dot (m.data[2], vec));
79  }
80 
81 
82  ////////////////////////////////////////////////////////////////////////////////////////
83  ///// Prefix Scan utility
84 
86 
87  template<ScanKind Kind, class T>
88  __device__ __forceinline__ T
89  scan_warp ( volatile T *ptr, const unsigned int idx = threadIdx.x )
90  {
91  const unsigned int lane = idx & 31; // index of thread in warp (0..31)
92 
93  if (lane >= 1) ptr[idx] = ptr[idx - 1] + ptr[idx];
94  if (lane >= 2) ptr[idx] = ptr[idx - 2] + ptr[idx];
95  if (lane >= 4) ptr[idx] = ptr[idx - 4] + ptr[idx];
96  if (lane >= 8) ptr[idx] = ptr[idx - 8] + ptr[idx];
97  if (lane >= 16) ptr[idx] = ptr[idx - 16] + ptr[idx];
98 
99  if (Kind == inclusive)
100  return ptr[idx];
101  else
102  return (lane > 0) ? ptr[idx - 1] : 0;
103  }
104  }
105 }
106 
107 #endif /* PCL_GPU_KINFU_DEVICE_HPP_ */
pcl
This file defines compatibility wrappers for low level I/O functions.
Definition: convolution.h:45
pcl::device::inclusive
@ inclusive
Definition: device.hpp:85
pcl::device::exclusive
@ exclusive
Definition: device.hpp:85
pcl::device::ScanKind
ScanKind
Definition: device.hpp:85
pcl::device::Mat33::data
float3 data[3]
Definition: internal.h:84
pcl::device::operator*
__device__ __forceinline__ float3 operator*(const Mat33 &m, const float3 &vec)
Definition: device.hpp:76
pcl::device::pack_tsdf
__device__ __forceinline__ void pack_tsdf(float tsdf, int weight, short2 &value)
Definition: device.hpp:54
pcl::device::DIVISOR
const int DIVISOR
Definition: internal.h:57
pcl::device::unpack_tsdf
__device__ __forceinline__ void unpack_tsdf(short2 value, float &tsdf, int &weight)
Definition: device.hpp:62
pcl::device::dot
__device__ __forceinline__ float dot(const float3 &v1, const float3 &v2)
Definition: utils.hpp:76
pcl::device::scan_warp
__device__ __forceinline__ T scan_warp(volatile T *ptr, const unsigned int idx=threadIdx.x)
Definition: device.hpp:89
pcl::device::Mat33
3x3 Matrix for device code
Definition: internal.h:82