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
|
||||||
|
|
||||||
|
|
||||||
|
@ -39,35 +37,9 @@ 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:
|
if name:
|
||||||
writer = vtk.vtkXMLPolyDataWriter()
|
v.write(os.path.splitext(name)[0])
|
||||||
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:
|
else:
|
||||||
writer = vtk.vtkDataSetWriter()
|
sys.stdout.write(v.__repr__())
|
||||||
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
|
||||||
|
|
||||||
|
|
||||||
|
@ -48,50 +45,14 @@ for name in filenames:
|
||||||
|
|
||||||
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':
|
||||||
coords = [0.5 * np.array([3.0 * coords[i][0] - coords[i][0 + int(len(coords[i]) > 1)]] + \
|
grid, size, origin = damask.grid_filters.cell_coord0_gridSizeOrigin(table.get(options.pos))
|
||||||
[coords[i][j-1] + coords[i][j] for j in range(1,len(coords[i]))] + \
|
elif options.mode == 'point':
|
||||||
[3.0 * coords[i][-1] - coords[i][-1 - int(len(coords[i]) > 1)]]) for i in range(3)]
|
grid, size, origin = damask.grid_filters.node_coord0_gridSizeOrigin(table.get(options.pos))
|
||||||
|
|
||||||
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 ---------------------------------------
|
|
||||||
|
|
||||||
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:
|
if name:
|
||||||
writer = vtk.vtkXMLRectilinearGridWriter()
|
v.write('{}_{}({})'.format(os.path.splitext(name)[0],options.pos,options.mode))
|
||||||
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:
|
else:
|
||||||
writer = vtk.vtkDataSetWriter()
|
sys.stdout.write(v.__repr__())
|
||||||
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