# IsoparametricCellsDemo

vtk-examples/Python/GeometricObjects/IsoparametricCellsDemo

### Description¶

This example shows the isoparametric cells supported by the VTK. These cells are nonlinear and contain one or more mid-side vertices. Isoparametric elements are typically used in finite element analysis. The term isoparametric is derived from the use of the same shape functions (or interpolation functions) to define the element's geometric shape as are used to define the displacements within the element.

This example illustrates each cell's representation using its parametric coordinates (pcoords) as the vertices of the cell. In practice, the vertices will correspond to physical points in a finite element model. Use vtkTessellatorFilter to better see the shape of the cell. See for example, QuadraticHexahedronDemo and QuadraticTetraDemo.

Other languages

See (Cxx)

Question

If you have a question about this example, please use the VTK Discourse Forum

### Code¶

IsoparametricCellsDemo.py

#!/usr/bin/env python
# -*- coding: utf-8 -*-

# noinspection PyUnresolvedReferences
import vtkmodules.vtkInteractionStyle
# noinspection PyUnresolvedReferences
import vtkmodules.vtkRenderingOpenGL2
from vtkmodules.vtkCommonColor import vtkNamedColors
from vtkmodules.vtkCommonDataModel import (
vtkCubicLine,
vtkUnstructuredGrid
)
from vtkmodules.vtkFiltersSources import vtkSphereSource
from vtkmodules.vtkRenderingCore import (
vtkActor,
vtkActor2D,
vtkDataSetMapper,
vtkGlyph3DMapper,
vtkRenderWindow,
vtkRenderWindowInteractor,
vtkRenderer,
vtkTextMapper,
vtkTextProperty
)
from vtkmodules.vtkRenderingLabel import vtkLabeledDataMapper

def main():
titles = list()
textMappers = list()
textActors = list()

uGrids = list()
mappers = list()
actors = list()
renderers = list()

uGrids.append(MakeUnstructuredGrid(

uGrids.append(MakeUnstructuredGrid(

uGrids.append(MakeUnstructuredGrid(

uGrids.append(MakeUnstructuredGrid(

uGrids.append(MakeUnstructuredGrid(

uGrids.append(MakeUnstructuredGrid(

uGrids.append(MakeUnstructuredGrid(

uGrids.append(MakeUnstructuredGrid(

uGrids.append(MakeUnstructuredGrid(

uGrids.append(MakeUnstructuredGrid(

uGrids.append(MakeUnstructuredGrid(

uGrids.append(MakeUnstructuredGrid(

uGrids.append(MakeUnstructuredGrid(

uGrids.append(MakeUnstructuredGrid(

uGrids.append(MakeUnstructuredGrid(
vtkCubicLine()))
titles.append('VTK_CUBIC_LINE (= 35)')

colors = vtkNamedColors()

renWin = vtkRenderWindow()
renWin.SetSize(600, 600)
renWin.SetWindowName('Isoparametric Cell')

iRen = vtkRenderWindowInteractor()
iRen.SetRenderWindow(renWin)

# Create one sphere for all
sphere = vtkSphereSource()
sphere.SetPhiResolution(21)
sphere.SetThetaResolution(21)

# Create one text property for all
textProperty = vtkTextProperty()
textProperty.SetFontSize(10)
textProperty.SetJustificationToCentered()

# Create and link the mappers actors and renderers together.
for i in range(0, len(uGrids)):
print('Creating:', titles[i])
textMappers.append(vtkTextMapper())
textActors.append(vtkActor2D())

textMappers[i].GetTextProperty().SetFontSize(10)
mappers.append(vtkDataSetMapper())
actors.append(vtkActor())
renderers.append(vtkRenderer())
mappers[i].SetInputData(uGrids[i])
actors[i].SetMapper(mappers[i])
actors[i].GetProperty().SetColor(colors.GetColor3d('Tomato'))
actors[i].GetProperty().EdgeVisibilityOn()
actors[i].GetProperty().SetLineWidth(3)
actors[i].GetProperty().SetOpacity(.5)

textMappers[i].SetInput(titles[i])
textActors[i].SetMapper(textMappers[i])
textActors[i].SetPosition(50, 10)

# Label the points
labelMapper = vtkLabeledDataMapper()
labelMapper.SetInputData(uGrids[i])
labelActor = vtkActor2D()
labelActor.SetMapper(labelMapper)

# Glyph the points
pointMapper = vtkGlyph3DMapper()
pointMapper.SetInputData(uGrids[i])
pointMapper.SetSourceConnection(sphere.GetOutputPort())
pointMapper.ScalingOff()
pointMapper.ScalarVisibilityOff()

pointActor = vtkActor()
pointActor.SetMapper(pointMapper)
pointActor.GetProperty().SetDiffuseColor(colors.GetColor3d('Banana'))
pointActor.GetProperty().SetSpecular(.6)
pointActor.GetProperty().SetSpecularColor(1.0, 1.0, 1.0)
pointActor.GetProperty().SetSpecularPower(100)

# Setup the viewports
xGridDimensions = 4
yGridDimensions = 4
rendererSize = 240
renWin.SetSize(rendererSize * xGridDimensions, rendererSize * yGridDimensions)
for row in range(0, yGridDimensions):
for col in range(0, xGridDimensions):
index = row * xGridDimensions + col

# (xmin, ymin, xmax, ymax)
viewport = [float(col) / xGridDimensions,
float(yGridDimensions - (row + 1)) / yGridDimensions,
float(col + 1) / xGridDimensions,
float(yGridDimensions - row) / yGridDimensions]

if index > (len(actors) - 1):
# Add a renderer even if there is no actor.
# This makes the render window background all the same color.
ren = vtkRenderer()
ren.SetBackground(colors.GetColor3d('SlateGray'))
ren.SetViewport(viewport)
continue

renderers[index].SetViewport(viewport)
renderers[index].SetBackground(colors.GetColor3d('SlateGray'))
renderers[index].ResetCamera()
renderers[index].GetActiveCamera().Azimuth(30)
renderers[index].GetActiveCamera().Elevation(-30)
renderers[index].ResetCameraClippingRange()

iRen.Initialize()
renWin.Render()
iRen.Start()

# These functions return a vtkUnstructured grid corresponding to the object.

def MakeUnstructuredGrid(aCell):
pcoords = aCell.GetParametricCoords()
for i in range(0, aCell.GetNumberOfPoints()):
aCell.GetPointIds().SetId(i, i)
aCell.GetPoints().SetPoint(i, (pcoords[3 * i]), (pcoords[3 * i + 1]), (pcoords[3 * i + 2]))

ug = vtkUnstructuredGrid()
ug.SetPoints(aCell.GetPoints())
ug.InsertNextCell(aCell.GetCellType(), aCell.GetPointIds())
return ug

quadraticPolygon.GetPoints().SetPoint(0, 0.0, 0.0, 0.0)
quadraticPolygon.GetPoints().SetPoint(1, 2.0, 0.0, 0.0)
quadraticPolygon.GetPoints().SetPoint(2, 2.0, 2.0, 0.0)
quadraticPolygon.GetPoints().SetPoint(3, 0.0, 2.0, 0.0)
quadraticPolygon.GetPoints().SetPoint(4, 1.0, 0.0, 0.0)
quadraticPolygon.GetPoints().SetPoint(5, 2.0, 1.0, 0.0)
quadraticPolygon.GetPoints().SetPoint(6, 1.0, 2.0, 0.0)
quadraticPolygon.GetPoints().SetPoint(7, 0.0, 1.0, 0.0)
quadraticPolygon.GetPoints().SetPoint(5, 3.0, 1.0, 0.0)

ug = vtkUnstructuredGrid()