public interface ILcdLabelConflictChecker 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 label placements and a list of label obstacles.
List<TLcdLabelPlacement> possible_placements = ...
List<TLcdLabelObstacle> label_obstacles = ...
// Create and reset a label conflict checker.
ILcdLabelConflictChecker conflict_checker = ...
conflict_checker.reset( new Rectangle( 0, 0, view_width, view_height ) );
// Add all label obstacles to the label conflict checker.
for ( TLcdLabelObstacle label_obstacle : label_obstacles )
conflict_checker.addLabelObstacle( label_obstacle );
// Create a list of label placements which do not overlap with label obstacles or other label placements.
List<TLcdLabelPlacement> result = new ArrayList<TLcdLabelPlacement>();
for ( TLcdLabelPlacement 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 |
ILcdLabelConflictChecker.Conflict
This class represents a conflict.
|
Modifier and Type | Method and Description |
---|---|
void |
addLabelObstacle(TLcdLabelObstacle aLabelObstacle)
Add the given obstacle to this label conflict checker.
|
void |
addLabelPlacement(TLcdLabelPlacement aPlacement)
Add the given label placement to this label conflict checker.
|
ILcdLabelConflictChecker.Conflict |
getConflict(TLcdLabelPlacement aPlacement)
Checks if the given label placement is valid, i.e. if it doesn't overlap with already added
label placements or label obstacles.
|
List<TLcdLabelObstacle> |
getLabelObstacles()
Returns all label obstacles that were added to (and not removed from) this conflict checker.
|
List<TLcdLabelPlacement> |
getLabelPlacements()
Returns all label placements that were added to (and not removed from) this conflict checker.
|
void |
removeLabelObstacle(TLcdLabelObstacle aLabelObstacle)
Removes the given obstacle from the conflict checker.
|
void |
removeLabelPlacement(TLcdLabelPlacement 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 addLabelObstacle(TLcdLabelObstacle aLabelObstacle)
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.
aLabelObstacle
- an obstacle.void removeLabelObstacle(TLcdLabelObstacle aLabelObstacle)
addLabelObstacle
.
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.
aLabelObstacle
- a label obstacle.List<TLcdLabelObstacle> getLabelObstacles()
void addLabelPlacement(TLcdLabelPlacement 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 removeLabelPlacement(TLcdLabelPlacement aPlacement)
addLabelPlacement
.
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<TLcdLabelPlacement> getLabelPlacements()
ILcdLabelConflictChecker.Conflict getConflict(TLcdLabelPlacement aPlacement)
When no conflict is found, the returned Conflict
should be null
.
aPlacement
- a label placement.null
if no conflict was found.