Class TLspLabelingAlgorithm

java.lang.Object
com.luciad.view.lightspeed.label.algorithm.discrete.ALspDiscreteLabelingAlgorithm
com.luciad.view.lightspeed.label.algorithm.discrete.TLspLabelingAlgorithm
All Implemented Interfaces:
ILcdCloneable, ILspLabelingAlgorithm, Cloneable

public class TLspLabelingAlgorithm extends ALspDiscreteLabelingAlgorithm

This algorithm is a greedy algorithm that uses a ALspLabelLocationProvider to retrieve possible placements. It tries to place labels in the order provided to the createLabelIterator method. It tries to place them one by one, and when it cannot be placed without overlap, it is omitted.

Since:
2012.0
  • Constructor Details

    • TLspLabelingAlgorithm

      public TLspLabelingAlgorithm()
      Creates a new algorithm with a default label location provider. The default provider will return placements based on the cardinal and inter-cardinal directions.
    • TLspLabelingAlgorithm

      public TLspLabelingAlgorithm(ALspLabelLocationProvider aLabelLocationProvider)
      Creates a new algorithm based on the given label location provider.
      Parameters:
      aLabelLocationProvider - a label location provider.
  • Method Details

    • getLabelLocationProvider

      public ALspLabelLocationProvider getLabelLocationProvider()
      Returns the label location provider used by this algorithm.
      Returns:
      the label location provider
    • clone

      public TLspLabelingAlgorithm clone()
      Description copied from interface: ILcdCloneable

      Makes Object.clone() public.

      When for example extending from 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 );
         }
       }
       
      Specified by:
      clone in interface ILcdCloneable
      Overrides:
      clone in class ALspDiscreteLabelingAlgorithm
      See Also:
    • setQuality

      public void setQuality(double aQuality)
      Description copied from class: 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.

      Specified by:
      setQuality in class ALspDiscreteLabelingAlgorithm
      Parameters:
      aQuality - the new quality. This is a number in [0, 1].
      See Also:
    • getQuality

      public double getQuality()
      Description copied from class: ALspDiscreteLabelingAlgorithm
      Returns the quality setting.
      Specified by:
      getQuality in class ALspDiscreteLabelingAlgorithm
      Returns:
      the quality setting.
      See Also:
    • isReusePreviousLocations

      public boolean isReusePreviousLocations()
      Returns if this algorithm reuses the previous label locations.
      Returns:
      true if this algorithm reuses the previous label locations.
      See Also:
    • setReusePreviousLocations

      public void setReusePreviousLocations(boolean aReusePreviousLocations)
      When set to 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.

      Parameters:
      aReusePreviousLocations - true to enable reusing previous label locations, and false to disable it.
      See Also:
    • setForcedPlacementThresholdPriority

      public void setForcedPlacementThresholdPriority(int aPriority)
      Sets the threshold priority for forced placement. The labels of objects with a priority value less than or equal to the threshold priority value will always be placed, even if the algorithm could not find any suitable place for the label. This makes it possible for labels to overlap. The default value is -1, in which case no forced painting is done.
      Parameters:
      aPriority - the threshold priority for forced placement.
      See Also:
    • getForcedPlacementThresholdPriority

      public int getForcedPlacementThresholdPriority()
      Returns the threshold priority for forced placement.
      Returns:
      the threshold priority for forced placement.
      See Also:
    • getMaxPlacementsPerLabel

      public int getMaxPlacementsPerLabel()
      Returns the maximum number of placements tried per label.
      Returns:
      the maximum number of placements tried per label.
      See Also:
    • setMaxPlacementsPerLabel

      public void setMaxPlacementsPerLabel(int aMaxPlacementsPerLabel)
      Sets the maximum number of placements per label that is tried. This number doesn't include a placement tried for the previous location of the label. By default, the maximum number of placements per label is Integer.MAX_VALUE, i.e. all possible placements are tried.
      Parameters:
      aMaxPlacementsPerLabel - the maximum number of placements tried per label.
      See Also:
    • createLabelIterator

      protected Iterator<TLspLabelID> createLabelIterator(List<TLspLabelID> aLabels, ILspLabelingAlgorithm.LabelContext aLabelContext, ILspLabelConflictChecker aConflictChecker, ILspView aView)
      Description copied from class: ALspDiscreteLabelingAlgorithm
      Creates a new Iterator that iterates over the TLspLabelIDs. The abstract algorithm will continue iterating over TLspLabelIDs 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.

      Specified by:
      createLabelIterator in class ALspDiscreteLabelingAlgorithm
      Parameters:
      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.
      Returns:
      a new Iterator that iterates over TLspLabelIDs.
    • createLabelPlacementIterator

      protected Iterator<TLspLabelPlacement> createLabelPlacementIterator(TLspLabelID aLabel, ALspLabelLocations aCurrentLabelLocations, ILspLabelingAlgorithm.LabelContext aLabelContext, ILspLabelConflictChecker aConflictChecker, ILspView aView)
      Description copied from class: ALspDiscreteLabelingAlgorithm
      Creates a new Iterator that iterates over the TLspLabelPlacements for the given label. The abstract algorithm will continue iterating over TLspLabelPlacements 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.

      Specified by:
      createLabelPlacementIterator in class ALspDiscreteLabelingAlgorithm
      Parameters:
      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.
      Returns:
      a new Iterator that iterates over TLspLabelPlacements.
    • createLabelPlacementEvaluator

      protected ILspLabelPlacementEvaluator createLabelPlacementEvaluator(List<TLspLabelID> aLabels, ILspLabelingAlgorithm.LabelContext aLabelContext, ILspLabelConflictChecker aConflictChecker, ILspView aView)
      Description copied from class: ALspDiscreteLabelingAlgorithm
      Creates a new 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 :

      Override this method to provide a custom implementation.

      Specified by:
      createLabelPlacementEvaluator in class ALspDiscreteLabelingAlgorithm
      Parameters:
      aLabels - a list of labels.
      aLabelContext - the label info object.
      aConflictChecker - the conflict checker to be used when evaluating placements.
      aView - the view
      Returns:
      a new ILspLabelPlacementEvaluator.
      See Also: