473,657 Members | 2,392 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Confusion storing vectors of polygon objects

1 New Member
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.Definit ely something wrong in using vector or something else.So please help me.
Thanks in advance.
Feb 27 '08 #1
3 2230
manontheedge
175 New Member
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 Recognized Expert Moderator Specialist
friendkitty-

What do you mean by 'the model'? Are you talking about the polygon object?
Feb 27 '08 #3
weaknessforcats
9,208 Recognized Expert Moderator Expert
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
3410
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 objects in the vector vec_A. Suppose there are K attributes to be added. For each of the attributes I define K vectors of appropriate types. Say, the attributes have types type1, type2, ..., typeK. So I define std::vector<type1> attr1(vec_A.size());
6
2564
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 "SEGV" when run (presumably - attempt to delete deleted memory. Please take a look and see if you can notice any mistakes I'm making. Basically, I want to store classes of my objects in a vector. I also have three further questions:
13
2544
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 coords and put all the objects in the same coordinate together.
5
18132
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 " << v1.size( ) << endl; v1.clear( ); //clears the vector I have a few questions:
13
2799
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 vector of objects of class A: vector<Avector_of_As; and I put objects to it like this: vector_of_As.push_back( A() );
10
2708
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
1305
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 `CPolygon::area()' The code is listed below:
3
6150
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 inside the polygon. Eg. Let's say we have 5 points to draw a polygon. Polygon ---------------------
3
1680
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 snippet below. I have some objects which are derived (subclassed?, subtyped?) from simpler ones, in increasing size. There is a linear hierarchy. I need to keep them all in some sort of linked list (perhaps std::vector). I could have several
0
8411
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8323
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8838
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8739
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8513
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7351
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5638
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4329
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
1732
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.