root/OpenSceneGraph/trunk/include/osg/ProxyNode @ 8325

Revision 8325, 5.4 kB (checked in by robert, 6 years ago)

Refactored DatabasePager? and related classes to introduce support for
multi-threaded paging, where the Pager manages threads of reading local
and http files via seperate threads. This makes it possible to smoothly
browse large databases where parts of the data are locally cached while
others are on a remote server. Previously with this type of dataset
the pager would stall all paging while http requests were being served,
even when parts of the models are still loadable virtue of being in the
local cache.

Also as part of the refactoring the DatabaseRequest? are now stored in the
ProxyNode?/PagedLOD nodes to facilitate quite updating in the cull traversal,
with the new code avoiding mutex locks and searches. Previous on big
databases the overhead involved in make database requests could accumulate
to a point where it'd cause the cull traversal to break frame. The overhead
now is negligable.

Finally OSG_FILE_CACHE support has been moved from the curl plugin into
the DatabasePager?. Eventually this functionality will be moved out into
osgDB for more general usage.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
Line 
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
19namespace osg {
20
21/** ProxyNode.
22*/
23class 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        /** Set the database path to prepend to children's filenames.*/
45        void setDatabasePath(const std::string& path);
46        /** Get the database path used to prepend to children's filenames.*/
47        inline const std::string& getDatabasePath() const { return _databasePath; }
48
49        void setFileName(unsigned int childNo, const std::string& filename) { expandFileNameListTo(childNo); _filenameList[childNo].first=filename; }
50        const std::string& getFileName(unsigned int childNo) const { return _filenameList[childNo].first; }
51        unsigned int getNumFileNames() const { return _filenameList.size(); }
52
53        /** Return the DatabaseRequest object used by the DatabasePager to keep track of file load requests
54          * being carried on behalf of the DatabasePager.
55          * Note, in normal OSG usage you should not set this value yourself, as this will be managed by
56          * the osgDB::DatabasePager.*/
57        osg::ref_ptr<osg::Referenced>& getDatabaseRequest(unsigned int childNo) { return _filenameList[childNo].second; }
58       
59        /** Return the const DatabaseRequest object.*/
60        const osg::ref_ptr<osg::Referenced>& getDatabaseRequest(unsigned int childNo) const { return _filenameList[childNo].second; }
61
62
63        /** Modes which control how the center of object should be determined when computed which child is active.*/
64        enum CenterMode
65        {
66            USE_BOUNDING_SPHERE_CENTER,
67            USER_DEFINED_CENTER
68        };
69
70        /** Set how the center of object should be determined when computed which child is active.*/
71        void setCenterMode(CenterMode mode) { _centerMode=mode; }
72
73        /** Get how the center of object should be determined when computed which child is active.*/
74        CenterMode getCenterMode() const { return _centerMode; }
75       
76        /** Modes which control how the proxynode external reference are loaded.*/
77        enum LoadingExternalReferenceMode
78        {
79            LOAD_IMMEDIATELY,
80            DEFER_LOADING_TO_DATABASE_PAGER,
81            NO_AUTOMATIC_LOADING
82        };
83
84        /** Set how the child loading is done.*/
85        void setLoadingExternalReferenceMode(LoadingExternalReferenceMode mode) { _loadingExtReference=mode; }
86
87        /** Get the setted mode of loading.*/
88        LoadingExternalReferenceMode getLoadingExternalReferenceMode() const { return _loadingExtReference; }
89
90        /** Sets the object-space point which defines the center of the osg::ProxyNode. 
91            center is affected by any transforms in the hierarchy above the osg::ProxyNode.*/
92        inline void setCenter(const Vec3& center) { _centerMode=USER_DEFINED_CENTER; _userDefinedCenter = center; }
93       
94        /** return the ProxyNode center point. */
95        inline const vec_type& getCenter() const { if (_centerMode==USER_DEFINED_CENTER) return _userDefinedCenter; else return getBound().center(); }
96
97
98        /** Set the object-space reference radius of the volume enclosed by the ProxyNode.
99          * Used to determine the bounding sphere of the ProxyNode in the absence of any children.*/
100        inline void setRadius(value_type radius) { _radius = radius; }
101       
102        /** Get the object-space radius of the volume enclosed by the ProxyNode.*/
103        inline value_type getRadius() const { return _radius; }
104
105        virtual BoundingSphere computeBound() const;
106
107    protected :
108   
109        virtual ~ProxyNode() {}
110
111        void expandFileNameListTo(unsigned int pos);
112
113        typedef std::pair< std::string, osg::ref_ptr<osg::Referenced> >  FileNameDatabaseRequestPair;
114        typedef std::vector<FileNameDatabaseRequestPair>                 FileNameDatabaseRequestList;
115
116        FileNameDatabaseRequestList     _filenameList;
117        std::string                     _databasePath;
118       
119        LoadingExternalReferenceMode    _loadingExtReference;
120       
121        CenterMode                      _centerMode;
122        vec_type                        _userDefinedCenter;
123        value_type                      _radius;
124       
125};
126
127}
128
129#endif
Note: See TracBrowser for help on using the browser.