H3D API  2.4.1
Classes | Public Types | Public Member Functions | Static Public Member Functions | Public Attributes | Static Public Attributes | List of all members
H3D::Scene Class Reference

The Scene node is topmost node that takes care of the rendering of the scene graph both haptically and graphically. More...

#include <H3D/Scene.h>

Inheritance diagram for H3D::Scene:
Inheritance graph

Classes

class  EventSink
 The EventSink class makes all fields up-to-date what are routed to it, with the exception of PeriodicUpdateFields. More...
 

Public Types

enum  CallbackCode { CALLBACK_DONE , CALLBACK_CONTINUE }
 Return code for callback functions. More...
 
typedef CallbackCode(* CallbackFunc) (void *data)
 Callback function type.
 
typedef void(* ProgramSettingsCallbackFunc) (ProgramSettingsEvent event, const ProgramSetting &settings, void *data)
 Callback function type.
 
- Public Types inherited from H3D::Node
typedef std::map< Node *, Node * > DeepCopyMap
 A map type used during a deep copy clone() to map from original nodes to cloned nodes.
 

Public Member Functions

 Scene (Inst< SFChildNode > _sceneRoot=0, Inst< MFWindow > _window=0, Inst< SFFloat > _frameRate=0, Inst< MFString > _profiledResult=0, Inst< SFFloat > _maxFrameRate=0, Inst< SFNvidiaGraphicsOptions > _nvidiaGraphicsOptions=0)
 Constructor.
 
 ~Scene ()
 Destructor.
 
TraverseInfogetLastTraverseInfo ()
 Returns the TraverseInfo from the previous sceneRoot traversal.
 
void setActive (bool _active)
 Set whether this Scene instance should be active or not. More...
 
bool isActive ()
 Returns if the Scene instance is active or not.
 
virtual void idle ()
 This function will be called by the event loop when there are no other events to process and the Scene is active. More...
 
void loadSceneRoot (const string &url)
 Load the scene graph that is to be the root of the Scene object. More...
 
void setSceneRoot (SAI::SAIScene *scene_info)
 Set the scene to use based on a SAIScene object.
 
SAI::Browser * getSAIBrowser ()
 Returns the SAI::Browser object for this Scene.
 
- Public Member Functions inherited from H3D::Node
 Node ()
 Constructor.
 
virtual Nodeclone (bool deepCopy=true, DeepCopyMap *deepCopyMap=NULL)
 Returns a new instance of this node type with the same state as this one. More...
 
virtual ~Node ()
 Destructor.
 
X3DPrototypeInstancegetProtoInstanceParent ()
 If this node is the root node in the proto body of a X3DPrototypeInstance then this will return that node. More...
 
void setProtoInstanceParent (X3DPrototypeInstance *p)
 Set the X3DPrototypeInstance this node is the the root node if applicaple.
 
virtual void render ()
 the render() function is used for the depth-first rendering traversal of the scene-graph. More...
 
virtual void traverseSG (TraverseInfo &ti)
 traverseSG is called once per scenegraph loop on the scene in order to traverse the scenegraph. More...
 
virtual bool lineIntersect (const Vec3f &from, const Vec3f &to, LineIntersectResult &result)
 Detect intersection between a line segment and the Node. More...
 
virtual void closestPoint (const Vec3f &p, NodeIntersectResult &result)
 Find closest point on Node to p. More...
 
virtual bool movingSphereIntersect (H3DFloat radius, const Vec3f &from, const Vec3f &to, NodeIntersectResult &result)
 Detect collision between a moving sphere and the Node. More...
 
virtual string defaultXMLContainerField ()
 Returns the default xml containerField attribute value. More...
 
virtual FieldgetField (const string &_name) const
 return a pointer to the field specified by name within this instance
 
int addDestructCallback (void(*func)(Node *, void *), void *args)
 Add a callback function to be run on destruction of node. More...
 
int removeDestructCallback (void(*func)(Node *, void *), void *args)
 Add a callback function to be run on destruction of node. More...
 

Static Public Member Functions

static void mainLoop ()
 Static function that is called to start the main event loop. More...
 
static void addCallback (CallbackFunc func, void *data)
 Add a callback function to be called after scene traversal and rendering.
 
static void addProgramSetting (Field *field, const string &name="", const string &section="Main settings")
 Add a program setting value. More...
 
static bool removeProgramSetting (const string &name, const string &section="Main settings")
 Remove a program setting value. More...
 
static bool removeProgramSetting (Field *field)
 Remove all program settings referring to a field. More...
 
static FieldgetProgramSetting (const string &name, const string &section="Main settings")
 Get a program setting value. More...
 
static SettingsIterator programSettingsBegin ()
 Get an iterator to the first element of the program settings. More...
 
static SettingsIterator programSettingsEnd ()
 Get an iterator to the end of the program settings.
 
static ProgramSettingsCallbackId addProgramSettingsCallback (ProgramSettingsCallbackFunc func, void *data)
 Add a callback function to be called each time a new program settings value is added, removed or changed.
 
static bool removeProgramSettingsCallback (ProgramSettingsCallbackId id)
 Remove a program settings callback function.
 
static void clearProgramSettingsCallbacks ()
 Remove all program setting callback functions.
 
static H3D::NodefindChildNode (H3D::X3DGroupingNode *group, const std::string &nodeType, const std::string &nodeName="")
 Find a child node for a given group node with a certain nodeType and optional name.
 
static H3D::NodefindNodeType (H3D::Node *node, const std::string &nodeType, const std::string &nodeName="")
 Top down search for a node with a certain nodeType and optional name starting from node passed as argument.
 
template<typename NodeType >
static void findNodes (Node &_node, AutoRefVector< NodeType > &_result, const std::string &_nodeName="", NodeParentsMap *_parentMap=NULL, SearchFieldNameMap *_searchFieldNames=NULL, StringVec *_typeNames=NULL, bool _exactNodeName=true, bool _verbose=false, Node *_parent=NULL, StringVec *_ignoreTraverseNodeTypeNames=NULL)
 Finds all the nodes of a given type (and optional name) by searching downwards from _node through all SFNode and MFNode fields. More...
 
static void removeCallback (void *data)
 Remove a callback function by finding a callback with the same data adress.
 
- Static Public Member Functions inherited from H3D::Node
static unsigned int nrNodesAlive ()
 Returns the nr of nodes currently alive, i.e. nodes created but not destructed.
 
static int nrNodesCreated ()
 Returns the number of nodes created in total since the start of the program.
 

Public Attributes

H3DUniquePtr< SFChildNodesceneRoot
 The scene graph to render in this scene. More...
 
H3DUniquePtr< MFWindowwindow
 The windows to render into this scene. More...
 
H3DUniquePtr< SFFloatframeRate
 The instantaneous frame rate of the scene. More...
 
H3DUniquePtr< SFFloatmaxFrameRate
 A desired maximum frame rate (Hz). More...
 

Static Public Attributes

static H3DUniquePtr< SFTimetime
 Current time within the simulation, updated during each graphic loop. More...
 
static set< Scene * > scenes
 All instances of Scene that has been created.
 
static H3DNodeDatabase database
 The H3DNodeDatabase for this node.
 
static H3DUniquePtr< EventSinkeventSink
 Any field routed to this field will be updated once per frame.
 

Additional Inherited Members

- Protected Member Functions inherited from H3D::Node
void cloneFieldValue (Field &_from, Field &_to, bool deepCopy, DeepCopyMap &deepCopyMap)
 A helper function for the clone() method. More...
 
- Static Protected Member Functions inherited from H3D::Node
static NodegetClonedInstance (Node *original, bool deepCopy, DeepCopyMap &deepCopyMap)
 A helper function for nodes that implement clone() More...
 

Detailed Description

The Scene node is topmost node that takes care of the rendering of the scene graph both haptically and graphically.

Scene::mainLoop() can be called to start the main event loop when using GLUT, e.g. start the haptic and graphical rendering. Before this function is called at least one instance of Scene must have created and be active.

Member Enumeration Documentation

◆ CallbackCode

Return code for callback functions.

Enumerator
CALLBACK_DONE 

The callback is done and should not be called any more.

CALLBACK_CONTINUE 

The callback should be rescheduled and called the next loop again.

Member Function Documentation

◆ addProgramSetting()

void Scene::addProgramSetting ( Field field,
const string &  name = "",
const string &  section = "Main settings" 
)
static

Add a program setting value.

A program setting value is a global Field value assiciated with a name. These settings can be used in GUIs in e.g. H3DViewer to allow a user to change the values. Settings can be dynamically added and removed during the execution of a program.

Parameters
fieldThe field to assiciate the name with. A field will be automatically removed from the settings if destructed somewhere else.
nameThe name of the parameter. If "" the name of the field will be used.
sectionThe type if paramter it is, e.g. graphics.

References H3D::Field::getName(), H3D::Field::markProgramSetting(), and H3DUtil::RefCountedClass::name.

◆ findNodes()

template<typename NodeType >
static void H3D::Scene::findNodes ( Node _node,
AutoRefVector< NodeType > &  _result,
const std::string &  _nodeName = "",
NodeParentsMap *  _parentMap = NULL,
SearchFieldNameMap *  _searchFieldNames = NULL,
StringVec *  _typeNames = NULL,
bool  _exactNodeName = true,
bool  _verbose = false,
Node _parent = NULL,
StringVec *  _ignoreTraverseNodeTypeNames = NULL 
)
inlinestatic

Finds all the nodes of a given type (and optional name) by searching downwards from _node through all SFNode and MFNode fields.

Parameters
[in]_nodeThe node to start searching down from
[out]_resultThe list of nodes found matching the search criteria. The type of this parameter is used to define the type of nodes to search for. Only nodes that can be dynamically cast to NodeType will be included in the results.
[in]_nodeNameThe name of the node(s) to find. If not empty then only nodes matching this name are found. If empty, then nodes of any name are found.
[out]_parentMapA map from a found node to a list of the node's parents. If NULL then no information about the found node's parents is collected.
[in]_searchFieldNamesA map from node type name, to a list of field names to search through for that node type. If NULL then all fields are searched.
[in]_typeNamesList of acceptable node type names that found nodes must match.
[in]_exactNodeNameIf true, then _nodeName must exactly match the node's name, otherwise the node's name must just contain _nodeName.
[in]_verboseIf true, then output will be written to the Console to show the search path.
[in]_parentThe parent of this node. Used during recursion, should usually be left as NULL when called from user code.
[in]_ignoreTraverseNodeTypeNamesThe nodes with type name in the _ignoreTraverseNodeTypeNames will neither be traversed nor added to the result.

Examples:

// Find all Shape nodes in a scene
AutoRefVector<Shape> shapes;
Scene::findNodes ( *scene, shapes );
// Find all Shape node with name "MyShape"
AutoRefVector<Shape> shapes;
Scene::findNodes ( *scene, shapes, "MyShape" );
// Find all Material nodes and their parents and display them
AutoRefVector<Material> materials;
Scene::NodeParentsMap parents;
Scene::findNodes ( *scene, materials, "", &parents );
for ( AutoRefVector<Material>::const_iterator i= materials.begin(); i != materials.end(); ++i ) {
Console(LogLevel::Error) << *i << " " << (*i)->getName() << endl;
Console(LogLevel::Error) << "Parents: " << endl;
const AutoRefVector<Node>& node_parents= parents[*i];
for ( AutoRefVector<Node>::const_iterator j= node_parents.begin(); j != node_parents.end(); ++j ) {
Console(LogLevel::Error) << *j << " " << (*j)->getName() << endl;
}
}
// Find all Material nodes, but only search through specific fields
AutoRefVector<Material> materials;
Scene::SearchFieldNameMap search_fields;
search_fields["Scene"].push_back ( "sceneRoot" );
search_fields["Group"].push_back ( "children" );
search_fields["Anchor"].push_back ( "children" );
search_fields["Shape"].push_back ( "appearance" );
search_fields["Appearance"].push_back ( "material" );
Scene::findNodes ( *scene, materials, "", NULL, &search_fields );
std::vector< RefCountedClassType * >::const_iterator const_iterator
static void findNodes(Node &_node, AutoRefVector< NodeType > &_result, const std::string &_nodeName="", NodeParentsMap *_parentMap=NULL, SearchFieldNameMap *_searchFieldNames=NULL, StringVec *_typeNames=NULL, bool _exactNodeName=true, bool _verbose=false, Node *_parent=NULL, StringVec *_ignoreTraverseNodeTypeNames=NULL)
Finds all the nodes of a given type (and optional name) by searching downwards from _node through all...
Definition: Scene.h:403

◆ getProgramSetting()

Field * Scene::getProgramSetting ( const string &  name,
const string &  section = "Main settings" 
)
static

Get a program setting value.

Parameters
nameThe name of the parameter.
sectionThe type if paramter it is, e.g. graphics.
Returns
The field that matches the name if it exists, NULL otherwise.

References H3DUtil::RefCountedClass::name.

Referenced by removeProgramSetting().

◆ idle()

void Scene::idle ( )
virtual

This function will be called by the event loop when there are no other events to process and the Scene is active.

Performs the rendering.

References H3D::X3DViewpointNode::accForwardMatrix, H3D::GraphicsOptions::bindlessTexturesUnusedTime, CALLBACK_DONE, H3D::TraverseInfo::callPostTraverseCallbacks(), H3D::DefaultAppearance::defaultAppearance, H3D::DeviceInfo::device, H3D::X3DShapeNode::disable_lighting_if_no_app, eventSink, frameRate, H3D::DeviceInfo::getActive(), H3D::GlobalSettings::getActive(), H3D::NavigationInfo::getActive(), H3D::X3DViewpointNode::getActive(), H3DUtil::ThreadBase::getCurrentThreadId(), H3D::Node::getField(), H3D::H3DHapticsDevice::getHAPIDevice(), H3DUtil::ThreadBase::getMainThreadId(), H3D::TraverseInfo::getMultiPassTransparency(), H3D::GlobalSettings::getOptionNode(), H3D::H3DHapticsDevice::getThread(), H3DUtil::ThreadBase::getThreadId(), H3DUtil::ThreadBase::getThreadName(), H3D::NavigationInfo::headlight, H3D::NavigationInfo::headlightShadows, H3D::H3DHapticsDevice::initialized, H3DUtil::MutexLock::lock(), H3D::H3DSingleTextureNode::makeUnusedTexturesNonResident(), H3D::Appearance::material, maxFrameRate, H3DUtil::Exception::H3DException::message, H3D::RenderProperties::multiPassTransparency, H3D::TraverseInfo::nrLayers(), H3D::H3DHapticsDevice::postRender(), H3D::H3DHapticsDevice::preRender(), H3D::H3DDisplayListObject::DisplayList::rebuildAllDisplayLists(), H3D::H3DWindowNode::render(), H3D::H3DHapticsDevice::renderEffects(), H3D::Appearance::renderProperties, H3D::H3DHapticsDevice::renderShapes(), H3D::Anchor::replaceSceneRoot(), H3D::H3DMultiPassRenderObject::resetCounters(), Rotation(), sceneRoot, H3D::X3DAppearanceNode::setDefaultUsingMultiPassTransparency(), H3D::H3DWindowNode::setMultiPassTransparency(), H3D::H3DHapticsDevice::stylus, time, H3D::X3DViewpointNode::totalOrientation, H3D::H3DHapticsDevice::trackerOrientation, H3D::Node::traverseSG(), H3DUtil::MutexLock::unlock(), H3D::H3DHapticsDevice::updateDeviceValues(), H3D::X3DProgrammableShaderObject::use_bindless_textures, H3D::H3DHapticsDevice::weightedProxyPosition, and window.

◆ loadSceneRoot()

void Scene::loadSceneRoot ( const string &  url)

Load the scene graph that is to be the root of the Scene object.

This function should always be used instead of setting sceneRoot directly in order to keep SAI information up to data.

References H3D::X3D::createX3DFromURL().

◆ mainLoop()

void Scene::mainLoop ( )
static

Static function that is called to start the main event loop.

Before this function is called at least one instance of Scene must have created and be active.

References H3D::GLUTWindow::initGLUT().

◆ programSettingsBegin()

Scene::SettingsIterator Scene::programSettingsBegin ( )
static

Get an iterator to the first element of the program settings.

Adding or removing a new program setting will make this iterator invalid.

◆ removeProgramSetting() [1/2]

bool Scene::removeProgramSetting ( const string &  name,
const string &  section = "Main settings" 
)
static

Remove a program setting value.

Parameters
nameThe name of the parameter. If "" the name of the field will be used.
sectionThe type if paramter it is, e.g. graphics.
Returns
true if successful, false otherwise.

References getProgramSetting(), and H3DUtil::RefCountedClass::name.

Referenced by removeProgramSetting(), and H3D::Field::~Field().

◆ removeProgramSetting() [2/2]

bool Scene::removeProgramSetting ( Field field)
static

Remove all program settings referring to a field.

Parameters
fieldThe field which settings to remove.
Returns
true if successfully removed, false otherwise.

References H3D::Field::markProgramSetting(), and removeProgramSetting().

◆ setActive()

void H3D::Scene::setActive ( bool  _active)
inline

Set whether this Scene instance should be active or not.

If a Scene is not active it will not be rendered at all.

Member Data Documentation

◆ frameRate

H3DUniquePtr< SFFloat > H3D::Scene::frameRate

The instantaneous frame rate of the scene.

Access type: outputOnly

Referenced by idle(), and Scene().

◆ maxFrameRate

H3DUniquePtr< SFFloat > H3D::Scene::maxFrameRate

A desired maximum frame rate (Hz).

If there is time left over the simulation loop will go to sleep in order to keep the frame rate below this maximum.

If <= 0 then the simulation loop will always run as fast as possible.

Access type: outputOnly

Referenced by idle(), and Scene().

◆ sceneRoot

H3DUniquePtr< SFChildNode > H3D::Scene::sceneRoot

The scene graph to render in this scene.

Access type: inputOutput

Referenced by idle(), and H3D::Anchor::replaceSceneRoot().

◆ time

H3DUniquePtr< SFTime > Scene::time
static

◆ window

H3DUniquePtr< MFWindow > H3D::Scene::window

The documentation for this class was generated from the following files: