Search in sources :

Example 71 with Vector3d

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

the class OBB method containsPoint.

public boolean containsPoint(Point3d pnt) {
    Point3d p = new Point3d(pnt);
    p.inverseTransform(myX);
    Vector3d hw = myHalfWidths;
    boolean status = (-hw.x <= p.x && p.x <= hw.x && -hw.y <= p.y && p.y <= hw.y && -hw.z <= p.z && p.z <= hw.z);
    return status;
}
Also used : Vector3d(maspack.matrix.Vector3d) Point3d(maspack.matrix.Point3d)

Example 72 with Vector3d

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

the class OBB method computeBoundsFromPoints.

private void computeBoundsFromPoints(Point3d min, Point3d max, Point3d[] pnts) {
    Vector3d xpnt = new Point3d();
    for (Point3d pnt : pnts) {
        xpnt.inverseTransform(myX, pnt);
        xpnt.updateBounds(min, max);
    }
}
Also used : Vector3d(maspack.matrix.Vector3d) Point3d(maspack.matrix.Point3d)

Example 73 with Vector3d

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

the class OBBTree method computeOBBNode.

private OBB computeOBBNode(ElemData[] edata, int num, OBB parent) {
    meanCentroid.setZero();
    for (int i = 0; i < num; i++) {
        meanCentroid.add(edata[i].myCentroid);
    }
    meanCentroid.scale(1 / (double) num);
    // OBB obb = new OBB (edata, num, myMargin);
    Boundable[] elems = createElementArray(edata, num);
    OBB node = new OBB();
    node.set(elems, num, myMargin, myMethod);
    node.setParent(parent);
    node.getSortedAxes(obbAxes);
    if (num > myMaxLeafElements) {
        // subdivide the box
        ElemData[] elemsU = new ElemData[num];
        ElemData[] elemsL = new ElemData[num];
        int numU = 0;
        int numL = 0;
        // start with long axis
        int axisIdx = 0;
        do {
            numU = 0;
            numL = 0;
            Vector3d axis = obbAxes[axisIdx];
            for (int i = 0; i < num; i++) {
                // face.computeCentroid (elemCentroid);
                tmpPnt.sub(edata[i].myCentroid, meanCentroid);
                // tmpPnt.sub (elemCentroid, meanCentroid);
                if (axis.dot(tmpPnt) >= 0) {
                    elemsU[numU++] = edata[i];
                } else {
                    elemsL[numL++] = edata[i];
                }
            }
            // potentially move to next axis
            axisIdx++;
        } while (axisIdx < 3 && (numL == 0 || numU == 0));
        if (numU < num && numL < num) {
            // System.out.println ("numU=" + numU);
            OBB nodeU = computeOBBNode(elemsU, numU, node);
            // System.out.println ("numL=" + numL);
            OBB nodeL = computeOBBNode(elemsL, numL, node);
            node.addChild(nodeL);
            node.addChild(nodeU);
        } else {
            // createElementArray (edata, num));
            node.setElements(elems);
        }
    } else {
        // createElementArray (edata, num));
        node.setElements(elems);
    }
    return node;
}
Also used : Vector3d(maspack.matrix.Vector3d)

Example 74 with Vector3d

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

the class PointMesh method write.

/**
 * Writes this mesh to a PrintWriter, using an Alias Wavefront "obj" file
 * format. Vertices are printed first, each starting with the letter "v" and
 * followed by x, y, and z coordinates. Normals, if present, are printed
 * next, starting with the letter "vn" and followed by x, y, and z
 * coordinates.
 *
 * <p>
 * The format used to print vertex coordinates is specified by a
 * {@link maspack.util.NumberFormat NumberFormat}.
 *
 * @param pw
 * PrintWriter to write this mesh to
 * @param fmt
 * (optional) format for writing the vertex and normals coordinates. If <code>null</code>,
 * a format of <code>"%.8g"</code> is assumed.
 * @param zeroIndexed
 * if true, index numbering for mesh vertices starts at 0. Otherwise,
 * numbering starts at 1.
 */
public void write(PrintWriter pw, NumberFormat fmt, boolean zeroIndexed) throws IOException {
    if (fmt == null) {
        fmt = new NumberFormat("%.8g");
    }
    for (Vertex3d vertex : myVertices) {
        Point3d pnt = vertex.pnt;
        pw.println("v " + fmt.format(pnt.x) + " " + fmt.format(pnt.y) + " " + fmt.format(pnt.z));
    }
    if (myNormals != null) {
        for (Vector3d nrm : myNormals) {
            pw.println("vn " + fmt.format(nrm.x) + " " + fmt.format(nrm.y) + " " + fmt.format(nrm.z));
        }
    }
    pw.flush();
}
Also used : Vector3d(maspack.matrix.Vector3d) Point3d(maspack.matrix.Point3d) NumberFormat(maspack.util.NumberFormat)

Example 75 with Vector3d

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

the class PointMeshRenderer method buildRenderObject.

@Override
protected RenderObject buildRenderObject(MeshBase mesh, RenderProps props) {
    RenderObject r = super.buildRenderObject(mesh, props);
    PointMesh pmesh = (PointMesh) mesh;
    int[] nidxs = pmesh.hasNormals() ? pmesh.getNormalIndices() : null;
    int[] cidxs = pmesh.hasColors() ? pmesh.getColorIndices() : null;
    int[] tidxs = pmesh.hasTextureCoords() ? pmesh.getTextureIndices() : null;
    int numv = pmesh.numVertices();
    for (int i = 0; i < numv; i++) {
        r.addVertex(i, nidxs != null ? nidxs[i] : -1, cidxs != null ? cidxs[i] : -1, tidxs != null ? tidxs[i] : -1);
        r.addPoint(i);
    }
    Point3d tip = new Point3d();
    double normalLen = pmesh.getNormalRenderLen();
    if (normalLen > 0 && pmesh.hasNormals()) {
        ArrayList<Vector3d> nrmls = pmesh.getNormals();
        for (int i = 0; i < numv; i++) {
            Point3d pnt = pmesh.getVertex(i).pnt;
            tip.scaledAdd(normalLen, nrmls.get(nidxs[i]), pnt);
            r.addPosition((float) tip.x, (float) tip.y, (float) tip.z);
            r.addVertex(numv + i, nidxs[i], -1, -1);
            r.addLine(i, numv + i);
        }
    }
    return r;
}
Also used : Vector3d(maspack.matrix.Vector3d) Point3d(maspack.matrix.Point3d) RenderObject(maspack.render.RenderObject)

Aggregations

Vector3d (maspack.matrix.Vector3d)441 Point3d (maspack.matrix.Point3d)128 RigidTransform3d (maspack.matrix.RigidTransform3d)56 ArrayList (java.util.ArrayList)38 Matrix3d (maspack.matrix.Matrix3d)32 RotationMatrix3d (maspack.matrix.RotationMatrix3d)30 SymmetricMatrix3d (maspack.matrix.SymmetricMatrix3d)24 PolygonalMesh (maspack.geometry.PolygonalMesh)23 Vertex3d (maspack.geometry.Vertex3d)23 Face (maspack.geometry.Face)20 AxisAngle (maspack.matrix.AxisAngle)19 Vector3i (maspack.matrix.Vector3i)19 Point (artisynth.core.mechmodels.Point)18 RenderProps (maspack.render.RenderProps)17 VectorNd (maspack.matrix.VectorNd)15 AffineTransform3d (maspack.matrix.AffineTransform3d)14 IOException (java.io.IOException)13 Vector2d (maspack.matrix.Vector2d)11 Plane (maspack.matrix.Plane)10 GLViewer (maspack.render.GL.GLViewer)9