Jump to content
Alexandre

export VDB data to a 3D matrix into a txt file

Recommended Posts

Hi everyone !

As says the title, I want to export scalar values attached to voxels (VDB) into a 3D matrix because I want to access to voxel data into another software (matlab)

does someone know how to do that ?

thanks !

Alex

Share this post


Link to post
Share on other sites
Posted (edited)

I found some startup ideas here : https://www.sidefx.com/forum/topic/56423/?page=1#post-255419

I use a py node for data export, with vdb visualize tree because the py node from the link export data geometry spread sheet

now I need to find how to reshape the vdb_float attribute (in relation to ptnum) from geometry spreadsheet in order to get a 3D matrix (basically, a matrix of 0 and 1 for a binary object)

Capture2.JPG

Capture.JPG

Edited by Alexandre

Share this post


Link to post
Share on other sites
Posted (edited)

I will try to reshape data using voxel position

 

Edited by Alexandre

Share this post


Link to post
Share on other sites
Posted (edited)

You can use hou.VDB.voxelRange() to get the array of voxel values

Use numpy to reshape it to 3d matrix

And export in the format you need

Edited by anim

Share this post


Link to post
Share on other sites

thank you !!

I have to dive a bit into python coding, but I am sure I will get much quicker to the desire result with your given functions

Share this post


Link to post
Share on other sites
Posted (edited)

Can someone help me on that ?

I am diving in python world and found some help using houdini doc : http://www.sidefx.com/docs/houdini/hom/hou/VDB.html

I have basically written the function found at the link above, and I try to use this function on my vdb volume (filled inside) but it seems that the object has no attribute 'activeVoxelBoundingBox' :/

I'm 100% sure the problem comes from me, so if someone can put me on the right track I would be grateful

thanks

 

 

Capture2.JPG

Capture.JPG

Edited by Alexandre

Share this post


Link to post
Share on other sites

You don't need to write that function as that's what hou.VDB.voxelRange() does, so just use that function

But no matter what you have to execute it on the volume prim, not the node

Share this post


Link to post
Share on other sites

here is the example

connect the Python SOP directly to the geo whose first primitive is the VDB volume you care about

import numpy

node = hou.pwd()
geo = node.geometry()

vdb = geo.iterPrims()[0]

vdbRes = vdb.resolution()
vdbBounds = vdb.activeVoxelBoundingBox()

values = vdb.voxelRange(vdbBounds)
values = numpy.array(values)
values3d = values.reshape(vdbRes, order='F')

print values3d

 

  • Like 1

Share this post


Link to post
Share on other sites
Posted (edited)

thank you very much it helps me a lot

I am learning a lot from your example

Edited by Alexandre

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×