vpSetVoxelField(3) | Library Functions Manual | vpSetVoxelField(3) |
vpSetVoxelField, vpFieldOffset - define the size and location of a voxel field
#include <volpack.h>
vpResult
vpSetVoxelField(vpc, field_num, field_size, field_offset, field_max)
int
vpFieldOffset(voxel_ptr, field_name)
vpSetVoxelField is used to define the size and location of each field in a voxel. Once you have chosen the sizes and order for the voxel fields, call vpSetVoxelSize once and then call vpSetVoxelField once for each field. Each field has a unique field number (the field_num argument); the first field is 0, the next is 1, and so on, up to one less than the total number of fields defined with VpSetVoxelSize. The field_max argument is used to determine the required size for lookup tables indexed by the value in a particular field; the maximum field value may be any number from 0 to the maximum unsigned integer representable by the field size.
If you have declared the layout of a voxel using a C structure then you can use the sizeof operator and the vpFieldOffset macro to compute the field sizes and offsets. vpFieldOffset returns the number of bytes from the beginning of a C structure to the beginning of a particular field in the structure. For example, the following code shows how to declare the size and offset for one voxel field:
struct voxel {
char field0;
char field1;
short field2; } *dummy_voxel; #define SIZE_0 sizeof(char) #define OFFSET_0 vpFieldOffset(dummy_voxel, field0) #define MAX_0 127 vpSetVoxelField(vpc, 0, SIZE_0, OFFSET_0, MAX_0);
The size of each field must be 1, 2 or 4 bytes. You must also obey any byte-alignment restrictions required by your hardware. On many machines, two-byte fields must begin on a two-byte boundary and four-byte fields must begin on a four-byte boundary. The total size of a voxel may also need to be padded so that voxels packed one after the other still obey the alignment restrictions. If you declare your voxel as a C structure and use the sizeof operator and the vpFieldOffset macro then you should always get correct results. However, if you do not consider alignment restrictions when choosing the voxel field ordering the compiler may have to insert padding for you, resulting in wasted memory.
Some of the VolPack routines require you to declare fields of a particular size in order to store their results. The functions to precompute surface normals and gradient magnitudes (see vpVolumeNormals(3), vpScanlineNormals(3), vpClassifyVolume(3), vpClassifyScalars(3) and vpClassifyScanline(3)) can optionally store a one-byte scalar value, a one-byte gradient magnitude, and a two-byte surface normal value in each voxel. The following constants defined in volpack.h give the corresponding maximum field values: VP_SCALAR_MAX, VP_GRAD_MAX, and VP_NORM_MAX. If you choose not to use these functions then there is no need to declare these fields.
It is usually not necessary to declare a field for the voxel opacity if the opacity can be computed from the other voxel fields. See vpSetClassifierTable(3) for further discussion.
If the call to vpSetVoxelSize succeeds, any existing precomputed volume data structures in the context are destroyed.
The current voxel field parameters can be retrieved with the following state variable codes (see vpGeti(3)): VP_FIELD_SIZES, VP_FIELD_OFFSETS, VP_FIELD_MAXES.
The normal return value is VP_OK. The following error return value is possible:
VolPack |