[vtkusers] Problem visualizing an image gradient vector field -> using vtkAssignAttribute
Oscar Yañez Suarez
yaso at xanum.uam.mx
Thu Oct 19 05:01:54 EDT 2006
Ok, so I've solved this problem thanks to Dean's help and further
investigation. I post this to the list in case it helps anyone else.
1) First of all, using vtkImageGradient on a 2D image with
SetDimensionality( 3 ) correctly yields a three-component Scalars, and
the third component, which I thought initially would be a constant
zero value (as theory indicates) is actually a constant nan. So, doing
a SetDimensionality( 2 ) and padding the third component with zeros as
Dean suggested is the way to get the correct 3D vector field, although
still in the wrong place for visualization using glyphs (in Scalars
instead of Vectors).
2) To overcome the Scalars/Vectors thing I tried using a vtkAssignAttribute:
vtkAssignAttribute aa
aa SetInput [ hgrds GetOutput ]
aa Assign SCALARS VECTORS POINT_DATA
but that always outputs an object with no Vectors array. I have no
idea of why this doesn't work. So, I did it in a nasty way, modifying
by brute force the Vectors array where needed:
vtkImageGradient hgrd
hgrd SetInput [ himg GetOutput ]
hgrd SetDimensionality 2
hgrd HandleBoundariesOn
vtkImageConstantPad hgrd3
hgrd3 SetOutputNumberOfScalarComponents 3
hgrd3 SetConstant 0
hgrd3 SetInput [ hgrd GetOutput ]
vtkImageShrink3D hgrds
hgrds SetInput [ hgrd3 GetOutput ]
hgrds SetShrinkFactors 4 4 1
hgrds Update
set arr [ [ [ hgrds GetOutput ] GetPointData ] GetScalars ]
[ [ hgrds GetOutput ] GetPointData ] SetVectors $arr
and this yields an hgrds output with a Vectors array equal to the
Scalars array. Of course, if anything gets updated upstream, the
Vectors array is not changed =(. This was the whole point of
vtkAssignAttribute. Maybe I am not using it correctly ....
So, time to move on ...
--
Oscar Yanez Suarez
Laboratorio de Neuroimagenologia
Departamento de Ingenieria Electrica
UAM - Iztapalapa
http://docencia.izt.uam.mx/oys
More information about the vtkusers
mailing list