-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathBezierPath.cpp
More file actions
69 lines (54 loc) · 2.16 KB
/
BezierPath.cpp
File metadata and controls
69 lines (54 loc) · 2.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
/**
* @file BezierPath.cpp
*
* @date 2019-08-04
*
* Copyright (c) organization
*
*/
#include <algorithm>
#include <cmath>
#include <iostream>
#include <vector>
#include <matplotlib_cpp/MatplotlibCpp.hpp>
enum MPL_PATH { STOP = 0, MOVETO = 1, LINETO = 2, CURVE3 = 3, CURVE4 = 4, CLOSEPOLY = 5 };
int main(int argc, char* argv[])
{
pe::vis::Matplotlib mpllib;
if (!mpllib.imported()) {
std::cout << "Failed to import matplotlib library\n";
exit(EXIT_FAILURE);
}
mpllib.axes(8, 4);
std::vector<std::array<double, 2>> vertices = {{0., 0.}, {0.2, 1.}, {1., 0.8}, {0.8, 0.}};
std::vector<int> codes = {MOVETO, CURVE4, CURVE4, CURVE4};
mpllib.add_patch(vertices, codes,
{
{"facecolor", pe::vis::Matplotlib::createAnyBaseMapData<std::string>("none")},
{"lw", pe::vis::Matplotlib::createAnyBaseMapData<int>(2)},
});
std::vector<double> xs, ys;
xs.reserve(vertices.size());
ys.reserve(vertices.size());
std::transform(vertices.cbegin(), vertices.cend(), std::back_inserter(xs),
[](const std::array<double, 2>& p) { return p[0]; });
std::transform(vertices.cbegin(), vertices.cend(), std::back_inserter(ys),
[](const std::array<double, 2>& p) { return p[1]; });
mpllib.plotAxes(xs, ys,
{
{"marker", pe::vis::Matplotlib::createAnyBaseMapData<std::string>("x")},
{"linestyle", pe::vis::Matplotlib::createAnyBaseMapData<std::string>("--")},
{"color", pe::vis::Matplotlib::createAnyBaseMapData<std::string>("black")},
{"lw", pe::vis::Matplotlib::createAnyBaseMapData<int>(2)},
{"ms", pe::vis::Matplotlib::createAnyBaseMapData<int>(10)},
});
mpllib.textAxes(-0.05, -0.05, "P0");
mpllib.textAxes(0.15, 1.05, "P");
mpllib.textAxes(1.05, 0.85, "P2");
mpllib.textAxes(0.85, -0.05, "P3");
mpllib.set_xlimAxes(-0.1, 1.1);
mpllib.set_ylimAxes(-0.1, 1.1);
mpllib.savefig("BezierPath");
mpllib.show();
return 0;
}