-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[ctc] added CtcCtcBoundary, CtcPolygon + binding + tests
- Loading branch information
1 parent
43c2b19
commit 147517e
Showing
18 changed files
with
548 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
/** | ||
* Codac binding (core) | ||
* ---------------------------------------------------------------------------- | ||
* \date 2024 | ||
* \author Simon Rohou | ||
* \copyright Copyright 2024 Codac Team | ||
* \license GNU Lesser General Public License (LGPL) | ||
*/ | ||
|
||
#include <pybind11/pybind11.h> | ||
#include <pybind11/operators.h> | ||
#include <pybind11/functional.h> | ||
#include <pybind11/stl.h> | ||
#include <codac2_template_tools.h> | ||
#include <codac2_CtcCtcBoundary.h> | ||
#include "codac2_py_Ctc.h" | ||
#include "codac2_py_CtcCtcBoundary_docs.h" // Generated file from Doxygen XML (doxygen2docstring.py): | ||
|
||
using namespace std; | ||
using namespace codac2; | ||
namespace py = pybind11; | ||
using namespace pybind11::literals; | ||
|
||
void export_CtcCtcBoundary(py::module& m, py::class_<CtcBase<IntervalVector>,pyCtcIntervalVector>& pyctc) | ||
{ | ||
py::class_<CtcCtcBoundary> exported(m, "CtcCtcBoundary", pyctc, CTCCTCBOUNDARY_MAIN); | ||
exported | ||
|
||
.def(py::init( | ||
[](const CtcBase<IntervalVector>& ctc_boundary, const std::function<BoolInterval(const Vector&)>& inside_test) | ||
{ | ||
return std::make_unique<CtcCtcBoundary>(ctc_boundary.copy(),inside_test); | ||
}), | ||
CTCCTCBOUNDARY_CTCCTCBOUNDARY_CONST_C_REF_CONST_FUNCTION_BOOLINTERVAL_CONST_VECTOR_REF__REF, | ||
"ctc_boundary"_a, "inside_test"_a) | ||
|
||
.def(CONTRACT_BOX_METHOD(CtcCtcBoundary, | ||
VOID_CTCCTCBOUNDARY_CONTRACT_INTERVALVECTOR_REF_CONST)) | ||
|
||
; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
/** | ||
* Codac binding (core) | ||
* ---------------------------------------------------------------------------- | ||
* \date 2024 | ||
* \author Simon Rohou | ||
* \copyright Copyright 2024 Codac Team | ||
* \license GNU Lesser General Public License (LGPL) | ||
*/ | ||
|
||
#include <pybind11/pybind11.h> | ||
#include <pybind11/operators.h> | ||
#include <pybind11/stl.h> | ||
#include <codac2_template_tools.h> | ||
#include <codac2_CtcPolygon.h> | ||
#include "codac2_py_Ctc.h" | ||
#include "codac2_py_CtcPolygon_docs.h" // Generated file from Doxygen XML (doxygen2docstring.py): | ||
|
||
using namespace std; | ||
using namespace codac2; | ||
namespace py = pybind11; | ||
using namespace pybind11::literals; | ||
|
||
void export_CtcPolygon(py::module& m, py::class_<CtcBase<IntervalVector>,pyCtcIntervalVector>& pyctc) | ||
{ | ||
py::class_<CtcPolygon> exported(m, "CtcPolygon", pyctc, CTCPOLYGON_MAIN); | ||
exported | ||
|
||
.def(py::init<const Polygon&>(), | ||
CTCPOLYGON_CTCPOLYGON_CONST_POLYGON_REF, | ||
"p"_a) | ||
|
||
.def(CONTRACT_BOX_METHOD(CtcPolygon, | ||
VOID_CTCPOLYGON_CONTRACT_INTERVALVECTOR_REF_CONST)) | ||
|
||
; | ||
|
||
py::implicitly_convertible<Polygon,CtcPolygon>(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
/** | ||
* codac2_CtcCtcBoundary.cpp | ||
* ---------------------------------------------------------------------------- | ||
* \date 2024 | ||
* \author Simon Rohou, Benoit Desrochers | ||
* \copyright Copyright 2024 Codac Team | ||
* \license GNU Lesser General Public License (LGPL) | ||
*/ | ||
|
||
#include "codac2_CtcCtcBoundary.h" | ||
|
||
using namespace std; | ||
using namespace codac2; | ||
|
||
void CtcCtcBoundary::contract(IntervalVector& x) const | ||
{ | ||
assert_release(x.size() == this->size()); | ||
|
||
size_t attempt_nb = 5; | ||
IntervalVector prev_x(x); | ||
_ctc_boundary.front().contract(x); | ||
|
||
for(const auto& b : prev_x.diff(x,false)) | ||
{ | ||
if(b.is_empty()) | ||
continue; | ||
|
||
Vector m = b.mid(); // first try: midpoint of the box | ||
BoolInterval d; | ||
size_t k = 0; | ||
|
||
do | ||
{ | ||
d = _inside_test(m); | ||
if(d == BoolInterval::UNKNOWN) | ||
m = b.rand(); // now, trying a random vector in the box | ||
} while(d == BoolInterval::UNKNOWN && k++ < attempt_nb); | ||
|
||
switch(d) | ||
{ | ||
case BoolInterval::TRUE: | ||
case BoolInterval::UNKNOWN: | ||
x |= b; | ||
break; | ||
case BoolInterval::FALSE: | ||
break; | ||
case BoolInterval::EMPTY: | ||
assert(false && "BoolInterval::EMPTY should not happen"); | ||
break; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
/** | ||
* \file codac2_CtcCtcBoundary.h | ||
* ---------------------------------------------------------------------------- | ||
* \date 2024 | ||
* \author Simon Rohou, Benoit Desrochers | ||
* \copyright Copyright 2024 Codac Team | ||
* \license GNU Lesser General Public License (LGPL) | ||
*/ | ||
|
||
#pragma once | ||
|
||
#include <functional> | ||
#include "codac2_Ctc.h" | ||
#include "codac2_IntervalVector.h" | ||
#include "codac2_Collection.h" | ||
#include "codac2_BoolInterval.h" | ||
#include "codac2_template_tools.h" | ||
|
||
namespace codac2 | ||
{ | ||
class CtcCtcBoundary : public Ctc<CtcCtcBoundary,IntervalVector> | ||
{ | ||
public: | ||
|
||
template<typename C> | ||
requires IsCtcBaseOrPtr<C,IntervalVector> | ||
CtcCtcBoundary(const C& ctc_boundary, const std::function<BoolInterval(const Vector&)>& inside_test) | ||
: Ctc<CtcCtcBoundary,IntervalVector>(size_of(ctc_boundary)), _ctc_boundary(ctc_boundary), _inside_test(inside_test) | ||
{ } | ||
|
||
void contract(IntervalVector& x) const; | ||
|
||
protected: | ||
|
||
const Collection<CtcBase<IntervalVector>> _ctc_boundary; | ||
const std::function<BoolInterval(const Vector&)> _inside_test; | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
/** | ||
* CtcPolygon.cpp | ||
* ---------------------------------------------------------------------------- | ||
* \date 2024 | ||
* \author Simon Rohou, Benoit Desrochers | ||
* \copyright Copyright 2024 Codac Team | ||
* \license GNU Lesser General Public License (LGPL) | ||
*/ | ||
|
||
#include <list> | ||
#include "codac2_CtcPolygon.h" | ||
#include "codac2_CtcUnion.h" | ||
#include "codac2_CtcSegment.h" | ||
#include "codac2_geometry.h" | ||
|
||
using namespace std; | ||
|
||
namespace codac2 | ||
{ | ||
CtcPolygon::CtcPolygon(const Polygon& p) | ||
: CtcCtcBoundary( | ||
|
||
// Contractor on the boundary | ||
[p] | ||
{ | ||
CtcUnion<IntervalVector> ctc_segments(2); | ||
for(const auto& edge_i : p.edges()) | ||
ctc_segments |= CtcSegment(edge_i[0],edge_i[1]); | ||
return ctc_segments; | ||
}(), | ||
|
||
// Tests if a point of a box is inside the polygon | ||
[p](const Vector& x) -> BoolInterval | ||
{ | ||
assert_release(x.size() == 2); | ||
return p.contains(x); | ||
} | ||
) | ||
{ } | ||
|
||
void CtcPolygon::contract(IntervalVector& x) const | ||
{ | ||
CtcCtcBoundary::contract(x); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
/** | ||
* \file codac2_CtcPolygon.h | ||
* ---------------------------------------------------------------------------- | ||
* \date 2024 | ||
* \author Simon Rohou, Benoit Desrochers | ||
* \copyright Copyright 2024 Codac Team | ||
* \license GNU Lesser General Public License (LGPL) | ||
*/ | ||
|
||
#pragma once | ||
|
||
#include "codac2_Polygon.h" | ||
#include "codac2_CtcCtcBoundary.h" | ||
#include "codac2_CtcUnion.h" | ||
|
||
namespace codac2 | ||
{ | ||
class CtcPolygon : public CtcCtcBoundary | ||
{ | ||
public: | ||
|
||
CtcPolygon(const Polygon& p); | ||
void contract(IntervalVector& x) const; | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.