-
Notifications
You must be signed in to change notification settings - Fork 11
/
svVoronoiCore.h
117 lines (93 loc) · 3.57 KB
/
svVoronoiCore.h
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
//
// svVoronoiCore.h
// SphericalVoronoi
//
// Created by Xiang Wei on 2014-05-03.
// Copyright (c) 2014 whenitsdone.org. All rights reserved.
//
#ifndef SphericalVoronoi_svvoronoi_h
#define SphericalVoronoi_svvoronoi_h
#include "svMath.h"
#include "svData.h"
namespace sv
{
class SphericalVoronoiCore
{
public:
SphericalVoronoiCore(const std::vector<Real3>& directions);
void setDebugMode(bool debugMode) { this->debugMode = debugMode; }
bool isFinished() const;
void step(Real maxDeltaXi);
void solve(std::function<void(int)> cb = nullptr); // step until finished
const std::vector<half_edge_ptr>& getHalfEdges() const { return halfEdges; }
const std::vector<vertex_ptr>& getVertices() const { return vertices; }
const std::vector<cell_ptr>& getCells() const { return cells; }
protected:
bool debugMode;
void dumpBeachState(std::ostream& stream);
void finializeGraph();
void cleanupMiddleVertices();
void duplicateHalfEdges();
void bindHalfEdgesToCells();
beach_type::const_iterator getPrevArcOnBeach(beach_type::const_iterator it) const
{
if (it != beach.begin())
{
return std::prev(it);
}
else
{
return std::prev(beach.end());
}
}
beach_type::const_iterator getNextArcOnBeach(beach_type::const_iterator it) const
{
auto next = std::next(it);
if (next == beach.end())
{
next = beach.begin();
}
return next;
}
bool intersectWithNextArc(beach_type::const_iterator itArc, Real xi, Point& oPoint) const;
bool intersectWithPrevArc(beach_type::const_iterator itArc, Real xi, Point& oPoint) const;
void handleSiteEvent(site_event& event);
void handleCircleEvent(const circle_event_ptr& event);
static Point thetaToPoint(Real theta, bool positive, Real xi, Real theta1, Real phi1);
static Point phiToPoint(Real phi, Real xi, Real theta1, Real phi1);
static bool arcsIntersection(const beach_arc& arc1, const beach_arc& arc2, Real xi, Point& oPoint);
int nbSteps;
SphericalLine scanLine;
constexpr static Real eps = 1e-5;
std::vector<half_edge_ptr> halfEdges;
std::vector<vertex_ptr> vertices;
std::vector<cell_ptr> cells;
beach_type beach;
bool isArcOnBeach(const beach_arc_ptr& arc) const
{
return find(beach.begin(), beach.end(), arc) != beach.end();
}
std::vector<site_event> siteEventQueue;
std::vector<circle_event_ptr> circleEventQueue;
void addNewSiteEvent(const site_event& event)
{
using namespace std;
auto it = lower_bound(siteEventQueue.begin(), siteEventQueue.end(), event);
siteEventQueue.insert(it, event);
}
void addNewCircleEvent(const std::shared_ptr<circle_event>& event)
{
using namespace std;
auto it = lower_bound(circleEventQueue.begin(), circleEventQueue.end(), event, compare_circle_event_priority());
circleEventQueue.insert(it, event);
}
void removeCircleEvent(const std::shared_ptr<circle_event>& event)
{
using namespace std;
auto it = find(circleEventQueue.begin(), circleEventQueue.end(), event);
assert(it != circleEventQueue.end());
circleEventQueue.erase(it);
}
};
}
#endif