With the following code I can easily create an Vectorfield of a volume ..
import numpy
# This code is called when instances of this SOP cook.
geo = hou.pwd().geometry()
volume = geo.prims()
np = numpy.array(volume.allVoxels()).reshape(volume.resolution())
npVectorField = numpy.gradient(np)
….
volume.setAllVoxels( np.flatten() )
But how could i get the vector field back as Hou Vector field ??
Or the other way round .. how would I get a numpy array of a Hou-Vector field ?
I need to do some processing of a gradient vector field in scipy and write it back to houdini for visualization ..
Gradient Vector Field <-> Numpy
8043 4 2-
- dulo
- Member
- 383 posts
- Joined: June 2010
- Offline
-
- koen
- Member
- 795 posts
- Joined: April 2020
- Offline
Houdini currently does not support true vector grids. Vector volumes are represented as 3 scalar volumes.
If the vector is your first volume, you can extend your current code with:
volume.x = geo.prims()
volume.y = geo.prims()
volume.z = geo.prims()
Of course the numbers of the prims you'll have to check in your setup.
similar on the way back.
One thing to double check (when you are working with velocities) is if the grids are collocated or staggered. When they are staggered, converting to a vector is a bit harder then just sticking the 3 floats in a vector. This usually happens as the output of a fluid sim. (in H12, you can switch you sim to be collocated to work around this.)
Hope that helps,
Koen
ps. If it is just the gradient you are after, you can use the “volume analysis” sop, or a volume vop to calculate this.
If the vector is your first volume, you can extend your current code with:
volume.x = geo.prims()
volume.y = geo.prims()
volume.z = geo.prims()
Of course the numbers of the prims you'll have to check in your setup.
similar on the way back.
One thing to double check (when you are working with velocities) is if the grids are collocated or staggered. When they are staggered, converting to a vector is a bit harder then just sticking the 3 floats in a vector. This usually happens as the output of a fluid sim. (in H12, you can switch you sim to be collocated to work around this.)
Hope that helps,
Koen
ps. If it is just the gradient you are after, you can use the “volume analysis” sop, or a volume vop to calculate this.
-
- dulo
- Member
- 383 posts
- Joined: June 2010
- Offline
-
- dulo
- Member
- 383 posts
- Joined: June 2010
- Offline
With the following Code I get a vector field from numpy/scipy to houdini. The code works and I end up with an object with three volumes in which the three components of the 3D vectorfield are stored. The objects looks identical to a vectorfield for example generated with the analysis node, but houdini doesnt seem to treat my numpy vectorfield as one. I guess I have to name the components in a special way to make it work with gradient visualization node or dynamic nodes, etc ..
I couldnt find any documentation about this. Maybe someone has a clou what to do ?
import numpy
# This code is called when instances of this SOP cook.
node = hou.pwd()
geo = node.geometry()
# Add code to modify the contents of geo.
filePath = hou.Node.evalParm(node, “parmFilePath”)
data = numpy.load(filePath)
data = data
data = data.astype(numpy.float64)
dimensions = data.shape
xres = dimensions
yres = dimensions
zres = dimensions
volume_bbox = hou.BoundingBox(0, 0, 0,xres , yres, zres)
volumeX = geo.createVolume( xres, yres, zres, volume_bbox)
volumeX.setAllVoxels (data.flatten(order='F'))
volumeY = geo.createVolume( xres, yres, zres, volume_bbox)
volumeY.setAllVoxels (data.flatten(order='F'))
volumeZ = geo.createVolume( xres, yres, zres, volume_bbox)
volumeZ.setAllVoxels (data.flatten(order='F'))
I couldnt find any documentation about this. Maybe someone has a clou what to do ?
import numpy
# This code is called when instances of this SOP cook.
node = hou.pwd()
geo = node.geometry()
# Add code to modify the contents of geo.
filePath = hou.Node.evalParm(node, “parmFilePath”)
data = numpy.load(filePath)
data = data
data = data.astype(numpy.float64)
dimensions = data.shape
xres = dimensions
yres = dimensions
zres = dimensions
volume_bbox = hou.BoundingBox(0, 0, 0,xres , yres, zres)
volumeX = geo.createVolume( xres, yres, zres, volume_bbox)
volumeX.setAllVoxels (data.flatten(order='F'))
volumeY = geo.createVolume( xres, yres, zres, volume_bbox)
volumeY.setAllVoxels (data.flatten(order='F'))
volumeZ = geo.createVolume( xres, yres, zres, volume_bbox)
volumeZ.setAllVoxels (data.flatten(order='F'))
-
- dulo
- Member
- 383 posts
- Joined: June 2010
- Offline
-
- Quick Links

