vpSetVoxelField(3)
vpSetVoxelField π (and its bestie vpFieldOffset)
okay so bestie, welcome to the Library Functions Manual section for vpSetVoxelField(3) β this is the one where you tell VolPack what your voxels actually look like inside. let's get into it π«Ά
β¨ NAME β¨
vpSetVoxelField, vpFieldOffset β define the size and location of a voxel field π
πΈ SYNOPSIS πΈ
#include <volpack.h>
vpResult
vpSetVoxelField(vpc, field_num, field_size, field_offset, field_max)
vpContext *vpc;
int field_num;
int field_size;
int field_offset;
int field_max;
int
vpFieldOffset(voxel_ptr, field_name)
vpContext *vpc;
LITERAL field_name;
π ARGUMENTS π
vpcβ the VolPack context, the one you got fromvpCreateContext. your whole world basically πfield_numβ which field you're defining (number it up! the first field is0, no cap)field_sizeβ how big the field is, in bytesfield_offsetβ how many bytes from the beginning of the voxel to the beginning of the fieldfield_maxβ the biggest value that field could ever possibly bevoxel_ptrβ pointer to a C structure that defines the fields inside the voxelfield_nameβ the literal name of the voxel field, as written in that C structure
π¦ DESCRIPTION π¦
so vpSetVoxelField is literally you going "here's how big each field in my voxel is and here's where it lives." that's it, that's the job β¨
once you've picked your sizes and your order for the voxel fields, you call vpSetVoxelSize once, and then you call vpSetVoxelField once for every single field. every field gets its own unique field number β that's the field_num argument. first field is 0, next one is 1, and so on, all the way up to one less than the total number of fields you defined with VpSetVoxelSize. π yes it's a lot of calls. you got this.
the field_max argument? that's what gets used to figure out how big your lookup tables need to be, since those tables are indexed by the value in a particular field. and the max field value can be any number from 0 to the maximum unsigned integer representable by the field size. so like, don't get cute with it.
π using a C struct (the iconic move) π
if you declared your voxel layout using a C structure, then you can just use the sizeof operator plus the vpFieldOffset macro to compute field sizes and offsets for you. vpFieldOffset returns the number of bytes from the beginning of a C structure to the beginning of a particular field inside it. periodt.
for example, here's how you'd 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 rules (do not skip these) π₯
- the size of each field must be
1,2or4bytes. those are the options, bestie. - you also have to obey any byte-alignment restrictions your hardware demands. on many machines, two-byte fields have to start on a two-byte boundary, and four-byte fields have to start on a four-byte boundary.
- the total size of a voxel may also need padding so that voxels packed one after the other still respect those alignment restrictions.
- if you declare your voxel as a C structure and use the
sizeofoperator and thevpFieldOffsetmacro, you should always get correct results. π - however β if you don't think about alignment restrictions when you pick your voxel field ordering, the compiler may have to insert padding for you, and that means wasted memory. π tragic. avoid.
β fields that VolPack routines actually need β
some VolPack routines require you to declare fields of a particular size so they have somewhere to store their results. the functions that precompute surface normals and gradient magnitudes (see vpVolumeNormals(3), vpScanlineNormals(3), vpClassifyVolume(3), vpClassifyScalars(3) and vpClassifyScanline(3)) can optionally store, in each voxel:
- a one-byte scalar value
- a one-byte gradient magnitude
- a two-byte surface normal value
these constants defined in volpack.h give you the matching maximum field values: VP_SCALAR_MAX, VP_GRAD_MAX, and VP_NORM_MAX. π«Ά
and if you decide not to use those functions at all? then there's literally no need to declare those fields. slay, save the bytes.
π§ a lil opacity note π§
it's 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. iykyk π
β οΈ heads up bestie: if the call to vpSetVoxelSize succeeds, any existing precomputed volume data structures in the context are destroyed. gone. poof. π
π STATE VARIABLES π
you can retrieve the current voxel field parameters with these state variable codes (see vpGeti(3)):
VP_FIELD_SIZESVP_FIELD_OFFSETSVP_FIELD_MAXES
π ERRORS π
the normal return value is VP_OK. β¨
this error return value is possible:
VPERROR_BAD_VALUEβ the field number, size or offset is out of range. (something's off, check your numbers bestie π)
π SEE ALSO π
VolPack(3), vpCreateContext(3), vpSetVoxelSize(3)
and that's the whole page, no notes π this was brought to you by the VolPack library manual β the vpSetVoxelField(3) page, straight from the Library Functions Manual, courtesy of VolPack. go set some voxel fields, you absolute icon πΈπ¦β¨
π¦ where this page comes from
- debian bookworm: libvolpack1-dev 1.0b3-9 Β· BSD-3-Clause
- debian trixie: libvolpack1-dev 1.0b3-10 Β· BSD-3-Clause
- ubuntu jammy: libvolpack1-dev 1.0b3-9 Β· BSD-3-Clause
- ubuntu noble: libvolpack1-dev 1.0b3-9.1 Β· BSD-3-Clause
- ubuntu questing: libvolpack1-dev 1.0b3-11
- ubuntu resolute: libvolpack1-dev 1.0b3-11build1 Β· BSD-3-Clause
- ubuntu stonking: libvolpack1-dev 1.0b3-11build1 Β· BSD-3-Clause
- Copyright (c) 1994 The Board of Trustees of The Leland Stanford
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms