CortidQCT  1.2.2.52
MeshAdaptors.h
Go to the documentation of this file.
1 
12 #pragma once
13 
14 #include "Mesh.h"
15 
16 #include <Eigen/Core>
17 #include <gsl/gsl>
18 
19 namespace CortidQCT {
20 namespace Internal {
21 namespace Adaptor {
22 
23 template <class T>
24 inline Eigen::Map<Eigen::Matrix<T, 3, Eigen::Dynamic> const>
25 vertexMap(Mesh<T> const &mesh) {
26  return mesh.withUnsafeVertexPointer([&mesh](auto const *ptr) {
27  return Eigen::Map<Eigen::Matrix<T, 3, Eigen::Dynamic> const>{
28  ptr, 3, gsl::narrow_cast<Eigen::Index>(mesh.vertexCount())};
29  });
30 }
31 
32 template <class T>
33 inline Eigen::Map<Eigen::Matrix<T, 3, Eigen::Dynamic>>
34 vertexMap(Mesh<T> &mesh) {
35  return mesh.withUnsafeVertexPointer([&mesh](auto *ptr) {
36  return Eigen::Map<Eigen::Matrix<T, 3, Eigen::Dynamic>>{
37  ptr, 3, gsl::narrow_cast<Eigen::Index>(mesh.vertexCount())};
38  });
39 }
40 
41 template <class T>
42 inline Eigen::Map<Eigen::Matrix<T, 3, Eigen::Dynamic> const>
43 vertexNormalMap(Mesh<T> const &mesh) {
44  return mesh.withUnsafeVertexNormalPointer([&mesh](auto const *ptr) {
45  return Eigen::Map<Eigen::Matrix<T, 3, Eigen::Dynamic> const>{
46  ptr, 3, gsl::narrow_cast<Eigen::Index>(mesh.vertexCount())};
47  });
48 }
49 
50 template <class T>
51 inline Eigen::Map<Eigen::Matrix<T, 3, Eigen::Dynamic>>
52 vertexNormalMap(Mesh<T> &mesh) {
53  return mesh.withUnsafeVertexNormalPointer([&mesh](auto *ptr) {
54  return Eigen::Map<Eigen::Matrix<T, 3, Eigen::Dynamic>>{
55  ptr, 3, gsl::narrow_cast<Eigen::Index>(mesh.vertexCount())};
56  });
57 }
58 
59 template <class T>
60 inline Eigen::Map<
61  Eigen::Matrix<typename Mesh<T>::Index, 3, Eigen::Dynamic> const>
62 indexMap(Mesh<T> const &mesh) {
63  using S = typename Mesh<T>::Index;
64  return mesh.withUnsafeIndexPointer([&mesh](auto const *ptr) {
65  return Eigen::Map<Eigen::Matrix<S, 3, Eigen::Dynamic> const>{
66  ptr, 3, gsl::narrow_cast<Eigen::Index>(mesh.triangleCount())};
67  });
68 }
69 
70 template <class T>
71 inline Eigen::Map<Eigen::Matrix<typename Mesh<T>::Index, 3, Eigen::Dynamic>>
72 indexMap(Mesh<T> &mesh) {
73  using S = typename Mesh<T>::Index;
74  return mesh.withUnsafeIndexPointer([&mesh](auto *ptr) {
75  return Eigen::Map<Eigen::Matrix<S, 3, Eigen::Dynamic>>{
76  ptr, 3, gsl::narrow_cast<Eigen::Index>(mesh.triangleCount())};
77  });
78 }
79 
80 template <class T>
81 inline Eigen::Map<
82  Eigen::Matrix<typename Mesh<T>::Label, Eigen::Dynamic, 1> const>
83 labelMap(Mesh<T> const &mesh) {
84  using S = typename Mesh<T>::Label;
85  return mesh.withUnsafeLabelPointer([&mesh](auto const *ptr) {
86  return Eigen::Map<Eigen::Matrix<S, Eigen::Dynamic, 1> const>{
87  ptr, gsl::narrow_cast<Eigen::Index>(mesh.vertexCount())};
88  });
89 }
90 
91 template <class T>
92 inline Eigen::Map<Eigen::Matrix<typename Mesh<T>::Label, Eigen::Dynamic, 1>>
93 labelMap(Mesh<T> &mesh) {
94  using S = typename Mesh<T>::Label;
95  return mesh.withUnsafeLabelPointer([&mesh](auto *ptr) {
96  return Eigen::Map<Eigen::Matrix<S, Eigen::Dynamic, 1>>{
97  ptr, gsl::narrow_cast<Eigen::Index>(mesh.vertexCount())};
98  });
99 }
100 
101 } // namespace Adaptor
102 } // namespace Internal
103 } // namespace CortidQCT
Name namespace for CortidQCT library.
Definition: CortidQCT.h:23
std::ptrdiff_t Index
Index type.
Definition: Mesh.h:45
Include file defining the Mesh data type.
unsigned int Label
Label type.
Definition: Mesh.h:51