public class VectorGrid<T extends VectorObject<T>> extends InterpolatingGridBase implements ParameterizedClass
VectorObject
values
using trilinear interpolation. The VectorObjects used are assumed to be of a
fixed size. For the variable sized objects VectorNd
and MatrixNd
, one should use VectorNdGrid
and MatrixNdGrid
instead.
The grid 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: the local
frame L, the world frame W, and the grid frame G. Details on
these are given in the documentation for InterpolatingGridBase
.
Values at any point within the grid are be obtained by trilinear
interpolation of the values at surrounding vertices. Queries can be made for
points in either local or world coordinates, using getLocalValue(maspack.matrix.Point3d)
or
getWorldValue(maspack.matrix.Point3d)
. If the query point is outside the grid, then null
is returned.
Values at the grid vertices can be assigned collectively or individually,
using setVertexValues(T[])
or setVertexValue(int, T)
. Values at grid
vertices can be queried using getVertexValue(int)
.
TRANSPARENT, TWO_DIMENSIONAL
Constructor and Description |
---|
VectorGrid(java.lang.Class<T> type)
This constructor should not be called by applications, unless
InterpolatingGridBase.scan(maspack.util.ReaderTokenizer, java.lang.Object) is called immediately after. |
VectorGrid(java.lang.Class<T> type,
Vector3d widths,
Vector3i resolution)
Creates a new grid with specified widths and resolution, centered on the
local coordinate system.
|
VectorGrid(java.lang.Class<T> type,
Vector3d widths,
Vector3i resolution,
RigidTransform3d TCL)
Creates a new grid with specified widths, resolution, and position and
orientation of the center given by
TCL . |
VectorGrid(java.lang.Class<T> type,
Vector3i resolution)
Creates a new grid, axis-aligned and centered on the origin, with the
specified resolution and x, y, z widths set to 1.
|
VectorGrid(VectorGrid<T> grid)
Creates a new grid that is a copy of an existing grid.
|
Modifier and Type | Method and Description |
---|---|
T |
createTypeInstance() |
boolean |
epsilonEquals(VectorGrid<T> grid,
double tol)
Returns
true if this grid equals another within a prescribed
tolerance. |
T |
getLocalValue(Point3d point)
Calculates the value at an arbitrary point in local coordinates using
multilinear interpolation of the vertex values for the grid cell
containing the point.
|
T |
getLocalValue(Point3d point,
boolean clipToGrid)
Calculates the value at an arbitrary point in local coordinates using
multilinear interpolation of the vertex values for the grid cell
containing the point.
|
java.lang.Class<T> |
getParameterType()
For subclasses with parameterized typing, returns the type parameter.
|
boolean |
getRenderVector(Vector3d vec3,
int xi,
int yj,
int zk)
For grid subclasses wishing to render 3D vector information, this method
should be overridden to optionally returns a vector quantity associated
with the vertex at indices
xi , yj , and zk . |
double |
getRenderVectorScale()
For grid subclasses wishing to render 3D vector information, this method
should be overridden to return a scaling factor to be applied to vectors
returned by
InterpolatingGridBase.getRenderVector(maspack.matrix.Vector3d, int, int, int) to determine the length of the
actual rendered vector. |
T |
getVertexValue(int vi)
Queries the value for the vertex indexed by
vi . |
T |
getVertexValue(int xi,
int yj,
int zk)
Queries the value at a specified vertex, as specified by x, y, z indices.
|
T |
getVertexValue(Vector3i vxyz)
Queries the value at a specified vertex, as specified by x, y, z indices.
|
java.util.ArrayList<T> |
getVertexValues()
Returns the internal array of the values at each vertex.
|
T |
getWorldValue(Point3d point)
Calculates the value at an arbitrary point in world coordinates using
multilinear interpolation of the vertex values for the grid cell
containing the point.
|
T |
getWorldValue(Point3d point,
boolean clipToGrid)
Calculates the value at an arbitrary point in world coordinates using
multilinear interpolation of the vertex values for the grid cell
containing the point.
|
boolean |
hasParameterizedType()
Queries whether this class explicitly utilizes a parameterized type.
|
T |
scanValue(ReaderTokenizer rtok)
Scans and returns an instance of the vector type associated with this
grid from a reader tokenizer.
|
void |
set(VectorGrid<T> grid)
Sets this grid to be a copy of an existing grid.
|
void |
setRenderVectorScale(double scale) |
void |
setVertexValue(int xi,
int yj,
int zk,
T value)
Sets the value for the vertex indexed by its x, y, z indices.
|
void |
setVertexValue(int vi,
T value)
Sets the value for the vertex indexed by
vi . |
void |
setVertexValues(T[] values)
Sets all the vertex values for this grid.
|
<S> void |
writeValue(java.io.PrintWriter pw,
NumberFormat fmt,
T val)
Writes a vector of the type associated with this grid to a
PrintWriter . |
void |
zeroVertexValues()
Zeros all the vertex values for this grid.
|
clearColors, createRenderProps, epsilonEquals, getCellVertex, getCellWidths, getCenter, getCenterAndOrientation, getClosestVertex, getDebug, getDefaultVertexColor, getGridToLocalTransformer, getLocalToWorld, getLocalToWorldTransformer, getLocalVertexCoords, getLocalVertexCoords, getOrientation, getRadius, getRenderHints, getRenderProps, getRenderRanges, getResolution, getSelection, getVertexColor, getWidths, getWidths, getWorldCenter, getWorldOrientation, getWorldVertexCoords, getWorldVertexCoords, hasLocalToWorld, isSelectable, isVertexRenderingEnabled, isWritable, numSelectionQueriesNeeded, numVertices, parseRenderRanges, prerender, prerender, render, render, scaleDistance, scan, set, setCenter, setCenterAndOrientation, setDebug, setDefaultVertexColor, setLocalToWorld, setOrientation, setRenderProps, setRenderRanges, setResolution, setVertexColor, setVertexRenderingEnabled, updateBounds, vertexToXyzIndices, write, xyzIndicesToVertex
public VectorGrid(java.lang.Class<T> type)
InterpolatingGridBase.scan(maspack.util.ReaderTokenizer, java.lang.Object)
is called immediately after.public VectorGrid(java.lang.Class<T> type, Vector3d widths, Vector3i resolution)
type
- class type for the VectorObject
associated with this
grid.widths
- widths along the x, y, and z axesresolution
- cell resolution along the x, y, and z axespublic VectorGrid(java.lang.Class<T> type, Vector3d widths, Vector3i resolution, RigidTransform3d TCL)
TCL
. The grid values
are initialized to zero.type
- class type for the VectorObject
associated with this
grid.widths
- widths along the x, y, and z axesresolution
- cell resolution along the x, y, and z axesTCL
- if not null
, describes the position and orientation
of the grid center in local coordinates.public VectorGrid(java.lang.Class<T> type, Vector3i resolution)
type
- class type for the VectorObject
associated with this
grid.resolution
- cell resolution along the x, y, and z axespublic VectorGrid(VectorGrid<T> grid)
grid
- grid to copypublic T createTypeInstance()
public java.lang.Class<T> getParameterType()
null
.getParameterType
in interface ParameterizedClass
getParameterType
in class InterpolatingGridBase
null
public boolean hasParameterizedType()
hasParameterizedType
in interface ParameterizedClass
true
if this class utilizes a parameterized type.public void set(VectorGrid<T> grid)
grid
- grid to copypublic void setVertexValues(T[] values)
idx = xi + nx*yj + (nx*ny)*zkwhere
nx
and ny
are the number
of vertices along x and y axes.
The input values are copied internally and are not referenced by the grid.
values
- value for each vertex. Must have a length
>=
InterpolatingGridBase.numVertices()
.public java.util.ArrayList<T> getVertexValues()
setVertexValues(T[])
for a description of how vertices are indexed with
respect to this array.
The returned values are those referenced directly by the grid.
public void setVertexValue(int vi, T value)
vi
. See setVertexValues(T[])
for a description of how vertices are indexed.
The input value is copied internally and is not referenced by the grid.
vi
- vertex indexvalue
- vertex valuepublic void setVertexValue(int xi, int yj, int zk, T value)
xi
- x vertex indexyj
- y vertex indexzk
- z vertex indexvalue
- new value for the vertexpublic T getVertexValue(int vi)
vi
. See setVertexValues(T[])
for a description of how vertices are indexed.
The returned value is the internal value referenced by the grid.
vi
- vertex indexpublic T getVertexValue(Vector3i vxyz)
The returned value is the internal value referenced by the grid.
vxyz
- x, y, z vertex indicespublic T getVertexValue(int xi, int yj, int zk)
The returned value is the internal value referenced by the grid.
xi
- x vertex indexyj
- y vertex indexzk
- z vertex indexpublic void zeroVertexValues()
public T getWorldValue(Point3d point)
null
is returned.point
- point at which to calculate the value
(world coordinates)null
public T getWorldValue(Point3d point, boolean clipToGrid)
null
,
depending on whether clipToGrid
is true
or false.point
- point at which to calculate the value
(world coordinates)clipToGrid
- if true
, return the nearest grid value if
point
is outside the grid volumenull
public T getLocalValue(Point3d point)
null
is returned.point
- point at which to calculate the normal and value
(local coordinates)null
public T getLocalValue(Point3d point, boolean clipToGrid)
null
,
depending on whether clipToGrid
is true
or false.point
- point at which to calculate the normal and value
(local coordinates)clipToGrid
- if true
, return the nearest grid value if
point
is outside the grid volumenull
public boolean getRenderVector(Vector3d vec3, int xi, int yj, int zk)
InterpolatingGridBase
xi
, yj
, and zk
. Should
returns null
if no vector information should be rendered at that
vertex.getRenderVector
in class InterpolatingGridBase
vec3
- three vector valuexi
- x vertex indexyj
- y vertex indexzk
- z vertex indextrue
if the vector quantity maps to a 3-vector valuepublic double getRenderVectorScale()
InterpolatingGridBase
InterpolatingGridBase.getRenderVector(maspack.matrix.Vector3d, int, int, int)
to determine the length of the
actual rendered vector. Returning 0 disables vector rendering.getRenderVectorScale
in class InterpolatingGridBase
public void setRenderVectorScale(double scale)
public boolean epsilonEquals(VectorGrid<T> grid, double tol)
true
if this grid equals another within a prescribed
tolerance. The grids are equal if the resolution, widths, center,
orientation and values are equal. Specifying tol = 0
requires
exact equality.grid
- grid to compare againsttol
- floating point tolerance (absolute)public T scanValue(ReaderTokenizer rtok) throws java.io.IOException
null
if the next token is
the word "null"
.rtok
- tokenizer to read the value fromnull
java.io.IOException
public <S> void writeValue(java.io.PrintWriter pw, NumberFormat fmt, T val) throws java.io.IOException
PrintWriter
. If the value is null
, writes
out the word "null"
.pw
- writer to write the value tofmt
- format for the floating point valuesval
- value to be writtenjava.io.IOException