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