-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.cpp
62 lines (44 loc) · 2.11 KB
/
main.cpp
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
#include <string>
#include <iostream>
#include <cmath>
#include <chrono>
#include <cairomm/cairomm.h>
#include <cairomm/context.h>
#include <cairomm/surface.h>
#include <cairomm/fontface.h>
#include "graph.hpp"
#include "heuristics.hpp"
int main(int argc, char **argv)
{
Mandoline::Graph polygon1 { Mandoline::Graph::Regular(20, 200.0) };
Mandoline::Graph polygon2 { Mandoline::Graph::Regular(20, 200.0) };
Mandoline::Graph polygon3 { Mandoline::Graph::Regular(20, 200.0) };
Eigen::Affine2d root = Eigen::Affine2d::Identity() * Eigen::Translation2d(720, 450);
Mandoline::Transform(polygon1, root * Eigen::Translation2d(100.0, 0.0)).Compute(polygon1);
Mandoline::Transform(polygon2, root * Eigen::Translation2d(-150.0, -150.0)).Compute(polygon2);
Mandoline::Transform(polygon3, root * Eigen::Translation2d(-100.0, 100.0)).Compute(polygon3);
Mandoline::Graph polygon_union;
Mandoline::Union(polygon1, polygon2).Compute(polygon_union);
Mandoline::Union(polygon_union, polygon3).Compute(polygon_union);
Mandoline::Graph polygon_slice;
Mandoline::Slice(polygon_union, 20.0).Compute(polygon_slice);
auto surface = Cairo::ImageSurface::create(Cairo::FORMAT_ARGB32, 1440, 900);
auto context = Cairo::Context::create(surface);
auto font = Cairo::ToyFontFace::create("Bitstream Charter", Cairo::FontSlant::FONT_SLANT_NORMAL, Cairo::FontWeight::FONT_WEIGHT_BOLD);
context->set_source_rgba(1.0, 1.0, 1.0, 1.0);
context->paint();
context->set_line_width(5.0);
int i = 0;
for (auto [vertex_a, vertex_b] : polygon_slice.Segments()) {
context->set_source_rgba(1.0, 0.0, 0.0, 1.0);
context->move_to(vertex_a.x(), vertex_a.y());
context->line_to(vertex_b.x(), vertex_b.y());
context->stroke();
Eigen::Vector2d v = (vertex_a + vertex_b) * 0.5 + Eigen::Hyperplane<double, 2>::Through(vertex_a, vertex_b).normal() * 10.0;
context->set_source_rgba(0.0, 0.0, 1.0, 1.0);
context->move_to(v.x(), v.y());
context->show_text(std::to_string(++i).c_str());
}
surface->write_to_png("slice.png");
return 0;
}