public class DistanceGrid extends java.lang.Object implements Renderable, Scannable
The field is implemented using a regular 3D grid composed of
nx
X ny
X nz
vertices along the x, y
and z directions, giving the grid a resolution of rx
,
ry
, rz
, cells along each of these directions,
where rx = nx-1
, ry = ny-1
, and rz =
nz-1
. The grid has widths w = (wx, wy, wz)
along each of
these directions, and cell widths given by wx/rx
,
wy/ry
, and wz/rz
.
Several coordinate frames are associated with the grid:
Distances for any point within the grid can be obtained by interpolation
of the distances at surrounding vertices. Interpolation can be either
linear or quadratic. Linearly interpolated distances are obtained using
getLocalDistance(maspack.matrix.Point3d)
and are computed using trilinear interpolation
within the grid cell containing the point. If the query point is outside the
grid, then the distance is assigned the special value OUTSIDE_GRID
. Normals can also be obtained, using the
getLocalDistanceAndNormal
methods. Normals are also
interpolated using trilinear interpolation, with the normals at each vertex
being computed on demand by mid-point differencing with adjacent
vertices. Note that this means that the normals do not correspond to
the gradient of the distance function; however, their interpolated values
are smoother than those of the gradient. Gradient values can be obtained
instead, using the getLocalDistanceAndGradient
methods. The
returned gradient is the true gradient of the distance function within the
interpolating cell and a linear function within that cell. All inputs and
outputs for the above described distance methods are assumed to be in local
coordinates. The method getWorldDistance(maspack.matrix.Point3d)
and associated
getWorldDistanceAndNormal
and
getWorldDistanceAndGradient
methods perform the same operations
in world coordinates.
Quadratically interpolated distances are obtained using getQuadDistance(maspack.matrix.Point3d)
. Quadratic interpolation is done within a composite
quadratic cell composed of 2 x 2 x 2 regular cells. To ensure that
all points within the grid can be assigned a unique quadratic cell, the grid
resolution is restricted so that rx
, ry
and
rz
are always even. Moreover, within each quadratic cell,
interpolation is done by partitioning the cell into six tetrahedra, each
with 10 nodes, and then performing quadratic interpolation within the
appropriate tetrahedron. This is done to ensure that the interpolation
function is exactly quadratic instead of tri-quadratic. Because the
interpolation is exactly quadratic, certain operations, such as intersecting
level set surfaces, can be performed by solving a simple quadratic equation.
The gradient of the quadratically interpolated distance function can also be
obtained using getQuadDistanceAndGradient(maspack.matrix.Vector3d, maspack.matrix.Matrix3d, maspack.matrix.Point3d)
; this will return
the gradient of the distance function within the quadratic cell containing
the query point. These gradient values are smoother than those associated
with linear interpolation and so (if normalized) can be used to provide
normal vectors. Consequently, quadratically interpolated normals, analagous
to those returned by getLocalDistanceAndNormal(maspack.matrix.Vector3d, double, double, double)
, are not currently
supported. All inputs and outputs for the above described quadratic distance
methods are assumed to be in local coordinates. The methods
getWorldQuadDistance(maspack.matrix.Point3d)
and
getWorldQuadDistanceAndGradient(maspack.matrix.Vector3d, maspack.matrix.Matrix3d, maspack.matrix.Point3d)
perform the same operations
in world coordinates.
Distances at the grid vertices can either be assigned directly, using
setDistances(double[], boolean)
, or can be computed based on nearest distance
calculations to a set of point-based geometric features such as vertices,
edges, or faces, using computeDistances(java.util.List<? extends maspack.geometry.Feature>, boolean)
. The convenience methods
computeFromFeatures(java.util.List<? extends maspack.geometry.Feature>, double, maspack.matrix.RigidTransform3d, int, boolean)
and computeFromFeaturesOBB(java.util.List<? extends maspack.geometry.Feature>, double, int, boolean)
will both
compute distances and also fit the grid to the features. When computed from
features, each grid vertex is associated with a nearest
feature.
Feature based distance computation assumes that the feature points are
represented in local coordinates. For grid vertices close to the mesh,
nearby features are examined to determine the distance from the mesh to the
vertex. A sweep method is then used to propagate distance values throughout
the volume and determine whether vertices are inside or outside. If the
features are faces, it is possible to request that the grid be
signed. In this case, ray casts are used to determine whether
vertices are inside or outside the feature set, with interior and exterior
vertices being given negative and positive distance values,
respectively. The algorithm is based on C++ code provided by Robert Bridson
(UBC) in the makelevelset3
class of his
common code set.
Modifier and Type | Class and Description |
---|---|
static class |
DistanceGrid.TetDesc |
static class |
DistanceGrid.TetID
Identifies a sub tet within a hex cell.
|
Modifier and Type | Field and Description |
---|---|
static double |
OUTSIDE_GRID
Special distance value indicating that a query point is outside the grid.
|
TRANSPARENT, TWO_DIMENSIONAL
Constructor and Description |
---|
DistanceGrid(java.util.List<? extends Feature> features,
double marginFrac,
int maxRes,
boolean signed)
Creates a new distance grid for a specified list of features,
axis-aligned and centered on the features, with a uniform cell width
along all axes defined so that the resolution along the maximum width
axis is
maxRes . |
DistanceGrid(java.util.List<? extends Feature> features,
double marginFrac,
Vector3i resolution,
boolean signed)
Creates a new distance grid for a specified list of features,
axis-aligned and centered on the features, with a the cell resolution
along each axis given by
resolution . |
DistanceGrid(Vector3d widths,
Vector3i resolution,
RigidTransform3d TCL)
Creates a new distance grid with specified widths, resolution, and
position and orientation of the center given by
TCL . |
DistanceGrid(Vector3i resolution)
Creates a new distance grid, axis-aligned and centered on the origin,
with the specified resolution and x, y, z widths set to 1.
|
Modifier and Type | Method and Description |
---|---|
void |
clearColors()
Clears the color map used to specify vertex colors.
|
void |
clearFeatures()
Clears the features, if any, associated with this distance
grid.
|
void |
computeDifference01(java.util.List<? extends Feature> features) |
void |
computeDifference10(java.util.List<? extends Feature> features) |
void |
computeDistances(java.util.List<? extends Feature> features,
boolean signed)
Computes the distance field for this grid, based on the nearest distances
to a supplied set of features.
|
void |
computeFromFeatures(java.util.List<? extends Feature> features,
double marginFrac,
RigidTransform3d TCL,
int maxRes,
boolean signed)
Fits this grid to a set of features and computes the corresponding
distance field.
|
void |
computeFromFeaturesOBB(java.util.List<? extends Feature> features,
double marginFrac,
int maxRes,
boolean signed)
Fits this grid in an oriented manner to a set of features and computes
the corresponding distance field.
|
void |
computeIntersection(java.util.List<? extends Feature> features) |
void |
computeQuadCoefs(double[] a,
DistanceGrid.TetDesc tdesc) |
void |
computeQuadCoefsStub(double[] a,
DistanceGrid.TetDesc tdesc) |
void |
computeUnion(java.util.List<? extends Feature> features) |
PolygonalMesh |
createDistanceSurface()
Creates a triangular mesh approximating the surface on which the linearly
interpolated distance function equals 0.
|
PolygonalMesh |
createDistanceSurface(double val)
Creates a triangular mesh approximating the surface on which the linearly
interpolated distance function equals
val . |
PolygonalMesh |
createDistanceSurface(double val,
int res)
Creates a triangular mesh approximating the surface on which the linearly
interpolated distance function equals
val . |
PolygonalMesh |
createQuadDistanceSurface(double val,
int res)
Creates a triangular mesh approximating the surface on which the
quadratically interpolated distance function equals
val . |
RenderProps |
createRenderProps()
Factory method to create render properties appropriate to this object.
|
boolean |
epsilonEquals(DistanceGrid grid,
double tol)
Returns
true if this distance grid equals another within a
prescribed tolerance. |
boolean |
findQuadSurfaceIntersection(Point3d pi,
Point3d p0,
Point3d pa,
Vector3d nrm)
Experimental method.
|
boolean |
findQuadSurfaceTangent(Point3d pt,
Point3d p0,
Point3d pa,
Vector3d nrm)
Find a point
pt such that the line segment
pa-pt is tangent to the quadratic zero distance surface and
also lies in the plane defined by point p0 and normal
nrm . |
void |
fitToFeatures(java.util.Collection<java.util.List<? extends Feature>> featureSets,
double marginFrac,
RigidTransform3d TCL,
int maxRes) |
void |
fitToFeatures(java.util.List<? extends Feature> features,
double marginFrac,
RigidTransform3d TCL,
int maxRes) |
void |
fitToFeaturesOBB(java.util.Collection<java.util.List<? extends Feature>> featureSets,
double marginFrac,
int maxRes) |
void |
fitToFeaturesOBB(java.util.List<? extends Feature> features,
double marginFrac,
int maxRes) |
Vector3i |
getCellVertex(Vector3i xyzi,
Point3d point)
Returns the x, y, z indices of the minimum vertex of the cell containing
point . |
Vector3d |
getCellWidths()
Returns the grid cell widths along each axis.
|
void |
getCenter(Vector3d center)
Returns the center of this grid with respect to its
local coordinates.
|
Feature |
getClosestFeature(int idx)
Returns the closest Feature to the vertex indexed by
idx . |
int |
getClosestVertex(Point3d point)
Returns the index of the closest vertex to a point.
|
int |
getDebug() |
java.awt.Color |
getDefaultVertexColor()
Returns the default color used for rendering vertices when a color map is
specified.
|
double[] |
getDistances()
Returns the full array of distances at each vertex.
|
boolean |
getDrawEdges() |
Feature[] |
getFeatures()
Returns the features, if any, associated with this distance
grid Features will be associated with the field if they were used to
compute it, via
computeFromFeatures(java.util.List<? extends maspack.geometry.Feature>, double, maspack.matrix.RigidTransform3d, int, boolean) , computeFromFeaturesOBB(java.util.List<? extends maspack.geometry.Feature>, double, int, boolean) , or one of the associated constructors. |
VectorTransformer3d |
getGridToLocalTransformer()
Returns the transformer that maps from grid to local coordinates.
|
double |
getLocalDistance(Point3d point)
Calculates the distance at an arbitrary point in local coordinates using
multilinear interpolation of the vertex values for the grid cell
containing the point.
|
double |
getLocalDistanceAndGradient(Vector3d grad,
double x,
double y,
double z)
Calculates the distance and gradient at an arbitrary point in
local coordinates using multilinear interpolation, as described
for
getLocalDistanceAndGradient(Vector3d,Point3d) . |
double |
getLocalDistanceAndGradient(Vector3d grad,
Point3d point)
Calculates the distance and gradient at an arbitrary point in local
coordinates using multilinear interpolation of the vertex values for the
grid cell containing the point.
|
double |
getLocalDistanceAndNormal(Vector3d norm,
double x,
double y,
double z)
Calculates the distance and normal at an arbitrary point in local
coordinates using multilinear interpolation, as described
for
getLocalDistanceAndNormal(Vector3d,Point3d) . |
double |
getLocalDistanceAndNormal(Vector3d norm,
Matrix3d Dnrm,
Point3d point)
Calculates the distance and normal at an arbitrary point in local
coordinates using multilinear interpolation, as described for
getLocalDistanceAndNormal(Vector3d,Point3d) . |
double |
getLocalDistanceAndNormal(Vector3d norm,
Point3d point)
Calculates the distance and normal at an arbitrary point in local
coordinates using multilinear interpolation of the vertex values for the
grid cell containing the point.
|
RigidTransform3d |
getLocalToWorld()
Returns the transform that maps from local to world coordinates.
|
VectorTransformer3d |
getLocalToWorldTransformer()
Returns the transformer that maps from local to world coordinates.
|
Vector3d |
getLocalVertexCoords(Vector3d coords,
Vector3i vxyz)
Find the local coordinates at a vertex, as specified by
its x, y, z indices.
|
Feature |
getNearestLocalFeature(Point3d nearest,
Point3d point)
Determines nearest feature to an arbitray point in local coordinates.
|
Feature |
getNearestWorldFeature(Point3d nearest,
Point3d point)
Determines nearest feature to an arbitray point in world coordinates.
|
void |
getOrientation(RotationMatrix3d R)
Returns the orientation of this grid with respect to its
local coordinates.
|
double |
getQuadDistance(Point3d point)
Calculates the distance at an arbitrary point in local coordinates using
quadratic interpolation, as described for
getQuadDistanceAndGradient(maspack.matrix.Vector3d, maspack.matrix.Matrix3d, maspack.matrix.Point3d) . |
double |
getQuadDistanceAndGradient(Vector3d grad,
Matrix3d dgrad,
Point3d point)
Calculates the distance and gradient at an arbitrary point in local
coordinates using quadratic interpolation.
|
DistanceGrid.TetDesc |
getQuadTet(Point3d point)
Used for debugging
|
double |
getRadius()
Returns the radius of this grid, defined as half the
distance across its maximal diagonal.
|
int |
getRenderHints()
Returns a bit code giving rendering hints about this renderable.
|
RenderProps |
getRenderProps()
Returns the render properities for this object.
|
java.lang.String |
getRenderRanges()
Returns a string describing the render ranges for this grid,
as described for
setRenderRanges(java.lang.String) . |
Vector3i |
getResolution()
Returns the resolution of this grid along each axis.
|
void |
getSelection(java.util.LinkedList<java.lang.Object> list,
int qid)
Append to
list the component (or components) associated with
the qid -th selection query issued by this component's render
method. |
java.awt.Color |
getVertexColor(int idx)
Returns the color used for rendering a specific vertex when using a color
map.
|
double |
getVertexDistance(Vector3i vxyz)
Returns the distance at a specified vertex, as specified by x, y, z
indices.
|
Vector3d |
getWidths()
Returns the widths of this grid along the x, y, and z axes.
|
void |
getWidths(Vector3d widths)
Returns the widths of this grid along the x, y, and z axes.
|
void |
getWorldCenter(Point3d center)
Returns the center of this grid, in world coordinates.
|
double |
getWorldDistance(Point3d point)
Calculates the distance at an arbitrary point in world coordinates using
multilinear interpolation of the vertex values for the grid cell
containing the point.
|
double |
getWorldDistanceAndGradient(Vector3d grad,
double x,
double y,
double z)
Calculates the distance and gradient at an arbitrary point in
world coordinates using multilinear interpolation, as described
for
getLocalDistanceAndGradient(Vector3d,Point3d) . |
double |
getWorldDistanceAndGradient(Vector3d grad,
Point3d point)
Calculates the distance and gradient at an arbitrary point.
|
double |
getWorldDistanceAndNormal(Vector3d norm,
double x,
double y,
double z)
Calculates the distance and normal at an arbitrary point in world
coordinates using multilinear interpolation, as described
for
getLocalDistanceAndNormal(Vector3d,Point3d) . |
double |
getWorldDistanceAndNormal(Vector3d norm,
Point3d point)
Calculates the distance and normal at an arbitrary point in world
coordinates using multilinear interpolation, as described for
getLocalDistanceAndNormal(Vector3d,Point3d) . |
void |
getWorldOrientation(RotationMatrix3d R)
Returns the orientation of this grid with respect to world
coordinates.
|
double |
getWorldQuadDistance(Point3d point)
Calculates the distance at an arbitrary point in world coordinates using
quadratic interpolation, as described for
getQuadDistanceAndGradient(maspack.matrix.Vector3d, maspack.matrix.Matrix3d, maspack.matrix.Point3d) . |
double |
getWorldQuadDistanceAndGradient(Vector3d grad,
Matrix3d dgrad,
Point3d point)
Calculates the distance and gradient at an arbitrary point in
world coordinates using quadratic interpolation, as described
for
getLocalDistanceAndGradient(Vector3d,Point3d) . |
Vector3d |
getWorldVertexCoords(Vector3d coords,
Vector3i vxyz)
Find the world coordinates at a vertex, as specified by
its x, y, z indices.
|
boolean |
isSelectable()
Returns true if this object is in fact selectable.
|
boolean |
isSigned()
Queries whether or not this grid is signed.
|
boolean |
isWritable()
Returns
true if this component should in fact be written to
secondary storage. |
int |
numSelectionQueriesNeeded()
If this selectable manages its own selection (by issuing selection
queries within its
render method), then this method should
return the maximum number of selection queries that will be
required. |
int |
numVertices()
Returns the total number of vertices in this grid.
|
int[] |
parseRenderRanges(java.lang.String str,
StringHolder errorMsg)
Parses a render range specification for this grid.
|
void |
prerender(RenderList list)
Called prior to rendering to allow this object to update the internal
state required for rendering (such as by caching rendering coordinates).
|
void |
prerender(RenderProps props) |
void |
render(Renderer renderer,
int flags)
Render this object using the functionality of the supplied
Renderer . |
void |
render(Renderer renderer,
RenderProps props,
int flags) |
void |
scan(ReaderTokenizer rtok,
java.lang.Object ref)
Scans this element from a ReaderTokenizer.
|
void |
setCenterAndOrientation(RigidTransform3d TCL)
Sets the center and orientation of this grid with respect to local
coordinates, by means of the transform
TCL whose rotation
matrix R gives the orientation and offset vector
p gives the center. |
void |
setDebug(int level) |
void |
setDefaultVertexColor(java.awt.Color color)
Sets the default color used for rendering vertices.
|
void |
setDistances(double[] distances,
boolean signed)
Explicitly sets the distance field for this grid.
|
void |
setDistancesAndFeatures(double[] distances,
java.util.List<? extends Feature> features,
int[] closestFeatures,
boolean signed)
Explicitly sets the distance field and features for this grid.
|
void |
setDrawEdges(boolean enable) |
void |
setLocalToWorld(RigidTransform3d TLW)
Sets a transform that maps from local to world coordinates
|
void |
setOrientation(RotationMatrix3d R)
Sets the orientation of this grid with respect to its local
coordinates.
|
void |
setRenderProps(RenderProps props)
Assigns a new set of render properties to this object.
|
void |
setRenderRanges(java.lang.String str)
Sets the render ranges for this grid.
|
void |
setResolution(Vector3i resolution)
Sets the resolution for this grid along the x, y, and z axes.
|
void |
setVertexColor(int idx,
java.awt.Color color)
Sets the color used to render a specific vertex.
|
void |
smooth()
Applies a simple Laplacian smoothing operation to the distance grid
|
void |
smooth(double lambda,
double mu)
Taubin Smoothing
|
void |
smooth(double lambda,
double mu,
int iters)
Applies Taubin smoothing
|
void |
smooth(int n)
Apply the smoothing operation n times
|
void |
updateBounds(Vector3d pmin,
Vector3d pmax)
Update the minimum and maximum points for this object.
|
Vector3i |
vertexToXyzIndices(Vector3i vxyz,
int vi)
Given a vertex index
vi , compute the corresponding
x, y, z indices. |
void |
write(java.io.PrintWriter pw,
NumberFormat fmt,
java.lang.Object ref)
Writes a text description of this element to a PrintWriter.
|
void |
zeroDistances()
Explicitly zeros the distance field for this grid.
|
public static double OUTSIDE_GRID
public DistanceGrid(java.util.List<? extends Feature> features, double marginFrac, int maxRes, boolean signed)
maxRes
. The grid is
created by calling
computeFromFeatures (features, marginFrac, null, maxRes, signed);
features
- features used to compute the distance fieldmarginFrac
- specifies the fractional amount that the
grid should be grown in each direction to better contain the featuresmaxRes
- specfies the resolution along the longest
width, with resolutions along other widths set to ensure uniform
cell size. Must be >
0.signed
- if true
, indicates that the field should be
signed. At present, signed fields can only be computed if all features
are faces (i.e., Face
).public DistanceGrid(java.util.List<? extends Feature> features, double marginFrac, Vector3i resolution, boolean signed)
resolution
. The grid is
created by calling
setResolution (resolution); computeFromFeatures (features, marginFrac, null, 0, signed);
features
- features used to compute the distance fieldmarginFrac
- specifies the fractional amount that the
grid should be grown in each direction to better contain the featuresresolution
- specfies the resolution along each of the
x, y, and z axes.signed
- if true
, indicates that the field should be
signed. At present, signed fields can only be computed if all features
are faces (i.e., Face
).public DistanceGrid(Vector3d widths, Vector3i resolution, RigidTransform3d TCL)
TCL
.
The grid distances are initialized to zero.widths
- widths along the x, y, and z axesresolution
- cell resolution along the x, y, and z axesTCL
- transformation giving the position and orientation
of the grid centerpublic DistanceGrid(Vector3i resolution)
resolution
- cell resolution along the x, y, and z axespublic void setLocalToWorld(RigidTransform3d TLW)
TLW
- transform from local to world coordinatespublic RigidTransform3d getLocalToWorld()
null
if no such transform is set.public VectorTransformer3d getLocalToWorldTransformer()
public VectorTransformer3d getGridToLocalTransformer()
public void setResolution(Vector3i resolution)
getFeatures()
, then these are used to recompute the
distances. Otherwise, the distances are set to zero. If a color map is
present, it is cleared.resolution
- cell resolution along the x, y and z axespublic void clearColors()
public void setVertexColor(int idx, java.awt.Color color)
idx
- vertex indexcolor
- rendering color for the vertexpublic java.awt.Color getVertexColor(int idx)
null
is returned.idx
- vertex indexpublic void setDefaultVertexColor(java.awt.Color color)
color
- default vertex color when using a color map.public java.awt.Color getDefaultVertexColor()
null
is returned.public void computeDistances(java.util.List<? extends Feature> features, boolean signed)
getFeatures()
. The grid resolution,
widths, center and orientaion remain unchanged.features
- features used to compute the distance fieldsigned
- if true
, indicates that the field should be
signed. At present, signed fields can only be computed if all features
are faces (i.e., Face
).public void setDistances(double[] distances, boolean signed)
distances
- distance for each vertex. Must have a length
>=
numVertices()
.signed
- if true
, indicates that the field should be
considered signed.public void zeroDistances()
false
.public void setDistancesAndFeatures(double[] distances, java.util.List<? extends Feature> features, int[] closestFeatures, boolean signed)
distances
- distance for each vertex. Must have a length
>=
numVertices()
.features
- list of features to be associated with this
grid.closestFeatures
- index (with respect to features
(
of the nearest feature to each vertex. Must have a length
>=
numVertices()
.signed
- if true
, indicates that the field should be
considered signed.public void setCenterAndOrientation(RigidTransform3d TCL)
TCL
whose rotation
matrix R
gives the orientation and offset vector
p
gives the center. All other aspects of the grid remain
unchanged. TCL
may also be specified as null
,
in which case the center and orientation will be set to 0 and the
identity.TCL
- transform giving the center and orientationpublic void computeFromFeatures(java.util.List<? extends Feature> features, double marginFrac, RigidTransform3d TCL, int maxRes, boolean signed)
getFeatures()
. The existing grid resolution is
unchanged, unless maxRes
exceeds 0, in which
case the resolution along the longest width is set to maxRes
and the resolution along all other axes are set so as to ensure
a uniform cell size. All resolutions are rounded up to an even number.
The points of the features are assumed to be given in local
coordinates. The application has the option of specifying the
position and orientation of the grid center using the optional
argument TCL
. If this is non-null, then the widths
are set large enough about the specified center to accomodate
the features. Otherwise, if TCL
is null, then
the grid is fit in an axis-aligned manner to the local coordinate
frame (i.e., getOrientation(maspack.matrix.RotationMatrix3d)
returns the identity), with
a center and widths computed to best fit the features.
To ensure that the grid is not degenerate, all widths are adjusted if necessary to ensure that they are at least 0.05 of the maximum width. Widths are then further adjusted by multiplying by
(1 + 2*marginFrac)to provide a margin around the features. Finally, if
maxRes > 0
,
widths may be grown to ensure uniform
cell size.features
- features used to compute the distance fieldmarginFrac
- specifies the fractional amount that the
grid should be grown in each direction to better contain the featuresTCL
- optional - if non-null, specifies the pose of the grid centermaxRes
- if > 0
,
specifies the resolution along the longest
width, with resolutions along other widths set to ensure uniform
cell sizesigned
- if true
, indicates that the field should be
signed. At present, signed fields can only be computed if all features
are faces (i.e., Face
).public void fitToFeatures(java.util.List<? extends Feature> features, double marginFrac, RigidTransform3d TCL, int maxRes)
public void fitToFeatures(java.util.Collection<java.util.List<? extends Feature>> featureSets, double marginFrac, RigidTransform3d TCL, int maxRes)
public void computeFromFeaturesOBB(java.util.List<? extends Feature> features, double marginFrac, int maxRes, boolean signed)
getFeatures()
. The existing grid
resolution is unchanged, unless maxRes
exceeds 0, in
which case the resolution along the longest width is set to
maxRes
and the resolution along all other axes are set so as
to ensure a uniform cell size. All resolutions are rounded up to an even
number.
The points of the features are assumed to be given in local
coordinates. The grid is fit to an oriented bounding box (OBB) with
respect to this frame; getCenter(maspack.matrix.Vector3d)
and getOrientation(maspack.matrix.RotationMatrix3d)
will
return the center and orientation of this box. To ensure that the grid is
not degenerate, all widths are adjusted if necessary to ensure that they
are at least 0.05 of the maximum width. Widths are then further adjusted
by multiplying by
(1 + 2*marginFrac)to provide a margin around the features.
features
- features used to compute the distance fieldmarginFrac
- specifies the fractional amount that the
grid should be grown in each direction to better contain the featuresmaxRes
- if >
0, specfies the resolution along the longest
width, with resolutions along other widths set to ensure uniform
cell sizesigned
- if true
, indicates that the field should be
signed. At present, signed fields can only be computed if all features
are faces (i.e., Face
).public void fitToFeaturesOBB(java.util.List<? extends Feature> features, double marginFrac, int maxRes)
public void fitToFeaturesOBB(java.util.Collection<java.util.List<? extends Feature>> featureSets, double marginFrac, int maxRes)
public void computeUnion(java.util.List<? extends Feature> features)
public void computeIntersection(java.util.List<? extends Feature> features)
public void computeDifference01(java.util.List<? extends Feature> features)
public void computeDifference10(java.util.List<? extends Feature> features)
public double getLocalDistance(Point3d point)
OUTSIDE_GRID
is returned.point
- point at which to calculate the normal and distance
(local coordinates).OUTSIDE_GRID
.public double getWorldDistance(Point3d point)
OUTSIDE_GRID
is returned.point
- point at which to calculate the normal and distance
(world coordinates).OUTSIDE_GRID
.public double getLocalDistanceAndNormal(Vector3d norm, double x, double y, double z)
getLocalDistanceAndNormal(Vector3d,Point3d)
.
If the point lies outside
the grid volume, OUTSIDE_GRID
is returned.norm
- returns the normal (local coordinates)x
- x coordinate of point (local coordinates).y
- y coordinate of point (local coordinates).z
- z coordinate of point (local coordinates).OUTSIDE_GRID
.public double getWorldDistanceAndNormal(Vector3d norm, double x, double y, double z)
getLocalDistanceAndNormal(Vector3d,Point3d)
.
If the point lies outside
the grid volume, OUTSIDE_GRID
is returned.norm
- returns the normal (world coordinates)x
- x coordinate of point (world coordinates).y
- y coordinate of point (world coordinates).z
- z coordinate of point (world coordinates).OUTSIDE_GRID
.public double getLocalDistanceAndGradient(Vector3d grad, double x, double y, double z)
getLocalDistanceAndGradient(Vector3d,Point3d)
.
If the point lies outside
the grid volume, OUTSIDE_GRID
is returned.grad
- returns the gradient (local coordinates)x
- x coordinate of point (local coordinates).y
- y coordinate of point (local coordinates).z
- z coordinate of point (local coordinates).OUTSIDE_GRID
.public double getWorldDistanceAndGradient(Vector3d grad, double x, double y, double z)
getLocalDistanceAndGradient(Vector3d,Point3d)
.
If the point lies outside
the grid volume, OUTSIDE_GRID
is returned.grad
- returns the gradient (world coordinates)x
- x coordinate of point (world coordinates).y
- y coordinate of point (world coordinates).z
- z coordinate of point (world coordinates).OUTSIDE_GRID
.public double getLocalDistanceAndNormal(Vector3d norm, Point3d point)
OUTSIDE_GRID
is
returned.norm
- returns the normal (local coordinates)point
- point at which to calculate the normal and distance
(local coordinates).OUTSIDE_GRID
.public double getWorldDistanceAndNormal(Vector3d norm, Point3d point)
getLocalDistanceAndNormal(Vector3d,Point3d)
.
If the point lies outside
the grid volume, OUTSIDE_GRID
is returned.norm
- returns the normal (world coordinates)point
- point at which to calculate the normal and distance
(world coordinates).OUTSIDE_GRID
.public double getLocalDistanceAndNormal(Vector3d norm, Matrix3d Dnrm, Point3d point)
getLocalDistanceAndNormal(Vector3d,Point3d)
. If Dnrm
is
non-null
, the method also calculated the normal derivative.
If the point lies outside the grid volume, OUTSIDE_GRID
is
returned.norm
- returns the normal (local coordinates)Dnrm
- if non-null, returns the normal derivative (local coordinates)point
- point at which to calculate the normal and distance
(local coordinates).OUTSIDE_GRID
.public double getLocalDistanceAndGradient(Vector3d grad, Point3d point)
OUTSIDE_GRID
is
returned.grad
- returns the gradient direction (local coordinates)point
- point at which to calculate the gradient and distance
(local coordinates).OUTSIDE_GRID
.public double getWorldDistanceAndGradient(Vector3d grad, Point3d point)
OUTSIDE_GRID
is returned.grad
- returns the gradient (world coordinates)point
- point at which to calculate the gradient and distance
(world coordinates).public Feature getNearestLocalFeature(Point3d nearest, Point3d point)
getFeatures()
returns null
), or if the point lies outside the grid,
null
is returned.nearest
- returns the nearest point on the feature (local coordinates)point
- point for which to find nearest feature (local coordinates)public Feature getNearestWorldFeature(Point3d nearest, Point3d point)
getFeatures()
returns null
), or if the point lies outside
the grid, null
is returned.nearest
- returns the nearest point on the feature (world coordinates)point
- point for which to find nearest feature (world coordinates)public Vector3i getCellVertex(Vector3i xyzi, Point3d point)
point
. If point
is outside the grid,
null
is returned.xyzi
- returns the x, y, z indices. If specified as
null
, then the containing vector is allocated internally.point
- point for which the cell vertex is desirednull
if point
is outside the grid.public Vector3i vertexToXyzIndices(Vector3i vxyz, int vi)
vi
, compute the corresponding
x, y, z indices.vxyz
- returns the x, y, z indices.vi
- global indexvxyz
public Vector3i getResolution()
public Vector3d getCellWidths()
i
, this equals w_i/res_i
, where w_i
and res_i
are the overall width and resolution associated
with that axis.public Vector3d getWidths()
public void getWidths(Vector3d widths)
widths
- returns the grid widthspublic void getCenter(Vector3d center)
center
- returns the grid centerpublic void getOrientation(RotationMatrix3d R)
R
- grid orientation in local coordinatespublic void setOrientation(RotationMatrix3d R)
R
- grid orientation in local coordinatespublic void getWorldOrientation(RotationMatrix3d R)
R
- grid orientation in world coordinatespublic void getWorldCenter(Point3d center)
center
- returns the grid centerpublic boolean isSigned()
true
if this grid is signed.public int numVertices()
public double[] getDistances()
idx = xi + nx*yj + (nx*ny)*zkwhere
nx
and ny
are the number
of vertices along x and y axes.null
if distances have
not yet been set.public double getVertexDistance(Vector3i vxyz)
vxyz
- x, y, z vertex indicespublic boolean getDrawEdges()
public void setDrawEdges(boolean enable)
public RenderProps getRenderProps()
getRenderProps
in interface HasRenderProps
public RenderProps createRenderProps()
createRenderProps
in interface HasRenderProps
public void setRenderProps(RenderProps props)
null
will remove render properties from this object.setRenderProps
in interface HasRenderProps
props
- new render properties for this objectpublic void getSelection(java.util.LinkedList<java.lang.Object> list, int qid)
list
the component (or components) associated with
the qid
-th selection query issued by this component's render
method. This will only be called if this component manages its own
selection (i.e., the number nums
returned by IsSelectable.numSelectionQueriesNeeded()
is positive), and qid
will in
turn be a number between 0 and nums
-1.getSelection
in interface IsSelectable
list
- selected objects are appended to the end of this listqid
- index of the selection querypublic boolean isSelectable()
isSelectable
in interface IsSelectable
public int numSelectionQueriesNeeded()
render
method), then this method should
return the maximum number of selection queries that will be
required. Otherwise, this method should return -1.numSelectionQueriesNeeded
in interface IsSelectable
public void prerender(RenderList list)
list.addIfVisible (obj);
for each of the objects in question.prerender
in interface IsRenderable
list
- list of objects to be renderedpublic void prerender(RenderProps props)
public void render(Renderer renderer, int flags)
Renderer
.render
in interface IsRenderable
renderer
- provides the functionality used to perform the rendering.flags
- flags that may be used to control different
aspects of the rendering. Flags are defined in Renderer
and currently include
Renderer.HIGHLIGHT
and
Renderer.SORT_FACES
.public void render(Renderer renderer, RenderProps props, int flags)
public void updateBounds(Vector3d pmin, Vector3d pmax)
updateBounds
in interface IsRenderable
pmin
- minimum pointpmax
- maximum pointpublic int getRenderHints()
TRANSPARENT
and
TWO_DIMENSIONAL
.getRenderHints
in interface IsRenderable
public Feature[] getFeatures()
computeFromFeatures(java.util.List<? extends maspack.geometry.Feature>, double, maspack.matrix.RigidTransform3d, int, boolean)
, computeFromFeaturesOBB(java.util.List<? extends maspack.geometry.Feature>, double, int, boolean)
, or one of the associated constructors. They
will also be associated with the field if they were explicitly specified
via a call to setDistancesAndFeatures(double[], java.util.List<? extends maspack.geometry.Feature>, int[], boolean)
.
If no features are associated with this grid,
null
is returned.null
if
there are none.public void clearFeatures()
public Feature getClosestFeature(int idx)
idx
.
This assumes that the distance field is associated with features, as
described for getFeatures()
. If this is not the case,
null
is returned.idx
- vertex indexnull
if there are no featurespublic int getClosestVertex(Point3d point)
point
- point for which to calculate closest vertexpoint
public Vector3d getLocalVertexCoords(Vector3d coords, Vector3i vxyz)
coords
- returns the coordinatesvxyz
- x, y, z vertex indicespublic Vector3d getWorldVertexCoords(Vector3d coords, Vector3i vxyz)
coords
- returns the coordinatesvxyz
- x, y, z vertex indicespublic java.lang.String getRenderRanges()
setRenderRanges(java.lang.String)
.public void setRenderRanges(java.lang.String str)
The format consists of three separate range descriptors, one for each axis. A range descriptor may be '*' (all vertices), 'n:m' (vertices in the index range n to m, inclusive), or 'n' (vertices only at index n). For example:
"* * *" - all vertices "* 7 *" - all vertices along x and z, and those at index 7 along y "0 2 3" - a single vertex at indices (0, 2, 3) "0:3 4:5 *" - all vertices between indices 0-3 along x, and 4-5 along yIn addition, the single charater "*" also indicates all vertices.
str
- render range specificationjava.lang.IllegalArgumentException
- if the range specification is not valid.public int[] parseRenderRanges(java.lang.String str, StringHolder errorMsg)
setRenderRanges(java.lang.String)
. This method does
not set anything; it simply parses the ranges and converts then into an
integer array of length 6. Applications can use this method to test if a
range specification is valid prior to calling setRenderRanges(java.lang.String)
.
If the specification is invalid, then an error message is placed in
errorMsg
and the method returns null
.str
- range specificationerrorMsg
- returns an error message in case of an errornull
if there
is an errorpublic void smooth(int n)
n
- number of times to apply the smoothing operationpublic void smooth(double lambda, double mu)
lambda
- >
0, fraction of gradient to shrinkmu
- <
0, fraction of gradient to expandpublic void smooth(double lambda, double mu, int iters)
lambda
- >
0, fraction of gradient to shrinkmu
- <
0, fraction of gradient to expanditers
- number of applicationspublic void smooth()
public PolygonalMesh createDistanceSurface()
public PolygonalMesh createDistanceSurface(double val)
val
.val
- iso surface valuepublic PolygonalMesh createDistanceSurface(double val, int res)
val
.val
- iso surface valuepublic PolygonalMesh createQuadDistanceSurface(double val, int res)
val
.val
- iso surface valueres
- multiplies the resolution of this grid to obtain the
resolution of the grid used to create the mesh.public double getRadius()
public double getQuadDistance(Point3d point)
getQuadDistanceAndGradient(maspack.matrix.Vector3d, maspack.matrix.Matrix3d, maspack.matrix.Point3d)
.
If the point lies outside the grid volume, OUTSIDE_GRID
is returned.point
- point at which to calculate the normal and distance
(local coordinates).OUTSIDE_GRID
.public double getWorldQuadDistance(Point3d point)
getQuadDistanceAndGradient(maspack.matrix.Vector3d, maspack.matrix.Matrix3d, maspack.matrix.Point3d)
.
If the point lies outside the grid volume, OUTSIDE_GRID
is returned.point
- point at which to calculate the normal and distance
(world coordinates).OUTSIDE_GRID
.public DistanceGrid.TetDesc getQuadTet(Point3d point)
public double getQuadDistanceAndGradient(Vector3d grad, Matrix3d dgrad, Point3d point)
OUTSIDE_GRID
is returned.grad
- returns the gradient direction (local coordinates)point
- point at which to calculate the gradient and distance
(local coordinates).dgrad
- if non-null, returns the derivative of the gradient (local
coordinates)OUTSIDE_GRID
.public double getWorldQuadDistanceAndGradient(Vector3d grad, Matrix3d dgrad, Point3d point)
getLocalDistanceAndGradient(Vector3d,Point3d)
.
If the point lies outside
the grid volume, OUTSIDE_GRID
is returned.grad
- returns the gradient (world coordinates)dgrad
- if non-null, returns the derivative of the gradient (world
coordinates)point
- point at which to calculate the gradient and distance
(world coordinates).OUTSIDE_GRID
.public void computeQuadCoefsStub(double[] a, DistanceGrid.TetDesc tdesc)
public void computeQuadCoefs(double[] a, DistanceGrid.TetDesc tdesc)
public boolean findQuadSurfaceTangent(Point3d pt, Point3d p0, Point3d pa, Vector3d nrm)
pt
such that the line segment
pa-pt
is tangent to the quadratic zero distance surface and
also lies in the plane defined by point p0
and normal
nrm
. The search starts by finding a point on the surface
that is close to p0
and proceeds from there.pt
- returns the tangent pointp0
- point on the planepa
- origin for the tangent segmentnrm
- normal defining the planepublic boolean findQuadSurfaceIntersection(Point3d pi, Point3d p0, Point3d pa, Vector3d nrm)
pi
between
the quadratic zero surface and a ray (p0, pa)
lying in the
plane defined by point p0
and normal nrm
.
pa
is projected onto the plane internally so the caller does
not need to ensure this.pi
- returns the intersection pointp0
- point on the plane and ray originpa
- projected onto the plane to form the outer point defining the raynrm
- normal defining the planepublic void scan(ReaderTokenizer rtok, java.lang.Object ref) throws java.io.IOException
Scannable
write
.public void write(java.io.PrintWriter pw, NumberFormat fmt, java.lang.Object ref) throws java.io.IOException
Scannable
scan
and complete
enough to allow full reconstruction of the element.public boolean isWritable()
Scannable
true
if this component should in fact be written to
secondary storage. This gives subclasses control over whether or
not they are actually written out.isWritable
in interface Scannable
true
if this component should be written to
secondary storage.public boolean epsilonEquals(DistanceGrid grid, double tol)
true
if this distance grid equals another within a
prescribed tolerance. The grids are equal if the resolution, widths,
center, orientation and distances are equal. Feature settings are
ignored.grid
- grid to compare againsttol
- floating point tolerance (absolute)public int getDebug()
public void setDebug(int level)