SceneElement.h
Go to the documentation of this file.
// This file is a part of the OpenSurgSim project.
// Copyright 2013-2016, SimQuest Solutions Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#ifndef SURGSIM_FRAMEWORK_SCENEELEMENT_H
#define SURGSIM_FRAMEWORK_SCENEELEMENT_H
#include <algorithm>
#include <boost/any.hpp>
#include <memory>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include "SurgSim/Math/RigidTransform.h"
namespace YAML
{
class Node;
}
namespace SurgSim
{
namespace Framework
{
class Component;
class PoseComponent;
class Scene;
class Runtime;
class SceneElement : public std::enable_shared_from_this<SceneElement>
{
public:
explicit SceneElement(const std::string& name);
virtual ~SceneElement();
virtual std::string getClassName() const;
bool addComponent(std::shared_ptr<Component> component);
bool removeComponent(std::shared_ptr<Component> component);
bool removeComponent(const std::string& name);
void removeComponents();
std::shared_ptr<Component> getComponent(const std::string& name) const;
std::vector<std::shared_ptr<Component>> getComponents() const;
template <class T>
std::vector<std::shared_ptr<T>> getComponents() const;
template <class T>
T getValue(const std::string& component, const std::string& property) const;
boost::any getValue(const std::string& component, const std::string& property) const;
template <class T>
bool getValue(const std::string& component, const std::string& property, T* value) const;
void setValue(const std::string& component, const std::string& property, const boost::any& value);
void addToGroup(const std::string& group);
void removeFromGroup(const std::string& group);
void setGroups(const std::vector<std::string>& groups);
std::vector<std::string> getGroups() const;
bool inGroup(const std::string& name);
bool initialize();
std::string getName() const;
void setPose(const SurgSim::Math::RigidTransform3d& pose);
const SurgSim::Math::RigidTransform3d& getPose() const;
std::shared_ptr<PoseComponent> getPoseComponent();
void setScene(std::weak_ptr<Scene> scene);
std::shared_ptr<Scene> getScene();
void setRuntime(std::weak_ptr<Runtime> runtime);
std::shared_ptr<Runtime> getRuntime();
bool isInitialized() const;
void setActive(bool val);
bool isActive() const;
std::shared_ptr<SceneElement> getSharedPtr();
virtual YAML::Node encode(bool standalone) const;
virtual bool decode(const YAML::Node& node);
private:
bool initializeComponent(std::shared_ptr<SurgSim::Framework::Component> component);
std::string m_name;
std::shared_ptr<SurgSim::Framework::PoseComponent> m_pose;
std::unordered_map<std::string, std::shared_ptr<Component>> m_components;
std::weak_ptr<Scene> m_scene;
std::weak_ptr<Runtime> m_runtime;
std::unordered_set<std::string> m_groups;
virtual bool doInitialize() = 0;
void setName(const std::string& name);
bool m_isInitialized;
bool m_isActive;
};
}; // namespace Framework
}; // namespace SurgSim
#include "SurgSim/Framework/SceneElement-inl.h"
#endif // SURGSIM_FRAMEWORK_SCENEELEMENT_H
SurgSim
Definition: CompoundShapeToGraphics.cpp:29
SurgSim::Framework::SceneElement::m_isInitialized
bool m_isInitialized
Indicates if this SceneElement has been initialized or not.
Definition: SceneElement.h:249
SceneElement-inl.h
SurgSim::Framework::SceneElement::m_runtime
std::weak_ptr< Runtime > m_runtime
A (weak) back pointer to the Runtime containing this SceneElement.
Definition: SceneElement.h:235
SurgSim::Framework::SceneElement::m_name
std::string m_name
Name of this SceneElement.
Definition: SceneElement.h:224
SurgSim::Framework::SceneElement::m_pose
std::shared_ptr< SurgSim::Framework::PoseComponent > m_pose
Definition: SceneElement.h:226
SurgSim::Framework::SceneElement::m_isActive
bool m_isActive
Indicates if this SceneElement is active or not.
Definition: SceneElement.h:252
RigidTransform.h
Definitions of 2x2 and 3x3 rigid (isometric) transforms.
SurgSim::Math::RigidTransform3d
Eigen::Transform< double, 3, Eigen::Isometry > RigidTransform3d
A 3D rigid (isometric) transform, represented as doubles.
Definition: RigidTransform.h:46
YAML
Definition: DataStructuresConvert.h:28
SurgSim::Framework::SceneElement::m_scene
std::weak_ptr< Scene > m_scene
A (weak) back pointer to the Scene containing this SceneElement.
Definition: SceneElement.h:232
SurgSim::Framework::SceneElement
SceneElement is the basic part of a scene, it is a container of components.
Definition: SceneElement.h:51
SurgSim::Framework::SceneElement::m_components
std::unordered_map< std::string, std::shared_ptr< Component > > m_components
A collection of Components.
Definition: SceneElement.h:229
SurgSim::Framework::SceneElement::m_groups
std::unordered_set< std::string > m_groups
Local groups for serialization local handling.
Definition: SceneElement.h:238