Skip to content

Commit 3b368cd

Browse files
committed
fix
1 parent 648d964 commit 3b368cd

File tree

2 files changed

+71
-97
lines changed

2 files changed

+71
-97
lines changed

include/geode/geometry/detail/aabb_impl.h

Lines changed: 71 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,31 @@ namespace geode
137137
absl::Span< const BoundingBox< dimension > > bboxes,
138138
index_t node_index,
139139
index_t element_begin,
140-
index_t element_end );
140+
index_t element_end )
141+
{
142+
OPENGEODE_ASSERT(
143+
node_index < tree_.size(), "Node index out of tree" );
144+
OPENGEODE_ASSERT( element_begin != element_end,
145+
"Begin and End indices should be different" );
146+
if( is_leaf( element_begin, element_end ) )
147+
{
148+
tree_[node_index] = bboxes[mapping_morton_[element_begin]];
149+
return;
150+
}
151+
const auto it = get_recursive_iterators(
152+
node_index, element_begin, element_end );
153+
OPENGEODE_ASSERT(
154+
it.child_left < tree_.size(), "Left index out of tree" );
155+
OPENGEODE_ASSERT(
156+
it.child_right < tree_.size(), "Right index out of tree" );
157+
initialize_tree_recursive(
158+
bboxes, it.child_left, element_begin, it.middle_box );
159+
initialize_tree_recursive(
160+
bboxes, it.child_right, it.middle_box, element_end );
161+
// before box_union
162+
tree_[node_index].add_box( node( it.child_left ) );
163+
tree_[node_index].add_box( node( it.child_right ) );
164+
}
141165

142166
template < typename ACTION >
143167
void closest_element_box_recursive( const Point< dimension >& query,
@@ -191,13 +215,57 @@ namespace geode
191215
ACTION& action ) const;
192216

193217
index_t closest_element_box_hint(
194-
const Point< dimension >& query ) const;
218+
const Point< dimension >& query ) const
219+
{
220+
index_t box_begin{ 0 };
221+
index_t box_end{ nb_bboxes() };
222+
index_t node_index{ Impl::ROOT_INDEX };
223+
while( !is_leaf( box_begin, box_end ) )
224+
{
225+
const auto it =
226+
get_recursive_iterators( node_index, box_begin, box_end );
227+
if( node( it.child_left ).signed_distance( query )
228+
< node( it.child_right ).signed_distance( query ) )
229+
{
230+
box_end = it.middle_box;
231+
node_index = it.child_left;
232+
}
233+
else
234+
{
235+
box_begin = it.middle_box;
236+
node_index = it.child_right;
237+
}
238+
}
239+
240+
return mapping_morton( box_begin );
241+
}
195242

196243
void containing_boxes_recursive( index_t node_index,
197244
index_t element_begin,
198245
index_t element_end,
199246
const Point< dimension >& query,
200-
std::vector< index_t >& result ) const;
247+
std::vector< index_t >& result ) const
248+
{
249+
OPENGEODE_ASSERT(
250+
node_index < tree_.size(), "Node index out of tree" );
251+
OPENGEODE_ASSERT( element_begin != element_end,
252+
"Begin and End indices should be different" );
253+
if( !node( node_index ).contains( query ) )
254+
{
255+
return;
256+
}
257+
if( is_leaf( element_begin, element_end ) )
258+
{
259+
result.push_back( mapping_morton( element_begin ) );
260+
return;
261+
}
262+
const auto it = get_recursive_iterators(
263+
node_index, element_begin, element_end );
264+
containing_boxes_recursive(
265+
it.child_left, element_begin, it.middle_box, query, result );
266+
containing_boxes_recursive(
267+
it.child_right, it.middle_box, element_end, query, result );
268+
}
201269

202270
private:
203271
std::vector< BoundingBox< dimension > > tree_;

src/geode/geometry/aabb.cpp

Lines changed: 0 additions & 94 deletions
Original file line numberDiff line numberDiff line change
@@ -90,100 +90,6 @@ namespace geode
9090
return result;
9191
}
9292

93-
template < index_t dimension >
94-
void AABBTree< dimension >::Impl::containing_boxes_recursive(
95-
index_t node_index,
96-
index_t element_begin,
97-
index_t element_end,
98-
const Point< dimension >& query,
99-
std::vector< index_t >& result ) const
100-
{
101-
OPENGEODE_ASSERT( node_index < tree_.size(), "Node index out of tree" );
102-
OPENGEODE_ASSERT( element_begin != element_end,
103-
"Begin and End indices should be different" );
104-
if( !node( node_index ).contains( query ) )
105-
{
106-
return;
107-
}
108-
if( is_leaf( element_begin, element_end ) )
109-
{
110-
result.push_back( mapping_morton( element_begin ) );
111-
return;
112-
}
113-
const auto it =
114-
get_recursive_iterators( node_index, element_begin, element_end );
115-
containing_boxes_recursive(
116-
it.child_left, element_begin, it.middle_box, query, result );
117-
containing_boxes_recursive(
118-
it.child_right, it.middle_box, element_end, query, result );
119-
}
120-
121-
/**
122-
* \brief Computes the hierarchy of bounding boxes recursively.
123-
* \param[in] bboxes the array of bounding boxes
124-
* \param[in] node_index the index of the root of the subtree
125-
* \param[in] element_begin first box index in the vector \p bboxes
126-
* \param[in] element_end one position past the last box index in the vector
127-
* \p
128-
* bboxes
129-
*/
130-
template < index_t dimension >
131-
void AABBTree< dimension >::Impl::initialize_tree_recursive(
132-
absl::Span< const BoundingBox< dimension > > bboxes,
133-
index_t node_index,
134-
index_t element_begin,
135-
index_t element_end )
136-
{
137-
OPENGEODE_ASSERT( node_index < tree_.size(), "Node index out of tree" );
138-
OPENGEODE_ASSERT( element_begin != element_end,
139-
"Begin and End indices should be different" );
140-
if( is_leaf( element_begin, element_end ) )
141-
{
142-
tree_[node_index] = bboxes[mapping_morton_[element_begin]];
143-
return;
144-
}
145-
const auto it =
146-
get_recursive_iterators( node_index, element_begin, element_end );
147-
OPENGEODE_ASSERT(
148-
it.child_left < tree_.size(), "Left index out of tree" );
149-
OPENGEODE_ASSERT(
150-
it.child_right < tree_.size(), "Right index out of tree" );
151-
initialize_tree_recursive(
152-
bboxes, it.child_left, element_begin, it.middle_box );
153-
initialize_tree_recursive(
154-
bboxes, it.child_right, it.middle_box, element_end );
155-
// before box_union
156-
tree_[node_index].add_box( node( it.child_left ) );
157-
tree_[node_index].add_box( node( it.child_right ) );
158-
}
159-
160-
template < index_t dimension >
161-
index_t AABBTree< dimension >::Impl::closest_element_box_hint(
162-
const Point< dimension >& query ) const
163-
{
164-
index_t box_begin{ 0 };
165-
index_t box_end{ nb_bboxes() };
166-
index_t node_index{ Impl::ROOT_INDEX };
167-
while( !is_leaf( box_begin, box_end ) )
168-
{
169-
const auto it =
170-
get_recursive_iterators( node_index, box_begin, box_end );
171-
if( node( it.child_left ).signed_distance( query )
172-
< node( it.child_right ).signed_distance( query ) )
173-
{
174-
box_end = it.middle_box;
175-
node_index = it.child_left;
176-
}
177-
else
178-
{
179-
box_begin = it.middle_box;
180-
node_index = it.child_right;
181-
}
182-
}
183-
184-
return mapping_morton( box_begin );
185-
}
186-
18793
template class opengeode_geometry_api AABBTree< 2 >;
18894
template class opengeode_geometry_api AABBTree< 3 >;
18995
} // namespace geode

0 commit comments

Comments
 (0)