Comments (3)
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.
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:
- 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. - When I use
pl.add_volume(dataset)
withpl = pv.pPlotter()
as in my last comment, then the default update rate is left at vtk's default of 0.0001. My commandpl.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 todataset.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.
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)
- GIF `Texture` animation broken in version 0.43
- Build PyVista Docker Image Locally results in ERROR HOT 3
- Segmentation fault when reading XDMF file
- Unhelfpul error message for `Plotter.subplot` HOT 1
- `plot_directive` generates build image even if `plot()` or `show()` is not called
- SVG export does not preserve multiline texts
- Add thanks for contributor which is not for code HOT 4
- DOCS: "Hide Cells with Ghosting" broken 0.43 HOT 5
- Docs site is inaccessible under specific ISP? HOT 3
- `Actor` bounds do not match the bounds of its dataset in some cases
- Scalar color bar not appearing on Orange pi 5 pro
- `add_floor` function incompatible with NumPy 2.0 HOT 1
- Grid Save accuracy loss in grids HOT 1
- How best to import and use OpenStreetMaps or Satellite images as textures on topography?
- Custom number formatting for axes
- `merge` does not set active normals
- Broken picking since 0.40.0 HOT 3
- texture_map_to_plane only works in z direction HOT 2
- Setting background_color for a scalar bar overwrites/invalidates out of range colors
- RGB scalars not working with `Plane` on Windows
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from pyvista.