Ejemplo n.º 1
0
def main():
    if len(sys.argv) < 2:
        print("Usage: ", sys.argv[0], "file.raw")
        return

    file = vkt.RawFile(sys.argv[1], "r")

    dims = file.getDims()
    if dims.x * dims.y * dims.y < 1:
        print("Cannot parse dimensions from file name")
        return

    bpv = file.getBytesPerVoxel()
    if bpv == 0:
        print("Cannot parse bytes per voxel from file name, guessing 1...")
        bpv = 1

    volume = vkt.StructuredVolume(dims.x, dims.y, dims.z, bpv)
    ips = vkt.InputStream(file)
    ips.read(volume)

    rgba = [
        1., 1., 1., .005, 0., .1, .1, .25, .5, .5, .7, .5, .7, .7, .07, .75,
        1., .3, .3, 1.
    ]
    lut = vkt.LookupTable(5, 1, 1, vkt.ColorFormat_RGBA32F)
    lut.setData(rgba)

    rs = vkt.RenderState()
    #rs.renderAlgo = vkt.RenderAlgo_RayMarching
    #rs.renderAlgo = vkt.RenderAlgo_ImplicitIso
    rs.renderAlgo = vkt.RenderAlgo_MultiScattering
    rs.rgbaLookupTable = lut.getResourceHandle()
    vkt.Render(volume, rs)
Ejemplo n.º 2
0
def main():
    if len(sys.argv) < 2:
        print("Usage: ", sys.argv[0], "file.raw")
        return

    file = vkt.RawFile(sys.argv[1], "r")

    dims = file.getDims()
    if dims.x * dims.y * dims.y < 1:
        print("Cannot parse dimensions from file name")
        return

    bpv = file.getBytesPerVoxel()
    if bpv == 0:
        print("Cannot parse bytes per voxel from file name, guessing 1...")
        bpv = 1

    volume = vkt.StructuredVolume(dims.x, dims.y, dims.z, bpv)
    ips = vkt.InputStream(file)
    ips.read(volume)

    # Print statistics for the whole volume
    aggr = vkt.Aggregates()
    vkt.ComputeAggregates(volume, aggr)
    printStatistics(aggr, 0, 0, 0, dims.x, dims.y, dims.z)
    print('\n')

    # Compute a brick decomposition and print per-brick statistics
    brickSize = vkt.Vec3i()
    brickSize.x = 100
    brickSize.y = 100
    brickSize.z = 100

    decomp = vkt.Array3D_StructuredVolume()
    vkt.BrickDecomposeResize(decomp, volume, brickSize)
    vkt.BrickDecompose(decomp, volume, brickSize)

    for z in range(0, decomp.dims().z):
        for y in range(0, decomp.dims().y):
            for x in range(0, decomp.dims().x):
                firstX = x * brickSize.x
                firstY = y * brickSize.y
                firstZ = z * brickSize.z
                lastX = min(volume.getDims().x, firstX + brickSize.x)
                lastY = min(volume.getDims().y, firstY + brickSize.y)
                lastZ = min(volume.getDims().z, firstZ + brickSize.z)
                aggr = vkt.Aggregates()
                # Compute aggregates only for the brick range
                vkt.ComputeAggregatesRange(volume, aggr, firstX, firstY,
                                           firstZ, lastX, lastY, lastZ)
                printStatistics(aggr, firstX, firstY, firstZ, lastX, lastY,
                                lastZ)
                print('\n')
Ejemplo n.º 3
0
def main():

    #--- Create a volume ----------------------------------

    bpv = 1
    mappingLo = 0.
    mappingHi = 1.
    distX = 1.
    distY = 1.
    distZ = 1.

    volume = vkt.StructuredVolume(8, 8, 8, bpv, distX, distY, distZ, mappingLo,
                                  mappingHi)

    # Fill the volume
    vkt.Fill(volume, .02)

    #--- ScanRange-----------------------------------------

    # Note how dst and src are the same
    vkt.ScanRange(
        volume,  # dst
        volume,  # src
        0,
        0,
        0,
        4,
        4,
        4,
        0,
        0,
        0)

    # In the following, some components of first > last
    vkt.ScanRange(volume, volume, 7, 0, 0, 3, 4, 4, 0, 0, 0)

    vkt.ScanRange(volume, volume, 0, 7, 0, 4, 3, 4, 0, 0, 0)

    vkt.ScanRange(volume, volume, 0, 0, 7, 4, 4, 3, 0, 0, 0)

    vkt.ScanRange(volume, volume, 7, 7, 0, 3, 3, 4, 0, 0, 0)

    vkt.ScanRange(volume, volume, 0, 7, 7, 4, 3, 3, 0, 0, 0)

    vkt.ScanRange(volume, volume, 7, 0, 7, 3, 4, 3, 0, 0, 0)

    vkt.ScanRange(volume, volume, 7, 7, 7, 3, 3, 3, 0, 0, 0)

    #--- Render -------------------------------------------

    # Render volume
    renderState = vkt.RenderState()
    vkt.Render(volume, renderState)
Ejemplo n.º 4
0
def main():
    dims = vkt.Vec3i()
    dims.x = 32
    dims.y = 32
    dims.z = 32

    bpv = 1
    volume1 = vkt.StructuredVolume(dims.x, dims.y, dims.z, bpv)

    # CPU rendering
    renderState = vkt.RenderState()
    renderState.renderAlgo = vkt.RenderAlgo_MultiScattering
    vkt.Render(volume1, renderState)
Ejemplo n.º 5
0
def main():
    dims = vkt.Vec3i()
    dims.x = 32
    dims.y = 32
    dims.z = 32

    dataFormat = vkt.DataFormat_UInt8
    volume1 = vkt.StructuredVolume(dims.x, dims.y, dims.z, dataFormat)

    # CPU rendering
    renderState = vkt.RenderState()
    renderState.renderAlgo = vkt.RenderAlgo_MultiScattering
    vkt.Render(volume1, renderState)
Ejemplo n.º 6
0
def main():
    # Volume dimensions
    dims = vkt.Vec3i()
    dims.x = 120
    dims.y = 66
    dims.z = 49

    # Brick size
    brickSize = vkt.Vec3i()
    brickSize.x = 16
    brickSize.y = 16
    brickSize.z = 16

    # Halo / ghost cells
    haloSizeNeg = vkt.Vec3i()
    haloSizeNeg.x = 1
    haloSizeNeg.y = 1
    haloSizeNeg.z = 1
    haloSizePos = vkt.Vec3i()
    haloSizePos.x = 1
    haloSizePos.y = 1
    haloSizePos.z = 1

    dataFormat = vkt.DataFormat_UInt8

    mappingLo = 0.
    mappingHi = 1.

    distX = 1.
    distY = 1.
    distZ = 1.

    volume = vkt.StructuredVolume(dims.x, dims.y, dims.z, dataFormat, distX,
                                  distY, distZ, mappingLo, mappingHi)

    # Put some values in
    vkt.Fill(volume, .1)

    # The destination data structure
    decomp = vkt.Array3D_StructuredVolume()

    # Preallocate storage for the decomposition
    vkt.BrickDecomposeResize(decomp, volume, brickSize, haloSizeNeg,
                             haloSizePos)

    # Compute the decomposition
    vkt.BrickDecompose(decomp, volume, brickSize, haloSizeNeg, haloSizePos)

    vkt.Render(decomp[vkt.Vec3i()])
Ejemplo n.º 7
0
def main():
    if len(sys.argv) < 2:
        print("Usage: ", sys.argv[0], "file.raw")
        return
  
    file = vkt.VolumeFile(sys.argv[1], vkt.OpenMode_Read)

    hdr = file.getHeader()

    if not hdr.isStructured:
        print("No valid volume file\n")
        return

    dims = hdr.dims
    if dims.x * dims.y * dims.y < 1:
        print("Cannot parse dimensions from file name")
        return

    bpv = hdr.bytesPerVoxel
    if bpv == 0:
        print("Cannot parse bytes per voxel from file name, guessing 1...")
        bpv = 1

    volume = vkt.StructuredVolume(dims.x, dims.y, dims.z, bpv)
    ips = vkt.InputStream(file)
    ips.read(volume)

    rgba = [
        1., 1., 1., .005,
        0., .1, .1, .25,
        .5, .5, .7, .5,
        .7, .7, .07, .75,
        1., .3, .3, 1.
        ]
    lut = vkt.LookupTable(5,1,1,vkt.ColorFormat_RGBA32F)
    lut.setData(rgba)

    # Switch execution to GPU (remove those lines for CPU rendering)
    ep = vkt.GetThreadExecutionPolicy()
    ep.device = vkt.ExecutionPolicy.Device_GPU
    vkt.SetThreadExecutionPolicy(ep)

    rs = vkt.RenderState()
    #rs.renderAlgo = vkt.RenderAlgo_RayMarching
    #rs.renderAlgo = vkt.RenderAlgo_ImplicitIso
    rs.renderAlgo = vkt.RenderAlgo_MultiScattering
    rs.rgbaLookupTable = lut.getResourceHandle()
    vkt.Render(volume, rs)
Ejemplo n.º 8
0
def main():
    # Create a structured volume
    dims = vkt.Vec3i()
    dims.x = 256
    dims.y = 128
    dims.z = 100

    dataFormat = vkt.DataFormat_UInt8
    volume = vkt.StructuredVolume(
            dims.x, dims.y, dims.z,
            dataFormat,
            1., 1., 1., # dist
            0., 1. # mapping
            )

    vkt.Fill(volume, .1)

    vkt.FillRange(
            volume,
            64,4,4,
            192,124,96,
            1.
            )

    # Destination volume; has the same size as the original one
    rotatedVolume = vkt.StructuredVolume(
            dims.x, dims.y, dims.z,
            dataFormat,
            1., 1., 1.,
            0., 1.
            )

    vkt.Fill(rotatedVolume, .1)

    # Rotate the volume with rotation center in the middle
    axis = vkt.Vec3f()
    axis.x = 1.
    axis.y = .3
    axis.z = 0.
    angleInRadians = 45.*math.pi/180
    centerOfRotation = vkt.Vec3f()
    centerOfRotation.x = dims.x * .5
    centerOfRotation.y = dims.y * .5
    centerOfRotation.z = dims.z * .5
    vkt.Rotate(
            rotatedVolume,
            volume,
            axis,
            angleInRadians,
            centerOfRotation
            )

    rgba = [
        1., 1., 1., .005,
        0., .1, .1, .25,
        .5, .5, .7, .5,
        .7, .7, .07, .75,
        1., .3, .3, 1.
        ]
    lut = vkt.LookupTable(5,1,1,vkt.ColorFormat_RGBA32F)
    lut.setData(rgba)

    renderState = vkt.RenderState()
    renderState.renderAlgo = vkt.RenderAlgo_MultiScattering
    renderState.rgbaLookupTable = lut.getResourceHandle();
    vkt.Render(rotatedVolume, renderState)