[vtkusers] best way to represent a (planar) irregular polygon ?

Henrik Westerberg henrik.westerberg at crg.es
Wed Jun 4 06:18:39 EDT 2008


Hello vtkusers,

I have been having a similar problem rendering a cube made up of four smaller cubes.

I would like to be able to visualise the interior nodes but they disappear
depending on the degree of the vertex. I have included a sample screen shot.

What I want to eventually do is extract the edges to a TubeFilter and color
the tubes depending on some scalar values, but I always only get the exterior
lines.

Also I will eventually need to visualise tetrahedra within a surface.

My current pipeline looks like:

reader = vtkUnstructuredGridReader()
reader.SetFileName(uginput)

geoFil = new vtkGeometryFilter()
geoFil.SetInput(reader.GetOutput())

triFil = new vtkTriangleFilter()
triFil.SetInput(geoFil.GetOutput())

gridMapper = vtkDataSetMapper()
gridMapper.SetInput(triFil.GetOutput())

gridActor = vtkActor()
gridActor.SetMapper(gridMapper)

thanks for your time,

Henrik


-----Original Message-----
From: vtkusers-bounces at vtk.org on behalf of Marie-Gabrielle Vallet
Sent: Fri 5/30/2008 9:21 PM
To: briand at aracnet.com
Cc: vtkusers at vtk.org
Subject: Re: [vtkusers] best way to represent a (planar) irregular polygon ?
 
Hi Brian,
I remember having some problem to render a non-convex polygon. I found an
example, I can't find again where it comes from, and I worked on it. Finally
the following python script does what you want.

You should try to add two filters : a GeometryFilter and a TriangleFilter.
Marie-Gabrielle

 #!/usr/bin/env python

 # This example shows how to visualize polygons, convex or not.

 import vtk

 # Define a set of points - these are the ordered polygon vertices
 polygonPoints = vtk.vtkPoints()
 polygonPoints.SetNumberOfPoints(6)
 polygonPoints.InsertPoint(0, 0, 0, 0)
 polygonPoints.InsertPoint(1,.4,.4, 0)
 polygonPoints.InsertPoint(2, 1, 0, 0)
 polygonPoints.InsertPoint(3, 1, 1, 0)
 polygonPoints.InsertPoint(4,.1,.7, 0)
 polygonPoints.InsertPoint(5, 0, 1, 0)

 # Make a cell with these points
 aPolygon = vtk.vtkPolygon()
 aPolygon.GetPointIds().SetNumberOfIds(6)
 aPolygon.GetPointIds().SetId(0, 0)
 aPolygon.GetPointIds().SetId(1, 1)
 aPolygon.GetPointIds().SetId(2, 2)
 aPolygon.GetPointIds().SetId(3, 3)
 aPolygon.GetPointIds().SetId(4, 4)
 aPolygon.GetPointIds().SetId(5, 5)

 # The cell is put into a mesh (containing only one cell)
 aPolygonGrid = vtk.vtkUnstructuredGrid()
 aPolygonGrid.Allocate(1, 1)
 aPolygonGrid.InsertNextCell(aPolygon.GetCellType(), aPolygon.GetPointIds())
 aPolygonGrid.SetPoints(polygonPoints)

 # This part is needed for non-convex polygon rendering
 aPolygonGeomFilter = vtk.vtkGeometryFilter()
 aPolygonGeomFilter.SetInput(aPolygonGrid)
 aPolygonTriangleFilter = vtk.vtkTriangleFilter()
 aPolygonTriangleFilter.SetInput(aPolygonGeomFilter.GetOutput())
 #
 # This one is only to check the triangulation (when factor < 1)
 aPolygonShrinkFilter = vtk.vtkShrinkFilter()
 aPolygonShrinkFilter.SetShrinkFactor( 0.9 )
 #aPolygonShrinkFilter.SetShrinkFactor( 1.0 )
 aPolygonShrinkFilter.SetInput( aPolygonGrid)

 # Make ready for rendering
 aPolygonMapper = vtk.vtkDataSetMapper()
 aPolygonMapper.SetInput(aPolygonShrinkFilter.GetOutput())
 aPolygonActor = vtk.vtkActor()
 aPolygonActor.SetMapper(aPolygonMapper)
 aPolygonActor.GetProperty().SetDiffuseColor(1, .4, .5)

 # Create the usual rendering stuff.
 ren = vtk.vtkRenderer()
 renWin = vtk.vtkRenderWindow()
 renWin.AddRenderer(ren)
 renWin.SetSize(300, 150)
 iren = vtk.vtkRenderWindowInteractor()
 iren.SetRenderWindow(renWin)

 ren.SetBackground(.1, .2, .4)
 ren.AddActor(aPolygonActor)
 ren.ResetCamera()

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



-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20080604/c5486b6d/attachment.htm>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: cube.jpg
Type: image/jpeg
Size: 32577 bytes
Desc: cube.jpg
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20080604/c5486b6d/attachment.jpg>


More information about the vtkusers mailing list