Coordinate Array

Started by
3 comments, last by Buckeye 14 years, 1 month ago
Hi. I have a text file with a list of coordinates as follows: x1 y1 z1 x2 y2 z2 etc... I wanted to create an array of coordinates. How do I do this? Also, for a given coordinate I would like to know its neighbouring coordinates that it is linked to. I guess it would make sense to read in an .OBJ file which details which coordinates are connected, however there are few .OBJ readers out there. Because the mesh is just made up of triangles, each selected coordinate is linked to 5 or 6 surrounding nodes. Any ideas? Thanks
Advertisement
Hi,

I think you need to be more specific in what you are tryng to do.

In having the text file, you already have an array of coordinates.
Do you mean create as in syntax for an array? Then in which language do you wnat? Or do you mean how to do file I/O?

If you know the relation of the coordinates, then maybe you could calculate the links yourself. Otherwise, this link information must be given to you in another file or something.
==============================================Rage - Really Amateurish Graphics EngineCollada Parser / Serializer
Sorry about being a bit vague.

1st: I would like to read in the file (as above) into an array[] in C++?

2nd: I know .OBJ files provide data about faces that are generated from triangles composed of 3 coordinates. I just wondered whether there are any file formats that specify the connected vertices of a given vertex? The other way to do it is to set a radius around a given vertex and just take those that fall within that radius (not so good for very fine or irregular meshes).
Quote:Original post by chrome68
1st: I would like to read in the file (as above) into an array[] in C++?

You'll want to use a std::vector for storage and an std::ifstream to read from the file (probably). On the other hand, this might be one of those occasions where fscanf() is a more pragmatic choice. boost also has lots of stuff for tokenizing and parsing.

Quote:
2nd: I know .OBJ files provide data about faces that are generated from triangles composed of 3 coordinates.

They can also contain arbitrary polygons, lines, curves and lots of other stuff too.

Quote:I just wondered whether there are any file formats that specify the connected vertices of a given vertex?


Probably. However, it's not too hard to work out connectivity even if it's not in the file. Just iterate over the edges of the polygons to find out which vertices are connected by an edge. From your wording I assume that's what you want?

Quote:The other way to do it is to set a radius around a given vertex and just take those that fall within that radius (not so good for very fine or irregular meshes).

I think that's making it more complicated (and probably slower) than it needs to be.
Quote:The other way to do it is to set a radius around a given vertex and just take those that fall within that radius

Unless the mesh is "connected," i.e., vertices are used in more than one face as opposed to 3 unique vertices per face, you'll have to generate adjacency information yourself. The method you mention (or something similar using an epsilon distance between vertices) is commonly used to do that. "Duplicate" vertices (vertices within epsilon of each other) are eliminated and the vertex indices are updated.

Please don't PM me with questions. Post them in the forums for everyone's benefit, and I can embarrass myself publicly.

You don't forget how to play when you grow old; you grow old when you forget how to play.

This topic is closed to new replies.

Advertisement