473,406 Members | 2,549 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

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.
Expand|Select|Wrap|Line Numbers
  1. //to search faces that share a vertex
  2.  
  3.     for (int i =0; i <(int)vertices.size(); i++)//loop1
  4.     {
  5.         int s=0;
  6.         Polygon polygon;
  7.         Face face;
  8.         Vertex vertex;
  9.         vertex=vertices.at(i);
  10.         polygon.incident=0;
  11.         vertex.Incident=0;
  12.  
  13.         for (int j = 0; j < (int)faces.size(); j ++)//loop2
  14.         {
  15.  
  16.             if(faces[j].v1==vertices[i].vertexid )
  17.             {    
  18.  
  19.                 face=faces.at(j);
  20.                 //vertex=vertices.at(i);
  21.                 polygon.faceid=face.faceid;
  22.                 polygon.v2=face.v1;
  23.                 polygon.v1=face.v2;
  24.                 polygon.v3=face.v3;
  25.                 polygon.v2x=vertex.x;
  26.                 polygon.v2y=vertex.y;
  27.                 polygon.v2z=vertex.z;
  28.  
  29.  
  30.                 for (int k = 0; k < (int)vertices.size(); k ++)//loop 3
  31.                 {    vertex=vertices.at(k);
  32.                     if(faces[j].v2==vertices[k].vertexid )
  33.                     {    
  34.  
  35.                         polygon.v1x=vertex.x;
  36.                         polygon.v1y=vertex.y;
  37.                         polygon.v1z=vertex.z;
  38.  
  39.                     }
  40.                     if(faces[j].v3==vertices[k].vertexid )
  41.                     {    
  42.                         polygon.v3x=vertex.x;
  43.                         polygon.v3y=vertex.y;
  44.                         polygon.v3z=vertex.z;
  45.  
  46.                     }
  47.                 }//loop 3
  48.                 s++;
  49.  
  50.             }
  51.             else if(faces[j].v2==vertices[i].vertexid )
  52.             {    
  53.  
  54.                 face=faces.at(j);
  55.                 //vertex=vertices.at(i);        
  56.  
  57.                 polygon.faceid=faces[j].faceid;
  58.                 polygon.v2=faces[j].v2;
  59.                 polygon.v1=faces[j].v1;
  60.                 polygon.v3=faces[j].v3;
  61.                 polygon.v2x=vertices[i].x;
  62.                 polygon.v2y=vertices[i].y;
  63.                 polygon.v2z=vertices[i].z;
  64.  
  65.  
  66.                 for (int k = 0; k < (int)vertices.size(); k ++)//loop 3
  67.                 {    
  68.                     vertex=vertices.at(k);
  69.                     if(faces[j].v1==vertices[k].vertexid )
  70.                     {    
  71.  
  72.                         polygon.v1x=vertex.x;
  73.                         polygon.v1y=vertex.y;
  74.                         polygon.v1z=vertex.z;
  75.  
  76.                     }
  77.                     if(faces[j].v3==vertices[k].vertexid )
  78.                     {    
  79.  
  80.                         polygon.v3x=vertex.x;
  81.                         polygon.v3y=vertex.y;
  82.                         polygon.v3z=vertex.z;
  83.  
  84.                     }
  85.                 }//loop 3
  86.                 s++;
  87.  
  88.  
  89.             }
  90.             else if(faces[j].v3==vertices[i].vertexid )
  91.             {    
  92.  
  93.  
  94.                 face=faces.at(j);
  95.                 //vertex=vertices.at(i);
  96.  
  97.                 polygon.faceid=faces[j].faceid;
  98.                 polygon.v2=faces[j].v3;
  99.                 polygon.v1=faces[j].v1;
  100.                 polygon.v3=faces[j].v2;
  101.                 polygon.v2x=vertices[i].x;
  102.                 polygon.v2y=vertices[i].y;
  103.                 polygon.v2z=vertices[i].z;
  104.  
  105.  
  106.                 for (int k = 0; k < (int)vertices.size(); k ++)//loop 3
  107.                 {
  108.                     vertex=vertices.at(k);
  109.                     if(faces[j].v1==vertices[k].vertexid )
  110.                     {    
  111.  
  112.                         polygon.v1x=vertex.x;
  113.                         polygon.v1y=vertex.y;
  114.                         polygon.v1z=vertex.z;
  115.  
  116.                     }
  117.                     if(faces[j].v2==vertices[k].vertexid )
  118.                     {    
  119.                         polygon.v3x=vertex.x;
  120.                         polygon.v3y=vertex.y;
  121.                         polygon.v3z=vertex.z;
  122.  
  123.                     }
  124.                 }//loop 3
  125.                 s++;
  126.  
  127.             }//else if
  128.         }//loop2
  129.             polygon.incident=s;//no of adjacent faces per vertex
  130.  
  131.             //cout<<"before vertex pointer"<<vertex.vp<<"\n";
  132.             vertex.vp=&poly;
  133.             vertices[i]=vertex;
  134.  
  135.     }//loop1
  136. //
  137. }    
After that the model disappered.I m not familiar with the usage of vectors.Definitely something wrong in using vector or something else.So please help me.
Thanks in advance.
Feb 27 '08 #1
3 2214
manontheedge
175 100+
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
Feb 27 '08 #2
sicarie
4,677 Expert Mod 4TB
friendkitty-

What do you mean by 'the model'? Are you talking about the polygon object?
Feb 27 '08 #3
weaknessforcats
9,208 Expert Mod 8TB
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.
Feb 27 '08 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: Pratyush | last post by:
Hi, Suppose there is a vector of objects of class A, i.e., std::vector<A> vec_A(N); The class A satisifies all the STL vector requirements. Now I wish to add some attributes for each of the...
6
by: Alfonso Morra | last post by:
I have written the following code, to test the concept of storing objects in a vector. I encounter two run time errors: 1). myClass gets destructed when pushed onto the vector 2). Prog throws a...
13
by: JoeC | last post by:
I am completly lost. I would like to create a function that takes two vectors. These two vectors have objects with x and y coords, what I want to do find all the objects in the same x and y...
5
by: madhu | last post by:
http://msdn2.microsoft.com/en-us/library/fs5a18ce(VS.80).aspx vector <intv1; v1.push_back( 10 ); //adds 10 to the tail v1.push_back( 20 ); //adds 20 to the tail cout << "The size of v1 is " <<...
13
by: r.z. | last post by:
I logged construtor and destructor calls for one of my classes and I discovered that the constructor was called only once while the destructor was called 3 times for a single object. I have a...
10
by: Jess | last post by:
Hello, I have a program that stores dynamically created objects into a vector. #include<iostream> #include<vector> using namespace std;
8
by: tharringtonan | last post by:
I am compiling the following code, main.cpp, as follows: gcc main.cpp I get the following compile error: main.cpp: In function `int main()': main.cpp:28: no matching function for call to...
3
by: jojo41300000 | last post by:
Hi, Is anyone know that how to get the x and y points inside the polygon using C++ program? I have the given polygon data to draw the polygon, but i don't know how to get all the points...
3
by: Ramon F Herrera | last post by:
Newbie alert: I come from C programming, so I still have that frame of mind, but I am trying to "Think in C++". In C this problem would be solved using unions. Hello: Please consider the...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.