# vtkTextProperty / vtkPointSetToLabelHierarchy offset strange behavior

**URL:** https://discourse.vtk.org/t/vtktextproperty-vtkpointsettolabelhierarchy-offset-strange-behavior/10092
**Category:** Support
**Tags:** code
**Created:** [December 6, 2022, 2:58pm UTC](https://discourse.vtk.org/t/vtktextproperty-vtkpointsettolabelhierarchy-offset-strange-behavior/10092 "2022-12-06T14:58:37Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![CharInt0](https://discourse.vtk.org/user_avatar/discourse.vtk.org/charint0/32/2983_2.png) [@CharInt0](https://discourse.vtk.org/u/CharInt0)
#### Post date: [December 6, 2022, 2:58pm UTC](https://discourse.vtk.org/t/vtktextproperty-vtkpointsettolabelhierarchy-offset-strange-behavior/10092/1 "2022-12-06T14:58:37Z")

</div>

Hi,  
(VTK 9.2.2, C++ language)  
I am trying to position some labels near some points at a distance using the class `vtkTextProperty` and `vtkPointSetToLabelHierarchy`, but I am obtaining unexpected results.

The `vtkTextProperty` documentation states:  
 ![image](https://discourse.vtk.org/uploads/default/original/2X/f/f57638cb5d33aab6029c4835fe40930db80a50b7.png)

I am not sure what cells refers to exactly, I suspect it does not apply to point set data.  
Whatever it means, the horizontal offset (CellOffset) has no effect on the labels positioning for point sets.

Vertically it works, for example whenever I set:

```auto
Justification = 1
VerticalJustification = 1
LineOffset = 80.0
CellOffset = 0.0

```

I am able to position the labels at a distance under the points:  
 ![image](https://discourse.vtk.org/uploads/default/original/2X/2/2603ea2de37bc265e59ff1363742e93c5ee4ff2e.png)  
and with:

```auto
Justification = 1
VerticalJustification = 2
LineOffset = -80.0
CellOffset = 0.0

```

I am able to position the labels above:  
 ![image](https://discourse.vtk.org/uploads/default/original/2X/4/484448fcf126e533cdb139ae956315395fdbbea4.png)

This works, even if the correct `VerticalJustification` values should be:

```auto
#define VTK_TEXT_BOTTOM 0
#define VTK_TEXT_TOP 2

```

but as you can see I am using the value:  
`#define VTK_TEXT_CENTERED 1`  
to set labels below, because if I set the value to 0 (Bottom) it does not work for whatever the offset.

So, is it possible to make it work horizontally too?

Thanks,  
C.

---

<div class="post-metadata">

### Author: ![CharInt0](https://discourse.vtk.org/user_avatar/discourse.vtk.org/charint0/32/2983_2.png) [@CharInt0](https://discourse.vtk.org/u/CharInt0)
#### Post date: [December 9, 2022, 10:13am UTC](https://discourse.vtk.org/t/vtktextproperty-vtkpointsettolabelhierarchy-offset-strange-behavior/10092/2 "2022-12-09T10:13:00Z")

</div>

Navigating through the source code

- file: vtkFreeTypeLabelRenderStrategy.cxx
- method:

```auto
  void vtkFreeTypeLabelRenderStrategy::ComputeLabelBounds(
    vtkTextProperty* tprop, vtkStdString label, double bds[4])

```

I see this:

```auto
  int bbox[4];
  this->TextRenderer->GetBoundingBox(copy, label, bbox, dpi);

  // Take line offset into account
  bds[0] = bbox[0];
  bds[1] = bbox[1];
  bds[2] = bbox[2] - tprop->GetLineOffset();
  bds[3] = bbox[3] - tprop->GetLineOffset();

  // Take justification into account
  double sz[2] = { bds[1] - bds[0], bds[3] - bds[2] };
  switch (tprop->GetJustification())
  {
    case VTK_TEXT_LEFT:
      break;
    case VTK_TEXT_CENTERED:
      bds[0] -= sz[0] / 2;
      bds[1] -= sz[0] / 2;
      break;
    case VTK_TEXT_RIGHT:
      bds[0] -= sz[0];
      bds[1] -= sz[0];
      break;
  }
  switch (tprop->GetVerticalJustification())
  {
    case VTK_TEXT_BOTTOM:
      break;
    case VTK_TEXT_CENTERED:
      bds[2] -= sz[1] / 2;
      bds[3] -= sz[1] / 2;
      break;
    case VTK_TEXT_TOP:
      bds[2] -= sz[1];
      bds[3] -= sz[1];
      break;
  }

```

So there is only the possibility to set an offset vertically and it is applied only when the VerticalJustification is set to TOP or CENTERED. This is consistent with my observations. Perhaps I will change the code to suit my needs and recompile the library.

---

<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: [December 9, 2022, 1:25pm UTC](https://discourse.vtk.org/t/vtktextproperty-vtkpointsettolabelhierarchy-offset-strange-behavior/10092/3 "2022-12-09T13:25:55Z")

</div>

Please also consider contributing back if you manage to solve some issues or make improvements that you think others could benefit from.

There are several incomplete and buggy features in label placement. Labeling developments seem to be abruptly stopped before it was completed (probably funding ran out). Even if nobody has the time to fully finish the work, It would be nice to at least fix small bugs and add small missing features.

---

<div class="post-metadata">

### Author: ![CharInt0](https://discourse.vtk.org/user_avatar/discourse.vtk.org/charint0/32/2983_2.png) [@CharInt0](https://discourse.vtk.org/u/CharInt0)
#### Post date: [December 12, 2022, 7:50am UTC](https://discourse.vtk.org/t/vtktextproperty-vtkpointsettolabelhierarchy-offset-strange-behavior/10092/4 "2022-12-12T07:50:12Z")

</div>

Andras, I will definitely consider it. Thanks for the info
