How can I get a dictionary of cells from this Voronoi Diagram data?

后端 未结 5 1246
[愿得一人]
[愿得一人] 2021-02-07 13:17

Using the voronoi/delaunay diagram generation library found in this program, which is based on Fortune\'s original implementation of his algorithm, with a random set of points a

5条回答
  •  耶瑟儿~
    2021-02-07 13:43

    Fortune's algorithm is O(n log n) - but your code will be O(n^2), if you try to reconstruct cells brute-force fashion as proposed by Alink.

    The starting point for my answer is that what you are using to generate the cells is not a library, but rather is just a class written to neatly wrap up the code originally presented by Fortune himself, and not actually a mature library. So, the author in fact hasn't anticipated your needs, and although the information you want has been computed, it isn't accessible.

    Internally, your input points are stored as instances of the "Site" struct, and the algorithm proceeds to create half-edges, each of which maintains a reference "vertex" which is a pointer to the Site it encloses. Stepping along half-edges you naturally circumnavigate the enclosed Site - exactly what you need.

    To access this data, I suggested modifying or extending the VoronoiDiagramGenerator class; I would do it by creating a hash table with Site pointers as the key and a single HalfEdge pointer as the value. Then, modify the generateVoroni method, inserting your new code immediately following the call to voronoi:

    For each HalfEdge in ELHash
             Get table entry for current half edge's Site
             If site in table has null HalfEdge reference
                set current HalfEdge reference
             End If
    End For each
    

    ...and there is your dictionary. That single half-edge will allow you to "walk" the perimeter of the polygon enclosing the related site, which I think is what you asked for. Your next problem will be to efficiently discover which polygon encloses some new data point - but that is another question :-). I hope you'll consider sharing your completed class - it should be a significantly more useful than the base class.

    Edit: Here is an excellent presentation descibing all said above in pictures: http://ima.udg.es/~sellares/ComGeo/Vor2D_1.ppt:

    • definition of Voronoy Diagram
    • tree of of half-edges (see pics. below)
    • Fortunes algorithm in pictures

    And here is a C# implementation which could help you to retrieve the dictionary, as proposed above: http://www.codeproject.com/Articles/11275/Fortune-s-Voronoi-algorithm-implemented-in-C

    Slide 31 Slide 32 Slide 33 Slide 34

提交回复
热议问题