viz3d.rst 19.8 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

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.

16
.. ocv:function:: Affine3d viz::makeTransformToGlobal(const Vec3f& axis_x, const Vec3f& axis_y, const Vec3f& axis_z, const Vec3f& origin = Vec3f::all(0))
Ozan Tonkal's avatar
Ozan Tonkal committed
17 18 19 20 21 22 23

    :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

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

    :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
This function returns pose of the camera in global coordinate frame.

37
viz::getWindowByName
38
--------------------
Ozan Tonkal's avatar
Ozan Tonkal committed
39 40
Retrieves a window by its name.

41
.. ocv:function:: Viz3d getWindowByName(const String &window_name)
Ozan Tonkal's avatar
Ozan Tonkal committed
42 43

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

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
viz::Viz3d
----------
Ozan Tonkal's avatar
Ozan Tonkal committed
81 82
.. ocv:class:: Viz3d

Ozan Tonkal's avatar
Ozan Tonkal committed
83 84 85 86 87 88 89 90 91 92 93 94 95 96
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();

97
        void showWidget(const String &id, const Widget &widget, const Affine3d &pose = Affine3d::Identity());
Ozan Tonkal's avatar
Ozan Tonkal committed
98 99 100 101
        void removeWidget(const String &id);
        Widget getWidget(const String &id) const;
        void removeAllWidgets();

102 103 104
        void setWidgetPose(const String &id, const Affine3d &pose);
        void updateWidgetPose(const String &id, const Affine3d &pose);
        Affine3d getWidgetPose(const String &id) const;
Anatoly Baksheev's avatar
Anatoly Baksheev committed
105

Anatoly Baksheev's avatar
Anatoly Baksheev committed
106
        void showImage(InputArray image, const Size& window_size = Size(-1, -1));
Ozan Tonkal's avatar
Ozan Tonkal committed
107

Ozan Tonkal's avatar
Ozan Tonkal committed
108 109
        void setCamera(const Camera &camera);
        Camera getCamera() const;
110 111
        Affine3d getViewerPose();
        void setViewerPose(const Affine3d &pose);
Ozan Tonkal's avatar
Ozan Tonkal committed
112

Ozan Tonkal's avatar
Ozan Tonkal committed
113 114
        void resetCameraViewpoint (const String &id);
        void resetCamera();
Ozan Tonkal's avatar
Ozan Tonkal committed
115

Ozan Tonkal's avatar
Ozan Tonkal committed
116 117
        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
118

Ozan Tonkal's avatar
Ozan Tonkal committed
119 120 121 122 123 124 125 126 127 128 129 130 131 132
        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
133

Ozan Tonkal's avatar
Ozan Tonkal committed
134 135
        void setRenderingProperty(const String &id, int property, double value);
        double getRenderingProperty(const String &id, int property);
Ozan Tonkal's avatar
Ozan Tonkal committed
136 137


Ozan Tonkal's avatar
Ozan Tonkal committed
138
        void setRepresentation(int representation);
Ozan Tonkal's avatar
Ozan Tonkal committed
139 140 141
    private:
        /* hidden */
    };
Ozan Tonkal's avatar
Ozan Tonkal committed
142

Ozan Tonkal's avatar
Ozan Tonkal committed
143 144
viz::Viz3d::Viz3d
-----------------
Ozan Tonkal's avatar
Ozan Tonkal committed
145 146 147 148
The constructors.

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

Ozan Tonkal's avatar
Ozan Tonkal committed
149
    :param window_name: Name of the window.
Ozan Tonkal's avatar
Ozan Tonkal committed
150

Ozan Tonkal's avatar
Ozan Tonkal committed
151 152
viz::Viz3d::showWidget
----------------------
Ozan Tonkal's avatar
Ozan Tonkal committed
153 154
Shows a widget in the window.

155
.. ocv:function:: void Viz3d::showWidget(const String &id, const Widget &widget, const Affine3d &pose = Affine3d::Identity())
Ozan Tonkal's avatar
Ozan Tonkal committed
156

Ozan Tonkal's avatar
Ozan Tonkal committed
157
    :param id: A unique id for the widget.
Ozan Tonkal's avatar
Ozan Tonkal committed
158
    :param widget: The widget to be displayed in the window.
Ozan Tonkal's avatar
Ozan Tonkal committed
159
    :param pose: Pose of the widget.
Ozan Tonkal's avatar
Ozan Tonkal committed
160

Ozan Tonkal's avatar
Ozan Tonkal committed
161 162
viz::Viz3d::removeWidget
------------------------
Ozan Tonkal's avatar
Ozan Tonkal committed
163 164 165 166
Removes a widget from the window.

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

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

Ozan Tonkal's avatar
Ozan Tonkal committed
169 170
viz::Viz3d::getWidget
---------------------
Ozan Tonkal's avatar
Ozan Tonkal committed
171
Retrieves a widget from the window. A widget is implicitly shared;
Ozan Tonkal's avatar
Ozan Tonkal committed
172
that is, if the returned widget is modified, the changes will be
Ozan Tonkal's avatar
Ozan Tonkal committed
173 174 175 176
immediately visible in the window.

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

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

Ozan Tonkal's avatar
Ozan Tonkal committed
179 180
viz::Viz3d::removeAllWidgets
----------------------------
Ozan Tonkal's avatar
Ozan Tonkal committed
181 182 183 184
Removes all widgets from the window.

.. ocv:function:: void removeAllWidgets()

Anatoly Baksheev's avatar
Anatoly Baksheev committed
185 186 187 188
viz::Viz3d::showImage
---------------------
Removed all widgets and displays image scaled to whole window area.

189
.. ocv:function:: void showImage(InputArray image, const Size& window_size = Size(-1, -1))
Anatoly Baksheev's avatar
Anatoly Baksheev committed
190 191 192 193

    :param image: Image to be displayed.
    :param size: Size of Viz3d window. Default value means no change.

Ozan Tonkal's avatar
Ozan Tonkal committed
194 195
viz::Viz3d::setWidgetPose
-------------------------
Ozan Tonkal's avatar
Ozan Tonkal committed
196 197
Sets pose of a widget in the window.

198
.. ocv:function:: void setWidgetPose(const String &id, const Affine3d &pose)
Ozan Tonkal's avatar
Ozan Tonkal committed
199

Ozan Tonkal's avatar
Ozan Tonkal committed
200 201
    :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
202

Ozan Tonkal's avatar
Ozan Tonkal committed
203 204
viz::Viz3d::updateWidgetPose
----------------------------
Ozan Tonkal's avatar
Ozan Tonkal committed
205 206
Updates pose of a widget in the window by pre-multiplying its current pose.

207
.. ocv:function:: void updateWidgetPose(const String &id, const Affine3d &pose)
Ozan Tonkal's avatar
Ozan Tonkal committed
208

Ozan Tonkal's avatar
Ozan Tonkal committed
209 210
    :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
211

Ozan Tonkal's avatar
Ozan Tonkal committed
212 213
viz::Viz3d::getWidgetPose
-------------------------
Ozan Tonkal's avatar
Ozan Tonkal committed
214 215
Returns the current pose of a widget in the window.

216
.. ocv:function:: Affine3d getWidgetPose(const String &id) const
Ozan Tonkal's avatar
Ozan Tonkal committed
217

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

Ozan Tonkal's avatar
Ozan Tonkal committed
220 221
viz::Viz3d::setCamera
---------------------
Ozan Tonkal's avatar
Ozan Tonkal committed
222 223 224 225
Sets the intrinsic parameters of the viewer using Camera.

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

Ozan Tonkal's avatar
Ozan Tonkal committed
226
    :param camera: Camera object wrapping intrinsinc parameters.
Ozan Tonkal's avatar
Ozan Tonkal committed
227

Ozan Tonkal's avatar
Ozan Tonkal committed
228 229
viz::Viz3d::getCamera
---------------------
Ozan Tonkal's avatar
Ozan Tonkal committed
230 231 232 233
Returns a camera object that contains intrinsic parameters of the current viewer.

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

Ozan Tonkal's avatar
Ozan Tonkal committed
234 235
viz::Viz3d::getViewerPose
-------------------------
Ozan Tonkal's avatar
Ozan Tonkal committed
236 237
Returns the current pose of the viewer.

238
..ocv:function:: Affine3d getViewerPose()
Ozan Tonkal's avatar
Ozan Tonkal committed
239

Ozan Tonkal's avatar
Ozan Tonkal committed
240 241
viz::Viz3d::setViewerPose
-------------------------
Ozan Tonkal's avatar
Ozan Tonkal committed
242 243
Sets pose of the viewer.

244
.. ocv:function:: void setViewerPose(const Affine3d &pose)
Ozan Tonkal's avatar
Ozan Tonkal committed
245

Ozan Tonkal's avatar
Ozan Tonkal committed
246
    :param pose: The new pose of the viewer.
Ozan Tonkal's avatar
Ozan Tonkal committed
247

Ozan Tonkal's avatar
Ozan Tonkal committed
248 249
viz::Viz3d::resetCameraViewpoint
--------------------------------
Ozan Tonkal's avatar
Ozan Tonkal committed
250 251 252 253
Resets camera viewpoint to a 3D widget in the scene.

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

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

Ozan Tonkal's avatar
Ozan Tonkal committed
256 257
viz::Viz3d::resetCamera
-----------------------
Ozan Tonkal's avatar
Ozan Tonkal committed
258 259 260 261
Resets camera.

.. ocv:function:: void resetCamera()

Ozan Tonkal's avatar
Ozan Tonkal committed
262 263
viz::Viz3d::convertToWindowCoordinates
--------------------------------------
Ozan Tonkal's avatar
Ozan Tonkal committed
264 265 266 267
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
268 269
    :param pt: Point in world coordinate system.
    :param window_coord: Output point in window coordinate system.
Ozan Tonkal's avatar
Ozan Tonkal committed
270

Ozan Tonkal's avatar
Ozan Tonkal committed
271 272
viz::Viz3d::converTo3DRay
-------------------------
Ozan Tonkal's avatar
Ozan Tonkal committed
273 274 275 276
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
277 278 279
    :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
280

Ozan Tonkal's avatar
Ozan Tonkal committed
281 282
viz::Viz3d::getWindowSize
-------------------------
Ozan Tonkal's avatar
Ozan Tonkal committed
283 284 285 286
Returns the current size of the window.

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

Ozan Tonkal's avatar
Ozan Tonkal committed
287 288
viz::Viz3d::setWindowSize
-------------------------
Ozan Tonkal's avatar
Ozan Tonkal committed
289 290 291 292
Sets the size of the window.

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

Ozan Tonkal's avatar
Ozan Tonkal committed
293
    :param window_size: New size of the window.
Ozan Tonkal's avatar
Ozan Tonkal committed
294

Ozan Tonkal's avatar
Ozan Tonkal committed
295 296
viz::Viz3d::getWindowName
-------------------------
Ozan Tonkal's avatar
Ozan Tonkal committed
297 298 299 300
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
301 302
viz::Viz3d::saveScreenshot
--------------------------
Ozan Tonkal's avatar
Ozan Tonkal committed
303 304 305 306
Saves screenshot of the current scene.

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

Ozan Tonkal's avatar
Ozan Tonkal committed
307
    :param file: Name of the file.
Ozan Tonkal's avatar
Ozan Tonkal committed
308

Ozan Tonkal's avatar
Ozan Tonkal committed
309 310
viz::Viz3d::setWindowPosition
-----------------------------
Ozan Tonkal's avatar
Ozan Tonkal committed
311 312 313 314
Sets the position of the window in the screen.

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

Ozan Tonkal's avatar
Ozan Tonkal committed
315 316
    :param x: x coordinate of the window
    :param y: y coordinate of the window
Ozan Tonkal's avatar
Ozan Tonkal committed
317

Ozan Tonkal's avatar
Ozan Tonkal committed
318 319
viz::Viz3d::setFullScreen
-------------------------
Ozan Tonkal's avatar
Ozan Tonkal committed
320 321 322 323
Sets or unsets full-screen rendering mode.

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

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

Ozan Tonkal's avatar
Ozan Tonkal committed
326 327
viz::Viz3d::setBackgroundColor
------------------------------
Ozan Tonkal's avatar
Ozan Tonkal committed
328 329 330 331
Sets background color.

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

Ozan Tonkal's avatar
Ozan Tonkal committed
332 333
viz::Viz3d::spin
----------------
Ozan Tonkal's avatar
Ozan Tonkal committed
334 335 336 337
The window renders and starts the event loop.

.. ocv:function:: void spin()

Ozan Tonkal's avatar
Ozan Tonkal committed
338 339
viz::Viz3d::spinOnce
--------------------
Ozan Tonkal's avatar
Ozan Tonkal committed
340 341 342 343
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
344 345
    :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
346

Ozan Tonkal's avatar
Ozan Tonkal committed
347 348
viz::Viz3d::wasStopped
----------------------
Ozan Tonkal's avatar
Ozan Tonkal committed
349 350 351 352
Returns whether the event loop has been stopped.

.. ocv:function:: bool wasStopped()

Ozan Tonkal's avatar
Ozan Tonkal committed
353 354
viz::Viz3d::registerKeyboardCallback
------------------------------------
Ozan Tonkal's avatar
Ozan Tonkal committed
355 356 357 358
Sets keyboard handler.

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

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

Ozan Tonkal's avatar
Ozan Tonkal committed
362 363
viz::Viz3d::registerMouseCallback
---------------------------------
Ozan Tonkal's avatar
Ozan Tonkal committed
364 365 366 367
Sets mouse handler.

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

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

Ozan Tonkal's avatar
Ozan Tonkal committed
371 372
viz::Viz3d::setRenderingProperty
--------------------------------
Ozan Tonkal's avatar
Ozan Tonkal committed
373 374 375 376
Sets rendering property of a widget.

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

Ozan Tonkal's avatar
Ozan Tonkal committed
377 378 379
    :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
380

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

Ozan Tonkal's avatar
Ozan Tonkal committed
383 384 385 386 387 388 389 390
    * **POINT_SIZE**
    * **OPACITY**
    * **LINE_WIDTH**
    * **FONT_SIZE**
    * **REPRESENTATION**: Expected values are
        * **REPRESENTATION_POINTS**
        * **REPRESENTATION_WIREFRAME**
        * **REPRESENTATION_SURFACE**
Ozan Tonkal's avatar
Ozan Tonkal committed
391
    * **IMMEDIATE_RENDERING**:
Ozan Tonkal's avatar
Ozan Tonkal committed
392 393 394 395 396 397
        * 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
398

Ozan Tonkal's avatar
Ozan Tonkal committed
399 400
viz::Viz3d::getRenderingProperty
--------------------------------
Ozan Tonkal's avatar
Ozan Tonkal committed
401 402 403 404
Returns rendering property of a widget.

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

Ozan Tonkal's avatar
Ozan Tonkal committed
405 406
    :param id: Id of the widget.
    :param property: Property.
Ozan Tonkal's avatar
Ozan Tonkal committed
407

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

Ozan Tonkal's avatar
Ozan Tonkal committed
410 411 412 413 414 415 416 417
    * **POINT_SIZE**
    * **OPACITY**
    * **LINE_WIDTH**
    * **FONT_SIZE**
    * **REPRESENTATION**: Expected values are
        * **REPRESENTATION_POINTS**
        * **REPRESENTATION_WIREFRAME**
        * **REPRESENTATION_SURFACE**
Ozan Tonkal's avatar
Ozan Tonkal committed
418
    * **IMMEDIATE_RENDERING**:
Ozan Tonkal's avatar
Ozan Tonkal committed
419 420 421 422 423 424 425 426 427 428
        * 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::setRepresentation
-----------------------------
Sets geometry representation of the widgets to surface, wireframe or points.
Ozan Tonkal's avatar
Ozan Tonkal committed
429

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

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

Ozan Tonkal's avatar
Ozan Tonkal committed
434 435 436
        * **REPRESENTATION_POINTS**
        * **REPRESENTATION_WIREFRAME**
        * **REPRESENTATION_SURFACE**
Ozan Tonkal's avatar
Ozan Tonkal committed
437

Ozan Tonkal's avatar
Ozan Tonkal committed
438 439
viz::Color
----------
Ozan Tonkal's avatar
Ozan Tonkal committed
440 441 442 443
.. ocv:class:: Color

This class a represents BGR color. ::

Ozan Tonkal's avatar
Ozan Tonkal committed
444 445 446 447 448 449
    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
450

Ozan Tonkal's avatar
Ozan Tonkal committed
451
        Color(const Scalar& color);
Ozan Tonkal's avatar
Ozan Tonkal committed
452

Ozan Tonkal's avatar
Ozan Tonkal committed
453 454 455 456
        static Color black();
        static Color blue();
        static Color green();
        static Color cyan();
Ozan Tonkal's avatar
Ozan Tonkal committed
457

Ozan Tonkal's avatar
Ozan Tonkal committed
458 459 460 461
        static Color red();
        static Color magenta();
        static Color yellow();
        static Color white();
Ozan Tonkal's avatar
Ozan Tonkal committed
462

Ozan Tonkal's avatar
Ozan Tonkal committed
463 464
        static Color gray();
    };
Ozan Tonkal's avatar
Ozan Tonkal committed
465

466
viz::Mesh
Ozan Tonkal's avatar
Ozan Tonkal committed
467
-----------
468
.. ocv:class:: Mesh
Ozan Tonkal's avatar
Ozan Tonkal committed
469 470 471

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

472
    class CV_EXPORTS Mesh
Ozan Tonkal's avatar
Ozan Tonkal committed
473 474
    {
    public:
Ozan Tonkal's avatar
Ozan Tonkal committed
475

476
        Mat cloud, colors, normals;
Anatoly Baksheev's avatar
Anatoly Baksheev committed
477

478 479
        //! Raw integer list of the form: (n,id1,id2,...,idn, n,id1,id2,...,idn, ...)
        //! where n is the number of points in the poligon, and id is a zero-offset index into an associated cloud.
Ozan Tonkal's avatar
Ozan Tonkal committed
480
        Mat polygons;
Ozan Tonkal's avatar
Ozan Tonkal committed
481

Ozan Tonkal's avatar
Ozan Tonkal committed
482
        //! Loads mesh from a given ply file
483
        static Mesh load(const String& file);
Ozan Tonkal's avatar
Ozan Tonkal committed
484
    };
Ozan Tonkal's avatar
Ozan Tonkal committed
485

486
viz::Mesh::load
Ozan Tonkal's avatar
Ozan Tonkal committed
487
---------------------
Ozan Tonkal's avatar
Ozan Tonkal committed
488 489
Loads a mesh from a ``ply`` file.

490
.. ocv:function:: static Mesh load(const String& file)
Ozan Tonkal's avatar
Ozan Tonkal committed
491

492
    :param file: File name (for no only PLY is supported)
Ozan Tonkal's avatar
Ozan Tonkal committed
493 494


Ozan Tonkal's avatar
Ozan Tonkal committed
495 496
viz::KeyboardEvent
------------------
Ozan Tonkal's avatar
Ozan Tonkal committed
497 498 499 500
.. ocv:class:: KeyboardEvent

This class represents a keyboard event. ::

Ozan Tonkal's avatar
Ozan Tonkal committed
501 502 503
    class CV_EXPORTS KeyboardEvent
    {
    public:
504 505
        enum { ALT = 1, CTRL = 2, SHIFT = 4 };
        enum Action { KEY_UP = 0, KEY_DOWN = 1 };
Ozan Tonkal's avatar
Ozan Tonkal committed
506

507
        KeyboardEvent(Action action, const String& symbol, unsigned char code, int modifiers);
Ozan Tonkal's avatar
Ozan Tonkal committed
508

509 510 511 512
        Action action;
        String symbol;
        unsigned char code;
        int modifiers;
Ozan Tonkal's avatar
Ozan Tonkal committed
513
    };
Ozan Tonkal's avatar
Ozan Tonkal committed
514

Ozan Tonkal's avatar
Ozan Tonkal committed
515 516
viz::KeyboardEvent::KeyboardEvent
---------------------------------
Ozan Tonkal's avatar
Ozan Tonkal committed
517 518
Constructs a KeyboardEvent.

519
.. ocv:function:: KeyboardEvent (Action action, const String& symbol, unsigned char code, Modifiers modifiers)
Ozan Tonkal's avatar
Ozan Tonkal committed
520

521 522 523 524
    :param action: Signals if key is pressed or released.
    :param symbol: Name of the key.
    :param code: Code of the key.
    :param modifiers: Signals if ``alt``, ``ctrl`` or ``shift`` are pressed or their combination.
Anatoly Baksheev's avatar
Anatoly Baksheev committed
525

Ozan Tonkal's avatar
Ozan Tonkal committed
526

Ozan Tonkal's avatar
Ozan Tonkal committed
527 528
viz::MouseEvent
---------------
Ozan Tonkal's avatar
Ozan Tonkal committed
529 530 531 532
.. ocv:class:: MouseEvent

This class represents a mouse event. ::

Ozan Tonkal's avatar
Ozan Tonkal committed
533 534 535 536 537
    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
538

539
        MouseEvent(const Type& type, const MouseButton& button, const Point& pointer, int modifiers);
Ozan Tonkal's avatar
Ozan Tonkal committed
540

Ozan Tonkal's avatar
Ozan Tonkal committed
541 542 543
        Type type;
        MouseButton button;
        Point pointer;
544
        int modifiers;
Ozan Tonkal's avatar
Ozan Tonkal committed
545
    };
Ozan Tonkal's avatar
Ozan Tonkal committed
546

Ozan Tonkal's avatar
Ozan Tonkal committed
547 548
viz::MouseEvent::MouseEvent
---------------------------
Ozan Tonkal's avatar
Ozan Tonkal committed
549 550
Constructs a MouseEvent.

551
.. ocv:function:: MouseEvent (const Type& type, const MouseButton& button, const Point& p, Modifiers modifiers)
Ozan Tonkal's avatar
Ozan Tonkal committed
552

Ozan Tonkal's avatar
Ozan Tonkal committed
553 554 555
    :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.
556
    :param modifiers: Signals if ``alt``, ``ctrl`` or ``shift`` are pressed or their combination.
Ozan Tonkal's avatar
Ozan Tonkal committed
557

Ozan Tonkal's avatar
Ozan Tonkal committed
558 559
viz::Camera
-----------
Ozan Tonkal's avatar
Ozan Tonkal committed
560 561 562 563 564 565
.. 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
566 567 568
    class CV_EXPORTS Camera
    {
    public:
569 570 571 572
        Camera(double f_x, double f_y, double c_x, double c_y, const Size &window_size);
        Camera(const Vec2d &fov, const Size &window_size);
        Camera(const Matx33d &K, const Size &window_size);
        Camera(const Matx44d &proj, const Size &window_size);
Ozan Tonkal's avatar
Ozan Tonkal committed
573

574 575
        inline const Vec2d & getClip() const;
        inline void setClip(const Vec2d &clip);
Ozan Tonkal's avatar
Ozan Tonkal committed
576

577
        inline const Size & getWindowSize() const;
Ozan Tonkal's avatar
Ozan Tonkal committed
578
        void setWindowSize(const Size &window_size);
Ozan Tonkal's avatar
Ozan Tonkal committed
579

580 581
        inline const Vec2d & getFov() const;
        inline void setFov(const Vec2d & fov);
Ozan Tonkal's avatar
Ozan Tonkal committed
582

583 584
        inline const Vec2d & getPrincipalPoint() const;
        inline const Vec2d & getFocalLength() const;
Ozan Tonkal's avatar
Ozan Tonkal committed
585

586
        void computeProjectionMatrix(Matx44d &proj) const;
Ozan Tonkal's avatar
Ozan Tonkal committed
587

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

Ozan Tonkal's avatar
Ozan Tonkal committed
590 591 592
    private:
        /* hidden */
    };
Ozan Tonkal's avatar
Ozan Tonkal committed
593

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

598
.. ocv:function:: Camera(double f_x, double f_y, double c_x, double c_y, const Size &window_size)
Ozan Tonkal's avatar
Ozan Tonkal committed
599

Ozan Tonkal's avatar
Ozan Tonkal committed
600 601 602 603 604
    :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
605

606
.. ocv:function:: Camera(const Vec2d &fov, const Size &window_size)
Ozan Tonkal's avatar
Ozan Tonkal committed
607

Ozan Tonkal's avatar
Ozan Tonkal committed
608 609
    :param fov: Field of view (horizontal, vertical)
    :param window_size: Size of the window.
Ozan Tonkal's avatar
Ozan Tonkal committed
610

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

613
.. ocv:function:: Camera(const Matx33d &K, const Size &window_size)
Ozan Tonkal's avatar
Ozan Tonkal committed
614

Ozan Tonkal's avatar
Ozan Tonkal committed
615 616
    :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
617

618
.. ocv:function:: Camera(const Matx44d &proj, const Size &window_size)
Ozan Tonkal's avatar
Ozan Tonkal committed
619

Ozan Tonkal's avatar
Ozan Tonkal committed
620 621
    :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
622

Ozan Tonkal's avatar
Ozan Tonkal committed
623 624
viz::Camera::computeProjectionMatrix
------------------------------------
Ozan Tonkal's avatar
Ozan Tonkal committed
625 626
Computes projection matrix using intrinsic parameters of the camera.

627
.. ocv:function:: void computeProjectionMatrix(Matx44d &proj) const
Ozan Tonkal's avatar
Ozan Tonkal committed
628

Ozan Tonkal's avatar
Ozan Tonkal committed
629
    :param proj: Output projection matrix.
Ozan Tonkal's avatar
Ozan Tonkal committed
630

Ozan Tonkal's avatar
Ozan Tonkal committed
631 632
viz::Camera::KinectCamera
-------------------------
Ozan Tonkal's avatar
Ozan Tonkal committed
633 634 635 636
Creates a Kinect Camera.

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

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