Search in sources :

Example 11 with Vector2d

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

the class CutPlaneProbe method setResolution.

/**
 * Sets the resolution fo teh display, integers (nx, ny) corresponding
 * to the number of divisions along the x and y axes.  This triggers
 * a rebuild of the mesh.
 */
public void setResolution(Vector2d res) {
    if (!myResolution.equals(res)) {
        myResolution = new Vector2d((int) res.x, (int) res.y);
        rebuildMesh();
        updateMeshDisplay();
    }
}
Also used : Vector2d(maspack.matrix.Vector2d)

Example 12 with Vector2d

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

the class PointDistributor method sphereGridFill.

// fills a mesh based on a regular grid of points
public static Point3d[] sphereGridFill(PolygonalMesh mesh, double r) {
    ArrayList<Point3d> pnts = new ArrayList<Point3d>();
    RigidTransform3d trans = getPrincipalAxes(mesh);
    Point3d[] box = getTightBox(mesh, trans);
    Point3d center = new Point3d(box[0]);
    center.add(box[6]);
    center.scale(0.5);
    trans.setTranslation(center);
    Vector3d l = new Vector3d(box[0]);
    l.sub(box[6]);
    l.inverseTransform(trans);
    double alpha = 2 * Math.sqrt(2) * r;
    int nx = (int) Math.ceil(l.x / alpha) + 1;
    int ny = (int) Math.ceil(l.y / alpha) + 1;
    int nz = (int) Math.ceil(l.z / alpha) + 1;
    double xoffset = -(nx - 1) * alpha / 2;
    double yoffset = -(ny - 1) * alpha / 2;
    double zoffset = -(nz - 1) * alpha / 2;
    BVTree bvh = mesh.getBVTree();
    Vector2d coords = new Vector2d();
    Point3d nearest = new Point3d();
    BVFeatureQuery query = new BVFeatureQuery();
    Point3d p;
    for (int i = 0; i < nx; i++) {
        for (int j = 0; j < ny; j++) {
            for (int k = 0; k < nz; k++) {
                double x = i * alpha + xoffset;
                double y = j * alpha + yoffset;
                double z = k * alpha + zoffset;
                p = new Point3d(x, y, z);
                p.transform(trans);
                addIfIntersects(pnts, p, r, bvh, nearest, coords, query);
            }
        }
    }
    return pnts.toArray(new Point3d[pnts.size()]);
}
Also used : BVTree(maspack.geometry.BVTree) RigidTransform3d(maspack.matrix.RigidTransform3d) Vector2d(maspack.matrix.Vector2d) Vector3d(maspack.matrix.Vector3d) Point3d(maspack.matrix.Point3d) ArrayList(java.util.ArrayList) BVFeatureQuery(maspack.geometry.BVFeatureQuery)

Example 13 with Vector2d

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

the class PointDistributor method sphereFCCFill.

// fills a mesh with spheres based on face-centered cubic packing
public static Point3d[] sphereFCCFill(PolygonalMesh mesh, double r) {
    ArrayList<Point3d> pnts = new ArrayList<Point3d>();
    RigidTransform3d trans = getPrincipalAxes(mesh);
    Point3d[] box = getTightBox(mesh, trans);
    Point3d center = new Point3d(box[0]);
    center.add(box[6]);
    center.scale(0.5);
    trans.setTranslation(center);
    Vector3d l = new Vector3d(box[0]);
    l.sub(box[6]);
    l.inverseTransform(trans);
    double alpha = 2 * Math.sqrt(2) * r;
    int nx = (int) Math.ceil(l.x / alpha) + 1;
    int ny = (int) Math.ceil(l.y / alpha) + 1;
    int nz = (int) Math.ceil(l.z / alpha) + 1;
    double xoffset = -(nx - 1) * alpha / 2;
    double yoffset = -(ny - 1) * alpha / 2;
    double zoffset = -(nz - 1) * alpha / 2;
    BVTree bvh = mesh.getBVTree();
    Vector2d coords = new Vector2d();
    Point3d nearest = new Point3d();
    BVFeatureQuery query = new BVFeatureQuery();
    Point3d p;
    for (int i = 0; i < nx; i++) {
        for (int j = 0; j < ny; j++) {
            for (int k = 0; k < nz; k++) {
                double x = i * alpha + xoffset;
                double y = j * alpha + yoffset;
                double z = k * alpha + zoffset;
                p = new Point3d(x, y, z);
                p.transform(trans);
                addIfIntersects(pnts, p, r, bvh, nearest, coords, query);
                // face centers
                if (i < nx - 1 && k < nz - 1) {
                    p = new Point3d(x + alpha / 2, y, z + alpha / 2);
                    p.transform(trans);
                    addIfIntersects(pnts, p, r, bvh, nearest, coords, query);
                }
                if (j < ny - 1 && k < nz - 1) {
                    p = new Point3d(x, y + alpha / 2, z + alpha / 2);
                    p.transform(trans);
                    addIfIntersects(pnts, p, r, bvh, nearest, coords, query);
                }
                if (i < nx - 1 && j < ny - 1) {
                    p = new Point3d(x + alpha / 2, y + alpha / 2, z);
                    p.transform(trans);
                    addIfIntersects(pnts, p, r, bvh, nearest, coords, query);
                }
            }
        }
    }
    return pnts.toArray(new Point3d[pnts.size()]);
}
Also used : BVTree(maspack.geometry.BVTree) RigidTransform3d(maspack.matrix.RigidTransform3d) Vector2d(maspack.matrix.Vector2d) Vector3d(maspack.matrix.Vector3d) Point3d(maspack.matrix.Point3d) ArrayList(java.util.ArrayList) BVFeatureQuery(maspack.geometry.BVFeatureQuery)

Example 14 with Vector2d

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

the class DicomLoader method addPlane.

void addPlane() {
    if (viewer == null) {
        return;
    }
    DicomImage image = viewer.getImage();
    Point3d pmin = new Point3d(Double.POSITIVE_INFINITY, Double.POSITIVE_INFINITY, Double.POSITIVE_INFINITY);
    Point3d pmax = new Point3d(Double.NEGATIVE_INFINITY, Double.NEGATIVE_INFINITY, Double.NEGATIVE_INFINITY);
    viewer.updateBounds(pmin, pmax);
    // center transform
    RigidTransform3d trans = new RigidTransform3d();
    trans.p.interpolate(pmin, 0.5, pmax);
    Vector2d size = new Vector2d(pmax.x - pmin.x, pmax.y - pmin.y);
    DicomPlaneViewer dpv = new DicomPlaneViewer("plane_" + viewerPlanes.size(), image, trans, size);
    addRenderable(dpv);
    viewerPlanes.add(dpv);
}
Also used : RigidTransform3d(maspack.matrix.RigidTransform3d) Vector2d(maspack.matrix.Vector2d) DicomPlaneViewer(artisynth.core.renderables.DicomPlaneViewer) Point3d(maspack.matrix.Point3d) DicomImage(maspack.image.dicom.DicomImage)

Example 15 with Vector2d

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

the class GLMouseAdapter method checkForSelection.

private void checkForSelection(MouseEvent e) {
    int flags = getSelectionOperation(e);
    ViewerSelectionEvent selEvent = new ViewerSelectionEvent();
    selEvent.setModifiersEx(e.getModifiersEx());
    viewer.selectionEvent = selEvent;
    // delimits the pick region (with x, y at the center)
    double x, y, w, h;
    boolean ignoreDepthTest = false;
    Rectangle dragBox = viewer.getDragBox();
    if (dragBox != null) {
        x = dragBox.x + dragBox.width / 2.0;
        y = dragBox.y + dragBox.height / 2.0;
        w = dragBox.width;
        h = dragBox.height;
        flags |= ViewerSelectionEvent.DRAG;
        if (!visibleSelectionOnly) {
            // Normally true!
            ignoreDepthTest = true;
        }
    } else {
        x = e.getX();
        y = e.getY();
        if (viewer.getEllipticSelection()) {
            Vector2d csize = viewer.getEllipticCursorSize();
            w = 2 * csize.x;
            h = 2 * csize.y;
            flags |= ViewerSelectionEvent.DRAG;
        } else {
            w = 3.0;
            h = 3.0;
        }
        ignoreDepthTest = false;
    }
    viewer.setPick(x, y, w, h, ignoreDepthTest);
    selEvent.setFlags(flags);
// {
// GLSelectionEvent selEvent = new GLSelectionEvent();
// selEvent.myModifiersEx = e.getModifiersEx();
// selEvent.setMode(SelectionType.Clear);
// viewer.selectionEvent = selEvent;
// }
}
Also used : Vector2d(maspack.matrix.Vector2d) Rectangle(java.awt.Rectangle) ViewerSelectionEvent(maspack.render.ViewerSelectionEvent) Point(java.awt.Point)

Aggregations

Vector2d (maspack.matrix.Vector2d)35 Point3d (maspack.matrix.Point3d)16 Vector3d (maspack.matrix.Vector3d)11 Face (maspack.geometry.Face)9 Vertex3d (maspack.geometry.Vertex3d)8 ArrayList (java.util.ArrayList)7 BVFeatureQuery (maspack.geometry.BVFeatureQuery)7 RigidTransform3d (maspack.matrix.RigidTransform3d)6 Point2d (maspack.matrix.Point2d)5 PolygonalMesh (maspack.geometry.PolygonalMesh)4 ContactPoint (artisynth.core.mechmodels.ContactPoint)3 Point (artisynth.core.mechmodels.Point)3 Point (java.awt.Point)3 VectorNd (maspack.matrix.VectorNd)3 PointAttachment (artisynth.core.mechmodels.PointAttachment)2 PointParticleAttachment (artisynth.core.mechmodels.PointParticleAttachment)2 Rectangle (java.awt.Rectangle)2 HashMap (java.util.HashMap)2 BVTree (maspack.geometry.BVTree)2 Matrix2dBase (maspack.matrix.Matrix2dBase)2