compound_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>
30 #include <boost/serialization/vector.hpp>
31 #include <boost/serialization/shared_ptr.hpp>
33 
34 #include <tesseract_common/utils.h>
40 
41 template <typename T>
42 std::vector<std::shared_ptr<tesseract_geometry::PolygonMesh>> convert(std::vector<std::shared_ptr<T>>& meshes)
43 {
44  std::vector<std::shared_ptr<tesseract_geometry::PolygonMesh>> polygon_meshes;
45  polygon_meshes.reserve(meshes.size());
46  for (const auto& mesh : meshes)
47  polygon_meshes.push_back(mesh);
48 
49  return polygon_meshes;
50 }
51 
52 namespace tesseract_geometry
53 {
54 CompoundMesh::CompoundMesh(std::vector<std::shared_ptr<PolygonMesh>> meshes)
55  : Geometry(GeometryType::COMPOUND_MESH), meshes_(std::move(meshes))
56 {
57  if (meshes_.size() <= 1)
58  throw std::runtime_error("Meshes must contain more than one mesh");
59 
60 #ifndef NDEBUG
61  for (const auto& mesh : meshes_)
62  {
63  assert(tesseract_common::pointersEqual<const tesseract_common::Resource>(meshes_[0]->getResource(),
64  mesh->getResource()));
65  assert(tesseract_common::almostEqualRelativeAndAbs(meshes_[0]->getScale(), mesh->getScale()));
66  }
67 #endif
68 }
69 
70 CompoundMesh::CompoundMesh(std::vector<std::shared_ptr<ConvexMesh>> meshes) : CompoundMesh(convert(meshes)) {}
71 
72 CompoundMesh::CompoundMesh(std::vector<std::shared_ptr<Mesh>> meshes) : CompoundMesh(convert(meshes)) {}
73 
74 CompoundMesh::CompoundMesh(std::vector<std::shared_ptr<SDFMesh>> meshes) : CompoundMesh(convert(meshes)) {}
75 
76 const std::vector<std::shared_ptr<PolygonMesh>>& CompoundMesh::getMeshes() const { return meshes_; }
77 
78 std::shared_ptr<const tesseract_common::Resource> CompoundMesh::getResource() const
79 {
80  return meshes_.front()->getResource();
81 }
82 
83 const Eigen::Vector3d& CompoundMesh::getScale() const { return meshes_.front()->getScale(); }
84 
86 {
87  std::vector<std::shared_ptr<PolygonMesh>> meshes;
88  meshes.reserve(meshes_.size());
89  for (const auto& mesh : meshes_)
90  meshes.emplace_back(std::dynamic_pointer_cast<PolygonMesh>(mesh->clone()));
91 
92  return std::make_shared<CompoundMesh>(meshes);
93 }
94 
95 bool CompoundMesh::operator==(const CompoundMesh& rhs) const
96 {
97  if (meshes_.size() != rhs.meshes_.size())
98  return false;
99 
100  bool equal = true;
101  equal &= Geometry::operator==(rhs);
102  for (std::size_t i = 0; i < meshes_.size(); ++i)
103  equal &= (*meshes_.at(i) == *rhs.meshes_.at(i));
104 
105  return equal;
106 }
107 bool CompoundMesh::operator!=(const CompoundMesh& rhs) const { return !operator==(rhs); }
108 
109 template <class Archive>
110 void CompoundMesh::serialize(Archive& ar, const unsigned int /*version*/)
111 {
112  ar& BOOST_SERIALIZATION_BASE_OBJECT_NVP(Geometry);
113  ar& BOOST_SERIALIZATION_NVP(meshes_);
114 }
115 } // namespace tesseract_geometry
116 
119 BOOST_CLASS_EXPORT_IMPLEMENT(tesseract_geometry::CompoundMesh)
tesseract_geometry::CompoundMesh::operator!=
bool operator!=(const CompoundMesh &rhs) const
Definition: compound_mesh.cpp:107
tesseract_geometry::CompoundMesh::getMeshes
const std::vector< std::shared_ptr< PolygonMesh > > & getMeshes() const
Get the meshes.
Definition: compound_mesh.cpp:76
tesseract_geometry::GeometryType::COMPOUND_MESH
@ COMPOUND_MESH
tesseract_geometry::Geometry::Ptr
std::shared_ptr< Geometry > Ptr
Definition: geometry.h:72
tesseract_geometry::Geometry
Definition: geometry.h:69
sdf_mesh.h
Tesseract SDF Mesh Geometry.
tesseract_geometry::CompoundMesh::operator==
bool operator==(const CompoundMesh &rhs) const
Definition: compound_mesh.cpp:95
utils.h
tesseract_geometry::GeometryType
GeometryType
Definition: geometry.h:48
tesseract_geometry::CompoundMesh::meshes_
std::vector< std::shared_ptr< PolygonMesh > > meshes_
Definition: compound_mesh.h:88
resource_locator.h
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_IGNORE_WARNINGS_PUSH
#define TESSERACT_COMMON_IGNORE_WARNINGS_PUSH
tesseract_geometry::Geometry::operator==
bool operator==(const Geometry &rhs) const
Definition: geometry.cpp:48
serialization.h
tesseract_geometry::CompoundMesh::serialize
void serialize(Archive &ar, const unsigned int version)
Definition: compound_mesh.cpp:110
mesh.h
Tesseract Mesh Geometry.
tesseract_geometry::CompoundMesh::getResource
std::shared_ptr< const tesseract_common::Resource > getResource() const
Get the path to file used to generate the meshs.
Definition: compound_mesh.cpp:78
tesseract_geometry::CompoundMesh::CompoundMesh
CompoundMesh()=default
tesseract_geometry::CompoundMesh::clone
Geometry::Ptr clone() const override final
Create a copy of this shape.
Definition: compound_mesh.cpp:85
TESSERACT_COMMON_IGNORE_WARNINGS_POP
#define TESSERACT_COMMON_IGNORE_WARNINGS_POP
tesseract_geometry
Definition: fwd.h:31
tesseract_geometry::CompoundMesh::getScale
const Eigen::Vector3d & getScale() const
Get the scale applied to file used to generate the meshs.
Definition: compound_mesh.cpp:83
macros.h
compound_mesh.h
Tesseract Compound Mesh Geometry.
convex_mesh.h
Tesseract Convex Mesh Geometry.
convert
TESSERACT_COMMON_IGNORE_WARNINGS_PUSH TESSERACT_COMMON_IGNORE_WARNINGS_POP std::vector< std::shared_ptr< tesseract_geometry::PolygonMesh > > convert(std::vector< std::shared_ptr< T >> &meshes)
Definition: compound_mesh.cpp:42
tesseract_geometry::CompoundMesh
This is store meshes that are associated with as single resource.
Definition: compound_mesh.h:49


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