GithubHelp home page GithubHelp logo

arlindnocaj / power-voronoi-diagram Goto Github PK

View Code? Open in Web Editor NEW
54.0 8.0 16.0 75 KB

standalone java library for computation of the weighted (power) voronoi diagram

License: GNU General Public License v3.0

Java 100.00%

power-voronoi-diagram's Introduction

Java Power Voronoi Diagram

Power Voronoi Diagram is a fast standalone java (minimum 1.6) library which computes a weighted Voronoi Diagram, called Power diagram.

(see http://en.wikipedia.org/wiki/Power_diagram)

The main difference to the ordinary Voronoi diagram is the possibility to set a positive weighting to each site which influences the corresponding Voronoi cells. If these weights are set to zero, the result is the ordinary Voronoi diagram.

Implementation

The implementation is based on the computation of a 3-dimensional convex hull, for which a randomized incremental algorithm is used, which is expected to run in O(n log n) time and needs O(n) space.

The following article contains most important references related to this implementation.

  • Arlind Nocaj, Ulrik Brandes, "Computing Voronoi Treemaps: Faster, Simpler, and Resolution-independent", Computer Graphics Forum, vol. 31, no. 3, June 2012, pp. 855-864

Usage

PowerDiagram diagram = new PowerDiagram();

// normal list based on an array
OpenList sites = new OpenList();

Random rand = new Random(100);
// create a root polygon which limits the voronoi diagram.
// here it is just a rectangle.

PolygonSimple rootPolygon = new PolygonSimple();
int width = 1000;
int height = 1000;
rootPolygon.add(0, 0);
rootPolygon.add(width, 0);
rootPolygon.add(width, height);
rootPolygon.add(0, height);

// create 100 points (sites) and set random positions in the rectangle defined above.
for (int i = 0; i < 100; i++) {
	Site site = new Site(rand.nextInt(width), rand.nextInt(width));
	// we could also set a different weighting to some sites
	// site.setWeight(30)
	sites.add(site);
}

// set the list of points (sites), necessary for the power diagram
diagram.setSites(sites);
// set the clipping polygon, which limits the power voronoi diagram
diagram.setClipPoly(rootPolygon);

// do the computation
diagram.computeDiagram();

// for each site we can no get the resulting polygon of its cell. 
// note that the cell can also be empty, in this case there is no polygon for the corresponding site.
for (int i=0;i<sites.size;i++){
	Site site=sites.array[i];
	PolygonSimple polygon=site.getPolygon();
}

maven (gradle sbt leiningen)

<repositories>
	<repository>
	    <id>jitpack.io</id>
	    <url>https://jitpack.io</url>
	</repository>
</repositories>

<dependency>
    <groupId>com.github.ArlindNocaj</groupId>
    <artifactId>power-voronoi-diagram</artifactId>
    <version>-SNAPSHOT</version>
</dependency>

For more info (see https://jitpack.io/#ArlindNocaj/power-voronoi-diagram)

License

Copyright (c) 2013 Arlind Nocaj, University of Konstanz.

All rights reserved. This program and the accompanying materials are made available under the terms of the GNU Public License v3.0 which accompanies this distribution, and is available at http://www.gnu.org/licenses/gpl.html

For distributors of proprietary software, other licensing is possible on request: [email protected]

Citation

This work is based on the publication below, please cite on usage.

  • Arlind Nocaj, Ulrik Brandes, "Computing Voronoi Treemaps: Faster, Simpler, and Resolution-independent", Computer Graphics Forum, vol. 31, no. 3, June 2012, pp. 855-864

power-voronoi-diagram's People

Contributors

arlindnocaj avatar culmat avatar sebkur avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

power-voronoi-diagram's Issues

Error at dublicated points

I try to dublicate first point - new SIte(400,200).
sites.add(new SIte(400,200)) - return true, but sites.get(i).getPolygon() return NullPointerException - Polygon doesn't calculatied for dublicatied points

Wrong result for simple?

import kn.uni.voronoitreemap.datastructure.OpenList;
import kn.uni.voronoitreemap.diagram.PowerDiagram;
import kn.uni.voronoitreemap.j2d.PolygonSimple;
import kn.uni.voronoitreemap.j2d.Site;

public class Diagrams {
public static void main(String[] args) {
// create a root polygon which limits the voronoi diagram
// here it's just rectangle
PolygonSimple rootPolygon = new PolygonSimple();
int width = 800;
int height = 800;
rootPolygon.add(0, 0);
rootPolygon.add(width, 0);
rootPolygon.add(width, height);
rootPolygon.add(0, height);

    OpenList sites = new OpenList();
    // add test points

    sites.add(new Site(400,200));
    sites.add(new Site(200,400));
    sites.add(new Site(400,400));
    sites.add(new Site(600,400));
    sites.add(new Site(400,600));

    PowerDiagram diagram = new PowerDiagram();
    diagram.setSites(sites);
    diagram.setClipPoly(rootPolygon);
    diagram.computeDiagram();
    PolygonSimple p;
    Site s;
    for (int i = 0; i < sites.size; i++) {
        s = sites.get(i);
        p = s.getPolygon();
        System.out.println("i: " + i + " " + s.getPoint() + " " + p.getNumPoints());
        for (int j = 0; j < p.getNumPoints(); j++)
            System.out.println("j: " + j + " x:" + p.getXPoints()[j] + " y:" + p.getYPoints()[j]);
        System.out.println();
    }
}

}

Output:

i: 0 (200.0,400.0) 4
j: 0 x:0.0 y:799.9999999999999
j: 1 x:0.0 y:0.0
j: 2 x:299.9999999999999 y:299.9999999999999
j: 3 x:299.99999999999983 y:499.9999999999999

i: 1 (400.0,400.0) 4
j: 0 x:299.9999999999999 y:299.9999999999999
j: 1 x:500.00000000000017 y:299.9999999999999
j: 2 x:500.0 y:499.9999999999999
j: 3 x:299.99999999999983 y:499.9999999999999

i: 2 (400.0,600.0) 7
j: 0 x:0.0 y:799.9999999999999
j: 1 x:299.99999999999983 y:499.9999999999999
j: 2 x:500.0 y:499.9999999999999
j: 3 x:800.0 y:799.9999999999999
j: 4 x:1045.4545454545455 y:1045.4545454545455
j: 5 x:400.0 y:1820.0
j: 6 x:-245.45454545454547 y:1045.4545454545455

i: 3 (600.0,400.0) 4
j: 0 x:800.0 y:800.0
j: 1 x:500.0 y:499.9999999999999
j: 2 x:500.00000000000017 y:299.9999999999999
j: 3 x:800.0 y:0.0

i: 4 (400.0,200.0) 4
j: 0 x:0.0 y:1.1368683772161603E-13
j: 1 x:800.0 y:0.0
j: 2 x:500.00000000000017 y:299.9999999999999

j: 3 x:299.9999999999999 y:299.9999999999999

Does this result is correct? ( x:1045.4545454545455 y:1045.4545454545455)?
Why order of items at OpenList was changed?
When rootPolygon is rootPolygon 1000*1000 - all work correctly.

License change

Hi Arlind,

Thank you for creating an excellent library! It's blazing fast and produces excellent results.

I am considering using it for a commercial project and I was wondering whether you would be open to releasing it under a more permissive open-source license (like MIT or Apache 2.0)

Please feel free to contact me at [email protected] to discuss any further details

Many thanks for considering!

Best,

Nikolay Samusik
Research Scientist
Stanford University

"Poly null of" error if next centroid is very close

Hi,

I know the insertion of duplicate sites/voronoi centroids is not supported and will lead to NullPointerExceptions when trying to access the Polygon of the duplicate site via duplSite.getPolygon().

Nevertheless, I get the same error when there are some sites/voronoi centroids very close to each other. The errors seem to occur when the distance between two sites is smaller than 2.0E-4.

Here are some system.out.printlns, where I am writing information about the site with a null polygon and their closest site/voronoi centroids to the console:

(This is from a VoronoiDiagram with 40k sites)


site_37314 [359.880278;51.5033]
no duplicate was found
closest distance for site[359.880278;51.5033]: 1.3800000306218863E-4
closestSite for site_37314 [359.880416;51.5033]
///////////////////////
site_38144 [-355.11748;52.3692]
no duplicate was found
closest distance for site[-355.11748;52.3692]: 1.4142136205919087E-4
closestSite for site_38144 [-355.11758;52.3691]
///////////////////////
site_38856 [-224.215;34.9946]
no duplicate was found
closest distance for site[-224.215;34.9946]: 1.9999999494757503E-4
closestSite for site_38856 [-224.215;34.9948]


Is there any chance for a fix? It wouldn't even be that much of a problem if I could access the neighbors of the specified site, but unfortunately the methods site.getNeighbors() and site.getOldNeighbors() also return null.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.