Draw an actor as 2D overlay using normalized viewport coordinates

Hello,

I created a 3D scene with some spheres close to a surface. Furthermore I want to render spheres which are not related to the surface. I already tried to place the additional spheres next to the surface but that’s not satisfying.

Thus, I want to render some spheres as 2D overlay and set its position in normalized viewport coordinates. I already created another renderer for the overlay and did the following:

vtkSmartPointer<vtkSphereSource> sphereSource = vtkSmartPointer<vtkSphereSource>::New();
sphereSource->Update();
sphereSource->SetThetaResolution(50);
sphereSource->SetPhiResolution(50);
sphereSource->SetRadius(0.05);          // SIZE WITH RESPECT TO VIEWPORT

vtkSmartPointer<vtkPoints> points = vtkSmartPointer<vtkPoints>::New();
points->SetNumberOfPoints(2);
points->Allocate(2);
points->InsertPoint(0, 0.25, 0.5, 0);    // VIEWPORT COORDINATES
points->InsertPoint(1, 0.75, 0.5, 0);

vtkSmartPointer<vtkPolyData> input = vtkSmartPointer<vtkPolyData>::New();
input->SetPoints(points);

vtkSmartPointer<vtkGlyph3D> glyph3D = vtkSmartPointer<vtkGlyph3D>::New();
glyph3D->SetSourceConnection(sphereSource->GetOutputPort());
glyph3D->SetInputData(input);
glyph3D->Update();

vtkSmartPointer<vtkCoordinate> coordinate = vtkSmartPointer<vtkCoordinate>::New();
coordinate->SetCoordinateSystemToNormalizedViewport();

vtkSmartPointer<vtkPolyDataMapper2D> mapper = vtkSmartPointer<vtkPolyDataMapper2D>::New();
mapper->SetInputConnection(glyph3D->GetOutputPort());
mapper->SetTransformCoordinate(coordinate);
mapper->TransformCoordinateUseDoubleOn();
mapper->Update();

vtkSmartPointer<vtkActor2D> actor = vtkSmartPointer<vtkActor2D>::New();
actor->SetMapper(mapper);
OverlayRenderer->AddActor(actor);

Basically it works but the rendered spheres are warped because of the viewport aspect.

Any ideas how to fix that behavior?

I want to place the spheres (should also work for cylinders) using normalized viewport coordinates but the shape should not be influenced.

Thank you.