SplatFace
Repository source: SplatFace
Description¶
Surface reconstructed using elliptical splats into 100^3 volume followed by isosurface extraction. Points regularly subsampled and overlayed on original mesh.
Info
See Figure 9-38b in Chapter 9 The VTK Textbook.
Other languages
See (Python)
Question
If you have a question about this example, please use the VTK Discourse Forum
Code¶
SplatFace.cxx
#include <vtkActor.h>
#include <vtkCamera.h>
#include <vtkContourFilter.h>
#include <vtkGaussianSplatter.h>
#include <vtkMaskPoints.h>
#include <vtkNamedColors.h>
#include <vtkNew.h>
#include <vtkPolyDataMapper.h>
#include <vtkPolyDataNormals.h>
#include <vtkPolyDataReader.h>
#include <vtkProperty.h>
#include <vtkRenderWindow.h>
#include <vtkRenderWindowInteractor.h>
#include <vtkRenderer.h>
int main(int argc, char* argv[])
{
if (argc < 2)
{
std::cout << "Usage: " << argv[0] << " fran_cut.vtk" << std::endl;
return EXIT_FAILURE;
}
vtkNew<vtkNamedColors> colors;
// Create the RenderWindow, Renderer and both Actors
//
vtkNew<vtkRenderer> ren1;
vtkNew<vtkRenderWindow> renWin;
renWin->AddRenderer(ren1);
vtkNew<vtkRenderWindowInteractor> iren;
iren->SetRenderWindow(renWin);
// read cyberware file
//
vtkNew<vtkPolyDataReader> cyber;
cyber->SetFileName(argv[1]);
vtkNew<vtkPolyDataNormals> normals;
normals->SetInputConnection(cyber->GetOutputPort());
vtkNew<vtkMaskPoints> mask;
mask->SetInputConnection(normals->GetOutputPort());
mask->SetOnRatio(8);
// mask->RandomModeOn();
vtkNew<vtkGaussianSplatter> splatter;
splatter->SetInputConnection(mask->GetOutputPort());
splatter->SetSampleDimensions(100, 100, 100);
splatter->SetEccentricity(2.5);
splatter->NormalWarpingOn();
splatter->SetScaleFactor(1.0);
splatter->SetRadius(0.025);
vtkNew<vtkContourFilter> contour;
contour->SetInputConnection(splatter->GetOutputPort());
contour->SetValue(0, 0.25);
vtkNew<vtkPolyDataMapper> splatMapper;
splatMapper->SetInputConnection(contour->GetOutputPort());
splatMapper->ScalarVisibilityOff();
vtkNew<vtkActor> splatActor;
splatActor->SetMapper(splatMapper);
splatActor->GetProperty()->SetColor(colors->GetColor3d("Flesh").GetData());
vtkNew<vtkPolyDataMapper> cyberMapper;
cyberMapper->SetInputConnection(cyber->GetOutputPort());
cyberMapper->ScalarVisibilityOff();
vtkNew<vtkActor> cyberActor;
cyberActor->SetMapper(cyberMapper);
cyberActor->GetProperty()->SetRepresentationToWireframe();
cyberActor->GetProperty()->SetColor(
colors->GetColor3d("Turquoise").GetData());
// Add the actors to the renderer, set the background and size
//
ren1->AddActor(cyberActor);
ren1->AddActor(splatActor);
ren1->SetBackground(colors->GetColor3d("Wheat").GetData());
renWin->SetSize(640, 480);
renWin->SetWindowName("SplatFace");
vtkNew<vtkCamera> camera;
camera->SetClippingRange(0.0332682, 1.66341);
camera->SetFocalPoint(0.0511519, -0.127555, -0.0554379);
camera->SetPosition(0.516567, -0.124763, -0.349538);
camera->SetViewAngle(18.1279);
camera->SetViewUp(-0.013125, 0.99985, -0.0112779);
ren1->SetActiveCamera(camera);
// render the image
//
renWin->Render();
iren->Start();
return EXIT_SUCCESS;
}
CMakeLists.txt¶
cmake_minimum_required(VERSION 3.12 FATAL_ERROR)
project(SplatFace)
find_package(VTK COMPONENTS
CommonColor
CommonCore
FiltersCore
IOLegacy
ImagingHybrid
InteractionStyle
RenderingContextOpenGL2
RenderingCore
RenderingFreeType
RenderingGL2PSOpenGL2
RenderingOpenGL2
)
if (NOT VTK_FOUND)
message(FATAL_ERROR "SplatFace: Unable to find the VTK build folder.")
endif()
# Prevent a "command line is too long" failure in Windows.
set(CMAKE_NINJA_FORCE_RESPONSE_FILE "ON" CACHE BOOL "Force Ninja to use response files.")
add_executable(SplatFace MACOSX_BUNDLE SplatFace.cxx )
target_link_libraries(SplatFace PRIVATE ${VTK_LIBRARIES}
)
# vtk_module_autoinit is needed
vtk_module_autoinit(
TARGETS SplatFace
MODULES ${VTK_LIBRARIES}
)
Download and Build SplatFace¶
Click here to download SplatFace and its CMakeLists.txt file. Once the tarball SplatFace.tar has been downloaded and extracted,
cd SplatFace/build
If VTK is installed:
cmake ..
If VTK is not installed but compiled on your system, you will need to specify the path to your VTK build:
cmake -DVTK_DIR:PATH=/home/me/vtk_build ..
Build the project:
make
and run it:
./SplatFace
WINDOWS USERS
Be sure to add the VTK bin directory to your path. This will resolve the VTK dll's at run time.