root/OpenSceneGraph/trunk/include/osg/PagedLOD @ 10174

Revision 10174, 7.5 kB (checked in by robert, 6 years ago)

Moved Registry::ReadFileCallback? + WriteFileCallback?, and osgDB::ReaderWriter::Options into their own separate Options file and into the osgDB namespace.

Introduced a new callback osgDB::FindFileCallback? that overrides the default behavior of findDataFile/findLibraryFile.

Introduced support for assigning ReaderWriter::Options directory to PagedLOD.

Introduced new osgDB::FileLocationCallback? for assistancing the DatabasePager? to know when a file is hosted on a local or remote file system.

  • 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_PagedLOD
15#define OSG_PagedLOD 1
16
17#include <osg/LOD>
18
19namespace osg {
20
21/** PagedLOD.
22*/
23class OSG_EXPORT PagedLOD : public LOD
24{
25    public :
26   
27        PagedLOD();
28
29        /** Copy constructor using CopyOp to manage deep vs shallow copy.*/
30        PagedLOD(const PagedLOD&,const CopyOp& copyop=CopyOp::SHALLOW_COPY);
31
32        META_Node(osg, PagedLOD);
33       
34       
35
36        virtual void traverse(NodeVisitor& nv);
37       
38        virtual bool addChild(Node *child);
39
40        virtual bool addChild(Node *child, float min, float max);
41
42        virtual bool addChild(Node *child, float min, float max,const std::string& filename, float priorityOffset=0.0f, float priorityScale=1.0f);
43
44        virtual bool removeChildren(unsigned int pos,unsigned int numChildrenToRemove=1);
45
46
47        /** Set the optional database osgDB::Options object to use when loaded children.*/
48        void setDatabaseOptions(osg::Referenced* options) { _databaseOptions = options; }
49
50        /** Get the optional database osgDB::Options object used when loaded children.*/
51        osg::Referenced* getDatabaseOptions() { return _databaseOptions.get(); }
52
53        /** Get the optional database osgDB::Options object used when loaded children.*/
54        const osg::Referenced* getDatabaseOptions() const { return _databaseOptions.get(); }
55
56
57        /** Set the database path to prepend to children's filenames.*/
58        void setDatabasePath(const std::string& path);
59
60        /** Get the database path used to prepend to children's filenames.*/
61        inline const std::string& getDatabasePath() const { return _databasePath; }
62
63       
64        struct OSG_EXPORT PerRangeData
65        {
66            PerRangeData();
67            PerRangeData(const PerRangeData& prd);
68            PerRangeData& operator = (const PerRangeData& prd);
69
70            std::string                     _filename;
71            float                           _priorityOffset;
72            float                           _priorityScale;
73            double                          _timeStamp;
74            int                             _frameNumber;
75            int                             _frameNumberOfLastReleaseGLObjects;
76            osg::ref_ptr<osg::Referenced>   _databaseRequest;
77        };
78
79        typedef std::vector<PerRangeData> PerRangeDataList;
80       
81        void setFileName(unsigned int childNo, const std::string& filename) { expandPerRangeDataTo(childNo); _perRangeDataList[childNo]._filename=filename; }
82        const std::string& getFileName(unsigned int childNo) const { return _perRangeDataList[childNo]._filename; }
83        unsigned int getNumFileNames() const { return _perRangeDataList.size(); }
84
85
86        void setPriorityOffset(unsigned int childNo, float priorityOffset) { expandPerRangeDataTo(childNo); _perRangeDataList[childNo]._priorityOffset=priorityOffset; }
87        float getPriorityOffset(unsigned int childNo) const { return _perRangeDataList[childNo]._priorityOffset; }
88        unsigned int getNumPriorityOffsets() const { return _perRangeDataList.size(); }
89
90        void setPriorityScale(unsigned int childNo, float priorityScale) { expandPerRangeDataTo(childNo); _perRangeDataList[childNo]._priorityScale=priorityScale; }
91        float getPriorityScale(unsigned int childNo) const { return _perRangeDataList[childNo]._priorityScale; }
92        unsigned int getNumPriorityScales() const { return _perRangeDataList.size(); }
93
94
95        void setTimeStamp(unsigned int childNo, double timeStamp) { expandPerRangeDataTo(childNo); _perRangeDataList[childNo]._timeStamp=timeStamp; }
96        double getTimeStamp(unsigned int childNo) const { return _perRangeDataList[childNo]._timeStamp; }
97        unsigned int getNumTimeStamps() const { return _perRangeDataList.size(); }
98
99        void setFrameNumber(unsigned int childNo, int frameNumber) { expandPerRangeDataTo(childNo); _perRangeDataList[childNo]._frameNumber=frameNumber; }
100        double getFrameNumber(unsigned int childNo) const { return _perRangeDataList[childNo]._frameNumber; }
101        unsigned int getNumFrameNumbers() const { return _perRangeDataList.size(); }
102
103
104        /** Return the DatabaseRequest object used by the DatabasePager to keep track of file load requests
105          * being carried on behalf of the DatabasePager.
106          * Note, in normal OSG usage you should not set this value yourself, as this will be managed by
107          * the osgDB::DatabasePager.*/
108        osg::ref_ptr<osg::Referenced>& getDatabaseRequest(unsigned int childNo) { return _perRangeDataList[childNo]._databaseRequest; }
109       
110        /** Return the const DatabaseRequest object.*/
111        const osg::ref_ptr<osg::Referenced>& getDatabaseRequest(unsigned int childNo) const { return _perRangeDataList[childNo]._databaseRequest; }
112
113
114        /** Set the frame number of the last time that this PageLOD node was traversed.
115          * Note, this frame number is automatically set by the traverse() method for all traversals (update, cull etc.).
116          */
117        inline void setFrameNumberOfLastTraversal(int frameNumber) { _frameNumberOfLastTraversal=frameNumber; }
118
119        /** Get the frame number of the last time that this PageLOD node was traversed.*/
120        inline int getFrameNumberOfLastTraversal() const { return _frameNumberOfLastTraversal; }
121
122
123        /** Set the number of children that the PagedLOD must keep around, even if they are older than their expiry time.*/
124        inline void setNumChildrenThatCannotBeExpired(unsigned int num) { _numChildrenThatCannotBeExpired = num; }
125
126        /** Get the number of children that the PagedLOD must keep around, even if they are older than their expiry time.*/
127        unsigned int getNumChildrenThatCannotBeExpired() const { return _numChildrenThatCannotBeExpired; }
128
129        /** Remove the children from the PagedLOD which haven't been visited since specified expiry time and expiry frame number.
130          * The removed children are added to the removeChildren list passed into the method,
131          * this allows the children to be deleted later at the caller's discretion.
132          * Return true if children are removed, false otherwise. */
133        virtual bool removeExpiredChildren(double expiryTime, int expiryFrame, NodeList& removedChildren);
134
135        /** Release the GL Objects of the children from the PagedLOD which haven't been visited since specified expiry time and expiry frame number.
136          * Return true if any children have release called upon them, false otherwise. */
137        virtual bool releaseGLObjectsOnExpiredChildren(double releaseTime, int releaseFrame);
138       
139    protected :
140   
141        virtual ~PagedLOD();
142       
143        void expandPerRangeDataTo(unsigned int pos);
144
145        ref_ptr<Referenced> _databaseOptions;
146        std::string         _databasePath;
147
148        int                 _frameNumberOfLastTraversal;
149        unsigned int        _numChildrenThatCannotBeExpired;
150        PerRangeDataList    _perRangeDataList;
151};
152
153}
154
155#endif
Note: See TracBrowser for help on using the browser.