Commit b425d9ca authored by Sreekanth Arikatla's avatar Sreekanth Arikatla
Browse files

REFAC: Remove redundant public api in scene class

Removes isLightRegistered, hasSceneObject
Adds removeLight
parent 9528a60c
......@@ -538,7 +538,8 @@ VTKRenderer::sceneModifed(Event* imstkNotUsed(e))
// If the SceneObject is being rendered but not in the scene
for (auto i = m_renderedObjects.begin(); i != m_renderedObjects.end(); i++)
{
if (!m_scene->hasSceneObject(*i))
auto sos = m_scene->getSceneObjects();
if (sos.find(*i) == sos.end())
{
i = removeSceneObject(*i);
}
......
......@@ -243,19 +243,19 @@ Scene::getSceneObject(const std::string& name) const
return (iter == m_sceneObjects.end()) ? nullptr : *iter;
}
bool
Scene::hasSceneObject(std::shared_ptr<SceneObject> sceneObject)
{
return m_sceneObjects.count(sceneObject) != 0;
}
bool
Scene::hasSceneObjectName(const std::string& name)
{
auto iter = std::find_if(m_sceneObjects.begin(), m_sceneObjects.end(),
[name](const std::shared_ptr<SceneObject>& i) { return i->getName() == name; });
return iter != m_sceneObjects.end();
}
//bool
//Scene::hasSceneObject(std::shared_ptr<SceneObject> sceneObject)
//{
// return m_sceneObjects.count(sceneObject) != 0;
//}
//
//bool
//Scene::hasSceneObject(const std::string& name)
//{
// auto iter = std::find_if(m_sceneObjects.begin(), m_sceneObjects.end(),
// [name](const std::shared_ptr<SceneObject>& i) { return i->getName() == name; });
// return iter != m_sceneObjects.end();
//}
const std::vector<std::shared_ptr<VisualModel>>
Scene::getDebugRenderModels() const
......@@ -275,7 +275,7 @@ Scene::addSceneObject(std::shared_ptr<SceneObject> newSceneObject)
{
std::string name = newSceneObject->getName();
if (this->hasSceneObjectName(name))
if (this->getSceneObject(name) != nullptr)
{
LOG(WARNING) << "Can not add object: '" << name
<< "' is already registered in this scene.";
......@@ -333,12 +333,6 @@ Scene::removeSceneObject(std::shared_ptr<SceneObject> sceneObject)
}
}
bool
Scene::isLightRegistered(const std::string& lightName) const
{
return m_lightsMap.find(lightName) != m_lightsMap.end();
}
const std::vector<std::shared_ptr<Light>>
Scene::getLights() const
{
......@@ -357,7 +351,7 @@ Scene::getLights() const
std::shared_ptr<Light>
Scene::getLight(const std::string& lightName) const
{
if (!this->isLightRegistered(lightName))
if ((m_lightsMap.find(lightName) == m_lightsMap.end()))
{
LOG(WARNING) << "No light named '" << lightName
<< "' was registered in this scene.";
......@@ -372,7 +366,7 @@ Scene::addLight(std::shared_ptr<Light> newLight)
{
std::string newlightName = newLight->getName();
if (this->isLightRegistered(newlightName))
if (this->getLight(newlightName) != nullptr)
{
LOG(WARNING) << "Can not add light: '" << newlightName
<< "' is already registered in this scene.";
......@@ -387,7 +381,7 @@ Scene::addLight(std::shared_ptr<Light> newLight)
void
Scene::removeLight(const std::string& lightName)
{
if (!this->isLightRegistered(lightName))
if (this->getLight(lightName) == nullptr)
{
LOG(WARNING) << "No light named '" << lightName
<< "' was registered in this scene.";
......@@ -427,6 +421,16 @@ Scene::getCamera(const std::string name) const
}
}
void
Scene::addCamera(std::string name, std::shared_ptr<Camera> cam)
{
if (m_cameras.find(name) != m_cameras.end())
{
LOG(WARNING) << "Cannot add camera: Camera with the name " << name << " already exists.";
}
m_cameras[name] = cam;
}
void
Scene::setActiveCamera(const std::string name)
{
......@@ -437,6 +441,22 @@ Scene::setActiveCamera(const std::string name)
}
}
void
Scene::removeCamera(const std::string name)
{
auto i = m_cameras.find(name);
if (i != m_cameras.end() && !(name == "default" || name == "debug"))
{
m_cameras.erase(name);
LOG(INFO) << name << " camera removed from " << m_name;
}
else
{
LOG(WARNING) << "No camera named '" << name
<< "' is part of the scene.";
}
}
void
Scene::addController(std::shared_ptr<TrackingDeviceControl> controller)
{
......@@ -499,7 +519,10 @@ Scene::advance(const double dt)
CollisionDetection::updateInternalOctreeAndDetectCollision();
// Execute the computational graph
m_taskGraphController->execute();
if (m_taskGraphController != nullptr)
{
m_taskGraphController->execute();
}
// Apply updated forces on device
for (auto controller : this->getControllers())
......
......@@ -158,7 +158,7 @@ public:
///
/// \brief Return a vector of shared pointers to the scene objects
/// NOTE: A separate list might be efficient as this is called runtime
/// \note A separate list might be efficient as this is called runtime
///
const std::vector<std::shared_ptr<VisualModel>> getDebugRenderModels() const;
......@@ -172,16 +172,6 @@ public:
///
std::shared_ptr<SceneObject> getSceneObject(const std::string& sceneObjectName) const;
///
/// \brief Returns true if SceneObject is apart of scene
///
bool hasSceneObject(std::shared_ptr<SceneObject> sceneObject);
///
/// \brief Returns true if a SceneObject with name already exists
///
bool hasSceneObjectName(const std::string& name);
///
/// \brief Add/remove a scene object
///
......@@ -202,11 +192,6 @@ public:
///
void addDebugVisualModel(std::shared_ptr<VisualModel> dbgRenderModel);
///
/// \brief Returns true if the light (checked against name) is registered to the scene, else false.
///
bool isLightRegistered(const std::string& lightName) const;
///
/// \brief Return a vector of lights in the scene
///
......@@ -218,7 +203,7 @@ public:
std::shared_ptr<Light> getLight(const std::string& lightName) const;
///
/// \brief
/// \brief Get and unordered map of cameras with names
///
const NamedMap<Camera>& getCameras() const { return m_cameras; }
......@@ -270,7 +255,7 @@ public:
///
/// \brief Set the camera for the scene
///
void addCamera(std::string name, std::shared_ptr<Camera> cam) { m_cameras[name] = cam; }
void addCamera(std::string name, std::shared_ptr<Camera> cam);
///
/// \brief Switch the active camera to the one requested by name.
......@@ -278,6 +263,11 @@ public:
///
void setActiveCamera(const std::string name);
///
/// \brief Remove the camera with a given name
///
void removeCamera(const std::string name);
///
/// \brief Return the collision graph of the scene
///
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment