Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions doc/manual/development/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,19 @@
Changelog
=========

Pull Request from godardma (17/04/26)
-------------------------------------


Commit 52b81c8 ([cmake] warning for Doxygen version)
----------------------------------------------------

set_axes change for Figure2D
~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Since this PR, a bounding box can be passed to the set_axes method to specify the ranges of the x and y axes.
The old method with ``axis(id,Interval)`` still works

Python binding build requirement
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Expand Down
14 changes: 7 additions & 7 deletions doc/manual/manual/visualization/figures.rst
Original file line number Diff line number Diff line change
Expand Up @@ -106,17 +106,17 @@ Once created, the properties of a Figure2D object can be modified using the foll
.. code-tab:: py

fig.set_window_properties([50,50],[500,500]) # set the window position and size
fig.set_axes(axis(0,[-10,10]), axis(1,[-10,10])) # set the x-axis index to 0 and its range to [-10,10], same for y with index 1
fig.set_axes([[-15,5],[-10,10]]) # set the x-axis range to [-15,5] and y-axis range to [-10,10]

.. code-tab:: c++

fig.set_window_properties({50,50},{500,500}); // set the window position and size
fig.set_axes(axis(0,{-10,10}), axis(1,{-10,10})); // set the x-axis index to 0 and its range to [-10,10], same for y with index 1
fig.set_axes({{-15,5},{-10,10}}); // set the x-axis range to [-15,5] and y-axis range to [-10,10]

.. code-tab:: matlab

fig.set_window_properties(Vector({50,50}),Vector({500,500})); % position, window size
fig.set_axes(axis(1,Interval(-10,10)), axis(2,Interval(-10,10))); % (axis_id,[range_of_values_on_this_axis])
fig.set_window_properties(Vector({50,50}),Vector({500,500})); % set the window position and size
fig.set_axes(IntervalVector({{-15,5},{-10,10}})); % set the x-axis range to [-15,5] and y-axis range to [-10,10]

The same methods can be applied on the DefaultFigure object.

Expand All @@ -125,17 +125,17 @@ The same methods can be applied on the DefaultFigure object.
.. code-tab:: py

DefaultFigure.set_window_properties([50,50],[500,500]) # set the window position and size
DefaultFigure.set_axes(axis(0,[-10,10]), axis(1,[-10,10])) # set the x-axis index to 0 and its range to [-10,10], same for y with index 1
DefaultFigure.set_axes([[-15,5],[-10,10]]) # set the x-axis range to [-15,5] and y-axis range to [-10,10]

.. code-tab:: c++

DefaultFigure::set_window_properties({50,50},{500,500}); // set the window position and size
DefaultFigure::set_axes(axis(0,{-10,10}), axis(1,{-10,10})); // set the x-axis index to 0 and its range to [-10,10], same for y with index 1
DefaultFigure::set_axes({{-15,5},{-10,10}}); // set the x-axis range to [-15,5] and y-axis range to [-10,10]

.. code-tab:: matlab

DefaultFigure().set_window_properties(Vector({50,50}),Vector({500,500})); % set the window position and size
DefaultFigure().set_axes(axis(1,Interval(-10,10)), axis(2,Interval(-10,10))); % set the x-axis index to 0 and its range to [-10,10], same for y with index 1
DefaultFigure().set_axes(IntervalVector({{-15,5},{-10,10}})); % set the x-axis range to [-15,5] and y-axis range to [-10,10]


Many properties have an associated getter :
Expand Down
4 changes: 2 additions & 2 deletions examples/00_graphics/graphic_examples.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,13 @@ int main(){
// For IPE, it generates a file named "My figure 1.xml" that can be edited with IPE, and converted to PDF

fig1->set_window_properties({50,50},{500,500}); // position, window size
fig1->set_axes(axis(0,{-10,10}), axis(1,{-10,10})); // (axis_id,{range_of_values_on_this_axis})
fig1->set_axes(IntervalVector::constant(2,{-10,10})); // bounding box
fig1->draw_box({{-1,1},{-1,1}},{Color::green(),Color::red(0.2)}); // drawing a green box with red opacity values inside
fig1->draw_circle({1,1},0.5,Color({255,155,5})); // drawing a circle at (1,1) of radius 0.5 with a custom RGB color
fig1->draw_ring({1,1},{4,6},Color::red()); // drawing a ring at (1,1) of radius {4,6} with a predefined red color

std::shared_ptr<codac2::Figure2D> fig2 = std::make_shared<Figure2D>("My Figure 2",GraphicOutput::VIBES|GraphicOutput::IPE);
fig2->set_axes(axis(0,{-1,5}), axis(1,{-1,5}));
fig2->set_axes(axis(0,{-1,5}), axis(1,{-1,5})); // (axis_id,{range_of_values_on_this_axis})
fig2->set_window_properties({250,250},{500,500});

// The previously declared figure "fig2" can now be used as a DefaultFigure
Expand Down
4 changes: 2 additions & 2 deletions examples/00_graphics/graphic_examples.m
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@
% For IPE, it generates a file named "My figure 1.xml" that can be edited with IPE, and converted to PDF

fig1.set_window_properties(Vector({50,50}),Vector({500,500})); % position, window size
fig1.set_axes(axis(1,Interval(-10,10)), axis(2,Interval(-10,10))); % (axis_id,[range_of_values_on_this_axis])
fig1.set_axes(IntervalVector().constant(2,Interval(-10,10))); % bounding box
fig1.draw_box(IntervalVector({{-1,1},{-1,1}}),StyleProperties({Color().green(),Color().red(0.2)})); % drawing a green box with red opacity values inside
fig1.draw_circle(Vector({1,1}),0.5,Color({255,155,5})); % drawing a circle at (1,1) of radius 0.5 with a custom RGB color
fig1.draw_ring(Vector({1,1}),Interval(4,6),Color().red()); % drawing a ring at (1,1) of radius [4,6] with a predefined red color

fig2 = Figure2D("My figure 2", GraphicOutput().VIBES.union(GraphicOutput().IPE));
fig2.set_axes(axis(1,Interval(-1,5)), axis(2,Interval(-1,5)));
fig2.set_axes(axis(1,Interval(-1,5)), axis(2,Interval(-1,5))); % (axis_id,[range_of_values_on_this_axis])
fig2.set_window_properties(Vector({250,250}),Vector({500,500}));

% The previously declared figure "fig2" can now be used as a DefaultFigure
Expand Down
4 changes: 2 additions & 2 deletions examples/00_graphics/graphic_examples.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@
# For IPE, it generates a file named "My figure 1.xml" that can be edited with IPE, and converted to PDF

fig1.set_window_properties([50,50],[500,500]) # position, window size
fig1.set_axes(axis(0,[-10,10]), axis(1,[-10,10])) # (axis_id,[range_of_values_on_this_axis])
fig1.set_axes(IntervalVector.constant(2,[-10,10])) # bounding box
fig1.draw_box([[-1,1],[-1,1]],[Color.green(),Color.red(0.2)]) # drawing a green box with red opacity values inside
fig1.draw_circle([1,1],0.5,Color([255,155,5])) # drawing a circle at (1,1) of radius 0.5 with a custom RGB color
fig1.draw_ring([1,1],[4,6],Color.red()) # drawing a ring at (1,1) of radius [4,6] with a predefined red color

fig2 = Figure2D("My figure 2", GraphicOutput.VIBES | GraphicOutput.IPE)
fig2.set_axes(axis(0,[-1,5]), axis(1,[-1,5]))
fig2.set_axes(axis(0,[-1,5]), axis(1,[-1,5])) # (axis_id,[range_of_values_on_this_axis])
fig2.set_window_properties([250,250],[500,500])

# The previously declared figure "fig2" can now be used as a DefaultFigure
Expand Down
17 changes: 13 additions & 4 deletions python/src/graphics/figures/codac2_py_Figure2D.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,14 @@ void export_Figure2D(py::module& m)

.def("axes", &Figure2D::axes,
CONST_VECTOR_FIGUREAXIS_REF_FIGURE2D_AXES_CONST)
.def("set_axes", &Figure2D::set_axes,

.def("set_axes", (Figure2D& (Figure2D::*)(const FigureAxis&, const FigureAxis&)) &Figure2D::set_axes,
FIGURE2D_REF_FIGURE2D_SET_AXES_CONST_FIGUREAXIS_REF_CONST_FIGUREAXIS_REF,
"axis1"_a, "axis2"_a)

.def("set_axes", (Figure2D& (Figure2D::*)(const IntervalVector&)) &Figure2D::set_axes,
FIGURE2D_REF_FIGURE2D_SET_AXES_CONST_INTERVALVECTOR_REF,
"bbox"_a)

.def("i", &Figure2D::i,
CONST_INDEX_REF_FIGURE2D_I_CONST)
Expand Down Expand Up @@ -321,10 +325,15 @@ void export_Figure2D(py::module& m)

.def_static("set", &DefaultFigure::set,
STATIC_VOID_DEFAULTFIGURE_SET_SHARED_PTR_FIGURE2D)
.def_static("set_axes", &DefaultFigure::set_axes, py::return_value_policy::reference,

.def_static("set_axes", (Figure2D& (*)(const FigureAxis&, const FigureAxis&)) &DefaultFigure::set_axes, py::return_value_policy::reference,
STATIC_FIGURE2D_REF_DEFAULTFIGURE_SET_AXES_CONST_FIGUREAXIS_REF_CONST_FIGUREAXIS_REF,
"axis1"_a, "axis2"_a)

.def_static("set_axes", (Figure2D& (*)(const IntervalVector&)) &DefaultFigure::set_axes, py::return_value_policy::reference,
STATIC_FIGURE2D_REF_DEFAULTFIGURE_SET_AXES_CONST_INTERVALVECTOR_REF,
"bbox"_a)


.def_static("set_window_properties", &DefaultFigure::set_window_properties,
STATIC_VOID_DEFAULTFIGURE_SET_WINDOW_PROPERTIES_CONST_VECTOR_REF_CONST_VECTOR_REF)
Expand Down
6 changes: 6 additions & 0 deletions src/graphics/figures/codac2_Figure2D.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,12 @@ Figure2D& Figure2D::set_axes(const FigureAxis& axis1, const FigureAxis& axis2)
return *this;
}

Figure2D& Figure2D::set_axes(const IntervalVector& bbox)
{
assert_release(bbox.size()==2);
return set_axes(axis(0,bbox[0]),axis(1,bbox[1]));
}

const Index& Figure2D::i() const
{
return axes()[0].dim_id;
Expand Down
18 changes: 18 additions & 0 deletions src/graphics/figures/codac2_Figure2D.h
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,13 @@ namespace codac2
*/
Figure2D& set_axes(const FigureAxis& axis1, const FigureAxis& axis2);

/**
* \brief Setter for the axes of the figure
*
* \param bbox Bounding box
*/
Figure2D& set_axes(const IntervalVector& bbox);

/**
* \brief Getter for the index of the horizontal axis
*
Expand Down Expand Up @@ -666,6 +673,17 @@ namespace codac2
auto_init();
return selected_fig()->set_axes(axis1,axis2);
}

/**
* \brief Setter for the axes of the figure
*
* \param bbox Bounding box
*/
static Figure2D& set_axes(const IntervalVector& bbox)
{
auto_init();
return selected_fig()->set_axes(bbox);
}

/**
* \brief Setter for the position and size of the window
Expand Down