using central functionality

This commit is contained in:
Martin Diehl 2020-03-19 09:02:50 +01:00
parent 0871111c11
commit f01af70357
2 changed files with 18 additions and 85 deletions

View File

@ -5,8 +5,6 @@ import sys
from io import StringIO
from optparse import OptionParser
import vtk
import damask
@ -39,35 +37,9 @@ for name in filenames:
damask.util.report(scriptName,name)
table = damask.Table.from_ASCII(StringIO(''.join(sys.stdin.read())) if name is None else name)
# ------------------------------------------ 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 ---------------------------------------
v = damask.VTK.from_polyData(table.get(options.pos))
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()))
v.write(os.path.splitext(name)[0])
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())
sys.stdout.write(v.__repr__())

View File

@ -5,9 +5,6 @@ import sys
from io import StringIO
from optparse import OptionParser
import vtk
import numpy as np
import damask
@ -48,50 +45,14 @@ for name in filenames:
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)]
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()
# ------------------------------------------ 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 ---------------------------------------
v = damask.VTK.from_rectilinearGrid(grid,size,origin)
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()))
v.write('{}_{}({})'.format(os.path.splitext(name)[0],options.pos,options.mode))
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())
sys.stdout.write(v.__repr__())