FANDOM


import sys

import toolutils

# some simple enum definitions

Red, Green, Blue, Alpha = range (4)

Color, Alpha, Depth, Normal = range (4)

planeLabels     = ['Color','Alpha','Depth','Normal']

planeToken      = ["C","A","Pz","N"]

componentLabels = ['All','Red','Green','Blue']

componentToken  = ['none','r','g','b']

#mymodule = toolutils.createModuleFromSection( 'PythonModule_BuildVolume',kwargs['type'], 'PythonModule_BuildVolume')

def buildVolumeFromCopSequence(cop_node, geo, plane, component, iStartFrame, iEndFrame):

    xres = cop_node.xRes()

    yres = cop_node.yRes()

    zres = iEndFrame - iStartFrame

    #print "XRes x YRes: " + str(xres) + " x " + str(yres) 

    #print "Sequence Length: " + str(zres)

volume_bbox = hou.BoundingBox(0, 0, 0,xres , yres, zres)

    volume = geo.createVolume( xres, yres, zres, volume_bbox)

#    try:

#        for z in range(iStartFrame, iEndFrame):

#            #print "index: " + str(z)

#            pixels = cop_node.allPixelsAsString( plane, component,time=hou.frameToTime(z + cop_node.sequenceStartFrame()))

#            volume.setVoxelSliceFromString(pixels, "xy", z - iStartFrame)

#            if hou.updateProgressAndCheckForInterrupt():

#                break

#     except:

#        raise hou.NodeError(str(sys.exc_info()[1]) + " \ncop_node.allPixelsAsString failed. For grayscale (dcm) set component All and for RGB set Red,Green or Blue.")

#    

    with hou.InterruptableOperation(

        "Performing Tasks", open_interrupt_dialog=True) as operation:

        for z in range(iStartFrame, iEndFrame):

            #

            # PERFORM TASK HERE.

            #

            pixels = cop_node.allPixelsAsString( plane, component,time=hou.frameToTime(z + cop_node.sequenceStartFrame()))

            volume.setVoxelSliceFromString(pixels, "xy", z - iStartFrame)

            # Update operation progress.

            percent = float(z) / zres

            operation.updateProgress(percent)


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

node = hou.pwd()

geo = node.geometry()