Changeset 13041 for OpenSceneGraph/trunk/include/osg/NodeVisitor
- Timestamp:
- 03/21/12 18:36:20 (14 months ago)
- Files:
-
- 1 modified
-
OpenSceneGraph/trunk/include/osg/NodeVisitor (modified) (22 diffs)
Legend:
- Unmodified
- Added
- Removed
-
OpenSceneGraph/trunk/include/osg/NodeVisitor
r12080 r13041 1 /* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield 1 /* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield 2 2 * 3 * This library is open source and may be redistributed and/or modified under 4 * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or 3 * This library is open source and may be redistributed and/or modified under 4 * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or 5 5 * (at your option) any later version. The full license is in LICENSE file 6 6 * included with this distribution, and on the openscenegraph.org website. 7 * 7 * 8 8 * This library is distributed in the hope that it will be useful, 9 9 * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 11 * OpenSceneGraph Public License for more details. 12 12 */ … … 50 50 51 51 /** Visitor for type safe operations on osg::Nodes. 52 Based on GOF's Visitor pattern. The NodeVisitor 52 Based on GOF's Visitor pattern. The NodeVisitor 53 53 is useful for developing type safe operations to nodes 54 54 in the scene graph (as per Visitor pattern), and adds to this … … 62 62 myVisitor.apply(*root). The later method will bypass the double 63 63 dispatch and the appropriate NodeVisitor::apply(..) method will 64 not be called. */ 64 not be called. */ 65 65 class OSG_EXPORT NodeVisitor : public virtual Referenced 66 66 { … … 74 74 TRAVERSE_ACTIVE_CHILDREN 75 75 }; 76 76 77 77 enum VisitorType 78 78 { … … 85 85 86 86 NodeVisitor(TraversalMode tm=TRAVERSE_NONE); 87 87 88 88 NodeVisitor(VisitorType type,TraversalMode tm=TRAVERSE_NONE); 89 89 90 90 virtual ~NodeVisitor(); 91 91 92 92 /** return the library name/namespapce of the visitor's. Should be defined by derived classes.*/ 93 93 virtual const char* libraryName() const { return "osg"; } … … 97 97 98 98 /** Method to call to reset visitor. Useful if your visitor accumulates 99 state during a traversal, and you plan to reuse the visitor. 99 state during a traversal, and you plan to reuse the visitor. 100 100 To flush that state for the next traversal: call reset() prior 101 101 to each traversal.*/ … … 107 107 * to select which behaviour to use for different types of traversal/visitors.*/ 108 108 inline void setVisitorType(VisitorType type) { _visitorType = type; } 109 109 110 110 /** Get the VisitorType.*/ 111 111 inline VisitorType getVisitorType() const { return _visitorType; } … … 113 113 /** Set the traversal number. Typically used to denote the frame count.*/ 114 114 inline void setTraversalNumber(unsigned int fn) { _traversalNumber = fn; } 115 115 116 116 /** Get the traversal number. Typically used to denote the frame count.*/ 117 117 inline unsigned int getTraversalNumber() const { return _traversalNumber; } … … 119 119 /** Set the FrameStamp that this traversal is associated with.*/ 120 120 inline void setFrameStamp(FrameStamp* fs) { _frameStamp = fs; } 121 121 122 122 /** Get the FrameStamp that this traversal is associated with.*/ 123 123 inline const FrameStamp* getFrameStamp() const { return _frameStamp.get(); } … … 139 139 140 140 /** Set the NodeMaskOverride mask. 141 * Used in validNodeMask() to determine whether to operate on a node or its 141 * Used in validNodeMask() to determine whether to operate on a node or its 142 142 * subgraph, by OR'ing NodeVisitor::_nodeMaskOverride with the Node's own Node::_nodeMask. 143 143 * Typically used to force on nodes which may have … … 147 147 /** Get the NodeMaskOverride mask.*/ 148 148 inline Node::NodeMask getNodeMaskOverride() const { return _nodeMaskOverride; } 149 149 150 150 /** Method to called by Node and its subclass' Node::accept() method, if the result is true 151 151 * it is used to cull operations of nodes and their subgraphs. … … 159 159 } 160 160 161 /** Set the traversal mode for Node::traverse() to use when 161 /** Set the traversal mode for Node::traverse() to use when 162 162 deciding which children of a node to traverse. If a 163 163 NodeVisitor has been attached via setTraverseVisitor() … … 165 165 visitor is detached. Default mode is TRAVERSE_NONE.*/ 166 166 inline void setTraversalMode(TraversalMode mode) { _traversalMode = mode; } 167 167 168 168 /** Get the traversal mode.*/ 169 169 inline TraversalMode getTraversalMode() const { return _traversalMode; } … … 171 171 /** 172 172 * Set user data, data must be subclassed from Referenced to allow 173 * automatic memory handling. If your own data isn't directly 173 * automatic memory handling. If your own data isn't directly 174 174 * subclassed from Referenced then create an adapter object 175 175 * which points to your own objects and handles the memory addressing. 176 176 */ 177 177 inline void setUserData(Referenced* obj) { _userData = obj; } 178 178 179 179 /** Get user data.*/ 180 180 inline Referenced* getUserData() { return _userData.get(); } 181 181 182 182 /** Get const user data.*/ 183 183 inline const Referenced* getUserData() const { return _userData.get(); } … … 185 185 186 186 /** Method for handling traversal of a nodes. 187 If you intend to use the visitor for actively traversing 187 If you intend to use the visitor for actively traversing 188 188 the scene graph then make sure the accept() methods call 189 189 this method unless they handle traversal directly.*/ … … 193 193 else if (_traversalMode!=TRAVERSE_NONE) node.traverse(*this); 194 194 } 195 195 196 196 /** Method called by osg::Node::accept() method before 197 197 * a call to the NodeVisitor::apply(..). The back of the list will, 198 198 * therefore, be the current node being visited inside the apply(..), 199 * and the rest of the list will be the parental sequence of nodes 199 * and the rest of the list will be the parental sequence of nodes 200 200 * from the top most node applied down the graph to the current node. 201 201 * Note, the user does not typically call pushNodeOnPath() as it 202 202 * will be called automatically by the Node::accept() method.*/ 203 203 inline void pushOntoNodePath(Node* node) { if (_traversalMode!=TRAVERSE_PARENTS) _nodePath.push_back(node); else _nodePath.insert(_nodePath.begin(),node); } 204 204 205 205 /** Method called by osg::Node::accept() method after 206 206 * a call to NodeVisitor::apply(..). … … 208 208 * will be called automatically by the Node::accept() method.*/ 209 209 inline void popFromNodePath() { if (_traversalMode!=TRAVERSE_PARENTS) _nodePath.pop_back(); else _nodePath.erase(_nodePath.begin()); } 210 210 211 211 /** Get the non const NodePath from the top most node applied down 212 212 * to the current Node being visited.*/ … … 216 216 * to the current Node being visited.*/ 217 217 const NodePath& getNodePath() const { return _nodePath; } 218 218 219 219 /** Get the eye point in local coordinates. 220 220 * Note, not all NodeVisitor implement this method, it is mainly cull visitors which will implement.*/ … … 239 239 * If the getDistanceToViewPoint(pos) is not implemented then a default value of 0.0 is returned.*/ 240 240 virtual float getDistanceToViewPoint(const Vec3& /*pos*/, bool /*useLODScale*/) const { return 0.0f; } 241 241 242 242 243 243 virtual void apply(Node& node); 244 244 245 245 virtual void apply(Geode& node); 246 246 virtual void apply(Billboard& node); 247 247 248 248 virtual void apply(Group& node); 249 249 … … 301 301 { 302 302 public: 303 303 304 304 ImageRequestHandler(): 305 305 Referenced(true) {} 306 306 307 307 virtual double getPreLoadTime() const = 0; 308 308 309 309 virtual osg::Image* readImageFile(const std::string& fileName) = 0; 310 310 311 311 virtual void requestImageFile(const std::string& fileName,osg::Object* attachmentPoint, int attachmentIndex, double timeToMergeBy, const FrameStamp* framestamp) = 0; 312 312 313 313 protected: 314 314 virtual ~ImageRequestHandler() {} 315 315 }; 316 316 317 317 /** Set the handler for image requests.*/ 318 318 void setImageRequestHandler(ImageRequestHandler* handler) { _imageRequestHandler = handler; } 319 319 320 320 /** Get the handler for image requests.*/ 321 321 ImageRequestHandler* getImageRequestHandler() { return _imageRequestHandler.get(); } … … 330 330 VisitorType _visitorType; 331 331 unsigned int _traversalNumber; 332 332 333 333 ref_ptr<FrameStamp> _frameStamp; 334 334 335 335 TraversalMode _traversalMode; 336 336 Node::NodeMask _traversalMask; 337 337 Node::NodeMask _nodeMaskOverride; 338 338 339 339 NodePath _nodePath; 340 340 … … 347 347 348 348 349 /** Convenience functor for assisting visiting of arrays of osg::Node's.*/ 349 /** Convenience functor for assisting visiting of arrays of osg::Node's.*/ 350 350 class NodeAcceptOp 351 351 {
