From f238b0169cf2a2fbb40c799051915c2777111c76 Mon Sep 17 00:00:00 2001 From: albertoesmp Date: Thu, 16 May 2024 10:41:35 +0200 Subject: [PATCH] Updated python bindings with python-dev-level stuff --- src/pybinds/PyAABBWrapper.h | 1 + src/pybinds/PyHelios.cpp | 75 ++++++++++++++++++++++++++++++ src/pybinds/PyPrimitiveWrapper.h | 12 +++++ src/pybinds/PyScenePartWrapper.cpp | 16 +++++++ src/pybinds/PyScenePartWrapper.h | 17 +++++++ src/pybinds/PySceneWrapper.cpp | 7 +++ src/pybinds/PySceneWrapper.h | 8 +++- src/pybinds/PythonDVec3.h | 5 ++ 8 files changed, 140 insertions(+), 1 deletion(-) diff --git a/src/pybinds/PyAABBWrapper.h b/src/pybinds/PyAABBWrapper.h index 7948648aa..937bf2acb 100644 --- a/src/pybinds/PyAABBWrapper.h +++ b/src/pybinds/PyAABBWrapper.h @@ -3,6 +3,7 @@ #ifdef PYTHON_BINDING #include +#include namespace pyhelios{ diff --git a/src/pybinds/PyHelios.cpp b/src/pybinds/PyHelios.cpp index d657d25cb..febedd9b1 100644 --- a/src/pybinds/PyHelios.cpp +++ b/src/pybinds/PyHelios.cpp @@ -1504,11 +1504,21 @@ BOOST_PYTHON_MODULE(_pyhelios){ &PyPlatformWrapper::getPositionPython, return_value_policy() ) + .def( + "getPosition", + &PyPlatformWrapper::getPositionPython, + return_value_policy() + ) .def( "getAttitudePython", &PyPlatformWrapper::getAttitudePython, return_internal_reference<>() ) + .def( + "getAttitude", + &PyPlatformWrapper::getAttitudePython, + return_internal_reference<>() + ) .def( "getCachedAbsolutePosition", &PyPlatformWrapper::getCachedAbsolutePosition, @@ -1589,6 +1599,22 @@ BOOST_PYTHON_MODULE(_pyhelios){ "update", &PyPrimitiveWrapper::update ) + .def( + "isTriangle", + &PyPrimitiveWrapper::isTriangle + ) + .def( + "isAABB", + &PyPrimitiveWrapper::isAABB + ) + .def( + "isVoxel", + &PyPrimitiveWrapper::isVoxel + ) + .def( + "isDetailedVoxel", + &PyPrimitiveWrapper::isDetailedVoxel + ) ; // Register Material @@ -1701,6 +1727,37 @@ BOOST_PYTHON_MODULE(_pyhelios){ &PyScenePartWrapper::getObserverStep, &PyScenePartWrapper::setObserverStep ) + .def( + "getPrimitive", + &PyScenePartWrapper::getPrimitive, + return_value_policy() + ) + .def( + "getNumPrimitives", + &PyScenePartWrapper::getNumPrimitives + ) + .def( + "computeCentroid", + &PyScenePartWrapper::computeCentroid + ) + .def( + "computeBound", + &PyScenePartWrapper::computeBound + ) + .def( + "getCentroid", + &PyScenePartWrapper::getCentroid, + return_value_policy() + ) + .def( + "getBound", + &PyScenePartWrapper::getBound, + return_value_policy() + ) + .def( + "translate", + &PySceneWrapper::translate + ) ; // Register Scene @@ -1720,6 +1777,10 @@ BOOST_PYTHON_MODULE(_pyhelios){ &PySceneWrapper::getPrimitive, return_value_policy() ) + .def( + "getNumPrimitives", + &PySceneWrapper::getNumPrimitives + ) .def( "getAABB", &PySceneWrapper::getAABB, @@ -1762,6 +1823,20 @@ BOOST_PYTHON_MODULE(_pyhelios){ &PySceneWrapper::getDynSceneStep, &PySceneWrapper::setDynSceneStep ) + .def( + "getBBox", + &PySceneWrapper::getBBox, + return_value_policy() + ) + .def( + "getBBoxCRS", + &PySceneWrapper::getBBoxCRS, + return_value_policy() + ) + .def( + "translate", + &PySceneWrapper::translate + ) ; // Register AABB diff --git a/src/pybinds/PyPrimitiveWrapper.h b/src/pybinds/PyPrimitiveWrapper.h index 42b72aa8f..4c4deba30 100644 --- a/src/pybinds/PyPrimitiveWrapper.h +++ b/src/pybinds/PyPrimitiveWrapper.h @@ -7,6 +7,10 @@ #include #include #include +#include +#include +#include +#include namespace pyhelios{ @@ -69,6 +73,14 @@ class PyPrimitiveWrapper{ size_t getNumVertices(){return prim->getNumVertices();} PyVertexWrapper * getVertex(size_t index) {return new PyVertexWrapper(prim->getVertices()+index);} + bool isTriangle () const + {return dynamic_cast(prim) != nullptr;} + bool isAABB () const + {return dynamic_cast(prim) != nullptr;} + bool isVoxel () const + {return dynamic_cast(prim) != nullptr;} + bool isDetailedVoxel () const + {return dynamic_cast(prim) != nullptr;} void update(){prim->update();} diff --git a/src/pybinds/PyScenePartWrapper.cpp b/src/pybinds/PyScenePartWrapper.cpp index 17a7b7b11..6e2a5d008 100644 --- a/src/pybinds/PyScenePartWrapper.cpp +++ b/src/pybinds/PyScenePartWrapper.cpp @@ -2,8 +2,24 @@ #include #include +#include +#include using pyhelios::PyScenePartWrapper; +using pyhelios::PyPrimitiveWrapper; + +// *** UTIL METHODS *** // +// ************************ // +void PyScenePartWrapper::translate(double const x, double const y, double const z){ + glm::dvec3 const v(x, y, z); + for(Primitive *p : sp.mPrimitives) p->translate(v); +} + +// *** GETTERs and SETTERs *** // +// ***************************** // +PyPrimitiveWrapper * PyScenePartWrapper::getPrimitive(size_t const index){ + return new PyPrimitiveWrapper(sp.mPrimitives[index]); +} // *** INTERNAL USE *** // // ********************** // diff --git a/src/pybinds/PyScenePartWrapper.h b/src/pybinds/PyScenePartWrapper.h index beec6eb4f..a9659cf15 100644 --- a/src/pybinds/PyScenePartWrapper.h +++ b/src/pybinds/PyScenePartWrapper.h @@ -5,9 +5,13 @@ #include #include #include +#include + namespace pyhelios{ +class PyPrimitiveWrapper; + /** * @author Alberto M. Esmoris Pena * @version 1.0 @@ -47,6 +51,19 @@ class PyScenePartWrapper{ {return _asDynMovingObject().getObserverStepInterval();} void setObserverStep(size_t const stepInterval) {_asDynMovingObject().setObserverStepInterval(stepInterval);} + PyPrimitiveWrapper * getPrimitive(size_t const index); + size_t getNumPrimitives() const {return sp.mPrimitives.size();} + PythonDVec3 * getCentroid() {return new PythonDVec3(sp.centroid);} + PyAABBWrapper * getBound() {return new PyAABBWrapper(sp.bound.get());} + + // *** UTIL METHODS *** // + // ************************ // + void computeCentroid(bool const computeBound=false) + {sp.computeCentroid(computeBound);} + void computeBound() {sp.computeCentroid(true);} + void translate(double const x, double const y, double const z); + + // *** INTERNAL USE *** // diff --git a/src/pybinds/PySceneWrapper.cpp b/src/pybinds/PySceneWrapper.cpp index 9a235f160..c1566e8d7 100644 --- a/src/pybinds/PySceneWrapper.cpp +++ b/src/pybinds/PySceneWrapper.cpp @@ -4,6 +4,13 @@ using pyhelios::PySceneWrapper; +// *** METHODS *** // +// ******************* // +void PySceneWrapper::translate(double const x, double const y, double const z){ + glm::dvec3 const v(x, y, z); + for(Primitive *p : scene.primitives) p->translate(v); +} + // *** INTERNAL USE *** // // ********************** // DynScene & PySceneWrapper::_asDynScene(){ diff --git a/src/pybinds/PySceneWrapper.h b/src/pybinds/PySceneWrapper.h index 33b8cfcfa..922805737 100644 --- a/src/pybinds/PySceneWrapper.h +++ b/src/pybinds/PySceneWrapper.h @@ -50,8 +50,9 @@ class PySceneWrapper{ scene.primitives.push_back(dv); return new PyDetailedVoxelWrapper(dv); } - PyPrimitiveWrapper * getPrimitive(size_t index) + PyPrimitiveWrapper * getPrimitive(size_t const index) {return new PyPrimitiveWrapper(scene.primitives[index]);} + size_t getNumPrimitives() const {return scene.primitives.size();} PyAABBWrapper * getAABB() {return new PyAABBWrapper(scene.getAABB().get());} PythonDVec3 * getGroundPointAt(double x, double y, double z){ @@ -76,12 +77,17 @@ class PySceneWrapper{ size_t getDynSceneStep(){return _asDynScene().getStepInterval();} void setDynSceneStep(size_t const stepInterval) {_asDynScene().setStepInterval(stepInterval);} + PyAABBWrapper * getBBox() + {return new PyAABBWrapper(scene.getBBox().get());} + PyAABBWrapper * getBBoxCRS() + {return new PyAABBWrapper(scene.getBBoxCRS().get());} // *** M E T H O D S *** // // *********************** // bool finalizeLoading() {return scene.finalizeLoading();} void writeObject(std::string path) {scene.writeObject(path);} + void translate(double const x, double const y, double const z); // *** INTERNAL USE *** // // ********************** // diff --git a/src/pybinds/PythonDVec3.h b/src/pybinds/PythonDVec3.h index c3b9822fa..b2b9a5084 100644 --- a/src/pybinds/PythonDVec3.h +++ b/src/pybinds/PythonDVec3.h @@ -4,6 +4,7 @@ #include #include +#include namespace pyhelios{ @@ -32,6 +33,10 @@ class PythonDVec3 { this->v = v; release = false; } + PythonDVec3(arma::colvec const v){ + this->v = new glm::dvec3(v[0], v[1], v[2]); + release = true; + } virtual ~PythonDVec3(){ if(release && v!=nullptr) delete v; }