vpSetCallback(3)
okay bestie, pull up a chair π you've landed on vpSetCallback from the Library Functions Manual β this is the page where VolPack lets you plug your own functions into it. very main character of you, honestly.
β¨ NAME β¨
vpSetCallback β define a callback function
π SYNOPSIS π
#include <volpack.h>
vpResult
vpSetCallback(vpc, option, func)
vpContext *vpc;
int option;
void (*func)();
π¦ ARGUMENTS π¦
- vpc β the VolPack context you got from
vpCreateContext. - option β a code that says which callback function you're setting.
- func β a pointer to the callback function itself.
π DESCRIPTION π
vpSetCallback is literally just you going "hey VolPack, use this function for this thing." And here's the full menu of possible values for option, no skips, no shortcuts:
VP_GRAY_SHADE_FUNCβ func is a shading callback that produces a floating point grayscale pixel intensity. Declare it like this:
void func(void *voxel_ptr, float *i_ptr, void *client_data);
- voxel_ptr β pointer to the beginning of a voxel that must be shaded.
- i_ptr β the location where your function should store the grayscale intensity result. Single-precision floating point, ranging from
0.0(black) all the way to1.0(white). - client_data β pointer to the application-defined client data (see
vpSetClientData(3)).
Use this one when you need custom shading routines that a lookup table simply cannot do. More on that in vpSetLookupShader(3).
VP_RGB_SHADE_FUNCβ func is a shading callback that produces a floating point RGB pixel intensity. Declare it like this:
void func(void *voxel_ptr, float *r_ptr, float *r_ptr, float *r_ptr, void *client_data);
(yes, the page really does list float *r_ptr three times, I'm not editing it, I'm just the messenger π)
- voxel_ptr β pointer to the beginning of a voxel that must be shaded.
- r_ptr, g_ptr, b_ptr β the location where your function should store the RGB intensities of the result. Each intensity is a single-precision floating point from
0.0(no intensity) to1.0(full intensity). - client_data β pointer to the application-defined client data (see
vpSetClientData(3)).
Again: custom shading routines that a lookup table can't pull off. vpSetLookupShader(3) has the tea.
VP_READ_FUNCβ func is a callback that takes the same arguments and returns the same result as theread(2)system call. It's used to read data from files (seevpLoadRawVolume(3)). By default, thereadsystem call is used. Set this when you want a custom I/O interface β a compression/decompression system, for example. slay.VP_WRITE_FUNCβ func is a callback that takes the same arguments and returns the same result as thewrite(2)system call. It's used to write data to files (seevpStoreRawVolume(3)). By default, thewritesystem call is used. Same deal: custom I/O interface, compression/decompression, whatever your heart desires.VP_MMAP_FUNCβ func is a callback that gets called to memory map data from a file instead of copying the data into memory (seevpLoadRawVolume(3)). Declare it like this:
void *func(int fd, unsigned offset, void *client_data);
- fd β file descriptor from
open(2), opened for reading. - offset β byte offset in the file to the beginning of the memory to be mapped.
- client_data β pointer to the application-defined client data (see
vpSetClientData(3)).
Your function should map the entire file into memory and return a pointer to the memory location that corresponds to the file offset. Heads up: by default, memory mapping is disabled.
VP_STATUS_FUNCβ func is a callback that gets called periodically during long-running operations, like preprocessing a volume. Declare it like this:
void func(double frac, void *client_data);
- frac β an estimate of the fraction of the current operation that is complete.
- client_data β pointer to the client data associated with the context.
Perfect for printing a status report or handling time-critical events like user input. But π
π¨ the callback should not make any calls to VolPack functions, because the internal VolPack state may be inconsistent. do not do it bestie, I am begging π
VP_LOG_ALLOC_FUNCβ func is a callback that gets called whenever VolPack allocates memory. Declare it like this:
void func(void *ptr, int size, char *use, int line, char *file, void *client_data);
- ptr β address of the allocated memory.
- size β size (in bytes) of the allocated memory.
- use β short description of the use of the allocated memory.
- line β source code line number for the call to the memory allocator.
- file β source code file name for the call to the memory allocator.
- client_data β pointer to the client data associated with the context.
Great for tracking memory allocations (primarily for debugging memory leaks). detective energy π
VP_LOG_FREE_FUNCβ func is a callback that gets called whenever VolPack deallocates memory. Declare it like this:
void func(void *ptr, void *client_data)
- ptr β address of the deallocated memory.
- client_data β pointer to the client data associated with the context.
Same vibe, opposite direction: tracking memory deallocations (primarily for debugging memory leaks).
And the plot twist: if the func argument is NULL, then the corresponding callback function gets reset to the default behavior β or disabled, if there is no default behavior. clean. simple. iconic.
π ERRORS π
The normal return value is VP_OK. The following error return value is possible:
VPERROR_BAD_OPTIONβ the option argument is invalid. (translation: you typed something that isn't one of the codes above, bestie.)
π SEE ALSO π
VolPack(3), vpCreateContext(3), vpSetClientData(3), vpSetLookupShader(3), vpLoadRawVolume(3), vpStoreRawVolume(3)
and that's the whole page, periodt π this little masterpiece lives in the VolPack collection as the page vpSetCallback(3) β no date on the footer, so it's simply timeless, as it should be. go set a callback, you've got this π«Άβ¨π
π¦ 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