# Wrong label positions with vtkLabelPlacementMapper

**URL:** https://discourse.vtk.org/t/wrong-label-positions-with-vtklabelplacementmapper/10043
**Category:** Support
**Created:** [December 2, 2022, 9:07am UTC](https://discourse.vtk.org/t/wrong-label-positions-with-vtklabelplacementmapper/10043 "2022-12-02T09:07:01Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![Peter](https://discourse.vtk.org/user_avatar/discourse.vtk.org/peter/32/3487_2.png) [@Peter](https://discourse.vtk.org/u/Peter)
#### Post date: [December 2, 2022, 9:07am UTC](https://discourse.vtk.org/t/wrong-label-positions-with-vtklabelplacementmapper/10043/1 "2022-12-02T09:07:02Z")

</div>

Hello!

I am using VTK 9.1.0 and Qt 5.15.3 and encountered the following problem with vtkLabelPlacementMapper:

Without setting a render strategy the labels are corrected:

vtkLabelPlacementMapper added to vtkRenderer with viewport [0 0 1 1]:

 ![image](https://discourse.vtk.org/uploads/default/original/2X/9/9d95ff611b54584af88bf51d7aa5ab61a1391e29.png)

vtkLabelPlacementMapper added to vtkRenderer with viewport [0.3 0 1 1]:

 ![image](https://discourse.vtk.org/uploads/default/original/2X/5/5dac29ec4c474c602769846f8f9c26f2c83209c4.png)

After setting an instance of “vtkQtLabelRenderStrategy” to vtkLabelPlacementMapper by  
using the “SetRenderStrategy(…)” method, the result is as follows:

vtkLabelPlacementMapper added to vtkRenderer with viewport [0 0 1 1]:

 ![image](https://discourse.vtk.org/uploads/default/original/2X/0/0898fb5ea39a624929c6772480fea9e67ffa3991.png)

vtkLabelPlacementMapper added to vtkRenderer with viewport [0.3 0 1 1]:

 ![image](https://discourse.vtk.org/uploads/default/original/2X/8/849d9826d731c0078b96d7cb02927c65e658fbc8.png)

Unfortunately, the label positions are wrong if the viewport is different.

Any idea why this happens? I think there should be no difference.

Initially, GetRenderStrategy()-\>GetClassName() returns “vtkFreeTypeLabelRenderStrategy”, so  
there might be a bug in vtkQtLabelRenderStrategy?

Thank you!

---

<div class="post-metadata">

### Author: ![Peter](https://discourse.vtk.org/user_avatar/discourse.vtk.org/peter/32/3487_2.png) [@Peter](https://discourse.vtk.org/u/Peter)
#### Post date: [December 2, 2022, 2:39pm UTC](https://discourse.vtk.org/t/wrong-label-positions-with-vtklabelplacementmapper/10043/2 "2022-12-02T14:39:14Z")

</div>

Adding the following code to vtkQtLabelRenderStrategy “RenderLabel(…)” fixes the issue:

```auto
void QtLabelRenderStrategy::RenderLabel(int x[2], vtkTextProperty* tprop, vtkUnicodeString label)
{
    double* vp = this->Renderer->GetViewport();
    int* rw_size = this->Renderer->GetRenderWindow()->GetSize();

    x[0] = x[0] - (1 - (vp[2] - vp[0])) * rw_size[0];

```

Is the actual implementation of vtkQtLabelRenderStrategy flawed or am I missing something?
