-
Notifications
You must be signed in to change notification settings - Fork 6
Volume API
Simon Leistikow edited this page Oct 29, 2024
·
1 revision
File | Class | Description |
---|---|---|
volumefactory.h/.cpp | VolumeFactory, VolumeGenerator | Implemented factory-pattern, to easily generate volumes from a specific format. |
volumebase.h/.cpp | VolumeBase | Implemented decorator-pattern. A VolumeBase does not store any data. |
volume.h/.cpp | Volume | A Volume instance, storing data representations (Disk, RAM, GL, Octree) and meta data. |
volumedecorator.h/.cpp | VolumeDecoratorIdentity, VolumeDecoratorReplace | Decorates a VolumeBase object and overwrites a single meta date. |
volumeram.h/.cpp | VolumeRAM | This class specifies the interface for volume data stored in RAM. |
volumedisk.h/.cpp | VolumeDisk | This class specifies the interface for volume data stored on Disk. |
volumegl.h/.cpp | VolumeGL | This class specifies the interface for volume data stored on GPU RAM. |
volumeoctree.h/.cpp | VolumeOctree | This class specifies the interface for volume data stored as Octree. |
volumeatomic.h | VolumeAtomic | Implements VolumeRAM for a Type T. |
volumeelement.h | VolumeElement | Helper class for VolumeAtomic. |
The following example shall demonstrate how to operate on volumes (possibly having multiple channels):
void Processor::process() {
const VolumeBase* volume = volumeInport_.getData(); // Volume is typically non-null (guaranteed by isReady() method per default).
VolumeRAMRepresentationLock volumeData(volume); // Grants access to volume data inside RAM.
/* If a specific data type is ensured by PortConditions, casting is safe.
* Port conditions should be added in the constructor similar to:
* volumeInport_.addCondition(new PortConditionVolumeType3xFloat());
*/
const auto* concreteType = dynamic_cast<VolumeRAM_3xFloat>(*volumeData);
// Applying real world mapping maps normalized voxel values to real world values.
RealWorldMapping rwm = volume->getRealWorldMapping();
// The following loops iterate each voxel by grid position.
tgt::svec3 dimensions = volumeData->getDimensions();
for(size_t z=0; z<dimensions.z; z++) {
for(size_t y=0; y<dimensions.y; y++) {
for(size_t x=0; x<dimensions.x; x++) {
tgt::vec3 voxel = tgt::vec3::zero;
// 1. Typed access if type is known:
if(concreteType) {
voxel = concreteType->voxel(x, y, z); // Fast access.
}
// 2. Normalized access if type is unknown (but number of channels still is):
else {
for(size_t channel=0; channel<tgt::vec3::size; channel++) {
voxel[channel] = volumeData->getVoxelNormalized(x, y, z, channel); // Slow access due to virtual function calls.
// Applying real world mapping might be necessary, depending on the task.
voxel[channel] = rwm.normalizedToRealWorld(voxel[channel]);
}
}
// Now the voxel's values can be used for any purpose.
...
}
}
}
}