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

Last change on this file since 94 was 88, checked in by Torben Dannhauer, 14 years ago

Moved memory leak detection from source file to headerfile. Its still in the class but at least not in the source file.

The leak detection works, but the false positives are not stopped.
Use Linux/Valgrind? to make your final leak detection beyond the easy first approach in MSVC

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{
57        #include <leakDetection.h>
58public:
59        /**
60         * \brief Construtor
61         *
62         */ 
63        util();
64
65        /**
66         * \brief Destructor
67         *
68         */ 
69        ~util();
70
71        /**
72         * \brief This functions searches in the scene graph for a node with a name
73         *
74         * This function searches in the scene graph unter the node "currNode" for a node named like the given search name.
75         * The functions returns the first node with that name.
76         *
77         * @param searchName_ : Nodename to search for
78         * @param currNode_ : Scene graph to search in.
79         * @return : if Node found: Pointer to the node. If not found: NULL
80         */ 
81        static osg::Node* findNamedNode(const std::string& searchName_, osg::Node* currNode_);
82
83        /**
84         * \brief This function creates a red cylinder of the specified size tor testing purposes.
85         *
86         * @param length_ : Length of the cylinder in meter.
87         * @param width_ : Diameter of the cylinder in meter.
88         * @param offset_ : Offset of the cylinder's origin in meter.
89         * @return : Referenced Pointer off the Geode with the created cylinder.
90         */ 
91        static osg::ref_ptr<osg::Geode> getDemoCylinder(double length_, double width_, osg::Vec3 offset_ = osg::Vec3(0.0, 0.0, 0.0) );
92       
93        /**
94         * \brief This function creates a red sphere of the specified size tor testing purposes.
95         *
96         * @param radius_ : Radius of the sphere in meter.
97         * @param offset_ : Offset of the sphere's origin in meter.
98         * @return : Referenced Pointer off the Geode with the created cylinder.
99         */ 
100        static osg::ref_ptr<osg::Geode> getDemoSphere(double radius_, osg::Vec3 offset_ = osg::Vec3(0.0, 0.0, 0.0) );
101
102        /**
103         * \brief This functions searches the scene graph for intersections of a line between two points and the model.
104         *
105         * @param start_ : Point 1 for the intersection line
106         * @param end_ : Point 2 for the intersection line
107         * @param intersection_ : vektor to the intersection point if any is found.
108         * @param node_ : Node which is the root of the scene graph to check for intersections
109         * @param intersectTraversalMask_ : Bitwise mask wich controls which nodes should be checked for intersections (e.g. to check only terrain but not clouds or sky)
110         * @return returns : True if an intersection is found.
111         */ 
112        static bool intersect(const osg::Vec3d& start_, const osg::Vec3d& end_, osg::Vec3d& intersection_, osg::Node* node_, osg::Node::NodeMask intersectTraversalMask_=0xffffffff );
113
114        /**
115         * \brief This function queries the height of terrain (hot) at a specified location.
116         *
117         * @param hot_ : Reference to write the calculated hot into.
118         * @param rootNode_ : Node which is the root of the scene graph to calculate the hot.
119         * @param lat_ : Latitude of the position to calculate the hot.
120         * @param lon_ : Longitude of the position to calculate the hot.
121         * @param traversalMask_ : Bitwise mask wich controls which nodes should be checked for hot (e.g. to check only terrain but not clouds or sky)
122         * @return : True if hot calculation successful.
123         */ 
124        static bool queryHeightOfTerrain(double& hot_, osg::Node* rootNode_, double lat_, double lon_, osg::Node::NodeMask traversalMask_=0xffffffff);
125
126        /**
127         * \brief This function queries the height above terrain (hat) at a specified location in WGS84 coordinates.
128         *
129         * @param hat_ : Reference to write the calculated hat into.
130         * @param rootNode_ : Node which is the root of the scene graph to calculate the hat.
131         * @param lat_ : Latitude of the position to calculate the hat. (e.g. lat of camera)
132         * @param lon_ : Longitude of the position to calculate the hat.(e.g. lon of camera)
133         * @param height_ : Height of the position to calculate the hat.(e.g. height of camera).
134         * @param traversalMask_ : Bitwise mask wich controls which nodes should be checked for hat (e.g. to check only terrain but not clouds or sky)
135         * @return :  True if hat calculation successful.
136         */ 
137        static bool queryHeightAboveTerrainInWGS84(double& hat_, osg::Node* rootNode_, double lat_, double lon_, double height_, osg::Node::NodeMask traversalMask_=0xffffffff);
138
139        /**
140         * \brief This function queries the height above terrain (hat) at a specified location in world coordinates.
141         *
142         * @param hat_ : Reference to write the calculated hat into.
143         * @param rootNode_ : Node which is the root of the scene graph to calculate the hat.
144         * @param x_ : First value of the pointer which points to the position to calculate hat for.
145         * @param y_ : Second value of the pointer which points to the position to calculate hat for.
146         * @param z_ : Third value of the pointer which points to the position to calculate hat for.
147         * @param traversalMask_ : Bitwise mask wich controls which nodes should be checked for hat (e.g. to check only terrain but not clouds or sky)
148         * @return :  True if hat calculation successful.
149         */ 
150        static bool queryHeightAboveTerrainInWorld(double& hat_, osg::Node* rootNode_, double x_, double y_, double z_, osg::Node::NodeMask traversalMask_=0xffffffff);
151
152        /**
153         * \brief This function calculates the earth readius (vector length in world coordiantes from origin to location) at the specified location.
154         *
155         * @param lat_ : Latitude in radians.
156         * @param lon_ : Longitude in radians.
157         * @param rootNode_ : Root node of the scene which coordinate system node should be used.
158         * @param radius_ : Calculated earth readius in meter.
159         * @return : True if calculation successful.
160         */ 
161        static bool calculateEarthRadiusAtWGS84Coordinate(double lat_, double lon_, osg::Node* rootNode_, double& radius_);
162
163        /**
164         * \brief This function converts a WGS84 position into global OpenGL XYZ coordinates.
165         *
166         * @param lat_ : Latitude of the position to calculate XYZ.
167         * @param lon_ : Longitude of the position to calculate XYZ.
168         * @param height_ : Height of the position to calculate XYZ.
169         * @param rootNode_ : Node which is the root of the scene graph to calculate XYZ.
170         * @param x_ : X Coordinate in global OpenGL coordinates.
171         * @param y_ : Y Coordinate in global OpenGL coordinates.
172         * @param z_ : Z Coordinate in global OpenGL coordinates.
173         * @return : True if calculation successful.
174         */ 
175        static bool calculateXYZAtWGS84Coordinate(double lat_, double lon_, double height_, osg::Node* rootNode_, double& x_, double& y_, double& z_);
176
177        /**
178         * \brief This function calculates lat, lon and height of a specified camera by a specified coordinate system node.
179         *
180         * @param camera_ : Camera node which position should be calculated.
181         * @param rootNode_ : rootNode of the scene.
182         * @param lat_ : Latitude variable to save value in.
183         * @param lon_ : Longitude variable to save value in.
184         * @param height_ : Height: variable to save value in.
185         * @return : True if calculation was successful.
186         */ 
187        static bool getWGS84ofCamera( osg::Camera* camera_, osg::Node* rootNode_, double& lat_, double& lon_, double& height_ ); 
188
189        /**
190         * \brief This function returns the global XYZ coordinates of the specified camera.
191         *
192         * @param camera_ : Camera to return the position.
193         * @param x_ : X coordinate.
194         * @param y_ : Y coordinate.
195         * @param z_ : Z coordinate.
196         */ 
197        static void getXYZofCamera( osg::Camera* camera_, double& x_, double& y_, double& z_ ); 
198
199        /**
200         * \brief This function disables the close button on the openGL's windowdecoration
201         *
202         * 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 ;)
203         *
204         * @param viewer_ : Pointer to the applications viewer
205         * @return : true if successful
206         */ 
207        static bool removeClosebuttonOnGLWindow(osgViewer::Viewer* viewer_);
208
209        /**
210         * \brief This function make the backgroud of the GL window blurred transparent, if an backgroud with alpha is set.
211         *
212         * 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 ;)
213         *
214         * @param viewer_ : Pointer to the applications viewer
215         * @return : true if successful
216         */ 
217        static bool setTransparentWindowBackground(osgViewer::Viewer* viewer_);
218};
219
220} //END NAMESPACE
Note: See TracBrowser for help on using the repository browser.