RobWorkProject  24.12.4-
Classes | Public Types | Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
SceneGraph Class Referenceabstract

interface for a minimalistic scenegraph that does not depend on the frame structure. See WorkCellScene for an implementation that wraps this interface to enable a more RobWork specific use. More...

#include <SceneGraph.hpp>

Inherited by SceneOpenGL.

Classes

struct  SceneGraphRenderInfo
 all general render information is located in this struct More...
 

Public Types

typedef rw::core::Ptr< SceneGraphPtr
 smart pointer type of this class
 
typedef DrawableNode::DrawType DrawType
 Drawing types.
 
using RenderInfo = SceneGraphRenderInfo
 
typedef boost::function< bool(rw::core::Ptr< rw::graphics::SceneNode > &node, rw::core::Ptr< rw::graphics::SceneNode > &parent)> NodeVisitor
 Type of a visitor function. Returns true if visit is done.
 
typedef boost::function< bool(const rw::core::Ptr< rw::graphics::SceneNode > &node)> NodeFilter
 Type of a filter function.
 

Public Member Functions

virtual ~SceneGraph ()
 Destructor.
 
virtual void draw (RenderInfo &info)=0
 draws the scene, using the specified render information More...
 
virtual DrawableNode::Ptr pickDrawable (RenderInfo &info, int x, int y)=0
 picks the drawable in the scene that intersects with the ray (x,y,-1) in camera coordinates. More...
 
virtual rw::math::Vector3D unproject (SceneCamera::Ptr camera, int x, int y)=0
 this method unprojects a 2D screen coordinate to 3D coordinates from the last draw'n scene. Which is the closest 3d point from the intersection of the ray (x,y,-1) and the objects drawn in the scene. More...
 
virtual rw::math::Vector3D project (SceneCamera::Ptr camera, double x, double y, double z)=0
 this method projects a 3D coordinate to 2D screen coordinates from the last draw'n scene. More...
 
virtual void update ()=0
 should be called after the structure of the scene has been changed
 
virtual void clear ()=0
 Clear the scene graph.
 
virtual rw::graphics::DrawableGeometryNode::Ptr makeDrawableFrameAxis (const std::string &name, double size, int dmask=DrawableNode::Physical)=0
 Create a drawable node for a frame axis coordinate system. More...
 
virtual rw::graphics::DrawableGeometryNode::Ptr makeDrawable (const std::string &name, rw::core::Ptr< class rw::geometry::Geometry > geom, int dmask=DrawableNode::Physical)=0
 Create a drawable node for a geometry. More...
 
virtual rw::graphics::DrawableGeometryNode::Ptr makeDrawable (const std::string &name, const std::vector< class rw::geometry::Line > &lines, int dmask=DrawableNode::Physical)=0
 Create a drawable node for lines. More...
 
virtual DrawableNode::Ptr makeDrawable (const std::string &name, const class rw::sensor::Image &img, int dmask=DrawableNode::Virtual)=0
 Create a drawable node for an image. More...
 
virtual DrawableNode::Ptr makeDrawable (const std::string &name, const rw::geometry::PointCloud &scan, int dmask=DrawableNode::Virtual)=0
 Create a drawable node for a point cloud. More...
 
virtual DrawableNode::Ptr makeDrawable (const std::string &name, rw::core::Ptr< rw::geometry::Model3D > model, int dmask=DrawableNode::Physical)=0
 Create a drawable node for a 3d model. More...
 
virtual DrawableNode::Ptr makeDrawable (const std::string &name, const std::string &text, rw::core::Ptr< rw::kinematics::Frame > labelFrame, int dmask=DrawableNode::Virtual)=0
 Create a drawable node for a text label. More...
 
virtual DrawableNode::Ptr makeDrawable (const std::string &name, rw::core::Ptr< rw::graphics::Render > render, int dmask=DrawableNode::Physical)=0
 Create a drawable node for a render. More...
 
virtual DrawableNode::Ptr makeDrawable (const std::string &filename, int dmask=DrawableNode::Physical)=0
 Create a drawable node from a file. More...
 
virtual rw::core::Ptr< SceneCameramakeCamera (const std::string &name)=0
 Create a new scene camera. More...
 
virtual GroupNode::Ptr makeGroupNode (const std::string &name)
 Make a group node. More...
 
virtual rw::core::Ptr< rw::graphics::CameraGroupmakeCameraGroup (const std::string &name)
 Create a camera group. More...
 
virtual rw::core::Ptr< rw::graphics::CameraGroupfindCameraGroup (const std::string &name)
 Find a camera group. More...
 
virtual void addCameraGroup (rw::core::Ptr< rw::graphics::CameraGroup > cgroup)
 Add a camera group. More...
 
virtual void removeCameraGroup (rw::core::Ptr< rw::graphics::CameraGroup > cgroup)
 Remove a camera group. More...
 
virtual void removeCameraGroup (const std::string &name)
 Remove a camera group. More...
 
virtual std::list< rw::core::Ptr< rw::graphics::CameraGroup > > getCameraGroups ()
 Get all camera groups. More...
 
virtual void setRoot (rw::graphics::GroupNode::Ptr node)
 Set the root of the scene graph. More...
 
virtual rw::graphics::GroupNode::Ptr getRoot ()
 Get the root of the scene graph. More...
 
virtual void addChild (rw::core::Ptr< rw::graphics::SceneNode > child, rw::graphics::GroupNode::Ptr parent)
 add a drawable to a node
 
virtual std::vector< rw::graphics::DrawableNode::PtrgetDrawables ()
 get all drawables in the scene. More...
 
virtual std::vector< rw::graphics::DrawableNode::PtrgetDrawables (rw::core::Ptr< rw::graphics::SceneNode > node)
 get a vector of drawables attached to a node More...
 
virtual std::vector< rw::graphics::DrawableNode::PtrgetDrawablesRec (rw::core::Ptr< rw::graphics::SceneNode > node)
 get all drawable nodes in the subtree of node. nodes of type camera will not be traversed More...
 
virtual rw::graphics::DrawableNode::Ptr findDrawable (const std::string &name)
 Find a drawable node in the scene graph. More...
 
virtual rw::graphics::DrawableNode::Ptr findDrawable (const std::string &name, rw::core::Ptr< SceneNode > node)
 Find a drawable node in the scene graph. More...
 
virtual std::vector< rw::graphics::DrawableNode::PtrfindDrawables (const std::string &name)
 Find multiple drawable nodes in the scene graph. More...
 
virtual bool removeDrawables (rw::graphics::GroupNode::Ptr node)
 Remove a node. More...
 
virtual bool removeDrawables (const std::string &name)
 Remove all drawables with a given name. More...
 
virtual bool removeDrawable (rw::graphics::DrawableNode::Ptr drawable)
 Remove a specific drawable. More...
 
virtual bool removeDrawable (rw::graphics::DrawableNode::Ptr drawable, rw::core::Ptr< rw::graphics::SceneNode > node)
 Remove a specific drawable. More...
 
virtual bool removeDrawable (const std::string &name)
 Remove a specific drawable with a given name. More...
 
virtual bool removeChild (const std::string &name, rw::graphics::GroupNode::Ptr node)
 Removes child with the specified name from the node. More...
 
void traverse (rw::core::Ptr< rw::graphics::SceneNode > &node, NodeVisitor &visitor)
 Traverse all nodes in the subtree under node recursively. More...
 
void traverse (rw::core::Ptr< rw::graphics::SceneNode > &node, NodeVisitor &visitor, NodeVisitor &postvisitor)
 Traverse all nodes in the subtree under node recursively. More...
 
void traverse (rw::core::Ptr< rw::graphics::SceneNode > &node, NodeVisitor &visitor, const NodeFilter &filter)
 Traverse all nodes in the subtree under node recursively. More...
 
void traverse (rw::core::Ptr< rw::graphics::SceneNode > &node, NodeVisitor &visitor, NodeVisitor &postvisitor, const NodeFilter &filter)
 Traverse all nodes in the subtree under node recursively. More...
 

Protected Member Functions

 SceneGraph ()
 Construct new scene graph with only a root node "Root".
 
 SceneGraph (rw::graphics::GroupNode::Ptr root)
 Construct a new scene graph with a given root node. More...
 

Protected Attributes

rw::graphics::GroupNode::Ptr _root
 The root node of the graph.
 
std::list< rw::core::Ptr< rw::graphics::CameraGroup > > _cameraGroups
 The camera groups in the graph.
 

Detailed Description

interface for a minimalistic scenegraph that does not depend on the frame structure. See WorkCellScene for an implementation that wraps this interface to enable a more RobWork specific use.

Cameras - SceneCameras define how the world is rendered from a specific point of view, render setting, projection matrix, viewport and so on.

Cameras are ordered in CameraGroups. Each camera group can contain multiple cameras that are ordered according to how they should render the scene. A typical setup of one group would be: first camera - clear color and depth buffers, render background ibn orthographic projection second camera - render all 3D scene elements in perspective projection third camera - render foreground such as logo in orthographic projection

As can be seen the ordering is of high importance since the first camera clears the frame buffers.

Constructor & Destructor Documentation

◆ SceneGraph()

SceneGraph ( rw::graphics::GroupNode::Ptr  root)
inlineprotected

Construct a new scene graph with a given root node.

Parameters
root[in] the root node.

Member Function Documentation

◆ addCameraGroup()

virtual void addCameraGroup ( rw::core::Ptr< rw::graphics::CameraGroup cgroup)
virtual

Add a camera group.

Parameters
cgroup[in] the group to add.

◆ draw()

virtual void draw ( RenderInfo info)
pure virtual

draws the scene, using the specified render information

Parameters
infodocumentation missing !

Implemented in SceneOpenGL.

◆ findCameraGroup()

virtual rw::core::Ptr<rw::graphics::CameraGroup> findCameraGroup ( const std::string &  name)
virtual

Find a camera group.

Parameters
name[in] name of the group.
Returns
the camera group if found, else NULL.

◆ findDrawable() [1/2]

virtual rw::graphics::DrawableNode::Ptr findDrawable ( const std::string &  name)
virtual

Find a drawable node in the scene graph.

Parameters
name[in] the name of the drawable node.
Returns
the node if found, NULL otherwise.

◆ findDrawable() [2/2]

virtual rw::graphics::DrawableNode::Ptr findDrawable ( const std::string &  name,
rw::core::Ptr< SceneNode node 
)
virtual

Find a drawable node in the scene graph.

Parameters
name[in] the name of the drawable node.
Returns
the node if found, NULL otherwise.
Parameters
node[in] search only this node and all children recursively.

◆ findDrawables()

virtual std::vector<rw::graphics::DrawableNode::Ptr> findDrawables ( const std::string &  name)
virtual

Find multiple drawable nodes in the scene graph.

Parameters
name[in] the name of the drawable node(s).
Returns
a vector of all nodes with the given name.

◆ getCameraGroups()

virtual std::list<rw::core::Ptr<rw::graphics::CameraGroup> > getCameraGroups ( )
virtual

Get all camera groups.

Returns
a list of camera groups.

◆ getDrawables() [1/2]

virtual std::vector<rw::graphics::DrawableNode::Ptr> getDrawables ( )
virtual

get all drawables in the scene.

Returns

◆ getDrawables() [2/2]

virtual std::vector<rw::graphics::DrawableNode::Ptr> getDrawables ( rw::core::Ptr< rw::graphics::SceneNode node)
virtual

get a vector of drawables attached to a node

Parameters
node
Returns

◆ getDrawablesRec()

virtual std::vector<rw::graphics::DrawableNode::Ptr> getDrawablesRec ( rw::core::Ptr< rw::graphics::SceneNode node)
virtual

get all drawable nodes in the subtree of node. nodes of type camera will not be traversed

Parameters
node[in]
Returns

◆ getRoot()

virtual rw::graphics::GroupNode::Ptr getRoot ( )
virtual

Get the root of the scene graph.

Returns
the root group node.

◆ makeCamera()

virtual rw::core::Ptr<SceneCamera> makeCamera ( const std::string &  name)
pure virtual

Create a new scene camera.

Parameters
name[in] name of the camera.
Returns
the new scene camera.

Implemented in SceneOpenGL.

◆ makeCameraGroup()

virtual rw::core::Ptr<rw::graphics::CameraGroup> makeCameraGroup ( const std::string &  name)
virtual

Create a camera group.

Parameters
name[in] name of the group.
Returns
a new camera group.

Reimplemented in SceneOpenGL.

◆ makeDrawable() [1/8]

virtual DrawableNode::Ptr makeDrawable ( const std::string &  filename,
int  dmask = DrawableNode::Physical 
)
pure virtual

Create a drawable node from a file.

Parameters
filename[in] a filename (alternatively a string for a geometric primitive).
dmask[in] (optional) the type of drawable. Default is DrawableNode::Physical.
Returns
a drawable node.

Implemented in SceneOpenGL.

◆ makeDrawable() [2/8]

virtual DrawableNode::Ptr makeDrawable ( const std::string &  name,
const class rw::sensor::Image img,
int  dmask = DrawableNode::Virtual 
)
pure virtual

Create a drawable node for an image.

Parameters
name[in] name of the drawable.
img[in] the image to draw.
dmask[in] (optional) the type of drawable. Default is DrawableNode::Physical.
Returns
a drawable node.

Implemented in SceneOpenGL.

◆ makeDrawable() [3/8]

virtual DrawableNode::Ptr makeDrawable ( const std::string &  name,
const rw::geometry::PointCloud scan,
int  dmask = DrawableNode::Virtual 
)
pure virtual

Create a drawable node for a point cloud.

Parameters
name[in] name of the drawable.
scan[in] the point cloud to draw.
dmask[in] (optional) the type of drawable. Default is DrawableNode::Physical.
Returns
a drawable node.

Implemented in SceneOpenGL.

◆ makeDrawable() [4/8]

virtual DrawableNode::Ptr makeDrawable ( const std::string &  name,
const std::string &  text,
rw::core::Ptr< rw::kinematics::Frame labelFrame,
int  dmask = DrawableNode::Virtual 
)
pure virtual

Create a drawable node for a text label.

Parameters
name[in] name of the drawable.
text[in] the text to draw.
labelFrame[in] the frame the label belongs to.
dmask[in] (optional) the type of drawable. Default is DrawableNode::Virtual.
Returns
a drawable node.

Implemented in SceneOpenGL.

◆ makeDrawable() [5/8]

virtual rw::graphics::DrawableGeometryNode::Ptr makeDrawable ( const std::string &  name,
const std::vector< class rw::geometry::Line > &  lines,
int  dmask = DrawableNode::Physical 
)
pure virtual

Create a drawable node for lines.

Parameters
name[in] name of the drawable.
lines[in] the lines to draw.
dmask[in] (optional) the type of drawable. Default is DrawableNode::Physical.
Returns
a drawable geometry node.

Implemented in SceneOpenGL.

◆ makeDrawable() [6/8]

virtual rw::graphics::DrawableGeometryNode::Ptr makeDrawable ( const std::string &  name,
rw::core::Ptr< class rw::geometry::Geometry geom,
int  dmask = DrawableNode::Physical 
)
pure virtual

Create a drawable node for a geometry.

Parameters
name[in] name of the drawable.
geom[in] the geometry to draw.
dmask[in] (optional) the type of drawable. Default is DrawableNode::Physical.
Returns
a drawable geometry node.

Implemented in SceneOpenGL.

◆ makeDrawable() [7/8]

virtual DrawableNode::Ptr makeDrawable ( const std::string &  name,
rw::core::Ptr< rw::geometry::Model3D model,
int  dmask = DrawableNode::Physical 
)
pure virtual

Create a drawable node for a 3d model.

Parameters
name[in] name of the drawable.
model[in] the 3d model to draw.
dmask[in] (optional) the type of drawable. Default is DrawableNode::Physical.
Returns
a drawable node.

Implemented in SceneOpenGL.

◆ makeDrawable() [8/8]

virtual DrawableNode::Ptr makeDrawable ( const std::string &  name,
rw::core::Ptr< rw::graphics::Render render,
int  dmask = DrawableNode::Physical 
)
pure virtual

Create a drawable node for a render.

Parameters
name[in] name of the drawable.
render[in] the render to draw.
dmask[in] (optional) the type of drawable. Default is DrawableNode::Physical.
Returns
a drawable node.

Implemented in SceneOpenGL.

◆ makeDrawableFrameAxis()

virtual rw::graphics::DrawableGeometryNode::Ptr makeDrawableFrameAxis ( const std::string &  name,
double  size,
int  dmask = DrawableNode::Physical 
)
pure virtual

Create a drawable node for a frame axis coordinate system.

Parameters
name[in] name of the drawable.
size[in] size of the axis.
dmask[in] (optional) the type of drawable. Default is DrawableNode::Physical.
Returns
a drawable geometry node.

Implemented in SceneOpenGL.

◆ makeGroupNode()

virtual GroupNode::Ptr makeGroupNode ( const std::string &  name)
virtual

Make a group node.

Parameters
name[in] name of the node.
Returns
new group node.

◆ pickDrawable()

virtual DrawableNode::Ptr pickDrawable ( RenderInfo info,
int  x,
int  y 
)
pure virtual

picks the drawable in the scene that intersects with the ray (x,y,-1) in camera coordinates.

Parameters
info[in] rendering information.
x[in] first camera coordinate.
y[in] second camera coordinate.
Returns
the picked drawable.

Implemented in SceneOpenGL.

◆ project()

virtual rw::math::Vector3D project ( SceneCamera::Ptr  camera,
double  x,
double  y,
double  z 
)
pure virtual

this method projects a 3D coordinate to 2D screen coordinates from the last draw'n scene.

Note
this method relies on a previously drawn scene, eg. call to draw(). Any thing drawn in the scene can be "picked" by this method.

(0,0) is located in the upper left corner, with x-axis increasing to the right and y-axis increasing to the bottom. The negative z-axis points into the scene-

Parameters
camera[in] the SceneCamera.
x[in] x coordinate [0;viewport.width]
y[in] y coordinate [0;viewport.height]
z[in] z coordinate
Returns
the 2D point,

Implemented in SceneOpenGL.

◆ removeCameraGroup() [1/2]

virtual void removeCameraGroup ( const std::string &  name)
virtual

Remove a camera group.

Parameters
name[in] the name of the group.

◆ removeCameraGroup() [2/2]

virtual void removeCameraGroup ( rw::core::Ptr< rw::graphics::CameraGroup cgroup)
virtual

Remove a camera group.

Parameters
cgroup[in] the group to remove.

◆ removeChild()

virtual bool removeChild ( const std::string &  name,
rw::graphics::GroupNode::Ptr  node 
)
virtual

Removes child with the specified name from the node.

Parameters
name[in] Name of child to remove
node[in] Node to remove from
Returns
true if found and successfully removed.

◆ removeDrawable() [1/3]

virtual bool removeDrawable ( const std::string &  name)
virtual

Remove a specific drawable with a given name.

Parameters
name[in] the name.
Returns
true if removed, false otherwise.

◆ removeDrawable() [2/3]

virtual bool removeDrawable ( rw::graphics::DrawableNode::Ptr  drawable)
virtual

Remove a specific drawable.

Parameters
drawable[in] the drawable.
Returns
true if removed, false otherwise.

◆ removeDrawable() [3/3]

virtual bool removeDrawable ( rw::graphics::DrawableNode::Ptr  drawable,
rw::core::Ptr< rw::graphics::SceneNode node 
)
virtual

Remove a specific drawable.

Parameters
drawable[in] the drawable.
node[in] only search this node and children recursively.
Returns
true if removed, false otherwise.

◆ removeDrawables() [1/2]

virtual bool removeDrawables ( const std::string &  name)
virtual

Remove all drawables with a given name.

Parameters
name[in] the name.
Returns
true if removed, false otherwise.

◆ removeDrawables() [2/2]

virtual bool removeDrawables ( rw::graphics::GroupNode::Ptr  node)
virtual

Remove a node.

Parameters
node[in] the group node to remove.
Returns
true if removed, false otherwise.

◆ setRoot()

virtual void setRoot ( rw::graphics::GroupNode::Ptr  node)
virtual

Set the root of the scene graph.

Parameters
node[in] the root node.

◆ traverse() [1/4]

void traverse ( rw::core::Ptr< rw::graphics::SceneNode > &  node,
NodeVisitor visitor 
)

Traverse all nodes in the subtree under node recursively.

Parameters
node[in] the root node.
visitor[in] the visitor function to execute for each node visited.

◆ traverse() [2/4]

void traverse ( rw::core::Ptr< rw::graphics::SceneNode > &  node,
NodeVisitor visitor,
const NodeFilter filter 
)

Traverse all nodes in the subtree under node recursively.

Parameters
node[in] the root node.
visitor[in] the visitor function to execute for each node visited.
filter[in] filter which nodes to visit.

◆ traverse() [3/4]

void traverse ( rw::core::Ptr< rw::graphics::SceneNode > &  node,
NodeVisitor visitor,
NodeVisitor postvisitor 
)

Traverse all nodes in the subtree under node recursively.

Parameters
node[in] the root node.
visitor[in] the visitor function to execute for each node visited.
postvisitor[in] the visitor function to execute for each node visited afterwards.

◆ traverse() [4/4]

void traverse ( rw::core::Ptr< rw::graphics::SceneNode > &  node,
NodeVisitor visitor,
NodeVisitor postvisitor,
const NodeFilter filter 
)

Traverse all nodes in the subtree under node recursively.

Parameters
node[in] the root node.
visitor[in] the visitor function to execute for each node visited.
postvisitor[in] the visitor function to execute for each node visited afterwards.
filter[in] filter which nodes to visit.

◆ unproject()

virtual rw::math::Vector3D unproject ( SceneCamera::Ptr  camera,
int  x,
int  y 
)
pure virtual

this method unprojects a 2D screen coordinate to 3D coordinates from the last draw'n scene. Which is the closest 3d point from the intersection of the ray (x,y,-1) and the objects drawn in the scene.

Note
this method relies on a previously drawn scene, eg. call to draw(). Any thing drawn in the scene can be "picked" by this method.

(0,0) is located in the upper left corner, with x-axis increasing to the right and y-axis increasing to the bottom. The negative z-axis points into the scene-

Parameters
camera[in] the scene camera.
x[in] x coordinate [0;viewport.width]
y[in] y coordinate [0;viewport.height]
Returns
the 3D point,

Implemented in SceneOpenGL.


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