polygon_mesh.cpp
Go to the documentation of this file.
1 
28 #include <boost/serialization/access.hpp>
29 #include <boost/serialization/base_object.hpp>
30 #include <boost/serialization/nvp.hpp>
31 #include <boost/serialization/string.hpp>
32 #include <boost/serialization/vector.hpp>
33 #include <boost/serialization/shared_ptr.hpp>
35 
36 #include <tesseract_common/utils.h>
41 
42 namespace tesseract_geometry
43 {
44 PolygonMesh::PolygonMesh(std::shared_ptr<const tesseract_common::VectorVector3d> vertices,
45  std::shared_ptr<const Eigen::VectorXi> faces,
46  std::shared_ptr<const tesseract_common::Resource> resource,
47  const Eigen::Vector3d& scale, // NOLINT
48  std::shared_ptr<const tesseract_common::VectorVector3d> normals,
49  std::shared_ptr<const tesseract_common::VectorVector4d> vertex_colors,
50  std::shared_ptr<MeshMaterial> mesh_material,
51  std::shared_ptr<const std::vector<std::shared_ptr<MeshTexture>>> mesh_textures,
52  GeometryType type)
53  : Geometry(type)
54  , vertices_(std::move(vertices))
55  , faces_(std::move(faces))
56  , vertex_count_(static_cast<int>(vertices_->size()))
57  , resource_(std::move(resource))
58  , scale_(scale)
59  , normals_(std::move(normals))
60  , vertex_colors_(std::move(vertex_colors))
61  , mesh_material_(std::move(mesh_material))
62  , mesh_textures_(std::move(mesh_textures))
63 {
64  for (int i = 0; i < faces_->size(); ++i)
65  {
66  ++face_count_;
67  int num_verts = (*faces_)(i); // NOLINT
68  i += num_verts;
69  }
70 }
71 
72 PolygonMesh::PolygonMesh(std::shared_ptr<const tesseract_common::VectorVector3d> vertices,
73  std::shared_ptr<const Eigen::VectorXi> faces,
74  int face_count,
76  const Eigen::Vector3d& scale, // NOLINT
77  std::shared_ptr<const tesseract_common::VectorVector3d> normals,
78  std::shared_ptr<const tesseract_common::VectorVector4d> vertex_colors,
79  MeshMaterial::Ptr mesh_material,
80  std::shared_ptr<const std::vector<MeshTexture::Ptr>> mesh_textures,
81  GeometryType type)
82  : Geometry(type)
83  , vertices_(std::move(vertices))
84  , faces_(std::move(faces))
85  , vertex_count_(static_cast<int>(vertices_->size()))
86  , face_count_(face_count)
87  , resource_(std::move(resource))
88  , scale_(scale)
89  , normals_(std::move(normals))
90  , vertex_colors_(std::move(vertex_colors))
91  , mesh_material_(std::move(mesh_material))
92  , mesh_textures_(std::move(mesh_textures))
93 {
94 }
95 
96 const std::shared_ptr<const tesseract_common::VectorVector3d>& PolygonMesh::getVertices() const { return vertices_; }
97 
98 const std::shared_ptr<const Eigen::VectorXi>& PolygonMesh::getFaces() const { return faces_; }
99 
101 
102 int PolygonMesh::getFaceCount() const { return face_count_; }
103 
105 
106 const Eigen::Vector3d& PolygonMesh::getScale() const { return scale_; }
107 
108 const std::shared_ptr<const tesseract_common::VectorVector3d>& PolygonMesh::getNormals() const { return normals_; }
109 
110 const std::shared_ptr<const tesseract_common::VectorVector4d>& PolygonMesh::getVertexColors() const
111 {
112  return vertex_colors_;
113 }
114 
116 
117 const std::shared_ptr<const std::vector<MeshTexture::Ptr>>& PolygonMesh::getTextures() const { return mesh_textures_; }
118 
120 {
121  return std::make_shared<PolygonMesh>(vertices_, faces_, face_count_, resource_, scale_);
122 }
123 
124 bool PolygonMesh::operator==(const PolygonMesh& rhs) const
125 {
126  bool equal = true;
127  equal &= Geometry::operator==(rhs);
128  equal &= vertex_count_ == rhs.vertex_count_;
129  equal &= face_count_ == rhs.face_count_;
132  return equal;
133 }
134 bool PolygonMesh::operator!=(const PolygonMesh& rhs) const { return !operator==(rhs); }
135 
136 template <class Archive>
137 void PolygonMesh::serialize(Archive& ar, const unsigned int /*version*/)
138 {
139  ar& BOOST_SERIALIZATION_BASE_OBJECT_NVP(Geometry);
140  ar& BOOST_SERIALIZATION_NVP(vertices_);
141  ar& BOOST_SERIALIZATION_NVP(faces_);
142  ar& BOOST_SERIALIZATION_NVP(vertex_count_);
143  ar& BOOST_SERIALIZATION_NVP(face_count_);
144  ar& BOOST_SERIALIZATION_NVP(resource_);
145  ar& BOOST_SERIALIZATION_NVP(scale_);
146  ar& BOOST_SERIALIZATION_NVP(normals_);
147  ar& BOOST_SERIALIZATION_NVP(vertex_colors_);
149  // ar& BOOST_SERIALIZATION_NVP(mesh_material_);
150  // ar& BOOST_SERIALIZATION_NVP(mesh_textures_);
151 }
152 } // namespace tesseract_geometry
153 
156 BOOST_CLASS_EXPORT_IMPLEMENT(tesseract_geometry::PolygonMesh)
tesseract_geometry::PolygonMesh::mesh_textures_
std::shared_ptr< const std::vector< std::shared_ptr< MeshTexture > > > mesh_textures_
Definition: polygon_mesh.h:212
tesseract_geometry::Geometry::Ptr
std::shared_ptr< Geometry > Ptr
Definition: geometry.h:72
tesseract_geometry::Geometry
Definition: geometry.h:69
tesseract_geometry::PolygonMesh::getVertexCount
int getVertexCount() const
Get vertex count.
Definition: polygon_mesh.cpp:100
tesseract_geometry::PolygonMesh::clone
Geometry::Ptr clone() const override
Create a copy of this shape.
Definition: polygon_mesh.cpp:119
utils.h
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_geometry::PolygonMesh::operator!=
bool operator!=(const PolygonMesh &rhs) const
Definition: polygon_mesh.cpp:134
tesseract_common::almostEqualRelativeAndAbs
bool almostEqualRelativeAndAbs(const Eigen::Ref< const Eigen::VectorXd > &v1, const Eigen::Ref< const Eigen::VectorXd > &v2, const Eigen::Ref< const Eigen::VectorXd > &max_diff, const Eigen::Ref< const Eigen::VectorXd > &max_rel_diff)
TESSERACT_SERIALIZE_ARCHIVES_INSTANTIATE
#define TESSERACT_SERIALIZE_ARCHIVES_INSTANTIATE(Type)
tesseract_common::Resource::ConstPtr
std::shared_ptr< const Resource > ConstPtr
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::PolygonMesh::getNormals
const std::shared_ptr< const tesseract_common::VectorVector3d > & getNormals() const
Get the vertex normal vectors.
Definition: polygon_mesh.cpp:108
tesseract_geometry::MeshMaterial::Ptr
std::shared_ptr< MeshMaterial > Ptr
Definition: mesh_material.h:67
tesseract_geometry::PolygonMesh::scale_
Eigen::Vector3d scale_
Definition: polygon_mesh.h:208
tesseract_geometry::PolygonMesh::normals_
std::shared_ptr< const tesseract_common::VectorVector3d > normals_
Definition: polygon_mesh.h:209
tesseract_geometry::PolygonMesh::resource_
std::shared_ptr< const tesseract_common::Resource > resource_
Definition: polygon_mesh.h:207
tesseract_geometry::Geometry::operator==
bool operator==(const Geometry &rhs) const
Definition: geometry.cpp:48
mesh_material.h
Tesseract Mesh Material read from a mesh file.
serialization.h
tesseract_geometry::PolygonMesh::getFaceCount
int getFaceCount() const
Get face count.
Definition: polygon_mesh.cpp:102
polygon_mesh.h
Tesseract Polygon Mesh Geometry.
tesseract_geometry::PolygonMesh::faces_
std::shared_ptr< const Eigen::VectorXi > faces_
Definition: polygon_mesh.h:203
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::vertex_count_
int vertex_count_
Definition: polygon_mesh.h:205
tesseract_geometry::PolygonMesh
Definition: polygon_mesh.h:51
TESSERACT_COMMON_IGNORE_WARNINGS_POP
#define TESSERACT_COMMON_IGNORE_WARNINGS_POP
type
type
tesseract_geometry::MeshMaterial::ConstPtr
std::shared_ptr< const MeshMaterial > ConstPtr
Definition: mesh_material.h:68
tesseract_geometry::PolygonMesh::vertex_colors_
std::shared_ptr< const tesseract_common::VectorVector4d > vertex_colors_
Definition: polygon_mesh.h:210
tesseract_geometry
Definition: fwd.h:31
tesseract_geometry::PolygonMesh::serialize
void serialize(Archive &ar, const unsigned int version)
Definition: polygon_mesh.cpp:137
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::PolygonMesh::vertices_
std::shared_ptr< const tesseract_common::VectorVector3d > vertices_
Definition: polygon_mesh.h:202
tesseract_geometry::PolygonMesh::PolygonMesh
PolygonMesh()=default
macros.h
tesseract_geometry::PolygonMesh::face_count_
int face_count_
Definition: polygon_mesh.h:206
tesseract_geometry::PolygonMesh::getVertices
const std::shared_ptr< const tesseract_common::VectorVector3d > & getVertices() const
Get Polygon mesh vertices.
Definition: polygon_mesh.cpp:96
eigen_serialization.h
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::PolygonMesh::mesh_material_
std::shared_ptr< MeshMaterial > mesh_material_
Definition: polygon_mesh.h:211


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