the best way to read this data....

Started by
5 comments, last by Deyja 18 years, 10 months ago
i have some data that i am going to have to store and am wondering what would be the best way to store in in memory. the data format is as follows: x y # of points 0.0 10.0 20.0 30.0 2.0 15.0 40.0 30.0 ... ... ... ... x y # of points etc etc etc. so basically # of points tells you how many points per location you will be reading. x and y are just that... x and y this is followed by the depth of the first point and 3 attributes the point has.. then the next point until you reach to # of points whatever that is. heres the problem...# of points can vary so its not a uniform data set. but they do all have 3 attributes per point. how would i connect the data via drawing them triangle strips etc etc or whatever. i think first i just need to come up with something to store the data in and then i can worry about the drawing later. i had something of a struct set up..such as struct data { x y z att1 att2 att3 }; i dont know if this would be the best way... thanks!
heh
Advertisement
There are several solutions. Is every data value of the same type?

Kuphryn
yeah they are all the same type...
heh
this is exactly what I have right now.


Struct data{  float d;  float x;  float y;  float z;} data *mydata;




the input file is layed out this way…



63 -> once I find this number out I put it into a variable num , then I can declare mydata = new data[num]; //so I have this part down.

0.0 20.0 30.0 40.0 50.0

2.0 6.0 20.0 50.0 100.0

4.0 3.0 1.0 40.0 43.5

…..(all the way down 60 more times)

5 ->next number

0.0 etc etc

2.0

4.0

6.0

8.0



109

….

….

….109 of these



55



….

..55 of these



so basically I need to group all the d, x, y, z’s together at the 0.0 level, same with the 2.0, 3.0, 4.0, etc etc. My mind is fried, I know its easier than it looks. I have thought of a linked list as the best way to access the first element of each “section” and so on.. but I don’t know.. what do you think??
heh
What language is this?

--Mark
- Declare container of containers of points CC.- While still more in file:  - Read count N from file line. Create new container C of this size.  - For N lines:    - Read one line. Create a point from the data. Add it to the end of C.  - Add C to the end of CC.


If you do not have the option of a "dynamically sized" CC, then you will need to add data to your file format to indicate its size (i.e. at the very beginning of the file, write how many sections there are). Fortunately, in C++ (as well as most other modern languages) there are plenty of good options for CC. In C++ in particular, consider std::vector<data*>, where each data* would point at an array of data (your Cs).
OpenGL_Guru; your name is not deserved.

This topic is closed to new replies.

Advertisement