-
Notifications
You must be signed in to change notification settings - Fork 258
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How did you create the vtk files in python? #5
Comments
Your code is not quite right. pip install --upgrade vtkplotter from vtkplotter import Plotter, sqrt
from vtkplotter.utils import pointScalars
print("enter size of the dataset ")
#limit=int(input())
limit=20
vp = Plotter()
grid=[]
scalars=[]
for i in range(0,limit):
for j in range(0,limit):
for k in range(0,limit):
vol = sqrt(pow(i,2)+pow(j,2)+pow(k,2))
scalars.append(vol)
grid.append([i,j,k])
act = vp.points(grid)
pointScalars(act, scalars, 'myscalars')
vp.write(act, 'myfile.vtk')
vp.show()
#to visualize, at command line:
# > vtkplotter myfile.vtk # (then press p and k) |
can we do it without using vtkplotter import vtk
It does create the file, but I am unable to add scalars (can't find set scalar function for polydata ) |
I really wonder why you would not use the package. Anyway you can find hints in vtkplotter/utils.py (pointScalars() method). |
I am trying to create a 3D dataset (I do not want to use existing) using python.
The output will be a vtk structured data format.
The size of the dataset is user input (currently I am trying with 216*216) over a domain from -50.0 to 50.0 in a. I am calculating the scalar value at each grid location by the circle formula sqrt(xx + yy + zz)
I have written the following code but it seems to be incorrect as no file is being generated.
import vtk
import math
x=0
y=0
z=0
print("enter size of the dataset ")
limit=int(input())
for i in range(0,limit):
for j in range(0,limit):
for k in range(0,limit):
x=i
y=j
z=k
vol=math.sqrt(pow(x,2)+pow(y,2)+pow(z,2))
w=vtk.vtkDataSetWriter()
w.SetFileName('C:/Users/prakhyati/datafile1.vtk')
w.Update()
w.Write()
The text was updated successfully, but these errors were encountered: