Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[graphics] draw_AUV and draw_tank for IPE #126

Open
wants to merge 5 commits into
base: codac2_dev
Choose a base branch
from
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
99 changes: 92 additions & 7 deletions src/graphics/3rd/ipe/codac2_Figure2D_IPE.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

#include <cstdio>
#include "codac2_Figure2D_IPE.h"
#include "codac2_math.h"

using namespace std;
using namespace codac2;
Expand Down Expand Up @@ -74,7 +75,7 @@ void Figure2D_IPE::center_viewbox(const Vector& c, const Vector& r)
assert(r.min_coeff() > 0.);
}

void Figure2D_IPE::begin_path(const StyleProperties& s)
void Figure2D_IPE::begin_path(const StyleProperties& s, bool tip=false)
{
// substr is needed to remove the "#" at the beginning of hex_str (deprecated by IPE)
_colors.emplace(s.stroke_color.hex_str.substr(1), s.stroke_color);
Expand All @@ -86,7 +87,32 @@ void Figure2D_IPE::begin_path(const StyleProperties& s)
fill=\"codac_color_" << s.fill_color.hex_str.substr(1) << "\" \n \
opacity=\"" << (int)(10*round(10.*s.fill_color.alpha)) << "%\" \n \
stroke-opacity=\"" << (int)(10*round(10.*s.stroke_color.alpha)) << "%\" \n \
pen=\"normal\"> \n ";
pen=\"normal\"";
if (tip)
_f_temp_content << "\n \
arrow=\"normal/normal\"";
_f_temp_content << "> \n";
}

void Figure2D_IPE::begin_path_with_matrix(const Vector& x, float length, const StyleProperties& s)
{
// substr is needed to remove the "#" at the beginning of hex_str (deprecated by IPE)
_colors.emplace(s.stroke_color.hex_str.substr(1), s.stroke_color);
_colors.emplace(s.fill_color.hex_str.substr(1), s.fill_color);

_f_temp_content << "\n \
<path layer=\"alpha\" \n \
stroke=\"codac_color_" << s.stroke_color.hex_str.substr(1) << "\" \n \
fill=\"codac_color_" << s.fill_color.hex_str.substr(1) << "\" \n \
opacity=\"" << (int)(10*round(10.*s.fill_color.alpha)) << "%\" \n \
stroke-opacity=\"" << (int)(10*round(10.*s.stroke_color.alpha)) << "%\" \n \
pen=\"normal\" \n \
matrix=";

// Matrix is composed of the 4 components of the 2D transformation matrix and the translation vector
_f_temp_content << "\"" << scale_length(length) * cos(x[j()+1]).mid() << " " << scale_length(length) * sin(x[j()+1]).mid() << " "
<< - scale_length(length) * sin(x[j()+1]).mid() << " " << scale_length(length) * cos(x[j()+1]).mid() << " "
<< scale_x(x[i()]) << " " << scale_y(x[j()]) << "\">\n";
}

void Figure2D_IPE::draw_point(const Vector& c, const StyleProperties& s)
Expand All @@ -103,7 +129,7 @@ void Figure2D_IPE::draw_point(const Vector& c, const StyleProperties& s)
fill=\"codac_color_" << s.fill_color.hex_str.substr(1) << "\" \n \
opacity=\"" << (int)(10*round(10.*s.fill_color.alpha)) << "%\" \n \
stroke-opacity=\"" << (int)(10*round(10.*s.stroke_color.alpha)) << "%\" \n \
size=\"normal\"/>";
size=\"normal\"\n/>";
}

void Figure2D_IPE::draw_box(const IntervalVector& x, const StyleProperties& s)
Expand Down Expand Up @@ -144,9 +170,8 @@ void Figure2D_IPE::draw_polyline(const std::vector<Vector>& x, float tip_length,
{
assert(x.size() > 1);
assert(tip_length >= 0.);
// todo: draw tip

begin_path(s);
begin_path(s, tip_length>2e-3*_fig.scaled_unit());

for(size_t k = 0 ; k < x.size() ; k++)
{
Expand Down Expand Up @@ -181,15 +206,75 @@ void Figure2D_IPE::draw_tank(const Vector& x, float size, const StyleProperties&
assert(_fig.size() <= x.size()+1);
assert(j()+1 < x.size());
assert(size >= 0.);
// Not implemented yet

float length=size/4.0; // from VIBes : initial vehicle's length is 4

begin_path_with_matrix(x,length,s);

// Body
_f_temp_content << 1 << " " << -1.5 << " m \n";
_f_temp_content << -1 << " " << -1.5 << " l \n";
_f_temp_content << 0 << " " << -1.5 << " l \n";
_f_temp_content << 0 << " " << -1 << " l \n";
_f_temp_content << -1 << " " << -1 << " l \n";
_f_temp_content << -1 << " " << 1 << " l \n";
_f_temp_content << 0 << " " << 1 << " l \n";
_f_temp_content << 0 << " " << 1.5 << " l \n";
_f_temp_content << -1 << " " << 1.5 << " l \n";
_f_temp_content << 1 << " " << 1.5 << " l \n";
_f_temp_content << 0 << " " << 1.5 << " l \n";
_f_temp_content << 0 << " " << 1 << " l \n";
_f_temp_content << 3 << " " << 0.5 << " l \n";
_f_temp_content << 3 << " " << -0.5 << " l \n";
_f_temp_content << 0 << " " << -1 << " l \n";
_f_temp_content << 0 << " " << -1.5 << " l \n";

_f_temp_content << "</path>";
}

void Figure2D_IPE::draw_AUV(const Vector& x, float size, const StyleProperties& s)
{
assert(_fig.size() <= x.size()+1);
assert(j()+1 < x.size());
assert(size >= 0.);
// Not implemented yet

float length=size/7.0; // from VIBes : initial vehicle's length is 7

_f_temp_content<<"\n<group>\n";

// Body

begin_path_with_matrix(x,length,s);

_f_temp_content << -4 << " " << 0 << " m \n";
_f_temp_content << -2 << " " << 1 << " l \n";
_f_temp_content << 2 << " " << 1 << " l \n";

for (float i = 90.; i > -90.; i -= 10.)
_f_temp_content << cos(i * codac2::pi / 180.).mid() + 2.0 << " "
<< sin(i * codac2::pi / 180.).mid() + 0.0 << " l \n";

_f_temp_content << 2 << " " << -1 << " l \n";
_f_temp_content << -2 << " " << -1 << " l \n";
_f_temp_content << -4 << " " << 0 << " l \n";

_f_temp_content << "</path>\n";

// Propulsion unit

begin_path_with_matrix(x,length,s);

_f_temp_content << -4 << " " << 1 << " m \n";
_f_temp_content << -3.25 << " " << 1 << " l \n";
_f_temp_content << -3.25 << " " << -1 << " l \n";
_f_temp_content << -4 << " " << -1 << " l \n";
_f_temp_content << -4 << " " << 1 << " l \n";

_f_temp_content << "</path>\n";

_f_temp_content<<"</group>";


}

double Figure2D_IPE::scale_x(double x) const
Expand Down
3 changes: 2 additions & 1 deletion src/graphics/3rd/ipe/codac2_Figure2D_IPE.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ namespace codac2
void update_axes();
void update_window_properties();
void center_viewbox(const Vector& c, const Vector& r);
void begin_path(const StyleProperties& s);
void begin_path(const StyleProperties& s,bool tip);
void begin_path_with_matrix(const Vector& x, float length, const StyleProperties& s);

// Geometric shapes
void draw_point(const Vector& c, const StyleProperties& s = StyleProperties());
Expand Down
Loading