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