Point Cloud Library (PCL)  1.14.0-dev
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 "utils.hpp" //temporary reimplementing to release kinfu without pcl_gpu_utils
42 
43 #include "internal.h"
44 
45 #include "pointer_shift.cu" // contains primitive needed by all cuda functions dealing with rolling tsdf buffer
46 
47 namespace pcl
48 {
49  namespace device
50  {
51  namespace kinfuLS
52  {
53  #define INV_DIV 3.051850947599719e-5f
54 
55  __device__ __forceinline__ void
56  pack_tsdf (float tsdf, int weight, short2& value)
57  {
58  int fixedp = max (-DIVISOR, min (DIVISOR, __float2int_rz (tsdf * DIVISOR)));
59  //int fixedp = __float2int_rz(tsdf * DIVISOR);
60  value = make_short2 (fixedp, weight);
61  }
62 
63  __device__ __forceinline__ void
64  unpack_tsdf (short2 value, float& tsdf, int& weight)
65  {
66  weight = value.y;
67  tsdf = __int2float_rn (value.x) / DIVISOR; //*/ * INV_DIV;
68  }
69 
70  __device__ __forceinline__ float
71  unpack_tsdf (short2 value)
72  {
73  return static_cast<float>(value.x) / DIVISOR; //*/ * INV_DIV;
74  }
75 
76 
77  __device__ __forceinline__ float3
78  operator* (const Mat33& m, const float3& vec)
79  {
80  return make_float3 (dot (m.data[0], vec), dot (m.data[1], vec), dot (m.data[2], vec));
81  }
82 
83 
84  ////////////////////////////////////////////////////////////////////////////////////////
85  ///// Prefix Scan utility
86 
88 
89  template<ScanKind Kind, class T>
90  __device__ __forceinline__ T
91  scan_warp ( volatile T *ptr, const unsigned int idx = threadIdx.x )
92  {
93  const unsigned int lane = idx & 31; // index of thread in warp (0..31)
94 
95  if (lane >= 1) ptr[idx] = ptr[idx - 1] + ptr[idx];
96  if (lane >= 2) ptr[idx] = ptr[idx - 2] + ptr[idx];
97  if (lane >= 4) ptr[idx] = ptr[idx - 4] + ptr[idx];
98  if (lane >= 8) ptr[idx] = ptr[idx - 8] + ptr[idx];
99  if (lane >= 16) ptr[idx] = ptr[idx - 16] + ptr[idx];
100 
101  if (Kind == inclusive)
102  return ptr[idx];
103  else
104  return (lane > 0) ? ptr[idx - 1] : 0;
105  }
106  }
107  }
108 }
109 
110 #endif /* PCL_GPU_KINFU_DEVICE_HPP_ */
constexpr int DIVISOR
Definition: device.h:62
__device__ __forceinline__ float3 operator*(const Mat33 &m, const float3 &vec)
Definition: device.hpp:78
__device__ __forceinline__ T scan_warp(volatile T *ptr, const unsigned int idx=threadIdx.x)
Definition: device.hpp:91
__device__ __forceinline__ void pack_tsdf(float tsdf, int weight, short2 &value)
Definition: device.hpp:56
__device__ __forceinline__ float dot(const float3 &v1, const float3 &v2)
Definition: utils.hpp:61
__device__ __forceinline__ void unpack_tsdf(short2 value, float &tsdf, int &weight)
Definition: device.hpp:64
3x3 Matrix for device code
Definition: device.h:106