Search in sources :

Example 1 with Point3d

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

the class MeshCollisionViewer method render.

public void render(Renderer renderer, int flags) {
    ContactInfo cinfo = myContactInfo;
    if (contourWidth > 0 && cinfo != null) {
        renderer.setShading(Shading.NONE);
        renderer.setLineWidth(contourWidth);
        renderer.setPointSize(contourWidth);
        renderer.setColor(contourColor, /*highlight=*/
        false);
        if (cinfo.getContours() != null) {
            for (IntersectionContour contour : cinfo.getContours()) {
                renderer.beginDraw(DrawMode.LINE_LOOP);
                for (IntersectionPoint p : contour) {
                    renderer.addVertex(p);
                }
                renderer.endDraw();
            }
        }
        Point3d pnt = new Point3d();
        renderer.beginDraw(DrawMode.POINTS);
        for (PenetratingPoint p : cinfo.getPenetratingPoints(0)) {
            pnt.set(p.vertex.pnt);
            pnt.transform(myMesh1.getMeshToWorld());
            renderer.addVertex(pnt);
        }
        for (PenetratingPoint p : cinfo.getPenetratingPoints(1)) {
            pnt.set(p.vertex.pnt);
            pnt.transform(myMesh2.getMeshToWorld());
            renderer.addVertex(pnt);
        }
        renderer.endDraw();
        renderer.setShading(Shading.FLAT);
        renderer.setLineWidth(1);
        renderer.setPointSize(1);
    }
}
Also used : IntersectionContour(maspack.collision.IntersectionContour) PenetratingPoint(maspack.collision.PenetratingPoint) IntersectionPoint(maspack.collision.IntersectionPoint) Point3d(maspack.matrix.Point3d) ContactInfo(maspack.collision.ContactInfo)

Example 2 with Point3d

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

the class MeshThicken method applyThickening.

public void applyThickening(Region region, MeshBase mesh, double thickening) {
    double margin = region.myMargin;
    Point3d pnt = new Point3d();
    Vector3d nrm = new Vector3d();
    Vector2d p2d = new Vector2d();
    ArrayList<Vertex3d> verts = myMesh.getVertices();
    ArrayList<Vector3d> nrmls = mesh.getNormals();
    if (nrmls == null) {
        System.out.println("Mesh does not have normals; thickening ignored");
    }
    int cnt = 0;
    Vector3d regionNrm = new Vector3d();
    // region normal in mesh coordinates
    region.myFrame.R.getColumn(2, regionNrm);
    for (int i = 0; i < verts.size(); i++) {
        Vertex3d v = verts.get(i);
        pnt.inverseTransform(region.myFrame, v.pnt);
        nrm.inverseTransform(region.myFrame, nrmls.get(i));
        if (pnt.z <= region.myHeight && pnt.z >= -region.myBackHeight) {
            // if (Math.abs(pnt.z) <= region.myHeight) {
            p2d.set(pnt.x, pnt.y);
            double d = region.myDist.computeInteriorDistance(/*near=*/
            null, p2d);
            if (d <= 0) {
                double dz = computeDeltaZ(-d, margin, thickening);
                if (region.myUseNormalZScalingP) {
                    if (adjacentFacesCrossNormal(v, regionNrm)) {
                        dz = 0;
                    } else {
                        dz *= nrm.z;
                    }
                } else {
                    dz = (nrm.z >= 0 ? dz : -dz);
                }
                if (nrm.z >= 0) {
                    pnt.z += dz;
                } else {
                    if (region.getThickenBackSide()) {
                        pnt.z += dz;
                    }
                }
                v.pnt.transform(region.myFrame, pnt);
                cnt++;
            }
        }
    }
    System.out.println("count=" + cnt);
    myMesh.notifyVertexPositionsModified();
    viewer.rerender();
}
Also used : Vertex3d(maspack.geometry.Vertex3d) Vector2d(maspack.matrix.Vector2d) Vector3d(maspack.matrix.Vector3d) Point3d(maspack.matrix.Point3d)

Example 3 with Point3d

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

the class IntersectionContour method fitPlane.

/**
 * Fits this contour to a plane by first computing the centroid,
 * and then forming a normal by summing the cross products of
 * adjacent rays between the centroid and the contour points.
 * This sum is returned in the optional argument <code>areaVec</code>.
 *
 * <p>When computing the centroid, points closer to each other
 * than <code>pointTol</code> are ignored. The points that are
 * actually used are collected into a separate list that is
 * returned by this method.
 *
 * @param areaVec if non-null, returns the computed area vector.
 * Normalizing this vector gives the normal for the plane, while
 * the length of this vector gives twice the area of the contour
 * with respect to the plane.
 * @param centroid if non-null, returns the computed centroid.
 * @param pointTol minimum distance between contour points used for
 * computing the plane
 * @return list of contours points with those closer than
 * <code>pointTol</code> removed.
 */
public ArrayList<IntersectionPoint> fitPlane(Vector3d areaVec, Vector3d centroid, double pointTol) {
    ArrayList<IntersectionPoint> points = new ArrayList<IntersectionPoint>(size());
    if (centroid == null) {
        centroid = new Vector3d();
    } else {
        centroid.setZero();
    }
    if (areaVec == null) {
        areaVec = new Vector3d();
    } else {
        areaVec.setZero();
    }
    IntersectionPoint plast = get(0);
    centroid.set(plast);
    points.add(plast);
    boolean closeToFirst = false;
    for (int i = 1; i < size(); i++) {
        IntersectionPoint p = get(i);
        if (isClosed() && i == size() - 1) {
            // in case contour is closed, check closeness to first point too
            closeToFirst = (p.distance(get(0)) < pointTol);
        }
        if (p.distance(plast) >= pointTol && !closeToFirst) {
            centroid.add(p);
            points.add(p);
            plast = p;
        }
    }
    int nump = points.size();
    centroid.scale(1.0 / nump);
    if (nump >= 3) {
        Vector3d ray0 = new Vector3d();
        Vector3d ray1 = new Vector3d();
        ray0.sub(points.get(nump - 1), centroid);
        for (Point3d p : points) {
            ray1.sub(p, centroid);
            areaVec.crossAdd(ray0, ray1, areaVec);
            ray0.set(ray1);
        }
    }
    return points;
}
Also used : Vector3d(maspack.matrix.Vector3d) Point3d(maspack.matrix.Point3d) ArrayList(java.util.ArrayList)

Example 4 with Point3d

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

the class IntersectionContour method printCornerPoints.

public void printCornerPoints(String name, String fmt, RigidTransform3d T) {
    if (name != null) {
        System.out.println(name);
    }
    double tol = computeLength() * 100 * DOUBLE_PREC;
    ArrayList<? extends Point3d> corners = getCornerPoints(tol);
    Point3d p = new Point3d();
    for (int i = 0; i < corners.size(); i++) {
        p.set(corners.get(i));
        if (T != null) {
            p.transform(T);
        }
        System.out.println(p.toString(fmt));
    }
}
Also used : Point3d(maspack.matrix.Point3d)

Example 5 with Point3d

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

the class IntersectionContour method computeLength.

/**
 * Computes the length of this contour
 *
 * @return contour length
 */
public double computeLength() {
    double length = 0;
    if (size() >= 2) {
        Point3d pa = get(0);
        for (int i = 1; i < size(); i++) {
            Point3d pb = get(i);
            length += pa.distance(pb);
            pa = pb;
        }
        if (isClosed) {
            length += pa.distance(get(0));
        }
    }
    return length;
}
Also used : Point3d(maspack.matrix.Point3d)

Aggregations

Point3d (maspack.matrix.Point3d)464 Vector3d (maspack.matrix.Vector3d)128 ArrayList (java.util.ArrayList)59 RigidTransform3d (maspack.matrix.RigidTransform3d)48 Vertex3d (maspack.geometry.Vertex3d)35 Point (artisynth.core.mechmodels.Point)30 PolygonalMesh (maspack.geometry.PolygonalMesh)30 Face (maspack.geometry.Face)25 ReaderTokenizer (maspack.util.ReaderTokenizer)19 IOException (java.io.IOException)18 RotationMatrix3d (maspack.matrix.RotationMatrix3d)17 Vector2d (maspack.matrix.Vector2d)16 VectorNd (maspack.matrix.VectorNd)16 IntegrationPoint3d (artisynth.core.femmodels.IntegrationPoint3d)15 HashMap (java.util.HashMap)14 Muscle (artisynth.core.mechmodels.Muscle)13 FemNode3d (artisynth.core.femmodels.FemNode3d)12 Particle (artisynth.core.mechmodels.Particle)12 BufferedReader (java.io.BufferedReader)11 Plane (maspack.matrix.Plane)11