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

ENH: Use vtkTriangleMeshPointNormals

The main bottleneck with real-time VTK rendering so far
appeared to be the normals computation. This commit addresses
that issue by making use of the latest normals computation
filter in VTK: vtkTriangleMeshPointNormals.

While this filter is much (5 to 16 times) faster than
vtkPolyDataNormals, it does not check for consistency in the
cell orientations that could cause inverted normals, which
is why the vtkPolyDataNormals is called once in the surfacemesh
renderdelegate to retrieve consistent cells for the input mesh.

See VTK merge request for more information :
vtk/vtk!2271

PS: That MR requires the latest commits from VTK master, which
does not include work made on texture wrap mode nor on multi
texture attributes yet:
- iMSTK/vtk@62a7ecd8
- iMSTK/vtk@ae373026
parent 39cddd34
No related branches found
No related tags found
No related merge requests found
......@@ -39,7 +39,7 @@
#include "vtkOpenGLPolyDataMapper.h"
#include "vtkOpenGLVertexBufferObject.h"
#include "vtkPolyDataNormals.h"
#include "vtkTriangleMeshPointNormals.h"
#include "vtkTransform.h"
namespace imstk
......@@ -98,11 +98,8 @@ void
VTKRenderDelegate::setUpMapper(vtkAlgorithmOutput *source)
{
// Add normals
/// TODO : replace by vtkTrianglePointsNormals when available
auto normalGen = vtkSmartPointer<vtkPolyDataNormals>::New();
auto normalGen = vtkSmartPointer<vtkTriangleMeshPointNormals>::New();
normalGen->SetInputConnection(source);
normalGen->SplittingOff();
normalGen->ConsistencyOff();
m_mapper->SetInputConnection(normalGen->GetOutputPort());
......
......@@ -74,6 +74,13 @@ VTKSurfaceMeshRenderDelegate::VTKSurfaceMeshRenderDelegate(std::shared_ptr<Surfa
polydata->SetPoints(points);
polydata->SetPolys(cells);
// Check for cell consistency
auto consistentCellsFilter = vtkSmartPointer<vtkPolyDataNormals>::New();
consistentCellsFilter->SplittingOff();
consistentCellsFilter->SetInputData(polydata);
consistentCellsFilter->Update();
polydata->SetPolys(consistentCellsFilter->GetOutput()->GetPolys());
// Create connection source
auto source = vtkSmartPointer<vtkTrivialProducer>::New();
source->SetOutput(polydata);
......@@ -114,12 +121,24 @@ VTKSurfaceMeshRenderDelegate::VTKSurfaceMeshRenderDelegate(std::shared_ptr<Surfa
auto texture = vtkSmartPointer<vtkTexture>::New();
texture->SetInputConnection(imgReader->GetOutputPort());
texture->SetBlendingMode(vtkTexture::VTK_TEXTURE_BLENDING_MODE_ADD);
/* /!\ VTKTextureWrapMode not yet supported in VTK 7
* See here for some work that needs to be imported back to upstream:
* https://gitlab.kitware.com/iMSTK/vtk/commit/62a7ecd8a5f54e243c26960de22d5d1d23ef932b
*
texture->SetWrapMode(vtkTexture::VTKTextureWrapMode::ClampToBorder);
// Link textures
* /!\ MultiTextureAttribute not yet supported in VTK 7
* See here for some work that needs to be imported back to upstream:
* https://gitlab.kitware.com/iMSTK/vtk/commit/ae373026755db42b6fdce5093109ef1a39a76340
*
// Link texture unit to texture attribute
m_mapper->MapDataArrayToMultiTextureAttribute(unit, tCoordsName.c_str(),
vtkDataObject::FIELD_ASSOCIATION_POINTS);
vtkDataObject::FIELD_ASSOCIATION_POINTS);
*/
// Set texture
m_actor->GetProperty()->SetTexture(unit, texture);
unit++;
}
}
......
......@@ -3,8 +3,8 @@
#-----------------------------------------------------------------------------
include(imstkAddExternalProject)
imstk_add_external_project( VTK
GIT_REPOSITORY git@gitlab.kitware.com:iMSTK/vtk.git
GIT_TAG 82896a55877fc060a0f0207dea10677f7d425f38
GIT_REPOSITORY https://gitlab.kitware.com/vtk/vtk.git
GIT_TAG 1f89d2d1acf154522cbaab67766066c72817659e
INSTALL_COMMAND ${SKIP_STEP_COMMAND}
CMAKE_ARGS
-DBUILD_EXAMPLES:BOOL=OFF
......@@ -15,6 +15,7 @@ imstk_add_external_project( VTK
-DModule_vtkIOXML:BOOL=ON
-DModule_vtkIOLegacy:BOOL=ON
-DModule_vtkIOPLY:BOOL=ON
-DModule_vtkIOGeometry:BOOL=ON
-DModule_vtkInteractionStyle:BOOL=ON
-DModule_vtkRenderingAnnotation:BOOL=ON
-DModule_vtkInteractionWidgets:BOOL=ON
......
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