/usr/include/osgEarth/Utils is in libosgearth-dev 2.5.0+dfsg-2+b2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 | /* -*-c++-*- */
/* osgEarth - Dynamic map generation toolkit for OpenSceneGraph
* Copyright 2008-2013 Pelican Mapping
* http://osgearth.org
*
* osgEarth is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>
*/
#ifndef OSGEARTH_UTILS_H
#define OSGEARTH_UTILS_H 1
#include <osgEarth/Common>
#include <osgEarth/StringUtils>
#include <osg/Vec3f>
#include <osg/AutoTransform>
#include <osgGA/GUIEventHandler>
#include <osgViewer/View>
#include <osgUtil/CullVisitor>
#include <osgUtil/RenderBin>
#include <string>
#include <list>
#include <map>
namespace osg
{
class EllipsoidModel;
}
namespace osgEarth
{
//------------------------------------------------------------------------
struct Utils
{
/**
* Clamps v to [vmin..vmax], then remaps its range to [r0..r1].
*/
static double remap( double v, double vmin, double vmax, double r0, double r1 )
{
float vr = (osg::clampBetween(v, vmin, vmax)-vmin)/(vmax-vmin);
return r0 + vr * (r1-r0);
}
};
/**
* Removes the given event handler from the view.
* This is the equivalent of osgViewer::View::removeEventHandler which is not available
* in older versions of OSG
*/
extern OSGEARTH_EXPORT void removeEventHandler(osgViewer::View* view, osgGA::GUIEventHandler* handler);
// utility: functor for traversing a target node
template<typename T> struct TraverseFunctor {
T* _target;
TraverseFunctor(T* target) : _target(target) { }
void operator()(osg::NodeVisitor& nv) { _target->T::traverse(nv); }
};
// utility: node that traverses another node via a functor
template<typename T>
struct TraverseNode : public osg::Node {
TraverseFunctor<T> _tf;
TraverseNode(TraverseFunctor<T>& tf) : _tf(tf) { }
TraverseNode(T* target) : _tf(TraverseFunctor<T>(target)) { }
void traverse(osg::NodeVisitor& nv) { _tf(nv); }
osg::BoundingSphere computeBound() const { return _tf._target->getBound(); }
};
// utility: cull callback that traverses another node
struct TraverseNodeCallback : public osg::NodeCallback {
osg::ref_ptr<osg::Node> _node;
TraverseNodeCallback(osg::Node* node) : _node(node) { }
void operator()(osg::Node* node, osg::NodeVisitor* nv) {
_node->accept(*nv);
traverse(node, nv);
}
};
// a cull callback that prevents objects from being included in the near/fear clip
// plane calculates that OSG does.
struct DoNotComputeNearFarCullCallback : public osg::NodeCallback
{
void operator()(osg::Node* node, osg::NodeVisitor* nv);
};
/**
* A pixel-based AutoTransform variant.
*/
class OSGEARTH_EXPORT PixelAutoTransform : public osg::AutoTransform
{
public:
PixelAutoTransform();
/**
* Sets the minimim width of the object, in pixels, when the scale
* factor is 1.0.
*/
void setMinPixelWidthAtScaleOne( double pixels ) { _minPixels = pixels; }
/**
* Sets the node to use to calculate the screen size. If this is NULL,
* it will use the size of the first child node.
*/
void setSizingNode( osg::Node* node ) { _sizingNode = node; dirty(); }
/**
* Forces a recalculation of the autoscale on the next traversal
* (this usually doesn't happen unless the camera moves)
*/
void dirty();
public: // override
void accept( osg::NodeVisitor& nv );
protected:
double _minPixels;
bool _dirty;
osg::observer_ptr<osg::Node> _sizingNode;
};
/**
* Proxy class that registers a custom render bin's prototype with the
* rendering system
*/
template<class T>
struct osgEarthRegisterRenderBinProxy
{
osgEarthRegisterRenderBinProxy(const std::string& name)
{
_prototype = new T();
osgUtil::RenderBin::addRenderBinPrototype(name, _prototype.get());
}
~osgEarthRegisterRenderBinProxy()
{
osgUtil::RenderBin::removeRenderBinPrototype(_prototype.get());
_prototype = 0L;
}
osg::ref_ptr<T> _prototype;
};
/**
* Shim to apply vertex cache optimizations to geometry when it's legal.
* This is really only here to work around an OSG bug in the VertexAccessOrder
* optimizer, which corrupts non-Triangle geometries.
*/
struct OSGEARTH_EXPORT VertexCacheOptimizer : public osg::NodeVisitor
{
VertexCacheOptimizer();
virtual ~VertexCacheOptimizer() { }
void apply( osg::Geode& node );
};
/**
* Sets the data variance on all discovered drawables.
*/
struct OSGEARTH_EXPORT SetDataVarianceVisitor : public osg::NodeVisitor
{
SetDataVarianceVisitor(osg::Object::DataVariance value);
virtual ~SetDataVarianceVisitor() { }
void apply( osg::Geode& node );
osg::Object::DataVariance _value;
};
}
#endif // OSGEARTH_UTILS_H
|