forked from AcademySoftwareFoundation/Imath
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implemented pybind11 wrapper for plane (AcademySoftwareFoundation#440)
Signed-off-by: Milana Tratsevska <[email protected]>
- Loading branch information
Showing
5 changed files
with
90 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
// | ||
// SPDX-License-Identifier: BSD-3-Clause | ||
// Copyright Contributors to the OpenEXR Project. | ||
// | ||
|
||
#include "PyBindImath.h" | ||
#include <ImathLine.h> | ||
|
||
|
||
namespace PyBindImath { | ||
template <class T, class Q, class S> | ||
void register_line(pybind11::module& m, const char *name) | ||
{ | ||
pybind11::class_<T> c(m, name); | ||
c.def(pybind11::init<>(), "Uninitialized by default") | ||
.def(pybind11::init<const Q &, Q &>(), pybind11::arg("point1"), pybind11::arg("point2"), "Initialize with two points. The direction is the difference between the points.") | ||
.def("__str__", [](const T &obj) { | ||
std::stringstream ss; | ||
ss << obj; | ||
return ss.str(); | ||
}); | ||
} | ||
|
||
void register_imath_line(pybind11::module &m) | ||
{ | ||
register_line<Imath::Line3f, Imath::V3f, float>(m, "Line3f"); | ||
register_line<Imath::Line3d, Imath::V3d, double>(m, "Line3d"); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
// | ||
// SPDX-License-Identifier: BSD-3-Clause | ||
// Copyright Contributors to the OpenEXR Project. | ||
// | ||
|
||
#include "PyBindImath.h" | ||
#include <ImathPlane.h> | ||
#include <ImathVec.h> | ||
#include <ImathLine.h> | ||
|
||
namespace PyBindImath { | ||
|
||
template <class T, class L, class Q, class S> | ||
void register_plane(pybind11::module& m, const char *name) | ||
{ | ||
pybind11::class_<T> c(m, name); | ||
c.def(pybind11::init<>(), "Uninitialized by default") | ||
.def(pybind11::init<const Q &, S>(), pybind11::arg("normal"), pybind11::arg("distance"), "Initialize with a normal and distance") | ||
.def(pybind11::init<const Q &, const Q &>(), pybind11::arg("point"), pybind11::arg("normal"), "Initialize with a point and a normal") | ||
.def(pybind11::init<const Q &, const Q &, const Q &>(), pybind11::arg("point1"), pybind11::arg("point2"), pybind11::arg("point3"), "Initialize with three points") | ||
.def_readwrite("normal", &T::normal, "The normal to the plane") | ||
.def_readwrite("distance", &T::distance, "The distance from the origin to the plane") | ||
.def("set", pybind11::overload_cast<const Q &, S>(&T::set), pybind11::arg("normal"), pybind11::arg("distance"), "Set via a given normal and distance") | ||
.def("set", pybind11::overload_cast<const Q &, const Q &>(&T::set), pybind11::arg("point"), pybind11::arg("normal"), "Set via a given point and normal") | ||
.def("set", pybind11::overload_cast<const Q &, const Q &, const Q &>(&T::set), pybind11::arg("point1"), pybind11::arg("point2"), pybind11::arg("point3"), "Set via three points") | ||
.def("intersect", [](T& self, const L& line) { | ||
Q intersection; | ||
bool result = self.intersect(line, intersection); | ||
return pybind11::make_tuple(result, intersection); | ||
}, pybind11::arg("line"), "Determine if a line intersects the plane. Returns a tuple (bool, Vec3). True if the line intersects the plane. Second element is the point of intersection") | ||
.def("intersectT", [](T& self, const L& line) { | ||
S intersection; | ||
bool result = self.intersectT(line, intersection); | ||
return pybind11::make_tuple(result, intersection); | ||
}, pybind11::arg("line"), "Determine if a line intersects the plane. Returns a tuple (bool, T). True if the line intersects the plane. Second element is the parametric value of the point of intersection") | ||
.def("distanceTo", &T::distanceTo, pybind11::arg("point"), "Returns the distance from a point to the plane") | ||
.def("reflectPoint", &T::reflectPoint, pybind11::arg("point"), "Reflects the given point around the plane") | ||
.def("reflectVector", &T::reflectVector, pybind11::arg("v"), "Reflects the direction vector around the plane") | ||
.def("__str__", [](const T &obj) { | ||
std::stringstream ss; | ||
ss << obj; | ||
return ss.str(); | ||
}); | ||
} | ||
|
||
void register_imath_plane(pybind11::module &m) | ||
{ | ||
register_plane<Imath::Plane3f, Imath::Line3f, Imath::V3f, float>(m, "Plane3f"); | ||
register_plane<Imath::Plane3d, Imath::Line3d, Imath::V3d, double>(m, "Plane3d"); | ||
} | ||
|
||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters