From bb6420a65e44960e868810ae7b60b38bb135d70b Mon Sep 17 00:00:00 2001 From: Wenzel Jakob Date: Sun, 21 Aug 2011 00:51:22 -0400 Subject: [PATCH] python binding improvements --- build/SConscript.configure | 2 ++ src/libpython/core.cpp | 33 +++++++++++++++++++++++++-------- 2 files changed, 27 insertions(+), 8 deletions(-) diff --git a/build/SConscript.configure b/build/SConscript.configure index 578022f1..788bcd9f 100644 --- a/build/SConscript.configure +++ b/build/SConscript.configure @@ -14,6 +14,8 @@ print("Using configuation file \"%s\"" % configFile) AddOption("--parallelize", dest="parallelize", action='store_true', help='Parallelize to the available number of cores?') parallelize = GetOption('parallelize') +EnsureSConsVersion(2, 0, 0) + if parallelize == True: SetOption('num_jobs', multiprocessing.cpu_count()) diff --git a/src/libpython/core.cpp b/src/libpython/core.cpp index 6a015966..2814748a 100644 --- a/src/libpython/core.cpp +++ b/src/libpython/core.cpp @@ -246,6 +246,23 @@ Float aabb_sqrdistanceto_aabb(AABB *aabb, const AABB &aabb2) { return aabb->squa Float aabb_sqrdistanceto_point(AABB *aabb, const Point &p) { return aabb->squaredDistanceTo(p); } bool aabb_contains_aabb(AABB *aabb, const AABB &aabb2) { return aabb->contains(aabb2); } bool aabb_contains_point(AABB *aabb, const Point &p) { return aabb->contains(p); } +bp::object bsphere_rayIntersect(BSphere *bsphere, const Ray &ray) { + Float nearT, farT; + if (bsphere->rayIntersect(ray, nearT, farT)) + return bp::make_tuple(nearT, farT); + else + return bp::object(); + +} + +bp::object aabb_rayIntersect(AABB *aabb, const Ray &ray) { + Float nearT, farT; + if (aabb->rayIntersect(ray, nearT, farT)) + return bp::make_tuple(nearT, farT); + else + return bp::object(); + +} BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS(fromLinearRGB_overloads, fromLinearRGB, 3, 4) BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS(fromXYZ_overloads, fromXYZ, 3, 4) @@ -852,9 +869,9 @@ void export_core() { .def("contains", &BSphere::contains) .def(bp::self == bp::self) .def(bp::self != bp::self) - .def("rayIntersect", &AABB::rayIntersect) - .def("serialize", &AABB::serialize) - .def("__str__", &AABB::toString); + .def("rayIntersect", &bsphere_rayIntersect) + .def("serialize", &BSphere::serialize) + .def("__str__", &BSphere::toString); bp::class_("AABB", bp::init<>()) .def(bp::init()) @@ -865,9 +882,9 @@ void export_core() { .def_readwrite("max", &AABB::max) .def("getSurfaceArea", &AABB::getSurfaceArea) .def("getVolume", &AABB::getVolume) - .def("getCorner", &AABB::getCorner) + .def("getCorner", &AABB::getCorner, BP_RETURN_VALUE) .def("overlaps", &AABB::overlaps) - .def("getCenter", &AABB::getCenter) + .def("getCenter", &AABB::getCenter, BP_RETURN_VALUE) .def("reset", &AABB::reset) .def("clip", &AABB::clip) .def("isValid", &AABB::isValid) @@ -881,11 +898,11 @@ void export_core() { .def("contains", &aabb_contains_point) .def("getLargestAxis", &AABB::getLargestAxis) .def("getShortestAxis", &AABB::getShortestAxis) - .def("getExtents", &AABB::getExtents) + .def("getExtents", &AABB::getExtents, BP_RETURN_VALUE) .def(bp::self == bp::self) .def(bp::self != bp::self) - .def("rayIntersect", &AABB::rayIntersect) - .def("getBSphere", &AABB::getBSphere) + .def("rayIntersect", &aabb_rayIntersect) + .def("getBSphere", &AABB::getBSphere, BP_RETURN_VALUE) .def("serialize", &AABB::serialize) .def("__str__", &AABB::toString);