diff --git a/doc/manual/manual/visualization/3d_visualization.rst b/doc/manual/manual/visualization/3d_visualization.rst index d9d632159..bfe22788b 100644 --- a/doc/manual/manual/visualization/3d_visualization.rst +++ b/doc/manual/manual/visualization/3d_visualization.rst @@ -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 ----------------- diff --git a/doc/manual/manual/visualization/colors.rst b/doc/manual/manual/visualization/colors.rst index 9cb20760f..c26802cc3 100644 --- a/doc/manual/manual/visualization/colors.rst +++ b/doc/manual/manual/visualization/colors.rst @@ -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 @@ -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. @@ -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 --------------- @@ -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. @@ -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`. @@ -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 ---------- @@ -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). @@ -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. @@ -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 @@ -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. @@ -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`. @@ -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 diff --git a/doc/manual/manual/visualization/figures.rst b/doc/manual/manual/visualization/figures.rst index d34442ca3..7142e7703 100644 --- a/doc/manual/manual/visualization/figures.rst +++ b/doc/manual/manual/visualization/figures.rst @@ -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: @@ -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 @@ -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 @@ -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:: @@ -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) diff --git a/doc/manual/manual/visualization/functions.rst b/doc/manual/manual/visualization/functions.rst index 90216a8b3..afa66ccc2 100644 --- a/doc/manual/manual/visualization/functions.rst +++ b/doc/manual/manual/visualization/functions.rst @@ -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 ` for more information. @@ -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 ` for more information. diff --git a/doc/manual/manual/visualization/img/colormaps.png b/doc/manual/manual/visualization/img/colormaps.png index 90efcd242..bc687b2d9 100644 Binary files a/doc/manual/manual/visualization/img/colormaps.png and b/doc/manual/manual/visualization/img/colormaps.png differ diff --git a/doc/manual/tuto/cp_robotics/src/lesson_C.m b/doc/manual/tuto/cp_robotics/src/lesson_C.m index 70a847d5b..21fd07526 100644 --- a/doc/manual/tuto/cp_robotics/src/lesson_C.m +++ b/doc/manual/tuto/cp_robotics/src/lesson_C.m @@ -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] diff --git a/examples/00_graphics/graphic_examples.cpp b/examples/00_graphics/graphic_examples.cpp index a64f7acf4..7c4fe8b07 100644 --- a/examples/00_graphics/graphic_examples.cpp +++ b/examples/00_graphics/graphic_examples.cpp @@ -1,5 +1,6 @@ #include #include +#include using namespace std; using namespace codac2; @@ -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()) .def_static("VIBES", [](){ return GraphicOutput::VIBES; }) .def_static("IPE", [](){ return GraphicOutput::IPE; }) - .def(py::self | py::self, GRAPHICOUTPUT_OPERATORUNION_GRAPHICOUTPUT_GRAPHICOUTPUT) + .def("union", [](GraphicOutput a, GraphicOutput b){ return a | b; }, + GRAPHICOUTPUT_OPERATORUNION_GRAPHICOUTPUT_GRAPHICOUTPUT, + "x"_a) ; } diff --git a/python/src/graphics/styles/codac2_py_Color.cpp b/python/src/graphics/styles/codac2_py_Color.cpp index 8bbfa409f..b177fc3c8 100644 --- a/python/src/graphics/styles/codac2_py_Color.cpp +++ b/python/src/graphics/styles/codac2_py_Color.cpp @@ -13,6 +13,7 @@ #include #include #include "codac2_py_Color_docs.h" // Generated file from Doxygen XML (doxygen2docstring.py): +#include "codac2_py_matlab.h" using namespace std; using namespace codac2; @@ -23,10 +24,23 @@ using namespace pybind11::literals; void export_Color(py::module& m) { - py::enum_(m, "Model") - .value("RGB", Model::RGB) - .value("HSV", Model::HSV) - ; + if constexpr(FOR_MATLAB) + { + py::class_(m, "Model") + .def(py::init<>()) + .def_static("RGB", [](){ return Model::RGB; }) + .def_static("HSV", [](){ return Model::HSV; }) + ; + } + + else + { + py::enum_(m, "Model") + .value("RGB", Model::RGB) + .value("HSV", Model::HSV) + ; + } + py::class_ exported_color(m, "Color", COLOR_MAIN); exported_color diff --git a/python/src/graphics/styles/codac2_py_ColorMap.cpp b/python/src/graphics/styles/codac2_py_ColorMap.cpp index 3dac81b40..cd5bc6c81 100644 --- a/python/src/graphics/styles/codac2_py_ColorMap.cpp +++ b/python/src/graphics/styles/codac2_py_ColorMap.cpp @@ -12,6 +12,7 @@ #include #include #include "codac2_py_ColorMap_docs.h" // Generated file from Doxygen XML (doxygen2docstring.py): +#include "codac2_py_matlab.h" using namespace std; using namespace codac2;