public class TLspInPathLabelingAlgorithm extends ALspDiscreteLabelingAlgorithm
Labeling algorithm that tries to place labels inside a path and keeps them inside the view. This algorithm checks the painted paths that are within the view and tries to add labels to them. These are located within the area defined by the path. This algorithm is typically used for placing labels for polygons or other closed shapes.
Note that this implementation does not support "holes" in paths.
The used label painter must be an ILspStampLocationLabelPainter
.
If not, the label will not be placed. The placed label location will be a
TLspStampLabelLocation
.
This algorithm has a computational overhead because it keeps the label inside the view. In order to use
a faster algorithm, that doesn't keep the label inside the view, TLspFixedInPathLabelLocationProvider
can be used.
ILspLabelingAlgorithm.LabelContext
CONSECUTIVE_LABEL_CONFLICT_FAIL_COUNT_KEY, CONSECUTIVE_LABEL_FAIL_COUNT_KEY, LABEL_ATTEMPT_COUNT_KEY, LABEL_CONFLICT_FAIL_COUNT_KEY, LABEL_FAIL_COUNT_KEY, LABEL_PLACED_COUNT_KEY, TOTAL_LABEL_COUNT_KEY
Constructor and Description |
---|
TLspInPathLabelingAlgorithm()
Creates a new
TLspInPathLabelingAlgorithm that can be used to place labels inside
paths. |
Modifier and Type | Method and Description |
---|---|
TLspInPathLabelingAlgorithm |
clone()
Makes
Object.clone() public. |
protected Iterator<TLspLabelID> |
createLabelIterator(List<TLspLabelID> aLabels,
ILspLabelingAlgorithm.LabelContext aLabelContext,
ILspLabelConflictChecker aConflictChecker,
ILspView aView)
Creates a new
Iterator that iterates over the TLspLabelID s. |
protected ILspLabelPlacementEvaluator |
createLabelPlacementEvaluator(List<TLspLabelID> aLabels,
ILspLabelingAlgorithm.LabelContext aLabelContext,
ILspLabelConflictChecker aConflictChecker,
ILspView aView)
Creates a new
ILspLabelPlacementEvaluator using the given parameters. |
protected Iterator<TLspLabelPlacement> |
createLabelPlacementIterator(TLspLabelID aLabel,
ALspLabelLocations aCurrentLabelLocations,
ILspLabelingAlgorithm.LabelContext aLabelContext,
ILspLabelConflictChecker aConflictChecker,
ILspView aView)
Creates a new
Iterator that iterates over the TLspLabelPlacement s for
the given label. |
double |
getMinimumPathLength()
Returns the minimum contour length for a clipped polygon to contain a label.
|
double |
getQuality()
Returns the quality setting.
|
boolean |
isReusePreviousLocations()
Returns if this algorithm reuses the previous label locations.
|
void |
setClipEdgeOffsets(int aLeftOffset,
int aRightOffset,
int aBottomOffset,
int aTopOffset)
Calling this methods lets you define a clipping rectangle within the view.
|
void |
setMinimumPathLength(double aMinimumPathLength)
Sets the minimum outline length for a clipped polygon to contain a label.
|
void |
setQuality(double aQuality)
Sets the quality.
|
void |
setReusePreviousLocations(boolean aReusePreviousLocations)
When set to
true , this algorithm will try to reuse the previous label locations. |
placeLabels
public TLspInPathLabelingAlgorithm()
TLspInPathLabelingAlgorithm
that can be used to place labels inside
paths. These paths are created by a default path provider that discretizes the anchor of a
label (see ILspLabelPainter.getAnchorObject
) or the domain object if no anchor is defined explicitly.public void setQuality(double aQuality)
ALspDiscreteLabelingAlgorithm
Sets the quality. If the quality setting is high, the algorithm will try to place more
labels. If it is low, the algorithm will only try to place a small portion of the labels,
making label placement faster. Setting the quality to e.g. 0.5
can dramatically
improve the label placement performance in some cases.
E.g. it is possible that due to the quality setting, this algorithm will only try to place 10% of the labels. This may still result in high quality results, but this depends on the used data. In general, using a lower quality setting will still work well when the data (and its labels) are distributed uniformly over the screen.
By default, the quality is set to 1.0.
setQuality
in class ALspDiscreteLabelingAlgorithm
aQuality
- the new quality. This is a number in [0, 1].ALspDiscreteLabelingAlgorithm.getQuality()
public double getQuality()
ALspDiscreteLabelingAlgorithm
getQuality
in class ALspDiscreteLabelingAlgorithm
ALspDiscreteLabelingAlgorithm.setQuality(double)
public boolean isReusePreviousLocations()
true
if this algorithm reuses the previous label locations.isReusePreviousLocations()
public void setReusePreviousLocations(boolean aReusePreviousLocations)
true
, this algorithm will try to reuse the previous label locations.
Reusing previous label locations causes the labels to be more stable, i.e. labels don't always
move when for example the view is panned, or when objects are selected. This is because
label positions are only recalculated when the previous label location has become invalid.
The default value is true
.
aReusePreviousLocations
- true
to enable reusing previous label locations,
and false
to disable it.isReusePreviousLocations()
public double getMinimumPathLength()
setMinimumPathLength(double)
public void setMinimumPathLength(double aMinimumPathLength)
The default value is 0 pixels, i.e. no clipped polygon will be excluded.
aMinimumPathLength
- the minimal length for a clipped polygon to contain a label.public void setClipEdgeOffsets(int aLeftOffset, int aRightOffset, int aBottomOffset, int aTopOffset)
aLeftOffset
- the offset from the left edge of the viewaRightOffset
- the offset from the right edge of the viewaBottomOffset
- the offset from the bottom edge of the viewaTopOffset
- the offset from the top edge of the viewpublic TLspInPathLabelingAlgorithm clone()
ILcdCloneable
Makes Object.clone()
public.
java.lang.Object
, it can be implemented like this:
public Object clone() {
try {
return super.clone();
} catch ( CloneNotSupportedException e ) {
// Cannot happen: extends from Object and implements Cloneable (see also Object.clone)
throw new RuntimeException( e );
}
}
clone
in interface ILcdCloneable
clone
in class ALspDiscreteLabelingAlgorithm
Object.clone()
protected Iterator<TLspLabelID> createLabelIterator(List<TLspLabelID> aLabels, ILspLabelingAlgorithm.LabelContext aLabelContext, ILspLabelConflictChecker aConflictChecker, ILspView aView)
ALspDiscreteLabelingAlgorithm
Iterator
that iterates over the TLspLabelID
s. The abstract algorithm will continue
iterating over TLspLabelID
s as long as Iterator.hasNext()
returns true
. When it returns false
, no more label placements will be
tried, and placeLabels
returns. Iterator.hasNext()
should always be called before
calling Iterator.next()
, and if it returns true
, Iterator.next()
should never return null
. The implementation of
this method should be as independent as possible. It should not rely on createLabelPlacementIterator
or createLabelPlacementEvaluator
. Not respecting this might result
in unexpected behaviour when wrapping or extending this class.
Override this method to provide a custom implementation.
createLabelIterator
in class ALspDiscreteLabelingAlgorithm
aLabels
- a list of labels that need to be placed.aLabelContext
- the label info object.aConflictChecker
- the conflict checker to be used when evaluating placements.aView
- the view.Iterator
that iterates over TLspLabelID
s.protected Iterator<TLspLabelPlacement> createLabelPlacementIterator(TLspLabelID aLabel, ALspLabelLocations aCurrentLabelLocations, ILspLabelingAlgorithm.LabelContext aLabelContext, ILspLabelConflictChecker aConflictChecker, ILspView aView)
ALspDiscreteLabelingAlgorithm
Iterator
that iterates over the TLspLabelPlacement
s for
the given label. The abstract algorithm will continue iterating over
TLspLabelPlacement
s as long as Iterator.hasNext()
returns
true
. When it returns false
, a new label will be tried. Iterator.hasNext()
should always be called before calling Iterator.next()
, and if it
returns true
, Iterator.next()
should never return null
.
The implementation of this method should be as independent as possible. It should not rely on
createLabelIterator
or createLabelPlacementEvaluator
. Not respecting this might result in unexpected behaviour when
wrapping or extending this class.
The returned TLspLabelPlacement
should be
correctly initialized, that is it should at least be able to return a valid label location,
bounds rectangle and bounds rotation. It should also reference its corresponding
TLspLabelID
.
Override this method to provide a custom implementation.
createLabelPlacementIterator
in class ALspDiscreteLabelingAlgorithm
aLabel
- the identifier for which an iterator should be created.aCurrentLabelLocations
- an ALspLabelLocations object containing locations for the
currently placed labels.aLabelContext
- the label info object.aConflictChecker
- the conflict checker to be used when evaluating placements.aView
- the view.Iterator
that iterates over TLspLabelPlacement
s.protected ILspLabelPlacementEvaluator createLabelPlacementEvaluator(List<TLspLabelID> aLabels, ILspLabelingAlgorithm.LabelContext aLabelContext, ILspLabelConflictChecker aConflictChecker, ILspView aView)
ALspDiscreteLabelingAlgorithm
ILspLabelPlacementEvaluator
using the given parameters. It evaluates
the placements returned by createLabelPlacementIterator
,
and returns a PlacementResult
to denote if the placement should be used for its
label or not. The following actions are undertaken for the following placement results :
PlacementResult.SUCCESS
:
the given placement will be used for its label, it will be added to the list of placed
representations, and it will be added to the given ILspLabelConflictChecker
. After
that, ILspLabelPlacementEvaluator.placementApplied
will be called and no more placements are tried for the label.PlacementResult.FALLBACK
: the abstract
algorithm will try to find an other placements which returns PlacementResult.SUCCESS
. When no such
placement is found, this placement will be added to the list of placed labels, and it will be
added to the given ILspLabelConflictChecker
. After that, ILspLabelPlacementEvaluator.placementApplied
will
be called.PlacementResult.TRY_NEW_PLACEMENT
: the abstract algorithm will try to find an other placement
which returns PlacementResult.SUCCESS
or PlacementResult.FALLBACK
. When no such placement is found, ILspLabelPlacementEvaluator.noPlacementApplied
is called.PlacementResult.FAILED
: the abstract algorithm will immediately call ILspLabelPlacementEvaluator.noPlacementApplied
and will not try to find other placements for the label.Override this method to provide a custom implementation.
createLabelPlacementEvaluator
in class ALspDiscreteLabelingAlgorithm
aLabels
- a list of labels.aLabelContext
- the label info object.aConflictChecker
- the conflict checker to be used when evaluating placements.aView
- the viewILspLabelPlacementEvaluator
.ILspLabelPlacementEvaluator