Lagrange
ActingMeshGeometry.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 {
23
24template <typename _VertexArray, typename _FacetArray>
25class ActingMeshGeometry : public MeshGeometry<_VertexArray, _FacetArray>
26{
27public:
29 using VertexArray = typename Parent::VertexArray;
30 using FacetArray = typename Parent::FacetArray;
31 using VertexType = typename Parent::VertexType;
32 using Scalar = typename Parent::Scalar;
33 using Index = typename Parent::Index;
34
35public:
36 ActingMeshGeometry() = delete;
37 ActingMeshGeometry(const VertexArray& vertices, const FacetArray& facets)
38 : m_vertices(vertices)
39 , m_facets(facets)
40 {}
41 virtual ~ActingMeshGeometry() = 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
60 {
61 // We assume geometry remain unchanged during the entire life span.
62 // Please use the const version instead.
63 throw std::runtime_error("ActingMeshGeometry does not support import/export!");
64 }
65
66 virtual FacetArray& get_facets_ref() override
67 {
68 // We assume geometry remain unchanged during the entire life span.
69 // Please use the const version instead.
70 throw std::runtime_error("ActingMeshGeometry does not support import/export!");
71 }
72
73private:
74 const VertexArray& m_vertices;
75 const FacetArray& m_facets;
76};
77
78} // namespace lagrange
Definition: ActingMeshGeometry.h:26
Definition: MeshGeometry.h:25
Main namespace for Lagrange.
Definition: AABBIGL.h:30