Last active
August 29, 2015 14:14
-
-
Save pwolfram/85478f5ea04b9d2db6f1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#input type: points with data associated with them | |
#output type: vtkUnstructuredGrid | |
# example of unstructured programmable filter | |
# gist -u 85478f5ea04b9d2db6f1 cylindrical_filter.py | |
#https://gist.github.com/85478f5ea04b9d2db6f1 | |
# place in script box: | |
from paraview import vtk | |
import numpy as np | |
def coord_transform(x,y,z,Rmax): | |
rhoact = np.sqrt(x*x + y*y + z*z) | |
theta = np.arctan(z/np.sqrt(x*x + y*y)) | |
thetay = np.arctan2(y,x) | |
z = Rmax * np.tan(theta) | |
rhotot = np.sqrt(z*z + Rmax*Rmax) | |
rhothick = rhotot - rhoact | |
#sf = (Rmax - rhothick)/np.sqrt(x*x + y*y) | |
#x = sf*x | |
#y = sf*y | |
x = (Rmax - rhothick)*np.cos(thetay) | |
y = (Rmax - rhothick)*np.sin(thetay) | |
return x, y, z | |
pdi = self.GetInput() | |
pdo = self.GetOutput() | |
newPoints = vtk.vtkPoints() | |
numPoints = pdi.GetNumberOfPoints() | |
ivals = pdi.GetPointData().GetArray(0) | |
#elev = vtk.vtkFloatArray() | |
#elev.SetName('elevation') | |
#elev.SetNumberOfComponents(1) | |
#elev.SetNumberOfTuples(numPoints) | |
Rmax = 0.0 | |
for i in range(0, numPoints): | |
coord = pdi.GetPoint(i) | |
x, y, z = coord[:3] | |
Rmax = np.maximum(0.0,np.sqrt(x*x + y*y )) | |
for i in range(0, numPoints): | |
coord = pdi.GetPoint(i) | |
x, y, z = coord[:3] | |
#elev.SetValue(i, z) | |
# coodinate transform | |
x, y, z = coord_transform(x,y,z,Rmax) | |
newPoints.InsertPoint(i, x, y, z) | |
pdo.SetPoints(newPoints) | |
pdo.GetPointData().AddArray(ivals) | |
#pdo.GetPointData().AddArray(elev) | |
print 'finished with coordinate transform!' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment