1 // Direct C++ interface example code
3 // Author : Chris H. Rycroft (LBL / UC Berkeley)
4 // Email : chr@alum.mit.edu
5 // Date : August 30th 2011
13 void draw_polygon(FILE *fp
,vector
<int> &f_vert
,vector
<double> &v
,int j
);
19 voronoicell_neighbor c
;
20 vector
<int> neigh
,f_vert
;
23 // Create a pre-container class to import the input file and guess the
24 // best computational grid size to use.
25 pre_container
pcon(-3,3,-3,3,0,6,false,false,false);
26 pcon
.import("pack_six_cube");
27 pcon
.guess_optimal(nx
,ny
,nz
);
29 // Set up the container class and import the particles from the
31 container
con(-3,3,-3,3,0,6,nx
,ny
,nz
,false,false,false,8);
34 // Open the output files
35 FILE *fp4
=safe_fopen("polygons4_v.pov","w"),
36 *fp5
=safe_fopen("polygons5_v.pov","w"),
37 *fp6
=safe_fopen("polygons6_v.pov","w");
39 // Loop over all particles in the container and compute each Voronoi
42 if(cl
.start()) do if(con
.compute_cell(c
,cl
)) {
43 cl
.pos(x
,y
,z
);id
=cl
.pid();
45 // Gather information about the computed Voronoi cell
47 c
.face_vertices(f_vert
);
50 // Loop over all faces of the Voronoi cell
51 for(i
=0,j
=0;i
<neigh
.size();i
++) {
53 // Draw all quadrilaterals, pentagons, and hexagons.
54 // Skip if the neighbor information is smaller than
55 // this particle's ID, to avoid double counting. This
56 // also removes faces that touch the walls, since the
57 // neighbor information is set to negative numbers for
61 case 4: draw_polygon(fp4
,f_vert
,v
,j
);
63 case 5: draw_polygon(fp5
,f_vert
,v
,j
);
65 case 6: draw_polygon(fp6
,f_vert
,v
,j
);
69 // Skip to the next entry in the face vertex list
74 // Close the output files
79 // Draw the outline of the domain
80 con
.draw_domain_pov("polygons_d.pov");
83 void draw_polygon(FILE *fp
,vector
<int> &f_vert
,vector
<double> &v
,int j
) {
84 static char s
[6][128];
87 // Create POV-Ray vector strings for each of the vertices
90 sprintf(s
[k
],"<%g,%g,%g>",v
[l
],v
[l
+1],v
[l
+2]);
93 // Draw the interior of the polygon
95 for(k
=2;k
<n
;k
++) fprintf(fp
,"\ttriangle{%s,%s,%s}\n",s
[0],s
[k
-1],s
[k
]);
96 fputs("\ttexture{t1}\n}\n",fp
);
98 // Draw the outline of the polygon
102 fprintf(fp
,"\tcylinder{%s,%s,r}\n\tsphere{%s,r}\n",
105 fputs("\ttexture{t2}\n}\n",fp
);