Added Node::asDrawable() and Node::asGeometry() methods to provide a low cost way of casting a node to Drawable and Geoemtry.

Changed the Group::computeBound() method so that it takes account of the a Drawable's BoundingBox.
This commit is contained in:
Robert Osfield
2014-05-15 09:26:59 +00:00
parent afcf54b108
commit 20b9f3ff88
4 changed files with 35 additions and 19 deletions

View File

@@ -106,13 +106,8 @@ class OSG_EXPORT Drawable : public Node
META_Node(osg, Drawable);
/** Convert 'this' into a Geometry pointer if Drawable is a Geometry, otherwise return 0.
* Equivalent to dynamic_cast<Geometry*>(this).*/
virtual Geometry* asGeometry() { return 0; }
/** Convert 'const this' into a const Geometry pointer if Drawable is a Geometry, otherwise return 0.
* Equivalent to dynamic_cast<const Geometry*>(this).*/
virtual const Geometry* asGeometry() const { return 0; }
virtual Drawable* asDrawable() { return this; }
virtual const Drawable* asDrawable() const { return this; }
/** Compute the DataVariance based on an assessment of callback etc.*/
virtual void computeDataVariance();

View File

@@ -35,17 +35,11 @@ class OSG_EXPORT Geometry : public Drawable
/** Copy constructor using CopyOp to manage deep vs shallow copy. */
Geometry(const Geometry& geometry,const CopyOp& copyop=CopyOp::SHALLOW_COPY);
virtual Object* cloneType() const { return new Geometry(); }
virtual Object* clone(const CopyOp& copyop) const { return new Geometry(*this,copyop); }
virtual bool isSameKindAs(const Object* obj) const { return dynamic_cast<const Geometry*>(obj)!=NULL; }
virtual const char* libraryName() const { return "osg"; }
virtual const char* className() const { return "Geometry"; }
META_Node(osg, Geometry);
virtual Geometry* asGeometry() { return this; }
virtual const Geometry* asGeometry() const { return this; }
virtual void accept(NodeVisitor& nv) { nv.apply(*this); }
bool empty() const;
typedef std::vector< osg::ref_ptr<osg::Array> > ArrayList;

View File

@@ -34,6 +34,8 @@ namespace osg {
// forcing declare classes to enable declaration of as*() methods.
class NodeVisitor;
class Drawable;
class Geometry;
class Group;
class Transform;
class Node;
@@ -132,6 +134,20 @@ class OSG_EXPORT Node : public Object
/** return the name of the node's class type.*/
virtual const char* className() const { return "Node"; }
/** convert 'this' into a Drawable pointer if Node is a Drawable, otherwise return 0.
* Equivalent to dynamic_cast<Group*>(this).*/
virtual Drawable* asDrawable() { return 0; }
/** convert 'const this' into a const Drawable pointer if Node is a Drawable, otherwise return 0.
* Equivalent to dynamic_cast<const Group*>(this).*/
virtual const Drawable* asDrawable() const { return 0; }
/** convert 'this' into a Geometry pointer if Node is a Geometry, otherwise return 0.
* Equivalent to dynamic_cast<Group*>(this).*/
virtual Geometry* asGeometry() { return 0; }
/** convert 'const this' into a const Geometry pointer if Node is a Geometry, otherwise return 0.
* Equivalent to dynamic_cast<const Group*>(this).*/
virtual const Geometry* asGeometry() const { return 0; }
/** convert 'this' into a Group pointer if Node is a Group, otherwise return 0.
* Equivalent to dynamic_cast<Group*>(this).*/
virtual Group* asGroup() { return 0; }