Skip to content

Commit

Permalink
[dartpy] Add raycast option and result (#1343)
Browse files Browse the repository at this point in the history
  • Loading branch information
jslee02 authored May 29, 2019
1 parent a6c4412 commit 5f20205
Show file tree
Hide file tree
Showing 12 changed files with 340 additions and 9 deletions.
4 changes: 2 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

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

*
* dartpy

*
* Added raycast option and result: [#1343](https://github.com/dartsim/dart/pull/1343)

### [DART 6.9.1 (2019-XX-XX)](https://github.com/dartsim/dart/milestone/59?closed=1)

Expand Down
4 changes: 2 additions & 2 deletions python/dartpy/collision/BulletCollisionDetector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@ void BulletCollisionDetector(py::module& m)
.def(
"createCollisionGroup",
+[](dart::collision::BulletCollisionDetector* self)
-> std::unique_ptr<dart::collision::CollisionGroup> {
return self->createCollisionGroup();
-> std::shared_ptr<dart::collision::CollisionGroup> {
return self->createCollisionGroupAsSharedPtr();
})
.def_static(
"getStaticType",
Expand Down
1 change: 1 addition & 0 deletions python/dartpy/collision/CollisionGroup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
*/

#include <dart/dart.hpp>
#include <pybind11/eigen.h>
#include <pybind11/pybind11.h>

namespace py = pybind11;
Expand Down
1 change: 1 addition & 0 deletions python/dartpy/collision/Contact.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
*/

#include <dart/dart.hpp>
#include <pybind11/eigen.h>
#include <pybind11/pybind11.h>

namespace py = pybind11;
Expand Down
4 changes: 2 additions & 2 deletions python/dartpy/collision/DARTCollisionDetector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@ void DARTCollisionDetector(py::module& m)
.def(
"createCollisionGroup",
+[](dart::collision::DARTCollisionDetector* self)
-> std::unique_ptr<dart::collision::CollisionGroup> {
return self->createCollisionGroup();
-> std::shared_ptr<dart::collision::CollisionGroup> {
return self->createCollisionGroupAsSharedPtr();
})
.def_static(
"getStaticType",
Expand Down
69 changes: 69 additions & 0 deletions python/dartpy/collision/DistanceOption.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
/*
* 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/dart.hpp>
#include <pybind11/pybind11.h>

namespace py = pybind11;

namespace dart {
namespace python {

void DistanceOption(py::module& m)
{
::pybind11::class_<dart::collision::DistanceOption>(m, "DistanceOption")
.def(::pybind11::init<>())
.def(::pybind11::init<bool>(), ::pybind11::arg("enableNearestPoints"))
.def(
::pybind11::init<bool, double>(),
::pybind11::arg("enableNearestPoints"),
::pybind11::arg("distanceLowerBound"))
.def(
::pybind11::init<
bool,
double,
const std::shared_ptr<dart::collision::DistanceFilter>&>(),
::pybind11::arg("enableNearestPoints"),
::pybind11::arg("distanceLowerBound"),
::pybind11::arg("distanceFilter"))
.def_readwrite(
"enableNearestPoints",
&dart::collision::DistanceOption::enableNearestPoints)
.def_readwrite(
"distanceLowerBound",
&dart::collision::DistanceOption::distanceLowerBound)
.def_readwrite(
"distanceFilter", &dart::collision::DistanceOption::distanceFilter);
}

} // namespace python
} // namespace dart
74 changes: 74 additions & 0 deletions python/dartpy/collision/DistanceResult.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
/*
* 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/dart.hpp>
#include <pybind11/pybind11.h>

namespace py = pybind11;

namespace dart {
namespace python {

void DistanceResult(py::module& m)
{
::pybind11::class_<dart::collision::DistanceResult>(m, "DistanceResult")
.def(::pybind11::init<>())
.def(
"clear",
+[](dart::collision::DistanceResult* self) { self->clear(); })
.def(
"found",
+[](const dart::collision::DistanceResult* self) -> bool {
return self->found();
})
.def(
"isMinDistanceClamped",
+[](const dart::collision::DistanceResult* self) -> bool {
return self->isMinDistanceClamped();
})
.def_readwrite(
"minDistance", &dart::collision::DistanceResult::minDistance)
.def_readwrite(
"unclampedMinDistance",
&dart::collision::DistanceResult::unclampedMinDistance)
.def_readwrite(
"shapeFrame1", &dart::collision::DistanceResult::shapeFrame1)
.def_readwrite(
"shapeFrame2", &dart::collision::DistanceResult::shapeFrame2)
.def_readwrite(
"nearestPoint1", &dart::collision::DistanceResult::nearestPoint1)
.def_readwrite(
"nearestPoint2", &dart::collision::DistanceResult::nearestPoint2);
}

} // namespace python
} // namespace dart
4 changes: 2 additions & 2 deletions python/dartpy/collision/OdeCollisionDetector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@ void OdeCollisionDetector(py::module& m)
.def(
"createCollisionGroup",
+[](dart::collision::OdeCollisionDetector* self)
-> std::unique_ptr<dart::collision::CollisionGroup> {
return self->createCollisionGroup();
-> std::shared_ptr<dart::collision::CollisionGroup> {
return self->createCollisionGroupAsSharedPtr();
})
.def_static(
"getStaticType",
Expand Down
57 changes: 57 additions & 0 deletions python/dartpy/collision/RaycastOption.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/dart.hpp>
#include <pybind11/pybind11.h>

namespace py = pybind11;

namespace dart {
namespace python {

void RaycastOption(py::module& m)
{
::pybind11::class_<dart::collision::RaycastOption>(m, "RaycastOption")
.def(::pybind11::init<>())
.def(::pybind11::init<bool>(), ::pybind11::arg("enableAllHits"))
.def(
::pybind11::init<bool, bool>(),
::pybind11::arg("enableAllHits"),
::pybind11::arg("sortByClosest"))
.def_readwrite(
"mEnableAllHits", &dart::collision::RaycastOption::mEnableAllHits)
.def_readwrite(
"mSortByClosest", &dart::collision::RaycastOption::mSortByClosest);
}

} // namespace python
} // namespace dart
67 changes: 67 additions & 0 deletions python/dartpy/collision/RaycastResult.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
/*
* 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/dart.hpp>
#include <pybind11/eigen.h>
#include <pybind11/pybind11.h>
#include <pybind11/stl.h>

namespace py = pybind11;

namespace dart {
namespace python {

void RaycastResult(py::module& m)
{
::pybind11::class_<dart::collision::RayHit>(m, "RayHit")
.def(::pybind11::init<>())
.def_readwrite(
"mCollisionObject", &dart::collision::RayHit::mCollisionObject)
.def_readwrite("mNormal", &dart::collision::RayHit::mNormal)
.def_readwrite("mPoint", &dart::collision::RayHit::mPoint)
.def_readwrite("mFraction", &dart::collision::RayHit::mFraction);

::pybind11::class_<dart::collision::RaycastResult>(m, "RaycastResult")
.def(::pybind11::init<>())
.def(
"clear", +[](dart::collision::RaycastResult* self) { self->clear(); })
.def(
"hasHit",
+[](const dart::collision::RaycastResult* self) -> bool {
return self->hasHit();
})
.def_readwrite("mHasHit", &dart::collision::RaycastResult::mHasHit)
.def_readwrite("mRayHits", &dart::collision::RaycastResult::mRayHits);
}

} // namespace python
} // namespace dart
12 changes: 12 additions & 0 deletions python/dartpy/collision/module.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,12 @@ void Contact(py::module& sm);
void CollisionOption(py::module& sm);
void CollisionResult(py::module& sm);

void DistanceOption(py::module& sm);
void DistanceResult(py::module& sm);

void RaycastOption(py::module& sm);
void RaycastResult(py::module& sm);

void CollisionDetector(py::module& sm);
void FCLCollisionDetector(py::module& sm);
void DARTCollisionDetector(py::module& sm);
Expand Down Expand Up @@ -70,6 +76,12 @@ void dart_collision(py::module& m)
CollisionOption(sm);
CollisionResult(sm);

DistanceOption(sm);
DistanceResult(sm);

RaycastOption(sm);
RaycastResult(sm);

CollisionDetector(sm);
FCLCollisionDetector(sm);
DARTCollisionDetector(sm);
Expand Down
Loading

0 comments on commit 5f20205

Please sign in to comment.