class cv::viz::Viz3d

Overview

The Viz3d class represents a 3D visualizer window. This class is implicitly shared. : Moreā€¦

#include <viz3d.hpp>

class Viz3d
{
public:
    // typedefs

    typedef cv::viz::Color Color;

    typedef void (*KeyboardCallback)(
        const KeyboardEvent &,
        void *
        );

    typedef void (*MouseCallback)(
        const MouseEvent &,
        void *
        );

    // construction

    Viz3d(const String& window_name = String());
    Viz3d(const Viz3d&);

    // methods

    void
    addLight(
        Vec3d position,
        Vec3d focalPoint = Vec3d(0, 0, 0),
        Color color = Color::white(),
        Color diffuseColor = Color::white(),
        Color ambientColor = Color::black(),
        Color specularColor = Color::white()
        );

    void
    close();

    void
    converTo3DRay(
        const Point3d& window_coord,
        Point3d& origin,
        Vec3d& direction
        );

    void
    convertToWindowCoordinates(
        const Point3d& pt,
        Point3d& window_coord
        );

    Camera
    getCamera() const;

    double
    getRenderingProperty(
        const String& id,
        int property
        );

    cv::Mat
    getScreenshot() const;

    Affine3d
    getViewerPose();

    Widget
    getWidget(const String& id) const;

    Affine3d
    getWidgetPose(const String& id) const;

    String
    getWindowName() const;

    Size
    getWindowSize() const;

    Viz3d&
    operator=(const Viz3d&);

    void
    registerKeyboardCallback(
        KeyboardCallback callback,
        void* cookie = 0
        );

    void
    registerMouseCallback(
        MouseCallback callback,
        void* cookie = 0
        );

    void
    removeAllLights();

    void
    removeAllWidgets();

    void
    removeWidget(const String& id);

    void
    resetCamera();

    void
    resetCameraViewpoint(const String& id);

    void
    saveScreenshot(const String& file);

    void
    setBackgroundColor(
        const Color& color = Color::black(),
        const Color& color2 = Color::not_set()
        );

    void
    setBackgroundMeshLab();

    void
    setBackgroundTexture(InputArray image = noArray());

    void
    setCamera(const Camera& camera);

    void
    setFullScreen(bool mode = true);

    void
    setGlobalWarnings(bool enabled = false);

    void
    setOffScreenRendering();

    void
    setRenderingProperty(
        const String& id,
        int property,
        double value
        );

    void
    setRepresentation(int representation);

    void
    setViewerPose(const Affine3d& pose);

    void
    setWidgetPose(
        const String& id,
        const Affine3d& pose
        );

    void
    setWindowPosition(const Point& window_position);

    void
    setWindowSize(const Size& window_size);

    void
    showImage(
        InputArray image,
        const Size& window_size = Size(-1, -1)
        );

    void
    showWidget(
        const String& id,
        const Widget& widget,
        const Affine3d& pose = Affine3d::Identity()
        );

    void
    spin();

    void
    spinOnce(
        int time = 1,
        bool force_redraw = false
        );

    void
    updateWidgetPose(
        const String& id,
        const Affine3d& pose
        );

    bool
    wasStopped() const;
};

Detailed Documentation

The Viz3d class represents a 3D visualizer window. This class is implicitly shared. :

Construction

Viz3d(const String& window_name = String())

The constructors.

Parameters:

window_name Name of the window.

Methods

void
addLight(
    Vec3d position,
    Vec3d focalPoint = Vec3d(0, 0, 0),
    Color color = Color::white(),
    Color diffuseColor = Color::white(),
    Color ambientColor = Color::black(),
    Color specularColor = Color::white()
    )

Add a light in the scene.

Parameters:

position The position of the light.
focalPoint The point at which the light is shining
color The color of the light
diffuseColor The diffuse color of the light
ambientColor The ambient color of the light
specularColor The specular color of the light
void
converTo3DRay(
    const Point3d& window_coord,
    Point3d& origin,
    Vec3d& direction
    )

Transforms a point in window coordinate system to a 3D ray in world coordinate system.

Parameters:

window_coord Point in window coordinate system.
origin Output origin of the ray.
direction Output direction of the ray.
void
convertToWindowCoordinates(
    const Point3d& pt,
    Point3d& window_coord
    )

Transforms a point in world coordinate system to window coordinate system.

Parameters:

pt Point in world coordinate system.
window_coord Output point in window coordinate system.
Camera
getCamera() const

Returns a camera object that contains intrinsic parameters of the current viewer.

double
getRenderingProperty(
    const String& id,
    int property
    )

Returns rendering property of a widget.

Rendering property** can be one of the following:

  • POINT_SIZE
  • OPACITY
  • LINE_WIDTH
  • FONT_SIZE
  • REPRESENTATION**: Expected values are
  • REPRESENTATION_POINTS
  • REPRESENTATION_WIREFRAME
  • REPRESENTATION_SURFACE
  • IMMEDIATE_RENDERING**:
  • Turn on immediate rendering by setting the value to 1.
  • Turn off immediate rendering by setting the value to 0.
  • SHADING**: Expected values are
  • SHADING_FLAT
  • SHADING_GOURAUD
  • SHADING_PHONG

Parameters:

id Id of the widget.
property Property.
cv::Mat
getScreenshot() const

Returns the Mat screenshot of the current scene.

Affine3d
getViewerPose()

Returns the current pose of the viewer.

Widget
getWidget(const String& id) const

Retrieves a widget from the window.

A widget is implicitly shared; that is, if the returned widget is modified, the changes will be immediately visible in the window.

Parameters:

id The id of the widget that will be returned.
Affine3d
getWidgetPose(const String& id) const

Returns the current pose of a widget in the window.

Parameters:

id The id of the widget whose pose will be returned.
String
getWindowName() const

Returns the name of the window which has been set in the constructor.

Size
getWindowSize() const

Returns the current size of the window.

void
registerKeyboardCallback(
    KeyboardCallback callback,
    void* cookie = 0
    )

Sets keyboard handler.

Parameters:

callback Keyboard callback (void (*KeyboardCallbackFunction(const KeyboardEvent &, void*)).
cookie The optional parameter passed to the callback.
void
registerMouseCallback(
    MouseCallback callback,
    void* cookie = 0
    )

Sets mouse handler.

Parameters:

callback Mouse callback (void (*MouseCallback)(const MouseEvent &, void*)).
cookie The optional parameter passed to the callback.
void
removeAllLights()

Remove all lights from the current scene.

void
removeAllWidgets()

Removes all widgets from the window.

void
removeWidget(const String& id)

Removes a widget from the window.

Parameters:

id The id of the widget that will be removed.
void
resetCamera()

Resets camera.

void
resetCameraViewpoint(const String& id)

Resets camera viewpoint to a 3D widget in the scene.

Parameters:

id Id of a 3D widget.
void
saveScreenshot(const String& file)

Saves screenshot of the current scene.

Parameters:

file Name of the file.
void
setBackgroundColor(
    const Color& color = Color::black(),
    const Color& color2 = Color::not_set()
    )

Sets background color.

void
setCamera(const Camera& camera)

Sets the intrinsic parameters of the viewer using Camera.

Parameters:

camera Camera object wrapping intrinsinc parameters.
void
setFullScreen(bool mode = true)

Sets or unsets full-screen rendering mode.

Parameters:

mode If true, window will use full-screen mode.
void
setOffScreenRendering()

Create a window in memory instead of on the screen.

void
setRenderingProperty(
    const String& id,
    int property,
    double value
    )

Sets rendering property of a widget.

Rendering property** can be one of the following:

  • POINT_SIZE
  • OPACITY
  • LINE_WIDTH
  • FONT_SIZE
  • REPRESENTATION**: Expected values are
  • REPRESENTATION_POINTS
  • REPRESENTATION_WIREFRAME
  • REPRESENTATION_SURFACE
  • IMMEDIATE_RENDERING**:
  • Turn on immediate rendering by setting the value to 1.
  • Turn off immediate rendering by setting the value to 0.
  • SHADING**: Expected values are
  • SHADING_FLAT
  • SHADING_GOURAUD
  • SHADING_PHONG

Parameters:

id Id of the widget.
property Property that will be modified.
value The new value of the property.
void
setRepresentation(int representation)

Sets geometry representation of the widgets to surface, wireframe or points.

Parameters:

representation

Geometry representation which can be one of the following:

  • REPRESENTATION_POINTS
  • REPRESENTATION_WIREFRAME
  • REPRESENTATION_SURFACE
void
setViewerPose(const Affine3d& pose)

Sets pose of the viewer.

Parameters:

pose The new pose of the viewer.
void
setWidgetPose(
    const String& id,
    const Affine3d& pose
    )

Sets pose of a widget in the window.

Parameters:

id The id of the widget whose pose will be set.
pose The new pose of the widget.
void
setWindowPosition(const Point& window_position)

Sets the position of the window in the screen.

Parameters:

window_position coordinates of the window
void
setWindowSize(const Size& window_size)

Sets the size of the window.

Parameters:

window_size New size of the window.
void
showImage(
    InputArray image,
    const Size& window_size = Size(-1, -1)
    )

Removed all widgets and displays image scaled to whole window area.

Parameters:

image Image to be displayed.
window_size Size of Viz3d window. Default value means no change.
void
showWidget(
    const String& id,
    const Widget& widget,
    const Affine3d& pose = Affine3d::Identity()
    )

Shows a widget in the window.

Parameters:

id A unique id for the widget.
widget The widget to be displayed in the window.
pose Pose of the widget.
void
spin()

The window renders and starts the event loop.

void
spinOnce(
    int time = 1,
    bool force_redraw = false
    )

Starts the event loop for a given time.

Parameters:

time Amount of time in milliseconds for the event loop to keep running.
force_redraw If true, window renders.
void
updateWidgetPose(
    const String& id,
    const Affine3d& pose
    )

Updates pose of a widget in the window by pre-multiplying its current pose.

Parameters:

id The id of the widget whose pose will be updated.
pose The pose that the current pose of the widget will be pre-multiplied by.
bool
wasStopped() const

Returns whether the event loop has been stopped.