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)
- Contour segmentation fault HOT 1
- pv.plotter.export_html Hangs when '-i' option is given to argparse in user script HOT 5
- Interactive plot with trame does not render in Jupyter HOT 8
- multi_ray_trace is not working under MPI (mpi4py | OpenMPI 3.1.4, CentOS7.6) HOT 4
- Scrollbars in interactive viewer in jupyter HOT 4
- Adding distortion parameters on the Plotter.Camera
- Many issues with `contour_labeled`, consider deprecating and rewriting as `contour_labels`
- Colors missing from interactive `MultiBlock` plots
- update scalars does not applies correct alpha values HOT 1
- Plot 2d with pyvista
- Incorrect color mapping using `categories=True` for non-linear categories
- Segmentation fault on boolean pyvista operation
- Python kernel crashes after running a simple example HOT 1
- `rgb` parameter for `add_composite` not working
- Deprecate using the `translate` method in `ImageData` HOT 1
- pyvista.CircularArc cannot create arc with 6 segments
- Allow clearing cell and point data for all blocks in `MultiBlock` objects
- stack overflow when computing delaunay_2d on bigger point clouds
- Allow reading of files from remote file stores such as S3 [willing to contribute a PR!] HOT 5
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.