[vtkusers] normal of a point or cell

David Gobbi dgobbi at irus.rri.on.ca
Fri Dec 15 15:54:41 EST 2000


On Fri, 15 Dec 2000, Chris Tsui wrote:

> Dear All,
> 
> I posted this question few days ago...  getting no reply..  I guess this 
> is kind of stupid that no one would bother to answer..  but I am still 
> struggling with this problem..  anyways.. here's my question again :
> 
> - I would like to get the normal whenever I click on the surface of the 
> mesh I have..  I can get the cell id or the world coordinates without 
> problem..  what I am struggling with is how to retrieve the normal of a 
> specific cell??  any idea?? 
> 
> your help would be greatly appreciated.
> 
> Regards,
> 
> Chris.

I'll give it a shot.  Here is the code that we have for doing this,
assuming you have the picked actor and the pick location in world
coordinates (the code is in Python)

# get the data
dataSet = actor.GetMapper().GetInput()

# convert coordinate from world coords to data coords
transform = vtkTransform()
transform.SetMatrix(actor.GetMatrix())    # or use 'GetMatrixPointer'
dcoord = transform.GetInverse().TransformPoint(coord)

# find the point associated with the world coordinate
pointId = dataSet.FindPoint(dcoord[0],dcoord[1],dcoord[2])

# get the normal
dnormal = dataSet.GetPointData().GetNormals().GetNormal(pointId)

# convert the normal to world coordinates
normal = transform.TransformNormal(dnormal)

This assumes that your data has a normal associated with each point,
you can pre-compute the point normals by applying the vtkPolyDataNormals
filter to your data if the data doesn't already have normals.

Hope this helps.  There are probably other ways to do this, too.  Also
note that this method does no interpolation between polygonal vertices.

 - David

--
  David Gobbi, MSc                    dgobbi at irus.rri.on.ca
  Advanced Imaging Research Group
  Robarts Research Institute, University of Western Ontario





More information about the vtkusers mailing list