# Mace

VTKExamples/Cxx/Rendering/Mace

### Description

An example of multiple inputs and outputs.

Info

See Figure 4-21 in Chapter 4 the VTK Textbook.

### Code

Mace.cxx

    #include <vtkConeSource.h>
    #include <vtkGlyph3D.h>
    #include <vtkNamedColors.h>
    #include <vtkPolyData.h>
    #include <vtkPolyDataMapper.h>
    #include <vtkRenderWindow.h>
    #include <vtkRenderWindowInteractor.h>
    #include <vtkRenderer.h>
    #include <vtkSphereSource.h>

    int main( int, char *[] )
    {
      vtkSmartPointer<vtkNamedColors> colors =
        vtkSmartPointer<vtkNamedColors>::New();

      vtkSmartPointer<vtkRenderer> renderer =
        vtkSmartPointer<vtkRenderer>::New();

      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(8); sphere->SetPhiResolution(8);

      vtkSmartPointer<vtkPolyDataMapper> sphereMapper =
        vtkSmartPointer<vtkPolyDataMapper>::New();
      sphereMapper->SetInputConnection(sphere->GetOutputPort());

      vtkSmartPointer<vtkActor> sphereActor =
        vtkSmartPointer<vtkActor>::New();
      sphereActor->SetMapper(sphereMapper);

      vtkSmartPointer<vtkConeSource> cone =
        vtkSmartPointer<vtkConeSource>::New();
      cone->SetResolution(6);

      vtkSmartPointer<vtkGlyph3D> glyph =
        vtkSmartPointer<vtkGlyph3D>::New();
      glyph->SetInputConnection(sphere->GetOutputPort());
      glyph->SetSourceConnection(cone->GetOutputPort());
      glyph->SetVectorModeToUseNormal();
      glyph->SetScaleModeToScaleByVector();
      glyph->SetScaleFactor(0.25);

      vtkSmartPointer<vtkPolyDataMapper> spikeMapper =
        vtkSmartPointer<vtkPolyDataMapper>::New();
      spikeMapper->SetInputConnection(glyph->GetOutputPort());

      vtkSmartPointer<vtkActor> spikeActor =
        vtkSmartPointer<vtkActor>::New();
      spikeActor->SetMapper(spikeMapper);

      renderer->AddActor(sphereActor);
      renderer->AddActor(spikeActor);
      renderer->SetBackground(colors->GetColor3d("SlateGray").GetData());
      renWin->SetSize(640, 480);

      // interact with data
      renWin->Render();

      iren->Start();

      return EXIT_SUCCESS;
    }

### CMakeLists.txt

    cmake_minimum_required(VERSION 2.8)

    PROJECT(Mace)

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

    add_executable(Mace MACOSX_BUNDLE Mace.cxx )

    target_link_libraries(Mace ${VTK_LIBRARIES})

### Download and Build Mace

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

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

    ./Mace

WINDOWS USERS

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