WarpTo
Repository source: WarpTo
Other languages
See (Python), (PythonicAPI), (Java)
Question
If you have a question about this example, please use the VTK Discourse Forum
Code¶
WarpTo.cxx
#include <vtkDataSetMapper.h>
#include <vtkLineSource.h>
#include <vtkNamedColors.h>
#include <vtkNew.h>
#include <vtkProperty.h>
#include <vtkRenderWindow.h>
#include <vtkRenderWindowInteractor.h>
#include <vtkRenderer.h>
#include <vtkTubeFilter.h>
#include <vtkWarpTo.h>
int main(int, char*[])
{
vtkNew<vtkNamedColors> namedColors;
// Create the RenderWindow, Renderer and both Actors.
vtkNew<vtkRenderer> renderer;
vtkNew<vtkRenderWindow> renderWindow;
renderWindow->AddRenderer(renderer);
vtkNew<vtkRenderWindowInteractor> renderWindowInteractor;
renderWindowInteractor->SetRenderWindow(renderWindow);
// Create a line
vtkNew<vtkLineSource> lineSource;
lineSource->SetPoint1(0.0, 0.0, 0.0);
lineSource->SetPoint2(0.0, 1.0, 0.0);
lineSource->SetResolution(20);
lineSource->Update();
// Create a tube (cylinder) around the line.
vtkNew<vtkTubeFilter> tubeFilter;
tubeFilter->SetInputConnection(lineSource->GetOutputPort());
tubeFilter->SetRadius(.01); // default is .5
tubeFilter->SetNumberOfSides(50);
tubeFilter->Update();
vtkNew<vtkWarpTo> warpTo;
warpTo->SetInputConnection(tubeFilter->GetOutputPort());
warpTo->SetPosition(10, 1, 0);
warpTo->SetScaleFactor(5);
warpTo->AbsoluteOn();
vtkNew<vtkDataSetMapper> mapper;
mapper->SetInputConnection(warpTo->GetOutputPort());
mapper->ScalarVisibilityOff();
vtkNew<vtkActor> actor;
actor->SetMapper(mapper);
actor->GetProperty()->SetColor(namedColors->GetColor3d("Gold").GetData());
renderer->AddActor(actor);
renderer->SetBackground(namedColors->GetColor3d("Green").GetData());
renderWindow->SetWindowName("WarpTo");
renderWindow->Render();
renderWindowInteractor->Initialize();
renderWindowInteractor->Start();
return EXIT_SUCCESS;
}
CMakeLists.txt¶
cmake_minimum_required(VERSION 3.12 FATAL_ERROR)
project(WarpTo)
find_package(VTK COMPONENTS
CommonColor
CommonCore
FiltersCore
FiltersGeneral
FiltersSources
InteractionStyle
RenderingContextOpenGL2
RenderingCore
RenderingFreeType
RenderingGL2PSOpenGL2
RenderingOpenGL2
)
if (NOT VTK_FOUND)
message(FATAL_ERROR "WarpTo: 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(WarpTo MACOSX_BUNDLE WarpTo.cxx )
target_link_libraries(WarpTo PRIVATE ${VTK_LIBRARIES}
)
# vtk_module_autoinit is needed
vtk_module_autoinit(
TARGETS WarpTo
MODULES ${VTK_LIBRARIES}
)
Download and Build WarpTo¶
Click here to download WarpTo and its CMakeLists.txt file. Once the tarball WarpTo.tar has been downloaded and extracted,
cd WarpTo/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:
./WarpTo
WINDOWS USERS
Be sure to add the VTK bin directory to your path. This will resolve the VTK dll's at run time.