use of maspack.matrix.Vector3i in project artisynth_core by artisynth.
the class DistanceGrid method getLocalDistanceAndGradient.
/**
* 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. The gradient is the true derivative
* of the interpolated distance function within the cell, and is
* in fact linear within the cell.
* If the point lies outside the grid volume, {@link #OUTSIDE_GRID} is
* returned.
*
* @param grad returns the gradient direction (local coordinates)
* @param point point at which to calculate the gradient and distance
* (local coordinates).
* @return interpolated distance, or <code>OUTSIDE_GRID</code>.
*/
public double getLocalDistanceAndGradient(Vector3d grad, Point3d point) {
Vector3d coords = new Vector3d();
Vector3i vidx = new Vector3i();
if (!getCellCoords(vidx, coords, point)) {
return OUTSIDE_GRID;
}
double dx = coords.x;
double dy = coords.y;
double dz = coords.z;
double w100x = (1 - dy) * (1 - dz);
double w101x = (1 - dy) * dz;
double w110x = dy * (1 - dz);
double w111x = dy * dz;
double w010y = (1 - dx) * (1 - dz);
double w011y = (1 - dx) * dz;
double w110y = dx * (1 - dz);
double w111y = dx * dz;
double w001z = (1 - dx) * (1 - dy);
double w011z = (1 - dx) * dy;
double w101z = dx * (1 - dy);
double w111z = dx * dy;
double w000 = w001z * (1 - dz);
double w001 = w001z * dz;
double w010 = w011z * (1 - dz);
double w011 = w011z * dz;
double w100 = w101z * (1 - dz);
double w101 = w101z * dz;
double w110 = w111z * (1 - dz);
double w111 = w111z * dz;
double d000 = getVertexDistance(vidx.x, vidx.y, vidx.z);
double d001 = getVertexDistance(vidx.x, vidx.y, vidx.z + 1);
double d010 = getVertexDistance(vidx.x, vidx.y + 1, vidx.z);
double d011 = getVertexDistance(vidx.x, vidx.y + 1, vidx.z + 1);
double d100 = getVertexDistance(vidx.x + 1, vidx.y, vidx.z);
double d101 = getVertexDistance(vidx.x + 1, vidx.y, vidx.z + 1);
double d110 = getVertexDistance(vidx.x + 1, vidx.y + 1, vidx.z);
double d111 = getVertexDistance(vidx.x + 1, vidx.y + 1, vidx.z + 1);
if (grad != null) {
grad.x = (-w100x * d000 - w101x * d001 - w110x * d010 - w111x * d011 + w100x * d100 + w101x * d101 + w110x * d110 + w111x * d111);
grad.y = (-w010y * d000 - w011y * d001 + w010y * d010 + w011y * d011 - w110y * d100 - w111y * d101 + w110y * d110 + w111y * d111);
grad.z = (-w001z * d000 + w001z * d001 - w011z * d010 + w011z * d011 - w101z * d100 + w101z * d101 - w111z * d110 + w111z * d111);
myGridToLocal.transformCovec(grad, grad);
}
return (w000 * d000 + w001 * d001 + w010 * d010 + w011 * d011 + w100 * d100 + w101 * d101 + w110 * d110 + w111 * d111);
}
use of maspack.matrix.Vector3i in project artisynth_core by artisynth.
the class DistanceGrid method fitToFeaturesOBB.
public void fitToFeaturesOBB(Collection<List<? extends Feature>> featureSets, double marginFrac, int maxRes) {
Vector3d widths = new Vector3d();
RigidTransform3d TCL = new RigidTransform3d();
fitOBB(widths, TCL, marginFrac, featureSets, OBB.Method.Covariance);
if (maxRes > 0) {
double cwidth = widths.maxElement() / maxRes;
Vector3i resolution = new Vector3i((int) (Math.ceil(widths.x / cwidth)), (int) (Math.ceil(widths.y / cwidth)), (int) (Math.ceil(widths.z / cwidth)));
setResolution(resolution);
// update widths and origin to accommodate uniform cell width
widths.set(resolution);
widths.scale(cwidth);
}
setWidths(widths);
setCenterAndOrientation(TCL);
}
use of maspack.matrix.Vector3i in project artisynth_core by artisynth.
the class DistanceGrid method getQuadTet.
/**
* Used for debugging
*/
public TetDesc getQuadTet(Point3d point) {
Vector3d coords = new Vector3d();
Vector3i vidx = new Vector3i();
if (getQuadCellCoords(coords, vidx, point, myQuadGridToLocal) == -1) {
return null;
}
double dx = coords.x;
double dy = coords.y;
double dz = coords.z;
return new TetDesc(vidx, TetID.findSubTet(dx, dy, dz));
}
use of maspack.matrix.Vector3i in project artisynth_core by artisynth.
the class DistanceGrid method createEdgeNode.
protected Vector3i createEdgeNode(Vector3i v0, Vector3i v1) {
Vector3i en = new Vector3i();
en.x = (v0.x + v1.x) / 2;
en.y = (v0.y + v1.y) / 2;
en.z = (v0.z + v1.z) / 2;
return en;
}
use of maspack.matrix.Vector3i in project artisynth_core by artisynth.
the class DistanceGridFeatureQuery method getOrCreateFaceGrid.
private static DistanceGrid getOrCreateFaceGrid(PolygonalMesh mesh) {
DistanceGrid sdGrid = mesh.getSignedDistanceGrid();
if (sdGrid == null) {
Vector3i cellDivisions = new Vector3i(20, 20, 20);
double gridMargin = 0.1;
sdGrid = mesh.getSignedDistanceGrid(gridMargin, cellDivisions);
}
return sdGrid;
}
Aggregations