WIP: making compatible with python3/vtk9
This commit is contained in:
parent
0ad189ea9d
commit
0878302961
|
@ -1,4 +1,4 @@
|
||||||
#!/usr/bin/env python2.7
|
#!/usr/bin/env python3
|
||||||
|
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
|
@ -17,7 +17,7 @@ scriptID = ' '.join([scriptName,damask.version])
|
||||||
|
|
||||||
# -----------------------------
|
# -----------------------------
|
||||||
def getHeader(filename,sizeFastIndex,sizeSlowIndex,stepsize):
|
def getHeader(filename,sizeFastIndex,sizeSlowIndex,stepsize):
|
||||||
"""Returns header for ang file step size in micrometer"""
|
"""Returns header for ang file step size in micrometer."""
|
||||||
return '\n'.join([ \
|
return '\n'.join([ \
|
||||||
'# TEM_PIXperUM 1.000000', \
|
'# TEM_PIXperUM 1.000000', \
|
||||||
'# x-star 1.000000', \
|
'# x-star 1.000000', \
|
||||||
|
@ -53,7 +53,7 @@ def getHeader(filename,sizeFastIndex,sizeSlowIndex,stepsize):
|
||||||
|
|
||||||
# -----------------------------
|
# -----------------------------
|
||||||
def positiveRadians(angle):
|
def positiveRadians(angle):
|
||||||
"""Returns positive angle in radians from angle in degrees"""
|
"""Returns positive angle in radians from angle in degrees."""
|
||||||
angle = math.radians(float(angle))
|
angle = math.radians(float(angle))
|
||||||
while angle < 0.0:
|
while angle < 0.0:
|
||||||
angle += 2.0 * math.pi
|
angle += 2.0 * math.pi
|
||||||
|
@ -67,7 +67,7 @@ def getDataLine(angles,x,y,validData=True):
|
||||||
Returns string of one line in ang file.
|
Returns string of one line in ang file.
|
||||||
|
|
||||||
Convention in ang file: y coordinate comes first and is fastest index
|
Convention in ang file: y coordinate comes first and is fastest index
|
||||||
positions in micrometer
|
positions in micrometer.
|
||||||
"""
|
"""
|
||||||
info = {True: (9999.9, 1.0, 0,99999,0.0),
|
info = {True: (9999.9, 1.0, 0,99999,0.0),
|
||||||
False: ( -1.0,-1.0,-1, -1,1.0)}
|
False: ( -1.0,-1.0,-1, -1,1.0)}
|
||||||
|
@ -75,11 +75,9 @@ def getDataLine(angles,x,y,validData=True):
|
||||||
%(tuple(map(positiveRadians,angles))+(y*1e6,x*1e6)+info[validData])
|
%(tuple(map(positiveRadians,angles))+(y*1e6,x*1e6)+info[validData])
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# --------------------------------------------------------------------
|
# --------------------------------------------------------------------
|
||||||
# MAIN FUNCTION STARTS HERE
|
# MAIN FUNCTION STARTS HERE
|
||||||
# --------------------------------------------------------------------
|
# --------------------------------------------------------------------
|
||||||
|
|
||||||
parser = OptionParser(usage='%prog options [file[s]]', description = """
|
parser = OptionParser(usage='%prog options [file[s]]', description = """
|
||||||
Builds a ang files from a vtk file.
|
Builds a ang files from a vtk file.
|
||||||
|
|
||||||
|
@ -110,11 +108,6 @@ parser.add_option('-s','--scale', dest='scale', type='float',
|
||||||
parser.add_option('-r','--resolution', dest='resolution', type='float',
|
parser.add_option('-r','--resolution', dest='resolution', type='float',
|
||||||
metavar ='float',
|
metavar ='float',
|
||||||
help='scaling factor for resolution [%default]')
|
help='scaling factor for resolution [%default]')
|
||||||
parser.add_option('--hex','--hexagonal', dest='hexagonal', action='store_true',
|
|
||||||
help='use in plane hexagonal grid')
|
|
||||||
parser.add_option('--interpolation', dest='interpolation', type='int',
|
|
||||||
metavar='float',
|
|
||||||
help='number of points for linear interpolation [%default]')
|
|
||||||
parser.add_option('--verbose', dest='verbose', action='store_true',
|
parser.add_option('--verbose', dest='verbose', action='store_true',
|
||||||
help='verbose mode')
|
help='verbose mode')
|
||||||
parser.add_option('--visualize', dest='visualize', action='store_true',
|
parser.add_option('--visualize', dest='visualize', action='store_true',
|
||||||
|
@ -122,7 +115,6 @@ parser.add_option('--visualize', dest='visualize', action='store_true
|
||||||
|
|
||||||
parser.set_defaults(dispLabel = 'displacement')
|
parser.set_defaults(dispLabel = 'displacement')
|
||||||
parser.set_defaults(eulerLabel = ['1_1_eulerangles','1_2_eulerangles','1_3_eulerangles'])
|
parser.set_defaults(eulerLabel = ['1_1_eulerangles','1_2_eulerangles','1_3_eulerangles'])
|
||||||
parser.set_defaults(hexagonal = False)
|
|
||||||
parser.set_defaults(normal = [0.0,0.0,-1.0])
|
parser.set_defaults(normal = [0.0,0.0,-1.0])
|
||||||
parser.set_defaults(up = [0.0,1.0,0.0])
|
parser.set_defaults(up = [0.0,1.0,0.0])
|
||||||
parser.set_defaults(Nslices = 1)
|
parser.set_defaults(Nslices = 1)
|
||||||
|
@ -130,7 +122,6 @@ parser.set_defaults(distance = 0.0)
|
||||||
parser.set_defaults(scale = 1.0)
|
parser.set_defaults(scale = 1.0)
|
||||||
parser.set_defaults(resolution = 1.0)
|
parser.set_defaults(resolution = 1.0)
|
||||||
parser.set_defaults(dispScaling = 1.0)
|
parser.set_defaults(dispScaling = 1.0)
|
||||||
parser.set_defaults(interpolation = 1)
|
|
||||||
parser.set_defaults(verbose = False)
|
parser.set_defaults(verbose = False)
|
||||||
parser.set_defaults(visualize = False)
|
parser.set_defaults(visualize = False)
|
||||||
(options,filenames) = parser.parse_args()
|
(options,filenames) = parser.parse_args()
|
||||||
|
@ -153,15 +144,6 @@ if np.dot(np.array(options.normal),np.array(options.up)) > 1e-3:
|
||||||
parser.error('normal vector and up vector have to be orthogonal')
|
parser.error('normal vector and up vector have to be orthogonal')
|
||||||
|
|
||||||
|
|
||||||
# check for options that are not yet implemented
|
|
||||||
|
|
||||||
if options.interpolation > 1:
|
|
||||||
parser.error('interpolation not yet supported')
|
|
||||||
if options.hexagonal:
|
|
||||||
parser.error('hexagonal grid not yet supported')
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#--- ITERATE OVER FILES AND PROCESS THEM
|
#--- ITERATE OVER FILES AND PROCESS THEM
|
||||||
|
|
||||||
for filename in filenames:
|
for filename in filenames:
|
||||||
|
@ -180,8 +162,8 @@ for filename in filenames:
|
||||||
|
|
||||||
if options.verbose: sys.stdout.write("\nGETTING EULER ANGLES\n")
|
if options.verbose: sys.stdout.write("\nGETTING EULER ANGLES\n")
|
||||||
angles = {}
|
angles = {}
|
||||||
for i in range(reader.GetNumberOfScalarsInFile()):
|
for i in range(undeformedMesh.GetPointData().GetNumberOfArrays()):
|
||||||
scalarName = reader.GetScalarsNameInFile(i)
|
scalarName = undeformedMesh.GetPointData().GetArrayName(i)
|
||||||
if scalarName in options.eulerLabel:
|
if scalarName in options.eulerLabel:
|
||||||
angles[scalarName] = undeformedMesh.GetCellData().GetScalars(scalarName)
|
angles[scalarName] = undeformedMesh.GetCellData().GetScalars(scalarName)
|
||||||
if options.verbose: sys.stdout.write(" found scalar with name %s\n"%scalarName)
|
if options.verbose: sys.stdout.write(" found scalar with name %s\n"%scalarName)
|
||||||
|
@ -196,7 +178,7 @@ for filename in filenames:
|
||||||
if options.verbose: sys.stdout.write("\nDEFORM MESH\n")
|
if options.verbose: sys.stdout.write("\nDEFORM MESH\n")
|
||||||
warpVector = vtk.vtkWarpVector()
|
warpVector = vtk.vtkWarpVector()
|
||||||
undeformedMesh.GetPointData().SetActiveVectors(options.dispLabel)
|
undeformedMesh.GetPointData().SetActiveVectors(options.dispLabel)
|
||||||
warpVector.SetInput(undeformedMesh)
|
warpVector.SetInputData(undeformedMesh)
|
||||||
warpVector.Update()
|
warpVector.Update()
|
||||||
deformedMesh = warpVector.GetOutput()
|
deformedMesh = warpVector.GetOutput()
|
||||||
box = deformedMesh.GetBounds() # bounding box in mesh system
|
box = deformedMesh.GetBounds() # bounding box in mesh system
|
||||||
|
@ -212,7 +194,7 @@ for filename in filenames:
|
||||||
if options.verbose: sys.stdout.write("\nGETTING CELL CENTERS OF DEFORMED MESH\n")
|
if options.verbose: sys.stdout.write("\nGETTING CELL CENTERS OF DEFORMED MESH\n")
|
||||||
cellCenter = vtk.vtkCellCenters()
|
cellCenter = vtk.vtkCellCenters()
|
||||||
cellCenter.SetVertexCells(0) # do not generate vertex cells, just points
|
cellCenter.SetVertexCells(0) # do not generate vertex cells, just points
|
||||||
cellCenter.SetInput(deformedMesh)
|
cellCenter.SetInputData(deformedMesh)
|
||||||
cellCenter.Update()
|
cellCenter.Update()
|
||||||
meshIPs = cellCenter.GetOutput()
|
meshIPs = cellCenter.GetOutput()
|
||||||
|
|
||||||
|
@ -221,7 +203,7 @@ for filename in filenames:
|
||||||
|
|
||||||
if options.verbose: sys.stdout.write("\nGETTING OUTER SURFACE OF DEFORMED MESH\n")
|
if options.verbose: sys.stdout.write("\nGETTING OUTER SURFACE OF DEFORMED MESH\n")
|
||||||
surfaceFilter = vtk.vtkDataSetSurfaceFilter()
|
surfaceFilter = vtk.vtkDataSetSurfaceFilter()
|
||||||
surfaceFilter.SetInput(deformedMesh)
|
surfaceFilter.SetInputData(deformedMesh)
|
||||||
surfaceFilter.Update()
|
surfaceFilter.Update()
|
||||||
surface = surfaceFilter.GetOutput()
|
surface = surfaceFilter.GetOutput()
|
||||||
|
|
||||||
|
@ -250,9 +232,9 @@ for filename in filenames:
|
||||||
if options.verbose: sys.stdout.write("\nGETTING BOUNDING BOX IN ROTATED SYSTEM\n")
|
if options.verbose: sys.stdout.write("\nGETTING BOUNDING BOX IN ROTATED SYSTEM\n")
|
||||||
rotatedbox = [[np.inf,-np.inf] for i in range(3)] # bounding box in rotated TSL system
|
rotatedbox = [[np.inf,-np.inf] for i in range(3)] # bounding box in rotated TSL system
|
||||||
for n in range(8): # loop over eight vertices of mesh bounding box
|
for n in range(8): # loop over eight vertices of mesh bounding box
|
||||||
vert = np.array([box[0+(n/1)%2],
|
vert = np.array([box[0+(n//1)%2],
|
||||||
box[2+(n/2)%2],
|
box[2+(n//2)%2],
|
||||||
box[4+(n/4)%2]]) # vertex in mesh system
|
box[4+(n//4)%2]]) # vertex in mesh system
|
||||||
rotatedvert = np.dot(R,vert) # vertex in rotated system
|
rotatedvert = np.dot(R,vert) # vertex in rotated system
|
||||||
for i in range(3):
|
for i in range(3):
|
||||||
rotatedbox[i][0] = min(rotatedbox[i][0],rotatedvert[i])
|
rotatedbox[i][0] = min(rotatedbox[i][0],rotatedvert[i])
|
||||||
|
@ -282,8 +264,8 @@ for filename in filenames:
|
||||||
correction.extend([0.0])
|
correction.extend([0.0])
|
||||||
options.distance = extent[2] / float(options.Nslices)
|
options.distance = extent[2] / float(options.Nslices)
|
||||||
for i in range(3):
|
for i in range(3):
|
||||||
rotatedbox[i][0] = rotatedbox[i][0] - 0.5 * correction[i]
|
rotatedbox[i][0] -= 0.5 * correction[i]
|
||||||
rotatedbox[i][1] = rotatedbox[i][1] + 0.5 * correction[i]
|
rotatedbox[i][1] += 0.5 * correction[i]
|
||||||
extent[i] = rotatedbox[i][1] - rotatedbox[i][0]
|
extent[i] = rotatedbox[i][1] - rotatedbox[i][0]
|
||||||
NpointsPerSlice = Npoints[0] * Npoints[1]
|
NpointsPerSlice = Npoints[0] * Npoints[1]
|
||||||
totalNpoints = NpointsPerSlice * Npoints[2]
|
totalNpoints = NpointsPerSlice * Npoints[2]
|
||||||
|
@ -304,8 +286,8 @@ for filename in filenames:
|
||||||
for j in range(Npoints[0]):
|
for j in range(Npoints[0]):
|
||||||
for i in range(Npoints[1]): # y is fastest index
|
for i in range(Npoints[1]): # y is fastest index
|
||||||
rotatedpoint = np.array([rotatedbox[0][0] + (float(j) + 0.5) * options.resolution,
|
rotatedpoint = np.array([rotatedbox[0][0] + (float(j) + 0.5) * options.resolution,
|
||||||
rotatedbox[1][0] + (float(i) + 0.5) * options.resolution,
|
rotatedbox[1][0] + (float(i) + 0.5) * options.resolution,
|
||||||
rotatedbox[2][0] + (float(k) + 0.5) * options.distance ]) # point in rotated system
|
rotatedbox[2][0] + (float(k) + 0.5) * options.distance ]) # point in rotated system
|
||||||
point = np.dot(R.T,rotatedpoint) # point in mesh system
|
point = np.dot(R.T,rotatedpoint) # point in mesh system
|
||||||
points.InsertNextPoint(list(point))
|
points.InsertNextPoint(list(point))
|
||||||
if options.verbose:
|
if options.verbose:
|
||||||
|
@ -357,7 +339,7 @@ for filename in filenames:
|
||||||
if enclosedPoints.IsInside(i):
|
if enclosedPoints.IsInside(i):
|
||||||
NenclosedPoints += 1
|
NenclosedPoints += 1
|
||||||
# here one could use faster(?) "FindClosestPoint" if only first nearest neighbor required
|
# here one could use faster(?) "FindClosestPoint" if only first nearest neighbor required
|
||||||
kdTree.FindClosestNPoints(options.interpolation,pointgrid.GetPoint(i),ids)
|
kdTree.FindClosestNPoints(1,pointgrid.GetPoint(i),ids)
|
||||||
for j in range(ids.GetNumberOfIds()):
|
for j in range(ids.GetNumberOfIds()):
|
||||||
gridToMesh[-1].extend([ids.GetId(j)])
|
gridToMesh[-1].extend([ids.GetId(j)])
|
||||||
if options.verbose:
|
if options.verbose:
|
||||||
|
|
Loading…
Reference in New Issue