Search in sources :

Example 16 with RenderObject

use of maspack.render.RenderObject in project artisynth_core by artisynth.

the class CollisionRenderer method createPenetrationRenderObject.

RenderObject createPenetrationRenderObject(CollisionHandler handler, ArrayList<PenetratingPoint> points, ArrayList<PenetrationRegion> regions) {
    RenderObject rd = new RenderObject();
    HashMap<Vertex3d, Double> depthMap = new HashMap<Vertex3d, Double>();
    double maxd = 0;
    for (PenetratingPoint pp : points) {
        depthMap.put(pp.vertex, pp.distance);
        if (pp.distance > maxd) {
            maxd = pp.distance;
        }
    }
    ScalarRange range = handler.myBehavior.myPenetrationDepthRange;
    range.updateInterval(0, maxd);
    float[] rgb = new float[3];
    for (int i = 0; i < 256; i++) {
        handler.myManager.myColorMap.getRGB(i / 255.0, rgb);
        rd.addColor(rgb);
    }
    Point3d wpnt = new Point3d();
    Vector3d wnrm = new Vector3d();
    for (PenetrationRegion region : regions) {
        for (Face face : region.getFaces()) {
            HalfEdge he = face.firstHalfEdge();
            Vertex3d v0 = he.getHead();
            Vertex3d v1 = he.getNext().getHead();
            Vertex3d v2 = he.getTail();
            v0.getWorldPoint(wpnt);
            int pi0 = rd.addPosition(wpnt);
            v1.getWorldPoint(wpnt);
            int pi1 = rd.addPosition(wpnt);
            v2.getWorldPoint(wpnt);
            int pi2 = rd.addPosition(wpnt);
            int ci0 = getColorIndex(range, v0, depthMap);
            int ci1 = getColorIndex(range, v1, depthMap);
            int ci2 = getColorIndex(range, v2, depthMap);
            face.getWorldNormal(wnrm);
            int ni = rd.addNormal(wnrm);
            int v0idx = rd.addVertex(pi0, ni, ci0, -1);
            int v1idx = rd.addVertex(pi1, ni, ci1, -1);
            int v2idx = rd.addVertex(pi2, ni, ci2, -1);
            rd.addTriangle(v0idx, v1idx, v2idx);
        }
    }
    return rd;
}
Also used : Vertex3d(maspack.geometry.Vertex3d) HashMap(java.util.HashMap) HalfEdge(maspack.geometry.HalfEdge) IntersectionPoint(maspack.collision.IntersectionPoint) PenetratingPoint(maspack.collision.PenetratingPoint) PenetratingPoint(maspack.collision.PenetratingPoint) Vector3d(maspack.matrix.Vector3d) Point3d(maspack.matrix.Point3d) RenderObject(maspack.render.RenderObject) Face(maspack.geometry.Face) PenetrationRegion(maspack.collision.PenetrationRegion) ScalarRange(artisynth.core.util.ScalarRange)

Example 17 with RenderObject

use of maspack.render.RenderObject in project artisynth_core by artisynth.

the class AxialSpringList method buildRenderObject.

protected void buildRenderObject() {
    myRob = new RenderObject();
    myRob.createLineGroup();
    myRob.createLineGroup();
    int vidx = 0;
    for (int i = 0; i < size(); i++) {
        AxialSpring spr = get(i);
        myRob.addPosition(spr.myPnt0.myRenderCoords);
        myRob.addVertex(vidx);
        myRob.addPosition(spr.myPnt1.myRenderCoords);
        myRob.addVertex(vidx + 1);
        if (spr.getRenderProps() == null) {
            myRob.lineGroup(spr.isSelected() ? SEL_GRP : REG_GRP);
            myRob.addLine(vidx, vidx + 1);
        }
        vidx += 2;
    }
}
Also used : RenderObject(maspack.render.RenderObject)

Example 18 with RenderObject

use of maspack.render.RenderObject in project artisynth_core by artisynth.

the class PointList method buildRenderObject.

protected void buildRenderObject() {
    myRob = new RenderObject();
    myRob.createPointGroup();
    myRob.createPointGroup();
    for (int i = 0; i < size(); i++) {
        Point pnt = get(i);
        myRob.addPosition(pnt.myRenderCoords);
        myRob.addVertex(i);
        if (pnt.getRenderProps() == null) {
            myRob.pointGroup(pnt.isSelected() ? SEL_GRP : REG_GRP);
            myRob.addPoint(i);
        }
    }
}
Also used : RenderObject(maspack.render.RenderObject)

Example 19 with RenderObject

use of maspack.render.RenderObject in project artisynth_core by artisynth.

the class ColorBar method buildRenderObject.

public RenderObject buildRenderObject(int divisions, ColorMap cmap, VectorNd labelPos, Vector2d tickWidths) {
    RenderObject out = new RenderObject();
    int labelSize = labelPos.size();
    out.ensurePositionCapacity(2 * divisions + 4 * labelSize + 2);
    out.ensureVertexCapacity(2 * divisions + 4 * labelSize + 2);
    out.ensureColorCapacity(divisions + 3);
    out.ensureTriangleCapacity(2 * divisions);
    out.ensureLineCapacity(2 + 2 * divisions);
    // for color interpolation
    float[] rgb = new float[3];
    // add positions and colors
    for (int i = 0; i <= divisions; ++i) {
        cmap.getRGB((float) i / divisions, rgb);
        out.addColor(rgb[0], rgb[1], rgb[2], 1f);
        out.addPosition(0, (float) i / divisions, 0);
        out.addPosition(1, (float) i / divisions, 0);
    }
    // line color
    int lineColor = out.addColor(0, 0, 0, 1);
    // tick positions
    for (int i = 0; i < labelPos.size(); ++i) {
        float y = (float) (labelPos.get(i));
        out.addPosition(0, y, 0);
        out.addPosition((float) (tickWidths.x), y, 0);
        out.addPosition((float) (1 - tickWidths.y), y, 0);
        out.addPosition(1, y, 0);
    }
    // color bar vertices
    int vidx = 0;
    out.addVertex(0, -1, 0, -1);
    out.addVertex(1, -1, 0, -1);
    for (int i = 1; i <= divisions; ++i) {
        vidx = out.addVertex(2 * i, -1, i, -1);
        out.addVertex(2 * i + 1, -1, i, -1);
        out.addTriangle(vidx - 2, vidx, vidx - 1);
        out.addTriangle(vidx - 1, vidx, vidx + 1);
    }
    // border vertices
    out.setCurrentColor(lineColor);
    vidx = out.addVertex(0);
    out.addVertex(1);
    out.addVertex(2 * divisions);
    out.addVertex(2 * divisions + 1);
    out.addLine(vidx, vidx + 1);
    out.addLine(vidx, vidx + 2);
    out.addLine(vidx + 2, vidx + 3);
    out.addLine(vidx + 1, vidx + 3);
    // tick vertices
    int tickPos = 2 * divisions + 2;
    for (int i = 0; i < labelPos.size(); ++i) {
        vidx = out.addVertex(tickPos++);
        out.addVertex(tickPos++);
        out.addLine(vidx, vidx + 1);
        vidx = out.addVertex(tickPos++);
        out.addVertex(tickPos++);
        out.addLine(vidx, vidx + 1);
    }
    return out;
}
Also used : RenderObject(maspack.render.RenderObject)

Example 20 with RenderObject

use of maspack.render.RenderObject 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)

Aggregations

RenderObject (maspack.render.RenderObject)45 Vector3d (maspack.matrix.Vector3d)8 RenderProps (maspack.render.RenderProps)7 Point3d (maspack.matrix.Point3d)4 Shading (maspack.render.Renderer.Shading)4 Color (java.awt.Color)3 IntersectionPoint (maspack.collision.IntersectionPoint)3 PenetratingPoint (maspack.collision.PenetratingPoint)3 LineSegment (maspack.geometry.LineSegment)3 AffineTransform3d (maspack.matrix.AffineTransform3d)3 RigidTransform3d (maspack.matrix.RigidTransform3d)3 PointStyle (maspack.render.Renderer.PointStyle)3 PenetrationRegion (maspack.collision.PenetrationRegion)2 Face (maspack.geometry.Face)2 Vertex3d (maspack.geometry.Vertex3d)2 Point2d (maspack.matrix.Point2d)2 Renderer (maspack.render.Renderer)2 ColorInterpolation (maspack.render.Renderer.ColorInterpolation)2 LineStyle (maspack.render.Renderer.LineStyle)2 Group (artisynth.core.mechmodels.Collidable.Group)1