DAMASK_EICMD/processing/post/vtk_pointCloud.py

74 lines
2.1 KiB
Python
Raw Normal View History

#!/usr/bin/env python3
import os
import sys
2019-12-22 11:37:34 +05:30
from io import StringIO
from optparse import OptionParser
import vtk
import damask
2014-12-19 00:56:52 +05:30
scriptName = os.path.splitext(os.path.basename(__file__))[0]
scriptID = ' '.join([scriptName,damask.version])
2014-12-19 00:56:52 +05:30
2014-12-19 00:56:52 +05:30
# --------------------------------------------------------------------
# MAIN
# --------------------------------------------------------------------
2019-02-16 22:11:56 +05:30
parser = OptionParser(option_class=damask.extendableOption, usage='%prog options [ASCIItable(s)]', description = """
2015-05-21 05:43:50 +05:30
Produce a VTK point cloud dataset based on coordinates given in an ASCIItable.
2014-12-19 00:56:52 +05:30
""", version = scriptID)
parser.add_option('-p',
'--pos', '--position',
dest = 'pos',
type = 'string', metavar = 'string',
2016-04-23 00:50:36 +05:30
help = 'label of coordinates [%default]')
parser.set_defaults(pos = 'pos',
)
(options, filenames) = parser.parse_args()
if filenames == []: filenames = [None]
for name in filenames:
damask.util.report(scriptName,name)
2019-12-22 00:48:33 +05:30
table = damask.Table.from_ASCII(StringIO(''.join(sys.stdin.read())) if name is None else name)
2020-03-17 00:25:26 +05:30
# ------------------------------------------ process data ---------------------------------------
Polydata = vtk.vtkPolyData()
Points = vtk.vtkPoints()
Points.SetDataTypeToDouble()
2019-12-22 00:48:33 +05:30
for p in table.get(options.pos):
pointID = Points.InsertNextPoint(p)
Polydata.SetPoints(Points)
Polydata.Modified()
2020-03-17 00:25:26 +05:30
# ------------------------------------------ output result ---------------------------------------
if name:
writer = vtk.vtkXMLPolyDataWriter()
writer.SetCompressorTypeToZLib()
writer.SetDataModeToBinary()
writer.SetFileName(os.path.join(os.path.split(name)[0],
os.path.splitext(os.path.split(name)[1])[0] +
'.' + writer.GetDefaultFileExtension()))
else:
writer = vtk.vtkDataSetWriter()
writer.SetHeader('# powered by '+scriptID)
writer.WriteToOutputStringOn()
2020-03-17 00:25:26 +05:30
writer.SetInputData(Polydata)
writer.Write()
2019-05-27 12:04:36 +05:30
if name is None: sys.stdout.write(writer.GetOutputString())