1 | /* osgVisual test. distortionNG, experimental. |
---|
2 | * |
---|
3 | * Permission is hereby granted, free of charge, to any person obtaining a copy |
---|
4 | * of this software and associated documentation files (the "Software"), to deal |
---|
5 | * in the Software without restriction, including without limitation the rights |
---|
6 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
---|
7 | * copies of the Software, and to permit persons to whom the Software is |
---|
8 | * furnished to do so, subject to the following conditions: |
---|
9 | * |
---|
10 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
---|
11 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
---|
12 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
---|
13 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
---|
14 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
---|
15 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
---|
16 | * THE SOFTWARE. |
---|
17 | */ |
---|
18 | |
---|
19 | #ifndef OSGGA_DISTORTION_MANIPULATOR |
---|
20 | #define OSGGA_DISTORTION_MANIPULATOR 1 |
---|
21 | |
---|
22 | #include <osgGA/GUIEventHandler> |
---|
23 | #include <osg/Referenced> |
---|
24 | #include <osg/Switch> |
---|
25 | #include <osg/Geometry> |
---|
26 | #include <osgUtil/IntersectionVisitor> |
---|
27 | #include <osgUtil/LineSegmentIntersector> |
---|
28 | #include <osgText/Text> |
---|
29 | |
---|
30 | #include "DistortionSetupStrategy.h" |
---|
31 | #include "DistortionSet.h" |
---|
32 | |
---|
33 | |
---|
34 | namespace osgViewer { |
---|
35 | |
---|
36 | |
---|
37 | class DistortionManipulator : public osgGA::GUIEventHandler |
---|
38 | { |
---|
39 | public: |
---|
40 | enum SetupMode { |
---|
41 | DISABLED, |
---|
42 | MANUAL, |
---|
43 | DELEGATED |
---|
44 | }; |
---|
45 | enum DistortionMode { |
---|
46 | MESH, |
---|
47 | TEXCOORDINATES |
---|
48 | }; |
---|
49 | enum ManualSetupMode { |
---|
50 | DISTORTION, |
---|
51 | BLENDING |
---|
52 | }; |
---|
53 | enum VisualizationMode { |
---|
54 | DISTORTION_MESH, |
---|
55 | INTENSITY_MAP, |
---|
56 | NONE |
---|
57 | }; |
---|
58 | |
---|
59 | |
---|
60 | DistortionManipulator(DistortionSet* ds); |
---|
61 | virtual ~DistortionManipulator(); |
---|
62 | |
---|
63 | virtual void getUsage(osg::ApplicationUsage& usage) const; |
---|
64 | virtual bool handle(const osgGA::GUIEventAdapter& ea,osgGA::GUIActionAdapter& aa, osg::Object*, osg::NodeVisitor* nv); |
---|
65 | |
---|
66 | void setDistortionSet(DistortionSet* ds) {_distortionSet = ds;} |
---|
67 | |
---|
68 | void setDistortionSetupStrategy(DistortionSetupStrategy* strategy) {_delegatedDistortionSetupStrategy = strategy;} |
---|
69 | |
---|
70 | private: |
---|
71 | void resetIntensityMap(); |
---|
72 | void resetDistortion(); |
---|
73 | void showDistortionMesh(bool show); |
---|
74 | void showIntensityMap(bool show); |
---|
75 | |
---|
76 | void computeSelectedVertex( osgUtil::LineSegmentIntersector::Intersection& result ); |
---|
77 | void createVertexHighlighter(); |
---|
78 | void createHUD(); |
---|
79 | void updateHUD(); |
---|
80 | |
---|
81 | SetupMode activeSetupMode; |
---|
82 | DistortionMode activeDistortionMode; |
---|
83 | ManualSetupMode activeManualSetupMode; |
---|
84 | VisualizationMode activeVisualizationMode; |
---|
85 | |
---|
86 | osg::ref_ptr<DistortionSet> _distortionSet; |
---|
87 | osg::ref_ptr<DistortionSetupStrategy> _delegatedDistortionSetupStrategy; |
---|
88 | |
---|
89 | osg::ref_ptr<osg::Geometry> _highlighter; |
---|
90 | osg::observer_ptr<osg::Camera> _camera; |
---|
91 | osg::Geometry* _distortionMesh; |
---|
92 | const osg::Vec4 _highlightColor; |
---|
93 | |
---|
94 | //LF Screen Resolution |
---|
95 | unsigned int _screenPixWidth, _screenPixHeight; |
---|
96 | |
---|
97 | |
---|
98 | // HUD |
---|
99 | osg::ref_ptr<osgText::Text> hudSetupMode; |
---|
100 | osg::ref_ptr<osgText::Text> hudDistortionMode; |
---|
101 | osg::ref_ptr<osgText::Text> hudManualSetupMode; |
---|
102 | osg::ref_ptr<osgText::Text> hudVisualizationMode; |
---|
103 | }; |
---|
104 | |
---|
105 | |
---|
106 | } |
---|
107 | |
---|
108 | #endif /* OSGGA_DISTORTION_MANIPULATOR */ |
---|