Class SoPolyLineScreenDrawer

  • All Implemented Interfaces:
    Direct Known Subclasses:
    SoEllipseScreenDrawer, SoLassoScreenDrawer, SoPolygonScreenDrawer, SoRectangleScreenDrawer

    public class SoPolyLineScreenDrawer
    extends SoScreenDrawer
    Interactively draw a polyline in normalized screen space. This class is a base class used to allow the user to dynamically draw line-based shapes (lasso, circle, rectangle, ...) on screen. The geometry is defined in normalized screen space ([-1, 1]x[-1, 1]).

    Applications will typically use one of the derived classes, for example, SoEllipseScreenDrawer, SoRectangleScreenDrawer, SoPolygonScreenDrawer or SoLassoScreenDrawer.

    The line color is specified by the color field (default is red).

    SoPolyLineScreenDrawer classes can automatically reduce the number of points in the shape drawn by the user. This is especially useful with SoLassoScreenDrawer. See the simplificationThreshold field.

    Sub-classes can implement the onMouseDown, onMouseMove, etc... methods, to add and edit points.


    • Viewer:
      • Screen drawers, like draggers, depend on SoHandleEventAction to get events. Therefore when using one of the Open Inventor viewer classes, screen drawers will only work when the viewer is in "selection" mode (arrow cursor). (In "viewing" mode, mouse events are handled by the viewer to control the camera.)

      • The escape key (ESC) can be used to cancel creation of the polyline. However, currently it also changes the viewer mode (this is a known problem).
    • Event handling:
      The drawer will automatically begin a new polyline when it sees a mouse button 1 down event. However the drawer does not call setHandled(), so other nodes in the scene graph, e.g. SoEventCallback or a dragger, may also handle this event.
    • Finish notification:
      • An event is raised to notify the application when the line is finished. (see onFinish ). This event is called at the end of line finalization (after simplification etc). See SbEventHandler for methods to set a callback to be notified when this event is raised.

      • In this callback the application can retrieve coordinates from the point field. These points are in Open Inventor normalized device coordinates (-1 to 1), not pixel coordinates.

      • The drawer does not call the SoHandleEventAction's setHandled() method for the event that finished the polyline. The application can call setHandled() in this callback.

      • With some drawers it is possible to get a call with zero points if the user pressed ESC to cancel the interaction. Applications should check for this case.

      • With some drawers it is also possible to get a call with a non-zero number of points, but all points are the same coordinate. E.g. SoRectangleScreenDrawer stores four points even if the mouse down/up events are at the same location.

      • Typically the application will want to remove the polyline from the screen in this callback. See the next note.
    • Part of the scene graph:
      • Note that the polyline remains on the screen (because it is part of the scene graph) until clear() is called or the user starts a new interaction.

      • Changing the color field or the isClosed field will immediately change the appearance of a polyline currently on the screen.
    • Simplification:
      Simplification is done (if > 0) when the user releases the mouse button and also if the simplificationThreshold is changed. But note that the old points are thrown away, so you can't re-simplify with a different value.
    • isClosed field:
      If true (default), the polyline will be closed while being drawn (not just when the user releases the mouse button). The default in this class is false, but most sub-classes set it to true.
    • Coordinates:
      This node and its subclasses use screen coordinates ranging from -1 to 1. (Because this is the default view volume for an SoOrthographicCamera node.) Be careful because other classes in Open Inventor use normalized screen coordinates ranging from 0 to 1. In particular the SbViewportRegion normalize() methods and the SbViewVolume methods that project from 3D to 2D and vice-versa.
    • There should only be one SoScreenDrawer derived node in the sceneGraph (to avoid conflicts in mouse events).


    Create a screen drawer, set the callback and add it to the scene graph:

     SoRectangleScreenDrawer drawer = new SoRectangleScreenDrawer();
     drawer.onFinish.addEventListener(new LineDrawerListener());
     root.addChild( drawer );
    A finish callback that gets the number of points created by the screen drawer:
     class LineDrawerListener implements SbEventListener<EventArg>
       public void onEvent(EventArg eventArg)
         SoPolyLineScreenDrawer drawer = eventArg.getSource();
         SoHandleEventAction action = eventArg.getAction();
         int numPoints = drawer.point.getNum();
         if ( numPoints > 0 )
           // Use points
           SbVec2f point0 = drawer.point.getValueAt(0);
         drawer.clear(); // Remove polyline from screen

    See Also:
    SoEllipseScreenDrawer, SoLassoScreenDrawer, SoPolygonScreenDrawer, SoRectangleScreenDrawer, SoScreenDrawer
    • Field Detail

      • simplificationThreshold

        public final SoSFUInt32 simplificationThreshold
        Threshold (in pixels) used to simplify line when it is finished. A value of 0 means no simplification. Default value is 5 pixels.
      • doCCW

        public final SoSFBool doCCW
        Make the line counter-clockwise when it is finalized. This can change order of points. Default is true.

        Note Some shapes (like "8") do not have a defined clockwiseness. In these cases, the result is undefined.

        Open Inventor 9.0

      • color

        public final SoSFColor color
        Color of line. Default value is red.
      • point

        public final SoMFVec2f point
        Points of line. Default is empty.
      • isClosed

        public final SoSFBool isClosed
        Close the line during display (connect last point to first point). Default is false (but most sub-classes automatically set it to true).

        Warning This only affects the display.

      • linePattern

        public final SoSFUShort linePattern
        Stipple pattern. This specifies how dashed or dotted lines will be drawn. The pattern is a 16-bit series of 0s and 1s and is repeated as necessary to stipple a given line. A 1 indicates that drawing occurs, and a 0 that it does not, on a pixel-by-pixel basis, starting with the low-order bits of the pattern. Values can range from 0 (invisible) to 0xffff (solid). Default is 0xffff.

        The line pattern can be stretched using the linePatternScaleFactor field.

      • linePatternScaleFactor

        public final SoSFInt32 linePatternScaleFactor
        Stipple pattern scale factor. It stretches the line pattern (see linePattern) by multiplying each subseries of consecutive 1s and 0s. Scale factors are clamped to lie between 1 and 255. Default is 1.
      • lineWidth

        public final SoSFFloat lineWidth
        Width of lines. The default line width is 0, meaning to use the default OpenGL value (1). Line widths greater than zero are considered to be specified in printer's points, where 1 inch = 72 printer's points. However the default pixels-per-inch value (managed by SbViewportRegion) is also 72. So effectively line width is specified in pixels unless the application sets a different pixels-per-inch value.
      • onStart

        public final SbEventHandler<SoPolyLineScreenDrawer.EventArg> onStart
        Event raised when starting to draw a polyline. See SbEventHandler for methods to set a callback to be notified when this event is raised. The callback will be called with an EventArg from which it can query the current action and drawer objects.
        Note that the callback parameter must be declared const .
      • onMove

        public final SbEventHandler<SoPolyLineScreenDrawer.EventArg> onMove
        Event raised during polyline drawing. See SbEventHandler for methods to set a callback to be notified when this event is raised. The callback will be called with an EventArg from which it can query the current action and drawer objects. Note that the callback parameter must be declared const .
      • onFinish

        public final SbEventHandler<SoPolyLineScreenDrawer.EventArg> onFinish
        Event raised when the line is finished. See SbEventHandler for methods to set a callback to be notified when this event is raised. The callback will be called with a line drawer specific EventArg from which you can query the current action and drawer objects. Note that the callback parameter in this case is not const.
    • Constructor Detail

      • SoPolyLineScreenDrawer

        public SoPolyLineScreenDrawer()
    • Method Detail

      • clear

        public void clear()
        Convenience method to clear the points in the line.