using central functionality
This commit is contained in:
parent
0871111c11
commit
f01af70357
|
@ -5,8 +5,6 @@ import sys
|
||||||
from io import StringIO
|
from io import StringIO
|
||||||
from optparse import OptionParser
|
from optparse import OptionParser
|
||||||
|
|
||||||
import vtk
|
|
||||||
|
|
||||||
import damask
|
import damask
|
||||||
|
|
||||||
|
|
||||||
|
@ -36,38 +34,12 @@ parser.set_defaults(pos = 'pos',
|
||||||
if filenames == []: filenames = [None]
|
if filenames == []: filenames = [None]
|
||||||
|
|
||||||
for name in filenames:
|
for name in filenames:
|
||||||
damask.util.report(scriptName,name)
|
damask.util.report(scriptName,name)
|
||||||
|
|
||||||
table = damask.Table.from_ASCII(StringIO(''.join(sys.stdin.read())) if name is None else name)
|
table = damask.Table.from_ASCII(StringIO(''.join(sys.stdin.read())) if name is None else name)
|
||||||
|
v = damask.VTK.from_polyData(table.get(options.pos))
|
||||||
|
|
||||||
# ------------------------------------------ process data ---------------------------------------
|
if name:
|
||||||
Polydata = vtk.vtkPolyData()
|
v.write(os.path.splitext(name)[0])
|
||||||
Points = vtk.vtkPoints()
|
else:
|
||||||
Points.SetDataTypeToDouble()
|
sys.stdout.write(v.__repr__())
|
||||||
|
|
||||||
for p in table.get(options.pos):
|
|
||||||
pointID = Points.InsertNextPoint(p)
|
|
||||||
|
|
||||||
Polydata.SetPoints(Points)
|
|
||||||
Polydata.Modified()
|
|
||||||
|
|
||||||
# ------------------------------------------ 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()
|
|
||||||
|
|
||||||
|
|
||||||
writer.SetInputData(Polydata)
|
|
||||||
|
|
||||||
writer.Write()
|
|
||||||
|
|
||||||
if name is None: sys.stdout.write(writer.GetOutputString())
|
|
||||||
|
|
|
@ -5,9 +5,6 @@ import sys
|
||||||
from io import StringIO
|
from io import StringIO
|
||||||
from optparse import OptionParser
|
from optparse import OptionParser
|
||||||
|
|
||||||
import vtk
|
|
||||||
import numpy as np
|
|
||||||
|
|
||||||
import damask
|
import damask
|
||||||
|
|
||||||
|
|
||||||
|
@ -44,54 +41,18 @@ parser.set_defaults(mode = 'cell',
|
||||||
if filenames == []: filenames = [None]
|
if filenames == []: filenames = [None]
|
||||||
|
|
||||||
for name in filenames:
|
for name in filenames:
|
||||||
damask.util.report(scriptName,name)
|
damask.util.report(scriptName,name)
|
||||||
|
|
||||||
table = damask.Table.from_ASCII(StringIO(''.join(sys.stdin.read())) if name is None else name)
|
table = damask.Table.from_ASCII(StringIO(''.join(sys.stdin.read())) if name is None else name)
|
||||||
|
|
||||||
coords = [np.unique(table.get(options.pos)[:,i]) for i in range(3)]
|
if options.mode == 'cell':
|
||||||
if options.mode == 'cell':
|
grid, size, origin = damask.grid_filters.cell_coord0_gridSizeOrigin(table.get(options.pos))
|
||||||
coords = [0.5 * np.array([3.0 * coords[i][0] - coords[i][0 + int(len(coords[i]) > 1)]] + \
|
elif options.mode == 'point':
|
||||||
[coords[i][j-1] + coords[i][j] for j in range(1,len(coords[i]))] + \
|
grid, size, origin = damask.grid_filters.node_coord0_gridSizeOrigin(table.get(options.pos))
|
||||||
[3.0 * coords[i][-1] - coords[i][-1 - int(len(coords[i]) > 1)]]) for i in range(3)]
|
|
||||||
|
|
||||||
grid = np.array(list(map(len,coords)),'i')
|
v = damask.VTK.from_rectilinearGrid(grid,size,origin)
|
||||||
N = grid.prod() if options.mode == 'point' else (grid-1).prod()
|
|
||||||
|
|
||||||
# ------------------------------------------ process data ---------------------------------------
|
if name:
|
||||||
|
v.write('{}_{}({})'.format(os.path.splitext(name)[0],options.pos,options.mode))
|
||||||
rGrid = vtk.vtkRectilinearGrid()
|
else:
|
||||||
coordArray = [vtk.vtkDoubleArray(),
|
sys.stdout.write(v.__repr__())
|
||||||
vtk.vtkDoubleArray(),
|
|
||||||
vtk.vtkDoubleArray(),
|
|
||||||
]
|
|
||||||
|
|
||||||
rGrid.SetDimensions(*grid)
|
|
||||||
for i,points in enumerate(coords):
|
|
||||||
for point in points:
|
|
||||||
coordArray[i].InsertNextValue(point)
|
|
||||||
|
|
||||||
rGrid.SetXCoordinates(coordArray[0])
|
|
||||||
rGrid.SetYCoordinates(coordArray[1])
|
|
||||||
rGrid.SetZCoordinates(coordArray[2])
|
|
||||||
|
|
||||||
|
|
||||||
# ------------------------------------------ output result ---------------------------------------
|
|
||||||
|
|
||||||
if name:
|
|
||||||
writer = vtk.vtkXMLRectilinearGridWriter()
|
|
||||||
writer.SetCompressorTypeToZLib()
|
|
||||||
writer.SetDataModeToBinary()
|
|
||||||
writer.SetFileName(os.path.join(os.path.split(name)[0],
|
|
||||||
os.path.splitext(os.path.split(name)[1])[0] +
|
|
||||||
'_{}({})'.format(options.pos, options.mode) +
|
|
||||||
'.' + writer.GetDefaultFileExtension()))
|
|
||||||
else:
|
|
||||||
writer = vtk.vtkDataSetWriter()
|
|
||||||
writer.SetHeader('# powered by '+scriptID)
|
|
||||||
writer.WriteToOutputStringOn()
|
|
||||||
|
|
||||||
writer.SetInputData(rGrid)
|
|
||||||
|
|
||||||
writer.Write()
|
|
||||||
|
|
||||||
if name is None: sys.stdout.write(writer.GetOutputString())
|
|
||||||
|
|
Loading…
Reference in New Issue