com.hedgehog.geo.twod.points
Class IndexPoint2DSet

java.lang.Object
  extended by com.hedgehog.HObject
      extended by com.hedgehog.geo.GeometricObject
          extended by com.hedgehog.geo.twod.IndexObject2D
              extended by com.hedgehog.geo.twod.IndexPointObject2D
                  extended by com.hedgehog.geo.twod.points.IndexPoint2DSet
All Implemented Interfaces:
ModelObject, java.lang.Comparable, java.util.Comparator

public class IndexPoint2DSet
extends IndexPointObject2D
implements ModelObject

Title: IndexPoint2DSet - a set of index points.

Description: Models a collection of 2D index-points. Internally stores the points as a vector of integer indices.

Copyright: Copyright (c) Hedgehog Software 2007-2009.

Company: Hedgehog Software.

Since:
1.0
Version:
1.1

Field Summary
protected  IntegerVector mPointIndices
          Point set point indices vector.
 
Fields inherited from class com.hedgehog.geo.twod.IndexPointObject2D
mPoints
 
Fields inherited from class com.hedgehog.HObject
mID, mName
 
Constructor Summary
IndexPoint2DSet()
          Default constructor.
IndexPoint2DSet(ID id)
          Constructor.
IndexPoint2DSet(IndexPoint2DSet object)
          Copy constructor.
IndexPoint2DSet(Point2DSet pset)
          Constructor.
IndexPoint2DSet(Point2DSet pset, IntegerVector pointIndices)
          Constructor.
IndexPoint2DSet(java.lang.String name)
          Constructor.
IndexPoint2DSet(java.lang.String name, ID id)
          Constructor.
IndexPoint2DSet(java.util.Vector<Point2D> points)
          Constructor.
IndexPoint2DSet(java.util.Vector<Point2D> points, int pointIndex)
          Constructor.
IndexPoint2DSet(java.util.Vector<Point2D> points, IntegerVector pointIndices)
          Constructor.
IndexPoint2DSet(java.util.Vector<Point2D> points, java.util.Vector<IndexPoint2D> indexPoints)
          Constructor.
 
Method Summary
 boolean add(int pointIndex, boolean performCheck)
          Adds the specified point index to this set.
 AxisAlignedBox2D boundingBox()
          Returns the axis aligned bounding box of this point set.
 java.util.Vector<ModelObject> childModelObjects()
          Returns a vector of this object's child ModelObject objects.
 void clear()
          Clears the mPointIndices vector, thus emptying this set.
 ConvexStraightEdgePolygon2D convexHull(ConvexHullMethod hullMethod)
          Returns the convex hull of this index-point set.
 java.sql.PreparedStatement databaseInsertStatement(java.sql.Connection connection, int modelID)
          Returns a prepared statement for inserting (INSERT command) a ModelObject object into a database.
 java.sql.PreparedStatement databaseUpdateStatement(java.sql.Connection connection, int modelID)
          Returns a prepared statement for updating (UPDATE command) a ModelObject object into a database.
 ModelObject fromDatabase(java.sql.Connection connection, Model model, int modelID, int objectID)
          Returns a model object from the specified database table.
 ModelObject fromXMLNode(org.w3c.dom.Document document, org.w3c.dom.Node documentRootNode, org.w3c.dom.Node node, Model model)
          Returns a model object from the specified xml node.
 Point2D getPoint(int pointIndex)
          Returns the actual point with the specified index.
 int getPointIndex(int i)
          Returns the point index at the specified index in the mPointIndices vector.
 IntegerVector getPointIndices()
          Returns the set's vector of point indices.
 boolean isEmpty()
          Tests whether ro not this set is empty.
 boolean isMember(int pointIndex)
          Tests whether or not the specified point index is a member of this set.
 int nearestPoint(IndexPoint2D p)
          Returns the set point nearest to the specified index-point, which can be any point and is assumed not to be a point of this set.
 int nearestPoint(Point2D p)
          Returns the set point nearest to the specified point, which can be any point and is assumed not to be a point of this set.
 int nearestPointToSetPoint(int pointIndex)
          Returns the set point index neareat to the set point having the specified index, other than this point itself.
 int numberPoints()
          Returns the number of points in this set.
 boolean remove(int pointIndex)
          Remoces the specified point index from this set.
 boolean replacePointIndex(int oldPointIndex, int newPointIndex)
          Replaces the point index oldPointIndex with newPointIndex.
 void setPointIndices(IntegerVector pointIndices)
          Sets the vector of point indices.
 Point2DSet toPoint2DSet()
          Returns a Point2DSet equivalent of this object.
 java.lang.String toString()
          Returns a String representation of a IndexPoint2DSet object.
 X3DNode toX3DNode(X3DObject x3dObject)
          X3D support.
 org.w3c.dom.Element toXMLNode(org.w3c.dom.Document document, org.w3c.dom.Element documentRootNode)
          Returns the xml node of this object.
 
Methods inherited from class com.hedgehog.geo.twod.IndexPointObject2D
getPoints, getPointsVector, isCurve, isGrid, isMesh, isPoint, isPointSet, isShape, isSurface, isValid, isValidIndex, maxPointIndex, minPointIndex, setPoints, threeNonCollinearPoints
 
Methods inherited from class com.hedgehog.geo.twod.IndexObject2D
is2D, is3D
 
Methods inherited from class com.hedgehog.geo.GeometricObject
objectDimension
 
Methods inherited from class com.hedgehog.HObject
clone, compare, compareTo, copy, equals, getID, getName, hashCode, hasID, hasName, setID, setName
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

mPointIndices

protected IntegerVector mPointIndices
Point set point indices vector.

Constructor Detail

IndexPoint2DSet

public IndexPoint2DSet()
Default constructor. Creates an empty but non-null vector of point indices.


IndexPoint2DSet

public IndexPoint2DSet(Point2DSet pset)
                throws java.lang.IllegalArgumentException
Constructor. Creates a new non-null empty vector of point indices.

Parameters:
pset - Underlying Point2DSet object of points.
Throws:
java.lang.IllegalArgumentException - Thrown if points is null.

IndexPoint2DSet

public IndexPoint2DSet(Point2DSet pset,
                       IntegerVector pointIndices)
                throws java.lang.IllegalArgumentException
Constructor.

Parameters:
pset - Underlying Point2DSet object of points.
pointIndices - Vector of point indices.
Throws:
java.lang.IllegalArgumentException - Thrown if pset is null, pointIndices is null or any point index is out of range.

IndexPoint2DSet

public IndexPoint2DSet(java.util.Vector<Point2D> points)
                throws java.lang.IllegalArgumentException
Constructor. Creates a new non-null empty vector of point indices.

Parameters:
points - Vector of points.
Throws:
java.lang.IllegalArgumentException - Thrown if points is null.

IndexPoint2DSet

public IndexPoint2DSet(java.util.Vector<Point2D> points,
                       IntegerVector pointIndices)
                throws java.lang.IllegalArgumentException
Constructor.

Parameters:
points - Vector of points.
pointIndices - Vector of point indices.
Throws:
java.lang.IllegalArgumentException - Thrown if points is null, pointIndices is null or any point index is out of range.

IndexPoint2DSet

public IndexPoint2DSet(java.util.Vector<Point2D> points,
                       java.util.Vector<IndexPoint2D> indexPoints)
Constructor. Creates an IndexPoint2DSet object from the specified vector of IndexPoint2D objects.

Parameters:
points - The points vector.
indexPoints - Vector of IndexPoint2D objects.

IndexPoint2DSet

public IndexPoint2DSet(java.util.Vector<Point2D> points,
                       int pointIndex)
Constructor. Initialises a point set with the specified point index.

Parameters:
points - Points vector.
pointIndex - Index of point used to initialise this point set.

IndexPoint2DSet

public IndexPoint2DSet(java.lang.String name)
Constructor. Creates an empty but non-null vector of points.

Parameters:
name - Point set name.

IndexPoint2DSet

public IndexPoint2DSet(ID id)
Constructor. Creates an empty but non-null vector of points.

Parameters:
id - Point set ID.

IndexPoint2DSet

public IndexPoint2DSet(java.lang.String name,
                       ID id)
Constructor. Creates an empty but non-null vector of points.

Parameters:
name - Point set name.
id - Point set ID.

IndexPoint2DSet

public IndexPoint2DSet(IndexPoint2DSet object)
Copy constructor.

Parameters:
object - Object to copy.
Method Detail

add

public boolean add(int pointIndex,
                   boolean performCheck)
Adds the specified point index to this set.

Parameters:
pointIndex - Point index.
performCheck - Specifies whether or not tp perform checks when adding the point-index.
Returns:
Logical-true if the specified point-index is added, else logical-false.

boundingBox

public AxisAlignedBox2D boundingBox()
Returns the axis aligned bounding box of this point set.

Returns:
Point set bounding box.

clear

public void clear()
Clears the mPointIndices vector, thus emptying this set.


convexHull

public ConvexStraightEdgePolygon2D convexHull(ConvexHullMethod hullMethod)
                                       throws java.lang.IllegalArgumentException
Returns the convex hull of this index-point set. Currently only supports ConvexHullMethod.INCREMENTAL and ConvexHullMethod.APPROXIMATE_BFP. If method is equal to ConvexHullMethod.INCREMENTAL then IncrementalConvexHull2D is called. If method is equal to ConvexHullMethod.APPROXIMATE_BFP then ApproximateConvexHull2D is called.

Parameters:
hullMethod - Method used to generate the hull.
Returns:
Convex hull of this index-point set. Returns a null value if unable to generate the hull polygon.
Throws:
java.lang.IllegalArgumentException - Thrown if hullMethod is invalid.

isMember

public boolean isMember(int pointIndex)
Tests whether or not the specified point index is a member of this set.

Parameters:
pointIndex - Point index to test.
Returns:
Logical-true if pointIndex is a member of this set, else logical-false.

numberPoints

public int numberPoints()
Returns the number of points in this set.

Overrides:
numberPoints in class IndexPointObject2D
Returns:
Number of points in this set.

isEmpty

public boolean isEmpty()
Tests whether ro not this set is empty.

Returns:
Logical-true if this set is empty, else logical-false.

getPointIndices

public IntegerVector getPointIndices()
Returns the set's vector of point indices.

Returns:
Vector point set indices.

getPointIndex

public int getPointIndex(int i)
Returns the point index at the specified index in the mPointIndices vector.

Parameters:
i - Index into mPointIndices vector.
Returns:
point index at specified vector index.

setPointIndices

public void setPointIndices(IntegerVector pointIndices)
                     throws java.lang.IllegalArgumentException
Sets the vector of point indices.

Parameters:
pointIndices - New vector of point indices.
Throws:
java.lang.IllegalArgumentException - Thrown if any of the specified point indices are out of range.

nearestPoint

public int nearestPoint(IndexPoint2D p)
Returns the set point nearest to the specified index-point, which can be any point and is assumed not to be a point of this set. Performs a linear traversal of the point set which is suitable for small point sets but for large point sets you may wish to use IndexPointBackgroundGrid2D instead.

Parameters:
p - Index point.
Returns:
Set to the index of the point in this set nearest to the specified point. A value of -1 is returned if no nearest point is found; eg empty set point.

nearestPoint

public int nearestPoint(Point2D p)
Returns the set point nearest to the specified point, which can be any point and is assumed not to be a point of this set. Performs a linear traversal of the point set which is suitable for small point sets but for large point sets you may wish to use IndexPointBackgroundGrid2D instead.

Parameters:
p - Point.
Returns:
Set to the index of the point in this set nearest to the specified point. A value of -1 is returned if no nearest point is found; eg empty set point.

nearestPointToSetPoint

public int nearestPointToSetPoint(int pointIndex)
                           throws java.lang.IllegalArgumentException
Returns the set point index neareat to the set point having the specified index, other than this point itself. Performs a linear traversal of the point set for the test, which is suitable for small point sets but for large point sets you may wish to use PointBackgroundGrid2D instead.

Parameters:
pointIndex - Set point index.
Returns:
Set to the index of the poit in this set nearest to the specified set point. A value of -1 is returned if no nearest point is found; eg p is the single set point.
Throws:
java.lang.IllegalArgumentException - Thrown if p is not a member of this set.

replacePointIndex

public boolean replacePointIndex(int oldPointIndex,
                                 int newPointIndex)
Replaces the point index oldPointIndex with newPointIndex.

Parameters:
oldPointIndex - Old point index.
newPointIndex - New point index.
Returns:
Logical-true if index replaced, else logical-false.

remove

public boolean remove(int pointIndex)
Remoces the specified point index from this set.

Parameters:
pointIndex - Point index to remove.
Returns:
Logical-true if the specified point-index is removed, else logical-false.

getPoint

public Point2D getPoint(int pointIndex)
                 throws java.lang.IllegalArgumentException
Returns the actual point with the specified index.

Parameters:
pointIndex - Point index.
Returns:
Point with the specified point index in this set.
Throws:
java.lang.IllegalArgumentException - Thrown if the specified point index is not an index of this set.

toString

public java.lang.String toString()
Returns a String representation of a IndexPoint2DSet object.

Overrides:
toString in class java.lang.Object
Returns:
A String representation of a IndexPoint2DSet object.

toPoint2DSet

public Point2DSet toPoint2DSet()
Returns a Point2DSet equivalent of this object.

Returns:
Converts this object to a Point2DSet object.

childModelObjects

public java.util.Vector<ModelObject> childModelObjects()
Returns a vector of this object's child ModelObject objects.

Specified by:
childModelObjects in interface ModelObject
Returns:
Returns a vector consists of a single element of this object's Point2DSet object.

databaseInsertStatement

public java.sql.PreparedStatement databaseInsertStatement(java.sql.Connection connection,
                                                          int modelID)
                                                   throws java.sql.SQLException
Returns a prepared statement for inserting (INSERT command) a ModelObject object into a database.

Specified by:
databaseInsertStatement in interface ModelObject
Parameters:
connection - Database connection.
modelID - Model ID.
Returns:
A prepared statement for inserting a ModelObject object into a database.
Throws:
java.sql.SQLException - Thrown if an SQL exception occurs.

databaseUpdateStatement

public java.sql.PreparedStatement databaseUpdateStatement(java.sql.Connection connection,
                                                          int modelID)
                                                   throws java.sql.SQLException
Returns a prepared statement for updating (UPDATE command) a ModelObject object into a database.

Specified by:
databaseUpdateStatement in interface ModelObject
Parameters:
connection - Database connection.
modelID - Model ID.
Returns:
A prepared statement for inserting a ModelObject object into a database.
Throws:
java.sql.SQLException - Thrown if an SQL exception occurs.

toXMLNode

public org.w3c.dom.Element toXMLNode(org.w3c.dom.Document document,
                                     org.w3c.dom.Element documentRootNode)
                              throws InvalidObjectException
Returns the xml node of this object.

Specified by:
toXMLNode in interface ModelObject
Parameters:
document - XML document.
documentRootNode - Document root node.
Returns:
The xml node of this object.
Throws:
InvalidObjectException - Thrown if this object's ID is equal to the default ID of -1.

fromXMLNode

public ModelObject fromXMLNode(org.w3c.dom.Document document,
                               org.w3c.dom.Node documentRootNode,
                               org.w3c.dom.Node node,
                               Model model)
                        throws InvalidObjectException
Returns a model object from the specified xml node.

Specified by:
fromXMLNode in interface ModelObject
Parameters:
document - XML document.
documentRootNode - Document root node; ie Model node.
node - XML node.
model - The model to which the returned object is associated.
Returns:
ModelObject corresponding to the specified node. A null value is returned if an error occurred building the object.
Throws:
InvalidObjectException - Thrown if an error occurred building the object.

fromDatabase

public ModelObject fromDatabase(java.sql.Connection connection,
                                Model model,
                                int modelID,
                                int objectID)
                         throws java.sql.SQLException
Returns a model object from the specified database table.

Specified by:
fromDatabase in interface ModelObject
Parameters:
connection - Database connection.
modelID - Model ID.
objectID - Object ID in associated ModelObjects table.
model - Model built from database.
Returns:
ModelObject corresponding to the specified db connection, model ID and obect ID. A null value is returned if no match found.
Throws:
java.sql.SQLException - Thrown if an SQL exception occurs.

toX3DNode

public X3DNode toX3DNode(X3DObject x3dObject)
                  throws InvalidObjectException
X3D support.

Specified by:
toX3DNode in interface ModelObject
Parameters:
x3dObject - X3D object.
Returns:
X3D object or null if object has no visualisation.
Throws:
InvalidObjectException - Thrown if this object is invalid.