vtkTextWidget position is not updated when the camera or zoom is used

Dear all,

I am trying to put a text around a object all in 2d. But i found that this widget when i move the camera (or zoom in an area) the objects moves correctly but the text widget stays and is not accordingly updated. The same problem happens with other widgets such as the seed widgets. I wonder how i can enable this text widget so that it gets correctly positioned when the camera moves. Thanks

textActor->SetInput(stream.c_str());
//textActor->SetTextScaleModeToNone();
textActor->SetTextScaleModeToProp();
textActor->GetTextProperty()->SetFontSize(90);
textActor->GetTextProperty()->SetColor(1.0, 0.0, 0.0);
vtkNew<vtkTextProperty> text_prop;
text_prop->SetFontSize(20);
text_prop->SetColor(0, 1, 0);
textActor->SetTextProperty(text_prop);

vtkNew<vtkTextWidget> textWidget;
vtkSmartPointer<vtkTextRepresentation> textRepresentation =
	vtkSmartPointer<vtkTextRepresentation>::New();
textRepresentation->GetPositionCoordinate()->SetCoordinateSystemToWorld();
//double mouse_click_pos1[3] = { roi.xmin, roi.ymin, roi.z };
textRepresentation->GetPositionCoordinate()->SetValue(mouse_click_pos);
textWidget->SetRepresentation(textRepresentation);

textWidget->SetInteractor(interactor);
textWidget->SetTextActor(textActor);
textWidget->SelectableOff();
textWidget->On();

Any idea than create an observer when i click the right mouse and redo he textwidget?. Thanks

Widgets are supposed to be overlays which show information over top of the rest of the scene, but do not move with the rest of the scene. For example, your reference axes should always stay in the same place on screen as you rotate your model, but the widget content might sync, such as changing the orientation of the axes to match your interaction.

If you want the behavior you have asked for, you can do it by overloading the interactor to add code to the methods which process camera movement and manually change the widget positions to match the rest of your scene.

You could also add text directly to your scene (not inside a widget), which will move as you want by default, but would not have the user interaction properties of a widget (click + drag, resize, etc).

1 Like