# centering (justification/alignment) of vtkFollower text

**URL:** https://discourse.vtk.org/t/centering-justification-alignment-of-vtkfollower-text/1632
**Category:** Support
**Created:** [August 21, 2019, 3:02pm UTC](https://discourse.vtk.org/t/centering-justification-alignment-of-vtkfollower-text/1632 "2019-08-21T15:02:07Z")
**Posts on this page:** 9
**Page:** 1

<div class="post-metadata">

### Author: ![dmgroppe](https://discourse.vtk.org/user_avatar/discourse.vtk.org/dmgroppe/32/25_2.png) [@dmgroppe](https://discourse.vtk.org/u/dmgroppe)
#### Post date: [August 21, 2019, 3:02pm UTC](https://discourse.vtk.org/t/centering-justification-alignment-of-vtkfollower-text/1632/1 "2019-08-21T15:02:07Z")

</div>

Hi all, I’m trying to use vtkFollower ([https://vtk.org/Wiki/VTK/Examples/Cxx/Visualization/Follower](https://vtk.org/Wiki/VTK/Examples/Cxx/Visualization/Follower)) to render text that labels a point in 3D space. The text appears slightly above and to the right of the point (i.e., the origin of text appears to be the lower, left corner of the text).

Is there a way to center the vtkFollower text on the point? There don’t appear to be any obvious methods for this.

```
  much thanks,
       -David
```

---

<div class="post-metadata">

### Author: ![allison.vacanti](https://discourse.vtk.org/user_avatar/discourse.vtk.org/allison.vacanti/32/679_2.png) [@allison.vacanti](https://discourse.vtk.org/u/allison.vacanti)
#### Post date: [August 22, 2019, 2:42am UTC](https://discourse.vtk.org/t/centering-justification-alignment-of-vtkfollower-text/1632/2 "2019-08-22T02:42:54Z")

</div>

The `vtkFollower` and `vtkVectorText` approach does not offer many controls for text placement. It’s sort of a relic from a time before we had access to actual text rendering in VTK.

The better way to render 3D embedded text is to use [`vtkBillboardTextActor3D`](https://vtk.org/doc/nightly/html/classvtkBillboardTextActor3D.html). It renders at a fixed size on screen and remains oriented toward the camera. It also provides a lot of customization options (including justification) via it’s `vtkTextProperty`.

---

<div class="post-metadata">

### Author: ![dmgroppe](https://discourse.vtk.org/user_avatar/discourse.vtk.org/dmgroppe/32/25_2.png) [@dmgroppe](https://discourse.vtk.org/u/dmgroppe)
#### Post date: [August 27, 2019, 7:52pm UTC](https://discourse.vtk.org/t/centering-justification-alignment-of-vtkfollower-text/1632/3 "2019-08-27T19:52:04Z")

</div>

Thanks very much, Alison! However, it appears that vtkBillboardTextActor3D has some issues with occlusion when using it with raycasting:

> [@vtkBillboardTextActor3D text always renders behind raycast volume](https://discourse.vtk.org/t/vtkbillboardtextactor3d-text-always-renders-behind-raycast-volume/983/2):
>
> Displaying labels correctly is extremely difficult. I’ve spent a lot of time experimenting with different options for markup display in 3D Slicer, but each option has different limitations. To tackle occlusion: To make sure the labels are not occluded, you can display 3D label actors on a separate layer or use 2D actors. However, then you need to manually hide the actors when the corresponding point of interest is occluded. In general, determining if a certain point is occluded is a very costly…

@lassoan, I like your suggestion of using vtkLabelPlacementMapper, but I can’t figure out how to control the size of the text or its alignment/justification.

---

<div class="post-metadata">

### Author: ![allison.vacanti](https://discourse.vtk.org/user_avatar/discourse.vtk.org/allison.vacanti/32/679_2.png) [@allison.vacanti](https://discourse.vtk.org/u/allison.vacanti)
#### Post date: [August 27, 2019, 8:06pm UTC](https://discourse.vtk.org/t/centering-justification-alignment-of-vtkfollower-text/1632/4 "2019-08-27T20:06:01Z")

</div>

It doesn’t look like `vtkLabelPlacementMapper` offers as much control over text rendering.

If just rendering the labels on top of the 3D geometry is an option, you may want to look at `vtkTextActor`, since it renders in the overlay plane (similar to `vtkLabelPlacementMapper`).

By default, it uses viewport (pixel) coordinates to specify location, but you can set it up to align with a 3D world location via `textActor->GetPositionCoordinate()->SetCoordinateSystemToWorld()`. This will anchor it to a 3D position in your scene, but it will always render on top of all 3D geometry in the current renderer layer.

---

<div class="post-metadata">

### Author: ![dmgroppe](https://discourse.vtk.org/user_avatar/discourse.vtk.org/dmgroppe/32/25_2.png) [@dmgroppe](https://discourse.vtk.org/u/dmgroppe)
#### Post date: [August 28, 2019, 1:40pm UTC](https://discourse.vtk.org/t/centering-justification-alignment-of-vtkfollower-text/1632/5 "2019-08-28T13:40:54Z")

</div>

> [@allison.vacanti](#):
>
> It doesn’t look like `vtkLabelPlacementMapper` offers as much control over text rendering.
> 
> If just rendering the labels on top of the 3D geometry is an option, you may want to look at `vtkTextActor` , since it renders in the overlay plane (similar to `vtkLabelPlacementMapper` ).
> 
> By default, it uses viewport (pixel) coordinates to specify location, but you can set it up to align with a 3D world location via `textActor->GetPositionCoordinate()->SetCoordinateSystemToWorld()` . This will anchor it to a 3D position in your scene, but it will always render on top of all 3D geometry in the current renderer layer.

Thanks very much, Allison. I’ll give that a shot.

---

<div class="post-metadata">

### Author: ![dmgroppe](https://discourse.vtk.org/user_avatar/discourse.vtk.org/dmgroppe/32/25_2.png) [@dmgroppe](https://discourse.vtk.org/u/dmgroppe)
#### Post date: [September 9, 2019, 8:09pm UTC](https://discourse.vtk.org/t/centering-justification-alignment-of-vtkfollower-text/1632/6 "2019-09-09T20:09:29Z")

</div>

Hi @allison.vacanti, Thanks again for the tip. Using world coordinates works great, but I have a new problem. Specifically, some of the text corresponds to points that are obscured by other voxels, but the text is always visible, which creates a lot of visual clutter. I’d like to only render text for points that are visible to the viewer.

Does anyone know if it is possible to get the accumulated opacity value of a point in a raycast volume so that I could know how visible that point is?

---

<div class="post-metadata">

### Author: ![allison.vacanti](https://discourse.vtk.org/user_avatar/discourse.vtk.org/allison.vacanti/32/679_2.png) [@allison.vacanti](https://discourse.vtk.org/u/allison.vacanti)
#### Post date: [September 9, 2019, 8:20pm UTC](https://discourse.vtk.org/t/centering-justification-alignment-of-vtkfollower-text/1632/7 "2019-09-09T20:20:16Z")

</div>

The typical way to do this would be [`vtkSelectVisiblePoints`](https://vtk.org/doc/nightly/html/classvtkSelectVisiblePoints.html) to filter out points that would be obscured. I’m not sure it’d work with a volume or if it only works with polygonal geometry…

From the thread you linked earlier, it sounds like @lassoan might have gotten it to work with a volume, so it should be worth a try.

---

<div class="post-metadata">

### Author: ![lassoan](https://discourse.vtk.org/user_avatar/discourse.vtk.org/lassoan/32/50_2.png) [@lassoan](https://discourse.vtk.org/u/lassoan)
#### Post date: [September 10, 2019, 3:26am UTC](https://discourse.vtk.org/t/centering-justification-alignment-of-vtkfollower-text/1632/8 "2019-09-10T03:26:25Z")

</div>

Most things work with volume rendering (point placing, picking, occlusion of glyph widget by the volume), however hiding of labels occluded by a rendered volume does not work.

vtkSelectVisiblePoints filter uses the Z buffer and as far as I know VTK does not write into Z buffer in translucent rendering step. Maybe the volume render mapper could be updated to write into the z buffer the distance where the ray reaches 1.0 opacity?

---

<div class="post-metadata">

### Author: ![dmgroppe](https://discourse.vtk.org/user_avatar/discourse.vtk.org/dmgroppe/32/25_2.png) [@dmgroppe](https://discourse.vtk.org/u/dmgroppe)
#### Post date: [September 10, 2019, 7:43pm UTC](https://discourse.vtk.org/t/centering-justification-alignment-of-vtkfollower-text/1632/9 "2019-09-10T19:43:06Z")

</div>

> [@allison.vacanti](#):
>
> By default, it uses viewport (pixel) coordinates to specify location, but you can set it up to align with a 3D world location via `textActor->GetPositionCoordinate()->SetCoordinateSystemToWorld()` . This will anchor it to a 3D position in your scene, but it will always render on top of all 3D geometry in the current renderer layer.

Thanks very much @allison.vacanti and @lassoan. I’ll look into it.
