viz3d.rst 22.1 KB
Newer Older
Ozan Tonkal's avatar
Ozan Tonkal committed
1 2
Viz
===
Ozan Tonkal's avatar
Ozan Tonkal committed
3 4 5

.. highlight:: cpp

Ozan Tonkal's avatar
Ozan Tonkal committed
6
This section describes 3D visualization window as well as classes and methods
Ozan Tonkal's avatar
Ozan Tonkal committed
7
that are used to interact with it.
Ozan Tonkal's avatar
Ozan Tonkal committed
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23

3D visualization window (see :ocv:class:`Viz3d`) is used to display widgets (see :ocv:class:`Widget`), and it provides
several methods to interact with scene and widgets.

viz::makeTransformToGlobal
--------------------------
Takes coordinate frame data and builds transform to global coordinate frame.

.. ocv:function:: Affine3f viz::makeTransformToGlobal(const Vec3f& axis_x, const Vec3f& axis_y, const Vec3f& axis_z, const Vec3f& origin = Vec3f::all(0))

    :param axis_x: X axis vector in global coordinate frame.
    :param axis_y: Y axis vector in global coordinate frame.
    :param axis_z: Z axis vector in global coordinate frame.
    :param origin: Origin of the coordinate frame in global coordinate frame.

This function returns affine transform that describes transformation between global coordinate frame and a given coordinate frame.
Ozan Tonkal's avatar
Ozan Tonkal committed
24

Ozan Tonkal's avatar
Ozan Tonkal committed
25 26 27
viz::makeCameraPose
-------------------
Constructs camera pose from position, focal_point and up_vector (see gluLookAt() for more infromation).
Ozan Tonkal's avatar
Ozan Tonkal committed
28

Ozan Tonkal's avatar
Ozan Tonkal committed
29 30 31 32 33
.. ocv:function:: Affine3f makeCameraPose(const Vec3f& position, const Vec3f& focal_point, const Vec3f& y_dir)

    :param position: Position of the camera in global coordinate frame.
    :param focal_point: Focal point of the camera in global coordinate frame.
    :param y_dir: Up vector of the camera in global coordinate frame.
Ozan Tonkal's avatar
Ozan Tonkal committed
34

Ozan Tonkal's avatar
Ozan Tonkal committed
35 36 37 38 39 40 41 42 43
This function returns pose of the camera in global coordinate frame.

viz::get
--------
Retrieves a window by its name.

.. ocv:function:: Viz3d get(const String &window_name)

    :param window_name: Name of the window that is to be retrieved.
Ozan Tonkal's avatar
Ozan Tonkal committed
44 45

This function returns a :ocv:class:`Viz3d` object with the given name.
Ozan Tonkal's avatar
Ozan Tonkal committed
46 47 48 49 50 51

.. note:: If the window with that name already exists, that window is returned. Otherwise, new window is created with the given name, and it is returned.

.. note:: Window names are automatically prefixed by "Viz - " if it is not done by the user.

          .. code-block:: cpp
Ozan Tonkal's avatar
Ozan Tonkal committed
52

Ozan Tonkal's avatar
Ozan Tonkal committed
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77
                /// window and window_2 are the same windows.
                viz::Viz3d window   = viz::get("myWindow");
                viz::Viz3d window_2 = viz::get("Viz - myWindow");

viz::isNan
----------
Checks **float/double** value for nan.

    .. ocv:function:: bool isNan(float x)

    .. ocv:function:: bool isNan(double x)

        :param x: return true if nan.

Checks **vector** for nan.

    .. ocv:function:: bool isNan(const Vec<_Tp, cn>& v)

        :param v: return true if **any** of the elements of the vector is *nan*.

Checks **point** for nan

    .. ocv:function:: bool isNan(const Point3_<_Tp>& p)

        :param p: return true if **any** of the elements of the point is *nan*.
Ozan Tonkal's avatar
Ozan Tonkal committed
78

Ozan Tonkal's avatar
Ozan Tonkal committed
79 80 81 82 83 84 85 86 87 88 89
viz::VizAccessor
----------------
.. ocv:class:: VizAccessor

A singleton class that provides access by name infrastructure for 3D visualization windows. ::

    class CV_EXPORTS VizAccessor
    {
    public:
        static VizAccessor & getInstance();
        static void release();
Ozan Tonkal's avatar
Ozan Tonkal committed
90

Ozan Tonkal's avatar
Ozan Tonkal committed
91
        Viz3d get(const String &window_name);
Ozan Tonkal's avatar
Ozan Tonkal committed
92

Ozan Tonkal's avatar
Ozan Tonkal committed
93 94
        //! window names automatically have Viz - prefix even though not provided by the users
        static void generateWindowName(const String &window_name, String &output);
Ozan Tonkal's avatar
Ozan Tonkal committed
95

Ozan Tonkal's avatar
Ozan Tonkal committed
96 97 98
    private:
        /* hidden */
    };
Ozan Tonkal's avatar
Ozan Tonkal committed
99

Ozan Tonkal's avatar
Ozan Tonkal committed
100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118
viz::VizAccessor::getInstance
-----------------------------
Returns the single instance of VizAccessor.

.. ocv:function:: static VizAccessor & getInstance()

viz::VizAccessor::release
-------------------------
Deletes the single instance of VizAccessor.

.. ocv:function:: static void release()

viz::VizAccessor::get
---------------------
Retrieves a window by its name.

.. ocv:function:: Viz3d get(const String &window_name)

    :param window_name: Name of the window that is to be retrieved.
Ozan Tonkal's avatar
Ozan Tonkal committed
119 120

This function returns a :ocv:class:`Viz3d` object with the given name.
Ozan Tonkal's avatar
Ozan Tonkal committed
121 122 123 124 125 126

.. note:: If the window with that name already exists, that window is returned. Otherwise, new window is created with the given name, and it is returned.

.. note:: Window names are automatically prefixed by "Viz - " if it is not done by the user.

          .. code-block:: cpp
Ozan Tonkal's avatar
Ozan Tonkal committed
127

Ozan Tonkal's avatar
Ozan Tonkal committed
128 129 130 131 132 133 134 135 136
                /// window and window_2 are the same windows.
                viz::Viz3d window   = viz::get("myWindow");
                viz::Viz3d window_2 = viz::get("Viz - myWindow");

viz::VizAccessor::generateWindowName
------------------------------------
Generates a window name by prefixing "Viz - " if it has not already been prefixed.

.. ocv:function:: static void generateWindowName(const String &window_name, String &output)
Ozan Tonkal's avatar
Ozan Tonkal committed
137

Ozan Tonkal's avatar
Ozan Tonkal committed
138 139 140 141 142
    :param window_name: Window name
    :param output: Prefixed window name

viz::Viz3d
----------
Ozan Tonkal's avatar
Ozan Tonkal committed
143 144
.. ocv:class:: Viz3d

Ozan Tonkal's avatar
Ozan Tonkal committed
145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166
The Viz3d class represents a 3D visualizer window. This class is implicitly shared.    ::

    class CV_EXPORTS Viz3d
    {
    public:
        typedef cv::Ptr<Viz3d> Ptr;
        typedef void (*KeyboardCallback)(const KeyboardEvent&, void*);
        typedef void (*MouseCallback)(const MouseEvent&, void*);

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

        void showWidget(const String &id, const Widget &widget, const Affine3f &pose = Affine3f::Identity());
        void removeWidget(const String &id);
        Widget getWidget(const String &id) const;
        void removeAllWidgets();

        void setWidgetPose(const String &id, const Affine3f &pose);
        void updateWidgetPose(const String &id, const Affine3f &pose);
        Affine3f getWidgetPose(const String &id) const;
Ozan Tonkal's avatar
Ozan Tonkal committed
167

Ozan Tonkal's avatar
Ozan Tonkal committed
168 169 170 171
        void setCamera(const Camera &camera);
        Camera getCamera() const;
        Affine3f getViewerPose();
        void setViewerPose(const Affine3f &pose);
Ozan Tonkal's avatar
Ozan Tonkal committed
172

Ozan Tonkal's avatar
Ozan Tonkal committed
173 174
        void resetCameraViewpoint (const String &id);
        void resetCamera();
Ozan Tonkal's avatar
Ozan Tonkal committed
175

Ozan Tonkal's avatar
Ozan Tonkal committed
176 177
        void convertToWindowCoordinates(const Point3d &pt, Point3d &window_coord);
        void converTo3DRay(const Point3d &window_coord, Point3d &origin, Vec3d &direction);
Ozan Tonkal's avatar
Ozan Tonkal committed
178

Ozan Tonkal's avatar
Ozan Tonkal committed
179 180 181 182 183 184 185 186 187 188 189 190 191 192
        Size getWindowSize() const;
        void setWindowSize(const Size &window_size);
        String getWindowName() const;
        void saveScreenshot (const String &file);
        void setWindowPosition (int x, int y);
        void setFullScreen (bool mode);
        void setBackgroundColor(const Color& color = Color::black());

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

        void registerKeyboardCallback(KeyboardCallback callback, void* cookie = 0);
        void registerMouseCallback(MouseCallback callback, void* cookie = 0);
Ozan Tonkal's avatar
Ozan Tonkal committed
193

Ozan Tonkal's avatar
Ozan Tonkal committed
194 195
        void setRenderingProperty(const String &id, int property, double value);
        double getRenderingProperty(const String &id, int property);
Ozan Tonkal's avatar
Ozan Tonkal committed
196

Ozan Tonkal's avatar
Ozan Tonkal committed
197 198
        void setDesiredUpdateRate(double rate);
        double getDesiredUpdateRate();
Ozan Tonkal's avatar
Ozan Tonkal committed
199

Ozan Tonkal's avatar
Ozan Tonkal committed
200
        void setRepresentation(int representation);
Ozan Tonkal's avatar
Ozan Tonkal committed
201 202 203
    private:
        /* hidden */
    };
Ozan Tonkal's avatar
Ozan Tonkal committed
204

Ozan Tonkal's avatar
Ozan Tonkal committed
205 206
viz::Viz3d::Viz3d
-----------------
Ozan Tonkal's avatar
Ozan Tonkal committed
207 208 209 210
The constructors.

.. ocv:function:: Viz3d::Viz3d(const String& window_name = String())

Ozan Tonkal's avatar
Ozan Tonkal committed
211
    :param window_name: Name of the window.
Ozan Tonkal's avatar
Ozan Tonkal committed
212

Ozan Tonkal's avatar
Ozan Tonkal committed
213 214
viz::Viz3d::showWidget
----------------------
Ozan Tonkal's avatar
Ozan Tonkal committed
215 216 217 218
Shows a widget in the window.

.. ocv:function:: void Viz3d::showWidget(const String &id, const Widget &widget, const Affine3f &pose = Affine3f::Identity())

Ozan Tonkal's avatar
Ozan Tonkal committed
219
    :param id: A unique id for the widget.
Ozan Tonkal's avatar
Ozan Tonkal committed
220
    :param widget: The widget to be displayed in the window.
Ozan Tonkal's avatar
Ozan Tonkal committed
221
    :param pose: Pose of the widget.
Ozan Tonkal's avatar
Ozan Tonkal committed
222

Ozan Tonkal's avatar
Ozan Tonkal committed
223 224
viz::Viz3d::removeWidget
------------------------
Ozan Tonkal's avatar
Ozan Tonkal committed
225 226 227 228
Removes a widget from the window.

.. ocv:function:: void removeWidget(const String &id)

Ozan Tonkal's avatar
Ozan Tonkal committed
229
    :param id: The id of the widget that will be removed.
Ozan Tonkal's avatar
Ozan Tonkal committed
230

Ozan Tonkal's avatar
Ozan Tonkal committed
231 232
viz::Viz3d::getWidget
---------------------
Ozan Tonkal's avatar
Ozan Tonkal committed
233
Retrieves a widget from the window. A widget is implicitly shared;
Ozan Tonkal's avatar
Ozan Tonkal committed
234
that is, if the returned widget is modified, the changes will be
Ozan Tonkal's avatar
Ozan Tonkal committed
235 236 237 238
immediately visible in the window.

.. ocv:function:: Widget getWidget(const String &id) const

Ozan Tonkal's avatar
Ozan Tonkal committed
239
    :param id: The id of the widget that will be returned.
Ozan Tonkal's avatar
Ozan Tonkal committed
240

Ozan Tonkal's avatar
Ozan Tonkal committed
241 242
viz::Viz3d::removeAllWidgets
----------------------------
Ozan Tonkal's avatar
Ozan Tonkal committed
243 244 245 246
Removes all widgets from the window.

.. ocv:function:: void removeAllWidgets()

Ozan Tonkal's avatar
Ozan Tonkal committed
247 248
viz::Viz3d::setWidgetPose
-------------------------
Ozan Tonkal's avatar
Ozan Tonkal committed
249 250 251 252
Sets pose of a widget in the window.

.. ocv:function:: void setWidgetPose(const String &id, const Affine3f &pose)

Ozan Tonkal's avatar
Ozan Tonkal committed
253 254
    :param id: The id of the widget whose pose will be set.
    :param pose: The new pose of the widget.
Ozan Tonkal's avatar
Ozan Tonkal committed
255

Ozan Tonkal's avatar
Ozan Tonkal committed
256 257
viz::Viz3d::updateWidgetPose
----------------------------
Ozan Tonkal's avatar
Ozan Tonkal committed
258 259 260 261
Updates pose of a widget in the window by pre-multiplying its current pose.

.. ocv:function:: void updateWidgetPose(const String &id, const Affine3f &pose)

Ozan Tonkal's avatar
Ozan Tonkal committed
262 263
    :param id: The id of the widget whose pose will be updated.
    :param pose: The pose that the current pose of the widget will be pre-multiplied by.
Ozan Tonkal's avatar
Ozan Tonkal committed
264

Ozan Tonkal's avatar
Ozan Tonkal committed
265 266
viz::Viz3d::getWidgetPose
-------------------------
Ozan Tonkal's avatar
Ozan Tonkal committed
267 268 269 270
Returns the current pose of a widget in the window.

.. ocv:function:: Affine3f getWidgetPose(const String &id) const

Ozan Tonkal's avatar
Ozan Tonkal committed
271
    :param id: The id of the widget whose pose will be returned.
Ozan Tonkal's avatar
Ozan Tonkal committed
272

Ozan Tonkal's avatar
Ozan Tonkal committed
273 274
viz::Viz3d::setCamera
---------------------
Ozan Tonkal's avatar
Ozan Tonkal committed
275 276 277 278
Sets the intrinsic parameters of the viewer using Camera.

.. ocv:function:: void setCamera(const Camera &camera)

Ozan Tonkal's avatar
Ozan Tonkal committed
279
    :param camera: Camera object wrapping intrinsinc parameters.
Ozan Tonkal's avatar
Ozan Tonkal committed
280

Ozan Tonkal's avatar
Ozan Tonkal committed
281 282
viz::Viz3d::getCamera
---------------------
Ozan Tonkal's avatar
Ozan Tonkal committed
283 284 285 286
Returns a camera object that contains intrinsic parameters of the current viewer.

.. ocv:function:: Camera getCamera() const

Ozan Tonkal's avatar
Ozan Tonkal committed
287 288
viz::Viz3d::getViewerPose
-------------------------
Ozan Tonkal's avatar
Ozan Tonkal committed
289 290 291 292
Returns the current pose of the viewer.

..ocv:function:: Affine3f getViewerPose()

Ozan Tonkal's avatar
Ozan Tonkal committed
293 294
viz::Viz3d::setViewerPose
-------------------------
Ozan Tonkal's avatar
Ozan Tonkal committed
295 296 297 298
Sets pose of the viewer.

.. ocv:function:: void setViewerPose(const Affine3f &pose)

Ozan Tonkal's avatar
Ozan Tonkal committed
299
    :param pose: The new pose of the viewer.
Ozan Tonkal's avatar
Ozan Tonkal committed
300

Ozan Tonkal's avatar
Ozan Tonkal committed
301 302
viz::Viz3d::resetCameraViewpoint
--------------------------------
Ozan Tonkal's avatar
Ozan Tonkal committed
303 304 305 306
Resets camera viewpoint to a 3D widget in the scene.

.. ocv:function:: void resetCameraViewpoint (const String &id)

Ozan Tonkal's avatar
Ozan Tonkal committed
307
    :param pose: Id of a 3D widget.
Ozan Tonkal's avatar
Ozan Tonkal committed
308

Ozan Tonkal's avatar
Ozan Tonkal committed
309 310
viz::Viz3d::resetCamera
-----------------------
Ozan Tonkal's avatar
Ozan Tonkal committed
311 312 313 314
Resets camera.

.. ocv:function:: void resetCamera()

Ozan Tonkal's avatar
Ozan Tonkal committed
315 316
viz::Viz3d::convertToWindowCoordinates
--------------------------------------
Ozan Tonkal's avatar
Ozan Tonkal committed
317 318 319 320
Transforms a point in world coordinate system to window coordinate system.

.. ocv:function:: void convertToWindowCoordinates(const Point3d &pt, Point3d &window_coord)

Ozan Tonkal's avatar
Ozan Tonkal committed
321 322
    :param pt: Point in world coordinate system.
    :param window_coord: Output point in window coordinate system.
Ozan Tonkal's avatar
Ozan Tonkal committed
323

Ozan Tonkal's avatar
Ozan Tonkal committed
324 325
viz::Viz3d::converTo3DRay
-------------------------
Ozan Tonkal's avatar
Ozan Tonkal committed
326 327 328 329
Transforms a point in window coordinate system to a 3D ray in world coordinate system.

.. ocv:function:: void converTo3DRay(const Point3d &window_coord, Point3d &origin, Vec3d &direction)

Ozan Tonkal's avatar
Ozan Tonkal committed
330 331 332
    :param window_coord: Point in window coordinate system.
    :param origin: Output origin of the ray.
    :param direction: Output direction of the ray.
Ozan Tonkal's avatar
Ozan Tonkal committed
333

Ozan Tonkal's avatar
Ozan Tonkal committed
334 335
viz::Viz3d::getWindowSize
-------------------------
Ozan Tonkal's avatar
Ozan Tonkal committed
336 337 338 339
Returns the current size of the window.

.. ocv:function:: Size getWindowSize() const

Ozan Tonkal's avatar
Ozan Tonkal committed
340 341
viz::Viz3d::setWindowSize
-------------------------
Ozan Tonkal's avatar
Ozan Tonkal committed
342 343 344 345
Sets the size of the window.

.. ocv:function:: void setWindowSize(const Size &window_size)

Ozan Tonkal's avatar
Ozan Tonkal committed
346
    :param window_size: New size of the window.
Ozan Tonkal's avatar
Ozan Tonkal committed
347

Ozan Tonkal's avatar
Ozan Tonkal committed
348 349
viz::Viz3d::getWindowName
-------------------------
Ozan Tonkal's avatar
Ozan Tonkal committed
350 351 352 353
Returns the name of the window which has been set in the constructor.

.. ocv:function:: String getWindowName() const

Ozan Tonkal's avatar
Ozan Tonkal committed
354 355
viz::Viz3d::saveScreenshot
--------------------------
Ozan Tonkal's avatar
Ozan Tonkal committed
356 357 358 359
Saves screenshot of the current scene.

.. ocv:function:: void saveScreenshot(const String &file)

Ozan Tonkal's avatar
Ozan Tonkal committed
360
    :param file: Name of the file.
Ozan Tonkal's avatar
Ozan Tonkal committed
361

Ozan Tonkal's avatar
Ozan Tonkal committed
362 363
viz::Viz3d::setWindowPosition
-----------------------------
Ozan Tonkal's avatar
Ozan Tonkal committed
364 365 366 367
Sets the position of the window in the screen.

.. ocv:function:: void setWindowPosition(int x, int y)

Ozan Tonkal's avatar
Ozan Tonkal committed
368 369
    :param x: x coordinate of the window
    :param y: y coordinate of the window
Ozan Tonkal's avatar
Ozan Tonkal committed
370

Ozan Tonkal's avatar
Ozan Tonkal committed
371 372
viz::Viz3d::setFullScreen
-------------------------
Ozan Tonkal's avatar
Ozan Tonkal committed
373 374 375 376
Sets or unsets full-screen rendering mode.

.. ocv:function:: void setFullScreen(bool mode)

Ozan Tonkal's avatar
Ozan Tonkal committed
377
    :param mode: If true, window will use full-screen mode.
Ozan Tonkal's avatar
Ozan Tonkal committed
378

Ozan Tonkal's avatar
Ozan Tonkal committed
379 380
viz::Viz3d::setBackgroundColor
------------------------------
Ozan Tonkal's avatar
Ozan Tonkal committed
381 382 383 384
Sets background color.

.. ocv:function:: void setBackgroundColor(const Color& color = Color::black())

Ozan Tonkal's avatar
Ozan Tonkal committed
385 386
viz::Viz3d::spin
----------------
Ozan Tonkal's avatar
Ozan Tonkal committed
387 388 389 390
The window renders and starts the event loop.

.. ocv:function:: void spin()

Ozan Tonkal's avatar
Ozan Tonkal committed
391 392
viz::Viz3d::spinOnce
--------------------
Ozan Tonkal's avatar
Ozan Tonkal committed
393 394 395 396
Starts the event loop for a given time.

.. ocv:function:: void spinOnce(int time = 1, bool force_redraw = false)

Ozan Tonkal's avatar
Ozan Tonkal committed
397 398
    :param time: Amount of time in milliseconds for the event loop to keep running.
    :param force_draw: If true, window renders.
Ozan Tonkal's avatar
Ozan Tonkal committed
399

Ozan Tonkal's avatar
Ozan Tonkal committed
400 401
viz::Viz3d::wasStopped
----------------------
Ozan Tonkal's avatar
Ozan Tonkal committed
402 403 404 405
Returns whether the event loop has been stopped.

.. ocv:function:: bool wasStopped()

Ozan Tonkal's avatar
Ozan Tonkal committed
406 407
viz::Viz3d::registerKeyboardCallback
------------------------------------
Ozan Tonkal's avatar
Ozan Tonkal committed
408 409 410 411
Sets keyboard handler.

.. ocv:function:: void registerKeyboardCallback(KeyboardCallback callback, void* cookie = 0)

Ozan Tonkal's avatar
Ozan Tonkal committed
412
    :param callback: Keyboard callback ``(void (*KeyboardCallbackFunction(const KeyboardEvent&, void*))``.
Ozan Tonkal's avatar
Ozan Tonkal committed
413
    :param cookie: The optional parameter passed to the callback.
Ozan Tonkal's avatar
Ozan Tonkal committed
414

Ozan Tonkal's avatar
Ozan Tonkal committed
415 416
viz::Viz3d::registerMouseCallback
---------------------------------
Ozan Tonkal's avatar
Ozan Tonkal committed
417 418 419 420
Sets mouse handler.

.. ocv:function:: void registerMouseCallback(MouseCallback callback, void* cookie = 0)

Ozan Tonkal's avatar
Ozan Tonkal committed
421
    :param callback: Mouse callback ``(void (*MouseCallback)(const MouseEvent&, void*))``.
Ozan Tonkal's avatar
Ozan Tonkal committed
422
    :param cookie: The optional parameter passed to the callback.
Ozan Tonkal's avatar
Ozan Tonkal committed
423

Ozan Tonkal's avatar
Ozan Tonkal committed
424 425
viz::Viz3d::setRenderingProperty
--------------------------------
Ozan Tonkal's avatar
Ozan Tonkal committed
426 427 428 429
Sets rendering property of a widget.

.. ocv:function:: void setRenderingProperty(const String &id, int property, double value)

Ozan Tonkal's avatar
Ozan Tonkal committed
430 431 432
    :param id: Id of the widget.
    :param property: Property that will be modified.
    :param value: The new value of the property.
Ozan Tonkal's avatar
Ozan Tonkal committed
433

Ozan Tonkal's avatar
Ozan Tonkal committed
434
    **Rendering property** can be one of the following:
Ozan Tonkal's avatar
Ozan Tonkal committed
435

Ozan Tonkal's avatar
Ozan Tonkal committed
436 437 438 439 440 441 442 443
    * **POINT_SIZE**
    * **OPACITY**
    * **LINE_WIDTH**
    * **FONT_SIZE**
    * **REPRESENTATION**: Expected values are
        * **REPRESENTATION_POINTS**
        * **REPRESENTATION_WIREFRAME**
        * **REPRESENTATION_SURFACE**
Ozan Tonkal's avatar
Ozan Tonkal committed
444
    * **IMMEDIATE_RENDERING**:
Ozan Tonkal's avatar
Ozan Tonkal committed
445 446 447 448 449 450
        * 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**
Ozan Tonkal's avatar
Ozan Tonkal committed
451

Ozan Tonkal's avatar
Ozan Tonkal committed
452 453
viz::Viz3d::getRenderingProperty
--------------------------------
Ozan Tonkal's avatar
Ozan Tonkal committed
454 455 456 457
Returns rendering property of a widget.

.. ocv:function:: double getRenderingProperty(const String &id, int property)

Ozan Tonkal's avatar
Ozan Tonkal committed
458 459
    :param id: Id of the widget.
    :param property: Property.
Ozan Tonkal's avatar
Ozan Tonkal committed
460

Ozan Tonkal's avatar
Ozan Tonkal committed
461
    **Rendering property** can be one of the following:
Ozan Tonkal's avatar
Ozan Tonkal committed
462

Ozan Tonkal's avatar
Ozan Tonkal committed
463 464 465 466 467 468 469 470
    * **POINT_SIZE**
    * **OPACITY**
    * **LINE_WIDTH**
    * **FONT_SIZE**
    * **REPRESENTATION**: Expected values are
        * **REPRESENTATION_POINTS**
        * **REPRESENTATION_WIREFRAME**
        * **REPRESENTATION_SURFACE**
Ozan Tonkal's avatar
Ozan Tonkal committed
471
    * **IMMEDIATE_RENDERING**:
Ozan Tonkal's avatar
Ozan Tonkal committed
472 473 474 475 476 477 478 479 480
        * 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**

viz::Viz3d::setDesiredUpdateRate
--------------------------------
Ozan Tonkal's avatar
Ozan Tonkal committed
481 482 483 484
Sets desired update rate of the window.

.. ocv:function:: void setDesiredUpdateRate(double rate)

Ozan Tonkal's avatar
Ozan Tonkal committed
485
    :param rate: Desired update rate. The default is 30.
Ozan Tonkal's avatar
Ozan Tonkal committed
486

Ozan Tonkal's avatar
Ozan Tonkal committed
487 488
viz::Viz3d::getDesiredUpdateRate
--------------------------------
Ozan Tonkal's avatar
Ozan Tonkal committed
489 490 491 492
Returns desired update rate of the window.

.. ocv:function:: double getDesiredUpdateRate()

Ozan Tonkal's avatar
Ozan Tonkal committed
493 494 495
viz::Viz3d::setRepresentation
-----------------------------
Sets geometry representation of the widgets to surface, wireframe or points.
Ozan Tonkal's avatar
Ozan Tonkal committed
496

Ozan Tonkal's avatar
Ozan Tonkal committed
497
.. ocv:function:: void setRepresentation(int representation)
Ozan Tonkal's avatar
Ozan Tonkal committed
498

Ozan Tonkal's avatar
Ozan Tonkal committed
499
    :param representation: Geometry representation which can be one of the following:
Ozan Tonkal's avatar
Ozan Tonkal committed
500

Ozan Tonkal's avatar
Ozan Tonkal committed
501 502 503
        * **REPRESENTATION_POINTS**
        * **REPRESENTATION_WIREFRAME**
        * **REPRESENTATION_SURFACE**
Ozan Tonkal's avatar
Ozan Tonkal committed
504

Ozan Tonkal's avatar
Ozan Tonkal committed
505 506
viz::Color
----------
Ozan Tonkal's avatar
Ozan Tonkal committed
507 508 509 510
.. ocv:class:: Color

This class a represents BGR color. ::

Ozan Tonkal's avatar
Ozan Tonkal committed
511 512 513 514 515 516
    class CV_EXPORTS Color : public Scalar
    {
    public:
        Color();
        Color(double gray);
        Color(double blue, double green, double red);
Ozan Tonkal's avatar
Ozan Tonkal committed
517

Ozan Tonkal's avatar
Ozan Tonkal committed
518
        Color(const Scalar& color);
Ozan Tonkal's avatar
Ozan Tonkal committed
519

Ozan Tonkal's avatar
Ozan Tonkal committed
520 521 522 523
        static Color black();
        static Color blue();
        static Color green();
        static Color cyan();
Ozan Tonkal's avatar
Ozan Tonkal committed
524

Ozan Tonkal's avatar
Ozan Tonkal committed
525 526 527 528
        static Color red();
        static Color magenta();
        static Color yellow();
        static Color white();
Ozan Tonkal's avatar
Ozan Tonkal committed
529

Ozan Tonkal's avatar
Ozan Tonkal committed
530 531
        static Color gray();
    };
Ozan Tonkal's avatar
Ozan Tonkal committed
532

Ozan Tonkal's avatar
Ozan Tonkal committed
533 534
viz::Mesh3d
-----------
Ozan Tonkal's avatar
Ozan Tonkal committed
535 536 537 538
.. ocv:class:: Mesh3d

This class wraps mesh attributes, and it can load a mesh from a ``ply`` file. ::

Ozan Tonkal's avatar
Ozan Tonkal committed
539 540 541
    class CV_EXPORTS Mesh3d
    {
    public:
Ozan Tonkal's avatar
Ozan Tonkal committed
542

Ozan Tonkal's avatar
Ozan Tonkal committed
543 544
        Mat cloud, colors;
        Mat polygons;
Ozan Tonkal's avatar
Ozan Tonkal committed
545

Ozan Tonkal's avatar
Ozan Tonkal committed
546 547
        //! Loads mesh from a given ply file
        static Mesh3d loadMesh(const String& file);
Ozan Tonkal's avatar
Ozan Tonkal committed
548

Ozan Tonkal's avatar
Ozan Tonkal committed
549 550 551
    private:
        /* hidden */
    };
Ozan Tonkal's avatar
Ozan Tonkal committed
552

Ozan Tonkal's avatar
Ozan Tonkal committed
553 554
viz::Mesh3d::loadMesh
---------------------
Ozan Tonkal's avatar
Ozan Tonkal committed
555 556 557 558
Loads a mesh from a ``ply`` file.

.. ocv:function:: static Mesh3d loadMesh(const String& file)

Ozan Tonkal's avatar
Ozan Tonkal committed
559
    :param file: File name.
Ozan Tonkal's avatar
Ozan Tonkal committed
560 561


Ozan Tonkal's avatar
Ozan Tonkal committed
562 563
viz::KeyboardEvent
------------------
Ozan Tonkal's avatar
Ozan Tonkal committed
564 565 566 567
.. ocv:class:: KeyboardEvent

This class represents a keyboard event. ::

Ozan Tonkal's avatar
Ozan Tonkal committed
568 569 570 571 572 573
    class CV_EXPORTS KeyboardEvent
    {
    public:
        static const unsigned int Alt   = 1;
        static const unsigned int Ctrl  = 2;
        static const unsigned int Shift = 4;
Ozan Tonkal's avatar
Ozan Tonkal committed
574

Ozan Tonkal's avatar
Ozan Tonkal committed
575 576 577
        //! Create a keyboard event
        //! - Note that action is true if key is pressed, false if released
        KeyboardEvent (bool action, const std::string& key_sym, unsigned char key, bool alt, bool ctrl, bool shift);
Ozan Tonkal's avatar
Ozan Tonkal committed
578

Ozan Tonkal's avatar
Ozan Tonkal committed
579 580 581
        bool isAltPressed () const;
        bool isCtrlPressed () const;
        bool isShiftPressed () const;
Ozan Tonkal's avatar
Ozan Tonkal committed
582

Ozan Tonkal's avatar
Ozan Tonkal committed
583
        unsigned char getKeyCode () const;
Ozan Tonkal's avatar
Ozan Tonkal committed
584

Ozan Tonkal's avatar
Ozan Tonkal committed
585 586 587
        const String& getKeySym () const;
        bool keyDown () const;
        bool keyUp () const;
Ozan Tonkal's avatar
Ozan Tonkal committed
588

Ozan Tonkal's avatar
Ozan Tonkal committed
589 590 591
    protected:
        /* hidden */
    };
Ozan Tonkal's avatar
Ozan Tonkal committed
592

Ozan Tonkal's avatar
Ozan Tonkal committed
593 594
viz::KeyboardEvent::KeyboardEvent
---------------------------------
Ozan Tonkal's avatar
Ozan Tonkal committed
595 596 597 598
Constructs a KeyboardEvent.

.. ocv:function:: KeyboardEvent (bool action, const std::string& key_sym, unsigned char key, bool alt, bool ctrl, bool shift)

Ozan Tonkal's avatar
Ozan Tonkal committed
599 600 601 602 603 604
    :param action: If true, key is pressed. If false, key is released.
    :param key_sym: Name of the key.
    :param key: Code of the key.
    :param alt: If true, ``alt`` is pressed.
    :param ctrl: If true, ``ctrl`` is pressed.
    :param shift: If true, ``shift`` is pressed.
Ozan Tonkal's avatar
Ozan Tonkal committed
605

Ozan Tonkal's avatar
Ozan Tonkal committed
606 607
viz::MouseEvent
---------------
Ozan Tonkal's avatar
Ozan Tonkal committed
608 609 610 611
.. ocv:class:: MouseEvent

This class represents a mouse event. ::

Ozan Tonkal's avatar
Ozan Tonkal committed
612 613 614 615 616
    class CV_EXPORTS MouseEvent
    {
    public:
        enum Type { MouseMove = 1, MouseButtonPress, MouseButtonRelease, MouseScrollDown, MouseScrollUp, MouseDblClick } ;
        enum MouseButton { NoButton = 0, LeftButton, MiddleButton, RightButton, VScroll } ;
Ozan Tonkal's avatar
Ozan Tonkal committed
617

Ozan Tonkal's avatar
Ozan Tonkal committed
618
        MouseEvent (const Type& type, const MouseButton& button, const Point& p, bool alt, bool ctrl, bool shift);
Ozan Tonkal's avatar
Ozan Tonkal committed
619

Ozan Tonkal's avatar
Ozan Tonkal committed
620 621 622 623 624
        Type type;
        MouseButton button;
        Point pointer;
        unsigned int key_state;
    };
Ozan Tonkal's avatar
Ozan Tonkal committed
625

Ozan Tonkal's avatar
Ozan Tonkal committed
626 627
viz::MouseEvent::MouseEvent
---------------------------
Ozan Tonkal's avatar
Ozan Tonkal committed
628 629 630 631
Constructs a MouseEvent.

.. ocv:function:: MouseEvent (const Type& type, const MouseButton& button, const Point& p, bool alt, bool ctrl, bool shift)

Ozan Tonkal's avatar
Ozan Tonkal committed
632 633 634 635 636 637
    :param type: Type of the event. This can be **MouseMove**, **MouseButtonPress**, **MouseButtonRelease**, **MouseScrollDown**, **MouseScrollUp**, **MouseDblClick**.
    :param button: Mouse button. This can be **NoButton**, **LeftButton**, **MiddleButton**, **RightButton**, **VScroll**.
    :param p: Position of the event.
    :param alt: If true, ``alt`` is pressed.
    :param ctrl: If true, ``ctrl`` is pressed.
    :param shift: If true, ``shift`` is pressed.
Ozan Tonkal's avatar
Ozan Tonkal committed
638

Ozan Tonkal's avatar
Ozan Tonkal committed
639 640
viz::Camera
-----------
Ozan Tonkal's avatar
Ozan Tonkal committed
641 642 643 644 645 646
.. ocv:class:: Camera

This class wraps intrinsic parameters of a camera. It provides several constructors
that can extract the intrinsic parameters from ``field of view``, ``intrinsic matrix`` and
``projection matrix``. ::

Ozan Tonkal's avatar
Ozan Tonkal committed
647 648 649 650 651 652 653
    class CV_EXPORTS Camera
    {
    public:
        Camera(float f_x, float f_y, float c_x, float c_y, const Size &window_size);
        Camera(const Vec2f &fov, const Size &window_size);
        Camera(const cv::Matx33f &K, const Size &window_size);
        Camera(const cv::Matx44f &proj, const Size &window_size);
Ozan Tonkal's avatar
Ozan Tonkal committed
654

Ozan Tonkal's avatar
Ozan Tonkal committed
655 656
        inline const Vec2d & getClip() const { return clip_; }
        inline void setClip(const Vec2d &clip) { clip_ = clip; }
Ozan Tonkal's avatar
Ozan Tonkal committed
657

Ozan Tonkal's avatar
Ozan Tonkal committed
658 659
        inline const Size & getWindowSize() const { return window_size_; }
        void setWindowSize(const Size &window_size);
Ozan Tonkal's avatar
Ozan Tonkal committed
660

Ozan Tonkal's avatar
Ozan Tonkal committed
661 662
        inline const Vec2f & getFov() const { return fov_; }
        inline void setFov(const Vec2f & fov) { fov_ = fov; }
Ozan Tonkal's avatar
Ozan Tonkal committed
663

Ozan Tonkal's avatar
Ozan Tonkal committed
664 665
        inline const Vec2f & getPrincipalPoint() const { return principal_point_; }
        inline const Vec2f & getFocalLength() const { return focal_; }
Ozan Tonkal's avatar
Ozan Tonkal committed
666

Ozan Tonkal's avatar
Ozan Tonkal committed
667
        void computeProjectionMatrix(Matx44f &proj) const;
Ozan Tonkal's avatar
Ozan Tonkal committed
668

Ozan Tonkal's avatar
Ozan Tonkal committed
669
        static Camera KinectCamera(const Size &window_size);
Ozan Tonkal's avatar
Ozan Tonkal committed
670

Ozan Tonkal's avatar
Ozan Tonkal committed
671 672 673
    private:
        /* hidden */
    };
Ozan Tonkal's avatar
Ozan Tonkal committed
674

Ozan Tonkal's avatar
Ozan Tonkal committed
675 676
viz::Camera::Camera
-------------------
Ozan Tonkal's avatar
Ozan Tonkal committed
677 678 679 680
Constructs a Camera.

.. ocv:function:: Camera(float f_x, float f_y, float c_x, float c_y, const Size &window_size)

Ozan Tonkal's avatar
Ozan Tonkal committed
681 682 683 684 685
    :param f_x: Horizontal focal length.
    :param f_y: Vertical focal length.
    :param c_x: x coordinate of the principal point.
    :param c_y: y coordinate of the principal point.
    :param window_size: Size of the window. This together with focal length and principal point determines the field of view.
Ozan Tonkal's avatar
Ozan Tonkal committed
686 687 688

.. ocv:function:: Camera(const Vec2f &fov, const Size &window_size)

Ozan Tonkal's avatar
Ozan Tonkal committed
689 690
    :param fov: Field of view (horizontal, vertical)
    :param window_size: Size of the window.
Ozan Tonkal's avatar
Ozan Tonkal committed
691

Ozan Tonkal's avatar
Ozan Tonkal committed
692
    Principal point is at the center of the window by default.
Ozan Tonkal's avatar
Ozan Tonkal committed
693

Ozan Tonkal's avatar
Ozan Tonkal committed
694 695
.. ocv:function:: Camera(const cv::Matx33f &K, const Size &window_size)

Ozan Tonkal's avatar
Ozan Tonkal committed
696 697
    :param K: Intrinsic matrix of the camera.
    :param window_size: Size of the window. This together with intrinsic matrix determines the field of view.
Ozan Tonkal's avatar
Ozan Tonkal committed
698 699 700

.. ocv:function:: Camera(const cv::Matx44f &proj, const Size &window_size)

Ozan Tonkal's avatar
Ozan Tonkal committed
701 702
    :param proj: Projection matrix of the camera.
    :param window_size: Size of the window. This together with projection matrix determines the field of view.
Ozan Tonkal's avatar
Ozan Tonkal committed
703

Ozan Tonkal's avatar
Ozan Tonkal committed
704 705
viz::Camera::computeProjectionMatrix
------------------------------------
Ozan Tonkal's avatar
Ozan Tonkal committed
706 707 708 709
Computes projection matrix using intrinsic parameters of the camera.

.. ocv:function:: void computeProjectionMatrix(Matx44f &proj) const

Ozan Tonkal's avatar
Ozan Tonkal committed
710
    :param proj: Output projection matrix.
Ozan Tonkal's avatar
Ozan Tonkal committed
711

Ozan Tonkal's avatar
Ozan Tonkal committed
712 713
viz::Camera::KinectCamera
-------------------------
Ozan Tonkal's avatar
Ozan Tonkal committed
714 715 716 717
Creates a Kinect Camera.

.. ocv:function:: static Camera KinectCamera(const Size &window_size)

Ozan Tonkal's avatar
Ozan Tonkal committed
718
    :param window_size: Size of the window. This together with intrinsic matrix of a Kinect Camera determines the field of view.