public class DynamicObstacleDecomposition extends Object implements IObstaclePartition, IDynamicDecomposition
IObstaclePartition
that decomposes its area dynamically.
The partitioning strategy is based on binary space partitioning. It divides the partition space recursively in two cells
until each cell is completely covered by one or more Obstacle
s or completely empty.
Constructor and Description |
---|
DynamicObstacleDecomposition()
Constructs a new instance of
DynamicObstacleDecomposition . |
Modifier and Type | Method and Description |
---|---|
void |
addDynamicDecompositionListener(IDecompositionListener listener)
Adds the given
dynamic decomposition listener to receive PartitionCell
subdivision and creation events from this decomposition. |
void |
clear()
Clears the partition data such that the
DynamicObstacleDecomposition can be reused and initialized
with new Obstacle s. |
protected void |
fireCreateCellEvent(PartitionCell createdCell)
Notifies all registered
dynamic decomposition listeners that the given partition cell
has been created. |
protected void |
fireFinalizeCellEvent(PartitionCell finalizedCell)
Notifies all registered
dynamic decomposition listeners that the given partition cell
has been finalized. |
protected void |
fireSubdividedEvent(PartitionCell cell,
List<Object> subCells)
Notifies all registered
dynamic decomposition listeners of a subdivision of a given
partition cell . |
YRectangle |
getBounds()
Gets the bounds of the original rectangular area that is being partitioned.
|
List<Object> |
getCells(Obstacle obstacle)
Returns all
partition cells that are completely covered by the given Obstacle . |
List<Object> |
getCells(YRectangle rect)
Returns a list of all
PartitionCell s that intersect or cover the given rectangle. |
double |
getCutObstacleCost()
Gets the costs incurred for every
Obstacle that must be cut in a subdivision. |
protected double |
getGeometricCutCosts(double cut,
double min,
double max,
double orthogonalMin,
double orthogonalMax)
Calculates the cost of a cut with respect to the geometry of the sub-cells.
|
List<Object> |
getNeighbors(PartitionCell cell)
Returns the neighbor
partition cells of the given cell. |
protected double |
getObstacleCutCosts(int numObstaclesInFirstHalf,
int numObstaclesInSecondHalf,
int numObstaclesOnCut)
Calculates the cost of a cut with respect to the subdivided obstacles.
|
List<Object> |
getObstacles(PartitionCell cell)
Returns all
Obstacle s that cover the given partition cell . |
double |
getUnbalancedObstaclesCost()
Gets the costs incurred if the distribution after a subdivision of obstacles is unbalanced in sub-cells.
|
double |
getUnbalancedRatioCost()
Gets the costs incurred if the subdivision produces unbalanced rectangles.
|
void |
init(List<Object> obstacles,
YRectangle partitionBounds)
Initializes this
DynamicObstacleDecomposition instance with the given obstacles and partition bounds. |
void |
removeDynamicDecompositionListener(IDecompositionListener listener)
Removes the given
dynamic decomposition listener such that it no longer receives PartitionCell
subdivision and creation events from this decomposition. |
void |
setCutObstacleCost(double value)
Sets the costs incurred for every
Obstacle that must be cut in a subdivision. |
void |
setUnbalancedObstaclesCost(double value)
Sets the costs incurred if the distribution after a subdivision of obstacles is unbalanced in sub-cells.
|
void |
setUnbalancedRatioCost(double value)
Sets the costs incurred if the subdivision produces unbalanced rectangles.
|
public DynamicObstacleDecomposition()
DynamicObstacleDecomposition
.public void addDynamicDecompositionListener(IDecompositionListener listener)
dynamic decomposition listener
to receive PartitionCell
subdivision and creation events from this decomposition.
These events occur when the decomposition changes the partition by subdividing cells into sub-cells or when new cells are created.
addDynamicDecompositionListener
in interface IDynamicDecomposition
listener
- the dynamic decomposition listener to addIDecompositionListener
public void clear()
DynamicObstacleDecomposition
can be reused and initialized
with new Obstacle
s.clear
in interface IObstaclePartition
init(List, YRectangle)
protected void fireCreateCellEvent(PartitionCell createdCell)
dynamic decomposition listeners
that the given partition cell
has been created.
This method is also called in init(List, YRectangle)
.
createdCell
- the newly created cellIDecompositionListener
protected void fireFinalizeCellEvent(PartitionCell finalizedCell)
dynamic decomposition listeners
that the given partition cell
has been finalized.finalizedCell
- the cell that has been finalizedIDecompositionListener
protected void fireSubdividedEvent(PartitionCell cell, List<Object> subCells)
dynamic decomposition listeners
of a subdivision of a given
partition cell
.cell
- the cell that has been subdividedsubCells
- the new sub-cells resulting from the subdivision of the given cellIDecompositionListener
public YRectangle getBounds()
getBounds
in interface IPartition
public List<Object> getCells(Obstacle obstacle)
partition cells
that are completely covered by the given Obstacle
.getCells
in interface IObstaclePartition
obstacle
- the obstacle for which the covered cells will be returnedPartitionCell
instances that are completely covered by the given obstaclepublic List<Object> getCells(YRectangle rect)
PartitionCell
s that intersect or cover the given rectangle.getCells
in interface IPartition
rect
- the rectangular area whose (partially) covered cells will be returnedPartitionCell
s that (partially) cover the given rectangular areapublic double getCutObstacleCost()
Obstacle
that must be cut in a subdivision.
Values need to be non-negative.
IllegalArgumentException
- if the cost is negativesetCutObstacleCost(double)
protected double getGeometricCutCosts(double cut, double min, double max, double orthogonalMin, double orthogonalMax)
The cost can take values between 0
and 1
.
This method is called while a PartitionCell
is divided into upper and lower or left and right child cells
depending on the cut costs (during getCells(Obstacle)
, getCells(YRectangle)
and getNeighbors(PartitionCell)
methods).
cut
- the coordinate of the cutmin
- the left side of the subdivided cellmax
- the right side of the subdivided cellorthogonalMin
- the upper side of the subdivided cellorthogonalMax
- the lower side of the subdivided cellpublic List<Object> getNeighbors(PartitionCell cell)
partition cells
of the given cell.getNeighbors
in interface IPartition
cell
- the cell whose neighbors will be returnedprotected double getObstacleCutCosts(int numObstaclesInFirstHalf, int numObstaclesInSecondHalf, int numObstaclesOnCut)
The cost can take values between 0
and 1
.
This method is called while a PartitionCell
is divided into upper and lower or left and right child cells
depending on the cut costs (during getCells(Obstacle)
, getCells(YRectangle)
and getNeighbors(PartitionCell)
methods).
numObstaclesInFirstHalf
- the number of obstacles that lie completely in the first halfnumObstaclesInSecondHalf
- the number of obstacles that lie completely in the second halfnumObstaclesOnCut
- the number of obstacles that lie on the cutpublic List<Object> getObstacles(PartitionCell cell)
Obstacle
s that cover the given partition cell
.getObstacles
in interface IObstaclePartition
cell
- the partition cell for which the obstacles will be returnedObstacle
instances that cover the given cellpublic double getUnbalancedObstaclesCost()
Values need to be non-negative.
IllegalArgumentException
- if the cost is negativesetUnbalancedObstaclesCost(double)
public double getUnbalancedRatioCost()
Values need to be non-negative.
IllegalArgumentException
- if the cost is negativesetUnbalancedRatioCost(double)
public void init(List<Object> obstacles, YRectangle partitionBounds)
DynamicObstacleDecomposition
instance with the given obstacles and partition bounds.
This method must be called before any other method is invoked.
init
in interface IObstaclePartition
obstacles
- a list of Obstacle
objectspartitionBounds
- the bounds of the partitionIObstaclePartition.clear()
public void removeDynamicDecompositionListener(IDecompositionListener listener)
dynamic decomposition listener
such that it no longer receives PartitionCell
subdivision and creation events from this decomposition.removeDynamicDecompositionListener
in interface IDynamicDecomposition
listener
- the dynamic decomposition listener to removeIDecompositionListener
public void setCutObstacleCost(double value)
Obstacle
that must be cut in a subdivision.
Values need to be non-negative.
IllegalArgumentException
- if the cost is negativevalue
- a non-negative cut costgetCutObstacleCost()
public void setUnbalancedObstaclesCost(double value)
Values need to be non-negative.
IllegalArgumentException
- if the cost is negativevalue
- a non-negative cost valuegetUnbalancedObstaclesCost()
public void setUnbalancedRatioCost(double value)
Values need to be non-negative.
IllegalArgumentException
- if the cost is negativevalue
- a non-negative cost valuegetUnbalancedRatioCost()