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