# vtkCaptionActor2D and the size of Leader glyph

**URL:** https://discourse.vtk.org/t/vtkcaptionactor2d-and-the-size-of-leader-glyph/13721
**Category:** Support
**Tags:** code
**Created:** [April 16, 2024, 3:04pm UTC](https://discourse.vtk.org/t/vtkcaptionactor2d-and-the-size-of-leader-glyph/13721 "2024-04-16T15:04:59Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![codeling](https://discourse.vtk.org/user_avatar/discourse.vtk.org/codeling/32/3792_2.png) [@codeling](https://discourse.vtk.org/u/codeling)
#### Post date: [April 16, 2024, 3:04pm UTC](https://discourse.vtk.org/t/vtkcaptionactor2d-and-the-size-of-leader-glyph/13721/1 "2024-04-16T15:04:59Z")

</div>

I am using vtkCaptionActor2D to create an annotation on a volume dataset; I liked the idea of the “leader glyph”, and played around with it a bit, but could not get the automatic sizing working for my case: when setting the camera rather close to the attachment point, the leader glyph is extremely small, and therefore not visible:

 ![grafik](https://discourse.vtk.org/uploads/default/original/2X/d/db368cfab1cc1488f0d394d65f5d33e0aded7e90.jpeg)

only when zooming out a lot, I see the glyph:

 ![grafik](https://discourse.vtk.org/uploads/default/original/2X/d/d372691584f879ad15bbecbcb3c34ec756a69803.png)

My code (sorry that it’s not a full MWE at the moment, I did not yet have time to prepare one):

```auto
	vtkNew<vtkCaptionActor2D> capAct;
	capAct->SetCaption("Annotation 0");
	vtkNew<vtkArrowSource> leaderGlyphSource;
	leaderGlyphSource->SetShaftRadius(0.2);
	leaderGlyphSource->SetTipRadius(0.5);
	leaderGlyphSource->SetTipLength(0.6);
	leaderGlyphSource->Update();
	
	capAct->SetLeaderGlyphConnection(leaderGlyphSource->GetOutputPort());
	capAct->SetLeaderGlyphSize(1);
	capAct->SetMaximumLeaderGlyphSize(30.0);
	...

```

Am I doing something weird here?

When looking at [the size adaptation code](https://gitlab.kitware.com/vtk/vtk/-/blob/master/Rendering/Annotation/vtkCaptionActor2D.cxx?ref_type=heads#L435-464), I found it peculiar that the code just takes the middle display point and computes the distance of 1 pixel in world coordinates.  
On a hunch, I took the attachment point instead, converted that to display coordinates, add +1 in x and y direction and converted it back, and used that distance for scale factor creation:

```auto
    auto p1 = this->AttachmentPointCoordinate->GetComputedWorldValue(viewport);
    // get world coordinates of point 1 pixel away from attach point:
    viewport->SetWorldPoint(p1[0], p1[1], p1[2], 1.0);
    viewport->WorldToDisplay();
    double dispPt[4];
    viewport->GetDisplayPoint(dispPt);
    dispPt[0] = dispPt[0] + 1;
    dispPt[1] = dispPt[1] + 1;
    viewport->SetDisplayPoint(dispPt);
    viewport->DisplayToWorld();
    double p2[4];
    viewport->GetWorldPoint(p2);
    if (p2[3] != 0.0)
    {
        p2[0] /= p2[3];
        p2[1] /= p2[3];
        p2[2] /= p2[3];
    }

```

Now it looks as expected - the leader glyph stays roughly the same when resized:

 ![grafik](https://discourse.vtk.org/uploads/default/original/2X/3/36eebaf1e3ac1f56aa69e3e49d91a1753f3b292e.jpeg)

Also regarding the “arbitrary” factor of 1.5 factor - I think a “more correct” value there would be the square root of 2 as the diagonal length of a unit cube?

Another minor nitpick: I find the name [`LeaderGlyphSize`](https://vtk.org/doc/nightly/html/classvtkCaptionActor2D.html#ab3b3ed4cf9914a17d3f1a9cdfca6946b) confusing - since, as specified in the doc, it is not a size, but a factor to the size of the glyph itself.

---

<div class="post-metadata">

### Author: ![codeling](https://discourse.vtk.org/user_avatar/discourse.vtk.org/codeling/32/3792_2.png) [@codeling](https://discourse.vtk.org/u/codeling)
#### Post date: [January 14, 2025, 11:26am UTC](https://discourse.vtk.org/t/vtkcaptionactor2d-and-the-size-of-leader-glyph/13721/2 "2025-01-14T11:26:20Z")

</div>

Anybody working with vtk’s text annotations who could chime in?

---

<div class="post-metadata">

### Author: ![codeling](https://discourse.vtk.org/user_avatar/discourse.vtk.org/codeling/32/3792_2.png) [@codeling](https://discourse.vtk.org/u/codeling)
#### Post date: [January 22, 2025, 4:28pm UTC](https://discourse.vtk.org/t/vtkcaptionactor2d-and-the-size-of-leader-glyph/13721/3 "2025-01-22T16:28:05Z")

</div>

The behavior I describe is actually visible [in the vtkCaptionWidget example](https://examples.vtk.org/site/Cxx/Widgets/CaptionWidget/) as well - zoom in there, and you will see the leader glyph (the arrow) get so small that it basically disappears (since vtkCaptionWidget internally uses vtkCaptionActor2D, vtkCaptionWidget is directly affected by this behavior).

I have [prepared a pull request with the changes proposed above](https://gitlab.kitware.com/vtk/vtk/-/merge_requests/11866), to fix the leader glyph size computation.
