Lagrange
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
28namespace internal {
29template <typename T>
30class weak_ptr;
31}
33
38
64template <typename Scalar_, typename Index_>
66{
67public:
69 using Scalar = Scalar_;
70
72 using Index = Index_;
73
75 using SignedIndex = std::make_signed_t<Index>;
76
77 // Static assertions to prevent users from instantiating unsupported types.
78 static_assert(
79 std::is_same_v<Scalar, float> || std::is_same_v<Scalar, double>,
80 "SurfaceMesh's Scalar template parameter can only be float or double.");
81 static_assert(
82 std::is_same_v<Index, uint32_t> || std::is_same_v<Index, uint64_t>,
83 "SurfaceMesh's Index template parameter can only be uint32_t or uint64_t.");
84
85public:
97
107
119
129
139
140public:
144
150 explicit SurfaceMesh(Index dimension = 3);
151
156
162 SurfaceMesh(SurfaceMesh&& other) noexcept;
163
172
179
188
207 template <typename OtherScalar, typename OtherIndex>
209
228 template <typename OtherScalar, typename OtherIndex>
230
237
243 void add_vertex(std::initializer_list<const Scalar> p);
244
252 void add_vertices(Index num_vertices, span<const Scalar> coordinates = {});
253
261 void add_vertices(Index num_vertices, std::initializer_list<const Scalar> coordinates);
262
269 void add_vertices(Index num_vertices, SetVertexCoordinatesFunction set_vertex_coordinates);
270
278 void add_triangle(Index v0, Index v1, Index v2);
279
293 void add_triangles(Index num_facets, span<const Index> facet_indices = {});
294
308 void add_triangles(Index num_facets, std::initializer_list<const Index> facet_indices);
309
316 void add_triangles(Index num_facets, SetMultiFacetsIndicesFunction set_facets_indices);
317
326 void add_quad(Index v0, Index v1, Index v2, Index v3);
327
341 void add_quads(Index num_facets, span<const Index> facet_indices = {});
342
356 void add_quads(Index num_facets, std::initializer_list<const Index> facet_indices);
357
364 void add_quads(Index num_facets, SetMultiFacetsIndicesFunction set_facets_indices);
365
371 void add_polygon(Index facet_size);
372
378 void add_polygon(span<const Index> facet_indices);
379
385 void add_polygon(std::initializer_list<const Index> facet_indices);
386
393 void add_polygon(Index facet_size, SetSingleFacetIndicesFunction set_facet_indices);
394
410 void add_polygons(Index num_facets, Index facet_size, span<const Index> facet_indices = {});
411
427 void add_polygons(
428 Index num_facets,
429 Index facet_size,
430 std::initializer_list<const Index> facet_indices);
431
439 void add_polygons(
440 Index num_facets,
441 Index facet_size,
442 SetMultiFacetsIndicesFunction set_facets_indices);
443
458 void add_hybrid(span<const Index> facet_sizes, span<const Index> facet_indices = {});
459
474 void add_hybrid(
475 std::initializer_list<const Index> facet_sizes,
476 std::initializer_list<const Index> facet_indices);
477
486 void add_hybrid(
487 Index num_facets,
488 GetFacetsSizeFunction facet_sizes,
489 SetMultiFacetsIndicesFunction set_facets_indices);
490
499 void remove_vertices(span<const Index> vertices_to_remove);
500
509 void remove_vertices(std::initializer_list<const Index> vertices_to_remove);
510
519 void remove_vertices(function_ref<bool(Index)> should_remove_func);
520
530 void remove_facets(span<const Index> facets_to_remove);
531
541 void remove_facets(std::initializer_list<const Index> facets_to_remove);
542
552 void remove_facets(function_ref<bool(Index)> should_remove_func);
553
559 void flip_facets(span<const Index> facets_to_flip);
560
566 void flip_facets(std::initializer_list<const Index> facets_to_flip);
567
574 void flip_facets(function_ref<bool(Index)> should_flip_func);
575
580 void clear_vertices();
581
586 void clear_facets();
587
591 void shrink_to_fit();
592
600 void compress_if_regular();
601
602public:
606
616 [[nodiscard]] bool is_triangle_mesh() const;
617
627 [[nodiscard]] bool is_quad_mesh() const;
628
638 [[nodiscard]] bool is_regular() const;
639
649 [[nodiscard]] bool is_hybrid() const { return !is_regular(); }
650
656 [[nodiscard]] Index get_dimension() const { return m_dimension; }
657
664 [[nodiscard]] Index get_vertex_per_facet() const;
665
671 [[nodiscard]] Index get_num_vertices() const { return m_num_vertices; }
672
678 [[nodiscard]] Index get_num_facets() const { return m_num_facets; }
679
685 [[nodiscard]] Index get_num_corners() const { return m_num_corners; }
686
692 [[nodiscard]] Index get_num_edges() const { return m_num_edges; }
693
701 [[nodiscard]] span<const Scalar> get_position(Index v) const;
702
710 [[nodiscard]] span<Scalar> ref_position(Index v);
711
719 [[nodiscard]] Index get_facet_size(Index f) const
720 {
722 }
723
732 [[nodiscard]] Index get_facet_vertex(Index f, Index lv) const
733 {
735 }
736
744 [[nodiscard]] Index get_facet_corner_begin(Index f) const;
745
753 [[nodiscard]] Index get_facet_corner_end(Index f) const;
754
764 [[nodiscard]] Index get_corner_vertex(Index c) const;
765
775 [[nodiscard]] Index get_corner_facet(Index c) const;
776
784 [[nodiscard]] span<const Index> get_facet_vertices(Index f) const;
785
798 [[nodiscard]] span<Index> ref_facet_vertices(Index f);
799
800public:
804
813 [[nodiscard]] AttributeId get_attribute_id(std::string_view name) const;
814
824 [[nodiscard]] std::string_view get_attribute_name(AttributeId id) const;
825
859 template <typename ValueType>
861 std::string_view name,
862 AttributeElement element,
863 size_t num_channels = 1,
865 span<const ValueType> initial_values = {},
866 span<const Index> initial_indices = {},
868
904 template <typename ValueType>
906 std::string_view name,
907 AttributeElement element,
908 AttributeUsage usage,
909 size_t num_channels = 1,
910 span<const ValueType> initial_values = {},
911 span<const Index> initial_indices = {},
913
932 template <typename OtherScalar, typename OtherIndex>
934 std::string_view name,
935 const SurfaceMesh<OtherScalar, OtherIndex>& source_mesh,
936 std::string_view source_name = {});
937
961 template <typename ValueType>
963 std::string_view name,
964 AttributeElement element,
965 AttributeUsage usage,
966 size_t num_channels,
967 span<ValueType> values_view);
968
976 template <typename ValueType>
978 std::string_view name,
979 AttributeElement element,
980 AttributeUsage usage,
981 size_t num_channels,
982 SharedSpan<ValueType> shared_values);
983
1007 template <typename ValueType>
1009 std::string_view name,
1010 AttributeElement element,
1011 AttributeUsage usage,
1012 size_t num_channels,
1013 span<const ValueType> values_view);
1014
1022 template <typename ValueType>
1024 std::string_view name,
1025 AttributeElement element,
1026 AttributeUsage usage,
1027 size_t num_channels,
1028 SharedSpan<const ValueType> shared_values);
1029
1056 template <typename ValueType>
1058 std::string_view name,
1059 AttributeUsage usage,
1060 size_t num_values,
1061 size_t num_channels,
1062 span<ValueType> values_view,
1063 span<Index> indices_view);
1064
1073 template <typename ValueType>
1075 std::string_view name,
1076 AttributeUsage usage,
1077 size_t num_values,
1078 size_t num_channels,
1079 SharedSpan<ValueType> shared_values,
1080 SharedSpan<Index> shared_indices);
1081
1089 template <typename ValueType>
1091 std::string_view name,
1092 AttributeUsage usage,
1093 size_t num_values,
1094 size_t num_channels,
1095 span<ValueType> values_view,
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 SharedSpan<ValueType> shared_values,
1112 span<Index> indices_view);
1113
1141 template <typename ValueType>
1143 std::string_view name,
1144 AttributeUsage usage,
1145 size_t num_values,
1146 size_t num_channels,
1147 span<const ValueType> values_view,
1148 span<const Index> indices_view);
1149
1158 template <typename ValueType>
1160 std::string_view name,
1161 AttributeUsage usage,
1162 size_t num_values,
1163 size_t num_channels,
1164 SharedSpan<const ValueType> shared_values,
1165 SharedSpan<const Index> shared_indices);
1166
1174 template <typename ValueType>
1176 std::string_view name,
1177 AttributeUsage usage,
1178 size_t num_values,
1179 size_t num_channels,
1180 span<const ValueType> values_view,
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 SharedSpan<const ValueType> shared_values,
1197 span<const Index> indices_view);
1198
1213 AttributeId wrap_as_vertices(span<Scalar> vertices_view, Index num_vertices);
1214
1222 AttributeId wrap_as_vertices(SharedSpan<Scalar> shared_vertices, Index num_vertices);
1223
1239 AttributeId wrap_as_const_vertices(span<const Scalar> vertices_view, Index num_vertices);
1240
1249 SharedSpan<const Scalar> shared_vertices,
1250 Index num_vertices);
1251
1266 AttributeId wrap_as_facets(span<Index> facets_view, Index num_facets, Index vertex_per_facet);
1267
1276 wrap_as_facets(SharedSpan<Index> shared_facets, Index num_facets, Index vertex_per_facet);
1277
1294 wrap_as_const_facets(span<const Index> facets_view, Index num_facets, Index vertex_per_facet);
1295
1304 SharedSpan<const Index> shared_facets,
1305 Index num_facets,
1306 Index vertex_per_facet);
1307
1327 span<Index> offsets_view,
1328 Index num_facets,
1329 span<Index> facets_view,
1330 Index num_corners);
1331
1341 SharedSpan<Index> shared_offsets,
1342 Index num_facets,
1343 SharedSpan<Index> shared_facets,
1344 Index num_corners);
1345
1354 span<Index> offsets_view,
1355 Index num_facets,
1356 SharedSpan<Index> shared_facets,
1357 Index num_corners);
1358
1367 SharedSpan<Index> shared_offsets,
1368 Index num_facets,
1369 span<Index> facets_view,
1370 Index num_corners);
1371
1392 span<const Index> offsets_view,
1393 Index num_facets,
1394 span<const Index> facets_view,
1395 Index num_corners);
1396
1406 SharedSpan<const Index> shared_offsets,
1407 Index num_facets,
1408 SharedSpan<const Index> shared_facets,
1409 Index num_corners);
1410
1419 span<const Index> offsets_view,
1420 Index num_facets,
1421 SharedSpan<const Index> shared_facets,
1422 Index num_corners);
1423
1432 SharedSpan<const Index> shared_offsets,
1433 Index num_facets,
1434 span<const Index> facets_view,
1435 Index num_corners);
1436
1446 AttributeId duplicate_attribute(std::string_view old_name, std::string_view new_name);
1447
1454 void rename_attribute(std::string_view old_name, std::string_view new_name);
1455
1466 void delete_attribute(
1467 std::string_view name,
1469
1487 template <typename ValueType>
1488 std::shared_ptr<Attribute<ValueType>> delete_and_export_attribute(
1489 std::string_view name,
1492
1510 template <typename ValueType>
1511 std::shared_ptr<const Attribute<ValueType>> delete_and_export_const_attribute(
1512 std::string_view name,
1515
1532 template <typename ValueType>
1534 std::string_view name,
1536 -> std::shared_ptr<IndexedAttribute<ValueType, Index>>;
1537
1554 template <typename ValueType>
1556 std::string_view name,
1558 -> std::shared_ptr<const IndexedAttribute<ValueType, Index>>;
1559
1560public:
1564
1579 AttributeId create_metadata(std::string_view name, std::string_view value);
1580
1587 void set_metadata(AttributeId id, std::string_view value);
1588
1596 void set_metadata(std::string_view name, std::string_view value);
1597
1605 std::string_view get_metadata(AttributeId id) const;
1606
1614 std::string_view get_metadata(std::string_view name) const;
1615
1616public:
1620
1631 [[nodiscard]] bool has_attribute(std::string_view name) const;
1632
1642 template <typename ValueType>
1643 [[nodiscard]] bool is_attribute_type(std::string_view name) const;
1644
1654 template <typename ValueType>
1655 [[nodiscard]] bool is_attribute_type(AttributeId id) const;
1656
1663 [[nodiscard]] bool is_attribute_indexed(std::string_view name) const;
1664
1671 [[nodiscard]] bool is_attribute_indexed(AttributeId id) const;
1672
1682 void seq_foreach_attribute_id(function_ref<void(AttributeId)> func) const;
1683
1693 void seq_foreach_attribute_id(function_ref<void(std::string_view, AttributeId)> func) const;
1694
1704 void par_foreach_attribute_id(function_ref<void(AttributeId)> func) const;
1705
1715 void par_foreach_attribute_id(function_ref<void(std::string_view, AttributeId)> func) const;
1716
1724 [[nodiscard]] const AttributeBase& get_attribute_base(std::string_view name) const;
1725
1733 [[nodiscard]] const AttributeBase& get_attribute_base(AttributeId id) const;
1734
1744 template <typename ValueType>
1745 [[nodiscard]] const Attribute<ValueType>& get_attribute(std::string_view name) const;
1746
1756 template <typename ValueType>
1757 [[nodiscard]] const Attribute<ValueType>& get_attribute(AttributeId id) const;
1758
1769 std::string_view name) const;
1770
1781 AttributeId id) const;
1782
1792 template <typename ValueType>
1793 [[nodiscard]] auto get_indexed_attribute(std::string_view name) const
1794 -> const IndexedAttribute<ValueType, Index>&;
1795
1805 template <typename ValueType>
1806 [[nodiscard]] auto get_indexed_attribute(AttributeId id) const
1807 -> const IndexedAttribute<ValueType, Index>&;
1808
1819 template <typename ValueType>
1820 [[nodiscard]] Attribute<ValueType>& ref_attribute(std::string_view name);
1821
1832 template <typename ValueType>
1833 [[nodiscard]] Attribute<ValueType>& ref_attribute(AttributeId id);
1834
1845 std::string_view name);
1846
1857
1868 template <typename ValueType>
1869 [[nodiscard]] auto ref_indexed_attribute(std::string_view name)
1870 -> IndexedAttribute<ValueType, Index>&;
1871
1882 template <typename ValueType>
1883 [[nodiscard]] auto ref_indexed_attribute(AttributeId id) -> IndexedAttribute<ValueType, Index>&;
1884
1890 [[nodiscard]] const Attribute<Scalar>& get_vertex_to_position() const;
1891
1897 [[nodiscard]] Attribute<Scalar>& ref_vertex_to_position();
1898
1904 [[nodiscard]] const Attribute<Index>& get_corner_to_vertex() const;
1905
1916 [[nodiscard]] Attribute<Index>& ref_corner_to_vertex();
1917
1918public:
1922
1931 static bool attr_name_is_reserved(std::string_view name);
1932
1938 static constexpr std::string_view attr_name_vertex_to_position()
1939 {
1940 return s_reserved_names.vertex_to_position();
1941 }
1942
1948 static constexpr std::string_view attr_name_corner_to_vertex()
1949 {
1950 return s_reserved_names.corner_to_vertex();
1951 }
1952
1958 static constexpr std::string_view attr_name_facet_to_first_corner()
1959 {
1960 return s_reserved_names.facet_to_first_corner();
1961 }
1962
1968 static constexpr std::string_view attr_name_corner_to_facet()
1969 {
1970 return s_reserved_names.corner_to_facet();
1971 }
1972
1978 static constexpr std::string_view attr_name_corner_to_edge()
1979 {
1980 return s_reserved_names.corner_to_edge();
1981 }
1982
1988 static constexpr std::string_view attr_name_edge_to_first_corner()
1989 {
1990 return s_reserved_names.edge_to_first_corner();
1991 }
1992
1998 static constexpr std::string_view attr_name_next_corner_around_edge()
1999 {
2000 return s_reserved_names.next_corner_around_edge();
2001 }
2002
2008 static constexpr std::string_view attr_name_vertex_to_first_corner()
2009 {
2010 return s_reserved_names.vertex_to_first_corner();
2011 }
2012
2018 static constexpr std::string_view attr_name_next_corner_around_vertex()
2019 {
2020 return s_reserved_names.next_corner_around_vertex();
2021 }
2022
2028 AttributeId attr_id_vertex_to_position() const { return m_reserved_ids.vertex_to_position(); }
2029
2035 [[deprecated("Use attr_id_vertex_to_position() instead.")]] AttributeId
2037 {
2038 return m_reserved_ids.vertex_to_position();
2039 }
2040
2046 AttributeId attr_id_corner_to_vertex() const { return m_reserved_ids.corner_to_vertex(); }
2047
2054 {
2055 return m_reserved_ids.facet_to_first_corner();
2056 }
2057
2063 AttributeId attr_id_corner_to_facet() const { return m_reserved_ids.corner_to_facet(); }
2064
2070 AttributeId attr_id_corner_to_edge() const { return m_reserved_ids.corner_to_edge(); }
2071
2078 {
2079 return m_reserved_ids.edge_to_first_corner();
2080 }
2081
2088 {
2089 return m_reserved_ids.next_corner_around_edge();
2090 }
2091
2098 {
2099 return m_reserved_ids.vertex_to_first_corner();
2100 }
2101
2108 {
2109 return m_reserved_ids.next_corner_around_vertex();
2110 }
2111
2112public:
2116
2125 void initialize_edges(span<const Index> edges = {});
2126
2138 void initialize_edges(Index num_user_edges, GetEdgeVertices get_user_edge);
2139
2152 void clear_edges();
2153
2159 bool has_edges() const
2160 {
2161 return m_reserved_ids.edge_to_first_corner() != invalid_attribute_id();
2162 }
2163
2172 Index get_edge(Index f, Index lv) const;
2173
2183 Index get_corner_edge(Index c) const;
2184
2190 [[deprecated("Use get_corner_edge() instead.")]] Index get_edge_from_corner(Index c) const;
2191
2199 std::array<Index, 2> get_edge_vertices(Index e) const;
2200
2208 Index find_edge_from_vertices(Index v0, Index v1) const;
2209
2219 Index get_next_corner_around_facet(Index c) const;
2220
2228 Index get_first_corner_around_edge(Index e) const;
2229
2238 Index get_next_corner_around_edge(Index c) const;
2239
2247 Index get_first_corner_around_vertex(Index v) const;
2248
2261 Index get_next_corner_around_vertex(Index c) const;
2262
2274 Index count_num_corners_around_edge(Index e) const;
2275
2287 Index count_num_corners_around_vertex(Index v) const;
2288
2304 Index get_counterclockwise_corner_around_vertex(Index c) const;
2305
2320 Index get_clockwise_corner_around_vertex(Index c) const;
2321
2329 Index get_one_facet_around_edge(Index e) const;
2330
2342 Index get_one_corner_around_edge(Index e) const;
2343
2355 Index get_one_corner_around_vertex(Index v) const;
2356
2364 bool is_boundary_edge(Index e) const;
2365
2375 void foreach_facet_around_edge(Index e, function_ref<void(Index)> func) const;
2376
2383 void foreach_facet_around_facet(Index f, function_ref<void(Index)> func) const;
2384
2394 void foreach_facet_around_vertex(Index v, function_ref<void(Index)> func) const;
2395
2402 void foreach_corner_around_edge(Index e, function_ref<void(Index)> func) const;
2403
2410 void foreach_corner_around_vertex(Index v, function_ref<void(Index)> func) const;
2411
2419 void foreach_edge_around_vertex_with_duplicates(Index v, function_ref<void(Index)> func) const;
2420
2422
2423protected:
2428 {
2429 };
2430
2436 explicit SurfaceMesh(BareMeshTag tag);
2437
2462 template <typename ValueType>
2464 std::string_view name,
2465 AttributeElement element,
2467 size_t num_channels = 1,
2468 span<const ValueType> initial_values = {},
2469 span<const Index> initial_indices = {});
2470
2478 template <typename ValueType>
2479 void set_attribute_default_internal(std::string_view name);
2480
2489 void reindex_vertices_internal(span<const Index> old_to_new);
2490
2501 std::pair<Index, Index> reindex_facets_internal(span<const Index> old_to_new);
2502
2508 RemovingFacets,
2509
2511 ReversingFacets,
2512 };
2513
2522 function_ref<Index(Index)> old_to_new_corners,
2523 CornerMappingType mapping_type);
2524
2533 template <AttributeElement element>
2534 void resize_elements_internal(Index num_elements);
2535
2542 void resize_vertices_internal(Index num_vertices);
2543
2550 void resize_facets_internal(Index num_facets);
2551
2558 void resize_corners_internal(Index num_corners);
2559
2566 void resize_edges_internal(Index num_edges);
2567
2578 span<Index> reserve_indices_internal(Index num_facets, Index facet_size);
2579
2590
2602 span<Index> reserve_indices_internal(Index num_facets, GetFacetsSizeFunction get_facets_size);
2603
2610 void compute_corner_to_facet_internal(Index facet_begin, Index facet_end);
2611
2621 Index num_user_edges = 0,
2622 GetEdgeVertices* get_user_edge_ptr = nullptr);
2623
2645 Index facet_begin,
2646 Index facet_end,
2647 Index num_user_edges = 0,
2648 GetEdgeVertices* get_user_edge_ptr = nullptr);
2649
2660 Index count,
2661 Index num_user_edges = 0,
2662 GetEdgeVertices* get_user_edge_ptr = nullptr);
2663
2672 [[nodiscard]] size_t get_num_elements_internal(AttributeElement element) const;
2673
2684 template <typename ValueType>
2686 Attribute<std::decay_t<ValueType>>& attr,
2687 size_t num_values,
2688 span<ValueType> values_view);
2689
2703 template <typename ValueType>
2705 Attribute<std::decay_t<ValueType>>& attr,
2706 size_t num_values,
2707 SharedSpan<ValueType> shared_values);
2708
2722 template <typename OffsetSpan, typename FacetSpan>
2724 OffsetSpan offsets,
2725 Index num_facets,
2726 FacetSpan facets,
2727 Index num_corners);
2728
2751 template <typename ValueSpan, typename IndexSpan = span<Index>>
2753 std::string_view name,
2754 AttributeElement element,
2755 AttributeUsage usage,
2756 size_t num_values,
2757 size_t num_channels,
2758 ValueSpan values,
2759 IndexSpan indices = {});
2760
2761protected:
2763
2765 template <typename, typename>
2766 friend class SurfaceMesh;
2767
2771 struct AttributeManager;
2772
2774
2775protected:
2778
2781
2784
2787
2790
2793
2796
2799 {
2800 AttributeId items[9];
2801
2802 ReservedAttributeIds() { std::fill_n(items, 9, invalid_attribute_id()); }
2803 static constexpr int size() { return 9; }
2804
2805 AttributeId& vertex_to_position() { return items[0]; };
2806 AttributeId& corner_to_vertex() { return items[1]; };
2807 AttributeId& facet_to_first_corner() { return items[2]; };
2808 AttributeId& corner_to_facet() { return items[3]; };
2809 AttributeId& corner_to_edge() { return items[4]; };
2810 AttributeId& edge_to_first_corner() { return items[5]; };
2811 AttributeId& next_corner_around_edge() { return items[6]; };
2812 AttributeId& vertex_to_first_corner() { return items[7]; };
2813 AttributeId& next_corner_around_vertex() { return items[8]; };
2814
2815 const AttributeId& vertex_to_position() const { return items[0]; };
2816 const AttributeId& corner_to_vertex() const { return items[1]; };
2817 const AttributeId& facet_to_first_corner() const { return items[2]; };
2818 const AttributeId& corner_to_facet() const { return items[3]; };
2819 const AttributeId& corner_to_edge() const { return items[4]; };
2820 const AttributeId& edge_to_first_corner() const { return items[5]; };
2821 const AttributeId& next_corner_around_edge() const { return items[6]; };
2822 const AttributeId& vertex_to_first_corner() const { return items[7]; };
2823 const AttributeId& next_corner_around_vertex() const { return items[8]; };
2824 } m_reserved_ids;
2825
2826protected:
2828 static constexpr struct
2829 {
2830 std::string_view items[9] = {
2831 "$vertex_to_position",
2832 "$corner_to_vertex",
2833 "$facet_to_first_corner",
2834 "$corner_to_facet",
2835 "$corner_to_edge",
2836 "$edge_to_first_corner",
2837 "$next_corner_around_edge",
2838 "$vertex_to_first_corner",
2839 "$next_corner_around_vertex",
2840 };
2841 std::string_view vertex_to_position() const { return items[0]; }
2842 std::string_view corner_to_vertex() const { return items[1]; }
2843 std::string_view facet_to_first_corner() const { return items[2]; }
2844 std::string_view corner_to_facet() const { return items[3]; }
2845 std::string_view corner_to_edge() const { return items[4]; }
2846 std::string_view edge_to_first_corner() const { return items[5]; }
2847 std::string_view next_corner_around_edge() const { return items[6]; }
2848 std::string_view vertex_to_first_corner() const { return items[7]; }
2849 std::string_view next_corner_around_vertex() const { return items[8]; }
2851};
2852
2853using SurfaceMesh32f = SurfaceMesh<float, uint32_t>;
2854using SurfaceMesh32d = SurfaceMesh<double, uint32_t>;
2855using SurfaceMesh64f = SurfaceMesh<float, uint64_t>;
2856using SurfaceMesh64d = SurfaceMesh<double, uint64_t>;
2857
2859
2860} // namespace lagrange
Derived attribute class that stores the actual information.
Definition: Attribute.h:153
Shared span with ownership tracking.
Definition: SharedSpan.h:36
A general purpose polygonal mesh class.
Definition: SurfaceMesh.h:66
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:138
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:1748
Index find_edge_from_vertices(Index v0, Index v1) const
Retrieve the edge index corresponding to (v0, v1).
Definition: SurfaceMesh.cpp:2481
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:2713
span< Index > reserve_indices_internal(Index num_facets, Index facet_size)
Reserve index buffer for multiple facets of a given size.
Definition: SurfaceMesh.cpp:3126
AttributeId attr_id_vertex_to_position() const
Attribute id for vertex -> positions.
Definition: SurfaceMesh.h:2028
void add_quads(Index num_facets, span< const Index > facet_indices={})
Adds multiple quadrilateral facets to the mesh.
Definition: SurfaceMesh.cpp:1679
Index get_next_corner_around_facet(Index c) const
Gets the next corner around the facet associated to a corner.
Definition: SurfaceMesh.cpp:2471
static constexpr std::string_view attr_name_facet_to_first_corner()
Attribute name for facet -> first corner index.
Definition: SurfaceMesh.h:1958
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:2664
void par_foreach_attribute_id(function_ref< void(AttributeId)> func) const
Iterates over all attribute ids in parallel.
Definition: SurfaceMesh.cpp:1250
bool is_quad_mesh() const
Whether the mesh must only contains quadrilateral facets.
Definition: SurfaceMesh.cpp:2098
std::string_view get_attribute_name(AttributeId id) const
Retrieve attribute name from its id.
Definition: SurfaceMesh.cpp:351
bool is_boundary_edge(Index e) const
Determines whether the specified edge e is a boundary edge.
Definition: SurfaceMesh.cpp:2615
Index get_facet_corner_end(Index f) const
Index past the last corner around the facet.
Definition: SurfaceMesh.cpp:2151
Attribute< Scalar > & ref_vertex_to_position()
Gets a writable reference to the vertex -> positions attribute.
Definition: SurfaceMesh.cpp:1381
void clear_edges()
Clears attributes related to mesh edges and connectivity:
Definition: SurfaceMesh.cpp:2424
function_ref< void(Index f, span< Index > t)> SetMultiFacetsIndicesFunction
Callback function to set indices of a multiple facets.
Definition: SurfaceMesh.h:118
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:2285
static constexpr std::string_view attr_name_next_corner_around_vertex()
Attribute name for corner -> next corner around vertex.
Definition: SurfaceMesh.h:2018
static constexpr std::string_view attr_name_vertex_to_position()
Attribute name for vertex -> position.
Definition: SurfaceMesh.h:1938
function_ref< Index(Index f)> GetFacetsSizeFunction
Callback function to get a facet size (number of vertices in the facet).
Definition: SurfaceMesh.h:128
static constexpr std::string_view attr_name_corner_to_vertex()
Attribute name for corner -> vertex indices.
Definition: SurfaceMesh.h:1948
AttributeId attr_id_corner_to_edge() const
Attribute id for corner -> edge indices.
Definition: SurfaceMesh.h:2070
static SurfaceMesh stripped_copy(const SurfaceMesh< OtherScalar, OtherIndex > &other)
Copy constructor stripping away non-reserved attributes.
void set_attribute_default_internal(std::string_view name)
Set attribute default value for known internal attributes.
Definition: SurfaceMesh.cpp:372
const Attribute< ValueType > & get_attribute(std::string_view name) const
Gets a read-only reference to an attribute given its name.
Definition: SurfaceMesh.cpp:1278
Index m_num_facets
Number of facets.
Definition: SurfaceMesh.h:2780
void delete_attribute(std::string_view name, AttributeDeletePolicy policy=AttributeDeletePolicy::ErrorIfReserved)
Delete an attribute given by name.
Definition: SurfaceMesh.cpp:1036
Index count_num_corners_around_edge(Index e) const
Count the number of corners incident to a given edge.
Definition: SurfaceMesh.cpp:2586
Index get_num_vertices() const
Retrieves the number of vertices.
Definition: SurfaceMesh.h:671
void resize_facets_internal(Index num_facets)
Resize the buffers associated to mesh facets and their attributes.
Definition: SurfaceMesh.cpp:3105
Attribute< ValueType > & ref_attribute(std::string_view name)
Gets a writable reference to an attribute given its name.
Definition: SurfaceMesh.cpp:1328
Index get_corner_edge(Index c) const
Gets the edge index corresponding to a corner index.
Definition: SurfaceMesh.cpp:2443
AttributeId attr_id_facet_to_first_corner() const
Attribute id for facet -> first corner index.
Definition: SurfaceMesh.h:2053
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:1101
std::array< Index, 2 > get_edge_vertices(Index e) const
Retrieve edge endpoints.
Definition: SurfaceMesh.cpp:2457
Index get_dimension() const
Retrieves the dimension of the mesh vertices.
Definition: SurfaceMesh.h:656
Index get_edge(Index f, Index lv) const
Gets the edge index corresponding to (f, lv) – (f, lv+1).
Definition: SurfaceMesh.cpp:2435
Index m_vertex_per_facet
Number of vertices per facet. Either constant (> 0) or variable (= 0).
Definition: SurfaceMesh.h:2792
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:2563
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:401
static constexpr std::string_view attr_name_corner_to_facet()
Attribute name for corner -> facet index.
Definition: SurfaceMesh.h:1968
AttributeId attr_id_corner_to_vertex() const
Attribute id for corner -> vertex indices.
Definition: SurfaceMesh.h:2046
bool is_attribute_type(std::string_view name) const
Checks whether the specified attribute is of a given type.
Definition: SurfaceMesh.cpp:1209
Index m_num_vertices
Number of vertices.
Definition: SurfaceMesh.h:2777
AttributeId get_attribute_id(std::string_view name) const
Retrieve an attribute id given its name.
Definition: SurfaceMesh.cpp:341
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:2926
void add_vertices(Index num_vertices, span< const Scalar > coordinates={})
Adds multiple vertices to the mesh.
Definition: SurfaceMesh.cpp:1566
std::make_signed_t< Index > SignedIndex
Signed index type corresponding to the mesh index type.
Definition: SurfaceMesh.h:75
Index get_next_corner_around_edge(Index c) const
Gets the next corner around the edge associated to a corner.
Definition: SurfaceMesh.cpp:2514
Index get_edge_from_corner(Index c) const
Gets the edge index corresponding to a corner index.
Definition: SurfaceMesh.cpp:2451
span< Index > ref_facet_vertices(Index f)
Retrieves a writable pointer to a facet indices.
Definition: SurfaceMesh.cpp:2188
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:2641
void remove_vertices(span< const Index > vertices_to_remove)
Removes a list of vertices.
Definition: SurfaceMesh.cpp:1795
void remove_facets(span< const Index > facets_to_remove)
Removes a list of facets.
Definition: SurfaceMesh.cpp:1886
void resize_vertices_internal(Index num_vertices)
Resize the buffers associated to mesh vertices and their attributes.
Definition: SurfaceMesh.cpp:3098
bool has_attribute(std::string_view name) const
Checks if an attribute of a given name is attached to the mesh.
Definition: SurfaceMesh.cpp:1202
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:719
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:1117
std::string_view get_metadata(AttributeId id) const
Read metadata attribute value.
Definition: SurfaceMesh.cpp:1188
AttributeId create_metadata(std::string_view name, std::string_view value)
Create a metadata attribute.
Definition: SurfaceMesh.cpp:1161
Index count_num_corners_around_vertex(Index v) const
Count the number of corners incident to a given vertex.
Definition: SurfaceMesh.cpp:2532
value_ptr< AttributeManager > m_attributes
Attribute manager. Hidden implementation.
Definition: SurfaceMesh.h:2795
void add_quad(Index v0, Index v1, Index v2, Index v3)
Adds a quadrilateral facet to the mesh.
Definition: SurfaceMesh.cpp:1610
void add_polygon(Index facet_size)
Adds a single (uninitialized) polygonal facet to the mesh.
Definition: SurfaceMesh.cpp:1619
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:3279
void shrink_to_fit()
Shrink buffer capacities to fit current mesh attributes, deallocating any extra capacity.
Definition: SurfaceMesh.cpp:2045
AttributeId attr_id_vertex_to_positions() const
Attribute id for vertex -> positions.
Definition: SurfaceMesh.h:2036
void clear_facets()
Clear buffer for mesh facets and other facet/corner attributes.
Definition: SurfaceMesh.cpp:2032
Index get_one_corner_around_vertex(Index v) const
Get the index of one corner around a given vertex.
Definition: SurfaceMesh.cpp:2609
SurfaceMesh & operator=(const SurfaceMesh &other)
Assignment copy operator.
Index get_facet_corner_begin(Index f) const
First corner around the facet.
Definition: SurfaceMesh.cpp:2139
void add_vertex(span< const Scalar > p)
Adds a vertex to the mesh.
Definition: SurfaceMesh.cpp:1546
SurfaceMesh(Index dimension=3)
Default constructor.
Definition: SurfaceMesh.cpp:1418
size_t get_num_elements_internal(AttributeElement element) const
Gets the number of mesh elements, based on an element type.
Definition: SurfaceMesh.cpp:357
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:527
AttributeId attr_id_vertex_to_first_corner() const
Attribute id for vertex -> first corner index.
Definition: SurfaceMesh.h:2097
Scalar_ Scalar
Mesh scalar type, used for vertex coordinates.
Definition: SurfaceMesh.h:69
::lagrange::internal::weak_ptr< AttributeBase > _ref_attribute_ptr(std::string_view name)
Gets a weak pointer to the base attribute object.
Definition: SurfaceMesh.cpp:1343
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:1264
void resize_corners_internal(Index num_corners)
Resize the buffers associated to mesh corners and their attributes.
Definition: SurfaceMesh.cpp:3112
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:2623
void add_triangle(Index v0, Index v1, Index v2)
Adds a triangular facet to the mesh.
Definition: SurfaceMesh.cpp:1601
Index_ Index
Mesh index type, used for facet indices.
Definition: SurfaceMesh.h:72
Index get_one_facet_around_edge(Index e) const
Get the index of one facet around a given edge.
Definition: SurfaceMesh.cpp:2595
Index get_first_corner_around_edge(Index e) const
Get the index of the first corner around a given edge.
Definition: SurfaceMesh.cpp:2508
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:3236
void add_triangles(Index num_facets, span< const Index > facet_indices={})
Adds multiple triangular facets to the mesh.
Definition: SurfaceMesh.cpp:1657
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:2229
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:1310
~SurfaceMesh()
Default destructor.
void resize_elements_internal(Index num_elements)
Resize the buffers associated to a specific element type in the mesh.
Definition: SurfaceMesh.cpp:3083
void set_metadata(AttributeId id, std::string_view value)
Write metadata attribute value.
Definition: SurfaceMesh.cpp:1172
bool is_regular() const
Whether the mesh must only contains facets of equal sizes.
Definition: SurfaceMesh.cpp:2104
AttributeId attr_id_next_corner_around_edge() const
Attribute id for corner -> next corner around edge.
Definition: SurfaceMesh.h:2087
Index get_first_corner_around_vertex(Index v) const
Get the index of the first corner around a given vertex.
Definition: SurfaceMesh.cpp:2520
Index m_num_corners
Number of corners.
Definition: SurfaceMesh.h:2783
bool is_attribute_indexed(std::string_view name) const
Determines whether the specified attribute is indexed.
Definition: SurfaceMesh.cpp:1223
const Attribute< Index > & get_corner_to_vertex() const
Gets a read-only reference to the corner -> vertex id attribute.
Definition: SurfaceMesh.cpp:1387
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:2274
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:826
Index get_next_corner_around_vertex(Index c) const
Gets the next corner around the vertex associated to a corner.
Definition: SurfaceMesh.cpp:2526
Index get_facet_vertex(Index f, Index lv) const
Index of a vertex given from a facet + local index.
Definition: SurfaceMesh.h:732
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:892
void compress_if_regular()
Compress mesh storage if the mesh is regular.
Definition: SurfaceMesh.cpp:2059
bool is_triangle_mesh() const
Whether the mesh must only contain triangular facets.
Definition: SurfaceMesh.cpp:2092
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:3265
Index get_corner_vertex(Index c) const
Retrieves the index of a vertex given its corner index.
Definition: SurfaceMesh.cpp:2165
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:2686
void resize_edges_internal(Index num_edges)
Resize the buffers associated to mesh edges and their attributes.
Definition: SurfaceMesh.cpp:3119
void flip_facets(span< const Index > facets_to_flip)
Reverses the orientation of a list of facets.
Definition: SurfaceMesh.cpp:1960
Index get_corner_facet(Index c) const
Retrieves the index of a facet given its corner index.
Definition: SurfaceMesh.cpp:2171
bool has_edges() const
Determines if the attributes associated to mesh edges and connectivity have been initialized.
Definition: SurfaceMesh.h:2159
SurfaceMesh(SurfaceMesh &&other) noexcept
Move constructor.
std::pair< Index, Index > reindex_facets_internal(span< const Index > old_to_new)
Reindex mesh facets according to the given mapping.
Definition: SurfaceMesh.cpp:2817
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:1132
span< const Index > get_facet_vertices(Index f) const
Retrieves a read-only pointer to a facet indices.
Definition: SurfaceMesh.cpp:2182
static constexpr std::string_view attr_name_edge_to_first_corner()
Attribute name for edge -> first corner index.
Definition: SurfaceMesh.h:1988
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:1358
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:591
bool is_hybrid() const
Whether the mesh may contain facets of different sizes.
Definition: SurfaceMesh.h:649
Index get_num_edges() const
Retrieves the number of edges.
Definition: SurfaceMesh.h:692
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:447
AttributeId wrap_as_vertices(span< Scalar > vertices_view, Index num_vertices)
Wraps a writable external buffer as mesh vertices coordinates.
Definition: SurfaceMesh.cpp:802
Index get_one_corner_around_edge(Index e) const
Get the index of one corner around a given edge.
Definition: SurfaceMesh.cpp:2603
Index get_num_facets() const
Retrieves the number of facets.
Definition: SurfaceMesh.h:678
Index get_vertex_per_facet() const
Retrieves the number of vertex per facet in a regular mesh.
Definition: SurfaceMesh.cpp:2118
SurfaceMesh(const SurfaceMesh &other)
Copy constructor.
span< Scalar > ref_position(Index v)
Retrieves a writeable pointer to a vertex coordinates.
Definition: SurfaceMesh.cpp:2133
AttributeId attr_id_edge_to_first_corner() const
Attribute id for edge -> first corner index.
Definition: SurfaceMesh.h:2077
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:635
AttributeId duplicate_attribute(std::string_view old_name, std::string_view new_name)
Duplicates an attribute.
Definition: SurfaceMesh.cpp:1014
static constexpr std::string_view attr_name_vertex_to_first_corner()
Attribute name for vertex -> first corner index.
Definition: SurfaceMesh.h:2008
static constexpr struct lagrange::SurfaceMesh::@0 s_reserved_names
Reserved attribute names.
AttributeId attr_id_next_corner_around_vertex() const
Attribute id for corner -> next corner around vertex.
Definition: SurfaceMesh.h:2107
Index m_dimension
Vertex dimension.
Definition: SurfaceMesh.h:2789
void initialize_edges(span< const Index > edges={})
Initializes attributes associated to mesh edges and connectivity.
Definition: SurfaceMesh.cpp:2198
function_ref< void(Index v, span< Scalar > p)> SetVertexCoordinatesFunction
Callback function to set vertex coordinates.
Definition: SurfaceMesh.h:96
static constexpr std::string_view attr_name_corner_to_edge()
Attribute name for corner -> edge indices.
Definition: SurfaceMesh.h:1978
Attribute< Index > & ref_corner_to_vertex()
Gets a writable reference to the corner -> vertex id attribute.
Definition: SurfaceMesh.cpp:1393
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:547
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:2541
AttributeId attr_id_corner_to_facet() const
Attribute id for corner -> facet index.
Definition: SurfaceMesh.h:2063
static SurfaceMesh stripped_move(SurfaceMesh< OtherScalar, OtherIndex > &&other)
Move constructor stripping away non-reserved attributes.
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:850
void reindex_vertices_internal(span< const Index > old_to_new)
Reindex mesh vertices according to the given mapping.
Definition: SurfaceMesh.cpp:2792
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:2700
void rename_attribute(std::string_view old_name, std::string_view new_name)
Rename an existing attribute.
Definition: SurfaceMesh.cpp:1025
const Attribute< Scalar > & get_vertex_to_position() const
Gets a read-only reference to the vertex -> positions attribute.
Definition: SurfaceMesh.cpp:1375
CornerMappingType
Assumptions on the corner mapping received by the internal reindexing method.
Definition: SurfaceMesh.h:2506
Index get_facet_size(Index f) const
Number of vertices in the facet.
Definition: SurfaceMesh.h:719
Index m_num_edges
Number of edges.
Definition: SurfaceMesh.h:2786
void clear_vertices()
Clear buffer for mesh vertices and other vertex attributes.
Definition: SurfaceMesh.cpp:2022
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:1147
function_ref< void(span< Index > t)> SetSingleFacetIndicesFunction
Callback function to set indices of a single facet.
Definition: SurfaceMesh.h:106
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:1701
::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:1293
static constexpr std::string_view attr_name_next_corner_around_edge()
Attribute name for corner -> next corner around edge.
Definition: SurfaceMesh.h:1998
static bool attr_name_is_reserved(std::string_view name)
Check whether the given name corresponds to a reserved attribute.
Definition: SurfaceMesh.cpp:1403
Index get_num_corners() const
Retrieves the number of corners.
Definition: SurfaceMesh.h:685
span< const Scalar > get_position(Index v) const
Retrieves a read-only pointer to a vertex coordinates.
Definition: SurfaceMesh.cpp:2127
void seq_foreach_attribute_id(function_ref< void(AttributeId)> func) const
Iterates over all attribute ids sequentially.
Definition: SurfaceMesh.cpp:1236
A lightweight non-owning reference to a callable.
Definition: function_ref.h:47
Definition: weak_ptr.h:26
uint32_t AttributeId
Identified to be used to access an attribute.
Definition: AttributeFwd.h:73
AttributeUsage
Usage tag indicating how the attribute should behave under mesh transformations.
Definition: AttributeFwd.h:54
AttributeCreatePolicy
Policy for attribute creation with reserved attribute names.
Definition: AttributeFwd.h:86
AttributeElement
Type of element to which the attribute is attached.
Definition: AttributeFwd.h:26
constexpr AttributeId invalid_attribute_id()
Invalid attribute id.
Definition: AttributeFwd.h:76
AttributeDeletePolicy
Policy for attribute deletion of reserved attribute names.
Definition: AttributeFwd.h:157
AttributeExportPolicy
Policy for exporting attributes that are views onto external buffers.
Definition: AttributeFwd.h:134
@ Vector
Mesh attribute can have any number of channels (including 1 channel).
@ ErrorIfReserved
Default deletion policy, throw an exception if attribute name is reserved.
@ ErrorIfReserved
Default deletion policy, throw an exception if attribute name is reserved.
@ CopyIfExternal
Copy the buffer during export if the attribute points to an external buffer.
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
Main namespace for Lagrange.
Definition: AABBIGL.h:30
Overload tag.
Definition: SurfaceMesh.h:2428
Reserved attribute ids.
Definition: SurfaceMesh.h:2799