<html>
<head>
<meta content="text/html; charset=ISO-8859-1"
http-equiv="Content-Type">
</head>
<body bgcolor="#FFFFFF" text="#000000">
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.<br>
<br>
Wayne<br>
<br>
On 10/14/11 11:09 AM, Yifei Li wrote:
<blockquote
cite="mid:CA+Jsj7oP11_AHH_PY+PbHxmpHT2nk5Er5oyE_1RHtvoxTotOPQ@mail.gmail.com"
type="cite">Hi all,
<div><br>
</div>
<div>My application displays a mesh and adds annotation to its
elements (i.e., faces, edges and vertices).</div>
<div><br>
</div>
<div>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:</div>
<div><br>
</div>
<div>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Monaco">#
convert the coordinate of a cell center to display coordinate</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Monaco">world_coord
= self.m_faceCenters().GetOutput().GetPoint(k)</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Monaco">self.m_renderer.SetWorldPoint(world_coord[<span
style="color: #960606">0</span>], world_coord[<span
style="color: #960606">1</span>], world_coord[<span
style="color: #960606">2</span>], <span style="color:
#960606">1.0</span>)</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Monaco">self.m_renderer.WorldToDisplay()</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Monaco">x,
y, z = self.m_renderer.GetDisplayPoint()</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Monaco"><br>
</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Monaco">#
get the value in z-buffer at display coordinate (x,y)</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Monaco">
# the annotation should not be displayed if its associated
cell cannot be seen</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Monaco">#
in theory, a cell center is seen if its z coordinate after the
above conversion is less than or equal to the </p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Monaco">#
the value in the z-buffer at (x, y). </p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Monaco">#
However, due to the imprecise nature of floating-point
arithmetic, I relaxed the criteria by adding (z-z_in_buffer
<= <span style="color: rgb(150, 6, 6); ">1e</span>-<span
style="color: rgb(150, 6, 6); ">3)</span></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Monaco">z_in_buffer
= self.m_renderer.GetZ(x,y)</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Monaco"><span
style="color: #1e39f6">if</span> z <= z_in_buffer <span
style="color: #1e39f6">or</span> z-z_in_buffer <= <span
style="color: #960606">1e</span>-<span style="color:
#960606">3</span>:</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Monaco">
actor.SetPosition(x,y)</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Monaco"><font
class="Apple-style-span" color="#1e39f6"><br>
</font></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Monaco"><font
class="Apple-style-span" color="#1e39f6"><span
class="Apple-style-span" style="font-family: arial;
font-size: small; color: rgb(0, 0, 0); ">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</span></font></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Monaco"><font
class="Apple-style-span" color="#1e39f6"><span
class="Apple-style-span" style="font-family: arial;
font-size: small; color: rgb(0, 0, 0); "><br>
</span></font></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Monaco"><font
class="Apple-style-span" color="#1e39f6"><span
class="Apple-style-span" style="font-family: arial;
font-size: small; color: rgb(0, 0, 0); ">Yifei</span></font></p>
</div>
<br>
<fieldset class="mimeAttachmentHeader"></fieldset>
<br>
<pre wrap="">_______________________________________________
Powered by <a class="moz-txt-link-abbreviated" href="http://www.kitware.com">www.kitware.com</a>
Visit other Kitware open-source projects at <a class="moz-txt-link-freetext" href="http://www.kitware.com/opensource/opensource.html">http://www.kitware.com/opensource/opensource.html</a>
Please keep messages on-topic and check the VTK FAQ at: <a class="moz-txt-link-freetext" href="http://www.vtk.org/Wiki/VTK_FAQ">http://www.vtk.org/Wiki/VTK_FAQ</a>
Follow this link to subscribe/unsubscribe:
<a class="moz-txt-link-freetext" href="http://www.vtk.org/mailman/listinfo/vtkusers">http://www.vtk.org/mailman/listinfo/vtkusers</a>
</pre>
</blockquote>
</body>
</html>