/usr/include/osgEarth/NodeUtils is in libosgearth-dev 2.5.0+dfsg-8build1.
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 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 | /* -*-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_NODE_UTILS_H
#define OSGEARTH_NODE_UTILS_H 1
#include <osgEarth/Common>
#include <osg/View>
#include <osg/PagedLOD>
#include <osgGA/GUIActionAdapter>
#include <osgUtil/LineSegmentIntersector>
#include <osgEarth/ThreadingUtils>
#include <set>
#include <vector>
namespace osgEarth
{
/**
* General purpose operation for doing something to a node.
*/
struct NodeOperation : public osg::Referenced
{
virtual void operator()( osg::Node* node ) =0;
};
typedef std::vector< osg::ref_ptr<NodeOperation> > NodeOperationVector;
struct RefNodeOperationVector : public osg::Referenced, public NodeOperationVector { };
/**
* A PagedLOD that will fire node operation callbacks when it merges
* new nodes into the graph.
*/
class OSGEARTH_EXPORT PagedLODWithNodeOperations : public osg::PagedLOD
{
public:
PagedLODWithNodeOperations( RefNodeOperationVector* postMergeOps );
public: // osg::Group
virtual bool addChild( osg::Node* child );
virtual bool insertChild( unsigned index, Node* child );
virtual bool replaceChild( Node* origChild, Node* newChild );
protected:
osg::observer_ptr<RefNodeOperationVector> _postMergeOps;
void runPostMerge( osg::Node* node );
};
/**
* Visitor that looks for empty group nodes and removes them from the
* scene graph. (Note, if the entry node is an empty group, it will
* not be affected.)
*/
class OSGEARTH_EXPORT RemoveEmptyGroupsVisitor : public osg::NodeVisitor
{
public:
static void run( osg::Node* entry ) {
if ( entry ) {
RemoveEmptyGroupsVisitor v;
entry->accept( v );
}
}
public:
RemoveEmptyGroupsVisitor();
void apply( osg::Group& group ); //override
};
/**
* Visitor that counts the number of point, line, and polygon primitive sets
* in a scene graph.
*/
class OSGEARTH_EXPORT PrimitiveSetTypeCounter : public osg::NodeVisitor
{
public:
PrimitiveSetTypeCounter();
/** dtor */
virtual ~PrimitiveSetTypeCounter() { }
void apply(class osg::Geode&);
unsigned _point;
unsigned _line;
unsigned _polygon;
};
/**
* Visitor that finds all the parental Camera Views, and calls an operator
* on each one.
*/
template<typename T>
class ViewVisitor : public osg::NodeVisitor, public T
{
public:
ViewVisitor() : osg::NodeVisitor(osg::NodeVisitor::TRAVERSE_PARENTS) { }
virtual ~ViewVisitor() { }
void apply(osg::Camera& cam) {
osg::View* view = cam.getView();
if ( view ) this->operator()( view );
traverse(cam);
}
};
/**
* Functor (for use with ViewVisitor) that notifies a view that it needs to
* redraw the scene because something has changed
* Usage: ViewVisitor<RequestRedraw> vis; node->accept(vis);
*/
struct RequestRedraw
{
void operator()(osg::View* view) {
osgGA::GUIActionAdapter* aa = dynamic_cast<osgGA::GUIActionAdapter*>(view);
if ( aa ) aa->requestRedraw();
}
};
/**
* Visitor that locates a node by its type
*/
template<typename T>
class FindTopMostNodeOfTypeVisitor : public osg::NodeVisitor
{
public:
FindTopMostNodeOfTypeVisitor():
osg::NodeVisitor(osg::NodeVisitor::TRAVERSE_ALL_CHILDREN),
_foundNode(0)
{}
void apply(osg::Node& node)
{
T* result = dynamic_cast<T*>(&node);
if (result)
{
_foundNode = result;
}
else
{
traverse(node);
}
}
T* _foundNode;
};
/**
* Collects all the nodes of type "T"
*/
template<typename T>
struct FindNodesVisitor : public osg::NodeVisitor
{
FindNodesVisitor() : osg::NodeVisitor(osg::NodeVisitor::TRAVERSE_ALL_CHILDREN) { }
void apply(osg::Node& node)
{
T* result = dynamic_cast<T*>( &node );
if ( result )
_results.push_back( result );
traverse(node);
}
std::vector<T*> _results;
};
/**
* Searchs the scene graph downward starting at [node] and returns the first node found
* that matches the template parameter type.
*/
template<typename T>
T* findTopMostNodeOfType(osg::Node* node, unsigned traversalMask =~0)
{
if (!node) return 0;
FindTopMostNodeOfTypeVisitor<T> fnotv;
fnotv.setTraversalMode(osg::NodeVisitor::TRAVERSE_ALL_CHILDREN);
fnotv.setTraversalMask(traversalMask);
node->accept(fnotv);
return fnotv._foundNode;
}
/**
* Searchs the scene graph upward starting at [node] and returns the first node found
* that matches the template parameter type.
*/
template<typename T>
T* findFirstParentOfType(osg::Node* node, unsigned traversalMask =~0)
{
if (!node) return 0;
FindTopMostNodeOfTypeVisitor<T> fnotv;
fnotv.setTraversalMode(osg::NodeVisitor::TRAVERSE_PARENTS);
fnotv.setTraversalMask(traversalMask);
node->accept(fnotv);
return fnotv._foundNode;
}
/**
* Searchs the scene graph starting at [node] and returns the first node found
* that matches the template parameter type. First searched upward, then downward.
*/
template<typename T>
T* findRelativeNodeOfType(osg::Node* node, unsigned traversalMask =~0)
{
if ( !node ) return 0;
T* result = findFirstParentOfType<T>( node, traversalMask );
if ( !result )
result = findTopMostNodeOfType<T>( node, traversalMask );
return result;
}
/**
* Replace one group with another
*/
inline void replaceGroup( osg::Group* oldGroup, osg::Group* newGroup )
{
if ( oldGroup && newGroup && oldGroup->getNumParents() > 0 )
{
for(unsigned i=0; i<oldGroup->getNumChildren(); ++i)
{
newGroup->addChild( oldGroup->getChild(0) );
}
osg::Node::ParentList parents = oldGroup->getParents();
for(osg::Node::ParentList::iterator i = parents.begin(); i != parents.end(); ++i )
{
(*i)->replaceChild( oldGroup, newGroup );
}
}
}
/**
* Remove all a group's children.
*/
inline void clearChildren( osg::Group* group )
{
if ( group )
group->removeChildren( 0, group->getNumChildren() );
}
/**
* OSG Group that keeps its children as observer_ptrs instead of ref_ptrs, and
* removes them when they deref.
*/
class OSGEARTH_EXPORT ObserverGroup : public osg::Group
{
public:
ObserverGroup();
virtual void traverse( osg::NodeVisitor& nv );
std::set<osg::Node*> _orphans;
};
/**
* Group that acts like a normal group but also notifies another
* object when a change occurs.
*/
template<typename T>
class NotifierGroup : public osg::Group
{
public:
NotifierGroup(T* listener) : _listener(listener) { }
virtual bool addChild( osg::Node* child ) {
bool ok = osg::Group::addChild(child);
if ( ok && _listener.valid() ) _listener->onGroupChanged(this);
return ok;
}
virtual bool insertChild( unsigned index, osg::Node* child ) {
bool ok = osg::Group::insertChild(index, child);
if ( ok && _listener.valid() ) _listener->onGroupChanged(this);
return ok;
}
virtual bool removeChild( osg::Node* child ) {
bool ok = osg::Group::removeChild( child );
if ( ok && _listener.valid() ) _listener->onGroupChanged(this);
return ok;
}
virtual bool replaceChild( osg::Node* origChild, osg::Node* newChild ) {
bool ok = osg::Group::replaceChild(origChild, newChild);
if ( ok && _listener.valid() ) _listener->onGroupChanged(this);
return ok;
}
protected:
virtual ~NotifierGroup() { }
osg::observer_ptr<T> _listener;
};
/**
* Adjusts a node's update traversal count by a delta.
* Only safe to call from the UPDATE thread
*/
#define ADJUST_UPDATE_TRAV_COUNT( NODE, DELTA ) \
{ \
int oldCount = NODE ->getNumChildrenRequiringUpdateTraversal(); \
if ( oldCount + DELTA >= 0 ) \
NODE ->setNumChildrenRequiringUpdateTraversal( (unsigned int)(oldCount + DELTA ) ); \
}
/**
* Adjusts a node's event traversal count by a delta.
* Only safe to call from the main/event/update threads
*/
#define ADJUST_EVENT_TRAV_COUNT( NODE, DELTA ) \
{ \
int oldCount = NODE ->getNumChildrenRequiringEventTraversal(); \
if ( oldCount + DELTA >= 0 ) \
NODE ->setNumChildrenRequiringEventTraversal( (unsigned int)(oldCount + DELTA ) ); \
}
}
#endif // OSGEARTH_CACHING_H
|