-
Notifications
You must be signed in to change notification settings - Fork 0
/
Skeleton.cpp
62 lines (53 loc) · 2.04 KB
/
Skeleton.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 "Skeleton.hpp"
#include "GeometryUtils.hpp"
#include <CGAL/Mean_curvature_flow_skeletonization.h>
#include <algorithm>
///////////////////////////////////////////////////////////////////////////////////////
// Constructs the skeleton using mean curvature flow.
///////////////////////////////////////////////////////////////////////////////////////
Skeleton3* construct_skeleton(const Polyhedron3* P, double quality_factor)
{
Skeleton3* S = new Skeleton3();
CGAL::Mean_curvature_flow_skeletonization<Polyhedron3> skeletonizer(*P);
// Default values:
// max triangle angle = 110 degrees
// min edge length = 0.002 * diagonal of bounding box
// max iterations = 500
// area variation factor = 0.0001
// quality speed tradeoff = 0.1 - larger values result in high quality skeletons
// is medially centered = true
// medially centered speed tradeoff = 0.2 - larger value is more accurate to medial but not as smooth or fast
skeletonizer.set_quality_speed_tradeoff(quality_factor);
skeletonizer.contract_until_convergence();
skeletonizer.convert_to_skeleton(*S);
return S;
}
///////////////////////////////////////////////////////////////////////////////////////
// Other skeleton utilties.
///////////////////////////////////////////////////////////////////////////////////////
struct Output_polylines {
const Skeleton3& skeleton;
std::ofstream& out;
int polyline_size;
std::stringstream sstr;
Output_polylines(const Skeleton3& skeleton, std::ofstream& out)
: skeleton(skeleton), out(out)
{}
void start_new_polyline()
{
polyline_size = 0;
sstr.str("");
sstr.clear();
}
void add_node(Skeleton3::vertex_descriptor v)
{
++polyline_size;
sstr << " " << skeleton[v].point;
}
void end_polyline() { out << polyline_size << sstr.str() << std::endl; }
};
void write_skeleton(const Skeleton3* S, std::ofstream& output)
{
Output_polylines outputter(*S, output);
CGAL::split_graph_into_polylines(*S, outputter);
}