Skip to content

Commit a0f4ae0

Browse files
committed
[doc] correction on figures
1 parent a521be0 commit a0f4ae0

File tree

3 files changed

+78
-1
lines changed

3 files changed

+78
-1
lines changed

doc/manual/manual/visualization/figures.rst

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,9 +74,11 @@ Any Figure2D object can be used as DefaultView with the set method:
7474

7575
.. code-tab:: c++
7676

77-
Figure2D figure = std::make_shared<Figure2D>("My Figure",GraphicOutput::VIBES|GraphicOutput::IPE);
77+
std::shared_ptr<codac2::Figure2D> figure = std::make_shared<Figure2D>("My Figure",GraphicOutput::VIBES|GraphicOutput::IPE);
7878
DefaultView::set(figure);
7979

80+
Note that in C++ the figure must be a shared pointer in order to be passed to the `set` method.
81+
8082
Equivalently, a Figure2D can be used as DefaultView by setting the flag `set_as_default` to true in the constructor:
8183

8284
.. tabs::
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: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
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+
}

0 commit comments

Comments
 (0)