Lagrange
create_mesh.h
1/*
2 * Copyright 2016 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/ActingMeshGeometry.h>
15#include <lagrange/GenuineMeshGeometry.h>
16#include <lagrange/Mesh.h>
17#include <lagrange/MeshGeometry.h>
18#include <lagrange/common.h>
19
20namespace lagrange {
21
22template <typename DerivedV, typename DerivedF>
23std::unique_ptr<Mesh<DerivedV, DerivedF>> create_empty_mesh()
24{
25 DerivedV vertices;
26 DerivedF facets;
27
28 auto geometry = std::make_unique<GenuineMeshGeometry<DerivedV, DerivedF>>(vertices, facets);
29 return std::make_unique<Mesh<DerivedV, DerivedF>>(std::move(geometry));
30}
31
32
38template <typename DerivedV, typename DerivedF>
40 const Eigen::MatrixBase<DerivedV>& vertices,
41 const Eigen::MatrixBase<DerivedF>& facets)
42{
43 using VertexArray = Eigen::Matrix<
44 typename DerivedV::Scalar,
45 DerivedV::RowsAtCompileTime,
46 DerivedV::ColsAtCompileTime,
47 Eigen::AutoAlign |
48 (DerivedV::Flags & Eigen::RowMajorBit ? Eigen::RowMajor : Eigen::ColMajor)>;
49 using FacetArray = Eigen::Matrix<
50 typename DerivedF::Scalar,
51 DerivedF::RowsAtCompileTime,
52 DerivedF::ColsAtCompileTime,
53 Eigen::AutoAlign |
54 (DerivedF::Flags & Eigen::RowMajorBit ? Eigen::RowMajor : Eigen::ColMajor)>;
55 auto geometry = std::make_unique<GenuineMeshGeometry<VertexArray, FacetArray>>(
56 vertices.derived(),
57 facets.derived());
58 return std::make_unique<Mesh<VertexArray, FacetArray>>(std::move(geometry));
59}
60
66template <typename DerivedV, typename DerivedF>
67std::unique_ptr<Mesh<DerivedV, DerivedF>> create_mesh(
68 Eigen::PlainObjectBase<DerivedV>&& vertices,
69 Eigen::PlainObjectBase<DerivedF>&& facets)
70{
71 auto geometry = std::make_unique<GenuineMeshGeometry<DerivedV, DerivedF>>();
72 geometry->import_vertices(vertices);
73 geometry->import_facets(facets);
74 return std::make_unique<Mesh<DerivedV, DerivedF>>(std::move(geometry));
75}
76
77template <typename DerivedV, typename DerivedF>
78std::unique_ptr<Mesh<DerivedV, DerivedF>> create_mesh(
79 const Eigen::MatrixBase<DerivedV>& vertices,
80 Eigen::MatrixBase<DerivedF>&& facets)
81{
82 auto geometry = std::make_unique<GenuineMeshGeometry<DerivedV, DerivedF>>();
83 DerivedV vertices_copy = vertices;
84 geometry->import_vertices(vertices_copy);
85 geometry->import_facets(facets);
86 return std::make_unique<Mesh<DerivedV, DerivedF>>(std::move(geometry));
87}
88
89template <typename DerivedV, typename DerivedF>
90std::unique_ptr<Mesh<DerivedV, DerivedF>> create_mesh(
91 Eigen::MatrixBase<DerivedV>&& vertices,
92 const Eigen::MatrixBase<DerivedF>& facets)
93{
94 auto geometry = std::make_unique<GenuineMeshGeometry<DerivedV, DerivedF>>();
95 DerivedF facets_copy = facets;
96 geometry->import_vertices(vertices);
97 geometry->import_facets(facets_copy);
98 return std::make_unique<Mesh<DerivedV, DerivedF>>(std::move(geometry));
99}
100
108template <typename VertexArray, typename FacetArray>
110 const Eigen::MatrixBase<VertexArray>& vertices,
111 const Eigen::MatrixBase<FacetArray>& facets)
112{
114
115 auto geometry = std::make_unique<ActingMeshGeometry<VertexArray, FacetArray>>(
116 vertices.derived(),
117 facets.derived());
118 return std::make_unique<MeshType>(std::move(geometry));
119}
120
121// Prevent user from wrapping Mesh around temp variables.
122template <typename VertexArray, typename FacetArray>
123void wrap_with_mesh(
124 const Eigen::MatrixBase<VertexArray>&& /*vertices*/,
125 const Eigen::MatrixBase<FacetArray>&& /*facets*/)
126{
127 static_assert(
128 StaticAssertableBool<VertexArray, FacetArray>::False,
129 "vertices and facets cannot be rvalues");
130}
131template <typename VertexArray, typename FacetArray>
132void wrap_with_mesh(
133 const Eigen::MatrixBase<VertexArray>& /*vertices*/,
134 const Eigen::MatrixBase<FacetArray>&& /*facets*/)
135{
136 static_assert(
137 StaticAssertableBool<VertexArray, FacetArray>::False,
138 "facets cannot be an rvalue");
139}
140template <typename VertexArray, typename FacetArray>
141void wrap_with_mesh(
142 const Eigen::MatrixBase<VertexArray>&& /*vertices*/,
143 const Eigen::MatrixBase<FacetArray>& /*facets*/)
144{
145 static_assert(
146 StaticAssertableBool<VertexArray, FacetArray>::False,
147 "vertices cannot be an rvalue");
148}
149
150std::unique_ptr<TriangleMesh3D> LA_CORE_API create_cube();
151
152std::unique_ptr<TriangleMesh3D> LA_CORE_API create_quad(bool with_center_vertex);
153
154std::unique_ptr<TriangleMesh3D> LA_CORE_API create_sphere(double refine_order = 2);
155
156} // namespace lagrange
Definition: Mesh.h:48
Main namespace for Lagrange.
Definition: AABBIGL.h:30
auto create_mesh(const Eigen::MatrixBase< DerivedV > &vertices, const Eigen::MatrixBase< DerivedF > &facets)
This function create a new mesh given the vertex and facet arrays by copying data into the Mesh objec...
Definition: create_mesh.h:39
auto wrap_with_mesh(const Eigen::MatrixBase< VertexArray > &vertices, const Eigen::MatrixBase< FacetArray > &facets)
This method creates a Mesh object that wraps around vertices and facets.
Definition: create_mesh.h:109