 |
Demonstration of VisAd's volume rendering capabilities
Source code name: "visad_3D_render.py"
Programming language: Python
Topic: Plots/3D
DMelt Version 1.9. Last modified: 07/08/2017. License: Pro
https://datamelt.org/code/cache/visad_3D_render_7724.py
To run this script using the DMelt IDE,
copy the above URL link to the menu [File]→[Read script from URL] of the DMelt IDE.
from javax.swing import *
from visad import FlatField,Display,Linear3DSet,RealTupleType,FunctionType,ScalarMap,RealType
from visad import DataReferenceImpl
from jhplot import *
from java.lang import Math
c1=HVisAd("3D")
display=c1.getDisplay()
# create types
x,y,z=RealType("x"),RealType("y"), RealType("z")
xyz = RealTupleType(x, y, z)
value = RealType.getRealType("value")
# generate some regular samples
size = 32
count = size * size * size
xset = Linear3DSet(xyz,0, 1000, size, 0, 1000, size, 0, 1000, size)
samples = xset.getSamples(False)
# build field
ftype = FunctionType(xyz, value)
field = FlatField(ftype, xset)
sss=[]
for i in range(count):
d= 1500 - (Math.abs(samples[0][i] - 500) + Math.abs(samples[1][i] - 500) + Math.abs(samples[2][i] - 500))
sss.append(d)
values=[]
values.append([sss][0])
field.setSamples(values, False)
# create display
display.getGraphicsModeControl().setPointSize(4.0)
display.addMap(ScalarMap(x, Display.XAxis))
display.addMap(ScalarMap(y, Display.YAxis))
display.addMap(ScalarMap(z, Display.ZAxis))
color = ScalarMap(value, Display.RGBA)
display.addMap(color)
# assign alpha channel
cc = color.getControl()
def tweakAlpha(table):
xpow = 2
xlen = len(table[3])
for i in range(xlen):
table[3][i] = Math.pow( i/float(xlen), xpow)
return table
cc.setTable(tweakAlpha(cc.getTable()))
# add data to display
ref = DataReferenceImpl("ref")
ref.setData(field)
display.addReference(ref)
c1.visible()
You see the box below because you did not login.