1

I would like to do volume rendering in vtk(python) using low data of grid and scalar values.

The Data which I have is like below

#{
#   "Field Quantity": "p(x,y,z,f)"
#   "Field Quantity Units": "Pa"
#   "Snapshot Quantity": "Frequency"
#   "Snapshot Value": 10000
#   "Snapshot Units": "Hz"
#   "Column 1 Quantity": "x"
#   "Column 1 Units": "m"
#   "Column 2 Quantity": "y"
#   "Column 2 Units": "m"
#   "Column 3 Quantity": "z"
#   "Column 3 Units": "m"
#   "Column 4-5 Quantity": "Re/Im Pressure"
#   "Column 4-5 Units": ""
#   "Number Rows": 48
#}
-2.5000000000e-003  -2.5000000000e-003  1.5000000000e-003   8.9377240003e-020   3.8721174272e-020   
-1.5000000000e-003  -2.5000000000e-003  1.5000000000e-003   -9.1717825094e-020  -3.9798318526e-020  
-5.0000000000e-004  -2.5000000000e-003  1.5000000000e-003   9.1171769567e-020   4.0357725265e-020   
5.0000000000e-004   -2.5000000000e-003  1.5000000000e-003   -8.9922526510e-020  -3.8161699679e-020  
-2.5000000000e-003  -1.5000000000e-003  1.5000000000e-003   9.0017374399e-020   3.8911280410e-020   
-1.5000000000e-003  -1.5000000000e-003  1.5000000000e-003   -9.2372396377e-020  -3.9998715954e-020  
-5.0000000000e-004  -1.5000000000e-003  1.5000000000e-003   9.1826276227e-020   4.0557825425e-020   
5.0000000000e-004   -1.5000000000e-003  1.5000000000e-003   -9.0563145582e-020  -3.8351773505e-020  
-2.5000000000e-003  -5.0000000000e-004  1.5000000000e-003   9.0017820301e-020   3.8911018685e-020   
-1.5000000000e-003  -5.0000000000e-004  1.5000000000e-003   -9.2372545011e-020  -3.9998454229e-020  
-5.0000000000e-004  -5.0000000000e-004  1.5000000000e-003   9.1826315001e-020   4.0557818963e-020   
5.0000000000e-004   -5.0000000000e-004  1.5000000000e-003   -9.0562932325e-020  -3.8351886597e-020  
-2.5000000000e-003  5.0000000000e-004   1.5000000000e-003   8.9376878111e-020   3.8721167810e-020   
-1.5000000000e-003  5.0000000000e-004   1.5000000000e-003   -9.1717663535e-020  -3.9798851670e-020  
-5.0000000000e-004  5.0000000000e-004   1.5000000000e-003   9.1171659707e-020   4.0357857743e-020   
5.0000000000e-004   5.0000000000e-004   1.5000000000e-003   -8.9922416650e-020  -3.8161906474e-020  
-2.5000000000e-003  -2.5000000000e-003  2.5000000000e-003   8.9725437804e-020   3.8824497532e-020   
-1.5000000000e-003  -2.5000000000e-003  2.5000000000e-003   -9.2073900498e-020  -3.9907483749e-020  
-5.0000000000e-004  -2.5000000000e-003  2.5000000000e-003   9.1527657564e-020   4.0466754778e-020   
5.0000000000e-004   -2.5000000000e-003  2.5000000000e-003   -9.0271053891e-020  -3.8265142492e-020  
-2.5000000000e-003  -1.5000000000e-003  2.5000000000e-003   9.0368493182e-020   3.9015298373e-020   
-1.5000000000e-003  -1.5000000000e-003  2.5000000000e-003   -9.2731211817e-020  -4.0107881177e-020  
-5.0000000000e-004  -1.5000000000e-003  2.5000000000e-003   9.2184755625e-020   4.0667446243e-020   
5.0000000000e-004   -1.5000000000e-003  2.5000000000e-003   -9.0914167430e-020  -3.8455775312e-020  
-2.5000000000e-003  -5.0000000000e-004  2.5000000000e-003   9.0368480257e-020   3.9015194975e-020   
-1.5000000000e-003  -5.0000000000e-004  2.5000000000e-003   -9.2730888700e-020  -4.0107984575e-020  
-5.0000000000e-004  -5.0000000000e-004  2.5000000000e-003   9.2184787937e-020   4.0667200674e-020   
5.0000000000e-004   -5.0000000000e-004  2.5000000000e-003   -9.0914225591e-020  -3.8455720382e-020  
-2.5000000000e-003  5.0000000000e-004   2.5000000000e-003   8.9725754459e-020   3.8824584774e-020   
-1.5000000000e-003  5.0000000000e-004   2.5000000000e-003   -9.2073939272e-020  -3.9907257567e-020  
-5.0000000000e-004  5.0000000000e-004   2.5000000000e-003   9.1527748036e-020   4.0466509209e-020   
5.0000000000e-004   5.0000000000e-004   2.5000000000e-003   -9.0271047429e-020  -3.8265126336e-020  
-2.5000000000e-003  -2.5000000000e-003  3.5000000000e-003   8.9376981509e-020   3.8721439229e-020   
-1.5000000000e-003  -2.5000000000e-003  3.5000000000e-003   -9.1717960803e-020  -3.9798441311e-020  
-5.0000000000e-004  -2.5000000000e-003  3.5000000000e-003   9.1171452912e-020   4.0357815738e-020   
5.0000000000e-004   -2.5000000000e-003  3.5000000000e-003   -8.9922507123e-020  -3.8161783690e-020  
-2.5000000000e-003  -1.5000000000e-003  3.5000000000e-003   9.0017632893e-020   3.8911241636e-020   
-1.5000000000e-003  -1.5000000000e-003  3.5000000000e-003   -9.2372435151e-020  -3.9998505928e-020  
-5.0000000000e-004  -1.5000000000e-003  3.5000000000e-003   9.1826114668e-020   4.0557731721e-020   
5.0000000000e-004   -1.5000000000e-003  3.5000000000e-003   -9.0562912938e-020  -3.8351615178e-020  
-2.5000000000e-003  -5.0000000000e-004  3.5000000000e-003   9.0017445485e-020   3.8911209325e-020   
-1.5000000000e-003  -5.0000000000e-004  3.5000000000e-003   -9.2372305904e-020  -3.9998441305e-020  
-5.0000000000e-004  -5.0000000000e-004  3.5000000000e-003   9.1826256840e-020   4.0557844812e-020   
5.0000000000e-004   -5.0000000000e-004  3.5000000000e-003   -9.0563074496e-020  -3.8352038462e-020  
-2.5000000000e-003  5.0000000000e-004   3.5000000000e-003   8.9377091369e-020   3.8721109649e-020   
-1.5000000000e-003  5.0000000000e-004   3.5000000000e-003   -9.1717986653e-020  -3.9798460698e-020  
-5.0000000000e-004  5.0000000000e-004   3.5000000000e-003   9.1171782492e-020   4.0357809276e-020   
5.0000000000e-004   5.0000000000e-004   3.5000000000e-003   -8.9922468349e-020  -3.8161635056e-020  

Data was constructed as 5 columns. 1,2,3 columns is x,y,z coordination of grid.

4 column is real parts of complex number and 5 column is imaginary parts of complex number. I made absolute value using 2 columns (4,5 columns) as scalar values.

Thus I tried to do volume rendering like below. There is no error, but nothings come up in vtk window
In my opinion, there seems to be a problem in UnStructuredGrid, vtkDataSetTriangleFilter

import vtk
import numpy as np

readtxt = np.genfromtxt("ExportedFieldData.txt",skip_header=16,comments='%', missing_values='1.#QNAN00000e+000')
re = readtxt[:,3]
re[np.isnan(re)] = 0

im = readtxt[:,4]
im[np.isnan(im)] = 0

p = np.abs(re+1j*im)

print(p[2])
max_p = max(p)
print(max_p)
x = readtxt[:,0]
y = readtxt[:,1]
z = readtxt[:,2]

points = vtk.vtkPoints()
ugrid = vtk.vtkUnstructuredGrid()

pressure = vtk.vtkFloatArray()
pressure.SetNumberOfTuples(len(x))

for i in range(len(x)):
    points.InsertNextPoint(x[i], y[i], z[i])
    pressure.SetValue(i, p[i])


ugrid.SetPoints(points)
ugrid.GetPointData().SetScalars(pressure)

trifilter = vtk.vtkDataSetTriangleFilter()
trifilter.SetInputData(ugrid)

volumeMapper = vtk.vtkOpenGLProjectedTetrahedraMapper()
volumeMapper.SetInputConnection(trifilter.GetOutputPort())

opacityTransferFunction = vtk.vtkPiecewiseFunction()
opacityTransferFunction.AddPoint(10000, 0.2)
opacityTransferFunction.AddPoint(200000, 1.0)

colorTransferFunction = vtk.vtkColorTransferFunction()
colorTransferFunction.AddRGBPoint(10000, 0.0, 0.0, 1.0)
colorTransferFunction.AddRGBPoint(200000, 1.0, 0.0, 0.0)

volumeProperty = vtk.vtkVolumeProperty()
volumeProperty.SetColor(colorTransferFunction)
volumeProperty.SetScalarOpacity(opacityTransferFunction)
volumeProperty.SetScalarOpacityUnitDistance(300)
volumeProperty.ShadeOff()

volume = vtk.vtkVolume()
volume.SetMapper(volumeMapper)
volume.SetProperty(volumeProperty)


ren = vtk.vtkRenderer()
ren.AddVolume(volume)

renderer_window = vtk.vtkRenderWindow()
renderer_window.AddRenderer(ren)

style = vtk.vtkInteractorStyleTrackballCamera()


interactor = vtk.vtkRenderWindowInteractor()
interactor.SetRenderWindow(renderer_window)
interactor.SetInteractorStyle(style)
interactor.Initialize()
interactor.Start()





print(len(x))
print(readtxt)
print(p)

So, I really appreciate if you let me know the solution of this problem :) what I want to make,,

enter image description here

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.