Skip to content

Commit 05da51c

Browse files
committed
Merge branch 'godardma-codac2_dev' into codac2_dev
2 parents fd4398b + ce16413 commit 05da51c

File tree

12 files changed

+265
-52
lines changed

12 files changed

+265
-52
lines changed

doc/manual/manual/visualization/figures.rst

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,101 @@
22

33
The Figure classes
44
==================
5+
6+
This page describes the classes used in Codac for 2D visualization.
7+
8+
.. _subsec-graphics-figures-graphical-outputs:
9+
10+
Graphical outputs
11+
-----------------
12+
13+
Two graphical outputs are currently supported in Codac: :ref:`VIBes <sec-graphics-vibes>` and :ref:`IPE <sec-graphics-ipe>`. VIBes is used for real-time
14+
visualization while IPE creates a file that can be edited by the IPE editor. These outputs are referenced by the enumeration GraphicOutput:
15+
16+
.. tabs::
17+
18+
.. code-tab:: py
19+
20+
GraphicOutput.VIBES # for VIBes
21+
GraphicOutput.IPE # for IPE
22+
GraphicOutput.VIBES | GraphicOutput.IPE # for both
23+
24+
.. code-tab:: c++
25+
26+
GraphicOutput::VIBES // for VIBes
27+
GraphicOutput::IPE // for IPE
28+
GraphicOutput::VIBES | GraphicOutput::IPE // for both
29+
30+
Note that for the VIBes output to work, the VIBes viewer must be launched before the program is run.
31+
32+
.. _subsec-graphics-figures-figure2d:
33+
34+
Figure2D
35+
--------
36+
37+
The basic class for 2D visualization is Figure2D. It is used to create a figure that can be displayed in VIBes or saved in an xml file for IPE.
38+
The constructor takes two arguments: the name of the figure and the graphical output. A boolean can be added to specify if the figure is to be used
39+
DefaultView (see :ref:`subsec-graphics-figures-figure2d-defaultview`).
40+
41+
.. tabs::
42+
43+
.. code-tab:: py
44+
45+
fig = Figure2D("My figure", GraphicOutput.VIBES | GraphicOutput.IPE)
46+
47+
.. code-tab:: c++
48+
49+
Figure2D figure ("My Figure",GraphicOutput::VIBES|GraphicOutput::IPE);
50+
51+
.. _subsec-graphics-figures-figure2d-defaultview:
52+
53+
DefaultView
54+
-----------
55+
56+
A DefaultView using only VIBes as graphical output is available. This figure is the one used by the function `draw_while_paving` by default.
57+
Any Figure2D object can be used as DefaultView with the set method:
58+
59+
.. tabs::
60+
61+
.. code-tab:: py
62+
63+
figure = Figure2D("My figure", GraphicOutput.VIBES | GraphicOutput.IPE)
64+
DefaultView.set(figure)
65+
66+
.. code-tab:: c++
67+
68+
std::shared_ptr<codac2::Figure2D> figure = std::make_shared<Figure2D>("My Figure",GraphicOutput::VIBES|GraphicOutput::IPE);
69+
DefaultView::set(figure);
70+
71+
Note that in C++ the figure must be a shared pointer in order to be passed to the `set` method.
72+
73+
Equivalently, a Figure2D can be used as DefaultView by setting the flag `set_as_default` to true in the constructor:
74+
75+
.. tabs::
76+
77+
.. code-tab:: py
78+
79+
fig = Figure2D("My figure", GraphicOutput.VIBES | GraphicOutput.IPE, True)
80+
81+
.. code-tab:: c++
82+
83+
Figure2D figure ("My Figure",GraphicOutput::VIBES|GraphicOutput::IPE,true);
84+
85+
.. _subsec-graphics-figures-figure2d-figure-properties:
86+
87+
Figure properties
88+
-----------------
89+
90+
Once created, the properties of a Figure2D object can be modified using the following methods:
91+
92+
.. tabs::
93+
94+
.. code-tab:: py
95+
96+
fig.set_window_properties([50,50],[500,500]) # set the window position and size
97+
fig.set_axes(axis(0,[-10,10]), axis(1,[-10,10])) # set the range of values on each axis : 0 for x-axis, 1 for y-axis
98+
99+
.. code-tab:: c++
100+
101+
fig.set_window_properties({50,50},{500,500}); // set the window position and size
102+
fig.set_axes(axis(0,{-10,10}), axis(1,{-10,10})); // set the range of values on each axis : 0 for x-axis, 1 for y-axis
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
.. _sec-graphics-functions:
2+
3+
Drawing functions
4+
=================
5+

doc/manual/manual/visualization/index.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,9 @@ Visualization
55

66
.. toctree::
77

8-
colors.rst
98
figures.rst
9+
functions.rst
10+
colors.rst
1011
vibes.rst
1112
ipe.rst
1213
3d_visualization.rst

examples/00_graphics/CMakeLists.txt

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# ==================================================================
2+
# codac / basics example - cmake configuration file
3+
# ==================================================================
4+
5+
cmake_minimum_required(VERSION 3.0.2)
6+
project(codac_example LANGUAGES CXX)
7+
8+
set(CMAKE_CXX_STANDARD 20)
9+
set(CMAKE_CXX_STANDARD_REQUIRED ON)
10+
11+
# Adding Codac
12+
13+
# In case you installed Codac in a local directory, you need
14+
# to specify its path with the CMAKE_PREFIX_PATH option.
15+
# set(CMAKE_PREFIX_PATH "~/codac/build_install")
16+
17+
find_package(CODAC REQUIRED)
18+
message(STATUS "Found Codac version ${CODAC_VERSION}")
19+
20+
# Initializating Ibex
21+
22+
ibex_init_common()
23+
24+
# Compilation
25+
26+
if(FAST_RELEASE)
27+
add_compile_definitions(FAST_RELEASE)
28+
message(STATUS "You are running Codac in fast release mode. (option -DCMAKE_BUILD_TYPE=Release is required)")
29+
endif()
30+
31+
add_executable(${PROJECT_NAME} graphic_examples.cpp)
32+
target_compile_options(${PROJECT_NAME} PUBLIC ${CODAC_CXX_FLAGS})
33+
target_include_directories(${PROJECT_NAME} SYSTEM PUBLIC ${CODAC_INCLUDE_DIRS})
34+
target_link_libraries(${PROJECT_NAME} PUBLIC ${CODAC_LIBRARIES})
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
#include <codac>
2+
3+
using namespace std;
4+
using namespace codac2;
5+
6+
int main(){
7+
8+
// Graphics can be directly called without a Figure2D instanciation, using "DefaultView"
9+
10+
DefaultView::set_window_properties({600,600},{300,300});
11+
DefaultView::draw_box({{2.2,2.5},{2.2,2.5}},{Color::black(),Color::yellow(0.5)});
12+
DefaultView::draw_AUV({1,1,3.14/2},1.,{Color::black(),Color::yellow()});
13+
DefaultView::draw_tank({2,1,3.14/2},1.,{Color::black(),Color::yellow()});
14+
DefaultView::draw_pie({2,2},{1.5,2.5},{(3*3.14/4)-0.5,(3*3.14/4)+0.5},{Color::blue(),Color::cyan()});
15+
DefaultView::draw_polyline({{2,-0.5},{4,0.5},{3,1.5},{4,2.5},{3,3}}, Color::red());
16+
DefaultView::draw_polygone({{2,4.5},{4,4.5},{4.2,3.5},{3.5,3}}, {Color::none(),Color::green(0.5)});
17+
DefaultView::draw_polyline({{-0.8,0},{0,1.5}}, 0.2, {Color::red(),Color::black(0.3)});
18+
19+
// Last argument corresponds to "StyleProperties" with one or two colors: edge color + (optional) fill color
20+
// Predefined Color objects can be configured with a float parameter for opacity (1=opaque, 0=transparent)
21+
22+
// Custom figures can also be created:
23+
std::shared_ptr<codac2::Figure2D> fig1 = std::make_shared<Figure2D>("My Figure 1",GraphicOutput::VIBES|GraphicOutput::IPE);
24+
25+
// Here, graphics will be rendered by two tools: both VIBES and IPE
26+
// For VIBES, it requires the VIBes viewer to be launched prior to the execution
27+
// For IPE, it generates a file named "My figure 1.xml" that can be edited with IPE, and converted to PDF
28+
29+
fig1->set_window_properties({50,50},{500,500}); // position, window size
30+
fig1->set_axes(axis(0,{-10,10}), axis(1,{-10,10})); // (axis_id,{range_of_values_on_this_axis})
31+
fig1->draw_box({{-1,1},{-1,1}},{Color::green(),Color::red(0.2)}); // drawing a green box with red opacity values inside
32+
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
33+
fig1->draw_ring({1,1},{4,6},Color::red()); // drawing a ring at (1,1) of radius {4,6} with a predefined red color
34+
35+
std::shared_ptr<codac2::Figure2D> fig2 = std::make_shared<Figure2D>("My Figure 2",GraphicOutput::VIBES|GraphicOutput::IPE);
36+
fig2->set_axes(axis(0,{-1,5}), axis(1,{-1,5}));
37+
fig2->set_window_properties({250,250},{500,500});
38+
39+
// The previously declared figure "fig2" can now be used as a DefaultView
40+
DefaultView::set(fig2);
41+
DefaultView::draw_box({{2.2,2.5},{2.2,2.5}},{Color::black(),Color::green(0.8)});
42+
43+
DefaultView::set(fig1);
44+
DefaultView::draw_box({{2.2,2.5},{2.2,2.5}},{Color::blue(),Color::cyan(0.8)});
45+
46+
fig2->draw_AUV({1,1,3.14/2},2.,{Color::black(),Color::yellow()});
47+
fig2->draw_tank({2,1,3.14/2},1.,{Color::black(),Color::yellow()});
48+
fig2->draw_pie({2,2},{1.5,2.5},{(3*3.14/4)-0.5,(3*3.14/4)+0.5},{Color::blue(),Color::cyan()});
49+
fig2->draw_polyline({{2,-0.5},{4,0.5},{3,1.5},{4,2.5},{3,3}}, Color::red());
50+
fig2->draw_polygone({{2,4.5},{4,4.5},{4.2,3.5},{3.5,3}}, {Color::none(),Color::green(0.5)});
51+
fig2->draw_polyline({{-0.8,0},{0,1.5}}, 0.2, {Color::red(),Color::black(0.3)});
52+
fig2->draw_ellipse({1,1},{0.5,2}, 0.2, {Color::blue(),Color::blue(0.3)});
53+
fig2->draw_line({1,1},{3,3}, Color::blue());
54+
fig2->draw_arrow({3,1},{2.2,2}, 0.2, {Color::red(),Color::black(0.3)});
55+
56+
// Colors
57+
// predefined colors without and with opacity
58+
fig2->draw_point({2,2}, {Color::red(),Color::yellow(0.5)});
59+
// HTML color without and with opacity
60+
fig2->draw_box({{2.4,2.9},{2.4,2.9}},{Color("#da3907"),Color("#da390755")});
61+
// HSV color without and with opacity
62+
fig2->draw_box({{2.6,3.1},{2.6,3.1}},{Color({108,90,78},Model::HSV),Color({108,90,78,20},Model::HSV)});
63+
64+
Figure2D fig3 ("My Figure 3",GraphicOutput::VIBES|GraphicOutput::IPE);
65+
fig3.set_axes(axis(0,{-1,21}), axis(1,{-5.5,0.5}));
66+
fig3.set_window_properties({800,250},{500,500});
67+
68+
ColorMap cmap_haxby = ColorMap::haxby();
69+
ColorMap cmap_default = ColorMap::basic();
70+
ColorMap cmap_blue_tube = ColorMap::blue_tube();
71+
ColorMap cmap_red_tube = ColorMap::red_tube();
72+
ColorMap cmap_rainbow = ColorMap::rainbow();
73+
74+
for (double i=0.; i<20; i++)
75+
{
76+
double ratio = i/20.;
77+
fig3.draw_box({{i,i+1},{-1,0}},{Color::black(),cmap_haxby.color(ratio)});
78+
fig3.draw_box({{i,i+1},{-2,-1}},{Color::black(),cmap_default.color(ratio)});
79+
fig3.draw_box({{i,i+1},{-3,-2}},{Color::black(),cmap_blue_tube.color(ratio)});
80+
fig3.draw_box({{i,i+1},{-4,-3}},{Color::black(),cmap_red_tube.color(ratio)});
81+
fig3.draw_box({{i,i+1},{-5,-4}},{Color::black(),cmap_rainbow.color(ratio)});
82+
}
83+
84+
Figure2D fig4 ("My Figure 4",GraphicOutput::VIBES);
85+
86+
fig4.set_axes(axis(0,{-10,10}), axis(1,{-10,10}));
87+
88+
double a=0.5;
89+
ScalarVar t;
90+
// Fermat's spiral
91+
AnalyticFunction f1 ({t},{a*sqrt(t)*cos(t),a*sqrt(t)*sin(t)});
92+
AnalyticTraj traj4 (f1,{0,100});
93+
fig4.draw_trajectory(traj4,ColorMap::rainbow());
94+
}

examples/00_graphics/graphic_examples.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -75,14 +75,14 @@
7575
fig3.draw_box([[i,i+1],[-4,-3]],[Color.black(),cmap_red_tube.color(ratio)])
7676
fig3.draw_box([[i,i+1],[-5,-4]],[Color.black(),cmap_rainbow.color(ratio)])
7777

78-
fig3 = Figure2D("My figure 3", GraphicOutput.VIBES)
78+
fig4 = Figure2D("My figure 4", GraphicOutput.VIBES)
7979

80-
fig3.set_window_properties([500,50],[500,500])
81-
fig3.set_axes(axis(0,[-10,10]), axis(1,[-10,10]))
80+
fig4.set_window_properties([500,50],[500,500])
81+
fig4.set_axes(axis(0,[-10,10]), axis(1,[-10,10]))
8282

8383
a = 0.8
8484
t=ScalarVar()
8585
# Fermat's spiral
8686
f1=AnalyticFunction([t], [a*sqrt(t)*cos(t),a*sqrt(t)*sin(t)])
87-
traj3=AnalyticTraj(f1, [0,100])
88-
fig3.draw_trajectory(traj3, ColorMap.rainbow())
87+
traj4=AnalyticTraj(f1, [0,100])
88+
fig4.draw_trajectory(traj4, ColorMap.rainbow())

examples/01_batman/CMakeLists.txt

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,6 @@
88
set(CMAKE_CXX_STANDARD 20)
99
set(CMAKE_CXX_STANDARD_REQUIRED ON)
1010

11-
# Adding IBEX
12-
13-
# In case you installed IBEX in a local directory, you need
14-
# to specify its path with the CMAKE_PREFIX_PATH option.
15-
# set(CMAKE_PREFIX_PATH "~/ibex-lib/build_install")
16-
17-
find_package(IBEX REQUIRED)
18-
ibex_init_common() # IBEX should have installed this function
19-
message(STATUS "Found IBEX version ${IBEX_VERSION}")
20-
2111
# Adding Codac
2212

2313
# In case you installed Codac in a local directory, you need
@@ -27,6 +17,10 @@
2717
find_package(CODAC REQUIRED)
2818
message(STATUS "Found Codac version ${CODAC_VERSION}")
2919

20+
# Initializating Ibex
21+
22+
ibex_init_common()
23+
3024
# Compilation
3125

3226
if(FAST_RELEASE)
@@ -37,4 +31,4 @@
3731
add_executable(${PROJECT_NAME} main.cpp)
3832
target_compile_options(${PROJECT_NAME} PUBLIC ${CODAC_CXX_FLAGS})
3933
target_include_directories(${PROJECT_NAME} SYSTEM PUBLIC ${CODAC_INCLUDE_DIRS})
40-
target_link_libraries(${PROJECT_NAME} PUBLIC ${CODAC_LIBRARIES} Ibex::ibex)
34+
target_link_libraries(${PROJECT_NAME} PUBLIC ${CODAC_LIBRARIES})

examples/02_centered_form/CMakeLists.txt

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,6 @@
88
set(CMAKE_CXX_STANDARD 20)
99
set(CMAKE_CXX_STANDARD_REQUIRED ON)
1010

11-
# Adding IBEX
12-
13-
# In case you installed IBEX in a local directory, you need
14-
# to specify its path with the CMAKE_PREFIX_PATH option.
15-
# set(CMAKE_PREFIX_PATH "~/ibex-lib/build_install")
16-
17-
find_package(IBEX REQUIRED)
18-
ibex_init_common() # IBEX should have installed this function
19-
message(STATUS "Found IBEX version ${IBEX_VERSION}")
20-
2111
# Adding Codac
2212

2313
# In case you installed Codac in a local directory, you need
@@ -27,6 +17,10 @@
2717
find_package(CODAC REQUIRED)
2818
message(STATUS "Found Codac version ${CODAC_VERSION}")
2919

20+
# Initializating Ibex
21+
22+
ibex_init_common()
23+
3024
# Compilation
3125

3226
if(FAST_RELEASE)
@@ -37,4 +31,4 @@
3731
add_executable(${PROJECT_NAME} main.cpp)
3832
target_compile_options(${PROJECT_NAME} PUBLIC ${CODAC_CXX_FLAGS})
3933
target_include_directories(${PROJECT_NAME} SYSTEM PUBLIC ${CODAC_INCLUDE_DIRS})
40-
target_link_libraries(${PROJECT_NAME} PUBLIC ${CODAC_LIBRARIES} Ibex::ibex)
34+
target_link_libraries(${PROJECT_NAME} PUBLIC ${CODAC_LIBRARIES})

examples/03_sivia/CMakeLists.txt

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,6 @@
88
set(CMAKE_CXX_STANDARD 20)
99
set(CMAKE_CXX_STANDARD_REQUIRED ON)
1010

11-
# Adding IBEX
12-
13-
# In case you installed IBEX in a local directory, you need
14-
# to specify its path with the CMAKE_PREFIX_PATH option.
15-
# set(CMAKE_PREFIX_PATH "~/ibex-lib/build_install")
16-
17-
find_package(IBEX REQUIRED)
18-
ibex_init_common() # IBEX should have installed this function
19-
message(STATUS "Found IBEX version ${IBEX_VERSION}")
20-
2111
# Adding Codac
2212

2313
# In case you installed Codac in a local directory, you need
@@ -27,6 +17,10 @@
2717
find_package(CODAC REQUIRED)
2818
message(STATUS "Found Codac version ${CODAC_VERSION}")
2919

20+
# Initializating Ibex
21+
22+
ibex_init_common()
23+
3024
# Compilation
3125

3226
if(FAST_RELEASE)
@@ -37,4 +31,4 @@
3731
add_executable(${PROJECT_NAME} main.cpp)
3832
target_compile_options(${PROJECT_NAME} PUBLIC ${CODAC_CXX_FLAGS})
3933
target_include_directories(${PROJECT_NAME} SYSTEM PUBLIC ${CODAC_INCLUDE_DIRS})
40-
target_link_libraries(${PROJECT_NAME} PUBLIC ${CODAC_LIBRARIES} Ibex::ibex)
34+
target_link_libraries(${PROJECT_NAME} PUBLIC ${CODAC_LIBRARIES})

0 commit comments

Comments
 (0)