sim.field.geo
Class GeomVectorField

java.lang.Object
  extended by sim.field.geo.GeomField
      extended by sim.field.geo.GeomVectorField
All Implemented Interfaces:
java.io.Serializable

public class GeomVectorField
extends GeomField

A GeomVectorField contains one or more MasonGeometry objects. The field stores the geometries as a quadtree and used the quadtree during various queries. As objects are inserted into the field, the minimum bounding rectangle (MBR) is expanded to include the new object. This allows a determination of the area of the field.

Note that the field assumes the geometries use the same coordinate system.

See Also:
Serialized Form

Field Summary
 com.vividsolutions.jts.geom.Envelope clipEnvelope
           
 com.vividsolutions.jts.geom.util.AffineTransformation jtsTransform
           
 java.awt.geom.AffineTransform worldToScreen
           
 
Fields inherited from class sim.field.geo.GeomField
drawX, drawY, fieldHeight, fieldWidth, MBR
 
Constructor Summary
GeomVectorField()
           
GeomVectorField(int w, int h)
          Default constructor, which resets all internal data structures.
 
Method Summary
 void addGeometry(MasonGeometry g)
          Adds the MasonGeometry to the field and also expands the MBR
 void clear()
          Removes all geometry objects and resets the MBR.
 void computeConvexHull()
          Computes the convex hull of all the geometries in this field.
 void computeUnion()
          Compute the union of the field's geometries.
 MasonGeometry findGeometry(MasonGeometry g)
          Locate a specific geometry inside the quadtree
 sim.util.Bag getContainingObjectgs(MasonGeometry mg)
           
 sim.util.Bag getContainingObjects(com.vividsolutions.jts.geom.Geometry g)
          Returns geometries that contain the given object.
 sim.util.Bag getCoveredObjects(MasonGeometry g)
          Return geometries that are covered by the given geometry.
 sim.util.Bag getCoveringObjects(com.vividsolutions.jts.geom.Geometry g)
          Returns geometries that cover the given object.
 sim.util.Bag getCoveringObjects(MasonGeometry mg)
           
 sim.util.Bag getGeometries()
          Returns all the field's geometry objects.
 MasonGeometry getGeometry(java.lang.String name, java.lang.Object value)
          Searches the field for the first object with attribute name that has value value.
 com.vividsolutions.jts.geom.Point getGeometryLocation(MasonGeometry g)
          Get the centroid of the given Geometry.
 sim.util.Bag getObjectsWithinDistance(com.vividsolutions.jts.geom.Geometry g, double dist)
          Returns a bag containing all those objects within distance of the given geometry.
 sim.util.Bag getObjectsWithinDistance(MasonGeometry mg, double dist)
           
 sim.util.Bag getTouchingObjects(MasonGeometry mg)
          Returns geometries that touch the given geometry.
 boolean isCovered(com.vividsolutions.jts.geom.Coordinate point)
          Returns true if the coordinate is within any geometry in the field.
 boolean isCovered(MasonGeometry g)
          Returns true if the given Geometry is covered by any geometry in the field.
 boolean isInsideConvexHull(com.vividsolutions.jts.geom.Coordinate coord)
          Determine if the Coordinate is within the convex hull of the field's geometries.
 boolean isInsideUnion(com.vividsolutions.jts.geom.Coordinate point)
          Determine if the Coordinate is within the bounding Geometry of the field's geometries.
 sim.util.Bag queryField(com.vividsolutions.jts.geom.Envelope e)
           
 sim.engine.Steppable scheduleSpatialIndexUpdater()
          Schedules a repeating Steppable that updates spatial index
 void setGeometryLocation(MasonGeometry g, com.vividsolutions.jts.geom.CoordinateSequenceFilter p)
          Moves the centroid of the given geometry to the provided point.
 void updateSpatialIndex()
          Rebuild the spatial index from the current set of geometry
 void updateTransform(sim.portrayal.DrawInfo2D info)
           
 void updateTree(com.vividsolutions.jts.geom.Geometry g, com.vividsolutions.jts.geom.util.AffineTransformation at)
           
 
Methods inherited from class sim.field.geo.GeomField
getFieldHeight, getFieldWidth, getHeight, getMBR, getWidth, setFieldHeight, setFieldWidth, setMBR
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

clipEnvelope

public com.vividsolutions.jts.geom.Envelope clipEnvelope

worldToScreen

public java.awt.geom.AffineTransform worldToScreen

jtsTransform

public com.vividsolutions.jts.geom.util.AffineTransformation jtsTransform
Constructor Detail

GeomVectorField

public GeomVectorField()

GeomVectorField

public GeomVectorField(int w,
                       int h)
Default constructor, which resets all internal data structures.

Method Detail

addGeometry

public void addGeometry(MasonGeometry g)
Adds the MasonGeometry to the field and also expands the MBR


clear

public void clear()
Removes all geometry objects and resets the MBR.

Overrides:
clear in class GeomField

computeConvexHull

public void computeConvexHull()
Computes the convex hull of all the geometries in this field. Call this method once.


isInsideConvexHull

public boolean isInsideConvexHull(com.vividsolutions.jts.geom.Coordinate coord)
Determine if the Coordinate is within the convex hull of the field's geometries. Call computeConvexHull first.


computeUnion

public void computeUnion()
Compute the union of the field's geometries. The resulting Geometry is the outside points of the field's geometries. Call this method only once.


isInsideUnion

public boolean isInsideUnion(com.vividsolutions.jts.geom.Coordinate point)
Determine if the Coordinate is within the bounding Geometry of the field's geometries. Call computeUnion first.


queryField

public sim.util.Bag queryField(com.vividsolutions.jts.geom.Envelope e)
Returns:
all the geometries that intersect the provided envelope; will be empty if none intersect

getGeometries

public sim.util.Bag getGeometries()
Returns all the field's geometry objects. Do not modify the Bag, nor the Geometries inside the bag, as this will have undefined consequences for drawing and inspecting.


getObjectsWithinDistance

public sim.util.Bag getObjectsWithinDistance(com.vividsolutions.jts.geom.Geometry g,
                                             double dist)
Returns a bag containing all those objects within distance of the given geometry. The distance calculation follows the JTS convention, which determines the distance between the closest points of two geometries. Do not modify the returned Bag.


getObjectsWithinDistance

public sim.util.Bag getObjectsWithinDistance(MasonGeometry mg,
                                             double dist)

getCoveringObjects

public final sim.util.Bag getCoveringObjects(com.vividsolutions.jts.geom.Geometry g)
Returns geometries that cover the given object. Cover here means completely cover, including points on the boundaries. Do not modify the returned Bag.


getCoveringObjects

public final sim.util.Bag getCoveringObjects(MasonGeometry mg)

getCoveredObjects

public final sim.util.Bag getCoveredObjects(MasonGeometry g)
Return geometries that are covered by the given geometry. Do not modify the returned Bag.

XXX Could be made more efficient by using spatial index to narrow candidates.


getContainingObjects

public final sim.util.Bag getContainingObjects(com.vividsolutions.jts.geom.Geometry g)
Returns geometries that contain the given object. Contain is more exclusive than cover and doesn't include things on the boundary. Do not modify the returned Bag.


getContainingObjectgs

public final sim.util.Bag getContainingObjectgs(MasonGeometry mg)

getTouchingObjects

public final sim.util.Bag getTouchingObjects(MasonGeometry mg)
Returns geometries that touch the given geometry. Do not modify the returned Bag.


isCovered

public boolean isCovered(MasonGeometry g)
Returns true if the given Geometry is covered by any geometry in the field. Cover here includes points in the boundaries.


isCovered

public boolean isCovered(com.vividsolutions.jts.geom.Coordinate point)
Returns true if the coordinate is within any geometry in the field. However, it offers no guarentee for points on the boundaries. Use this version if you want to check if an agent is within a geometry; its roughly an order of magnitude faster than using the Geometry version.


getGeometryLocation

public com.vividsolutions.jts.geom.Point getGeometryLocation(MasonGeometry g)
Get the centroid of the given Geometry. Note that the returned location uses the coordinate system of the underlying GIS data.


setGeometryLocation

public void setGeometryLocation(MasonGeometry g,
                                com.vividsolutions.jts.geom.CoordinateSequenceFilter p)
Moves the centroid of the given geometry to the provided point.

Note that the spatial index is not notified of the geometry changes. It is strongly recommended that updateSpatialIndex() be invoked after all geometry position changes.

See Also:
updateSpatialIndex()

updateSpatialIndex

public void updateSpatialIndex()
Rebuild the spatial index from the current set of geometry

If the objects contained in this field have moved, then the spatial index will have to be updated. This is done by replacing the current spatial index with an entirely new one built from the same stored geometry.


scheduleSpatialIndexUpdater

public sim.engine.Steppable scheduleSpatialIndexUpdater()
Schedules a repeating Steppable that updates spatial index

The spatial index for a GeomVectorField containing moving objects will need to be updated after all such objects have moved. This method returns a Steppable that invokes updateSpatialIndex() that does this.

Returns:
a Steppable that can be used to remove this Steppable from the schedule

findGeometry

public MasonGeometry findGeometry(MasonGeometry g)
Locate a specific geometry inside the quadtree

XXX Is returning what we're looking for when the target geometry is not found the desired behavior?

Parameters:
g - is geometry for which we're looking
Returns:
located geometry; will return g if not found.

updateTree

public void updateTree(com.vividsolutions.jts.geom.Geometry g,
                       com.vividsolutions.jts.geom.util.AffineTransformation at)

getGeometry

public MasonGeometry getGeometry(java.lang.String name,
                                 java.lang.Object value)
Searches the field for the first object with attribute name that has value value.

Parameters:
name - of attribute
value - of attribute TODO What if there is more than one such object?
Returns:
MasonGeometry with specified attribute otherwise null

updateTransform

public void updateTransform(sim.portrayal.DrawInfo2D info)