Skip to content

Commit

Permalink
Updated python bindings with python-dev-level stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
albertoesmp committed May 16, 2024
1 parent ee8488f commit f238b01
Show file tree
Hide file tree
Showing 8 changed files with 140 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/pybinds/PyAABBWrapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#ifdef PYTHON_BINDING

#include <PyVertexWrapper.h>
#include <AABB.h>

namespace pyhelios{

Expand Down
75 changes: 75 additions & 0 deletions src/pybinds/PyHelios.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1504,11 +1504,21 @@ BOOST_PYTHON_MODULE(_pyhelios){
&PyPlatformWrapper::getPositionPython,
return_value_policy<manage_new_object>()
)
.def(
"getPosition",
&PyPlatformWrapper::getPositionPython,
return_value_policy<manage_new_object>()
)
.def(
"getAttitudePython",
&PyPlatformWrapper::getAttitudePython,
return_internal_reference<>()
)
.def(
"getAttitude",
&PyPlatformWrapper::getAttitudePython,
return_internal_reference<>()
)
.def(
"getCachedAbsolutePosition",
&PyPlatformWrapper::getCachedAbsolutePosition,
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -1701,6 +1727,37 @@ BOOST_PYTHON_MODULE(_pyhelios){
&PyScenePartWrapper::getObserverStep,
&PyScenePartWrapper::setObserverStep
)
.def(
"getPrimitive",
&PyScenePartWrapper::getPrimitive,
return_value_policy<manage_new_object>()
)
.def(
"getNumPrimitives",
&PyScenePartWrapper::getNumPrimitives
)
.def(
"computeCentroid",
&PyScenePartWrapper::computeCentroid
)
.def(
"computeBound",
&PyScenePartWrapper::computeBound
)
.def(
"getCentroid",
&PyScenePartWrapper::getCentroid,
return_value_policy<manage_new_object>()
)
.def(
"getBound",
&PyScenePartWrapper::getBound,
return_value_policy<manage_new_object>()
)
.def(
"translate",
&PySceneWrapper::translate
)
;

// Register Scene
Expand All @@ -1720,6 +1777,10 @@ BOOST_PYTHON_MODULE(_pyhelios){
&PySceneWrapper::getPrimitive,
return_value_policy<manage_new_object>()
)
.def(
"getNumPrimitives",
&PySceneWrapper::getNumPrimitives
)
.def(
"getAABB",
&PySceneWrapper::getAABB,
Expand Down Expand Up @@ -1762,6 +1823,20 @@ BOOST_PYTHON_MODULE(_pyhelios){
&PySceneWrapper::getDynSceneStep,
&PySceneWrapper::setDynSceneStep
)
.def(
"getBBox",
&PySceneWrapper::getBBox,
return_value_policy<manage_new_object>()
)
.def(
"getBBoxCRS",
&PySceneWrapper::getBBoxCRS,
return_value_policy<manage_new_object>()
)
.def(
"translate",
&PySceneWrapper::translate
)
;

// Register AABB
Expand Down
12 changes: 12 additions & 0 deletions src/pybinds/PyPrimitiveWrapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@
#include <PythonDVec3.h>
#include <PyDoubleVector.h>
#include <PyVertexWrapper.h>
#include <Triangle.h>
#include <AABB.h>
#include <Voxel.h>
#include <DetailedVoxel.h>

namespace pyhelios{

Expand Down Expand Up @@ -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<Triangle *>(prim) != nullptr;}
bool isAABB () const
{return dynamic_cast<AABB *>(prim) != nullptr;}
bool isVoxel () const
{return dynamic_cast<Voxel *>(prim) != nullptr;}
bool isDetailedVoxel () const
{return dynamic_cast<DetailedVoxel *>(prim) != nullptr;}
void update(){prim->update();}


Expand Down
16 changes: 16 additions & 0 deletions src/pybinds/PyScenePartWrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,24 @@

#include <PyScenePartWrapper.h>
#include <PyHeliosException.h>
#include <PyPrimitiveWrapper.h>
#include <Primitive.h>

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 *** //
// ********************** //
Expand Down
17 changes: 17 additions & 0 deletions src/pybinds/PyScenePartWrapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,13 @@
#include <string>
#include <ScenePart.h>
#include <DynMovingObject.h>
#include <pybinds/PyAABBWrapper.h>


namespace pyhelios{

class PyPrimitiveWrapper;

/**
* @author Alberto M. Esmoris Pena
* @version 1.0
Expand Down Expand Up @@ -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 *** //
Expand Down
7 changes: 7 additions & 0 deletions src/pybinds/PySceneWrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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(){
Expand Down
8 changes: 7 additions & 1 deletion src/pybinds/PySceneWrapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -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){
Expand All @@ -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 *** //
// ********************** //
Expand Down
5 changes: 5 additions & 0 deletions src/pybinds/PythonDVec3.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

#include <glm/glm.hpp>
#include <memory>
#include <armadillo>

namespace pyhelios{

Expand Down Expand Up @@ -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;
}
Expand Down

0 comments on commit f238b01

Please sign in to comment.