Managed to do it in a rather silly way:
Load the vtk point data into a vtkTable, push that and apply
TableToPoints. Code attached.
Main takeaway: please never change the TableToPoints filter in case that
is considered (as, for example, it's not in servermanager.sources and
would be edited when moving there). It's the only filter I found doing
the right thing and using only one cell.
By the way, paraview.servermanager.sources.TrivialProducer() is not
accessible on importing just paraview.servermanager, you also need to
import paraview.simple. Not sure if this is by design.
By the way #2, a "print(1)" ProgrammableFilter is even crashing via
pvpython scripts (Run Script) in Ubuntu's standard ParaView (5.1.2).
Unsubscribing from this list as not interested in the traffic, so if
anybody wants to address me, please add me in the CC.
cheers
Donjan
On 04.05.2017 19:34, Donjan Rodic wrote:
Continuing to battle with this...
Loading a VTK file, the CellCenters filter with "Vertex Cells"
displays inner points but doesn't keep color information.
The PointDatatoCellData Filter stores the information in Cell Data,
but averages colors at the region boundaries. Then using CellCenters
(+Vertex Cells) does some additional averaging, but at least shows
something.
Having PointDatatoCellData "Pass Point Data" allows me to access this
original information as input to CellCenters, but that's not useful
because it gets averaged at this point.
Can't see how to improve in that direction.
I've tried ExtractComponent, AppendAttributes and others to
overwrite/adjust/... CellCenters' data array with the original color
data, but I can't manage to do it with the built-in filters or Create
Custom Filter. It's a size mismatch anyway.
Another option is to manually load the points into one cell.
Unfortunately both Programmable Filter and Programmable Source
segfault regardless of the Output Data Set Type (ParaView 5.1.2,
upgrading is currently undesirable due to 5.1 being the version for
Ubuntu 16.10 and 17.04, ideally the fix would be pushed in a
patchlevel update).
I've tried to modify the data in pvpython operating on
servermanager.Fetch(...).GetCellData() with AddArray(...) and
GetArray(0).SetComponent(...), but this doesn't seem to be the right
way to go about things.
Next up is trying to run a ProgrammableFilter within a pvpython script.
Any help on how to achieve the subject line with a reasonable amount
of effort is welcome.
On 03.05.2017 22:38, Donjan Rodic wrote:
I'm visualising a large grid dataset with different regions == scalar
colors with ParaView 5.1.2 on Ubuntu 16.10.
The computation prints the colors (floats in [0,1]) of a 250^3
(usually larger) grid into a CSV file:
x,y,z,color
0,0,0,0.5
0,0,1,0.5
0,0,2,0.3
...
I load it with ParaView (Python script), apply TableToPoints, set
points.XColumn = 'x', etc. and the Points representation.
This works really well with opacity mapping and sliding the Mapping
Data curve to highlight the different regions inside the grid.
The main problem is the large size (hundreds of MB) of the CSV files.
Since the grid is rectilinear and equidistant, verbose x,y,z columns
are wasteful.
Writing into a legacy VTK file with STRUCTURED_POINTS yields a nice
7x size reduction, but then in ParaView the inner points are not
displayed.
I've tried using the Glyph representation, which makes the rendering
unusably slow (10+ seconds for a small rotation).
2D Glyphs with Glyph Type Vertex are not noticeably faster and lose
coloring.
Applying the Shrink filter (random googled hint) freezes the GUI for
more than 5 minutes before I kill it. At smaller system sizes the
performance is bad.
For the CSV->TableToPoints described initially, the resulting data
structure is shown in the Information tab as a Polygonal Mesh with 1
single cell and 15 million points, Memory: 600 MB. After loading it
responds and rotates snappily on a recent Core i7 & NVidia GPU.
The VTK file loads with several million cells as well as 15 million
points, and a Image (Uniform Rectilinear Grid) type. Memory: 15 MB
... much lower but irrelevant with 16 GB RAM.
It appears what I want is to have all points in one single cell, and
the CSV reader is the only one I've found doing the right thing.
Using RECTILINEAR_GRID and custom CELL_DATA in the VTK file doesn't
help: the format apparently doesn't allow to specify less than 1 cell
per 8 vertices (or 4 in 2D).
Next I've tried to use a raw format, but after setting it up,
ParaView insists on creating millions of cells. Same experience as
with VTK.
I've also tried ExtractSurface to at least get a Polygonal Mesh from
the Rectilinear Grid: still too slow and too many cells.
Something like a "GridToTable" filter with a subsequent TableToPoints
would do the job, but I can't find such a function. Or a routine to
merge all cells into one.
Creating a custom filter via GUI doesn't work because the loaded
data.vtk "does not have any inputs".
How do I achieve the same performance and display of inner points as
CSV->TableToPoints with either another file format or from the Grid
data structure offered by the VTK file reader?
cheers
Donjan
PS: googling for
paraview grid "to table"
mainly yields results for a typo in the documentation of
TableToStructuredGrid, saying "Converts to table to structured....".
#!/usr/bin/env python2
#
# Plot point data grid with ParaView
# (C) 2017 Donjan Rodic. For free use, no warranties.
#
# Usage:
# ./pvplot filename
# ./pvplot
# ParaView: Tools -> Python Shell -> Run Script -> <full file path>
#
# If no filename is specified on the command line and no fallback_file is set,
# the program will ask for an input file.
# If it's in ParaView CSV format, the first line must be exactly 'x,y,z,region'.
# If it's in STRUCTURED_POINTS legacy .vtk, the scalars must be named 'region'.
# Writing Python2 code due to ParaView compatibility (issue: raw_input).
#
################################################################################
import paraview.simple as pvs
import paraview.servermanager as pvsm
from os.path import splitext
from paraview.vtk import vtkFloatArray, vtkTable
# fallback_file = "/home/..."
################################################################################
def display(fname):
_, ftype = splitext(fname)
source = pvs.OpenDataFile(fname)
if ftype == '.csv':
pass
elif ftype == '.vtk':
rsrc = pvsm.Fetch(pvs.GetActiveSource())
dims = rsrc.GetDimensions()
spac = rsrc.GetSpacing()
region = rsrc.GetPointData().GetArray(0)
N = region.GetNumberOfTuples()
table = vtkTable()
xarr = vtkFloatArray(); xarr.SetName('x'); xarr.Resize(N)
yarr = vtkFloatArray(); yarr.SetName('y'); yarr.Resize(N)
zarr = vtkFloatArray(); zarr.SetName('z'); zarr.Resize(N)
rarr = vtkFloatArray(); rarr.SetName('region'); rarr.Resize(N)
for i in range(N): # zyx ordering
xarr.InsertNextValue(spac[0] * ( i % dims[0]))
yarr.InsertNextValue(spac[1] * ((i // dims[0] ) % dims[1]))
zarr.InsertNextValue(spac[2] * ((i // (dims[0]*dims[1])) % dims[2]))
rarr.InsertNextValue(int(region.GetTuple(i)[0]))
table.AddColumn(xarr)
table.AddColumn(yarr)
table.AddColumn(zarr)
table.AddColumn(rarr)
source = pvsm.sources.TrivialProducer()
pvsm.Register(source, registrationName="Temporary Table")
filter = source.GetClientSideObject()
filter.SetOutput(table)
source.UpdatePipeline()
else:
raise ValueError("Can't read this file type")
#~ points = pvsm.sources.TableToPoints() # best filter, not in pvsm.sources
#~ pvsm.Register(points, registrationName="Point Grid")
points = pvs.TableToPoints(source) # convert table to Polygonal Mesh
points.XColumn = 'x'
points.YColumn = 'y'
points.ZColumn = 'z'
pvs.Show(points)
dprops = pvs.GetDisplayProperties(points)
# dprops.add_attribute('Representation', None) # sometimes race condition!?
dprops.Representation = 'Points'
N = pvsm.Fetch(pvs.GetActiveSource()).GetNumberOfPoints()
dprops.PointSize = 200 * N**(1./3) / N**(0.7)
# dprops.ColorArrayName = ('POINTS', 'region') # seems unneeded with ColorBy
pvs.ColorBy(dprops, ('POINTS', 'region'))
dprops.RescaleTransferFunctionToDataRange(False)
lut = pvs.GetColorTransferFunction('region')
lut.ApplyPreset('Blue to Red Rainbow')
lut.EnableOpacityMapping = 1
pwf = pvs.GetOpacityTransferFunction('region')
r0op = 0.05 # region 0 opacity
r1op = 1.00 # region 1 opacity
r2op = 1.00 # region 2 opacity
pwf.Points = [0.0, r0op, 0.5, 0.0, 0.5, r1op, 0.5, 0.0, 1.0, r2op, 0.5, 0.0]
# [base, opacity, shift, curve, ...]
pvs.Render()
pvs.GetActiveViewOrCreate('RenderView').AxesGrid.Visibility = 1
def main(standalone=False):
if standalone:
import argparse
parser = argparse.ArgumentParser(description='Plot with ParaView')
parser.add_argument('fname', metavar='filename', nargs='?',
type=str, help="Input file")
args = parser.parse_args()
try:
fname = args.fname
assert(fname is not None)
except (UnboundLocalError, AssertionError):
try:
fname = fallback_file
except UnboundLocalError:
import readline
readline.parse_and_bind("tab: complete")
fname = raw_input("Enter filename: ")
display(fname)
if(standalone):
pvs.Interact()
if __name__ == "__main__": # called directly from command line
main(standalone=True)
else: # called as module (e.g. ParaView Run Script)
main(standalone=False)
_______________________________________________
Powered by www.kitware.com
Visit other Kitware open-source projects at
http://www.kitware.com/opensource/opensource.html
Please keep messages on-topic and check the ParaView Wiki at:
http://paraview.org/Wiki/ParaView
Search the list archives at: http://markmail.org/search/?q=ParaView
Follow this link to subscribe/unsubscribe:
http://public.kitware.com/mailman/listinfo/paraview