Skip to content

Commit 1fa25e3

Browse files
committed
Rebase from 'release/noetic/geometric_shapes'
1 parent c47976d commit 1fa25e3

File tree

16 files changed

+214
-144
lines changed

16 files changed

+214
-144
lines changed

.github/workflows/ci.yaml

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,22 +29,23 @@ jobs:
2929
BASEDIR: ${{ github.workspace }}/.work
3030
CACHE_PREFIX: ${{ matrix.env.ROS_DISTRO }}-${{ matrix.env.ROS_REPO }}
3131
CLANG_TIDY_BASE_REF: ${{ github.base_ref || github.ref }}
32+
GHA_CACHE_SAVE: always
3233

3334
name: ${{ matrix.env.ROS_DISTRO }}-${{ matrix.env.ROS_REPO }}${{ matrix.env.CATKIN_LINT && ' + catkin_lint' || ''}}${{ matrix.env.CLANG_TIDY && ' + clang-tidy' || ''}}
3435
runs-on: ubuntu-latest
3536
steps:
36-
- uses: actions/checkout@v2
37+
- uses: actions/checkout@v3
3738
# The target directory cache doesn't include the source directory because
3839
# that comes from the checkout. See "prepare target_ws for cache" task below
3940
- name: cache target_ws
40-
uses: pat-s/always-upload-cache@v2.1.5
41+
uses: rhaschke/cache@main
4142
with:
4243
path: ${{ env.BASEDIR }}/target_ws
4344
key: target_ws-${{ env.CACHE_PREFIX }}-${{ hashFiles('**/CMakeLists.txt', '**/package.xml') }}-${{ github.run_id }}
4445
restore-keys: |
4546
target_ws-${{ env.CACHE_PREFIX }}-${{ hashFiles('**/CMakeLists.txt', '**/package.xml') }}
4647
- name: cache ccache
47-
uses: pat-s/always-upload-cache@v2.1.5
48+
uses: rhaschke/cache@main
4849
with:
4950
path: ${{ env.CCACHE_DIR }}
5051
key: ccache-${{ env.CACHE_PREFIX }}-${{ github.sha }}-${{ github.run_id }}
@@ -55,7 +56,7 @@ jobs:
5556
uses: ros-industrial/industrial_ci@master
5657
env: ${{ matrix.env }}
5758
- name: upload test artifacts (on failure)
58-
uses: actions/upload-artifact@v2
59+
uses: actions/upload-artifact@v3
5960
if: failure()
6061
with:
6162
name: test-results

.github/workflows/format.yaml

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,10 @@ on:
1111
jobs:
1212
pre-commit:
1313
name: Format
14-
runs-on: ubuntu-latest
14+
runs-on: ubuntu-20.04
1515
steps:
16-
- uses: actions/checkout@v2
17-
- uses: actions/setup-python@v2
16+
- uses: actions/checkout@v3
1817
- name: Install clang-format-10
1918
run: sudo apt-get install clang-format-10
2019
- uses: rhaschke/[email protected]
21-
- uses: pre-commit/action@v2.0.0
20+
- uses: pre-commit/action@v3.0.0

.github/workflows/prerelease.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,6 @@ jobs:
2121
name: "${{ matrix.distro }}"
2222
runs-on: ubuntu-latest
2323
steps:
24-
- uses: actions/checkout@v2
24+
- uses: actions/checkout@v3
2525
- name: industrial_ci
2626
uses: ros-industrial/industrial_ci@master

CHANGELOG.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,12 @@
22
Changelog for package geometric_shapes
33
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
44

5+
0.7.5 (2023-04-12)
6+
------------------
7+
* Limit indefinite growth of OBBs during merging (`#232 <https://github.com/ros-planning/geometric_shapes/issues/232>`_)
8+
* Correctly initialize OBB with default constructor
9+
* Contributors: Martin Pecka
10+
511
0.7.4 (2023-03-31)
612
------------------
713
* Body::getScaledDimensions(): avoid vtable lookup (`#225 <https://github.com/ros-planning/geometric_shapes/issues/225>`_)

debian/changelog.em

Lines changed: 0 additions & 7 deletions
This file was deleted.

debian/compat.em

Lines changed: 0 additions & 1 deletion
This file was deleted.

debian/control.em

Lines changed: 0 additions & 14 deletions
This file was deleted.

debian/copyright.em

Lines changed: 0 additions & 11 deletions
This file was deleted.

debian/gbp.conf.em

Lines changed: 0 additions & 3 deletions
This file was deleted.

debian/rules.em

Lines changed: 0 additions & 67 deletions
This file was deleted.

debian/source/format.em

Lines changed: 0 additions & 1 deletion
This file was deleted.

debian/source/options.em

Lines changed: 0 additions & 6 deletions
This file was deleted.

include/geometric_shapes/obb.h

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
#include <Eigen/Core>
4343
#include <Eigen/Geometry>
4444

45+
#include <eigen_stl_containers/eigen_stl_containers.h>
4546
#include <geometric_shapes/aabb.h>
4647

4748
namespace bodies
@@ -52,6 +53,8 @@ class OBBPrivate;
5253
class OBB
5354
{
5455
public:
56+
/** \brief Initialize an oriented bounding box at position 0, with 0 extents and
57+
* identity orientation. */
5558
OBB();
5659
OBB(const OBB& other);
5760
OBB(const Eigen::Isometry3d& pose, const Eigen::Vector3d& extents);
@@ -114,14 +117,27 @@ class OBB
114117
* \param point The point to check.
115118
* \return Whether the point is inside or not.
116119
*/
117-
bool contains(const Eigen::Vector3d& point);
120+
bool contains(const Eigen::Vector3d& point) const;
118121

119122
/**
120123
* \brief Check whether this and the given OBBs have nonempty intersection.
121124
* \param other The other OBB to check.
122125
* \return Whether the OBBs overlap.
123126
*/
124-
bool overlaps(const OBB& other);
127+
bool overlaps(const OBB& other) const;
128+
129+
/**
130+
* \brief Check if this OBB contains whole other OBB.
131+
* \param point The point to check.
132+
* \return Whether the point is inside or not.
133+
*/
134+
bool contains(const OBB& obb) const;
135+
136+
/**
137+
* \brief Compute coordinates of the 8 vertices of this OBB.
138+
* \return The vertices.
139+
*/
140+
EigenSTL::vector_Vector3d computeVertices() const;
125141

126142
protected:
127143
/** \brief PIMPL pointer */

package.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<package format="3">
22
<name>geometric_shapes</name>
3-
<version>0.7.4</version>
3+
<version>0.7.5</version>
44
<description>Generic definitions of geometric shapes and bodies.</description>
55

66
<author email="[email protected]">Ioan Sucan</author>

src/obb.cpp

Lines changed: 73 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -42,16 +42,29 @@ class OBBPrivate : public FCL_OBB
4242

4343
OBB::OBB()
4444
{
45-
this->obb_.reset(new OBBPrivate);
45+
obb_.reset(new OBBPrivate);
46+
// Initialize the OBB to position 0, with 0 extents and identity rotation
47+
#if FCL_MAJOR_VERSION > 0 || FCL_MINOR_VERSION > 5
48+
// FCL 0.6+ does not zero-initialize the OBB.
49+
obb_->extent.setZero();
50+
obb_->To.setZero();
51+
obb_->axis.setIdentity();
52+
#else
53+
// FCL 0.5 zero-initializes the OBB, so we just put the identity into orientation.
54+
obb_->axis[0][0] = 1.0;
55+
obb_->axis[1][1] = 1.0;
56+
obb_->axis[2][2] = 1.0;
57+
#endif
4658
}
4759

48-
OBB::OBB(const OBB& other) : OBB()
60+
OBB::OBB(const OBB& other)
4961
{
50-
*obb_ = *other.obb_;
62+
obb_.reset(new OBBPrivate(*other.obb_));
5163
}
5264

53-
OBB::OBB(const Eigen::Isometry3d& pose, const Eigen::Vector3d& extents) : OBB()
65+
OBB::OBB(const Eigen::Isometry3d& pose, const Eigen::Vector3d& extents)
5466
{
67+
obb_.reset(new OBBPrivate);
5568
setPoseAndExtents(pose, extents);
5669
}
5770

@@ -94,20 +107,12 @@ void OBB::getPose(Eigen::Isometry3d& pose) const
94107
{
95108
pose = Eigen::Isometry3d::Identity();
96109
pose.translation() = fromFcl(obb_->To);
97-
// If all axes are zero, we report the rotation as identity
98-
// This happens if OBB is default-constructed
99110
#if FCL_MAJOR_VERSION == 0 && FCL_MINOR_VERSION == 5
100-
if (!obb_->axis[0].isZero() && !obb_->axis[3].isZero() && !obb_->axis[2].isZero())
101-
{
102-
pose.linear().col(0) = fromFcl(obb_->axis[0]);
103-
pose.linear().col(1) = fromFcl(obb_->axis[1]);
104-
pose.linear().col(2) = fromFcl(obb_->axis[2]);
105-
}
111+
pose.linear().col(0) = fromFcl(obb_->axis[0]);
112+
pose.linear().col(1) = fromFcl(obb_->axis[1]);
113+
pose.linear().col(2) = fromFcl(obb_->axis[2]);
106114
#else
107-
if (!obb_->axis.isApprox(fcl::Matrix3d::Zero()))
108-
{
109-
pose.linear() = obb_->axis;
110-
}
115+
pose.linear() = obb_->axis;
111116
#endif
112117
}
113118

@@ -132,20 +137,70 @@ void OBB::toAABB(AABB& aabb) const
132137

133138
OBB* OBB::extendApprox(const OBB& box)
134139
{
140+
if (this->getExtents() == Eigen::Vector3d::Zero())
141+
{
142+
*obb_ = *box.obb_;
143+
return this;
144+
}
145+
146+
if (this->contains(box))
147+
return this;
148+
149+
if (box.contains(*this))
150+
{
151+
*obb_ = *box.obb_;
152+
return this;
153+
}
154+
135155
*this->obb_ += *box.obb_;
136156
return this;
137157
}
138158

139-
bool OBB::contains(const Eigen::Vector3d& point)
159+
bool OBB::contains(const Eigen::Vector3d& point) const
140160
{
141161
return obb_->contain(toFcl(point));
142162
}
143163

144-
bool OBB::overlaps(const bodies::OBB& other)
164+
bool OBB::overlaps(const bodies::OBB& other) const
145165
{
146166
return obb_->overlap(*other.obb_);
147167
}
148168

169+
EigenSTL::vector_Vector3d OBB::computeVertices() const
170+
{
171+
const Eigen::Vector3d e = getExtents() / 2; // do not use auto type, Eigen would be inefficient
172+
// clang-format off
173+
EigenSTL::vector_Vector3d result = {
174+
{ -e[0], -e[1], -e[2] },
175+
{ -e[0], -e[1], e[2] },
176+
{ -e[0], e[1], -e[2] },
177+
{ -e[0], e[1], e[2] },
178+
{ e[0], -e[1], -e[2] },
179+
{ e[0], -e[1], e[2] },
180+
{ e[0], e[1], -e[2] },
181+
{ e[0], e[1], e[2] },
182+
};
183+
// clang-format on
184+
185+
const auto pose = getPose();
186+
for (auto& v : result)
187+
{
188+
v = pose * v;
189+
}
190+
191+
return result;
192+
}
193+
194+
bool OBB::contains(const OBB& obb) const
195+
{
196+
for (const auto& v : obb.computeVertices())
197+
{
198+
if (!contains(v))
199+
return false;
200+
}
201+
return true;
202+
}
203+
149204
OBB::~OBB() = default;
150205

151206
} // namespace bodies

0 commit comments

Comments
 (0)