HDK
|
A 3D texture map is similar to a 2D texture. However in addition to having an x
and y
resolution the texture has a z
resolution as well (turning the pixels into voxels).
Like modern 2D images, the 3D texture files can have any number of image channels with arbitrary vector sizes per pixel.
Unlike 2D images, the 3D texture image has a bounding box. The voxel (0, 0, 0)
is mapped to the xmin()
, ymin()
, and zmin()
of the bounding box. The voxel at (xres-1, yres-1, zres-1)
is mapped to the maximum values of the bounding box. Evaluations of the 3D texture have their lookup position transformed to this bounding box.
The Houdini 3D texture format is a tiled format. When reading voxels from the image, only portions of the file need to be loaded into RAM at one time. This makes it possible to read very large images. On the other hand, it means that writing the images can be problematic. Often, the data you want to write to the file is not tiled, which makes it difficult to process.
The 3D texture format can store "tags" in the texture file. These tags are arbitrary and can be used to store auxiliary information. Users can query these tags from VEX using the teximport()
function.
The IMG3D_Manager class is used to read data from a 3D texture. Each instance of an IMG3D_Manager is able to read values from a single channel of a 3D texture.
To read multiple channels, the best approach is to have an IMG3D_Manager for each channel to be read.
To open a 3D texture the texture file needs to be opened, but the channel also needs to be opened:
After the file is open (before the channel is open), it is possible to query properties of the texture.
The IMG3D_Manager class provides several ways of accessing channel data. Most methods will perform filtering of the texture. The filter can be set by calling IMG3D_Manager::setFilter().
result
buffer should be able to store 3 floats.In addition, it's possible to load an entire channel at one time by calling IMG3D_Manager::loadUntiledChannel().
As mentioned in the introduction, the 3D texture format is a tiled format. The native process for writing 3D textures is to allow the IMG3D_Manager to call an evaluation callback. This is appropriate when the generation function is procedural and there's no issue with random access of the 3D image.
However, in many cases, it isn't feasible to fill a texture in random order. So, like the IMG3D_Manager::loadUntiledChannel(), it's possible to create a 3D texture with a flat image by calling IMG3D_Manager::fillUntiledTexture().
To create an 3D texture, you must first call IMG3D_Manager::createTexture(). This specifies the bounding box, resolution and a compression.
Once the 3D texture has been created, you can call either:
The sample file standalone/i3dsphere.C shows a very simple example of creating a 3D texture.