Commit 4c47e8b4 authored by Sreekanth Arikatla's avatar Sreekanth Arikatla

ENH: Add sphere glyph based rendering for point set

parent 4cb361b0
......@@ -245,16 +245,6 @@ void
Geometry::setRenderMaterial(std::shared_ptr<RenderMaterial> renderMaterial)
{
m_renderMaterial = renderMaterial;
// Enforce RenderMaterial::DisplayMode::POINTS if the connectivity information is missing
if (m_type == Type::PointSet)
{
if (m_renderMaterial->getDisplayMode() != RenderMaterial::DisplayMode::POINTS)
{
LOG(WARNING) << "Geometry::setRenderMaterial: The mesh doesn't have a connectivity. Enforcing RenderMaterial::DisplayMode::POINTS display mode";
m_renderMaterial->setDisplayMode(RenderMaterial::DisplayMode::POINTS);
}
}
}
std::shared_ptr<RenderMaterial>
......
......@@ -153,6 +153,18 @@ RenderMaterial::setRoughness(const float roughness)
m_roughness = roughness;
}
const double&
RenderMaterial::getSphereGlyphSize() const
{
return m_sphereGlyphSize;
}
void
RenderMaterial::setSphereGlyphSize(const double size)
{
m_sphereGlyphSize = size;
}
std::shared_ptr<Texture>
RenderMaterial::getTexture(Texture::Type type)
{
......
......@@ -93,6 +93,12 @@ public:
const float& getRoughness() const;
void setRoughness(const float roughness);
///
/// \brief Get/Set the roughness
///
const double& getSphereGlyphSize() const;
void setSphereGlyphSize(const double size);
///
/// \brief Add/Get texture
///
......@@ -121,6 +127,9 @@ protected:
float m_pointSize = 1.0;
bool m_backfaceCulling = true; ///< For performance, uncommon for this to be false
// Sphere size used for glyph in rendering (valid only for point set)
double m_sphereGlyphSize = 0.05;
// Colors
Color m_diffuseColor = Color::White;
......
......@@ -25,6 +25,8 @@
#include <vtkTrivialProducer.h>
#include <vtkDoubleArray.h>
#include <vtkVertexGlyphFilter.h>
#include <vtkSphereSource.h>
#include <vtkGlyph3D.h>
namespace imstk
{
......@@ -47,25 +49,31 @@ VTKPointSetRenderDelegate::VTKPointSetRenderDelegate(std::shared_ptr<PointSet> m
auto pointsPolydata = vtkSmartPointer<vtkPolyData>::New();
pointsPolydata->SetPoints(points);
auto vertexFilter = vtkSmartPointer<vtkVertexGlyphFilter>::New();
auto sphere = vtkSmartPointer<vtkSphereSource>::New();
auto glyph = vtkSmartPointer<vtkGlyph3D>::New();
#if VTK_MAJOR_VERSION <= 5
vertexFilter->SetInputConnection(pointsPolydata->GetProducerPort());
glyph->SetSource(sphere->GetOutput());
glyph->SetInput(selectPoints->GetOutput());
#else
vertexFilter->SetInputData(pointsPolydata);
glyph->SetSourceConnection(sphere->GetOutputPort());
glyph->SetInputData(pointsPolydata);
#endif
vertexFilter->Update();
m_geometry->m_dataModified = false;
// Update Transform, Render Properties
this->update();
// Setup custom mapper
m_mapper->SetInputConnection(vertexFilter->GetOutputPort());
m_mapper->SetInputConnection(glyph->GetOutputPort());
auto mapper = VTKCustomPolyDataMapper::SafeDownCast(m_mapper.GetPointer());
if (!mesh->getRenderMaterial())
{
mesh->setRenderMaterial(std::make_shared<RenderMaterial>());
}
sphere->SetRadius(mesh->getRenderMaterial()->getSphereGlyphSize());
mapper->setGeometry(mesh);
}
......
......@@ -35,7 +35,8 @@ class PointSet;
///
/// \class PointSetRenderDelegate
///
/// \brief
/// \brief Render delegate for point set. A 3D glyph of spheres is
/// created to render each node
///
class VTKPointSetRenderDelegate : public VTKRenderDelegate
{
......@@ -62,7 +63,7 @@ public:
protected:
std::shared_ptr<PointSet> m_geometry; ///> Geometry to render
std::shared_ptr<PointSet> m_geometry; ///> Geometry to render
vtkSmartPointer<vtkDoubleArray> m_mappedVertexArray; ///> Mapped array of vertices
};
}
......
......@@ -1859,12 +1859,6 @@ void testPbdFluidBenchmarking()
auto cubeMesh = std::make_shared<imstk::PointSet>();
cubeMesh->initialize(vertList);
auto material1 = std::make_shared<RenderMaterial>();
material1->setDisplayMode(RenderMaterial::DisplayMode::POINTS);
material1->setDiffuseColor(Color::Blue);
material1->setPointSize(5.0);
cubeMesh->setRenderMaterial(material1);
auto cube = std::make_shared<PbdObject>("Cube");
cube->setCollidingGeometry(cubeMesh);
cube->setVisualGeometry(cubeMesh);
......
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