|
For this implementation, I use a generic value class to represent the data in the tables. This
generic value class can contain single values or multiple values. Types can be int, short,
float, and string. The support of multiple values is important because a number of fields in the
VPF format can have multiple values (coordinates, tile triplets, etc.)
The next step was to add methods to the table for efficiently finding columns by name, and attributes in in the rows. In the VPF format, tables refer to other tables which can refer to other tables. Values in one table may be column names (keys) into another table. The ability to easily take a value out of a table and look it up as a column name in another table is key. How many columns a table has, and the ordering of the columns in the tables, can be a dynamic matter based upon whether the table contains optional items. Enough about parsing, because I doubt anyone comes to a webpage like this to read about parsing!
|
|
Phase 2: Initial Vector Feature Classes To test the initial parsing and to get the vector feature of the project under way, a couple vector feature classes were written:
The Basic Vector Feature class is little more than a test class which supports storing the line strips using STL vectors and rendering them. Its goal was simply to provide support for a vector feature while testing the parsing logic. Using this basic logic, the north american coastlines contain about 501k vertices, and almost 13,000 line strips. The Indexed Vector Feature Class implemented the vector feature interface while internally supporting a vertex table, and storing the line segments as a series of indices into the vertex table. It uses a STL multiset to store vertex search information to provide fast searching for existing vertices, when adding line strips to the feature. The indexed vertex table shows that the unique vertex count for the north american coastlines is actually 489k vertices not 501k. Not a large savings, but this is just a building block for later vector feature classes.
Phase 3: Optimizing Vector Feature Classes In the case of the Indexed Vector Feature, this optimization is searching for line segments which can be merged together into one segment. To do this efficiently, it iterates through the line strips adding the line strip index to a STL vector for the starting and end vertex of the line strip. Then it iterates through the vertices checking to see if the vertex has more than one line strip associated with it. If so, it can merge those line strips. (It may have to reorder one or both to get the line strips merged at the given vertex.) This processing (which is rather efficient) reduces the line strip count by 1000 line strips!
Phase 4: Level of Detail & Simplification The simplification algorithm was leveraged from one I developed for some other polygon simplification work that I have done. In this case, it could be described as a Douglas-Peucker algorithm reversed. The initial implementation simplified based on the number of vertices, reducing features more that had more vertices. The following images illustrates how effective it was at a global level and a more local level.
|
![]() |
![]() |
Simplification of vector features to a desired number of vertices works because the simplification
algorithm removes vertices in order from the smallest to largest amount of error introduced.
The problem
is that it isn't the best way to do it, because we may simplify an island more than it should be,
but not simplify a coast as much as it should (because we are targeting vertex counts.) To fix this,
Simplification based on a maximum error factor was added. The following images illustrate that this
worked quite well:
|
![]() |
The vertex totals are for the entire file, not just the section shown in the images.
Click here to see an animated version of the simplification. |
Implementation: A new vector feature class was added, LOD Vector Feature, which inherits from the IndexedVectorFeature.
It adds creating, drawing, and deletion of the LOD levels. It uses the maximum error factor as
its mechanism for specifying the LOD levels. The Vector Feature Interface supports specifying a
parametric value [0..1] when drawing for how detailed the resulting draw should be. This parameter
is used by the LOD Vector Feature to compute a target number of vertices and to then look up in its
list of LODs for the best level of detail to draw.
Phase 5: Tiling The following images illustrate the difference between the original 553k vertices, and an automatically generated low level of detail (62k vertices.) It is pretty much impossible to determine the difference at this zoom factor. This technology will be used to display the vector features at various levels of details based upon the zoom factor. When zoomed closer, only a few tiles will be in view, but they will rendered at higher levels of detail. This will keep the polygon budget per frame for vector features at a fairly consistent level. |