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_INTERACTOR_STYLE_H__
47 #define __OPENCV_VIZ_INTERACTOR_STYLE_H__
48 
49 #include <vtkInteractorStyle.h>
50 
51 namespace cv
52 {
53     namespace viz
54     {
55         class vtkVizInteractorStyle : public vtkInteractorStyle
56         {
57         public:
58             static vtkVizInteractorStyle *New();
59             vtkTypeMacro(vtkVizInteractorStyle, vtkInteractorStyle)
60             void PrintSelf(ostream& os, vtkIndent indent);
61 
62             virtual void OnChar();
63             virtual void OnKeyDown();
64             virtual void OnKeyUp();
65 
66             virtual void OnMouseMove();
67             virtual void OnLeftButtonDown();
68             virtual void OnLeftButtonUp();
69             virtual void OnMiddleButtonDown();
70             virtual void OnMiddleButtonUp();
71             virtual void OnRightButtonDown();
72             virtual void OnRightButtonUp();
73             virtual void OnMouseWheelForward();
74             virtual void OnMouseWheelBackward();
75             virtual void OnTimer();
76 
77             virtual void Rotate();
78             virtual void Spin();
79             virtual void Pan();
80             virtual void Dolly();
81 
82             vtkSetMacro(FlyMode,bool)
83             vtkGetMacro(FlyMode,bool)
84 
85 
86             vtkSetMacro(MotionFactor, double)
87             vtkGetMacro(MotionFactor, double)
88 
89             void registerMouseCallback(void (*callback)(const MouseEvent&, void*), void* cookie = 0);
90             void registerKeyboardCallback(void (*callback)(const KeyboardEvent&, void*), void * cookie = 0);
91 
setWidgetActorMap(const Ptr<WidgetActorMap> & actors)92             void setWidgetActorMap(const Ptr<WidgetActorMap>& actors) { widget_actor_map_ = actors; }
93             void saveScreenshot(const String &file);
94             void exportScene(const String &file);
95             void exportScene();
96             void changePointsSize(float delta);
97             void setRepresentationToPoints();
98             void printCameraParams();
99             void toggleFullScreen();
100             void resetViewerPose();
101             void toggleStereo();
102             void printHelp();
103 
104             // Set the basic unit step size : by default 1/250 of bounding diagonal
105             vtkSetMacro(MotionStepSize,double)
106             vtkGetMacro(MotionStepSize,double)
107 
108             // Set acceleration factor when shift key is applied : default 10
109             vtkSetMacro(MotionAccelerationFactor,double)
110             vtkGetMacro(MotionAccelerationFactor,double)
111 
112             // Set the basic angular unit for turning : efault 1 degree
113             vtkSetMacro(AngleStepSize,double)
114             vtkGetMacro(AngleStepSize,double)
115 
116         private:
117             Ptr<WidgetActorMap> widget_actor_map_;
118 
119             Vec2i win_size_;
120             Vec2i win_pos_;
121             Vec2i max_win_size_;
122 
123             void zoomIn();
124             void zoomOut();
125 
126         protected:
127             vtkVizInteractorStyle();
128             ~vtkVizInteractorStyle();
129 
130             virtual void Dolly(double factor);
131 
132             void Fly();
133             void FlyByMouse();
134             void FlyByKey();
135             void SetupMotionVars();
136             void MotionAlongVector(const Vec3d& vector, double amount, vtkCamera* cam);
137 
138         private:
139             vtkVizInteractorStyle(const vtkVizInteractorStyle&);
140             vtkVizInteractorStyle& operator=(const vtkVizInteractorStyle&);
141 
142             //! True for red-blue colors, false for magenta-green.
143             bool stereo_anaglyph_redblue_;
144 
145             void (*keyboardCallback_)(const KeyboardEvent&, void*);
146             void *keyboard_callback_cookie_;
147 
148             void (*mouseCallback_)(const MouseEvent&, void*);
149             void *mouse_callback_cookie_;
150 
151             bool FlyMode;
152             double MotionFactor;
153 
154             int getModifiers();
155 
156             // from fly
157             unsigned char KeysDown;
158             double        DiagonalLength;
159             double        MotionStepSize;
160             double        MotionUserScale;
161             double        MotionAccelerationFactor;
162             double        AngleStepSize;
163             double        DeltaYaw;
164             double        DeltaPitch;
165         };
166     }
167 }
168 
169 #endif
170