Skip to content

Commit

Permalink
Add unique_register_ptr_to_python method to get rid of python runtime…
Browse files Browse the repository at this point in the history
… warnings.
  • Loading branch information
fabianbl committed Jul 18, 2017
1 parent 5829edd commit 4cfa11c
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 9 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#ifndef SM_PYTHON_UNIQUE_REGISTER_PTR_TO_PYTHON
#define SM_PYTHON_UNIQUE_REGISTER_PTR_TO_PYTHON

#include <boost/python/register_ptr_to_python.hpp>
#include <boost/python/type_id.hpp>

namespace sm {
namespace python {

// Calls register_ptr_to_python<D>() in case the class has not already been
// registered. Related to
// https://stackoverflow.com/questions/9888289/checking-whether-a-converter-has-already-been-registered#
template <typename D>
void unique_register_ptr_to_python() {
boost::python::type_info info = boost::python::type_id<D>();
const boost::python::converter::registration* reg = boost::python::converter::registry::query(info);
if (reg == NULL || reg->m_to_python == NULL) {
boost::python::register_ptr_to_python<D>();
}
}

} // namespace python
} // namespace sm

#endif // SM_PYTHON_UNIQUE_REGISTER_PTR_TO_PYTHON

13 changes: 7 additions & 6 deletions aslam_cv/aslam_cv_python/src/CameraProjections.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include <aslam/cameras/RadialTangentialDistortion.hpp>
#include <boost/serialization/nvp.hpp>
#include <sm/python/boost_serialization_pickle.hpp>
#include <sm/python/unique_register_ptr_to_python.hpp>
//#include <aslam/python/ExportDesignVariableAdapter.hpp>
//#include <aslam/backend/DesignVariableAdapter.hpp>
//#include <aslam/python/ExportAPrioriInformationError.hpp>
Expand Down Expand Up @@ -215,7 +216,7 @@ void exportGenericDistortionFunctions(T & dist) {

void exportFovDistortionFunctions() {
class_<FovDistortion, boost::shared_ptr<FovDistortion> > distortion("FovDistortion", init<>());
register_ptr_to_python<boost::shared_ptr<FovDistortion> >();
sm::python::unique_register_ptr_to_python<boost::shared_ptr<FovDistortion> >();

exportGenericDistortionFunctions<FovDistortion>(distortion);
distortion.def(init<double>(("FovDistortion(double w)")));
Expand All @@ -227,7 +228,7 @@ void exportRadialTangentialDistortionFunctions() {
class_<RadialTangentialDistortion,
boost::shared_ptr<RadialTangentialDistortion> > rtDistortion(
"RadialTangentialDistortion", init<>());
register_ptr_to_python<boost::shared_ptr<RadialTangentialDistortion> >();
sm::python::unique_register_ptr_to_python<boost::shared_ptr<RadialTangentialDistortion> >();

exportGenericDistortionFunctions<RadialTangentialDistortion>(rtDistortion);

Expand All @@ -251,7 +252,7 @@ void exportOmniProjection(std::string name) {

class_<OmniProjection<D>, boost::shared_ptr<OmniProjection<D> > > omniProjection(
name.c_str(), init<>());
register_ptr_to_python<boost::shared_ptr<OmniProjection<D> > >();
sm::python::unique_register_ptr_to_python<boost::shared_ptr<OmniProjection<D> > >();

omniProjection.def(init<>((name + "(distortion_t distortion)").c_str())).def(
init<double, double, double, double, double, int, int, D>(
Expand Down Expand Up @@ -295,7 +296,7 @@ void exportPinholeProjection(std::string name) {

class_<PinholeProjection<D>, boost::shared_ptr<PinholeProjection<D> > > pinholeProjection(
name.c_str(), init<>());
register_ptr_to_python<boost::shared_ptr<PinholeProjection<D> > >();
sm::python::unique_register_ptr_to_python<boost::shared_ptr<PinholeProjection<D> > >();

pinholeProjection.def(init<>((name + "(distortion_t distortion)").c_str()))
.def(
Expand Down Expand Up @@ -339,13 +340,13 @@ void exportCameraProjections() {

class_<NoDistortion, boost::shared_ptr<NoDistortion> > noDistortion(
"NoDistortion", init<>());
register_ptr_to_python<boost::shared_ptr<NoDistortion> >();
sm::python::unique_register_ptr_to_python<boost::shared_ptr<NoDistortion> >();

exportGenericDistortionFunctions<NoDistortion>(noDistortion);

class_<EquidistantDistortion, boost::shared_ptr<EquidistantDistortion> > equidistantDistortion(
"EquidistantDistortion", init<>());
register_ptr_to_python<boost::shared_ptr<EquidistantDistortion> >();
sm::python::unique_register_ptr_to_python<boost::shared_ptr<EquidistantDistortion> >();

equidistantDistortion.def(init<double, double, double, double>());
exportGenericDistortionFunctions<EquidistantDistortion>(
Expand Down
5 changes: 3 additions & 2 deletions aslam_cv/aslam_cv_python/src/CameraShutters.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include <boost/serialization/nvp.hpp>
#include <aslam/Time.hpp>
#include <sm/python/boost_serialization_pickle.hpp>
#include <sm/python/unique_register_ptr_to_python.hpp>

//#include <aslam/python/ExportDesignVariableAdapter.hpp>

Expand Down Expand Up @@ -40,7 +41,7 @@ void exportGlobalShutter(std::string name) {
name.c_str(), init<>());
globalShutter.def(init<>((name + "()").c_str()));

register_ptr_to_python<boost::shared_ptr<GlobalShutter> >();
sm::python::unique_register_ptr_to_python<boost::shared_ptr<GlobalShutter> >();

exportGenericShutterFunctions<GlobalShutter>(globalShutter);
}
Expand All @@ -54,7 +55,7 @@ void exportRollingShutter(std::string name) {
"lineDelay", &RollingShutter::lineDelay,
"Returns the Line Delay of the Rolling Shutter");

register_ptr_to_python<boost::shared_ptr<RollingShutter> >();
sm::python::unique_register_ptr_to_python<boost::shared_ptr<RollingShutter> >();

exportGenericShutterFunctions<RollingShutter>(rollingShutter);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include <sstream>
#include <aslam/backend/DesignVariable.hpp>
#include <aslam/backend/DesignVariableAdapter.hpp>
#include <sm/python/unique_register_ptr_to_python.hpp>


namespace aslam {
Expand All @@ -26,7 +27,8 @@ namespace aslam {
class_< DesignVariableAdapter<dv_t>, boost::shared_ptr<DesignVariableAdapter<dv_t> >, bases<DesignVariable> >( name.c_str(), init<boost::shared_ptr< dv_t> >() )
.def("value", &DesignVariableAdapter<dv_t>::valuePtr)
;
register_ptr_to_python<boost::shared_ptr<DesignVariableAdapter<dv_t> > >();

sm::python::unique_register_ptr_to_python<boost::shared_ptr<DesignVariableAdapter<dv_t> > >();
//boost::python::implicitly_convertible<boost::shared_ptr<DesignVariableAdapter<dv_t> >, boost::shared_ptr<DesignVariable> >();

}
Expand Down

0 comments on commit 4cfa11c

Please sign in to comment.