Xmipp  v3.23.11-Nereus
dcel.h
Go to the documentation of this file.
1 #ifndef DCEL_H
2 #define DCEL_H
3 
4 #include "point.h"
5 #include "stack.h"
6 #include <stdio.h>
7 
8 
9 /**************************************************************************
10 * Defines
11 **************************************************************************/
12 #define EXTERNAL_FACE 0
13 
14 #define POINTS_TYPE 1
15 #define DCEL_TYPE 2
16 
17 #define NO_UPDATE -1
18 
19 #define CONVEX_HULL_LEN_FACTOR 1
20 
21 /**************************************************************************
22 * Data types definition
23 **************************************************************************/
27 
28 
30 {
32  struct Point_T vertex;
33 };
34 
36 {
38  int twin_Edge;
40  int next_Edge;
41  int face;
42 };
43 
45 {
46  int edge;
48 };
49 
50 struct DCEL_T
51 {
53 
54  // Vertex data.
55  int nVertex;
58 
59  // Edges data.
60  int nEdges;
61  int sizeEdges;
63  struct Dcel_Edge_T *edges;
64 
65  // Vertex data.
66  int nFaces;
67  int sizeFaces;
68  struct Dcel_Face_T *faces;
69 };
70 
71 
72 /**************************************************************************
73 * Public function headers.
74 **************************************************************************/
75 // General DCEL interface.
76 int initialize_DCEL( struct DCEL_T *dcel, int nPoints, int nEdges, int nFaces);
77 void reset_DCEL( struct DCEL_T *dcel);
78 void copy_Dcel( struct DCEL_T *in_dcel, struct DCEL_T *out_dcel);
79 int resize_DCEL( struct DCEL_T *dcel, enum Resize_DCEL_T resize_Type);
80 void check_DCEL_Data( struct DCEL_T *dcel);
81 void shake_Points_DCEL( struct DCEL_T *dcel);
82 void finalize_DCEL( struct DCEL_T *dcel);
83 
84 // Vertexes interface.
85 int get_Number_Vertex( struct DCEL_T *dcel);
86 int insertPoint( struct DCEL_T *dcel, struct Point_T *point);
87 int insertVertex( struct DCEL_T *dcel, struct Dcel_Vertex_T vertex);
88 int insert_Vertex_At( struct DCEL_T *dcel, struct Dcel_Vertex_T vertex, int index);
89 int update_Vertex_Edge_At( struct DCEL_T *dcel, int edge_ID, int index);
90 int swap_Vertex( struct DCEL_T *dcel, int index1, int index2);
91 struct Dcel_Vertex_T *get_Vertex( struct DCEL_T *dcel, int index);
92 struct Point_T *get_Vertex_Point( struct DCEL_T *dcel, int index);
93 
94 // Edges interface.
95 int get_Number_Edges( struct DCEL_T *dcel);
96 int get_Number_Real_Edges( struct DCEL_T *dcel);
97 int insertEdge( struct DCEL_T *dcel, int origin, int twin, int prev, int next, int face);
98 int update_Edge( struct DCEL_T *dcel, int origin, int twin, int prev, int next, int face, int index);
99 int are_Twins( struct DCEL_T *dcel, struct Dcel_Edge_T *edge1, struct Dcel_Edge_T *edge2);
100 int is_External_Edge( struct DCEL_T *dcel, int index);
101 int set_Edge_Not_Checked( struct DCEL_T *dcel, int index, int *n);
102 int get_Edge_Origin_Vertex( struct DCEL_T *dcel, int edge_Index);
103 int get_Edge_In_Convex_Hull( struct DCEL_T *dcel, int faceID);
104 struct Dcel_Edge_T *get_Edge( struct DCEL_T *dcel, int index);
105 int copy_Edge( struct DCEL_T *dcel, int index, struct Dcel_Edge_T *edge);
106 
107 // Faces interface.
108 int get_Number_Faces(struct DCEL_T *dcel);
109 int get_Number_Real_Faces(struct DCEL_T *dcel);
110 int insertFace( struct DCEL_T *dcel, int edge_ID);
111 int update_Face(struct DCEL_T *dcel, int edge_ID, int index);
112 struct Dcel_Face_T *get_Face( struct DCEL_T *dcel, int index);
113 int get_Face_Vertex( struct DCEL_T *dcel, int face_ID, struct Dcel_Vertex_T *v1,
114  struct Dcel_Vertex_T *v2, struct Dcel_Vertex_T *v3);
115 int is_Negative_Any_Vertex( struct DCEL_T *dcel, int edge_Index);
116 void printFace( struct DCEL_T *dcel, int faceID);
117 
118 // Points interface.
119 enum Turn_T return_Turn( struct DCEL_T *dcel, struct Point_T *p,
120  int source_ID,
121  int dest_ID);
122 void shake_Dcel( struct DCEL_T *dcel);
123 void get_Extreme_Point( struct DCEL_T *dcel, int (*f)(struct Point_T *, struct Point_T *),
124  struct Point_T *p);
125 void get_Vertex_Of_Face( struct DCEL_T *dcel, int face, int *index1, int *index2, int *index3);
126 bool is_Interior_To_Face( struct DCEL_T *dcel, struct Point_T *p, int face);
127 
128 // Figures interface.
129 bool get_Convex_Hull( struct DCEL_T *dcel, int *length, int *edges);
130 bool is_Interior_To_Convex_Hull( struct DCEL_T *dcel, struct Point_T *p, bool *error);
131 
132 // I/O DCEL interface.
133 int read_DCEL( struct DCEL_T *dcel, char *fileName);
134 int read_Points_Flat_File( struct DCEL_T *dcel, const char *fileName);
135 int write_DCEL( struct DCEL_T *dcel, int type, const char *fileName);
136 void print_DCEL( struct DCEL_T *dcel);
137 int read_Points_DCEL( FILE *fd, int nPoints, struct DCEL_T *dcel);
138 void generate_Random_Points_DCEL( int nPoints, struct DCEL_T *dcel, TYPE maxX, TYPE maxY);
139 void generate_Cluster_Points_DCEL( int nPoints, struct DCEL_T *dcel,
140  int nClusters, int radius, TYPE maxX, TYPE maxY);
141 
142 #define DCEL_STATISTICS
143 #ifdef DCEL_STATISTICS
144 void print_Dcel_Statistics( char *fileName, struct DCEL_T *dcel);
145 #endif
146 
147 #endif
bool get_Convex_Hull(struct DCEL_T *dcel, int *length, int *edges)
Definition: dcel.cpp:1910
void print_Dcel_Statistics(char *fileName, struct DCEL_T *dcel)
Definition: dcel.cpp:2378
int twin_Edge
Definition: dcel.h:38
int get_Number_Vertex(struct DCEL_T *dcel)
Definition: dcel.cpp:638
void generate_Random_Points_DCEL(int nPoints, struct DCEL_T *dcel, TYPE maxX, TYPE maxY)
Definition: dcel.cpp:2187
int edge
Definition: dcel.h:46
int resize_DCEL(struct DCEL_T *dcel, enum Resize_DCEL_T resize_Type)
Definition: dcel.cpp:471
int origin_Vertex
Definition: dcel.h:37
void check_DCEL_Data(struct DCEL_T *dcel)
Definition: dcel.cpp:578
int update_Edge(struct DCEL_T *dcel, int origin, int twin, int prev, int next, int face, int index)
Definition: dcel.cpp:1060
Definition: point.h:12
void shake_Points_DCEL(struct DCEL_T *dcel)
Definition: dcel.cpp:2445
int sizeVertex
Definition: dcel.h:56
Turn_T
Definition: point.h:10
Definition: dcel.h:50
struct Dcel_Face_T * get_Face(struct DCEL_T *dcel, int index)
Definition: dcel.cpp:1479
Resize_DCEL_T
Definition: dcel.h:24
int read_Points_DCEL(FILE *fd, int nPoints, struct DCEL_T *dcel)
Definition: dcel.cpp:2100
int insertPoint(struct DCEL_T *dcel, struct Point_T *point)
Definition: dcel.cpp:656
void print_DCEL(struct DCEL_T *dcel)
Definition: dcel.cpp:386
void printFace(struct DCEL_T *dcel, int faceID)
Definition: dcel.cpp:1719
int are_Twins(struct DCEL_T *dcel, struct Dcel_Edge_T *edge1, struct Dcel_Edge_T *edge2)
Definition: dcel.cpp:1137
int swap_Vertex(struct DCEL_T *dcel, int index1, int index2)
Definition: dcel.cpp:838
int previous_Edge
Definition: dcel.h:39
int get_Number_Real_Faces(struct DCEL_T *dcel)
Definition: dcel.cpp:1568
void get_Extreme_Point(struct DCEL_T *dcel, int(*f)(struct Point_T *, struct Point_T *), struct Point_T *p)
Definition: dcel.cpp:1855
void generate_Cluster_Points_DCEL(int nPoints, struct DCEL_T *dcel, int nClusters, int radius, TYPE maxX, TYPE maxY)
Definition: dcel.cpp:2250
int update_Face(struct DCEL_T *dcel, int edge_ID, int index)
Definition: dcel.cpp:1428
struct Dcel_Edge_T * get_Edge(struct DCEL_T *dcel, int index)
Definition: dcel.cpp:1287
int write_DCEL(struct DCEL_T *dcel, int type, const char *fileName)
Definition: dcel.cpp:301
#define TYPE
Definition: defines.h:47
int get_Number_Faces(struct DCEL_T *dcel)
Definition: dcel.cpp:1360
double v1
struct Point_T * get_Vertex_Point(struct DCEL_T *dcel, int index)
Definition: dcel.cpp:917
int get_Edge_Origin_Vertex(struct DCEL_T *dcel, int edge_Index)
Definition: dcel.cpp:1218
viol index
viol type
bool is_Interior_To_Convex_Hull(struct DCEL_T *dcel, struct Point_T *p, bool *error)
Definition: dcel.cpp:2018
int nEdges
Definition: dcel.h:60
int next_Edge
Definition: dcel.h:40
void copy_Dcel(struct DCEL_T *in_dcel, struct DCEL_T *out_dcel)
Definition: dcel.cpp:443
struct Dcel_Vertex_T * get_Vertex(struct DCEL_T *dcel, int index)
Definition: dcel.cpp:882
struct Dcel_Edge_T * edges
Definition: dcel.h:63
double * f
int insertFace(struct DCEL_T *dcel, int edge_ID)
Definition: dcel.cpp:1376
int read_DCEL(struct DCEL_T *dcel, char *fileName)
Definition: dcel.cpp:95
int is_External_Edge(struct DCEL_T *dcel, int index)
Definition: dcel.cpp:1175
int * edgeChecked
Definition: dcel.h:62
int get_Number_Edges(struct DCEL_T *dcel)
Definition: dcel.cpp:950
int copy_Edge(struct DCEL_T *dcel, int index, struct Dcel_Edge_T *edge)
Definition: dcel.cpp:1320
__host__ __device__ float length(float2 v)
int sizeFaces
Definition: dcel.h:67
int get_Number_Real_Edges(struct DCEL_T *dcel)
Definition: dcel.cpp:965
int get_Face_Vertex(struct DCEL_T *dcel, int face_ID, struct Dcel_Vertex_T *v1, struct Dcel_Vertex_T *v2, struct Dcel_Vertex_T *v3)
Definition: dcel.cpp:1513
int insertVertex(struct DCEL_T *dcel, struct Dcel_Vertex_T vertex)
Definition: dcel.cpp:707
int insert_Vertex_At(struct DCEL_T *dcel, struct Dcel_Vertex_T vertex, int index)
Definition: dcel.cpp:757
int get_Edge_In_Convex_Hull(struct DCEL_T *dcel, int faceID)
Definition: dcel.cpp:1242
struct Dcel_Vertex_T * vertex
Definition: dcel.h:57
void finalize_DCEL(struct DCEL_T *dcel)
Definition: dcel.cpp:595
enum Turn_T return_Turn(struct DCEL_T *dcel, struct Point_T *p, int source_ID, int dest_ID)
Definition: dcel.cpp:1736
struct Point_T vertex
Definition: dcel.h:32
int origin_Edge
Definition: dcel.h:31
int nVertex
Definition: dcel.h:55
int insertEdge(struct DCEL_T *dcel, int origin, int twin, int prev, int next, int face)
Definition: dcel.cpp:998
void get_Vertex_Of_Face(struct DCEL_T *dcel, int face, int *index1, int *index2, int *index3)
Definition: dcel.cpp:1603
int set_Edge_Not_Checked(struct DCEL_T *dcel, int index, int *n)
Definition: dcel.cpp:2554
int nFaces
Definition: dcel.h:66
int is_Negative_Any_Vertex(struct DCEL_T *dcel, int edge_Index)
Definition: dcel.cpp:1676
bool incremental
Definition: dcel.h:52
bool is_Interior_To_Face(struct DCEL_T *dcel, struct Point_T *p, int face)
Definition: dcel.cpp:1628
void reset_DCEL(struct DCEL_T *dcel)
Definition: dcel.cpp:427
int sizeEdges
Definition: dcel.h:61
int imaginaryFace
Definition: dcel.h:47
void shake_Dcel(struct DCEL_T *dcel)
Definition: dcel.cpp:1842
struct Dcel_Face_T * faces
Definition: dcel.h:68
int * n
int read_Points_Flat_File(struct DCEL_T *dcel, const char *fileName)
Definition: dcel.cpp:239
int initialize_DCEL(struct DCEL_T *dcel, int nPoints, int nEdges, int nFaces)
Definition: dcel.cpp:32
int face
Definition: dcel.h:41
int update_Vertex_Edge_At(struct DCEL_T *dcel, int edge_ID, int index)
Definition: dcel.cpp:799