2 * \brief Header file for the voronoicell_2d class. */
4 #ifndef VOROPP_CELL_2D_HH
5 #define VOROPP_CELL_2D_HH
18 /** \brief A class encapsulating all the routines for storing and calculating a
19 * single Voronoi cell. */
20 class voronoicell_base_2d
{
22 /** This holds the current size of the ed and pts arrays. If
23 * more vertices are created than can fit in these arrays, then
24 * they are dynamically extended using the add_memory_vertices
27 /** This sets the size of the current delete stack. */
28 int current_delete_size
;
29 /** The total nuber of vertices in the current cell. */
31 /** An array with size 2*current_vertices holding information
32 * about edge connections between vertices.*/
34 /** An array with size 2*current_vertices for holding
35 * the positions of the vertices. */
37 voronoicell_base_2d();
38 ~voronoicell_base_2d();
39 void init_base(double xmin
,double xmax
,double ymin
,double ymax
);
40 void draw_gnuplot(double x
,double y
,FILE *fp
=stdout
);
41 /** Outputs the edges of the Voronoi cell in gnuplot format to
43 * \param[in] (x,y) a displacement vector to be added to the
45 * \param[in] filename the file to write to. */
46 inline void draw_gnuplot(double x
,double y
,const char *filename
) {
47 FILE *fp
=safe_fopen(filename
,"w");
51 void draw_pov(double x
,double y
,FILE *fp
=stdout
);
52 /** Outputs the edges of the Voronoi cell in POV-Ray format to
53 * an open file stream, displacing the cell by given vector.
54 * \param[in] (x,y,z) a displacement vector to be added to the
56 * \param[in] filename the file to write to. */
57 inline void draw_pov(double x
,double y
,const char *filename
) {
58 FILE *fp
=safe_fopen(filename
,"w");
62 void output_custom(const char *format
,int i
,double x
,double y
,double r
,FILE *fp
=stdout
);
63 /** Computes the Voronoi cells for all particles in the
64 * container, and for each cell, outputs a line containing
65 * custom information about the cell structure. The output
66 * format is specified using an input string with control
67 * sequences similar to the standard C printf() routine.
68 * \param[in] format the format of the output lines, using
69 * control sequences to denote the different
71 * \param[in] i the ID of the particle associated with this
73 * \param[in] (x,y) the position of the particle associated
74 * with this Voronoi cell.
75 * \param[in] r a radius associated with the particle.
76 * \param[in] filename the file to write to. */
77 inline void output_custom(const char *format
,int i
,double x
,double y
,double r
,const char *filename
) {
78 FILE *fp
=safe_fopen(filename
,"w");
79 output_custom(format
,i
,x
,y
,r
,fp
);
82 template<class vc_class
>
83 bool nplane(vc_class
&vc
,double x
,double y
,double rs
,int p_id
);
84 template<class vc_class
>
85 bool nplane_cut(vc_class
&vc
,double x
,double y
,double rsq
,int p_id
,double u
,int up
);
86 bool plane_intersects(double x
,double y
,double rs
);
87 inline bool plane_intersects_guess(double x
,double y
,double rs
) {
88 return plane_intersects(x
,y
,rs
);
90 double max_radius_squared();
93 void vertices(vector
<double> &v
);
94 void output_vertices(FILE *fp
=stdout
);
95 void vertices(double x
,double y
,vector
<double> &v
);
96 void output_vertices(double x
,double y
,FILE *fp
=stdout
);
97 void edge_lengths(vector
<double> &vd
);
98 void normals(vector
<double> &vd
);
99 void centroid(double &cx
,double &cy
);
100 virtual void neighbors(vector
<int> &v
) {v
.clear();}
102 /** Computes the distance of a Voronoi cell vertex to a plane.
103 * \param[in] (x,y) the normal vector to the plane.
104 * \param[in] rsq the distance along this vector of the plane.
105 * \param[in] qp the index of the vertex to consider. */
106 inline double pos(double x
,double y
,double rsq
,int qp
) {
107 return x
*pts
[2*qp
]+y
*pts
[2*qp
+1]-rsq
;
110 template<class vc_class
>
111 void add_memory_vertices(vc_class
&vc
);
112 void add_memory_ds(int *&stackp
);
113 /** The delete stack, used to store the vertices that are
114 * deleted during the plane cutting procedure. */
116 /** A pointer to the end of the delete stack, used to detect
117 * when it is full. */
121 class voronoicell_2d
: public voronoicell_base_2d
{
123 using voronoicell_base_2d::nplane
;
124 inline bool nplane(double x
,double y
,double rs
,int p_id
) {
125 return nplane(*this,x
,y
,rs
,0);
127 inline bool nplane(double x
,double y
,int p_id
) {
129 return nplane(*this,x
,y
,rs
,0);
131 inline bool plane(double x
,double y
,double rs
) {
132 return nplane(*this,x
,y
,rs
,0);
134 inline bool plane(double x
,double y
) {
136 return nplane(*this,x
,y
,rs
,0);
138 inline void init(double xmin
,double xmax
,double ymin
,double ymax
) {
139 init_base(xmin
,xmax
,ymin
,ymax
);
142 inline void n_add_memory_vertices() {}
143 inline void n_copy(int a
,int b
) {}
144 inline void n_set(int a
,int id
) {}
145 friend class voronoicell_base_2d
;
148 class voronoicell_neighbor_2d
: public voronoicell_base_2d
{
150 using voronoicell_base_2d::nplane
;
152 voronoicell_neighbor_2d() : ne(new int[init_vertices
]) {}
153 ~voronoicell_neighbor_2d() {delete [] ne
;}
154 inline bool nplane(double x
,double y
,double rs
,int p_id
) {
155 return nplane(*this,x
,y
,rs
,p_id
);
157 inline bool nplane(double x
,double y
,int p_id
) {
159 return nplane(*this,x
,y
,rs
,p_id
);
161 inline bool plane(double x
,double y
,double rs
) {
162 return nplane(*this,x
,y
,rs
,0);
164 inline bool plane(double x
,double y
) {
166 return nplane(*this,x
,y
,rs
,0);
168 void init(double xmin
,double xmax
,double ymin
,double ymax
);
169 virtual void neighbors(vector
<int> &v
);
171 inline void n_add_memory_vertices();
172 inline void n_copy(int a
,int b
) {ne
[a
]=ne
[b
];}
173 inline void n_set(int a
,int id
) {ne
[a
]=id
;}
174 friend class voronoicell_base_2d
;