<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
<HTML>
<HEAD>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1">
<META NAME="Generator" CONTENT="MS Exchange Server version 6.5.7652.24">
<TITLE>RE: [vtkusers] best way to represent a (planar) irregular polygon ?</TITLE>
</HEAD>
<BODY>
<!-- Converted from text/plain format -->
<BR>
<P><FONT SIZE=2>Hello vtkusers,<BR>
<BR>
I have been having a similar problem rendering a cube made up of four smaller cubes.<BR>
<BR>
I would like to be able to visualise the interior nodes but they disappear<BR>
depending on the degree of the vertex. I have included a sample screen shot.<BR>
<BR>
What I want to eventually do is extract the edges to a TubeFilter and color<BR>
the tubes depending on some scalar values, but I always only get the exterior<BR>
lines.<BR>
<BR>
Also I will eventually need to visualise tetrahedra within a surface.<BR>
<BR>
My current pipeline looks like:<BR>
<BR>
reader = vtkUnstructuredGridReader()<BR>
reader.SetFileName(uginput)<BR>
<BR>
geoFil = new vtkGeometryFilter()<BR>
geoFil.SetInput(reader.GetOutput())<BR>
<BR>
triFil = new vtkTriangleFilter()<BR>
triFil.SetInput(geoFil.GetOutput())<BR>
<BR>
gridMapper = vtkDataSetMapper()<BR>
gridMapper.SetInput(triFil.GetOutput())<BR>
<BR>
gridActor = vtkActor()<BR>
gridActor.SetMapper(gridMapper)<BR>
<BR>
thanks for your time,<BR>
<BR>
Henrik<BR>
<BR>
<BR>
-----Original Message-----<BR>
From: vtkusers-bounces@vtk.org on behalf of Marie-Gabrielle Vallet<BR>
Sent: Fri 5/30/2008 9:21 PM<BR>
To: briand@aracnet.com<BR>
Cc: vtkusers@vtk.org<BR>
Subject: Re: [vtkusers] best way to represent a (planar) irregular polygon ?<BR>
<BR>
Hi Brian,<BR>
I remember having some problem to render a non-convex polygon. I found an<BR>
example, I can't find again where it comes from, and I worked on it. Finally<BR>
the following python script does what you want.<BR>
<BR>
You should try to add two filters : a GeometryFilter and a TriangleFilter.<BR>
Marie-Gabrielle<BR>
<BR>
#!/usr/bin/env python<BR>
<BR>
# This example shows how to visualize polygons, convex or not.<BR>
<BR>
import vtk<BR>
<BR>
# Define a set of points - these are the ordered polygon vertices<BR>
polygonPoints = vtk.vtkPoints()<BR>
polygonPoints.SetNumberOfPoints(6)<BR>
polygonPoints.InsertPoint(0, 0, 0, 0)<BR>
polygonPoints.InsertPoint(1,.4,.4, 0)<BR>
polygonPoints.InsertPoint(2, 1, 0, 0)<BR>
polygonPoints.InsertPoint(3, 1, 1, 0)<BR>
polygonPoints.InsertPoint(4,.1,.7, 0)<BR>
polygonPoints.InsertPoint(5, 0, 1, 0)<BR>
<BR>
# Make a cell with these points<BR>
aPolygon = vtk.vtkPolygon()<BR>
aPolygon.GetPointIds().SetNumberOfIds(6)<BR>
aPolygon.GetPointIds().SetId(0, 0)<BR>
aPolygon.GetPointIds().SetId(1, 1)<BR>
aPolygon.GetPointIds().SetId(2, 2)<BR>
aPolygon.GetPointIds().SetId(3, 3)<BR>
aPolygon.GetPointIds().SetId(4, 4)<BR>
aPolygon.GetPointIds().SetId(5, 5)<BR>
<BR>
# The cell is put into a mesh (containing only one cell)<BR>
aPolygonGrid = vtk.vtkUnstructuredGrid()<BR>
aPolygonGrid.Allocate(1, 1)<BR>
aPolygonGrid.InsertNextCell(aPolygon.GetCellType(), aPolygon.GetPointIds())<BR>
aPolygonGrid.SetPoints(polygonPoints)<BR>
<BR>
# This part is needed for non-convex polygon rendering<BR>
aPolygonGeomFilter = vtk.vtkGeometryFilter()<BR>
aPolygonGeomFilter.SetInput(aPolygonGrid)<BR>
aPolygonTriangleFilter = vtk.vtkTriangleFilter()<BR>
aPolygonTriangleFilter.SetInput(aPolygonGeomFilter.GetOutput())<BR>
#<BR>
# This one is only to check the triangulation (when factor < 1)<BR>
aPolygonShrinkFilter = vtk.vtkShrinkFilter()<BR>
aPolygonShrinkFilter.SetShrinkFactor( 0.9 )<BR>
#aPolygonShrinkFilter.SetShrinkFactor( 1.0 )<BR>
aPolygonShrinkFilter.SetInput( aPolygonGrid)<BR>
<BR>
# Make ready for rendering<BR>
aPolygonMapper = vtk.vtkDataSetMapper()<BR>
aPolygonMapper.SetInput(aPolygonShrinkFilter.GetOutput())<BR>
aPolygonActor = vtk.vtkActor()<BR>
aPolygonActor.SetMapper(aPolygonMapper)<BR>
aPolygonActor.GetProperty().SetDiffuseColor(1, .4, .5)<BR>
<BR>
# Create the usual rendering stuff.<BR>
ren = vtk.vtkRenderer()<BR>
renWin = vtk.vtkRenderWindow()<BR>
renWin.AddRenderer(ren)<BR>
renWin.SetSize(300, 150)<BR>
iren = vtk.vtkRenderWindowInteractor()<BR>
iren.SetRenderWindow(renWin)<BR>
<BR>
ren.SetBackground(.1, .2, .4)<BR>
ren.AddActor(aPolygonActor)<BR>
ren.ResetCamera()<BR>
<BR>
# Render the scene and start interaction.<BR>
iren.Initialize()<BR>
renWin.Render()<BR>
iren.Start()<BR>
<BR>
<BR>
<BR>
</FONT>
</P>
</BODY>
</HTML>