PDA

View Full Version : Problems reading and drawing PLY files



chincheta21
12-07-2012, 11:55 AM
Hello everyone,

I am doing my third exercise about ply files. I have to generate a code what it can print PLY files (I have that files).

I have a class with everything what I need (open, create and read PLY files). For example, I can read a PLY file and my read function does a vector with all the points and another one with the face index. It is the code:


int _file_ply::
read(vector<float> &Vertices,vector<int> &Faces)
{
int Next_token,i,j;
int Num_vertices,Num_faces;

if (File!=NULL)
{
Next_token=next_token();
if (Next_token==PLY)
{
Next_token=next_token();
if (Next_token==FORMAT)
{
Next_token=next_token();
if (Next_token==ASCII)
{
Next_token=next_token();
if (Next_token==NUMBER)
{// head
Next_token=next_token();
while (Next_token!=END_HEADER)
{
if (Next_token==ELEMENT)
{
Next_token=next_token();
switch (Next_token)
{
case VERTEX:
Next_token=next_token();
if (Next_token==NUMBER)
{
Num_vertices=(int) Yylval.Real;
Vertices.resize(Num_vertices*3);
}
else error("no number of vertex");
break;
case FACE:
Next_token=next_token();
if (Next_token==NUMBER)
{
Num_faces=(int) Yylval.Real;
Faces.resize(Num_faces*3);
}
else error("no number of faces");
break;
default:
error("element type not supported");
break;
}
}
Next_token=next_token();
}
// data
// vertices data
for (i=0;i<Num_vertices;i++)
{// vertices data
for (j=0;j<3;j++)
{
Next_token=next_token();
if (Next_token==NUMBER)
{
Vertices[i*3+j]=Yylval.Real;
}
else error("no number for coordinate");
}
}
// faces data
for (i=0;i<Num_faces;i++)
{
Next_token=next_token();
if (Next_token==NUMBER)
{
if ((int)Yylval.Real!=3) {
printf("Face=%d Token=%s\n",i,Yylval.Text.c_str());
error("only triangles supported");;
}
}
else error("no number of vertex indices");
for (j=0;j<3;j++)
{
Next_token=next_token();
if (Next_token==NUMBER)
{
Faces[i*3+j]=(int)Yylval.Real;
}
else error("no number for coordinate");
}
}
printf("File readed\n");
}
else error("no format number");
}
else error("no ascii format");
}
else error("no format word");
}
else error("this is not a ply file");
return(0);
}
else
{
error("there is not a ply file open");
return(-1);
}
}

Well, I need to generate C code to print that points drawing triangles... OK, I have no idea, maybe I need a tip from you because I do not understand that function and what it does correctly...

It is my first time working with C/C++

Well, Im spanish! Sorry for my language!