Contenuto principale

PrimitiveCollection

R2026b

Specify primitive collection in RoadRunner Viewer

Since R2026b

    Description

    The PrimitiveCollection object represents a primitive collection, a collection of 3D primitives, in the RoadRunner Viewer scene graph. The PrimitiveCollection object enables you to draw 3D primitives, such as points, lines, and triangles, in the scene graph. You can use 3D primitives to highlight actor trajectories and road lanes, indicate sensor locations, or outline the locations of expected events during simulation.

    Creation

    The addPrimitive function adds an empty primitive collection to the scene graph of the specified RoadRunner Viewer object. For example, pc = addPrimitive(rrViewer); adds a new PrimitiveCollection object, pc, that represents a primitive collection in the scene graph of the RoadRunner Viewer object rrViewer.

    Object Functions

    drawPointsDraw points in RoadRunner Viewer scene graph
    drawLinesDraw connected line segments in RoadRunner Viewer scene graph
    drawTrianglesDraw filled triangles in RoadRunner Viewer scene graph
    drawTrianglesFromMeshDraw triangles from 3D mesh file in RoadRunner Viewer scene graph
    resetClear 3D primitives from RoadRunner Viewer scene graph

    Examples

    collapse all

    Use a PrimitiveCollection object to draw points, lines, and two triangles in the RoadRunner Viewer scene graph. This example assumes you have already added the folder containing the RoadRunner API to your MATLAB® path. For information on getting started with RoadRunner Viewer, see Get Started with RoadRunner Viewer (RoadRunner Scenario).

    Open RoadRunner Viewer and create a roadrunnerViewer object rrViewer.

    rrViewer = roadrunnerViewer;

    To create a PrimitiveCollection object, pc, to represent a primitive collection, use the addPrimitive function and specify the roadrunnerViewer object rrViewer.

    pc = addPrimitive(rrViewer);

    Draw a row of red points along the x-axis of the RoadRunner Viewer scene graph. Use the drawPoints function and specify the primitive collection pc, the point locations pts, the point color, and the point size.

    pts = [0 0 0; 1 0 0; 2 0 0; 3 0 0; 4 0 0];
    drawPoints(pc,pts,[1 0 0],10);

    Draw a green polyline in the RoadRunner Viewer scene graph. Use the drawLines function and specify the primitive collection pc, the polyline point locations linePts, the line color, and the line width.

    linePts = [0 0 1; 1 1 1; 2 0 1; 3 1 1; 4 0 1];
    drawLines(pc,linePts,[0 0.8 0],3);

    Draw two blue triangles that form a square in the RoadRunner Viewer scene graph. Use the drawTriangles function and specify the primitive collection pc, the triangle vertex locations triVerts, and the triangle color.

    triVerts = [-2 0 0; -1 0 0; -2 0 1; -1 0 0; -1 0 1; -2 0 1];
    drawTriangles(pc,triVerts,[0 0.4 1]);

    To update the scene graph and view the newly added primitives, use the drawnow function.

    drawnow(rrViewer)

    Version History

    Introduced in R2026b