2013-11-27 01:49:27 +05:30
|
|
|
#!/usr/bin/env python
|
2014-04-02 00:11:14 +05:30
|
|
|
# -*- coding: UTF-8 no BOM -*-
|
2013-11-27 01:49:27 +05:30
|
|
|
|
2014-12-19 00:56:52 +05:30
|
|
|
import os,sys,string,re,vtk
|
2013-11-27 01:49:27 +05:30
|
|
|
import damask
|
2014-12-19 00:56:52 +05:30
|
|
|
from optparse import OptionParser
|
|
|
|
|
|
|
|
scriptID = string.replace('$Id$','\n','\\n')
|
|
|
|
scriptName = os.path.splitext(scriptID.split()[1])[0]
|
|
|
|
|
|
|
|
# --------------------------------------------------------------------
|
|
|
|
# MAIN
|
|
|
|
# --------------------------------------------------------------------
|
|
|
|
|
|
|
|
parser = OptionParser(option_class=damask.extendableOption, usage='%prog options [file[s]]', description = """
|
2013-11-27 01:49:27 +05:30
|
|
|
Add grain index based on similitude of crystal lattice orientation.
|
2014-12-19 00:56:52 +05:30
|
|
|
|
|
|
|
""", version = scriptID)
|
2013-11-27 01:49:27 +05:30
|
|
|
|
2014-09-12 19:44:55 +05:30
|
|
|
parser.add_option('-p', '--positions', dest='pos', \
|
2013-11-27 01:49:27 +05:30
|
|
|
help = 'coordinate label')
|
|
|
|
|
|
|
|
parser.set_defaults(pos = 'pos')
|
|
|
|
|
|
|
|
(options, filenames) = parser.parse_args()
|
|
|
|
|
|
|
|
datainfo = { # list of requested labels per datatype
|
|
|
|
'vector': {'len':3,
|
|
|
|
'label':[]},
|
|
|
|
}
|
|
|
|
|
|
|
|
if options.pos != None: datainfo['vector']['label'] += [options.pos]
|
|
|
|
|
|
|
|
# ------------------------------------------ setup file handles ---------------------------------------
|
|
|
|
|
|
|
|
files = []
|
|
|
|
for name in filenames:
|
|
|
|
if os.path.exists(name):
|
|
|
|
files.append({'name':name, 'input':open(name), 'output':os.path.splitext(name)[0]+'.vtp', 'croak':sys.stderr})
|
|
|
|
|
|
|
|
#--- loop over input files ------------------------------------------------------------------------
|
|
|
|
for file in files:
|
|
|
|
if file['name'] != 'STDIN': file['croak'].write('\033[1m'+scriptName+'\033[0m: '+file['name']+'\n')
|
|
|
|
else: file['croak'].write('\033[1m'+scriptName+'\033[0m\n')
|
|
|
|
|
|
|
|
table = damask.ASCIItable(file['input'],file['croak'],False) # make unbuffered ASCII_table
|
|
|
|
table.head_read() # read ASCII header info
|
|
|
|
|
|
|
|
# --------------- figure out columns to process
|
|
|
|
active = {}
|
|
|
|
column = {}
|
|
|
|
head = []
|
|
|
|
|
|
|
|
for datatype,info in datainfo.items():
|
|
|
|
for label in info['label']:
|
|
|
|
foundIt = False
|
|
|
|
for key in ['1_'+label,label]:
|
|
|
|
if key in table.labels:
|
|
|
|
foundIt = True
|
|
|
|
if datatype not in active: active[datatype] = []
|
|
|
|
if datatype not in column: column[datatype] = {}
|
|
|
|
active[datatype].append(label)
|
|
|
|
column[datatype][label] = table.labels.index(key) # remember columns of requested data
|
|
|
|
if not foundIt:
|
|
|
|
file['croak'].write('column %s not found...\n'%label)
|
|
|
|
break
|
|
|
|
|
|
|
|
|
|
|
|
# ------------------------------------------ process data ---------------------------------------
|
|
|
|
|
|
|
|
Polydata = vtk.vtkPolyData()
|
|
|
|
Points = vtk.vtkPoints()
|
|
|
|
Vertices = vtk.vtkCellArray()
|
2014-11-18 20:52:00 +05:30
|
|
|
table.data_readArray(range(column['vector'][options.pos],\
|
|
|
|
column['vector'][options.pos]+datainfo['vector']['len']))
|
2013-11-27 01:49:27 +05:30
|
|
|
|
2014-11-18 20:52:00 +05:30
|
|
|
for p in table.data:
|
2013-11-27 01:49:27 +05:30
|
|
|
id = Points.InsertNextPoint(p)
|
|
|
|
Vertices.InsertNextCell(1)
|
|
|
|
Vertices.InsertCellPoint(id)
|
|
|
|
|
|
|
|
Polydata.SetPoints(Points)
|
|
|
|
Polydata.SetVerts(Vertices)
|
|
|
|
Polydata.Modified()
|
|
|
|
if vtk.VTK_MAJOR_VERSION <= 5:
|
|
|
|
Polydata.Update()
|
|
|
|
|
|
|
|
# ------------------------------------------ output result ---------------------------------------
|
|
|
|
|
|
|
|
writer = vtk.vtkXMLPolyDataWriter()
|
|
|
|
writer.SetDataModeToBinary()
|
|
|
|
writer.SetCompressorTypeToZLib()
|
|
|
|
writer.SetFileName(file['output'])
|
|
|
|
if vtk.VTK_MAJOR_VERSION <= 5:
|
|
|
|
writer.SetInput(Polydata)
|
|
|
|
else:
|
|
|
|
writer.SetInputData(Polydata)
|
|
|
|
writer.Write()
|
|
|
|
|
2014-08-22 22:28:53 +05:30
|
|
|
table.input_close() # close input ASCII table
|