Skip to content

Commit 8363b21

Browse files
committed
feat(ModelHelpers): create AABBTree for model components
1 parent b7a9f43 commit 8363b21

File tree

3 files changed

+153
-0
lines changed

3 files changed

+153
-0
lines changed
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
/*
2+
* Copyright (c) 2019 - 2022 Geode-solutions
3+
*
4+
* Permission is hereby granted, free of charge, to any person obtaining a copy
5+
* of this software and associated documentation files (the "Software"), to deal
6+
* in the Software without restriction, including without limitation the rights
7+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8+
* copies of the Software, and to permit persons to whom the Software is
9+
* furnished to do so, subject to the following conditions:
10+
*
11+
* The above copyright notice and this permission notice shall be included in
12+
* all copies or substantial portions of the Software.
13+
*
14+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20+
* SOFTWARE.
21+
*
22+
*/
23+
24+
#pragma once
25+
26+
#include <absl/container/fixed_array.h>
27+
28+
#include <geode/model/common.h>
29+
30+
namespace geode
31+
{
32+
FORWARD_DECLARATION_DIMENSION_CLASS( AABBTree );
33+
ALIAS_2D_AND_3D( AABBTree );
34+
class BRep;
35+
class Section;
36+
struct uuid;
37+
} // namespace geode
38+
39+
namespace geode
40+
{
41+
std::tuple< AABBTree3D, absl::FixedArray< uuid > >
42+
opengeode_model_api create_lines_aabb_tree( const BRep& model );
43+
44+
std::tuple< AABBTree3D, absl::FixedArray< uuid > >
45+
opengeode_model_api create_surfaces_aabb_tree( const BRep& model );
46+
47+
std::tuple< AABBTree3D, absl::FixedArray< uuid > >
48+
opengeode_model_api create_blocks_aabb_tree( const BRep& model );
49+
50+
std::tuple< AABBTree2D, absl::FixedArray< uuid > >
51+
opengeode_model_api create_lines_aabb_tree( const Section& model );
52+
53+
std::tuple< AABBTree2D, absl::FixedArray< uuid > >
54+
opengeode_model_api create_surfaces_aabb_tree( const Section& model );
55+
} // namespace geode

src/geode/model/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ add_geode_library(
2323
FOLDER "geode/model"
2424
SOURCES
2525
"common.cpp"
26+
"helpers/aabb_model_helpers.cpp"
2627
"helpers/component_mesh_edges.cpp"
2728
"helpers/component_mesh_polygons.cpp"
2829
"helpers/component_mesh_vertices.cpp"
@@ -69,6 +70,7 @@ add_geode_library(
6970
"representation/io/section_output.cpp"
7071
PUBLIC_HEADERS
7172
"common.h"
73+
"helpers/aabb_model_helpers.h"
7274
"helpers/component_mesh_edges.h"
7375
"helpers/component_mesh_polygons.h"
7476
"helpers/component_mesh_vertices.h"
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
/*
2+
* Copyright (c) 2019 - 2022 Geode-solutions
3+
*
4+
* Permission is hereby granted, free of charge, to any person obtaining a copy
5+
* of this software and associated documentation files (the "Software"), to deal
6+
* in the Software without restriction, including without limitation the rights
7+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8+
* copies of the Software, and to permit persons to whom the Software is
9+
* furnished to do so, subject to the following conditions:
10+
*
11+
* The above copyright notice and this permission notice shall be included in
12+
* all copies or substantial portions of the Software.
13+
*
14+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20+
* SOFTWARE.
21+
*
22+
*/
23+
24+
#include <geode/model/helpers/aabb_model_helpers.h>
25+
26+
#include <async++.h>
27+
28+
#include <geode/geometry/aabb.h>
29+
#include <geode/geometry/bounding_box.h>
30+
31+
#include <geode/mesh/core/edged_curve.h>
32+
#include <geode/mesh/core/solid_mesh.h>
33+
#include <geode/mesh/core/surface_mesh.h>
34+
35+
#include <geode/model/mixin/core/block.h>
36+
#include <geode/model/mixin/core/line.h>
37+
#include <geode/model/mixin/core/surface.h>
38+
#include <geode/model/representation/core/brep.h>
39+
#include <geode/model/representation/core/section.h>
40+
41+
namespace
42+
{
43+
template < geode::index_t dimension, typename Range >
44+
std::tuple< geode::AABBTree< dimension >, absl::FixedArray< geode::uuid > >
45+
create_aabb( const Range& range, geode::index_t nb_elements )
46+
{
47+
absl::FixedArray< geode::BoundingBox< dimension > > boxes(
48+
nb_elements );
49+
absl::FixedArray< geode::uuid > mapping( nb_elements );
50+
absl::FixedArray< async::task< void > > tasks( nb_elements );
51+
geode::index_t id{ 0 };
52+
for( const auto& element : range )
53+
{
54+
tasks[id++] = async::spawn( [id, &mapping, &boxes, &element] {
55+
mapping[id] = element.id();
56+
boxes[id] = element.mesh().bounding_box();
57+
} );
58+
}
59+
async::when_all( tasks.begin(), tasks.end() ).wait();
60+
return std::make_tuple(
61+
geode::AABBTree< dimension >{ boxes }, std::move( mapping ) );
62+
}
63+
} // namespace
64+
65+
namespace geode
66+
{
67+
std::tuple< AABBTree3D, absl::FixedArray< uuid > > create_lines_aabb_tree(
68+
const BRep& model )
69+
{
70+
return create_aabb< 3 >( model.lines(), model.nb_lines() );
71+
}
72+
73+
std::tuple< AABBTree3D, absl::FixedArray< uuid > >
74+
create_surfaces_aabb_tree( const BRep& model )
75+
{
76+
return create_aabb< 3 >( model.surfaces(), model.nb_surfaces() );
77+
}
78+
79+
std::tuple< AABBTree3D, absl::FixedArray< uuid > > create_blocks_aabb_tree(
80+
const BRep& model )
81+
{
82+
return create_aabb< 3 >( model.blocks(), model.nb_blocks() );
83+
}
84+
85+
std::tuple< AABBTree2D, absl::FixedArray< uuid > > create_lines_aabb_tree(
86+
const Section& model )
87+
{
88+
return create_aabb< 2 >( model.lines(), model.nb_lines() );
89+
}
90+
91+
std::tuple< AABBTree2D, absl::FixedArray< uuid > >
92+
create_surfaces_aabb_tree( const Section& model )
93+
{
94+
return create_aabb< 2 >( model.surfaces(), model.nb_surfaces() );
95+
}
96+
} // namespace geode

0 commit comments

Comments
 (0)