public class ScalarGrid extends ScalarGridBase
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
.
Scalar 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 the
special value ScalarGridBase.OUTSIDE_GRID
is returned.
Values at the grid vertices can be assigned collectively or individually,
using setVertexValues(double[])
or setVertexValue(int, double)
. Values at grid
vertices can be queried using getVertexValue(int)
.
OUTSIDE_GRID
TRANSPARENT, TWO_DIMENSIONAL
Constructor and Description |
---|
ScalarGrid()
Default constructor.
|
ScalarGrid(ScalarGrid grid)
Creates a new grid that is a copy of an existing grid.
|
ScalarGrid(Vector3d widths,
Vector3i resolution)
Creates a new grid with specified widths and resolution, centered on the
local coordinate system.
|
ScalarGrid(Vector3d widths,
Vector3i resolution,
RigidTransform3d TCL)
Creates a new grid with specified widths, resolution, and position and
orientation of the center given by
TCL . |
ScalarGrid(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.
|
Modifier and Type | Method and Description |
---|---|
boolean |
epsilonEquals(ScalarGrid grid,
double tol) |
double |
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.
|
double |
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.
|
double |
getVertexValue(int vi)
Queries the value for the vertex indexed by
vi . |
double |
getVertexValue(int xi,
int yj,
int zk)
Queries the value at a specified vertex, as specified by x, y, z indices.
|
double |
getVertexValue(Vector3i vxyz)
Queries the value at a specified vertex, as specified by x, y, z indices.
|
double[] |
getVertexValues()
Returns an array of the values at each vertex.
|
double |
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.
|
double |
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.
|
void |
set(ScalarGrid grid) |
void |
setVertexValue(int vi,
double value)
Sets the value for the vertex indexed by
vi . |
void |
setVertexValue(int xi,
int yi,
int zi,
double value)
Sets the value for the vertex indexed by its x, y, z indices.
|
void |
setVertexValues(double[] values)
Sets all the vertex values for this grid.
|
void |
zeroVertexValues()
Zeros all the vertex values for this grid.
|
createDistanceSurface, createDistanceSurface, createDistanceSurface, epsilonEquals, getParameterType
clearColors, createRenderProps, epsilonEquals, getCellVertex, getCellWidths, getCenter, getCenterAndOrientation, getClosestVertex, getDebug, getDefaultVertexColor, getGridToLocalTransformer, getLocalToWorld, getLocalToWorldTransformer, getLocalVertexCoords, getLocalVertexCoords, getOrientation, getRadius, getRenderHints, getRenderProps, getRenderRanges, getRenderVector, getRenderVectorScale, 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 ScalarGrid()
InterpolatingGridBase.scan(maspack.util.ReaderTokenizer, java.lang.Object)
is called immediately after.public ScalarGrid(Vector3d widths, Vector3i resolution)
widths
- widths along the x, y, and z axesresolution
- cell resolution along the x, y, and z axespublic ScalarGrid(Vector3d widths, Vector3i resolution, RigidTransform3d TCL)
TCL
. The grid values
are initialized to zero.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 ScalarGrid(Vector3i resolution)
resolution
- cell resolution along the x, y, and z axespublic ScalarGrid(ScalarGrid grid)
grid
- grid to copypublic void set(ScalarGrid grid)
public void setVertexValues(double[] values)
idx = xi + nx*yj + (nx*ny)*zkwhere
nx
and ny
are the number
of vertices along x and y axes.values
- value for each vertex. Must have a length
>=
InterpolatingGridBase.numVertices()
.public double[] getVertexValues()
ScalarGridBase.setVertexValues(double[])
for a description of how vertices are indexed with
respect to this array.public void setVertexValue(int vi, double value)
vi
. See ScalarGridBase.setVertexValues(double[])
for a description of how vertices are indexed.vi
- vertex indexvalue
- vertex valuepublic void setVertexValue(int xi, int yi, int zi, double value)
setVertexValue
in class ScalarGridBase
xi
- x vertex indexyi
- y vertex indexzi
- z vertex indexvalue
- new value for the vertexpublic double getVertexValue(int vi)
vi
. See ScalarGridBase.setVertexValues(double[])
for a description of how vertices are indexed.vi
- vertex indexpublic double getVertexValue(Vector3i vxyz)
vxyz
- x, y, z vertex indicespublic double getVertexValue(int xi, int yj, int zk)
xi
- x vertex indexyj
- y vertex indexzk
- z vertex indexpublic void zeroVertexValues()
public double getWorldValue(Point3d point)
ScalarGridBase.OUTSIDE_GRID
is returned.point
- point at which to calculate the value
(world coordinates)OUTSIDE_GRID
public double getWorldValue(Point3d point, boolean clipToGrid)
ScalarGridBase.OUTSIDE_GRID
, 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 volumeOUTSIDE_GRID
public double getLocalValue(Point3d point)
ScalarGridBase.OUTSIDE_GRID
is returned.point
- point at which to calculate the normal and value
(local coordinates)OUTSIDE_GRID
public double getLocalValue(Point3d point, boolean clipToGrid)
ScalarGridBase.OUTSIDE_GRID
, 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 volumeOUTSIDE_GRID
public boolean epsilonEquals(ScalarGrid grid, double tol)