Click here to Skip to main content
15,892,805 members

How can I specify vertices of all faces of a voronoi cell, according to voro++?

lee.lion asked:

Open original thread
My question is: how can I change code so that each line shows the vertices of face corresponding to that id?

I am so appreciated for any help and hint.

What I have tried:

according to the below link:

http://math.lbl.gov/voro++/examples/polygons/

(explanation about above link)
1- on line 41, there is a loop over all particles,
2- the loop that is from line 51 to 71 investigates all faces of a cell,
3- for investigation all faces without considering them twice, parameter "IF" on the line 59 does this. for example for my cube, which is defined below, for first particle, in output there are 6 lines as we can see in below output.

I defined a cubic with the vertices:

1	0	0	0  <br />
2	0	2	0  <br />
3	2	0	0  <br />
4	2	2	0  <br />
5	0	0	2  <br />
6	0	2	2  <br />
7	2	0	2  <br />
8	2	2	2


then, writing this code:

C++
#include <vector>
using namespace std;
#include "voro++.hh"
using namespace voro;
#include <fstream>
#include <iostream>

int main() {
	const double x_min=0,x_max=4.0000001;
	const double y_min=0,y_max=4.0000001;
	const double z_min=0,z_max=4.0000001;
	int nx,ny,nz; 
	pre_container  pcon(x_min,x_max,y_min,y_max,z_min,z_max,true,true,true);
    pcon.import("cube");
	pcon.guess_optimal(nx,ny,nz);
	container con(x_min,x_max,y_min,y_max,z_min,z_max,nx,ny,nz,true,true,true,8);
	pcon.setup(con);
	
	unsigned int i,j;
	int id;
	double x,y,z;
	voronoicell_neighbor c;
	vector<int> neigh,f_vert;
	vector<double> v;
	FILE *fp5=safe_fopen("1.txt","w");

	c_loop_all cl(con);
        if(cl.start()) do if(con.compute_cell(c,cl)) {
            cl.pos(x,y,z);id=cl.pid();
            c.neighbors(neigh);
            c.face_vertices(f_vert);
            c.vertices(x,y,z,v);
			
			for(i=0,j=0;i<neigh.size();i++) {
			   
				if(neigh.at(i)>id) {
					
					switch(f_vert.at(j)) {
                        case 4:{ 
							fprintf(fp5,"%i, (%g %g %g) (%g %g %g) (%g %g %g) (%g %g %g)\n",id,v[0],v[1],v[2],v[3],v[4],v[5],v[6],v[7],v[8],v[9],v[10],v[11]);
						}break;
					}
                }
				j+=f_vert[j]+1;
            }
        } while (cl.inc());
	fclose(fp5);
}


I expected that each line of output would show the vertices of face corresponding to that id. but all of vertices of faces for a given id were identical, like this:

1, (-1 -1 -1) (1 -1 -1) (-1 1 -1) (1 1 -1)  <br />
1, (-1 -1 -1) (1 -1 -1) (-1 1 -1) (1 1 -1)  <br />
1, (-1 -1 -1) (1 -1 -1) (-1 1 -1) (1 1 -1)  <br />
1, (-1 -1 -1) (1 -1 -1) (-1 1 -1) (1 1 -1)  <br />
1, (-1 -1 -1) (1 -1 -1) (-1 1 -1) (1 1 -1)  <br />
1, (-1 -1 -1) (1 -1 -1) (-1 1 -1) (1 1 -1)  <br />
2, (-1 3 1) (1 3 -1) (-1 3 -1) (1 1 1)  <br />
2, (-1 3 1) (1 3 -1) (-1 3 -1) (1 1 1)  <br />
2, (-1 3 1) (1 3 -1) (-1 3 -1) (1 1 1)  <br />
2, (-1 3 1) (1 3 -1) (-1 3 -1) (1 1 1)  <br />
3, (1 1 -1) (1 -1 1) (1 -1 -1) (3 -1 -1)  <br />
3, (1 1 -1) (1 -1 1) (1 -1 -1) (3 -1 -1)  <br />
3, (1 1 -1) (1 -1 1) (1 -1 -1) (3 -1 -1)  <br />
3, (1 1 -1) (1 -1 1) (1 -1 -1) (3 -1 -1)  <br />
4, (1 3 1) (3 3 -1) (3 1 -1) (3 1 1)  <br />
4, (1 3 1) (3 3 -1) (3 1 -1) (3 1 1)  <br />
5, (-1 -1 3) (1 -1 3) (-1 -1 1) (1 1 3)  <br />
5, (-1 -1 3) (1 -1 3) (-1 -1 1) (1 1 3)  <br />
5, (-1 -1 3) (1 -1 3) (-1 -1 1) (1 1 3)  <br />
5, (-1 -1 3) (1 -1 3) (-1 -1 1) (1 1 3)  <br />
6, (1 1 3) (1 1 1) (-1 3 1) (1 3 1)  <br />
6, (1 1 3) (1 1 1) (-1 3 1) (1 3 1)  <br />
7, (1 1 3) (3 1 3) (1 -1 3) (3 -1 3)  <br />
7, (1 1 3) (3 1 3) (1 -1 3) (3 -1 3)


when I substituted
fprintf(fp5,"%i, (%g %g %g) (%g %g %g) (%g %g %g) (%g %g %g)\n",id,v[0],v[1],v[2],v[3],v[4],v[5],v[6], v[7],v[8],v[9],v[10],v[11]);

with

fprintf(fp5,"%i %i, (%g %g %g) (%g %g %g) (%g %g %g) (%g %g %g) (%g %g %g) (%g %g %g) (%g %g %g) (%g %g %g)\n",id,v.size(),v[0],v[1],v[2],v[3],v[4],v[5],v[6],v[7],v[8], v[9],v[10],v[11],v[12],v[13],v[14],v[15],v[16],v[17],v[18],v[19],v[20],v[21],v[22],v[23]);

I found each line showed whole vertices of a cell of a given id, while it shouldn't be like this. i mean it should be something like this:
1, (1 -1 -1) (1 1 -1) (1 -1 1) (1 1 1)
this is vertices of face between particle 1 and 2
Tags: C++, 3D

Plain Text
ASM
ASP
ASP.NET
BASIC
BAT
C#
C++
COBOL
CoffeeScript
CSS
Dart
dbase
F#
FORTRAN
HTML
Java
Javascript
Kotlin
Lua
MIDL
MSIL
ObjectiveC
Pascal
PERL
PHP
PowerShell
Python
Razor
Ruby
Scala
Shell
SLN
SQL
Swift
T4
Terminal
TypeScript
VB
VBScript
XML
YAML

Preview



When answering a question please:
  1. Read the question carefully.
  2. Understand that English isn't everyone's first language so be lenient of bad spelling and grammar.
  3. If a question is poorly phrased then either ask for clarification, ignore it, or edit the question and fix the problem. Insults are not welcome.
  4. Don't tell someone to read the manual. Chances are they have and don't get it. Provide an answer or move on to the next question.
Let's work to help developers, not make them feel stupid.
Please note that all posts will be submitted under the http://www.codeproject.com/info/cpol10.aspx.



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900