source: osgVisual/include/util/visual_util.h @ 54

Last change on this file since 54 was 32, checked in by Torben Dannhauer, 15 years ago

Adding first version of osgVisual!!

File size: 9.7 KB
Line 
1#pragma once
2/* -*-c++-*- osgVisual - Copyright (C) 2009-2010 Torben Dannhauer
3 *
4 * This library is based on OpenSceneGraph, open source and may be redistributed and/or modified under
5 * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
6 * (at your option) any later version.  The full license is in LICENSE file
7 * included with this distribution, and on the openscenegraph.org website.
8 *
9 * osgVisual requires for some proprietary modules a license from the correspondig manufacturer.
10 * You have to aquire licenses for all used proprietary modules.
11 *
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 * OpenSceneGraph Public License for more details.
16*/
17
18#include <string.h>
19#include <iostream>
20
21
22#include <osg/Node>
23#include <osg/Group>
24#include <osg/Geode>
25#include <osg/CoordinateSystemNode>
26#include <osg/ShapeDrawable>
27
28#include <osgViewer/Viewer>
29
30#ifdef FUNFUNCTIONS_ENABLED
31#ifdef WIN32
32#include <osgViewer/api/Win32/GraphicsHandleWin32>
33#include "C:\\Program Files/Microsoft SDKs/Windows/v6.1/Include/dwmapi.h"
34#pragma comment ( lib, "C:\\Program Files/Microsoft SDKs/Windows/v6.1/Lib/dwmapi.lib" )
35#endif
36#endif
37
38#include <OpenThreads/ReentrantMutex>
39
40#include <osgUtil/LineSegmentIntersector>
41
42namespace osgVisual
43{ 
44
45/**
46 * \brief This class provides utility functions.
47 *
48 * The utility functions are implemented as static functions if possible for easy use in other classes.
49 *
50 * \todo check why lineIntersector is unstable, check if newer and better system is available.
51 *
52 * @author Torben Dannhauer
53 * @date  Jul 2009
54 */ 
55class util
56{
57public:
58        /**
59         * \brief Construtor
60         *
61         */ 
62        util();
63
64        /**
65         * \brief Destructor
66         *
67         */ 
68        ~util();
69
70        /**
71         * \brief This functions searches in the scene graph for a node with a name
72         *
73         * This function searches in the scene graph unter the node "currNode" for a node named like the given search name.
74         * The functions returns the first node with that name.
75         *
76         * @param searchName_ : Nodename to search for
77         * @param currNode_ : Scene graph to search in.
78         * @return : if Node found: Pointer to the node. If not found: NULL
79         */ 
80        static osg::Node* findNamedNode(const std::string& searchName_, osg::Node* currNode_);
81
82        /**
83         * \brief This function creates a red cylinder of the specified size tor testing purposes.
84         *
85         * @param length_ : Length of the cylinder in meter.
86         * @param width_ : Diameter of the cylinder in meter.
87         * @param offset_ : Offset of the cylinder's origin in meter.
88         * @return : Referenced Pointer off the Geode with the created cylinder.
89         */ 
90        static osg::ref_ptr<osg::Geode> getDemoCylinder(double length_, double width_, osg::Vec3 offset_ = osg::Vec3(0.0, 0.0, 0.0) );
91       
92        /**
93         * \brief This function creates a red sphere of the specified size tor testing purposes.
94         *
95         * @param radius_ : Radius of the sphere in meter.
96         * @param offset_ : Offset of the sphere's origin in meter.
97         * @return : Referenced Pointer off the Geode with the created cylinder.
98         */ 
99        static osg::ref_ptr<osg::Geode> getDemoSphere(double radius_, osg::Vec3 offset_ = osg::Vec3(0.0, 0.0, 0.0) );
100
101        /**
102         * \brief This functions searches the scene graph for intersections of a line between two points and the model.
103         *
104         * @param start_ : Point 1 for the intersection line
105         * @param end_ : Point 2 for the intersection line
106         * @param intersection_ : vektor to the intersection point if any is found.
107         * @param node_ : Node which is the root of the scene graph to check for intersections
108         * @param intersectTraversalMask_ : Bitwise mask wich controls which nodes should be checked for intersections (e.g. to check only terrain but not clouds or sky)
109         * @return returns : True if an intersection is found.
110         */ 
111        static bool intersect(const osg::Vec3d& start_, const osg::Vec3d& end_, osg::Vec3d& intersection_, osg::Node* node_, osg::Node::NodeMask intersectTraversalMask_=0xffffffff );
112
113        /**
114         * \brief This function queries the height of terrain (hot) at a specified location.
115         *
116         * @param hot_ : Reference to write the calculated hot into.
117         * @param rootNode_ : Node which is the root of the scene graph to calculate the hot.
118         * @param lat_ : Latitude of the position to calculate the hot.
119         * @param lon_ : Longitude of the position to calculate the hot.
120         * @param traversalMask_ : Bitwise mask wich controls which nodes should be checked for hot (e.g. to check only terrain but not clouds or sky)
121         * @return : True if hot calculation successful.
122         */ 
123        static bool queryHeightOfTerrain(double& hot_, osg::Node* rootNode_, double lat_, double lon_, osg::Node::NodeMask traversalMask_=0xffffffff);
124
125        /**
126         * \brief This function queries the height above terrain (hat) at a specified location in WGS84 coordinates.
127         *
128         * @param hat_ : Reference to write the calculated hat into.
129         * @param rootNode_ : Node which is the root of the scene graph to calculate the hat.
130         * @param lat_ : Latitude of the position to calculate the hat. (e.g. lat of camera)
131         * @param lon_ : Longitude of the position to calculate the hat.(e.g. lon of camera)
132         * @param height_ : Height of the position to calculate the hat.(e.g. height of camera).
133         * @param traversalMask_ : Bitwise mask wich controls which nodes should be checked for hat (e.g. to check only terrain but not clouds or sky)
134         * @return :  True if hat calculation successful.
135         */ 
136        static bool queryHeightAboveTerrainInWGS84(double& hat_, osg::Node* rootNode_, double lat_, double lon_, double height_, osg::Node::NodeMask traversalMask_=0xffffffff);
137
138        /**
139         * \brief This function queries the height above terrain (hat) at a specified location in world coordinates.
140         *
141         * @param hat_ : Reference to write the calculated hat into.
142         * @param rootNode_ : Node which is the root of the scene graph to calculate the hat.
143         * @param x_ : First value of the pointer which points to the position to calculate hat for.
144         * @param y_ : Second value of the pointer which points to the position to calculate hat for.
145         * @param z_ : Third value of the pointer which points to the position to calculate hat for.
146         * @param traversalMask_ : Bitwise mask wich controls which nodes should be checked for hat (e.g. to check only terrain but not clouds or sky)
147         * @return :  True if hat calculation successful.
148         */ 
149        static bool queryHeightAboveTerrainInWorld(double& hat_, osg::Node* rootNode_, double x_, double y_, double z_, osg::Node::NodeMask traversalMask_=0xffffffff);
150
151        /**
152         * \brief This function calculates the earth readius (vector length in world coordiantes from origin to location) at the specified location.
153         *
154         * @param lat_ : Latitude in radians.
155         * @param lon_ : Longitude in radians.
156         * @param rootNode_ : Root node of the scene which coordinate system node should be used.
157         * @param radius_ : Calculated earth readius in meter.
158         * @return : True if calculation successful.
159         */ 
160        static bool calculateEarthRadiusAtWGS84Coordinate(double lat_, double lon_, osg::Node* rootNode_, double& radius_);
161
162        /**
163         * \brief This function converts a WGS84 position into global OpenGL XYZ coordinates.
164         *
165         * @param lat_ : Latitude of the position to calculate XYZ.
166         * @param lon_ : Longitude of the position to calculate XYZ.
167         * @param height_ : Height of the position to calculate XYZ.
168         * @param rootNode_ : Node which is the root of the scene graph to calculate XYZ.
169         * @param x_ : X Coordinate in global OpenGL coordinates.
170         * @param y_ : Y Coordinate in global OpenGL coordinates.
171         * @param z_ : Z Coordinate in global OpenGL coordinates.
172         * @return : True if calculation successful.
173         */ 
174        static bool calculateXYZAtWGS84Coordinate(double lat_, double lon_, double height_, osg::Node* rootNode_, double& x_, double& y_, double& z_);
175
176        /**
177         * \brief This function calculates lat, lon and height of a specified camera by a specified coordinate system node.
178         *
179         * @param camera_ : Camera node which position should be calculated.
180         * @param rootNode_ : rootNode of the scene.
181         * @param lat_ : Latitude variable to save value in.
182         * @param lon_ : Longitude variable to save value in.
183         * @param height_ : Height: variable to save value in.
184         * @return : True if calculation was successful.
185         */ 
186        static bool getWGS84ofCamera( osg::Camera* camera_, osg::Node* rootNode_, double& lat_, double& lon_, double& height_ ); 
187
188        /**
189         * \brief This function returns the global XYZ coordinates of the specified camera.
190         *
191         * @param camera_ : Camera to return the position.
192         * @param x_ : X coordinate.
193         * @param y_ : Y coordinate.
194         * @param z_ : Z coordinate.
195         */ 
196        static void getXYZofCamera( osg::Camera* camera_, double& x_, double& y_, double& z_ ); 
197
198        /**
199         * \brief This function disables the close button on the openGL's windowdecoration
200         *
201         * To be honest, this function is only to play, I have found it on http://forum.openscenegraph.org and found it interesting enought to play along ;)
202         *
203         * @param viewer_ : Pointer to the applications viewer
204         * @return : true if successful
205         */ 
206        static bool removeClosebuttonOnGLWindow(osgViewer::Viewer* viewer_);
207
208        /**
209         * \brief This function make the backgroud of the GL window blurred transparent, if an backgroud with alpha is set.
210         *
211         * To be honest, this function is only to play, I have found it on http://forum.openscenegraph.org and found it interesting enought to play along ;)
212         *
213         * @param viewer_ : Pointer to the applications viewer
214         * @return : true if successful
215         */ 
216        static bool setTransparentWindowBackground(osgViewer::Viewer* viewer_);
217};
218
219} //END NAMESPACE
Note: See TracBrowser for help on using the repository browser.