C programming

davidktw

Arch-Supremacy Member
Joined
Apr 15, 2010
Messages
13,546
Reaction score
1,299
I was thinking whether to store them into array first,because need to cross references,then store them into half-edge

3d - Loading a model into a half-edge data structure from a .PLY file - Stack Overflow

perhaps this is related to the ply model?

it says something like using a mark method to ensure that it was already visited,i recalled I learnt before a mark method to check if it is visited.

the problem is how to cross-reference,

flipcode | Daily Game Development | Programming 3D Games and Graphics

it will read the vertex first,

then read the face,

but face normal vertex to do calculation of normal,

in between need to store in the mesh data structure

after that vertex normal need faces.

It is up to you how to want to construct the Half Edge Graph. Of course you can choose to use temporary data structures before constructing the actual Half Edge Mesh. You can always store the raw input data in simple data structure, after which you can construct the HE Mesh using these raw data. There is definitely more than 1 way to do the same thing. It's up to you to go and explore these methods and see which one is better. You won't get the best method until you try out at least one. Understand the difficulties in getting to your final objective. Don't expect best method or best approach, they only exist after you know what you are going through. Go through the process.

As for the marking process, that's normally an approach to stop loops in searching algorithm. As your HE Mesh has a "next" property that stores the next HE, then during searching you may need a marking algorithm or data structure to know if all the edges in a Face you are traversing has been visited. I'm not sure how you are manipulating or traversing your HE Mesh, so I can't advise much.

PLY Model or any other model is just input file format, it shouldn't be too much of a concern to your HE Mesh, just how you are consuming input data.

I really think you need to have deeper thoughts in what you are doing. I find you are either going in circles, or don't exactly know what you want and what to ask. Please be more specific in what you are trying to achieve. Don't ask big broad questions, it tend to stray in answers. Ask something more specific, like what you did, what you are doing now, what are you trying to achieve, what is the exact problem you encounter. Show codes, show examples, should diagrams to let others help you.
 

bhtan760

Banned
Joined
Aug 11, 2013
Messages
249
Reaction score
0
article_halfedge.png


Code:
  struct HE_edge
    {

        HE_vert* vert;   // vertex at the end of the half-edge
        HE_edge* pair;   // oppositely oriented adjacent half-edge 
        HE_face* face;   // face the half-edge borders
        HE_edge* next;   // next half-edge around the face
    
    };

Code:
    struct HE_vert
    {

        float x;
        float y;
        float z;

        HE_edge* edge;  // one of the half-edges emantating from the vertex
    
    };

Code:
struct HE_face
    {

        HE_edge* edge;  // one of the half-edges bordering the face

    };

it mentioned that can I start the HE_vert,

however I still need to change to

Code:
    struct HE_vert
    {
        int vid;
        float x,y,z;
        float ny,ny,nz
        
        HE_edge* edge;  // one of the half-edges emantating from the vertex
    
    };

i am thinking of changing HE_edge to:

Code:
struct HE_face
    {
        int vid,v1,v2,v3
        float nz,ny,nz;
        HE_edge* edge;  // one of the half-edges bordering the face

    };

how do I manipulate it while doing fscanf thats the question,
and then use glVertex3d to output the data,
glNormal3d to calculate at the point it was GL_TRIANGLE
 
Last edited:

davidktw

Arch-Supremacy Member
Joined
Apr 15, 2010
Messages
13,546
Reaction score
1,299
article_halfedge.png


Code:
  struct HE_edge
    {

        HE_vert* vert;   // vertex at the end of the half-edge
        HE_edge* pair;   // oppositely oriented adjacent half-edge 
        HE_face* face;   // face the half-edge borders
        HE_edge* next;   // next half-edge around the face
    
    };

Code:
    struct HE_vert
    {

        float x;
        float y;
        float z;

        HE_edge* edge;  // one of the half-edges emantating from the vertex
    
    };

Code:
struct HE_face
    {

        HE_edge* edge;  // one of the half-edges bordering the face

    };

it mentioned that can I start the HE_vert,

however I still need to change to

Code:
    struct HE_vert
    {
        int vid;
        float x,y,z;
        float ny,ny,nz
        
        HE_edge* edge;  // one of the half-edges emantating from the vertex
    
    };

i am thinking of changing HE_edge to:

Code:
struct HE_face
    {
        int vid,v1,v2,v3
        float nz,ny,nz;
        HE_edge* edge;  // one of the half-edges bordering the face

    };

how do I manipulate it while doing fscanf thats the question,
and then use glVertex3d to output the data,
glNormal3d to calculate at the point it was GL_TRIANGLE

Are you forced to generate HE Mesh on the first parse ? If not, why are you forcing yourself to do that ? Just because your objective is to generate HE Mesh, that doesn't mean you are not allowed to have temporary data structures to store the data as-is, after read from the 3D model file. Please try thinking out of the box when solving problem.

You need to think incrementally. Just because you are told to create a HE Mesh, doesn't mean you need only 1 pass to create it. When creating a HE_vert structure, nothing is stopping you from just filling in the "x", "y", and "z" attributes first without giving any meaningful values to "nx", "ny", "nz", "edge" etc. Besides you don't have sufficient information to construct the whole of them on first pass too. For example, how would you know the normal to a vertex without at least have 2 other adjacent vertices in the same face ? In fact, if you are going to construct smoothing normal of each vertex, you need more than just 2 other adjacent vertices in the same face, you actually require all normals of all adjacent faces. So you see, you wouldn't be using the first pass to generate the HE Mesh. It means your "fscanf" is just reading in data as-is. You are suppose to parse through the intermediate data structure representing your vertices and faces, and construct the HE Mesh from them.
 

bhtan760

Banned
Joined
Aug 11, 2013
Messages
249
Reaction score
0
i found some stuff from berkeley,it can read mesh file and do all the calculation,hard for me to understand.

http://www.cs.berkeley.edu/~sarietta/data/cs451/ass01/src/asgn1/main.cpp

it can read the .OFF mesh data structure similiar to my but it is in C++

http://www.cs.berkeley.edu/~sarietta/data/cs451/ass01/src/models/1-simple/hand.off

if need to do hashtable in c is so troublesome unlike java,otherwise can mark already

http://troydhanson.github.io/uthash/

my teacher document omitted out he_mesh,seems dubious to me,i never come across he_mesh before,he never even mention need first pass
 
Last edited:

davidktw

Arch-Supremacy Member
Joined
Apr 15, 2010
Messages
13,546
Reaction score
1,299

Well is that what you wanted ? I also provided you with PLY standard 3D file format reader. Is someone already telling you what file format to you to store your 3D file format, or are you implementing your own ?
 

bhtan760

Banned
Joined
Aug 11, 2013
Messages
249
Reaction score
0
Well is that what you wanted ? I also provided you with PLY standard 3D file format reader. Is someone already telling you what file format to you to store your 3D file format, or are you implementing your own ?

need some reference
 

bhtan760

Banned
Joined
Aug 11, 2013
Messages
249
Reaction score
0
Code:
if (fscanf(f, "ace %d %d %d %d\n", &fid, &v1, &v2, &v3) == 4)
{
// save the triangle into the face array
	face_array[fid-1][0]=v1;
	face_array[fid-1][1]=v2;
	face_array[fid-1][2]=v3;
	printf("%d,%d,%d,%d\n",fid,v1,v2,v3);
	f_size++;
	if((fid-1)>face_count)
		face_count=vid-1;
		
}

i have worked out using a 2d array to store the vertices temporary.


Code:
//create the half-edge data structure
HE_edge *he_edge = (HE_edge*)malloc(sizeof(HE_edge) * f_size* 2);
HE_vert *he_vert = (HE_vert*)malloc(sizeof(HE_vert) * v_size);
HE_face *he_face = (HE_face*)malloc(sizeof(HE_face) * f_size);

then I discussed with friend the number of edge is twice the number of face.

would like to hear your comments.
 

davidktw

Arch-Supremacy Member
Joined
Apr 15, 2010
Messages
13,546
Reaction score
1,299
Code:
if (fscanf(f, "ace %d %d %d %d\n", &fid, &v1, &v2, &v3) == 4)
{
// save the triangle into the face array
	face_array[fid-1][0]=v1;
	face_array[fid-1][1]=v2;
	face_array[fid-1][2]=v3;
	printf("%d,%d,%d,%d\n",fid,v1,v2,v3);
	f_size++;
	if((fid-1)>face_count)
		face_count=vid-1;
		
}

i have worked out using a 2d array to store the vertices temporary.


Code:
//create the half-edge data structure
HE_edge *he_edge = (HE_edge*)malloc(sizeof(HE_edge) * f_size* 2);
HE_vert *he_vert = (HE_vert*)malloc(sizeof(HE_vert) * v_size);
HE_face *he_face = (HE_face*)malloc(sizeof(HE_face) * f_size);

then I discussed with friend the number of edge is twice the number of face.

would like to hear your comments.

I don't quite get the following
Code:
	if((fid-1)>face_count)
		face_count=vid-1;

While 2d array works, but since you have already learnt C structures, why are you not using it instead for clearer codes ?

Is there any reason to determine no. of edges is 2x no. of faces ? If 1 have only 1 face, does it mean there are only 2 edges ?
 

bhtan760

Banned
Joined
Aug 11, 2013
Messages
249
Reaction score
0
I don't quite get the following
Code:
	if((fid-1)>face_count)
		face_count=vid-1;

While 2d array works, but since you have already learnt C structures, why are you not using it instead for clearer codes ?

Is there any reason to determine no. of edges is 2x no. of faces ? If 1 have only 1 face, does it mean there are only 2 edges ?

article_halfedge.png


as you can see,

number of edges is 10

Vertices 6

Face 5
 

davidktw

Arch-Supremacy Member
Joined
Apr 15, 2010
Messages
13,546
Reaction score
1,299
article_halfedge.png


as you can see,

number of edges is 10

Vertices 6

Face 5

Are you taught in Mathematics that showing me one example is the proof to your hypothesis ?
I have shown you one counter example that 1 face have 3 edges right ? So how can your hypothesis be true ?
 

bhtan760

Banned
Joined
Aug 11, 2013
Messages
249
Reaction score
0
Are you taught in Mathematics that showing me one example is the proof to your hypothesis ?
I have shown you one counter example that 1 face have 3 edges right ? So how can your hypothesis be true ?

got it,figure it out.
 

bhtan760

Banned
Joined
Aug 11, 2013
Messages
249
Reaction score
0
void line(void){
glMatrixMode(GL_MODELVIEW);
glPushMatrix();
glScalef(0.1,0.1,0.1);
glClear(GL_COLOR_BUFFER_BIT); // clear display windows
glBegin(GL_LINES);
glColor3f(1.0, 1.0, 1.0);
for(int i = -10;i < 10;i++){
glVertex3f(-10.0,i,0);
glVertex3f(10.0,i,0);
}
for(int j = -10;j < 10;j++){
glVertex3f(j,-10.0,0);
glVertex3f(j,10.0,0);
}
glEnd();
glPopMatrix();
glFlush();
}

by the way I am trying to draw these lines,
how can i rotation such that it looks like the one in 3ds maxs?
the one in perspectives.

516760fg0201_0.jpg
 

davidktw

Arch-Supremacy Member
Joined
Apr 15, 2010
Messages
13,546
Reaction score
1,299
void line(void){
glMatrixMode(GL_MODELVIEW);
glPushMatrix();
glScalef(0.1,0.1,0.1);
glClear(GL_COLOR_BUFFER_BIT); // clear display windows
glBegin(GL_LINES);
glColor3f(1.0, 1.0, 1.0);
for(int i = -10;i < 10;i++){
glVertex3f(-10.0,i,0);
glVertex3f(10.0,i,0);
}
for(int j = -10;j < 10;j++){
glVertex3f(j,-10.0,0);
glVertex3f(j,10.0,0);
}
glEnd();
glPopMatrix();
glFlush();
}

by the way I am trying to draw these lines,
how can i rotation such that it looks like the one in 3ds maxs?
the one in perspectives.

516760fg0201_0.jpg

Rotation. How much freedom of rotation will depend on how you are performing your rotation transformation of the scene.

Gimbal Lock is the idea. Gimble Lock - Explained - YouTube
http://www.youtube.com/watch?gl=SG&v=zc8b2Jo7mno&hl=en-GB

Rotate before you draw your grid. Your grid is just like another mesh

Update: Do read this too http://www.opengl.org/archives/resources/faq/technical/viewing.htm
 
Last edited:

bhtan760

Banned
Joined
Aug 11, 2013
Messages
249
Reaction score
0
Rotation. How much freedom of rotation will depend on how you are performing your rotation transformation of the scene.

Gimbal Lock is the idea. Gimble Lock - Explained - YouTube
Euler (gimbal lock) Explained - YouTube

Rotate before you draw your grid. Your grid is just like another mesh

Update: Do read this too OpenGL FAQ / 8 Viewing and Camera Transforms, and Using gluLookAt()

t8191d.png


yes,

i set the gluLookAt(2.0,2.0,2.0,0.0,0.0,0.0,0.0,0.0,1.0); to this i manage to get this to work.

however,not sure how to reset the rotation and translation,read up on the net it seems to say glLoadIdentity again to do reset?

by the way can write alphabets X,Y,Z in openGL?

one big problem,when I resize the screen or do some rotation everything gone
 

bhtan760

Banned
Joined
Aug 11, 2013
Messages
249
Reaction score
0
14oaout.png



void display(void){
glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
gluLookAt(2.0,2.0,2.0,0.0,0.0,0.0,0.0,0.0,1.0);
glMatrixMode(GL_MODELVIEW);
glScalef(0.1,0.1,0.1);
line();
glPushMatrix();
cylinder();
cone();
glPopMatrix();
glPushMatrix();
glRotatef(90,1,0,0);
cylinder();
cone();
glPopMatrix();
glPushMatrix();
glRotatef(90,0,1,0);
cylinder();
cone();
glPopMatrix();
glFlush();
glutSwapBuffers();
}

a little stranger,i rotate 90 around the z axis it goes to the left,

when i y axes it faces towards me,the cones offset.
 

davidktw

Arch-Supremacy Member
Joined
Apr 15, 2010
Messages
13,546
Reaction score
1,299
14oaout.png



void display(void){
glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
gluLookAt(2.0,2.0,2.0,0.0,0.0,0.0,0.0,0.0,1.0);
glMatrixMode(GL_MODELVIEW);
glScalef(0.1,0.1,0.1);
line();
glPushMatrix();
cylinder();
cone();
glPopMatrix();
glPushMatrix();
glRotatef(90,1,0,0);
cylinder();
cone();
glPopMatrix();
glPushMatrix();
glRotatef(90,0,1,0);
cylinder();
cone();
glPopMatrix();
glFlush();
glutSwapBuffers();
}

a little stranger,i rotate 90 around the z axis it goes to the left,

when i y axes it faces towards me,the cones offset.

It will be hard to identify what your arrows are presenting ? Which is the X, Y, Z axis ? Please use colour to denote them differently. Also show us the mesh before rotation and after rotation.
 

bhtan760

Banned
Joined
Aug 11, 2013
Messages
249
Reaction score
0
hi there,

i got

min=(-0.432908,-0.444530,-0.360542)
max=(0.432955,0.499768,0.360629)

how can i draw the bounding box?

will it take 3^2 or 3^3?

i thought of a way by drawing the glbox

max - min get the difference
scale the difference
draw the wire cube with 1.0
translate by the min

as for the below,could be due to my reshape,
off and turn it on again,and type in the file name,this is causing a lot of problem,need to build restarts and on the vs again

Code:
void reshape(GLsizei width, GLsizei height) {  // GLsizei for non-negative integer
    glViewport(0,0,width,height);
	glMatrixMode(GL_PROJECTION);
	gluPerspective(60,1.00,1.0,10.0);
	glMatrixMode(GL_MODELVIEW);
	glClear(GL_COLOR_BUFFER_BIT);
}
 
Last edited:
Important Forum Advisory Note
This forum is moderated by volunteer moderators who will react only to members' feedback on posts. Moderators are not employees or representatives of HWZ Forums. Forum members and moderators are responsible for their own posts. Please refer to our Community Guidelines and Standards and Terms and Conditions for more information.
Top