Confusion storing vectors of polygon objects

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • friendkitty
    New Member
    • Feb 2008
    • 1

    Confusion storing vectors of polygon objects

    Hi All,
    I m a new member here.I am now writing a program that render Vertex Normals.I m now trying to implement a data structure that will best suit computing vertex normals.For that computation , my data structure should have accessed to the faces adjacent to each vertices.
    first i read all vertices ,and faces from .m file into a structure.And stored in vectors.

    vector<Vertex> vertices;
    vector<Face> faces;
    Then i render that model.No error and problem till now.

    After that i created "poly" vector to store the faces adjacent to each vertices.

    vector<Polygon> poly;

    For all vertices,I find the faces that share a vertex and stored in poly.Following is the code i wrote for this.
    [code=cpp]
    //to search faces that share a vertex

    for (int i =0; i <(int)vertices. size(); i++)//loop1
    {
    int s=0;
    Polygon polygon;
    Face face;
    Vertex vertex;
    vertex=vertices .at(i);
    polygon.inciden t=0;
    vertex.Incident =0;

    for (int j = 0; j < (int)faces.size (); j ++)//loop2
    {

    if(faces[j].v1==vertices[i].vertexid )
    {

    face=faces.at(j );
    //vertex=vertices .at(i);
    polygon.faceid= face.faceid;
    polygon.v2=face .v1;
    polygon.v1=face .v2;
    polygon.v3=face .v3;
    polygon.v2x=ver tex.x;
    polygon.v2y=ver tex.y;
    polygon.v2z=ver tex.z;


    for (int k = 0; k < (int)vertices.s ize(); k ++)//loop 3
    { vertex=vertices .at(k);
    if(faces[j].v2==vertices[k].vertexid )
    {

    polygon.v1x=ver tex.x;
    polygon.v1y=ver tex.y;
    polygon.v1z=ver tex.z;

    }
    if(faces[j].v3==vertices[k].vertexid )
    {
    polygon.v3x=ver tex.x;
    polygon.v3y=ver tex.y;
    polygon.v3z=ver tex.z;

    }
    }//loop 3
    s++;

    }
    else if(faces[j].v2==vertices[i].vertexid )
    {

    face=faces.at(j );
    //vertex=vertices .at(i);

    polygon.faceid= faces[j].faceid;
    polygon.v2=face s[j].v2;
    polygon.v1=face s[j].v1;
    polygon.v3=face s[j].v3;
    polygon.v2x=ver tices[i].x;
    polygon.v2y=ver tices[i].y;
    polygon.v2z=ver tices[i].z;


    for (int k = 0; k < (int)vertices.s ize(); k ++)//loop 3
    {
    vertex=vertices .at(k);
    if(faces[j].v1==vertices[k].vertexid )
    {

    polygon.v1x=ver tex.x;
    polygon.v1y=ver tex.y;
    polygon.v1z=ver tex.z;

    }
    if(faces[j].v3==vertices[k].vertexid )
    {

    polygon.v3x=ver tex.x;
    polygon.v3y=ver tex.y;
    polygon.v3z=ver tex.z;

    }
    }//loop 3
    s++;


    }
    else if(faces[j].v3==vertices[i].vertexid )
    {


    face=faces.at(j );
    //vertex=vertices .at(i);

    polygon.faceid= faces[j].faceid;
    polygon.v2=face s[j].v3;
    polygon.v1=face s[j].v1;
    polygon.v3=face s[j].v2;
    polygon.v2x=ver tices[i].x;
    polygon.v2y=ver tices[i].y;
    polygon.v2z=ver tices[i].z;


    for (int k = 0; k < (int)vertices.s ize(); k ++)//loop 3
    {
    vertex=vertices .at(k);
    if(faces[j].v1==vertices[k].vertexid )
    {

    polygon.v1x=ver tex.x;
    polygon.v1y=ver tex.y;
    polygon.v1z=ver tex.z;

    }
    if(faces[j].v2==vertices[k].vertexid )
    {
    polygon.v3x=ver tex.x;
    polygon.v3y=ver tex.y;
    polygon.v3z=ver tex.z;

    }
    }//loop 3
    s++;

    }//else if
    }//loop2
    polygon.inciden t=s;//no of adjacent faces per vertex

    //cout<<"before vertex pointer"<<verte x.vp<<"\n";
    vertex.vp=&poly ;
    vertices[i]=vertex;

    }//loop1
    //
    } [/code]
    After that the model disappered.I m not familiar with the usage of vectors.Definit ely something wrong in using vector or something else.So please help me.
    Thanks in advance.
    Last edited by sicarie; Feb 27 '08, 02:13 PM. Reason: Code tags are [code=cpp] and after your code [/code]. Please use them. They want to be used. They like to be used.
  • manontheedge
    New Member
    • Oct 2006
    • 175

    #2
    if that's the first time you've written in C++ maybe you should learn the basics of the language before you try to get that figured out

    Comment

    • sicarie
      Recognized Expert Specialist
      • Nov 2006
      • 4677

      #3
      friendkitty-

      What do you mean by 'the model'? Are you talking about the polygon object?

      Comment

      • weaknessforcats
        Recognized Expert Expert
        • Mar 2007
        • 9214

        #4
        Odd a Polygon would store the number of its faces.

        I would expect a base class Polygon with derived classes for Parallelogram, Trapezoid, etc. in case a specific shape needs specific calculations.

        I would create specific objects and store them in the vector as Polygon pointers. Actually, I would use handles but pointers will work to get you started.

        Comment

        Working...