Commit 458fa955 authored by Sreekanth Arikatla's avatar Sreekanth Arikatla
Browse files

REFAC: Refactor to add computBoundingBox to the scene

Refactor to add computBoundingBox to the entire scene
Remove Renderer::updateConfig and do the update in the setConfig itself
Remove unused include in the imstkKeyboardSceneControl
parent b97a4883
......@@ -62,10 +62,6 @@ main()
// Head mesh
auto surfaceMesh = MeshIO::read<SurfaceMesh>(iMSTK_DATA_ROOT "/head/head_revised.obj");
Vec3d l, u;
surfaceMesh->computeBoundingBox(l, u, 20.);
sceneSize = (u - l).norm() * 2;
imstkNew<RenderMaterial> material;
material->setDisplayMode(RenderMaterial::DisplayMode::Surface);
material->setShadingModel(RenderMaterial::ShadingModel::PBR);
......@@ -88,7 +84,7 @@ main()
// Lights
imstkNew<DirectionalLight> dirLight("DirectionalLight");
dirLight->setIntensity(15.0);
dirLight->setIntensity(10.0);
dirLight->setColor(Color(1.0, 0.95, 0.8));
scene->addLight(dirLight);
......@@ -128,10 +124,14 @@ main()
}
// Enable SSAO
Vec3d l, u;
scene->computeBoundingBox(l, u);
sceneSize = (u - l).norm();
auto rendConfig = std::make_shared<RendererConfig>();
rendConfig->m_ssaoConfig.m_enableSSAO = true;
rendConfig->m_ssaoConfig.m_SSAOBlur = true;
rendConfig->m_ssaoConfig.m_SSAORadius = 0.1 * sceneSize;
rendConfig->m_ssaoConfig.m_SSAORadius = 1.0 * sceneSize;
rendConfig->m_ssaoConfig.m_SSAOBias = 0.001 * sceneSize;
rendConfig->m_ssaoConfig.m_KernelSize = 128;
......
......@@ -181,8 +181,7 @@ VTKRenderDelegate::update()
{
// Then leave it up to subclasses to implement how to process the events
processEvents();
// Needed to inform VTK to update things for shadows
//m_actor->Modified();
}
......
......@@ -238,7 +238,7 @@ VTKRenderer::VTKRenderer(std::shared_ptr<Scene> scene, const bool enableVR) :
// Prepare screen space ambient occlusion effect
m_ssaoPass->SetDelegatePass(m_renderStepsPass);
updateConfig();
this->setConfig(this->m_config);
}
void
......@@ -630,12 +630,7 @@ void
VTKRenderer::setConfig(std::shared_ptr<RendererConfig> config)
{
m_config = config;
updateConfig();
}
void
VTKRenderer::updateConfig()
{
// update SSAO if enabled
if (m_config->m_ssaoConfig.m_enableSSAO)
{
......
......@@ -145,12 +145,10 @@ protected:
void addActors(const std::vector<vtkSmartPointer<vtkProp>>& actorList);
///
/// \brief Apply config changes
/// \brief Apply configuration changes
///
void setConfig(std::shared_ptr<RendererConfig> config) override;
void updateConfig() override;
protected:
///
/// \brief Adds a SceneObject to be rendered
......@@ -186,7 +184,7 @@ protected:
void sceneObjectModified(Event* e);
///
/// \brief Function call for proccessing diffs on a SceneObject
/// \brief Function call for processing diffs on a SceneObject
///
void sceneObjectModified(std::shared_ptr<SceneObject> sceneObject);
......
......@@ -93,9 +93,8 @@ public:
std::shared_ptr<RendererConfig> getRenderConfig() const { return m_config; }
///
/// \brief Apply config changes
/// \brief Sets the configuration and updates the render pipeline accordingly
///
virtual void updateConfig() = 0;
virtual void setConfig(std::shared_ptr<RendererConfig> config) = 0;
protected:
......
......@@ -84,29 +84,41 @@ Scene::initialize()
// Init the debug camera to the bounding box of the visual geometries
if (m_config->debugCamBoundingBox)
{
Vec3d globalMin = Vec3d(IMSTK_DOUBLE_MAX, IMSTK_DOUBLE_MAX, IMSTK_DOUBLE_MAX);
Vec3d globalMax = Vec3d(IMSTK_DOUBLE_MIN, IMSTK_DOUBLE_MIN, IMSTK_DOUBLE_MIN);
for (const auto& obj : m_sceneObjects)
{
for (auto visualModels : obj->getVisualModels())
{
Vec3d min = Vec3d(IMSTK_DOUBLE_MAX, IMSTK_DOUBLE_MAX, IMSTK_DOUBLE_MAX);
Vec3d max = Vec3d(IMSTK_DOUBLE_MIN, IMSTK_DOUBLE_MIN, IMSTK_DOUBLE_MIN);
visualModels->getGeometry()->computeBoundingBox(min, max);
globalMin = globalMin.cwiseMin(min);
globalMax = globalMax.cwiseMax(max);
}
}
Vec3d globalMin, globalMax;
Scene::computeBoundingBox(globalMin, globalMax);
const Vec3d center = (globalMin + globalMax) * 0.5;
const Vec3d size = globalMax - globalMin;
const double size = (globalMax - globalMin).norm();
m_cameras["debug"]->setFocalPoint(center);
m_cameras["debug"]->setPosition(center + Vec3d(0.0, 1.0, 1.0).normalized() * size.norm());
m_cameras["debug"]->setPosition(center + Vec3d(0.0, 1.0, 1.0).normalized() * size);
}
LOG(INFO) << "Scene '" << this->getName() << "' initialized!";
return true;
}
void
Scene::computeBoundingBox(Vec3d& lowerCorner, Vec3d& upperCorner, const double paddingPercent)
{
lowerCorner = Vec3d(IMSTK_DOUBLE_MAX, IMSTK_DOUBLE_MAX, IMSTK_DOUBLE_MAX);
upperCorner = Vec3d(IMSTK_DOUBLE_MIN, IMSTK_DOUBLE_MIN, IMSTK_DOUBLE_MIN);
for (const auto& obj : m_sceneObjects)
{
for (auto visualModels : obj->getVisualModels())
{
Vec3d min = Vec3d(IMSTK_DOUBLE_MAX, IMSTK_DOUBLE_MAX, IMSTK_DOUBLE_MAX);
Vec3d max = Vec3d(IMSTK_DOUBLE_MIN, IMSTK_DOUBLE_MIN, IMSTK_DOUBLE_MIN);
visualModels->getGeometry()->computeBoundingBox(min, max);
lowerCorner = lowerCorner.cwiseMin(min);
upperCorner = upperCorner.cwiseMax(max);
}
}
const Vec3d range = upperCorner - lowerCorner;
lowerCorner = lowerCorner - range * (paddingPercent / 100.0);
upperCorner = upperCorner + range * (paddingPercent / 100.0);
}
void
Scene::buildTaskGraph()
{
......
......@@ -22,6 +22,7 @@
#pragma once
#include "imstkEventObject.h"
#include "imstkMath.h"
#include <atomic>
#include <string>
......
......@@ -25,7 +25,6 @@
#include "imstkModuleDriver.h"
#include "imstkScene.h"
#include "imstkSceneManager.h"
#include "imstkSceneObject.h"
#include "imstkVisualModel.h"
#include "imstkVTKRenderer.h"
#include "imstkVTKTextStatusManager.h"
......
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