• 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_IMPL_HPP__
47 #define __OPENCV_VIZ_VIZ3D_IMPL_HPP__
48 
49 struct cv::viz::Viz3d::VizImpl
50 {
51 public:
52     typedef Viz3d::KeyboardCallback KeyboardCallback;
53     typedef Viz3d::MouseCallback MouseCallback;
54 
55     int ref_counter;
56 
57     VizImpl(const String &name);
58     virtual ~VizImpl();
59 
60     bool wasStopped() const;
61     void close();
62 
63     void spin();
64     void spinOnce(int time = 1, bool force_redraw = false);
65 
66     void showWidget(const String &id, const Widget &widget, const Affine3d &pose = Affine3d::Identity());
67     void removeWidget(const String &id);
68     Widget getWidget(const String &id) const;
69     void removeAllWidgets();
70 
71     void showImage(InputArray image, const Size& window_size);
72 
73     void setWidgetPose(const String &id, const Affine3d &pose);
74     void updateWidgetPose(const String &id, const Affine3d &pose);
75     Affine3d getWidgetPose(const String &id) const;
76 
77     void setRepresentation(int representation);
78 
79     void setCamera(const Camera &camera);
80     Camera getCamera() const;
81 
82     /** \brief Reset the camera to a given widget */
83     void resetCameraViewpoint(const String& id);
84     void resetCamera();
85 
86     void setViewerPose(const Affine3d &pose);
87     Affine3d getViewerPose();
88 
89     void convertToWindowCoordinates(const Point3d &pt, Point3d &window_coord);
90     void converTo3DRay(const Point3d &window_coord, Point3d &origin, Vec3d &direction);
91 
92     void saveScreenshot(const String &file);
93     void setWindowPosition(const Point& position);
94     Size getWindowSize() const;
95     void setWindowSize(const Size& window_size);
96     void setFullScreen(bool mode);
97     String getWindowName() const;
98     void setBackgroundColor(const Color& color, const Color& color2);
99     void setBackgroundTexture(InputArray image);
100     void setBackgroundMeshLab();
101 
102     void registerKeyboardCallback(KeyboardCallback callback, void* cookie = 0);
103     void registerMouseCallback(MouseCallback callback, void* cookie = 0);
104 
105 private:
106     struct TimerCallback : public vtkCommand
107     {
Newcv::viz::Viz3d::VizImpl::TimerCallback108         static TimerCallback* New() { return new TimerCallback; }
109         virtual void Execute(vtkObject* caller, unsigned long event_id, void* cookie);
110         int timer_id;
111     };
112 
113     struct ExitCallback : public vtkCommand
114     {
Newcv::viz::Viz3d::VizImpl::ExitCallback115         static ExitCallback* New() { return new ExitCallback; }
116         virtual void Execute(vtkObject*, unsigned long event_id, void*);
117         VizImpl* viz;
118     };
119 
120     mutable bool spin_once_state_;
121     vtkSmartPointer<vtkRenderWindowInteractor> interactor_;
122 
123     vtkSmartPointer<vtkRenderWindow> window_;
124     String window_name_;
125     Vec2i window_position_;
126 
127     vtkSmartPointer<TimerCallback> timer_callback_;
128     vtkSmartPointer<ExitCallback> exit_callback_;
129 
130     vtkSmartPointer<vtkRenderer> renderer_;
131     vtkSmartPointer<vtkVizInteractorStyle> style_;
132     Ptr<WidgetActorMap> widget_actor_map_;
133 
134     bool removeActorFromRenderer(vtkSmartPointer<vtkProp> actor);
135     void recreateRenderWindow();
136 };
137 
138 #endif
139