/usr/share/pyshared/tvtk/misc.py is in mayavi2 4.1.0-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 | """Some miscellaneous convenience functionality.
"""
# Author: Prabhu Ramachandran <prabhu_r [at] users.sf.net>
# Copyright (c) 2007, Enthought, Inc.
# License: BSD Style.
from os.path import splitext
# We import from tvtk.py and not api.py to prevent circular imports.
from tvtk.tvtk_access import tvtk
######################################################################
# Utility functions.
######################################################################
def write_data(dataset, fname, **kwargs):
"""Given a TVTK `dataset` this writes the `dataset` to a VTK XML
file having file name `fname`.
If the given file name has no extension, one is automatically picked
based on the dataset and an XML file is written out. If the
filename has a '.vtk' extension an old style VTK file is written.
If any other extension is specified, an XML file is written out with
the given extension.
Any additional keyword arguments are passed to the writer used.
"""
err_msg = "Can only write tvtk.DataSet instances "\
"'got %s instead"%(dataset.__class__.__name__)
assert isinstance(dataset, tvtk.DataSet), err_msg
# Mapping to determine appropriate extension and writer.
d2r = {'vtkImageData': ('.vti', tvtk.StructuredPointsWriter),
'vtkRectilinearGrid': ('.vtr', tvtk.RectilinearGridWriter),
'vtkStructuredGrid': ('.vts', tvtk.StructuredGridWriter),
'vtkPolyData': ('.vtp', tvtk.PolyDataWriter),
'vtkUnstructuredGrid': ('.vtu', tvtk.UnstructuredGridWriter)
}
for type in d2r:
if dataset.is_a(type):
datatype = d2r[type]
break
ext = splitext(fname)[1]
if ext == '.vtk':
file_name = fname
writer = datatype[1]
elif len(ext) == 0:
file_name = fname + datatype[0]
writer = tvtk.XMLDataSetWriter
else:
file_name = fname
writer = tvtk.XMLDataSetWriter
w = writer(file_name=file_name, input=dataset, **kwargs)
w.write()
|