ProxyNode 6.2 KB

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