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

Add raycast query to BulletCollisionDetector #1309

Merged
merged 2 commits into from
May 7, 2019
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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

### [DART 6.9.0 (20XX-XX-XX)](https://github.com/dartsim/dart/milestone/52?closed=1)

* Collision Detection

* Added raycast query to BulletCollisionDetector: [#1309](https://github.com/dartsim/dart/pull/1309)

* Parser

* Changed URDF parser to use URDF material color when specified: [#1295](https://github.com/dartsim/dart/pull/1295)
Expand Down
4 changes: 4 additions & 0 deletions dart/collision/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -41,5 +41,9 @@ add_subdirectory(ode)
add_subdirectory(bullet)

dart_format_add(
RaycastOption.hpp
RaycastOption.cpp
RaycastResult.hpp
RaycastResult.cpp
SmartPointer.hpp
)
13 changes: 13 additions & 0 deletions dart/collision/CollisionDetector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,19 @@ CollisionDetector::createCollisionGroupAsSharedPtr()
return std::shared_ptr<CollisionGroup>(createCollisionGroup().release());
}

//==============================================================================
bool CollisionDetector::raycast(
CollisionGroup* /*group*/,
const Eigen::Vector3d& /*from*/,
const Eigen::Vector3d& /*to*/,
const RaycastOption& /*option*/,
RaycastResult* /*result*/)
{
dtwarn << "[CollisionDetector] Raycast is not supported by '" << getType()
<< "'\n";
return false;
}

//==============================================================================
std::shared_ptr<CollisionObject> CollisionDetector::claimCollisionObject(
const dynamics::ShapeFrame* shapeFrame)
Expand Down
17 changes: 17 additions & 0 deletions dart/collision/CollisionDetector.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@
#include "dart/collision/CollisionResult.hpp"
#include "dart/collision/DistanceOption.hpp"
#include "dart/collision/DistanceResult.hpp"
#include "dart/collision/RaycastOption.hpp"
#include "dart/collision/RaycastResult.hpp"
#include "dart/collision/SmartPointer.hpp"
#include "dart/dynamics/SmartPointer.hpp"

Expand Down Expand Up @@ -156,6 +158,21 @@ class CollisionDetector : public std::enable_shared_from_this<CollisionDetector>
const DistanceOption& option = DistanceOption(false, 0.0, nullptr),
DistanceResult* result = nullptr) = 0;

/// Perform raycast to a collision group.
///
/// \param[in] group The collision group the ray will be casted onto.
/// \param[in] from The start point of the ray in world coordinates.
/// \param[in] to The end point of the ray in world coordinates.
/// \param[in] option The raycast option.
/// \param[in] result The raycast result.
/// \return True if the ray hit an collision object.
virtual bool raycast(
CollisionGroup* group,
const Eigen::Vector3d& from,
const Eigen::Vector3d& to,
const RaycastOption& option = RaycastOption(),
RaycastResult* result = nullptr);

protected:

class CollisionObjectManager;
Expand Down
46 changes: 46 additions & 0 deletions dart/collision/RaycastOption.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*
* Copyright (c) 2011-2019, The DART development contributors
* All rights reserved.
*
* The list of contributors can be found at:
* https://github.com/dartsim/dart/blob/master/LICENSE
*
* This file is provided under the following "BSD-style" License:
* 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.
* 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.
*/

#include "dart/collision/RaycastOption.hpp"

namespace dart {
namespace collision {

//==============================================================================
RaycastOption::RaycastOption(bool enableAllHits, bool sortByClosest)
: mEnableAllHits(enableAllHits), mSortByClosest(sortByClosest)
{
// Do nothing
}

} // namespace collision
} // namespace dart
57 changes: 57 additions & 0 deletions dart/collision/RaycastOption.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/*
* Copyright (c) 2011-2019, The DART development contributors
* All rights reserved.
*
* The list of contributors can be found at:
* https://github.com/dartsim/dart/blob/master/LICENSE
*
* This file is provided under the following "BSD-style" License:
* 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.
* 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.
*/

#ifndef DART_COLLISION_RAYCASTOPTION_HPP_
#define DART_COLLISION_RAYCASTOPTION_HPP_

#include <cstddef>
#include <memory>

namespace dart {
namespace collision {

struct RaycastOption
{
/// Constructor
RaycastOption(bool enableAllHits = false, bool sortByClosest = false);

bool mEnableAllHits;

bool mSortByClosest;

// TODO(JS): Add filter
};

} // namespace collision
} // namespace dart

#endif // DART_COLLISION_RAYCASTOPTION_HPP_
57 changes: 57 additions & 0 deletions dart/collision/RaycastResult.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/*
* Copyright (c) 2011-2019, The DART development contributors
* All rights reserved.
*
* The list of contributors can be found at:
* https://github.com/dartsim/dart/blob/master/LICENSE
*
* This file is provided under the following "BSD-style" License:
* 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.
* 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.
*/

#include "dart/collision/RaycastResult.hpp"

namespace dart {
namespace collision {

//==============================================================================
RaycastResult::RaycastResult()
{
// Do nothing
}

//==============================================================================
void RaycastResult::clear()
{
mRayHits.clear();
}

//==============================================================================
bool RaycastResult::hasHit() const
{
return !mRayHits.empty();
}

} // namespace collision
} // namespace dart
78 changes: 78 additions & 0 deletions dart/collision/RaycastResult.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
/*
* Copyright (c) 2011-2019, The DART development contributors
* All rights reserved.
*
* The list of contributors can be found at:
* https://github.com/dartsim/dart/blob/master/LICENSE
*
* This file is provided under the following "BSD-style" License:
* 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.
* 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.
*/

#ifndef DART_COLLISION_RAYCASTRESULT_HPP_
#define DART_COLLISION_RAYCASTRESULT_HPP_

#include <vector>
#include <Eigen/Dense>

namespace dart {
namespace collision {

class CollisionObject;

struct RayHit
{
/// The collision object the ray hit
const CollisionObject* mCollisionObject;

/// The normal at the hit point in the world coordinates
Eigen::Vector3d mNormal;

/// The hit point in the world coordinates
Eigen::Vector3d mPoint;

/// The fraction from "from" point to "to" point
double mFraction;
};

struct RaycastResult
{
/// Constructor
RaycastResult();

/// Clear the result
void clear();

/// Returns true if there is a hit
bool hasHit() const;

bool mHasHit;

std::vector<RayHit> mRayHits;
};

} // namespace collision
} // namespace dart

#endif // DART_COLLISION_RAYCASTRESULT_HPP_
Loading