Click here to Skip to main content
15,886,069 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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
Posted
Updated 13-Sep-19 11:06am
v9
Comments
Rick York 8-Sep-19 21:52pm    
Thanks for the link. There is some very interesting stuff there.
Rick York 11-Sep-19 23:03pm    
Did you look at the sample code - polygons.cc in Examples/Interface ?
lee.lion 12-Sep-19 7:19am    
so many thanks for your attention,

I wrote my code according to that sample mentioned by you."Stefan_Lang", solution 2 in the beneath, says that the values of "v" do not change. while according to the sample code, I think in the loop of "For", in the middle of my code, program should consider faces of a given cell in order. base on this, I expect that "fprintf" shows vertices of a face, and by increasing "i", demonstrates vertices of other faces of a given cell.
Rick York 12-Sep-19 10:54am    
I have added a solution below for you to consider.
Stefan_Lang 13-Sep-19 3:44am    
Solutions 2 and 3 are both correct. Your code always accesses v through the same index values, whereas, as Rick pointed out, the sample code uses a variable 'l' to offset those index values. Therefore, the sample code reads different values with every loop iteration, but yours does not.

On a sidenote. using one-letter variables is almost always a bad idea, and, in particular, using 'l' is doubly bad: on first read I mistook it for a '1' (i. e. the numerical value one). Take your own conclusions... ;-)

Looks like in the inner for loop, the vector v is never modified. That explains why you keep getting multiple identical outputs. I have no idea what you want to achieve or what that library does, but whatever it is you wanted to print, you should make sure to actually load or process those values.
 
Share this answer
 
As I mentioned above, it seems you used the code from Examples/Interface/Polygons.cc on the Voro++ package. There are two big differences in them. It has to do with how you are accessing the data. Here is an excerpt from the example code :
C++
void draw_polygon( FILE *fp, vector<int> &f_vert, vector<double> &v, int j )
{
    static char s[6][128];
    int k, l, n = f_vert[j];

    // Create POV-Ray vector strings for each of the vertices

    for( k = 0; k < n; k++ )
    {
        l = 3 * f_vert[ j + k + 1 ];  // <--- IMPORTANT !!!

        sprintf( s[k],"<%g,%g,%g>",v[l], v[l+1], v[l+2] );
    }
    // ...
}

int main()
{
    // ...
    if( neigh[i] > id )
    {
        switch( f_vert[j] )
        {
        case 4: draw_polygon( fp4, f_vert, v, j ); break;
        // other cases here
        }
    }
and here is your code :
C++
if(neigh[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;
    }
}
I hope you can see that how you access the vector is considerably different. You are using indexes starting from zero. The example use indexes based on the variable l which is computed as 3*fvert[j+k+1]. This gives a different set of indexes for each vertex and that is why your results are weird. I added a comment to emphasize this point and where it occurs.
 
Share this answer
 
Comments
lee.lion 13-Sep-19 6:32am    
after about one month, my first problem solved with aid of generous persons.

"Rick York", you were quite right. I never paid attention to the second part of sample code, while it plays a crucial role in solving this problem. I thought that the latter part just relates to POV-Ray, then I ignored that. you made me aware of my mistake.

thank you dear "Rick York", thank you dear "Stefan_Lang"
for all of your attention

What a splendid website, What open-handed members
Rick York 13-Sep-19 11:03am    
POV-Ray is very cool if you like computer graphics and ray tracing. I am into both quite a bit. I wrote a reader to load POV-Ray files into my OpenGL app that can display them in real-time. I had never seen this voro++ site and I like the graphics so I am now importing the files generated by the example programs there. They are pretty cool. Thanks again for the link. :)
This is not a software development question: or if it is, we aren't here to do it all for you - we are more than willing to help people, but we expect to to do the work and we will help when you get stuck.

Just posting your task and saying "I tried for a month" isn't showing us where you are stuck. It's just like saying "do it for me" and not bothering.

So if you have tried for a month you will have code to show us. Show us that, explain where you are stuck, what you have tried to do to continue, and what help you need.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



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