Skip to content

Commit

Permalink
[py] binding of get_connected_subsets and related classes
Browse files Browse the repository at this point in the history
  • Loading branch information
SimonRohou committed Jun 21, 2023
1 parent 3477015 commit eeb6d3d
Show file tree
Hide file tree
Showing 9 changed files with 107 additions and 7 deletions.
2 changes: 2 additions & 0 deletions python/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
7 changes: 5 additions & 2 deletions python/codac_py_core.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,10 @@ void export_VIBesFigPaving(py::module& m);

void export_geometry(py::module& m, py::class_<Ctc, pyCtc>& ctc, py::class_<ibex::Sep, pySep>& 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);
Expand Down Expand Up @@ -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);
Expand Down
3 changes: 2 additions & 1 deletion python/src/core/graphics/codac_py_VIBesFigPaving.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ void export_VIBesFigPaving(py::module& m)

.def(py::init<const string&, const Paving*>(),
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)
Expand Down
36 changes: 36 additions & 0 deletions python/src/core/paving/codac_py_ConnectedSubset.cpp
Original file line number Diff line number Diff line change
@@ -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 <pybind11/pybind11.h>
#include <pybind11/stl.h>
#include <pybind11/operators.h>
#include <pybind11/functional.h>

#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> connectedsubset(m, "ConnectedSubset", CONNECTEDSUBSET_MAIN);
connectedsubset

.def("get_boxes", &ConnectedSubset::get_boxes,
CONNECTEDSUBSET_VECTORINTERVALVECTOR_GET_BOXES)

;
}
10 changes: 9 additions & 1 deletion python/src/core/paving/codac_py_Paving.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include <pybind11/operators.h>
#include <pybind11/functional.h>

#include "codac_Set.h"
#include "codac_Paving.h"
// Generated file from Doxygen XML (doxygen2docstring.py):
#include "codac_py_Paving_docs.h"
Expand All @@ -26,5 +27,12 @@ using namespace pybind11::literals;

void export_Paving(py::module& m)
{
py::class_<Paving> tplane(m, "Paving", PAVING_MAIN);
py::class_<Paving> 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)

;
}
47 changes: 47 additions & 0 deletions python/src/core/paving/codac_py_SIVIAPaving.cpp
Original file line number Diff line number Diff line change
@@ -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 <pybind11/pybind11.h>
#include <pybind11/stl.h>
#include <pybind11/operators.h>
#include <pybind11/functional.h>

#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_<SIVIAPaving,Paving> paving(m, "SIVIAPaving", SIVIAPAVING_MAIN);
paving

.def(py::init<const IntervalVector&>(),
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)
;
}
3 changes: 3 additions & 0 deletions python/src/core/paving/codac_py_Set.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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; })
;
}
3 changes: 1 addition & 2 deletions src/core/paving/codac_Paving.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -237,12 +237,11 @@ namespace codac
// todo: return x1->get_items().size() > x2->get_items().size();
// todo: }

vector<ConnectedSubset> Paving::get_connected_subsets(bool sort_by_size) const
vector<ConnectedSubset> Paving::get_connected_subsets(bool sort_by_size, SetValue val) const
{
reset_flags();

const Paving *p;
SetValue val = SetValue::UNKNOWN | SetValue::IN;
vector<ConnectedSubset> v_connected_subsets;

while((p = get_first_leaf(val, true)))
Expand Down
3 changes: 2 additions & 1 deletion src/core/paving/codac_Paving.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<ConnectedSubset> get_connected_subsets(bool sort_by_size = false) const;
std::vector<ConnectedSubset> get_connected_subsets(bool sort_by_size = false, SetValue val = SetValue::UNKNOWN | SetValue::IN) const;

/// @}

Expand Down

0 comments on commit eeb6d3d

Please sign in to comment.