• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*M///////////////////////////////////////////////////////////////////////////////////////
2 //
3 //  IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
4 //
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.
8 //
9 //
10 //                           License Agreement
11 //                For Open Source Computer Vision Library
12 //
13 // Copyright (C) 2013, OpenCV Foundation, all rights reserved.
14 // Third party copyrights are property of their respective owners.
15 //
16 // Redistribution and use in source and binary forms, with or without modification,
17 // are permitted provided that the following conditions are met:
18 //
19 //   * Redistribution's of source code must retain the above copyright notice,
20 //     this list of conditions and the following disclaimer.
21 //
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.
25 //
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.
28 //
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.
39 //
40 // Authors:
41 //  * Ozan Tonkal, ozantonkal@gmail.com
42 //  * Anatoly Baksheev, Itseez Inc.  myname.mysurname <> mycompany.com
43 //
44 //M*/
45 
46 #ifndef __OPENCV_VIZ_VIZ3D_HPP__
47 #define __OPENCV_VIZ_VIZ3D_HPP__
48 
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"
51 #endif
52 
53 #include <opencv2/core.hpp>
54 #include <opencv2/viz/types.hpp>
55 #include <opencv2/viz/widgets.hpp>
56 
57 namespace cv
58 {
59     namespace viz
60     {
61 
62 //! @addtogroup viz
63 //! @{
64 
65         /** @brief The Viz3d class represents a 3D visualizer window. This class is implicitly shared. :
66         */
67         class CV_EXPORTS Viz3d
68         {
69         public:
70             typedef cv::viz::Color Color;
71             typedef void (*KeyboardCallback)(const KeyboardEvent&, void*);
72             typedef void (*MouseCallback)(const MouseEvent&, void*);
73 
74             /** @brief The constructors.
75 
76             @param window_name Name of the window.
77              */
78             Viz3d(const String& window_name = String());
79             Viz3d(const Viz3d&);
80             Viz3d& operator=(const Viz3d&);
81             ~Viz3d();
82 
83             /** @brief Shows a widget in the window.
84 
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.
87              */
88             void showWidget(const String &id, const Widget &widget, const Affine3d &pose = Affine3d::Identity());
89 
90             /** @brief Removes a widget from the window.
91 
92             @param id The id of the widget that will be removed.
93              */
94             void removeWidget(const String &id);
95 
96             /** @brief Retrieves a widget from the window.
97 
98             A widget is implicitly shared; that is, if the returned widget is modified, the changes
99             will be immediately visible in the window.
100 
101             @param id The id of the widget that will be returned.
102              */
103             Widget getWidget(const String &id) const;
104 
105             /** @brief Removes all widgets from the window.
106             */
107             void removeAllWidgets();
108 
109             /** @brief Removed all widgets and displays image scaled to whole window area.
110 
111             @param image Image to be displayed.
112             @param window_size Size of Viz3d window. Default value means no change.
113              */
114             void showImage(InputArray image, const Size& window_size = Size(-1, -1));
115 
116             /** @brief Sets pose of a widget in the window.
117 
118             @param id The id of the widget whose pose will be set. @param pose The new pose of the widget.
119              */
120             void setWidgetPose(const String &id, const Affine3d &pose);
121 
122             /** @brief Updates pose of a widget in the window by pre-multiplying its current pose.
123 
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.
126              */
127             void updateWidgetPose(const String &id, const Affine3d &pose);
128 
129             /** @brief Returns the current pose of a widget in the window.
130 
131             @param id The id of the widget whose pose will be returned.
132              */
133             Affine3d getWidgetPose(const String &id) const;
134 
135             /** @brief Sets the intrinsic parameters of the viewer using Camera.
136 
137             @param camera Camera object wrapping intrinsinc parameters.
138              */
139             void setCamera(const Camera &camera);
140 
141             /** @brief Returns a camera object that contains intrinsic parameters of the current viewer.
142             */
143             Camera getCamera() const;
144 
145             /** @brief Returns the current pose of the viewer.
146             */
147             Affine3d getViewerPose();
148 
149             /** @brief Sets pose of the viewer.
150 
151             @param pose The new pose of the viewer.
152              */
153             void setViewerPose(const Affine3d &pose);
154 
155             /** @brief Resets camera viewpoint to a 3D widget in the scene.
156 
157             @param id Id of a 3D widget.
158              */
159             void resetCameraViewpoint(const String &id);
160 
161             /** @brief Resets camera.
162             */
163             void resetCamera();
164 
165             /** @brief Transforms a point in world coordinate system to window coordinate system.
166 
167             @param pt Point in world coordinate system.
168             @param window_coord Output point in window coordinate system.
169              */
170             void convertToWindowCoordinates(const Point3d &pt, Point3d &window_coord);
171 
172             /** @brief Transforms a point in window coordinate system to a 3D ray in world coordinate system.
173 
174             @param window_coord Point in window coordinate system. @param origin Output origin of the ray.
175             @param direction Output direction of the ray.
176              */
177             void converTo3DRay(const Point3d &window_coord, Point3d &origin, Vec3d &direction);
178 
179             /** @brief Returns the current size of the window.
180             */
181             Size getWindowSize() const;
182             /** @brief Sets the size of the window.
183 
184             @param window_size New size of the window.
185              */
186             void setWindowSize(const Size &window_size);
187 
188             /** @brief Returns the name of the window which has been set in the constructor.
189              */
190             String getWindowName() const;
191 
192             /** @brief Saves screenshot of the current scene.
193 
194             @param file Name of the file.
195              */
196             void saveScreenshot(const String &file);
197 
198             /** @brief Sets the position of the window in the screen.
199 
200             @param window_position coordinates of the window
201              */
202             void setWindowPosition(const Point& window_position);
203 
204             /** @brief Sets or unsets full-screen rendering mode.
205 
206             @param mode If true, window will use full-screen mode.
207              */
208             void setFullScreen(bool mode = true);
209 
210             /** @brief Sets background color.
211             */
212             void setBackgroundColor(const Color& color = Color::black(), const Color& color2 = Color::not_set());
213             void setBackgroundTexture(InputArray image = noArray());
214             void setBackgroundMeshLab();
215 
216             /** @brief The window renders and starts the event loop.
217             */
218             void spin();
219 
220             /** @brief Starts the event loop for a given time.
221 
222             @param time Amount of time in milliseconds for the event loop to keep running.
223             @param force_redraw If true, window renders.
224              */
225             void spinOnce(int time = 1, bool force_redraw = false);
226 
227             /** @brief Returns whether the event loop has been stopped.
228             */
229             bool wasStopped() const;
230             void close();
231 
232             /** @brief Sets keyboard handler.
233 
234             @param callback Keyboard callback (void (\*KeyboardCallbackFunction(const
235             KeyboardEvent&, void\*)).
236             @param cookie The optional parameter passed to the callback.
237              */
238             void registerKeyboardCallback(KeyboardCallback callback, void* cookie = 0);
239 
240             /** @brief Sets mouse handler.
241 
242             @param callback Mouse callback (void (\*MouseCallback)(const MouseEvent&, void\*)).
243             @param cookie The optional parameter passed to the callback.
244              */
245             void registerMouseCallback(MouseCallback callback, void* cookie = 0);
246 
247             /** @brief Sets rendering property of a widget.
248 
249             @param id Id of the widget.
250             @param property Property that will be modified.
251             @param value The new value of the property.
252 
253             **Rendering property** can be one of the following:
254             -   **POINT_SIZE**
255             -   **OPACITY**
256             -   **LINE_WIDTH**
257             -   **FONT_SIZE**
258             -
259             **REPRESENTATION**: Expected values are
260             -   **REPRESENTATION_POINTS**
261             -   **REPRESENTATION_WIREFRAME**
262             -   **REPRESENTATION_SURFACE**
263             -
264             **IMMEDIATE_RENDERING**:
265             -   Turn on immediate rendering by setting the value to 1.
266             -   Turn off immediate rendering by setting the value to 0.
267             -
268             **SHADING**: Expected values are
269             -   **SHADING_FLAT**
270             -   **SHADING_GOURAUD**
271             -   **SHADING_PHONG**
272              */
273             void setRenderingProperty(const String &id, int property, double value);
274             /** @brief Returns rendering property of a widget.
275 
276             @param id Id of the widget.
277             @param property Property.
278 
279             **Rendering property** can be one of the following:
280             -   **POINT_SIZE**
281             -   **OPACITY**
282             -   **LINE_WIDTH**
283             -   **FONT_SIZE**
284             -
285             **REPRESENTATION**: Expected values are
286             -   **REPRESENTATION_POINTS**
287             -   **REPRESENTATION_WIREFRAME**
288             -   **REPRESENTATION_SURFACE**
289             -
290             **IMMEDIATE_RENDERING**:
291             -   Turn on immediate rendering by setting the value to 1.
292             -   Turn off immediate rendering by setting the value to 0.
293             -
294             **SHADING**: Expected values are
295             -   **SHADING_FLAT**
296             -   **SHADING_GOURAUD**
297             -   **SHADING_PHONG**
298              */
299             double getRenderingProperty(const String &id, int property);
300 
301             /** @brief Sets geometry representation of the widgets to surface, wireframe or points.
302 
303             @param representation Geometry representation which can be one of the following:
304             -   **REPRESENTATION_POINTS**
305             -   **REPRESENTATION_WIREFRAME**
306             -   **REPRESENTATION_SURFACE**
307              */
308             void setRepresentation(int representation);
309 
310             void setGlobalWarnings(bool enabled = false);
311         private:
312 
313             struct VizImpl;
314             VizImpl* impl_;
315 
316             void create(const String &window_name);
317             void release();
318 
319             friend class VizStorage;
320         };
321 
322 //! @}
323 
324     } /* namespace viz */
325 } /* namespace cv */
326 
327 #endif
328