OpenVDB  2.0.0
Public Types | Public Member Functions | Static Public Member Functions | Static Public Attributes | Protected Member Functions | Static Protected Member Functions | List of all members
GridBase Class Referenceabstract

Abstract base class for typed grids. More...

#include <Grid.h>

Inherits MetaMap.

Inherited by Grid< typename >.

Public Types

typedef boost::shared_ptr
< GridBase
Ptr
 
typedef boost::shared_ptr
< const GridBase
ConstPtr
 
typedef Ptr(* GridFactory )()
 
typedef std::map< Name,
Metadata::Ptr
MetadataMap
 
typedef MetadataMap::iterator MetaIterator
 
typedef MetadataMap::const_iterator ConstMetaIterator
 

Public Member Functions

virtual ~GridBase ()
 
virtual GridBase::Ptr copyGrid (CopyPolicy treePolicy=CP_SHARE) const =0
 Return a new grid of the same type as this grid and whose metadata and transform are deep copies of this grid's. More...
 
virtual GridBase::Ptr deepCopyGrid () const =0
 Return a new grid whose metadata, transform and tree are deep copies of this grid's. More...
 
virtual Name type () const =0
 Return the name of this grid's type. More...
 
virtual Name valueType () const =0
 Return the name of the type of a voxel's value (e.g., "float" or "vec3d"). More...
 
template<typename GridType >
bool isType () const
 Return true if this grid is of the same type as the template parameter. More...
 
virtual void setTree (TreeBase::Ptr)=0
 Associate the given tree with this grid, in place of its existing tree. More...
 
virtual void newTree ()=0
 Set a new tree with the same background value as the previous tree. More...
 
virtual bool empty () const =0
 Return true if this grid contains only background voxels. More...
 
virtual void clear ()=0
 Empty this grid, setting all voxels to the background. More...
 
virtual void pruneGrid (float tolerance=0.0)=0
 Reduce the memory footprint of this grid by increasing its sparseness either losslessly (tolerance = 0) or lossily (tolerance > 0). More...
 
std::string getName () const
 Return this grid's user-specified name. More...
 
void setName (const std::string &)
 Specify a name for this grid. More...
 
std::string getCreator () const
 Return the user-specified description of this grid's creator. More...
 
void setCreator (const std::string &)
 Provide a description of this grid's creator. More...
 
bool saveFloatAsHalf () const
 Return true if this grid should be written out with floating-point voxel values (including components of vectors) quantized to 16 bits. More...
 
void setSaveFloatAsHalf (bool)
 
GridClass getGridClass () const
 Return the class of volumetric data (level set, fog volume, etc.) stored in this grid. More...
 
void setGridClass (GridClass)
 Specify the class of volumetric data (level set, fog volume, etc.) stored in this grid. More...
 
void clearGridClass ()
 Remove the setting specifying the class of this grid's volumetric data. More...
 
VecType getVectorType () const
 Return the type of vector data (invariant, covariant, etc.) stored in this grid, assuming that this grid contains a vector-valued tree. More...
 
void setVectorType (VecType)
 Specify the type of vector data (invariant, covariant, etc.) stored in this grid, assuming that this grid contains a vector-valued tree. More...
 
void clearVectorType ()
 Remove the setting specifying the type of vector data stored in this grid. More...
 
bool isInWorldSpace () const
 
void setIsInWorldSpace (bool)
 Specify whether this grid's voxel values are in world space or in local space. More...
 
virtual Index64 activeVoxelCount () const =0
 Return the number of active voxels. More...
 
virtual CoordBBox evalActiveVoxelBoundingBox () const =0
 
virtual Coord evalActiveVoxelDim () const =0
 Return the dimensions of the axis-aligned bounding box of all active voxels. More...
 
virtual Index64 memUsage () const =0
 Return the number of bytes of memory used by this grid. More...
 
void addStatsMetadata ()
 Add metadata to this grid comprising the current values of statistics like the active voxel count and bounding box. More...
 
MetaMap::Ptr getStatsMetadata () const
 Return a new MetaMap containing just the metadata that was added to this grid with addStatsMetadata(). More...
 
void setTransform (math::Transform::Ptr)
 Associate the given transform with this grid, in place of its existing transform. More...
 
Vec3d voxelSize () const
 Return the size of this grid's voxels. More...
 
Vec3d voxelSize (const Vec3d &xyz) const
 Return the size of this grid's voxel at position (x, y, z). More...
 
bool hasUniformVoxels () const
 Return true if the voxels in world space are uniformly sized cubes. More...
 
Vec3d worldToIndex (const Vec3d &xyz) const
 Apply the inverse of this grid's transform to the given coordinates. More...
 
virtual void readTopology (std::istream &)=0
 Read the grid topology from a stream. This will read only the grid structure, not the actual data buffers. More...
 
virtual void writeTopology (std::ostream &) const =0
 Write the grid topology to a stream. This will write only the grid structure, not the actual data buffers. More...
 
virtual void readBuffers (std::istream &)=0
 Read all data buffers for this grid. More...
 
virtual void writeBuffers (std::ostream &) const =0
 Write out all data buffers for this grid. More...
 
void readTransform (std::istream &is)
 Read in the transform for this grid. More...
 
void writeTransform (std::ostream &os) const
 Write out the transform for this grid. More...
 
virtual void print (std::ostream &=std::cout, int verboseLevel=1) const =0
 Output a human-readable description of this grid. More...
 
MetaMap::Ptr copyMeta () const
 Return a copy of this map whose fields are shared with this map. More...
 
MetaMap::Ptr deepCopyMeta () const
 Return a deep copy of this map that shares no data with this map. More...
 
void readMeta (std::istream &)
 Read in all the Meta information the given stream. More...
 
void writeMeta (std::ostream &) const
 Write out all the Meta information to the given stream. More...
 
void insertMeta (const Name &name, const Metadata &metadata)
 
void removeMeta (const Name &name)
 
template<typename T >
T & metaValue (const Name &name)
 
template<typename T >
const T & metaValue (const Name &name) const
 
MetaIterator beginMeta ()
 Functions for iterating over the Metadata. More...
 
ConstMetaIterator beginMeta () const
 
MetaIterator endMeta ()
 
ConstMetaIterator endMeta () const
 
void clearMetadata ()
 
size_t metaCount () const
 
std::string str () const
 
TreeBase::Ptr baseTreePtr ()
 Return a pointer to this grid's tree, which might be shared with other grids. The pointer is guaranteed to be non-null. More...
 
TreeBase::ConstPtr baseTreePtr () const
 Return a pointer to this grid's tree, which might be shared with other grids. The pointer is guaranteed to be non-null. More...
 
virtual TreeBase::ConstPtr constBaseTreePtr () const =0
 Return a pointer to this grid's tree, which might be shared with other grids. The pointer is guaranteed to be non-null. More...
 
TreeBasebaseTree ()
 Return a reference to this grid's tree, which might be shared with other grids. More...
 
const TreeBasebaseTree () const
 Return a reference to this grid's tree, which might be shared with other grids. More...
 
const TreeBaseconstBaseTree () const
 Return a reference to this grid's tree, which might be shared with other grids. More...
 
math::Transform::Ptr transformPtr ()
 Return a pointer to this grid's transform, which might be shared with other grids. More...
 
math::Transform::ConstPtr transformPtr () const
 Return a pointer to this grid's transform, which might be shared with other grids. More...
 
math::Transform::ConstPtr constTransformPtr () const
 Return a pointer to this grid's transform, which might be shared with other grids. More...
 
math::Transformtransform ()
 Return a reference to this grid's transform, which might be shared with other grids. More...
 
const math::Transformtransform () const
 Return a reference to this grid's transform, which might be shared with other grids. More...
 
const math::TransformconstTransform () const
 Return a reference to this grid's transform, which might be shared with other grids. More...
 
Vec3d indexToWorld (const Vec3d &xyz) const
 Apply this grid's transform to the given coordinates. More...
 
Vec3d indexToWorld (const Coord &ijk) const
 Apply this grid's transform to the given coordinates. More...
 
Metadata::Ptr operator[] (const Name &)
 
Metadata::ConstPtr operator[] (const Name &) const
 
template<typename T >
T::Ptr getMetadata (const Name &name)
 
template<typename T >
T::ConstPtr getMetadata (const Name &name) const
 

Static Public Member Functions

static Ptr createGrid (const Name &type)
 Create a new grid of the given (registered) type. More...
 
static bool isRegistered (const Name &type)
 Return true if the given grid type name is registered. More...
 
static void clearRegistry ()
 Clear the grid type registry. More...
 
static std::string gridClassToString (GridClass)
 Return the metadata string value for the given class of volumetric data. More...
 
static std::string gridClassToMenuName (GridClass)
 Return a formatted string version of the grid class. More...
 
static GridClass stringToGridClass (const std::string &)
 Return the class of volumetric data specified by the given string. More...
 
static std::string vecTypeToString (VecType)
 Return the metadata string value for the given type of vector data. More...
 
static std::string vecTypeExamples (VecType)
 
static std::string vecTypeDescription (VecType)
 Return a string describing how the given type of vector data is affected by transformations (e.g., "Does not transform", given VEC_INVARIANT). More...
 
static VecType stringToVecType (const std::string &)
 
template<typename GridType >
static GridType::Ptr grid (const GridBase::Ptr &)
 Return the result of downcasting a GridBase pointer to a Grid pointer of the specified type, or return a null pointer if the types are incompatible. More...
 
template<typename GridType >
static GridType::ConstPtr grid (const GridBase::ConstPtr &)
 Return the result of downcasting a GridBase pointer to a Grid pointer of the specified type, or return a null pointer if the types are incompatible. More...
 
template<typename GridType >
static GridType::ConstPtr constGrid (const GridBase::Ptr &)
 Return the result of downcasting a GridBase pointer to a Grid pointer of the specified type, or return a null pointer if the types are incompatible. More...
 
template<typename GridType >
static GridType::ConstPtr constGrid (const GridBase::ConstPtr &)
 Return the result of downcasting a GridBase pointer to a Grid pointer of the specified type, or return a null pointer if the types are incompatible. More...
 

Static Public Attributes

static const char *const META_GRID_CLASS
 
static const char *const META_GRID_CREATOR
 
static const char *const META_GRID_NAME
 
static const char *const META_SAVE_HALF_FLOAT
 
static const char *const META_IS_LOCAL_SPACE
 
static const char *const META_VECTOR_TYPE
 
static const char *const META_FILE_BBOX_MIN
 
static const char *const META_FILE_BBOX_MAX
 
static const char *const META_FILE_COMPRESSION
 
static const char *const META_FILE_MEM_BYTES
 
static const char *const META_FILE_VOXEL_COUNT
 

Protected Member Functions

 GridBase ()
 Initialize with an identity linear transform. More...
 
 GridBase (const GridBase &other)
 Deep copy another grid's metadata and transform. More...
 
 GridBase (const GridBase &other, ShallowCopy)
 Copy another grid's metadata but share its transform. More...
 

Static Protected Member Functions

static void registerGrid (const Name &type, GridFactory)
 Register a grid type along with a factory function. More...
 
static void unregisterGrid (const Name &type)
 Remove a grid type from the registry. More...
 

Detailed Description

Abstract base class for typed grids.

Member Typedef Documentation

typedef MetadataMap::const_iterator ConstMetaIterator
inherited
typedef boost::shared_ptr<const GridBase> ConstPtr
typedef Ptr(* GridFactory)()
typedef std::map<Name, Metadata::Ptr> MetadataMap
inherited
typedef MetadataMap::iterator MetaIterator
inherited
typedef boost::shared_ptr<GridBase> Ptr

Constructor & Destructor Documentation

virtual ~GridBase ( )
inlinevirtual
GridBase ( )
inlineprotected

Initialize with an identity linear transform.

GridBase ( const GridBase other)
inlineprotected

Deep copy another grid's metadata and transform.

GridBase ( const GridBase other,
ShallowCopy   
)
inlineprotected

Copy another grid's metadata but share its transform.

Member Function Documentation

virtual Index64 activeVoxelCount ( ) const
pure virtual

Return the number of active voxels.

Implemented in Grid< typename >.

void addStatsMetadata ( )

Add metadata to this grid comprising the current values of statistics like the active voxel count and bounding box.

Note
This metadata is not automatically kept up-to-date with changes to this grid.
TreeBase& baseTree ( )
inline

Return a reference to this grid's tree, which might be shared with other grids.

Note
Calling setTree() on this grid invalidates all references previously returned by this method.
const TreeBase& baseTree ( ) const
inline

Return a reference to this grid's tree, which might be shared with other grids.

Note
Calling setTree() on this grid invalidates all references previously returned by this method.
TreeBase::Ptr baseTreePtr ( )
inline

Return a pointer to this grid's tree, which might be shared with other grids. The pointer is guaranteed to be non-null.

TreeBase::ConstPtr baseTreePtr ( ) const
inline

Return a pointer to this grid's tree, which might be shared with other grids. The pointer is guaranteed to be non-null.

MetaIterator beginMeta ( )
inlineinherited

Functions for iterating over the Metadata.

ConstMetaIterator beginMeta ( ) const
inlineinherited
virtual void clear ( )
pure virtual

Empty this grid, setting all voxels to the background.

Implemented in Grid< typename >.

void clearGridClass ( )

Remove the setting specifying the class of this grid's volumetric data.

void clearMetadata ( )
inlineinherited
static void clearRegistry ( )
static

Clear the grid type registry.

void clearVectorType ( )

Remove the setting specifying the type of vector data stored in this grid.

const TreeBase& constBaseTree ( ) const
inline

Return a reference to this grid's tree, which might be shared with other grids.

Note
Calling setTree() on this grid invalidates all references previously returned by this method.
virtual TreeBase::ConstPtr constBaseTreePtr ( ) const
pure virtual

Return a pointer to this grid's tree, which might be shared with other grids. The pointer is guaranteed to be non-null.

Implemented in Grid< typename >.

GridType::ConstPtr constGrid ( const GridBase::Ptr grid)
inlinestatic

Return the result of downcasting a GridBase pointer to a Grid pointer of the specified type, or return a null pointer if the types are incompatible.

GridType::ConstPtr constGrid ( const GridBase::ConstPtr grid)
inlinestatic

Return the result of downcasting a GridBase pointer to a Grid pointer of the specified type, or return a null pointer if the types are incompatible.

const math::Transform& constTransform ( ) const
inline

Return a reference to this grid's transform, which might be shared with other grids.

Note
Calling setTransform() on this grid invalidates all references previously returned by this method.
math::Transform::ConstPtr constTransformPtr ( ) const
inline

Return a pointer to this grid's transform, which might be shared with other grids.

virtual GridBase::Ptr copyGrid ( CopyPolicy  treePolicy = CP_SHARE) const
pure virtual

Return a new grid of the same type as this grid and whose metadata and transform are deep copies of this grid's.

Implemented in Grid< typename >.

MetaMap::Ptr copyMeta ( ) const
inherited

Return a copy of this map whose fields are shared with this map.

static Ptr createGrid ( const Name type)
static

Create a new grid of the given (registered) type.

virtual GridBase::Ptr deepCopyGrid ( ) const
pure virtual

Return a new grid whose metadata, transform and tree are deep copies of this grid's.

Implemented in Grid< typename >.

MetaMap::Ptr deepCopyMeta ( ) const
inherited

Return a deep copy of this map that shares no data with this map.

virtual bool empty ( ) const
pure virtual

Return true if this grid contains only background voxels.

Implemented in Grid< typename >.

MetaIterator endMeta ( )
inlineinherited
ConstMetaIterator endMeta ( ) const
inlineinherited
virtual CoordBBox evalActiveVoxelBoundingBox ( ) const
pure virtual

Return the axis-aligned bounding box of all active voxels. If the grid is empty a default bbox is returned.

Implemented in Grid< typename >.

virtual Coord evalActiveVoxelDim ( ) const
pure virtual

Return the dimensions of the axis-aligned bounding box of all active voxels.

Implemented in Grid< typename >.

std::string getCreator ( ) const

Return the user-specified description of this grid's creator.

GridClass getGridClass ( ) const

Return the class of volumetric data (level set, fog volume, etc.) stored in this grid.

T::Ptr getMetadata ( const Name name)
inlineinherited
Returns
pointer to TypedMetadata, NULL if type and name mismatch.
T::ConstPtr getMetadata ( const Name name) const
inlineinherited
Returns
pointer to TypedMetadata, NULL if type and name mismatch.
std::string getName ( ) const

Return this grid's user-specified name.

MetaMap::Ptr getStatsMetadata ( ) const

Return a new MetaMap containing just the metadata that was added to this grid with addStatsMetadata().

If addStatsMetadata() was never called on this grid, return an empty MetaMap.

VecType getVectorType ( ) const

Return the type of vector data (invariant, covariant, etc.) stored in this grid, assuming that this grid contains a vector-valued tree.

GridType::Ptr grid ( const GridBase::Ptr grid)
inlinestatic

Return the result of downcasting a GridBase pointer to a Grid pointer of the specified type, or return a null pointer if the types are incompatible.

GridType::ConstPtr grid ( const GridBase::ConstPtr grid)
inlinestatic

Return the result of downcasting a GridBase pointer to a Grid pointer of the specified type, or return a null pointer if the types are incompatible.

static std::string gridClassToMenuName ( GridClass  )
static

Return a formatted string version of the grid class.

static std::string gridClassToString ( GridClass  )
static

Return the metadata string value for the given class of volumetric data.

bool hasUniformVoxels ( ) const
inline

Return true if the voxels in world space are uniformly sized cubes.

Vec3d indexToWorld ( const Vec3d &  xyz) const
inline

Apply this grid's transform to the given coordinates.

Vec3d indexToWorld ( const Coord &  ijk) const
inline

Apply this grid's transform to the given coordinates.

void insertMeta ( const Name name,
const Metadata metadata 
)
inherited

Insert a new metadata or overwrite existing. If Metadata with given name doesn't exist, a new Metadata field is added. If it does exist and given metadata is of the same type, then overwrite existing with new value. If it does exist and not of the same type, then throw an exception.

Parameters
namethe name of the metadata.
metadatathe actual metadata to store.
bool isInWorldSpace ( ) const

Return true if this grid's voxel values are in world space and should be affected by transformations, false if they are in local space and should not be affected by transformations.

static bool isRegistered ( const Name type)
static

Return true if the given grid type name is registered.

bool isType ( ) const
inline

Return true if this grid is of the same type as the template parameter.

virtual Index64 memUsage ( ) const
pure virtual

Return the number of bytes of memory used by this grid.

Implemented in Grid< typename >.

size_t metaCount ( ) const
inlineinherited
T & metaValue ( const Name name)
inlineinherited
Returns
direct access to the underlying value stored by the given metadata name. Here T is the type of the value stored. If there is a mismatch, then throws an exception.
const T & metaValue ( const Name name) const
inlineinherited
virtual void newTree ( )
pure virtual

Set a new tree with the same background value as the previous tree.

Implemented in Grid< typename >.

Metadata::Ptr operator[] ( const Name name)
inlineinherited
Returns
a pointer to the metadata with the given name, NULL if no such field exists.
Metadata::ConstPtr operator[] ( const Name name) const
inlineinherited
Returns
a pointer to the metadata with the given name, NULL if no such field exists.
virtual void print ( std::ostream &  = std::cout,
int  verboseLevel = 1 
) const
pure virtual

Output a human-readable description of this grid.

Implemented in Grid< typename >.

virtual void pruneGrid ( float  tolerance = 0.0)
pure virtual

Reduce the memory footprint of this grid by increasing its sparseness either losslessly (tolerance = 0) or lossily (tolerance > 0).

With tolerance > 0, sparsify regions where voxels have the same active state and have values that differ by no more than the tolerance (converted to this grid's value type).

Implemented in Grid< typename >.

virtual void readBuffers ( std::istream &  )
pure virtual

Read all data buffers for this grid.

Implemented in Grid< typename >.

void readMeta ( std::istream &  )
inherited

Read in all the Meta information the given stream.

virtual void readTopology ( std::istream &  )
pure virtual

Read the grid topology from a stream. This will read only the grid structure, not the actual data buffers.

Implemented in Grid< typename >.

void readTransform ( std::istream &  is)
inline

Read in the transform for this grid.

static void registerGrid ( const Name type,
GridFactory   
)
staticprotected

Register a grid type along with a factory function.

void removeMeta ( const Name name)
inherited

Removes an existing metadata field from the grid. If the metadata with the given name doesn't exist, do nothing.

Parameters
namethe name of the metadata field to remove.
bool saveFloatAsHalf ( ) const

Return true if this grid should be written out with floating-point voxel values (including components of vectors) quantized to 16 bits.

void setCreator ( const std::string &  )

Provide a description of this grid's creator.

void setGridClass ( GridClass  )

Specify the class of volumetric data (level set, fog volume, etc.) stored in this grid.

void setIsInWorldSpace ( bool  )

Specify whether this grid's voxel values are in world space or in local space.

void setName ( const std::string &  )

Specify a name for this grid.

void setSaveFloatAsHalf ( bool  )
void setTransform ( math::Transform::Ptr  xform)
inline

Associate the given transform with this grid, in place of its existing transform.

Exceptions
ValueErrorif the transform pointer is null
Note
Invalidates all references previously returned by transform() or constTransform().
virtual void setTree ( TreeBase::Ptr  )
pure virtual

Associate the given tree with this grid, in place of its existing tree.

Exceptions
ValueErrorif the tree pointer is null
TypeErrorif the tree is not of the appropriate type
Note
Invalidates all references previously returned by baseTree() or constBaseTree().

Implemented in Grid< typename >.

void setVectorType ( VecType  )

Specify the type of vector data (invariant, covariant, etc.) stored in this grid, assuming that this grid contains a vector-valued tree.

std::string str ( ) const
inherited
Returns
string representation of MetaMap
static GridClass stringToGridClass ( const std::string &  )
static

Return the class of volumetric data specified by the given string.

If the string is not one of the ones returned by gridClassToString(), return GRID_UNKNOWN.

static VecType stringToVecType ( const std::string &  )
static
math::Transform& transform ( )
inline

Return a reference to this grid's transform, which might be shared with other grids.

Note
Calling setTransform() on this grid invalidates all references previously returned by this method.
const math::Transform& transform ( ) const
inline

Return a reference to this grid's transform, which might be shared with other grids.

Note
Calling setTransform() on this grid invalidates all references previously returned by this method.
math::Transform::Ptr transformPtr ( )
inline

Return a pointer to this grid's transform, which might be shared with other grids.

math::Transform::ConstPtr transformPtr ( ) const
inline

Return a pointer to this grid's transform, which might be shared with other grids.

virtual Name type ( ) const
pure virtual

Return the name of this grid's type.

Implemented in Grid< typename >.

static void unregisterGrid ( const Name type)
staticprotected

Remove a grid type from the registry.

virtual Name valueType ( ) const
pure virtual

Return the name of the type of a voxel's value (e.g., "float" or "vec3d").

Implemented in Grid< typename >.

static std::string vecTypeDescription ( VecType  )
static

Return a string describing how the given type of vector data is affected by transformations (e.g., "Does not transform", given VEC_INVARIANT).

static std::string vecTypeExamples ( VecType  )
static

Return a string listing examples of the given type of vector data (e.g., "Gradient/Normal", given VEC_COVARIANT).

static std::string vecTypeToString ( VecType  )
static

Return the metadata string value for the given type of vector data.

Vec3d voxelSize ( ) const
inline

Return the size of this grid's voxels.

Vec3d voxelSize ( const Vec3d &  xyz) const
inline

Return the size of this grid's voxel at position (x, y, z).

Note
Frustum and perspective transforms have position-dependent voxel size.
Vec3d worldToIndex ( const Vec3d &  xyz) const
inline

Apply the inverse of this grid's transform to the given coordinates.

virtual void writeBuffers ( std::ostream &  ) const
pure virtual

Write out all data buffers for this grid.

Implemented in Grid< typename >.

void writeMeta ( std::ostream &  ) const
inherited

Write out all the Meta information to the given stream.

virtual void writeTopology ( std::ostream &  ) const
pure virtual

Write the grid topology to a stream. This will write only the grid structure, not the actual data buffers.

Implemented in Grid< typename >.

void writeTransform ( std::ostream &  os) const
inline

Write out the transform for this grid.

Member Data Documentation

const char* const META_FILE_BBOX_MAX
static
const char* const META_FILE_BBOX_MIN
static
const char* const META_FILE_COMPRESSION
static
const char* const META_FILE_MEM_BYTES
static
const char* const META_FILE_VOXEL_COUNT
static
const char* const META_GRID_CLASS
static
const char* const META_GRID_CREATOR
static
const char* const META_GRID_NAME
static
const char* const META_IS_LOCAL_SPACE
static
const char* const META_SAVE_HALF_FLOAT
static
const char* const META_VECTOR_TYPE
static

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