FANDOM


import numpy

import scipy

import scipy.ndimage

# This code is called when instances of this SOP cook.

geo = hou.pwd().geometry()

# Add code to modify the contents of geo.

prim_number = hou.pwd().parm("prim_number").eval()

volume = geo.prims()[prim_number]

np = numpy.array(volume.allVoxels()).reshape(volume.resolution(), order='F')

# Now we have our numpy 3d array... have fun!

#outFile = file('t:\\numpy.npy','w+')

#numpy.save(outFile,np)

#outFile.close ()

#print volume.resolution()

if hou.pwd().parm("do_gaussian").eval():

  sigma= hou.pwd().parm("gaussian_sigma").eval()

  np = scipy.ndimage.filters.gaussian_filter( np, sigma, mode='nearest' )


if hou.pwd().parm("do_uniform").eval():

  uniform_size = hou.pwd().parm("uniform_size").eval()

  np = scipy.ndimage.filters.uniform_filter( np, uniform_size  )


if hou.pwd().parm("do_sobel").eval():

  np = scipy.ndimage.filters.sobel( np  )


if hou.pwd().parm("do_prewitt").eval():

  np = scipy.ndimage.filters.prewitt( np  )


if hou.pwd().parm("do_abs").eval():

  np = abs(np)


if hou.pwd().parm("parmSaveNumpy").eval():

    path = hou.pwd().parm("parmPath").eval()

    out = file(path,'w+')

    npflat = np.flatten(order='F')

    #npflat = numpy.multiply(npflat,255)

    #npflat = numpy.where(npflat > 128, numpy.uint8(255), numpy.uint8(0))

    numpy.save(out,npflat)

    out.close()

# set the values of the volume back in Houdini

volume.setAllVoxels( np.flatten(order='F') )