Skip to content

Commit 34fe39a

Browse files
authored
Merge pull request #263 from SimonRohou/codac2_dev
Various updates.. tubes, graphics, and minor corrections
2 parents bfb5739 + a9717f5 commit 34fe39a

7 files changed

Lines changed: 206 additions & 11 deletions

File tree

doc/manual/manual/visualization/functions.rst

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,8 +131,8 @@ Geometric shapes
131131
.. doxygenfunction:: codac2::Figure2D::draw_ellipsoid(const Ellipsoid&, const StyleProperties&)
132132
:project: codac
133133

134-
Trajectories
135-
------------
134+
Trajectories and tubes
135+
----------------------
136136

137137
.. doxygenfunction:: codac2::Figure2D::draw_trajectory(const SampledTraj<Vector>&, const StyleProperties&)
138138
:project: codac
@@ -148,6 +148,12 @@ Trajectories can be drawn with a ColorMap instead of the classic StyleProperties
148148
.. doxygenfunction:: codac2::Figure2D::draw_trajectory(const AnalyticTraj<VectorType>&, const ColorMap&)
149149
:project: codac
150150

151+
.. doxygenfunction:: codac2::Figure2D::draw_tube(const SlicedTube<IntervalVector>&, const StyleProperties&)
152+
:project: codac
153+
154+
.. doxygenfunction:: codac2::Figure2D::draw_tube(const SlicedTube<IntervalVector>&, const ColorMap&)
155+
:project: codac
156+
151157
Vehicles
152158
--------
153159

python/src/core/codac2_py_cast.h

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
#include <pybind11/pybind11.h>
1414
#include <codac2_AnalyticTraj.h>
15+
#include <codac2_SlicedTube.h>
1516

1617
namespace py = pybind11;
1718
using namespace pybind11::literals;
@@ -103,4 +104,25 @@ namespace codac2
103104
const py::object& f_ = x.attr("f");
104105
return f_.cast<const T&>();
105106
}
107+
108+
template<typename T>
109+
requires (std::is_same_v<SlicedTube<Interval>,T>
110+
|| std::is_same_v<SlicedTube<IntervalVector>,T>
111+
|| std::is_same_v<SlicedTube<IntervalMatrix>,T>)
112+
bool is_instance(const py::object& x)
113+
{
114+
const py::object& x_ = x.attr("tube");
115+
return x_ && py::isinstance<T>(x_);
116+
}
117+
118+
template<typename T>
119+
requires (std::is_same_v<SlicedTube<Interval>,T>
120+
|| std::is_same_v<SlicedTube<IntervalVector>,T>
121+
|| std::is_same_v<SlicedTube<IntervalMatrix>,T>)
122+
const T& cast(const py::object& x)
123+
{
124+
assert(is_instance<T>(x));
125+
const py::object& x_ = x.attr("tube");
126+
return x_.cast<const T&>();
127+
}
106128
}

python/src/core/paver/codac2_py_pave.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#include <pybind11/pybind11.h>
1111
#include <pybind11/operators.h>
1212
#include <pybind11/stl.h>
13+
#include <pybind11/functional.h>
1314
#include <codac2_pave.h>
1415
#include "codac2_py_pave_docs.h" // Generated file from Doxygen XML (doxygen2docstring.py):
1516
#include "codac2_py_cast.h"
@@ -29,7 +30,7 @@ void export_pave(py::module& m)
2930
PAVINGINOUT_PAVE_CONST_INTERVALVECTOR_REF_CONST_SEPBASE_REF_DOUBLE_BOOL,
3031
"x"_a, "s"_a, "eps"_a, "verbose"_a=false);
3132

32-
m.def("pave", &codac2::regular_pave,
33+
m.def("regular_pave", &codac2::regular_pave,
3334
PAVINGINOUT_REGULAR_PAVE_CONST_INTERVALVECTOR_REF_CONST_FUNCTION_BOOLINTERVAL_CONST_INTERVALVECTOR_REF__REF_DOUBLE_BOOL,
3435
"x"_a, "test"_a, "eps"_a, "verbose"_a=false);
3536

python/src/graphics/figures/codac2_py_Figure2D.cpp

Lines changed: 48 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ void export_Figure2D(py::module& m)
7979
CONST_VECTOR_FIGUREAXIS_REF_FIGURE2D_AXES_CONST)
8080

8181
.def("set_axes", &Figure2D::set_axes,
82-
VOID_FIGURE2D_SET_AXES_CONST_FIGUREAXIS_REF_CONST_FIGUREAXIS_REF,
82+
FIGURE2D_REF_FIGURE2D_SET_AXES_CONST_FIGUREAXIS_REF_CONST_FIGUREAXIS_REF,
8383
"axis1"_a, "axis2"_a)
8484

8585
.def("i", &Figure2D::i,
@@ -213,6 +213,27 @@ void export_Figure2D(py::module& m)
213213
VOID_FIGURE2D_PLOT_TRAJECTORY_CONST_SAMPLEDTRAJ_DOUBLE_REF_CONST_STYLEPROPERTIES_REF,
214214
"x"_a, "s"_a=StyleProperties())
215215

216+
.def("draw_tube", [](Figure2D& fig, const py::object& x, const StyleProperties& s)
217+
{
218+
if(!is_instance<SlicedTube<IntervalVector>>(x)) {
219+
assert_release("draw_tube: invalid function type");
220+
}
221+
222+
fig.draw_tube(cast<SlicedTube<IntervalVector>>(x), s);
223+
},
224+
VOID_FIGURE2D_DRAW_TUBE_CONST_SLICEDTUBE_INTERVALVECTOR_REF_CONST_STYLEPROPERTIES_REF,
225+
"x"_a, "s"_a)
226+
227+
.def("draw_tube", [](Figure2D& fig, const py::object& x, const ColorMap& cmap)
228+
{
229+
if(!is_instance<SlicedTube<IntervalVector>>(x)) {
230+
assert_release("draw_tube: invalid function type");
231+
}
232+
233+
fig.draw_tube(cast<SlicedTube<IntervalVector>>(x), cmap);
234+
},
235+
VOID_FIGURE2D_DRAW_TUBE_CONST_SLICEDTUBE_INTERVALVECTOR_REF_CONST_COLORMAP_REF,
236+
"x"_a, "cmap"_a)
216237

217238
// Robots
218239

@@ -253,14 +274,15 @@ void export_Figure2D(py::module& m)
253274

254275
.def(py::init<>()) // for using static methods in Matlab
255276

256-
.def_static("selected_fig", &DefaultFigure::selected_fig,
277+
.def_static("selected_fig", &DefaultFigure::selected_fig, py::return_value_policy::reference,
257278
STATIC_SHARED_PTR_FIGURE2D_DEFAULTFIGURE_SELECTED_FIG)
258279

259280
.def_static("set", &DefaultFigure::set,
260281
STATIC_VOID_DEFAULTFIGURE_SET_SHARED_PTR_FIGURE2D)
261282

262-
.def_static("set_axes", &DefaultFigure::set_axes,
263-
STATIC_VOID_DEFAULTFIGURE_SET_AXES_CONST_FIGUREAXIS_REF_CONST_FIGUREAXIS_REF)
283+
.def_static("set_axes", &DefaultFigure::set_axes, py::return_value_policy::reference,
284+
STATIC_FIGURE2D_REF_DEFAULTFIGURE_SET_AXES_CONST_FIGUREAXIS_REF_CONST_FIGUREAXIS_REF,
285+
"axis1"_a, "axis2"_a)
264286

265287
.def_static("set_window_properties", &DefaultFigure::set_window_properties,
266288
STATIC_VOID_DEFAULTFIGURE_SET_WINDOW_PROPERTIES_CONST_VECTOR_REF_CONST_VECTOR_REF)
@@ -357,6 +379,28 @@ void export_Figure2D(py::module& m)
357379
STATIC_VOID_DEFAULTFIGURE_DRAW_TRAJECTORY_CONST_ANALYTICTRAJ_VECTORTYPE_REF_CONST_COLORMAP_REF,
358380
"x"_a, "cmap"_a)
359381

382+
.def_static("draw_tube", [](const py::object& x, const StyleProperties& s)
383+
{
384+
if(!is_instance<SlicedTube<IntervalVector>>(x)) {
385+
assert_release("draw_tube: invalid function type");
386+
}
387+
388+
DefaultFigure::draw_tube(cast<SlicedTube<IntervalVector>>(x), s);
389+
},
390+
STATIC_VOID_DEFAULTFIGURE_DRAW_TUBE_CONST_SLICEDTUBE_INTERVALVECTOR_REF_CONST_STYLEPROPERTIES_REF,
391+
"x"_a, "s"_a)
392+
393+
.def_static("draw_tube", [](const py::object& x, const ColorMap& cmap)
394+
{
395+
if(!is_instance<SlicedTube<IntervalVector>>(x)) {
396+
assert_release("draw_tube: invalid function type");
397+
}
398+
399+
DefaultFigure::draw_tube(cast<SlicedTube<IntervalVector>>(x), cmap);
400+
},
401+
STATIC_VOID_DEFAULTFIGURE_DRAW_TUBE_CONST_SLICEDTUBE_INTERVALVECTOR_REF_CONST_COLORMAP_REF,
402+
"x"_a, "cmap"_a)
403+
360404
// Robots
361405

362406
.def_static("draw_tank", &DefaultFigure::draw_tank,

src/core/matrices/eigen/MatrixBase_addons/codac2_MatrixBase_addons_IntervalMatrixBase.h

Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,8 +116,19 @@ inline auto diam() const
116116
degenerate_mat(diam);
117117
}
118118

119+
inline bool contains(const Matrix<double,RowsAtCompileTime,ColsAtCompileTime>& x) const
120+
{
121+
return _contains(x);
122+
}
123+
119124
template<typename OtherDerived>
120125
inline bool contains(const MatrixBase<OtherDerived>& x) const
126+
{
127+
return _contains(x);
128+
}
129+
130+
template<typename T>
131+
inline bool _contains(const T& x) const
121132
{
122133
assert_release(x.size() == this->size());
123134

@@ -132,8 +143,19 @@ inline bool contains(const MatrixBase<OtherDerived>& x) const
132143
return true;
133144
}
134145

146+
inline bool interior_contains(const Matrix<double,RowsAtCompileTime,ColsAtCompileTime>& x) const
147+
{
148+
return _interior_contains(x);
149+
}
150+
135151
template<typename OtherDerived>
136152
inline bool interior_contains(const MatrixBase<OtherDerived>& x) const
153+
{
154+
return _interior_contains(x);
155+
}
156+
157+
template<typename T>
158+
inline bool _interior_contains(const T& x) const
137159
{
138160
assert_release(x.size() == this->size());
139161

@@ -177,8 +199,19 @@ inline bool is_flat() const
177199
return false;
178200
}
179201

202+
inline bool intersects(const Matrix<codac2::Interval,RowsAtCompileTime,ColsAtCompileTime>& x) const
203+
{
204+
return _intersects(x);
205+
}
206+
180207
template<typename OtherDerived>
181208
inline bool intersects(const MatrixBase<OtherDerived>& x) const
209+
{
210+
return _intersects(x);
211+
}
212+
213+
template<typename OtherDerived>
214+
inline bool _intersects(const MatrixBase<OtherDerived>& x) const
182215
{
183216
assert_release(this->size() == x.size());
184217

@@ -193,8 +226,19 @@ inline bool intersects(const MatrixBase<OtherDerived>& x) const
193226
return true;
194227
}
195228

229+
inline bool is_disjoint(const Matrix<codac2::Interval,RowsAtCompileTime,ColsAtCompileTime>& x) const
230+
{
231+
return _is_disjoint(x);
232+
}
233+
196234
template<typename OtherDerived>
197235
inline bool is_disjoint(const MatrixBase<OtherDerived>& x) const
236+
{
237+
return _is_disjoint(x);
238+
}
239+
240+
template<typename OtherDerived>
241+
inline bool _is_disjoint(const MatrixBase<OtherDerived>& x) const
198242
{
199243
assert_release(this->size() == x.size());
200244

@@ -209,8 +253,19 @@ inline bool is_disjoint(const MatrixBase<OtherDerived>& x) const
209253
return false;
210254
}
211255

256+
inline bool overlaps(const Matrix<codac2::Interval,RowsAtCompileTime,ColsAtCompileTime>& x) const
257+
{
258+
return _overlaps(x);
259+
}
260+
212261
template<typename OtherDerived>
213262
inline bool overlaps(const MatrixBase<OtherDerived>& x) const
263+
{
264+
return _overlaps(x);
265+
}
266+
267+
template<typename OtherDerived>
268+
inline bool _overlaps(const MatrixBase<OtherDerived>& x) const
214269
{
215270
assert_release(this->size() == x.size());
216271

@@ -225,8 +280,19 @@ inline bool overlaps(const MatrixBase<OtherDerived>& x) const
225280
return true;
226281
}
227282

283+
inline bool is_subset(const Matrix<codac2::Interval,RowsAtCompileTime,ColsAtCompileTime>& x) const
284+
{
285+
return _is_subset(x);
286+
}
287+
228288
template<typename OtherDerived>
229289
inline bool is_subset(const MatrixBase<OtherDerived>& x) const
290+
{
291+
return _is_subset(x);
292+
}
293+
294+
template<typename T>
295+
inline bool _is_subset(const T& x) const
230296
{
231297
assert_release(this->size() == x.size());
232298

@@ -241,8 +307,19 @@ inline bool is_subset(const MatrixBase<OtherDerived>& x) const
241307
return true;
242308
}
243309

310+
inline bool is_strict_subset(const Matrix<codac2::Interval,RowsAtCompileTime,ColsAtCompileTime>& x) const
311+
{
312+
return _is_strict_subset(x);
313+
}
314+
244315
template<typename OtherDerived>
245316
inline bool is_strict_subset(const MatrixBase<OtherDerived>& x) const
317+
{
318+
return _is_strict_subset(x);
319+
}
320+
321+
template<typename T>
322+
inline bool _is_strict_subset(const T& x) const
246323
{
247324
assert_release(this->size() == x.size());
248325

@@ -260,8 +337,19 @@ inline bool is_strict_subset(const MatrixBase<OtherDerived>& x) const
260337
return false;
261338
}
262339

340+
inline bool is_interior_subset(const Matrix<codac2::Interval,RowsAtCompileTime,ColsAtCompileTime>& x) const
341+
{
342+
return _is_interior_subset(x);
343+
}
344+
263345
template<typename OtherDerived>
264346
inline bool is_interior_subset(const MatrixBase<OtherDerived>& x) const
347+
{
348+
return _is_interior_subset(x);
349+
}
350+
351+
template<typename OtherDerived>
352+
inline bool _is_interior_subset(const MatrixBase<OtherDerived>& x) const
265353
{
266354
assert_release(this->size() == x.size());
267355

@@ -276,8 +364,19 @@ inline bool is_interior_subset(const MatrixBase<OtherDerived>& x) const
276364
return true;
277365
}
278366

367+
inline bool is_strict_interior_subset(const Matrix<codac2::Interval,RowsAtCompileTime,ColsAtCompileTime>& x) const
368+
{
369+
return _is_strict_interior_subset(x);
370+
}
371+
279372
template<typename OtherDerived>
280373
inline bool is_strict_interior_subset(const MatrixBase<OtherDerived>& x) const
374+
{
375+
return _is_strict_interior_subset(x);
376+
}
377+
378+
template<typename OtherDerived>
379+
inline bool _is_strict_interior_subset(const MatrixBase<OtherDerived>& x) const
281380
{
282381
assert_release(this->size() == x.size());
283382

@@ -292,8 +391,19 @@ inline bool is_strict_interior_subset(const MatrixBase<OtherDerived>& x) const
292391
return true;
293392
}
294393

394+
inline bool is_superset(const Matrix<codac2::Interval,RowsAtCompileTime,ColsAtCompileTime>& x) const
395+
{
396+
return _is_superset(x);
397+
}
398+
295399
template<typename OtherDerived>
296400
inline bool is_superset(const MatrixBase<OtherDerived>& x) const
401+
{
402+
return _is_superset(x);
403+
}
404+
405+
template<typename OtherDerived>
406+
inline bool _is_superset(const MatrixBase<OtherDerived>& x) const
297407
{
298408
assert_release(this->size() == x.size());
299409

@@ -308,8 +418,19 @@ inline bool is_superset(const MatrixBase<OtherDerived>& x) const
308418
return true;
309419
}
310420

421+
inline bool is_strict_superset(const Matrix<codac2::Interval,RowsAtCompileTime,ColsAtCompileTime>& x) const
422+
{
423+
return _is_strict_superset(x);
424+
}
425+
311426
template<typename OtherDerived>
312427
inline bool is_strict_superset(const MatrixBase<OtherDerived>& x) const
428+
{
429+
return _is_strict_superset(x);
430+
}
431+
432+
template<typename OtherDerived>
433+
inline bool _is_strict_superset(const MatrixBase<OtherDerived>& x) const
313434
{
314435
assert_release(this->size() == x.size());
315436

src/graphics/figures/codac2_Figure2D.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,12 @@ const std::vector<FigureAxis>& Figure2D::axes() const
4848
return _axes;
4949
}
5050

51-
void Figure2D::set_axes(const FigureAxis& axis1, const FigureAxis& axis2)
51+
Figure2D& Figure2D::set_axes(const FigureAxis& axis1, const FigureAxis& axis2)
5252
{
5353
_axes = { axis1, axis2 };
5454
for(const auto& output_fig : _output_figures)
5555
output_fig->update_axes();
56+
return *this;
5657
}
5758

5859
const Index& Figure2D::i() const

0 commit comments

Comments
 (0)