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:
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.
This works, even if the correct VerticalJustification values should be:
#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?
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.
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.