Skip to content

Commit

Permalink
[py] binding of loop detections
Browse files Browse the repository at this point in the history
  • Loading branch information
SimonRohou committed Feb 9, 2021
1 parent bb3d64c commit d0351fb
Show file tree
Hide file tree
Showing 10 changed files with 233 additions and 2 deletions.
4 changes: 2 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"Codac is a library providing tools for constraint programming over reals and trajectories.")
set(PROJECT_LONG_DESCRIPTION
"${PROJECT_DESCRIPTION}")
set(PROJECT_HOMEPAGE_URL "http://simon-rohou.fr/research/codac")
set(PROJECT_HOMEPAGE_URL "http://codac.io")
message(STATUS "Configuring build for ${PROJECT_NAME} ${PROJECT_VERSION}")

if(NOT CMAKE_BUILD_TYPE)
Expand Down Expand Up @@ -166,7 +166,7 @@

set(CPACK_GENERATOR "TGZ" "ZIP" "DEB")
string(TOLOWER "${CMAKE_PROJECT_NAME}" CPACK_PACKAGE_NAME)
set(CPACK_PACKAGE_VENDOR "CodacTeam")
set(CPACK_PACKAGE_VENDOR "Codac Team")
set(CPACK_PACKAGE_DESCRIPTION_SUMMARY ${CODAC_DESCRIPTION})
set(CPACK_PACKAGE_VERSION_MAJOR ${PROJECT_VERSION_MAJOR})
set(CPACK_PACKAGE_VERSION_MINOR ${PROJECT_VERSION_MINOR})
Expand Down
59 changes: 59 additions & 0 deletions examples/robotics/06_loops_proofs/06_loops_proofs.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
# Codac - Examples
# Reliable loop detection of a mobile robot
# ----------------------------------------------------------------------------

from pyibex import *
from codac import *
import sys # only for checking if this example still works


# =================== 0. Parameters, truth and data ====================

Tube.enable_syntheses() # faster integral computations

dt = 0.01
tdomain = Interval(-1.,10.)

x_truth = TrajectoryVector(tdomain, TFunction("(10*cos(t)+t;5*sin(2*t)+t)"))
x = TubeVector(tdomain, dt, 2)
v = TubeVector(tdomain, dt, TFunction("(-10*sin(t)+1+[-0.2,0.2];10*cos(2*t)+1+[-0.2,0.2])"))

x.set(x_truth(tdomain.lb()), tdomain.lb())

ctc.deriv.contract(x, v)


# =================== 1. Loops detection ====================

tplane = TPlane(x.tdomain())
tplane.compute_detections(dt*2., x, v)
#tplane.compute_proofs(f)


# =================== 2. Graphics ====================

beginDrawing()

fig_tplane = VIBesFigPaving("t-plane", tplane)
fig_tplane.set_properties(550, 150, 500, 500)
fig_tplane.show()

fig_map = VIBesFigMap("Map")
fig_map.set_properties(450, 50, 800, 800)
fig_map.add_tube(x, "x", 0, 1)
fig_map.add_trajectory(x_truth, "x*", 0, 1)
fig_map.show(1.)

v_loops = tplane.detected_loops()
for loop in v_loops:
fig_tplane.draw_box(loop, "red")

v_loops = tplane.proven_loops()
for loop in v_loops:
fig_tplane.draw_box(loop, "green")

endDrawing()


# Checking if this example still works:
sys.exit(0 if (tplane.nb_loops_detections() == 5 and tplane.nb_loops_proofs() == 4) else 1)
4 changes: 4 additions & 0 deletions python/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,12 @@
src/core/graphics/codac_py_VIBesFigTube.cpp
src/core/graphics/codac_py_VIBesFigTubeVector.cpp
src/core/graphics/codac_py_VIBesFigMap.cpp
src/core/graphics/codac_py_VIBesFigPaving.cpp

src/core/paving/codac_py_Paving.cpp

src/robotics/codac_py_DataLoader.cpp
src/robotics/codac_py_TPlane.cpp
)

target_include_directories(tube
Expand Down
8 changes: 8 additions & 0 deletions python/codac_py.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,12 @@ void export_VIBesFig(py::module& m);
void export_VIBesFigTube(py::module& m);
void export_VIBesFigTubeVector(py::module& m);
void export_VIBesFigMap(py::module& m);
void export_VIBesFigPaving(py::module& m);

void export_Paving(py::module& m);

void export_DataLoader(py::module& m);
void export_TPlane(py::module& m);

PYBIND11_MODULE(tube, m)
{
Expand Down Expand Up @@ -93,8 +97,12 @@ PYBIND11_MODULE(tube, m)
export_VIBesFigTube(m);
export_VIBesFigTubeVector(m);
export_VIBesFigMap(m);
export_VIBesFigPaving(m);

export_Paving(m);

export_DataLoader(m);
export_TPlane(m);

// m.attr("ibex_version") = _IBEX_VERSION_;
// return m.ptr();
Expand Down
16 changes: 16 additions & 0 deletions python/src/core/domains/tube/codac_py_TubeVector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,22 @@ void export_TubeVector(py::module& m)
TUBEVECTOR_BOOL_OVERLAPS_TUBEVECTOR_FLOAT,
"x"_a, "ratio"_a=1)

.def("set", [](TubeVector& x, const Vector& y) { x.set(y); },
TUBEVECTOR_VOID_SET_INTERVALVECTOR,
"y"_a)

.def("set", [](TubeVector& x, const Vector& y, int slice_id) { x.set(y, slice_id); },
TUBEVECTOR_VOID_SET_INTERVALVECTOR_INT,
"y"_a, "slice_id"_a)

.def("set", [](TubeVector& x, const Vector& y, double t) { x.set(y, t); },
TUBEVECTOR_VOID_SET_INTERVALVECTOR_DOUBLE,
"y"_a, "t"_a)

.def("set", [](TubeVector& x, const Vector& y, const Interval& t) { x.set(y, t); },
TUBEVECTOR_VOID_SET_INTERVALVECTOR_INTERVAL,
"y"_a, "t"_a)

.def("set", (void (TubeVector::*)(const IntervalVector&))&TubeVector::set,
TUBEVECTOR_VOID_SET_INTERVALVECTOR,
"y"_a)
Expand Down
42 changes: 42 additions & 0 deletions python/src/core/graphics/codac_py_VIBesFigPaving.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/**
* \file
* VIBesFigPaving Python binding
* ----------------------------------------------------------------------------
* \date 2020
* \author Simon Rohou, Benoît Desrochers
* \copyright Copyright 2021 Codac Team
* \license This program is distributed under the terms of
* the GNU Lesser General Public License (LGPL).
*/

#include <pybind11/pybind11.h>
#include <pybind11/stl.h>
#include <pybind11/operators.h>
#include <pybind11/functional.h>
#include "pyIbex_type_caster.h"

#include "codac_VIBesFigPaving.h"
// Generated file from Doxygen XML (doxygen2docstring.py):
#include "codac_py_VIBesFigPaving_docs.h"

using namespace std;
using namespace ibex;
using namespace codac;
namespace py = pybind11;
using namespace pybind11::literals;


void export_VIBesFigPaving(py::module& m)
{
py::class_<VIBesFigPaving,VIBesFig> fig_map(m, "VIBesFigPaving", VIBESFIGPAVING_MAIN);
fig_map

.def(py::init<const string&, const Paving*>(),
VIBESFIGPAVING_CONSTPAVING_M_PAVING,
"fig_name"_a, "paving"_a)

.def("show", (void (VIBesFigPaving::*)())&VIBesFigPaving::show,
VIBESFIGPAVING_VOID_SHOW)

;
}
31 changes: 31 additions & 0 deletions python/src/core/paving/codac_py_Paving.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/**
* \file
* Paving Python binding
* ----------------------------------------------------------------------------
* \date 2021
* \author Simon Rohou
* \copyright Copyright 2021 Codac Team
* \license This program is distributed under the terms of
* the GNU Lesser General Public License (LGPL).
*/

#include <pybind11/pybind11.h>
#include <pybind11/stl.h>
#include <pybind11/operators.h>
#include <pybind11/functional.h>

#include "codac_Paving.h"
// Generated file from Doxygen XML (doxygen2docstring.py):
#include "codac_py_Paving_docs.h"

using namespace std;
using namespace ibex;
using namespace codac;
namespace py = pybind11;
using namespace pybind11::literals;


void export_Paving(py::module& m)
{
py::class_<Paving> tplane(m, "Paving", PAVING_MAIN);
}
60 changes: 60 additions & 0 deletions python/src/robotics/codac_py_TPlane.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/**
* \file
* TPlane Python binding
* ----------------------------------------------------------------------------
* \date 2021
* \author Simon Rohou
* \copyright Copyright 2021 Codac Team
* \license This program is distributed under the terms of
* the GNU Lesser General Public License (LGPL).
*/

#include <pybind11/pybind11.h>
#include <pybind11/stl.h>
#include <pybind11/operators.h>
#include <pybind11/functional.h>

#include "codac_Paving.h"
#include "codac_TPlane.h"
// Generated file from Doxygen XML (doxygen2docstring.py):
#include "codac_py_TPlane_docs.h"

using namespace std;
using namespace ibex;
using namespace codac;
namespace py = pybind11;
using namespace pybind11::literals;


void export_TPlane(py::module& m)
{
py::class_<TPlane, Paving> tplane(m, "TPlane", TPLANE_MAIN);
tplane

.def(py::init<const Interval&>(),
TPLANE_TPLANE_INTERVAL)

.def("compute_detections", (void (TPlane::*)(float,const TubeVector&,const TubeVector&))&TPlane::compute_detections,
TPLANE_VOID_COMPUTE_DETECTIONS_FLOAT_TUBEVECTOR_TUBEVECTOR,
"precision"_a, "p"_a, "v"_a)

.def("compute_proofs", &TPlane::compute_proofs,
TPLANE_VOID_COMPUTE_PROOFS_INTERVALVECTORPINTERVALVECTORB,
"f"_a)

.def("nb_loops_detections", &TPlane::nb_loops_detections,
TPLANE_INT_NB_LOOPS_DETECTIONS)

.def("nb_loops_proofs", &TPlane::nb_loops_proofs,
TPLANE_INT_NB_LOOPS_PROOFS)

.def("detected_loops", &TPlane::detected_loops,
TPLANE_CONSTVECTORINTERVALVECTOR_DETECTED_LOOPS)

.def("proven_loops", &TPlane::proven_loops,
TPLANE_CONSTVECTORINTERVALVECTOR_PROVEN_LOOPS)

.def("traj_loops_summary", &TPlane::traj_loops_summary,
TPLANE_TRAJECTORY_TRAJ_LOOPS_SUMMARY)
;
}
8 changes: 8 additions & 0 deletions src/core/paving/codac_ConnectedSubset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,4 +84,12 @@ namespace codac

return v_boundaries;
}

const vector<IntervalVector> ConnectedSubset::get_boxed_hulls(const vector<ConnectedSubset> v_subsets)
{
vector<IntervalVector> v_boxes(v_subsets.size());
for(size_t i = 0 ; i < v_subsets.size() ; i++)
v_boxes[i] = v_subsets[i].box();
return v_boxes;
}
}
3 changes: 3 additions & 0 deletions src/core/paving/codac_ConnectedSubset.h
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,9 @@ namespace codac
*/
std::vector<IntervalVector> get_boundary(SetValue value_boundary = SetValue::MAYBE, SetValue value_out = SetValue::OUT) const; // items of type k-1


static const std::vector<IntervalVector> get_boxed_hulls(const std::vector<ConnectedSubset> v_subsets);

/// @}
/// \name Methods related to topological degree
/// @{
Expand Down

0 comments on commit d0351fb

Please sign in to comment.