GithubHelp home page GithubHelp logo

Comments (3)

ahaldane avatar ahaldane commented on July 19, 2024 1

Further debugging:

I found the vtk code in python to do approximately the equivalent as the example (folded below).

When I run the pure-vtk example, overall I don't see the artifact from pyvista from the second screenshot above, at least to anywhere the same degree. However if I look very closely I can see a slight moire effect reminiscent of the artifacts seen in pyvista above, which disappears when I release the mouse.

This makes me think that during mouse panning, VTK is using some rendering approximations causing the artifacts. However in plain vtk the default settings make the approximations very small, but in pyvista the approximations are large.

So my hunch is that solving this problem boils down to finding the setting in pyvista controlling the approximations to volume rendering during panning, and turn it down.

python vtk code for volume rendering
#!/usr/bin/env python

# noinspection PyUnresolvedReferences
import vtkmodules.vtkInteractionStyle
from vtkmodules.vtkCommonColor import vtkNamedColors
from vtkmodules.vtkCommonDataModel import vtkPiecewiseFunction
from vtkmodules.vtkIOLegacy import vtkStructuredPointsReader
from vtkmodules.vtkRenderingCore import (
    vtkColorTransferFunction,
    vtkRenderWindow,
    vtkRenderWindowInteractor,
    vtkRenderer,
    vtkVolume,
    vtkVolumeProperty
)
from vtkmodules.vtkRenderingVolume import vtkFixedPointVolumeRayCastMapper
# noinspection PyUnresolvedReferences
from vtkmodules.vtkRenderingVolumeOpenGL2 import vtkOpenGLRayCastImageDisplayHelper
from vtkmodules.vtkInteractionStyle import vtkInteractorStyleTrackballCamera

def main():
    fileName = 'ironProt.vtk'
    colors = vtkNamedColors()

    # Create the standard renderer, render window
    # and interactor.
    ren1 = vtkRenderer()

    renWin = vtkRenderWindow()
    renWin.AddRenderer(ren1)

    iren = vtkRenderWindowInteractor()
    iren.SetRenderWindow(renWin)

    style = vtkInteractorStyleTrackballCamera()
    iren.SetInteractorStyle(style)

    # Create the reader for the data.
    reader = vtkStructuredPointsReader()
    reader.SetFileName(fileName)

    # Create transfer mapping scalar value to opacity.
    opacityTransferFunction = vtkPiecewiseFunction()
    opacityTransferFunction.AddPoint(20, 0.0)
    opacityTransferFunction.AddPoint(255, 0.2)

    # Create transfer mapping scalar value to color.
    colorTransferFunction = vtkColorTransferFunction()
    colorTransferFunction.AddRGBPoint(0.0, 1.0, 1.0, 1.0)
    colorTransferFunction.AddRGBPoint(255.0, 0.0, 0.0, 1.0)

    # The property describes how the data will look.
    volumeProperty = vtkVolumeProperty()
    volumeProperty.SetColor(colorTransferFunction)
    volumeProperty.SetScalarOpacity(opacityTransferFunction)
    volumeProperty.ShadeOn()
    volumeProperty.SetInterpolationTypeToLinear()

    # The mapper / ray cast function know how to render the data.
    volumeMapper = vtkFixedPointVolumeRayCastMapper()
    volumeMapper.SetInputConnection(reader.GetOutputPort())

    # The volume holds the mapper and the property and
    # can be used to position/orient the volume.
    volume = vtkVolume()
    volume.SetMapper(volumeMapper)
    volume.SetProperty(volumeProperty)

    ren1.AddVolume(volume)
    ren1.SetBackground(colors.GetColor3d('white'))
    ren1.GetActiveCamera().Azimuth(45)
    ren1.GetActiveCamera().Elevation(30)
    ren1.ResetCameraClippingRange()
    ren1.ResetCamera()

    renWin.SetSize(600, 600)
    renWin.SetWindowName('SimpleRayCast')
    renWin.Render()

    iren.Start()

if __name__ == '__main__':
    main()

from pyvista.

ahaldane avatar ahaldane commented on July 19, 2024 1

Sorry for noise, but an update: The previous comment is not right, the problem still exists.

I got myself confused above, here is the real situation:

  1. When I use dataset.plot(volume=True), then the default update rate is set to 30, making the artifact really big as in my initial screenshot.
  2. When I use pl.add_volume(dataset) with pl = pv.pPlotter() as in my last comment, then the default update rate is left at vtk's default of 0.0001. My command pl.ren_win.SetDesiredUpdateRate(0.0) actually had almost no effect. (0.0001 vs 0.0 gives the same result, I tested). While this greatly reduces the artifact compared to dataset.plot, the artifact is still much larger than in pure vtk.

So in summary, while I found a way to greatly reduce the artifact, it is still much larger than I get in pure vtk. There must be another LOD setting to tweak somewhere.

from pyvista.

ahaldane avatar ahaldane commented on July 19, 2024

OK, I've pretty much solved the issue: It is because pyvista sets the default update rate to 30, different from the vtk default of 0.0001. Feel free to close this issue, unless you want to consider changing the default.

I can reset the rate to a lower value in pyvista as follows:

import pyvista as pv

dataset = pv.examples.download_iron_protein()

pl = pv.Plotter()
print(pl.ren_win.GetDesiredUpdateRate())  # prints 0.0001, but somehow this gets reset to 30 by pyvista
pl.ren_win.SetDesiredUpdateRate(0.0)      # this allows full computation per frame
pl.add_volume(dataset, opacity='linear', cmap='Blues')  
pl.show()

Then the plot "looks good" even when panning.

The print statement there says the initial default is 0.0001, same as in my vtk code, which confused me. But actually, pyvista later resets it to 30.

from pyvista.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.