Lagrange
eigen_convert.h
1/*
2 * Copyright 2024 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#include <Eigen/Core>
18
19namespace lagrange {
27
45template <typename Scalar, typename Index, typename DerivedV, typename DerivedF>
47 const Eigen::MatrixBase<DerivedV>& V,
48 const Eigen::MatrixBase<DerivedF>& F)
49{
50 SurfaceMesh<Scalar, Index> mesh(static_cast<Index>(V.cols()));
51 mesh.add_vertices(static_cast<Index>(V.rows()));
52 mesh.add_polygons(static_cast<Index>(F.rows()), static_cast<Index>(F.cols()));
53 vertex_ref(mesh) = V.template cast<Scalar>();
54 facet_ref(mesh) = F.template cast<Index>();
55 return mesh;
56}
57
59} // namespace lagrange
60
SurfaceMesh< Scalar, Index > eigen_to_surface_mesh(const Eigen::MatrixBase< DerivedV > &V, const Eigen::MatrixBase< DerivedF > &F)
Create a SurfaceMesh from a igl-style pair of matrices (V, F).
Definition: eigen_convert.h:46
RowMatrixView< Scalar > vertex_ref(SurfaceMesh< Scalar, Index > &mesh)
Returns a writable view of the mesh vertices in the form of an Eigen matrix.
Definition: views.cpp:150
RowMatrixView< Index > facet_ref(SurfaceMesh< Scalar, Index > &mesh)
Returns a writable view of a mesh facets in the form of an Eigen matrix.
Definition: views.cpp:162
Main namespace for Lagrange.
Definition: AABBIGL.h:30