[vtk 9.0.0.rc3][Python]GetMultiSamples() returns different value after doing Render()
Running vtk-example.py (see script below) shows that in an environment with vtk 9.0.0.rc3 with mesalib, calling GetMultiSamples() after calling Render() returns 0, which is different from what GetMultiSamples() returns before Render().
Platform: MacOS - 10.14.6
Running the following script in a conda environment with vtk 9.0.0.rc3 with mesalib shows that 2nd call to GetMultiSamples() return 0.
Run: python vtk-example.py <num of multisamples> [mesalib|no_mesalib]
Ex: python vtk-example.py 8 mesalib
import sys
import random
import vtk
print(vtk.VTK_VERSION)
mesa_or_no_mesa = sys.argv[2]
print(mesa_or_no_mesa)
r = random.Random(1234)
poly = vtk.vtkPolyData()
pts = vtk.vtkPoints()
w, h = 640, 480
step = 10
for x, y in zip(range(0, w+step, step), [r.randint(0, h) for _ in range(0, w+step, step)]):
pts.InsertNextPoint((x, y, 0.0))
poly.SetPoints(pts)
lines = vtk.vtkCellArray()
for x in range(0, int((w+step)/step)-1):
line = vtk.vtkLine()
line.GetPointIds().SetId(0, x)
line.GetPointIds().SetId(1, x+1)
lines.InsertNextCell(line)
poly.SetLines(lines)
colors = vtk.vtkNamedColors()
mapper = vtk.vtkPolyDataMapper2D()
mapper.SetInputData(poly)
actor = vtk.vtkActor2D()
actor.SetMapper(mapper)
actor.GetProperty().SetLineWidth(1)
actor.GetProperty().SetColor(colors.GetColor3d('black'))
renderer = vtk.vtkRenderer()
renderer.AddActor(actor)
renderer.SetBackground(colors.GetColor3d('white'))
win = vtk.vtkRenderWindow()
win.SetMultiSamples(int(sys.argv[1]))
win.SetSize(w, h)
win.AddRenderer(renderer)
#print(win.ReportCapabilities())
interactor = vtk.vtkRenderWindowInteractor()
interactor.SetRenderWindow(win)
print('Before Render', win.GetMultiSamples())
win.Render()
interactor.Start()
print('After Render', win.GetMultiSamples())
filter = vtk.vtkWindowToImageFilter()
filter.SetInput(win)
writer = vtk.vtkPNGWriter()
#writer.SetFileName(f'vtk-{vtk.VTK_VERSION}.png')
writer.SetFileName(f'vtk-{vtk.VTK_VERSION}.{sys.argv[2]}.png')
writer.SetInputConnection(filter.GetOutputPort())
writer.Write()
NOTE: for some reason with vtk 8.2.0, the png written out is a blank black screen
Results of running vtk-example.py:
[1] With vtk 9.0.0.rc3 - no mesalib
conda create -n vtk_9.0.0 -c conda-forge/label/vtk_dev -c conda-forge vtk=9.0.0.rc3 "python>=3.7,<3.8"
conda list | grep -E "^(vtk|mesalib)"
vtk 9.0.0.rc3 no_osmesa_py37h3fd7587_100 conda-forge/label/vtk_dev
Running 'python vtk-example.py 8' returns:
Before Render 8
After Render 8
[2] With vtk 9.0.0.rc3 and mesalib
conda create -n vtk_9.0.0_mesalib -c conda-forge/label/vtk_dev -c conda-forge vtk=9.0.0.rc3 mesalib=17.3.9 "python>=3.7,<3.8"
conda list | grep -E "^(vtk|mesalib)"
mesalib 17.3.9 hdd5ec5b_0 conda-forge
vtk 9.0.0.rc3 with_osmesa_py37hb208ac8_0 [mesalib] conda-forge/label/vtk_dev
Running 'python vtk-example.py 8' returns:
Before Render 8
After Render 0
[3] With vtk 8.2.0 - no mesalib
conda create -n vtk_8.2.0 -c conda-forge vtk=8.2.0 "python>=3.7,<3.8"
conda list | grep -E "^(vtk|mesalib)"
vtk 8.2.0 py37hd5eadda_217 conda-forge
Running 'python vtk-example.py 8' returns:
Before Render 8
After Render 8
[4] With vtk 8.2.0 and mesalib
conda create -n vtk_8.2.0_mesalib -c conda-forge vtk=8.2.0 mesalib=17.3.9 "python>=3.7,<3.8"
conda list | grep -E "^(vtk|mesalib)"
mesalib 17.3.9 hdd5ec5b_0 conda-forge
vtk 8.2.0 py37hd5eadda_217 conda-forge
Running 'python vtk-example.py 8' returns:
Before Render 8
After Render 8
You can see the images generated with [1] matches [3] and [4], but not [2].
The lines in [1], [3] and [4] are smoother than [2].
(In other words, the lines in [2] are more jagged than in [1], [3] and [4])