Refactored Callback system in osg::Node, osg::Drawable, osg::StateSet and osg::StateAttribute to use a new osg::Callback base class.

git-svn-id: http://svn.openscenegraph.org/osg/OpenSceneGraph/trunk@14244 16af8721-9629-0410-8352-f15c8da7e697
This commit is contained in:
Robert Osfield 2014-06-05 16:26:13 +00:00
parent 35d6cb812f
commit 977ec20751
64 changed files with 590 additions and 471 deletions

View File

@ -23,7 +23,6 @@
#include <osg/Geometry>
#include <osg/GLExtensions>
#include <osg/Node>
#include <osg/NodeCallback>
#include <osg/Notify>
#include <osg/observer_ptr>
#include <osg/Projection>

View File

@ -10,40 +10,41 @@ class PosterVisitor : public osg::NodeVisitor
{
public:
typedef std::set<std::string> PagedNodeNameSet;
PosterVisitor();
META_NodeVisitor( osgPoster, PosterVisitor );
void insertName( const std::string& name )
{ if ( _pagedNodeNames.insert(name).second ) _needToApplyCount++; }
void eraseName( const std::string& name )
{ if ( _pagedNodeNames.erase(name)>0 ) _needToApplyCount--; }
void clearNames() { _pagedNodeNames.clear(); _needToApplyCount = 0; _appliedCount = 0; }
unsigned int getNumNames() const { return _pagedNodeNames.size(); }
PagedNodeNameSet& getPagedNodeNames() { return _pagedNodeNames; }
const PagedNodeNameSet& getPagedNodeNames() const { return _pagedNodeNames; }
unsigned int getNeedToApplyCount() const { return _needToApplyCount; }
unsigned int getAppliedCount() const { return _appliedCount; }
unsigned int inQueue() const { return _needToApplyCount>_appliedCount ? _needToApplyCount-_appliedCount : 0; }
void setAddingCallbacks( bool b ) { _addingCallbacks = b; }
bool getAddingCallbacks() const { return _addingCallbacks; }
virtual void apply( osg::LOD& node );
virtual void apply( osg::PagedLOD& node );
protected:
bool hasCullCallback( osg::NodeCallback* nc, osg::NodeCallback* target )
bool hasCullCallback( osg::Callback* nc, osg::Callback* target )
{
if ( nc==target ) return true;
else if ( !nc ) return false;
return hasCullCallback( nc->getNestedCallback(), target );
}
PagedNodeNameSet _pagedNodeNames;
unsigned int _appliedCount;
unsigned int _needToApplyCount;
@ -55,24 +56,24 @@ class PosterIntersector : public osgUtil::Intersector
{
public:
typedef std::set<std::string> PagedNodeNameSet;
PosterIntersector( const osg::Polytope& polytope );
PosterIntersector( double xMin, double yMin, double xMax, double yMax );
void setPosterVisitor( PosterVisitor* pcv ) { _visitor = pcv; }
PosterVisitor* getPosterVisitor() { return _visitor.get(); }
const PosterVisitor* getPosterVisitor() const { return _visitor.get(); }
virtual Intersector* clone( osgUtil::IntersectionVisitor& iv );
virtual bool containsIntersections()
{ return _visitor.valid()&&_visitor->getNumNames()>0; }
virtual bool enter( const osg::Node& node );
virtual void leave() {}
virtual void reset();
virtual void intersect( osgUtil::IntersectionVisitor& iv, osg::Drawable* drawable );
protected:
osgUtil::IntersectionVisitor* _intersectionVisitor;
osg::ref_ptr<PosterVisitor> _visitor;
@ -86,60 +87,60 @@ class PosterPrinter : public osg::Referenced
public:
typedef std::pair<unsigned int, unsigned int> TilePosition;
typedef std::map< TilePosition, osg::ref_ptr<osg::Image> > TileImages;
PosterPrinter();
/** Set to output each sub-image-tile to disk */
void setOutputTiles( bool b ) { _outputTiles = b; }
bool getOutputTiles() const { return _outputTiles; }
/** Set the output sub-image-tile extension, e.g. bmp */
void setOutputTileExtension( const std::string& ext ) { _outputTileExt = ext; }
const std::string& getOutputTileExtension() const { return _outputTileExt; }
/** Set the output poster name, e.g. output.bmp */
void setOutputPosterName( const std::string& name ) { _outputPosterName = name; }
const std::string& getOutputPosterName() const { return _outputPosterName; }
/** Set the size of each sub-image-tile, e.g. 640x480 */
void setTileSize( int w, int h ) { _tileSize.set(w, h); }
const osg::Vec2& getTileSize() const { return _tileSize; }
/** Set the final size of the high-res poster, e.g. 6400x4800 */
void setPosterSize( int w, int h ) { _posterSize.set(w, h); }
const osg::Vec2& getPosterSize() const { return _posterSize; }
/** Set the capturing camera */
void setCamera( osg::Camera* camera ) { _camera = camera; }
const osg::Camera* getCamera() const { return _camera.get(); }
/** Set the final poster image, should be already allocated */
void setFinalPoster( osg::Image* image ) { _finalPoster = image; }
const osg::Image* getFinalPoster() const { return _finalPoster.get(); }
PosterVisitor* getPosterVisitor() { return _visitor.get(); }
const PosterVisitor* getPosterVisitor() const { return _visitor.get(); }
bool done() const { return !_isRunning && !_isFinishing; }
void init( const osg::Camera* camera );
void init( const osg::Matrixd& view, const osg::Matrixd& proj );
void frame( const osg::FrameStamp* fs, osg::Node* node );
protected:
virtual ~PosterPrinter() {}
bool addCullCallbacks( const osg::FrameStamp* fs, osg::Node* node );
void removeCullCallbacks( osg::Node* node );
void bindCameraToImage( osg::Camera* camera, int row, int col );
void recordImages();
bool _outputTiles;
std::string _outputTileExt;
std::string _outputPosterName;
osg::Vec2 _tileSize;
osg::Vec2 _posterSize;
bool _isRunning;
bool _isFinishing;
unsigned int _lastBindingFrame;
@ -149,7 +150,7 @@ protected:
int _currentColumn;
osg::ref_ptr<PosterIntersector> _intersector;
osg::ref_ptr<PosterVisitor> _visitor;
osg::Matrixd _currentViewMatrix;
osg::Matrixd _currentProjectionMatrix;
osg::ref_ptr<osg::Camera> _camera;

View File

@ -25,7 +25,6 @@
#include <osg/Geode>
#include <osg/Transform>
#include <osg/Material>
#include <osg/NodeCallback>
#include <osg/Depth>
#include <osg/CullFace>
#include <osg/TexMat>
@ -220,7 +219,7 @@ class MoveEarthySkyWithEyePointTransform : public osg::Transform
{
public:
/** Get the transformation matrix which moves from local coords to world coords.*/
virtual bool computeLocalToWorldMatrix(osg::Matrix& matrix,osg::NodeVisitor* nv) const
virtual bool computeLocalToWorldMatrix(osg::Matrix& matrix,osg::NodeVisitor* nv) const
{
osgUtil::CullVisitor* cv = dynamic_cast<osgUtil::CullVisitor*>(nv);
if (cv)
@ -270,7 +269,7 @@ osg::Node* createSkyBox()
// clear the depth to the far plane.
osg::Depth* depth = new osg::Depth;
depth->setFunction(osg::Depth::ALWAYS);
depth->setRange(1.0,1.0);
depth->setRange(1.0,1.0);
stateset->setAttributeAndModes(depth, osg::StateAttribute::ON );
stateset->setRenderBinDetails(-1,"RenderBin");
@ -305,7 +304,7 @@ osg::Node* addRefractStateSet(osg::Node* node)
osg::TextureCubeMap* reflectmap = readCubeMap();
stateset->setTextureAttributeAndModes( 0, reflectmap, osg::StateAttribute::ON | osg::StateAttribute::OVERRIDE );
stateset->setTextureAttributeAndModes( 1, reflectmap, osg::StateAttribute::ON | osg::StateAttribute::OVERRIDE );
osg::TexMat* texMat = new osg::TexMat;
stateset->setTextureAttribute(0, texMat);
@ -329,14 +328,14 @@ osg::Node* addRefractStateSet(osg::Node* node)
// REPLACE function: Arg0
// = T0
osg::TexEnvCombine *te0 = new osg::TexEnvCombine;
osg::TexEnvCombine *te0 = new osg::TexEnvCombine;
te0->setCombine_RGB(osg::TexEnvCombine::REPLACE);
te0->setSource0_RGB(osg::TexEnvCombine::TEXTURE0);
te0->setOperand0_RGB(osg::TexEnvCombine::SRC_COLOR);
// INTERPOLATE function: Arg0 * (Arg2) + Arg1 * (1-Arg2)
// = T1 * C0.a + Cp * (1-C0.a)
osg::TexEnvCombine *te1 = new osg::TexEnvCombine;
osg::TexEnvCombine *te1 = new osg::TexEnvCombine;
// rgb = Cp + Ct
te1->setCombine_RGB(osg::TexEnvCombine::INTERPOLATE);
@ -354,7 +353,7 @@ osg::Node* addRefractStateSet(osg::Node* node)
group->addChild(node);
group->setCullCallback(new TexMatCallback(*texMat));
group->setStateSet( stateset );
return group;
}
@ -385,7 +384,7 @@ int main(int argc, char *argv[])
osgUtil::Optimizer optimzer;
optimzer.optimize(model);
// create normals.
// create normals.
osgUtil::SmoothingVisitor smoother;
model->accept(smoother);
@ -393,7 +392,7 @@ int main(int argc, char *argv[])
// add a viewport to the viewer and attach the scene graph.
viewer.setSceneData(rootnode);
// create the windows and run the threads.
viewer.realize();

View File

@ -21,7 +21,7 @@
#include <osg/Matrixf>
#include <osg/Matrixd>
#include <osg/Quat>
#include <osg/NodeCallback>
#include <osg/Callback>
namespace osg {

202
include/osg/Callback Normal file
View File

@ -0,0 +1,202 @@
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
*
* This library is open source and may be redistributed and/or modified under
* the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
* (at your option) any later version. The full license is in LICENSE file
* included with this distribution, and on the openscenegraph.org website.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* OpenSceneGraph Public License for more details.
*/
#ifndef OSG_CALLBACK
#define OSG_CALLBACK 1
#include <osg/Object>
#include <osg/UserDataContainer>
namespace osg {
class Callback : public virtual Object {
public :
Callback(){}
Callback(const Callback& cb,const CopyOp&):
_nestedCallback(cb._nestedCallback) {}
META_Object(osg, Callback);
/** Invoke the callback, first parameter is the Object that the callback is attached to,
* the second parameter, the data, is typically the NodeVisitor that is invoking the callback.
* The run(..) method may be overriden by users directly, or if the user is using one of the old
* style callbacks such as NodeCallback or Drawable::UpdateCallback then you can just override
* the appropriate callback method on those callback subclasses.
* If you are implementing your own callback then one should call traverse() to make sure nested callbacks
* and visitor traversal() is completed. */
virtual bool run(osg::Object* object, osg::Object* data)
{
return traverse(object, data);
}
/** traverse the nested callbacks or call NodeVisitor::traverse() if the object is Node, and data is NodeVisitor.*/
bool traverse(osg::Object* object, osg::Object* data);
void setNestedCallback(osg::Callback* cb) { _nestedCallback = cb; }
osg::Callback* getNestedCallback() { return _nestedCallback.get(); }
const osg::Callback* getNestedCallback() const { return _nestedCallback.get(); }
inline void addNestedCallback(osg::Callback* nc)
{
if (nc)
{
if (_nestedCallback.valid())
{
_nestedCallback->addNestedCallback(nc);
}
else
{
_nestedCallback = nc;
}
}
}
inline void removeNestedCallback(osg::Callback* nc)
{
if (nc)
{
if (_nestedCallback==nc)
{
ref_ptr<osg::Callback> new_nested_callback = _nestedCallback->getNestedCallback();
_nestedCallback->setNestedCallback(0);
_nestedCallback = new_nested_callback;
}
else if (_nestedCallback.valid())
{
_nestedCallback->removeNestedCallback(nc);
}
}
}
protected:
virtual ~Callback() {}
ref_ptr<Callback> _nestedCallback;
};
typedef std::vector< osg::ref_ptr<osg::Object> > Parameters;
/** Callback for attaching a script to a Node's via there UserDataContainer for the purpose of overriding class methods within scripts.*/
class OSG_EXPORT CallbackObject : public virtual osg::Callback
{
public:
CallbackObject() {}
CallbackObject(const std::string& name) { setName(name); }
CallbackObject(const CallbackObject& rhs, const osg::CopyOp copyop=osg::CopyOp::SHALLOW_COPY):osg::Callback(rhs,copyop) {}
META_Object(osg, CallbackObject);
virtual CallbackObject* asCallbackObject() { return this; }
virtual const CallbackObject* asCallbackObject() const { return this; }
/** override Callback::run() entry point to adapt to CallbackObject::run(..) method.*/
bool run(osg::Object* object, osg::Object* data);
inline bool run(osg::Object* object) const
{
osg::Parameters inputParameters;
osg::Parameters outputParameters;
return run(object, inputParameters, outputParameters);
}
virtual bool run(osg::Object* object, osg::Parameters& inputParameters, osg::Parameters& outputParameters) const;
};
/** Convinience function for getting the CallbackObject associated with specificed name from an Object's UserDataContainer.*/
inline CallbackObject* getCallbackObject(osg::Object* object, const std::string& name)
{
osg::UserDataContainer* udc = object->getUserDataContainer();
return udc ? dynamic_cast<osg::CallbackObject*>(udc->getUserObject(name)) : 0;
}
/** Call run(..) on named CallbackObjects attached to specified Object. Return true if at least one CallbackObject has been successfully invoked.*/
inline bool runNamedCallbackObjects(osg::Object* object, const std::string& name, osg::Parameters& inputParameters, osg::Parameters& outputParameters)
{
bool result = false;
osg::UserDataContainer* udc = object->getUserDataContainer();
if (udc)
{
for(unsigned int i = 0; i<udc->getNumUserObjects(); ++i)
{
osg::Object* obj = udc->getUserObject(i);
if (obj && obj->getName()==name)
{
osg::CallbackObject* co = dynamic_cast<osg::CallbackObject*>(obj);
if (co) result = co->run(object, inputParameters, outputParameters) | result;
}
}
}
return result;
}
// forward declare
class Node;
class NodeVisitor;
/** Deprecated. */
class OSG_EXPORT NodeCallback : public virtual Callback {
public :
NodeCallback(){}
NodeCallback(const NodeCallback& nc,const CopyOp& copyop):
Callback(nc,copyop) {}
META_Object(osg,NodeCallback);
/** NodeCallback overrides the Callback::run() method to adapt it the old style NodeCallback::operator()(Node* node, NodeVisitor* nv) method.*/
virtual bool run(osg::Object* object, osg::Object* data);
/** Callback method called by the NodeVisitor when visiting a node.*/
virtual void operator()(Node* node, NodeVisitor* nv);
protected:
virtual ~NodeCallback() {}
};
// forward declare
class StateAttribute;
/** Deprecated. */
class OSG_EXPORT StateAttributeCallback : public virtual osg::Callback
{
public:
StateAttributeCallback() {}
StateAttributeCallback(const StateAttributeCallback&,const CopyOp&) {}
META_Object(osg,StateAttributeCallback);
/** override Callback::run() entry point to adapt to StateAttributeCallback::run(..) method.*/
virtual bool run(osg::Object* object, osg::Object* data);
/** do customized update code.*/
virtual void operator () (StateAttribute*, NodeVisitor*) {}
};
} // namespace
#endif

View File

@ -15,7 +15,7 @@
#define OSG_CLUSTERCULLINGCALLBACK 1
#include <osg/Drawable>
#include <osg/NodeCallback>
#include <osg/Callback>
namespace osg {

View File

@ -31,7 +31,7 @@ class Drawable;
class Array;
class PrimitiveSet;
class Shape;
class NodeCallback;
class Callback;
/** Copy Op(erator) used to control whether shallow or deep copy is used
@ -80,7 +80,7 @@ class OSG_EXPORT CopyOp
virtual PrimitiveSet* operator() (const PrimitiveSet* primitives) const;
virtual Shape* operator() (const Shape* shape) const;
virtual Uniform* operator() (const Uniform* shape) const;
virtual NodeCallback* operator() (const NodeCallback* nodecallback) const;
virtual Callback* operator() (const Callback* nodecallback) const;
virtual StateAttributeCallback* operator() (const StateAttributeCallback* stateattributecallback) const;
protected:

View File

@ -268,7 +268,7 @@ class OSG_EXPORT Drawable : public Node
* for all graphics contexts. */
virtual void releaseGLObjects(State* state=0) const;
struct UpdateCallback : public virtual osg::Object
struct OSG_EXPORT UpdateCallback : public virtual Callback
{
UpdateCallback() {}
@ -276,24 +276,15 @@ class OSG_EXPORT Drawable : public Node
META_Object(osg,UpdateCallback);
/** override Callback::run() entry point to adapt to StateAttributeCallback::run(..) method.*/
virtual bool run(osg::Object* object, osg::Object* data);
/** do customized update code.*/
virtual void update(osg::NodeVisitor*, osg::Drawable*) {}
};
/** Set the UpdateCallback which allows users to attach customize the updating of an object during the update traversal. */
virtual void setUpdateCallback(UpdateCallback* ac);
/** Get the non const UpdateCallback.*/
UpdateCallback* getUpdateCallback() { return _drawableUpdateCallback.get(); }
/** Get the const UpdateCallback.*/
const UpdateCallback* getUpdateCallback() const { return _drawableUpdateCallback.get(); }
/** Return whether this Drawable has update callbacks associated with it, and therefore must be traversed.*/
bool requiresUpdateTraversal() const { return _drawableUpdateCallback.valid() || (_stateset.valid() && _stateset->requiresUpdateTraversal()); }
struct EventCallback : public virtual osg::Object
struct OSG_EXPORT EventCallback : public virtual Callback
{
EventCallback() {}
@ -301,24 +292,14 @@ class OSG_EXPORT Drawable : public Node
META_Object(osg,EventCallback);
/** override Callback::run() entry point to adapt to StateAttributeCallback::run(..) method.*/
virtual bool run(osg::Object* object, osg::Object* data);
/** do customized Event code. */
virtual void event(osg::NodeVisitor*, osg::Drawable*) {}
};
/** Set the EventCallback which allows users to attach customize the updating of an object during the Event traversal.*/
virtual void setEventCallback(EventCallback* ac);
/** Get the non const EventCallback.*/
EventCallback* getEventCallback() { return _drawableEventCallback.get(); }
/** Get the const EventCallback.*/
const EventCallback* getEventCallback() const { return _drawableEventCallback.get(); }
/** Return whether this Drawable has event callbacks associated with it, and therefore must be traversed.*/
bool requiresEventTraversal() const { return _drawableEventCallback.valid() || (_stateset.valid() && _stateset->requiresEventTraversal()); }
struct CullCallback : public virtual osg::Object
struct CullCallback : public virtual Callback
{
CullCallback() {}
@ -333,17 +314,6 @@ class OSG_EXPORT Drawable : public Node
virtual bool cull(osg::NodeVisitor* nv, osg::Drawable* drawable, osg::RenderInfo* renderInfo) const { return cull(nv, drawable, renderInfo? renderInfo->getState():0); }
};
/** Set the CullCallback which allows users to customize the culling of Drawable during the cull traversal.*/
virtual void setCullCallback(CullCallback* cc) { _drawableCullCallback=cc; }
/** Get the non const CullCallback.*/
CullCallback* getCullCallback() { return _drawableCullCallback.get(); }
/** Get the const CullCallback.*/
const CullCallback* getCullCallback() const { return _drawableCullCallback.get(); }
/** Callback attached to an Drawable which allows the users to customize the drawing of an exist Drawable object.
* The draw callback is implement as a replacement to the Drawable's own drawImplementation() method, if the

View File

@ -19,7 +19,7 @@
#include <osg/StateSet>
#include <osg/BoundingSphere>
#include <osg/BoundingBox>
#include <osg/NodeCallback>
#include <osg/Callback>
#include <string>
#include <vector>
@ -202,16 +202,16 @@ class OSG_EXPORT Node : public Object
/** Set update node callback, called during update traversal. */
void setUpdateCallback(NodeCallback* nc);
void setUpdateCallback(Callback* nc);
/** Get update node callback, called during update traversal. */
inline NodeCallback* getUpdateCallback() { return _updateCallback.get(); }
inline Callback* getUpdateCallback() { return _updateCallback.get(); }
/** Get const update node callback, called during update traversal. */
inline const NodeCallback* getUpdateCallback() const { return _updateCallback.get(); }
inline const Callback* getUpdateCallback() const { return _updateCallback.get(); }
/** Convenience method that sets the update callback of the node if it doesn't exist, or nest it into the existing one. */
inline void addUpdateCallback(NodeCallback* nc) {
inline void addUpdateCallback(Callback* nc) {
if (nc != NULL) {
if (_updateCallback.valid()) _updateCallback->addNestedCallback(nc);
else setUpdateCallback(nc);
@ -219,7 +219,7 @@ class OSG_EXPORT Node : public Object
}
/** Convenience method that removes a given callback from a node, even if that callback is nested. There is no error return in case the given callback is not found. */
inline void removeUpdateCallback(NodeCallback* nc) {
inline void removeUpdateCallback(Callback* nc) {
if (nc != NULL && _updateCallback.valid()) {
if (_updateCallback == nc)
{
@ -236,16 +236,16 @@ class OSG_EXPORT Node : public Object
/** Set event node callback, called during event traversal. */
void setEventCallback(NodeCallback* nc);
void setEventCallback(Callback* nc);
/** Get event node callback, called during event traversal. */
inline NodeCallback* getEventCallback() { return _eventCallback.get(); }
inline Callback* getEventCallback() { return _eventCallback.get(); }
/** Get const event node callback, called during event traversal. */
inline const NodeCallback* getEventCallback() const { return _eventCallback.get(); }
inline const Callback* getEventCallback() const { return _eventCallback.get(); }
/** Convenience method that sets the event callback of the node if it doesn't exist, or nest it into the existing one. */
inline void addEventCallback(NodeCallback* nc) {
inline void addEventCallback(Callback* nc) {
if (nc != NULL) {
if (_eventCallback.valid()) _eventCallback->addNestedCallback(nc);
else setEventCallback(nc);
@ -253,7 +253,7 @@ class OSG_EXPORT Node : public Object
}
/** Convenience method that removes a given callback from a node, even if that callback is nested. There is no error return in case the given callback is not found. */
inline void removeEventCallback(NodeCallback* nc) {
inline void removeEventCallback(Callback* nc) {
if (nc != NULL && _eventCallback.valid()) {
if (_eventCallback == nc)
{
@ -270,16 +270,16 @@ class OSG_EXPORT Node : public Object
/** Set cull node callback, called during cull traversal. */
void setCullCallback(NodeCallback* nc) { _cullCallback = nc; }
void setCullCallback(Callback* nc) { _cullCallback = nc; }
/** Get cull node callback, called during cull traversal. */
inline NodeCallback* getCullCallback() { return _cullCallback.get(); }
inline Callback* getCullCallback() { return _cullCallback.get(); }
/** Get const cull node callback, called during cull traversal. */
inline const NodeCallback* getCullCallback() const { return _cullCallback.get(); }
inline const Callback* getCullCallback() const { return _cullCallback.get(); }
/** Convenience method that sets the cull callback of the node if it doesn't exist, or nest it into the existing one. */
inline void addCullCallback(NodeCallback* nc) {
inline void addCullCallback(Callback* nc) {
if (nc != NULL) {
if (_cullCallback.valid()) _cullCallback->addNestedCallback(nc);
else setCullCallback(nc);
@ -287,7 +287,7 @@ class OSG_EXPORT Node : public Object
}
/** Convenience method that removes a given callback from a node, even if that callback is nested. There is no error return in case the given callback is not found. */
inline void removeCullCallback(NodeCallback* nc) {
inline void removeCullCallback(Callback* nc) {
if (nc != NULL && _cullCallback.valid()) {
if (_cullCallback == nc)
{
@ -477,15 +477,15 @@ class OSG_EXPORT Node : public Object
friend class osg::Drawable;
friend class osg::StateSet;
ref_ptr<NodeCallback> _updateCallback;
ref_ptr<Callback> _updateCallback;
unsigned int _numChildrenRequiringUpdateTraversal;
void setNumChildrenRequiringUpdateTraversal(unsigned int num);
ref_ptr<NodeCallback> _eventCallback;
ref_ptr<Callback> _eventCallback;
unsigned int _numChildrenRequiringEventTraversal;
void setNumChildrenRequiringEventTraversal(unsigned int num);
ref_ptr<NodeCallback> _cullCallback;
ref_ptr<Callback> _cullCallback;
bool _cullingActive;
unsigned int _numChildrenWithCullingDisabled;

View File

@ -14,86 +14,7 @@
#ifndef OSG_NODECALLBACK
#define OSG_NODECALLBACK 1
#include <osg/Object>
#include <osg/ref_ptr>
namespace osg {
class Node;
class NodeVisitor;
class OSG_EXPORT NodeCallback : public virtual Object {
public :
NodeCallback(){}
NodeCallback(const NodeCallback& nc,const CopyOp&):
_nestedCallback(nc._nestedCallback) {}
META_Object(osg,NodeCallback);
/** Callback method called by the NodeVisitor when visiting a node.*/
virtual void operator()(Node* node, NodeVisitor* nv)
{
// note, callback is responsible for scenegraph traversal so
// they must call traverse(node,nv) to ensure that the
// scene graph subtree (and associated callbacks) are traversed.
traverse(node,nv);
}
/** Call any nested callbacks and then traverse the scene graph. */
void traverse(Node* node,NodeVisitor* nv);
void setNestedCallback(NodeCallback* nc) { _nestedCallback = nc; }
NodeCallback* getNestedCallback() { return _nestedCallback.get(); }
const NodeCallback* getNestedCallback() const { return _nestedCallback.get(); }
inline void addNestedCallback(NodeCallback* nc)
{
if (nc)
{
if (_nestedCallback.valid())
{
_nestedCallback->addNestedCallback(nc);
}
else
{
_nestedCallback = nc;
}
}
}
inline void removeNestedCallback(NodeCallback* nc)
{
if (nc)
{
if (_nestedCallback==nc)
{
ref_ptr<NodeCallback> new_nested_callback = _nestedCallback->getNestedCallback();
_nestedCallback->setNestedCallback(0);
_nestedCallback = new_nested_callback;
}
else if (_nestedCallback.valid())
{
_nestedCallback->removeNestedCallback(nc);
}
}
}
public:
ref_ptr<NodeCallback> _nestedCallback;
protected:
virtual ~NodeCallback() {}
};
} // namespace
#include <osg/Callback>
#endif

View File

@ -17,7 +17,6 @@
#include <iterator>
#include <osg/Node>
#include <osg/NodeCallback>
#include <osg/ObserverNodePath>
namespace osg

View File

@ -15,20 +15,16 @@
#define OSG_SCRIPTENGINE 1
#include <osg/Object>
#include <osg/NodeCallback>
#include <osg/Callback>
#include <osg/NodeVisitor>
#include <osg/UserDataContainer>
namespace osg
{
typedef std::vector< osg::ref_ptr<osg::Object> > Parameters;
// forward declare
class ScriptEngine;
/* Script class for wrapping a script and the language used in the script.*/
class Script : public osg::Object
{
@ -57,53 +53,6 @@ class Script : public osg::Object
unsigned int _modifiedCount;
};
/** Callback for attaching a script to a Node's via there UserDataContainer for the purpose of overriding class methods within scripts.*/
class OSG_EXPORT CallbackObject : public osg::Object
{
public:
CallbackObject() {}
CallbackObject(const std::string& name) { setName(name); }
CallbackObject(const CallbackObject& rhs, const osg::CopyOp copyop=osg::CopyOp::SHALLOW_COPY):osg::Object(rhs,copyop) {}
META_Object(osg, CallbackObject);
inline bool run(osg::Object* object) const
{
osg::Parameters inputParameters;
osg::Parameters outputParameters;
return run(object, inputParameters, outputParameters);
}
virtual bool run(osg::Object* object, osg::Parameters& inputParameters, osg::Parameters& outputParameters) const;
};
/** Convinience function for getting the CallbackObject associated with specificed name from an Object's UserDataContainer.*/
inline CallbackObject* getCallbackObject(osg::Object* object, const std::string& name)
{
osg::UserDataContainer* udc = object->getUserDataContainer();
return udc ? dynamic_cast<osg::CallbackObject*>(udc->getUserObject(name)) : 0;
}
/** Call run(..) on named CallbackObjects attached to specified Object. Return true if at least one CallbackObject has been successfully invoked.*/
inline bool runNamedCallbackObjects(osg::Object* object, const std::string& name, osg::Parameters& inputParameters, osg::Parameters& outputParameters)
{
bool result = false;
osg::UserDataContainer* udc = object->getUserDataContainer();
if (udc)
{
for(unsigned int i = 0; i<udc->getNumUserObjects(); ++i)
{
osg::Object* obj = udc->getUserObject(i);
if (obj && obj->getName()==name)
{
osg::CallbackObject* co = dynamic_cast<osg::CallbackObject*>(obj);
if (co) result = co->run(object, inputParameters, outputParameters) | result;
}
}
}
return result;
}
/** NodeCallback for attaching a script to a NodeCallback so that it can be called as an update or event callback.*/
class OSG_EXPORT ScriptNodeCallback : public osg::NodeCallback

View File

@ -16,7 +16,7 @@
#include <osg/Export>
#include <osg/Object>
#include <osg/StateAttributeCallback>
#include <osg/Callback>
#include <osg/Shader>
#include <osg/GL>

View File

@ -13,27 +13,6 @@
#ifndef OSG_STATEATTRIBUTECALLBACK
#define OSG_STATEATTRIBUTECALLBACK 1
#include <osg/Export>
#include <osg/Object>
namespace osg {
class StateAttribute;
class NodeVisitor;
class OSG_EXPORT StateAttributeCallback : public virtual osg::Object
{
public:
StateAttributeCallback() {}
StateAttributeCallback(const StateAttributeCallback&,const CopyOp&) {}
META_Object(osg,StateAttributeCallback);
/** do customized update code.*/
virtual void operator () (StateAttribute*, NodeVisitor*) {}
};
}
#include <osg/Callback>
#endif

View File

@ -378,7 +378,7 @@ class OSG_EXPORT StateSet : public Object
inline bool getNestRenderBins() const { return _nestRenderBins; }
struct Callback : public virtual osg::Object
struct Callback : public virtual osg::Callback
{
Callback() {}
@ -386,6 +386,9 @@ class OSG_EXPORT StateSet : public Object
META_Object(osg,Callback);
/** override Callback::run() entry point to adapt to StateAttributeCallback::run(..) method.*/
virtual bool run(osg::Object* object, osg::Object* data);
/** do customized callback code.*/
virtual void operator() (StateSet*, NodeVisitor*) {}
};

View File

@ -17,6 +17,7 @@
#include <osgAnimation/Export>
#include <osg/MatrixTransform>
#include <osg/Callback>
namespace osgAnimation
{

View File

@ -16,10 +16,10 @@
#ifndef OSGANIMATION_UPDATE_MATRIX_TRANSFORM
#define OSGANIMATION_UPDATE_MATRIX_TRANSFORM 1
#include <osg/Callback>
#include <osgAnimation/Export>
#include <osgAnimation/AnimationUpdateCallback>
#include <osgAnimation/StackedTransform>
#include <osg/NodeCallback>
namespace osgAnimation
{

View File

@ -16,7 +16,6 @@
#include <vector>
#include <osg/NodeCallback>
#include <osg/Drawable>
#include <osg/ApplicationUsage>
@ -37,12 +36,20 @@ public:
EventHandler() {}
EventHandler(const EventHandler& eh,const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY):
osg::Object(eh,copyop),
osg::Callback(eh,copyop),
osg::NodeCallback(eh, copyop),
osg::Drawable::EventCallback(eh, copyop) {}
META_Object(osgGA, EventHandler);
virtual bool run(osg::Object* object, osg::Object* data)
{
osg::Node* node = dynamic_cast<osg::Node*>(object);
osg::NodeVisitor* nv = dynamic_cast<osg::NodeVisitor*>(data);
operator()(node, nv);
return true;
}
/** Event traversal node callback method. There is no need to override this method in subclasses of EventHandler as this implementation calls handle(..) for you. */
virtual void operator()(osg::Node* node, osg::NodeVisitor* nv);

View File

@ -24,6 +24,7 @@
#include <osg/Transform>
#include <osg/Projection>
#include <osg/OccluderNode>
#include <osg/ScriptEngine>
#include <osgGA/GUIEventAdapter>
#include <osgGA/GUIActionAdapter>
@ -68,8 +69,27 @@ class OSGGA_EXPORT EventVisitor : public osg::NodeVisitor
/** During traversal each type of node calls its callbacks and its children traversed. */
virtual void apply(osg::Node& node) { handle_callbacks_and_traverse(node); }
virtual void apply(osg::Geode& node) { handle_geode_callbacks(node); }
virtual void apply(osg::Billboard& node) { handle_geode_callbacks(node); }
virtual void apply(osg::Drawable& drawable)
{
osg::Callback* callback = drawable.getEventCallback();
if (callback)
{
osg::Drawable::UpdateCallback* drawable_callback = dynamic_cast<osg::Drawable::UpdateCallback*>(callback);
osg::NodeCallback* node_callback = dynamic_cast<osg::NodeCallback*>(callback);
osg::CallbackObject* callback_object = dynamic_cast<osg::CallbackObject*>(callback);
if (drawable_callback) drawable_callback->update(this,&drawable);
if (node_callback) (*node_callback)(&drawable, this);
if ((!drawable_callback && !node_callback) || callback_object) callback_object->run(&drawable, this);
}
handle_callbacks(drawable.getStateSet());
}
virtual void apply(osg::Geode& node) { handle_callbacks_and_traverse(node); }
virtual void apply(osg::Billboard& node) { handle_callbacks_and_traverse(node); }
virtual void apply(osg::LightSource& node) { handle_callbacks_and_traverse(node); }
@ -98,34 +118,11 @@ class OSGGA_EXPORT EventVisitor : public osg::NodeVisitor
{
handle_callbacks(node.getStateSet());
osg::NodeCallback* callback = node.getEventCallback();
if (callback) (*callback)(&node,this);
else if (node.getNumChildrenRequiringEventTraversal()>0) traverse(node);
osg::Callback* callback = node.getEventCallback();
if (callback) callback->run(&node,this);
else if (node.getNumChildrenRequiringUpdateTraversal()>0) traverse(node);
}
inline void handle_geode_callbacks(osg::Geode& node)
{
handle_callbacks(node.getStateSet());
osg::NodeCallback* callback = node.getEventCallback();
if (callback) (*callback)(&node,this);
/*else if (node.getNumChildrenRequiringEventTraversal()>0)*/
traverseGeode(node);
}
inline void traverseGeode(osg::Geode& geode)
{
traverse((osg::Node&)geode);
// Call the app callbacks on the drawables.
for(unsigned int i=0;i<geode.getNumDrawables();++i)
{
osg::Drawable::EventCallback* callback = geode.getDrawable(i)->getEventCallback();
if (callback) callback->event(this,geode.getDrawable(i));
handle_callbacks(geode.getDrawable(i)->getStateSet());
}
}
osgGA::GUIActionAdapter* _actionAdapter;

View File

@ -16,7 +16,6 @@
#include <vector>
#include <osg/NodeCallback>
#include <osg/Drawable>
#include <osg/ApplicationUsage>
@ -54,7 +53,7 @@ public:
#if 1
GUIEventHandler() {}
GUIEventHandler(const GUIEventHandler& eh,const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY):
osg::Object(eh, copyop), EventHandler(eh, copyop) {}
osg::Callback(eh, copyop), EventHandler(eh, copyop) {}
#else
GUIEventHandler() : _ignoreHandledEventsMask(GUIEventAdapter::NONE) {}
GUIEventHandler(const GUIEventHandler& eh,const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY):
@ -123,7 +122,7 @@ protected:
unsigned int _ignoreHandledEventsMask;
#endif
protected:
protected:
virtual ~GUIEventHandler();
};

View File

@ -14,7 +14,7 @@
#define OSG_ANIMATIONMATERIAL 1
#include <osg/Material>
#include <osg/NodeCallback>
#include <osg/Callback>
#include <osgPresentation/Export>

View File

@ -15,7 +15,6 @@
#include <osg/UserDataContainer>
#include <osg/ValueObject>
#include <osg/NodeCallback>
#include <osg/ImageSequence>
#include <osgGA/GUIEventHandler>
@ -29,13 +28,13 @@ namespace osgPresentation
class PropertyManager : protected osg::Object
{
public:
PropertyManager() {}
PropertyManager(const PropertyManager& pm, const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY):
osg::Object(pm,copyop) {}
META_Object(osgPresentation, PropertyManager)
/** Convinience method that casts the named UserObject to osg::TemplateValueObject<T> and gets the value.
* To use this template method you need to include the osg/ValueObject header.*/
template<typename T>
@ -57,7 +56,7 @@ public:
int ref() const { return osg::Referenced::ref(); }
int unref() const { return osg::Referenced::unref(); }
protected:
mutable OpenThreads::Mutex _mutex;
@ -125,7 +124,7 @@ struct PropertyReader
bool _errorGenerated;
osg::NodePath _nodePath;
std::istringstream _sstream;
std::istringstream _sstream;
};
@ -176,7 +175,7 @@ protected:
double _latestTime;
bool _pause;
double _pauseTime;
};

View File

@ -98,28 +98,30 @@ class OSGSHADOW_EXPORT MinimalDrawBoundsShadowMap
osg::observer_ptr< ViewData > _vd;
};
struct CameraCullCallback: public osg::NodeCallback {
struct CameraCullCallback: public osg::Callback {
CameraCullCallback(ViewData * vd, osg::NodeCallback * nc): _vd(vd), _nc(nc)
CameraCullCallback(ViewData * vd, osg::Callback * nc): _vd(vd), _nc(nc)
{
}
virtual void operator()(osg::Node* node, osg::NodeVisitor* nv)
virtual bool run(osg::Object* object, osg::Object* data)
{
osgUtil::CullVisitor *cv = dynamic_cast< osgUtil::CullVisitor *>( nv );
osgUtil::CullVisitor *cv = dynamic_cast< osgUtil::CullVisitor *>( data );
if( _nc.valid() )
_nc->operator()(node,nv);
_nc->run(object, data);
else
traverse(node,nv);
traverse(object, data);
if( cv )
_vd->recordShadowMapParams( );
return true;
}
protected:
osg::observer_ptr< ViewData > _vd;
osg::ref_ptr< osg::NodeCallback > _nc;
osg::ref_ptr< osg::Callback > _nc;
};
};

View File

@ -309,15 +309,15 @@ class OSGUTIL_EXPORT CullVisitor : public osg::NodeVisitor, public osg::CullStac
inline void handle_cull_callbacks_and_traverse(osg::Node& node)
{
osg::NodeCallback* callback = node.getCullCallback();
if (callback) (*callback)(&node,this);
osg::Callback* callback = node.getCullCallback();
if (callback) callback->run(&node,this);
else traverse(node);
}
inline void handle_cull_callbacks_and_accept(osg::Node& node,osg::Node* acceptNode)
{
osg::NodeCallback* callback = node.getCullCallback();
if (callback) (*callback)(&node,this);
osg::Callback* callback = node.getCullCallback();
if (callback) callback->run(&node,this);
else acceptNode->accept(*this);
}

View File

@ -15,7 +15,7 @@
#ifndef OSGUTIL_TRANSFORMCALLBACK
#define OSGUTIL_TRANSFORMCALLBACK 1
#include <osg/Node>
#include <osg/Callback>
#include <osgUtil/Export>
namespace osgUtil

View File

@ -15,7 +15,6 @@
#define OSGUTIL_UPDATEVISITOR 1
#include <osg/NodeVisitor>
#include <osg/Node>
#include <osg/Geode>
#include <osg/Billboard>
#include <osg/LOD>
@ -24,6 +23,7 @@
#include <osg/Transform>
#include <osg/Projection>
#include <osg/OccluderNode>
#include <osg/ScriptEngine>
#include <osgUtil/Export>
@ -50,17 +50,24 @@ class OSGUTIL_EXPORT UpdateVisitor : public osg::NodeVisitor
virtual void apply(osg::Drawable& drawable)
{
osg::Drawable::UpdateCallback* callback = drawable.getUpdateCallback();
if (callback) callback->update(this,&drawable);
osg::Callback* callback = drawable.getUpdateCallback();
if (callback)
{
osg::Drawable::UpdateCallback* drawable_callback = dynamic_cast<osg::Drawable::UpdateCallback*>(callback);
osg::NodeCallback* node_callback = dynamic_cast<osg::NodeCallback*>(callback);
osg::CallbackObject* callback_object = dynamic_cast<osg::CallbackObject*>(callback);
osg::NodeCallback* node_callback = drawable.osg::Node::getUpdateCallback();
if (node_callback) (*node_callback)(&drawable, this);
if (drawable_callback) drawable_callback->update(this,&drawable);
if (node_callback) (*node_callback)(&drawable, this);
if ((!drawable_callback && !node_callback) || callback_object) callback_object->run(&drawable, this);
}
handle_callbacks(drawable.getStateSet());
}
virtual void apply(osg::Geode& node) { handle_geode_callbacks(node); }
virtual void apply(osg::Billboard& node) { handle_geode_callbacks(node); }
virtual void apply(osg::Geode& node) { handle_callbacks_and_traverse(node); }
virtual void apply(osg::Billboard& node) { handle_callbacks_and_traverse(node); }
virtual void apply(osg::LightSource& node) { handle_callbacks_and_traverse(node); }
@ -92,31 +99,10 @@ class OSGUTIL_EXPORT UpdateVisitor : public osg::NodeVisitor
{
handle_callbacks(node.getStateSet());
osg::NodeCallback* callback = node.getUpdateCallback();
if (callback) (*callback)(&node,this);
osg::Callback* callback = node.getUpdateCallback();
if (callback) callback->run(&node,this);
else if (node.getNumChildrenRequiringUpdateTraversal()>0) traverse(node);
}
inline void handle_geode_callbacks(osg::Geode& geode)
{
handle_callbacks(geode.getStateSet());
osg::NodeCallback* callback = geode.getUpdateCallback();
if (callback) (*callback)(&geode,this);
// Call the app callbacks on the drawables.
for(unsigned int i=0;i<geode.getNumDrawables();++i)
{
osg::Drawable::UpdateCallback* callback = geode.getDrawable(i)->getUpdateCallback();
if (callback) callback->update(this,geode.getDrawable(i));
handle_callbacks(geode.getDrawable(i)->getStateSet());
}
// should we traverse just in case a subclass of Geode adds children?? Won't for now as
// Geode's arn't designed to have children.
// traverse(geode);
}
};
}

View File

@ -525,7 +525,7 @@ protected:
InteractiveImageHandler() {}
InteractiveImageHandler(const InteractiveImageHandler&,const osg::CopyOp& = osg::CopyOp::SHALLOW_COPY):
osg::Object(), osgGA::GUIEventHandler(), osg::Drawable::CullCallback(), _fullscreen(false) {}
osg::Callback(), osgGA::GUIEventHandler(), osg::Drawable::CullCallback(), _fullscreen(false) {}
bool mousePosition(osgViewer::View* view, osg::NodeVisitor* nv, const osgGA::GUIEventAdapter& ea, int& x, int &y) const;

View File

@ -447,7 +447,9 @@ class OSGVOLUME_EXPORT PropertyAdjustmentCallback : public osgGA::GUIEventHandle
PropertyAdjustmentCallback(const PropertyAdjustmentCallback&,const osg::CopyOp&);
META_Object(osgVolume,PropertyAdjustmentCallback);
META_Object(osgVolume, PropertyAdjustmentCallback);
virtual bool run(osg::Object* object, osg::Object* data) { return osgGA::GUIEventHandler::run(object, data); }
void setKeyEventCycleForward(int key) { _cyleForwardKey = key; }
int getKeyEventCycleForward() const { return _cyleForwardKey; }

View File

@ -37,6 +37,7 @@ SET(TARGET_H
${HEADER_PATH}/buffered_value
${HEADER_PATH}/BufferIndexBinding
${HEADER_PATH}/BufferObject
${HEADER_PATH}/Callback
${HEADER_PATH}/Camera
${HEADER_PATH}/CameraView
${HEADER_PATH}/ClampColor
@ -230,6 +231,7 @@ SET(TARGET_SRC
BlendFunc.cpp
BufferIndexBinding.cpp
BufferObject.cpp
Callback.cpp
Camera.cpp
CameraView.cpp
ClampColor.cpp
@ -296,7 +298,6 @@ SET(TARGET_SRC
# Matrix_implementation.cpp
MatrixTransform.cpp
Multisample.cpp
NodeCallback.cpp
Node.cpp
NodeTrackerCallback.cpp
NodeVisitor.cpp

109
src/osg/Callback.cpp Normal file
View File

@ -0,0 +1,109 @@
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
*
* This library is open source and may be redistributed and/or modified under
* the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
* (at your option) any later version. The full license is in LICENSE file
* included with this distribution, and on the openscenegraph.org website.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* OpenSceneGraph Public License for more details.
*/
#include <osg/Node>
#include <osg/NodeVisitor>
#include <osg/ScriptEngine>
using namespace osg;
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//
// Callback
//
bool Callback::traverse(Object* object, Object* data)
{
if (_nestedCallback.valid()) return run(object, data);
else
{
#if 1
osg::Node* node = dynamic_cast<osg::Node*>(object);
osg::NodeVisitor* nv = dynamic_cast<osg::NodeVisitor*>(data);
#else
osg::Node* node = object ? data->asNode() : 0;
osg::NodeVisitor* nv = data ? data->asNodeVisitor() : 0;
#endif
if (node && nv)
{
nv->traverse(*node);
return true;
}
else return false;
}
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//
// CallbackObject
//
bool CallbackObject::run(osg::Object* object, osg::Object* data)
{
osg::Parameters inputParameters, outputParameters;
if (data && data->referenceCount()>=1)
{
inputParameters.push_back(data);
}
return run(object,inputParameters, outputParameters);
}
bool CallbackObject::run(osg::Object* object, osg::Parameters& inputParameters, osg::Parameters& outputParameters) const
{
OSG_NOTICE<<"CallbackObject::run(object="<<object<<")"<<std::endl;
return false;
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//
// NodeCallback
//
bool NodeCallback::run(osg::Object* object, osg::Object* data)
{
osg::Node* node = dynamic_cast<osg::Node*>(object);
osg::NodeVisitor* nv = dynamic_cast<osg::NodeVisitor*>(data);
if (node && nv)
{
operator()(node, nv);
return true;
}
else
{
return traverse(object, data);
}
}
void NodeCallback::operator()(Node* node, NodeVisitor* nv)
{
// note, callback is responsible for scenegraph traversal so
// they must call traverse(node,nv) to ensure that the
// scene graph subtree (and associated callbacks) are traversed.
traverse(node,nv);
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//
// StateAttributeCallback
//
bool StateAttributeCallback::run(osg::Object* object, osg::Object* data)
{
osg::StateAttribute* sa = dynamic_cast<osg::StateAttribute*>(object);
osg::NodeVisitor* nv = dynamic_cast<osg::NodeVisitor*>(data);
if (sa && nv)
{
operator()(sa, nv);
return true;
}
else
{
return traverse(object, data);
}
}

View File

@ -19,6 +19,7 @@
#include <osg/PrimitiveSet>
#include <osg/Shape>
#include <osg/StateAttribute>
#include <osg/Callback>
using namespace osg;
@ -66,19 +67,19 @@ StateAttribute* CopyOp::operator() (const StateAttribute* attr) const
return const_cast<StateAttribute*>(attr);
}
NodeCallback* CopyOp::operator() (const NodeCallback* nc) const
Callback* CopyOp::operator() (const Callback* nc) const
{
if (nc && _flags&DEEP_COPY_CALLBACKS)
{
// deep copy the full chain of callback
osg::NodeCallback* first = osg::clone(nc, *this);
Callback* first = osg::clone(nc, *this);
if (!first) return 0;
first->setNestedCallback(0);
nc = nc->getNestedCallback();
while (nc)
{
osg::NodeCallback* ucb = osg::clone(nc, *this);
Callback* ucb = osg::clone(nc, *this);
if (ucb)
{
ucb->setNestedCallback(0);
@ -89,5 +90,5 @@ NodeCallback* CopyOp::operator() (const NodeCallback* nc) const
return first;
}
else
return const_cast<NodeCallback*>(nc);
return const_cast<Callback*>(nc);
}

View File

@ -216,6 +216,36 @@ void Drawable::flushDeletedDisplayLists(unsigned int contextID, double& availabl
#endif
}
bool Drawable::UpdateCallback::run(osg::Object* object, osg::Object* data)
{
osg::Drawable* drawable = dynamic_cast<osg::Drawable*>(object);
osg::NodeVisitor* nv = dynamic_cast<osg::NodeVisitor*>(data);
if (drawable && nv)
{
update(nv, drawable);
return true;
}
else
{
return traverse(object, data);
}
}
bool Drawable::EventCallback::run(osg::Object* object, osg::Object* data)
{
osg::Drawable* drawable = dynamic_cast<osg::Drawable*>(object);
osg::NodeVisitor* nv = dynamic_cast<osg::NodeVisitor*>(data);
if (drawable && nv)
{
event(nv, drawable);
return true;
}
else
{
return traverse(object, data);
}
}
Drawable::Drawable()
{
_boundingBoxComputed = false;
@ -468,48 +498,6 @@ void Drawable::dirtyDisplayList()
}
void Drawable::setUpdateCallback(UpdateCallback* ac)
{
if (_drawableUpdateCallback==ac) return;
int delta = 0;
if (_drawableUpdateCallback.valid()) --delta;
if (ac) ++delta;
_drawableUpdateCallback = ac;
if (delta!=0 && !(_stateset.valid() && _stateset->requiresUpdateTraversal()))
{
for(ParentList::iterator itr=_parents.begin();
itr!=_parents.end();
++itr)
{
(*itr)->setNumChildrenRequiringUpdateTraversal((*itr)->getNumChildrenRequiringUpdateTraversal()+delta);
}
}
}
void Drawable::setEventCallback(EventCallback* ac)
{
if (_drawableEventCallback==ac) return;
int delta = 0;
if (_drawableEventCallback.valid()) --delta;
if (ac) ++delta;
_drawableEventCallback = ac;
if (delta!=0 && !(_stateset.valid() && _stateset->requiresEventTraversal()))
{
for(ParentList::iterator itr=_parents.begin();
itr!=_parents.end();
++itr)
{
(*itr)->setNumChildrenRequiringEventTraversal( (*itr)->getNumChildrenRequiringEventTraversal()+delta );
}
}
}
struct ComputeBound : public PrimitiveFunctor
{
ComputeBound()

View File

@ -203,7 +203,7 @@ MatrixList Node::getWorldMatrices(const osg::Node* haltTraversalAtNode) const
return matrices;
}
void Node::setUpdateCallback(NodeCallback* nc)
void Node::setUpdateCallback(Callback* nc)
{
// if no changes just return.
if (_updateCallback==nc) return;
@ -281,7 +281,7 @@ void Node::setNumChildrenRequiringUpdateTraversal(unsigned int num)
}
void Node::setEventCallback(NodeCallback* nc)
void Node::setEventCallback(Callback* nc)
{
// if no changes just return.
if (_eventCallback==nc) return;

View File

@ -1,23 +0,0 @@
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
*
* This library is open source and may be redistributed and/or modified under
* the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
* (at your option) any later version. The full license is in LICENSE file
* included with this distribution, and on the openscenegraph.org website.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* OpenSceneGraph Public License for more details.
*/
#include <osg/Node>
#include <osg/NodeCallback>
#include <osg/NodeVisitor>
using namespace osg;
void NodeCallback::traverse(Node* node,NodeVisitor* nv)
{
if (_nestedCallback.valid()) (*_nestedCallback)(node,nv);
else nv->traverse(*node);
}

View File

@ -16,13 +16,6 @@
using namespace osg;
bool CallbackObject::run(osg::Object* object, osg::Parameters& inputParameters, osg::Parameters& outputParameters) const
{
OSG_NOTICE<<"CallbackObject::run(object="<<object<<")"<<std::endl;
return false;
}
ScriptEngine* ScriptNodeCallback::getScriptEngine(osg::NodePath& nodePath)
{
if (!_script) return 0;

View File

@ -12,6 +12,7 @@
#include <osg/StateAttribute>
#include <osg/StateSet>
#include <osg/State>
#include <osg/NodeVisitor>
#include <osg/Notify>
#include <algorithm>

View File

@ -84,6 +84,26 @@ bool osg::isTextureMode(StateAttribute::GLMode mode)
return getTextureGLModeSet().isTextureMode(mode);
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//
// StateAttributeCallback
//
bool StateSet::Callback::run(osg::Object* object, osg::Object* data)
{
osg::StateSet* ss = dynamic_cast<osg::StateSet*>(object);
osg::NodeVisitor* nv = dynamic_cast<osg::NodeVisitor*>(data);
if (ss && nv)
{
operator()(ss, nv);
return true;
}
else
{
return traverse(object, data);
}
}
StateSet::StateSet():
Object(true),
_nestRenderBins(true)

View File

@ -62,7 +62,7 @@ void AnimationManagerBase::operator()(osg::Node* node, osg::NodeVisitor* nv)
}
AnimationManagerBase::AnimationManagerBase(const AnimationManagerBase& b, const osg::CopyOp& copyop) : osg::Object(b, copyop), osg::NodeCallback(b,copyop) // TODO check this
AnimationManagerBase::AnimationManagerBase(const AnimationManagerBase& b, const osg::CopyOp& copyop) : osg::Callback(b, copyop), osg::NodeCallback(b,copyop) // TODO check this
{
const AnimationList& animationList = b.getAnimationList();
for (AnimationList::const_iterator it = animationList.begin();

View File

@ -64,7 +64,7 @@ void LinkVisitor::apply(osg::Node& node)
if (st)
handle_stateset(st);
osg::NodeCallback* cb = node.getUpdateCallback();
osg::Callback* cb = node.getUpdateCallback();
while (cb)
{
osgAnimation::AnimationUpdateCallbackBase* cba = dynamic_cast<osgAnimation::AnimationUpdateCallbackBase*>(cb);

View File

@ -466,7 +466,7 @@ struct FindTimelineStats : public osg::NodeVisitor
FindTimelineStats() : osg::NodeVisitor(osg::NodeVisitor::TRAVERSE_ALL_CHILDREN) {}
void apply(osg::Node& node) {
osg::NodeCallback* cb = node.getUpdateCallback();
osg::Callback* cb = node.getUpdateCallback();
while (cb) {
osgAnimation::TimelineAnimationManager* tam = dynamic_cast<osgAnimation::TimelineAnimationManager*>(cb);
if (tam)

View File

@ -21,7 +21,7 @@ CameraManipulator::CameraManipulator()
CameraManipulator::CameraManipulator(const CameraManipulator& mm, const CopyOp& copyOp)
: osg::Object(mm, copyOp),
: osg::Callback(mm, copyOp),
inherited(mm, copyOp),
_intersectTraversalMask(mm._intersectTraversalMask),
_autoComputeHomePosition(mm._autoComputeHomePosition),

View File

@ -44,7 +44,7 @@ FirstPersonManipulator::FirstPersonManipulator( int flags )
/// Constructor.
FirstPersonManipulator::FirstPersonManipulator( const FirstPersonManipulator& fpm, const CopyOp& copyOp )
: osg::Object(fpm, copyOp),
: osg::Callback(fpm, copyOp),
inherited( fpm, copyOp ),
_eye( fpm._eye ),
_rotation( fpm._rotation ),

View File

@ -28,7 +28,7 @@ FlightManipulator::FlightManipulator( int flags )
/// Constructor.
FlightManipulator::FlightManipulator( const FlightManipulator& fm, const CopyOp& copyOp )
: osg::Object(fm, copyOp),
: osg::Callback(fm, copyOp),
inherited( fm, copyOp ),
_yawMode( fm._yawMode )
{

View File

@ -30,7 +30,7 @@ MultiTouchTrackballManipulator::MultiTouchTrackballManipulator( int flags )
/// Constructor.
MultiTouchTrackballManipulator::MultiTouchTrackballManipulator( const MultiTouchTrackballManipulator& tm, const CopyOp& copyOp )
: osg::Object(tm, copyOp), inherited( tm, copyOp )
: osg::Callback(tm, copyOp), inherited( tm, copyOp )
{
}

View File

@ -30,7 +30,7 @@ NodeTrackerManipulator::NodeTrackerManipulator( int flags )
NodeTrackerManipulator::NodeTrackerManipulator( const NodeTrackerManipulator& m, const CopyOp& copyOp )
: osg::Object(m, copyOp),
: osg::Callback(m, copyOp),
inherited( m, copyOp ),
_trackNodePath( m._trackNodePath ),
_trackerMode( m._trackerMode )

View File

@ -43,7 +43,7 @@ OrbitManipulator::OrbitManipulator( int flags )
/// Constructor.
OrbitManipulator::OrbitManipulator( const OrbitManipulator& om, const CopyOp& copyOp )
: osg::Object(om, copyOp),
: osg::Callback(om, copyOp),
inherited( om, copyOp ),
_center( om._center ),
_rotation( om._rotation ),

View File

@ -48,7 +48,7 @@ StandardManipulator::StandardManipulator( int flags )
/// Constructor.
StandardManipulator::StandardManipulator( const StandardManipulator& uim, const CopyOp& copyOp )
: osg::Object(uim, copyOp),
: osg::Callback(uim, copyOp),
inherited( uim, copyOp ),
_thrown( uim._thrown ),
_allowThrow( uim._allowThrow ),

View File

@ -29,7 +29,7 @@ TerrainManipulator::TerrainManipulator( int flags )
/// Constructor.
TerrainManipulator::TerrainManipulator( const TerrainManipulator& tm, const CopyOp& copyOp )
: osg::Object(tm, copyOp),
: osg::Callback(tm, copyOp),
inherited( tm, copyOp ),
_previousUp( tm._previousUp )
{

View File

@ -28,7 +28,7 @@ TrackballManipulator::TrackballManipulator( int flags )
/// Constructor.
TrackballManipulator::TrackballManipulator( const TrackballManipulator& tm, const CopyOp& copyOp )
: osg::Object(tm, copyOp),
: osg::Callback(tm, copyOp),
inherited( tm, copyOp )
{
}

View File

@ -46,7 +46,7 @@ public:
parent->setMatrixInSkeletonSpace( osg::Matrix::translate(offset) *
parent->getMatrixInSkeletonSpace() );
osgAnimation::UpdateBone* updateBone =
static_cast<osgAnimation::UpdateBone*>( parent->getUpdateCallback() );
dynamic_cast<osgAnimation::UpdateBone*>( parent->getUpdateCallback() );
if ( updateBone )
{
osgAnimation::StackedTransform& stack = updateBone->getStackedTransforms();

View File

@ -758,7 +758,7 @@ daeReader::ChannelPart* daeReader::processSampler(domChannel* pDomChannel, Sourc
return NULL;
}
osgAnimation::Target* findChannelTarget(osg::NodeCallback* nc, const std::string& targetName, bool& rotation)
osgAnimation::Target* findChannelTarget(osg::Callback* nc, const std::string& targetName, bool& rotation)
{
if (osgAnimation::UpdateMatrixTransform* umt = dynamic_cast<osgAnimation::UpdateMatrixTransform*>(nc))
{
@ -827,7 +827,7 @@ void daeReader::processChannel(domChannel* pDomChannel, SourceMap& sources, Targ
domChannelOsgAnimationUpdateCallbackMap::iterator iter = _domChannelOsgAnimationUpdateCallbackMap.find(pDomChannel);
if (iter != _domChannelOsgAnimationUpdateCallbackMap.end())
{
osg::NodeCallback* nc = iter->second.get();
osg::Callback* nc = iter->second.get();
std::string channelName, targetName, componentName;
extractTargetName(pDomChannel->getTarget(), channelName, targetName, componentName);

View File

@ -44,7 +44,7 @@ osg::Transform* daeReader::processOsgMatrixTransform(domNode *node, bool isBone)
resultNode = new osg::MatrixTransform;
}
osg::NodeCallback* pNodeCallback = resultNode->getUpdateCallback();
osg::Callback* pNodeCallback = resultNode->getUpdateCallback();
std::vector<osg::ref_ptr<osgAnimation::StackedTransformElement> > transformElements;
osg::ref_ptr<osgAnimation::StackedTransformElement> pLastStaticTransformElement;

View File

@ -241,7 +241,7 @@ public:
typedef std::map<domMaterial*, osg::ref_ptr<osg::StateSet> > domMaterialStateSetMap;
typedef std::map<std::string, osg::ref_ptr<osg::StateSet> > MaterialStateSetMap;
typedef std::multimap< daeElement*, domChannel*> daeElementDomChannelMap;
typedef std::map<domChannel*, osg::ref_ptr<osg::NodeCallback> > domChannelOsgAnimationUpdateCallbackMap;
typedef std::map<domChannel*, osg::ref_ptr<osg::Callback> > domChannelOsgAnimationUpdateCallbackMap;
typedef std::map<domNode*, osg::ref_ptr<osgAnimation::Bone> > domNodeOsgBoneMap;
typedef std::map<domNode*, osg::ref_ptr<osgAnimation::Skeleton> > domNodeOsgSkeletonMap;
typedef std::map<TextureParameters, osg::ref_ptr<osg::Texture2D> > TextureParametersMap;

View File

@ -37,7 +37,7 @@ using namespace osgDAE;
void daeWriter::writeAnimations( osg::Node &node )
{
const std::string nodeNameUTF( _pluginOptions.namesUseCodepage ? osgDB::convertStringFromCurrentCodePageToUTF8(node.getName()) : node.getName() );
osg::NodeCallback* ncb = node.getUpdateCallback();
osg::Callback* ncb = node.getUpdateCallback();
if (ncb)
{
osgAnimation::AnimationManagerBase* am = dynamic_cast<osgAnimation::AnimationManagerBase*>(ncb);

View File

@ -67,7 +67,7 @@ void daeWriter::apply( osg::MatrixTransform &node )
std::string nodeName = getNodeName(node,"matrixTransform");
currentNode->setId(nodeName.c_str());
osg::NodeCallback* ncb = node.getUpdateCallback();
osg::Callback* ncb = node.getUpdateCallback();
bool handled = false;
if (ncb)
{
@ -124,7 +124,7 @@ void daeWriter::apply( osg::PositionAttitudeTransform &node )
const osg::Quat &q = node.getAttitude();
const osg::Vec3 &s = node.getScale();
osg::NodeCallback* ncb = node.getUpdateCallback();
osg::Callback* ncb = node.getUpdateCallback();
bool handled = false;
if (ncb)
{
@ -287,7 +287,7 @@ void daeWriter::apply( osg::Transform &node )
osg::Matrix matrix;
node.computeLocalToWorldMatrix(matrix, NULL);
osg::NodeCallback* ncb = node.getUpdateCallback();
osg::Callback* ncb = node.getUpdateCallback();
bool handled = false;
if (ncb)
{
@ -309,7 +309,7 @@ void daeWriter::apply( osg::Transform &node )
domMatrix *mat = daeSafeCast< domMatrix >(currentNode->add( COLLADA_ELEMENT_MATRIX ) );
nodeName += "_matrix";
mat->setSid(nodeName.c_str());
const osg::Matrix::value_type *mat_vals = matrix.ptr();
for ( int i = 0; i < 4; i++ )
{

View File

@ -93,7 +93,7 @@ public:
virtual void apply(osg::Node& node)
{
osg::NodeCallback* ncb = node.getUpdateCallback();
osg::Callback* ncb = node.getUpdateCallback();
if (ncb)
{
osgAnimation::AnimationUpdateCallback<osg::NodeCallback>* ut = dynamic_cast<osgAnimation::AnimationUpdateCallback<osg::NodeCallback>*>(ncb);

View File

@ -37,7 +37,6 @@
#include <osg/Group>
#include <osg/NodeVisitor>
#include <osg/NodeCallback>
#include <osg/ref_ptr>
#include "TXPArchive.h"

View File

@ -985,8 +985,11 @@ void CullVisitor::apply(osg::Drawable& drawable)
if( drawable.getCullCallback() )
{
if( drawable.getCullCallback()->cull( this, &drawable, &_renderInfo ) == true )
return;
osg::Drawable::CullCallback* dcb = dynamic_cast<osg::Drawable::CullCallback*>(drawable.getCullCallback());
if (dcb)
{
if( dcb->cull( this, &drawable, &_renderInfo ) == true ) return;
}
}
if (!getNodePath().empty() && getNodePath().back()->isCullingActive() && isCulled(bb)) return;
@ -1073,7 +1076,8 @@ void CullVisitor::apply(Billboard& node)
if( drawable->getCullCallback() )
{
if( drawable->getCullCallback()->cull( this, drawable, &_renderInfo ) == true )
osg::Drawable::CullCallback* dcb = dynamic_cast<osg::Drawable::CullCallback*>(drawable->getCullCallback());
if (dcb && dcb->cull( this, drawable, &_renderInfo ) == true )
continue;
}

View File

@ -903,8 +903,8 @@ bool SceneView::cullStage(const osg::Matrixd& projection,const osg::Matrixd& mod
// If the camera has a cullCallback execute the callback which has the
// requirement that it must traverse the camera's children.
{
osg::NodeCallback* callback = _camera->getCullCallback();
if (callback) (*callback)(_camera.get(), cullVisitor);
osg::Callback* callback = _camera->getCullCallback();
if (callback) callback->run(_camera.get(), cullVisitor);
else cullVisitor->traverse(*_camera);
}

View File

@ -1,6 +1,6 @@
#include <osg/Notify>
#include <osg/NodeCallback>
#include <osg/Callback>
#include <osgDB/Registry>
#include <osgDB/Input>

View File

@ -0,0 +1,18 @@
#undef OBJECT_CAST
#define OBJECT_CAST dynamic_cast
#include <osg/Node>
#include <osgDB/ObjectWrapper>
#include <osgDB/InputStream>
#include <osgDB/OutputStream>
REGISTER_OBJECT_WRAPPER( Callback,
new osg::Callback,
osg::Callback,
"osg::Object osg::Callback" )
{
ADD_OBJECT_SERIALIZER( NestedCallback, osg::Callback, NULL ); // _nestedCallback
}
#undef OBJECT_CAST
#define OBJECT_CAST static_cast

View File

@ -43,8 +43,8 @@ REGISTER_OBJECT_WRAPPER( Drawable,
ADD_BOOL_SERIALIZER( SupportsDisplayList, true ); // _supportsDisplayList
ADD_BOOL_SERIALIZER( UseDisplayList, true ); // _useDisplayList
ADD_BOOL_SERIALIZER( UseVertexBufferObjects, false ); // _useVertexBufferObjects
ADD_OBJECT_SERIALIZER( UpdateCallback, osg::Drawable::UpdateCallback, NULL ); // _updateCallback
ADD_OBJECT_SERIALIZER( EventCallback, osg::Drawable::EventCallback, NULL ); // _eventCallback
ADD_OBJECT_SERIALIZER( CullCallback, osg::Drawable::CullCallback, NULL ); // _cullCallback
ADD_OBJECT_SERIALIZER( UpdateCallback, osg::Callback, NULL ); // _updateCallback
ADD_OBJECT_SERIALIZER( EventCallback, osg::Callback, NULL ); // _eventCallback
ADD_OBJECT_SERIALIZER( CullCallback, osg::Callback, NULL ); // _cullCallback
ADD_OBJECT_SERIALIZER( DrawCallback, osg::Drawable::DrawCallback, NULL ); // _drawCallback
}

View File

@ -72,9 +72,9 @@ REGISTER_OBJECT_WRAPPER( Node,
ADD_USER_SERIALIZER( InitialBound ); // _initialBound
ADD_OBJECT_SERIALIZER( ComputeBoundingSphereCallback,
osg::Node::ComputeBoundingSphereCallback, NULL ); // _computeBoundCallback
ADD_OBJECT_SERIALIZER( UpdateCallback, osg::NodeCallback, NULL ); // _updateCallback
ADD_OBJECT_SERIALIZER( EventCallback, osg::NodeCallback, NULL ); // _eventCallback
ADD_OBJECT_SERIALIZER( CullCallback, osg::NodeCallback, NULL ); // _cullCallback
ADD_OBJECT_SERIALIZER( UpdateCallback, osg::Callback, NULL ); // _updateCallback
ADD_OBJECT_SERIALIZER( EventCallback, osg::Callback, NULL ); // _eventCallback
ADD_OBJECT_SERIALIZER( CullCallback, osg::Callback, NULL ); // _cullCallback
ADD_BOOL_SERIALIZER( CullingActive, true ); // _cullingActive
ADD_HEXINT_SERIALIZER( NodeMask, 0xffffffff ); // _nodeMask

View File

@ -1,6 +1,3 @@
#undef OBJECT_CAST
#define OBJECT_CAST dynamic_cast
#include <osg/Node>
#include <osgDB/ObjectWrapper>
#include <osgDB/InputStream>
@ -9,10 +6,6 @@
REGISTER_OBJECT_WRAPPER( NodeCallback,
new osg::NodeCallback,
osg::NodeCallback,
"osg::Object osg::NodeCallback" )
"osg::Object osg::Callback osg::NodeCallback" )
{
ADD_OBJECT_SERIALIZER( NestedCallback, osg::NodeCallback, NULL ); // _nestedCallback
}
#undef OBJECT_CAST
#define OBJECT_CAST static_cast