Class TLcyShapeObserver

java.lang.Object
com.luciad.lucy.addons.tea.shapevisibility.TLcyShapeObserver
All Implemented Interfaces:
ILcdBounded

public final class TLcyShapeObserver extends Object implements ILcdBounded

Domain object representing an observer in a shape visibility calculation. Currently only point shapes are supported as observers. These observers are contained in the observer model of the map.

Each observer has:

Creating observer instances is done through the TLcyShapeVisibilityManager:

    //Retrieve the manager from the services
    TLcyShapeVisibilityManager manager = aLucyEnv.getService(TLcyShapeVisibilityManager.class);

    //Ask the manager to create an observer for the specified domain object
    //Interacting with the manager must happen on the AWT thread (Event Dispatch Thread)
    if (manager.canAddObserver(aDomainObjectContext)) {
      TLcyShapeObserver pointObserver = manager.addObserver(aDomainObjectContext);
    }
Since:
2019.1
  • Method Details

    • getObserver

      public TLcdDomainObjectContext getObserver()
      Returns the domain object context for which this observer was created.
      Returns:
      the domain object context which this observer was created.
    • getObserverShape

      public ILcdPoint getObserverShape()

      Returns the point shape based on the point that was created by the TLcyShapeVisibilityAddOn.createPointObserverShapeProvider() function for this observer, and which is used in the visibility calculations.

      The returned point:

      The returned point should not be modified.

      Returns:
      the point shape used in the visibility calculations for this observer
      Since:
      2020.1
      See Also:
    • getObserverCoverageAltitudeMode

      public TLcdCoverageAltitudeMode getObserverCoverageAltitudeMode()

      Returns the altitude mode indicating how to interpret the Z-values of the observer shape. This altitude mode is determined by the TLcyShapeVisibilityAddOn.createPointObserverShapeProvider() function.

      Returns:
      the altitude mode for the observer shape.
      Since:
      2020.1
      See Also:
    • getObservees

      public List<TLcdDomainObjectContext> getObservees()

      Returns the list of domain object contexts this observer is currently observing.

      This list cannot be modified directly. Use the startObserving(TLcdDomainObjectContext) and stopObserving(TLcdDomainObjectContext) methods to start or stop observing specific domain objects.

      Returns:
      the list of domain object contexts this observer is currently observing. Possibly empty, never null
    • canObserve

      public boolean canObserve(TLcdDomainObjectContext aDomainObjectContext)

      Returns true when the specified domain object context can be observed by this observer.

      Currently this method only returns true when:

      • The view in the context is the same view as the one for which this observer was created.
      • The domain object is not the same as the one for which this observer was created: the observer cannot observe itself.
      • The model, layer and view are specified in the context.
      • The model in the context is not a model created by the TLcyShapeVisibilityAddOn.
      • This observer is not yet observing the domain object.
      • The TLcyShapeVisibilityAddOn.createObserveeShapeProvider() function can retrieve a shape for the context.
      Parameters:
      aDomainObjectContext - The context to check
      Returns:
      true when the specified domain object context can be observed by this observer.
    • startObserving

      public TLcyShapeObservationResult startObserving(TLcdDomainObjectContext aDomainObjectContext) throws IllegalArgumentException

      Start observing the specified domain object using this observer. This method modifies the observer, so it must be called under a write lock as illustrated below:

            //Find the observer model in the view
            ILcdModel pointObserverModel = view.getLayers()
                                               .stream()
                                               .map(ILcdLayer::getModel)
                                               .filter(model -> Objects.equals(TLcyShapeVisibilityAddOn.OBSERVER_MODEL_TYPE_NAME, model.getModelDescriptor().getTypeName()))
                                               .findFirst()
                                               .orElseThrow(() -> new RuntimeException("Cannot find the model containing the observers"));
            //Let the observer observe another shape
            //As this modifies the point observer, it requires a lock on the point observer model
            try (TLcdLockUtil.Lock autoUnlock = TLcdLockUtil.writeLock(pointObserverModel)) {
              if (pointObserver.canObserve(aDomainObjectContextToObserve)) {
                //Tell the observer to start observing another object
                pointObserver.startObserving(aDomainObjectContextToObserve);
                //Indicate to the model that the observer has been changed
                pointObserverModel.elementChanged(pointObserver, ILcdModel.FIRE_LATER);
              }
            } finally {
              pointObserverModel.fireCollectedModelChanges();
            }
      

      This method returns immediately and doesn't wait for the calculation to finish. This means the matrix in the observation result will not yet contain the result of this observer.

      When the calculation finishes, the TLcyShapeObservationResult instance will be updated and a model change event is fired for the observation results model.

      Parameters:
      aDomainObjectContext - The domain object this observer needs to observe.
      Returns:
      The observation result for aDomainObjectContext. If the object was not yet under observation by a different observer, this will be a new instance. If the object was already under observation by other observers, the existing result for that observee is updated and returned.
      Throws:
      IllegalArgumentException - When the specified context cannot be observed (by this observer).
      See Also:
    • stopObserving

      public void stopObserving(TLcdDomainObjectContext aDomainObjectContext)

      Stop observing the specified domain object with this observer. This method modifies the observer, so it must be called under a write lock as illustrated blow:

            //Find the observer model in the view
            ILcdModel pointObserverModel = view.getLayers()
                                               .stream()
                                               .map(ILcdLayer::getModel)
                                               .filter(model -> Objects.equals(TLcyShapeVisibilityAddOn.OBSERVER_MODEL_TYPE_NAME, model.getModelDescriptor().getTypeName()))
                                               .findFirst()
                                               .orElseThrow(() -> new RuntimeException("Cannot find the model containing the observers"));
            //Stop observing a specific shape
            //As this modifies the point observer, it requires a lock on the point observer model
            try (TLcdLockUtil.Lock autoUnlock = TLcdLockUtil.writeLock(pointObserverModel)) {
              //Tell the observer to stop observing a specific object
              pointObserver.stopObserving(aDomainObjectContextToObserve);
              //Indicate to the model that the observer has been changed
              pointObserverModel.elementChanged(pointObserver, ILcdModel.FIRE_LATER);
            } finally {
              pointObserverModel.fireCollectedModelChanges();
            }
      
      Parameters:
      aDomainObjectContext - The domain object this observer should stop observing.
    • getBounds

      public ILcdBounds getBounds()
      Description copied from interface: ILcdBounded
      Returns the ILcdBounds by which the geometry of this ILcdBounded object is bounded.

      If the geometry does not allow retrieving valid bounds (for example a polyline with 0 points) the return value is unspecified. It is highly recommended to return an undefined bounds. You can create undefined bounds using the default constructors of TLcdLonLatBounds or TLcdXYBounds.

      Specified by:
      getBounds in interface ILcdBounded
      Returns:
      the ILcdBounds by which the geometry of this ILcdBounded object is bounded.