public class GraphPartition extends Object implements IPartition, IDynamicDecomposition, IDecompositionListener
GraphPartition
partitions the bounding box of a graph into rectangles using the graph elements as
Obstacle
s.
All Obstacle
s used during the partitioning are created
by
IGraphPartitionExtension
s. IGraphPartitionExtension
s have been registered
before using method IGraphPartitionExtension.preparePartition(PathSearchConfiguration, GraphPartition)
which is
called during the initialization
of a GraphPartition
.
The core partitioning is delegated to an IObstaclePartition
that is initialized
with these Obstacle
s.
If the IObstaclePartition
is of type IDynamicDecomposition
, GraphPartition
re-dispatches the
decomposition notifications to its extensions.
IGraphPartitionExtension
Constructor and Description |
---|
GraphPartition(IObstaclePartition partition)
Creates a new
GraphPartition instance using the given
delegate inner obstacle partition . |
Modifier and Type | Method and Description |
---|---|
void |
addDynamicDecompositionListener(IDecompositionListener listener)
Adds the given listener to the
GraphPartition . |
void |
clear()
Clears the
partition data such that the GraphPartition can be reused and initialized
with a new configuration. |
Obstacle |
createObstacle(YRectangle bounds,
Object data)
Creates and returns a new
Obstacle using the given bounds and data. |
YRectangle |
getBounds()
Gets the bounds of the original rectangular area that is being partitioned.
|
List<Object> |
getCells(Node node)
Returns all
PartitionCell s that are completely covered by the bounds of the given node. |
List<Object> |
getCells(YRectangle rect)
Returns a list of all
PartitionCell s that intersect or cover the given rectangle by delegating to the
corresponding method of the inner partition . |
List<Object> |
getNeighbors(PartitionCell cell)
Returns a list of all
PartitionCell s that are neighbors of the given cell, i.e., those cells that have a common border segment
with the given cell. |
List<Object> |
getNodes(PartitionCell cell)
Returns a list of all
Node s whose bounds intersect or cover the bounds of the given cell. |
Obstacle |
getObstacle(Object data)
Returns the
Obstacle that has been created earlier for the given data object. |
List<Object> |
getObstacles(PartitionCell cell)
Returns all
Obstacle s covering the given PartitionCell by delegating to the corresponding method of the
inner partition . |
protected IObstaclePartition |
getPartition()
Gets the delegate inner obstacle partition.
|
void |
init(PathSearchConfiguration configuration)
Initializes the
GraphPartition with the given graph instance based on the given configuration
used by path search algorithms. |
void |
onCellCreated(PartitionCell createdCell)
Re-dispatches the event of the creation of a new
PartitionCell to all registered
IDecompositionListener s. |
void |
onCellFinalized(PartitionCell finalizedCell)
Re-dispatches the event of having completed the process of subdivisions of a given
PartitionCell to all
registered IDecompositionListener s. |
void |
onCellSubdivided(PartitionCell cell,
List<Object> subCells)
Re-dispatches the event of the subdivision of a given
PartitionCell into several sub-cells to all registered
IDecompositionListener s. |
void |
removeDynamicDecompositionListener(IDecompositionListener listener)
Removes the given listener from the
GraphPartition . |
public GraphPartition(IObstaclePartition partition)
GraphPartition
instance using the given
delegate inner obstacle partition
.partition
- the delegate inner obstacle partitionpublic void addDynamicDecompositionListener(IDecompositionListener listener)
GraphPartition
.
The listener will be notified upon dynamic decomposition events. If it is a IGraphPartitionExtension
, method IGraphPartitionExtension.preparePartition(PathSearchConfiguration, GraphPartition)
is called during initialization
.
addDynamicDecompositionListener
in interface IDynamicDecomposition
listener
- the listener to be addedpublic void clear()
partition
data such that the GraphPartition
can be reused and initialized
with a new configuration.
All IGraphPartitionExtension
s are cleaned up
; partition listeners and
obstacles are removed
.
init(PathSearchConfiguration)
public Obstacle createObstacle(YRectangle bounds, Object data)
Obstacle
using the given bounds and data.
All obstacles created via this method are delegated to the inner partition
upon
initialization
.
bounds
- the bounds of the obstacledata
- the additional data that should be associated with the obstacleObstacle
using the given bounds and datapublic YRectangle getBounds()
This method delegates to the corresponding method of the inner partition
.
getBounds
in interface IPartition
IPartition.getBounds()
public List<Object> getCells(Node node)
PartitionCell
s that are completely covered by the bounds of the given node.IllegalArgumentException
- if the node is unknownnode
- the node for which the covered cells will be returnedPartitionCell
instances that are completely covered by the bounds of the given nodepublic List<Object> getCells(YRectangle rect)
PartitionCell
s that intersect or cover the given rectangle by delegating to the
corresponding method of the inner partition
.getCells
in interface IPartition
rect
- the rectangular area whose (partially) covered cells will be returnedPartitionCell
sIPartition.getCells(YRectangle)
public List<Object> getNeighbors(PartitionCell cell)
PartitionCell
s that are neighbors of the given cell, i.e., those cells that have a common border segment
with the given cell.getNeighbors
in interface IPartition
cell
- the cell whose neighbors will be returnedPartitionCell
s that are neighbors of the given cellpublic List<Object> getNodes(PartitionCell cell)
Node
s whose bounds intersect or cover the bounds of the given cell.cell
- the cellNode
s that are intersected by the given cellpublic Obstacle getObstacle(Object data)
Obstacle
that has been created earlier for the given data object.data
- the given data for which the obstacle will be returnedObstacle
that has been created earlier for the given data objectpublic List<Object> getObstacles(PartitionCell cell)
Obstacle
s covering the given PartitionCell
by delegating to the corresponding method of the
inner partition
.cell
- the cell whose obstacles will be returnedObstacle
s that cover the given cellIObstaclePartition.getObstacles(PartitionCell)
protected IObstaclePartition getPartition()
public void init(PathSearchConfiguration configuration)
GraphPartition
with the given graph instance based on the given configuration
used by path search algorithms.
Before calling this method, any old partitioning information must be cleared
.
This initialization method calls IGraphPartitionExtension.preparePartition(PathSearchConfiguration, GraphPartition)
of all registered extensions. Then, the inner delegate partition
is initialized passing all added
obstacles as well as the given graph's bounds extended by a small padding.
In the case where the delegate partition
is of type IDynamicDecomposition
, this GraphPartition
will also be added as IDecompositionListener
to it.
configuration
- the configuration used by path search algorithmsclear()
,
IGraphPartitionExtension.preparePartition(PathSearchConfiguration, GraphPartition)
,
addDynamicDecompositionListener(IDecompositionListener)
public void onCellCreated(PartitionCell createdCell)
PartitionCell
to all registered
IDecompositionListener
s.
This method is a callback after a PartitionCell
has been created.
onCellCreated
in interface IDecompositionListener
createdCell
- the newly created PartitionCell
public void onCellFinalized(PartitionCell finalizedCell)
PartitionCell
to all
registered IDecompositionListener
s.
This method is a callback after a PartitionCell
has been finalized and won't be further subdivided.
onCellFinalized
in interface IDecompositionListener
finalizedCell
- the cell that has been finalizedpublic void onCellSubdivided(PartitionCell cell, List<Object> subCells)
PartitionCell
into several sub-cells to all registered
IDecompositionListener
s.
This method is a callback after a PartitionCell
has been subdivided into several sub-cells.
onCellSubdivided
in interface IDecompositionListener
cell
- the cell that has been subdividedsubCells
- the sub-cells resulting from the subdivision of the given PartitionCell
public void removeDynamicDecompositionListener(IDecompositionListener listener)
GraphPartition
.
The listener will not be notified of dynamic decomposition events anymore.
removeDynamicDecompositionListener
in interface IDynamicDecomposition
listener
- the listener to be removed