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 // Turn on if to be used with voro_connect
39 // To be used with voro_connect
41 // To be used with voro_connect
43 voronoicell_base_2d();
44 ~voronoicell_base_2d();
45 void init_base(double xmin
,double xmax
,double ymin
,double ymax
);
46 void draw_gnuplot(double x
,double y
,FILE *fp
=stdout
);
47 /** Outputs the edges of the Voronoi cell in gnuplot format to
49 * \param[in] (x,y) a displacement vector to be added to the
51 * \param[in] filename the file to write to. */
52 inline void draw_gnuplot(double x
,double y
,const char *filename
) {
53 FILE *fp
=safe_fopen(filename
,"w");
57 void draw_pov(double x
,double y
,FILE *fp
=stdout
);
58 /** Outputs the edges of the Voronoi cell in POV-Ray format to
59 * an open file stream, displacing the cell by given vector.
60 * \param[in] (x,y,z) a displacement vector to be added to the
62 * \param[in] filename the file to write to. */
63 inline void draw_pov(double x
,double y
,const char *filename
) {
64 FILE *fp
=safe_fopen(filename
,"w");
68 void output_custom(const char *format
,int i
,double x
,double y
,double r
,FILE *fp
=stdout
);
69 /** Computes the Voronoi cells for all particles in the
70 * container, and for each cell, outputs a line containing
71 * custom information about the cell structure. The output
72 * format is specified using an input string with control
73 * sequences similar to the standard C printf() routine.
74 * \param[in] format the format of the output lines, using
75 * control sequences to denote the different
77 * \param[in] i the ID of the particle associated with this
79 * \param[in] (x,y) the position of the particle associated
80 * with this Voronoi cell.
81 * \param[in] r a radius associated with the particle.
82 * \param[in] filename the file to write to. */
83 inline void output_custom(const char *format
,int i
,double x
,double y
,double r
,const char *filename
) {
84 FILE *fp
=safe_fopen(filename
,"w");
85 output_custom(format
,i
,x
,y
,r
,fp
);
88 template<class vc_class
>
89 bool nplane(vc_class
&vc
,double x
,double y
,double rs
,int p_id
);
90 template<class vc_class
>
91 bool nplane_cut(vc_class
&vc
,double x
,double y
,double rsq
,int p_id
,double u
,int up
);
92 bool plane_intersects(double x
,double y
,double rs
);
93 inline bool plane_intersects_guess(double x
,double y
,double rs
) {
94 return plane_intersects(x
,y
,rs
);
96 double max_radius_squared();
99 void vertices(vector
<double> &v
);
100 void output_vertices(FILE *fp
=stdout
);
101 void vertices(double x
,double y
,vector
<double> &v
);
102 void output_vertices(double x
,double y
,FILE *fp
=stdout
);
103 void edge_lengths(vector
<double> &vd
);
104 void normals(vector
<double> &vd
);
105 void centroid(double &cx
,double &cy
);
106 //given 2 vectors a and b, returns an element that they have in common !=c
107 vector
<int> common_gen(vector
<int> &a
,vector
<int> &b
);
108 //called from voro_connect
109 inline void full_connect_on(){
111 vertexg
=new vector
<int>[current_vertices
];
112 for(int i
=0;i
<p
;i
++){
113 vertexg
[i
].push_back(my_id
);
116 //called from voro_connect
117 inline void set_id(int id
){
120 //called from voro_connect(add vertex-generator)
121 void add_vg(vector
<int> &a
,int g
);
122 void vg_copy(int o
,int n
);
124 virtual void neighbors(vector
<int> &v
) {v
.clear();}
126 /** Computes the distance of a Voronoi cell vertex to a plane.
127 * \param[in] (x,y) the normal vector to the plane.
128 * \param[in] rsq the distance along this vector of the plane.
129 * \param[in] qp the index of the vertex to consider. */
130 inline double pos(double x
,double y
,double rsq
,int qp
) {
131 return x
*pts
[2*qp
]+y
*pts
[2*qp
+1]-rsq
;
134 template<class vc_class
>
135 void add_memory_vertices(vc_class
&vc
);
136 void add_memory_ds(int *&stackp
);
137 /** The delete stack, used to store the vertices that are
138 * deleted during the plane cutting procedure. */
140 /** A pointer to the end of the delete stack, used to detect
141 * when it is full. */
145 class voronoicell_2d
: public voronoicell_base_2d
{
147 using voronoicell_base_2d::nplane
;
148 inline bool nplane(double x
,double y
,double rs
,int p_id
) {
149 return nplane(*this,x
,y
,rs
,0);
151 inline bool nplane(double x
,double y
,int p_id
) {
153 return nplane(*this,x
,y
,rs
,0);
155 inline bool plane(double x
,double y
,double rs
) {
156 return nplane(*this,x
,y
,rs
,0);
158 inline bool plane(double x
,double y
) {
160 return nplane(*this,x
,y
,rs
,0);
162 inline void init(double xmin
,double xmax
,double ymin
,double ymax
) {
163 init_base(xmin
,xmax
,ymin
,ymax
);
166 inline void n_add_memory_vertices() {}
167 inline void n_copy(int a
,int b
) {}
168 inline void n_set(int a
,int id
) {}
169 friend class voronoicell_base_2d
;
172 class voronoicell_neighbor_2d
: public voronoicell_base_2d
{
174 using voronoicell_base_2d::nplane
;
176 voronoicell_neighbor_2d() : ne(new int[init_vertices
]) {}
177 ~voronoicell_neighbor_2d() {delete [] ne
;}
178 inline bool nplane(double x
,double y
,double rs
,int p_id
) {
179 return nplane(*this,x
,y
,rs
,p_id
);
181 inline bool nplane(double x
,double y
,int p_id
) {
183 return nplane(*this,x
,y
,rs
,p_id
);
185 inline bool plane(double x
,double y
,double rs
) {
186 return nplane(*this,x
,y
,rs
,0);
188 inline bool plane(double x
,double y
) {
190 return nplane(*this,x
,y
,rs
,0);
192 void init(double xmin
,double xmax
,double ymin
,double ymax
);
193 virtual void neighbors(vector
<int> &v
);
195 inline void n_add_memory_vertices();
196 inline void n_copy(int a
,int b
) {ne
[a
]=ne
[b
];}
197 inline void n_set(int a
,int id
) {ne
[a
]=id
;}
198 friend class voronoicell_base_2d
;