Lagrange
MeshGeometry.h
1/*
2 * Copyright 2017 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 <memory>
15
16#include <Eigen/Core>
17
18#include <lagrange/common.h>
19#include <lagrange/utils/warning.h>
20
21namespace lagrange {
22
23template <typename _VertexArray, typename _FacetArray>
25{
26public:
27 using VertexArray = _VertexArray;
28 using FacetArray = _FacetArray;
29 using VertexType =
30 Eigen::Matrix<typename VertexArray::Scalar, 1, VertexArray::ColsAtCompileTime>;
31
32
33 using Scalar = typename VertexArray::Scalar;
34 using Index = typename FacetArray::Scalar;
35
36public:
37 MeshGeometry() = default;
38 MeshGeometry(const VertexArray& /*vertices*/, const FacetArray& /*facets*/) {}
39 virtual ~MeshGeometry() = default;
40
41 virtual Index get_dim() const = 0;
42 virtual Index get_num_vertices() const = 0;
43 virtual Index get_num_facets() const = 0;
44 virtual Index get_vertex_per_facet() const = 0;
45
46 virtual const VertexArray& get_vertices() const = 0;
47 virtual const FacetArray& get_facets() const = 0;
48
49 virtual VertexArray& get_vertices_ref() = 0;
50 virtual FacetArray& get_facets_ref() = 0;
51
52public:
53 template <typename Derived>
54 void import_vertices(Eigen::MatrixBase<Derived>& vertices)
55 {
56 auto& member_vertices = this->get_vertices_ref();
57 move_data(vertices, member_vertices);
58 }
59
60 template <typename Derived>
61 void import_facets(Eigen::MatrixBase<Derived>& facets)
62 {
63 auto& member_facets = this->get_facets_ref();
64 move_data(facets, member_facets);
65 }
66
67 template <typename Derived>
68 void export_vertices(Eigen::MatrixBase<Derived>& vertices)
69 {
70 auto& member_vertices = this->get_vertices_ref();
71 move_data(member_vertices, vertices);
72 }
73
74 template <typename Derived>
75 void export_facets(Eigen::MatrixBase<Derived>& facets)
76 {
77 auto& member_facets = this->get_facets_ref();
78 move_data(member_facets, facets);
79 }
80
81 template <typename Archive>
82 void serialize_impl(Archive& ar)
83 {
85 enum { VERTICES = 0, FACETS = 1 };
86 ar.object([&](auto& ar) {
87 ar("vertices", VERTICES) & get_vertices_ref();
88 ar("facets", FACETS) & get_facets_ref();
89 });
90 LA_IGNORE_SHADOW_WARNING_END
91 }
92};
93
94template <typename _VertexArray, typename _FacetArray, typename Archive>
95void serialize(MeshGeometry<_VertexArray, _FacetArray>& geometry, Archive& ar)
96{
97 geometry.serialize_impl(ar);
98}
99
100} // namespace lagrange
Definition: MeshGeometry.h:25
#define LA_IGNORE_SHADOW_WARNING_BEGIN
Ignore shadow warnings.
Definition: warning.h:68
Main namespace for Lagrange.
Definition: AABBIGL.h:30
void move_data(Eigen::DenseBase< Derived1 > &from, Eigen::DenseBase< Derived2 > &to)
Move data from one Eigen obj to another.
Definition: common.h:61