< VTK‎ | Examples‎ | Cxx

This example demonstrates how to display several types of quadratic surfaces.

```#include <vtkQuadric.h>
#include <vtkSampleFunction.h>
#include <vtkContourFilter.h>
#include <vtkOutlineFilter.h>
#include <vtkPolyDataMapper.h>
#include <vtkActor.h>
#include <vtkProperty.h>
#include <vtkRenderWindow.h>
#include <vtkRenderer.h>
#include <vtkRenderWindowInteractor.h>
#include <vtkImageData.h>
#include <vtkSmartPointer.h>

void Other();
void Sphere();
void Cone();
void Ellipsoid();
void Cylinder();
void HyperboloidOneSheet();
void HyperboloidTwoSheets();
void HyperbolicParaboloid();
void EllipticParaboloid();

int main (int, char *[])
{
//Other();
//Sphere();
//Cone();
//Ellipsoid();
//Cylinder();
//HyperboloidOneSheet();
//HyperboloidTwoSheets();
//HyperbolicParaboloid();
EllipticParaboloid();

return 0;
}

void Sphere()
{
// create the quadric function definition

// F(x,y,z) = a0*x^2 + a1*y^2 + a2*z^2 + a3*x*y + a4*y*z + a5*x*z + a6*x + a7*y + a8*z + a9
// F(x,y,z) = 1*x^2 + 1*y^2 + 1*z^2

}

void EllipticParaboloid()
{
// create the quadric function definition

// F(x,y,z) = a0*x^2 + a1*y^2 + a2*z^2 + a3*x*y + a4*y*z + a5*x*z + a6*x + a7*y + a8*z + a9
// F(x,y,z) = 1*x^2 + 1*y^2

}

void HyperbolicParaboloid()
{
// create the quadric function definition

// F(x,y,z) = a0*x^2 + a1*y^2 + a2*z^2 + a3*x*y + a4*y*z + a5*x*z + a6*x + a7*y + a8*z + a9
// F(x,y,z) = 1*x^2 - 1*y^2

}

void Cylinder()
{
// create the quadric function definition

// F(x,y,z) = a0*x^2 + a1*y^2 + a2*z^2 + a3*x*y + a4*y*z + a5*x*z + a6*x + a7*y + a8*z + a9
// F(x,y,z) = 1*x^2 + 1*y^2

}

void HyperboloidOneSheet()
{
// create the quadric function definition

// F(x,y,z) = a0*x^2 + a1*y^2 + a2*z^2 + a3*x*y + a4*y*z + a5*x*z + a6*x + a7*y + a8*z + a9
// F(x,y,z) = 1*x^2 + 1*y^2

}

void HyperboloidTwoSheets()
{
// create the quadric function definition

// F(x,y,z) = a0*x^2 + a1*y^2 + a2*z^2 + a3*x*y + a4*y*z + a5*x*z + a6*x + a7*y + a8*z + a9
// F(x,y,z) = 1*x^2 + 1*y^2

}

void Ellipsoid()
{
// create the quadric function definition

// F(x,y,z) = a0*x^2 + a1*y^2 + a2*z^2 + a3*x*y + a4*y*z + a5*x*z + a6*x + a7*y + a8*z + a9
// F(x,y,z) = 1*x^2 + 1*y^2 + 1*z^2

}

void Cone()
{
// create the quadric function definition

// F(x,y,z) = a0*x^2 + a1*y^2 + a2*z^2 + a3*x*y + a4*y*z + a5*x*z + a6*x + a7*y + a8*z + a9
// F(x,y,z) = 1*x^2 + 1*y^2 - 1*z^2

}

void Other()
{
// create the quadric function definition

// F(x,y,z) = a0*x^2 + a1*y^2 + a2*z^2 + a3*x*y + a4*y*z + a5*x*z + a6*x + a7*y + a8*z + a9
// F(x,y,z) = 0.5*x^2 + 1*y^2 + 0.2*z^2 + 0*x*y + 0.1*y*z + 0*x*z + 0*x + 0.2*y + 0*z + 0

}

{

vtkSmartPointer<vtkSampleFunction> sample = vtkSmartPointer<vtkSampleFunction>::New();
sample->SetSampleDimensions(50,50,50);
//double xmin = 0, xmax=1, ymin=0, ymax=1, zmin=0, zmax=1;
double xmin = -10, xmax=11, ymin=-10, ymax=10, zmin=-10, zmax=10;
sample->SetModelBounds(xmin, xmax, ymin, ymax, zmin, zmax);

// Create five surfaces F(x,y,z) = constant between range specified
/*
vtkContourFilter *contours = vtkContourFilter::New();
contours->SetInput(sample->GetOutput());
contours->GenerateValues(5, 0.0, 1.2);
*/

//create the 0 isosurface
vtkSmartPointer<vtkContourFilter> contours = vtkSmartPointer<vtkContourFilter>::New();
contours->SetInputConnection(sample->GetOutputPort());
contours->GenerateValues(1, value, value);

// map the contours to graphical primitives
vtkSmartPointer<vtkPolyDataMapper> contourMapper = vtkSmartPointer<vtkPolyDataMapper>::New();
contourMapper->SetInputConnection(contours->GetOutputPort());
contourMapper->SetScalarRange(0.0, 1.2);

// create an actor for the contours
vtkSmartPointer<vtkActor> contourActor = vtkSmartPointer<vtkActor>::New();
contourActor->SetMapper(contourMapper);

// -- create a box around the function to indicate the sampling volume --

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

// map it to graphics primitives
vtkSmartPointer<vtkPolyDataMapper> outlineMapper = vtkSmartPointer<vtkPolyDataMapper>::New();
outlineMapper->SetInputConnection(outline->GetOutputPort());

// create an actor for it
vtkSmartPointer<vtkActor> outlineActor = vtkSmartPointer<vtkActor>::New();
outlineActor->SetMapper(outlineMapper);
outlineActor->GetProperty()->SetColor(0,0,0);

// setup the window
vtkSmartPointer<vtkRenderer> ren1 = vtkSmartPointer<vtkRenderer>::New();
vtkSmartPointer<vtkRenderWindow> renWin = vtkSmartPointer<vtkRenderWindow>::New();
vtkSmartPointer<vtkRenderWindowInteractor> iren = vtkSmartPointer<vtkRenderWindowInteractor>::New();
iren->SetRenderWindow(renWin);

// add the actors to the scene
ren1->SetBackground(1,1,1); // Background color white

// render and interact
renWin->Render();
iren->Start();
}
```

# Please try the new VTKExamples website.

## CMakeLists.txt

```cmake_minimum_required(VERSION 2.8)

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

if(VTK_LIBRARIES)
else()
endif()
```

```cd DisplayQuadraticSurfaces/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:

```./DisplayQuadraticSurfaces
```

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.

Display all at the same time using many side-by-side renderers!