14#include <lagrange/AttributeTypes.h>
15#include <lagrange/NormalWeightingType.h>
16#include <lagrange/cast_attribute.h>
17#include <lagrange/combine_meshes.h>
18#include <lagrange/compute_area.h>
19#include <lagrange/compute_centroid.h>
20#include <lagrange/compute_components.h>
21#include <lagrange/compute_dihedral_angles.h>
22#include <lagrange/compute_dijkstra_distance.h>
23#include <lagrange/compute_edge_lengths.h>
24#include <lagrange/compute_facet_circumcenter.h>
25#include <lagrange/compute_facet_normal.h>
26#include <lagrange/compute_greedy_coloring.h>
27#include <lagrange/compute_mesh_covariance.h>
28#include <lagrange/compute_normal.h>
29#include <lagrange/compute_pointcloud_pca.h>
30#include <lagrange/compute_seam_edges.h>
31#include <lagrange/compute_tangent_bitangent.h>
32#include <lagrange/compute_uv_charts.h>
33#include <lagrange/compute_uv_distortion.h>
34#include <lagrange/compute_vertex_normal.h>
35#include <lagrange/compute_vertex_valence.h>
36#include <lagrange/extract_submesh.h>
37#include <lagrange/filter_attributes.h>
38#include <lagrange/internal/constants.h>
39#include <lagrange/isoline.h>
40#include <lagrange/map_attribute.h>
41#include <lagrange/normalize_meshes.h>
42#include <lagrange/orient_outward.h>
43#include <lagrange/orientation.h>
44#include <lagrange/permute_facets.h>
45#include <lagrange/permute_vertices.h>
46#include <lagrange/python/binding.h>
47#include <lagrange/python/tensor_utils.h>
48#include <lagrange/python/utils/StackVector.h>
49#include <lagrange/remap_vertices.h>
50#include <lagrange/reorder_mesh.h>
51#include <lagrange/select_facets_by_normal_similarity.h>
52#include <lagrange/select_facets_in_frustum.h>
53#include <lagrange/separate_by_components.h>
54#include <lagrange/separate_by_facet_groups.h>
55#include <lagrange/split_facets_by_material.h>
56#include <lagrange/thicken_and_close_mesh.h>
57#include <lagrange/topology.h>
58#include <lagrange/transform_mesh.h>
59#include <lagrange/triangulate_polygonal_facets.h>
60#include <lagrange/unify_index_buffer.h>
61#include <lagrange/utils/invalid.h>
62#include <lagrange/uv_mesh.h>
63#include <lagrange/weld_indexed_attribute.h>
69namespace lagrange::python {
71template <
typename Scalar,
typename Index>
72void bind_utilities(nanobind::module_& m)
74 namespace nb = nanobind;
75 using namespace nb::literals;
76 using MeshType = SurfaceMesh<Scalar, Index>;
78 nb::enum_<NormalWeightingType>(m,
"NormalWeightingType",
"Normal weighting type.")
83 "Weight by corner triangle area")
86 nb::class_<VertexNormalOptions>(
88 "VertexNormalOptions",
89 "Options for computing vertex normals")
92 "output_attribute_name",
94 "Output attribute name. Default is `@vertex_normal`.")
98 "Weighting type for normal computation. Default is Angle.")
100 "weighted_corner_normal_attribute_name",
102 R
"(Precomputed weighted corner normals attribute name (default: @weighted_corner_normal).
104If attribute exists, the precomputed weighted corner normal will be used.)")
106 "recompute_weighted_corner_normals",
108 "Whether to recompute weighted corner normals (default: false).")
110 "keep_weighted_corner_normals",
112 "Whether to keep the weighted corner normal attribute (default: false).")
114 "distance_tolerance",
116 "Distance tolerance for degenerate edge check in polygon facets.");
119 "compute_vertex_normal",
122 "options"_a = VertexNormalOptions(),
123 R
"(Compute vertex normal.
125:param mesh: Input mesh.
126:param options: Options for computing vertex normals.
128:returns: Vertex normal attribute id.)");
131 "compute_vertex_normal",
133 std::optional<std::string_view> output_attribute_name,
134 std::optional<NormalWeightingType> weight_type,
135 std::optional<std::string_view> weighted_corner_normal_attribute_name,
136 std::optional<bool> recompute_weighted_corner_normals,
137 std::optional<bool> keep_weighted_corner_normals,
138 std::optional<float> distance_tolerance) {
139 VertexNormalOptions options;
140 if (output_attribute_name) options.output_attribute_name = *output_attribute_name;
141 if (weight_type) options.weight_type = *weight_type;
142 if (weighted_corner_normal_attribute_name)
143 options.weighted_corner_normal_attribute_name =
144 *weighted_corner_normal_attribute_name;
145 if (recompute_weighted_corner_normals)
146 options.recompute_weighted_corner_normals = *recompute_weighted_corner_normals;
147 if (keep_weighted_corner_normals)
148 options.keep_weighted_corner_normals = *keep_weighted_corner_normals;
149 if (distance_tolerance) options.distance_tolerance = *distance_tolerance;
154 "output_attribute_name"_a = nb::none(),
155 "weight_type"_a = nb::none(),
156 "weighted_corner_normal_attribute_name"_a = nb::none(),
157 "recompute_weighted_corner_normals"_a = nb::none(),
158 "keep_weighted_corner_normals"_a = nb::none(),
159 "distance_tolerance"_a = nb::none(),
160 R
"(Compute vertex normal (Pythonic API).
162:param mesh: Input mesh.
163:param output_attribute_name: Output attribute name.
164:param weight_type: Weighting type for normal computation.
165:param weighted_corner_normal_attribute_name: Precomputed weighted corner normals attribute name.
166:param recompute_weighted_corner_normals: Whether to recompute weighted corner normals.
167:param keep_weighted_corner_normals: Whether to keep the weighted corner normal attribute.
168:param distance_tolerance: Distance tolerance for degenerate edge check.
169 (Only used to bypass degenerate edge in polygon facets.)
171:returns: Vertex normal attribute id.)");
173 nb::class_<FacetNormalOptions>(m, "FacetNormalOptions",
"Facet normal computation options.")
176 "output_attribute_name",
178 "Output attribute name. Default: `@facet_normal`");
181 "compute_facet_normal",
184 "options"_a = FacetNormalOptions(),
185 R
"(Compute facet normal.
187:param mesh: Input mesh.
188:param options: Options for computing facet normals.
190:returns: Facet normal attribute id.)");
193 "compute_facet_normal",
194 [](MeshType& mesh, std::optional<std::string_view> output_attribute_name) {
195 FacetNormalOptions options;
196 if (output_attribute_name) options.output_attribute_name = *output_attribute_name;
200 "output_attribute_name"_a = nb::none(),
201 R
"(Compute facet normal (Pythonic API).
203:param mesh: Input mesh.
204:param output_attribute_name: Output attribute name.
206:returns: Facet normal attribute id.)");
208 nb::class_<NormalOptions>(m, "NormalOptions",
"Normal computation options.")
211 "output_attribute_name",
213 "Output attribute name. Default: `@normal`")
217 "Weighting type for normal computation. Default is Angle.")
219 "facet_normal_attribute_name",
221 "Facet normal attribute name to use. Default is `@facet_normal`.")
223 "recompute_facet_normals",
225 "Whether to recompute facet normals. Default is false.")
227 "keep_facet_normals",
229 "Whether to keep the computed facet normal attribute. Default is false.")
231 "distance_tolerance",
233 "Distance tolerance for degenerate edge check. (Only used to bypass degenerate edge in "
239 Scalar feature_angle_threshold,
240 nb::object cone_vertices,
241 std::optional<NormalOptions> normal_options) {
242 NormalOptions options;
243 if (normal_options.has_value()) {
244 options = std::move(normal_options.value());
247 if (cone_vertices.is_none()) {
249 }
else if (nb::isinstance<nb::list>(cone_vertices)) {
250 auto cone_vertices_list = nb::cast<std::vector<Index>>(cone_vertices);
253 }
else if (nb::isinstance<Tensor<Index>>(cone_vertices)) {
254 auto cone_vertices_tensor = nb::cast<Tensor<Index>>(cone_vertices);
255 auto [data, shape, stride] = tensor_to_span(cone_vertices_tensor);
259 throw std::runtime_error(
"Invalid cone_vertices type");
263 "feature_angle_threshold"_a = lagrange::internal::pi / 4,
264 "cone_vertices"_a = nb::none(),
265 "options"_a = nb::none(),
266 R
"(Compute indexed normal attribute.
268Edge with dihedral angles larger than `feature_angle_threshold` are considered as sharp edges.
269Vertices listed in `cone_vertices` are considered as cone vertices, which is always sharp.
271:param mesh: input mesh
272:param feature_angle_threshold: feature angle threshold
273:param cone_vertices: cone vertices
274:param options: normal options
276:returns: the id of the indexed normal attribute.
282 Scalar feature_angle_threshold,
283 nb::object cone_vertices,
284 std::optional<std::string_view> output_attribute_name,
285 std::optional<NormalWeightingType> weight_type,
286 std::optional<std::string_view> facet_normal_attribute_name,
287 std::optional<bool> recompute_facet_normals,
288 std::optional<bool> keep_facet_normals,
289 std::optional<float> distance_tolerance) {
290 NormalOptions options;
291 if (output_attribute_name) options.output_attribute_name = *output_attribute_name;
292 if (weight_type) options.weight_type = *weight_type;
293 if (facet_normal_attribute_name)
294 options.facet_normal_attribute_name = *facet_normal_attribute_name;
295 if (recompute_facet_normals) options.recompute_facet_normals = *recompute_facet_normals;
296 if (keep_facet_normals) options.keep_facet_normals = *keep_facet_normals;
297 if (distance_tolerance) options.distance_tolerance = *distance_tolerance;
299 if (cone_vertices.is_none()) {
301 }
else if (nb::isinstance<nb::list>(cone_vertices)) {
302 auto cone_vertices_list = nb::cast<std::vector<Index>>(cone_vertices);
305 }
else if (nb::isinstance<Tensor<Index>>(cone_vertices)) {
306 auto cone_vertices_tensor = nb::cast<Tensor<Index>>(cone_vertices);
307 auto [data, shape, stride] = tensor_to_span(cone_vertices_tensor);
311 throw std::runtime_error(
"Invalid cone_vertices type");
315 "feature_angle_threshold"_a = lagrange::internal::pi / 4,
316 "cone_vertices"_a = nb::none(),
317 "output_attribute_name"_a = nb::none(),
318 "weight_type"_a = nb::none(),
319 "facet_normal_attribute_name"_a = nb::none(),
320 "recompute_facet_normals"_a = nb::none(),
321 "keep_facet_normals"_a = nb::none(),
322 "distance_tolerance"_a = nb::none(),
323 R
"(Compute indexed normal attribute (Pythonic API).
325:param mesh: input mesh
326:param feature_angle_threshold: feature angle threshold
327:param cone_vertices: cone vertices
328:param output_attribute_name: output normal attribute name
329:param weight_type: normal weighting type
330:param facet_normal_attribute_name: facet normal attribute name
331:param recompute_facet_normals: whether to recompute facet normals
332:param keep_facet_normals: whether to keep the computed facet normal attribute
333:param distance_tolerance: distance tolerance for degenerate edge check
334 (only used to bypass degenerate edges in polygon facets)
336:returns: the id of the indexed normal attribute.)");
338 using ConstArray3d = nb::ndarray<
const double, nb::shape<-1, 3>, nb::c_contig, nb::device::cpu>;
340 "compute_pointcloud_pca",
341 [](ConstArray3d points,
bool shift_centroid,
bool normalize) {
342 ComputePointcloudPCAOptions options;
343 options.shift_centroid = shift_centroid;
344 options.normalize = normalize;
345 PointcloudPCAOutput<Scalar> output =
347 return std::make_tuple(output.center, output.eigenvectors, output.eigenvalues);
350 "shift_centroid"_a = ComputePointcloudPCAOptions().shift_centroid,
351 "normalize"_a = ComputePointcloudPCAOptions().normalize,
352 R
"(Compute principal components of a point cloud.
354:param points: Input points.
355:param shift_centroid: When true: covariance = (P-centroid)^T (P-centroid), when false: covariance = (P)^T (P).
356:param normalize: Should we divide the result by number of points?
358:returns: tuple of (center, eigenvectors, eigenvalues).)");
361 "compute_greedy_coloring",
364 size_t num_color_used,
365 std::optional<std::string_view> output_attribute_name) {
366 GreedyColoringOptions options;
367 options.element_type = element_type;
368 options.num_color_used = num_color_used;
369 if (output_attribute_name) options.output_attribute_name = *output_attribute_name;
374 "num_color_used"_a = 8,
375 "output_attribute_name"_a = nb::none(),
376 R
"(Compute greedy coloring of mesh elements.
378:param mesh: Input mesh.
379:param element_type: Element type to be colored. Can be either Vertex or Facet.
380:param num_color_used: Minimum number of colors to use. The algorithm will cycle through them but may use more.
381:param output_attribute_name: Output attribute name.
383:returns: Color attribute id.)");
386 "normalize_mesh_with_transform",
388 bool normalize_normals,
389 bool normalize_tangents_bitangents) -> Eigen::Matrix<Scalar, 4, 4> {
390 TransformOptions options;
391 options.normalize_normals = normalize_normals;
392 options.normalize_tangents_bitangents = normalize_tangents_bitangents;
396 "normalize_normals"_a = TransformOptions().normalize_normals,
397 "normalize_tangents_bitangents"_a = TransformOptions().normalize_tangents_bitangents,
398 R
"(Normalize a mesh to fit into a unit box centered at the origin.
400:param mesh: Input mesh.
401:param normalize_normals: Whether to normalize normals.
402:param normalize_tangents_bitangents: Whether to normalize tangents and bitangents.
404:return Inverse transform, can be used to undo the normalization process.)");
408 "normalize_mesh_with_transform_2d",
410 bool normalize_normals,
411 bool normalize_tangents_bitangents) -> Eigen::Matrix<Scalar, 3, 3> {
412 TransformOptions options;
413 options.normalize_normals = normalize_normals;
414 options.normalize_tangents_bitangents = normalize_tangents_bitangents;
418 "normalize_normals"_a = TransformOptions().normalize_normals,
419 "normalize_tangents_bitangents"_a = TransformOptions().normalize_tangents_bitangents,
420 R
"(Normalize a mesh to fit into a unit box centered at the origin.
422:param mesh: Input mesh.
423:param normalize_normals: Whether to normalize normals.
424:param normalize_tangents_bitangents: Whether to normalize tangents and bitangents.
426:return Inverse transform, can be used to undo the normalization process.)");
430 [](MeshType& mesh,
bool normalize_normals,
bool normalize_tangents_bitangents) ->
void {
431 TransformOptions options;
432 options.normalize_normals = normalize_normals;
433 options.normalize_tangents_bitangents = normalize_tangents_bitangents;
437 "normalize_normals"_a = TransformOptions().normalize_normals,
438 "normalize_tangents_bitangents"_a = TransformOptions().normalize_tangents_bitangents,
439 R
"(Normalize a mesh to fit into a unit box centered at the origin.
441:param mesh: Input mesh.
442:param normalize_normals: Whether to normalize normals.
443:param normalize_tangents_bitangents: Whether to normalize tangents and bitangents.)");
446 "normalize_meshes_with_transform",
447 [](std::vector<MeshType*> meshes,
448 bool normalize_normals,
449 bool normalize_tangents_bitangents) -> Eigen::Matrix<Scalar, 4, 4> {
450 TransformOptions options;
451 options.normalize_normals = normalize_normals;
452 options.normalize_tangents_bitangents = normalize_tangents_bitangents;
457 "normalize_normals"_a = TransformOptions().normalize_normals,
458 "normalize_tangents_bitangents"_a = TransformOptions().normalize_tangents_bitangents,
459 R
"(Normalize a mesh to fit into a unit box centered at the origin.
461:param meshes: Input meshes.
462:param normalize_normals: Whether to normalize normals.
463:param normalize_tangents_bitangents: Whether to normalize tangents and bitangents.
465:return Inverse transform, can be used to undo the normalization process.)");
468 "normalize_meshes_with_transform_2d",
469 [](std::vector<MeshType*> meshes,
470 bool normalize_normals,
471 bool normalize_tangents_bitangents) -> Eigen::Matrix<Scalar, 3, 3> {
472 TransformOptions options;
473 options.normalize_normals = normalize_normals;
474 options.normalize_tangents_bitangents = normalize_tangents_bitangents;
479 "normalize_normals"_a = TransformOptions().normalize_normals,
480 "normalize_tangents_bitangents"_a = TransformOptions().normalize_tangents_bitangents,
481 R
"(Normalize a mesh to fit into a unit box centered at the origin.
483:param meshes: Input meshes.
484:param normalize_normals: Whether to normalize normals.
485:param normalize_tangents_bitangents: Whether to normalize tangents and bitangents.
487:return Inverse transform, can be used to undo the normalization process.)");
492 [](std::vector<MeshType*> meshes,
493 bool normalize_normals,
494 bool normalize_tangents_bitangents) {
495 TransformOptions options;
496 options.normalize_normals = normalize_normals;
497 options.normalize_tangents_bitangents = normalize_tangents_bitangents;
502 "normalize_normals"_a = TransformOptions().normalize_normals,
503 "normalize_tangents_bitangents"_a = TransformOptions().normalize_tangents_bitangents,
504 R
"(Normalize a list of meshes to fit into a unit box centered at the origin.
506:param meshes: Input meshes.
507:param normalize_normals: Whether to normalize normals.
508:param normalize_tangents_bitangents: Whether to normalize tangents and bitangents.)");
512 [](std::vector<MeshType*> meshes,
bool preserve_vertices) {
515 [&](
size_t i) ->
const MeshType& { return *meshes[i]; },
519 "preserve_attributes"_a =
true,
520 R
"(Combine a list of meshes into a single mesh.
522:param meshes: Input meshes.
523:param preserve_attributes: Whether to preserve attributes.
525:returns: The combined mesh.)");
528 "compute_seam_edges",
531 std::optional<std::string_view> output_attribute_name) {
532 SeamEdgesOptions options;
533 if (output_attribute_name) options.output_attribute_name = *output_attribute_name;
537 "indexed_attribute_id"_a,
538 "output_attribute_name"_a = nb::none(),
539 R
"(Compute seam edges for a given indexed attribute.
541:param mesh: Input mesh.
542:param indexed_attribute_id: Input indexed attribute id.
543:param output_attribute_name: Output attribute name.
545:returns: Attribute id for the output per-edge seam attribute (1 is a seam, 0 is not).)");
549 [](MeshType& mesh,
bool positive) {
550 OrientOptions options;
551 options.positive = positive;
555 "positive"_a = OrientOptions().positive,
556 R
"(Orient mesh facets to ensure positive or negative signed volume.
558:param mesh: Input mesh.
559:param positive: Whether to orient volumes positively or negatively.)");
562 "unify_index_buffer",
565 R
"(Unify the index buffer for all indexed attributes.
567:param mesh: Input mesh.
569:returns: Unified mesh.)");
572 "unify_index_buffer",
576 R
"(Unify the index buffer for selected attributes.
578:param mesh: Input mesh.
579:param attribute_ids: Attribute IDs to unify.
581:returns: Unified mesh.)");
584 "unify_index_buffer",
588 R
"(Unify the index buffer for selected attributes.
590:param mesh: Input mesh.
591:param attribute_names: Attribute names to unify.
593:returns: Unified mesh.)");
596 "triangulate_polygonal_facets",
597 [](MeshType& mesh, std::string_view scheme) {
598 lagrange::TriangulationOptions opt;
599 if (scheme ==
"earcut") {
601 }
else if (scheme ==
"centroid_fan") {
604 throw Error(fmt::format(
"Unsupported triangulation scheme {}", scheme));
609 "scheme"_a =
"earcut",
610 R
"(Triangulate polygonal facets of the mesh.
612:param mesh: The input mesh to be triangulated in place.
613:param scheme: The triangulation scheme (options are 'earcut' and 'centroid_fan'))");
615 nb::enum_<ComponentOptions::ConnectivityType>(m, "ConnectivityType",
"Mesh connectivity type")
618 ComponentOptions::ConnectivityType::Vertex,
619 "Two facets are connected if they share a vertex")
622 ComponentOptions::ConnectivityType::Edge,
623 "Two facets are connected if they share an edge");
626 "compute_components",
628 std::optional<std::string_view> output_attribute_name,
629 std::optional<lagrange::ConnectivityType> connectivity_type,
630 std::optional<nb::list>& blocker_elements) {
631 lagrange::ComponentOptions opt;
632 if (output_attribute_name.has_value()) {
635 if (connectivity_type.has_value()) {
638 std::vector<Index> blocker_elements_vec;
639 if (blocker_elements.has_value()) {
640 for (
auto val : blocker_elements.value()) {
641 blocker_elements_vec.push_back(nb::cast<Index>(val));
647 "output_attribute_name"_a = nb::none(),
648 "connectivity_type"_a = nb::none(),
649 "blocker_elements"_a = nb::none(),
650 R
"(Compute connected components.
652This method will create a per-facet component id attribute named by the `output_attribute_name`
653argument. Each component id is in [0, num_components-1] range.
655:param mesh: The input mesh.
656:param output_attribute_name: The name of the output attribute.
657:param connectivity_type: The connectivity type. Either "Vertex" or "Edge".
658:param blocker_elements: The list of blocker element indices. If `connectivity_type` is `Edge`, facets adjacent to a blocker edge are not considered as connected through this edge. If `connectivity_type` is `Vertex`, facets sharing a blocker vertex are not considered as connected through this vertex.
660:returns: The total number of components.)");
662 nb::class_<VertexValenceOptions>(m, "VertexValenceOptions",
"Vertex valence options")
665 "output_attribute_name",
667 "The name of the output attribute")
669 "induced_by_attribute",
671 "Optional per-edge attribute used as indicator function to restrict the graph used for "
672 "vertex valence computation");
675 "compute_vertex_valence",
678 "options"_a = VertexValenceOptions(),
679 R
"(Compute vertex valence
681:param mesh: The input mesh.
682:param options: The vertex valence options.
684:returns: The vertex valence attribute id.)");
687 "compute_vertex_valence",
689 std::optional<std::string_view> output_attribute_name,
690 std::optional<std::string_view> induced_by_attribute) {
691 VertexValenceOptions opt;
692 if (output_attribute_name.has_value()) {
693 opt.output_attribute_name = output_attribute_name.value();
695 if (induced_by_attribute.has_value()) {
696 opt.induced_by_attribute = induced_by_attribute.value();
701 "output_attribute_name"_a = nb::none(),
702 "induced_by_attribute"_a = nb::none(),
703 R
"(Compute vertex valence);
705:param mesh: The input mesh.
706:param output_attribute_name: The name of the output attribute.
707:param induced_by_attribute: Optional per-edge attribute used as indicator function to restrict the graph used for vertex valence computation.
709:returns: The vertex valence attribute id)");
711 nb::class_<TangentBitangentOptions>(m, "TangentBitangentOptions",
"Tangent bitangent options")
714 "tangent_attribute_name",
716 "The name of the output tangent attribute, default is `@tangent`")
718 "bitangent_attribute_name",
720 "The name of the output bitangent attribute, default is `@bitangent`")
724 "The name of the uv attribute")
726 "normal_attribute_name",
728 "The name of the normal attribute")
730 "output_element_type",
732 "The output element type")
736 "Whether to pad the output tangent/bitangent with sign")
738 "orthogonalize_bitangent",
740 "Whether to compute the bitangent as cross(normal, tangent). If false, the bitangent "
741 "is computed as the derivative of v-coordinate")
743 "keep_existing_tangent",
745 "Whether to recompute tangent if the tangent attribute (specified by "
746 "tangent_attribute_name) already exists. If true, bitangent is computed by normalizing "
747 "cross(normal, tangent) and param orthogonalize_bitangent must be true.");
748 nb::class_<TangentBitangentResult>(m,
"TangentBitangentResult",
"Tangent bitangent result")
753 "The output tangent attribute id")
757 "The output bitangent attribute id");
760 "compute_tangent_bitangent",
763 "options"_a = TangentBitangentOptions(),
764 R
"(Compute tangent and bitangent vector attributes.
766:param mesh: The input mesh.
767:param options: The tangent bitangent options.
769:returns: The tangent and bitangent attribute ids)");
772 "compute_tangent_bitangent",
774 std::optional<std::string_view>(tangent_attribute_name),
775 std::optional<std::string_view>(bitangent_attribute_name),
776 std::optional<std::string_view>(uv_attribute_name),
777 std::optional<std::string_view>(normal_attribute_name),
778 std::optional<AttributeElement>(output_attribute_type),
779 std::optional<bool>(pad_with_sign),
780 std::optional<bool>(orthogonalize_bitangent),
781 std::optional<bool>(keep_existing_tangent)) {
782 TangentBitangentOptions opt;
783 if (tangent_attribute_name.has_value()) {
784 opt.tangent_attribute_name = tangent_attribute_name.value();
786 if (bitangent_attribute_name.has_value()) {
787 opt.bitangent_attribute_name = bitangent_attribute_name.value();
789 if (uv_attribute_name.has_value()) {
790 opt.uv_attribute_name = uv_attribute_name.value();
792 if (normal_attribute_name.has_value()) {
793 opt.normal_attribute_name = normal_attribute_name.value();
795 if (output_attribute_type.has_value()) {
796 opt.output_element_type = output_attribute_type.value();
798 if (pad_with_sign.has_value()) {
799 opt.pad_with_sign = pad_with_sign.value();
801 if (orthogonalize_bitangent.has_value()) {
802 opt.orthogonalize_bitangent = orthogonalize_bitangent.value();
804 if (keep_existing_tangent.has_value()) {
805 opt.keep_existing_tangent = keep_existing_tangent.value();
809 return std::make_tuple(r.tangent_id, r.bitangent_id);
812 "tangent_attribute_name"_a = nb::none(),
813 "bitangent_attribute_name"_a = nb::none(),
814 "uv_attribute_name"_a = nb::none(),
815 "normal_attribute_name"_a = nb::none(),
816 "output_attribute_type"_a = nb::none(),
817 "pad_with_sign"_a = nb::none(),
818 "orthogonalize_bitangent"_a = nb::none(),
819 "keep_existing_tangent"_a = nb::none(),
820 R
"(Compute tangent and bitangent vector attributes (Pythonic API).
822:param mesh: The input mesh.
823:param tangent_attribute_name: The name of the output tangent attribute.
824:param bitangent_attribute_name: The name of the output bitangent attribute.
825:param uv_attribute_name: The name of the uv attribute.
826:param normal_attribute_name: The name of the normal attribute.
827:param output_attribute_type: The output element type.
828:param pad_with_sign: Whether to pad the output tangent/bitangent with sign.
829:param orthogonalize_bitangent: Whether to compute the bitangent as sign * cross(normal, tangent).
830:param keep_existing_tangent: Whether to recompute tangent if the tangent attribute (specified by tangent_attribute_name) already exists. If true, bitangent is computed by normalizing cross(normal, tangent) and param orthogonalize_bitangent must be true.
832:returns: The tangent and bitangent attribute ids)");
839 "old_attribute_id"_a,
840 "new_attribute_name"_a,
842 R
"(Map an attribute to a new element type.
844:param mesh: The input mesh.
845:param old_attribute_id: The id of the input attribute.
846:param new_attribute_name: The name of the new attribute.
847:param new_element: The new element type.
849:returns: The id of the new attribute.)");
857 "old_attribute_name"_a,
858 "new_attribute_name"_a,
860 R
"(Map an attribute to a new element type.
862:param mesh: The input mesh.
863:param old_attribute_name: The name of the input attribute.
864:param new_attribute_name: The name of the new attribute.
865:param new_element: The new element type.
867:returns: The id of the new attribute.)");
870 "map_attribute_in_place",
876 R
"(Map an attribute to a new element type in place.
878:param mesh: The input mesh.
879:param id: The id of the input attribute.
880:param new_element: The new element type.
882:returns: The id of the new attribute.)");
885 "map_attribute_in_place",
891 R
"(Map an attribute to a new element type in place.
893:param mesh: The input mesh.
894:param name: The name of the input attribute.
895:param new_element: The new element type.
897:returns: The id of the new attribute.)");
899 nb::class_<FacetAreaOptions>(m, "FacetAreaOptions",
"Options for computing facet area.")
902 "output_attribute_name",
904 "The name of the output attribute.");
907 "compute_facet_area",
910 "options"_a = FacetAreaOptions(),
911 R
"(Compute facet area.
913:param mesh: The input mesh.
914:param options: The options for computing facet area.
916:returns: The id of the new attribute.)");
919 "compute_facet_area",
920 [](MeshType& mesh, std::optional<std::string_view> name) {
921 FacetAreaOptions opt;
922 if (name.has_value()) {
923 opt.output_attribute_name = name.value();
928 "output_attribute_name"_a = nb::none(),
929 R
"(Compute facet area (Pythonic API).
931:param mesh: The input mesh.
932:param output_attribute_name: The name of the output attribute.
934:returns: The id of the new attribute.)");
937 "compute_facet_vector_area",
938 [](MeshType& mesh, std::optional<std::string_view> name) {
939 FacetVectorAreaOptions opt;
940 if (name.has_value()) {
941 opt.output_attribute_name = name.value();
946 "output_attribute_name"_a = nb::none(),
947 R
"(Compute facet vector area (Pythonic API).
949Vector area is defined as the area multiplied by the facet normal.
950For triangular facets, it is equivalent to half of the cross product of two edges.
951For non-planar polygonal facets, the vector area offers a robust way to compute the area and normal.
952The magnitude of the vector area is the largest area of any orthogonal projection of the facet.
953The direction of the vector area is the normal direction that maximizes the projected area [1, 2].
955[1] Sullivan, John M. "Curvatures of smooth and discrete surfaces." Discrete differential geometry.
956Basel: Birkhäuser Basel, 2008. 175-188.
958[2] Alexa, Marc, and Max Wardetzky. "Discrete Laplacians on general polygonal meshes." ACM SIGGRAPH
9592011 papers. 2011. 1-10.
961:param mesh: The input mesh.
962:param output_attribute_name: The name of the output attribute.
964:returns: The id of the new attribute.)");
966 nb::class_<MeshAreaOptions>(m, "MeshAreaOptions",
"Options for computing mesh area.")
969 "input_attribute_name",
971 "The name of the pre-computed facet area attribute, default is `@facet_area`.")
975 "Whether to use signed area.");
981 "options"_a = MeshAreaOptions(),
982 R
"(Compute mesh area.
984:param mesh: The input mesh.
985:param options: The options for computing mesh area.
987:returns: The mesh area.)");
992 std::optional<std::string_view> input_attribute_name,
993 std::optional<bool> use_signed_area) {
995 if (input_attribute_name.has_value()) {
996 opt.input_attribute_name = input_attribute_name.value();
998 if (use_signed_area.has_value()) {
999 opt.use_signed_area = use_signed_area.value();
1004 "input_attribute_name"_a = nb::none(),
1005 "use_signed_area"_a = nb::none(),
1006 R
"(Compute mesh area (Pythonic API).
1008:param mesh: The input mesh.
1009:param input_attribute_name: The name of the pre-computed facet area attribute.
1010:param use_signed_area: Whether to use signed area.
1012:returns: The mesh area.)");
1014 nb::class_<FacetCentroidOptions>(m, "FacetCentroidOptions",
"Facet centroid options.")
1017 "output_attribute_name",
1019 "The name of the output attribute.");
1021 "compute_facet_centroid",
1024 "options"_a = FacetCentroidOptions(),
1025 R
"(Compute facet centroid.
1027:param mesh: The input mesh.
1028:param options: The options for computing facet centroid.
1030:returns: The id of the new attribute.)");
1033 "compute_facet_centroid",
1034 [](MeshType& mesh, std::optional<std::string_view> output_attribute_name) {
1035 FacetCentroidOptions opt;
1036 if (output_attribute_name.has_value()) {
1037 opt.output_attribute_name = output_attribute_name.value();
1042 "output_attribute_name"_a = nb::none(),
1043 R
"(Compute facet centroid (Pythonic API).
1045:param mesh: Input mesh.
1046:param output_attribute_name: Output attribute name.
1048:returns: Attribute ID.)");
1051 "compute_facet_circumcenter",
1052 [](MeshType& mesh, std::optional<std::string_view> output_attribute_name) {
1053 FacetCircumcenterOptions opt;
1054 if (output_attribute_name.has_value()) {
1055 opt.output_attribute_name = output_attribute_name.value();
1060 "output_attribute_name"_a = nb::none(),
1061 R
"(Compute facet circumcenter (Pythonic API).
1063:param mesh: The input mesh.
1064:param output_attribute_name: The name of the output attribute.
1066:returns: The id of the new attribute.)");
1068 nb::enum_<MeshCentroidOptions::WeightingType>(
1070 "CentroidWeightingType",
1071 "Centroid weighting type.")
1075 nb::class_<MeshCentroidOptions>(m,
"MeshCentroidOptions",
"Mesh centroid options.")
1077 .def_rw(
"weighting_type", &MeshCentroidOptions::weighting_type,
"The weighting type.")
1079 "facet_centroid_attribute_name",
1081 "The name of the pre-computed facet centroid attribute if available.")
1083 "facet_area_attribute_name",
1085 "The name of the pre-computed facet area attribute if available.");
1088 "compute_mesh_centroid",
1089 [](
const MeshType& mesh, MeshCentroidOptions opt) {
1096 "options"_a = MeshCentroidOptions(),
1097 R
"(Compute mesh centroid.
1099:param mesh: Input mesh.
1100:param options: Centroid computation options.
1102:returns: Mesh centroid coordinates.)");
1105 "compute_mesh_centroid",
1107 std::optional<MeshCentroidOptions::WeightingType> weighting_type,
1108 std::optional<std::string_view> facet_centroid_attribute_name,
1109 std::optional<std::string_view> facet_area_attribute_name) {
1110 MeshCentroidOptions opt;
1111 if (weighting_type.has_value()) {
1112 opt.weighting_type = weighting_type.value();
1114 if (facet_centroid_attribute_name.has_value()) {
1115 opt.facet_centroid_attribute_name = facet_centroid_attribute_name.value();
1117 if (facet_area_attribute_name.has_value()) {
1118 opt.facet_area_attribute_name = facet_area_attribute_name.value();
1126 "weighting_type"_a = nb::none(),
1127 "facet_centroid_attribute_name"_a = nb::none(),
1128 "facet_area_attribute_name"_a = nb::none(),
1129 R
"(Compute mesh centroid (Pythonic API).
1131:param mesh: Input mesh.
1132:param weighting_type: Weighting type (default: Area).
1133:param facet_centroid_attribute_name: Pre-computed facet centroid attribute name.
1134:param facet_area_attribute_name: Pre-computed facet area attribute name.
1136:returns: Mesh centroid coordinates.)");
1140 [](MeshType& mesh, Tensor<Index> new_to_old) {
1141 auto [data, shape, stride] = tensor_to_span(new_to_old);
1147 R
"(Reorder vertices of a mesh in place based on a permutation.
1149:param mesh: input mesh
1150:param new_to_old: permutation vector for vertices)");
1154 [](MeshType& mesh, Tensor<Index> new_to_old) {
1155 auto [data, shape, stride] = tensor_to_span(new_to_old);
1161 R
"(Reorder facets of a mesh in place based on a permutation.
1163:param mesh: input mesh
1164:param new_to_old: permutation vector for facets)");
1166 nb::enum_<MappingPolicy>(m, "MappingPolicy",
"Mapping policy for handling collisions.")
1171 nb::class_<RemapVerticesOptions>(m,
"RemapVerticesOptions",
"Options for remapping vertices.")
1174 "collision_policy_float",
1176 "The collision policy for float attributes.")
1178 "collision_policy_integral",
1180 "The collision policy for integral attributes.");
1184 [](MeshType& mesh, Tensor<Index> old_to_new, RemapVerticesOptions opt) {
1185 auto [data, shape, stride] = tensor_to_span(old_to_new);
1191 "options"_a = RemapVerticesOptions(),
1192 R
"(Remap vertices of a mesh in place based on a permutation.
1194:param mesh: input mesh
1195:param old_to_new: permutation vector for vertices
1196:param options: options for remapping vertices)");
1201 Tensor<Index> old_to_new,
1202 std::optional<MappingPolicy> collision_policy_float,
1203 std::optional<MappingPolicy> collision_policy_integral) {
1204 RemapVerticesOptions opt;
1205 if (collision_policy_float.has_value()) {
1206 opt.collision_policy_float = collision_policy_float.value();
1208 if (collision_policy_integral.has_value()) {
1209 opt.collision_policy_integral = collision_policy_integral.value();
1211 auto [data, shape, stride] = tensor_to_span(old_to_new);
1217 "collision_policy_float"_a = nb::none(),
1218 "collision_policy_integral"_a = nb::none(),
1219 R
"(Remap vertices of a mesh in place based on a permutation (Pythonic API).
1221:param mesh: input mesh
1222:param old_to_new: permutation vector for vertices
1223:param collision_policy_float: The collision policy for float attributes.
1224:param collision_policy_integral: The collision policy for integral attributes.)");
1228 [](MeshType& mesh, std::string_view method) {
1230 if (method ==
"Lexicographic" || method ==
"lexicographic") {
1232 }
else if (method ==
"Morton" || method ==
"morton") {
1234 }
else if (method ==
"Hilbert" || method ==
"hilbert") {
1236 }
else if (method ==
"None" || method ==
"none") {
1239 throw std::runtime_error(fmt::format(
"Invalid reordering method: {}", method));
1245 "method"_a =
"Morton",
1246 R
"(Reorder a mesh in place.
1248:param mesh: input mesh
1249:param method: reordering method, options are 'Lexicographic', 'Morton', 'Hilbert', 'None' (default is 'Morton').)",
1251 "def reorder_mesh(mesh: SurfaceMesh, "
1252 "method: typing.Literal['Lexicographic', 'Morton', 'Hilbert', 'None']) -> None"));
1255 "separate_by_facet_groups",
1257 Tensor<Index> facet_group_indices,
1258 std::string_view source_vertex_attr_name,
1259 std::string_view source_facet_attr_name,
1260 bool map_attributes) {
1261 SeparateByFacetGroupsOptions options;
1262 options.source_vertex_attr_name = source_vertex_attr_name;
1263 options.source_facet_attr_name = source_facet_attr_name;
1265 auto [data, shape, stride] = tensor_to_span(facet_group_indices);
1270 "facet_group_indices"_a,
1271 "source_vertex_attr_name"_a =
"",
1272 "source_facet_attr_name"_a =
"",
1273 "map_attributes"_a =
false,
1274 R
"(Extract a set of submeshes based on facet groups.
1276:param mesh: The source mesh.
1277:param facet_group_indices: The group index for each facet. Each group index must be in the range of [0, max(facet_group_indices)]
1278:param source_vertex_attr_name: The optional attribute name to track source vertices.
1279:param source_facet_attr_name: The optional attribute name to track source facets.
1281:returns: A list of meshes, one for each facet group.
1285 "separate_by_components",
1287 std::string_view source_vertex_attr_name,
1288 std::string_view source_facet_attr_name,
1289 bool map_attributes,
1291 SeparateByComponentsOptions options;
1292 options.source_vertex_attr_name = source_vertex_attr_name;
1293 options.source_facet_attr_name = source_facet_attr_name;
1295 options.connectivity_type = connectivity_type;
1299 "source_vertex_attr_name"_a =
"",
1300 "source_facet_attr_name"_a =
"",
1301 "map_attributes"_a =
false,
1303 R
"(Extract a set of submeshes based on connected components.
1305:param mesh: The source mesh.
1306:param source_vertex_attr_name: The optional attribute name to track source vertices.
1307:param source_facet_attr_name: The optional attribute name to track source facets.
1308:param map_attributes: Map attributes from the source to target meshes.
1309:param connectivity_type: The connectivity used for component computation.
1311:returns: A list of meshes, one for each connected component.
1317 Tensor<Index> selected_facets,
1318 std::string_view source_vertex_attr_name,
1319 std::string_view source_facet_attr_name,
1320 bool map_attributes) {
1321 SubmeshOptions options;
1322 options.source_vertex_attr_name = source_vertex_attr_name;
1323 options.source_facet_attr_name = source_facet_attr_name;
1325 auto [data, shape, stride] = tensor_to_span(selected_facets);
1330 "selected_facets"_a,
1331 "source_vertex_attr_name"_a =
"",
1332 "source_facet_attr_name"_a =
"",
1333 "map_attributes"_a =
false,
1334 R
"(Extract a submesh based on the selected facets.
1336:param mesh: The source mesh.
1337:param selected_facets: A listed of facet ids to extract.
1338:param source_vertex_attr_name: The optional attribute name to track source vertices.
1339:param source_facet_attr_name: The optional attribute name to track source facets.
1340:param map_attributes: Map attributes from the source to target meshes.
1342:returns: A mesh that contains only the selected facets.
1346 "compute_dihedral_angles",
1348 std::optional<std::string_view> output_attribute_name,
1349 std::optional<std::string_view> facet_normal_attribute_name,
1350 std::optional<bool> recompute_facet_normals,
1351 std::optional<bool> keep_facet_normals) {
1352 DihedralAngleOptions options;
1353 if (output_attribute_name.has_value()) {
1354 options.output_attribute_name = output_attribute_name.value();
1356 if (facet_normal_attribute_name.has_value()) {
1357 options.facet_normal_attribute_name = facet_normal_attribute_name.value();
1359 if (recompute_facet_normals.has_value()) {
1360 options.recompute_facet_normals = recompute_facet_normals.value();
1362 if (keep_facet_normals.has_value()) {
1363 options.keep_facet_normals = keep_facet_normals.value();
1368 "output_attribute_name"_a = nb::none(),
1369 "facet_normal_attribute_name"_a = nb::none(),
1370 "recompute_facet_normals"_a = nb::none(),
1371 "keep_facet_normals"_a = nb::none(),
1372 R
"(Compute dihedral angles for each edge.
1374The dihedral angle of an edge is defined as the angle between the __normals__ of two facets adjacent
1375to the edge. The dihedral angle is always in the range [0, pi] for manifold edges. For boundary
1376edges, the dihedral angle defaults to 0. For non-manifold edges, the dihedral angle is not
1377well-defined and will be set to the special value 2 * π.
1379:param mesh: The source mesh.
1380:param output_attribute_name: The optional edge attribute name to store the dihedral angles.
1381:param facet_normal_attribute_name: The optional attribute name to store the facet normals.
1382:param recompute_facet_normals: Whether to recompute facet normals.
1383:param keep_facet_normals: Whether to keep newly computed facet normals. It has no effect on pre-existing facet normals.
1385:return: The edge attribute id of dihedral angles.)");
1388 "compute_edge_lengths",
1389 [](MeshType& mesh, std::optional<std::string_view> output_attribute_name) {
1390 EdgeLengthOptions options;
1391 if (output_attribute_name.has_value())
1392 options.output_attribute_name = output_attribute_name.value();
1396 "output_attribute_name"_a = nb::none(),
1397 R
"(Compute edge lengths.
1399:param mesh: The source mesh.
1400:param output_attribute_name: The optional edge attribute name to store the edge lengths.
1402:return: The edge attribute id of edge lengths.)");
1405 "compute_dijkstra_distance",
1408 const nb::list& barycentric_coords,
1409 std::optional<Scalar> radius,
1410 std::string_view output_attribute_name,
1411 bool output_involved_vertices) {
1412 DijkstraDistanceOptions<Scalar, Index> options;
1413 options.seed_facet = seed_facet;
1414 for (
auto val : barycentric_coords) {
1415 options.barycentric_coords.push_back(nb::cast<Scalar>(val));
1417 if (radius.has_value()) {
1418 options.radius = radius.value();
1420 options.output_attribute_name = output_attribute_name;
1421 options.output_involved_vertices = output_involved_vertices;
1426 "barycentric_coords"_a,
1427 "radius"_a = nb::none(),
1428 "output_attribute_name"_a = DijkstraDistanceOptions<Scalar, Index>{}.output_attribute_name,
1429 "output_involved_vertices"_a =
1430 DijkstraDistanceOptions<Scalar, Index>{}.output_involved_vertices,
1431 R
"(Compute Dijkstra distance from a seed facet.
1433:param mesh: The source mesh.
1434:param seed_facet: The seed facet index.
1435:param barycentric_coords: The barycentric coordinates of the seed facet.
1436:param radius: The maximum radius of the dijkstra distance.
1437:param output_attribute_name: The output attribute name to store the dijkstra distance.
1438:param output_involved_vertices: Whether to output the list of involved vertices.)");
1441 "weld_indexed_attribute",
1444 std::optional<double> epsilon_rel,
1445 std::optional<double> epsilon_abs,
1446 std::optional<double> angle_abs,
1447 std::optional<std::vector<size_t>> exclude_vertices) {
1448 WeldOptions options;
1449 options.epsilon_rel = epsilon_rel;
1450 options.epsilon_abs = epsilon_abs;
1451 options.angle_abs = angle_abs;
1452 if (exclude_vertices.has_value()) {
1453 const auto& exclude_vertices_vec = exclude_vertices.value();
1454 options.exclude_vertices = {
1455 exclude_vertices_vec.data(),
1456 exclude_vertices_vec.size()};
1458 return weld_indexed_attribute(mesh, attribute_id, options);
1462 "epsilon_rel"_a = nb::none(),
1463 "epsilon_abs"_a = nb::none(),
1464 "angle_abs"_a = nb::none(),
1465 "exclude_vertices"_a = nb::none(),
1466 R
"(Weld indexed attribute.
1468:param mesh: The source mesh to be updated in place.
1469:param attribute_id: The indexed attribute id to weld.
1470:param epsilon_rel: The relative tolerance for welding.
1471:param epsilon_abs: The absolute tolerance for welding.
1472:param angle_abs: The absolute angle tolerance for welding.
1473:param exclude_vertices: Optional list of vertex indices to exclude from welding.)");
1479 R
"(Compute the Euler characteristic.
1481:param mesh: The source mesh.
1483:return: The Euler characteristic.)");
1489 R
"(Check if the mesh is closed.
1491A mesh is considered closed if it has no boundary edges.
1493:param mesh: The source mesh.
1495:return: Whether the mesh is closed.)");
1498 "is_vertex_manifold",
1501 R
"(Check if the mesh is vertex manifold.
1503:param mesh: The source mesh.
1505:return: Whether the mesh is vertex manifold.)");
1511 R
"(Check if the mesh is edge manifold.
1513:param mesh: The source mesh.
1515:return: Whether the mesh is edge manifold.)");
1519A mesh considered as manifold if it is both vertex and edge manifold.
1521:param mesh: The source mesh.
1523:return: Whether the mesh is manifold.)");
1529 R
"(Check if the mesh is oriented.
1531:param mesh: The source mesh.
1533:return: Whether the mesh is oriented.)");
1538 Eigen::Matrix<Scalar, 4, 4> affine_transform,
1539 bool normalize_normals,
1540 bool normalize_tangents_bitangents,
1541 bool in_place) -> std::optional<MeshType> {
1542 Eigen::Transform<Scalar, 3, Eigen::Affine> M(affine_transform);
1543 TransformOptions options;
1544 options.normalize_normals = normalize_normals;
1545 options.normalize_tangents_bitangents = normalize_tangents_bitangents;
1547 std::optional<MeshType> result;
1556 "affine_transform"_a,
1557 "normalize_normals"_a = TransformOptions().normalize_normals,
1558 "normalize_tangents_bitangents"_a = TransformOptions().normalize_tangents_bitangents,
1559 "in_place"_a =
true,
1560 R
"(Apply affine transformation to a mesh.
1562:param mesh: Input mesh.
1563:param affine_transform: Affine transformation matrix.
1564:param normalize_normals: Whether to normalize normals.
1565:param normalize_tangents_bitangents: Whether to normalize tangents and bitangents.
1566:param in_place: Whether to apply transformation in place.
1568:returns: Transformed mesh if in_place is False.)");
1570 nb::enum_<DistortionMetric>(m, "DistortionMetric",
"Distortion metric.")
1574 "SymmetricDirichlet",
1576 "Symmetric Dirichlet energy")
1577 .value(
"AreaRatio", DistortionMetric::AreaRatio,
"Area ratio")
1581 "compute_uv_distortion",
1583 std::string_view uv_attribute_name,
1584 std::string_view output_attribute_name,
1586 UVDistortionOptions opt;
1587 opt.uv_attribute_name = uv_attribute_name;
1588 opt.output_attribute_name = output_attribute_name;
1589 opt.metric = metric;
1593 "uv_attribute_name"_a =
"@uv",
1594 "output_attribute_name"_a =
"@uv_measure",
1596 R
"(Compute UV distortion.
1598:param mesh: Input mesh.
1599:param uv_attribute_name: UV attribute name (default: "@uv").
1600:param output_attribute_name: Output attribute name (default: "@uv_measure").
1601:param metric: Distortion metric (default: MIPS).
1603:returns: Facet attribute ID for distortion.)");
1607 [](
const MeshType& mesh,
1608 std::variant<AttributeId, std::string_view> attribute,
1612 if (std::holds_alternative<AttributeId>(attribute)) {
1613 opt.attribute_id = std::get<AttributeId>(attribute);
1615 opt.attribute_id = mesh.
get_attribute_id(std::get<std::string_view>(attribute));
1617 opt.isovalue = isovalue;
1618 opt.keep_below = keep_below;
1623 "isovalue"_a = IsolineOptions().isovalue,
1624 "keep_below"_a = IsolineOptions().keep_below,
1625 R
"(Trim a triangle mesh by an isoline.
1627:param mesh: Input triangle mesh.
1628:param attribute: Attribute ID or name of scalar field (vertex or indexed).
1629:param isovalue: Isovalue to trim with.
1630:param keep_below: Whether to keep the part below the isoline.
1632:returns: Trimmed mesh.)");
1636 [](
const MeshType& mesh,
1637 std::variant<AttributeId, std::string_view> attribute,
1640 if (std::holds_alternative<AttributeId>(attribute)) {
1641 opt.attribute_id = std::get<AttributeId>(attribute);
1643 opt.attribute_id = mesh.
get_attribute_id(std::get<std::string_view>(attribute));
1645 opt.isovalue = isovalue;
1650 "isovalue"_a = IsolineOptions().isovalue,
1651 R
"(Extract the isoline of an implicit function defined on the mesh vertices/corners.
1653The input mesh must be a triangle mesh.
1655:param mesh: Input triangle mesh to extract the isoline from.
1656:param attribute: Attribute id or name of the scalar field to use. Can be a vertex or indexed attribute.
1657:param isovalue: Isovalue to extract.
1659:return: A mesh whose facets is a collection of size 2 elements representing the extracted isoline.)");
1663 "filter_attributes",
1665 std::optional<std::vector<AttributeNameOrId>> included_attributes,
1666 std::optional<std::vector<AttributeNameOrId>> excluded_attributes,
1667 std::optional<std::unordered_set<AttributeUsage>> included_usages,
1668 std::optional<std::unordered_set<AttributeElement>> included_element_types) {
1669 AttributeFilter filter;
1670 if (included_attributes.has_value()) {
1671 filter.included_attributes = included_attributes.value();
1673 if (excluded_attributes.has_value()) {
1674 filter.excluded_attributes = excluded_attributes.value();
1676 if (included_usages.has_value()) {
1677 filter.included_usages.clear_all();
1678 for (
auto usage : included_usages.value()) {
1679 filter.included_usages.set(usage);
1682 if (included_element_types.has_value()) {
1683 filter.included_element_types.clear_all();
1684 for (
auto element_type : included_element_types.value()) {
1685 filter.included_element_types.set(element_type);
1691 "included_attributes"_a = nb::none(),
1692 "excluded_attributes"_a = nb::none(),
1693 "included_usages"_a = nb::none(),
1694 "included_element_types"_a = nb::none(),
1695 R
"(Filters the attributes of mesh according to user specifications.
1697:param mesh: Input mesh.
1698:param included_attributes: List of attribute names or ids to include. By default, all attributes are included.
1699:param excluded_attributes: List of attribute names or ids to exclude. By default, no attribute is excluded.
1700:param included_usages: List of attribute usages to include. By default, all usages are included.
1701:param included_element_types: List of attribute element types to include. By default, all element types are included.)");
1706 std::variant<AttributeId, std::string_view> input_attribute,
1707 nb::type_object dtype,
1708 std::optional<std::string_view> output_attribute_name) {
1711 auto np = nb::module_::import_(
"numpy");
1712 if (output_attribute_name.has_value()) {
1713 auto name = output_attribute_name.value();
1714 if (dtype.is(&PyFloat_Type)) {
1717 }
else if (dtype.is(&PyLong_Type)) {
1720 }
else if (dtype.is(np.attr(
"float32"))) {
1722 }
else if (dtype.is(np.attr(
"float64"))) {
1724 }
else if (dtype.is(np.attr(
"int8"))) {
1726 }
else if (dtype.is(np.attr(
"int16"))) {
1728 }
else if (dtype.is(np.attr(
"int32"))) {
1730 }
else if (dtype.is(np.attr(
"int64"))) {
1732 }
else if (dtype.is(np.attr(
"uint8"))) {
1734 }
else if (dtype.is(np.attr(
"uint16"))) {
1736 }
else if (dtype.is(np.attr(
"uint32"))) {
1738 }
else if (dtype.is(np.attr(
"uint64"))) {
1741 throw nb::type_error(
"Unsupported `dtype`!");
1744 if (dtype.is(&PyFloat_Type)) {
1747 }
else if (dtype.is(&PyLong_Type)) {
1750 }
else if (dtype.is(np.attr(
"float32"))) {
1752 }
else if (dtype.is(np.attr(
"float64"))) {
1754 }
else if (dtype.is(np.attr(
"int8"))) {
1756 }
else if (dtype.is(np.attr(
"int16"))) {
1758 }
else if (dtype.is(np.attr(
"int32"))) {
1760 }
else if (dtype.is(np.attr(
"int64"))) {
1762 }
else if (dtype.is(np.attr(
"uint8"))) {
1764 }
else if (dtype.is(np.attr(
"uint16"))) {
1766 }
else if (dtype.is(np.attr(
"uint32"))) {
1768 }
else if (dtype.is(np.attr(
"uint64"))) {
1771 throw nb::type_error(
"Unsupported `dtype`!");
1776 if (std::holds_alternative<AttributeId>(input_attribute)) {
1777 return cast(std::get<AttributeId>(input_attribute));
1784 "input_attribute"_a,
1786 "output_attribute_name"_a = nb::none(),
1787 R
"(Cast an attribute to a new dtype.
1789:param mesh: The input mesh.
1790:param input_attribute: The input attribute id or name.
1791:param dtype: The new dtype.
1792:param output_attribute_name: The output attribute name. If none, cast will replace the input attribute.
1794:returns: The id of the new attribute.)");
1797 "compute_mesh_covariance",
1799 std::array<Scalar, 3> center,
1800 std::optional<std::string_view> active_facets_attribute_name)
1801 -> std::array<std::array<Scalar, 3>, 3> {
1802 MeshCovarianceOptions options;
1803 options.center = center;
1804 options.active_facets_attribute_name = active_facets_attribute_name;
1809 "active_facets_attribute_name"_a = nb::none(),
1810 R
"(Compute the covariance matrix of a mesh w.r.t. a center (Pythonic API).
1812:param mesh: Input mesh.
1813:param center: The center of the covariance computation.
1814:param active_facets_attribute_name: (optional) Attribute name of whether a facet should be considered in the computation.
1816:returns: The 3 by 3 covariance matrix, which should be symmetric.)");
1819 "select_facets_by_normal_similarity",
1821 Index seed_facet_id,
1822 std::optional<double> flood_error_limit,
1823 std::optional<double> flood_second_to_first_order_limit_ratio,
1824 std::optional<std::string_view> facet_normal_attribute_name,
1825 std::optional<std::string_view> is_facet_selectable_attribute_name,
1826 std::optional<std::string_view> output_attribute_name,
1827 std::optional<std::string_view> search_type,
1828 std::optional<int> num_smooth_iterations) {
1830 SelectFacetsByNormalSimilarityOptions options;
1831 if (flood_error_limit.has_value())
1832 options.flood_error_limit = flood_error_limit.value();
1833 if (flood_second_to_first_order_limit_ratio.has_value())
1834 options.flood_second_to_first_order_limit_ratio =
1835 flood_second_to_first_order_limit_ratio.value();
1836 if (facet_normal_attribute_name.has_value())
1837 options.facet_normal_attribute_name = facet_normal_attribute_name.value();
1838 if (is_facet_selectable_attribute_name.has_value()) {
1839 options.is_facet_selectable_attribute_name = is_facet_selectable_attribute_name;
1841 if (output_attribute_name.has_value())
1842 options.output_attribute_name = output_attribute_name.value();
1843 if (search_type.has_value()) {
1844 if (search_type.value() ==
"BFS")
1846 else if (search_type.value() ==
"DFS")
1849 throw std::runtime_error(
1850 fmt::format(
"Invalid search type: {}", search_type.value()));
1852 if (num_smooth_iterations.has_value())
1853 options.num_smooth_iterations = num_smooth_iterations.value();
1859 "flood_error_limit"_a = nb::none(),
1860 "flood_second_to_first_order_limit_ratio"_a = nb::none(),
1861 "facet_normal_attribute_name"_a = nb::none(),
1862 "is_facet_selectable_attribute_name"_a = nb::none(),
1863 "output_attribute_name"_a = nb::none(),
1864 "search_type"_a = nb::none(),
1865 "num_smooth_iterations"_a = nb::none(),
1866 R
"(Select facets by normal similarity (Pythonic API).
1868:param mesh: Input mesh.
1869:param seed_facet_id: Index of the seed facet.
1870:param flood_error_limit: Tolerance for normals of the seed and the selected facets. Higher limit leads to larger selected region.
1871:param flood_second_to_first_order_limit_ratio: Ratio of the flood_error_limit and the tolerance for normals of neighboring selected facets. Higher ratio leads to more curvature in selected region.
1872:param facet_normal_attribute_name: Attribute name of the facets normal. If the mesh doesn't have this attribute, it will call compute_facet_normal to compute it.
1873:param is_facet_selectable_attribute_name: If provided, this function will look for this attribute to determine if a facet is selectable.
1874:param output_attribute_name: Attribute name of whether a facet is selected.
1875:param search_type: Use 'BFS' for breadth-first search or 'DFS' for depth-first search.
1876:param num_smooth_iterations: Number of iterations to smooth the boundary of the selected region.
1878:returns: Id of the attribute on whether a facet is selected.)",
1880 "def select_facets_by_normal_similarity(mesh: SurfaceMesh, "
1881 "seed_facet_id: int, "
1882 "flood_error_limit: float | None = None, "
1883 "flood_second_to_first_order_limit_ratio: float | None = None, "
1884 "facet_normal_attribute_name: str | None = None, "
1885 "is_facet_selectable_attribute_name: str | None = None, "
1886 "output_attribute_name: str | None = None, "
1887 "search_type: typing.Literal['BFS', 'DFS'] | None = None,"
1888 "num_smooth_iterations: int | None = None) -> int"));
1891 "select_facets_in_frustum",
1893 std::array<std::array<Scalar, 3>, 4> frustum_plane_points,
1894 std::array<std::array<Scalar, 3>, 4> frustum_plane_normals,
1895 std::optional<bool> greedy,
1896 std::optional<std::string_view> output_attribute_name) {
1898 Frustum<Scalar> frustum;
1899 for (
size_t i = 0; i < 4; ++i) {
1900 frustum.planes[i].point = frustum_plane_points[i];
1901 frustum.planes[i].normal = frustum_plane_normals[i];
1903 FrustumSelectionOptions options;
1904 if (greedy.has_value()) options.greedy = greedy.value();
1905 if (output_attribute_name.has_value())
1906 options.output_attribute_name = output_attribute_name.value();
1911 "frustum_plane_points"_a,
1912 "frustum_plane_normals"_a,
1913 "greedy"_a = nb::none(),
1914 "output_attribute_name"_a = nb::none(),
1915 R
"(Select facets in a frustum (Pythonic API).
1917:param mesh: Input mesh.
1918:param frustum_plane_points: Four points on each of the frustum planes.
1919:param frustum_plane_normals: Four normals of each of the frustum planes.
1920:param greedy: If true, the function returns as soon as the first facet is found.
1921:param output_attribute_name: Attribute name of whether a facet is selected.
1923:returns: Whether any facets got selected.)");
1926 "thicken_and_close_mesh",
1928 std::optional<Scalar> offset_amount,
1929 std::variant<std::monostate, std::array<double, 3>, std::string_view> direction,
1930 std::optional<double> mirror_ratio,
1931 std::optional<size_t> num_segments,
1932 std::optional<std::vector<std::string>> indexed_attributes) {
1933 ThickenAndCloseOptions options;
1935 if (
auto array_val = std::get_if<std::array<double, 3>>(&direction)) {
1936 options.direction = *array_val;
1937 }
else if (
auto string_val = std::get_if<std::string_view>(&direction)) {
1938 options.direction = *string_val;
1940 options.offset_amount = offset_amount.value_or(options.offset_amount);
1941 options.mirror_ratio = std::move(mirror_ratio);
1942 options.num_segments = num_segments.value_or(options.num_segments);
1943 options.indexed_attributes = indexed_attributes.value_or(options.indexed_attributes);
1948 "offset_amount"_a = nb::none(),
1949 "direction"_a = nb::none(),
1950 "mirror_ratio"_a = nb::none(),
1951 "num_segments"_a = nb::none(),
1952 "indexed_attributes"_a = nb::none(),
1953 R
"(Thicken a mesh by offsetting it, and close the shape into a thick 3D solid.
1955:param mesh: Input mesh.
1956:param direction: Direction of the offset. Can be an attribute name or a fixed 3D vector.
1957:param offset_amount: Amount of offset.
1958:param mirror_ratio: Ratio of the offset amount to mirror the mesh.
1959:param num_segments: Number of segments to use for the thickening.
1960:param indexed_attributes: List of indexed attributes to copy to the new mesh.
1962:returns: The thickened and closed mesh.)");
1965 "extract_boundary_loops",
1968 R
"(Extract boundary loops from a mesh.
1970:param mesh: Input mesh.
1972:returns: A list of boundary loops, each represented as a list of vertex indices.)");
1975 "extract_boundary_edges",
1976 [](MeshType& mesh) {
1979 std::vector<Index> bd_edges;
1980 bd_edges.reserve(num_edges);
1981 for (Index ei = 0; ei < num_edges; ++ei) {
1983 bd_edges.push_back(ei);
1989 R
"(Extract boundary edges from a mesh.
1991:param mesh: Input mesh.
1993:returns: A list of boundary edge indices.)");
1996 "compute_uv_charts",
1998 std::string_view uv_attribute_name,
1999 std::string_view output_attribute_name,
2000 std::string_view connectivity_type) {
2001 UVChartOptions options;
2002 options.uv_attribute_name = uv_attribute_name;
2003 options.output_attribute_name = output_attribute_name;
2004 if (connectivity_type ==
"Vertex") {
2005 options.connectivity_type = UVChartOptions::ConnectivityType::Vertex;
2006 }
else if (connectivity_type ==
"Edge") {
2007 options.connectivity_type = UVChartOptions::ConnectivityType::Edge;
2009 throw std::runtime_error(
2010 fmt::format(
"Invalid connectivity type: {}", connectivity_type));
2015 "uv_attribute_name"_a = UVChartOptions().uv_attribute_name,
2016 "output_attribute_name"_a = UVChartOptions().output_attribute_name,
2017 "connectivity_type"_a =
"Edge",
2018 R
"(Compute UV charts.
2020@param mesh: Input mesh.
2021@param uv_attribute_name: Name of the UV attribute.
2022@param output_attribute_name: Name of the output attribute to store the chart ids.
2023@param connectivity_type: Type of connectivity to use for chart computation. Can be "Vertex" or "Edge".
2025@returns: A list of chart ids for each vertex.)");
2029 [](
const MeshType& mesh, std::string_view uv_attribute_name) {
2030 UVMeshOptions options;
2031 options.uv_attribute_name = uv_attribute_name;
2035 "uv_attribute_name"_a = UVMeshOptions().uv_attribute_name,
2036 R
"(Extract a UV mesh view from a 3D mesh.
2038:param mesh: Input mesh.
2039:param uv_attribute_name: Name of the (indexed or vertex) UV attribute.
2041:return: A new mesh representing the UV mesh.)");
2044 [](MeshType& mesh, std::string_view uv_attribute_name) {
2045 UVMeshOptions options;
2046 options.uv_attribute_name = uv_attribute_name;
2050 "uv_attribute_name"_a = UVMeshOptions().uv_attribute_name,
2051 R
"(Extract a UV mesh reference from a 3D mesh.
2053:param mesh: Input mesh.
2054:param uv_attribute_name: Name of the (indexed or vertex) UV attribute.
2056:return: A new mesh representing the UV mesh.)");
2059 "split_facets_by_material",
2062 "material_attribute_name"_a,
2063 R
"(Split mesh facets based on a material attribute.
2065@param mesh: Input mesh on which material segmentation will be applied in place.
2066@param material_attribute_name: Name of the material attribute to use for inserting boundaries.
2068@note The material attribute should be n by k vertex attribute, where n is the number of vertices,
2069and k is the number of materials. The value at row i and column j indicates the probability of vertex
2070i belonging to material j. The function will insert boundaries between different materials based on
2071the material attribute.
bool is_boundary_edge(Index e) const
Determines whether the specified edge e is a boundary edge.
Definition SurfaceMesh.cpp:2621
Index get_dimension() const
Retrieves the dimension of the mesh vertices.
Definition SurfaceMesh.h:656
AttributeId get_attribute_id(std::string_view name) const
Retrieve an attribute id given its name.
Definition SurfaceMesh.cpp:345
Index get_num_edges() const
Retrieves the number of edges.
Definition SurfaceMesh.h:692
void initialize_edges(span< const Index > edges={})
Initializes attributes associated to mesh edges and connectivity.
Definition SurfaceMesh.cpp:2204
SurfaceMesh< Scalar, Index > unify_named_index_buffer(const SurfaceMesh< Scalar, Index > &mesh, const std::vector< std::string_view > &attribute_names)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition unify_index_buffer.cpp:277
AttributeId map_attribute_in_place(SurfaceMesh< Scalar, Index > &mesh, AttributeId id, AttributeElement new_element)
Map attribute values to a different element type.
Definition map_attribute.cpp:270
AttributeId map_attribute(SurfaceMesh< Scalar, Index > &mesh, AttributeId id, std::string_view new_name, AttributeElement new_element)
Map attribute values to a new attribute with a different element type.
Definition map_attribute.cpp:243
SurfaceMesh< Scalar, Index > unify_index_buffer(const SurfaceMesh< Scalar, Index > &mesh, const std::vector< AttributeId > &attribute_ids={})
Unify index buffers of the input mesh for all attributes specified in attribute_ids.
Definition unify_index_buffer.cpp:34
uint32_t AttributeId
Identified to be used to access an attribute.
Definition AttributeFwd.h:73
AttributeElement
Type of element to which the attribute is attached.
Definition AttributeFwd.h:26
@ Scalar
Mesh attribute must have exactly 1 channel.
Definition AttributeFwd.h:56
@ Facet
Per-facet mesh attributes.
Definition AttributeFwd.h:31
AttributeId compute_normal(SurfaceMesh< Scalar, Index > &mesh, function_ref< bool(Index)> is_edge_smooth, span< const Index > cone_vertices={}, NormalOptions options={})
Compute smooth normals based on specified sharp edges and cone vertices.
Definition compute_normal.cpp:198
SurfaceMesh< Scalar, Index > trim_by_isoline(const SurfaceMesh< Scalar, Index > &mesh, const IsolineOptions &options={})
Trim a mesh by the isoline of an implicit function defined on the mesh vertices/corners.
Definition isoline.cpp:325
AttributeId cast_attribute_in_place(SurfaceMesh< Scalar, Index > &mesh, AttributeId attribute_id)
Cast an attribute in place to a different value type.
Definition cast_attribute.cpp:68
bool is_closed(const SurfaceMesh< Scalar, Index > &mesh)
Check if a mesh is closed.
Definition topology.cpp:51
int compute_euler(const SurfaceMesh< Scalar, Index > &mesh)
Compute Euler characteristic of a mesh.
Definition topology.cpp:35
bool select_facets_in_frustum(SurfaceMesh< Scalar, Index > &mesh, const Frustum< Scalar > &frustum, const FrustumSelectionOptions &options={})
Select all facets that intersect the cone/frustrum bounded by 4 planes defined by (n_i,...
Definition select_facets_in_frustum.cpp:44
AttributeId compute_greedy_coloring(SurfaceMesh< Scalar, Index > &mesh, const GreedyColoringOptions &options={})
Compute a greedy graph coloring of the mesh.
Definition compute_greedy_coloring.cpp:153
SurfaceMesh< Scalar, Index > combine_meshes(std::initializer_list< const SurfaceMesh< Scalar, Index > * > meshes, bool preserve_attributes=true)
Combine multiple meshes into a single mesh.
Definition combine_meshes.cpp:295
std::vector< SurfaceMesh< Scalar, Index > > separate_by_facet_groups(const SurfaceMesh< Scalar, Index > &mesh, size_t num_groups, span< const Index > facet_group_indices, const SeparateByFacetGroupsOptions &options={})
Extract a set of submeshes based on facet groups.
Definition separate_by_facet_groups.cpp:29
bool is_oriented(const SurfaceMesh< Scalar, Index > &mesh)
Check if a mesh is oriented.
Definition orientation.cpp:57
bool is_manifold(const SurfaceMesh< Scalar, Index > &mesh)
Check if a mesh is both vertex-manifold and edge-manifold.
Definition topology.h:98
void permute_facets(SurfaceMesh< Scalar, Index > &mesh, span< const Index > new_to_old)
Reorder facets of a mesh based on a given permutation.
Definition permute_facets.cpp:26
AttributeId compute_facet_normal(SurfaceMesh< Scalar, Index > &mesh, FacetNormalOptions options={})
Compute facet normals.
Definition compute_facet_normal.cpp:34
bool is_edge_manifold(const SurfaceMesh< Scalar, Index > &mesh)
Check if a mesh is edge-manifold.
Definition topology.cpp:125
AttributeId compute_facet_area(SurfaceMesh< Scalar, Index > &mesh, FacetAreaOptions options={})
Compute per-facet area.
Definition compute_area.cpp:304
AttributeId compute_edge_lengths(SurfaceMesh< Scalar, Index > &mesh, const EdgeLengthOptions &options={})
Computes edge lengths attribute.
Definition compute_edge_lengths.cpp:28
AttributeId cast_attribute(SurfaceMesh< Scalar, Index > &mesh, AttributeId source_id, std::string_view target_name)
Cast an attribute in place to a different value type.
Definition cast_attribute.cpp:25
std::optional< std::vector< Index > > compute_dijkstra_distance(SurfaceMesh< Scalar, Index > &mesh, const DijkstraDistanceOptions< Scalar, Index > &options={})
Computes dijkstra distance from a seed facet.
Definition compute_dijkstra_distance.cpp:24
Scalar compute_mesh_area(const SurfaceMesh< Scalar, Index > &mesh, MeshAreaOptions options={})
Compute mesh area.
Definition compute_area.cpp:361
AttributeId compute_vertex_valence(SurfaceMesh< Scalar, Index > &mesh, VertexValenceOptions options={})
Compute vertex valence.
Definition compute_vertex_valence.cpp:25
SurfaceMesh< Scalar, Index > extract_submesh(const SurfaceMesh< Scalar, Index > &mesh, span< const Index > selected_facets, const SubmeshOptions &options={})
Extract a submesh that consists of a subset of the facets of the source mesh.
Definition extract_submesh.cpp:26
void normalize_mesh(SurfaceMesh< Scalar, Index > &mesh, const TransformOptions &options={})
Normalize a mesh to fit in a unit box centered at the origin.
Definition normalize_meshes.cpp:52
AttributeId compute_facet_vector_area(SurfaceMesh< Scalar, Index > &mesh, FacetVectorAreaOptions options={})
Compute per-facet vector area.
Definition compute_area.cpp:322
void remap_vertices(SurfaceMesh< Scalar, Index > &mesh, span< const Index > forward_mapping, RemapVerticesOptions options={})
Remap vertices of a mesh based on provided forward mapping.
Definition remap_vertices.cpp:138
void triangulate_polygonal_facets(SurfaceMesh< Scalar, Index > &mesh, const TriangulationOptions &options={})
Triangulate polygonal facets of a mesh using a prescribed set of rules.
Definition triangulate_polygonal_facets.cpp:520
auto normalize_mesh_with_transform(SurfaceMesh< Scalar, Index > &mesh, const TransformOptions &options={}) -> Eigen::Transform< Scalar, Dimension, Eigen::Affine >
Normalize a mesh to fit in a unit box centered at the origin.
Definition normalize_meshes.cpp:25
void permute_vertices(SurfaceMesh< Scalar, Index > &mesh, span< const Index > new_to_old)
Reorder vertices of a mesh based on a given permutation.
Definition permute_vertices.cpp:26
AttributeId compute_vertex_normal(SurfaceMesh< Scalar, Index > &mesh, VertexNormalOptions options={})
Compute per-vertex normals based on specified weighting type.
Definition compute_vertex_normal.cpp:34
bool is_vertex_manifold(const SurfaceMesh< Scalar, Index > &mesh)
Check if a mesh is vertex-manifold.
Definition topology.cpp:98
AttributeId compute_facet_centroid(SurfaceMesh< Scalar, Index > &mesh, FacetCentroidOptions options={})
Compute per-facet centroid.
Definition compute_centroid.cpp:31
std::vector< SurfaceMesh< Scalar, Index > > separate_by_components(const SurfaceMesh< Scalar, Index > &mesh, const SeparateByComponentsOptions &options={})
Separate a mesh by connected components.
Definition separate_by_components.cpp:21
AttributeId select_facets_by_normal_similarity(SurfaceMesh< Scalar, Index > &mesh, const Index seed_facet_id, const SelectFacetsByNormalSimilarityOptions &options={})
Given a seed facet, selects facets around it based on the change in triangle normals.
Definition select_facets_by_normal_similarity.cpp:27
std::vector< std::vector< Index > > extract_boundary_loops(const SurfaceMesh< Scalar, Index > &mesh)
Extract boundary loops from a surface mesh.
Definition extract_boundary_loops.cpp:24
AttributeId compute_dihedral_angles(SurfaceMesh< Scalar, Index > &mesh, const DihedralAngleOptions &options={})
Computes dihedral angles for each edge in the mesh.
Definition compute_dihedral_angles.cpp:33
SurfaceMesh< ToScalar, ToIndex > cast(const SurfaceMesh< FromScalar, FromIndex > &source_mesh, const AttributeFilter &convertible_attributes={}, std::vector< std::string > *converted_attributes_names=nullptr)
Cast a mesh to a mesh of different scalar and/or index type.
TangentBitangentResult compute_tangent_bitangent(SurfaceMesh< Scalar, Index > &mesh, TangentBitangentOptions options={})
Compute mesh tangent and bitangent vectors orthogonal to the input mesh normals.
Definition compute_tangent_bitangent.cpp:534
SurfaceMesh< Scalar, Index > transformed_mesh(SurfaceMesh< Scalar, Index > mesh, const Eigen::Transform< Scalar, Dimension, Eigen::Affine > &transform, const TransformOptions &options={})
Apply an affine transform to a mesh and return the transformed mesh.
Definition transform_mesh.cpp:207
SurfaceMesh< Scalar, Index > filter_attributes(SurfaceMesh< Scalar, Index > source_mesh, const AttributeFilter &options={})
Filters the attributes of mesh according to user specifications.
Definition filter_attributes.cpp:116
void normalize_meshes(span< SurfaceMesh< Scalar, Index > * > meshes, const TransformOptions &options={})
Normalize a list of meshes to fit in a unit box centered at the origin.
Definition normalize_meshes.cpp:102
void transform_mesh(SurfaceMesh< Scalar, Index > &mesh, const Eigen::Transform< Scalar, Dimension, Eigen::Affine > &transform, const TransformOptions &options={})
Apply an affine transform to a mesh in-place.
Definition transform_mesh.cpp:198
AttributeId compute_uv_distortion(SurfaceMesh< Scalar, Index > &mesh, const UVDistortionOptions &options={})
Compute uv distortion using the selected distortion measure.
Definition compute_uv_distortion.cpp:31
DistortionMetric
UV distortion metric type.
Definition DistortionMetric.h:26
void compute_mesh_centroid(const SurfaceMesh< Scalar, Index > &mesh, span< Scalar > centroid, MeshCentroidOptions options={})
Compute mesh centroid, where mesh centroid is defined as the weighted sum of facet centroids.
Definition compute_centroid.cpp:74
size_t compute_components(SurfaceMesh< Scalar, Index > &mesh, ComponentOptions options={})
Compute connected components of an input mesh.
Definition compute_components.cpp:99
SurfaceMesh< Scalar, Index > extract_isoline(const SurfaceMesh< Scalar, Index > &mesh, const IsolineOptions &options={})
Extract the isoline of an implicit function defined on the mesh vertices/corners.
Definition isoline.cpp:333
auto normalize_meshes_with_transform(span< SurfaceMesh< Scalar, Index > * > meshes, const TransformOptions &options={}) -> Eigen::Transform< Scalar, Dimension, Eigen::Affine >
Normalize a list of meshes to fit in a unit box centered at the origin.
Definition normalize_meshes.cpp:62
@ Angle
Incident face normals are averaged weighted by incident angle of vertex.
Definition NormalWeightingType.h:36
@ CornerTriangleArea
Incident face normals are averaged weighted by area of the corner triangle.
Definition NormalWeightingType.h:33
@ Uniform
Incident face normals have uniform influence on vertex normal.
Definition NormalWeightingType.h:29
@ MIPS
UV triangle area / 3D triangle area.
Definition DistortionMetric.h:31
@ InverseDirichlet
Inverse Dirichlet energy.
Definition DistortionMetric.h:28
@ SymmetricDirichlet
Symmetric Dirichlet energy.
Definition DistortionMetric.h:29
@ Dirichlet
Dirichlet energy.
Definition DistortionMetric.h:27
#define la_runtime_assert(...)
Runtime assertion check.
Definition assert.h:174
::nonstd::span< T, Extent > span
A bounds-safe view for sequences of objects.
Definition span.h:27
constexpr T invalid()
You can use invalid<T>() to get a value that can represent "invalid" values, such as invalid indices ...
Definition invalid.h:40
void map_attributes(const SurfaceMesh< Scalar, Index > &source_mesh, SurfaceMesh< Scalar, Index > &target_mesh, span< const Index > mapping_data, span< const Index > mapping_offsets={}, const MapAttributesOptions &options={})
Map attributes from the source mesh to the target mesh.
Definition map_attributes.cpp:26
std::array< std::array< Scalar, 3 >, 3 > compute_mesh_covariance(const SurfaceMesh< Scalar, Index > &mesh, const MeshCovarianceOptions &options={})
Compute the covariance matrix w.r.t.
Definition compute_mesh_covariance.cpp:98
SurfaceMesh< Scalar, Index > uv_mesh_view(const SurfaceMesh< Scalar, Index > &mesh, const UVMeshOptions &options={})
Extract a UV mesh view from an input mesh.
Definition uv_mesh.cpp:51
size_t compute_uv_charts(SurfaceMesh< Scalar, Index > &mesh, const UVChartOptions &options={})
Compute UV charts of an input mesh.
Definition compute_uv_charts.cpp:23
ConnectivityType
This type defines the condition when two facets are considered as "connected".
Definition ConnectivityType.h:19
@ Edge
Two facets are considered connected if they share an edge.
Definition ConnectivityType.h:21
ReorderingMethod
Mesh reordering method to apply before decimation.
Definition reorder_mesh.h:21
@ Lexicographic
Sort vertices/facets lexicographically.
Definition reorder_mesh.h:22
@ None
Do not reorder mesh vertices/facets.
Definition reorder_mesh.h:25
@ Hilbert
Spatial sort vertices/facets using Hilbert curve.
Definition reorder_mesh.h:24
@ Morton
Spatial sort vertices/facets using Morton encoding.
Definition reorder_mesh.h:23
SurfaceMesh< Scalar, Index > thicken_and_close_mesh(SurfaceMesh< Scalar, Index > input_mesh, const ThickenAndCloseOptions &options={})
Thicken a mesh by offsetting it, and close the shape into a thick 3D solid.
Definition thicken_and_close_mesh.cpp:270
void orient_outward(lagrange::SurfaceMesh< Scalar, Index > &mesh, const OrientOptions &options={})
Orient the facets of a mesh so that the signed volume of each connected component is positive or nega...
Definition orient_outward.cpp:126
void split_facets_by_material(SurfaceMesh< Scalar, Index > &mesh, std::string_view material_attribute_name)
Split mesh facets based on material labels.
Definition split_facets_by_material.cpp:57
PointcloudPCAOutput< Scalar > compute_pointcloud_pca(span< const Scalar > points, ComputePointcloudPCAOptions options={})
Finds the principal components for a pointcloud.
Definition compute_pointcloud_pca.cpp:23
AttributeId compute_facet_circumcenter(SurfaceMesh< Scalar, Index > &mesh, FacetCircumcenterOptions options={})
Compute per-facet circumcenter.
Definition compute_facet_circumcenter.cpp:32
SurfaceMesh< Scalar, Index > uv_mesh_ref(SurfaceMesh< Scalar, Index > &mesh, const UVMeshOptions &options={})
Extract a UV mesh reference from an input mesh.
Definition uv_mesh.cpp:21
AttributeId compute_seam_edges(SurfaceMesh< Scalar, Index > &mesh, AttributeId indexed_attribute_id, const SeamEdgesOptions &options={})
Computes the seam edges for a given indexed attribute.
Definition compute_seam_edges.cpp:35
@ KeepFirst
Keep the value of the first elements.
Definition MappingPolicy.h:23
@ Error
Throw an error if collision is detected.
Definition MappingPolicy.h:24
@ Average
Take the average of all involved elements.
Definition MappingPolicy.h:22
void reorder_mesh(SurfaceMesh< Scalar, Index > &mesh, ReorderingMethod method)
Mesh reordering to improve cache locality.
Definition reorder_mesh.cpp:178
std::variant< AttributeId, std::string > AttributeNameOrId
Variant identifying an attribute by its name or id.
Definition filter_attributes.h:39
ConnectivityType connectivity_type
Connectivity type used for component computation.
Definition compute_components.h:38
std::string_view output_attribute_name
Output component id attribute name.
Definition compute_components.h:35
std::string_view output_attribute_name
Output attribute name for facet area.
Definition compute_area.h:34
std::string_view output_attribute_name
Ouptut facet centroid attribute name.
Definition compute_centroid.h:33
std::string_view output_attribute_name
Output normal attribute name.
Definition compute_facet_normal.h:35
std::string_view input_attribute_name
Precomputed facet area attribute name.
Definition compute_area.h:119
bool use_signed_area
For 2D mesh only: whether the computed facet area (if any) should be signed.
Definition compute_area.h:122
std::string_view facet_centroid_attribute_name
Precomputed facet centroid attribute name.
Definition compute_centroid.h:66
@ Area
Per-facet centroid are weighted by facet area.
Definition compute_centroid.h:61
@ Uniform
Per-facet centroid are weighted uniformly.
Definition compute_centroid.h:60
std::string_view facet_area_attribute_name
Precomputed facet area attribute name.
Definition compute_centroid.h:70
bool keep_facet_normals
Whether to keep any newly added facet normal attribute.
Definition compute_normal.h:55
std::string_view facet_normal_attribute_name
Precomputed facet normal attribute name.
Definition compute_normal.h:48
bool recompute_facet_normals
Whether to recompute the facet normal attribute, or reuse existing cached values if present.
Definition compute_normal.h:51
std::string_view output_attribute_name
Output normal attribute name.
Definition compute_normal.h:41
float distance_tolerance
Tolerance for degenerate edge check. (only used to bypass degenerate edges in polygon facets)
Definition compute_normal.h:58
NormalWeightingType weight_type
Per-vertex normal averaging weighting type.
Definition compute_normal.h:44
CollisionPolicy collision_policy_integral
Collision policy for integral valued attributes.
Definition remap_vertices.h:39
CollisionPolicy collision_policy_float
Collision policy for float or double valued attributes.
Definition remap_vertices.h:36
@ BFS
Breadth-First Search.
Definition select_facets_by_normal_similarity.h:62
@ DFS
Depth-First Search.
Definition select_facets_by_normal_similarity.h:63
std::string_view bitangent_attribute_name
Output bitangent attribute name.
Definition compute_tangent_bitangent.h:41
bool keep_existing_tangent
Whether to recompute tangent if the tangent attribute (specified by tangent_attribute_name) already e...
Definition compute_tangent_bitangent.h:70
std::string_view normal_attribute_name
Normal attribute name used to compute the BTN frame.
Definition compute_tangent_bitangent.h:52
std::string_view tangent_attribute_name
Output tangent attribute name.
Definition compute_tangent_bitangent.h:38
AttributeElement output_element_type
Output element type. Can be either Corner or Indexed.
Definition compute_tangent_bitangent.h:55
bool pad_with_sign
Whether to pad the tangent/bitangent vectors with a 4th coordinate indicating the sign of the UV tria...
Definition compute_tangent_bitangent.h:59
bool orthogonalize_bitangent
Whether to compute the bitangent as sign * cross(normal, tangent) If false, the bitangent is computed...
Definition compute_tangent_bitangent.h:63
std::string_view uv_attribute_name
UV attribute name used to orient the BTN frame.
Definition compute_tangent_bitangent.h:45
AttributeId tangent_id
Tangent vector attribute id.
Definition compute_tangent_bitangent.h:77
AttributeId bitangent_id
Bitangent vector attribute id.
Definition compute_tangent_bitangent.h:80
@ Earcut
Use earcut algorithm to triangulate polygons.
Definition triangulate_polygonal_facets.h:31
@ CentroidFan
Connect facet centroid to polygon edges to form a fan of triangles.
Definition triangulate_polygonal_facets.h:32
Scheme scheme
Triangulation scheme to use.
Definition triangulate_polygonal_facets.h:35
bool keep_weighted_corner_normals
Whether to keep any newly added weighted corner normal attribute.
Definition compute_vertex_normal.h:56
std::string_view weighted_corner_normal_attribute_name
Precomputed weighted corner attribute name.
Definition compute_vertex_normal.h:47
std::string_view output_attribute_name
Output normal attribute name.
Definition compute_vertex_normal.h:39
float distance_tolerance
Tolerance for degenerate edge check. (only used to bypass degenerate edges in polygon facets)
Definition compute_vertex_normal.h:59
bool recompute_weighted_corner_normals
Whether to recompute the weighted corner normal attribute, or reuse existing cached values if present...
Definition compute_vertex_normal.h:51
NormalWeightingType weight_type
Per-vertex normal averaging weighting type.
Definition compute_vertex_normal.h:42
std::string_view induced_by_attribute
Optional per-edge attribute used as indicator function to restrict the graph used for vertex valence ...
Definition compute_vertex_valence.h:39
std::string_view output_attribute_name
Output vertex valence attribute name.
Definition compute_vertex_valence.h:42