using central functionality
This commit is contained in:
parent
0871111c11
commit
f01af70357
|
@ -5,8 +5,6 @@ import sys
|
|||
from io import StringIO
|
||||
from optparse import OptionParser
|
||||
|
||||
import vtk
|
||||
|
||||
import damask
|
||||
|
||||
|
||||
|
@ -36,38 +34,12 @@ parser.set_defaults(pos = 'pos',
|
|||
if filenames == []: filenames = [None]
|
||||
|
||||
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 ---------------------------------------
|
||||
Polydata = vtk.vtkPolyData()
|
||||
Points = vtk.vtkPoints()
|
||||
Points.SetDataTypeToDouble()
|
||||
|
||||
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())
|
||||
if name:
|
||||
v.write(os.path.splitext(name)[0])
|
||||
else:
|
||||
sys.stdout.write(v.__repr__())
|
||||
|
|
|
@ -5,9 +5,6 @@ import sys
|
|||
from io import StringIO
|
||||
from optparse import OptionParser
|
||||
|
||||
import vtk
|
||||
import numpy as np
|
||||
|
||||
import damask
|
||||
|
||||
|
||||
|
@ -44,54 +41,18 @@ parser.set_defaults(mode = 'cell',
|
|||
if filenames == []: filenames = [None]
|
||||
|
||||
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':
|
||||
coords = [0.5 * np.array([3.0 * coords[i][0] - coords[i][0 + int(len(coords[i]) > 1)]] + \
|
||||
[coords[i][j-1] + coords[i][j] for j in range(1,len(coords[i]))] + \
|
||||
[3.0 * coords[i][-1] - coords[i][-1 - int(len(coords[i]) > 1)]]) for i in range(3)]
|
||||
if options.mode == 'cell':
|
||||
grid, size, origin = damask.grid_filters.cell_coord0_gridSizeOrigin(table.get(options.pos))
|
||||
elif options.mode == 'point':
|
||||
grid, size, origin = damask.grid_filters.node_coord0_gridSizeOrigin(table.get(options.pos))
|
||||
|
||||
grid = np.array(list(map(len,coords)),'i')
|
||||
N = grid.prod() if options.mode == 'point' else (grid-1).prod()
|
||||
v = damask.VTK.from_rectilinearGrid(grid,size,origin)
|
||||
|
||||
# ------------------------------------------ process data ---------------------------------------
|
||||
|
||||
rGrid = vtk.vtkRectilinearGrid()
|
||||
coordArray = [vtk.vtkDoubleArray(),
|
||||
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())
|
||||
if name:
|
||||
v.write('{}_{}({})'.format(os.path.splitext(name)[0],options.pos,options.mode))
|
||||
else:
|
||||
sys.stdout.write(v.__repr__())
|
||||
|
|
Loading…
Reference in New Issue