-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtriangle.h
More file actions
132 lines (111 loc) · 3.77 KB
/
triangle.h
File metadata and controls
132 lines (111 loc) · 3.77 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
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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
#ifndef PDLN_TRIANGLE_H
#define PDLN_TRIANGLE_H
#include "common_utils.h"
#ifdef OPENCV
#include "opencv2/opencv.hpp"
#endif
class Triangle;
class Triangle_inline;
class Triangle_withBound;
struct Bound {
double min_x;
double max_x;
double min_y;
double max_y;
};
class Point
{
public:
double x;
double y;
int id;
int next;
int prev;
Point();
Point(double, double);
Point(double, double, int, int = -1, int = -1);
~Point();
double calculate_distance(const Point*) const;
double calculate_distance(double, double) const;
int position_to_edge(const Point*, const Point*) const;
int position_to_edge(double, double, double, double) const;
int position_to_triangle(const Point*, const Point*, const Point*) const;
int position_to_triangle(const Triangle_inline*) const;
int position_to_triangle(Triangle_withBound*) const;
int is_in_region(double min_x, double max_x, double min_y, double max_y) const;
};
class Edge
{
private:
int head;
int tail; /* the tail of this edge, constant */
Edge* twin_edge; /* the twin_edge edge, whose tail is the head of this edge and head is the tail of this edge */
Edge* next_edge_in_triangle; /* the next_edge_in_triangle edge, whose tail is the head of this edge but head isn't the tail of this edge */
Edge* prev_edge_in_triangle; /* the prev_edge_in_triangle edge, whose head is the tail of this edge but tail isn't the head of this edge */
int ref_count;
Triangle* triangle; /* the triangle which is composed by this edge and its next_edge_in_triangle and prev_edge_in_triangle */
public:
Edge();
~Edge();
Edge *generate_twins_edge();
inline void ref_inc() {ref_count++;};
#ifdef OPENCV
friend void draw_line(cv::Mat, Edge*, double, double, double, double, cv::Scalar);
#endif
friend class Triangle;
friend class Delaunay_Voronoi;
};
class Triangle
{
private:
int v[3]; /* index of vertexes */
Edge* edge[3];
unsigned is_leaf:1;
unsigned is_cyclic:1;
unsigned is_virtual:1;
int remained_points_head;
int remained_points_tail;
double circum_center[2];
double circum_radius;
int stack_ref_count;
int circum_circle_contains(Point*, Point*, double tolerance=PDLN_ABS_TOLERANCE);
bool really_on_circum_circle(Point*, Point*, double);
public:
Triangle();
~Triangle();
void get_center_coordinates();
int find_best_candidate_point(Point*) const;
bool contain_vertex(int);
void calulate_circum_circle(const Point*, const Point*, const Point*);
int find_dividing_point(Point*);
void set_remained_points(int, int);
int pop_tail(Point*);
friend class Delaunay_Voronoi;
friend class Point;
friend void plot_triangles_into_file(const char *filename, std::vector<Triangle*>, Point*);
friend class Triangle_pool;
};
class Triangle_inline
{
public:
Point v[3];
bool is_cyclic;
Triangle_inline() {};
Triangle_inline(Point, Point, Point, bool = false);
void check_cyclic();
friend bool operator == (Triangle_inline, Triangle_inline);
};
class Triangle_withBound
{
public:
double v_x[3];
double v_y[3];
double min_x;
double max_x;
double min_y;
double max_y;
int index_in_vector;
Triangle_withBound() {};
void make_from_triangle(double, double, double, double, double, double, Bound*, unsigned);
};
#endif