Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Antialiasing doesn't appear to work for png output (2.12) #267

Open
durack1 opened this issue Nov 2, 2017 · 6 comments
Open

Antialiasing doesn't appear to work for png output (2.12) #267

durack1 opened this issue Nov 2, 2017 · 6 comments
Assignees
Labels
Milestone

Comments

@durack1
Copy link
Member

durack1 commented Nov 2, 2017

Using the code example in #266 I have been trying to generate clean *.png output, however it seems that antialiasing is not working for this output format.

Example output seems to show slightly different file sizes, but the line output in the examples doesn't appear to improve with a high antialiasing setting - there are jaggies in all of the png outputs, whereas the pdf output is much sharper.

antialiasing = 1 (44.7K)
171102_antialiasing_1_

antialiasing = 8 (45.5K)
171102_antialiasing_8_

antialiasing = 64 (45.5K)
171102_antialiasing_64_

pdf output
171102_antiAliasing_1_.pdf

@doutriaux1 doutriaux1 added the bug label Nov 2, 2017
@doutriaux1 doutriaux1 added this to the 3.0 milestone Nov 2, 2017
@doutriaux1
Copy link
Contributor

@aashish24 @danlipsa that's the bug I was just talking about with you.

@doutriaux1
Copy link
Contributor

@danlipsa this is a big problem, I can confirm at least with mesa no antialiasing ever seems to be applied.

@doutriaux1 doutriaux1 modified the milestones: 3.0, Next Release Mar 29, 2018
@scottwittenburg
Copy link
Collaborator

Here is the code snippet from the issue mentioned above:

import vcs

x = vcs.init(bg=False,geometry=(900,900))

for anti in [0,8,64]:
    x.setantialiasing(anti)
    x.plot([1,3,5,7,10,24,36,3,6,8,9,10])
    x.png('_'.join(['antialias',str(anti),'.png']))
    x.pdf('_'.join(['antialias',str(anti),'.pdf']))
    x.clear()

I have been able to confirm that this results in three pngs with no antialiasing. However, it seems to be related to the clearing of the canvas in the last line of the loop. If instead I change the code to for anti in [64, 8, 0]: (just reverse the order of the multisamples to be set), then I get three pngs with antialiasing.

Additionally, if I change the code as follows:

import vcs

for anti in [0,8,64]:
    x = vcs.init(bg=False,geometry=(900,900))
    x.setantialiasing(anti)
    x.plot([1,3,5,7,10,24,36,3,6,8,9,10])
    x.png('_'.join(['antialias',str(anti),'.png']))
    x.pdf('_'.join(['antialias',str(anti),'.pdf']))

Then I get one png which appears with no antialiasing, but two with it. For this reason, I believe there may be a bug with the clear method.

For now I may leave this alone, as once we update our pipelines to use Context2D (thus allowing us to use the OpenGL2 backend), the clear issue may go away on it's own. If not, it would make sense to debug the clear issue further at that point.

ping @doutriaux1 @danlipsa @aashish24

@scottwittenburg
Copy link
Collaborator

So now that I have a working debug build of VTK to test vtk-cdat issues, I have been able to confirm that although you can set MultiSamples on a vtkRenderWindow at any time, it is only used when the thing is actually initialized.

This explains why we can't seem to change the value in the loop, but only the first value chosen is used. It would also mean that there is probably not a bug in the canvas clear function.

Does this jive with your understanding of how multisample antialiasing works in VTK @danlipsa and @aashish24?

@danlipsa
Copy link
Contributor

danlipsa commented May 8, 2018

Maybe its a bug in VTK and you need to call Modified so that it can re-set the proper OpenGL functions?
I wonder if OpenGL2 works correctly. If that's the case we can focus on the OpenGL2 conversion.

@scottwittenburg
Copy link
Collaborator

Here's a vanilla vtkpython script to reproduce the issue outside of vcs with a plot that looks similar to the reproduction scripts listed in comments above:

import vtk

def buildPolyData():
    N = 12

    pts = [
        [0,   0.0,  0.0, 0.0],
        [1,   3.0,  3.0, 0.0],
        [2,   6.0,  6.0, 0.0],
        [3,   9.0,  7.0, 0.0],
        [4,  12.0, 10.0, 0.0],
        [5,  15.0, 24.0, 0.0],
        [6,  18.0, 36.0, 0.0],
        [7,  21.0,  3.0, 0.0],
        [8,  24.0,  6.5, 0.0],
        [9,  27.0,  8.0, 0.0],
        [10, 30.0,  9.0, 0.0],
        [11, 33.0, 10.0, 0.0]
    ]

    points = vtk.vtkPoints()
    points.SetNumberOfPoints(N)

    for i in range(N):
        points.SetPoint(*pts[i])

    lines = vtk.vtkCellArray()

    for i in range(N - 1):
        lines.InsertNextCell(2)
        lines.InsertCellPoint(i)
        lines.InsertCellPoint(i + 1)

    poly = vtk.vtkPolyData()
    poly.SetPoints(points)
    poly.SetLines(lines)

    return poly


pd = buildPolyData()

polyMapper = vtk.vtkPolyDataMapper()
polyMapper.SetInputData(pd)
polyMapper.Update()

polyActor1 = vtk.vtkActor()
polyActor1.SetMapper(polyMapper)

ren1 = vtk.vtkRenderer()
ren1.AddActor(polyActor1)
ren1.SetBackground(0.1, 0.2, 0.4)
ren1.ResetCamera()

renWin = vtk.vtkRenderWindow()
renWin.AddRenderer(ren1)
renWin.SetSize(800, 800)

for anti in [0,8,64]:
    renWin.SetMultiSamples(anti)
    print('RenderWindow multisamples is now: %d' % renWin.GetMultiSamples())
    renWin.Render()

    # Just gives us a chance to look at the render window
    stuff = raw_input('Please enter something:\n')
    print('You entered %s' % stuff)

    pd.Modified()

I have run this with both OpenGL and OpenGL2 builds and got the same results. That is, the first value of multisamples is the only one used in all three Render() calls. So that Modified() call upstream of the rendering pipeline doesn't seem to help.

I have noticed in the vtkXOpenGLRenderWindow code (at least under OpenGL2), that a call to WindowRemap should re-trigger the creation of the framebuffer and visual. I have tried this out, and with the OpenGL2 backend, it causes the new value of MultiSamples to be used and then behaves as we would like/expect. However, calling WindowRemap under the OpenGL backend results in X Error of failed request: GLXBadDrawable.

So you're probably right we should focus on the OpenGL2 conversion.

@doutriaux1 doutriaux1 modified the milestones: 8.1, 8.2 Mar 27, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

5 participants