1/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
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 * (at your option) any later version. The full license is in LICENSE file
6 * included with this distribution, and on the openscenegraph.org website.
8 * This library is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * OpenSceneGraph Public License for more details.
15#define OSG_ProxyNode 1
23class OSG_EXPORT ProxyNode : public Group
29 /** Copy constructor using CopyOp to manage deep vs shallow copy.*/
30 ProxyNode(const ProxyNode&,const CopyOp& copyop=CopyOp::SHALLOW_COPY);
32 META_Node(osg, ProxyNode);
34 typedef osg::BoundingSphere::vec_type vec_type;
35 typedef osg::BoundingSphere::value_type value_type;
37 virtual void traverse(NodeVisitor& nv);
39 using osg::Group::addChild;
41 virtual bool addChild(Node *child);
43 virtual bool addChild(Node *child, const std::string& filename);
45 template<class T> bool addChild( const ref_ptr<T>& child, const std::string& filename) { return addChild(child.get(), filename); }
47 virtual bool removeChildren(unsigned int pos,unsigned int numChildrenToRemove);
50 /** Set the optional database osgDB::Options object to use when loading children.*/
51 void setDatabaseOptions(osg::Referenced* options) { _databaseOptions = options; }
53 /** Get the optional database osgDB::Options object used when loading children.*/
54 osg::Referenced* getDatabaseOptions() { return _databaseOptions.get(); }
56 /** Get the optional database osgDB::Options object used when loading children.*/
57 const osg::Referenced* getDatabaseOptions() const { return _databaseOptions.get(); }
60 /** Set the database path to prepend to children's filenames.*/
61 void setDatabasePath(const std::string& path);
62 /** Get the database path used to prepend to children's filenames.*/
63 inline const std::string& getDatabasePath() const { return _databasePath; }
65 void setFileName(unsigned int childNo, const std::string& filename) { expandFileNameListTo(childNo); _filenameList[childNo].first=filename; }
66 const std::string& getFileName(unsigned int childNo) const { return _filenameList[childNo].first; }
67 unsigned int getNumFileNames() const { return _filenameList.size(); }
69 /** Return the DatabaseRequest object used by the DatabasePager to keep track of file load requests
70 * being carried out on behalf of the DatabasePager.
71 * Note, in normal OSG usage you should not set this value yourself, as this will be managed by
72 * the osgDB::DatabasePager.*/
73 osg::ref_ptr<osg::Referenced>& getDatabaseRequest(unsigned int childNo) { return _filenameList[childNo].second; }
75 /** Return the const DatabaseRequest object.*/
76 const osg::ref_ptr<osg::Referenced>& getDatabaseRequest(unsigned int childNo) const { return _filenameList[childNo].second; }
79 /** Modes which control how the center of object should be determined when computing which child is active.*/
82 USE_BOUNDING_SPHERE_CENTER,
84 UNION_OF_BOUNDING_SPHERE_AND_USER_DEFINED
87 /** Set how the center of object should be determined when computing which child is active.*/
88 void setCenterMode(CenterMode mode) { _centerMode=mode; }
90 /** Get how the center of object should be determined when computing which child is active.*/
91 CenterMode getCenterMode() const { return _centerMode; }
93 /** Modes which control how the proxynode external reference are loaded.*/
94 enum LoadingExternalReferenceMode
97 DEFER_LOADING_TO_DATABASE_PAGER,
101 /** Set how the child loading is done.*/
102 void setLoadingExternalReferenceMode(LoadingExternalReferenceMode mode) { _loadingExtReference=mode; }
104 /** Get the loading mode.*/
105 LoadingExternalReferenceMode getLoadingExternalReferenceMode() const { return _loadingExtReference; }
107 /** Sets the object-space point which defines the center of the osg::ProxyNode.
108 Center is affected by any transforms in the hierarchy above the osg::ProxyNode.*/
109 inline void setCenter(const vec_type& center) { if (_centerMode!=UNION_OF_BOUNDING_SPHERE_AND_USER_DEFINED) { _centerMode=USER_DEFINED_CENTER; } _userDefinedCenter = center; }
111 /** Return the ProxyNode center point. */
112 inline const vec_type& getCenter() const { if ((_centerMode==USER_DEFINED_CENTER)||(_centerMode==UNION_OF_BOUNDING_SPHERE_AND_USER_DEFINED)) return _userDefinedCenter; else return getBound().center(); }
115 /** Set the object-space reference radius of the volume enclosed by the ProxyNode.
116 * Used to determine the bounding sphere of the ProxyNode in the absence of any children.*/
117 inline void setRadius(value_type radius) { _radius = radius; }
119 /** Get the object-space radius of the volume enclosed by the ProxyNode.*/
120 inline value_type getRadius() const { return _radius; }
122 virtual BoundingSphere computeBound() const;
126 virtual ~ProxyNode() {}
128 void expandFileNameListTo(unsigned int pos);
130 typedef std::pair< std::string, osg::ref_ptr<osg::Referenced> > FileNameDatabaseRequestPair;
131 typedef std::vector<FileNameDatabaseRequestPair> FileNameDatabaseRequestList;
133 FileNameDatabaseRequestList _filenameList;
134 ref_ptr<Referenced> _databaseOptions;
135 std::string _databasePath;
137 LoadingExternalReferenceMode _loadingExtReference;
139 CenterMode _centerMode;
140 vec_type _userDefinedCenter;