OSG  3.4.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Keystone.h
Go to the documentation of this file.
1 /* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
2  *
3  * This library is open source and may be redistributed and/or modified under
4  * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
5  * (at your option) any later version. The full license is in LICENSE file
6  * included with this distribution, and on the openscenegraph.org website.
7  *
8  * This library is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  * OpenSceneGraph Public License for more details.
12 */
13 
14 
15 #ifndef OSGVIEWER_Keystone
16 #define OSGVIEWER_Keystone 1
17 
18 #include <osg/Geometry>
19 #include <osg/Geode>
20 #include <osg/DisplaySettings>
21 
22 #include <osgGA/GUIEventHandler>
23 #include <osgViewer/Export>
24 
25 namespace osgViewer
26 {
27 
29 {
30 public:
31  Keystone();
32 
33  Keystone(const Keystone& rhs, const osg::CopyOp& copop=osg::CopyOp::SHALLOW_COPY);
34 
36 
37  void reset();
38 
39  Keystone& operator = (const Keystone& rhs);
40 
41  void setKeystoneEditingEnabled(bool flag) { keystoneEditingEnabled = flag; }
42  bool getKeystoneEditingEnabled() const { return keystoneEditingEnabled; }
43 
44  void setGridColor(const osg::Vec4& color) { gridColour = color; }
45  osg::Vec4& getGridColor() { return gridColour; }
46  const osg::Vec4& getGridColor() const { return gridColour; }
47 
48  void setBottomLeft(const osg::Vec2d& v) { bottom_left = v; }
49  osg::Vec2d& getBottomLeft() { return bottom_left; }
50  const osg::Vec2d& getBottomLeft() const { return bottom_left; }
51 
52  void setBottomRight(const osg::Vec2d& v) { bottom_right = v; }
53  osg::Vec2d& getBottomRight() { return bottom_right; }
54  const osg::Vec2d& getBottomRight() const { return bottom_right; }
55 
56  void setTopLeft(const osg::Vec2d& v) { top_left = v; }
57  osg::Vec2d& getTopLeft() { return top_left; }
58  const osg::Vec2d& getTopLeft() const { return top_left; }
59 
60  void setTopRight(const osg::Vec2d& v) { top_right = v; }
61  osg::Vec2d& getTopRight() { return top_right; }
62  const osg::Vec2d& getTopRight() const { return top_right; }
63 
64 
65 
66  void compute3DPositions(osg::DisplaySettings* ds, osg::Vec3& tl, osg::Vec3& tr, osg::Vec3& br, osg::Vec3& bl) const;
67 
68  osg::Geode* createKeystoneDistortionMesh();
69 
70  osg::Node* createGrid();
71 
73  bool writeToFile();
74 
76  static bool loadKeystoneFiles(osg::DisplaySettings* ds);
77 
78 
79 protected:
80 
82 
84 
89 
90 
91 protected:
92 
93  virtual ~Keystone() {}
94 
95 
96 };
97 
99 {
100 public:
101 
102  KeystoneHandler(Keystone* keystone);
103 
105 
106  bool handle(const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& aa, osg::Object* obj, osg::NodeVisitor* nv);
107 
108  void setKeystoneEditingEnabled(bool enabled) { if (_currentControlPoints.valid()) _currentControlPoints->setKeystoneEditingEnabled(enabled); }
109  bool getKeystoneEditingEnabled() const { return _currentControlPoints.valid() ? _currentControlPoints->getKeystoneEditingEnabled() : false; }
110 
111  enum Region
112  {
122  CENTER
123  };
124 
125  osg::Vec2d incrementScale(const osgGA::GUIEventAdapter& ea) const;
126  Region computeRegion(const osgGA::GUIEventAdapter& ea) const;
127  void move(Region region, const osg::Vec2d& delta);
128 
129 protected:
130 
131 
133 
138 
141 
144 
145 };
146 
147 }
148 
149 #endif
bool getKeystoneEditingEnabled() const
Definition: Keystone.h:109
void setGridColor(const osg::Vec4 &color)
Definition: Keystone.h:44
const osg::Vec2d & getBottomLeft() const
Definition: Keystone.h:50
virtual ~Keystone()
Definition: Keystone.h:93
osg::Vec2d & getBottomRight()
Definition: Keystone.h:53
osg::Vec4 gridColour
Definition: Keystone.h:83
void setKeystoneEditingEnabled(bool flag)
Definition: Keystone.h:41
#define OSGVIEWER_EXPORT
Definition: Export.h:40
osg::Vec4 & getGridColor()
Definition: Keystone.h:45
osg::Vec2d _defaultIncrement
Definition: Keystone.h:134
void setKeystoneEditingEnabled(bool enabled)
Definition: Keystone.h:108
const osg::Vec2d & getBottomRight() const
Definition: Keystone.h:54
osg::ref_ptr< Keystone > _currentControlPoints
Definition: Keystone.h:143
const osg::Vec2d & getTopLeft() const
Definition: Keystone.h:58
bool getKeystoneEditingEnabled() const
Definition: Keystone.h:42
osg::ref_ptr< Keystone > _keystone
Definition: Keystone.h:132
void setBottomRight(const osg::Vec2d &v)
Definition: Keystone.h:52
const osg::Vec2d & getTopRight() const
Definition: Keystone.h:62
#define META_Object(library, name)
Definition: Object.h:42
osg::Vec2d bottom_right
Definition: Keystone.h:86
void setBottomLeft(const osg::Vec2d &v)
Definition: Keystone.h:48
osg::ref_ptr< Keystone > _startControlPoints
Definition: Keystone.h:140
osg::Vec2d top_right
Definition: Keystone.h:88
void setTopLeft(const osg::Vec2d &v)
Definition: Keystone.h:56
osg::Vec2d & getTopLeft()
Definition: Keystone.h:57
void setTopRight(const osg::Vec2d &v)
Definition: Keystone.h:60
const osg::Vec4 & getGridColor() const
Definition: Keystone.h:46
osg::Vec2d top_left
Definition: Keystone.h:87
Definition: Node.h:71
osg::Vec2d _shiftIncrement
Definition: Keystone.h:136
osg::Vec2d & getBottomLeft()
Definition: Keystone.h:49
bool keystoneEditingEnabled
Definition: Keystone.h:81
osg::Vec2d & getTopRight()
Definition: Keystone.h:61
osg::Vec2d bottom_left
Definition: Keystone.h:85