Point Cloud Library (PCL) 1.13.1
Loading...
Searching...
No Matches
octree_iterator.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_ITERATOR
38#define PCL_GPU_OCTREE_ITERATOR
39
40namespace pcl
41{
42 namespace device
43 {
44
45 template<int CTA_SIZE, int STACK_DEPTH>
47 {
48 using Storage = int[STACK_DEPTH][CTA_SIZE];
49
50 int level;
52
53 __device__ __forceinline__ OctreeIteratorDevice(Storage& storage_arg) : storage(storage_arg)
54 {
55 level = 0; // root level
56 storage[level][threadIdx.x] = (0 << 8) + 1;
57 }
58
59 __device__ __forceinline__ void gotoNextLevel(int first, int len)
60 {
61 ++level;
62 storage[level][threadIdx.x] = (first << 8) + len;
63 }
64
65 __device__ __forceinline__ int operator*() const
66 {
67 return storage[level][threadIdx.x] >> 8;
68 }
69
70 __device__ __forceinline__ void operator++()
71 {
72 while(level >= 0)
73 {
74 int data = storage[level][threadIdx.x];
75
76 if ((data & 0xFF) > 1) // there are another siblings, can goto there
77 {
78 data += (1 << 8) - 1; // +1 to first and -1 from len
79 storage[level][threadIdx.x] = data;
80 break;
81 }
82 else
83 --level; //goto parent;
84 }
85 }
86 };
87
89 {
90 int level;
92 int length;
94
95 __device__ __forceinline__ OctreeIteratorDeviceNS(const OctreeGlobalWithBox& octree_arg) : octree(octree_arg)
96 {
97 node_idx = 0;
98 level = 0;
99 length = 1;
100 }
101
102 __device__ __forceinline__ void gotoNextLevel(int first, int len)
103 {
104 node_idx = first;
105 length = len;
106 ++level;
107 }
108
109 __device__ __forceinline__ int operator*() const
110 {
111 return node_idx;
112 }
113
114 __device__ __forceinline__ void operator++()
115 {
116#if 1
117 while(level >= 0)
118 {
119 if (length > 1)
120 {
121 length--;
122 node_idx++;
123 break;
124 }
125
126 if (node_idx == 0)
127 {
128 level = -1;
129 return;
130 }
131
133 --level;
134 if (node_idx == 0)
135 {
136 level = -1;
137 return;
138 }
139
140 int parent = octree.nodes[octree.parent[node_idx]];
141 int parent_first = parent >> 8;
142 int parent_len = __popc(parent & 0xFF);
143
144 int pos = node_idx - parent_first;
145
146 length = parent_len - pos;
147 }
148#endif
149 }
150
151 };
152 }
153}
154
155#endif /* PCL_GPU_OCTREE_ITERATOR */
__device__ __forceinline__ void operator++()
__device__ __forceinline__ int operator*() const
__device__ __forceinline__ void gotoNextLevel(int first, int len)
int[STACK_DEPTH][CTA_SIZE] Storage
__device__ __forceinline__ OctreeIteratorDevice(Storage &storage_arg)
__device__ __forceinline__ void gotoNextLevel(int first, int len)
__device__ __forceinline__ OctreeIteratorDeviceNS(const OctreeGlobalWithBox &octree_arg)
__device__ __forceinline__ void operator++()
const OctreeGlobalWithBox & octree
__device__ __forceinline__ int operator*() const