1+ /*
2+ * Copyright (c) 2019 - 2025 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 < geode/geometry/basic_objects/tetrahedron.hpp>
27+
28+ #include < geode/mesh/common.hpp>
29+ #include < geode/mesh/core/grid.hpp>
30+ #include < geode/mesh/core/light_regular_grid.hpp>
31+ #include < geode/mesh/core/regular_grid_solid.hpp>
32+ #include < geode/mesh/core/regular_grid_surface.hpp>
33+
34+ namespace geode
35+ {
36+ template < typename T >
37+ class GenericMeshAccessor ;
38+ FORWARD_DECLARATION_DIMENSION_CLASS ( Point );
39+ struct uuid ;
40+ } // namespace geode
41+
42+ namespace geode
43+ {
44+ template < index_t dimension >
45+ class GenericMeshAccessor < Grid< dimension > >
46+ {
47+ public:
48+ explicit GenericMeshAccessor ( const Grid< dimension >& grid )
49+ : grid_( grid )
50+ {
51+ }
52+
53+ [[nodiscard]] index_t nb_vertices () const
54+ {
55+ return grid_.nb_grid_vertices ();
56+ }
57+
58+ [[nodiscard]] index_t nb_elements () const
59+ {
60+ return grid_.nb_cells ();
61+ }
62+
63+ [[nodiscard]] index_t nb_element_vertices ( index_t /* unused*/ ) const
64+ {
65+ return grid_.nb_cell_vertices ();
66+ }
67+
68+ [[nodiscard]] index_t nb_element_facets ( index_t /* unused*/ ) const
69+ {
70+ return grid_.nb_cell_neighbors ();
71+ }
72+
73+ [[nodiscard]] Point< dimension > element_barycenter (
74+ index_t cell_id ) const
75+ {
76+ return grid_.cell_barycenter ( cell_id );
77+ }
78+
79+ [[nodiscard]] const uuid& id () const
80+ {
81+ return grid_.id ();
82+ }
83+
84+ [[nodiscard]] Point< dimension > point ( index_t vertex_id ) const
85+ {
86+ return grid_.grid_point ( grid_.vertex_indices ( vertex_id ) );
87+ }
88+
89+ [[nodiscard]] AttributeManager& vertex_attribute_manager () const
90+ {
91+ return grid_.grid_vertex_attribute_manager ();
92+ }
93+
94+ [[nodiscard]] AttributeManager& element_attribute_manager () const
95+ {
96+ return grid_.cell_attribute_manager ();
97+ }
98+
99+ private:
100+ const Grid< dimension >& grid_;
101+ };
102+
103+ template < index_t dimension >
104+ class GenericMeshAccessor < LightRegularGrid< dimension > >
105+ : public GenericMeshAccessor< Grid< dimension > >
106+ {
107+ public:
108+ using Base = GenericMeshAccessor< Grid< dimension > >;
109+ using VerticesAroundVertex =
110+ typename LightRegularGrid< dimension >::VerticesAroundVertex;
111+
112+ explicit GenericMeshAccessor (
113+ const LightRegularGrid< dimension >& grid )
114+ : Base{ grid }, grid_( grid )
115+ {
116+ }
117+
118+ [[nodiscard]] VerticesAroundVertex vertices_around_vertex (
119+ index_t vertex_id ) const
120+ {
121+ return grid_.vertices_around_vertex ( vertex_id );
122+ }
123+
124+ private:
125+ const LightRegularGrid< dimension >& grid_;
126+ };
127+
128+ template < index_t dimension >
129+ class GenericMeshAccessor < RegularGrid< dimension > >
130+ : public GenericMeshAccessor< Grid< dimension > >
131+ {
132+ public:
133+ using Base = GenericMeshAccessor< Grid< dimension > >;
134+ using VerticesAroundVertex =
135+ typename RegularGrid< dimension >::VerticesAroundVertex;
136+
137+ explicit GenericMeshAccessor ( const RegularGrid< dimension >& grid )
138+ : Base{ grid }, grid_( grid )
139+ {
140+ }
141+
142+ [[nodiscard]] VerticesAroundVertex vertices_around_vertex (
143+ index_t vertex_id ) const
144+ {
145+ return grid_.vertices_around_vertex ( vertex_id );
146+ }
147+
148+ private:
149+ const RegularGrid< dimension >& grid_;
150+ };
151+ } // namespace geode
0 commit comments