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
 
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 ()
 
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 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)
 
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 setAttributes (const UT_OptionsHolder &attrib)
 
UT_OptionsHolder attributes () const
 
template<typename OP >
void updateAttributes (const OP &op)
 
- Public Member Functions inherited from IMX_PoolEntry
 IMX_PoolEntry ()
 Creates a new buffer. You must call setSize to make this buffer usable. More...
 
virtual ~IMX_PoolEntry ()
 
 IMX_PoolEntry (const IMX_PoolEntry &)=delete
 
IMX_PoolEntryoperator= (const IMX_PoolEntry &)=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 (IMX_PoolEntry *otherbase) override
 True if the swap does something. More...
 
void poolShallowCopyGPUBuffer (const IMX_PoolEntry *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 myAttributes
 
IMX_TypeInfo myTypeInfo = IMX_TypeInfo::IMX_NONE
 
UT_VDBType myStorageType = UT_VDB_INVALID
 
bool myOnCPU = false
 
bool myOnGPU = false
 
bool myStealable = true
 
- Protected Attributes inherited from IMX_PoolEntry
int myGPUInUseCount = 0
 

Friends

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

Additional Inherited Members

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

Detailed Description

Definition at line 36 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 42 of file IMX_VDB.h.

IMX_VDB::IMX_VDB ( IMX_VDB &&  other)
inlinenoexcept

Definition at line 43 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 220 of file IMX_VDB.h.

UT_OptionsHolder IMX_VDB::attributes ( ) const
inline

Definition at line 227 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
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 attributes.

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

Definition at line 82 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 201 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 194 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 108 of file IMX_VDB.h.

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

Return a gpu version.

Definition at line 191 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 86 of file IMX_VDB.h.

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

Definition at line 120 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 123 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 207 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 161 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 154 of file IMX_VDB.h.

exint IMX_VDB::leafCount ( ) const
inline

Definition at line 175 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 177 of file IMX_VDB.h.

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

Definition at line 51 of file IMX_VDB.h.

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

Definition at line 54 of file IMX_VDB.h.

UT_Vector3 IMX_VDB::origin ( ) const
inline

Definition at line 119 of file IMX_VDB.h.

bool IMX_VDB::poolIsGPUBufferEmpty ( ) const
inlineoverrideprotectedvirtual

True if the gpu buffer is null.

Implements IMX_PoolEntry.

Definition at line 309 of file IMX_VDB.h.

bool IMX_VDB::poolIsGPUBufferValid ( ) const
inlineoverrideprotectedvirtual

True if the gpu buffer is not null and valid.

Implements IMX_PoolEntry.

Definition at line 314 of file IMX_VDB.h.

void IMX_VDB::poolResetGPUBuffer ( )
inlineoverrideprotectedvirtual

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

Implements IMX_PoolEntry.

Definition at line 299 of file IMX_VDB.h.

void IMX_VDB::poolSetOnGPU ( bool  ongpu)
inlineoverrideprotectedvirtual

Update OnGPU.

Implements IMX_PoolEntry.

Definition at line 304 of file IMX_VDB.h.

void IMX_VDB::poolShallowCopyGPUBuffer ( const IMX_PoolEntry srcbase)
inlineoverrideprotectedvirtual

Shallow copy.

Implements IMX_PoolEntry.

Definition at line 330 of file IMX_VDB.h.

bool IMX_VDB::poolSwapGPUBuffer ( IMX_PoolEntry otherbase)
inlineoverrideprotectedvirtual

True if the swap does something.

Implements IMX_PoolEntry.

Definition at line 319 of file IMX_VDB.h.

EntryType IMX_VDB::poolTypeID ( ) const
inlineoverridevirtual

Implements IMX_PoolEntry.

Definition at line 47 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::setAttributes ( const UT_OptionsHolder attrib)
inline

Definition at line 225 of file IMX_VDB.h.

void IMX_VDB::setDenseLeaves ( bool  dense)
inline

Definition at line 203 of file IMX_VDB.h.

void IMX_VDB::setDirty ( )
inline

Flag all grids as dirty without freeing them.

Definition at line 210 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 172 of file IMX_VDB.h.

void IMX_VDB::setTypeInfo ( IMX_TypeInfo  typeinfo)
inline

Definition at line 114 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 168 of file IMX_VDB.h.

UT_VDBType IMX_VDB::storageType ( ) const
inline

Definition at line 110 of file IMX_VDB.h.

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 115 of file IMX_VDB.h.

void IMX_VDB::unloadFromGPU ( )
overrideprotectedvirtual

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

Implements IMX_PoolEntry.

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

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

Updates the contents of the attributes, 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 235 of file IMX_VDB.h.

void IMX_VDB::updateMetadataFromOptions ( const UT_Options opt)

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

exint IMX_VDB::upperCount ( ) const
inline

Definition at line 179 of file IMX_VDB.h.

UT_Vector3 IMX_VDB::voxelSize ( ) const
inline

Definition at line 118 of file IMX_VDB.h.

Friends And Related Function Documentation

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

Member Data Documentation

UT_OptionsHolder IMX_VDB::myAttributes
protected

Definition at line 357 of file IMX_VDB.h.

UT_SharedPtr<CE_BufferHostByte> IMX_VDB::myCPUBuffer
protected

Definition at line 342 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 355 of file IMX_VDB.h.

GA_PrimVolumeXform IMX_VDB::myIndexSpace
protected

Definition at line 351 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 367 of file IMX_VDB.h.

bool IMX_VDB::myOnGPU = false
protected

Definition at line 368 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 372 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 363 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 346 of file IMX_VDB.h.

IMX_TypeInfo IMX_VDB::myTypeInfo = IMX_TypeInfo::IMX_NONE
protected

Definition at line 358 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 350 of file IMX_VDB.h.


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