1
/*M///////////////////////////////////////////////////////////////////////////////////////
3
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
5
// By downloading, copying, installing or using the software you agree to this license.
6
// If you do not agree to this license, do not download, install,
7
// copy or use the software.
11
// For Open Source Computer Vision Library
13
// Copyright (C) 2013, OpenCV Foundation, all rights reserved.
14
// Third party copyrights are property of their respective owners.
16
// Redistribution and use in source and binary forms, with or without modification,
17
// are permitted provided that the following conditions are met:
19
// * Redistribution's of source code must retain the above copyright notice,
20
// this list of conditions and the following disclaimer.
22
// * Redistribution's in binary form must reproduce the above copyright notice,
23
// this list of conditions and the following disclaimer in the documentation
24
// and/or other materials provided with the distribution.
26
// * The name of the copyright holders may not be used to endorse or promote products
27
// derived from this software without specific prior written permission.
29
// This software is provided by the copyright holders and contributors "as is" and
30
// any express or implied warranties, including, but not limited to, the implied
31
// warranties of merchantability and fitness for a particular purpose are disclaimed.
32
// In no event shall the Intel Corporation or contributors be liable for any direct,
33
// indirect, incidental, special, exemplary, or consequential damages
34
// (including, but not limited to, procurement of substitute goods or services;
35
// loss of use, data, or profits; or business interruption) however caused
36
// and on any theory of liability, whether in contract, strict liability,
37
// or tort (including negligence or otherwise) arising in any way out of
38
// the use of this software, even if advised of the possibility of such damage.
41
// * Ozan Tonkal, ozantonkal@gmail.com
42
// * Anatoly Baksheev, Itseez Inc. myname.mysurname <> mycompany.com
46
#ifndef __OPENCV_VIZ_VIZ3D_HPP__
47
#define __OPENCV_VIZ_VIZ3D_HPP__
49
#if !defined YES_I_AGREE_THAT_VIZ_API_IS_NOT_STABLE_NOW_AND_BINARY_COMPARTIBILITY_WONT_BE_SUPPORTED && !defined CVAPI_EXPORTS
50
//#error "Viz is in beta state now. Please define macro above to use it"
53
#include <opencv2/core.hpp>
54
#include <opencv2/viz/types.hpp>
55
#include <opencv2/viz/widgets.hpp>
65
/** @brief The Viz3d class represents a 3D visualizer window. This class is implicitly shared. :
67
class CV_EXPORTS Viz3d
70
typedef cv::viz::Color Color;
71
typedef void (*KeyboardCallback)(const KeyboardEvent&, void*);
72
typedef void (*MouseCallback)(const MouseEvent&, void*);
74
/** @brief The constructors.
76
@param window_name Name of the window.
78
Viz3d(const String& window_name = String());
80
Viz3d& operator=(const Viz3d&);
83
/** @brief Shows a widget in the window.
85
@param id A unique id for the widget. @param widget The widget to be displayed in the window.
86
@param pose Pose of the widget.
88
void showWidget(const String &id, const Widget &widget, const Affine3d &pose = Affine3d::Identity());
90
/** @brief Removes a widget from the window.
92
@param id The id of the widget that will be removed.
94
void removeWidget(const String &id);
96
/** @brief Retrieves a widget from the window.
98
A widget is implicitly shared; that is, if the returned widget is modified, the changes
99
will be immediately visible in the window.
101
@param id The id of the widget that will be returned.
103
Widget getWidget(const String &id) const;
105
/** @brief Removes all widgets from the window.
107
void removeAllWidgets();
109
/** @brief Removed all widgets and displays image scaled to whole window area.
111
@param image Image to be displayed.
112
@param window_size Size of Viz3d window. Default value means no change.
114
void showImage(InputArray image, const Size& window_size = Size(-1, -1));
116
/** @brief Sets pose of a widget in the window.
118
@param id The id of the widget whose pose will be set. @param pose The new pose of the widget.
120
void setWidgetPose(const String &id, const Affine3d &pose);
122
/** @brief Updates pose of a widget in the window by pre-multiplying its current pose.
124
@param id The id of the widget whose pose will be updated. @param pose The pose that the current
125
pose of the widget will be pre-multiplied by.
127
void updateWidgetPose(const String &id, const Affine3d &pose);
129
/** @brief Returns the current pose of a widget in the window.
131
@param id The id of the widget whose pose will be returned.
133
Affine3d getWidgetPose(const String &id) const;
135
/** @brief Sets the intrinsic parameters of the viewer using Camera.
137
@param camera Camera object wrapping intrinsinc parameters.
139
void setCamera(const Camera &camera);
141
/** @brief Returns a camera object that contains intrinsic parameters of the current viewer.
143
Camera getCamera() const;
145
/** @brief Returns the current pose of the viewer.
147
Affine3d getViewerPose();
149
/** @brief Sets pose of the viewer.
151
@param pose The new pose of the viewer.
153
void setViewerPose(const Affine3d &pose);
155
/** @brief Resets camera viewpoint to a 3D widget in the scene.
157
@param id Id of a 3D widget.
159
void resetCameraViewpoint(const String &id);
161
/** @brief Resets camera.
165
/** @brief Transforms a point in world coordinate system to window coordinate system.
167
@param pt Point in world coordinate system.
168
@param window_coord Output point in window coordinate system.
170
void convertToWindowCoordinates(const Point3d &pt, Point3d &window_coord);
172
/** @brief Transforms a point in window coordinate system to a 3D ray in world coordinate system.
174
@param window_coord Point in window coordinate system. @param origin Output origin of the ray.
175
@param direction Output direction of the ray.
177
void converTo3DRay(const Point3d &window_coord, Point3d &origin, Vec3d &direction);
179
/** @brief Returns the current size of the window.
181
Size getWindowSize() const;
182
/** @brief Sets the size of the window.
184
@param window_size New size of the window.
186
void setWindowSize(const Size &window_size);
188
/** @brief Returns the name of the window which has been set in the constructor.
190
String getWindowName() const;
192
/** @brief Returns the Mat screenshot of the current scene.
194
cv::Mat getScreenshot() const;
196
/** @brief Saves screenshot of the current scene.
198
@param file Name of the file.
200
void saveScreenshot(const String &file);
202
/** @brief Sets the position of the window in the screen.
204
@param window_position coordinates of the window
206
void setWindowPosition(const Point& window_position);
208
/** @brief Sets or unsets full-screen rendering mode.
210
@param mode If true, window will use full-screen mode.
212
void setFullScreen(bool mode = true);
214
/** @brief Sets background color.
216
void setBackgroundColor(const Color& color = Color::black(), const Color& color2 = Color::not_set());
217
void setBackgroundTexture(InputArray image = noArray());
218
void setBackgroundMeshLab();
220
/** @brief The window renders and starts the event loop.
224
/** @brief Starts the event loop for a given time.
226
@param time Amount of time in milliseconds for the event loop to keep running.
227
@param force_redraw If true, window renders.
229
void spinOnce(int time = 1, bool force_redraw = false);
231
/** @brief Create a window in memory instead of on the screen.
233
void setOffScreenRendering();
235
/** @brief Remove all lights from the current scene.
237
void removeAllLights();
239
/** @brief Add a light in the scene.
241
@param position The position of the light.
242
@param focalPoint The point at which the light is shining
243
@param color The color of the light
244
@param diffuseColor The diffuse color of the light
245
@param ambientColor The ambient color of the light
246
@param specularColor The specular color of the light
248
void addLight(Vec3d position, Vec3d focalPoint = Vec3d(0, 0, 0), Color color = Color::white(),
249
Color diffuseColor = Color::white(), Color ambientColor = Color::black(), Color specularColor = Color::white());
251
/** @brief Returns whether the event loop has been stopped.
253
bool wasStopped() const;
256
/** @brief Sets keyboard handler.
258
@param callback Keyboard callback (void (\*KeyboardCallbackFunction(const
259
KeyboardEvent&, void\*)).
260
@param cookie The optional parameter passed to the callback.
262
void registerKeyboardCallback(KeyboardCallback callback, void* cookie = 0);
264
/** @brief Sets mouse handler.
266
@param callback Mouse callback (void (\*MouseCallback)(const MouseEvent&, void\*)).
267
@param cookie The optional parameter passed to the callback.
269
void registerMouseCallback(MouseCallback callback, void* cookie = 0);
271
/** @brief Sets rendering property of a widget.
273
@param id Id of the widget.
274
@param property Property that will be modified.
275
@param value The new value of the property.
277
**Rendering property** can be one of the following:
283
**REPRESENTATION**: Expected values are
284
- **REPRESENTATION_POINTS**
285
- **REPRESENTATION_WIREFRAME**
286
- **REPRESENTATION_SURFACE**
288
**IMMEDIATE_RENDERING**:
289
- Turn on immediate rendering by setting the value to 1.
290
- Turn off immediate rendering by setting the value to 0.
292
**SHADING**: Expected values are
294
- **SHADING_GOURAUD**
297
void setRenderingProperty(const String &id, int property, double value);
298
/** @brief Returns rendering property of a widget.
300
@param id Id of the widget.
301
@param property Property.
303
**Rendering property** can be one of the following:
309
**REPRESENTATION**: Expected values are
310
- **REPRESENTATION_POINTS**
311
- **REPRESENTATION_WIREFRAME**
312
- **REPRESENTATION_SURFACE**
314
**IMMEDIATE_RENDERING**:
315
- Turn on immediate rendering by setting the value to 1.
316
- Turn off immediate rendering by setting the value to 0.
318
**SHADING**: Expected values are
320
- **SHADING_GOURAUD**
323
double getRenderingProperty(const String &id, int property);
325
/** @brief Sets geometry representation of the widgets to surface, wireframe or points.
327
@param representation Geometry representation which can be one of the following:
328
- **REPRESENTATION_POINTS**
329
- **REPRESENTATION_WIREFRAME**
330
- **REPRESENTATION_SURFACE**
332
void setRepresentation(int representation);
334
void setGlobalWarnings(bool enabled = false);
340
void create(const String &window_name);
343
friend class VizStorage;
348
} /* namespace viz */