Skip to content

Commit 160efb8

Browse files
authored
fix(Mesh): add mesh element data structure (#545)
1 parent e24b3c8 commit 160efb8

File tree

4 files changed

+101
-1
lines changed

4 files changed

+101
-1
lines changed

include/geode/basic/bitsery_archive.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,4 +192,4 @@ namespace bitsery
192192
struct PolymorphicClassName< Type > \
193193
{ \
194194
static constexpr auto name = Name; \
195-
};
195+
}
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
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 <geode/basic/uuid.h>
27+
28+
#include <geode/mesh/common.h>
29+
30+
namespace geode
31+
{
32+
struct MeshElement
33+
{
34+
MeshElement( uuid mesh_id_in, index_t element_id_in )
35+
: mesh_id( std::move( mesh_id_in ) ), element_id( element_id_in )
36+
{
37+
}
38+
39+
bool operator==( const MeshElement& other ) const
40+
{
41+
return mesh_id == other.mesh_id && element_id == other.element_id;
42+
}
43+
44+
bool operator!=( const MeshElement& other ) const
45+
{
46+
return mesh_id != other.mesh_id || element_id != other.element_id;
47+
}
48+
49+
template < typename Archive >
50+
void serialize( Archive& archive )
51+
{
52+
archive.ext( *this, DefaultGrowable< Archive, MeshElement >{},
53+
[]( Archive& a, MeshElement& mesh_element ) {
54+
a.object( mesh_element.mesh_id );
55+
a.value4b( mesh_element.element_id );
56+
} );
57+
}
58+
59+
uuid mesh_id;
60+
index_t element_id;
61+
62+
private:
63+
friend class bitsery::Access;
64+
MeshElement() = default;
65+
};
66+
67+
struct MeshVertex : public MeshElement
68+
{
69+
using MeshElement::MeshElement;
70+
};
71+
72+
struct MeshEdge : public MeshElement
73+
{
74+
using MeshElement::MeshElement;
75+
};
76+
77+
struct MeshPolygon : public MeshElement
78+
{
79+
using MeshElement::MeshElement;
80+
};
81+
} // namespace geode
82+
83+
namespace std
84+
{
85+
template <>
86+
struct hash< geode::MeshElement >
87+
{
88+
public:
89+
size_t operator()( const geode::MeshElement& mesh_element ) const
90+
{
91+
return absl::Hash< geode::uuid >()( mesh_element.mesh_id )
92+
^ absl::Hash< geode::index_t >()( mesh_element.element_id );
93+
}
94+
};
95+
} // namespace std

src/geode/mesh/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,7 @@ add_geode_library(
172172
"core/grid.h"
173173
"core/hybrid_solid.h"
174174
"core/mesh_factory.h"
175+
"core/mesh_element.h"
175176
"core/mesh_id.h"
176177
"core/point_set.h"
177178
"core/polygonal_surface.h"

src/geode/mesh/core/bitsery_archive.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
#include <geode/mesh/core/geode_tetrahedral_solid.h>
4141
#include <geode/mesh/core/geode_triangulated_surface.h>
4242
#include <geode/mesh/core/geode_vertex_set.h>
43+
#include <geode/mesh/core/mesh_element.h>
4344
#include <geode/mesh/core/private/solid_mesh_impl.h>
4445
#include <geode/mesh/core/private/surface_mesh_impl.h>
4546

@@ -245,6 +246,9 @@ namespace
245246
geode::AttributeManager::register_attribute_type<
246247
geode::HybridSolid3D::Type, Serializer >(
247248
context, "HybridSolidType" );
249+
geode::AttributeManager::register_attribute_type<
250+
std::vector< geode::MeshElement >, Serializer >(
251+
context, "MeshElement" );
248252
context.registerBasesList< Serializer >(
249253
bitsery::ext::PolymorphicClassesList< geode::VertexSet >{} );
250254
}

0 commit comments

Comments
 (0)