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

REFAC: Refactor imstk light class

parent 365c3814
Pipeline #134178 failed with stage
......@@ -58,8 +58,8 @@ int main()
{
vertList[i*nCols + j] = Vec3d((double)dx*i, 1.0, (double)dy*j);
std::cout << vertList[i*nCols + j][0] << ", "
<< vertList[i*nCols + j][1] << ", "
<< vertList[i*nCols + j][2] << ", ";
<< vertList[i*nCols + j][1] << ", "
<< vertList[i*nCols + j][2] << ", ";
}
std::cout << std::endl;
}
......@@ -125,19 +125,18 @@ int main()
beforeLastPositions.resize(nRows*nCols);
auto func =
[&surfMesh](Module* module)
{
auto newPositions = surfMesh->getVertexPositions();
for (int i = 0; i < nRows; ++i)
[&surfMesh](Module* module)
{
for (int j = 0; j < nCols; j++)
auto newPositions = surfMesh->getVertexPositions();
for (int i = 0; i < nRows; ++i)
{
beforeLastPositions[i*nCols + j] = lastPositions[i*nCols + j];
lastPositions[i*nCols + j] = newPositions[i*nCols + j];
for (int j = 0; j < nCols; j++)
{
beforeLastPositions[i*nCols + j] = lastPositions[i*nCols + j];
lastPositions[i*nCols + j] = newPositions[i*nCols + j];
}
}
}
};
};
sdk->getSceneManager(scene)->setPostUpdateCallback(func);
// Start
......@@ -182,31 +181,30 @@ int main()
bool expectedLastStateSuccess = true;
for (int i = 0; i < nRows; ++i)
{
for (int j = 0; j < nCols; j++)
{
std::cout << lastPositions[i*nCols + j][0] << ", " << lastPositions[i*nCols + j][1] << ", " << lastPositions[i*nCols + j][2] << ", " << std::endl;
}
for (int j = 0; j < nCols; j++)
{
std::cout << lastPositions[i*nCols + j][0] << ", " << lastPositions[i*nCols + j][1] << ", " << lastPositions[i*nCols + j][2] << ", " << std::endl;
}
}
for (int i = 0; i < nRows; ++i)
{
for (int j = 0; j < nCols; j++)
{
for (int k = 0; k < 3; ++k)
{
sameLastStateSuccess &= vtkMathUtilities::FuzzyCompare(
for (int j = 0; j < nCols; j++)
{
for (int k = 0; k < 3; ++k)
{
sameLastStateSuccess &= vtkMathUtilities::FuzzyCompare(
beforeLastPositions[i*nCols + j][k], lastPositions[i*nCols + j][k], epsilon);
expectedLastStateSuccess &= vtkMathUtilities::FuzzyCompare(
expectedLastStateSuccess &= vtkMathUtilities::FuzzyCompare(
lastPositions[i*nCols + j][k], expectedFinalPositions[i*nCols + j][k]);
if (!expectedLastStateSuccess)
{
std::cout << lastPositions[i*nCols + j][k] << " " << expectedFinalPositions[i*nCols + j][k]<< std::endl;
expectedLastStateSuccess = true;
}
}
}
if (!expectedLastStateSuccess)
{
std::cout << lastPositions[i*nCols + j][k] << " " << expectedFinalPositions[i*nCols + j][k]<< std::endl;
expectedLastStateSuccess = true;
}
}
}
}
if (!sameLastStateSuccess)
......@@ -216,8 +214,8 @@ int main()
}
if (!expectedLastStateSuccess)
{
std::cerr << "Error: last state positions are wrong" << std::endl;
return EXIT_FAILURE;
std::cerr << "Error: last state positions are wrong" << std::endl;
return EXIT_FAILURE;
}
return 0;
......
......@@ -26,7 +26,7 @@
using namespace imstk;
const bool runSimWithoutRendering = true;
const bool runSimWithoutRendering = false;
///
/// \brief This example demonstrates the cloth simulation
......@@ -128,7 +128,7 @@ int main()
// Start
sdk->setActiveScene(scene);
sdk->startSimulation(SimulationStatus::RUNNING);
sdk->startSimulation(SimulationStatus::RUNNING);
return 0;
}
......@@ -34,7 +34,7 @@ using namespace imstk;
///
int main()
{
auto sdk = std::make_shared<SimulationManager>(1);
auto sdk = std::make_shared<SimulationManager>(0);
auto scene = sdk->createNewScene("PBDFluid");
scene->getCamera()->setPosition(0, 10.0, 15.0);
......
......@@ -92,7 +92,7 @@ Graph::doGreedyColoring(bool print /*= false*/) const
int cr;
for (cr = 0; cr < numNodes; cr++)
{
if (available[cr] == false)
if (!available[cr])
{
break;
}
......
......@@ -64,15 +64,70 @@ VTKRenderer::VTKRenderer(std::shared_ptr<Scene> scene, const bool enableVR)
}
// Lights and light actors
for ( const auto& light : scene->getLights() )
for (const auto& light : scene->getLights())
{
m_vtkLights.push_back( light->getVtkLight() );
if (light->getType() == LightType::POINT_LIGHT ||
light->getType() == LightType::SPOT_LIGHT)
// Create lights specified in the scene
switch (light->getType())
{
auto lightActor = vtkSmartPointer<vtkLightActor>::New();
lightActor->SetLight( light->getVtkLight() );
m_debugVtkActors.push_back( lightActor );
case imstk::LightType::DIRECTIONAL_LIGHT:
{
auto m_vtkLight = vtkSmartPointer<vtkLight>::New();
m_vtkLight->SetPositional(false);
auto color = light->getColor();
m_vtkLight->SetColor(color.r, color.g, color.b);
m_vtkLight->SetIntensity(light->getIntensity());
m_vtkLight->SetFocalPoint(light->getFocalPoint().data());
m_vtkLights.push_back(m_vtkLight);
}
break;
case imstk::LightType::SPOT_LIGHT:
{
auto m_vtkLight = vtkSmartPointer<vtkLight>::New();
m_vtkLight->SetPositional(true);
auto color = light->getColor();
m_vtkLight->SetColor(color.r, color.g, color.b);
m_vtkLight->SetIntensity(light->getIntensity());
m_vtkLight->SetFocalPoint(light->getFocalPoint().data());
auto spotLight = std::dynamic_pointer_cast<SpotLight>(light);
m_vtkLight->SetConeAngle(spotLight->getConeAngle());
m_vtkLight->SetPosition(spotLight->getPosition().data());
m_vtkLight->SetConeAngle(spotLight->getSpotAngle());
m_vtkLights.push_back(m_vtkLight);
auto lightActorSpot = vtkSmartPointer<vtkLightActor>::New();
lightActorSpot->SetLight(m_vtkLight);
m_debugVtkActors.push_back(lightActorSpot);
}
break;
case imstk::LightType::POINT_LIGHT:
{
auto m_vtkLight = vtkSmartPointer<vtkLight>::New();
m_vtkLight->SetPositional(true);
auto color = light->getColor();
m_vtkLight->SetColor(color.r, color.g, color.b);
m_vtkLight->SetIntensity(light->getIntensity());
m_vtkLight->SetFocalPoint(light->getFocalPoint().data());
auto pointLight = std::dynamic_pointer_cast<PointLight>(light);
m_vtkLight->SetConeAngle(pointLight->getConeAngle());
m_vtkLight->SetPosition(pointLight->getPosition().data());
m_vtkLights.push_back(m_vtkLight);
auto lightActorPoint = vtkSmartPointer<vtkLightActor>::New();
lightActorPoint->SetLight(m_vtkLight);
m_debugVtkActors.push_back(lightActorPoint);
}
break;
default:
LOG(WARNING) << "Light type undefined!";
}
}
......
......@@ -25,54 +25,12 @@
namespace imstk
{
LightType
Light::getType() const
{
return m_type;
}
void
Light::setType(const LightType& type)
{
m_type = type;
}
const Vec3d
PointLight::getPosition() const
{
double p[3];
m_vtkLight->GetPosition(p);
return Vec3d(p[0], p[1], p[2]);
}
void
PointLight::setPosition(const Vec3d& p)
{
this->setPosition(p[0], p[1], p[2]);
}
void
PointLight::setPosition(const double& x,
const double& y,
const double& z)
{
m_vtkLight->SetPosition(x, y, z);
}
void
DirectionalLight::setFocalPoint(const Vec3d& p)
{
this->setFocalPoint(p[0], p[1], p[2]);
}
void
DirectionalLight::setFocalPoint(const double& x,
const double& y,
const double& z)
Light::setFocalPoint(const float& x, const float& y, const float& z)
{
if (x != 0 || y != 0 || z != 0)
{
m_vtkLight->SetFocalPoint(x, y, z);
m_focalPoint = Vec3f((float)x, (float)y, (float)z);
}
else
{
......@@ -80,129 +38,5 @@ DirectionalLight::setFocalPoint(const double& x,
}
}
void
DirectionalLight::setCastsShadow(bool shadow)
{
m_castShadow = shadow;
}
void
DirectionalLight::setShadowCenter(Vec3f position)
{
m_shadowCenter = position;
}
void
DirectionalLight::setShadowRange(float range)
{
m_shadowRange = range;
}
const Vec3d
Light::getFocalPoint() const
{
double p[3];
m_vtkLight->GetFocalPoint(p);
return Vec3d(p[0], p[1], p[2]);
}
void
Light::setFocalPoint(const Vec3d& p)
{
this->setFocalPoint(p[0], p[1], p[2]);
}
void
Light::setFocalPoint(const double& x,
const double& y,
const double& z)
{
m_vtkLight->SetFocalPoint(x, y, z);
}
bool
Light::isOn() const
{
return m_vtkLight->GetSwitch() != 0;
}
void
Light::switchOn() const
{
m_vtkLight->SwitchOn();
}
bool
Light::isOff() const
{
return !this->isOn();
}
void
Light::switchOff()
{
m_vtkLight->SwitchOff();
}
double
SpotLight::getSpotAngle() const
{
return m_vtkLight->GetConeAngle();
}
void
SpotLight::setSpotAngle(const double& angle)
{
m_vtkLight->SetConeAngle(angle);
}
const Color
Light::getColor() const
{
Color c;
m_vtkLight->GetDiffuseColor(c.rgba);
return c;
}
void
Light::setColor(const Color& c)
{
m_vtkLight->SetColor(c(0), c(1), c(2));
}
float
Light::getIntensity() const
{
return m_vtkLight->GetIntensity();
}
void
Light::setIntensity(const float intensity)
{
m_vtkLight->SetIntensity(intensity);
}
vtkSmartPointer<vtkLight>
Light::getVtkLight() const
{
return m_vtkLight;
}
const std::string&
Light::getName() const
{
return m_name;
}
void
Light::setName(const std::string& name)
{
m_name = name;
}
void
Light::setName(const std::string&& name)
{
m_name = std::move(name);
}
//---------------------------------------------------------------------------------
} // imstk
......@@ -24,10 +24,6 @@
#include <string>
// vtk
#include <vtkSmartPointer.h>
#include <vtkLight.h>
// imstk
#include "imstkMath.h"
#include "imstkColor.h"
......@@ -55,91 +51,87 @@ public:
///
/// \brief Returns the type of light (see imstk::LightType)
///
LightType getType() const;
LightType getType() const { return m_type; };
///
/// \brief Set the type of the light
///
void setType(const LightType& type);
///
/// \brief Get the light focal point
///
const Vec3d getFocalPoint() const;
void setType(const LightType& type) { m_type = type; };
///
/// \brief Set the light focal point
///
virtual void setFocalPoint(const Vec3d& p);
virtual void setFocalPoint(const double& x,
const double& y,
const double& z);
virtual void setFocalPoint(const Vec3d& p) { this->setFocalPoint((float)p[0], (float)p[1], (float)p[2]); };
virtual void setFocalPoint(const float& x, const float& y, const float& z);
const Vec3f getFocalPoint() const { return m_focalPoint; }
///
/// \brief Get the status (On/off) of the light
///
bool isOn() const;
bool isOn() const { return m_switchState; };
///
/// \brief Switch the light On
///
void switchOn() const;
void switchOn() { m_switchState = true; };
///
/// \brief Get the status (On/off) of the light
///
bool isOff() const;
bool isOff() const { return m_switchState; };
///
/// \brief Switch the light Off
///
void switchOff();
void switchOff() { m_switchState = false; };
///
/// \brief Get the light color
///
const Color getColor() const;
const Color getColor() const { return m_color; };
///
/// \brief Set the light color
///
void setColor(const Color& c);
void setColor(const Color& c) { m_color = c; };
///
/// \brief Get the light intensity
///
float getIntensity() const;
float getIntensity() const { return m_intensity; };
///
/// \brief Set the light intensity. This value is unbounded.
///
void setIntensity(float intensity);
///
/// \brief Get the VTK light
///
vtkSmartPointer<vtkLight> getVtkLight() const;
void setIntensity(double intensity) { m_intensity = (float)intensity; };
///
/// \brief Get the light name
///
const std::string& getName() const;
const std::string& getName() const { return m_name; };
///
/// \brief Set the light name
///
void setName(const std::string& name);
void setName(const std::string&& name);
void setName(const std::string& name) { m_name = name; };
void setName(const std::string&& name) { m_name = std::move(name); };
protected:
Light(const std::string& name) : m_name(name){};
Light(std::string&& name) : m_name(std::move(name)){};
vtkSmartPointer<vtkLight> m_vtkLight = vtkSmartPointer<vtkLight>::New();
// properties with defaults
float m_intensity = 100.;
Color m_color = Color::White;
bool m_switchState = true;
Vec3f m_focalPoint = Vec3f(0, 0, 0);
std::string m_name;
LightType m_type;
};
//-----------------------------------------------------------------------------
///
/// \class DirectionalLight
///
......@@ -157,38 +149,30 @@ public:
DirectionalLight(const std::string& name) : Light(name)
{
m_type = LightType::DIRECTIONAL_LIGHT;
m_vtkLight->SetPositional(false);
this->setFocalPoint(-1, -1, -1);
};
DirectionalLight(std::string&& name) : Light(std::move(name))
{
m_type = LightType::DIRECTIONAL_LIGHT;
m_vtkLight->SetPositional(false);
this->setFocalPoint(-1, -1, -1);
};
virtual void setFocalPoint(const Vec3d& p);
virtual void setFocalPoint(const double& x,
const double& y,
const double& z);
///
/// \brief Turn shadows on
///
void setCastsShadow(bool shadow);
void setCastsShadow(bool shadow) { m_castShadow = shadow; };
///
/// \brief Center point for shadow projection
/// Sets the shadow map center to this position
///
void setShadowCenter(Vec3f position);
void setShadowCenter(Vec3d center) { m_shadowCenter = Vec3f((float)center[0], (float)center[1], (float)center[2]); };
///
/// \brief Range for shadows
/// A smaller range results in a denser shadow map
///
void setShadowRange(float range);
void setShadowRange(const double range) { m_shadowRange = (float)range; };
protected:
friend class VulkanRenderer;
......@@ -199,6 +183,8 @@ protected:
int m_shadowMapIndex = -1;
};
//-----------------------------------------------------------------------------
///
/// \class PointLight
///
......@@ -216,30 +202,46 @@ public:
PointLight(const std::string& name) : Light(name)
{
m_type = LightType::POINT_LIGHT;
m_vtkLight->SetPositional(true);
m_vtkLight->SetConeAngle(179.0);
};
PointLight(std::string&& name) : Light(std::move(name))
{
m_type = LightType::POINT_LIGHT;
m_vtkLight->SetPositional(true);
m_vtkLight->SetConeAngle(179.0);
};
///
/// \brief Get the cone angle
///
const float getConeAngle() const { return m_coneAngle; }
///
/// \brief Get the light position
///
const Vec3d getPosition() const;
void setConeAngle(const double angle) { m_coneAngle = (float)angle; };