Point Cloud Library (PCL) 1.13.0
Loading...
Searching...
No Matches
boxutils.hpp
1/*
2 * Software License Agreement (BSD License)
3 *
4 * Copyright (c) 2011, Willow Garage, Inc.
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 *
11 * * Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * * Redistributions in binary form must reproduce the above
14 * copyright notice, this list of conditions and the following
15 * disclaimer in the documentation and/or other materials provided
16 * with the distribution.
17 * * Neither the name of Willow Garage, Inc. nor the names of its
18 * contributors may be used to endorse or promote products derived
19 * from this software without specific prior written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
24 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
25 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
27 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
29 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
31 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32 * POSSIBILITY OF SUCH DAMAGE.
33 *
34 * Author: Anatoly Baskeheev, Itseez Ltd, (myname.mysurname@mycompany.com)
35 */
36
37#ifndef _PCL_GPU_OCTREE_BOXUTILS_HPP_
38#define _PCL_GPU_OCTREE_BOXUTILS_HPP_
39
40#include "utils/morton.hpp"
41
42namespace pcl
43{
44 namespace device
45 {
46 __device__ __host__ __forceinline__
47 static bool checkIfNodeInsideSphere(const float3& minp, const float3& maxp, const float3& c, float r)
48 {
49 r *= r;
50
51 float d2_xmin = (minp.x - c.x) * (minp.x - c.x);
52 float d2_ymin = (minp.y - c.y) * (minp.y - c.y);
53 float d2_zmin = (minp.z - c.z) * (minp.z - c.z);
54
55 if (d2_xmin + d2_ymin + d2_zmin > r)
56 return false;
57
58 float d2_zmax = (maxp.z - c.z) * (maxp.z - c.z);
59
60 if (d2_xmin + d2_ymin + d2_zmax > r)
61 return false;
62
63 float d2_ymax = (maxp.y - c.y) * (maxp.y - c.y);
64
65 if (d2_xmin + d2_ymax + d2_zmin > r)
66 return false;
67
68 if (d2_xmin + d2_ymax + d2_zmax > r)
69 return false;
70
71 float d2_xmax = (maxp.x - c.x) * (maxp.x - c.x);
72
73 if (d2_xmax + d2_ymin + d2_zmin > r)
74 return false;
75
76 if (d2_xmax + d2_ymin + d2_zmax > r)
77 return false;
78
79 if (d2_xmax + d2_ymax + d2_zmin > r)
80 return false;
81
82 if (d2_xmax + d2_ymax + d2_zmax > r)
83 return false;
84
85 return true;
86 }
87
88 __device__ __host__ __forceinline__
89 static bool checkIfNodeOutsideSphere(const float3& minp, const float3& maxp, const float3& c, float r)
90 {
91 if (maxp.x < (c.x - r) || maxp.y < (c.y - r) || maxp.z < (c.z - r))
92 return true;
93
94 if ((c.x + r) < minp.x || (c.y + r) < minp.y || (c.z + r) < minp.z)
95 return true;
96
97 return false;
98 }
99
100 __device__ __host__ __forceinline__
101 static void calcBoundingBox(int level, int code, float3& res_minp, float3& res_maxp)
102 {
103 int cell_x, cell_y, cell_z;
104 Morton::decomposeCode(code, cell_x, cell_y, cell_z);
105
106 float cell_size_x = (res_maxp.x - res_minp.x) / (1 << level);
107 float cell_size_y = (res_maxp.y - res_minp.y) / (1 << level);
108 float cell_size_z = (res_maxp.z - res_minp.z) / (1 << level);
109
110 res_minp.x += cell_x * cell_size_x;
111 res_minp.y += cell_y * cell_size_y;
112 res_minp.z += cell_z * cell_size_z;
113
114 res_maxp.x = res_minp.x + cell_size_x;
115 res_maxp.y = res_minp.y + cell_size_y;
116 res_maxp.z = res_minp.z + cell_size_z;
117 }
118 }
119}
120
121#endif /* _PCL_GPU_OCTREE_BOXUTILS_HPP_ */
__device__ __host__ static __forceinline__ void calcBoundingBox(int level, int code, float3 &res_minp, float3 &res_maxp)
Definition boxutils.hpp:101
__device__ __host__ static __forceinline__ bool checkIfNodeInsideSphere(const float3 &minp, const float3 &maxp, const float3 &c, float r)
Definition boxutils.hpp:47
__device__ __host__ static __forceinline__ bool checkIfNodeOutsideSphere(const float3 &minp, const float3 &maxp, const float3 &c, float r)
Definition boxutils.hpp:89
__device__ __host__ static __forceinline__ void decomposeCode(code_t code, int &cell_x, int &cell_y, int &cell_z)
Definition morton.hpp:84