LoopShrink
VTKEx/Cxx/Visualization/LoopShrink
Description¶
A network with a loop. VTK 5.0 and later do not allow you to execute a looping visualization network; this was possible in previous versions of VTK.
Info
See Figure 4-22 in Chapter 4 the VTK Textbook.
Question
If you have a simple question about this example contact us at VTKExProject If your question is more complex and may require extended discussion, please use the VTK Discourse Forum
Code¶
LoopShrink.cxx
#include <vtkActor.h>
#include <vtkCullerCollection.h>
#include <vtkDataSetMapper.h>
#include <vtkElevationFilter.h>
#include <vtkNamedColors.h>
#include <vtkRenderWindow.h>
#include <vtkRenderWindowInteractor.h>
#include <vtkRenderer.h>
#include <vtkShrinkFilter.h>
#include <vtkSphereSource.h>
int main( int, char *[] )
{
vtkSmartPointer<vtkNamedColors> colors =
vtkSmartPointer<vtkNamedColors>::New();
vtkSmartPointer<vtkRenderer> renderer =
vtkSmartPointer<vtkRenderer>::New();
renderer->GetCullers()->RemoveAllItems();
vtkSmartPointer<vtkRenderWindow> renWin =
vtkSmartPointer<vtkRenderWindow>::New();
renWin->AddRenderer(renderer);
vtkSmartPointer<vtkRenderWindowInteractor> iren =
vtkSmartPointer<vtkRenderWindowInteractor>::New();
iren->SetRenderWindow(renWin);
vtkSmartPointer<vtkSphereSource> sphere =
vtkSmartPointer<vtkSphereSource>::New();
sphere->SetThetaResolution(12); sphere->SetPhiResolution(12);
vtkSmartPointer<vtkShrinkFilter> shrink =
vtkSmartPointer<vtkShrinkFilter>::New();
shrink->SetInputConnection(sphere->GetOutputPort());
shrink->SetShrinkFactor(0.9);
vtkSmartPointer<vtkElevationFilter> colorIt =
vtkSmartPointer<vtkElevationFilter>::New();
colorIt->SetInputConnection(shrink->GetOutputPort());
colorIt->SetLowPoint(0,0,-.5);
colorIt->SetHighPoint(0,0,.5);
vtkSmartPointer<vtkDataSetMapper> mapper =
vtkSmartPointer<vtkDataSetMapper>::New();
mapper->SetInputConnection(colorIt->GetOutputPort());
vtkSmartPointer<vtkActor> actor =
vtkSmartPointer<vtkActor>::New();
actor->SetMapper(mapper);
renderer->AddActor(actor);
renderer->SetBackground(colors->GetColor3d("White").GetData());
renWin->SetSize(640, 480);
renWin->Render();
// interact with data
iren->Start();
return EXIT_SUCCESS;
}
CMakeLists.txt¶
cmake_minimum_required(VERSION 3.3 FATAL_ERROR)
project(LoopShrink)
find_package(VTK COMPONENTS
vtkvtkCommonColor
vtkvtkFiltersCore
vtkvtkFiltersGeneral
vtkvtkFiltersSources
vtkvtkInteractionStyle
vtkvtkRenderingContextOpenGL2
vtkvtkRenderingCore
vtkvtkRenderingFreeType
vtkvtkRenderingGL2PSOpenGL2
vtkvtkRenderingOpenGL2 QUIET)
if (NOT VTK_FOUND)
message("Skipping LoopShrink: ${VTK_NOT_FOUND_MESSAGE}")
return ()
endif()
message (STATUS "VTK_VERSION: ${VTK_VERSION}")
if (VTK_VERSION VERSION_LESS "8.90.0")
# old system
include(${VTK_USE_FILE})
add_executable(LoopShrink MACOSX_BUNDLE LoopShrink.cxx )
target_link_libraries(LoopShrink PRIVATE ${VTK_LIBRARIES})
else ()
# include all components
add_executable(LoopShrink MACOSX_BUNDLE LoopShrink.cxx )
target_link_libraries(LoopShrink PRIVATE ${VTK_LIBRARIES})
# vtk_module_autoinit is needed
vtk_module_autoinit(
TARGETS LoopShrink
MODULES ${VTK_LIBRARIES}
)
endif ()
Download and Build LoopShrink¶
Click here to download LoopShrink and its CMakeLists.txt file. Once the tarball LoopShrink.tar has been downloaded and extracted,
cd LoopShrink/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:
./LoopShrink
WINDOWS USERS
Be sure to add the VTK bin directory to your path. This will resolve the VTK dll's at run time.