| 1 | /* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield |
|---|
| 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 |
|---|
| 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. |
|---|
| 7 | * |
|---|
| 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. |
|---|
| 12 | */ |
|---|
| 13 | |
|---|
| 14 | #ifndef OSG_ProxyNode |
|---|
| 15 | #define OSG_ProxyNode 1 |
|---|
| 16 | |
|---|
| 17 | #include <osg/Group> |
|---|
| 18 | |
|---|
| 19 | namespace osg { |
|---|
| 20 | |
|---|
| 21 | /** ProxyNode. |
|---|
| 22 | */ |
|---|
| 23 | class OSG_EXPORT ProxyNode : public Group |
|---|
| 24 | { |
|---|
| 25 | public : |
|---|
| 26 | |
|---|
| 27 | ProxyNode(); |
|---|
| 28 | |
|---|
| 29 | /** Copy constructor using CopyOp to manage deep vs shallow copy.*/ |
|---|
| 30 | ProxyNode(const ProxyNode&,const CopyOp& copyop=CopyOp::SHALLOW_COPY); |
|---|
| 31 | |
|---|
| 32 | META_Node(osg, ProxyNode); |
|---|
| 33 | |
|---|
| 34 | typedef osg::BoundingSphere::vec_type vec_type; |
|---|
| 35 | typedef osg::BoundingSphere::value_type value_type; |
|---|
| 36 | |
|---|
| 37 | virtual void traverse(NodeVisitor& nv); |
|---|
| 38 | |
|---|
| 39 | virtual bool addChild(Node *child); |
|---|
| 40 | virtual bool addChild(Node *child, const std::string& filename); |
|---|
| 41 | |
|---|
| 42 | virtual bool removeChildren(unsigned int pos,unsigned int numChildrenToRemove); |
|---|
| 43 | |
|---|
| 44 | |
|---|
| 45 | /** Set the optional database osgDB::Options object to use when loaded children.*/ |
|---|
| 46 | void setDatabaseOptions(osg::Referenced* options) { _databaseOptions = options; } |
|---|
| 47 | |
|---|
| 48 | /** Get the optional database osgDB::Options object used when loaded children.*/ |
|---|
| 49 | osg::Referenced* getDatabaseOptions() { return _databaseOptions.get(); } |
|---|
| 50 | |
|---|
| 51 | /** Get the optional database osgDB::Options object used when loaded children.*/ |
|---|
| 52 | const osg::Referenced* getDatabaseOptions() const { return _databaseOptions.get(); } |
|---|
| 53 | |
|---|
| 54 | |
|---|
| 55 | /** Set the database path to prepend to children's filenames.*/ |
|---|
| 56 | void setDatabasePath(const std::string& path); |
|---|
| 57 | /** Get the database path used to prepend to children's filenames.*/ |
|---|
| 58 | inline const std::string& getDatabasePath() const { return _databasePath; } |
|---|
| 59 | |
|---|
| 60 | void setFileName(unsigned int childNo, const std::string& filename) { expandFileNameListTo(childNo); _filenameList[childNo].first=filename; } |
|---|
| 61 | const std::string& getFileName(unsigned int childNo) const { return _filenameList[childNo].first; } |
|---|
| 62 | unsigned int getNumFileNames() const { return _filenameList.size(); } |
|---|
| 63 | |
|---|
| 64 | /** Return the DatabaseRequest object used by the DatabasePager to keep track of file load requests |
|---|
| 65 | * being carried on behalf of the DatabasePager. |
|---|
| 66 | * Note, in normal OSG usage you should not set this value yourself, as this will be managed by |
|---|
| 67 | * the osgDB::DatabasePager.*/ |
|---|
| 68 | osg::ref_ptr<osg::Referenced>& getDatabaseRequest(unsigned int childNo) { return _filenameList[childNo].second; } |
|---|
| 69 | |
|---|
| 70 | /** Return the const DatabaseRequest object.*/ |
|---|
| 71 | const osg::ref_ptr<osg::Referenced>& getDatabaseRequest(unsigned int childNo) const { return _filenameList[childNo].second; } |
|---|
| 72 | |
|---|
| 73 | |
|---|
| 74 | /** Modes which control how the center of object should be determined when computed which child is active.*/ |
|---|
| 75 | enum CenterMode |
|---|
| 76 | { |
|---|
| 77 | USE_BOUNDING_SPHERE_CENTER, |
|---|
| 78 | USER_DEFINED_CENTER, |
|---|
| 79 | UNION_OF_BOUNDING_SPHERE_AND_USER_DEFINED |
|---|
| 80 | }; |
|---|
| 81 | |
|---|
| 82 | /** Set how the center of object should be determined when computed which child is active.*/ |
|---|
| 83 | void setCenterMode(CenterMode mode) { _centerMode=mode; } |
|---|
| 84 | |
|---|
| 85 | /** Get how the center of object should be determined when computed which child is active.*/ |
|---|
| 86 | CenterMode getCenterMode() const { return _centerMode; } |
|---|
| 87 | |
|---|
| 88 | /** Modes which control how the proxynode external reference are loaded.*/ |
|---|
| 89 | enum LoadingExternalReferenceMode |
|---|
| 90 | { |
|---|
| 91 | LOAD_IMMEDIATELY, |
|---|
| 92 | DEFER_LOADING_TO_DATABASE_PAGER, |
|---|
| 93 | NO_AUTOMATIC_LOADING |
|---|
| 94 | }; |
|---|
| 95 | |
|---|
| 96 | /** Set how the child loading is done.*/ |
|---|
| 97 | void setLoadingExternalReferenceMode(LoadingExternalReferenceMode mode) { _loadingExtReference=mode; } |
|---|
| 98 | |
|---|
| 99 | /** Get the setted mode of loading.*/ |
|---|
| 100 | LoadingExternalReferenceMode getLoadingExternalReferenceMode() const { return _loadingExtReference; } |
|---|
| 101 | |
|---|
| 102 | /** Sets the object-space point which defines the center of the osg::ProxyNode. |
|---|
| 103 | center is affected by any transforms in the hierarchy above the osg::ProxyNode.*/ |
|---|
| 104 | inline void setCenter(const vec_type& center) { if (_centerMode!=UNION_OF_BOUNDING_SPHERE_AND_USER_DEFINED) { _centerMode=USER_DEFINED_CENTER; } _userDefinedCenter = center; } |
|---|
| 105 | |
|---|
| 106 | /** return the ProxyNode center point. */ |
|---|
| 107 | 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(); } |
|---|
| 108 | |
|---|
| 109 | |
|---|
| 110 | /** Set the object-space reference radius of the volume enclosed by the ProxyNode. |
|---|
| 111 | * Used to determine the bounding sphere of the ProxyNode in the absence of any children.*/ |
|---|
| 112 | inline void setRadius(value_type radius) { _radius = radius; } |
|---|
| 113 | |
|---|
| 114 | /** Get the object-space radius of the volume enclosed by the ProxyNode.*/ |
|---|
| 115 | inline value_type getRadius() const { return _radius; } |
|---|
| 116 | |
|---|
| 117 | virtual BoundingSphere computeBound() const; |
|---|
| 118 | |
|---|
| 119 | protected : |
|---|
| 120 | |
|---|
| 121 | virtual ~ProxyNode() {} |
|---|
| 122 | |
|---|
| 123 | void expandFileNameListTo(unsigned int pos); |
|---|
| 124 | |
|---|
| 125 | typedef std::pair< std::string, osg::ref_ptr<osg::Referenced> > FileNameDatabaseRequestPair; |
|---|
| 126 | typedef std::vector<FileNameDatabaseRequestPair> FileNameDatabaseRequestList; |
|---|
| 127 | |
|---|
| 128 | FileNameDatabaseRequestList _filenameList; |
|---|
| 129 | ref_ptr<Referenced> _databaseOptions; |
|---|
| 130 | std::string _databasePath; |
|---|
| 131 | |
|---|
| 132 | LoadingExternalReferenceMode _loadingExtReference; |
|---|
| 133 | |
|---|
| 134 | CenterMode _centerMode; |
|---|
| 135 | vec_type _userDefinedCenter; |
|---|
| 136 | value_type _radius; |
|---|
| 137 | |
|---|
| 138 | }; |
|---|
| 139 | |
|---|
| 140 | } |
|---|
| 141 | |
|---|
| 142 | #endif |
|---|