HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
IMX_VDB Class Reference

#include <IMX_VDB.h>

+ Inheritance diagram for IMX_VDB:

Classes

class  Topology
 

Public Member Functions

 IMX_VDB ()
 An un-allocated null-VDB, but with default meta data. More...
 
 IMX_VDB (const IMX_VDB &other)
 
 IMX_VDB (IMX_VDB &&other) noexcept
 
 ~IMX_VDB () override
 
EntryType poolTypeID () const override
 
void copy (const IMX_VDB &other)
 Assignment operators. More...
 
IMX_VDBoperator= (const IMX_VDB &other)
 
void swap (IMX_VDB &other)
 
IMX_VDBoperator= (IMX_VDB &&other)
 
openvdb::GridBase::Ptr createVDB () const
 
bool save (std::ostream &os) const
 Returns true for successful save. More...
 
bool saveJSON (UT_JSONWriter &w) const
 
void copyMetadataToOptions (UT_Options &opt) const
 
void updateMetadataFromOptions (const UT_Options &opt)
 Load ourselves from the options, ignoring fields we don't know. More...
 
void copyFromVDB (const openvdb::GridBase &vdb, const UT_Vector3 &voxelsize, const GA_PrimVolumeXform &indexspace, bool ontocpu=true, bool ontogppu=true)
 
void cpuCopyFromVDB (const openvdb::GridBase &vdb, const UT_Vector3 &voxelsize, const GA_PrimVolumeXform &indexspace)
 
void gpuCopyFromVDB (const openvdb::GridBase &vdb, const UT_Vector3 &voxelsize, const GA_PrimVolumeXform &indexspace)
 
void buildFromTopology (UT_VDBType storage, const IMX_VDB *refvdb)
 
CE_VDBGridgetGPUBuffer (bool read, bool write)
 
const CE_VDBGridgetGPUBufferR () const
 
CE_VDBGridgetGPUBufferW ()
 
UT_VDBType storageType () const
 
int getChannels () const
 
bool storesIntegers () const
 
void setTypeInfo (IMX_TypeInfo typeinfo)
 
IMX_TypeInfo typeInfo () const
 
UT_Vector3 voxelSize () const
 
UT_Vector3 origin () const
 
GA_PrimVolumeXform indexSpace () const
 
bool isAligned (const IMX_VDB *vdb) const
 True if the two vdbs map the same indices to the same positions. More...
 
void transform (const UT_Matrix4D &m)
 
void adoptGrid (UT_UniquePtr< CE_VDBGrid > grid, cl::Buffer tilestarts, exint leafcount, exint lowercount, exint uppercount, const UT_Vector3 &voxelsize, const GA_PrimVolumeXform &indexspace)
 
UT_SharedPtr< CE_BufferHostBytegetCPUBufferR () const
 
CE_BufferHostBytegetCPUBufferRW ()
 
void setFromRawNanoVDB (const void *data, exint size)
 
bool isOnGPU () const
 Returns true if this vdb's data is currently on the GPU. More...
 
bool isOnCPU () const
 
bool stealable () const
 
void setStealable (bool v) const
 
bool hasTopology () const
 
exint leafCount () const
 
exint lowerCount () const
 
exint upperCount () const
 
void voxelBounds (UT_Vector3i &lower, UT_Vector3i &upper) const
 
void buildTopology (const openvdb::GridBase &grid)
 
void buildTopologyFromCPU (bool denseleaves)
 Build topology from our own cpu buffer. More...
 
cl::Buffer getGPUTileStarts (exint &tilecount) const
 Return a gpu version. More...
 
UT_SharedPtr< UT_Array
< UT_Vector3i > > 
getCPUTileStarts () const
 
bool denseLeaves () const
 
void setDenseLeaves (bool dense)
 
void setConstantV3 (UT_Vector3 v)
 NOTE: These only set leaf values. More...
 
void setConstantF (fpreal32 f=0.0f)
 
void setConstantI (int32 i=0)
 
bool isDirty () const
 True if there are no VDB grids on GPU or CPU. More...
 
void setDirty ()
 Flag all grids as dirty without freeing them. More...
 
void freeBuffers ()
 Frees all buffers and marks dirty. More...
 
void destroy ()
 Frees all the memory. More...
 
bool allocated () const
 
int64 getMemoryUsage () const
 
int64 getDeviceMemoryUsage () const
 
void setProperties (const UT_OptionsHolder &props)
 
UT_OptionsHolder properties () const
 
template<typename OP >
void updateProperties (const OP &op)
 
fpreal64 computeMin (int channel=0) const
 
fpreal64 computeMax (int channel=0) const
 
fpreal64 computeAverage (int channel=0) const
 
fpreal64 computeMinLength () const
 
fpreal64 computeMaxLength () const
 
- Public Member Functions inherited from CE_HotSwapPoolEntry
 CE_HotSwapPoolEntry ()
 Creates a new buffer. You must call setSize to make this buffer usable. More...
 
virtual ~CE_HotSwapPoolEntry ()
 
 CE_HotSwapPoolEntry (const CE_HotSwapPoolEntry &)=delete
 
CE_HotSwapPoolEntryoperator= (const CE_HotSwapPoolEntry &)=delete
 
bool isInUseGPU () const
 
void setInUseGPUFlag () const
 
void clearInUseGPUFlag () const
 

Static Public Member Functions

static IMX_VDBPtr load (UT_IStream &is)
 
static IMX_VDBPtr loadJSON (UT_JSONParser &p)
 
static const char * cnanovdbStorageDefine (UT_VDBType storagetype)
 
static int registerVDB (IMX_VDBConstPtr vdb, UT_IntArray &registered)
 
static void unregisterVDBs (UT_IntArray &registered)
 
static IMX_VDBConstPtr lookupVDB (int handle)
 Look up a registered vdb by handle. More...
 

Protected Member Functions

void poolResetGPUBuffer () override
 
void poolSetOnGPU (bool ongpu) override
 Update OnGPU. More...
 
bool poolIsGPUBufferEmpty () const override
 True if the gpu buffer is null. More...
 
bool poolIsGPUBufferValid () const override
 True if the gpu buffer is not null and valid. More...
 
bool poolSwapGPUBuffer (CE_HotSwapPoolEntry *otherbase) override
 True if the swap does something. More...
 
void poolShallowCopyGPUBuffer (const CE_HotSwapPoolEntry *srcbase) override
 Shallow copy. More...
 
void unloadFromGPU () override
 
UT_SharedPtr< CE_BufferHostBytegetCPUBufferRInternal ()
 

Protected Attributes

UT_SharedPtr< CE_BufferHostBytemyCPUBuffer
 
UT_SharedPtr< TopologymyTopology
 
UT_Vector3 myVoxelSize
 
GA_PrimVolumeXform myIndexSpace
 
UT_SharedPtr< CE_VDBGridmyGPUBuffer
 
UT_OptionsHolder myProperties
 
IMX_TypeInfo myTypeInfo = IMX_TypeInfo::IMX_NONE
 
UT_VDBType myStorageType = UT_VDB_INVALID
 
bool myOnCPU = false
 
bool myOnGPU = false
 
bool myStealable = true
 

Friends

IMX_API size_t UTformatBuffer (char *buffer, size_t buffer_size, const IMX_VDB &v)
 

Additional Inherited Members

- Public Types inherited from CE_HotSwapPoolEntry
enum  EntryType { EntryType::BUFFER = 0, EntryType::VDB, EntryType::ATTRIBUTE }
 To avoid the need for dynamic casts: More...
 

Detailed Description

Definition at line 37 of file IMX_VDB.h.

Constructor & Destructor Documentation

IMX_VDB::IMX_VDB ( )

An un-allocated null-VDB, but with default meta data.

IMX_VDB::IMX_VDB ( const IMX_VDB other)
inline

Definition at line 43 of file IMX_VDB.h.

IMX_VDB::IMX_VDB ( IMX_VDB &&  other)
inlinenoexcept

Definition at line 44 of file IMX_VDB.h.

IMX_VDB::~IMX_VDB ( )
override

Member Function Documentation

void IMX_VDB::adoptGrid ( UT_UniquePtr< CE_VDBGrid grid,
cl::Buffer  tilestarts,
exint  leafcount,
exint  lowercount,
exint  uppercount,
const UT_Vector3 voxelsize,
const GA_PrimVolumeXform indexspace 
)

Sets the underlying GPU buffer to provided grid, taking ownership of it.

bool IMX_VDB::allocated ( ) const
inline

True if there are any CPU or GPU buffers, they may not have valid data - use isDirty() to see that.

Definition at line 240 of file IMX_VDB.h.

void IMX_VDB::buildFromTopology ( UT_VDBType  storage,
const IMX_VDB refvdb 
)

Replaces self with a vdb using the provided source's topology. If same type this is just a copy(). Otherewise it is zeroed. Copies transform & metadata options.

void IMX_VDB::buildTopology ( const openvdb::GridBase &  grid)

Build topology from provided grid. These are built onto the GPU & CPU. This could be delayed since we share the topology pointer so would only upload once.

void IMX_VDB::buildTopologyFromCPU ( bool  denseleaves)

Build topology from our own cpu buffer.

static const char* IMX_VDB::cnanovdbStorageDefine ( UT_VDBType  storagetype)
static
fpreal64 IMX_VDB::computeAverage ( int  channel = 0) const
fpreal64 IMX_VDB::computeMax ( int  channel = 0) const
fpreal64 IMX_VDB::computeMaxLength ( ) const
fpreal64 IMX_VDB::computeMin ( int  channel = 0) const

Compute useful aggregate properties of the layer. For integer vdb, use computeMinI() and computeMaxI().

fpreal64 IMX_VDB::computeMinLength ( ) const
void IMX_VDB::copy ( const IMX_VDB other)

Assignment operators.

void IMX_VDB::copyFromVDB ( const openvdb::GridBase &  vdb,
const UT_Vector3 voxelsize,
const GA_PrimVolumeXform indexspace,
bool  ontocpu = true,
bool  ontogppu = true 
)

Copies a VDB into ourselves, creating both CPU and GPU buffers by default. Can throw CE exceptions.

void IMX_VDB::copyMetadataToOptions ( UT_Options opt) const

Write our fields into the provided options: THis does not include properties.

void IMX_VDB::cpuCopyFromVDB ( const openvdb::GridBase &  vdb,
const UT_Vector3 voxelsize,
const GA_PrimVolumeXform indexspace 
)
inline

Definition at line 83 of file IMX_VDB.h.

openvdb::GridBase::Ptr IMX_VDB::createVDB ( ) const

Conversion to/from openvdb. Can throw CE exceptions.

bool IMX_VDB::denseLeaves ( ) const
inline

If we know all leaves are fully activated, we can avoid doing activation tests per voxel. This can be set at build time and then cleared if any topology change op occurs.

Definition at line 216 of file IMX_VDB.h.

void IMX_VDB::destroy ( )

Frees all the memory.

void IMX_VDB::freeBuffers ( )

Frees all buffers and marks dirty.

int IMX_VDB::getChannels ( ) const
UT_SharedPtr<CE_BufferHostByte> IMX_VDB::getCPUBufferR ( ) const

If onCPU, returns a shared pointer to the cpu buffer If onGPU, copy to CPU and return the shared pointer, keeping GPU copy. If dirty, return null. Can throw CE exceptions.

UT_SharedPtr<CE_BufferHostByte> IMX_VDB::getCPUBufferRInternal ( )
protected
CE_BufferHostByte* IMX_VDB::getCPUBufferRW ( )

If onCPU, ensure unique and return the raw pointer that is our own buffer. If onGPU, copies to the CPU and returns that, resetting onGPU to false If dirty, return null.

UT_SharedPtr<UT_Array<UT_Vector3i> > IMX_VDB::getCPUTileStarts ( ) const
inline

Definition at line 209 of file IMX_VDB.h.

int64 IMX_VDB::getDeviceMemoryUsage ( ) const
CE_VDBGrid* IMX_VDB::getGPUBuffer ( bool  read,
bool  write 
)

Returns this vdb's GPU storage object. If read is true, isDirty must be false. If write is true then it turns off isDirty by setting isOnGPU() and turning off isOnCPU() (it is assuming caller will actually write the buffer) When using one of these methods, this buffer must be guarded with the in-use GPU flag. See setInUseGPUFlag() documentation for more information. Can throw CE exceptions.

const CE_VDBGrid* IMX_VDB::getGPUBufferR ( ) const
CE_VDBGrid* IMX_VDB::getGPUBufferW ( )
inline

Definition at line 109 of file IMX_VDB.h.

cl::Buffer IMX_VDB::getGPUTileStarts ( exint tilecount) const
inline

Return a gpu version.

Definition at line 206 of file IMX_VDB.h.

int64 IMX_VDB::getMemoryUsage ( ) const
void IMX_VDB::gpuCopyFromVDB ( const openvdb::GridBase &  vdb,
const UT_Vector3 voxelsize,
const GA_PrimVolumeXform indexspace 
)
inline

Definition at line 87 of file IMX_VDB.h.

bool IMX_VDB::hasTopology ( ) const
GA_PrimVolumeXform IMX_VDB::indexSpace ( ) const
inline

Definition at line 122 of file IMX_VDB.h.

bool IMX_VDB::isAligned ( const IMX_VDB vdb) const
inline

True if the two vdbs map the same indices to the same positions.

Definition at line 125 of file IMX_VDB.h.

bool IMX_VDB::isDirty ( ) const
inline

True if there are no VDB grids on GPU or CPU.

Definition at line 227 of file IMX_VDB.h.

bool IMX_VDB::isOnCPU ( ) const
inline

Returns true if this vdb's data is currently on the CPU (this is not necessarily !isOnGPU()).

Definition at line 167 of file IMX_VDB.h.

bool IMX_VDB::isOnGPU ( ) const
inline

Returns true if this vdb's data is currently on the GPU.

Definition at line 160 of file IMX_VDB.h.

exint IMX_VDB::leafCount ( ) const
inline

Definition at line 181 of file IMX_VDB.h.

static IMX_VDBPtr IMX_VDB::load ( UT_IStream is)
static

Returns a newly created VDB loaded from the stream, or null if load failure.

static IMX_VDBPtr IMX_VDB::loadJSON ( UT_JSONParser p)
static
static IMX_VDBConstPtr IMX_VDB::lookupVDB ( int  handle)
static

Look up a registered vdb by handle.

exint IMX_VDB::lowerCount ( ) const
inline

Definition at line 183 of file IMX_VDB.h.

IMX_VDB& IMX_VDB::operator= ( const IMX_VDB other)
inline

Definition at line 52 of file IMX_VDB.h.

IMX_VDB& IMX_VDB::operator= ( IMX_VDB &&  other)
inline

Definition at line 55 of file IMX_VDB.h.

UT_Vector3 IMX_VDB::origin ( ) const
inline

Definition at line 121 of file IMX_VDB.h.

bool IMX_VDB::poolIsGPUBufferEmpty ( ) const
inlineoverrideprotectedvirtual

True if the gpu buffer is null.

Implements CE_HotSwapPoolEntry.

Definition at line 339 of file IMX_VDB.h.

bool IMX_VDB::poolIsGPUBufferValid ( ) const
inlineoverrideprotectedvirtual

True if the gpu buffer is not null and valid.

Implements CE_HotSwapPoolEntry.

Definition at line 344 of file IMX_VDB.h.

void IMX_VDB::poolResetGPUBuffer ( )
inlineoverrideprotectedvirtual

These implement methods required by the pool. Resets the GPU Buffer pointer.

Implements CE_HotSwapPoolEntry.

Definition at line 329 of file IMX_VDB.h.

void IMX_VDB::poolSetOnGPU ( bool  ongpu)
inlineoverrideprotectedvirtual

Update OnGPU.

Implements CE_HotSwapPoolEntry.

Definition at line 334 of file IMX_VDB.h.

void IMX_VDB::poolShallowCopyGPUBuffer ( const CE_HotSwapPoolEntry srcbase)
inlineoverrideprotectedvirtual

Shallow copy.

Implements CE_HotSwapPoolEntry.

Definition at line 360 of file IMX_VDB.h.

bool IMX_VDB::poolSwapGPUBuffer ( CE_HotSwapPoolEntry otherbase)
inlineoverrideprotectedvirtual

True if the swap does something.

Implements CE_HotSwapPoolEntry.

Definition at line 349 of file IMX_VDB.h.

EntryType IMX_VDB::poolTypeID ( ) const
inlineoverridevirtual

Implements CE_HotSwapPoolEntry.

Definition at line 48 of file IMX_VDB.h.

UT_OptionsHolder IMX_VDB::properties ( ) const
inline

Definition at line 247 of file IMX_VDB.h.

static int IMX_VDB::registerVDB ( IMX_VDBConstPtr  vdb,
UT_IntArray registered 
)
static

VDB registration to allow vdbs to be converted to integers across HOM boundaries. Registers & returns the handle, adding the handle to the registered list

bool IMX_VDB::save ( std::ostream &  os) const

Returns true for successful save.

bool IMX_VDB::saveJSON ( UT_JSONWriter w) const
void IMX_VDB::setConstantF ( fpreal32  f = 0.0f)
inline

Definition at line 223 of file IMX_VDB.h.

void IMX_VDB::setConstantI ( int32  i = 0)
void IMX_VDB::setConstantV3 ( UT_Vector3  v)

NOTE: These only set leaf values.

void IMX_VDB::setDenseLeaves ( bool  dense)
inline

Definition at line 218 of file IMX_VDB.h.

void IMX_VDB::setDirty ( )
inline

Flag all grids as dirty without freeing them.

Definition at line 230 of file IMX_VDB.h.

void IMX_VDB::setFromRawNanoVDB ( const void data,
exint  size 
)

Replace VDB with raw NanoVDB buffer. Can throw CE exceptions for malformed or unhandled data.

void IMX_VDB::setProperties ( const UT_OptionsHolder props)
inline

Definition at line 245 of file IMX_VDB.h.

void IMX_VDB::setStealable ( bool  v) const
inline

Can be used to control what stealable() subsequently returns. If set to true, indicates to the verbs that this buffer may be stolen from.

Definition at line 178 of file IMX_VDB.h.

void IMX_VDB::setTypeInfo ( IMX_TypeInfo  typeinfo)
inline

Definition at line 116 of file IMX_VDB.h.

bool IMX_VDB::stealable ( ) const
inline

True if data in this buffer may be stolen from (or changed) by the verbs even if it's an input.

Definition at line 174 of file IMX_VDB.h.

UT_VDBType IMX_VDB::storageType ( ) const
inline

Definition at line 111 of file IMX_VDB.h.

bool IMX_VDB::storesIntegers ( ) const
void IMX_VDB::swap ( IMX_VDB other)
void IMX_VDB::transform ( const UT_Matrix4D m)

Transform the vdb, this REQUIRES updating the nanovdb structure so will run OpenCL.

IMX_TypeInfo IMX_VDB::typeInfo ( ) const
inline

Definition at line 117 of file IMX_VDB.h.

void IMX_VDB::unloadFromGPU ( )
overrideprotectedvirtual

Queues up commands that transfer this buffer's GPU storage to main memory.

Implements CE_HotSwapPoolEntry.

static void IMX_VDB::unregisterVDBs ( UT_IntArray registered)
static

Unregister all vdbs corresponding to the provided list, erase the list afterwards. Assertion if handle wasn't regsitered

void IMX_VDB::updateMetadataFromOptions ( const UT_Options opt)

Load ourselves from the options, ignoring fields we don't know.

template<typename OP >
void IMX_VDB::updateProperties ( const OP &  op)
inline

Updates the contents of the properties, first making sure it is unique. The provided operator should take a reference to a UT_Options that it will update. this->update([](UT_Options &opt) { opt.setOptionS("test", "bar"); });

Definition at line 255 of file IMX_VDB.h.

exint IMX_VDB::upperCount ( ) const
inline

Definition at line 185 of file IMX_VDB.h.

void IMX_VDB::voxelBounds ( UT_Vector3i lower,
UT_Vector3i upper 
) const
inline

Half-inclusive bounds of the volume in voxels; using only the leaf information. Requires possibly copying back tilestarts and running over, so not fast. Voxels are in [lower, upper)

Definition at line 191 of file IMX_VDB.h.

UT_Vector3 IMX_VDB::voxelSize ( ) const
inline

Definition at line 120 of file IMX_VDB.h.

Friends And Related Function Documentation

IMX_API size_t UTformatBuffer ( char *  buffer,
size_t  buffer_size,
const IMX_VDB v 
)
friend

Member Data Documentation

UT_SharedPtr<CE_BufferHostByte> IMX_VDB::myCPUBuffer
protected

Definition at line 372 of file IMX_VDB.h.

UT_SharedPtr<CE_VDBGrid> IMX_VDB::myGPUBuffer
protected

All changes to this member (the shared pointer) must be done by the memory pool!!!

Definition at line 385 of file IMX_VDB.h.

GA_PrimVolumeXform IMX_VDB::myIndexSpace
protected

Definition at line 381 of file IMX_VDB.h.

bool IMX_VDB::myOnCPU = false
protected

This pair of flags hold the state of data that lives in the two storage spots.

Definition at line 397 of file IMX_VDB.h.

bool IMX_VDB::myOnGPU = false
protected

Definition at line 398 of file IMX_VDB.h.

UT_OptionsHolder IMX_VDB::myProperties
protected

Definition at line 387 of file IMX_VDB.h.

bool IMX_VDB::myStealable = true
mutableprotected

Can data of this buffer be stolen by the verbs? TODO: who should reset this and when?

Definition at line 402 of file IMX_VDB.h.

UT_VDBType IMX_VDB::myStorageType = UT_VDB_INVALID
protected

The type of the grid so we can avoid unpacking it to find out. Note this is ALSO on the CE_VDBGrid, but that might not exist for CPU buffers so it is duplicated here.

Definition at line 393 of file IMX_VDB.h.

UT_SharedPtr<Topology> IMX_VDB::myTopology
protected

Tracks the leaf starts & node counts. Stores GPU and CPU versions of these.

Definition at line 376 of file IMX_VDB.h.

IMX_TypeInfo IMX_VDB::myTypeInfo = IMX_TypeInfo::IMX_NONE
protected

Definition at line 388 of file IMX_VDB.h.

UT_Vector3 IMX_VDB::myVoxelSize
protected

Because the nanovdb buffers are somewhat opaque, we store some meta data locally.

Definition at line 380 of file IMX_VDB.h.


The documentation for this class was generated from the following file: