Lagrange
Loading...
Searching...
No Matches
geometry_central_utils.h
1/*
2 * Copyright 2025 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/SurfaceMesh.h>
15#include <lagrange/views.h>
16
17// clang-format off
18#include <lagrange/utils/warnoff.h>
19#include <geometrycentral/surface/manifold_surface_mesh.h>
20#include <geometrycentral/surface/vertex_position_geometry.h>
21#include <geometrycentral/surface/surface_point.h>
22#include <lagrange/utils/warnon.h>
23// clang-format on
24
25#include <memory>
26
27namespace lagrange::geodesic::gc {
28
29using gcSurfaceMesh = geometrycentral::surface::SurfaceMesh;
30using gcManifoldMesh = geometrycentral::surface::ManifoldSurfaceMesh;
31using gcGeometry = geometrycentral::surface::VertexPositionGeometry;
32using gcSurfacePoint = geometrycentral::surface::SurfacePoint;
33
34template <typename Scalar, typename Index>
35std::tuple<std::unique_ptr<gcSurfaceMesh>, std::unique_ptr<gcGeometry>> extract_gc_mesh(
36 SurfaceMesh<Scalar, Index>& mesh)
37{
38 auto vertices = vertex_view(mesh);
39 auto facets = facet_view(mesh);
40 auto gc_mesh = std::make_unique<gcSurfaceMesh>(facets);
41 auto gc_geom = std::make_unique<gcGeometry>(*gc_mesh, vertices);
42 return std::make_tuple(std::move(gc_mesh), std::move(gc_geom));
43}
44
45template <typename Scalar, typename Index>
46std::tuple<std::unique_ptr<gcManifoldMesh>, std::unique_ptr<gcGeometry>> extract_gc_manifold_mesh(
47 SurfaceMesh<Scalar, Index>& mesh)
48{
49 auto vertices = vertex_view(mesh);
50 auto facets = facet_view(mesh);
51 auto gc_mesh = std::make_unique<gcManifoldMesh>(facets);
52 auto gc_geom = std::make_unique<gcGeometry>(*gc_mesh, vertices);
53 return std::make_tuple(std::move(gc_mesh), std::move(gc_geom));
54}
55
56} // namespace lagrange::geodesic::gc
ConstRowMatrixView< Scalar > vertex_view(const SurfaceMesh< Scalar, Index > &mesh)
Returns a read-only view of the mesh vertices in the form of an Eigen matrix.
Definition views.cpp:156
ConstRowMatrixView< Index > facet_view(const SurfaceMesh< Scalar, Index > &mesh)
Returns a read-only view of a mesh facets in the form of an Eigen matrix.
Definition views.cpp:170