Archive

Posts Tagged ‘Paraview’

Reload files in Paraview

June 21, 2013 Leave a comment

Here is a macro to reload files in Paraview. To use it go to Macro, Add new macro....

import re
import os

files = None
s = GetActiveSource()
try:
    files = s.FileName
except AttributeError:
    print "Not a file source"

if files and len(files) == 1:
    # one time step
    s.FileName = [files[0]]
elif files:
    # multiple time steps
    reg = re.compile(r"(.+[^0-9])([0-9]+)\.(.+)")
    roots = set()
    exts = set()
    for f in files:
       m = reg.match(f)
       if m:
           roots.add(m.group(1))
           exts.add(m.group(3))
       else:
           roots = None
           break
    if roots and len(roots) == 1 and len(exts) == 1:
        root = roots.pop()
        ext = exts.pop()
        basedir = os.path.dirname(root)
        basename = os.path.basename(root)
        unsorted_l = []
        for p in os.listdir(basedir):
            m = reg.match(p)
            if m and basename == m.group(1):
                unsorted_l.append((int(m.group(2)), os.path.join(basedir, p)))
        s.FileName = [p for i, p in sorted(unsorted_l)]
Tags:

Display point coordinates in Paraview (the return)

June 21, 2013 Leave a comment

The previous version was using the ProgrammableFilter of Paraview. This one is a macro that was tested with Paraview 4. Here are pros/cons compared to the previous version:

pros:

  • Automatic selection display mode configuration
  • Automatic selection of all points

cons: automatic selection of all points on large mesh is not what you want.

To install it go to Macros, Add new macro.

from paraview.simple import *

coord_prog_filter = ProgrammableFilter()
RenameSource("Coordinates", coord_prog_filter)
coord_prog_filter.Script = """
pdi = self.GetInput()
pdo = self.GetOutput()
coords = vtk.vtkDoubleArray()
coords.SetName("Coordinates")
coords.SetNumberOfComponents(3)
n = pdi.GetNumberOfPoints()
for i in xrange(n):
   p=pdi.GetPoint(i)
   coords.InsertNextTuple3(p[0], p[1], p[2])
pdo.GetPointData().AddArray(coords)
"""

sel = servermanager.sources.SelectionQuerySource()
sel.FieldType = "POINT"
sel.QueryString = "id >= 0"
coord_prog_filter.SMProxy.SetSelectionInput(coord_prog_filter.Port, sel.SMProxy, 0)

coord_repr = Show()
coord_repr.SelectionPointLabelColor = [0.0, 0.0, 0.0]
coord_repr.SelectionPointLabelFormat = '%g'
coord_repr.SelectionPointLabelVisibility = 1
coord_repr.SelectionPointFieldDataArrayName = 'Coordinates'
coord_repr.SelectionPointLabelVisibility = 1

Render()
Tags:

Display point coordinates in Paraview

July 17, 2012 4 comments

Here is how to display point coordinates in Paraview. First create a programmable filter with the following code:

pdi = self.GetInput()
pdo = self.GetOutput()
coords = vtk.vtkDoubleArray()
coords.SetName("Coordinates")
coords.SetNumberOfComponents(3)
n = pdi.GetNumberOfPoints()
for i in xrange(n):
   p=pdi.GetPoint(i)
   coords.InsertNextTuple3(p[0], p[1], p[2])
pdo.GetPointData().AddArray(coords)

Then select points and enable point labels in the Selection inspector:

Tags: ,