[vtkusers] Make 2D texts follow model

Yifei Li yifli82 at gmail.com
Fri Oct 14 14:09:42 EDT 2011


Hi all,

My application displays a mesh and adds annotation to its elements (i.e.,
faces, edges and vertices).

In order to make annotations follow the elements they are annotating, I
calculated the display coordinates of the cell centers and use those
coordinates to set the positions of annotation actors whenever the model is
rotated or the viewport is resized. For example:

# convert the coordinate of a cell center to display coordinate

world_coord = self.m_faceCenters().GetOutput().GetPoint(k)

self.m_renderer.SetWorldPoint(world_coord[0], world_coord[1], world_coord[2],
1.0)

self.m_renderer.WorldToDisplay()

x, y, z = self.m_renderer.GetDisplayPoint()


# get the value in z-buffer at display coordinate (x,y)

# the annotation should not be displayed if its associated cell cannot be
seen

# in theory, a cell center is seen if its z coordinate after the above
conversion is less than or equal to the

# the value in the z-buffer at (x, y).

# However, due to the imprecise nature of floating-point arithmetic, I
relaxed the criteria by adding (z-z_in_buffer <= 1e-3)

z_in_buffer = self.m_renderer.GetZ(x,y)

if z <= z_in_buffer or z-z_in_buffer <= 1e-3:

   actor.SetPosition(x,y)


My strategy of making 2D annotations follow model ALMOST works. However, the
annotations flickers when I rotate the model or resize the viewport, and I
found out the reason is that renderer.GetZ(x,y) sometimes returns 0!  Do you
have any idea why this happens? Thanks in advance


Yifei
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20111014/bcd586ab/attachment.htm>


More information about the vtkusers mailing list