# Glyph3DMapper

VTKExamples/Cxx/Visualization/Glyph3DMapper

### Code

Glyph3DMapper.cxx

    #include <vtkVersion.h>
    #include <vtkSmartPointer.h>
    #include <vtkCubeSource.h>
    #include <vtkPolyData.h>
    #include <vtkPoints.h>
    #include <vtkGlyph3DMapper.h>
    #include <vtkCellArray.h>
    #include <vtkActor.h>
    #include <vtkRenderWindow.h>
    #include <vtkRenderer.h>
    #include <vtkRenderWindowInteractor.h>

    int main(int, char *[])
    {
      vtkSmartPointer<vtkPoints> points =
        vtkSmartPointer<vtkPoints>::New();
      points->InsertNextPoint(0,0,0);
      points->InsertNextPoint(1,1,1);
      points->InsertNextPoint(2,2,2);

      vtkSmartPointer<vtkPolyData> polydata =
        vtkSmartPointer<vtkPolyData>::New();
      polydata->SetPoints(points);

      vtkSmartPointer<vtkPolyData> glyph =
        vtkSmartPointer<vtkPolyData>::New();

      // Create anything you want here, we will use a cube for the demo.
      vtkSmartPointer<vtkCubeSource> cubeSource =
        vtkSmartPointer<vtkCubeSource>::New();

      vtkSmartPointer<vtkGlyph3DMapper> glyph3Dmapper =
        vtkSmartPointer<vtkGlyph3DMapper>::New();
      glyph3Dmapper->SetSourceConnection(cubeSource->GetOutputPort());
    #if VTK_MAJOR_VERSION <= 5
      glyph3Dmapper->SetInputConnection(polydata->GetProducerPort());
    #else
      glyph3Dmapper->SetInputData(polydata);
    #endif
      glyph3Dmapper->Update();

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

      // Create a renderer, render window, and interactor
      vtkSmartPointer<vtkRenderer> renderer =
        vtkSmartPointer<vtkRenderer>::New();
      vtkSmartPointer<vtkRenderWindow> renderWindow =
        vtkSmartPointer<vtkRenderWindow>::New();
      renderWindow->AddRenderer(renderer);
      vtkSmartPointer<vtkRenderWindowInteractor> renderWindowInteractor =
        vtkSmartPointer<vtkRenderWindowInteractor>::New();
      renderWindowInteractor->SetRenderWindow(renderWindow);

      // Add the actor to the scene
      renderer->AddActor(actor);

      // Render and interact
      renderWindow->Render();
      renderWindowInteractor->Start();

      return EXIT_SUCCESS;
    }

### CMakeLists.txt

    cmake_minimum_required(VERSION 2.8)

    PROJECT(Glyph3DMapper)

    find_package(VTK REQUIRED)
    include(${VTK_USE_FILE})

    add_executable(Glyph3DMapper MACOSX_BUNDLE Glyph3DMapper.cxx)

    target_link_libraries(Glyph3DMapper ${VTK_LIBRARIES})

### Download and Build Glyph3DMapper

Danger

The generation of tar files has not been ported to the new VTKExamples. Some tarballs may be missing or out-of-date.

Click here to download Glyph3DMapper and its CMakeLists.txt file. Once the tarball Glyph3DMapper.tar has been downloaded and extracted,

    cd Glyph3DMapper/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:

    ./Glyph3DMapper

WINDOWS USERS PLEASE NOTE: Be sure to add the VTK bin directory to your path. This will resolve the VTK dll's at run time.