List of usage examples for org.apache.commons.math3.geometry.partitioning BSPTree BSPTree
public BSPTree()
From source file:edu.stanford.cfuller.imageanalysistools.util.VoronoiDiagram.java
/** * Constrcuts a new VoronoiDiagram from a list of input points. * * Each of these points will be assigned a unique region in the final diagram; * the ordering of the points determines the region label (1-indexed) in the diagram. * * @param pointsInput a List of Vector2D objects that describe the set of points * around which the diagram will be constructed. */// www . j ava2 s. c o m public VoronoiDiagram(List<Vector2D> pointsInput) { this.regionLookup = new java.util.HashMap<Vector2D, Integer>(); for (int i = 0; i < pointsInput.size(); i++) { regionLookup.put(pointsInput.get(i), i + 1); } this.diagram = new BSPTree<Euclidean2D>(); if (pointsInput.size() <= 1) { return; } List<PointPair> allPairs = new java.util.ArrayList<PointPair>(); for (int i = 0; i < pointsInput.size(); i++) { for (int j = i + 1; j < pointsInput.size(); j++) { allPairs.add(new PointPair(pointsInput.get(i), pointsInput.get(j))); } } java.util.Collections.sort(allPairs); divideRecursive(this.diagram, allPairs); for (Vector2D point : pointsInput) { BSPTree<Euclidean2D> node = this.diagram.getCell(point); node.setAttribute(this.regionLookup.get(point)); } }