#!/usr/bin/env python

import vtk

quadPoints = vtk.vtkPoints()
quadPoints.SetNumberOfPoints(8)

# 4 points for non-planar quad (this is almost planar)

quadPoints.InsertPoint(0, -1.1, 0, 0)
quadPoints.InsertPoint(1, -0.1, 0, 0)
quadPoints.InsertPoint(2, -0.1, 1, 0)
quadPoints.InsertPoint(3, -1.1, 1, 0.1)

# 4 points for planar quad

quadPoints.InsertPoint(4, 0.1, 0, 0)
quadPoints.InsertPoint(5, 1.1, 0, 0)
quadPoints.InsertPoint(6, 1.1, 1, 0)
quadPoints.InsertPoint(7, 0.1, 1, 0)


aQuadGrid1 = vtk.vtkPolyData()
aQuadGrid1.Allocate(1, 1)
aQuadGrid1.SetPoints(quadPoints)

aQuadGrid2 = vtk.vtkPolyData()
aQuadGrid2.Allocate(1, 1)
aQuadGrid2.SetPoints(quadPoints)


ids = vtk.vtkIdList()
ids.SetNumberOfIds(4)

# add one quad

ids.SetId(0, 0)
ids.SetId(1, 1)
ids.SetId(2, 2)
ids.SetId(3, 3)
aQuadGrid1.InsertNextCell(7, ids)

# add a second quad

ids.SetId(0, 4)
ids.SetId(1, 5)
ids.SetId(2, 6)
ids.SetId(3, 7)
aQuadGrid2.InsertNextCell(7, ids)

# create mapper and actor
aQuadMapper1 = vtk.vtkPolyDataMapper()
aQuadMapper1.SetInput(aQuadGrid1)
aQuadActor1 = vtk.vtkActor()
aQuadActor1.SetMapper(aQuadMapper1)

aQuadMapper2 = vtk.vtkPolyDataMapper()
aQuadMapper2.SetInput(aQuadGrid2)
aQuadActor2 = vtk.vtkActor()
aQuadActor2.SetMapper(aQuadMapper2)


# Create the usual rendering stuff.
ren = vtk.vtkRenderer()
renWin = vtk.vtkRenderWindow()
renWin.AddRenderer(ren)
iren = vtk.vtkRenderWindowInteractor()
iren.SetRenderWindow(renWin)
picker = vtk.vtkCellPicker()
iren.SetPicker(picker)

ren.AddProp(aQuadActor1)
ren.AddProp(aQuadActor2)

ren.ResetCamera()

# Render the scene and start interaction.
iren.Initialize()
renWin.Render()
iren.Start()
