SurgSim::Framework::SceneElement Class Referenceabstract

SceneElement is the basic part of a scene, it is a container of components. More...

`#include <SurgSim/Framework/SceneElement.h>`

Inheritance diagram for SurgSim::Framework::SceneElement:

## Public Member Functions

| SceneElement (const std::string &name)
| Constructor. More...
virtual | ~SceneElement ()
| Destructor. More...
virtual std::string | getClassName () const
bool | addComponent (std::shared_ptr< Component > component)
| Adds a component, calls initialize() on the component, if SceneElement::isInitialized() is true. More...
bool | removeComponent (std::shared_ptr< Component > component)
| Removes a given component. More...
bool | removeComponent (const std::string &name)
| Removes the component described by name. More...
void | removeComponents ()
| Removes all components. More...
std::shared_ptr< Component > | getComponent (const std::string &name) const
| Gets the component identified by name. More...
std::vector< std::shared_ptr< Component > > | getComponents () const
| Gets all the components of this SceneElement. More...
template<class T >
std::vector< std::shared_ptr< T > > | getComponents () const
| Template version of getComponents method to get all the components with type T. More...
template<class T >
T | getValue (const std::string &component, const std::string &property) const
| Retrieves the property value from a component. More...
boost::any | getValue (const std::string &component, const std::string &property) const
| Retrieves the property value from a component. More...
template<class T >
bool | getValue (const std::string &component, const std::string &property, T *value) const
| Retrieves the property value from a component, and convertis it to the type of the output parameter. More...
void | setValue (const std::string &component, const std::string &property, const boost::any &value)
| Sets the property value of a component. More...
void | addToGroup (const std::string &group)
| Add this scene element to the given group. More...
void | removeFromGroup (const std::string &group)
| Remove this scene element from the given group. More...
void | setGroups (const std::vector< std::string > &groups)
| Set the groups of this scene element. More...
std::vector< std::string > | getGroups () const
bool | inGroup (const std::string &name)
| Test whether this SceneElement is in a specific group. More...
bool | initialize ()
| Executes the initialize operation. More...
std::string | getName () const
| Return the name of this SceneElement. More...
void | setPose (const SurgSim::Math::RigidTransform3d &pose)
| Set the pose of this SceneElement. More...
const SurgSim::Math::RigidTransform3d & | getPose () const
| Get the pose of this SceneElement. More...
std::shared_ptr< PoseComponent > | getPoseComponent ()
| Get the PoseComponent that controls the pose all Representations in this SceneElement. More...
void | setScene (std::weak_ptr< Scene > scene)
| Sets the Scene. More...
std::shared_ptr< Scene > | getScene ()
| Gets the Scene. More...
void | setRuntime (std::weak_ptr< Runtime > runtime)
| Sets the Runtime. More...
std::shared_ptr< Runtime > | getRuntime ()
| Gets the runtime. More...
bool | isInitialized () const
| Return if this SceneElement is initialized. More...
void | setActive (bool val)
| Set this SceneElement's status (active/inactive) More...
bool | isActive () const
std::shared_ptr< SceneElement > | getSharedPtr ()
| Gets a shared pointer to this SceneElement. More...
virtual YAML::Node | encode (bool standalone) const
| Convert to a YAML::Node. More...
virtual bool | decode (const YAML::Node &node)
| Pull data from a YAML::Node. More...

## Private Member Functions

bool | initializeComponent (std::shared_ptr< SurgSim::Framework::Component > component)
| Initialize the given component. More...
virtual bool | doInitialize ()=0
| Method to initialize this SceneElement. More...
void | setName (const std::string &name)
| Sets the name of this SceneElement. More...

## Private Attributes

std::string | m_name
| Name of this SceneElement. More...
std::shared_ptr< SurgSim::Framework::PoseComponent > | m_pose
std::unordered_map< std::string, std::shared_ptr< Component > > | m_components
| A collection of Components. More...
std::weak_ptr< Scene > | m_scene
| A (weak) back pointer to the Scene containing this SceneElement. More...
std::weak_ptr< Runtime > | m_runtime
| A (weak) back pointer to the Runtime containing this SceneElement. More...
std::unordered_set< std::string > | m_groups
| Local groups for serialization local handling. More...
bool | m_isInitialized
| Indicates if this SceneElement has been initialized or not. More...
bool | m_isActive
| Indicates if this SceneElement is active or not. More...

## Detailed Description

SceneElement is the basic part of a scene, it is a container of components.

When a SceneElement is added to a Scene, the Scene will call initialize() on the SceneElement, which in turn will call initialize() on all its components. If a component is added to a SceneElement after the SceneElement was initialized, the component will be initialized immediately.

Note
  A SceneElement needs to be created as a shared_ptr.

## Constructor & Destructor Documentation

## SceneElement()

SurgSim::Framework::SceneElement::SceneElement | ( | const std::string & | name | ) |

explicit

Constructor.

Parameters

  name | Name of this SceneElement

## ~SceneElement()

SurgSim::Framework::SceneElement::~SceneElement | ( |  | ) |

virtual

Destructor.

## Member Function Documentation

## addComponent()

bool SurgSim::Framework::SceneElement::addComponent | ( | std::shared_ptr< Component > | component | ) |

Adds a component, calls initialize() on the component, if SceneElement::isInitialized() is true.

Parameters

  component | The component.

Returns
  true if it succeeds, false if it fails.

## addToGroup()

void SurgSim::Framework::SceneElement::addToGroup | ( | const std::string & | group | ) |

Add this scene element to the given group.

Parameters

  group | name of the group

## decode()

bool SurgSim::Framework::SceneElement::decode | ( | const YAML::Node & | node | ) |

virtual

Pull data from a YAML::Node.

Exceptions

  SurgSim::Framework::AssertionFailure | if the SceneElement is already initialized

Parameters

  node | the node to decode.

Returns
  true if the decoding succeeded and the node was formatted correctly, false otherwise

## doInitialize()

virtual bool SurgSim::Framework::SceneElement::doInitialize | ( |  | ) |

private pure virtual

Method to initialize this SceneElement.

To be overridden by derived class(es).

Returns
  True if initialization is successful; Otherwise, false.

Implemented in SurgSim::Graphics::ViewElement, SurgSim::Graphics::RenderPass, SurgSim::Graphics::OsgScreenSpacePass, SurgSim::Framework::BasicSceneElement, and SurgSim::Blocks::SphereElement.

## encode()

YAML::Node SurgSim::Framework::SceneElement::encode | ( | bool | standalone | ) | const

virtual

Convert to a YAML::Node.

Parameters

  standalone | when true, all the components will be represented as full component, when false they will be represented as references

Returns
  A node with all the public data of this instance

## getClassName()

std::string SurgSim::Framework::SceneElement::getClassName | ( |  | ) | const

virtual

Returns
  the class name for this class

## getComponent()

std::shared_ptr< Component > SurgSim::Framework::SceneElement::getComponent | ( | const std::string & | name | ) | const

Gets the component identified by name.

Parameters

  name | The name.

Returns
  The component or nullptr if the component cannot be found.

## getComponents() [1/2]

std::vector< std::shared_ptr< Component > > SurgSim::Framework::SceneElement::getComponents | ( |  | ) | const

Gets all the components of this SceneElement.

Returns
  The components.

## getComponents() [2/2]

template<class T >

std::vector< std::shared_ptr< T > > SurgSim::Framework::SceneElement::getComponents | ( |  | ) | const

Template version of getComponents method to get all the components with type T.

Implementation of getComponents method to get all the components with type T.

Returns
  The type T components

## getGroups()

std::vector< std::string > SurgSim::Framework::SceneElement::getGroups | ( |  | ) | const

Returns
  all the groups of this scene element

## getName()

std::string SurgSim::Framework::SceneElement::getName | ( |  | ) | const

Return the name of this SceneElement.

Returns
  The name.

## getPose()

const SurgSim::Math::RigidTransform3d & SurgSim::Framework::SceneElement::getPose | ( |  | ) | const

Get the pose of this SceneElement.

Returns
  the pose

## getPoseComponent()

std::shared_ptr< PoseComponent > SurgSim::Framework::SceneElement::getPoseComponent | ( |  | ) |

Get the PoseComponent that controls the pose all Representations in this SceneElement.

Returns
  the PoseComponent

## getRuntime()

std::shared_ptr< Runtime > SurgSim::Framework::SceneElement::getRuntime | ( |  | ) |

Gets the runtime.

Returns
  The runtime.

## getScene()

std::shared_ptr< Scene > SurgSim::Framework::SceneElement::getScene | ( |  | ) |

Gets the Scene.

Returns
  The scene.

## getSharedPtr()

std::shared_ptr< SceneElement > SurgSim::Framework::SceneElement::getSharedPtr | ( |  | ) |

Gets a shared pointer to this SceneElement.

Returns
  The shared pointer.

## getValue() [1/3]

template<class T >

T SurgSim::Framework::SceneElement::getValue | ( | const std::string & | component,
|  | const std::string & | property
| ) |  | const

Retrieves the property value from a component.

Exceptions

  SurgSim::Framework::AssertionFailure | If the conversion fails or the property cannot be found.

Template Parameters

  T | The requested type for the property.

Parameters

  component | The name of the component.
  property | The name of the property.

Returns
  The value of the property if found.

## getValue() [2/3]

boost::any SurgSim::Framework::SceneElement::getValue | ( | const std::string & | component,
|  | const std::string & | property
| ) |  | const

Retrieves the property value from a component.

Exceptions

  SurgSim::Framework::AssertionFailure | if the property cannot be found

Parameters

  component | The name of the component.
  property | The name of the property.

Returns
  The value of the property if found.

## getValue() [3/3]

template<class T >

bool SurgSim::Framework::SceneElement::getValue | ( | const std::string & | component,
|  | const std::string & | property,
|  | T * | value
| ) |  | const

Retrieves the property value from a component, and convertis it to the type of the output parameter.

This does not throw.

Template Parameters

  T | the type of the property

Parameters

  | component | The name of the component.
  | property | The name of the property.
  [out] | value | If non-null, will receive the value of the given property.

Returns
  true if value != nullptr and the property is found.

## inGroup()

bool SurgSim::Framework::SceneElement::inGroup | ( | const std::string & | name | ) |

Test whether this SceneElement is in a specific group.

Parameters

  name | group to test

Returns
  true if the SceneElement is in group name

## initialize()

bool SurgSim::Framework::SceneElement::initialize | ( |  | ) |

Executes the initialize operation.

Returns
  true if it succeeds, false if it fails.

## initializeComponent()

bool SurgSim::Framework::SceneElement::initializeComponent | ( | std::shared_ptr< SurgSim::Framework::Component > | component | ) |

private

Initialize the given component.

Parameters

  component | The component to be initialized.

Returns
  True if initialization succeeded, false otherwise.

## isActive()

bool SurgSim::Framework::SceneElement::isActive | ( |  | ) | const

Returns
  True if this SceneElement is active; Otherwise, false.

## isInitialized()

bool SurgSim::Framework::SceneElement::isInitialized | ( |  | ) | const

Return if this SceneElement is initialized.

Returns
  True if this SceneElement is initialized; Otherwise, false.

## removeComponent() [1/2]

bool SurgSim::Framework::SceneElement::removeComponent | ( | std::shared_ptr< Component > | component | ) |

Removes a given component.

Parameters

  component | The component.

Returns
  true if it succeeds, false if it fails or the component cannot be found.

## removeComponent() [2/2]

bool SurgSim::Framework::SceneElement::removeComponent | ( | const std::string & | name | ) |

Removes the component described by name.

Parameters

  name | The name.

Returns
  true if it succeeds, false if it fails or the component cannot be found.

## removeComponents()

void SurgSim::Framework::SceneElement::removeComponents | ( |  | ) |

Removes all components.

## removeFromGroup()

void SurgSim::Framework::SceneElement::removeFromGroup | ( | const std::string & | group | ) |

Remove this scene element from the given group.

Parameters

  group | name of the group

## setActive()

void SurgSim::Framework::SceneElement::setActive | ( | bool | val | ) |

Set this SceneElement's status (active/inactive)

Note
  Set 'inactive' on an active SceneElement will cause all the components it contains to not be processed.
  Set 'active' on an inactive SceneElement will cause all the components it contains which are active
  to be processed again.
  Inactive components will not be processed no matter the SceneElement is active or inactive.

Parameters

  val | True to set the SceneElement active, false to set inactive.

## setGroups()

void SurgSim::Framework::SceneElement::setGroups | ( | const std::vector< std::string > & | groups | ) |

Set the groups of this scene element.

Parameters

  groups | all the groups that this scene element should be in

## setName()

void SurgSim::Framework::SceneElement::setName | ( | const std::string & | name | ) |

private

Sets the name of this SceneElement.

Parameters

  name | The new name.

## setPose()

void SurgSim::Framework::SceneElement::setPose | ( | const SurgSim::Math::RigidTransform3d & | pose | ) |

Set the pose of this SceneElement.

Parameters

  pose | The pose

## setRuntime()

void SurgSim::Framework::SceneElement::setRuntime | ( | std::weak_ptr< Runtime > | runtime | ) |

Sets the Runtime.

Parameters

  runtime | Pointer to the runtime.

## setScene()

void SurgSim::Framework::SceneElement::setScene | ( | std::weak_ptr< Scene > | scene | ) |

Sets the Scene.

Parameters

  scene | Pointer to the scene.

## setValue()

void SurgSim::Framework::SceneElement::setValue | ( | const std::string & | component,
|  | const std::string & | property,
|  | const boost::any & | value
| ) |  |

Sets the property value of a component.

Exceptions

  SurgSim::Framework::AssertionFailure | If the property cannot be found.

Parameters

  component | The name of the component.
  property | The name of the property.
  value | The value that it should be set to.

## Member Data Documentation

## m_components

std::unordered_map<std::string, std::shared_ptr<Component> > SurgSim::Framework::SceneElement::m_components

private

A collection of Components.

## m_groups

std::unordered_set<std::string> SurgSim::Framework::SceneElement::m_groups

private

Local groups for serialization local handling.

## m_isActive

bool SurgSim::Framework::SceneElement::m_isActive

private

Indicates if this SceneElement is active or not.

## m_isInitialized

bool SurgSim::Framework::SceneElement::m_isInitialized

private

Indicates if this SceneElement has been initialized or not.

## m_name

std::string SurgSim::Framework::SceneElement::m_name

private

Name of this SceneElement.

## m_pose

std::shared_ptr<SurgSim::Framework::PoseComponent> SurgSim::Framework::SceneElement::m_pose

private

## m_runtime

std::weak_ptr<Runtime> SurgSim::Framework::SceneElement::m_runtime

private

A (weak) back pointer to the Runtime containing this SceneElement.

## m_scene

std::weak_ptr<Scene> SurgSim::Framework::SceneElement::m_scene

private

A (weak) back pointer to the Scene containing this SceneElement.

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

- SurgSim/Framework/SceneElement.h
- SurgSim/Framework/SceneElement-inl.h
- SurgSim/Framework/SceneElement.cpp