Skip to content
Snippets Groups Projects
Commit 65f81868 authored by Alexis Girault's avatar Alexis Girault
Browse files

BUG: Fix #122 black analytic objects

Fix regression introduced in !121 with the use of the fast normals filter
`vtkTriangleMeshPointNormals`. That filter was also applied for surface
meshes with non-triangular cells: cells, sphere, capsule, cube (quads and
not triangles).

Since the issue of non-triangular meshes comes from analytic mesh sources,
the output surface meshes will always be rigid, so their normals will stay
constant and won't need to be recomputed. We can therefore use the filter
`vtkPolyDataNormals`, which is slower but will only need to be called once
of no deformation occurs.
parent 0b4868ae
No related branches found
No related tags found
No related merge requests found
......@@ -39,7 +39,7 @@ m_capsuleGeometry(capsule)
source->SetThetaResolution(10);
// Setup Mapper & Actor
this->setUpMapper(source->GetOutputPort());
this->setUpMapper(source->GetOutputPort(), true);
this->updateActorTransform();
}
......
......@@ -39,7 +39,7 @@ VTKCubeRenderDelegate::VTKCubeRenderDelegate(std::shared_ptr<Cube>cube) :
source->SetZLength(width);
// Setup Mapper & Actor
this->setUpMapper(source->GetOutputPort());
this->setUpMapper(source->GetOutputPort(), true);
this->updateActorTransform();
}
......
......@@ -53,7 +53,7 @@ VTKLineMeshRenderDelegate::VTKLineMeshRenderDelegate(std::shared_ptr<LineMesh> l
lines->SetPoints(points);
// Setup Mapper & Actor
this->setUpMapper(lines->GetOutputPort());
this->setUpMapper(lines->GetOutputPort(), true);
this->updateActorTransform();
}
......
......@@ -35,7 +35,7 @@ VTKPlaneRenderDelegate::VTKPlaneRenderDelegate(std::shared_ptr<Plane>plane) :
source->SetNormal(m_geometry->getNormal().data());
// Setup Mapper & Actor
this->setUpMapper(source->GetOutputPort());
this->setUpMapper(source->GetOutputPort(), true);
this->updateActorTransform();
}
......
......@@ -42,6 +42,7 @@
#include "vtkOpenGLPolyDataMapper.h"
#include "vtkOpenGLVertexBufferObject.h"
#include "vtkPolyDataNormals.h"
#include "vtkTriangleMeshPointNormals.h"
#include "vtkTransform.h"
......@@ -102,18 +103,26 @@ VTKRenderDelegate::make_delegate(std::shared_ptr<Geometry>geom)
}
void
VTKRenderDelegate::setUpMapper(vtkAlgorithmOutput *source)
VTKRenderDelegate::setUpMapper(vtkAlgorithmOutput *source, const bool rigid)
{
// Add normals
auto normalGen = vtkSmartPointer<vtkTriangleMeshPointNormals>::New();
vtkSmartPointer<vtkPolyDataAlgorithm> normalGen;
if (rigid)
{
normalGen = vtkSmartPointer<vtkPolyDataNormals>::New();
vtkPolyDataNormals::SafeDownCast(normalGen)->SplittingOff();
}
else
{
normalGen = vtkSmartPointer<vtkTriangleMeshPointNormals>::New();
}
normalGen->SetInputConnection(source);
m_mapper->SetInputConnection(normalGen->GetOutputPort());
// Disable auto Shift & Scale which is slow for deformable objects
// as it needs to compute a bounding box at every frame
auto mapper = dynamic_cast<vtkOpenGLPolyDataMapper*>(m_mapper.GetPointer());
if(mapper)
if(auto mapper = vtkOpenGLPolyDataMapper::SafeDownCast(m_mapper.GetPointer()))
{
mapper->SetVBOShiftScaleMethod(vtkOpenGLVertexBufferObject::DISABLE_SHIFT_SCALE);
}
......
......@@ -57,7 +57,7 @@ public:
///
/// \brief
///
void setUpMapper(vtkAlgorithmOutput *source);
void setUpMapper(vtkAlgorithmOutput *source, const bool rigid);
///
/// \brief
......
......@@ -37,7 +37,7 @@ VTKSphereRenderDelegate::VTKSphereRenderDelegate(std::shared_ptr<Sphere>sphere)
source->SetThetaResolution(20);
// Setup Mapper & Actor
this->setUpMapper(source->GetOutputPort());
this->setUpMapper(source->GetOutputPort(), true);
this->updateActorTransform();
}
......
......@@ -86,7 +86,7 @@ VTKSurfaceMeshRenderDelegate::VTKSurfaceMeshRenderDelegate(std::shared_ptr<Surfa
source->SetOutput(polydata);
// Setup Mapper & Actor
this->setUpMapper(source->GetOutputPort());
this->setUpMapper(source->GetOutputPort(), false);
this->updateActorTransform();
// Copy textures
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment