Skip to content
Open
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
4 changes: 4 additions & 0 deletions doc/manual/manual/visualization/3d_visualization.rst
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ The constructor takes one arguments: the name of the object file.

Figure3D fig ("my_object"); // for the object file my_object.obj

.. code-tab:: matlab

fig = Figure3D("my_object") % for the object file my_object.obj

Drawing functions
-----------------

Expand Down
85 changes: 84 additions & 1 deletion doc/manual/manual/visualization/colors.rst
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,20 @@ Predefined colors are available in the ``Color`` class. Each of the static metho
Color::light_purple(), Color::purple(), Color::dark_purple()
Color::light_pink(), Color::pink(), Color::dark_pink()

.. code-tab:: matlab

Color().none(), Color().white(), Color().black()
Color().light_gray(), Color().gray(), Color().dark_gray()
Color().light_green(), Color().green(), Color().dark_green()
Color().light_blue(), Color().blue(), Color().dark_blue()
Color().light_cyan(), Color().cyan(), Color().dark_cyan()
Color().light_yellow(), Color().yellow(), Color().dark_yellow()
Color().light_orange(), Color().orange(), Color().dark_orange()
Color().light_red(), Color().red(), Color().dark_red()
Color().light_brown(), Color().brown(), Color().dark_brown()
Color().light_purple(), Color().purple(), Color().dark_purple()
Color().light_pink(), Color().pink(), Color().dark_pink()

Each basic color is available in three shades: ``light_``, normal and ``dark_``:

.. figure:: img/codac_colors.png
Expand All @@ -59,6 +73,11 @@ Custom colors can be defined in the RGB or HSV color spaces. An enumeration ``Mo
Model::RGB; // RGB color space
Model::HSV; // HSV color space

.. code-tab:: matlab

Model().RGB % RGB color space
Model().HSV % HSV color space

A getter ``model()`` is available, and the methods ``rgb()`` and ``hsv()`` are used to do the conversion between the two color spaces.

If the color is in RGB then the red, green, blue and alpha values are between 0 and 255.
Expand Down Expand Up @@ -99,6 +118,16 @@ Additionnal methods are available for any useful purpose:
// HSV color without and with opacity
fig2.draw_box({{2.6,3.1},{2.6,3.1}}, {Color({108,90,78},Model::HSV),Color({108,90,78,20},Model::HSV)});

.. code-tab:: matlab

% predefined colors without and with opacity
fig.draw_point(Vector({2,2}), StyleProperties({Color().red(),Color().yellow(0.5)}));
% HTML color without and with opacity
fig.draw_box(IntervalVector({{2.4,2.9},{2.4,2.9}}),StyleProperties({Color("#da3907"),Color("#da390755")}));
% HSV color without and with opacity
fig.draw_box(IntervalVector({{2.6,3.1},{2.6,3.1}}),StyleProperties({Color({108,90,78},Model().HSV),Color({108,90,78,20},Model().HSV)}));



StyleProperties
---------------
Expand Down Expand Up @@ -127,6 +156,12 @@ A ``StyleProperties`` object is composed of two ``Color`` objects, one for the e
StyleProperties edge_style(Color::red()); // edge only
StyleProperties edge_fill_style({Color::blue(),Color::green()}); // edge and fill

.. code-tab:: matlab

default_style = StyleProperties() % default
edge_style = StyleProperties(Color().red()) % edge only
edge_fill_style = StyleProperties({Color().blue(),Color().green()}) % edge and fill


It can also be deduced from one or two ``Color`` objects.

Expand All @@ -146,6 +181,13 @@ It can also be deduced from one or two ``Color`` objects.
fig.draw_box({{2,5},{2,5}}, Color::red()); // red edge, no fill
fig.draw_box({{2,5},{2,5}}, {Color::blue(),Color::green()}); // blue edge, green fill

.. code-tab:: matlab

fig.draw_box(IntervalVector({{2.2,2.5},{2.2,2.5}}));
fig.draw_box(IntervalVector({{2.2,2.5},{2.2,2.5}}),StyleProperties().inside());
fig.draw_box(IntervalVector({{2.2,2.5},{2.2,2.5}}),Color().red());
fig.draw_box(IntervalVector({{2.2,2.5},{2.2,2.5}}),StyleProperties({Color().blue(),Color().green()}));

In addition, optional arguments can be passed to the ``StyleProperties`` object to define line style, line width, layer and Z-value.
For more information, see :ref:`subsec-graphics-colors-optional-arguments`.

Expand All @@ -161,6 +203,11 @@ For more information, see :ref:`subsec-graphics-colors-optional-arguments`.
fig.draw_box({{2,5},{2,5}}, StyleProperties(Color::red(), "..", "layer1", "w:0.1", "z:1.5"));
// Red edge, dotted line, line width of 0.1, z-value of 1.5 and on layer1

.. code-tab:: matlab

fig.draw_box(IntervalVector({{2,5},{2,5}}), StyleProperties(Color().red(), "..", "layer1", "w:0.1", "z:1.5"));
% Red edge, dotted line, line width of 0.1, z-value of 1.5 and on layer1


Color maps
----------
Expand All @@ -185,10 +232,19 @@ Color maps are used to convert a scalar value (between 0 and 1) to a color. The
ColorMap::blue_tube(); // blue color map, used mainly for tubes
ColorMap::red_tube(); // red color map, used mainly for tubes

.. code-tab:: matlab

ColorMap().basic(); % default color map
ColorMap().haxby(); % Haxby color map
ColorMap().rainbow(); % rainbow color map
ColorMap().blue_tube(); % blue color map, used mainly for tubes
ColorMap().red_tube(); % red color map, used mainly for tubes


These five color maps are displayed below:

.. figure:: img/colormaps.png
:width: 400px
:width: 600px

A paramater ``alpha`` can be passed to the predefined color maps to set the opacity of the colors (between 0 and 1). The default value is 1 (full opacity).

Expand All @@ -204,6 +260,11 @@ A paramater ``alpha`` can be passed to the predefined color maps to set the opac
// Create a haxby color map with 50% opacity
ColorMap cmap = ColorMap::haxby(0.5);

.. code-tab:: matlab

% Create a haxby color map with 50% opacity
cmap = ColorMap.haxby(0.5)

The method ``color()`` is used to get the color corresponding to a scalar value. The argument is a float between 0 and 1.

As for the ``Color`` class, the ``ColorMap`` also has a ``Model`` (RGB or HSV) and an associated getter ``model()``. The default ``Model`` is RGB.
Expand All @@ -228,6 +289,14 @@ You can also create your own color map :
custom_map[0.5] = Color({0,255,0});
custom_map[1] = Color({0,0,255});

.. code-tab:: matlab

% Create a custom color map
custom_map = ColorMap(Model().RGB);
custom_map.set_item(0,Color({255,0,0}));
custom_map.set_item(0.5,Color({0,255,0}));
custom_map.set_item(1,Color({0,0,255}));

Note that you can add RGB and HSV colors to the same color map. The model of the color map will define the interpolation space.

StyleGradientProperties
Expand All @@ -250,6 +319,10 @@ A ``StyleGradientProperties`` object involves a ``ColorMap``. Two constructors a
StyleGradientProperties default_style; // default
StyleGradientProperties custom_style(ColorMap::haxby()); // haxby color map

.. code-tab:: matlab

default_style = StyleGradientProperties() % default
custom_style = StyleGradientProperties(ColorMap().haxby()) % haxby color map

It can also be deduced from a ``ColorMap`` object.

Expand All @@ -265,6 +338,11 @@ It can also be deduced from a ``ColorMap`` object.
fig.draw_trajectory(traj); // Default style
fig.draw_trajectory(traj,ColorMap::haxby()); // haxby color map

.. code-tab:: matlab

fig.draw_trajectory(traj) % Default style
fig.draw_trajectory(traj,ColorMap().haxby()) % haxby color map

In addition, optional arguments can be passed to the ``StyleGradientProperties`` object to define line style, line width, layer and Z-value.
For more information, see :ref:`subsec-graphics-colors-optional-arguments`.

Expand All @@ -280,6 +358,11 @@ For more information, see :ref:`subsec-graphics-colors-optional-arguments`.
fig.draw_trajectory(traj, StyleGradientProperties(ColorMap::haxby(), "..", "layer1", "w:0.1", "z:1.5"));
// haxby color map, dotted line, line width of 0.1, z-value of 1.5 and on layer1

.. code-tab:: matlab

fig.draw_trajectory(traj, StyleGradientProperties(ColorMap().haxby(), "..", "layer1", "w:0.1", "z:1.5"))
% haxby color map, dotted line, line width of 0.1, z-value of 1.5 and on layer1

.. _subsec-graphics-colors-optional-arguments:

Optional arguments
Expand Down
30 changes: 29 additions & 1 deletion doc/manual/manual/visualization/figures.rst
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,12 @@ visualization while IPE creates a file that can be edited by the IPE editor. The
GraphicOutput::IPE // for IPE
GraphicOutput::VIBES | GraphicOutput::IPE // for both

.. code-tab:: matlab

GraphicOutput().VIBES % for VIBes
GraphicOutput().IPE % for IPE
GraphicOutput().VIBES.union(GraphicOutput().IPE) % for both

Note that for the VIBes output to work, the VIBes viewer must be launched before the program is run.

.. _subsec-graphics-2d-figures-figure2d:
Expand All @@ -50,6 +56,10 @@ DefaultFigure (see :ref:`subsec-graphics-2d-figures-defaultfigure`).

Figure2D fig ("My Figure",GraphicOutput::VIBES|GraphicOutput::IPE);

.. code-tab:: matlab

fig = Figure2D("My figure 1", GraphicOutput().VIBES.union(GraphicOutput().IPE));

.. _subsec-graphics-2d-figures-defaultfigure:

DefaultFigure
Expand All @@ -74,9 +84,16 @@ Any Figure2D object can be used as DefaultFigure with the set method:
DefaultFigure::set(fig);
fig->is_default(); // is true

Note that in C++ the figure must be a shared pointer in order to be passed to the `set` method.
.. code-tab:: matlab

fig = Figure2D("My figure", GraphicOutput().VIBES.union(GraphicOutput().IPE));
fig.is_default() % is False
DefaultFigure().set(fig);
fig.is_default() % is True


Note that in C++ the figure must be a shared pointer in order to be passed to the `set` method.

.. _subsec-graphics-2d-figures-figure-properties:

Figure properties
Expand All @@ -96,6 +113,11 @@ Once created, the properties of a Figure2D object can be modified using the foll
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

.. 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])

The same methods can be applied on the DefaultFigure object.

.. tabs::
Expand All @@ -110,6 +132,12 @@ The same methods can be applied on the DefaultFigure object.
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

.. 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


Many properties have an associated getter :

- size() for the figure size (type is Index)
Expand Down
15 changes: 15 additions & 0 deletions doc/manual/manual/visualization/functions.rst
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,14 @@ For example :
// On the DefaultFigure
DefaultFigure::draw_box({{2.2,2.5},{2.2,2.5}});

.. code-tab:: matlab

% On a figure
fig.draw_box(IntervalVector({{2.2,2.5},{2.2,2.5}}));

% On the DefaultFigure
DefaultFigure().draw_box(IntervalVector({{2.2,2.5},{2.2,2.5}}));

In addition to the arguments described here for every function, an optionnal argument of type StyleProperties can be added to choose the edge
and fill color (by default black edge no fill). This object can be deduced from one or two Color objects, see :ref:`this page <sec-graphics-colors>`
for more information.
Expand All @@ -46,6 +54,13 @@ for more information.
fig.draw_box({{2.2,2.5},{2.2,2.5}},{Color.red()}); // Red edge
fig.draw_box({{2.2,2.5},{2.2,2.5}},{Color.red(),Color.blue()}); // Red edge and blue fill

.. code-tab:: matlab

DefaultFigure().draw_box(IntervalVector({{2.2,2.5},{2.2,2.5}}),Color().red()); % Red edge
DefaultFigure().draw_box(IntervalVector({{2.2,2.5},{2.2,2.5}}),StyleProperties({Color().red()})); % Red edge
DefaultFigure().draw_box(IntervalVector({{2.2,2.5},{2.2,2.5}}),StyleProperties({Color().red(),Color().blue()})); % Red edge and blue fill


A line style and a layer can be added to the StyleProperties object, see :ref:`the dedicated page <sec-graphics-colors>` for more information.


Expand Down
Binary file modified doc/manual/manual/visualization/img/colormaps.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion doc/manual/tuto/cp_robotics/src/lesson_C.m
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@
obs{end+1} = yi;
end
end
t = t + 0.01;
t = t + 0.01; % for performance, it is advised to increment by steps of 0.1 instead
end
% [C-q5-end]

Expand Down
5 changes: 3 additions & 2 deletions examples/00_graphics/graphic_examples.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include <codac>
#include <filesystem>
#include <iostream>

using namespace std;
using namespace codac2;
Expand Down Expand Up @@ -98,7 +99,7 @@ int main(){

double subdivisions = 40.;
fig3.set_axes(axis(0,{-1,subdivisions+1}), axis(1,{-1.25,0.05}));
for (double i=0.; i<subdivisions; i+=1.0)
for (double i=0.; i<=subdivisions; i+=1.0)
{
double ratio = i/subdivisions;
fig3.draw_box({{i,i+1},{-1./5.,0}},{Color::black(),cmap_default.color(ratio)});
Expand All @@ -114,7 +115,7 @@ int main(){
fig4.set_window_properties({500,50},{500,500});
fig4.set_axes(axis(0,{-10,10}), axis(1,{-10,10}));

double a=0.5;
double a=0.8;
ScalarVar t;
// Fermat's spiral
AnalyticFunction f1 ({t},{a*sqrt(t)*cos(t),a*sqrt(t)*sin(t)});
Expand Down
Loading