public interface ILspLabelConflictChecker extends ILcdCloneable
The following code snippet shows a typical usage of this interface. Note : this code is only needed for labeling algorithm implementations.
// Given : a list of possible placements and a list of obstacles.
List<TLspLabelPlacement> possible_placements = ...
List<TLspLabelObstacle> obstacles = ...
// Create and reset a label conflict checker.
ILspLabelConflictChecker conflict_checker = ...
conflict_checker.reset( new Rectangle( 0, 0, view_width, view_height ) );
// Add all obstacles to the conflict checker.
for ( TLspLabelObstacle obstacle : obstacles )
conflict_checker.addLabelObstacle( obstacle );
// Create a list of placements which do not overlap with obstacles or other placements.
List<TLspLabelPlacement> result = new ArrayList<TLspLabelPlacement>();
for ( TLspLabelPlacement placement : possible_placements ) {
if ( conflict_checker.getConflict( placement ) == null ) {
// No conflicts.
conflict_checker.addLabelPlacement( placement );
result.add( placement );
}
}
Modifier and Type | Interface and Description |
---|---|
static class |
ILspLabelConflictChecker.Conflict
This class represents a conflict.
|
Modifier and Type | Method and Description |
---|---|
void |
addObstacle(TLspLabelObstacle aObstacle)
Add the given obstacle to this conflict checker.
|
void |
addPlacement(TLspLabelPlacement aPlacement)
Add the given label placement to this conflict checker.
|
ILspLabelConflictChecker.Conflict |
getConflict(TLspLabelPlacement aPlacement)
Checks if the given placement is valid, that is if it does not overlap with already added
placements or obstacles.
|
List<TLspLabelObstacle> |
getObstacles()
Returns all obstacles that were added to (and not removed from) this conflict checker.
|
List<TLspLabelPlacement> |
getPlacements()
Returns all label placements that were added to (and not removed from) this conflict checker.
|
void |
removeObstacle(TLspLabelObstacle aObstacle)
Removes the given obstacle from the conflict checker.
|
void |
removePlacement(TLspLabelPlacement aPlacement)
Removes the given label placement from the conflict checker.
|
void |
reset(Rectangle aViewBounds)
Resets the conflict checker.
|
clone
void reset(Rectangle aViewBounds)
aViewBounds
- the view bounds.void addObstacle(TLspLabelObstacle aObstacle)
getConflict
method can use the given obstacle to detect conflicts.
After calling this method, it is possible that this bounds conflict checker keeps a reference to the given obstacle. By consequence, the given obstacle should not be changed outside this method. The given obstacle cannot be changed inside this method.
Adding the same obstacle instance twice should have the exact same effect as adding the obstacle instance only once.
aObstacle
- an obstacle.void removeObstacle(TLspLabelObstacle aObstacle)
addObstacle
.
After calling this method, it is possible that this bounds conflict checker keeps a reference to the given obstacle. By consequence, the given obstacle should never be changed outside this method. The given obstacle cannot be changed inside this method.
aObstacle
- an obstacle.List<TLspLabelObstacle> getObstacles()
void addPlacement(TLspLabelPlacement aPlacement)
getConflict
method can use the given placement to detect conflicts.
After calling this method, it is possible that this bounds conflict checker keeps a reference to the given label placement. By consequence, the bounds information in the given placement should not be changed outside this method. The given label placement cannot be changed inside this method.
Adding the same label placement instance twice should have the exact same effect as adding the label placement instance only once.
aPlacement
- a label placement.void removePlacement(TLspLabelPlacement aPlacement)
addPlacement
.
After calling this method, it is possible that this bounds conflict checker keeps a reference to the given label placement. By consequence, the bounds inside the given label placement should never be changed outside this method. The given bounds cannot be changed inside this method.
aPlacement
- a label placement.List<TLspLabelPlacement> getPlacements()
ILspLabelConflictChecker.Conflict getConflict(TLspLabelPlacement aPlacement)
When no conflict is found, the returned Conflict
should be null
.
aPlacement
- a label placement.null
if no conflict was found.