# ContourQuadric

VTKExamples/Cxx/VisualizationAlgorithms/ContourQuadric

### Code

ContourQuadric.cxx

    #include <vtkActor.h>
    #include <vtkCamera.h>
    #include <vtkContourFilter.h>
    #include <vtkNamedColors.h>
    #include <vtkOutlineFilter.h>
    #include <vtkPolyDataMapper.h>
    #include <vtkProperty.h>
    #include <vtkQuadric.h>
    #include <vtkRenderWindow.h>
    #include <vtkRenderWindowInteractor.h>
    #include <vtkRenderer.h>
    #include <vtkSampleFunction.h>

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

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

      vtkSmartPointer<vtkRenderWindow> renWin =
        vtkSmartPointer<vtkRenderWindow>::New();
      renWin->AddRenderer(aren);

      vtkSmartPointer<vtkRenderWindowInteractor> iren =
        vtkSmartPointer<vtkRenderWindowInteractor>::New();
      iren->SetRenderWindow(renWin);

    //
    // Create surfaces F(x,y,z) = constant
    //
      // Sample quadric function
      vtkSmartPointer<vtkQuadric> quadric =
        vtkSmartPointer<vtkQuadric>::New();
      quadric->SetCoefficients(.5,1,.2,0,.1,0,0,.2,0,0);
      vtkSmartPointer<vtkSampleFunction> sample =
        vtkSmartPointer<vtkSampleFunction>::New();
      sample->SetSampleDimensions(50,50,50);
      sample->SetImplicitFunction(quadric);

      vtkSmartPointer<vtkContourFilter> contour =
        vtkSmartPointer<vtkContourFilter>::New();
      contour->SetInputConnection(sample->GetOutputPort());
      contour->GenerateValues(5,0,1.2);

      vtkSmartPointer<vtkPolyDataMapper> contourMapper =
        vtkSmartPointer<vtkPolyDataMapper>::New();
      contourMapper->SetInputConnection(contour->GetOutputPort());
      contourMapper->SetScalarRange(0,1.2);

      vtkSmartPointer<vtkActor> contourActor =
        vtkSmartPointer<vtkActor>::New();
      contourActor->SetMapper(contourMapper);

      // Create outline
      vtkSmartPointer<vtkOutlineFilter> outline =
        vtkSmartPointer<vtkOutlineFilter>::New();
      outline->SetInputConnection(sample->GetOutputPort());

      vtkSmartPointer<vtkPolyDataMapper> outlineMapper =
        vtkSmartPointer<vtkPolyDataMapper>::New();
      outlineMapper->SetInputConnection(outline->GetOutputPort());

      vtkSmartPointer<vtkActor> outlineActor =
        vtkSmartPointer<vtkActor>::New();
      outlineActor->SetMapper(outlineMapper);
      outlineActor->GetProperty()->SetColor(colors->GetColor3d("Brown").GetData());
      outlineActor->GetProperty()->SetLineWidth(3.0);

    //
    // Rendering stuff
    //
      aren->SetBackground(colors->GetColor3d("SlateGray").GetData());
      aren->AddActor(contourActor);
      aren->AddActor(outlineActor);

      aren->ResetCamera();
      aren->GetActiveCamera()->Azimuth(30);
      aren->GetActiveCamera()->Elevation(30);

      renWin->SetSize(640, 512);
      renWin->Render();

      // interact with data
      iren->Start();

      return EXIT_SUCCESS;
    }

### CMakeLists.txt

    cmake_minimum_required(VERSION 2.8)

    PROJECT(ContourQuadric)

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

    add_executable(ContourQuadric MACOSX_BUNDLE ContourQuadric.cxx )

    target_link_libraries(ContourQuadric ${VTK_LIBRARIES})

### Download and Build ContourQuadric

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

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

    ./ContourQuadric

WINDOWS USERS

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