From eeb6d3d69770ed0168b159601aef05059bd12721 Mon Sep 17 00:00:00 2001 From: SimonRohou Date: Wed, 21 Jun 2023 16:05:05 +0200 Subject: [PATCH] [py] binding of get_connected_subsets and related classes --- python/CMakeLists.txt | 2 + python/codac_py_core.cpp | 7 ++- .../core/graphics/codac_py_VIBesFigPaving.cpp | 3 +- .../core/paving/codac_py_ConnectedSubset.cpp | 36 ++++++++++++++ python/src/core/paving/codac_py_Paving.cpp | 10 +++- .../src/core/paving/codac_py_SIVIAPaving.cpp | 47 +++++++++++++++++++ python/src/core/paving/codac_py_Set.cpp | 3 ++ src/core/paving/codac_Paving.cpp | 3 +- src/core/paving/codac_Paving.h | 3 +- 9 files changed, 107 insertions(+), 7 deletions(-) create mode 100644 python/src/core/paving/codac_py_ConnectedSubset.cpp create mode 100644 python/src/core/paving/codac_py_SIVIAPaving.cpp diff --git a/python/CMakeLists.txt b/python/CMakeLists.txt index 184cbc7a4..680ce863e 100644 --- a/python/CMakeLists.txt +++ b/python/CMakeLists.txt @@ -97,7 +97,9 @@ src/core/geometry/codac_py_geometry.cpp src/core/paving/codac_py_Paving.cpp + src/core/paving/codac_py_SIVIAPaving.cpp src/core/paving/codac_py_Set.cpp + src/core/paving/codac_py_ConnectedSubset.cpp src/core/sivia/codac_py_sivia.cpp diff --git a/python/codac_py_core.cpp b/python/codac_py_core.cpp index 91c270bf5..49b111895 100644 --- a/python/codac_py_core.cpp +++ b/python/codac_py_core.cpp @@ -78,9 +78,10 @@ void export_VIBesFigPaving(py::module& m); void export_geometry(py::module& m, py::class_& ctc, py::class_& sep); - -void export_Paving(py::module& m); void export_Set(py::module& m); +void export_Paving(py::module& m); +void export_SIVIAPaving(py::module& m); +void export_ConnectedSubset(py::module& m); void export_DataLoader(py::module& m); void export_TPlane(py::module& m); @@ -144,7 +145,9 @@ PYBIND11_MODULE(core, m) export_geometry(m, ctc, sep); export_Paving(m); + export_SIVIAPaving(m); export_Set(m); + export_ConnectedSubset(m); export_DataLoader(m); export_TPlane(m); diff --git a/python/src/core/graphics/codac_py_VIBesFigPaving.cpp b/python/src/core/graphics/codac_py_VIBesFigPaving.cpp index ec5d566b2..d0bf7e2cf 100644 --- a/python/src/core/graphics/codac_py_VIBesFigPaving.cpp +++ b/python/src/core/graphics/codac_py_VIBesFigPaving.cpp @@ -32,7 +32,8 @@ void export_VIBesFigPaving(py::module& m) .def(py::init(), VIBESFIGPAVING_CONSTPAVING_M_PAVING, - "fig_name"_a, "paving"_a) + "fig_name"_a, "paving"_a.noconvert(), + py::keep_alive<1,3>()) .def("show", (void (VIBesFigPaving::*)())&VIBesFigPaving::show, VIBESFIGPAVING_VOID_SHOW) diff --git a/python/src/core/paving/codac_py_ConnectedSubset.cpp b/python/src/core/paving/codac_py_ConnectedSubset.cpp new file mode 100644 index 000000000..5890fe326 --- /dev/null +++ b/python/src/core/paving/codac_py_ConnectedSubset.cpp @@ -0,0 +1,36 @@ +/** + * \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 +#include +#include +#include + +#include "codac_ConnectedSubset.h" +// Generated file from Doxygen XML (doxygen2docstring.py): +#include "codac_py_ConnectedSubset_docs.h" + +using namespace std; +using namespace codac; +namespace py = pybind11; +using namespace pybind11::literals; + + +void export_ConnectedSubset(py::module& m) +{ + py::class_ connectedsubset(m, "ConnectedSubset", CONNECTEDSUBSET_MAIN); + connectedsubset + + .def("get_boxes", &ConnectedSubset::get_boxes, + CONNECTEDSUBSET_VECTORINTERVALVECTOR_GET_BOXES) + + ; +} \ No newline at end of file diff --git a/python/src/core/paving/codac_py_Paving.cpp b/python/src/core/paving/codac_py_Paving.cpp index f82bf4c9f..49f73642b 100644 --- a/python/src/core/paving/codac_py_Paving.cpp +++ b/python/src/core/paving/codac_py_Paving.cpp @@ -14,6 +14,7 @@ #include #include +#include "codac_Set.h" #include "codac_Paving.h" // Generated file from Doxygen XML (doxygen2docstring.py): #include "codac_py_Paving_docs.h" @@ -26,5 +27,12 @@ using namespace pybind11::literals; void export_Paving(py::module& m) { - py::class_ tplane(m, "Paving", PAVING_MAIN); + py::class_ paving(m, "Paving", PAVING_MAIN); + paving + + .def("get_connected_subsets", &Paving::get_connected_subsets, + PAVING_VECTORCONNECTEDSUBSET_GET_CONNECTED_SUBSETS_BOOL_SETVALUE, + "sort_by_size"_a=false, "val"_a) + + ; } \ No newline at end of file diff --git a/python/src/core/paving/codac_py_SIVIAPaving.cpp b/python/src/core/paving/codac_py_SIVIAPaving.cpp new file mode 100644 index 000000000..cc1526230 --- /dev/null +++ b/python/src/core/paving/codac_py_SIVIAPaving.cpp @@ -0,0 +1,47 @@ +/** + * \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 +#include +#include +#include + +#include "codac_SIVIAPaving.h" +// Generated file from Doxygen XML (doxygen2docstring.py): +#include "codac_py_SIVIAPaving_docs.h" + +using namespace std; +using namespace codac; +namespace py = pybind11; +using namespace pybind11::literals; + + +void export_SIVIAPaving(py::module& m) +{ + py::class_ paving(m, "SIVIAPaving", SIVIAPAVING_MAIN); + paving + + .def(py::init(), + SIVIAPAVING_SIVIAPAVING_INTERVALVECTOR) + + .def("compute", (void (SIVIAPaving::*)(const Function&,const IntervalVector&,float))&SIVIAPaving::compute, + SIVIAPAVING_VOID_COMPUTE_FUNCTION_INTERVALVECTOR_FLOAT, + "f"_a, "y"_a, "precision"_a) + + .def("compute", (void (SIVIAPaving::*)(Ctc&,float))&SIVIAPaving::compute, + SIVIAPAVING_VOID_COMPUTE_CTC_FLOAT, + "ctc"_a, "precision"_a) + + .def("compute", (void (SIVIAPaving::*)(ibex::Sep&,float))&SIVIAPaving::compute, + SIVIAPAVING_VOID_COMPUTE_SEP_FLOAT, + "sep"_a, "precision"_a) + ; +} \ No newline at end of file diff --git a/python/src/core/paving/codac_py_Set.cpp b/python/src/core/paving/codac_py_Set.cpp index d6f99b472..96e862ef9 100644 --- a/python/src/core/paving/codac_py_Set.cpp +++ b/python/src/core/paving/codac_py_Set.cpp @@ -31,5 +31,8 @@ void export_Set(py::module& m) .value("OUT", SetValue::OUT) .value("IN", SetValue::IN) .value("PENUMBRA", SetValue::PENUMBRA) + + .def("__or__", [](SetValue v1, SetValue v2) { return v1|v2; }) + .def("__and__", [](SetValue v1, SetValue v2) { return v1&v2; }) ; } \ No newline at end of file diff --git a/src/core/paving/codac_Paving.cpp b/src/core/paving/codac_Paving.cpp index 0eb054e5f..307cb1e9c 100644 --- a/src/core/paving/codac_Paving.cpp +++ b/src/core/paving/codac_Paving.cpp @@ -237,12 +237,11 @@ namespace codac // todo: return x1->get_items().size() > x2->get_items().size(); // todo: } - vector Paving::get_connected_subsets(bool sort_by_size) const + vector Paving::get_connected_subsets(bool sort_by_size, SetValue val) const { reset_flags(); const Paving *p; - SetValue val = SetValue::UNKNOWN | SetValue::IN; vector v_connected_subsets; while((p = get_first_leaf(val, true))) diff --git a/src/core/paving/codac_Paving.h b/src/core/paving/codac_Paving.h index 5e633f105..42a049ae0 100644 --- a/src/core/paving/codac_Paving.h +++ b/src/core/paving/codac_Paving.h @@ -206,9 +206,10 @@ namespace codac * * \param sort_by_size (optional) if `true` then the subsets will be * sort by the number of boxes they are made of + * \param val the value of the leaves defining the connected items * \return the set of connected subsets */ - std::vector get_connected_subsets(bool sort_by_size = false) const; + std::vector get_connected_subsets(bool sort_by_size = false, SetValue val = SetValue::UNKNOWN | SetValue::IN) const; /// @}