我尝试用Voro ++实现一个简单的3d voronoi应用程序。我有一个装有颗粒的容器。将所有粒子放入容器后,如何获得Voro ++计算的所有voronoicell的顶点。
答案 0 :(得分:3)
从文档中应该是这样的: http://math.lbl.gov/voro++/examples/polygons/
文件说: 在第47行,调用face_vertices例程,该例程返回关于哪些顶点构成每个面的信息。它是具有特定格式的整数向量:第一个条目是对应于构成面的顶点数量的数字k,并且这是跟随k个附加条目,其描述哪个顶点构成该面。例如,序列(3,16,20,13)将对应于将顶点16,20和13连接在一起的三角形面。在第48行,返回顶点位置:这对应于描述每个顶点位置的三元组(x,y,z)的向量。我修改了示例脚本,以便它在向量中存储每个粒子单元连接和顶点位置。但请验证这一点! 希望这有帮助!
#include "voro++.hh"
#include "container.hh"
#include <v_compute.hh>
#include <c_loops.hh>
#include <vector>
#include <iostream>
using namespace voro;
int main() {
// Set up constants for the container geometry
const double x_min=-5,x_max=5;
const double y_min=-5,y_max=5;
const double z_min=0,z_max=10;
unsigned int i,j;
int id,nx,ny,nz;
double x,y,z;
std::vector<int> neigh;
voronoicell_neighbor c;
// Set up the number of blocks that the container is divided into
const int n_x=6,n_y=6,n_z=6;
// Create a container with the geometry given above, and make it
// non-periodic in each of the three coordinates. Allocate space for
// eight particles within each computational block
container con(x_min,x_max,y_min,y_max,z_min,z_max,n_x,n_y,n_z,
false,false,false,8);
//Randomly add particles into the container
con.import("pack_six_cube");
// Save the Voronoi network of all the particles to text files
// in gnuplot and POV-Ray formats
con.draw_cells_gnuplot("pack_ten_cube.gnu");
con.draw_cells_pov("pack_ten_cube_v.pov");
// Output the particles in POV-Ray format
con.draw_particles_pov("pack_ten_cube_p.pov");
// Loop over all particles in the container and compute each Voronoi
// cell
c_loop_all cl(con);
int dimension = 0;
if(cl.start()) do if(con.compute_cell(c,cl)) {
dimension+=1;
} while (cl.inc());
std::vector<std::vector<int> > face_connections(dimension);
std::vector<std::vector<double> > vertex_positions(dimension);
int counter = 0;
if(cl.start()) do if(con.compute_cell(c,cl)) {
cl.pos(x,y,z);id=cl.pid();
std::vector<int> f_vert;
std::vector<double> v;
// Gather information about the computed Voronoi cell
c.neighbors(neigh);
c.face_vertices(f_vert);
c.vertices(x,y,z,v);
face_connections[counter] = f_vert;
vertex_positions[counter] = v;
std::cout << f_vert.size() << std::endl;
std::cout << v.size() << std::endl;
counter += 1;
} while (cl.inc());
}
此致,Lukas