vtkAxesActor Fails to Render at Some Angles

After upgrading from 8.2.0 to 9.0.1, VTK AxesActors do not render at certain
angles. Here is a Python script that demonstrates this:

 # This script demonstrates that the vtkAxesActor is not drawn between phi = 91 degrees and 261 degrees.

import math
from typing import List
import vtk

def main():

    # set the camera angle
    camera = vtk.vtkCamera()
    camera.SetPosition(10., 10., 20.)
    camera.SetViewUp(0., 1., 0.)
    camera.SetFocalPoint(0., 2., 0.)

    # create renderer
    renderer = vtk.vtkRenderer()
    renderer.SetActiveCamera(camera)

    # set spherical angles
    radius = 2.0

    phi = [0.0, 45.0, 91.0, 135.0, 180.0, 225.0, 261.0, 315.0]
    pCount = len(phi)
    theta = [45.0]*pCount

    # loop over the number of angles
    for i in range(0, pCount):
        rPosition = spherical2Rectangular(radius, theta[i], phi[i])

        # create transform to rotate the axes based on the spherical angles
        transform = vtk.vtkTransform()
        transform.Translate(rPosition[0], rPosition[1], rPosition[2])
        transform.Scale(0.2, 0.2, 0.2)
        transform.RotateZ(180.0+phi[i])
        transform.RotateY(-180.0-theta[i])
        transform.RotateZ(-90.0)

        # create axis actor
        srcActor = vtk.vtkAxesActor()
        srcActor.SetUserTransform(transform)
        srcActor.SetXAxisLabelText("")
        srcActor.SetYAxisLabelText("")
        srcActor.SetZAxisLabelText("")

        renderer.AddActor(srcActor)

        # Axis label
        textActor = vtk.vtkBillboardTextActor3D()
        textActor.SetInput("I_" + str(int(phi[i])))
        textActor.SetPosition(rPosition[0], rPosition[1], rPosition[2])
        textActor.GetTextProperty().SetFontSize(24)
        textActor.GetTextProperty().SetJustificationToCentered()
        textActor.SetScale(5.0, 5.0, 5.0)

        renderer.AddActor(textActor)

    # create render window
    renWin = vtk.vtkRenderWindow()
    renWin.SetSize(1200,1200)

    # create render window interactor
    renderWindowInteractor = vtk.vtkRenderWindowInteractor()
    renderWindowInteractor.SetRenderWindow(renWin)
    renderWindowInteractor.SetInteractorStyle(vtk.vtkInteractorStyleTrackballCamera())

    # add renderer to render windows
    renWin.AddRenderer(renderer)
    renWin.Render()

    # Begin mouse interaction
    renderWindowInteractor.Start()

def spherical2Rectangular(radius: float, thetaD: float, phiD: float) -> List[float]:
    theta = thetaD*(math.pi / 180.0)
    phi = phiD*(math.pi / 180.0)

    x = radius * math.sin(theta) * math.cos(phi)
    y = radius * math.sin(theta) * math.sin(phi)
    z = radius * math.cos(theta)

    return [x, y, z]

if __name__ == '__main__':
    main()

Here are the results for 9.0.1:

Here are the results for 8.2.0:

Is there anything I’m missing?

Thanks.

Ok, I can confirm that after modifying your camera parameters as follows:

    camera.SetPosition(-0.308454, -4.328727, 6.006257)
    camera.SetFocalPoint(0.073685, 0.471175, 0.624938)
    camera.SetViewUp(0.085563, 0.740509, 0.666578)
    camera.SetDistance(7.221058)
    camera.SetClippingRange(3.089628, 12.804766)

I get an image much like yours with missing axes for I_91 … I_261. These missing axes briefly appear then disappear when rendered. @ben.boeckel, @ken-martin any ideas?

I too have been running into something similar to this, and after exhaustively attempting every workaround I can find on the internet, I am here to report that I either am missing something huge or there continues to be a bug in vtk version 9.5.1 (and 9.5.0). I’ve got a scene with a cube orbiting earth and I have optional vtkAxesActors drawn at the origin of each actor in the scene when toggled on with the ‘a’ key. In general this feature works well except when the scene first starts up before any object or camera has moved. Upon moving the camera “enough” the axes will pop into view. I’ve captured this behavior in a video of my vtk scene: https://youtu.be/IPjFpeaQ4O4

I believe I’ve narrowed this down to an issue with the bounding box of the vtkAxesActor itself, as when the axes are not visible I see their bounding box located too far away to be rendered. From my notes:


When the scene comes up and we can't see the axes, we see this
    DEBUG: self._axes.GetVisibility is 1 with axes_pos [6867500.0, 0.0, 0.0]
    Axes bounds: (-50.00000000000002, 50.00000000000002, -50.000000000000014, 50.000000000000014, -50.00000000000002, 50.00000000000002)
After wiggling the camera, and seeing them, we see this:
    DEBUG: self._axes.GetVisibility is 1 with axes_pos [6867499.95774354, 761.8349401624926, 0.0]
    Axes bounds: (-6867550.0, 6867550.0, -50.00000000000002, 50.00000000000002, -50.00000000000002, 50.00000000000002)

Failure looks like -50.00000000000002, 50.00000000000002, success looks like -6867550.0, 6867550.0, in the Axes bounds. I have tried self._axes.Modified() after changing their state in any way, and I know a Render() has occurred, and I’ve tried several other things recommended by AI (some of which weren’t even valid code!) but none of my attempts have yielded a different result. Interestingly this behavior only happens for this small cube actor and not for the larger earth actor. I can’t figure out why the bounding box refuses to update until the object/camera movement satisfies some unknown condition, if anyone has any ideas on how to debug this please let me know!