[vtkusers] How to extract poly data from an unstructured grid
Elvis Dowson
elvis.dowson at mac.com
Thu Oct 9 03:20:59 EDT 2008
Hi Frederic,
I want to retain the use of the unstructured
grid, for later purposes. The only reason I want to extract the poly
data from the unstructured grid is to compute the cell normals using
vtkPolyDataNormals, which has a method to compute cell normals.
I'm taking a look at vtkCellDataToPointData, but can't seem to get it
to work. When I run the program, the surface normal does not get
displayed for the triangle cell, plus I get the following error output
in the terminal window:
ERROR: In /Users/elvis/Tool/vtk-5.x/src/VTK/Filtering/
vtkDemandDrivenPipeline.cxx, line 722
vtkStreamingDemandDrivenPipeline (0x612fe70): Input port 0 of
algorithm vtkPolyDataNormals(0x612f870) has 0 connections but is not
optional.
Best regards,
Elvis Dowson
Example TCL code
# This example shows how to manually construct triangle cell using
unstructured grids
# and display its surface normal.
#
package require vtk
package require vtkinteraction
# Create an unstructured grids containing a triangle cell.
vtkPoints trianglePoints
trianglePoints SetNumberOfPoints 3
trianglePoints InsertPoint 0 0 0 0
trianglePoints InsertPoint 1 1 0 0
trianglePoints InsertPoint 2 .5 .5 0
vtkTriangle aTriangle
[aTriangle GetPointIds] SetId 0 0
[aTriangle GetPointIds] SetId 1 1
[aTriangle GetPointIds] SetId 2 2
vtkUnstructuredGrid aTriangleGrid
aTriangleGrid Allocate 1 1
aTriangleGrid InsertNextCell [aTriangle GetCellType] [aTriangle
GetPointIds]
aTriangleGrid SetPoints trianglePoints
vtkDataSetMapper aTriangleMapper
aTriangleMapper SetInput aTriangleGrid
vtkActor aTriangleActor
aTriangleActor SetMapper aTriangleMapper
aTriangleActor AddPosition 4 0 2
[aTriangleActor GetProperty] SetDiffuseColor .3 1 .5
# Create an arrow glyph to represent the surface normal for the
triangle cell.
# Specify the location of the glyph
vtkPolyData arrowGlyphPolyData
vtkPoints arrowGlyphPoints
arrowGlyphPolyData SetPoints arrowGlyphPoints
arrowGlyphPoints InsertNextPoint 1 1 0
vtkCellDataToPointData triangleCellToPolyData
triangleCellToPolyData SetInput aTriangleGrid
triangleCellToPolyData PassCellDataOff
# Question: Is this mapping necessary?
vtkPolyDataMapper trianglePolyData
trianglePolyData SetInput [triangleCellToPolyData GetPolyDataOutput]
vtkPolyDataNormals triangleCellNormals
# TODO: Fix this
triangleCellNormals SetInputConnection [trianglePolyData
GetOutputPort]
#triangleCellNormals SetInputConnection [triangleCellNormals
GetOutputPort]
#triangleCellNormals SetInput arrowGlyphPolyData
triangleCellNormals ComputePointNormalsOff
triangleCellNormals ComputeCellNormalsOn
# Specify the shape of the glyph
vtkArrowSource arrowSource
vtkGlyph3D arrowGlyph
arrowGlyph ScalingOn
arrowGlyph SetScaleFactor 0.7
arrowGlyph SetVectorModeToUseNormal
arrowGlyph SetScaleModeToScaleByVector
arrowGlyph OrientOn
arrowGlyph SetSourceConnection [arrowSource GetOutputPort]
arrowGlyph SetInputConnection [triangleCellNormals GetOutputPort]
vtkDataSetMapper arrowGlyphMapper
arrowGlyphMapper SetInputConnection [arrowGlyph GetOutputPort]
vtkActor glyphActor
glyphActor SetMapper arrowGlyphMapper
# Create the usual rendering stuff.
vtkRenderer ren1
vtkRenderWindow renWin
renWin AddRenderer ren1
renWin SetSize 300 150
vtkRenderWindowInteractor iren
iren SetRenderWindow renWin
ren1 SetBackground .1 .2 .4
ren1 AddActor aTriangleActor
ren1 AddActor glyphActor
ren1 ResetCamera
ren1 ResetCameraClippingRange
renWin Render
# render the image
#
iren AddObserver UserEvent {wm deiconify .vtkInteract}
iren Initialize
wm withdraw .
On Oct 9, 2008, at 10:49 AM, Frederic DANESI wrote:
> It should be easier if you build directly a polydata …
> # Create an unstructured grids containing a triangle cell.
> vtkPoints trianglePoints
> trianglePoints SetNumberOfPoints 3
> trianglePoints InsertPoint 0 0 0 0
> trianglePoints InsertPoint 1 1 0 0
> trianglePoints InsertPoint 2 .5 .5 0
> vtkTriangle aTriangle
> [aTriangle GetPointIds] SetId 0 0
> [aTriangle GetPointIds] SetId 1 1
> [aTriangle GetPointIds] SetId 2 2
> vtkPolyData aTrianglePoly
> aTrianglePoly Allocate 1 1
> aTrianglePoly InsertNextCell [aTriangle GetCellType] [aTriangle
> GetPointIds]
> aTrianglePoly SetPoints trianglePoints
>
> Fred.
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20081009/fd2ed812/attachment.htm>
More information about the vtkusers
mailing list