Lagrange
GenuineMeshGeometry.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/MeshGeometry.h>
19#include <lagrange/common.h>
20#include <lagrange/utils/safe_cast.h>
21
22namespace lagrange {
23template <typename _VertexArray, typename _FacetArray>
24class GenuineMeshGeometry : public MeshGeometry<_VertexArray, _FacetArray>
25{
26public:
28 using VertexArray = typename Parent::VertexArray;
29 using FacetArray = typename Parent::FacetArray;
30 using VertexType = typename Parent::VertexType;
31 using Scalar = typename Parent::Scalar;
32 using Index = typename Parent::Index;
33
34public:
35 EIGEN_MAKE_ALIGNED_OPERATOR_NEW
36 GenuineMeshGeometry() = default;
37 GenuineMeshGeometry(const VertexArray& vertices, const FacetArray& facets)
38 : m_vertices(vertices)
39 , m_facets(facets)
40 {}
41 virtual ~GenuineMeshGeometry() = default;
42
43public:
44 virtual Index get_dim() const override { return safe_cast<Index>(m_vertices.cols()); }
45
46 virtual Index get_num_vertices() const override { return safe_cast<Index>(m_vertices.rows()); }
47
48 virtual Index get_num_facets() const override { return safe_cast<Index>(m_facets.rows()); }
49
50 virtual Index get_vertex_per_facet() const override
51 {
52 return safe_cast<Index>(m_facets.cols());
53 }
54
55 virtual const VertexArray& get_vertices() const override { return m_vertices; }
56
57 virtual const FacetArray& get_facets() const override { return m_facets; }
58
59 virtual VertexArray& get_vertices_ref() override { return m_vertices; }
60
61 virtual FacetArray& get_facets_ref() override { return m_facets; }
62
63public:
64 VertexArray& get_vertices() { return m_vertices; }
65
66 FacetArray& get_facets() { return m_facets; }
67
68private:
69 VertexArray m_vertices;
70 FacetArray m_facets;
71};
72
73template <typename _VertexArray, typename _FacetArray, typename Archive>
74void serialize(std::shared_ptr<MeshGeometry<_VertexArray, _FacetArray>>& geometry, Archive& ar)
75{
76 if (ar.is_input()) {
77 geometry = std::make_shared<GenuineMeshGeometry<_VertexArray, _FacetArray>>();
78 }
79 geometry->serialize_impl(ar);
80}
81
82} // namespace lagrange
Definition: GenuineMeshGeometry.h:25
Definition: MeshGeometry.h:25
Main namespace for Lagrange.
Definition: AABBIGL.h:30