Added new Node/Drawable::s/getInitialBound and Node/Drawable::s/getComputeBoundCallback

methods and reimplement computeBound so that it passes back a bounding volume rather
than modifying the local one.
This commit is contained in:
Robert Osfield
2005-05-12 14:03:22 +00:00
parent ad2bd31ac8
commit bf4d63f6ea
52 changed files with 337 additions and 377 deletions

View File

@@ -97,12 +97,12 @@ class OSG_EXPORT Billboard : public Geode
bool computeMatrix(Matrix& modelview, const Vec3& eye_local, const Vec3& pos_local) const;
virtual BoundingSphere computeBound() const;
protected:
virtual ~Billboard();
virtual bool computeBound() const;
enum AxisAligned
{
AXIAL_ROT_X_AXIS=AXIAL_ROT+1,

View File

@@ -40,6 +40,12 @@ class OSG_EXPORT BoundingSphere
/** Creates a bounding sphere initialized to the given extents. */
BoundingSphere(const Vec3& center,float radius) : _center(center),_radius(radius) {}
/** Creates a bounding sphere initialized to the given extents. */
BoundingSphere(const BoundingSphere& bs) : _center(bs._center),_radius(bs._radius) {}
/** Creates a bounding sphere initialized to the given extents. */
BoundingSphere(const BoundingBox& bb) : _center(0.0f,0.0f,0.0f),_radius(-1.0f) { expandBy(bb); }
/** Clear the bounding sphere. Reset to default values. */
inline void init()
{

View File

@@ -75,12 +75,12 @@ class OSG_EXPORT ClipNode : public Group
/** Set up the local StateSet. */
void setLocalStateSetModes(StateAttribute::GLModeValue=StateAttribute::ON);
virtual BoundingSphere computeBound() const;
protected:
virtual ~ClipNode();
virtual bool computeBound() const;
StateAttribute::GLModeValue _value;
ClipPlaneList _planes;
};

View File

@@ -59,15 +59,14 @@ class OSG_EXPORT DrawPixels : public Drawable
virtual void drawImplementation(State& state) const;
virtual BoundingBox computeBound() const;
protected:
DrawPixels& operator = (const DrawPixels&) { return *this;}
virtual ~DrawPixels();
virtual bool computeBound() const;
Vec3 _position;
ref_ptr<Image> _image;

View File

@@ -149,6 +149,12 @@ class OSG_EXPORT Drawable : public Object
StateSet* getOrCreateStateSet();
/** Set the intial bounding volume to use when computing the overall bounding volume.*/
void setInitialBound(const osg::BoundingBox& bbox) { _initialBound = bbox; dirtyBound(); }
/** Set the intial bounding volume to use when computing the overall bounding volume.*/
const BoundingBox& getInitialBound() const { return _initialBound; }
/** Dirty the bounding box, forcing a computeBound() on the next call
* to getBound(). Should be called in the internal geometry of the Drawable
* is modified.*/
@@ -160,12 +166,39 @@ class OSG_EXPORT Drawable : public Object
*/
inline const BoundingBox& getBound() const
{
if( !_bbox_computed)
computeBound();
return _bbox;
if(!_boundingBoxComputed)
{
_boundingBox = _initialBound;
if (_computeBoundCallback.valid())
_boundingBox.expandBy(_computeBoundCallback->computeBound(*this));
else
_boundingBox.expandBy(computeBound());
_boundingBoxComputed = true;
}
return _boundingBox;
}
/** Compute the bounding box around Drawables's geometry.*/
virtual BoundingBox computeBound() const;
/** Callback to allow users to override the default computation of bounding volume.*/
struct ComputeBoundCallback : public osg::Referenced
{
virtual BoundingBox computeBound(const osg::Drawable&) const = 0;
};
/** Set the compute bound callback to override the default computeBound.*/
void setComputeBoundCallback(ComputeBoundCallback* callback) { _computeBoundCallback = callback; }
/** Get the compute bound callback.*/
ComputeBoundCallback* getComputeBoundCallback() { return _computeBoundCallback.get(); }
/** Get the const compute bound callback.*/
const ComputeBoundCallback* getComputeBoundCallback() const { return _computeBoundCallback.get(); }
/** Set the Shape of the \c Drawable. The shape can be used to
* speed up collision detection or as a guide for procedural
* geometry generation.
@@ -694,9 +727,6 @@ class OSG_EXPORT Drawable : public Object
virtual ~Drawable();
/** Compute the bounding box of the drawable. Method must be
implemented by subclasses.*/
virtual bool computeBound() const;
/** set the bounding box .*/
void setBound(const BoundingBox& bb) const;
@@ -711,10 +741,12 @@ class OSG_EXPORT Drawable : public Object
ref_ptr<StateSet> _stateset;
mutable BoundingBox _bbox;
mutable bool _bbox_computed;
BoundingBox _initialBound;
ref_ptr<ComputeBoundCallback> _computeBoundCallback;
mutable BoundingBox _boundingBox;
mutable bool _boundingBoxComputed;
ref_ptr<Shape> _shape;
ref_ptr<Shape> _shape;
bool _supportsDisplayList;
bool _useDisplayList;

View File

@@ -128,20 +128,22 @@ class OSG_EXPORT Geode : public Node
* bounding boxes of the geode's drawables.*/
inline const BoundingBox& getBoundingBox() const
{
if(!_bsphere_computed) computeBound();
if(!_boundingSphereComputed) getBound();
return _bbox;
}
virtual BoundingSphere computeBound() const;
/** If State is non-zero, this function releases any associated OpenGL objects for
* the specified graphics context. Otherwise, releases OpenGL objexts
* for all graphics contexts. */
virtual void releaseGLObjects(osg::State* = 0) const;
protected:
virtual ~Geode();
virtual bool computeBound() const;
mutable osg::BoundingBox _bbox;
DrawableList _drawables;

View File

@@ -130,7 +130,7 @@ class OSG_EXPORT Group : public Node
virtual ~Group();
virtual bool computeBound() const;
virtual BoundingSphere computeBound() const;
virtual void childRemoved(unsigned int /*pos*/, unsigned int /*numChildrenToRemove*/) {}
virtual void childInserted(unsigned int /*pos*/) {}

View File

@@ -119,11 +119,11 @@ class OSG_EXPORT LOD : public Group
/** return the list of MinMax ranges for each child.*/
inline const RangeList& getRangeList() const { return _rangeList; }
virtual BoundingSphere computeBound() const;
protected :
virtual ~LOD() {}
virtual bool computeBound() const;
virtual void childRemoved(unsigned int pos, unsigned int numChildrenToRemove);
virtual void childInserted(unsigned int pos);

View File

@@ -72,12 +72,12 @@ class OSG_EXPORT LightSource : public Group
/** Set up the local StateSet. */
void setLocalStateSetModes(StateAttribute::GLModeValue value = StateAttribute::ON);
virtual BoundingSphere computeBound() const;
protected:
virtual ~LightSource();
virtual bool computeBound() const;
StateAttribute::GLModeValue _value;
ref_ptr<Light> _light;

View File

@@ -231,22 +231,57 @@ class OSG_EXPORT Node : public Object
/** Return the node's StateSet. returns NULL if a stateset is not attached.*/
inline osg::StateSet* getStateSet() { return _stateset.get(); }
/** return the node's const StateSet. Returns NULL if a stateset is not attached.*/
/** Return the node's const StateSet. Returns NULL if a stateset is not attached.*/
inline const osg::StateSet* getStateSet() const { return _stateset.get(); }
/** get the bounding sphere of node.
Using lazy evaluation computes the bounding sphere if it is 'dirty'.*/
inline const BoundingSphere& getBound() const
{
if(!_bsphere_computed) computeBound();
return _bsphere;
}
/** Set the intial bounding volume to use when computing the overall bounding volume.*/
void setInitialBound(const osg::BoundingSphere& bsphere) { _initialBound = bsphere; dirtyBound(); }
/** Set the intial bounding volume to use when computing the overall bounding volume.*/
const BoundingSphere& getInitialBound() const { return _initialBound; }
/** Mark this node's bounding sphere dirty.
Forcing it to be computed on the next call to getBound().*/
void dirtyBound();
/** Get the bounding sphere of node.
Using lazy evaluation computes the bounding sphere if it is 'dirty'.*/
inline const BoundingSphere& getBound() const
{
if(!_boundingSphereComputed)
{
_boundingSphere = _initialBound;
if (_computeBoundCallback.valid())
_boundingSphere.expandBy(_computeBoundCallback->computeBound(*this));
else
_boundingSphere.expandBy(computeBound());
_boundingSphereComputed = true;
}
return _boundingSphere;
}
/** Compute the bounding sphere around Node's geometry or children.
This method is automatically called by getBound() when the bounding
sphere has been marked dirty via dirtyBound().*/
virtual BoundingSphere computeBound() const;
/** Callback to allow users to override the default computation of bounding volume.*/
struct ComputeBoundCallback : public osg::Referenced
{
virtual BoundingSphere computeBound(const osg::Node&) const = 0;
};
/** Set the compute bound callback to override the default computeBound.*/
void setComputeBoundCallback(ComputeBoundCallback* callback) { _computeBoundCallback = callback; }
/** Get the compute bound callback.*/
ComputeBoundCallback* getComputeBoundCallback() { return _computeBoundCallback.get(); }
/** Get the const compute bound callback.*/
const ComputeBoundCallback* getComputeBoundCallback() const { return _computeBoundCallback.get(); }
/** If State is non-zero, this function releases any associated OpenGL objects for
* the specified graphics context. Otherwise, releases OpenGL objexts
@@ -266,13 +301,11 @@ class OSG_EXPORT Node : public Object
virtual ~Node();
/** Compute the bounding sphere around Node's geometry or children.
This method is automatically called by getBound() when the bounding
sphere has been marked dirty via dirtyBound().*/
virtual bool computeBound() const;
mutable BoundingSphere _bsphere;
mutable bool _bsphere_computed;
BoundingSphere _initialBound;
ref_ptr<ComputeBoundCallback> _computeBoundCallback;
mutable BoundingSphere _boundingSphere;
mutable bool _boundingSphereComputed;
std::string _name;

View File

@@ -45,14 +45,13 @@ class OSG_EXPORT OccluderNode : public Group
/** Get the const ConvexPlanarOccluder* attached to a OccluderNode.*/
const ConvexPlanarOccluder* getOccluder() const { return _occluder.get(); }
/** Overrides Group's computeBound.*/
virtual BoundingSphere computeBound() const;
protected :
virtual ~OccluderNode() {}
/** Overrides Group's computeBound.*/
virtual bool computeBound() const;
ref_ptr<ConvexPlanarOccluder> _occluder;
};

View File

@@ -76,12 +76,12 @@ class OSG_EXPORT ProxyNode : public Group
/** Get the object-space radius of the volume enclosed by the ProxyNode.*/
inline float getRadius() const { return _radius; }
virtual BoundingSphere computeBound() const;
protected :
virtual ~ProxyNode() {}
virtual bool computeBound() const;
void expandFileNameListTo(unsigned int pos);
FileNameList _filenameList;

View File

@@ -177,14 +177,14 @@ class OSG_EXPORT ShapeDrawable : public Drawable
/** Accept a PrimitiveFunctor and call its methods to tell it about the internal primitives that this Drawable has.*/
virtual void accept(PrimitiveFunctor& pf) const;
virtual BoundingBox computeBound() const;
protected:
ShapeDrawable& operator = (const ShapeDrawable&) { return *this;}
virtual ~ShapeDrawable();
virtual bool computeBound() const;
Vec4 _color;
ref_ptr<TessellationHints> _tessellationHints;

View File

@@ -77,12 +77,12 @@ class OSG_EXPORT Switch : public Group
const ValueList& getValueList() const { return _values; }
virtual BoundingSphere computeBound() const;
protected :
virtual ~Switch() {}
virtual bool computeBound() const;
// This is effectively a bit mask.
bool _newChildDefaultValue;
ValueList _values;

View File

@@ -135,16 +135,17 @@ class OSG_EXPORT Transform : public Group
}
}
protected :
virtual ~Transform();
/** Overrides Group's computeBound.
* There is no need to override in subclasses from osg::Transform
* since this computeBound() uses the underlying matrix (calling
* computeMatrix if required).
*/
virtual bool computeBound() const;
virtual BoundingSphere computeBound() const;
protected :
virtual ~Transform();
ReferenceFrame _referenceFrame;

View File

@@ -131,12 +131,12 @@ namespace osgParticle
/// Transform a vector from world to local coordinates, discarding translation (valid only during cull traversal).
inline osg::Vec3 rotateWorldToLocal(const osg::Vec3& P);
virtual osg::BoundingSphere computeBound() const;
protected:
virtual ~ParticleProcessor() {}
ParticleProcessor& operator=(const ParticleProcessor&) { return *this; }
inline bool computeBound() const;
virtual void process(double dt) = 0;
private:
@@ -249,13 +249,6 @@ namespace osgParticle
return _resetTime;
}
inline bool ParticleProcessor::computeBound() const
{
_bsphere.init();
_bsphere_computed = true;
return true;
}
inline const osg::Matrix& ParticleProcessor::getLocalToWorldMatrix()
{
if (_need_ltw_matrix) {

View File

@@ -159,13 +159,14 @@ namespace osgParticle
virtual void drawImplementation(osg::State& state) const;
virtual osg::BoundingBox computeBound() const;
protected:
virtual ~ParticleSystem();
ParticleSystem& operator=(const ParticleSystem&) { return *this; }
inline virtual bool computeBound() const;
inline void update_bounds(const osg::Vec3& p, float r);
void single_pass_render(osg::State& state, const osg::Matrix& modelview) const;
@@ -298,18 +299,6 @@ namespace osgParticle
return _last_frame;
}
inline bool ParticleSystem::computeBound() const
{
if (!_bounds_computed) {
_bbox = _def_bbox;
} else {
_bbox._min = _bmin;
_bbox._max = _bmax;
}
_bbox_computed = true;
return true;
}
inline void ParticleSystem::update_bounds(const osg::Vec3& p, float r)
{
if (_reset_bounds_flag) {

View File

@@ -75,11 +75,12 @@ namespace osgParticle
virtual void traverse(osg::NodeVisitor& nv);
virtual osg::BoundingSphere computeBound() const;
protected:
virtual ~ParticleSystemUpdater() {}
ParticleSystemUpdater &operator=(const ParticleSystemUpdater &) { return *this; }
inline virtual bool computeBound() const;
private:
typedef std::vector<osg::ref_ptr<ParticleSystem> > ParticleSystem_Vector;
@@ -90,13 +91,6 @@ namespace osgParticle
// INLINE FUNCTIONS
inline bool ParticleSystemUpdater::computeBound() const
{
_bsphere.init();
_bsphere_computed = true;
return true;
}
inline bool ParticleSystemUpdater::addParticleSystem(ParticleSystem* ps)
{
_psv.push_back(ps);

View File

@@ -100,12 +100,12 @@ class OSGSIM_EXPORT Impostor : public osg::LOD
/** Get a const list of ImpostorSprites attached to this const Impostor. */
inline const ImpostorSpriteList& getImpostorSpriteList(unsigned int contexID) const { return _impostorSpriteListBuffer[contexID]; }
virtual osg::BoundingSphere computeBound() const;
protected :
virtual ~Impostor() {}
virtual bool computeBound() const;
mutable osg::buffered_object<ImpostorSpriteList> _impostorSpriteListBuffer;

View File

@@ -148,6 +148,8 @@ class OSGSIM_EXPORT ImpostorSprite : public osg::Drawable
// for debugging purposes.
osg::Vec4 _color;
virtual osg::BoundingBox computeBound() const;
protected:
ImpostorSprite(const ImpostorSprite&):Drawable() {}
@@ -155,8 +157,6 @@ class OSGSIM_EXPORT ImpostorSprite : public osg::Drawable
virtual ~ImpostorSprite();
virtual bool computeBound() const;
Impostor* _parent;
friend class osgSim::ImpostorSpriteManager;

View File

@@ -82,6 +82,8 @@ class OSGSIM_EXPORT LightPointNode : public osg::Node
osgSim::LightPointSystem* getLightPointSystem() { return _lightSystem.get(); }
virtual osg::BoundingSphere computeBound() const;
protected:
~LightPointNode() {}
@@ -90,8 +92,6 @@ class OSGSIM_EXPORT LightPointNode : public osg::Node
// view frustum check.
mutable osg::BoundingBox _bbox;
virtual bool computeBound() const;
LightPointList _lightPointList;
float _minPixelSize;

View File

@@ -284,12 +284,12 @@ public:
return _textureGlyphQuadMap;
}
virtual osg::BoundingBox computeBound() const;
protected:
virtual ~Text();
virtual bool computeBound() const;
Font* getActiveFont();
const Font* getActiveFont() const;