Tesseract
Motion Planning Environment
Loading...
Searching...
No Matches
mesh.h
Go to the documentation of this file.
1
26#ifndef TESSERACT_GEOMETRY_MESH_H
27#define TESSERACT_GEOMETRY_MESH_H
28
32#include <boost/serialization/access.hpp>
33#include <boost/serialization/export.hpp>
34#include <Eigen/Geometry>
35#include <memory>
37
42
43namespace tesseract_geometry
44{
45class Mesh : public PolygonMesh
46{
47public:
48 // LCOV_EXCL_START
49 EIGEN_MAKE_ALIGNED_OPERATOR_NEW
50 // LCOV_EXCL_STOP
51
52 using Ptr = std::shared_ptr<Mesh>;
53 using ConstPtr = std::shared_ptr<const Mesh>;
54
69 Mesh(std::shared_ptr<const tesseract_common::VectorVector3d> vertices,
70 std::shared_ptr<const Eigen::VectorXi> triangles,
72 const Eigen::Vector3d& scale = Eigen::Vector3d(1, 1, 1),
73 std::shared_ptr<const tesseract_common::VectorVector3d> normals = nullptr,
74 std::shared_ptr<const tesseract_common::VectorVector4d> vertex_colors = nullptr,
75 MeshMaterial::Ptr mesh_material = nullptr,
76 std::shared_ptr<const std::vector<MeshTexture::Ptr>> mesh_textures = nullptr)
77 : PolygonMesh(std::move(vertices),
78 std::move(triangles),
79 std::move(resource),
80 scale,
81 std::move(normals),
82 std::move(vertex_colors),
83 std::move(mesh_material),
84 std::move(mesh_textures),
86 {
87 if ((static_cast<long>(getFaceCount()) * 4) != getFaces()->size())
88 std::throw_with_nested(std::runtime_error("Mesh is not triangular")); // LCOV_EXCL_LINE
89 }
90
106 Mesh(std::shared_ptr<const tesseract_common::VectorVector3d> vertices,
107 std::shared_ptr<const Eigen::VectorXi> triangles,
108 int triangle_count,
110 const Eigen::Vector3d& scale = Eigen::Vector3d(1, 1, 1),
111 std::shared_ptr<const tesseract_common::VectorVector3d> normals = nullptr,
112 std::shared_ptr<const tesseract_common::VectorVector4d> vertex_colors = nullptr,
113 MeshMaterial::Ptr mesh_material = nullptr,
114 std::shared_ptr<const std::vector<MeshTexture::Ptr>> mesh_textures = nullptr)
115 : PolygonMesh(std::move(vertices),
116 std::move(triangles),
117 triangle_count,
118 std::move(resource),
119 scale,
120 std::move(normals),
121 std::move(vertex_colors),
122 std::move(mesh_material),
123 std::move(mesh_textures),
125 {
126 if ((static_cast<long>(getFaceCount()) * 4) != getFaces()->size())
127 std::throw_with_nested(std::runtime_error("Mesh is not triangular")); // LCOV_EXCL_LINE
128 }
129
130 Mesh() = default;
131 ~Mesh() override = default;
132
133 Geometry::Ptr clone() const override
134 {
135 // getMaterial returns a pointer-to-const, so deference and make_shared, but also guard against nullptr
136 std::shared_ptr<Mesh> ptr;
137 if (getMaterial() != nullptr)
138 {
139 ptr = std::make_shared<Mesh>(getVertices(),
140 getFaces(),
141 getFaceCount(),
142 getResource(),
143 getScale(),
144 getNormals(),
146 std::make_shared<MeshMaterial>(*getMaterial()),
147 getTextures());
148 }
149 else
150 {
151 ptr = std::make_shared<Mesh>(getVertices(),
152 getFaces(),
153 getFaceCount(),
154 getResource(),
155 getScale(),
156 getNormals(),
158 nullptr,
159 getTextures());
160 }
161 return ptr;
162 }
163 bool operator==(const Mesh& rhs) const;
164 bool operator!=(const Mesh& rhs) const;
165
166private:
168 template <class Archive>
169 void serialize(Archive& ar, const unsigned int version); // NOLINT
170};
171} // namespace tesseract_geometry
172
173BOOST_CLASS_EXPORT_KEY2(tesseract_geometry::Mesh, "Mesh")
174#endif
std::shared_ptr< const Resource > ConstPtr
Definition: resource_locator.h:102
std::shared_ptr< Resource > Ptr
Definition: resource_locator.h:101
std::shared_ptr< Geometry > Ptr
Definition: geometry.h:62
std::shared_ptr< MeshMaterial > Ptr
Definition: mesh_material.h:63
Definition: mesh.h:46
void serialize(Archive &ar, const unsigned int version)
Definition: mesh.cpp:47
Geometry::Ptr clone() const override
Create a copy of this shape.
Definition: mesh.h:133
~Mesh() override=default
Mesh(std::shared_ptr< const tesseract_common::VectorVector3d > vertices, std::shared_ptr< const Eigen::VectorXi > triangles, tesseract_common::Resource::Ptr resource=nullptr, const Eigen::Vector3d &scale=Eigen::Vector3d(1, 1, 1), std::shared_ptr< const tesseract_common::VectorVector3d > normals=nullptr, std::shared_ptr< const tesseract_common::VectorVector4d > vertex_colors=nullptr, MeshMaterial::Ptr mesh_material=nullptr, std::shared_ptr< const std::vector< MeshTexture::Ptr > > mesh_textures=nullptr)
Mesh geometry.
Definition: mesh.h:69
friend class boost::serialization::access
Definition: mesh.h:167
bool operator==(const Mesh &rhs) const
Definition: mesh.cpp:38
Mesh(std::shared_ptr< const tesseract_common::VectorVector3d > vertices, std::shared_ptr< const Eigen::VectorXi > triangles, int triangle_count, tesseract_common::Resource::ConstPtr resource=nullptr, const Eigen::Vector3d &scale=Eigen::Vector3d(1, 1, 1), std::shared_ptr< const tesseract_common::VectorVector3d > normals=nullptr, std::shared_ptr< const tesseract_common::VectorVector4d > vertex_colors=nullptr, MeshMaterial::Ptr mesh_material=nullptr, std::shared_ptr< const std::vector< MeshTexture::Ptr > > mesh_textures=nullptr)
Mesh geometry.
Definition: mesh.h:106
bool operator!=(const Mesh &rhs) const
Definition: mesh.cpp:44
std::shared_ptr< const Mesh > ConstPtr
Definition: mesh.h:53
std::shared_ptr< Mesh > Ptr
Definition: mesh.h:52
Definition: polygon_mesh.h:46
const std::shared_ptr< const Eigen::VectorXi > & getFaces() const
Get Polygon mesh faces.
Definition: polygon_mesh.h:152
int getFaceCount() const
Get face count.
Definition: polygon_mesh.h:164
tesseract_common::Resource::ConstPtr getResource() const
Get the path to file used to generate the mesh.
Definition: polygon_mesh.h:173
const std::shared_ptr< const tesseract_common::VectorVector3d > & getVertices() const
Get Polygon mesh vertices.
Definition: polygon_mesh.h:146
const Eigen::Vector3d & getScale() const
Get the scale applied to file used to generate the mesh.
Definition: polygon_mesh.h:179
const std::shared_ptr< const std::vector< MeshTexture::Ptr > > & getTextures() const
Get textures extracted from the mesh file.
Definition: polygon_mesh.h:219
const std::shared_ptr< const tesseract_common::VectorVector4d > & getVertexColors() const
Get the vertex colors.
Definition: polygon_mesh.h:197
MeshMaterial::ConstPtr getMaterial() const
Get material data extracted from the mesh file.
Definition: polygon_mesh.h:207
const std::shared_ptr< const tesseract_common::VectorVector3d > & getNormals() const
Get the vertex normal vectors.
Definition: polygon_mesh.h:188
double scale
Definition: collision_margin_data_unit.cpp:133
Common Tesseract Macros.
#define TESSERACT_COMMON_IGNORE_WARNINGS_PUSH
Definition: macros.h:71
Tesseract Mesh Material read from a mesh file.
Definition: create_convex_hull.cpp:36
Definition: geometry.h:39
GeometryType
Definition: geometry.h:41
@ MESH
Definition: geometry.h:49
Tesseract Polygon Mesh Geometry.
Locate and retrieve resource data.
Resource::Ptr resource
Definition: resource_locator_unit.cpp:59
Common Tesseract Types.
Tesseract Geometries.