Search in sources :

Example 1 with Vector3d

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

the class MeshThicken method applyGrowth.

public void applyGrowth(PolygonalMesh mesh, double dn) {
    mesh.autoGenerateNormals();
    for (int i = 0; i < mesh.numVertices(); i++) {
        Vertex3d v = mesh.getVertex(i);
        Vector3d n = mesh.getNormal(i);
        v.pnt.scaledAdd(dn, n);
    }
    myMesh.notifyVertexPositionsModified();
    viewer.rerender();
}
Also used : Vertex3d(maspack.geometry.Vertex3d) Vector3d(maspack.matrix.Vector3d)

Example 2 with Vector3d

use of maspack.matrix.Vector3d 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 Vector3d

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

the class MeshViewer method checkFaces.

private void checkFaces(PolygonalMesh mesh) {
    for (Face face : mesh.getFaces()) {
        Vector3d nrm = face.getNormal();
        if (nrm.containsNaN()) {
            System.out.println("face " + face.getIndex() + " badly formed");
            for (int i = 0; i < 3; i++) {
                Vertex3d v = face.getVertex(i);
                System.out.println(" " + v + " " + v.pnt + " " + v.numIncidentHalfEdges());
            }
        }
    }
}
Also used : Vertex3d(maspack.geometry.Vertex3d) Vector3d(maspack.matrix.Vector3d) Face(maspack.geometry.Face) Point(java.awt.Point)

Example 4 with Vector3d

use of maspack.matrix.Vector3d 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 5 with Vector3d

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

the class IntersectionContour method computePlanarArea.

/**
 * Computes the area of this contour with respect to a plane formed
 * by computing the centroid and then summing the cross products of
 * rays from the centroid to adjacent contour points.
 *
 * @return planar area
 */
public double computePlanarArea() {
    Vector3d areaVec = new Vector3d();
    // reject closer points
    double pointTol = computeLength() * 1e-10;
    fitPlane(areaVec, /*centroid=*/
    null, pointTol);
    return 0.5 * areaVec.norm();
}
Also used : Vector3d(maspack.matrix.Vector3d)

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