mesh.cpp
Go to the documentation of this file.
1 
27 #include <boost/serialization/access.hpp>
28 #include <boost/serialization/base_object.hpp>
29 #include <boost/serialization/nvp.hpp>
31 
35 
36 namespace tesseract_geometry
37 {
38 Mesh::Mesh(std::shared_ptr<const tesseract_common::VectorVector3d> vertices,
39  std::shared_ptr<const Eigen::VectorXi> triangles,
40  std::shared_ptr<const tesseract_common::Resource> resource,
41  const Eigen::Vector3d& scale,
42  std::shared_ptr<const tesseract_common::VectorVector3d> normals,
43  std::shared_ptr<const tesseract_common::VectorVector4d> vertex_colors,
44  std::shared_ptr<MeshMaterial> mesh_material,
45  std::shared_ptr<const std::vector<std::shared_ptr<MeshTexture>>> mesh_textures)
46  : PolygonMesh(std::move(vertices),
47  std::move(triangles),
48  std::move(resource),
49  scale,
50  std::move(normals),
51  std::move(vertex_colors),
52  std::move(mesh_material),
53  std::move(mesh_textures),
55 {
56  if ((static_cast<long>(getFaceCount()) * 4) != getFaces()->size())
57  std::throw_with_nested(std::runtime_error("Mesh is not triangular")); // LCOV_EXCL_LINE
58 }
59 
60 Mesh::Mesh(std::shared_ptr<const tesseract_common::VectorVector3d> vertices,
61  std::shared_ptr<const Eigen::VectorXi> triangles,
62  int triangle_count,
63  std::shared_ptr<const tesseract_common::Resource> resource,
64  const Eigen::Vector3d& scale,
65  std::shared_ptr<const tesseract_common::VectorVector3d> normals,
66  std::shared_ptr<const tesseract_common::VectorVector4d> vertex_colors,
67  std::shared_ptr<MeshMaterial> mesh_material,
68  std::shared_ptr<const std::vector<std::shared_ptr<MeshTexture>>> mesh_textures)
69  : PolygonMesh(std::move(vertices),
70  std::move(triangles),
71  triangle_count,
72  std::move(resource),
73  scale,
74  std::move(normals),
75  std::move(vertex_colors),
76  std::move(mesh_material),
77  std::move(mesh_textures),
79 {
80  if ((static_cast<long>(getFaceCount()) * 4) != getFaces()->size())
81  std::throw_with_nested(std::runtime_error("Mesh is not triangular")); // LCOV_EXCL_LINE
82 }
83 
85 {
86  // getMaterial returns a pointer-to-const, so deference and make_shared, but also guard against nullptr
87  std::shared_ptr<Mesh> ptr;
88  if (getMaterial() != nullptr)
89  {
90  ptr = std::make_shared<Mesh>(getVertices(),
91  getFaces(),
92  getFaceCount(),
93  getResource(),
94  getScale(),
95  getNormals(),
97  std::make_shared<MeshMaterial>(*getMaterial()),
98  getTextures());
99  }
100  else
101  {
102  ptr = std::make_shared<Mesh>(getVertices(),
103  getFaces(),
104  getFaceCount(),
105  getResource(),
106  getScale(),
107  getNormals(),
108  getVertexColors(),
109  nullptr,
110  getTextures());
111  }
112  return ptr;
113 }
114 
115 bool Mesh::operator==(const Mesh& rhs) const
116 {
117  bool equal = true;
118  equal &= PolygonMesh::operator==(rhs);
119  return equal;
120 }
121 bool Mesh::operator!=(const Mesh& rhs) const { return !operator==(rhs); }
122 
123 template <class Archive>
124 void Mesh::serialize(Archive& ar, const unsigned int /*version*/)
125 {
126  ar& BOOST_SERIALIZATION_BASE_OBJECT_NVP(PolygonMesh);
127 }
128 } // namespace tesseract_geometry
129 
132 BOOST_CLASS_EXPORT_IMPLEMENT(tesseract_geometry::Mesh)
tesseract_geometry::Mesh
Definition: mesh.h:45
tesseract_geometry::Geometry::Ptr
std::shared_ptr< Geometry > Ptr
Definition: geometry.h:72
tesseract_geometry::Mesh::operator==
bool operator==(const Mesh &rhs) const
Definition: mesh.cpp:115
tesseract_geometry::GeometryType
GeometryType
Definition: geometry.h:48
tesseract_geometry::PolygonMesh::getMaterial
std::shared_ptr< const MeshMaterial > getMaterial() const
Get material data extracted from the mesh file.
Definition: polygon_mesh.cpp:115
resource_locator.h
TESSERACT_SERIALIZE_ARCHIVES_INSTANTIATE
#define TESSERACT_SERIALIZE_ARCHIVES_INSTANTIATE(Type)
tesseract_geometry::Mesh::serialize
void serialize(Archive &ar, const unsigned int version)
Definition: mesh.cpp:124
TESSERACT_COMMON_IGNORE_WARNINGS_PUSH
#define TESSERACT_COMMON_IGNORE_WARNINGS_PUSH
tesseract_geometry::PolygonMesh::getFaces
const std::shared_ptr< const Eigen::VectorXi > & getFaces() const
Get Polygon mesh faces.
Definition: polygon_mesh.cpp:98
tesseract_geometry::GeometryType::MESH
@ MESH
tesseract_geometry::PolygonMesh::getNormals
const std::shared_ptr< const tesseract_common::VectorVector3d > & getNormals() const
Get the vertex normal vectors.
Definition: polygon_mesh.cpp:108
mesh_material.h
Tesseract Mesh Material read from a mesh file.
tesseract_geometry::Mesh::clone
Geometry::Ptr clone() const override final
Create a copy of this shape.
Definition: mesh.cpp:84
tesseract_geometry::Mesh::operator!=
bool operator!=(const Mesh &rhs) const
Definition: mesh.cpp:121
serialization.h
tesseract_geometry::PolygonMesh::getFaceCount
int getFaceCount() const
Get face count.
Definition: polygon_mesh.cpp:102
mesh.h
Tesseract Mesh Geometry.
tesseract_geometry::PolygonMesh::operator==
bool operator==(const PolygonMesh &rhs) const
Definition: polygon_mesh.cpp:124
tesseract_geometry::PolygonMesh::getScale
const Eigen::Vector3d & getScale() const
Get the scale applied to file used to generate the mesh.
Definition: polygon_mesh.cpp:106
tesseract_geometry::PolygonMesh::getVertexColors
const std::shared_ptr< const tesseract_common::VectorVector4d > & getVertexColors() const
Get the vertex colors.
Definition: polygon_mesh.cpp:110
tesseract_geometry::PolygonMesh
Definition: polygon_mesh.h:51
TESSERACT_COMMON_IGNORE_WARNINGS_POP
#define TESSERACT_COMMON_IGNORE_WARNINGS_POP
tesseract_geometry
Definition: fwd.h:31
tesseract_geometry::PolygonMesh::getTextures
const std::shared_ptr< const std::vector< std::shared_ptr< MeshTexture > > > & getTextures() const
Get textures extracted from the mesh file.
Definition: polygon_mesh.cpp:117
tesseract_geometry::Mesh::Mesh
Mesh()=default
macros.h
tesseract_geometry::PolygonMesh::getVertices
const std::shared_ptr< const tesseract_common::VectorVector3d > & getVertices() const
Get Polygon mesh vertices.
Definition: polygon_mesh.cpp:96
tesseract_geometry::PolygonMesh::getResource
std::shared_ptr< const tesseract_common::Resource > getResource() const
Get the path to file used to generate the mesh.
Definition: polygon_mesh.cpp:104


tesseract_geometry
Author(s): Levi Armstrong
autogenerated on Sun May 18 2025 03:01:46