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>