Default value field
Within the addon a function is defined which can produce a standard value field. This field is used in the example animations to color Suzanne.Code
The code of this function is quite straightforward:def fillLat():
maxValue = 3.5
lat = Lattice((30,30,30),(-1.0,-1.0,-1.0),(3.0,3.0,3.0))
for z in range(lat.dim[2]) :
for y in range(lat.dim[1]) :
for x in range(lat.dim[0]) :
wp = lat.discreteToWorld((x,y,z))
d = math.sqrt(wp[0]*wp[0] + wp[1]*wp[1] + wp[2]*wp[2])
lat.setValue(maxValue - d,(x,y,z))
lat.min = 0.0
lat.max = maxValue
return lat
Here a couple of things happen
- maxValue is defined to be 3.5
- We create a Lattice defined by three tuples
- Number of voxels in each direction
- Position of first corner of the total data field in the world coordinates (global coordinate system)
- Extent of the total data field
- Loop over all dimensions, to handle every voxel
- Get the position of the (center of the) current voxel in the world coordinates (wp)
- Calculate the distance (d) of the current voxel relative to (0,0,0)
- Set the value of the current voxel to the defined maximum minus the distance
- Set the minimum value to 0.0; this value can be used to initialize the colormap
- Set the maximum value to maxValue; this value can be used to initialize the colormap
- Return the create lattice
radth-packages/radthlib/lattice.py
When another default value field is requested, this function must be re-implemented, or such a lattice can be read from a pickle file.