-
Notifications
You must be signed in to change notification settings - Fork 92
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
[ROS2] Porting bodies::Body::computeBoundingBox changes from noetic to ROS2 #239
base: ros2
Are you sure you want to change the base?
Changes from all commits
92744ad
2e7de79
f74c0d1
994b258
517648f
5d04936
d6a80af
483b844
c014758
9caa2eb
169d33b
e055eed
a108625
0814306
8aa8ca3
f49fdf6
fdad9d3
43939d4
48bc778
5f351f4
e15c6af
520d5a5
126955b
94ea0df
48bba6f
26212d1
b36a5d7
6c321ec
1818146
5bd19db
998a998
0d04ba5
daa7464
7f76e3b
0117184
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,142 @@ | ||
// Copyright 2024 Open Robotics | ||
// | ||
// Redistribution and use in source and binary forms, with or without | ||
// modification, are permitted provided that the following conditions are met: | ||
// | ||
// * Redistributions of source code must retain the above copyright | ||
// notice, this list of conditions and the following disclaimer. | ||
// | ||
// * Redistributions in binary form must reproduce the above copyright | ||
// notice, this list of conditions and the following disclaimer in the | ||
// documentation and/or other materials provided with the distribution. | ||
// | ||
// * Neither the name of the Open Robotics nor the names of its | ||
// contributors may be used to endorse or promote products derived from | ||
// this software without specific prior written permission. | ||
// | ||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | ||
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE | ||
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | ||
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | ||
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | ||
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | ||
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | ||
// POSSIBILITY OF SUCH DAMAGE. | ||
|
||
/* Author: Martin Pecka */ | ||
|
||
#ifndef GEOMETRIC_SHAPES_OBB_H | ||
#define GEOMETRIC_SHAPES_OBB_H | ||
|
||
#include <memory> | ||
|
||
#include <Eigen/Core> | ||
#include <Eigen/Geometry> | ||
|
||
#include <eigen_stl_containers/eigen_stl_containers.h> | ||
#include <geometric_shapes/aabb.h> | ||
|
||
namespace bodies | ||
{ | ||
class OBBPrivate; | ||
|
||
/** \brief Represents an oriented bounding box. */ | ||
class OBB | ||
{ | ||
public: | ||
/** \brief Initialize an oriented bounding box at position 0, with 0 extents and | ||
* identity orientation. */ | ||
OBB(); | ||
OBB(const OBB& other); | ||
OBB(const Eigen::Isometry3d& pose, const Eigen::Vector3d& extents); | ||
virtual ~OBB(); | ||
|
||
OBB& operator=(const OBB& other); | ||
|
||
/** | ||
* \brief Set both the pose and extents of the OBB. | ||
* \param [in] pose New pose of the OBB. | ||
* \param [in] extents New extents of the OBB. | ||
*/ | ||
void setPoseAndExtents(const Eigen::Isometry3d& pose, const Eigen::Vector3d& extents); | ||
|
||
/** | ||
* \brief Get the extents of the OBB. | ||
* \return The extents. | ||
*/ | ||
Eigen::Vector3d getExtents() const; | ||
|
||
/** | ||
* \brief Get the extents of the OBB. | ||
* \param extents [out] The extents. | ||
*/ | ||
void getExtents(Eigen::Vector3d& extents) const; | ||
|
||
/** | ||
* \brief Get the pose of the OBB. | ||
* \return The pose. | ||
*/ | ||
Eigen::Isometry3d getPose() const; | ||
|
||
/** | ||
* \brief Get The pose of the OBB. | ||
* \param pose The pose. | ||
*/ | ||
void getPose(Eigen::Isometry3d& pose) const; | ||
|
||
/** | ||
* \brief Convert this OBB to an axis-aligned BB. | ||
* \return The AABB. | ||
*/ | ||
AABB toAABB() const; | ||
|
||
/** | ||
* \brief Convert this OBB to an axis-aligned BB. | ||
* \param aabb The AABB. | ||
*/ | ||
void toAABB(AABB& aabb) const; | ||
|
||
/** | ||
* \brief Add the other OBB to this one and compute an approximate enclosing OBB. | ||
* \param box The other box to add. | ||
* \return Pointer to this OBB after the update. | ||
*/ | ||
OBB* extendApprox(const OBB& box); | ||
|
||
/** | ||
* \brief Check if this OBB contains the given point. | ||
* \param point The point to check. | ||
* \return Whether the point is inside or not. | ||
*/ | ||
bool contains(const Eigen::Vector3d& point) const; | ||
|
||
/** | ||
* \brief Check whether this and the given OBBs have nonempty intersection. | ||
* \param other The other OBB to check. | ||
* \return Whether the OBBs overlap. | ||
*/ | ||
bool overlaps(const OBB& other) const; | ||
|
||
/** | ||
* \brief Check if this OBB contains whole other OBB. | ||
* \param point The point to check. | ||
* \return Whether the point is inside or not. | ||
*/ | ||
bool contains(const OBB& obb) const; | ||
|
||
/** | ||
* \brief Compute coordinates of the 8 vertices of this OBB. | ||
* \return The vertices. | ||
*/ | ||
EigenSTL::vector_Vector3d computeVertices() const; | ||
|
||
protected: | ||
/** \brief PIMPL pointer */ | ||
std::unique_ptr<OBBPrivate> obb_; | ||
}; | ||
} // namespace bodies | ||
|
||
#endif // GEOMETRIC_SHAPES_OBB_H |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -30,22 +30,24 @@ | |
|
||
#include <geometric_shapes/aabb.h> | ||
|
||
#include <fcl/geometry/shape/utility.h> | ||
|
||
spelletier1996 marked this conversation as resolved.
Show resolved
Hide resolved
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These includes now seem irrelevant. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. With switching to the correct ifdef as you mentioned below I believe that #include <fcl/geometry/shape/utility.h> There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Right, some fcl include is still required. This seems good. |
||
void bodies::AABB::extendWithTransformedBox(const Eigen::Isometry3d& transform, const Eigen::Vector3d& box) | ||
{ | ||
// Method adapted from FCL src/shape/geometric_shapes_utility.cpp#computeBV<AABB, Box>(...) (BSD-licensed code): | ||
// https://github.com/flexible-collision-library/fcl/blob/fcl-0.4/src/shape/geometric_shapes_utility.cpp#L292 | ||
// We don't call their code because it would need creating temporary objects, and their method is in floats. | ||
// We don't call their code because it would need creating temporary objects, and their method is in floats in FCL 0.5 | ||
// | ||
// Here's a nice explanation why it works: https://zeuxcg.org/2010/10/17/aabb-from-obb-with-component-wise-abs/ | ||
|
||
const Eigen::Matrix3d& r = transform.rotation(); | ||
const Eigen::Vector3d& t = transform.translation(); | ||
|
||
double x_range = 0.5 * (fabs(r(0, 0) * box[0]) + fabs(r(0, 1) * box[1]) + fabs(r(0, 2) * box[2])); | ||
double y_range = 0.5 * (fabs(r(1, 0) * box[0]) + fabs(r(1, 1) * box[1]) + fabs(r(1, 2) * box[2])); | ||
double z_range = 0.5 * (fabs(r(2, 0) * box[0]) + fabs(r(2, 1) * box[1]) + fabs(r(2, 2) * box[2])); | ||
|
||
const Eigen::Vector3d v_delta(x_range, y_range, z_range); | ||
extend(t + v_delta); | ||
extend(t - v_delta); | ||
fcl::AABBd aabb; | ||
fcl::computeBV(fcl::Boxd(box), transform, aabb); | ||
extend(aabb.min_); | ||
extend(aabb.max_); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will break ABI (the virtual keyword). Not sure what is the current policy regarding ABI breakages.