# WarpTo

VTKExamples/Cxx/Filtering/WarpTo

Other Languages

See (Python), (Java)

### Code

WarpTo.cxx

    #include <vtkSmartPointer.h>
    #include <vtkLineSource.h>
    #include <vtkTubeFilter.h>
    #include <vtkDataSetMapper.h>
    #include <vtkRenderWindow.h>
    #include <vtkRenderWindowInteractor.h>
    #include <vtkRenderer.h>
    #include <vtkWarpTo.h>

    int main(int, char*[])
    {
      // Create the RenderWindow, Renderer and both Actors
      vtkSmartPointer<vtkRenderer> renderer =
        vtkSmartPointer<vtkRenderer>::New();
      vtkSmartPointer<vtkRenderWindow> renderWindow =
        vtkSmartPointer<vtkRenderWindow>::New();
      renderWindow->AddRenderer(renderer);
      vtkSmartPointer<vtkRenderWindowInteractor> renderWindowInteractor =
        vtkSmartPointer<vtkRenderWindowInteractor>::New();
      renderWindowInteractor->SetRenderWindow(renderWindow);

      // Create a line
      vtkSmartPointer<vtkLineSource> lineSource =
        vtkSmartPointer<vtkLineSource>::New();
      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
      vtkSmartPointer<vtkTubeFilter> tubeFilter =
        vtkSmartPointer<vtkTubeFilter>::New();
      tubeFilter->SetInputConnection(lineSource->GetOutputPort());
      tubeFilter->SetRadius(.01); //default is .5
      tubeFilter->SetNumberOfSides(50);
      tubeFilter->Update();

      vtkSmartPointer<vtkWarpTo> warpTo =
        vtkSmartPointer<vtkWarpTo>::New();
      warpTo->SetInputConnection(tubeFilter->GetOutputPort());
      warpTo->SetPosition(10, 1, 0);
      warpTo->SetScaleFactor(5);
      warpTo->AbsoluteOn();

      vtkSmartPointer<vtkDataSetMapper> mapper =
        vtkSmartPointer<vtkDataSetMapper>::New();
      mapper->SetInputConnection(warpTo->GetOutputPort());
      mapper->ScalarVisibilityOff();

      vtkSmartPointer<vtkActor> actor =
        vtkSmartPointer<vtkActor>::New();
      actor->SetMapper(mapper);

      renderer->AddActor(actor);

      renderWindow->Render();
      renderWindowInteractor->Initialize();
      renderWindowInteractor->Start();

      return EXIT_SUCCESS;
    }

### CMakeLists.txt

    cmake_minimum_required(VERSION 3.3 FATAL_ERROR)

    project(WarpTo)

    find_package(VTK COMPONENTS
      vtkCommonCore
      vtkFiltersCore
      vtkFiltersGeneral
      vtkFiltersSources
      vtkInteractionStyle
      vtkRenderingContextOpenGL2
      vtkRenderingCore
      vtkRenderingFreeType
      vtkRenderingGL2PSOpenGL2
      vtkRenderingOpenGL2 QUIET)
    if (NOT VTK_FOUND)
      message("Skipping WarpTo: ${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(WarpTo MACOSX_BUNDLE WarpTo.cxx )
      target_link_libraries(WarpTo PRIVATE ${VTK_LIBRARIES})
    else ()
      # include all components
      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}
        )
    endif ()

### 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.