com.hedgehog.geo.threed.points
Class Point3DSet

java.lang.Object
  extended by com.hedgehog.HObject
      extended by com.hedgehog.geo.GeometricObject
          extended by com.hedgehog.geo.threed.points.Point3DSet
All Implemented Interfaces:
ModelObject, java.lang.Comparable, java.util.Comparator

public class Point3DSet
extends GeometricObject
implements ModelObject

Title: Point3DSet - models a set of 3D points.

Description: Models a collection of 3D points. Internally stores the points as a vector.

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

Company: Hedgehog Software.

Since:
1.0
Version:
1.1

Field Summary
protected  java.util.Vector<Point3D> mPoints
          Point set.
 
Fields inherited from class com.hedgehog.HObject
mID, mName
 
Constructor Summary
Point3DSet()
          Default constructor.
Point3DSet(java.util.ArrayList<Point3D> points)
          Constructor.
Point3DSet(ID id)
          Constructor.
Point3DSet(Point3D point)
          Constructor.
Point3DSet(Point3D[] points)
          Constructor.
Point3DSet(Point3DSet object)
          Copy constructor.
Point3DSet(java.lang.String name)
          Constructor.
Point3DSet(java.lang.String name, ID id)
          Constructor.
Point3DSet(java.util.Vector<Point3D> points)
          Constructor.
Point3DSet(VectorOpt<Point3D> points)
          Constructor.
 
Method Summary
 boolean add(Point3D p, boolean performCheck, double tolerance)
          Adds the specified point to this point set.
 AxisAlignedBox3D boundingBox()
          Returns the axis aligned bounding box of this point set.
 Sphere3D boundingBoxEnclosingSphere()
          Returns the circle that encloses the bounding box of this point set.
 Sphere3D boundingCentroidSphere()
          Returns the bounding sphere centred at the point set centroid and radius sufficient to enclose all points.
 Point3D centroid()
          Returns the centroid of this point set.
 java.util.Vector<ModelObject> childModelObjects()
          Returns a vector of this object's child ModelObject objects.
 void clear()
          Clears this point by emptying the vector of points.
 boolean contains(Point3D p, double tolerance)
          Tests whether or not the specified point (within the specified tolerance) is contained within this 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.
 Point3D getPoint(int index)
          Returns the point having the specified index.
 java.util.Vector<Point3D> getPoints()
          Returns the point set points vector.
 boolean is2D()
          Tests whether or not this object is a 2D obect; ie false.
 boolean is3D()
          Tests whether or not this object is a 3D obect; ie true.
 boolean isCurve()
          Tests whether or not this object is a curve; ie false.
 boolean isEmpty()
          Tests whether or not this point set is empty.
 boolean isGrid()
          Tests whether or not this object is a grid; ie false.
 boolean isMember(Point3D p, double tolerance)
          Tests whether or not the specified point is a member of this set.
 boolean isMesh()
          Tests whether or not this object is a mesh; ie false.
 boolean isParallelToCoordinatePlane(int plane, double tolerance)
          Tests whether or not a point set is parallel or lies in one of the three coordinate planes.
 boolean isPoint()
          Tests whether or not this object is a point; ie false.
 boolean isPointIndex(int index)
          Tests whether or not the specified index is a valid index of the underlying vector.
 boolean isPointSet()
          Tests whether or not this object is a point set; ie true.
 boolean isShape()
          Tests whether or not this object is a shape; ie false.
 boolean isSurface()
          Tests whether or not this object is a surface; ie false.
 PairPQ<Point3D,HDouble> minEnclosingSphere(double tolerance)
          Returns the minimum area circle containing this point set.
 Point3D nearestPoint(Point3D 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.
 Point3D nearestPointToSetPoint(Point3D p, double tolerance)
          Returns the set point nearest to the specified point, other than p itself.
 int numberPoints()
          Returns the number of points in this set.
 int[] pointIDs()
          Returns an array of this object's point IDs.
 boolean remove(int index)
          Removes from this point set the point with the specified index.
 boolean remove(Point3D p)
          Removes the specified point from this point set.
 boolean samePointSet(Point3DSet pset, double tolerance)
          Tests if two point sets are equivalent; ie both sets are of the same size and all points of one set exist in the other.
 void setPoint(Point3D p, int index)
          Sets the point at the specified index to the new point p.
 void setPoints(java.util.Vector<Point3D> points)
          Sets the points vector.
 int size()
          Returns the number of points in this set.
 java.lang.String toString()
          Returns a String representation of a Point3DSet object.
 X3DNode toX3DNode(X3DObject x3dObject)
          X3D support.
 org.w3c.dom.Element toXMLNode(org.w3c.dom.Document document, org.w3c.dom.Element doucmentRootNode)
          Returns the xml node of this object.
 
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

mPoints

protected java.util.Vector<Point3D> mPoints
Point set.

Constructor Detail

Point3DSet

public Point3DSet()
Default constructor. Sets up a new non-null but empty vector of points.


Point3DSet

public Point3DSet(java.util.Vector<Point3D> points)
Constructor. Sets up a new point set from the specified vector of points.

Parameters:
points - Vector of points.

Point3DSet

public Point3DSet(java.util.ArrayList<Point3D> points)
Constructor. Sets up a new point set from the specified vector of points.

Parameters:
points - Vector of points.

Point3DSet

public Point3DSet(VectorOpt<Point3D> points)
Constructor. Sets up a new point set from the specified vector of points.

Parameters:
points - Vector of points.

Point3DSet

public Point3DSet(Point3D[] points)
Constructor. Sets up a new point set from the specified Java 1D array of points.

Parameters:
points - Vector of points.

Point3DSet

public Point3DSet(Point3D point)
Constructor. Initialises a point set with the specified point.

Parameters:
point - Point to intialise a point set.

Point3DSet

public Point3DSet(java.lang.String name)
Constructor. Sets up a new non-null but empty vector of points.

Parameters:
name - Point set name.

Point3DSet

public Point3DSet(ID id)
Constructor. Sets up a new non-null but empty vector of points.

Parameters:
id - Point set ID.

Point3DSet

public Point3DSet(java.lang.String name,
                  ID id)
Constructor. Sets up a new non-null but empty vector of points.

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

Point3DSet

public Point3DSet(Point3DSet object)
Copy constructor.

Parameters:
object - Object to copy.
Method Detail

add

public boolean add(Point3D p,
                   boolean performCheck,
                   double tolerance)
Adds the specified point to this point set.

Parameters:
p - Point to add.
performCheck - Specifies whether or not to check that p is not already a member of this set.
tolerance - Required tolerance.
Returns:
Logical-true if p is added, else logical-false.

boundingBox

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

Returns:
Point set bounding box.

boundingBoxEnclosingSphere

public Sphere3D boundingBoxEnclosingSphere()
Returns the circle that encloses the bounding box of this point set. Used by boundingSuperTriangle() for generating the bounding super triangle.

Returns:
Bounding box enclosing circle.

boundingCentroidSphere

public Sphere3D boundingCentroidSphere()
Returns the bounding sphere centred at the point set centroid and radius sufficient to enclose all points.

Returns:
Enclosing sphere centred at point set centroid.

centroid

public Point3D centroid()
Returns the centroid of this point set. If the set is null or empty then Point3D() is returned.

Returns:
Point set centroid.

clear

public void clear()
Clears this point by emptying the vector of points.


contains

public boolean contains(Point3D p,
                        double tolerance)
Tests whether or not the specified point (within the specified tolerance) is contained within this point set.

Parameters:
p - Point to test.
tolerance - Required tolerance.
Returns:
Logical-tue if p is in this point set, else logical-false.

getPoint

public Point3D getPoint(int index)
                 throws java.lang.IllegalArgumentException
Returns the point having the specified index.

Parameters:
index - Index into this point set vector.
Returns:
Point at specified index.
Throws:
java.lang.IllegalArgumentException - Thrown if index if out of range.

getPoints

public java.util.Vector<Point3D> getPoints()
Returns the point set points vector.

Returns:
Point set points.

setPoints

public void setPoints(java.util.Vector<Point3D> points)
Sets the points vector.

Parameters:
points - New points vector.

isPointIndex

public boolean isPointIndex(int index)
Tests whether or not the specified index is a valid index of the underlying vector.

Parameters:
index - Index to test.
Returns:
Logical-true if the specified index is a valid index of the underlying vector, else logical-false.

remove

public boolean remove(int index)
Removes from this point set the point with the specified index.

Parameters:
index - point index.
Returns:
Logical-true if the point having the specified index is removed, else logical-false if index is out of range and the point is not removed.

remove

public boolean remove(Point3D p)
Removes the specified point from this point set.

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

setPoint

public void setPoint(Point3D p,
                     int index)
              throws java.lang.IllegalArgumentException
Sets the point at the specified index to the new point p.

Parameters:
p - New point p.
index - Set index.
Throws:
java.lang.IllegalArgumentException - Thrown if index is out of range.

samePointSet

public boolean samePointSet(Point3DSet pset,
                            double tolerance)
Tests if two point sets are equivalent; ie both sets are of the same size and all points of one set exist in the other. Uses Point3D.samePoint() to compare two points.

Parameters:
pset - Point set to compare against this point set.
tolerance - Required tolerance.
Returns:
Logical-true if two sets are equivalent.

numberPoints

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

Returns:
Number of points in this set.

size

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

Returns:
Number of points in this set.

isEmpty

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

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

isMember

public boolean isMember(Point3D p,
                        double tolerance)
Tests whether or not the specified point is a member of this set. Performs a linear traversal of the point set using Point3D.samePoint() for the test, which is suitable for small point sets but for large point sets you may wish to use PointBackgroundGrid3D instead.

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

minEnclosingSphere

public PairPQ<Point3D,HDouble> minEnclosingSphere(double tolerance)
Returns the minimum area circle containing this point set. Calls the support class MinSphere3D for generating the minimum enclosing sphere.

Parameters:
tolerance - Required tolerance.
Returns:
Minimum enclosing circle centre and radius pair.
See Also:
MinSphere3D

nearestPoint

public Point3D nearestPoint(Point3D 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 for the test, which is suitable for small point sets but for large point sets you may wish to use PointBackgroundGrid3D r KDTreePoint3D instead.

Parameters:
p - Point.
Returns:
Set point nearest to p. A null value is returned if no nearest point is found; eg empty set point.
See Also:
PointBackgroundGrid3D, KDTreePoint3D

nearestPointToSetPoint

public Point3D nearestPointToSetPoint(Point3D p,
                                      double tolerance)
                               throws java.lang.IllegalArgumentException
Returns the set point nearest to the specified point, other than p itself. Performs a linear traversal of the point set using Point3D.samePoint() for the test, which is suitable for small point sets but for large point sets you may wish to use PointBackgroundGrid3D instead.

Parameters:
p - Set point.
tolerance - Required tolerance.
Returns:
Set point nearest to p. A null value 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.

pointIDs

public int[] pointIDs()
Returns an array of this object's point IDs.

Returns:
An array of this object's point IDs.

isParallelToCoordinatePlane

public boolean isParallelToCoordinatePlane(int plane,
                                           double tolerance)
                                    throws java.lang.IllegalArgumentException
Tests whether or not a point set is parallel or lies in one of the three coordinate planes.

Parameters:
plane - Indicates the type of coordinate plane: CoordinatePlaneType.XY_PLANE, CoordinatePlaneType.YZ or CoordinatePlaneType.XZ.
tolerance - Required tolerance.
Returns:
Logical-true if this point set is parallel to the specified coordinate plane, else logical-false.
Throws:
java.lang.IllegalArgumentException - Thrown if the specified plane is not CoordinatePlaneType.XY_PLANE, CoordinatePlaneType.YZ or CoordinatePlaneType.XZ.

toString

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

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

is2D

public boolean is2D()
Tests whether or not this object is a 2D obect; ie false.

Specified by:
is2D in class GeometricObject
Returns:
Logical-false.

is3D

public boolean is3D()
Tests whether or not this object is a 3D obect; ie true.

Specified by:
is3D in class GeometricObject
Returns:
Logical-true.

isPoint

public boolean isPoint()
Tests whether or not this object is a point; ie false.

Specified by:
isPoint in class GeometricObject
Returns:
Logical-false.

isPointSet

public boolean isPointSet()
Tests whether or not this object is a point set; ie true.

Specified by:
isPointSet in class GeometricObject
Returns:
Logical-true.

isCurve

public boolean isCurve()
Tests whether or not this object is a curve; ie false.

Specified by:
isCurve in class GeometricObject
Returns:
Logical-false.

isGrid

public boolean isGrid()
Tests whether or not this object is a grid; ie false.

Specified by:
isGrid in class GeometricObject
Returns:
Logical-false.

isMesh

public boolean isMesh()
Tests whether or not this object is a mesh; ie false.

Specified by:
isMesh in class GeometricObject
Returns:
Logical-false.

isSurface

public boolean isSurface()
Tests whether or not this object is a surface; ie false.

Specified by:
isSurface in class GeometricObject
Returns:
Logical-false.

isShape

public boolean isShape()
Tests whether or not this object is a shape; ie false.

Specified by:
isShape in class GeometricObject
Returns:
Logical-false.

childModelObjects

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

Specified by:
childModelObjects in interface ModelObject
Returns:
A vector consisting of the vector of points.

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 doucmentRootNode)
                              throws InvalidObjectException
Returns the xml node of this object.

Specified by:
toXMLNode in interface ModelObject
Parameters:
document - XML document.
doucmentRootNode - 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 - Model to which the object is added.
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. All point set points are initially assigned the colour of this point set (if any) and white if this point set has no assigned colour attribute. The method used to assign attribute colours (if any) is to first see if a ColourAttribute attribute is associated with a point and if so to then assign the colour directly. If no ColourAttribute attributes are associated then it tests for MaterialAttribute attributes and if present then to extract the diffuse colour component. Finally, if no ColourAttribute or MaterialAttribute attributes are found then it checks for AppearanceAttribute attributes and if present then extracts the diffuse colour of the appearance attribute's material property.

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.