maspack.geometry
Class HalfEdge

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

public class HalfEdge
extends Feature
implements Boundable

Half-edge for 3D dimensional polyhedral objects. A half-edge is a directed edge between two counter-clockwise adjacent vertices of a face. Two adjacent half-edges together define a single edge.


Field Summary
 Vertex3d head
           
 HalfEdge opposite
           
 Vertex3d tail
           
 
Fields inherited from class maspack.geometry.Feature
CELL, EDGE, FACE, FACET, HALF_EDGE, TYPE_MASK, UNKNOWN, VERTEX_2D, VERTEX_3D, VISITED
 
Constructor Summary
HalfEdge()
           
HalfEdge(Vertex3d head, HalfEdge opp, Face face)
          Creates a new half-edge with a specified head vertex, opposite half-edge, and face.
HalfEdge(Vertex3d head, Vertex3d tail, Face face)
          Creates a new half-edge with a specified head vertex, tail vertex, and face.
 
Method Summary
 void addAngleWeightedNormal(Vector3d res, HalfEdge he)
           
 void computeCentroid(Vector3d p)
          Computed the centroid of this element.
 double computeCovariance(Matrix3d C)
          Computes covariance of this half edge and returns its length.
 double computeEdgeUnitVec(Vector3d u)
          Computes a unit vector for the edge associated with this half-edge, and returns the edge's length.
 void computeUnitVec(Vector3d u)
          Computes a unit vector in the direction of this edge, and returns the edge's length.
 void computeVertexNormal(Vector3d nrm, boolean useRenderNormals)
          Computes a normal for the head vertex of this half-edge, by averaging all the surrounding face normals starting with the face corresponding to this half edge, and ending when either a hard edge is encountered, or when all faces have been traversed.
static HalfEdge createLineSegment(Vertex3d v1, Vertex3d v2)
          Creates a pair of adjacent half-edges that together define a line segment connecting two vertices.
 double dotDirection(Vector3d v1)
          Computes the dot product between a vector v1 and a non-normalized vector in the direction of this half-edge.
 Face getFace()
          Returns the face associated with this half-edge.
 Vertex3d getHead()
           
 HalfEdge getNext()
           
 Point3d getPoint(int idx)
          Returns the idx-th point associated with this element.
 HalfEdge getPrimary()
           
 Vertex3d getTail()
           
 boolean intersectionWithFace(Face aFace)
           
 boolean isHard()
           
 boolean isPrimary()
           
 HalfEdge lastHardEdge()
          Returns the last hard edge (if any) incident on this half-edge's head vertex, relative to this half-edge in a counter-clockwise direction about the vertex.
 double length()
          Returns the length of this half-edge.
 double lengthSquared()
          Returns the length squared of this half-edge.
 int numPoints()
          Returns the number of points associated with this element, if any, or zero otherwise.
 java.lang.String pointList()
           
 void setHard(boolean hard)
           
 void setNext(HalfEdge heNext)
          Sets the next half-edge adjacent to this one (in a counter-clockwise sense).
 void setPrimary(boolean primary)
           
 double sideProductDirection(Vector3d v1, Vector3d v2)
          Computes the dot product of (v1 X dir) and v2, where dir is the vector from the head to the tail of this half-edge.
 void updateBounds(Point3d min, Point3d max)
          Updates the axis-aligned bounds of this element.
 
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

head

public Vertex3d head

tail

public Vertex3d tail

opposite

public HalfEdge opposite
Constructor Detail

HalfEdge

public HalfEdge()

HalfEdge

public HalfEdge(Vertex3d head,
                Vertex3d tail,
                Face face)
Creates a new half-edge with a specified head vertex, tail vertex, and face.

Parameters:
head - head vertex
tail - head vertex
face - associated face

HalfEdge

public HalfEdge(Vertex3d head,
                HalfEdge opp,
                Face face)
Creates a new half-edge with a specified head vertex, opposite half-edge, and face. The head vertex is assumed to correspond to the tail of the opposite half-edge. Both half-edges are set to be each other's opposites.

Parameters:
head - head vertex
opp - opposite half-edge
face - associated face
Method Detail

isHard

public boolean isHard()

setHard

public void setHard(boolean hard)

setNext

public void setNext(HalfEdge heNext)
Sets the next half-edge adjacent to this one (in a counter-clockwise sense).

Parameters:
heNext - next half-edge

createLineSegment

public static HalfEdge createLineSegment(Vertex3d v1,
                                         Vertex3d v2)
Creates a pair of adjacent half-edges that together define a line segment connecting two vertices.

Parameters:
v1 - first vertex on the line segment
v2 - second vertex on the line segment
Returns:
the half edge whose head is the first vertex

computeEdgeUnitVec

public double computeEdgeUnitVec(Vector3d u)
Computes a unit vector for the edge associated with this half-edge, and returns the edge's length. The direction runs from the tail to the head if the half-edge is primary (i.e., isPrimary() returns true), and from the head to the tail otherwise. If the length of the edge is 0, all elements of the vector are set to 0.

Parameters:
u - returns the edge unit vector

computeUnitVec

public void computeUnitVec(Vector3d u)
Computes a unit vector in the direction of this edge, and returns the edge's length. The direction is defined as running from the tail to the head. If the length of the edge is 0, all elements of the vector are set to 0.

Parameters:
u - returns the normalized direction vector

getFace

public Face getFace()
Returns the face associated with this half-edge.

Returns:
associated face

lastHardEdge

public HalfEdge lastHardEdge()
Returns the last hard edge (if any) incident on this half-edge's head vertex, relative to this half-edge in a counter-clockwise direction about the vertex. If there is no hard-edge incident on the vertex, null is returned.


computeVertexNormal

public void computeVertexNormal(Vector3d nrm,
                                boolean useRenderNormals)
Computes a normal for the head vertex of this half-edge, by averaging all the surrounding face normals starting with the face corresponding to this half edge, and ending when either a hard edge is encountered, or when all faces have been traversed. Face traversal proceeds in a clockwise direction about the vertex.


dotDirection

public double dotDirection(Vector3d v1)
Computes the dot product between a vector v1 and a non-normalized vector in the direction of this half-edge.

Parameters:
v1 - vector to dot with direction vector
Returns:
dot product

addAngleWeightedNormal

public void addAngleWeightedNormal(Vector3d res,
                                   HalfEdge he)

length

public double length()
Returns the length of this half-edge.

Returns:
half-edge length

lengthSquared

public double lengthSquared()
Returns the length squared of this half-edge.

Returns:
length squared

sideProductDirection

public double sideProductDirection(Vector3d v1,
                                   Vector3d v2)
Computes the dot product of (v1 X dir) and v2, where dir is the vector from the head to the tail of this half-edge.

Parameters:
v1 - first vector
v2 - second vector
Returns:
dot product

getHead

public final Vertex3d getHead()

getNext

public final HalfEdge getNext()

getTail

public final Vertex3d getTail()

pointList

public java.lang.String pointList()

isPrimary

public boolean isPrimary()

getPrimary

public HalfEdge getPrimary()

setPrimary

public void setPrimary(boolean primary)

intersectionWithFace

public boolean intersectionWithFace(Face aFace)

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

computeCentroid

public void computeCentroid(Vector3d p)
Description copied from interface: Boundable
Computed the centroid of this element.

Specified by:
computeCentroid in interface Boundable
Parameters:
p - returns the computed centroid value.

computeCovariance

public double computeCovariance(Matrix3d C)
Computes covariance of this half edge and returns its length.

The formula was determined by substituting the the parametric form for x

 x = (1-s) p0 + s p1
 
into the general formula for C
 C = \int_V \rho x x^T dV
 
and evaluating the integral over the s interval [0,1].

Specified by:
computeCovariance in interface Boundable
Parameters:
C - returns the covariance
Returns:
length of the half edge

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.