2019-02-14 06:09:54 +05:30
|
|
|
#!/usr/bin/env python3
|
2013-11-27 01:49:27 +05:30
|
|
|
|
2019-06-14 16:33:30 +05:30
|
|
|
import os
|
|
|
|
import sys
|
2019-12-22 11:37:34 +05:30
|
|
|
from io import StringIO
|
2019-06-14 16:33:30 +05:30
|
|
|
from optparse import OptionParser
|
|
|
|
|
|
|
|
import vtk
|
|
|
|
|
2013-11-27 01:49:27 +05:30
|
|
|
import damask
|
2019-06-14 16:33:30 +05:30
|
|
|
|
2014-12-19 00:56:52 +05:30
|
|
|
|
2016-01-27 22:36:00 +05:30
|
|
|
scriptName = os.path.splitext(os.path.basename(__file__))[0]
|
|
|
|
scriptID = ' '.join([scriptName,damask.version])
|
2014-12-19 00:56:52 +05:30
|
|
|
|
2019-06-14 16:33:30 +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)
|
2013-11-27 01:49:27 +05:30
|
|
|
|
2016-04-22 23:39:23 +05:30
|
|
|
parser.add_option('-p',
|
|
|
|
'--pos', '--position',
|
2016-04-14 03:19:48 +05:30
|
|
|
dest = 'pos',
|
2015-08-24 19:12:29 +05:30
|
|
|
type = 'string', metavar = 'string',
|
2016-04-23 00:50:36 +05:30
|
|
|
help = 'label of coordinates [%default]')
|
2016-04-22 23:39:23 +05:30
|
|
|
|
|
|
|
parser.set_defaults(pos = 'pos',
|
2015-08-24 19:12:29 +05:30
|
|
|
)
|
2013-11-27 01:49:27 +05:30
|
|
|
|
2015-08-24 19:12:29 +05:30
|
|
|
(options, filenames) = parser.parse_args()
|
|
|
|
if filenames == []: filenames = [None]
|
2013-11-27 01:49:27 +05:30
|
|
|
|
|
|
|
for name in filenames:
|
2015-10-09 16:54:26 +05:30
|
|
|
damask.util.report(scriptName,name)
|
2015-08-24 19:12:29 +05:30
|
|
|
|
2019-12-22 00:48:33 +05:30
|
|
|
table = damask.Table.from_ASCII(StringIO(''.join(sys.stdin.read())) if name is None else name)
|
2013-11-27 01:49:27 +05:30
|
|
|
|
2020-03-17 00:25:26 +05:30
|
|
|
# ------------------------------------------ process data ---------------------------------------
|
2013-11-27 01:49:27 +05:30
|
|
|
Polydata = vtk.vtkPolyData()
|
2015-11-14 07:22:31 +05:30
|
|
|
Points = vtk.vtkPoints()
|
2020-03-17 00:31:50 +05:30
|
|
|
Points.SetDataTypeToDouble()
|
2013-11-27 01:49:27 +05:30
|
|
|
|
2019-12-22 00:48:33 +05:30
|
|
|
for p in table.get(options.pos):
|
2015-10-09 16:54:26 +05:30
|
|
|
pointID = Points.InsertNextPoint(p)
|
2013-11-27 01:49:27 +05:30
|
|
|
|
|
|
|
Polydata.SetPoints(Points)
|
|
|
|
Polydata.Modified()
|
2020-03-17 00:25:26 +05:30
|
|
|
|
|
|
|
# ------------------------------------------ output result ---------------------------------------
|
2013-11-27 01:49:27 +05:30
|
|
|
|
2016-04-22 23:39:23 +05:30
|
|
|
if name:
|
2016-04-25 11:58:00 +05:30
|
|
|
writer = vtk.vtkXMLPolyDataWriter()
|
|
|
|
writer.SetCompressorTypeToZLib()
|
2016-04-24 23:04:01 +05:30
|
|
|
writer.SetDataModeToBinary()
|
2016-04-22 23:39:23 +05:30
|
|
|
writer.SetFileName(os.path.join(os.path.split(name)[0],
|
|
|
|
os.path.splitext(os.path.split(name)[1])[0] +
|
2016-04-24 23:04:01 +05:30
|
|
|
'.' + writer.GetDefaultFileExtension()))
|
2015-08-24 19:12:29 +05:30
|
|
|
else:
|
2016-04-25 11:58:00 +05:30
|
|
|
writer = vtk.vtkDataSetWriter()
|
|
|
|
writer.SetHeader('# powered by '+scriptID)
|
2015-08-24 19:12:29 +05:30
|
|
|
writer.WriteToOutputStringOn()
|
2020-03-17 00:25:26 +05:30
|
|
|
|
|
|
|
|
2019-02-17 02:50:10 +05:30
|
|
|
writer.SetInputData(Polydata)
|
2016-04-22 23:39:23 +05:30
|
|
|
|
2015-10-09 16:54:26 +05:30
|
|
|
writer.Write()
|
2016-04-22 23:39:23 +05:30
|
|
|
|
2019-05-27 12:04:36 +05:30
|
|
|
if name is None: sys.stdout.write(writer.GetOutputString())
|