vpLoadRawVolume(3)

๐Ÿ’พ vpLoadRawVolume(3) โ€” the load-your-volume-data-up era โœจ

okay bestie, so this is a page from the Library Functions Manual for VolPack, and it's literally all about loading volume data structures from a file into your rendering context. it's giving "let me pull up your whole vibe from disk" energy and honestly? iconic. ๐Ÿซถ


๐ŸŒธ NAME ๐ŸŒธ

vpLoadRawVolume, vpLoadMinMaxOctree, vpLoadClassifiedVolume, vpLoadContext โ€” load volume data structures from a file


โœจ SYNOPSIS โœจ

#include <volpack.h>

vpResult
vpLoadRawVolume(vpc, fd)
    vpContext *vpc;
    int fd;

vpResult
vpLoadMinMaxOctree(vpc, fd)
    vpContext *vpc;
    int fd;

vpResult
vpLoadClassifiedVolume(vpc, fd)
    vpContext *vpc;
    int fd;

vpResult
vpLoadContext(vpc, fd)
    vpContext *vpc;
    int fd;

๐ŸŽ€ ARGUMENTS ๐ŸŽ€

  • vpc โ€” the VolPack context, the one you got from vpCreateContext. your main character fr.
  • fd โ€” a file descriptor from open(2), and it needs to be opened for reading. no write-mode nonsense here, bestie.

๐Ÿ’– DESCRIPTION ๐Ÿ’–

so like, these functions are how you load volume data structures into a rendering context, from files that were written in the format produced by the VolPack file storing routines (peep vpStoreRawVolume(3) for that side of the story).

vpLoadRawVolume loads a 3D voxel array file. the file is carrying info about the size of the volume and the layout of the voxels, plus the volume data itself. a new voxel array gets allocated, the data gets read into that array, and the array gets stashed in the rendering context. ๐Ÿซง

lowkey important: that array will not be freed automatically when the context is destroyed. no cap. the application is responsible for freeing the array when appropriate โ€” by using vpGetp with the VP_VOXEL_DATA state variable code to retrieve the array pointer โ€” or for unmapping the voxel array if it's been memory mapped (see below). don't leave it hanging, bestie. ๐Ÿ˜ญ

any existing min-max octree or preclassified volume data gets destroyed the moment vpLoadRawVolume is called. gone. the info loaded from the file includes all the parameters set with vpSetVolumeSize, vpSetVoxelSize, vpSetVoxelField and vpSetRawVoxels. and the data in the file gets automatically byte-swapped if the file was written on an architecture with a different byte ordering than the current architecture โ€” a magic constant in the file is what decides if byte-swapping is necessary. ๐Ÿ”ฎ

but heads up: volume fields that were not explicitly declared (by calling vpSetVoxelField before storing the voxel array file) cannot be byte-swapped. periodt.

vpLoadMinMaxOctree loads a min-max octree file. the current 3D voxel array size and voxel layout must match the data in the octree file before the file is loaded โ€” consistency checks are performed, so no sneaking mismatched data past it. ๐Ÿ‘€ any existing octree is destroyed and the new octree is stored in the rendering context. byte-swapping happens if it's necessary.

vpLoadClassifiedVolume loads a preclassified volume data file. the file includes info about the size of the volume and the layout of the voxels, plus the volume data itself. here's the vibe check:

  • if the volume matches the size and layout of any existing volume data in the rendering context, then the data in the file replaces only the current preclassified volume.
  • otherwise, the old octree is destroyed, the 3D voxel array parameters are zeroed out, and the new size and layout parameters get loaded.

the info loaded from the file includes all the parameters set with vpSetVolumeSize, vpSetVoxelSize and vpSetVoxelField. byte-swapping is performed if necessary. ๐Ÿ’…

vpLoadContext loads a rendering context file. the file includes all rendering parameters except volume data and callback functions. the contents of any lookup tables for shading and classification are also loaded. any existing preclassified volume data or octree are destroyed, and the 3D voxel array parameters pointer is zeroed out. the lookup tables get loaded into dynamically allocated arrays, and โ€” again, saying it louder for the people in the back โ€” the application is responsible for freeing those arrays when necessary; they are not automatically freed when vpDestroyContext is called. ๐Ÿ˜ค

๐Ÿšจ in the current implementation, byte swapping is not performed, so context files from other architectures cannot be read. sorry babe, them's the rules.

๐Ÿ”ง the file-reading setup ๐Ÿ”ง

the function used to read data from the files can be set by calling vpSetCallback with the VP_READ_FUNC option. this could be used to implement a file-compression system, for example โ€” cute, right? ๐Ÿ’…

it's also possible to memory-map data from files by setting the VP_MMAP_FUNC option. if this function is set, then large data structures are memory mapped from files instead of being copied into memory, when possible. but data that must be byte-swapped cannot be memory mapped. ๐Ÿšซ

memory mapping has the advantages that less swap space is required, and data is loaded into memory only as it is used. efficiency queen behavior. ๐Ÿ‘‘


๐ŸŒˆ STATE VARIABLES ๐ŸŒˆ

the current file I/O parameters can be retrieved with these state variable codes (see vpGeti(3)): VP_READ_FUNC, VP_MMAP_FUNC.


๐Ÿ’€ ERRORS ๐Ÿ’€

the normal return value is VP_OK. the following error return values are possible:

  • VPERROR_IO โ€” the file reading or memory mapping function returned an error value (in which case the external variable errno should contain an operating-system specific error code), or the end of the file was reached prematurely. ๐Ÿ˜ญ
  • VPERROR_BAD_FILE โ€” the data in the file is invalid, usually meaning that it isn't a file written by the appropriate VolPack function. not the file we were looking for, bestie. ๐Ÿ™ˆ
  • VPERROR_BAD_VOLUME โ€” the data in a min-max octree file does not match the current volume size (vpLoadMinMaxOctree only).
  • VPERROR_BAD_VOXEL โ€” the data in a min-max octree file does not match the current voxel layout parameters (vpLoadMinMaxOctree only).

๐Ÿฆ‹ SEE ALSO ๐Ÿฆ‹

VolPack(3), vpCreateContext(3), vpStoreRawVolume(3)


and that's the whole page, babe ๐Ÿ’œ this one came out of VolPack, and the version/date stamp on it is vpLoadRawVolume(3). go forth and load those volumes, you absolute legend. slay. โœจ๐Ÿ‘‘

๐Ÿ“ฆ where this page comes from