Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix some missing features in base classes #275

Merged
merged 8 commits into from
Mar 21, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions include/hpp/fcl/BV/AABB.h
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,8 @@ class HPP_FCL_DLLAPI AABB
{
}

AABB(const AABB & other) = default;

AABB & update(const Vec3f& a, const Vec3f& b)
{
min_ = a.cwiseMin(b); max_ = a.cwiseMax(b);
Expand All @@ -98,6 +100,11 @@ class HPP_FCL_DLLAPI AABB
{
return min_ == other.min_ && max_ == other.max_;
}

bool operator!=(const AABB & other) const
{
return !(*this == other);
}

/// @name Bounding volume API
/// Common API to BVs.
Expand Down
12 changes: 8 additions & 4 deletions include/hpp/fcl/shape/details/convex.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ Convex<PolygonT>::Convex(const Convex<PolygonT>& other) :
{
if (own_storage_) {
polygons = new PolygonT[num_polygons];
memcpy(polygons, other.polygons, sizeof(PolygonT) * num_polygons);
std::copy(other.polygons, other.polygons + num_polygons, polygons);
}
}

Expand Down Expand Up @@ -98,11 +98,15 @@ template <typename PolygonT>
Convex<PolygonT> * Convex<PolygonT>::clone() const
{
Vec3f * cloned_points = new Vec3f[num_points];
memcpy(cloned_points, polygons, sizeof(Vec3f) * num_points);
std::copy(points, points + num_points, cloned_points);

PolygonT * cloned_polygons = new PolygonT[num_polygons];
memcpy(cloned_polygons, polygons, sizeof(PolygonT) * num_polygons);
return new Convex(true, cloned_points, num_points, cloned_polygons, num_polygons);;
std::copy(polygons, polygons + num_polygons, cloned_polygons);

Convex * copy_ptr = new Convex(true, cloned_points, num_points, cloned_polygons, num_polygons);

copy_ptr->ShapeBase::operator=(*this);
return copy_ptr;
}

template <typename PolygonT>
Expand Down
3 changes: 2 additions & 1 deletion include/hpp/fcl/shape/geometric_shapes.h
Original file line number Diff line number Diff line change
Expand Up @@ -535,9 +535,10 @@ class HPP_FCL_DLLAPI ConvexBase : public ShapeBase
if(!copy.own_storage_)
{
copy.points = new Vec3f[copy.num_points];
memcpy((void*)copy.points, points, sizeof(Vec3f) * (size_t)copy.num_points);
std::copy(points, points + num_points, copy.points);
}
copy.own_storage_ = true;
copy.ShapeBase::operator=(*this);

return copy_ptr;
}
Expand Down
13 changes: 13 additions & 0 deletions python/collision-geometries.cc
Original file line number Diff line number Diff line change
Expand Up @@ -439,6 +439,7 @@ void exposeCollisionGeometries ()
"A class describing the AABB collision structure, which is a box in 3D space determined by two diagonal points",
no_init)
.def(init<>(bp::arg("self"), "Default constructor"))
.def(init<AABB>(bp::args("self","other"), "Copy constructor"))
.def(init<Vec3f>(bp::args("self","v"),"Creating an AABB at position v with zero size."))
.def(init<Vec3f,Vec3f>(bp::args("self","a","b"),"Creating an AABB with two endpoints a and b."))
.def(init<AABB,Vec3f>(bp::args("self","core","delta"),"Creating an AABB centered as core and is of half-dimension delta."))
Expand Down Expand Up @@ -471,6 +472,18 @@ void exposeCollisionGeometries ()
// bp::args("self","other"),
// "Distance between two AABBs.")

.add_property("min_",
bp::make_function(+[](AABB & self) -> Vec3f & { return self.min_; }, bp::return_internal_reference<>()),
bp::make_function(+[](AABB & self, const Vec3f & min_) -> void { self.min_ = min_; }),
"The min point in the AABB.")
.add_property("max_",
bp::make_function(+[](AABB & self) -> Vec3f & { return self.max_; }, bp::return_internal_reference<>()),
bp::make_function(+[](AABB & self, const Vec3f & max_) -> void { self.max_ = max_; }),
"The max point in the AABB.")

.def(bp::self == bp::self)
.def(bp::self != bp::self)

.def(bp::self + bp::self)
.def(bp::self += bp::self)
.def(bp::self += Vec3f())
Expand Down
8 changes: 4 additions & 4 deletions src/BVH/BVH_model.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ int BVHModelBase::addTriangles(const Matrixx3i & triangles)
return BVH_ERR_MODEL_OUT_OF_MEMORY;
}

memcpy(temp, tri_indices, sizeof(Triangle) * (size_t)num_tris);
std::copy(tri_indices, tri_indices + num_tris, temp);
delete [] tri_indices;
tri_indices = temp;
num_tris_allocated = num_tris_allocated * 2 + num_tris_to_add;
Expand Down Expand Up @@ -372,7 +372,7 @@ int BVHModelBase::addTriangle(const Vec3f& p1, const Vec3f& p2, const Vec3f& p3)
return BVH_ERR_MODEL_OUT_OF_MEMORY;
}

memcpy(temp, tri_indices, sizeof(Triangle) * (size_t)num_tris);
std::copy(tri_indices, tri_indices + num_tris, temp);
delete [] tri_indices;
tri_indices = temp;
num_tris_allocated *= 2;
Expand Down Expand Up @@ -465,7 +465,7 @@ int BVHModelBase::addSubModel(const std::vector<Vec3f>& ps, const std::vector<Tr
return BVH_ERR_MODEL_OUT_OF_MEMORY;
}

memcpy(temp, tri_indices, sizeof(Triangle) * (size_t)num_tris);
std::copy(tri_indices, tri_indices + num_tris, temp);
delete [] tri_indices;
tri_indices = temp;
num_tris_allocated = num_tris_allocated * 2 + num_tris_to_add - 1;
Expand Down Expand Up @@ -507,7 +507,7 @@ int BVHModelBase::endModel()
std::cerr << "BVH Error! Out of memory for tri_indices array in endModel() call!" << std::endl;
return BVH_ERR_MODEL_OUT_OF_MEMORY;
}
memcpy(new_tris, tri_indices, sizeof(Triangle) * (size_t)num_tris);
std::copy(tri_indices, tri_indices + num_tris, new_tris);
delete [] tri_indices;
tri_indices = new_tris;
num_tris_allocated = num_tris;
Expand Down
2 changes: 2 additions & 0 deletions src/broadphase/broadphase_dynamic_AABB_tree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -600,6 +600,8 @@ void DynamicAABBTreeCollisionManager::update()
CollisionObject* obj = it->first;
DynamicAABBNode* node = it->second;
node->bv = obj->getAABB();
if(node->bv.volume() <= 0.)
throw std::invalid_argument("The bounding volume has a negative volume.");
}

dtree.refit();
Expand Down
8 changes: 5 additions & 3 deletions src/shape/geometric_shapes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,19 +70,21 @@ ConvexBase::ConvexBase(const ConvexBase& other) :
if (own_storage_ && points) delete [] points;

points = new Vec3f[num_points];
memcpy((void*)points, other.points, sizeof(Vec3f) * num_points);
std::copy(other.points, other.points + num_points, points);
}
else
points = other.points;

neighbors = new Neighbors[num_points];
memcpy(neighbors, other.neighbors, sizeof(Neighbors) * num_points);
std::copy(other.neighbors, other.neighbors + num_points, neighbors);

std::size_t c_nneighbors = 0;
for (std::size_t i = 0; i < num_points; ++i)
c_nneighbors += neighbors[i].count();
nneighbors_ = new unsigned int[c_nneighbors];
memcpy(nneighbors_, other.nneighbors_, sizeof(unsigned int) * c_nneighbors);
std::copy(other.nneighbors_, other.nneighbors_ + c_nneighbors, nneighbors_);

ShapeBase::operator=(*this);
}

ConvexBase::~ConvexBase ()
Expand Down