Search in sources :

Example 6 with Point2d

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

the class MeshIntersectingProbe method findNextFace.

// does not add the vertex, goes in a loop around contour until we hit a face
private Face findNextFace(Point3d pnt, LinkedList<Point3d> contour, OBBTree obbt, Intersector2d ti, Vector3d vx, Vector3d vy, Point3d o, SplitStorage info) {
    Face face = null;
    Vector3d dir = new Vector3d();
    if (info.idx < contour.size() - 1) {
        dir.sub(contour.get(info.idx + 1), contour.get(info.idx));
    } else {
        dir.sub(contour.get(info.idx), contour.get(info.idx - 1));
    }
    dir.normalize();
    while (face == null && info.idx < contour.size() - 1) {
        Point3d pntNext = contour.get(info.idx + 1);
        Point2d pnt2d = Intersector2d.get2dCoordinate(pnt, vx, vy, o);
        Point2d pnt2dNext = Intersector2d.get2dCoordinate(pntNext, vx, vy, o);
        Vector2d diff2d = new Vector2d();
        ArrayList<BVNode> bvNodes = new ArrayList<BVNode>();
        // get close nodes
        obbt.intersectLineSegment(bvNodes, pnt, pntNext);
        double minDist = Double.MAX_VALUE;
        Point2d minPnt = null;
        for (BVNode node : bvNodes) {
            for (int i = 0; i < node.getNumElements(); i++) {
                Boundable ps = node.getElements()[i];
                if (ps instanceof Face) {
                    Face f = (Face) ps;
                    Vertex3d[] vtxs = f.getVertices();
                    Point2d p0 = Intersector2d.get2dCoordinate(vtxs[0].getWorldPoint(), vx, vy, o);
                    Point2d p1 = Intersector2d.get2dCoordinate(vtxs[1].getWorldPoint(), vx, vy, o);
                    Point2d p2 = Intersector2d.get2dCoordinate(vtxs[2].getWorldPoint(), vx, vy, o);
                    ArrayList<Point2d> points = new ArrayList<Point2d>();
                    ti.intersectTriangleLineSegment(p0, p1, p2, pnt2d, pnt2dNext, points);
                    // check points
                    for (Point2d p : points) {
                        diff2d.sub(p, pnt2d);
                        if (diff2d.norm() < minDist) {
                            face = f;
                            minDist = diff2d.norm();
                            minPnt = p;
                        }
                    }
                }
            }
        }
        if (face == null || minDist >= pnt2dNext.distance(pnt2d)) {
            face = null;
            // move to next point
            info.idx++;
            pnt = contour.get(info.idx);
            if (info.idx < contour.size() - 1) {
                dir.sub(contour.get(info.idx + 1), pnt);
            }
        } else {
            // snap to edge if within tolerance
            Point3d pos = Intersector2d.get3dCoordinate(minPnt, vx, vy, o);
            if (pos.distance(pnt) < ti.epsilon) {
                pos.set(pnt);
            }
            // check if we have to make a new vertex
            info.vtx = createOrGetVertex(pos, face.getVertices(), ti.epsilon);
        }
    }
    return face;
}
Also used : Vertex3d(maspack.geometry.Vertex3d) ArrayList(java.util.ArrayList) Vector2d(maspack.matrix.Vector2d) Vector3d(maspack.matrix.Vector3d) Point2d(maspack.matrix.Point2d) Point3d(maspack.matrix.Point3d) BVNode(maspack.geometry.BVNode) Boundable(maspack.geometry.Boundable) Face(maspack.geometry.Face)

Example 7 with Point2d

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

the class DicomPlaneViewer method buildRenderObject.

protected RenderObject buildRenderObject() {
    RenderObject robj = new RenderObject();
    float[][] coords = { { -0.5f, -0.5f }, { -0.5f, 0.5f }, { 0.5f, 0.5f }, { 0.5f, -0.5f } };
    // xy-slice
    Point2d[] texcoords = texture.getTextureCoordinates();
    robj.addNormal(0, 0, 1);
    for (int i = 0; i < 4; ++i) {
        robj.addPosition(coords[i][0], coords[i][1], 0);
        robj.addTextureCoord(texcoords[i]);
        robj.addVertex();
    }
    robj.createTriangleGroup();
    robj.addTriangle(0, 1, 2);
    robj.addTriangle(0, 2, 3);
    return robj;
}
Also used : Point2d(maspack.matrix.Point2d) RenderObject(maspack.render.RenderObject)

Example 8 with Point2d

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

the class TextLabeller3d method setDefaults.

@Override
protected void setDefaults() {
    myFont = new Font(defaultFontName, 0, defaultFontSize);
    myRenderProps = createDefaultRenderProps();
    hAlignment = defaultHAlignment;
    vAlignment = defaultVAlignment;
    myTextSize = defaultTextSize;
    myFontSize = defaultFontSize;
    myTextOffset = new Point2d(defaultTextOffset);
    myItems = new ArrayList<LabelItem>();
}
Also used : Point2d(maspack.matrix.Point2d) Font(java.awt.Font)

Example 9 with Point2d

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

the class HudPrintStream method setDefaults.

@Override
protected void setDefaults() {
    myFont = new Font(defaultFontName, Font.PLAIN, defaultFontSize);
    myRenderProps = createDefaultRenderProps();
    hAlignment = defaultHAlignment;
    vAlignment = defaultVAlignment;
    myTextSize = defaultTextSize;
    myFontSize = defaultFontSize;
    myPos = new Point2d();
    myMaxDisplayLines = defaultNumDisplayLines;
    myLineSpacing = defaultLineSpacing;
    myBufferSize = defaultBufferSize;
    myTextLines = new String[myBufferSize];
    myLineIdx = 0;
    myScrollOffset = 0;
    clear();
}
Also used : Point2d(maspack.matrix.Point2d) Font(java.awt.Font)

Example 10 with Point2d

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

the class HudPrintStream method fullscreen.

/**
 * Makes the HUD full-screen according to the viewer's current height
 */
public void fullscreen() {
    // save previous values so we can return
    lastLocation = new Point2d(myPos);
    lastVAlignment = vAlignment;
    // move to top
    myPos.set(myPos.x, 1);
    vAlignment = VerticalAlignment.TOP;
    isFullScreen = true;
}
Also used : Point2d(maspack.matrix.Point2d)

Aggregations

Point2d (maspack.matrix.Point2d)20 ArrayList (java.util.ArrayList)6 Point3d (maspack.matrix.Point3d)5 Vector2d (maspack.matrix.Vector2d)5 Vector3d (maspack.matrix.Vector3d)4 Font (java.awt.Font)3 Face (maspack.geometry.Face)3 BVNode (maspack.geometry.BVNode)2 Boundable (maspack.geometry.Boundable)2 Vertex3d (maspack.geometry.Vertex3d)2 RenderObject (maspack.render.RenderObject)2 HalfEdge (maspack.geometry.HalfEdge)1 RigidTransform3d (maspack.matrix.RigidTransform3d)1 Shading (maspack.render.Renderer.Shading)1 Rectangle (maspack.util.Rectangle)1