473,698 Members | 2,222 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

where are my objects???

I have a class Model that contains a private

vector<Vertex*> vertices

Each Vertex object has some info in it, and among those there is a

Vector *normal

In a piece of code (inside a parser that reads data from a file and builds a
data structure) I have this loop:

void Model::computeV erticesNormals( void) {
for(int i=0; i<vertices.size (); i++) {

// for each vertex....
Vertex *v = vertices[i];
int numOfTriangles = v->getNumberOfTri angles();
float x=0.0f, y=0.0f, z=0.0f;

// ....goes through the list of incident triangles
// (i.e. triangles that share the same vertex)
for(int j=0; j<numOfTriangle s; j++) {
Triangle *t = v->getTriangle(j) ;
Vertex *n = t->getNormal();
x = x+n->getX();
y = y+n->getY();
z = z+n->getZ();
}

// averages the normals of each triangle
// to get the normal at the vertex
x = x/numOfTriangles;
y = y/numOfTriangles;
z = z/numOfTriangles;

Vertex *result = new Vertex(x,y,z);
result->normalize();

// set the vertex normal
v->setNormal(resu lt);

// reads back the vertex normal from the vertex itself
// to see if the correct value has been saved
Vertex *test = v->getNormal();
cout<< i << ") " << *test << endl;
}
}
This is the ouput produced:

Computing normals at vertices...
0) (0,0,1)
1) (0.467037,-0.494024,0.7333 6)
2) (-0.611279,-0.146755,0.7776 9)
3) (0.184617,0.627 597,0.756332)
4) (0.220298,-0.969669,-0.105883)
5) (-0.947068,0.2819 57,0.153498)
6) (0.720865,0.691 571,-0.0456409)
7) (0.215026,-0.96971,-0.115873)
8) (-0.93456,0.27721 4,0.223049)
9) (0.71061,0.6957 13,-0.104963)
10) (0.176013,-0.961244,-0.212202)
11) (-0.901334,0.2727 84,0.336431)
12) (0.702211,0.703 715,-0.108096)
13) (0.132502,-0.956589,-0.259579)
14) (-0.835799,0.2531 62,0.487185)
15) (0.660714,0.724 194,-0.197484)
16) (0.0889998,-0.951882,-0.293258)
17) (-0.775485,0.2361 46,0.585541)
18) (0.624514,0.743 401,-0.239451)
............... ..
............... ..

which shows that the normals have been successfully saved in the Vertex
objects.

When this part of code ends, the code goes into some other code (different
..cpp file) that is in charge of displaying the geometry on the screen using
openGL. The part of code that surprises me is the following:

// for each vertex
int numOfVertices = my_model->getNumOfVertic es();
cout << "vertices = " << numOfVertices <<endl;
for(int j=0; j<numOfVertices ; j++) {

// prints out the content of the vertex (x,y,z coords)
Vertex* v=my_model->getVertex(j) ;
cout << "vertex["<<j<<"]" <<*v << endl;
// and the address of the normal (which should be a valid address)
Vertex* n=v->getNormal();
cout << "normal["<<j<<"]" <<n << endl;
}

instead the output that I am getting is:

vertices = 234
vertex[0](-1.01545,-0.479097,-17.894)
normal[0]CDCDCDCD
vertex[1](-1.17015,0.16529 6,-17.894)
normal[1]CDCDCDCD
vertex[2](-0.380034,-0.667315,-17.894)
normal[2]CDCDCDCD
vertex[3](-1.49616,-0.935275,-17.894)
normal[3]CDCDCDCD
vertex[4](-0.616068,0.0011 6807,-11.7246)
normal[4]CDCDCDCD
vertex[5](0.17405,-0.831445,-11.7246)
normal[5]CDCDCDCD
vertex[6](-0.942071,-1.09939,-11.7246)
normal[6]CDCDCDCD
vertex[7](0.32804,-0.27849,-7.19337)
normal[7]CDCDCDCD
vertex[8](1.11816,-1.1111,-7.19337)
normal[8]CDCDCDCD
vertex[9](0.00204068,-1.37905,-7.19337)
normal[9]CDCDCDCD
vertex[10](1.4273,-0.604105,-2.42307)
normal[10]CDCDCDCD
.............
.............

where CDCDCDCD is a way for VC6 to say that the address is not valid

Where are my normals? They were there a fraction of a second before... where
are they now???
Any suggestions???
I am totally lost on this one. Maybe some of you had similar problems before
and you can suggest a debugging plan or something....

thanks

Francesco
Jul 19 '05 #1
3 1680
> Where are my normals?

Should ask them, they know better than anyone.

Please post some real code describing your problem
and every function which interacts with the problematic
code along with object declarations.
Jonathan
Jul 19 '05 #2
Hi,

It is hard to tell from this code. Just a gamble and probably wrong but are
you trying to read a 3DS file with andrea's ingegneri's code?

Regards, Ron AF Greve.
"Francesco Gallarotti" <ga********@hot mail.com> wrote in message
news:Xz******** *************@n ews4.srv.hcvlny .cv.net...
I have a class Model that contains a private

vector<Vertex*> vertices

Each Vertex object has some info in it, and among those there is a

Vector *normal

In a piece of code (inside a parser that reads data from a file and builds a data structure) I have this loop:

void Model::computeV erticesNormals( void) {
for(int i=0; i<vertices.size (); i++) {

// for each vertex....
Vertex *v = vertices[i];
int numOfTriangles = v->getNumberOfTri angles();
float x=0.0f, y=0.0f, z=0.0f;

// ....goes through the list of incident triangles
// (i.e. triangles that share the same vertex)
for(int j=0; j<numOfTriangle s; j++) {
Triangle *t = v->getTriangle(j) ;
Vertex *n = t->getNormal();
x = x+n->getX();
y = y+n->getY();
z = z+n->getZ();
}

// averages the normals of each triangle
// to get the normal at the vertex
x = x/numOfTriangles;
y = y/numOfTriangles;
z = z/numOfTriangles;

Vertex *result = new Vertex(x,y,z);
result->normalize();

// set the vertex normal
v->setNormal(resu lt);

// reads back the vertex normal from the vertex itself
// to see if the correct value has been saved
Vertex *test = v->getNormal();
cout<< i << ") " << *test << endl;
}
}
This is the ouput produced:

Computing normals at vertices...
0) (0,0,1)
1) (0.467037,-0.494024,0.7333 6)
2) (-0.611279,-0.146755,0.7776 9)
3) (0.184617,0.627 597,0.756332)
4) (0.220298,-0.969669,-0.105883)
5) (-0.947068,0.2819 57,0.153498)
6) (0.720865,0.691 571,-0.0456409)
7) (0.215026,-0.96971,-0.115873)
8) (-0.93456,0.27721 4,0.223049)
9) (0.71061,0.6957 13,-0.104963)
10) (0.176013,-0.961244,-0.212202)
11) (-0.901334,0.2727 84,0.336431)
12) (0.702211,0.703 715,-0.108096)
13) (0.132502,-0.956589,-0.259579)
14) (-0.835799,0.2531 62,0.487185)
15) (0.660714,0.724 194,-0.197484)
16) (0.0889998,-0.951882,-0.293258)
17) (-0.775485,0.2361 46,0.585541)
18) (0.624514,0.743 401,-0.239451)
............... .
............... .

which shows that the normals have been successfully saved in the Vertex
objects.

When this part of code ends, the code goes into some other code (different
.cpp file) that is in charge of displaying the geometry on the screen using openGL. The part of code that surprises me is the following:

// for each vertex
int numOfVertices = my_model->getNumOfVertic es();
cout << "vertices = " << numOfVertices <<endl;
for(int j=0; j<numOfVertices ; j++) {

// prints out the content of the vertex (x,y,z coords)
Vertex* v=my_model->getVertex(j) ;
cout << "vertex["<<j<<"]" <<*v << endl;
// and the address of the normal (which should be a valid address) Vertex* n=v->getNormal();
cout << "normal["<<j<<"]" <<n << endl;
}

instead the output that I am getting is:

vertices = 234
vertex[0](-1.01545,-0.479097,-17.894)
normal[0]CDCDCDCD
vertex[1](-1.17015,0.16529 6,-17.894)
normal[1]CDCDCDCD
vertex[2](-0.380034,-0.667315,-17.894)
normal[2]CDCDCDCD
vertex[3](-1.49616,-0.935275,-17.894)
normal[3]CDCDCDCD
vertex[4](-0.616068,0.0011 6807,-11.7246)
normal[4]CDCDCDCD
vertex[5](0.17405,-0.831445,-11.7246)
normal[5]CDCDCDCD
vertex[6](-0.942071,-1.09939,-11.7246)
normal[6]CDCDCDCD
vertex[7](0.32804,-0.27849,-7.19337)
normal[7]CDCDCDCD
vertex[8](1.11816,-1.1111,-7.19337)
normal[8]CDCDCDCD
vertex[9](0.00204068,-1.37905,-7.19337)
normal[9]CDCDCDCD
vertex[10](1.4273,-0.604105,-2.42307)
normal[10]CDCDCDCD
............
............

where CDCDCDCD is a way for VC6 to say that the address is not valid

Where are my normals? They were there a fraction of a second before... where are they now???
Any suggestions???
I am totally lost on this one. Maybe some of you had similar problems before and you can suggest a debugging plan or something....

thanks

Francesco

Jul 19 '05 #3
> > void Model::computeV erticesNormals( void) {
for(int i=0; i<vertices.size (); i++) {

// for each vertex....
Vertex *v = vertices[i];
int numOfTriangles = v->getNumberOfTri angles();
float x=0.0f, y=0.0f, z=0.0f;

// ....goes through the list of incident triangles
// (i.e. triangles that share the same vertex)
for(int j=0; j<numOfTriangle s; j++) {
Triangle *t = v->getTriangle(j) ;
Vertex *n = t->getNormal();
x = x+n->getX();
y = y+n->getY();
z = z+n->getZ();
}

// averages the normals of each triangle
// to get the normal at the vertex
x = x/numOfTriangles;
y = y/numOfTriangles;
z = z/numOfTriangles;

Vertex *result = new Vertex(x,y,z); <<<<<<<<< creating Vertex result object here result->normalize();

// set the vertex normal
v->setNormal(resu lt); <<<<<<<<< making the Vertex v point to it
Apparently the problem are dangling pointers.
What seems to be happening here is that i am creating objects of type Vertex
inside this function and then, after the function terminates, the objects
are gone and the pointers to them are not pointing to anything anymore.
I am not sure if this is completely correct but this seems to be the
problem.

// reads back the vertex normal from the vertex itself
// to see if the correct value has been saved
Vertex *test = v->getNormal();
cout<< i << ") " << *test << endl;
}
}
This is the ouput produced:

Computing normals at vertices...
0) (0,0,1)
1) (0.467037,-0.494024,0.7333 6)
2) (-0.611279,-0.146755,0.7776 9)
3) (0.184617,0.627 597,0.756332)
4) (0.220298,-0.969669,-0.105883)
5) (-0.947068,0.2819 57,0.153498)
6) (0.720865,0.691 571,-0.0456409)
7) (0.215026,-0.96971,-0.115873)
8) (-0.93456,0.27721 4,0.223049)
9) (0.71061,0.6957 13,-0.104963)
10) (0.176013,-0.961244,-0.212202)
11) (-0.901334,0.2727 84,0.336431)
12) (0.702211,0.703 715,-0.108096)
13) (0.132502,-0.956589,-0.259579)
14) (-0.835799,0.2531 62,0.487185)
15) (0.660714,0.724 194,-0.197484)
16) (0.0889998,-0.951882,-0.293258)
17) (-0.775485,0.2361 46,0.585541)
18) (0.624514,0.743 401,-0.239451)
............... .
............... .

which shows that the normals have been successfully saved in the Vertex
objects.

When this part of code ends, the code goes into some other code (different .cpp file) that is in charge of displaying the geometry on the screen

using
openGL. The part of code that surprises me is the following:

// for each vertex
int numOfVertices = my_model->getNumOfVertic es();
cout << "vertices = " << numOfVertices <<endl;
for(int j=0; j<numOfVertices ; j++) {

// prints out the content of the vertex (x,y,z coords)
Vertex* v=my_model->getVertex(j) ;
cout << "vertex["<<j<<"]" <<*v << endl;
// and the address of the normal (which should be a valid

address)
Vertex* n=v->getNormal();
cout << "normal["<<j<<"]" <<n << endl;
}

instead the output that I am getting is:

vertices = 234
vertex[0](-1.01545,-0.479097,-17.894)
normal[0]CDCDCDCD
vertex[1](-1.17015,0.16529 6,-17.894)
normal[1]CDCDCDCD
vertex[2](-0.380034,-0.667315,-17.894)
normal[2]CDCDCDCD
vertex[3](-1.49616,-0.935275,-17.894)
normal[3]CDCDCDCD
vertex[4](-0.616068,0.0011 6807,-11.7246)
normal[4]CDCDCDCD
vertex[5](0.17405,-0.831445,-11.7246)
normal[5]CDCDCDCD
vertex[6](-0.942071,-1.09939,-11.7246)
normal[6]CDCDCDCD
vertex[7](0.32804,-0.27849,-7.19337)
normal[7]CDCDCDCD
vertex[8](1.11816,-1.1111,-7.19337)
normal[8]CDCDCDCD
vertex[9](0.00204068,-1.37905,-7.19337)
normal[9]CDCDCDCD
vertex[10](1.4273,-0.604105,-2.42307)
normal[10]CDCDCDCD
............
............

where CDCDCDCD is a way for VC6 to say that the address is not valid

Where are my normals? They were there a fraction of a second before...

where
are they now???
Any suggestions???
I am totally lost on this one. Maybe some of you had similar problems

before
and you can suggest a debugging plan or something....

thanks

Francesco


anyway thanks to everybody for spending your time trying to help.
I hope I had a good idea to change my code to fix this problem.

Francesco
Jul 19 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

17
5039
by: Jonas Rundberg | last post by:
Hi I just started with c++ and I'm a little bit confused where stuff go... Assume we have a class: class test { private: int arr; };
1
1316
by: Bae,Hyun-jik | last post by:
Where are __value objects allocated? I guess __value object is same to basic __value objects such as int,char,float, but C# compiler demands using new keyword even to __value classes. Please reply. Thanks in advance. Regards, Hyun-jik Bae
3
2338
by: Smithers | last post by:
In Windows Forms MDI applications... I'm wondering if it is standard practice to create DAL and business objects as static classes. The only alternative (please enlighten me if I'm wrong about this) is to instantiate the DAL and business objects in a Form class - most likely the MDI parent - and then expose the business objects as public members. What is standard practice here? .
9
19148
by: Emin | last post by:
Dear Experts, I have a fairly simple query in which adding a where clause slows things down by at least a factor of 100. The following is the slow version of the query ------------------------- SELECT * FROM ( Select x.event_date From x FULL OUTER JOIN y ON x.event_date = y.event_date
1
2018
by: Edward K Ream | last post by:
Hello all. I'm tracking down memory leaks in my app. To do this I wrote a script to show the numbers of each different type of object. But it doesn't show strings! Here is the script: import gc,types def printDict(d): keys = d.keys() ; keys.sort() print '-' * 30 for key in keys:
34
2126
by: linq936 | last post by:
Hi, I just did the following test: 1:void main(void){ 2: int p = 1; 3: int* pp = &p; 4: int c = p * pp; 5: int d = p + pp; 6:}
1
1001
by: ismailc | last post by:
Hi, I imported an css file for my dropdowns, but it does not align with the other objects in my xslt. I checked the imported css file for dropdown & it's aligned left but somehow I other objects are out by 2 spaces. The imported dropdwon does not allow for any characters or objects next to it - so i can't add a space at it moves to a new line All objects with new dropdown are aligned to left but still out - how & where can i edit the...
8
1503
by: junky_fellow | last post by:
Guys, Consider the following snippet of code: int main(VOID) { static ushort fractionalValue={ 0, 100, 200, 300, 400, 500, 600, 700, 800, 900, 250, 333, 666, 750, 0, 0 };
10
1758
by: mirandacascade | last post by:
Question toward the bottom of this post....background information immediately below. Access 97 SQL Server 2000 Please note: although the subject line uses the word 'bloat', this post is NOT a "what can I do to prevent bloat?" inquiry. When I searched the postings in this group for information about bloat, I believe I gained a rudimentary understanding of some of the things
0
8674
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
8604
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
9157
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
9028
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
8895
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
8861
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7728
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...
1
3046
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2330
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.