[vtkusers] How to generate a surface normal glyph for a triangle cell

Elvis Dowson elvis.dowson at mac.com
Wed Oct 8 15:20:29 EDT 2008


Hi,
        What I can't seem to figure out is why the vtkPolyData object  
that is generated from vtkPolyDataNormals::GetOutput() is different  
from a manually constructed vtkPolyData object with the plane's  
surface normal? :-)  Can anyone please tell me?

Here is the code snippet

# Create a plane source
vtkPlaneSource planeSource

vtkPolyDataNormals planeNormals
   planeNormals SetInputConnection [planeSource GetOutputPort]

arrowGlyph SetInputConnection  [planeNormals GetOutputPort]

In the above code, a call to vtkPolyDataNormals::GetOutput() will give  
you a vtkPolyData object.

Now, shouldn't the following code snipped also generate a single  
surface normal vector?

# Specify the location of the glyph
vtkPolyData arrowGlyphPolyData
vtkPoints   arrowGlyphPoints
   arrowGlyphPolyData SetPoints arrowGlyphPoints
   eval arrowGlyphPoints InsertNextPoint [planeSource GetNormal]

However, when I run it,  arrowGlyph SetInputConnection  [planeNormals  
GetOutputPort]   give me the correct ouput with 4 surface normal  
glyphs at each vertex.


But, if I use arrowGlyph SetInput arrowGlyphPolyData, it gives me a  
surface normal glyph oriented the wrong way.



The full code can be found below. Note some parts are commented to  
switch the connection between the output of vtkPolyDataNormals and the  
manually constructed vtkPolyData for the 3D glyph for the surface  
normal vector. In the full code, the code is right now connected to  
the manually constructed vtkPolyData object.

Best regards,

Elvis Dowson


# This example shows how to manually construct a plane and display its  
surface normal
# using Tcl.
#

package require vtk
package require vtkinteraction

# Create a plane source
vtkPlaneSource planeSource

vtkPolyDataNormals planeNormals
   planeNormals SetInputConnection [planeSource GetOutputPort]

vtkDataSetMapper planeMapper
   planeMapper SetInputConnection [planeNormals GetOutputPort]

vtkActor planeActor
   planeActor SetMapper planeMapper

# Create an arrow glyph to represent the surface normal
# -----------------------------------------------------

# Specify the location of the glyph
vtkPolyData arrowGlyphPolyData
vtkPoints   arrowGlyphPoints
   arrowGlyphPolyData SetPoints arrowGlyphPoints
   #arrowGlyphPoints InsertNextPoint 1 1 0
   eval arrowGlyphPoints InsertNextPoint [planeSource GetNormal]

# 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]

   # Note: Uncomment the following line and comment the next line to  
connect to the output of vtkPolyDataNormals
   #arrowGlyph SetInputConnection  [planeNormals GetOutputPort]
   arrowGlyph SetInput arrowGlyphPolyData

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 planeActor
ren1 AddActor glyphActor

ren1 ResetCamera
ren1 ResetCameraClippingRange

renWin Render

# render the image
#
iren AddObserver UserEvent {wm deiconify .vtkInteract}
iren Initialize
wm withdraw .

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20081008/609d2a2c/attachment.htm>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: pastedGraphic.png
Type: image/png
Size: 28662 bytes
Desc: not available
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20081008/609d2a2c/attachment.png>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: pastedGraphic.png
Type: image/png
Size: 26980 bytes
Desc: not available
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20081008/609d2a2c/attachment-0001.png>


More information about the vtkusers mailing list