Skip to content

Commit

Permalink
Rebase from 'release/jazzy/geometric_shapes'
Browse files Browse the repository at this point in the history
  • Loading branch information
sea-bass committed Nov 29, 2024
1 parent 73d784e commit a0446fc
Show file tree
Hide file tree
Showing 20 changed files with 747 additions and 162 deletions.
17 changes: 10 additions & 7 deletions .github/workflows/build_and_test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,11 @@ jobs:
name: "${{ matrix.env.ROS_DISTRO }}-${{ matrix.env.ROS_REPO }}${{ matrix.env.CCOV && ' + ccov' || ''}}"
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
- name: cache upstream_ws
uses: pat-s/always-upload-cache@v2.1.5
uses: actions/cache@v4
with:
save-always: true
path: ${{ env.BASEDIR }}/upstream_ws
key: upstream_ws-${{ env.CACHE_PREFIX }}-${{ github.run_id }}
restore-keys: |
Expand All @@ -58,31 +59,33 @@ jobs:
# that comes from the checkout. See "prepare target_ws for cache" task below
- name: cache target_ws
if: ${{ ! matrix.env.CCOV }}
uses: pat-s/always-upload-cache@v2.1.5
uses: actions/cache@v4
with:
save-always: true
path: ${{ env.BASEDIR }}/target_ws
key: target_ws-${{ env.CACHE_PREFIX }}-${{ hashFiles('**/CMakeLists.txt', '**/package.xml') }}-${{ github.run_id }}
restore-keys: |
target_ws-${{ env.CACHE_PREFIX }}-${{ hashFiles('**/CMakeLists.txt', '**/package.xml') }}
- name: cache ccache
uses: pat-s/always-upload-cache@v2.1.5
uses: actions/cache@v4
with:
save-always: true
path: ${{ env.CCACHE_DIR }}
key: ccache-${{ env.CACHE_PREFIX }}-${{ github.sha }}-${{ github.run_id }}
restore-keys: |
ccache-${{ env.CACHE_PREFIX }}-${{ github.sha }}
ccache-${{ env.CACHE_PREFIX }}
- name: industrial_ci
uses: 'ros-industrial/industrial_ci@master'
uses: ros-industrial/industrial_ci@master
env: ${{ matrix.env }}
- name: upload test artifacts (on failure)
uses: actions/upload-artifact@v2
uses: actions/upload-artifact@v4
if: failure()
with:
name: test-results
path: ${{ env.BASEDIR }}/target_ws/**/test_results/**/*.xml
- name: upload codecov report
uses: codecov/codecov-action@v1
uses: codecov/codecov-action@v4
if: ${{ matrix.env.CCOV }}
with:
files: ${{ env.BASEDIR }}/coverage.info
Expand Down
5 changes: 2 additions & 3 deletions .github/workflows/format.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@ jobs:
name: Format
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-python@v2
- uses: actions/checkout@v4
- name: Install clang-format-14
run: sudo apt-get install clang-format-14
- uses: pre-commit/action@v2.0.0
- uses: pre-commit/action@v3.0.1
20 changes: 12 additions & 8 deletions .github/workflows/prerelease.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,26 @@ name: pre-release

on:
workflow_dispatch:
inputs:
ROS_DISTRO:
type: string
required: true
description: 'ROS distribution codename:'
default: rolling

permissions:
contents: read # to fetch code (actions/checkout)

jobs:
default:
strategy:
fail-fast: false
matrix:
distro: [foxy, galactic, humble, rolling]

env:
ROS_DISTRO: ${{ matrix.distro }}
ROS_DISTRO: ${{ inputs.ROS_DISTRO }}
PRERELEASE: true
BASEDIR: ${{ github.workspace }}/.work

name: "${{ matrix.distro }}"
name: "${{ inputs.ROS_DISTRO }}"
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
- name: industrial_ci
uses: ros-industrial/industrial_ci@master
4 changes: 2 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
repos:
# Standard hooks
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v3.4.0
rev: v4.6.0
hooks:
- id: check-added-large-files
- id: check-case-conflict
Expand All @@ -34,7 +34,7 @@ repos:
- id: trailing-whitespace

- repo: https://github.com/psf/black
rev: 22.3.0
rev: 24.8.0
hooks:
- id: black

Expand Down
7 changes: 7 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@
Changelog for package geometric_shapes
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

2.3.0 (2024-11-29)
------------------
* Install headers into subdirectory (`#253 <https://github.com/moveit/geometric_shapes/issues/253>`_)
* Added bodies::Body::computeBoundingBox (oriented box version) (`#239 <https://github.com/moveit/geometric_shapes/issues/239>`_)
* Improve padding of meshes using weighted vertex normals (`#240 <https://github.com/moveit/geometric_shapes/issues/240>`_)
* Contributors: Kenji Brameld (TRACLabs), Robert Haschke, Sebastian Castro, Sebastian Pelletier, Tyler Mayoff

2.2.1 (2024-06-26)
------------------
* Use the system version of octomap (`#244 <https://github.com/ros-planning/geometric_shapes/issues/244>`_)
Expand Down
10 changes: 7 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ find_package(rclcpp REQUIRED)
find_package(resource_retriever REQUIRED)
find_package(shape_msgs REQUIRED)
find_package(visualization_msgs REQUIRED)
find_package(fcl REQUIRED)
include(ConfigExtras)

set(THIS_PACKAGE_EXPORT_DEPENDS
Expand All @@ -73,20 +74,23 @@ set(THIS_PACKAGE_EXPORT_DEPENDS
# Set VERSION from package.xml
ament_package_xml()

include_directories(include)

add_library(${PROJECT_NAME} SHARED
src/aabb.cpp
src/bodies.cpp
src/body_operations.cpp
src/mesh_operations.cpp
src/obb.cpp
src/shape_extents.cpp
src/shape_operations.cpp
src/shape_to_marker.cpp
src/shapes.cpp
)
set_target_properties(${PROJECT_NAME} PROPERTIES VERSION ${${PROJECT_NAME}_VERSION} WINDOWS_EXPORT_ALL_SYMBOLS TRUE)
target_compile_options(${PROJECT_NAME} PRIVATE ${PROJECT_COMPILE_OPTIONS})
target_include_directories(${PROJECT_NAME}
PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:include/${PROJECT_NAME}>)
target_link_libraries(${PROJECT_NAME} fcl)
ament_target_dependencies(${PROJECT_NAME}
${THIS_PACKAGE_EXPORT_DEPENDS}
)
Expand Down Expand Up @@ -114,7 +118,7 @@ install(
RUNTIME DESTINATION bin
INCLUDES DESTINATION include
)
install(DIRECTORY include/ DESTINATION include)
install(DIRECTORY include/ DESTINATION include/${PROJECT_NAME})

ament_export_targets(export_${PROJECT_NAME} HAS_LIBRARY_TARGET)
ament_export_dependencies(${THIS_PACKAGE_EXPORT_DEPENDS})
Expand Down
9 changes: 9 additions & 0 deletions include/geometric_shapes/bodies.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@

#define _USE_MATH_DEFINES
#include "geometric_shapes/aabb.h"
#include "geometric_shapes/obb.h"
#include "geometric_shapes/shapes.h"
#include <eigen_stl_containers/eigen_stl_containers.h>
#include <random_numbers/random_numbers.h>
Expand Down Expand Up @@ -240,6 +241,10 @@ class Body
pose. Scaling and padding are accounted for. */
virtual void computeBoundingBox(AABB& bbox) const = 0;

/** \brief Compute the oriented bounding box for the body, in its current
pose. Scaling and padding are accounted for. */
virtual void computeBoundingBox(OBB& bbox) const = 0;

/** \brief Get a clone of this body, but one that is located at the pose \e pose */
inline BodyPtr cloneAt(const Eigen::Isometry3d& pose) const
{
Expand Down Expand Up @@ -307,6 +312,7 @@ class Sphere : public Body
void computeBoundingSphere(BoundingSphere& sphere) const override;
void computeBoundingCylinder(BoundingCylinder& cylinder) const override;
void computeBoundingBox(AABB& bbox) const override;
void computeBoundingBox(OBB& bbox) const override;
bool intersectsRay(const Eigen::Vector3d& origin, const Eigen::Vector3d& dir,
EigenSTL::vector_Vector3d* intersections = nullptr, unsigned int count = 0) const override;

Expand Down Expand Up @@ -359,6 +365,7 @@ class Cylinder : public Body
void computeBoundingSphere(BoundingSphere& sphere) const override;
void computeBoundingCylinder(BoundingCylinder& cylinder) const override;
void computeBoundingBox(AABB& bbox) const override;
void computeBoundingBox(OBB& bbox) const override;
bool intersectsRay(const Eigen::Vector3d& origin, const Eigen::Vector3d& dir,
EigenSTL::vector_Vector3d* intersections = nullptr, unsigned int count = 0) const override;

Expand Down Expand Up @@ -421,6 +428,7 @@ class Box : public Body
void computeBoundingSphere(BoundingSphere& sphere) const override;
void computeBoundingCylinder(BoundingCylinder& cylinder) const override;
void computeBoundingBox(AABB& bbox) const override;
void computeBoundingBox(OBB& bbox) const override;
bool intersectsRay(const Eigen::Vector3d& origin, const Eigen::Vector3d& dir,
EigenSTL::vector_Vector3d* intersections = nullptr, unsigned int count = 0) const override;

Expand Down Expand Up @@ -483,6 +491,7 @@ class ConvexMesh : public Body
void computeBoundingSphere(BoundingSphere& sphere) const override;
void computeBoundingCylinder(BoundingCylinder& cylinder) const override;
void computeBoundingBox(AABB& bbox) const override;
void computeBoundingBox(OBB& bbox) const override;
bool intersectsRay(const Eigen::Vector3d& origin, const Eigen::Vector3d& dir,
EigenSTL::vector_Vector3d* intersections = nullptr, unsigned int count = 0) const override;

Expand Down
3 changes: 3 additions & 0 deletions include/geometric_shapes/body_operations.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,9 @@ void mergeBoundingSpheres(const std::vector<BoundingSphere>& spheres, BoundingSp
/** \brief Compute an axis-aligned bounding box to enclose a set of bounding boxes. */
void mergeBoundingBoxes(const std::vector<AABB>& boxes, AABB& mergedBox);

/** \brief Compute an approximate oriented bounding box to enclose a set of bounding boxes. */
void mergeBoundingBoxesApprox(const std::vector<OBB>& boxes, OBB& mergedBox);

/** \brief Compute the bounding sphere for a set of \e bodies and store the resulting sphere in \e mergedSphere */
void computeBoundingSphere(const std::vector<const Body*>& bodies, BoundingSphere& mergedSphere);
} // namespace bodies
Expand Down
142 changes: 142 additions & 0 deletions include/geometric_shapes/obb.h
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
3 changes: 2 additions & 1 deletion include/geometric_shapes/shapes.h
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,8 @@ class Mesh : public Shape
/** \brief Compute the normals of each triangle from its vertices via cross product. */
void computeTriangleNormals();

/** \brief Compute vertex normals by averaging from adjacent triangle normals.
/** \brief Compute vertex normals by averaging from adjacent triangle normals, weighted using magnitude of
* angles formed by adjacent triangles at the vertex.
Calls computeTriangleNormals() if needed. */
void computeVertexNormals();
Expand Down
Loading

0 comments on commit a0446fc

Please sign in to comment.