maspack.geometry
Class Face

java.lang.Object
  extended by maspack.geometry.Feature
      extended by maspack.geometry.Face
All Implemented Interfaces:
Boundable

public class Face
extends Feature
implements Boundable


Field Summary
 int idx
           
static double insideTriangleTolerance
           
 
Fields inherited from class maspack.geometry.Feature
CELL, EDGE, FACE, FACET, HALF_EDGE, TYPE_MASK, UNKNOWN, VERTEX_2D, VERTEX_3D, VISITED
 
Constructor Summary
Face(int idx)
          Creates an empty face with a specified index value.
 
Method Summary
 void clearNormal()
          Clears the normal vector for this face.
 double computeArea()
          Computes the area of this face.
 void computeCentroid(Vector3d centroid)
          Computes centroid of this face.
 void computeCoords(Point3d pnt, Vector2d coords)
          Computes the barycentric coordinates of a point to the plane
 double computeCovariance(Matrix3d C)
          Computes covariance of this face and returns its area.
 void computeNormal()
          Computes the normal for this face.
 void computeNormal(Vector3d normal)
          Computes the normal for this face.
 void computePoint(Point3d pnt, Vector2d coords)
          Computes a point on this face as described by barycentric coordinates.
 void computeRenderNormal()
           
 void computeWorldCentroid(Point3d pnt)
           
static Face create(Vertex3d... vtxs)
           
 HalfEdge firstHalfEdge()
          Returns the first half-edge associated with this face.
 HalfEdge getEdge(int idx)
          Returns a specific edge associated with this face, or null is the edge does not exist.
 int getIndex()
          Returns the index value for this faces.
 MeshBase getMesh()
           
 Vector3d getNormal()
          Returns a normal vector for this face.
 Point3d getPoint(int idx)
          Returns the idx-th point associated with this element.
 double getPoint0DotNormal()
           
 Vector3d getRenderNormal()
           
 Vertex3d getVertex(int idx)
           
 int[] getVertexIndices()
          Returns an array of the vertex indices associated with this face.
 Vertex3d[] getVertices()
           
 Vector3d getWorldNormal()
           
 int indexOfEdge(HalfEdge halfEdge)
          Returns the index of a specified HalfEdge, or -1 if the half edge does not belong to this face.
 int indexOfVertex(Vertex3d vtx)
          Returns the vertex associated with a specified vertex, or -1 if the vertex is not found in this face.
 boolean isFirstQuadTriangle()
          Check to see if this face is the first triangle of a triangulated quad.
 boolean isPointInside(double x, double y, double z)
           
 boolean isTriangle()
           
 void nearestPoint(Point3d pc, Point3d p1)
          Computes the closest point on this face to a specified point.
 int numEdges()
          Returns the number of edges associated with the face.
 int numPoints()
          Returns the number of points associated with this element, if any, or zero otherwise.
 int numVertices()
           
 boolean set(Vertex3d[] vtxs, int numVtxs, boolean connect)
          Creates a face from a counter-clockwise list of vertices.
 void setFirstQuadTriangle(boolean firstQuad)
          Sets a flag indicating that this face is the first triangle of a triangulated quad.
 void setIndex(int i)
          Sets the index value for this face.
 void triangulate(java.util.ArrayList<Vertex3d[]> tris)
          Returns a list of Vertex3d[3] representing the triangulated faces.
 void updateBounds(Point3d min, Point3d max)
          Updates the axis-aligned bounds of this element.
 void updateNormalAndEdges()
          Called to update normal and edge data when vertices have been transformed
 
Methods inherited from class maspack.geometry.Feature
checkFlag, clearFlag, clearVisited, getType, getTypeName, isVisited, setFlag, setVisited, voronoiCheck
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

idx

public int idx

insideTriangleTolerance

public static double insideTriangleTolerance
Constructor Detail

Face

public Face(int idx)
Creates an empty face with a specified index value.

Parameters:
idx - desired index value
Method Detail

getIndex

public int getIndex()
Returns the index value for this faces.

Returns:
index value

setIndex

public void setIndex(int i)
Sets the index value for this face.

Parameters:
i - new index value

isTriangle

public boolean isTriangle()

isFirstQuadTriangle

public boolean isFirstQuadTriangle()
Check to see if this face is the first triangle of a triangulated quad.

Returns:
true if this face is the first triangle of a triangulated quad.
See Also:
setFirstQuadTriangle(boolean)

setFirstQuadTriangle

public void setFirstQuadTriangle(boolean firstQuad)
Sets a flag indicating that this face is the first triangle of a triangulated quad. This enables rendering software to combine the rendering of this face and the one following it to create a smoothly rendered quad.

Parameters:
firstQuad - True if this face is the first triangle of a triangulated quad.

getVertexIndices

public int[] getVertexIndices()
Returns an array of the vertex indices associated with this face.

Returns:
array of vertex indices

getWorldNormal

public Vector3d getWorldNormal()

getPoint0DotNormal

public double getPoint0DotNormal()

create

public static Face create(Vertex3d... vtxs)

set

public boolean set(Vertex3d[] vtxs,
                   int numVtxs,
                   boolean connect)
Creates a face from a counter-clockwise list of vertices. This involves creating a list of half-edges which link the vertices together.

If connect is true, then these half-edges will also be added to the list of half-edges incident on each vertex, and connected, when possible, to half-edges pointing in the opposite direction. Opposite half-edges are found by searhing the existing half-edges which are incident on each vertex. If an opposite half-edge is already connected to another half-edge, then the current half-edge is considered redundant, no connection is made and the method returns false. A redundant half edge implies that the mesh structure containing this face is non-manifold.

Parameters:
vtxs - vertices to connect
numVtxs - number of vertices to connect
connect - connect to opposite half-edges
Returns:
false if this face contains redundant half edges.

computeCentroid

public void computeCentroid(Vector3d centroid)
Computes centroid of this face.

Specified by:
computeCentroid in interface Boundable
Parameters:
centroid - returns the centroid

computeWorldCentroid

public void computeWorldCentroid(Point3d pnt)

computeCovariance

public double computeCovariance(Matrix3d C)
Computes covariance of this face and returns its area. This is done by subdividing the face into a triangular fan centered on the first vertex, and adding the covariance and area for all the triangles.

Specified by:
computeCovariance in interface Boundable
Parameters:
C - returns the covariance
Returns:
area of the face

computePoint

public void computePoint(Point3d pnt,
                         Vector2d coords)
Computes a point on this face as described by barycentric coordinates. Specifically, if p0, p1 and p2 are the points associated with the first three vertices of this face, and s1 and s2 are the x and y values of coords, then the point is computed from pnt = (1-s1-s2)*p0 + s1*p1 + s2*p2 This method is most often used for triangular faces, but that does not have to be the case.

Parameters:
pnt - returns the computed point
coords - specifies s0 and s0

computeCoords

public void computeCoords(Point3d pnt,
                          Vector2d coords)
Computes the barycentric coordinates of a point to the plane

Parameters:
pnt - the point to consider
coords - the returned coordinates

computeNormal

public void computeNormal()
Computes the normal for this face.


computeNormal

public void computeNormal(Vector3d normal)
Computes the normal for this face.

Parameters:
normal - returns the normal
See Also:
getNormal()

computeArea

public double computeArea()
Computes the area of this face.


getRenderNormal

public Vector3d getRenderNormal()

computeRenderNormal

public void computeRenderNormal()

nearestPoint

public void nearestPoint(Point3d pc,
                         Point3d p1)
Computes the closest point on this face to a specified point.

Parameters:
pc - returns the closest point
p1 - point for which closest point is computed

getNormal

public Vector3d getNormal()
Returns a normal vector for this face. The normal vector is allocated on-demand and computed, upon initialization, using computeNormal. In order to have the normal vector recomputed, one should first clear it using clearNormal.

Returns:
normal vector

clearNormal

public void clearNormal()
Clears the normal vector for this face. A subsequent call to getNormal will cause the normal vector to be reallocated and recomputed.


numEdges

public int numEdges()
Returns the number of edges associated with the face.

Returns:
number of edges

getEdge

public HalfEdge getEdge(int idx)
Returns a specific edge associated with this face, or null is the edge does not exist.

Parameters:
idx - index of the desired edge
Returns:
a specific edge

indexOfEdge

public int indexOfEdge(HalfEdge halfEdge)
Returns the index of a specified HalfEdge, or -1 if the half edge does not belong to this face.


firstHalfEdge

public HalfEdge firstHalfEdge()
Returns the first half-edge associated with this face. Starting with this half-edge, an application can find sucessive half-edges, by following their next pointers, which are arranged in a circular linked link that runs around the face in counter-clockwise order.

Returns:
first half edge

updateBounds

public void updateBounds(Point3d min,
                         Point3d max)
Description copied from interface: Boundable
Updates the axis-aligned bounds of this element. The value in min and max should be decreased or increased, respectively, so that all spatial points associated with this element lie within the axis-aligned box defined by min and max.

Specified by:
updateBounds in interface Boundable
Parameters:
min - minimum values to be updated
max - maximum values to be updated

numVertices

public int numVertices()

getMesh

public MeshBase getMesh()

getVertices

public Vertex3d[] getVertices()

getVertex

public Vertex3d getVertex(int idx)

indexOfVertex

public int indexOfVertex(Vertex3d vtx)
Returns the vertex associated with a specified vertex, or -1 if the vertex is not found in this face.


updateNormalAndEdges

public void updateNormalAndEdges()
Called to update normal and edge data when vertices have been transformed


numPoints

public int numPoints()
Description copied from interface: Boundable
Returns the number of points associated with this element, if any, or zero otherwise. If the element has points, then it's spatial extent is assumed to be enclosed within their convex hull. At present, elements that do not have points cannot be enclosed within oriented bounding box (OBB) trees.

Specified by:
numPoints in interface Boundable
Returns:
number of points associated with this element

getPoint

public Point3d getPoint(int idx)
Description copied from interface: Boundable
Returns the idx-th point associated with this element.

Specified by:
getPoint in interface Boundable
Parameters:
idx - index of the point (must be on the range 0 to Boundable.numPoints()).
Returns:
idx-th point associated with this element. Must not be modified.

isPointInside

public boolean isPointInside(double x,
                             double y,
                             double z)

triangulate

public void triangulate(java.util.ArrayList<Vertex3d[]> tris)
Returns a list of Vertex3d[3] representing the triangulated faces. Note that this does not actually affect the current mesh.