public abstract class BarnesHutLayout extends SourceBase implements Layout, org.miv.pherd.ParticleBoxListener
This base class creates the space decomposition method and manages the
main loop of the simulation. The simulation is made of NodeParticle
and EdgeSpring elements that are created and linked for you in
response to graph events received via the Sink interface. However
you have to provide an implementation of the abstract NodeParticle class
(by overriding the abstract method newNodeParticle(String)).
As almost all the repulsion/attraction forces computation is done in the
NodeParticle class, this is the most important one.
This algorithm can be configured using several attributes put on the graph :
SourceBase.ElementType| Constructor and Description |
|---|
BarnesHutLayout()
New 2D Barnes-Hut simulation.
|
BarnesHutLayout(boolean is3D)
New Barnes-Hut simulation.
|
BarnesHutLayout(boolean is3D,
Random randomNumberGenerator)
New Barnes-Hut simulation.
|
| Modifier and Type | Method and Description |
|---|---|
void |
clear()
Clears the whole nodes and edges structures
|
void |
compute()
Method to call repeatedly to compute the layout.
|
void |
edgeAdded(String graphId,
long time,
String edgeId,
String fromNodeId,
String toNodeId,
boolean directed)
An edge was inserted in graph.
|
void |
edgeAttributeAdded(String graphId,
long time,
String edgeId,
String attribute,
Object value)
A edge attribute was added.
|
void |
edgeAttributeChanged(String graphId,
long time,
String edgeId,
String attribute,
Object oldValue,
Object newValue)
A edge attribute was changed.
|
void |
edgeAttributeRemoved(String graphId,
long time,
String edgeId,
String attribute)
A edge attribute was removed.
|
void |
edgeRemoved(String graphId,
long time,
String edgeId)
An edge of graph was removed.The nodes the edge connects may already have
been removed from the graph.
|
void |
freezeNode(String id,
boolean on)
Freeze or un-freeze a node.
|
double |
getBarnesHutTheta()
The Barnes-Hut theta value used to know if we use a pole or not.
|
Point3 |
getCenterPoint() |
Energies |
getEnergies() |
double |
getForce()
The current layout force.
|
double |
getGravityFactor()
A gravity factor that attracts all nodes to the center of the layout to avoid flying components.
|
Point3 |
getHiPoint()
Largest point in space of the layout bounding box.
|
long |
getLastStepTime()
Time in nanoseconds used by the last call to step().
|
abstract String |
getLayoutAlgorithmName()
Name of the layout algorithm.
|
Point3 |
getLowPoint()
Smallest point in space of the layout bounding box.
|
int |
getNodeMovedCount()
How many nodes moved during the last step?.
|
double |
getQuality()
The current layout algorithm quality.
|
Random |
getRandom() |
org.miv.pherd.ParticleBox |
getSpatialIndex()
The spatial index as a n-tree.
|
double |
getStabilization()
Estimate of how close to stabilization the layout algorithm is.
|
double |
getStabilizationLimit()
Above which value a correct stabilization is achieved?
|
int |
getSteps()
Number of calls made to step() so far.
|
double |
getViewZone() |
void |
graphAttributeAdded(String graphId,
long time,
String attribute,
Object value)
A graph attribute was added.
|
void |
graphAttributeChanged(String graphId,
long time,
String attribute,
Object oldValue,
Object newValue)
A graph attribute was changed.
|
void |
graphAttributeRemoved(String graphId,
long time,
String attribute)
A graph attribute was removed.
|
void |
graphCleared(String graphId,
long time)
The whole graph was cleared.
|
boolean |
is3D() |
void |
moveNode(String id,
double x,
double y,
double z)
Move a node by force to a new location.
|
abstract NodeParticle |
newNodeParticle(String id)
Factory method to create node particles.
|
void |
nodeAdded(String graphId,
long time,
String nodeId)
A node was inserted in the given graph.
|
void |
nodeAttributeAdded(String graphId,
long time,
String nodeId,
String attribute,
Object value)
A node attribute was added.
|
void |
nodeAttributeChanged(String graphId,
long time,
String nodeId,
String attribute,
Object oldValue,
Object newValue)
A node attribute was changed.
|
void |
nodeAttributeRemoved(String graphId,
long time,
String nodeId,
String attribute)
A node attribute was removed.
|
void |
nodeRemoved(String graphId,
long time,
String nodeId)
A node was removed from the graph.
|
void |
particleAdded(Object id,
double x,
double y,
double z) |
void |
particleAdded(Object id,
double x,
double y,
double z,
Object mark) |
void |
particleAttributeChanged(Object id,
String attribute,
Object newValue,
boolean removed) |
void |
particleMarked(Object id,
Object mark) |
void |
particleMoved(Object id,
double x,
double y,
double z) |
void |
particleRemoved(Object id) |
double |
randomXInsideBounds() |
double |
randomYInsideBounds() |
double |
randomZInsideBounds() |
void |
setBarnesHutTheta(double theta)
Change the barnes-hut theta parameter allowing to know if we use a pole
or not.
|
void |
setForce(double value)
The general "speed" of the algorithm.
|
void |
setGravityFactor(double value)
Set the gravity factor that attracts all nodes to the center of the layout to avoid flying components.
|
void |
setQuality(double qualityLevel)
Set the overall quality level, a number between 0 and 1 with 1 the
highest quality available, but often with a slower computation.
|
void |
setSendNodeInfos(boolean on)
If true, node informations messages are sent for every node.
|
void |
setStabilizationLimit(double value)
Change the stabilization limit for this layout algorithm.
|
void |
shake()
Add a random vector whose length is 10% of the size of the graph to all
node positions.
|
void |
stepBegins(String graphId,
long time,
double step)
Since dynamic graphs are based on discrete event modifications, the
notion of step is defined to simulate elapsed time between events.
|
void |
stepFinished(int time) |
addAttributeSink, addElementSink, addSink, attributeSinks, clearAttributeSinks, clearElementSinks, clearSinks, elementSinks, removeAttributeSink, removeElementSink, removeSink, sendAttributeChangedEvent, sendAttributeChangedEvent, sendEdgeAdded, sendEdgeAdded, sendEdgeAttributeAdded, sendEdgeAttributeAdded, sendEdgeAttributeChanged, sendEdgeAttributeChanged, sendEdgeAttributeRemoved, sendEdgeAttributeRemoved, sendEdgeRemoved, sendEdgeRemoved, sendGraphAttributeAdded, sendGraphAttributeAdded, sendGraphAttributeChanged, sendGraphAttributeChanged, sendGraphAttributeRemoved, sendGraphAttributeRemoved, sendGraphCleared, sendGraphCleared, sendNodeAdded, sendNodeAdded, sendNodeAttributeAdded, sendNodeAttributeAdded, sendNodeAttributeChanged, sendNodeAttributeChanged, sendNodeAttributeRemoved, sendNodeAttributeRemoved, sendNodeRemoved, sendNodeRemoved, sendStepBegins, sendStepBeginsequals, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitaddAttributeSink, addElementSink, addSink, clearAttributeSinks, clearElementSinks, clearSinks, removeAttributeSink, removeElementSink, removeSinkpublic BarnesHutLayout()
public BarnesHutLayout(boolean is3D)
is3D - If true the simulation dimensions count is 3 else 2.public BarnesHutLayout(boolean is3D,
Random randomNumberGenerator)
is3D - If true the simulation dimensions count is 3 else 2.randomNumberGenerator - The random number generator to use.public Point3 getLowPoint()
LayoutgetLowPoint in interface Layoutpublic Point3 getHiPoint()
LayoutgetHiPoint in interface Layoutpublic double randomXInsideBounds()
public double randomYInsideBounds()
public double randomZInsideBounds()
public Point3 getCenterPoint()
public double getGravityFactor()
public void setGravityFactor(double value)
value - The new gravity factor, usually between 0 and 1.public org.miv.pherd.ParticleBox getSpatialIndex()
public long getLastStepTime()
LayoutgetLastStepTime in interface Layoutpublic abstract String getLayoutAlgorithmName()
LayoutgetLayoutAlgorithmName in interface Layoutpublic int getNodeMovedCount()
LayoutgetNodeMovedCount in interface Layoutpublic double getStabilization()
LayoutgetStabilization in interface Layoutpublic double getStabilizationLimit()
LayoutgetStabilizationLimit in interface Layoutpublic int getSteps()
Layoutpublic double getQuality()
LayoutgetQuality in interface Layoutpublic boolean is3D()
public double getForce()
Layoutpublic Random getRandom()
public Energies getEnergies()
public double getBarnesHutTheta()
public double getViewZone()
public void setSendNodeInfos(boolean on)
LayoutsetSendNodeInfos in interface Layouton - If true, send node informations to a "layout.info" attribute.public void setBarnesHutTheta(double theta)
theta - The new value for theta (between 0 and 1).public void setForce(double value)
Layoutpublic void setStabilizationLimit(double value)
Layout
The stabilization is a number between 0 and 1 that indicates how close to
stabilization (no nodes need to move) the layout is. The value 1 means
the layout is fully stabilized. Naturally this is often only an
indication only, for some algorithms, it is difficult to determine if the
layout is correct or acceptable enough. You can get the actual
stabilization limit using Layout.getStabilizationLimit(). You can get
the actual stabilization using Layout.getStabilization().
Be careful, most layout classes do not use the stabilization limit, this
number is mostly used the process that control the layout, like the
LayoutRunner for example. The stabilization limit is only an
indication with a default set for each layout algorithm. However this
default can be changed using this method, or by storing on the graph an
attribute "layout.stabilization-limit" (or "layout.stabilisation-limit").
The convention is that the value 0 means that the process controlling the layout will not stop the layout (will therefore not consider the stabilization limit). In other words the layout will compute endlessly.
setStabilizationLimit in interface Layoutvalue - The new stabilization limit, 0 means no need to stabilize.
Else a value larger than zero or equal to 1 is accepted.public void setQuality(double qualityLevel)
LayoutsetQuality in interface LayoutqualityLevel - The quality level, a number between 0 and 1.public void clear()
Layoutpublic void compute()
Layout
This method implements the layout algorithm proper. It must be called in
a loop, until the layout stabilizes. You can know if the layout is stable
by using the Layout.getNodeMovedCount() method that returns the number
of node that have moved during the last call to step().
The listener is called by this method, therefore each call to step() will also trigger layout events, allowing to reproduce the layout process graphically for example. You can insert the listener only when the layout stabilized, and then call step() anew if you do not want to observe the layout process.
public void shake()
Layoutpublic void moveNode(String id, double x, double y, double z)
Layoutpublic void freezeNode(String id, boolean on)
LayoutfreezeNode in interface Layoutid - The node identifier.on - If true the node is frozen.public void particleAdded(Object id, double x, double y, double z)
particleAdded in interface org.miv.pherd.ParticleBoxListenerpublic void particleMoved(Object id, double x, double y, double z)
particleMoved in interface org.miv.pherd.ParticleBoxListenerpublic void particleRemoved(Object id)
particleRemoved in interface org.miv.pherd.ParticleBoxListenerpublic void stepFinished(int time)
stepFinished in interface org.miv.pherd.ParticleBoxListenerpublic void particleAttributeChanged(Object id, String attribute, Object newValue, boolean removed)
particleAttributeChanged in interface org.miv.pherd.ParticleBoxListenerpublic void edgeAdded(String graphId, long time, String edgeId, String fromNodeId, String toNodeId, boolean directed)
ElementSinkedgeAdded in interface ElementSinkgraphId - Identifier of the graph where the edge was added.edgeId - Identifier of the added edge.fromNodeId - Identifier of the first node of the edge.toNodeId - Identifier of the second node of the edge.directed - If true, the edge is directed.public void nodeAdded(String graphId, long time, String nodeId)
ElementSinknodeAdded in interface ElementSinkgraphId - Identifier of the graph where the node was added.nodeId - Identifier of the added node.public void edgeRemoved(String graphId, long time, String edgeId)
ElementSinkedgeRemoved in interface ElementSinkgraphId - The graph where the edge will be removed.edgeId - The edge that will be removed.public void nodeRemoved(String graphId, long time, String nodeId)
ElementSinknodeRemoved in interface ElementSinkgraphId - Identifier of the graph where the node will be removed.nodeId - Identifier of the removed node.public void graphCleared(String graphId, long time)
ElementSinkgraphCleared in interface ElementSinkgraphId - The graph cleared.public void stepBegins(String graphId, long time, double step)
ElementSinkSince dynamic graphs are based on discrete event modifications, the notion of step is defined to simulate elapsed time between events. So a step is a event that occurs in the graph, it does not modify it but it gives a kind of timestamp that allow the tracking of the progress of the graph over the time.
This kind of event is useful for dynamic algorithms that listen to the dynamic graph and need to measure the time in the graph's evolution.
stepBegins in interface ElementSinkgraphId - Identifier of the graph where the step starts.time - A numerical value that may give a timestamp to track the
evolution of the graph over the time.public void graphAttributeAdded(String graphId, long time, String attribute, Object value)
AttributeSinkgraphAttributeAdded in interface AttributeSinkgraphId - Identifier of the graph where the attribute changed.attribute - The attribute name.value - The attribute new value.public void graphAttributeChanged(String graphId, long time, String attribute, Object oldValue, Object newValue)
AttributeSinkgraphAttributeChanged in interface AttributeSinkgraphId - Identifier of the graph where the attribute changed.attribute - The attribute name.oldValue - The attribute old value.newValue - The attribute new value.public void graphAttributeRemoved(String graphId, long time, String attribute)
AttributeSinkgraphAttributeRemoved in interface AttributeSinkgraphId - Identifier of the graph where the attribute was removed.attribute - The removed attribute name.public void nodeAttributeAdded(String graphId, long time, String nodeId, String attribute, Object value)
AttributeSinknodeAttributeAdded in interface AttributeSinkgraphId - Identifier of the graph where the change occurred.nodeId - Identifier of the node whose attribute changed.attribute - The attribute name.value - The attribute new value.public void nodeAttributeChanged(String graphId, long time, String nodeId, String attribute, Object oldValue, Object newValue)
AttributeSinknodeAttributeChanged in interface AttributeSinkgraphId - Identifier of the graph where the change occurred.nodeId - Identifier of the node whose attribute changed.attribute - The attribute name.oldValue - The attribute old value.newValue - The attribute new value.public void nodeAttributeRemoved(String graphId, long time, String nodeId, String attribute)
AttributeSinknodeAttributeRemoved in interface AttributeSinkgraphId - Identifier of the graph where the attribute was removed.nodeId - Identifier of the node whose attribute was removed.attribute - The removed attribute name.public void edgeAttributeAdded(String graphId, long time, String edgeId, String attribute, Object value)
AttributeSinkedgeAttributeAdded in interface AttributeSinkgraphId - Identifier of the graph where the change occurred.edgeId - Identifier of the edge whose attribute changed.attribute - The attribute name.value - The attribute new value.public void edgeAttributeChanged(String graphId, long time, String edgeId, String attribute, Object oldValue, Object newValue)
AttributeSinkedgeAttributeChanged in interface AttributeSinkgraphId - Identifier of the graph where the change occurred.edgeId - Identifier of the edge whose attribute changed.attribute - The attribute name.oldValue - The attribute old value.newValue - The attribute new value.public void edgeAttributeRemoved(String graphId, long time, String edgeId, String attribute)
AttributeSinkedgeAttributeRemoved in interface AttributeSinkgraphId - Identifier of the graph where the attribute was removed.edgeId - Identifier of the edge whose attribute was removed.attribute - The removed attribute name.public abstract NodeParticle newNodeParticle(String id)
id - The identifier of the new node/particle.Copyright © 2015. All rights reserved.