BoundaryEdges
Repository source: BoundaryEdges
Description¶
This filter will extract the boundary edges of a mesh. The original mesh is shown with the feature edges shown in red.
Question
If you have a question about this example, please use the VTK Discourse Forum
Code¶
BoundaryEdges.cxx
#include <vtkActor.h>
#include <vtkDiskSource.h>
#include <vtkFeatureEdges.h>
#include <vtkNamedColors.h>
#include <vtkNew.h>
#include <vtkPolyDataMapper.h>
#include <vtkProperty.h>
#include <vtkRenderWindow.h>
#include <vtkRenderWindowInteractor.h>
#include <vtkRenderer.h>
int main(int, char*[])
{
vtkNew<vtkNamedColors> colors;
vtkNew<vtkDiskSource> diskSource;
diskSource->Update();
vtkNew<vtkFeatureEdges> featureEdges;
featureEdges->SetInputConnection(diskSource->GetOutputPort());
featureEdges->BoundaryEdgesOn();
featureEdges->FeatureEdgesOff();
featureEdges->ManifoldEdgesOff();
featureEdges->NonManifoldEdgesOff();
featureEdges->ColoringOn();
featureEdges->Update();
// Visualize
vtkNew<vtkPolyDataMapper> edgeMapper;
edgeMapper->SetInputConnection(featureEdges->GetOutputPort());
edgeMapper->SetScalarModeToUseCellData();
vtkNew<vtkActor> edgeActor;
edgeActor->SetMapper(edgeMapper);
vtkNew<vtkPolyDataMapper> diskMapper;
diskMapper->SetInputConnection(diskSource->GetOutputPort());
vtkNew<vtkActor> diskActor;
diskActor->SetMapper(diskMapper);
diskActor->GetProperty()->SetColor(colors->GetColor3d("Gray").GetData());
// Create a renderer, render window, and interactor
vtkNew<vtkRenderer> renderer;
vtkNew<vtkRenderWindow> renderWindow;
renderWindow->AddRenderer(renderer);
renderWindow->SetWindowName("BoundaryEdges");
vtkNew<vtkRenderWindowInteractor> renderWindowInteractor;
renderWindowInteractor->SetRenderWindow(renderWindow);
renderer->AddActor(edgeActor);
renderer->AddActor(diskActor);
renderer->SetBackground(colors->GetColor3d("DimGray").GetData());
renderWindow->Render();
renderWindowInteractor->Start();
return EXIT_SUCCESS;
}
CMakeLists.txt¶
cmake_minimum_required(VERSION 3.12 FATAL_ERROR)
project(BoundaryEdges)
find_package(VTK COMPONENTS
CommonColor
CommonCore
FiltersCore
FiltersSources
InteractionStyle
RenderingContextOpenGL2
RenderingCore
RenderingFreeType
RenderingGL2PSOpenGL2
RenderingOpenGL2
)
if (NOT VTK_FOUND)
message(FATAL_ERROR "BoundaryEdges: 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(BoundaryEdges MACOSX_BUNDLE BoundaryEdges.cxx )
target_link_libraries(BoundaryEdges PRIVATE ${VTK_LIBRARIES}
)
# vtk_module_autoinit is needed
vtk_module_autoinit(
TARGETS BoundaryEdges
MODULES ${VTK_LIBRARIES}
)
Download and Build BoundaryEdges¶
Click here to download BoundaryEdges and its CMakeLists.txt file. Once the tarball BoundaryEdges.tar has been downloaded and extracted,
cd BoundaryEdges/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:
./BoundaryEdges
WINDOWS USERS
Be sure to add the VTK bin directory to your path. This will resolve the VTK dll's at run time.