[vtkusers] Make 2D texts follow model

Wayne Christopher wayne at 4raccoons.com
Fri Oct 14 14:13:31 EDT 2011


What you want is a vtkCaptionActor2D.  You give it a point in world 
coordinates and it will make a text actor that will follow that point.

     Wayne

On 10/14/11 11:09 AM, Yifei Li wrote:
> 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
>
>
>
> _______________________________________________
> Powered by www.kitware.com
>
> Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html
>
> Please keep messages on-topic and check the VTK FAQ at: http://www.vtk.org/Wiki/VTK_FAQ
>
> Follow this link to subscribe/unsubscribe:
> http://www.vtk.org/mailman/listinfo/vtkusers
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20111014/cfb86419/attachment.htm>


More information about the vtkusers mailing list