[vtkusers] Problem visualizing an image gradient vector field

Dean Inglis dean.inglis at sympatico.ca
Wed Oct 18 09:15:19 EDT 2006


Hi Oscar,

if your original image is a 2D image, then you
have to set the gradient filter correctly (I think
it will do this for you automatically)

hgrd SetDimensionality 2

then try padding the gradient image with zeros:

vtkImageConstantPad pad
pad SetOutputNumberOfScalarComponents 3
pad SetOutputWholeExtent [ hgrd GetOutputWholeExtent ] 
pad SetConstant 0
pad SetInput [ hgrd GetOutput ]

this will give you a 3D vector field, 
so use a vtkArrowSource instead of a vtkGlyphSource2D:

vtkArrowSource arrow

vtkGlyph3D field
field SetInput [ ... whatever vector field you want ... ]
field SetSource [arrow GetOutput] 
field SetVectorModeToUseVector
field SetScaleModeToDataScalingOff
field OrientOn
field SetScaleFactor 0.05


HTH,
Dean



vtkImageGradient hgrd
   hgrd SetInput [ himg GetOutput ]
   hgrd SetDimensionality 3
   hgrd HandleBoundariesOn
vtkImageShrink3D hgsub
   hgsub SetInput [ hgrd GetOutput ]
   hgsub SetShrinkFactors 5 5 1
vtkAssignAttribute hg
   hg SetInput [ hgsub GetOutput ]
   hg Assign SCALARS VECTORS POINT_DATA
...
# building the glyph

vtkGlyphSource2D arrow
   arrow SetGlyphTypeToArrow
   arrow SetScale 0.2
vtkGlyph3D field
   field SetInput [ hg GetOutput ]
   field SetSource [ arrow GetOutput ]
   field ScalingOn
   field OrientOn
   field SetScaleFactor 0.05
...



More information about the vtkusers mailing list