Lagrange
Loading...
Searching...
No Matches
SurfaceMesh.h
1/*
2 * Copyright 2022 Adobe. All rights reserved.
3 * This file is licensed to you under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License. You may obtain a copy
5 * of the License at http://www.apache.org/licenses/LICENSE-2.0
6 *
7 * Unless required by applicable law or agreed to in writing, software distributed under
8 * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
9 * OF ANY KIND, either express or implied. See the License for the specific language
10 * governing permissions and limitations under the License.
11 */
12#pragma once
13
14#include <lagrange/AttributeFwd.h>
15#include <lagrange/utils/SharedSpan.h>
16#include <lagrange/utils/function_ref.h>
17#include <lagrange/utils/span.h>
18#include <lagrange/utils/value_ptr.h>
19
20#include <initializer_list>
21#include <string_view>
22#include <type_traits>
23
24namespace lagrange {
25
28template <typename Scalar_, typename Index_>
29class SurfaceMesh;
30namespace internal {
31template <typename T>
32class weak_ptr;
33struct SurfaceMeshInfo;
34template <typename Scalar, typename Index>
35SurfaceMeshInfo from_surface_mesh(const SurfaceMesh<Scalar, Index>&);
36template <typename Scalar, typename Index>
37SurfaceMesh<Scalar, Index> to_surface_mesh(const SurfaceMeshInfo&);
38} // namespace internal
40
45
71template <typename Scalar_, typename Index_>
73{
74public:
76 using Scalar = Scalar_;
77
79 using Index = Index_;
80
82 using SignedIndex = std::make_signed_t<Index>;
83
84 // Static assertions to prevent users from instantiating unsupported types.
85 static_assert(
86 std::is_same_v<Scalar, float> || std::is_same_v<Scalar, double>,
87 "SurfaceMesh's Scalar template parameter can only be float or double.");
88 static_assert(
89 std::is_same_v<Index, uint32_t> || std::is_same_v<Index, uint64_t>,
90 "SurfaceMesh's Index template parameter can only be uint32_t or uint64_t.");
91
92public:
104
114
126
136
146
147public:
151
157 explicit SurfaceMesh(Index dimension = 3);
158
163
169 SurfaceMesh(SurfaceMesh&& other) noexcept;
170
179
186
195
214 template <typename OtherScalar, typename OtherIndex>
216
235 template <typename OtherScalar, typename OtherIndex>
237
244
250 void add_vertex(std::initializer_list<const Scalar> p);
251
259 void add_vertices(Index num_vertices, span<const Scalar> coordinates = {});
260
268 void add_vertices(Index num_vertices, std::initializer_list<const Scalar> coordinates);
269
276 void add_vertices(Index num_vertices, SetVertexCoordinatesFunction set_vertex_coordinates);
277
285 void add_triangle(Index v0, Index v1, Index v2);
286
300 void add_triangles(Index num_facets, span<const Index> facet_indices = {});
301
315 void add_triangles(Index num_facets, std::initializer_list<const Index> facet_indices);
316
323 void add_triangles(Index num_facets, SetMultiFacetsIndicesFunction set_facets_indices);
324
333 void add_quad(Index v0, Index v1, Index v2, Index v3);
334
348 void add_quads(Index num_facets, span<const Index> facet_indices = {});
349
363 void add_quads(Index num_facets, std::initializer_list<const Index> facet_indices);
364
371 void add_quads(Index num_facets, SetMultiFacetsIndicesFunction set_facets_indices);
372
378 void add_polygon(Index facet_size);
379
385 void add_polygon(span<const Index> facet_indices);
386
392 void add_polygon(std::initializer_list<const Index> facet_indices);
393
400 void add_polygon(Index facet_size, SetSingleFacetIndicesFunction set_facet_indices);
401
417 void add_polygons(Index num_facets, Index facet_size, span<const Index> facet_indices = {});
418
435 Index num_facets,
436 Index facet_size,
437 std::initializer_list<const Index> facet_indices);
438
447 Index num_facets,
448 Index facet_size,
449 SetMultiFacetsIndicesFunction set_facets_indices);
450
465 void add_hybrid(span<const Index> facet_sizes, span<const Index> facet_indices = {});
466
482 std::initializer_list<const Index> facet_sizes,
483 std::initializer_list<const Index> facet_indices);
484
494 Index num_facets,
495 GetFacetsSizeFunction facet_sizes,
496 SetMultiFacetsIndicesFunction set_facets_indices);
497
506 void remove_vertices(span<const Index> vertices_to_remove);
507
516 void remove_vertices(std::initializer_list<const Index> vertices_to_remove);
517
526 void remove_vertices(function_ref<bool(Index)> should_remove_func);
527
537 void remove_facets(span<const Index> facets_to_remove);
538
548 void remove_facets(std::initializer_list<const Index> facets_to_remove);
549
559 void remove_facets(function_ref<bool(Index)> should_remove_func);
560
568 span<const Index> facets_to_flip,
570
578 std::initializer_list<const Index> facets_to_flip,
580
589 function_ref<bool(Index)> should_flip_func,
591
597
603
608
617
618public:
622
632 [[nodiscard]] bool is_triangle_mesh() const;
633
643 [[nodiscard]] bool is_quad_mesh() const;
644
654 [[nodiscard]] bool is_regular() const;
655
665 [[nodiscard]] bool is_hybrid() const { return !is_regular(); }
666
672 [[nodiscard]] Index get_dimension() const { return m_dimension; }
673
680 [[nodiscard]] Index get_vertex_per_facet() const;
681
687 [[nodiscard]] Index get_num_vertices() const { return m_num_vertices; }
688
694 [[nodiscard]] Index get_num_facets() const { return m_num_facets; }
695
701 [[nodiscard]] Index get_num_corners() const { return m_num_corners; }
702
708 [[nodiscard]] Index get_num_edges() const { return m_num_edges; }
709
717 [[nodiscard]] span<const Scalar> get_position(Index v) const;
718
727
735 [[nodiscard]] Index get_facet_size(Index f) const
736 {
738 }
739
748 [[nodiscard]] Index get_facet_vertex(Index f, Index lv) const
749 {
751 }
752
760 [[nodiscard]] Index get_facet_corner_begin(Index f) const;
761
769 [[nodiscard]] Index get_facet_corner_end(Index f) const;
770
780 [[nodiscard]] Index get_corner_vertex(Index c) const;
781
791 [[nodiscard]] Index get_corner_facet(Index c) const;
792
801
815
816public:
820
829 [[nodiscard]] AttributeId get_attribute_id(std::string_view name) const;
830
840 [[nodiscard]] std::string_view get_attribute_name(AttributeId id) const;
841
875 template <typename ValueType>
877 std::string_view name,
878 AttributeElement element,
879 size_t num_channels = 1,
881 span<const ValueType> initial_values = {},
882 span<const Index> initial_indices = {},
884
920 template <typename ValueType>
922 std::string_view name,
923 AttributeElement element,
924 AttributeUsage usage,
925 size_t num_channels = 1,
926 span<const ValueType> initial_values = {},
927 span<const Index> initial_indices = {},
929
948 template <typename OtherScalar, typename OtherIndex>
950 std::string_view name,
951 const SurfaceMesh<OtherScalar, OtherIndex>& source_mesh,
952 std::string_view source_name = {});
953
977 template <typename ValueType>
979 std::string_view name,
980 AttributeElement element,
981 AttributeUsage usage,
982 size_t num_channels,
983 span<ValueType> values_view);
984
992 template <typename ValueType>
994 std::string_view name,
995 AttributeElement element,
996 AttributeUsage usage,
997 size_t num_channels,
998 SharedSpan<ValueType> shared_values);
999
1023 template <typename ValueType>
1025 std::string_view name,
1026 AttributeElement element,
1027 AttributeUsage usage,
1028 size_t num_channels,
1029 span<const ValueType> values_view);
1030
1038 template <typename ValueType>
1040 std::string_view name,
1041 AttributeElement element,
1042 AttributeUsage usage,
1043 size_t num_channels,
1044 SharedSpan<const ValueType> shared_values);
1045
1072 template <typename ValueType>
1074 std::string_view name,
1075 AttributeUsage usage,
1076 size_t num_values,
1077 size_t num_channels,
1078 span<ValueType> values_view,
1079 span<Index> indices_view);
1080
1089 template <typename ValueType>
1091 std::string_view name,
1092 AttributeUsage usage,
1093 size_t num_values,
1094 size_t num_channels,
1095 SharedSpan<ValueType> shared_values,
1096 SharedSpan<Index> shared_indices);
1097
1105 template <typename ValueType>
1107 std::string_view name,
1108 AttributeUsage usage,
1109 size_t num_values,
1110 size_t num_channels,
1111 span<ValueType> values_view,
1112 SharedSpan<Index> shared_indices);
1113
1121 template <typename ValueType>
1123 std::string_view name,
1124 AttributeUsage usage,
1125 size_t num_values,
1126 size_t num_channels,
1127 SharedSpan<ValueType> shared_values,
1128 span<Index> indices_view);
1129
1157 template <typename ValueType>
1159 std::string_view name,
1160 AttributeUsage usage,
1161 size_t num_values,
1162 size_t num_channels,
1163 span<const ValueType> values_view,
1164 span<const Index> indices_view);
1165
1174 template <typename ValueType>
1176 std::string_view name,
1177 AttributeUsage usage,
1178 size_t num_values,
1179 size_t num_channels,
1180 SharedSpan<const ValueType> shared_values,
1181 SharedSpan<const Index> shared_indices);
1182
1190 template <typename ValueType>
1192 std::string_view name,
1193 AttributeUsage usage,
1194 size_t num_values,
1195 size_t num_channels,
1196 span<const ValueType> values_view,
1197 SharedSpan<const Index> shared_indices);
1198
1206 template <typename ValueType>
1208 std::string_view name,
1209 AttributeUsage usage,
1210 size_t num_values,
1211 size_t num_channels,
1212 SharedSpan<const ValueType> shared_values,
1213 span<const Index> indices_view);
1214
1229 AttributeId wrap_as_vertices(span<Scalar> vertices_view, Index num_vertices);
1230
1239
1256
1265 SharedSpan<const Scalar> shared_vertices,
1266 Index num_vertices);
1267
1282 AttributeId wrap_as_facets(span<Index> facets_view, Index num_facets, Index vertex_per_facet);
1283
1292 wrap_as_facets(SharedSpan<Index> shared_facets, Index num_facets, Index vertex_per_facet);
1293
1310 wrap_as_const_facets(span<const Index> facets_view, Index num_facets, Index vertex_per_facet);
1311
1320 SharedSpan<const Index> shared_facets,
1321 Index num_facets,
1322 Index vertex_per_facet);
1323
1343 span<Index> offsets_view,
1344 Index num_facets,
1345 span<Index> facets_view,
1346 Index num_corners);
1347
1357 SharedSpan<Index> shared_offsets,
1358 Index num_facets,
1359 SharedSpan<Index> shared_facets,
1360 Index num_corners);
1361
1370 span<Index> offsets_view,
1371 Index num_facets,
1372 SharedSpan<Index> shared_facets,
1373 Index num_corners);
1374
1383 SharedSpan<Index> shared_offsets,
1384 Index num_facets,
1385 span<Index> facets_view,
1386 Index num_corners);
1387
1408 span<const Index> offsets_view,
1409 Index num_facets,
1410 span<const Index> facets_view,
1411 Index num_corners);
1412
1422 SharedSpan<const Index> shared_offsets,
1423 Index num_facets,
1424 SharedSpan<const Index> shared_facets,
1425 Index num_corners);
1426
1435 span<const Index> offsets_view,
1436 Index num_facets,
1437 SharedSpan<const Index> shared_facets,
1438 Index num_corners);
1439
1448 SharedSpan<const Index> shared_offsets,
1449 Index num_facets,
1450 span<const Index> facets_view,
1451 Index num_corners);
1452
1462 AttributeId duplicate_attribute(std::string_view old_name, std::string_view new_name);
1463
1470 void rename_attribute(std::string_view old_name, std::string_view new_name);
1471
1480 std::string_view name,
1482
1491 AttributeId id,
1493
1511 template <typename ValueType>
1512 std::shared_ptr<Attribute<ValueType>> delete_and_export_attribute(
1513 std::string_view name,
1516
1534 template <typename ValueType>
1535 std::shared_ptr<const Attribute<ValueType>> delete_and_export_const_attribute(
1536 std::string_view name,
1539
1556 template <typename ValueType>
1558 std::string_view name,
1560 -> std::shared_ptr<IndexedAttribute<ValueType, Index>>;
1561
1578 template <typename ValueType>
1580 std::string_view name,
1582 -> std::shared_ptr<const IndexedAttribute<ValueType, Index>>;
1583
1584public:
1588
1603 AttributeId create_metadata(std::string_view name, std::string_view value);
1604
1611 void set_metadata(AttributeId id, std::string_view value);
1612
1620 void set_metadata(std::string_view name, std::string_view value);
1621
1629 std::string_view get_metadata(AttributeId id) const;
1630
1638 std::string_view get_metadata(std::string_view name) const;
1639
1640public:
1644
1655 [[nodiscard]] bool has_attribute(std::string_view name) const;
1656
1666 template <typename ValueType>
1667 [[nodiscard]] bool is_attribute_type(std::string_view name) const;
1668
1678 template <typename ValueType>
1679 [[nodiscard]] bool is_attribute_type(AttributeId id) const;
1680
1687 [[nodiscard]] bool is_attribute_indexed(std::string_view name) const;
1688
1695 [[nodiscard]] bool is_attribute_indexed(AttributeId id) const;
1696
1708
1719 void seq_foreach_attribute_id(function_ref<void(std::string_view, AttributeId)> func) const;
1720
1732
1743 void par_foreach_attribute_id(function_ref<void(std::string_view, AttributeId)> func) const;
1744
1752 [[nodiscard]] const AttributeBase& get_attribute_base(std::string_view name) const;
1753
1761 [[nodiscard]] const AttributeBase& get_attribute_base(AttributeId id) const;
1762
1772 template <typename ValueType>
1773 [[nodiscard]] const Attribute<ValueType>& get_attribute(std::string_view name) const;
1774
1784 template <typename ValueType>
1785 [[nodiscard]] const Attribute<ValueType>& get_attribute(AttributeId id) const;
1786
1797 std::string_view name) const;
1798
1809 AttributeId id) const;
1810
1820 template <typename ValueType>
1821 [[nodiscard]] auto get_indexed_attribute(std::string_view name) const
1823
1833 template <typename ValueType>
1834 [[nodiscard]] auto get_indexed_attribute(AttributeId id) const
1836
1847 template <typename ValueType>
1848 [[nodiscard]] Attribute<ValueType>& ref_attribute(std::string_view name);
1849
1860 template <typename ValueType>
1862
1873 std::string_view name);
1874
1885
1896 template <typename ValueType>
1897 [[nodiscard]] auto ref_indexed_attribute(std::string_view name)
1899
1910 template <typename ValueType>
1912
1918 [[nodiscard]] const Attribute<Scalar>& get_vertex_to_position() const;
1919
1926
1932 [[nodiscard]] const Attribute<Index>& get_corner_to_vertex() const;
1933
1948
1949public:
1953
1962 static bool attr_name_is_reserved(std::string_view name);
1963
1969 static constexpr std::string_view attr_name_vertex_to_position()
1970 {
1971 return s_reserved_names.vertex_to_position();
1972 }
1973
1979 static constexpr std::string_view attr_name_corner_to_vertex()
1980 {
1981 return s_reserved_names.corner_to_vertex();
1982 }
1983
1989 static constexpr std::string_view attr_name_facet_to_first_corner()
1990 {
1991 return s_reserved_names.facet_to_first_corner();
1992 }
1993
1999 static constexpr std::string_view attr_name_corner_to_facet()
2000 {
2001 return s_reserved_names.corner_to_facet();
2002 }
2003
2009 static constexpr std::string_view attr_name_corner_to_edge()
2010 {
2011 return s_reserved_names.corner_to_edge();
2012 }
2013
2019 static constexpr std::string_view attr_name_edge_to_first_corner()
2020 {
2021 return s_reserved_names.edge_to_first_corner();
2022 }
2023
2029 static constexpr std::string_view attr_name_next_corner_around_edge()
2030 {
2031 return s_reserved_names.next_corner_around_edge();
2032 }
2033
2039 static constexpr std::string_view attr_name_vertex_to_first_corner()
2040 {
2041 return s_reserved_names.vertex_to_first_corner();
2042 }
2043
2049 static constexpr std::string_view attr_name_next_corner_around_vertex()
2050 {
2051 return s_reserved_names.next_corner_around_vertex();
2052 }
2053
2059 AttributeId attr_id_vertex_to_position() const { return m_reserved_ids.vertex_to_position(); }
2060
2066 [[deprecated("Use attr_id_vertex_to_position() instead.")]] AttributeId
2068 {
2069 return m_reserved_ids.vertex_to_position();
2070 }
2071
2077 AttributeId attr_id_corner_to_vertex() const { return m_reserved_ids.corner_to_vertex(); }
2078
2085 {
2086 return m_reserved_ids.facet_to_first_corner();
2087 }
2088
2094 AttributeId attr_id_corner_to_facet() const { return m_reserved_ids.corner_to_facet(); }
2095
2101 AttributeId attr_id_corner_to_edge() const { return m_reserved_ids.corner_to_edge(); }
2102
2109 {
2110 return m_reserved_ids.edge_to_first_corner();
2111 }
2112
2119 {
2120 return m_reserved_ids.next_corner_around_edge();
2121 }
2122
2129 {
2130 return m_reserved_ids.vertex_to_first_corner();
2131 }
2132
2139 {
2140 return m_reserved_ids.next_corner_around_vertex();
2141 }
2142
2143public:
2147
2157
2169 void initialize_edges(Index num_user_edges, GetEdgeVertices get_user_edge);
2170
2184
2190 bool has_edges() const
2191 {
2192 return m_reserved_ids.edge_to_first_corner() != invalid_attribute_id();
2193 }
2194
2204
2215
2221 [[deprecated("Use get_corner_edge() instead.")]] Index get_edge_from_corner(Index c) const;
2222
2230 std::array<Index, 2> get_edge_vertices(Index e) const;
2231
2240
2251
2260
2270
2279
2293
2306
2319
2336
2352
2361
2374
2387
2396
2407
2415
2426
2434
2442
2451
2453
2454protected:
2459 {
2460 };
2461
2467 explicit SurfaceMesh(BareMeshTag tag);
2468
2493 template <typename ValueType>
2495 std::string_view name,
2496 AttributeElement element,
2498 size_t num_channels = 1,
2499 span<const ValueType> initial_values = {},
2500 span<const Index> initial_indices = {});
2501
2509 template <typename ValueType>
2510 void set_attribute_default_internal(std::string_view name);
2511
2521
2532 std::pair<Index, Index> reindex_facets_internal(span<const Index> old_to_new);
2533
2544
2553 function_ref<Index(Index)> old_to_new_corners,
2554 CornerMappingType mapping_type);
2555
2564 template <AttributeElement element>
2566
2574
2582
2590
2598
2610
2621
2634
2641 void compute_corner_to_facet_internal(Index facet_begin, Index facet_end);
2642
2652 Index num_user_edges = 0,
2653 GetEdgeVertices* get_user_edge_ptr = nullptr);
2654
2676 Index facet_begin,
2677 Index facet_end,
2678 Index num_user_edges = 0,
2679 GetEdgeVertices* get_user_edge_ptr = nullptr);
2680
2691 Index count,
2692 Index num_user_edges = 0,
2693 GetEdgeVertices* get_user_edge_ptr = nullptr);
2694
2703 [[nodiscard]] size_t get_num_elements_internal(AttributeElement element) const;
2704
2715 template <typename ValueType>
2717 Attribute<std::decay_t<ValueType>>& attr,
2718 size_t num_values,
2719 span<ValueType> values_view);
2720
2734 template <typename ValueType>
2736 Attribute<std::decay_t<ValueType>>& attr,
2737 size_t num_values,
2738 SharedSpan<ValueType> shared_values);
2739
2753 template <typename OffsetSpan, typename FacetSpan>
2755 OffsetSpan offsets,
2756 Index num_facets,
2757 FacetSpan facets,
2758 Index num_corners);
2759
2782 template <typename ValueSpan, typename IndexSpan = span<Index>>
2784 std::string_view name,
2785 AttributeElement element,
2786 AttributeUsage usage,
2787 size_t num_values,
2788 size_t num_channels,
2789 ValueSpan values,
2790 IndexSpan indices = {});
2791
2792protected:
2794
2796 template <typename, typename>
2797 friend class SurfaceMesh;
2798
2800 template <typename S, typename I>
2802 template <typename S, typename I>
2804
2808 struct AttributeManager;
2809
2811
2812protected:
2815
2818
2821
2824
2827
2830
2833
2835 struct ReservedAttributeIds
2836 {
2837 AttributeId items[9];
2838
2839 ReservedAttributeIds() { std::fill_n(items, 9, invalid_attribute_id()); }
2840 static constexpr int size() { return 9; }
2841
2842 AttributeId& vertex_to_position() { return items[0]; };
2843 AttributeId& corner_to_vertex() { return items[1]; };
2844 AttributeId& facet_to_first_corner() { return items[2]; };
2845 AttributeId& corner_to_facet() { return items[3]; };
2846 AttributeId& corner_to_edge() { return items[4]; };
2847 AttributeId& edge_to_first_corner() { return items[5]; };
2848 AttributeId& next_corner_around_edge() { return items[6]; };
2849 AttributeId& vertex_to_first_corner() { return items[7]; };
2850 AttributeId& next_corner_around_vertex() { return items[8]; };
2851
2852 const AttributeId& vertex_to_position() const { return items[0]; };
2853 const AttributeId& corner_to_vertex() const { return items[1]; };
2854 const AttributeId& facet_to_first_corner() const { return items[2]; };
2855 const AttributeId& corner_to_facet() const { return items[3]; };
2856 const AttributeId& corner_to_edge() const { return items[4]; };
2857 const AttributeId& edge_to_first_corner() const { return items[5]; };
2858 const AttributeId& next_corner_around_edge() const { return items[6]; };
2859 const AttributeId& vertex_to_first_corner() const { return items[7]; };
2860 const AttributeId& next_corner_around_vertex() const { return items[8]; };
2861 } m_reserved_ids;
2862
2863protected:
2865 static constexpr struct
2866 {
2867 std::string_view items[9] = {
2868 "$vertex_to_position",
2869 "$corner_to_vertex",
2870 "$facet_to_first_corner",
2871 "$corner_to_facet",
2872 "$corner_to_edge",
2873 "$edge_to_first_corner",
2874 "$next_corner_around_edge",
2875 "$vertex_to_first_corner",
2876 "$next_corner_around_vertex",
2877 };
2878 std::string_view vertex_to_position() const { return items[0]; }
2879 std::string_view corner_to_vertex() const { return items[1]; }
2880 std::string_view facet_to_first_corner() const { return items[2]; }
2881 std::string_view corner_to_facet() const { return items[3]; }
2882 std::string_view corner_to_edge() const { return items[4]; }
2883 std::string_view edge_to_first_corner() const { return items[5]; }
2884 std::string_view next_corner_around_edge() const { return items[6]; }
2885 std::string_view vertex_to_first_corner() const { return items[7]; }
2886 std::string_view next_corner_around_vertex() const { return items[8]; }
2888};
2889
2890using SurfaceMesh32f = SurfaceMesh<float, uint32_t>;
2891using SurfaceMesh32d = SurfaceMesh<double, uint32_t>;
2892using SurfaceMesh64f = SurfaceMesh<float, uint64_t>;
2893using SurfaceMesh64d = SurfaceMesh<double, uint64_t>;
2894
2896
2897} // namespace lagrange
Base handle for attributes.
Definition Attribute.h:62
Derived attribute class that stores the actual information.
Definition Attribute.h:174
Derived attribute class that stores the actual information.
Definition IndexedAttribute.h:29
Shared span with ownership tracking.
Definition SharedSpan.h:36
A general purpose polygonal mesh class.
Definition SurfaceMesh.h:73
function_ref< std::array< Index, 2 >(Index e)> GetEdgeVertices
Callback function to get the vertex indices of an edge endpoints in a user-provided ordering of a mes...
Definition SurfaceMesh.h:145
void add_hybrid(span< const Index > facet_sizes, span< const Index > facet_indices={})
Adds multiple polygonal facets of different sizes to the mesh.
Definition SurfaceMesh.cpp:1763
Index find_edge_from_vertices(Index v0, Index v1) const
Retrieve the edge index corresponding to (v0, v1).
Definition SurfaceMesh.cpp:2709
void foreach_edge_around_vertex_with_duplicates(Index v, function_ref< void(Index)> func) const
Applies a function to each edge around a prescribed vertex.
Definition SurfaceMesh.cpp:2941
span< Index > reserve_indices_internal(Index num_facets, Index facet_size)
Reserve index buffer for multiple facets of a given size.
Definition SurfaceMesh.cpp:3354
AttributeId attr_id_vertex_to_position() const
Attribute id for vertex -> positions.
Definition SurfaceMesh.h:2059
void add_quads(Index num_facets, span< const Index > facet_indices={})
Adds multiple quadrilateral facets to the mesh.
Definition SurfaceMesh.cpp:1694
AttributeId wrap_as_const_indexed_attribute(std::string_view name, AttributeUsage usage, size_t num_values, size_t num_channels, SharedSpan< const ValueType > shared_values, SharedSpan< const Index > shared_indices)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition SurfaceMesh.cpp:747
Index get_next_corner_around_facet(Index c) const
Gets the next corner around the facet associated to a corner.
Definition SurfaceMesh.cpp:2699
static constexpr std::string_view attr_name_facet_to_first_corner()
Attribute name for facet -> first corner index.
Definition SurfaceMesh.h:1989
AttributeId wrap_as_const_indexed_attribute(std::string_view name, AttributeUsage usage, size_t num_values, size_t num_channels, SharedSpan< const ValueType > shared_values, span< const Index > indices_view)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition SurfaceMesh.cpp:789
void foreach_facet_around_edge(Index e, function_ref< void(Index)> func) const
Applies a function to each facet around a prescribed edge.
Definition SurfaceMesh.cpp:2892
void par_foreach_attribute_id(function_ref< void(AttributeId)> func) const
Iterates over all attribute ids in parallel.
Definition SurfaceMesh.cpp:1264
bool is_quad_mesh() const
Whether the mesh must only contains quadrilateral facets.
Definition SurfaceMesh.cpp:2326
std::string_view get_attribute_name(AttributeId id) const
Retrieve attribute name from its id.
Definition SurfaceMesh.cpp:357
void add_quads(Index num_facets, SetMultiFacetsIndicesFunction set_facets_indices)
Adds multiple quadrilateral facets to the mesh.
Definition SurfaceMesh.cpp:1708
bool is_boundary_edge(Index e) const
Determines whether the specified edge e is a boundary edge.
Definition SurfaceMesh.cpp:2843
Index get_facet_corner_end(Index f) const
Index past the last corner around the facet.
Definition SurfaceMesh.cpp:2379
Attribute< Scalar > & ref_vertex_to_position()
Gets a writable reference to the vertex -> positions attribute.
Definition SurfaceMesh.cpp:1395
void clear_edges()
Clears attributes related to mesh edges and connectivity:
Definition SurfaceMesh.cpp:2652
function_ref< void(Index f, span< Index > t)> SetMultiFacetsIndicesFunction
Callback function to set indices of a multiple facets.
Definition SurfaceMesh.h:125
void set_metadata(std::string_view name, std::string_view value)
Write metadata attribute value.
Definition SurfaceMesh.cpp:1196
void add_vertex(std::initializer_list< const Scalar > p)
Adds a vertex to the mesh.
Definition SurfaceMesh.cpp:1571
void update_edges_range_internal(Index facet_begin, Index facet_end, Index num_user_edges=0, GetEdgeVertices *get_user_edge_ptr=nullptr)
Update attributes associated to mesh edges and connectivity for a specific range of facets.
Definition SurfaceMesh.cpp:2513
static constexpr std::string_view attr_name_next_corner_around_vertex()
Attribute name for corner -> next corner around vertex.
Definition SurfaceMesh.h:2049
static constexpr std::string_view attr_name_vertex_to_position()
Attribute name for vertex -> position.
Definition SurfaceMesh.h:1969
function_ref< Index(Index f)> GetFacetsSizeFunction
Callback function to get a facet size (number of vertices in the facet).
Definition SurfaceMesh.h:135
static constexpr std::string_view attr_name_corner_to_vertex()
Attribute name for corner -> vertex indices.
Definition SurfaceMesh.h:1979
AttributeId attr_id_corner_to_edge() const
Attribute id for corner -> edge indices.
Definition SurfaceMesh.h:2101
static SurfaceMesh stripped_copy(const SurfaceMesh< OtherScalar, OtherIndex > &other)
Copy constructor stripping away non-reserved attributes.
bool is_attribute_type(AttributeId id) const
Checks whether the specified attribute is of a given type.
Definition SurfaceMesh.cpp:1230
void set_attribute_default_internal(std::string_view name)
Set attribute default value for known internal attributes.
Definition SurfaceMesh.cpp:378
void add_polygon(Index facet_size, SetSingleFacetIndicesFunction set_facet_indices)
Adds a single polygonal facet to the mesh.
Definition SurfaceMesh.cpp:1660
const Attribute< ValueType > & get_attribute(std::string_view name) const
Gets a read-only reference to an attribute given its name.
Definition SurfaceMesh.cpp:1292
Index m_num_facets
Definition SurfaceMesh.h:2817
void delete_attribute(std::string_view name, AttributeDeletePolicy policy=AttributeDeletePolicy::ErrorIfReserved)
Delete an attribute given by name.
Definition SurfaceMesh.cpp:1043
Index count_num_corners_around_edge(Index e) const
Count the number of corners incident to a given edge.
Definition SurfaceMesh.cpp:2814
Index get_num_vertices() const
Retrieves the number of vertices.
Definition SurfaceMesh.h:687
void resize_facets_internal(Index num_facets)
Resize the buffers associated to mesh facets and their attributes.
Definition SurfaceMesh.cpp:3333
Attribute< ValueType > & ref_attribute(std::string_view name)
Gets a writable reference to an attribute given its name.
Definition SurfaceMesh.cpp:1342
AttributeId wrap_as_const_attribute(std::string_view name, AttributeElement element, AttributeUsage usage, size_t num_channels, SharedSpan< const ValueType > shared_values)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition SurfaceMesh.cpp:620
Index get_corner_edge(Index c) const
Gets the edge index corresponding to a corner index.
Definition SurfaceMesh.cpp:2671
void flip_facets(span< const Index > facets_to_flip, AttributeReorientPolicy reorient_policy=AttributeReorientPolicy::None)
Reverses the orientation of a list of facets.
Definition SurfaceMesh.cpp:2168
AttributeId attr_id_facet_to_first_corner() const
Attribute id for facet -> first corner index.
Definition SurfaceMesh.h:2084
std::shared_ptr< Attribute< ValueType > > delete_and_export_attribute(std::string_view name, AttributeDeletePolicy delete_policy=AttributeDeletePolicy::ErrorIfReserved, AttributeExportPolicy export_policy=AttributeExportPolicy::CopyIfExternal)
Delete an attribute and export its content in a writable shared_ptr.
Definition SurfaceMesh.cpp:1115
std::array< Index, 2 > get_edge_vertices(Index e) const
Retrieve edge endpoints.
Definition SurfaceMesh.cpp:2685
void add_vertices(Index num_vertices, std::initializer_list< const Scalar > coordinates)
Adds multiple vertices to the mesh.
Definition SurfaceMesh.cpp:1594
void add_hybrid(Index num_facets, GetFacetsSizeFunction facet_sizes, SetMultiFacetsIndicesFunction set_facets_indices)
Adds multiple polygonal facets of different sizes to the mesh.
Definition SurfaceMesh.cpp:1790
void remove_vertices(std::initializer_list< const Index > vertices_to_remove)
Removes a list of vertices.
Definition SurfaceMesh.cpp:1854
AttributeId wrap_as_facets(SharedSpan< Index > shared_offsets, Index num_facets, span< Index > facets_view, Index num_corners)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition SurfaceMesh.cpp:971
Index get_dimension() const
Retrieves the dimension of the mesh vertices.
Definition SurfaceMesh.h:672
void add_quads(Index num_facets, std::initializer_list< const Index > facet_indices)
Adds multiple quadrilateral facets to the mesh.
Definition SurfaceMesh.cpp:1700
AttributeId wrap_as_const_indexed_attribute(std::string_view name, AttributeUsage usage, size_t num_values, size_t num_channels, span< const ValueType > values_view, SharedSpan< const Index > shared_indices)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition SurfaceMesh.cpp:768
Index get_edge(Index f, Index lv) const
Gets the edge index corresponding to (f, lv) – (f, lv+1).
Definition SurfaceMesh.cpp:2663
::lagrange::internal::weak_ptr< const AttributeBase > _get_attribute_ptr(AttributeId id) const
Gets a read-only weak pointer to the base attribute object.
Definition SurfaceMesh.cpp:1314
Index m_vertex_per_facet
Definition SurfaceMesh.h:2829
void wrap_as_attribute_internal(Attribute< std::decay_t< ValueType > > &attr, size_t num_values, SharedSpan< ValueType > shared_values)
Wrap a shared span in an attribute.
Definition SurfaceMesh.cpp:3479
Index get_clockwise_corner_around_vertex(Index c) const
Get the adjacent corner around the vertex associated to a corner in the clockwise direction.
Definition SurfaceMesh.cpp:2791
AttributeId create_attribute(std::string_view name, AttributeElement element, size_t num_channels=1, AttributeUsage usage=AttributeUsage::Vector, span< const ValueType > initial_values={}, span< const Index > initial_indices={}, AttributeCreatePolicy policy=AttributeCreatePolicy::ErrorIfReserved)
Create a new attribute and return the newly created attribute id.
Definition SurfaceMesh.cpp:408
static constexpr std::string_view attr_name_corner_to_facet()
Attribute name for corner -> facet index.
Definition SurfaceMesh.h:1999
AttributeId attr_id_corner_to_vertex() const
Attribute id for corner -> vertex indices.
Definition SurfaceMesh.h:2077
bool is_attribute_type(std::string_view name) const
Checks whether the specified attribute is of a given type.
Definition SurfaceMesh.cpp:1223
Index m_num_vertices
Definition SurfaceMesh.h:2814
AttributeId get_attribute_id(std::string_view name) const
Retrieve an attribute id given its name.
Definition SurfaceMesh.cpp:347
void reindex_corners_internal(function_ref< Index(Index)> old_to_new_corners, CornerMappingType mapping_type)
Reindex mesh corners according to the given mapping.
Definition SurfaceMesh.cpp:3154
void add_vertices(Index num_vertices, span< const Scalar > coordinates={})
Adds multiple vertices to the mesh.
Definition SurfaceMesh.cpp:1581
std::make_signed_t< Index > SignedIndex
Signed index type corresponding to the mesh index type.
Definition SurfaceMesh.h:82
Index get_next_corner_around_edge(Index c) const
Gets the next corner around the edge associated to a corner.
Definition SurfaceMesh.cpp:2742
Index get_edge_from_corner(Index c) const
Gets the edge index corresponding to a corner index.
Definition SurfaceMesh.cpp:2679
void add_triangles(Index num_facets, SetMultiFacetsIndicesFunction set_facets_indices)
Adds multiple triangular facets to the mesh.
Definition SurfaceMesh.cpp:1686
AttributeId wrap_as_vertices(SharedSpan< Scalar > shared_vertices, Index num_vertices)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition SurfaceMesh.cpp:821
span< Index > ref_facet_vertices(Index f)
Retrieves a writable pointer to a facet indices.
Definition SurfaceMesh.cpp:2416
void foreach_facet_around_vertex(Index v, function_ref< void(Index)> func) const
Applies a function to each facet around a prescribed vertex.
Definition SurfaceMesh.cpp:2869
AttributeId create_attribute(std::string_view name, AttributeElement element, AttributeUsage usage, size_t num_channels=1, span< const ValueType > initial_values={}, span< const Index > initial_indices={}, AttributeCreatePolicy policy=AttributeCreatePolicy::ErrorIfReserved)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition SurfaceMesh.cpp:433
void remove_vertices(span< const Index > vertices_to_remove)
Removes a list of vertices.
Definition SurfaceMesh.cpp:1810
void remove_facets(span< const Index > facets_to_remove)
Removes a list of facets.
Definition SurfaceMesh.cpp:1901
void resize_vertices_internal(Index num_vertices)
Resize the buffers associated to mesh vertices and their attributes.
Definition SurfaceMesh.cpp:3326
bool has_attribute(std::string_view name) const
Checks if an attribute of a given name is attached to the mesh.
Definition SurfaceMesh.cpp:1216
const Attribute< ValueType > & get_attribute(AttributeId id) const
Gets a read-only reference to an attribute given its id.
Definition SurfaceMesh.cpp:1299
AttributeId wrap_as_const_facets(SharedSpan< const Index > shared_offsets, Index num_facets, span< const Index > facets_view, Index num_corners)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition SurfaceMesh.cpp:1011
AttributeId wrap_as_facets(span< Index > offsets_view, Index num_facets, span< Index > facets_view, Index num_corners)
Wraps writable external buffers as mesh facets for a hybrid mesh.
Definition SurfaceMesh.cpp:941
AttributeId wrap_as_const_indexed_attribute(std::string_view name, AttributeUsage usage, size_t num_values, size_t num_channels, span< const ValueType > values_view, span< const Index > indices_view)
Wraps a read-only external buffer as a mesh attribute.
Definition SurfaceMesh.cpp:726
std::shared_ptr< const Attribute< ValueType > > delete_and_export_const_attribute(std::string_view name, AttributeDeletePolicy delete_policy=AttributeDeletePolicy::ErrorIfReserved, AttributeExportPolicy export_policy=AttributeExportPolicy::CopyIfExternal)
Delete an attribute and export its content in a read-only shared_ptr.
Definition SurfaceMesh.cpp:1131
std::string_view get_metadata(AttributeId id) const
Read metadata attribute value.
Definition SurfaceMesh.cpp:1202
AttributeId create_metadata(std::string_view name, std::string_view value)
Create a metadata attribute.
Definition SurfaceMesh.cpp:1175
Index count_num_corners_around_vertex(Index v) const
Count the number of corners incident to a given vertex.
Definition SurfaceMesh.cpp:2760
AttributeId wrap_as_const_facets(span< const Index > offsets_view, Index num_facets, span< const Index > facets_view, Index num_corners)
Wraps read-only external buffers as mesh facets for a hybrid mesh.
Definition SurfaceMesh.cpp:981
bool is_attribute_indexed(AttributeId id) const
Determines whether the specified attribute is indexed.
Definition SurfaceMesh.cpp:1243
value_ptr< AttributeManager > m_attributes
Definition SurfaceMesh.h:2832
AttributeId wrap_as_facets(SharedSpan< Index > shared_facets, Index num_facets, Index vertex_per_facet)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition SurfaceMesh.cpp:878
void add_quad(Index v0, Index v1, Index v2, Index v3)
Adds a quadrilateral facet to the mesh.
Definition SurfaceMesh.cpp:1625
void add_polygon(Index facet_size)
Adds a single (uninitialized) polygonal facet to the mesh.
Definition SurfaceMesh.cpp:1634
auto ref_indexed_attribute(AttributeId id) -> IndexedAttribute< ValueType, Index > &
Gets a writable reference to an indexed attribute given its id.
Definition SurfaceMesh.cpp:1380
AttributeId wrap_as_facets_internal(OffsetSpan offsets, Index num_facets, FacetSpan facets, Index num_corners)
Wrap shared spans as offsets and facets.
Definition SurfaceMesh.cpp:3507
void shrink_to_fit()
Shrink buffer capacities to fit current mesh attributes, deallocating any extra capacity.
Definition SurfaceMesh.cpp:2273
AttributeId attr_id_vertex_to_positions() const
Attribute id for vertex -> positions.
Definition SurfaceMesh.h:2067
void clear_facets()
Clear buffer for mesh facets and other facet/corner attributes.
Definition SurfaceMesh.cpp:2260
Index get_one_corner_around_vertex(Index v) const
Get the index of one corner around a given vertex.
Definition SurfaceMesh.cpp:2837
SurfaceMesh & operator=(const SurfaceMesh &other)
Assignment copy operator.
Index get_facet_corner_begin(Index f) const
First corner around the facet.
Definition SurfaceMesh.cpp:2367
::lagrange::internal::weak_ptr< AttributeBase > _ref_attribute_ptr(AttributeId id)
Gets a weak pointer to the base attribute object.
Definition SurfaceMesh.cpp:1364
void add_vertex(span< const Scalar > p)
Adds a vertex to the mesh.
Definition SurfaceMesh.cpp:1561
SurfaceMesh(Index dimension=3)
Default constructor.
Definition SurfaceMesh.cpp:1433
size_t get_num_elements_internal(AttributeElement element) const
Gets the number of mesh elements, based on an element type.
Definition SurfaceMesh.cpp:363
AttributeId create_attribute_from(std::string_view name, const SurfaceMesh< OtherScalar, OtherIndex > &source_mesh, std::string_view source_name={})
Creates an new attribute by creating a shallow copy of another mesh's attribute.
Definition SurfaceMesh.cpp:534
AttributeId attr_id_vertex_to_first_corner() const
Attribute id for vertex -> first corner index.
Definition SurfaceMesh.h:2128
void add_polygons(Index num_facets, Index facet_size, std::initializer_list< const Index > facet_indices)
Adds multiple polygonal facets of the same size to the mesh.
Definition SurfaceMesh.cpp:1736
AttributeId wrap_as_indexed_attribute(std::string_view name, AttributeUsage usage, size_t num_values, size_t num_channels, SharedSpan< ValueType > shared_values, SharedSpan< Index > shared_indices)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition SurfaceMesh.cpp:663
Scalar_ Scalar
Mesh scalar type, used for vertex coordinates.
Definition SurfaceMesh.h:76
::lagrange::internal::weak_ptr< AttributeBase > _ref_attribute_ptr(std::string_view name)
Gets a weak pointer to the base attribute object.
Definition SurfaceMesh.cpp:1357
const AttributeBase & get_attribute_base(std::string_view name) const
Gets a read-only reference to the base class of attribute given its name.
Definition SurfaceMesh.cpp:1278
void resize_corners_internal(Index num_corners)
Resize the buffers associated to mesh corners and their attributes.
Definition SurfaceMesh.cpp:3340
void foreach_facet_around_facet(Index f, function_ref< void(Index)> func) const
Applies a function to each of the facets around a prescribed facet.
Definition SurfaceMesh.cpp:2851
void add_triangle(Index v0, Index v1, Index v2)
Adds a triangular facet to the mesh.
Definition SurfaceMesh.cpp:1616
Index_ Index
Mesh index type, used for facet indices.
Definition SurfaceMesh.h:79
void add_hybrid(std::initializer_list< const Index > facet_sizes, std::initializer_list< const Index > facet_indices)
Adds multiple polygonal facets of different sizes to the mesh.
Definition SurfaceMesh.cpp:1780
span< Index > reserve_indices_internal(Index num_facets, GetFacetsSizeFunction get_facets_size)
Reserve index buffer for multiple facets of a given size.
Definition SurfaceMesh.cpp:3383
Index get_one_facet_around_edge(Index e) const
Get the index of one facet around a given edge.
Definition SurfaceMesh.cpp:2823
Index get_first_corner_around_edge(Index e) const
Get the index of the first corner around a given edge.
Definition SurfaceMesh.cpp:2736
AttributeId wrap_as_indexed_attribute(std::string_view name, AttributeUsage usage, size_t num_values, size_t num_channels, SharedSpan< ValueType > shared_values, span< Index > indices_view)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition SurfaceMesh.cpp:705
void seq_foreach_attribute_id(function_ref< void(std::string_view, AttributeId)> func) const
Iterates over all pairs of attribute names x ids sequentially.
Definition SurfaceMesh.cpp:1257
void add_triangles(Index num_facets, std::initializer_list< const Index > facet_indices)
Adds multiple triangular facets to the mesh.
Definition SurfaceMesh.cpp:1678
void flip_facets(std::initializer_list< const Index > facets_to_flip, AttributeReorientPolicy reorient_policy=AttributeReorientPolicy::None)
Reverses the orientation of a list of facets.
Definition SurfaceMesh.cpp:2193
void remove_facets(std::initializer_list< const Index > facets_to_remove)
Removes a list of facets.
Definition SurfaceMesh.cpp:1936
void compute_corner_to_facet_internal(Index facet_begin, Index facet_end)
Compute inverse mapping corner -> facet index for a specific range of facets.
Definition SurfaceMesh.cpp:3464
void add_triangles(Index num_facets, span< const Index > facet_indices={})
Adds multiple triangular facets to the mesh.
Definition SurfaceMesh.cpp:1672
void add_polygon(std::initializer_list< const Index > facet_indices)
Adds a single polygonal facet to the mesh.
Definition SurfaceMesh.cpp:1651
void initialize_edges_internal(Index num_user_edges=0, GetEdgeVertices *get_user_edge_ptr=nullptr)
Initializes attributes associated to mesh edges and connectivity.
Definition SurfaceMesh.cpp:2457
auto get_indexed_attribute(std::string_view name) const -> const IndexedAttribute< ValueType, Index > &
Gets a read-only reference to an indexed attribute given its name.
Definition SurfaceMesh.cpp:1324
~SurfaceMesh()
Default destructor.
Attribute< ValueType > & ref_attribute(AttributeId id)
Gets a writable reference to an attribute given its id.
Definition SurfaceMesh.cpp:1349
void resize_elements_internal(Index num_elements)
Resize the buffers associated to a specific element type in the mesh.
Definition SurfaceMesh.cpp:3311
void initialize_edges(Index num_user_edges, GetEdgeVertices get_user_edge)
Initializes attributes associated to mesh edges and connectivity.
Definition SurfaceMesh.cpp:2449
void set_metadata(AttributeId id, std::string_view value)
Write metadata attribute value.
Definition SurfaceMesh.cpp:1186
bool is_regular() const
Whether the mesh must only contains facets of equal sizes.
Definition SurfaceMesh.cpp:2332
AttributeId attr_id_next_corner_around_edge() const
Attribute id for corner -> next corner around edge.
Definition SurfaceMesh.h:2118
AttributeId wrap_as_indexed_attribute(std::string_view name, AttributeUsage usage, size_t num_values, size_t num_channels, span< ValueType > values_view, SharedSpan< Index > shared_indices)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition SurfaceMesh.cpp:684
Index get_first_corner_around_vertex(Index v) const
Get the index of the first corner around a given vertex.
Definition SurfaceMesh.cpp:2748
AttributeId wrap_as_facets(span< Index > offsets_view, Index num_facets, SharedSpan< Index > shared_facets, Index num_corners)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition SurfaceMesh.cpp:961
Index m_num_corners
Definition SurfaceMesh.h:2820
bool is_attribute_indexed(std::string_view name) const
Determines whether the specified attribute is indexed.
Definition SurfaceMesh.cpp:1237
const Attribute< Index > & get_corner_to_vertex() const
Gets a read-only reference to the corner -> vertex id attribute.
Definition SurfaceMesh.cpp:1401
std::string_view get_metadata(std::string_view name) const
Read metadata attribute value.
Definition SurfaceMesh.cpp:1210
void update_edges_last_internal(Index count, Index num_user_edges=0, GetEdgeVertices *get_user_edge_ptr=nullptr)
Same as update_edges_range_internal, but operate on the last count facets in the mesh instead.
Definition SurfaceMesh.cpp:2502
void par_foreach_attribute_id(function_ref< void(std::string_view, AttributeId)> func) const
Iterates over all pairs of attribute names x ids in parallel.
Definition SurfaceMesh.cpp:1271
SurfaceMesh & operator=(SurfaceMesh &&other) noexcept
Assignment move operator.
AttributeId wrap_as_const_vertices(span< const Scalar > vertices_view, Index num_vertices)
Wraps a read-only external buffer as mesh vertices coordinates.
Definition SurfaceMesh.cpp:833
Index get_next_corner_around_vertex(Index c) const
Gets the next corner around the vertex associated to a corner.
Definition SurfaceMesh.cpp:2754
Index get_facet_vertex(Index f, Index lv) const
Index of a vertex given from a facet + local index.
Definition SurfaceMesh.h:748
AttributeId wrap_as_const_facets(span< const Index > facets_view, Index num_facets, Index vertex_per_facet)
Wraps a read-only external buffer as mesh facets for a regular mesh.
Definition SurfaceMesh.cpp:899
void compress_if_regular()
Compress mesh storage if the mesh is regular.
Definition SurfaceMesh.cpp:2287
bool is_triangle_mesh() const
Whether the mesh must only contain triangular facets.
Definition SurfaceMesh.cpp:2320
void wrap_as_attribute_internal(Attribute< std::decay_t< ValueType > > &attr, size_t num_values, span< ValueType > values_view)
Wrap a span in an attribute.
Definition SurfaceMesh.cpp:3493
Index get_corner_vertex(Index c) const
Retrieves the index of a vertex given its corner index.
Definition SurfaceMesh.cpp:2393
void foreach_corner_around_vertex(Index v, function_ref< void(Index)> func) const
Applies a function to each corner around a prescribed vertex.
Definition SurfaceMesh.cpp:2914
void resize_edges_internal(Index num_edges)
Resize the buffers associated to mesh edges and their attributes.
Definition SurfaceMesh.cpp:3347
Index get_corner_facet(Index c) const
Retrieves the index of a facet given its corner index.
Definition SurfaceMesh.cpp:2399
bool has_edges() const
Determines if the attributes associated to mesh edges and connectivity have been initialized.
Definition SurfaceMesh.h:2190
AttributeId wrap_as_const_facets(span< const Index > offsets_view, Index num_facets, SharedSpan< const Index > shared_facets, Index num_corners)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition SurfaceMesh.cpp:1001
SurfaceMesh(SurfaceMesh &&other) noexcept
Move constructor.
void add_vertices(Index num_vertices, SetVertexCoordinatesFunction set_vertex_coordinates)
Adds multiple vertices to the mesh.
Definition SurfaceMesh.cpp:1602
std::pair< Index, Index > reindex_facets_internal(span< const Index > old_to_new)
Reindex mesh facets according to the given mapping.
Definition SurfaceMesh.cpp:3045
auto delete_and_export_indexed_attribute(std::string_view name, AttributeExportPolicy policy=AttributeExportPolicy::CopyIfExternal) -> std::shared_ptr< IndexedAttribute< ValueType, Index > >
Delete an indexed attribute and export its content in a writable shared_ptr.
Definition SurfaceMesh.cpp:1146
span< const Index > get_facet_vertices(Index f) const
Retrieves a read-only pointer to a facet indices.
Definition SurfaceMesh.cpp:2410
static constexpr std::string_view attr_name_edge_to_first_corner()
Attribute name for edge -> first corner index.
Definition SurfaceMesh.h:2019
auto ref_indexed_attribute(std::string_view name) -> IndexedAttribute< ValueType, Index > &
Gets a writable reference to an indexed attribute given its name.
Definition SurfaceMesh.cpp:1372
AttributeId wrap_as_const_attribute(std::string_view name, AttributeElement element, AttributeUsage usage, size_t num_channels, span< const ValueType > values_view)
Wraps a read-only external buffer as a mesh attribute.
Definition SurfaceMesh.cpp:598
bool is_hybrid() const
Whether the mesh may contain facets of different sizes.
Definition SurfaceMesh.h:665
AttributeId wrap_as_attribute(std::string_view name, AttributeElement element, AttributeUsage usage, size_t num_channels, SharedSpan< ValueType > shared_values)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition SurfaceMesh.cpp:576
Index get_num_edges() const
Retrieves the number of edges.
Definition SurfaceMesh.h:708
AttributeId create_attribute_internal(std::string_view name, AttributeElement element, AttributeUsage usage=AttributeUsage::Vector, size_t num_channels=1, span< const ValueType > initial_values={}, span< const Index > initial_indices={})
Same as create_attribute, but allows creation of reserved attributes.
Definition SurfaceMesh.cpp:454
AttributeId wrap_as_vertices(span< Scalar > vertices_view, Index num_vertices)
Wraps a writable external buffer as mesh vertices coordinates.
Definition SurfaceMesh.cpp:809
AttributeId wrap_as_facets(SharedSpan< Index > shared_offsets, Index num_facets, SharedSpan< Index > shared_facets, Index num_corners)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition SurfaceMesh.cpp:951
Index get_one_corner_around_edge(Index e) const
Get the index of one corner around a given edge.
Definition SurfaceMesh.cpp:2831
static constexpr struct lagrange::SurfaceMesh::@325255152247021150212276167153340070021334233120 s_reserved_names
Index get_num_facets() const
Retrieves the number of facets.
Definition SurfaceMesh.h:694
Index get_vertex_per_facet() const
Retrieves the number of vertex per facet in a regular mesh.
Definition SurfaceMesh.cpp:2346
AttributeId wrap_as_const_facets(SharedSpan< const Index > shared_offsets, Index num_facets, SharedSpan< const Index > shared_facets, Index num_corners)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition SurfaceMesh.cpp:991
SurfaceMesh(const SurfaceMesh &other)
Copy constructor.
span< Scalar > ref_position(Index v)
Retrieves a writeable pointer to a vertex coordinates.
Definition SurfaceMesh.cpp:2361
AttributeId attr_id_edge_to_first_corner() const
Attribute id for edge -> first corner index.
Definition SurfaceMesh.h:2108
AttributeId wrap_as_indexed_attribute(std::string_view name, AttributeUsage usage, size_t num_values, size_t num_channels, span< ValueType > values_view, span< Index > indices_view)
Wraps a writable external buffer as a mesh attribute.
Definition SurfaceMesh.cpp:642
AttributeId duplicate_attribute(std::string_view old_name, std::string_view new_name)
Duplicates an attribute.
Definition SurfaceMesh.cpp:1021
void flip_facets(function_ref< bool(Index)> should_flip_func, AttributeReorientPolicy reorient_policy=AttributeReorientPolicy::None)
Reverses the orientation of a list of facets.
Definition SurfaceMesh.cpp:2201
static constexpr std::string_view attr_name_vertex_to_first_corner()
Attribute name for vertex -> first corner index.
Definition SurfaceMesh.h:2039
void delete_attribute(AttributeId id, AttributeDeletePolicy policy=AttributeDeletePolicy::ErrorIfReserved)
Delete an attribute given by its id.
Definition SurfaceMesh.cpp:1080
void remove_vertices(function_ref< bool(Index)> should_remove_func)
Removes a list of vertices, defined by a predicate function.
Definition SurfaceMesh.cpp:1861
AttributeId wrap_as_attribute_internal(std::string_view name, AttributeElement element, AttributeUsage usage, size_t num_values, size_t num_channels, ValueSpan values, IndexSpan indices={})
The most generic way of creating an attribute wrapped around external buffers.
Definition SurfaceMesh.cpp:3556
AttributeId attr_id_next_corner_around_vertex() const
Attribute id for corner -> next corner around vertex.
Definition SurfaceMesh.h:2138
Index m_dimension
Definition SurfaceMesh.h:2826
void initialize_edges(span< const Index > edges={})
Initializes attributes associated to mesh edges and connectivity.
Definition SurfaceMesh.cpp:2426
function_ref< void(Index v, span< Scalar > p)> SetVertexCoordinatesFunction
Callback function to set vertex coordinates.
Definition SurfaceMesh.h:103
static constexpr std::string_view attr_name_corner_to_edge()
Attribute name for corner -> edge indices.
Definition SurfaceMesh.h:2009
AttributeId wrap_as_attribute(std::string_view name, AttributeElement element, AttributeUsage usage, size_t num_channels, span< ValueType > values_view)
Wraps a writable external buffer as a mesh attribute.
Definition SurfaceMesh.cpp:554
Index get_counterclockwise_corner_around_vertex(Index c) const
Get the adjacent corner around the vertex associated to a corner in the counterclockwise direction.
Definition SurfaceMesh.cpp:2769
const AttributeBase & get_attribute_base(AttributeId id) const
Gets a read-only reference to an attribute given its id.
Definition SurfaceMesh.cpp:1284
void add_polygons(Index num_facets, Index facet_size, SetMultiFacetsIndicesFunction set_facets_indices)
Adds multiple polygonal facets of the same size to the mesh.
Definition SurfaceMesh.cpp:1748
AttributeId attr_id_corner_to_facet() const
Attribute id for corner -> facet index.
Definition SurfaceMesh.h:2094
void add_polygon(span< const Index > facet_indices)
Adds a single polygonal facet to the mesh.
Definition SurfaceMesh.cpp:1642
static SurfaceMesh stripped_move(SurfaceMesh< OtherScalar, OtherIndex > &&other)
Move constructor stripping away non-reserved attributes.
Attribute< Index > & ref_corner_to_vertex(AttributeRefPolicy policy=AttributeRefPolicy::Default)
Gets a writable reference to the corner -> vertex id attribute.
Definition SurfaceMesh.cpp:1407
AttributeId wrap_as_facets(span< Index > facets_view, Index num_facets, Index vertex_per_facet)
Wraps a writable external buffer as mesh facets for a regular mesh.
Definition SurfaceMesh.cpp:857
void reindex_vertices_internal(span< const Index > old_to_new)
Reindex mesh vertices according to the given mapping.
Definition SurfaceMesh.cpp:3020
void foreach_corner_around_edge(Index e, function_ref< void(Index)> func) const
Applies a function to each corner around a prescribed edge.
Definition SurfaceMesh.cpp:2928
void rename_attribute(std::string_view old_name, std::string_view new_name)
Rename an existing attribute.
Definition SurfaceMesh.cpp:1032
span< Index > reserve_indices_internal(span< const Index > facet_sizes)
Reserve index buffer for multiple facets of a given size.
Definition SurfaceMesh.cpp:3374
const Attribute< Scalar > & get_vertex_to_position() const
Gets a read-only reference to the vertex -> positions attribute.
Definition SurfaceMesh.cpp:1389
CornerMappingType
Assumptions on the corner mapping received by the internal reindexing method.
Definition SurfaceMesh.h:2537
@ RemovingFacets
Buffer is being compressed, so it is safe to move data without an intermediate buffer.
Definition SurfaceMesh.h:2539
@ ReversingFacets
Facets are being flipped, so it is safe to simply swap rows i and j when i < j.
Definition SurfaceMesh.h:2542
Index get_facet_size(Index f) const
Number of vertices in the facet.
Definition SurfaceMesh.h:735
void remove_facets(function_ref< bool(Index)> should_remove_func)
Removes a list of facets, defined by a predicate function.
Definition SurfaceMesh.cpp:1942
Index m_num_edges
Definition SurfaceMesh.h:2823
void clear_vertices()
Clear buffer for mesh vertices and other vertex attributes.
Definition SurfaceMesh.cpp:2250
AttributeId wrap_as_const_facets(SharedSpan< const Index > shared_facets, Index num_facets, Index vertex_per_facet)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition SurfaceMesh.cpp:920
auto delete_and_export_const_indexed_attribute(std::string_view name, AttributeExportPolicy policy=AttributeExportPolicy::CopyIfExternal) -> std::shared_ptr< const IndexedAttribute< ValueType, Index > >
Delete an indexed attribute and export its content in a read-only shared_ptr.
Definition SurfaceMesh.cpp:1161
AttributeId wrap_as_const_vertices(SharedSpan< const Scalar > shared_vertices, Index num_vertices)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition SurfaceMesh.cpp:845
function_ref< void(span< Index > t)> SetSingleFacetIndicesFunction
Callback function to set indices of a single facet.
Definition SurfaceMesh.h:113
void add_polygons(Index num_facets, Index facet_size, span< const Index > facet_indices={})
Adds multiple polygonal facets of the same size to the mesh.
Definition SurfaceMesh.cpp:1716
::lagrange::internal::weak_ptr< const AttributeBase > _get_attribute_ptr(std::string_view name) const
Gets a read-only weak pointer to the base attribute object.
Definition SurfaceMesh.cpp:1307
static constexpr std::string_view attr_name_next_corner_around_edge()
Attribute name for corner -> next corner around edge.
Definition SurfaceMesh.h:2029
static bool attr_name_is_reserved(std::string_view name)
Check whether the given name corresponds to a reserved attribute.
Definition SurfaceMesh.cpp:1418
SurfaceMesh(BareMeshTag tag)
Internal constructor.
Definition SurfaceMesh.cpp:1428
auto get_indexed_attribute(AttributeId id) const -> const IndexedAttribute< ValueType, Index > &
Gets a read-only reference to an indexed attribute given its id.
Definition SurfaceMesh.cpp:1332
Index get_num_corners() const
Retrieves the number of corners.
Definition SurfaceMesh.h:701
span< const Scalar > get_position(Index v) const
Retrieves a read-only pointer to a vertex coordinates.
Definition SurfaceMesh.cpp:2355
void seq_foreach_attribute_id(function_ref< void(AttributeId)> func) const
Iterates over all attribute ids sequentially.
Definition SurfaceMesh.cpp:1250
A lightweight non-owning reference to a callable.
Definition function_ref.h:47
Definition weak_ptr.h:26
Smart pointer with value semantics.
Definition value_ptr.h:134
AttributeReorientPolicy
Policy for updating attribute values when reorienting mesh facets.
Definition AttributeFwd.h:192
AttributeRefPolicy
Policy for retrieving writable references to attribute buffers.
Definition AttributeFwd.h:202
AttributeCreatePolicy
Policy for attribute creation with reserved attribute names.
Definition AttributeFwd.h:86
uint32_t AttributeId
Identified to be used to access an attribute.
Definition AttributeFwd.h:73
AttributeExportPolicy
Policy for exporting attributes that are views onto external buffers.
Definition AttributeFwd.h:149
AttributeUsage
Usage tag indicating how the attribute should behave under mesh transformations.
Definition AttributeFwd.h:54
AttributeElement
Type of element to which the attribute is attached.
Definition AttributeFwd.h:26
AttributeDeletePolicy
Policy for attribute deletion of reserved attribute names.
Definition AttributeFwd.h:172
constexpr AttributeId invalid_attribute_id()
Invalid attribute id.
Definition AttributeFwd.h:76
@ None
Do not reorient attribute values when flipping mesh facets.
Definition AttributeFwd.h:193
@ Default
Throws an exception if the attribute is the corner -> vertex id attribute and the mesh has edge/conne...
Definition AttributeFwd.h:205
@ ErrorIfReserved
Default deletion policy, throw an exception if attribute name is reserved.
Definition AttributeFwd.h:87
@ CopyIfExternal
Copy the buffer during export if the attribute points to an external buffer.
Definition AttributeFwd.h:150
@ Vector
Mesh attribute can have any number of channels (including 1 channel).
Definition AttributeFwd.h:55
@ ErrorIfReserved
Default deletion policy, throw an exception if attribute name is reserved.
Definition AttributeFwd.h:173
function_ref(R(*)(Args...)) -> function_ref< R(Args...)>
Deduce function_ref type from a function pointer.
::nonstd::span< T, Extent > span
A bounds-safe view for sequences of objects.
Definition span.h:27
nullptr_t, size_t, ptrdiff_t basic_ostream bad_weak_ptr extent, remove_extent, is_array,...
Definition attribute_string_utils.h:21
SurfaceMesh< Scalar, Index > to_surface_mesh(const SurfaceMeshInfo &info)
Reconstruct a SurfaceMesh from a SurfaceMeshInfo.
Definition SurfaceMesh.cpp:3659
SurfaceMeshInfo from_surface_mesh(const SurfaceMesh< Scalar, Index > &mesh)
Extract a SurfaceMeshInfo from a SurfaceMesh.
Definition SurfaceMesh.cpp:3601
Main namespace for Lagrange.
Overload tag.
Definition SurfaceMesh.h:2459
Complete serialized mesh representation using standard types.
Definition SurfaceMeshInfo.h:58