Class VoronoiTreemap
- java.lang.Object
-
- com.macrofocus.treemap.originalfastvoronoi.VoronoiTreemap
-
- All Implemented Interfaces:
StatusObject,VoronoiTreemapInterface,java.lang.Iterable<VoroNode>
public class VoronoiTreemap extends java.lang.Object implements java.lang.Iterable<VoroNode>, StatusObject, VoronoiTreemapInterface
Main Voronoi Treemap class implementing the Voronoi Treemap interface and maintaining the settings.
-
-
Field Summary
Fields Modifier and Type Field Description protected doubleerrorAreaThresholdprotected booleanpreflowFinishedprotected VoroNoderoot
-
Constructor Summary
Constructors Constructor Description VoronoiTreemap()VoronoiTreemap(StatusObject statusObject)when a node is finished the status object is notified.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclear()Clears the used datastructures.voidcompute()After setting at least the rootPolygon and the treeStructure(seeVoronoiTreemapInterface.setTreeAndWeights(PolygonSimple, ArrayList, ArrayList, ArrayList)), the voronoi Treemap can be computed.protected VoroNodecreateVoroNode(java.util.HashMap<java.lang.Integer,VoroNode> idToNode, java.util.ArrayList<java.lang.Integer> adjacencyLine)voidfinished()voidfinishedNode(int Node, int layer, int[] children, PolygonSimple[] polygons)booleangetAggressiveMode()true: aggressive weight modification false: normal weight modificationdoublegetCancelErrorThreshold()maximal error threshold to cancel the optimization process.booleangetCancelOnMaxIteration()booleangetCancelOnThreshold()booleangetGuaranteeValidCells()intgetNumberMaxIterations()the maximal number of iterations.doublegetPreflowIncrease()doublegetPreflowPercentage()longgetRandomSeed()Seed which is used for random initialization of the sites.PolygonSimplegetRootPolygon()Returns the root polygon.booleangetShowLeafs()doublegetShrinkPercentage()StatusObjectgetStatusObject()booleangetUseBorder()booleangetUseExtrapolation()protected voidinit()protected voidinitVoroNodes()booleanisUseNegativeWeights()Return whether negative weights for the sites are allowed.java.util.Iterator<VoroNode>iterator()voidsetAggressiveMode(boolean mode)the aggressive mode modifies the weights of the sites very aggressively and is not 100% stable (some cells can get empty), anyway sometimes it yields better local minima.voidsetAreaGoals(java.util.ArrayList<Tuple2ID> areaGoals)Sets a weighting for each nodes which influences the final area the node polygon has.voidsetCancelOnMaxIteration(boolean cancelOnMaxIterat)true: The optimization process is canceled when the maximal iteration number is reached.voidsetCancelOnThreshold(boolean cancelOnThreshold)true: the optimization process is canceled when the area error is below the given threshold.voidsetGuaranteeValidCells(boolean guaranteeInvariant)true: guarantees that the weight adaption does not cause empty cells.voidsetNumberMaxIterations(int numberMaxIterations)Sets the default maximal number of iterations done in a single level computation.voidsetNumberThreads(int numberThreads)If possible the given number of threads will be started to speed up the optimization process.voidsetPreflowIncrease(double preflowIncrease)voidsetPreflowPercentage(double preflowPercentage)If the desire of a cell (site) to increase its area is above this percentage, then this cell pushes the other cells away.voidsetRandomSeed(long seed)Sets the seed for the random position generator which is used to initialize the sites.voidsetReferenceMap(java.util.ArrayList<Tuple3ID> relativePositions)ReferenceMap, which consists of a relative x,y position for each node: each coordinate must be in the range between [0...1]voidsetRootPolygon(PolygonSimple rootPolygon)Sets the convex root polygon in which the treemap is computed.voidsetRootRectangle(double x, double y, double width, double height)Sets the a rectangle (as root polygon) in which the treemap is computed.protected voidsetSettingsToVoroNode(VoroNode node)voidsetShrinkPercentage(double shrinkPercentage)Sets the factor which scales every iteration, so 1-shrinkPercentage is equally the border percentage.voidsetStatusObject(StatusObject statusObject)This status object is notified when the children of a node are processed and when the whole computation has finished.voidsetTree(java.util.ArrayList<java.util.ArrayList<java.lang.Integer>> treeStructure)Sets the tree.voidsetTreeAndWeights(PolygonSimple rootPolygon, java.util.ArrayList<java.util.ArrayList<java.lang.Integer>> treeStructure, java.util.ArrayList<Tuple2ID> areaGoals, java.util.ArrayList<Tuple3ID> relativePositions)All necessary things are set here such that a Voronoi Treemap can be computed.voidsetUseBorder(boolean useBorder)Sets whether there borders are added for every iteration level or not.voidsetUseExtrapolation(boolean useExtrapolation)Activates the speed up heuristic which uses some kind of force to make more space for big cells.voidsetUseNegativeWeights(boolean use)set usage of negative weights for the sites.
-
-
-
Field Detail
-
root
protected VoroNode root
-
errorAreaThreshold
protected double errorAreaThreshold
-
preflowFinished
protected boolean preflowFinished
-
-
Constructor Detail
-
VoronoiTreemap
public VoronoiTreemap(StatusObject statusObject)
when a node is finished the status object is notified.
-
VoronoiTreemap
public VoronoiTreemap()
-
-
Method Detail
-
init
protected void init()
-
initVoroNodes
protected void initVoroNodes()
-
compute
public void compute()
Description copied from interface:VoronoiTreemapInterfaceAfter setting at least the rootPolygon and the treeStructure(seeVoronoiTreemapInterface.setTreeAndWeights(PolygonSimple, ArrayList, ArrayList, ArrayList)), the voronoi Treemap can be computed. For every computed Node finishedNode(...) will be called in the StatusObject. If the computation is completed finished() will be called in the Statusobject.- Specified by:
computein interfaceVoronoiTreemapInterface
-
setSettingsToVoroNode
protected void setSettingsToVoroNode(VoroNode node)
-
setTreeAndWeights
public void setTreeAndWeights(PolygonSimple rootPolygon, java.util.ArrayList<java.util.ArrayList<java.lang.Integer>> treeStructure, java.util.ArrayList<Tuple2ID> areaGoals, java.util.ArrayList<Tuple3ID> relativePositions)
Description copied from interface:VoronoiTreemapInterfaceAll necessary things are set here such that a Voronoi Treemap can be computed. AreaGoals and refereceMapPositions can be null.- Specified by:
setTreeAndWeightsin interfaceVoronoiTreemapInterface
-
createVoroNode
protected final VoroNode createVoroNode(java.util.HashMap<java.lang.Integer,VoroNode> idToNode, java.util.ArrayList<java.lang.Integer> adjacencyLine)
-
getShowLeafs
public boolean getShowLeafs()
- Specified by:
getShowLeafsin interfaceVoronoiTreemapInterface
-
iterator
public java.util.Iterator<VoroNode> iterator()
- Specified by:
iteratorin interfacejava.lang.Iterable<VoroNode>
-
finished
public void finished()
- Specified by:
finishedin interfaceStatusObject
-
setShrinkPercentage
public void setShrinkPercentage(double shrinkPercentage)
Description copied from interface:VoronoiTreemapInterfaceSets the factor which scales every iteration, so 1-shrinkPercentage is equally the border percentage.- Specified by:
setShrinkPercentagein interfaceVoronoiTreemapInterface- Parameters:
shrinkPercentage- preferred between 0 < shrinkPercentage <= 1
-
getShrinkPercentage
public double getShrinkPercentage()
Description copied from interface:VoronoiTreemapInterface- Specified by:
getShrinkPercentagein interfaceVoronoiTreemapInterface- Returns:
-
setUseBorder
public void setUseBorder(boolean useBorder)
Description copied from interface:VoronoiTreemapInterfaceSets whether there borders are added for every iteration level or not.- Specified by:
setUseBorderin interfaceVoronoiTreemapInterface
-
getUseBorder
public boolean getUseBorder()
Description copied from interface:VoronoiTreemapInterface- Specified by:
getUseBorderin interfaceVoronoiTreemapInterface- Returns:
-
setNumberMaxIterations
public void setNumberMaxIterations(int numberMaxIterations)
Description copied from interface:VoronoiTreemapInterfaceSets the default maximal number of iterations done in a single level computation.- Specified by:
setNumberMaxIterationsin interfaceVoronoiTreemapInterface
-
getNumberMaxIterations
public int getNumberMaxIterations()
Description copied from interface:VoronoiTreemapInterfacethe maximal number of iterations.- Specified by:
getNumberMaxIterationsin interfaceVoronoiTreemapInterface- Returns:
- cancelOnMaxIterat
-
setPreflowPercentage
public void setPreflowPercentage(double preflowPercentage)
Description copied from interface:VoronoiTreemapInterfaceIf the desire of a cell (site) to increase its area is above this percentage, then this cell pushes the other cells away. This option reduces the number of needed iteration if there is high variance in the desired cell sizes.- Specified by:
setPreflowPercentagein interfaceVoronoiTreemapInterface
-
getPreflowPercentage
public double getPreflowPercentage()
Description copied from interface:VoronoiTreemapInterface- Specified by:
getPreflowPercentagein interfaceVoronoiTreemapInterface- Returns:
-
setPreflowIncrease
public void setPreflowIncrease(double preflowIncrease)
- Specified by:
setPreflowIncreasein interfaceVoronoiTreemapInterface- Parameters:
preflowIncrease- the preflowIncrease to set
-
getPreflowIncrease
public double getPreflowIncrease()
- Specified by:
getPreflowIncreasein interfaceVoronoiTreemapInterface- Returns:
- the preflowIncrease
-
setUseExtrapolation
public void setUseExtrapolation(boolean useExtrapolation)
Description copied from interface:VoronoiTreemapInterfaceActivates the speed up heuristic which uses some kind of force to make more space for big cells.- Specified by:
setUseExtrapolationin interfaceVoronoiTreemapInterface- Parameters:
useExtrapolation- the useExtrapolation to set
-
getUseExtrapolation
public boolean getUseExtrapolation()
Description copied from interface:VoronoiTreemapInterface- Specified by:
getUseExtrapolationin interfaceVoronoiTreemapInterface- Returns:
- the useExtrapolation
-
setCancelOnThreshold
public void setCancelOnThreshold(boolean cancelOnThreshold)
Description copied from interface:VoronoiTreemapInterfacetrue: the optimization process is canceled when the area error is below the given threshold.- Specified by:
setCancelOnThresholdin interfaceVoronoiTreemapInterface- Parameters:
cancelOnThreshold- the cancelOnThreshold to set
-
getCancelOnThreshold
public boolean getCancelOnThreshold()
Description copied from interface:VoronoiTreemapInterface- Specified by:
getCancelOnThresholdin interfaceVoronoiTreemapInterface- Returns:
- the cancelOnThreshold
-
setCancelOnMaxIteration
public void setCancelOnMaxIteration(boolean cancelOnMaxIterat)
Description copied from interface:VoronoiTreemapInterfacetrue: The optimization process is canceled when the maximal iteration number is reached.- Specified by:
setCancelOnMaxIterationin interfaceVoronoiTreemapInterface- Parameters:
cancelOnMaxIterat- the cancelOnMaxIterat to set
-
getCancelOnMaxIteration
public boolean getCancelOnMaxIteration()
- Specified by:
getCancelOnMaxIterationin interfaceVoronoiTreemapInterface
-
setRootPolygon
public void setRootPolygon(PolygonSimple rootPolygon)
Description copied from interface:VoronoiTreemapInterfaceSets the convex root polygon in which the treemap is computed. The result will always be included into the root polygon. Currently the root polygon has to be convex, if you have a fast implementation for the intersection of non convex polygons, I could easily extend the library to simple polygons.- Specified by:
setRootPolygonin interfaceVoronoiTreemapInterface- Parameters:
rootPolygon- the root Polygon to be set (must be convex currently)
-
setRootRectangle
public void setRootRectangle(double x, double y, double width, double height)Description copied from interface:VoronoiTreemapInterfaceSets the a rectangle (as root polygon) in which the treemap is computed.- Specified by:
setRootRectanglein interfaceVoronoiTreemapInterface- Parameters:
x- x-coordinate of the upper left point of the rectangley- y-coordinate of the upper left point of the rectanglewidth- width of the rectangleheight- height of the rectangle
-
getRootPolygon
public PolygonSimple getRootPolygon()
Description copied from interface:VoronoiTreemapInterfaceReturns the root polygon.- Specified by:
getRootPolygonin interfaceVoronoiTreemapInterface- Returns:
- the rootPolygon
-
setGuaranteeValidCells
public void setGuaranteeValidCells(boolean guaranteeInvariant)
Description copied from interface:VoronoiTreemapInterfacetrue: guarantees that the weight adaption does not cause empty cells. false:computation is approx. 30 % faster, but exception could be thrown in the optimization process- Specified by:
setGuaranteeValidCellsin interfaceVoronoiTreemapInterface- Parameters:
guaranteeInvariant- guarantee non empty cells
-
getGuaranteeValidCells
public boolean getGuaranteeValidCells()
Description copied from interface:VoronoiTreemapInterface- Specified by:
getGuaranteeValidCellsin interfaceVoronoiTreemapInterface- Returns:
- the guaranteeInvariant
-
setNumberThreads
public void setNumberThreads(int numberThreads)
Description copied from interface:VoronoiTreemapInterfaceIf possible the given number of threads will be started to speed up the optimization process. Usually this is possible after the computation of the first hierarchy level has been finished.- Specified by:
setNumberThreadsin interfaceVoronoiTreemapInterface- Parameters:
numberThreads- the numberThreads to set
-
setStatusObject
public void setStatusObject(StatusObject statusObject)
Description copied from interface:VoronoiTreemapInterfaceThis status object is notified when the children of a node are processed and when the whole computation has finished.- Specified by:
setStatusObjectin interfaceVoronoiTreemapInterface- Parameters:
statusObject- the tellTheEndObject to set
-
getStatusObject
public StatusObject getStatusObject()
Description copied from interface:VoronoiTreemapInterface- Specified by:
getStatusObjectin interfaceVoronoiTreemapInterface- Returns:
-
finishedNode
public void finishedNode(int Node, int layer, int[] children, PolygonSimple[] polygons)- Specified by:
finishedNodein interfaceStatusObject
-
setAreaGoals
public void setAreaGoals(java.util.ArrayList<Tuple2ID> areaGoals)
Description copied from interface:VoronoiTreemapInterfaceSets a weighting for each nodes which influences the final area the node polygon has. the weightings are normalized so that the sum over the weightings of descendant nodes equals to one. this function must be called after the tree structure is defined (setTree(...)).- Specified by:
setAreaGoalsin interfaceVoronoiTreemapInterface- Parameters:
areaGoals- Tupel2ID with (NodeId, weight)
-
setReferenceMap
public void setReferenceMap(java.util.ArrayList<Tuple3ID> relativePositions)
Description copied from interface:VoronoiTreemapInterfaceReferenceMap, which consists of a relative x,y position for each node: each coordinate must be in the range between [0...1]- Specified by:
setReferenceMapin interfaceVoronoiTreemapInterface- Parameters:
relativePositions- Tupel3ID with (NodeId, relative x, relative y), x,y in range [0,1]
-
setTree
public void setTree(java.util.ArrayList<java.util.ArrayList<java.lang.Integer>> treeStructure)
Description copied from interface:VoronoiTreemapInterfaceSets the tree.- Specified by:
setTreein interfaceVoronoiTreemapInterface- Parameters:
treeStructure- defines a tree by an adjacency list, node a has children b,c,d (list(a,b,c,d))
-
isUseNegativeWeights
public boolean isUseNegativeWeights()
Description copied from interface:VoronoiTreemapInterfaceReturn whether negative weights for the sites are allowed. Negative weights should result in a faster convergence.- Specified by:
isUseNegativeWeightsin interfaceVoronoiTreemapInterface- Returns:
-
setUseNegativeWeights
public void setUseNegativeWeights(boolean use)
Description copied from interface:VoronoiTreemapInterfaceset usage of negative weights for the sites. Negative weights should result in a faster convergence.- Specified by:
setUseNegativeWeightsin interfaceVoronoiTreemapInterface
-
clear
public void clear()
Description copied from interface:VoronoiTreemapInterfaceClears the used datastructures.- Specified by:
clearin interfaceVoronoiTreemapInterface
-
setAggressiveMode
public void setAggressiveMode(boolean mode)
Description copied from interface:VoronoiTreemapInterfacethe aggressive mode modifies the weights of the sites very aggressively and is not 100% stable (some cells can get empty), anyway sometimes it yields better local minima.- Specified by:
setAggressiveModein interfaceVoronoiTreemapInterface
-
getAggressiveMode
public boolean getAggressiveMode()
Description copied from interface:VoronoiTreemapInterfacetrue: aggressive weight modification false: normal weight modification- Specified by:
getAggressiveModein interfaceVoronoiTreemapInterface- Returns:
-
setRandomSeed
public void setRandomSeed(long seed)
Description copied from interface:VoronoiTreemapInterfaceSets the seed for the random position generator which is used to initialize the sites.- Specified by:
setRandomSeedin interfaceVoronoiTreemapInterface
-
getRandomSeed
public long getRandomSeed()
Description copied from interface:VoronoiTreemapInterfaceSeed which is used for random initialization of the sites.- Specified by:
getRandomSeedin interfaceVoronoiTreemapInterface- Returns:
-
getCancelErrorThreshold
public double getCancelErrorThreshold()
Description copied from interface:VoronoiTreemapInterfacemaximal error threshold to cancel the optimization process.- Specified by:
getCancelErrorThresholdin interfaceVoronoiTreemapInterface- Returns:
-
-