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

Amy Squillacote ahs at cfdrc.com
Wed Jun 4 10:03:02 EDT 2008


Henrik,

If you want to extract the edges of your unstructured grid dataset, you 
don't need a geometry filter or a triangle filter. (The geometry filter 
is the reason you're not seeing interior points; for 3D cells, it 
extracts the 2D faces used by only one 3D cells. This works out to be 
the boundary faces. This is described in the online documentation for 
this class: 
http://www.vtk.org/doc/nightly/html/classvtkGeometryFilter.html.) To put 
tubes around the edges in your dataset, set up a pipeline like the 
following (shown in c++)

vtkUnstructuredGridReader *reader = vtkUnstructuredGridReader::New();
... set up the rest of the reader's parameters ...

vtkExtractEdges *edges = vtkExtractEdges::New();
edges->SetInputConnection(reader->GetOutputPort());
... set up the rest of this filter's parameters ...

vtkTubeFilter *tubes = vtkTubeFilter::New();
tubes->SetInputConnection(tubes->GetOutputPort());
... set up the rest of this filter's parameters ...

vtkPolyDataMapper *mapper = vtkPolyDataMapper::New();
mapper->SetInputConnection(tubes->GetOutputPort());
...

vtkActor *actor = vtkActor::New();
actor->SetMapper(mapper);
...

- Amy

Marie-Gabrielle Vallet wrote:
> Henrik,
>
> That's not a similar problem. A polygon is a surface, discretized with 
> triangles. For a non-convex polygon, the triangles have to be filtered 
> before rendering, to correct their orientation I guess.
>
> Your grid is volumetric. There is no triangle to filter. I don't know 
> how to visualise your grid inside. And I'm not sure you want to see 
> all these lines.
>
> A TubeFilter generates a surface around a line. There is nothing 
> inside. You can cap both ends. But you can only see the exterior 
> surface because their is no volume.
>
> Marie-Gabrielle Vallet
>
> 2008/6/4 Henrik Westerberg <henrik.westerberg at crg.es 
> <mailto:henrik.westerberg at crg.es>>:
>
>
>     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 <mailto:vtkusers-bounces at vtk.org>
>     on behalf of Marie-Gabrielle Vallet
>     Sent: Fri 5/30/2008 9:21 PM
>     To: briand at aracnet.com <mailto:briand at aracnet.com>
>     Cc: vtkusers at vtk.org <mailto: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()
>
>
>
>
> ------------------------------------------------------------------------
>
> _______________________________________________
> This is the private VTK discussion list.
> Please keep messages on-topic. Check the FAQ at: http://www.vtk.org/Wiki/VTK_FAQ
> Follow this link to subscribe/unsubscribe:
> http://www.vtk.org/mailman/listinfo/vtkusers
>   

-- 
Amy Squillacote                    Phone: (256) 726-4839
Computer Scientist                 Fax: (256) 726-4806
CFD Research Corporation           Web: http://www.cfdrc.com
215 Wynn Drive, Suite 501
Huntsville, AL  35805





More information about the vtkusers mailing list