Class GraphView

All Implemented Interfaces:
Graph.Graphic, NamedObjectOps

public class GraphView extends DirectedObject2D
Configure a graph to provide a movable and zoomable view of plane. This class is used to support animations by providing a view that one would obtain as one moved along some path above the plane while looking vertically downwards at the plane. The view can be zoomed.

By default, an instance of GraphView is constructed so that it is visible and so that its zorder is the smallest (most negative) integer that can be represented by the primitive type long.

  • Constructor Details

  • Method Details

    • initialize

      public void initialize(double xgcs, double ygcs, double xf, double yf, double scaleX, double scaleY, double zoom)
      Initializer. The description of the arguments makes use of terminology defined by the Graph class.

      The location (xgcs,ygcs) in graph coordinate space will be positioned at a specific point in user space. This point is located at (xlo+ xf*(w -xlo -xuo), h - (ylo + yf*(h-ylo-yuo))) in user space, where

        xlo is the graph's lower x offset in user space. xuo is the graph's upper x offset in user space. ylo is the graph's lower y offset in user space. yuo is the graphs' upper y offset in user space. w is the width of the graph in user space. h is the height of the graph in user space.
      Typically in an animation, the lower and upper x and y offsets are set to zero, which is the default behavior when a graph is created.

      The scale factors scaleX and scaleY are the amount by which to multiple a distance in graph coordinate space along the X and Y axes respectively to get the corresponding distance in user space. The zoom parameter is basically the magnification, so a value of 2.0 makes the image appear twice as big.

      To rotate the view about the point (xgcs, ycgs), use the methods DirectedObject2D.setAngle(double) or DirectedObject2D.setPathAngle(double) (possibly calling DirectedObject2D.setAngleRelative(boolean) if the angle should be relative to a path). Objects in the view will appear to rotate in the opposite direction of the view's rotation. The setPath methods for DirectedObject2D can also be used, as can methods that set angular velocity, angular acceleration, etc.

      As an example, if (xgsc, ygsc) = (500.0, 0.0), and xf and yf are both 0.5, the point (500.0, 0.0) in graph coordinate space will appear in the middle of the frame. The factors scaleX and scaleY determine how graph coordinate space is scaled to be displayed in the frame when the zoom factor is 1.0. The view can subsequently be moved and zoomed. If the graph view is moved to 600.0, 0.0), then the point (600.0, 0.0) will be in the middle of the frame.

      The effect is that one can 'pan' over user space, zooming in and out as appropriate. As a subclass of DirectedObject2D, one can specify a path to follow and control the motion along that path.

      Parameters:
      xgcs - the x coordinate of a point in graph coordinate space that will be positioned at a specified location on the graph
      ygcs - the y coordinate of a point in graph coordinate space that will be positioned at a specified location on the graph
      xf - the fractional distance from the graph's left offset to its right offset at which the point xgcs in graph coordinate space appears
      yf - the fractional distance from the graph's lower offset to its upper offset at which the point ygcs in graph coordinate space appears
      scaleX - the scale factor for the X direction
      scaleY - the scale factor for the Y direction
      zoom - the zoom level, which must be a positive real number
      Throws:
      IllegalStateException - initialize was called multiple times
    • defaultAngleRelative

      protected boolean defaultAngleRelative()
      Return the default value of the angle-relative flag. This method returns false unless overridden.
      Overrides:
      defaultAngleRelative in class DirectedObject2D
      Returns:
      the default value for setPath methods
      See Also:
    • setZoom

      public void setZoom(double zoom)
      Set the zoom factor.
      Parameters:
      zoom - the zoom factor.
    • setAngle

      public void setAngle(double theta)
      Set the rotation. The argument gives the angle the graph view rotates in the counterclockwise direction in graph coordinate space space, causing objects in graph coordinate space to rotate clockwise.
      Overrides:
      setAngle in class DirectedObject2D
      Parameters:
      theta - the rotation in radians
    • setPosition

      public void setPosition(double x, double y, double angle)
      Set an object's position and orientation. The argument gives the angle the graph view rotates in the counterclockwise direction in graph coordinate space, causing objects in graph coordinate space to rotate clockwise. The coordinates (x,y) are the coordinates of the view's reference point, which will appear at a specific location in the frame determined when the view was initialized.
      Overrides:
      setPosition in class DirectedObject2D
      Parameters:
      x - the x coordinate in graph coordinate space
      y - the y coordinate in graph coordinate space
      angle - the angle giving the view's orientation in radians
    • setLogZoomRate

      public void setLogZoomRate(double zoomRate)
      Set the zoom rate logarithmicly. The zoom factor will change with time as exp(zoomRate * t);
      Parameters:
      zoomRate - the logarithmic zoom rate
    • setLogZoomRate

      public void setLogZoomRate(double zoomTarget, double deltaT)
      Set the zoom rate logarithmicly to zoom to a target value in a specified time.
      Parameters:
      zoomTarget - the target zoom value after a time interval of deltaT elapses
      deltaT - the time interval for the zoom factor to change from its current value to the target value
    • update

      public void update(double t, long simtime)
      Description copied from class: DirectedObject2D
      Update the object's state to that at a specified time. The values of t passed to this method should form an increasing sequence. The default implementation's behavior depends on whether functions are provided. A distance function, path velocity, path acceleration, or angle function is not used when there is no path, although the angular acceleration and angular velocity will be used if these are nonzero.
      1. If a distance function is provided, that function is used to determine the new value of s (the distance along the path from its start) at time τ, with the path velocity and acceleration determined by that function's first and second derivatives (if not implemented, the path velocity and/or acceleration is set to Double.NaN). The time τ is the difference between the current time t and the time time0 at which the path traversal starts.
      2. If a distance function is not provided, the path velocity and path acceleration are used to determine the new value of s, and the path velocity is updated as well.
      3. If an angle function is provided, that function is used to determine the new angle, and its derivatives, if implemented provide the angular velocity and angular acceleration. The time argument $tau; is the difference between the current time t and the time time0 at which the path traversal starts. If the path was set with the flag angleRelative set to true, the angle is added to the tangent at the object's new position along the path; otherwise the angle is measured counterclockwise from the direction of the positive X axis.
      4. If an angle function is not provided the path angular velocity and path angular acceleration are used to compute the change in angle from the last time update was called. If the path was set with the flag angleRelative set to true, the angle is added to the angle of the tangent to the path at its new location; otherwise the angle is measured counterclockwise from the direction of the positive X axis.
      The angleRelative flag is the boolean argument to DirectedObject2D.setPath(org.bzdev.geom.BasicSplinePath2D,double,double,boolean,double) or DirectedObject2D.setPath(AnimationPath2D,double,double,boolean,double), but may be subsequently changed by calling DirectedObject2D.setAngleRelative(boolean).

      If a velocity or acceleration has the value Double.NaN, it is treated as if its value were 0.0. In cases where one needs to obtain the previous value of s, one can override this method and obtain the previous value by calling DirectedObject2D.getS() before calling super.update.

      Overrides:
      update in class DirectedObject2D
      Parameters:
      t - the time for which the object should be calculated.
      simtime - the simulation time
    • addTo

      public void addTo(Graph graph, Graphics2D g2d, Graphics2D g2dGCS) throws IllegalStateException
      Add this object to a graph. A GraphView is a special case. There should be only on in use per graph. It will set up the graph so that the graph displays a particular range in graph coordinate space. Angles refer to the view, not the object. Graphic operations at a particular time should be performed after a graph's add method is called for any GraphView defined for the graph, and after update is called with the current time as its argument.
      Parameters:
      graph - the graph on which this object should be drawn
      g2d - (ignored but needed by Graph.Graphics interface)
      g2dGCS - (ignored but needed by Graph.Graphics interface)
      Throws:
      IllegalStateException - initialize was not called
    • gwidth

      public double gwidth(Graph graph) throws IllegalStateException
      Get the graph width in graph coordinate space excluding the offsets.
      Parameters:
      graph - the graph
      Returns:
      the graph width in graph coordinate space, excluding any offsets
      Throws:
      IllegalStateException - initialize was not called
    • gheight

      public double gheight(Graph graph) throws IllegalStateException
      Get the graph height in graph coordinate space excluding the offsets.
      Parameters:
      graph - the graph
      Returns:
      the graph height in graph coordinate space, excluding any offsets
      Throws:
      IllegalStateException - initialize was not called
    • printConfiguration

      public void printConfiguration(String iPrefix, String prefix, boolean printName, PrintWriter out)
      Print this simulation object's configuration. Documentation for the use of this method is provided by the documentation for the SimObject method SimObject.printConfiguration(String,String,boolean,PrintWriter).

      When the second argument has a value of true, the object name and class name will be printed in a standard format with its indentation provided by the iPrefix argument. In addition, the configuration that is printed includes the following items.

      Defined in AnimationObject2D:

      • the Z-order.
      • whether or not this object is visible.
      Defined in PlacedAnimationObject2D:
      • the reference-point name (if any).
      • the reference point location.
      • the reference point bounds (minimum and maximum X and Y values for the rectangle to which the reference point names refer).
      Defined in DirectedObject2D:
      • the path this object will follow: either the name of an instance of AnimationPath2D or the configuration of a BasicSplinePath2D as provided by its method BasicSplinePath2D.printTable(String,Appendable).
      • the distance along a path for its starting point (the initial distance).
      • the initial value of the path's parameter.
      • the time at which a path traversal should start.
      • the initial value for whether or not the angle for the object is relative to the path's tangent or absolute.
      • the distance function.
      • a flag indicating if the distance function is set.
      • the path velocity.
      • the path acceleration.
      • the path inversion limit (described in the documentation for DirectedObject2D.getPathInversionLimit().
      Defined in GraphView:
      • the X reference point fractional position.
      • the Y reference point fractional position.
      • the X scale factor.
      • the Y scale factor.
      • the X initial position.
      • the Y initial position.
      • the initial zoom factor.
      Overrides:
      printConfiguration in class DirectedObject2D
      Parameters:
      iPrefix - the prefix to use for an initial line when printName is true with null treated as an empty string
      prefix - a prefix string (typically whitespace) to put at the start of each line other than the initial line that is printed when printName is true
      printName - requests printing the name of an object
      out - the output print writer
    • printState

      public void printState(String iPrefix, String prefix, boolean printName, PrintWriter out)
      Print this simulation object's state. Documentation for the use of this method is provided by the documentation for the SimObject method SimObject.printState(String,String,boolean,PrintWriter).

      When the third argument has a value of true, the object name and class name will be printed in a standard format with its indentation provided by the iPrefix argument. In addition, the state that is printed includes the following items.

      Defined in PlacedAnimationObject2D:

      • the X coordinate of this object.
      • the Y coordinate of this object.
      • the angle for this object, measured counterclockwise.
      Defined in DirectedObject2D:
      • the name of the path (if any) this object can follow.
      • the path parameter.
      • the path distance.
      • the angle-relative flag.
      • the velocity along the path (NaN if undefined). When a distance function is used, its derivative, if implemented, determines this value.
      • the acceleration along the path (NaN if undefined). When a distance function is used, its second derivative, if implemented, determines this value.
      • the path angle. The angle is measured relative to the path's tangent in the direction of an increasing path parameter when the angle-relative flag is true; otherwise it is measured relative to the X axis. Angles are measured counterclockwise.
      • the angular velocity. When a path-angle function is used, its derivative, if implemented, determines this value.
      • the angular acceleration. When a path-angle function is used, its derivative, if implemented, determines this value.
      • the angular acceleration. When a path-angle function is used, its derivative, if implemented, determines this value.
      • the time at which this data was last updated.
      Defined in GraphView:
      • the zoom factor.
      • the zoom rate (which is logarithmic).
      Overrides:
      printState in class DirectedObject2D
      Parameters:
      iPrefix - the prefix to use for an initial line when printName is true with null treated as an empty string
      prefix - a prefix string (typically whitespace) to put at the start of each line other than the initial line that is printed when printName is true
      printName - requests printing the name of an object
      out - the output print writer
    • clone

      protected Object clone() throws CloneNotSupportedException
      Creates and returns a copy of this object. This method will throw the exception CloneNotSupportedException if the object is interned.
      Overrides:
      clone in class Object
      Throws:
      CloneNotSupportedException - a clone could not be created
      See Also:
    • isInterned

      public boolean isInterned()
      Determine if an object is interned in a object namer's tables.
      Specified by:
      isInterned in interface NamedObjectOps
      Returns:
      true if the object is interned; false if not
    • getObjectNamer

      protected Simulation getObjectNamer()
      Get the object namer for a named object.
      Returns:
      the object namer for this named object
    • getName

      public final String getName()
      Get an object's name.
      Specified by:
      getName in interface NamedObjectOps
      Returns:
      the name of the object
    • canDelete

      public boolean canDelete()
      Determine if this named object can be deleted. A named object can be deleted if the method delete has not been called and if the object is not in a state that prevents the object from being deleted. Subclasses that override this method must call canDelete() for their superclasses and return false if the superclass' canDelete method returns false. The default method returns true if delete() has not been called and returned true.
      Specified by:
      canDelete in interface NamedObjectOps
      Returns:
      true if this object can be deleted; false otherwise
    • delete

      public final boolean delete()
      Delete an object. An object can only be deleted once. If this method returns true, the object (if interned) will have been removed from the object namer tables.

      The implementations provided by DefaultNamedObect and generated because of a @NamedObject annotation provide a protected method named onDelete. A subclass that overrides onDelete() must call the onDelete method of its superclass after it's onDelete method has been called and any cleanup actions performed. In some cases, this may happen at a later time (e.g., if a thread is used for some of the cleanup operations or if it is otherwise necessary to wait).

      Specified by:
      delete in interface NamedObjectOps
      Returns:
      true if the deletion request was accepted; false otherwise
    • isDeleted

      public final boolean isDeleted()
      Determine if an object has been deleted. An object is deleted if the method delete() has been called and returned true.
      Specified by:
      isDeleted in interface NamedObjectOps
      Returns:
      true if deleted; false otherwise
    • deletePending

      public final boolean deletePending()
      Determine if an object is being deleted. An deletion is pending if the method delete() has been called and returned true but the deletion has not been completed.
      Specified by:
      deletePending in interface NamedObjectOps
      Returns:
      true if deletion is pending; false otherwise