1/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
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.
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.
15#ifndef OSGVIEWER_Keystone
16#define OSGVIEWER_Keystone 1
18#include <osg/Geometry>
20#include <osg/DisplaySettings>
22#include <osgGA/GUIEventHandler>
23#include <osgViewer/Export>
28class OSGVIEWER_EXPORT Keystone : public osg::Object
33 Keystone(const Keystone& rhs, const osg::CopyOp& copop=osg::CopyOp::SHALLOW_COPY);
35 META_Object(osgViewer, Keystone)
39 Keystone& operator = (const Keystone& rhs);
41 void setKeystoneEditingEnabled(bool flag) { keystoneEditingEnabled = flag; }
42 bool getKeystoneEditingEnabled() const { return keystoneEditingEnabled; }
44 void setGridColor(const osg::Vec4& color) { gridColour = color; }
45 osg::Vec4& getGridColor() { return gridColour; }
46 const osg::Vec4& getGridColor() const { return gridColour; }
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; }
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; }
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; }
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; }
66 void compute3DPositions(osg::DisplaySettings* ds, osg::Vec3& tl, osg::Vec3& tr, osg::Vec3& br, osg::Vec3& bl) const;
68 osg::Geode* createKeystoneDistortionMesh();
70 osg::Node* createGrid();
72 /** Write the file specified by the "filename" user value field. Return true if file successfully written. */
75 /** Convenience function that loads and assigns any keystone files specified in the DisplaySettings::KeystoneFileNames list, return true if Keystone's assigned to DisplaySettings.*/
76 static bool loadKeystoneFiles(osg::DisplaySettings* ds);
81 bool keystoneEditingEnabled;
85 osg::Vec2d bottom_left;
86 osg::Vec2d bottom_right;
93 virtual ~Keystone() {}
98class OSGVIEWER_EXPORT KeystoneHandler : public osgGA::GUIEventHandler
102 KeystoneHandler(Keystone* keystone);
104 ~KeystoneHandler() {}
106 bool handle(const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& aa, osg::Object* obj, osg::NodeVisitor* nv);
108 void setKeystoneEditingEnabled(bool enabled) { if (_currentControlPoints.valid()) _currentControlPoints->setKeystoneEditingEnabled(enabled); }
109 bool getKeystoneEditingEnabled() const { return _currentControlPoints.valid() ? _currentControlPoints->getKeystoneEditingEnabled() : false; }
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);
132 osg::ref_ptr<Keystone> _keystone;
134 osg::Vec2d _defaultIncrement;
135 osg::Vec2d _ctrlIncrement;
136 osg::Vec2d _shiftIncrement;
137 osg::Vec2d _keyIncrement;
139 osg::Vec2d _startPosition;
140 osg::ref_ptr<Keystone> _startControlPoints;
142 Region _selectedRegion;
143 osg::ref_ptr<Keystone> _currentControlPoints;