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
10 void draw_polygon(FILE *fp
,vector
<int> &f_vert
,vector
<double> &v
,int j
);
16 voronoicell_neighbor c
;
17 vector
<int> neigh
,f_vert
;
20 // Create a pre-container class to import the input file and guess the
21 // best computational grid size to use.
22 pre_container
pcon(-3,3,-3,3,0,6,false,false,false);
23 pcon
.import("pack_six_cube");
24 pcon
.guess_optimal(nx
,ny
,nz
);
26 // Set up the container class and import the particles from the
28 container
con(-3,3,-3,3,0,6,nx
,ny
,nz
,false,false,false,8);
31 // Open the output files
32 FILE *fp4
=safe_fopen("polygons4_v.pov","w"),
33 *fp5
=safe_fopen("polygons5_v.pov","w"),
34 *fp6
=safe_fopen("polygons6_v.pov","w");
36 // Loop over all particles in the container and compute each Voronoi
39 if(cl
.start()) do if(con
.compute_cell(c
,cl
)) {
40 cl
.pos(x
,y
,z
);id
=cl
.pid();
42 // Gather information about the computed Voronoi cell
44 c
.face_vertices(f_vert
);
47 // Loop over all faces of the Voronoi cell
48 for(i
=0,j
=0;i
<neigh
.size();i
++) {
50 // Draw all quadrilaterals, pentagons, and hexagons.
51 // Skip if the neighbor information is smaller than
52 // this particle's ID, to avoid double counting. This
53 // also removes faces that touch the walls, since the
54 // neighbor information is set to negative numbers for
58 case 4: draw_polygon(fp4
,f_vert
,v
,j
);
60 case 5: draw_polygon(fp5
,f_vert
,v
,j
);
62 case 6: draw_polygon(fp6
,f_vert
,v
,j
);
66 // Skip to the next entry in the face vertex list
71 // Close the output files
76 // Draw the outline of the domain
77 con
.draw_domain_pov("polygons_d.pov");
80 void draw_polygon(FILE *fp
,vector
<int> &f_vert
,vector
<double> &v
,int j
) {
81 static char s
[6][128];
84 // Create POV-Ray vector strings for each of the vertices
87 sprintf(s
[k
],"<%g,%g,%g>",v
[l
],v
[l
+1],v
[l
+2]);
90 // Draw the interior of the polygon
92 for(k
=2;k
<n
;k
++) fprintf(fp
,"\ttriangle{%s,%s,%s}\n",s
[0],s
[k
-1],s
[k
]);
93 fputs("\ttexture{t1}\n}\n",fp
);
95 // Draw the outline of the polygon
99 fprintf(fp
,"\tcylinder{%s,%s,r}\n\tsphere{%s,r}\n",
102 fputs("\ttexture{t2}\n}\n",fp
);