-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #296 from alhom/vtk_interface
Experimental VTK interface for VLSV files, implemented via a rudimentary VTKPythonAlgorithmBase-based reader exposing a vtkHyperTreeGrid. This will cache HTG metadata on disk. Includes a ParaView plugin script, wrapping the interface for ParaView access. Works on Paraview>=5.13.1.
- Loading branch information
Showing
6 changed files
with
1,105 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import vtk | ||
import pytools as pt | ||
|
||
# This initializes a hypertreegrid from the given reader. | ||
reader = pt.vlsvfile.VlsvVtkReader() | ||
reader.SetFileName("../../bulk.0002189.vlsv") | ||
|
||
# These functions grab one SpatialGrid variable and map that to | ||
# the hypertreegrid. Variable vector sizes of 1,2,3,4,9 supported. | ||
reader.addArrayFromVlsv("vg_b_vol") | ||
reader.addArrayFromVlsv("vg_beta_star") | ||
|
||
reader.Update() | ||
|
||
writer = vtk.vtkXMLHyperTreeGridWriter() | ||
writer.SetFileName("output_EGE.htg") | ||
writer.SetInputData(reader.GetOutputDataObject(0)) | ||
writer.Write() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
""" A rudimentary wrapper from the vlsvVtkInterface. Add and load from Paraview | ||
plugins menu. | ||
Built on Kitware example: | ||
https://github.com/Kitware/ParaView/blob/master/Examples/Plugins/PythonAlgorithm/PythonAlgorithmExamples.py | ||
This module demonstrates various ways of adding | ||
VTKPythonAlgorithmBase subclasses as filters, sources, readers, | ||
and writers in ParaView""" | ||
|
||
# https://github.com/Kitware/ParaView/blob/master/Examples/Plugins/PythonAlgorithm/PythonAlgorithmExamples.py | ||
|
||
# This is module to import. It provides VTKPythonAlgorithmBase, the base class | ||
# for all python-based vtkAlgorithm subclasses in VTK and decorators used to | ||
# 'register' the algorithm with ParaView along with information about UI. | ||
from paraview.util.vtkAlgorithm import * | ||
import pytools as pt | ||
|
||
# Use the analysator reader, but include Paraview decorators via inheriting/chaining | ||
# necessary methods etc | ||
|
||
#------------------------------------------------------------------------------ | ||
# A reader example. | ||
#------------------------------------------------------------------------------ | ||
|
||
# To add a reader, we can use the following decorators | ||
# @smproxy.source(name="PythonCSVReader", label="Python-based CSV Reader") | ||
# @smhint.xml("""<ReaderFactory extensions="csv" file_description="Numpy CSV files" />""") | ||
# or directly use the "@reader" decorator. | ||
@smproxy.reader(name="PythonVLSVReader", label="Python-based VLSV Reader, outputs htg", | ||
extensions="vlsv", file_description="VLSV files") | ||
class PythonPvVLSVReader(pt.vlsvfile.VlsvVtkReader): | ||
"""A reader that wraps an Analysator VLSV file reader. | ||
""" | ||
def __init__(self): | ||
super().__init__() | ||
|
||
|
||
@smproperty.stringvector(name="FileName") | ||
@smdomain.filelist() | ||
@smhint.filechooser(extensions="vlsv", file_description="Vlasiator VLSV files") | ||
def SetFileName(self, filename): | ||
"""Specify filename for the file to read.""" | ||
if filename is None or filename == "None": | ||
return | ||
print(filename) | ||
super().SetFileName(filename) | ||
|
||
@smproperty.doublevector(name="TimestepValues", information_only="1", si_class="vtkSITimeStepsProperty") | ||
def GetTimestepValues(self): | ||
return None | ||
|
||
# Array selection API is typical with readers in VTK | ||
# This is intended to allow ability for users to choose which arrays to | ||
# load. To expose that in ParaView, simply use the | ||
# smproperty.dataarrayselection(). | ||
# This method **must** return a `vtkDataArraySelection` instance. | ||
@smproperty.dataarrayselection(name="Arrays") | ||
def GetDataArraySelection(self): | ||
return super().GetDataArraySelection() | ||
|
||
|
||
#------------------------------------------------------------------------------ | ||
# Todo: some tests | ||
#------------------------------------------------------------------------------ | ||
|
||
def test_PythonVLSVReader(fname): | ||
pass | ||
|
||
if __name__ == "__main__": | ||
pass |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.