Rogach/jopenvoronoi

fileformat for test geometry

Closed this issue · 9 comments

I came up with this format for test-geometry:
http://pastebin.com/WEbkwXFV
There are pros and cons with any fileformat, but at least XML should be easily readable by both humans and computers using almost any programming language. There doesn't seem to be a good standard for compressed XML so I am using gzip because it was easy in python.
This also allows for a future arc-specification to be added.
If you think this is OK I can convert some openvoronoi tests to this format.
Previously I did code-coverage analysis for the tests - it would be interesting to know the minimum set of test-geometries that is 'complete' in the sense that code-coverage is close to 100%.

Yes, it looks nice. I'll try to implement it in jopenvoronoi some time on this week.

I'm not sure about timestamps and comments, though. Do we really need that? If necessary, we can always insert comments easily as plain xml comments, same for timestamps.

I implemented the proposed format, and added a bunch of test files in jopenvornoi-test/src/test/resources/.

Hi guys,
I have clone jopenvoronoi and successfully run it. It is the only way for me to get segment voronoi diagrams (not speaking C and CGAL being too hard). I would appreciate if the spec for PSLG was available (the pastebin has been removed) in a redme or so, so I can see how to deal with it. Thanks,

Hi! You can find lots of .pslg files in test directory: jopenvoronoi-test/src/test/resources.

Basically, it is simply some gzipped XML, listing points and lines connecting them. For example, here's ungzipped xml for Moore's curve of order 1:

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<PSLG>
  <PointSites>
    <PointSite idx="0" x="-0.7" y="0.7"/>
    <PointSite idx="1" x="-0.6999999999999998" y="-0.7"/>
    <PointSite idx="2" x="0.7000000000000001" y="-0.7"/>
    <PointSite idx="3" x="0.7000000000000002" y="0.7"/>
  </PointSites>
  <LineSites>
    <LineSite source_idx="1" target_idx="0"/>
    <LineSite source_idx="2" target_idx="1"/>
    <LineSite source_idx="3" target_idx="2"/>
  </LineSites>
</PSLG>

Thanks Rogach,
a couple of questions:

  1. Is the idx necessarily consecutive, or it can be any value? As I am
    interested in using inputs from a GIS, I need to convert the data somehow
    and this is an important consideration.
  2. What is the coordinate system (axis directions). Or does it not care?
  3. IS there a way to output some such format, or only the svg as in the
    example? Again, I will want to go back to a gis format ultimately. I am
    also looking into finding a way to get the resulting voronoi polygons as
    faces (Polygons), by preference tagged with the id of the generator.

Cheers and thanks for the great tool,
M.

On Tue, Aug 18, 2015 at 9:01 AM, Rogach notifications@github.com wrote:

Hi! You can find lots of .pslg files in test directory:
jopenvoronoi-test/src/test/resources
https://github.com/Rogach/jopenvoronoi/tree/master/jopenvoronoi-test/src/test/resources
.

Basically, it is simply some gzipped XML, listing points and lines
connecting them. For example, here's ungzipped xml for Moore's curve of
order 1:


Reply to this email directly or view it on GitHub
#1 (comment).

  1. No, it doesn't care - as long as it is integer and unique for this point.
  2. Planar XY, otherwise it doesn't matter. One important consideration - both X and Y must be in (-1,1) range, so you may need to scale your points before running the algorithm and rescale them back afterwards.
  3. The internal workings are extremely simple - basically, you only have points and edges between them. I actually think that it will be easier for you to use programmatic diagram building instead of messing with PSLG (it was added for testing anyway). This way, you will have maximum flexibility while retrieving data from GIS and outputting it back. Building the diagram is simple:
VoronoiDiagram vd = new VoronoiDiagram();
Vertex v1 = vd.insert_point_side(new Point(0, 0));
Vertex v2 = vd.insert_point_side(new Point(1, 1));
Vertex v3 = vd.insert_point_side(new Point(1, 0));
vd.insert_line_site(v1, v2);
vd.insert_line_site(v2, v3);
vd.insert_line_site(v3, v1);

And outputting it becomes:

HalfEdgeDiagram g = vd.get_graph_reference();
for (Vertex v : g.vertices) {
  // v.position.x, v.position.y
}
for (Edge e : g.edges) {
  if (e.valid) {
    Vertex src = e.source;
    Vertex trg = e.target;
    // use src.position.x to access X coordinate of edge start
    switch(e.type) {
      case LINESITE:
      case PARABOLA:
      case LINELINE:
      case PARA_LINELINE:
      // etc.
    }
  }
}

You can look in SvgOutput.java for specifics on edge output.

You're welcome :)

Very cool, thanks.
I assume there is no way to know that certain graphical elements together
compose the voronoi polygon around a certain generator, right? They are
just the atomic elements - lines, parabolas etc..?

Thanks,
M.

On Tue, Aug 18, 2015 at 12:58 PM, Rogach notifications@github.com wrote:

  1. No, it doesn't care - as long as it is integer and unique for this
    point.
  2. Planar XY, otherwise it doesn't matter. One important consideration
  3. both X and Y must be in (-1,1) range, so you may need to scale your
    points before running the algorithm and rescale them back afterwards.
  4. The internal workings are extremely simple - basically, you only
    have points and edges between them. I actually think that it will be easier
    for you to use programmatic diagram building instead of messing with PSLG
    (it was added for testing anyway). This way, you will have maximum
    flexibility while retrieving data from GIS and outputting it back. Building
    the diagram is simple:

VoronoiDiagram vd = new VoronoiDiagram();Vertex v1 = vd.insert_point_side(new Point(0, 0));Vertex v2 = vd.insert_point_side(new Point(1, 1));Vertex v3 = vd.insert_point_side(new Point(1, 0));
vd.insert_line_site(v1, v2);
vd.insert_line_site(v2, v3);
vd.insert_line_site(v3, v1);

And outputting it becomes:

HalfEdgeDiagram g = vd.get_graph_reference();for (Vertex v : g.vertices) {
// v.position.x, v.position.y
}for (Edge e : g.edges) {
if (e.valid) {
Vertex src = e.source;
Vertex trg = e.target;
// use src.position.x to access X coordinate of edge start
switch(e.type) {
case LINESITE:
case PARABOLA:
case LINELINE:
case PARA_LINELINE:
// etc.
}
}
}

You can look in (SvgOutput.java)[
https://github.com/Rogach/jopenvoronoi/blob/master/jopenvoronoi-main/src/main/java/org/rogach/jopenvoronoi/SvgOutput.java#L69]
for specifics on edge output.

You're welcome :)


Reply to this email directly or view it on GitHub
#1 (comment).

No, you can do that. From edges you can use .source or .target to get vertices, and from vertices you can use .out_edges or .in_edges to get edges.