Search in sources :

Example 26 with Vector3i

use of maspack.matrix.Vector3i in project artisynth_core by artisynth.

the class DistanceGrid method createTetOffsetsIfNecessary.

protected void createTetOffsetsIfNecessary() {
    if (myTetOffsets0156 == null) {
        Vector3i v0 = new Vector3i(0, 0, 0);
        Vector3i v1 = new Vector3i(2, 0, 0);
        Vector3i v2 = new Vector3i(2, 0, 2);
        Vector3i v3 = new Vector3i(0, 0, 2);
        Vector3i v4 = new Vector3i(0, 2, 0);
        Vector3i v5 = new Vector3i(2, 2, 0);
        Vector3i v6 = new Vector3i(2, 2, 2);
        Vector3i v7 = new Vector3i(0, 2, 2);
        myTetOffsets0156 = createTetOffsets(v0, v1, v5, v6);
        myTetOffsets0126 = createTetOffsets(v0, v1, v2, v6);
        myTetOffsets0326 = createTetOffsets(v0, v3, v2, v6);
        myTetOffsets0376 = createTetOffsets(v0, v3, v7, v6);
        myTetOffsets0476 = createTetOffsets(v0, v4, v7, v6);
        myTetOffsets0456 = createTetOffsets(v0, v4, v5, v6);
    }
}
Also used : Vector3i(maspack.matrix.Vector3i)

Example 27 with Vector3i

use of maspack.matrix.Vector3i in project artisynth_core by artisynth.

the class DistanceGrid method getNearestLocalFeature.

/**
 * Determines nearest feature to an arbitray point in local coordinates.  If
 * the grid is not associated with features (i.e., {@link #getFeatures}
 * returns <code>null</code>), or if the point lies outside the grid,
 * <code>null</code> is returned.
 *
 * @param nearest returns the nearest point on the feature (local coordinates)
 * @param point point for which to find nearest feature (local coordinates)
 * @return nearest feature, or null if outside of domain or if
 * no features are set.
 */
public Feature getNearestLocalFeature(Point3d nearest, Point3d point) {
    Vector3d cpos = new Vector3d();
    Vector3i vidx = new Vector3i();
    if (!getCellCoords(vidx, cpos, point)) {
        return null;
    }
    Point3d tmp = new Point3d();
    double dmin = INF;
    Feature nf = null;
    int[] coords = { vidx.x, vidx.y, vidx.z, vidx.x + 1, vidx.y, vidx.z, vidx.x, vidx.y + 1, vidx.z, vidx.x, vidx.y, vidx.z + 1, vidx.x + 1, vidx.y + 1, vidx.z, vidx.x + 1, vidx.y, vidx.z + 1, vidx.x, vidx.y + 1, vidx.z + 1, vidx.x + 1, vidx.y + 1, vidx.z + 1 };
    // check 8 nearest features from corners
    for (int i = 0; i < coords.length; i += 3) {
        int idx = xyzIndicesToVertex(coords[i], coords[i + 1], coords[i + 2]);
        Feature f = myFeatures[idx];
        f.nearestPoint(tmp, point);
        double d = tmp.distance(point);
        if (d < dmin) {
            dmin = d;
            if (nearest != null) {
                nearest.set(tmp);
            }
            nf = f;
        }
    }
    return nf;
}
Also used : Vector3d(maspack.matrix.Vector3d) Vector3i(maspack.matrix.Vector3i)

Example 28 with Vector3i

use of maspack.matrix.Vector3i in project artisynth_core by artisynth.

the class DistanceGrid method fitToFeatures.

public void fitToFeatures(Collection<List<? extends Feature>> featureSets, double marginFrac, RigidTransform3d TCL, int maxRes) {
    Vector3d widths = new Vector3d();
    Vector3d center = new Vector3d();
    fitAABB(widths, center, marginFrac, featureSets, TCL);
    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);
    if (TCL == null) {
        TCL = new RigidTransform3d(center.x, center.y, center.z);
    }
    setCenterAndOrientation(TCL);
}
Also used : Vector3d(maspack.matrix.Vector3d) Vector3i(maspack.matrix.Vector3i)

Example 29 with Vector3i

use of maspack.matrix.Vector3i in project artisynth_core by artisynth.

the class DistanceGrid method epsilonEquals.

/**
 * Returns <code>true</code> 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.
 *
 * @param grid grid to compare against
 * @param tol floating point tolerance (absolute)
 */
public boolean epsilonEquals(DistanceGrid grid, double tol) {
    Vector3i resolution = getResolution();
    if (!resolution.equals(grid.getResolution())) {
        return false;
    }
    if (!myWidths.epsilonEquals(grid.myWidths, tol)) {
        return false;
    }
    RigidTransform3d TCL = new RigidTransform3d();
    RigidTransform3d gridTCL = new RigidTransform3d();
    getOrientation(TCL.R);
    getCenter(TCL.p);
    getOrientation(gridTCL.R);
    getCenter(gridTCL.p);
    if (!TCL.epsilonEquals(gridTCL, tol)) {
        return false;
    }
    int numv = numVertices();
    for (int i = 0; i < numv; i++) {
        if (Math.abs(myPhi[i] - grid.myPhi[i]) > tol) {
            return false;
        }
    }
    return true;
}
Also used : Vector3i(maspack.matrix.Vector3i)

Example 30 with Vector3i

use of maspack.matrix.Vector3i in project artisynth_core by artisynth.

the class DistanceGrid method createTetOffsets.

protected int[] createTetOffsets(Vector3i v0, Vector3i v1, Vector3i v2, Vector3i v3) {
    Vector3i e01 = createEdgeNode(v0, v1);
    Vector3i e12 = createEdgeNode(v1, v2);
    Vector3i e23 = createEdgeNode(v2, v3);
    Vector3i e02 = createEdgeNode(v0, v2);
    Vector3i e13 = createEdgeNode(v1, v3);
    Vector3i e03 = createEdgeNode(v0, v3);
    Vector3i[] nodes = new Vector3i[] { v0, v1, v2, v3, e01, e12, e23, e02, e13, e03 };
    int[] offsets = new int[nodes.length];
    for (int i = 0; i < nodes.length; i++) {
        offsets[i] = xyzIndicesToVertex(nodes[i]);
    }
    return offsets;
}
Also used : Vector3i(maspack.matrix.Vector3i)

Aggregations

Vector3i (maspack.matrix.Vector3i)30 Vector3d (maspack.matrix.Vector3d)19 Point3d (maspack.matrix.Point3d)5 ArrayList (java.util.ArrayList)2 DistanceGrid (maspack.geometry.DistanceGrid)2 TetDesc (maspack.geometry.DistanceGrid.TetDesc)2 Face (maspack.geometry.Face)2 RigidTransform3d (maspack.matrix.RigidTransform3d)2 InternalErrorException (maspack.util.InternalErrorException)2 FemModel3d (artisynth.core.femmodels.FemModel3d)1 FemNode3d (artisynth.core.femmodels.FemNode3d)1 IntegrationPoint3d (artisynth.core.femmodels.IntegrationPoint3d)1 TransformableGeometry (artisynth.core.modelbase.TransformableGeometry)1 Color (java.awt.Color)1 File (java.io.File)1 IOException (java.io.IOException)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 TetID (maspack.geometry.DistanceGrid.TetID)1 OBB (maspack.geometry.OBB)1