| kenter13 (20) | |||
|
Hello I have a text file with the following format
I want to get the X and Y coordinates of the each control points from 2 images. For example, from the above file i want to retrieve such information: -PointID=1 and point coordinates are 802,725(from image1) and 480,708 (from image2) -PointID=2 and point coordinates are 317,130(from image1) and 128,116 (from image2) There can be millions of points in such a text file. So what is the best way to parse these files? Thanks | |||
|
|
|||
| Ogoyant (153) | |||
|
The control point objects are nested in a main object. Does each text file contain only one main object, or does it contain an arbitrary number of main objects (each of which contain an arbitrary number of control point objects)? You can use a vector to store the control point objects as you parse through your file, something like this:
If your file contains more than a single main object, you'll have to keep track of the nesting level and the current object you are in (by parsing "Object =" and "End_Object" notations, and counting their occurance using a suitable variable structure), and perhaps maintain a similar vector for the file's main objects, each entry of which will contain the controlPoints vector you fill as you parse the main object. If you are working with a very large number of points, and you want to use the data in your program for calculations that are memory intensive (and not just extract and save it in a new file, or something similar), you may want to implement the above with dynamically allocated arrays, because vectors have some memory overhead due to the fact that they allocate some additional memory as they grow, in order to store potential new entries to the vector without having to allocate new memory for each such new entry as it occurs (i.e. , the vector::capacity can be equal to or greater than the vector::size for a given vector). | |||
|
Last edited on
|
|||