4 #ifndef OPENVDB_GRID_HAS_BEEN_INCLUDED
5 #define OPENVDB_GRID_HAS_BEEN_INCLUDED
18 #include <type_traits>
28 template<
typename>
class Grid;
35 template<
typename Gr
idType>
42 template<
typename Gr
idType>
50 template<
typename TreePtrType>
68 template<
typename Gr
idType>
70 Real voxelSize = 1.0,
Real halfWidth = LEVEL_SET_HALF_WIDTH);
83 using GridFactory =
Ptr (*)();
129 static bool isRegistered(
const Name &
type);
132 static void clearRegistry();
142 virtual Name valueType()
const = 0;
145 template<
typename Gr
idType>
146 bool isType()
const {
return (this->
type() == GridType::gridType()); }
153 template<
typename Gr
idType>
155 template<
typename Gr
idType>
157 template<
typename Gr
idType>
158 static typename GridType::ConstPtr constGrid(
const GridBase::Ptr&);
159 template<
typename Gr
idType>
177 virtual bool isTreeUnique()
const = 0;
204 virtual void newTree() = 0;
209 virtual bool empty()
const = 0;
211 virtual void clear() = 0;
222 virtual void pruneGrid(
float tolerance = 0.0) = 0;
228 void clipGrid(
const BBoxd&);
262 template<
typename Gr
idTypeListT,
typename OpT>
inline bool apply(OpT&)
const;
263 template<
typename Gr
idTypeListT,
typename OpT>
inline bool apply(OpT&);
264 template<
typename Gr
idTypeListT,
typename OpT>
inline bool apply(
const OpT&)
const;
265 template<
typename Gr
idTypeListT,
typename OpT>
inline bool apply(
const OpT&);
274 void setName(
const std::string&);
277 std::string getCreator()
const;
279 void setCreator(
const std::string&);
283 bool saveFloatAsHalf()
const;
284 void setSaveFloatAsHalf(
bool);
295 void clearGridClass();
300 static std::string gridClassToString(
GridClass);
302 static std::string gridClassToMenuName(
GridClass);
307 static GridClass stringToGridClass(
const std::string&);
321 void clearVectorType();
326 static std::string vecTypeToString(
VecType);
329 static std::string vecTypeExamples(
VecType);
332 static std::string vecTypeDescription(
VecType);
333 static VecType stringToVecType(
const std::string&);
341 bool isInWorldSpace()
const;
343 void setIsInWorldSpace(
bool);
369 virtual Index64 activeVoxelCount()
const = 0;
373 virtual CoordBBox evalActiveVoxelBoundingBox()
const = 0;
376 virtual Coord evalActiveVoxelDim()
const = 0;
379 virtual Index64 memUsage()
const = 0;
385 void addStatsMetadata();
451 virtual void readTopology(std::istream&) = 0;
454 virtual void writeTopology(std::ostream&)
const = 0;
457 virtual void readBuffers(std::istream&) = 0;
459 virtual void readBuffers(std::istream&,
const CoordBBox&) = 0;
465 virtual void readNonresidentBuffers()
const = 0;
467 virtual void writeBuffers(std::ostream&)
const = 0;
475 virtual void print(std::ostream& = std::cout,
int verboseLevel = 1)
const = 0;
482 GridBase(): mTransform(math::Transform::createLinearTransform()) {}
495 static void registerGrid(
const Name&
type, GridFactory);
497 static void unregisterGrid(
const Name&
type);
538 template<
typename Gr
idPtrContainerT>
543 typename GridPtrContainerT::const_iterator it =
544 std::find_if(container.begin(), container.end(),
GridNamePred(name));
545 return (it == container.end() ? GridPtrT() : *it);
549 template<
typename KeyT,
typename Gr
idPtrT>
553 using GridPtrMapT = std::map<KeyT, GridPtrT>;
554 for (
typename GridPtrMapT::const_iterator it = container.begin(),
end = container.end();
557 const GridPtrT& grid = it->second;
558 if (grid && grid->getName() == name)
return grid;
569 template<
typename _TreeType>
570 class Grid:
public GridBase
600 template<
typename OtherValueType>
632 template<
typename OtherTreeType>
806 void pruneGrid(
float tolerance = 0.0)
override;
834 template<
typename OtherTreeType>
849 template<
typename OtherTreeType>
862 template<
typename OtherTreeType>
952 void print(std::ostream& = std::cout,
int verboseLevel = 1)
const override;
996 template<
typename Gr
idType>
997 inline typename GridType::Ptr
1000 return GridBase::grid<GridType>(grid);
1012 template<
typename Gr
idType>
1013 inline typename GridType::ConstPtr
1016 return GridBase::constGrid<GridType>(grid);
1029 template<
typename Gr
idType>
1030 inline typename GridType::Ptr
1033 if (!grid || !grid->isType<
GridType>())
return typename GridType::Ptr();
1034 return gridPtrCast<GridType>(grid->deepCopyGrid());
1038 template<
typename Gr
idType>
1039 inline typename GridType::Ptr
1054 template<
typename _TreeType>
1084 template<
typename _TreeType>
1113 template<
typename _TreeType>
1142 template<
typename _TreeType>
1189 template<
typename LeafNodeType>
1195 template<
typename RootNodeType>
1202 template<
typename TreeType>
1215 if (!xform)
OPENVDB_THROW(ValueError,
"Transform pointer is null");
1218 template<
typename Gr
idType>
1219 inline typename GridType::Ptr
1224 if (grid && grid->type() == GridType::gridType()) {
1225 return StaticPtrCast<GridType>(
grid);
1227 return typename GridType::Ptr();
1231 template<
typename Gr
idType>
1232 inline typename GridType::ConstPtr
1235 return ConstPtrCast<const GridType>(
1236 GridBase::grid<GridType>(ConstPtrCast<GridBase>(
grid)));
1240 template<
typename Gr
idType>
1241 inline typename GridType::ConstPtr
1244 return ConstPtrCast<const GridType>(GridBase::grid<GridType>(
grid));
1248 template<
typename Gr
idType>
1249 inline typename GridType::ConstPtr
1252 return ConstPtrCast<const GridType>(
1253 GridBase::grid<GridType>(ConstPtrCast<GridBase>(
grid)));
1267 if (!xform)
OPENVDB_THROW(ValueError,
"Transform pointer is null");
1275 template<
typename TreeT>
1281 template<
typename TreeT>
1287 template<
typename TreeT>
1290 if (!tree)
OPENVDB_THROW(ValueError,
"Tree pointer is null");
1294 template<
typename TreeT>
1299 if (!tree)
OPENVDB_THROW(ValueError,
"Tree pointer is null");
1303 template<
typename TreeT>
1311 template<
typename TreeT>
1312 template<
typename OtherTreeType>
1315 mTree(new
TreeType(other.constTree()))
1320 template<
typename TreeT>
1328 template<
typename TreeT>
1337 template<
typename TreeT>
1346 template<
typename TreeT>
1350 return Ptr(
new Grid(background));
1355 template<
typename TreeT>
1364 template<
typename TreeT>
1375 template<
typename TreeT>
1383 template<
typename TreeT>
1388 this->constTransformPtr());
1389 TreePtrType treePtr = ConstPtrCast<TreeT>(this->constTreePtr());
1393 template<
typename TreeT>
1397 return this->copyReplacingMetadataAndTransform(*
this, xform);
1400 template<
typename TreeT>
1405 TreePtrType treePtr = ConstPtrCast<TreeT>(this->constTreePtr());
1410 template<
typename TreeT>
1418 template<
typename TreeT>
1428 template<
typename TreeT>
1432 return this->copy();
1435 template<
typename TreeT>
1439 return this->copy();
1442 template<
typename TreeT>
1446 return this->copyReplacingMetadata(meta);
1449 template<
typename TreeT>
1453 return this->copyReplacingTransform(xform);
1456 template<
typename TreeT>
1461 return this->copyReplacingMetadataAndTransform(meta, xform);
1464 template<
typename TreeT>
1468 return this->copyWithNewTree();
1475 template<
typename TreeT>
1479 return mTree.use_count() == 1;
1483 template<
typename TreeT>
1487 if (!tree)
OPENVDB_THROW(ValueError,
"Tree pointer is null");
1488 if (tree->type() != TreeType::treeType()) {
1490 + tree->type() +
" to a grid of type " + this->
type());
1492 mTree = StaticPtrCast<TreeType>(tree);
1496 template<
typename TreeT>
1500 mTree.reset(
new TreeType(this->background()));
1507 template<
typename TreeT>
1511 tree().sparseFill(bbox, value, active);
1515 template<
typename TreeT>
1519 this->sparseFill(bbox, value, active);
1522 template<
typename TreeT>
1526 tree().denseFill(bbox, value, active);
1529 template<
typename TreeT>
1534 this->tree().prune(static_cast<ValueType>(
value));
1537 template<
typename TreeT>
1544 template<
typename TreeT>
1548 tree().merge(other.tree(), policy);
1552 template<
typename TreeT>
1553 template<
typename OtherTreeType>
1557 tree().topologyUnion(other.tree());
1561 template<
typename TreeT>
1562 template<
typename OtherTreeType>
1566 tree().topologyIntersection(other.tree());
1570 template<
typename TreeT>
1571 template<
typename OtherTreeType>
1575 tree().topologyDifference(other.tree());
1582 template<
typename TreeT>
1587 tree().evalActiveVoxelBoundingBox(bbox);
1592 template<
typename TreeT>
1597 const bool nonempty = tree().evalActiveVoxelDim(dim);
1598 return (nonempty ? dim : Coord());
1608 template<
typename TreeT>
1612 tree().readTopology(is, saveFloatAsHalf());
1616 template<
typename TreeT>
1620 tree().writeTopology(os, saveFloatAsHalf());
1624 template<
typename TreeT>
1630 if (!hasMultiPassIO()) {
1631 tree().readBuffers(is, saveFloatAsHalf());
1633 uint16_t numPasses = 1;
1634 is.read(reinterpret_cast<char*>(&numPasses),
sizeof(uint16_t));
1637 for (uint16_t passIndex = 0; passIndex < numPasses; ++passIndex) {
1638 uint32_t pass = (uint32_t(numPasses) << 16) | uint32_t(passIndex);
1639 meta->setPass(pass);
1640 tree().readBuffers(is, saveFloatAsHalf());
1648 template<
typename TreeT>
1654 if (!hasMultiPassIO()) {
1655 tree().readBuffers(is, bbox, saveFloatAsHalf());
1657 uint16_t numPasses = 1;
1658 is.read(reinterpret_cast<char*>(&numPasses),
sizeof(uint16_t));
1661 for (uint16_t passIndex = 0; passIndex < numPasses; ++passIndex) {
1662 uint32_t pass = (uint32_t(numPasses) << 16) | uint32_t(passIndex);
1663 meta->setPass(pass);
1664 tree().readBuffers(is, saveFloatAsHalf());
1673 template<
typename TreeT>
1677 tree().readNonresidentBuffers();
1681 template<
typename TreeT>
1685 if (!hasMultiPassIO()) {
1686 tree().writeBuffers(os, saveFloatAsHalf());
1691 uint16_t numPasses = 1;
1692 meta->setCountingPasses(
true);
1694 tree().writeBuffers(os, saveFloatAsHalf());
1695 numPasses =
static_cast<uint16_t
>(meta->pass());
1696 os.write(reinterpret_cast<const char*>(&numPasses),
sizeof(uint16_t));
1697 meta->setCountingPasses(
false);
1700 for (uint16_t passIndex = 0; passIndex < numPasses; ++passIndex) {
1701 uint32_t pass = (uint32_t(numPasses) << 16) | uint32_t(passIndex);
1702 meta->setPass(pass);
1703 tree().writeBuffers(os, saveFloatAsHalf());
1710 template<
typename TreeT>
1718 template<
typename TreeT>
1722 tree().print(os, verboseLevel);
1724 if (metaCount() > 0) {
1725 os <<
"Additional metadata:" << std::endl;
1727 os <<
" " << it->first;
1729 const std::string
value = it->second->str();
1730 if (!value.empty()) os <<
": " << value;
1736 os <<
"Transform:" << std::endl;
1745 template<
typename Gr
idType>
1746 inline typename GridType::Ptr
1749 return GridType::create(background);
1753 template<
typename Gr
idType>
1754 inline typename GridType::Ptr
1757 return GridType::create();
1761 template<
typename TreePtrType>
1762 inline typename Grid<typename TreePtrType::element_type>::Ptr
1765 using TreeType =
typename TreePtrType::element_type;
1770 template<
typename Gr
idType>
1771 typename GridType::Ptr
1778 "level-set grids must be floating-point-valued");
1780 typename GridType::Ptr grid = GridType::create(
1781 static_cast<ValueType>(voxelSize * halfWidth));
1791 template<
typename Gr
idTypeListT,
typename OpT>
1795 return GridTypeListT::template apply<OpT&, const GridBase>(
std::ref(op), *
this);
1798 template<
typename Gr
idTypeListT,
typename OpT>
1802 return GridTypeListT::template apply<OpT&, GridBase>(
std::ref(op), *
this);
1805 template<
typename Gr
idTypeListT,
typename OpT>
1809 return GridTypeListT::template apply<const OpT&, const GridBase>(
std::ref(op), *
this);
1812 template<
typename Gr
idTypeListT,
typename OpT>
1816 return GridTypeListT::template apply<const OpT&, GridBase>(
std::ref(op), *
this);
1823 #endif // OPENVDB_GRID_HAS_BEEN_INCLUDED
static const NonConstTreeType & constTree(const NonConstGridType &g)
SharedPtr< T > StaticPtrCast(const SharedPtr< U > &ptr)
Return a new shared pointer that points to the same object as the given pointer after a static_cast...
typename _TreeType::Accessor Accessor
bool isTreeUnique() const final
Return true if tree is not shared with another grid.
typename _TreeType::ValueType ValueType
typename TreeType::ConstPtr ConstTreePtrType
static GridType::ConstPtr constGrid(const GridBase::Ptr &)
Return the result of downcasting a GridBase pointer to a Grid pointer of the specified type...
typename tree::ValueAccessor< const TreeType > ConstAccessorType
static const NonConstTreeType & constTree(const NonConstGridType &g)
typename tree::ValueAccessor< TreeType > AccessorType
ConstUnsafeAccessor getConstUnsafeAccessor() const
Return an unsafe accessor that provides random read-only access to this grid's voxels.
GridPtrSet::iterator GridPtrSetIter
OPENVDB_API void setGridClass(std::ios_base &, uint32_t)
Associate with the given stream the class (GRID_LEVEL_SET, GRID_UNKNOWN, etc.) of the grid currently ...
SharedPtr< TreeBase > Ptr
typename TreeType::ConstPtr ConstTreePtrType
typename NonConstTreeType::Ptr NonConstTreePtrType
GridType::Ptr createGrid(const typename GridType::ValueType &background)
Create a new grid of type GridType with a given background value.
typename tree::ValueAccessor< const NonConstTreeType > ConstAccessorType
typename tree::ValueAccessor< TreeType > AccessorType
Vec3d indexToWorld(const Coord &ijk) const
Apply this grid's transform to the given coordinates.
Vec3d worldToIndex(const Vec3d &xyz) const
Apply the inverse of this grid's transform to the given coordinates.
typename _TreeType::UnsafeAccessor UnsafeAccessor
SharedPtr< GridBase > Ptr
Tag dispatch class that distinguishes shallow copy constructors from deep copy constructors.
static NonConstTreeType & tree(NonConstTreeType &t)
void writeTransform(std::ostream &os) const
Write out the transform for this grid.
SharedPtr< const Grid > ConstPtr
static const NonConstTreeType & constTree(const NonConstAccessorType &a)
ValueAllIter beginValueAll()
Return an iterator over all of this grid's values (tile and voxel).
void topologyIntersection(const Grid< OtherTreeType > &other)
Intersect this grid's set of active values with the active values of the other grid, whose value type may be different.
Name valueType() const override
Return the name of the type of a voxel's value (e.g., "float" or "vec3d").
void readTransform(std::istream &is)
Read in the transform for this grid.
Grid & operator=(const Grid &)=delete
Disallow assignment, since it wouldn't be obvious whether the copy is deep or shallow.
static const NonConstTreeType & tree(const NonConstGridType &g)
GridType
List of types that are currently supported by NanoVDB.
static const char *const META_GRID_NAME
typename tree::ValueAccessor< TreeType > AccessorType
ConstPtr copyReplacingMetadata(const MetaMap &meta) const
Return a new grid of the same type as this grid whose tree and transform is shared with this grid and...
typename TreeType::ConstPtr ConstTreePtrType
static const NonConstTreeType & tree(const NonConstGridType &g)
GLsizei const GLfloat * value
ValueOnIter beginValueOn()
Return an iterator over all of this grid's active values (tile and voxel).
Mat3< Type1 > cwiseAdd(const Mat3< Type1 > &m, const Type2 s)
Vec3d voxelSize(const Vec3d &xyz) const
Return the size of this grid's voxel at position (x, y, z).
typename _TreeType::ValueOffCIter ValueOffCIter
SharedPtr< GridCPtrVec > GridCPtrVecPtr
SharedPtr< GridPtrSet > GridPtrSetPtr
ValueConverter<T>::Type is the type of a grid having the same hierarchy as this grid but a different ...
Ptr copyWithNewTree() const
Return a new grid of the same type as this grid whose metadata and transform are deep copies of this ...
static const char *const META_SAVE_HALF_FLOAT
void topologyDifference(const Grid< OtherTreeType > &other)
Difference this grid's set of active values with the active values of the other grid, whose value type may be different.
TreePtrType treePtr()
Return a pointer to this grid's tree, which might be shared with other grids. The pointer is guarante...
typename TreeType::ValueType ValueType
typename tree::ValueAccessor< const TreeType > ConstAccessorType
typename tree::ValueAccessor< const TreeType > ConstAccessorType
TreeType & tree()
Return a reference to this grid's tree, which might be shared with other grids.
SharedPtr< GridCPtrSet > GridCPtrSetPtr
GLboolean GLboolean GLboolean GLboolean a
#define OPENVDB_USE_VERSION_NAMESPACE
GridBase::Ptr deepCopyGrid() const override
Return a new grid whose metadata, transform and tree are deep copies of this grid's.
typename TreeType::Ptr TreePtrType
GridCPtrSet::const_iterator GridCPtrSetCIter
bool operator()(const GridBase::ConstPtr &g) const
static const char *const META_FILE_COMPRESSION
static const char *const META_IS_LOCAL_SPACE
The Value Accessor Implementation and API methods. The majoirty of the API matches the API of a compa...
typename tree::ValueAccessor< NonConstTreeType > NonConstAccessorType
static const NonConstTreeType & constTree(NonConstGridType &g)
typename NonConstGridType::Ptr NonConstGridPtrType
**But if you need a result
static const char *const META_GRID_CLASS
Ptr copy()
Return a new grid of the same type as this grid whose metadata and transform are deep copies of this ...
typename TreeType::ValueType ValueType
static const NonConstTreeType & tree(const NonConstTreeType &t)
ConstAccessor getConstAccessor() const
Return an accessor that provides random read-only access to this grid's voxels.
ConstPtr copyReplacingTransform(math::Transform::Ptr xform) const
Return a new grid of the same type as this grid whose tree is shared with this grid, whose metadata is a deep copy of this grid's and whose transform is provided as an argument.
TreeBase::Ptr baseTreePtr()
Return a pointer to this grid's tree, which might be shared with other grids. The pointer is guarante...
std::vector< GridBase::Ptr > GridPtrVec
typename std::remove_const< TreeType >::type NonConstTreeType
std::set< GridBase::Ptr > GridPtrSet
typename _TreeType::ConstPtr ConstTreePtrType
OPENVDB_API void checkFormatVersion(std::ios_base &)
Throws an IoError if the file format version number is not supported.
static NonConstTreeType & tree(NonConstGridType &g)
This adapter allows code that is templated on a Tree type to accept either a Tree type or a Grid type...
GridBase::ConstPtr copyGridReplacingTransform(math::Transform::Ptr xform) const override
Return a new grid of the same type as this grid whose tree is shared with this grid, whose metadata is a deep copy of this grid's and whose transform is provided as an argument.
GridBase::Ptr copyGrid() override
Return a new grid of the same type as this grid whose metadata is a deep copy of this grid's and whos...
static const NonConstTreeType & tree(const NonConstGridType &g)
static const NonConstTreeType & constTree(const NonConstGridType &g)
typename tree::ValueAccessor< NonConstTreeType > NonConstAccessorType
GridCPtrSet::iterator GridCPtrSetIter
static const char *const META_FILE_VOXEL_COUNT
ValueOffCIter cbeginValueOff() const
Return an iterator over all of this grid's inactive values (tile and voxel).
#define OPENVDB_ASSERT(X)
std::shared_ptr< T > SharedPtr
static const NonConstTreeType & tree(const ConstAccessorType &a)
Abstract base class for typed grids.
void clip(const CoordBBox &) override
Clip this grid to the given index-space bounding box.
static const NonConstTreeType & constTree(const NonConstTreeType &t)
Vec3d indexToWorld(const Vec3d &xyz) const
Apply this grid's transform to the given coordinates.
static const char *const META_FILE_BBOX_MIN
static const NonConstTreeType & tree(ConstAccessorType &a)
typename std::remove_const< TreeType >::type NonConstTreeType
GLint GLint GLsizei GLint GLenum GLenum type
static const NonConstTreeType & tree(const NonConstAccessorType &a)
ValueOffIter beginValueOff()
Return an iterator over all of this grid's inactive values (tile and voxel).
bool isType() const
Return true if this grid is of the same type as the template parameter.
GridBase::ConstPtr copyGridReplacingMetadataAndTransform(const MetaMap &meta, math::Transform::Ptr xform) const override
Return a new grid of the same type as this grid whose tree is shared with this grid and whose transfo...
void writeTopology(std::ostream &) const override
Write the grid topology to a stream. This will write only the grid structure, not the actual data buf...
static void unregisterGrid()
Remove this grid type from the registry.
typename _TreeType::ValueAllCIter ValueAllCIter
static Ptr create()
Return a new grid with background value zero.
static void registerGrid()
Register this grid type along with a factory function.
GridType::Ptr createLevelSet(Real voxelSize=1.0, Real halfWidth=LEVEL_SET_HALF_WIDTH)
Create a new grid of type GridType classified as a "Level Set", i.e., a narrow-band level set...
GridBase(GridBase &other, ShallowCopy)
Copy another grid's metadata but share its transform.
virtual GridBase::Ptr deepCopyGrid() const =0
Return a new grid whose metadata, transform and tree are deep copies of this grid's.
math::Transform::ConstPtr transformPtr() const
Return a pointer to this grid's transform, which might be shared with other grids.
GridBase::Ptr copyGridWithNewTree() const override
Return a new grid of the same type as this grid whose metadata and transform are deep copies of this ...
PXL_API const char * getName(const ColorSpace *space)
Return the name of the color space.
Accessor getAccessor()
Return an accessor that provides random read and write access to this grid's voxels.
void sparseFill(const CoordBBox &bbox, const ValueType &value, bool active=true)
Set all voxels within a given axis-aligned box to a constant value.
ConstTreePtrType treePtr() const
Return a pointer to this grid's tree, which might be shared with other grids. The pointer is guarante...
static const NonConstTreeType & constTree(const ConstAccessorType &a)
typename GridType::ConstPtr ConstGridPtrType
static const NonConstTreeType & tree(const NonConstTreeType &t)
bool apply(OpT &) const
If this grid resolves to one of the listed grid types, invoke the given functor on the resolved grid...
typename GridType::Ptr GridPtrType
static const NonConstTreeType & constTree(const NonConstTreeType &t)
CoordBBox evalActiveVoxelBoundingBox() const override
Return the axis-aligned bounding box of all active voxels.
typename _TreeType::ValueOffIter ValueOffIter
static NonConstTreeType & tree(NonConstTreeType &t)
typename NonConstGridType::Ptr NonConstGridPtrType
typename GridType::ConstPtr ConstGridPtrType
Name type() const override
Return the name of this grid's type.
Index64 memUsage() const override
GridType::Ptr gridPtrCast(const GridBase::Ptr &grid)
Cast a generic grid pointer to a pointer to a grid of a concrete class.
const TreeBase & constBaseTree() const
Return a reference to this grid's tree, which might be shared with other grids.
typename NonConstTreeType::Ptr NonConstTreePtrType
typename TreeType::ConstPtr ConstTreePtrType
ValueOffCIter beginValueOff() const
Return an iterator over all of this grid's inactive values (tile and voxel).
GridNamePred(const Name &_name)
static const NonConstTreeType & constTree(const NonConstGridType &g)
GridBase()
Initialize with an identity linear transform.
GLuint const GLchar * name
static void unregisterGrid(const Name &type)
Remove a grid type from the registry.
typename TreeType::Ptr TreePtrType
math::Transform::Ptr transformPtr()
Return a pointer to this grid's transform, which might be shared with other grids.
typename GridType::Ptr GridPtrType
GA_API const UT_StringHolder transform
TreeBase::ConstPtr baseTreePtr() const
Return a pointer to this grid's tree, which might be shared with other grids. The pointer is guarante...
math::Transform & transform()
Return a reference to this grid's transform, which might be shared with other grids.
static const NonConstTreeType & tree(const NonConstTreeType &t)
static const NonConstTreeType & constTree(NonConstAccessorType &a)
Container class that associates a tree with a transform and metadata.
that also have some descendant prim *whose name begins with which in turn has a child named baz where *the predicate active
ConstTreePtrType constTreePtr() const
Return a pointer to this grid's tree, which might be shared with other grids. The pointer is guarante...
void topologyUnion(const Grid< OtherTreeType > &other)
Union this grid's set of active values with the active values of the other grid, whose value type may...
SharedPtr< GridPtrVec > GridPtrVecPtr
typename _TreeType::ValueOnIter ValueOnIter
void readNonresidentBuffers() const override
Read all of this grid's data buffers that are not yet resident in memory (because delayed loading is ...
GridPtrSet::const_iterator GridPtrSetCIter
ValueAllCIter cbeginValueAll() const
Return an iterator over all of this grid's values (tile and voxel).
static GridType::Ptr grid(const GridBase::Ptr &)
Return the result of downcasting a GridBase pointer to a Grid pointer of the specified type...
typename _TreeType::ConstUnsafeAccessor ConstUnsafeAccessor
const ValueType & background() const
Return this grid's background value.
Base class for typed trees.
static const NonConstTreeType & constTree(const NonConstTreeType &t)
GridType::Ptr deepCopyTypedGrid(const GridBase::ConstPtr &grid)
Return a pointer to a deep copy of the given grid, provided that the grid's concrete type is GridType...
typename std::remove_const< TreeType >::type NonConstTreeType
static NonConstTreeType & tree(NonConstTreeType &t)
static bool hasMultiPassIO()
Return true if grids of this type require multiple I/O passes to read and write data buffers...
typename GridType::Ptr GridPtrType
Predicate functor that returns true for grids that have a specified name.
static NonConstTreeType & tree(NonConstGridType &g)
GridCPtrVec::iterator GridCPtrVecIter
static NonConstTreeType & tree(NonConstGridType &g)
void print(std::ostream &=std::cout, int verboseLevel=1) const override
Output a human-readable description of this grid.
ConstPtr copyReplacingMetadataAndTransform(const MetaMap &meta, math::Transform::Ptr xform) const
Return a new grid of the same type as this grid whose tree is shared with this grid and whose transfo...
static const char *const META_FILE_MEM_BYTES
static const NonConstTreeType & constTree(NonConstGridType &g)
void denseFill(const CoordBBox &bbox, const ValueType &value, bool active=true)
Set all voxels within a given axis-aligned box to a constant value and ensure that those voxels are a...
void fill(const CoordBBox &bbox, const ValueType &value, bool active=true)
Set all voxels within a given axis-aligned box to a constant value.
GridBase::ConstPtr copyGridReplacingMetadata(const MetaMap &meta) const override
Return a new grid of the same type as this grid whose tree and transform is shared with this grid and...
TreeBase & baseTree()
Return a reference to this grid's tree, which might be shared with other grids.
Coord evalActiveVoxelDim() const override
Return the dimensions of the axis-aligned bounding box of all active voxels.
typename GridType::Ptr GridPtrType
bool hasUniformVoxels() const
Return true if the voxels in world space are uniformly sized cubes.
OPENVDB_API uint32_t getGridClass(std::ios_base &)
Return the class (GRID_LEVEL_SET, GRID_UNKNOWN, etc.) of the grid currently being read from or writte...
typename _TreeType::ValueOnCIter ValueOnCIter
ValueAccessorImpl< TreeType, IsSafe, MutexType, openvdb::make_index_sequence< CacheLevels >> ValueAccessor
Default alias for a ValueAccessor. This is simply a helper alias for the generic definition but takes...
GridPtrVec::iterator GridPtrVecIter
static NonConstTreeType & tree(NonConstTreeType &t)
typename TreeType::ValueType ValueType
static const char *const META_FILE_DELAYED_LOAD
ValueAllCIter beginValueAll() const
Return an iterator over all of this grid's values (tile and voxel).
static const NonConstTreeType & constTree(const NonConstTreeType &t)
math::Transform::ConstPtr constTransformPtr() const
Return a pointer to this grid's transform, which might be shared with other grids.
void clear() override
Empty this grid, so that all voxels become inactive background voxels.
ConstAccessor getAccessor() const
Return an accessor that provides random read-only access to this grid's voxels.
static const NonConstTreeType & constTree(NonConstGridType &g)
typename NonConstGridType::Ptr NonConstGridPtrType
SharedPtr< const GridBase > ConstPtr
void pruneGrid(float tolerance=0.0) override
Reduce the memory footprint of this grid by increasing its sparseness.
UnsafeAccessor getUnsafeAccessor()
Return an unsafe accessor that provides random read and write access to this grid's voxels...
static const NonConstTreeType & constTree(NonConstTreeType &t)
SharedPtr< const TreeBase > ConstPtr
static const char *const META_GRID_CREATOR
typename std::remove_const< TreeType >::type NonConstTreeType
static const NonConstTreeType & constTree(NonConstTreeType &t)
void writeBuffers(std::ostream &) const override
Write out all data buffers for this grid.
GridType::ConstPtr gridConstPtrCast(const GridBase::ConstPtr &grid)
Cast a generic const grid pointer to a const pointer to a grid of a concrete class.
static const NonConstTreeType & tree(const NonConstGridType &g)
typename GridType::ConstPtr ConstGridPtrType
OPENVDB_API SharedPtr< StreamMetadata > getStreamMetadataPtr(std::ios_base &)
Return a shared pointer to an object that stores metadata (file format, compression scheme...
typename TreeType::Ptr TreePtrType
ValueOnCIter beginValueOn() const
Return an iterator over all of this grid's active values (tile and voxel).
Vec3d voxelSize() const
Return the size of this grid's voxels.
static bool isRegistered()
Return true if this grid type is registered.
bool empty() const override
Return true if this grid contains only inactive background voxels.
GridBase(const GridBase &other)
Deep copy another grid's metadata and transform.
Metafunction that specifies whether a given leaf node, tree, or grid type requires multiple passes to...
const math::Transform & transform() const
Return a reference to this grid's transform, which might be shared with other grids.
GridPtrContainerT::value_type findGridByName(const GridPtrContainerT &container, const Name &name)
Return the first grid in the given container whose name is name.
static const NonConstTreeType & constTree(NonConstTreeType &t)
typename TreeType::ValueType ValueType
typename _TreeType::BuildType BuildType
typename NonConstTreeType::Ptr NonConstTreePtrType
static const char *const META_VECTOR_TYPE
virtual TreeBase::ConstPtr constBaseTreePtr() const =0
Return a pointer to this grid's tree, which might be shared with other grids. The pointer is guarante...
typename NonConstGridType::Ptr NonConstGridPtrType
typename _TreeType::ConstAccessor ConstAccessor
Grid()
Construct a new grid with background value zero.
static const NonConstTreeType & constTree(NonConstTreeType &t)
void readBuffers(std::istream &) override
Read all data buffers for this grid.
void merge(Grid &other, MergePolicy policy=MERGE_ACTIVE_STATES)
Efficiently merge another grid into this grid using one of several schemes.
static bool isRegistered(const Name &type)
Return true if the given grid type name is registered.
typename TreeType::Ptr TreePtrType
std::set< GridBase::ConstPtr > GridCPtrSet
static const NonConstTreeType & constTree(ConstAccessorType &a)
void setTransform(math::Transform::Ptr)
Associate the given transform with this grid, in place of its existing transform. ...
const math::Transform & constTransform() const
Return a reference to this grid's transform, which might be shared with other grids.
std::vector< GridBase::ConstPtr > GridCPtrVec
typename _TreeType::ValueAllIter ValueAllIter
static NonConstTreeType & tree(NonConstAccessorType &a)
FMT_INLINE void print(format_string< T...> fmt, T &&...args)
static Name gridType()
Return the name of this type of grid.
const TreeType & constTree() const
Return a reference to this grid's tree, which might be shared with other grids.
IMATH_INTERNAL_NAMESPACE_HEADER_ENTER IMATH_HOSTDEVICE IMATH_CONSTEXPR14 T clip(const T &p, const Box< T > &box) IMATH_NOEXCEPT
Ptr deepCopy() const
Return a new grid whose metadata, transform and tree are deep copies of this grid's.
#define OPENVDB_VERSION_NAME
The version namespace name for this library version.
typename tree::ValueAccessor< NonConstTreeType > NonConstAccessorType
TreeBase::ConstPtr constBaseTreePtr() const override
Return a pointer to this grid's tree, which might be shared with other grids. The pointer is guarante...
void readTopology(std::istream &) override
Read the grid topology from a stream. This will read only the grid structure, not the actual data buf...
GridCPtrVec::const_iterator GridCPtrVecCIter
void newTree() override
Associate a new, empty tree with this grid, in place of its existing tree.
ValueOnCIter cbeginValueOn() const
Return an iterator over all of this grid's active values (tile and voxel).
static void registerGrid(const Name &type, GridFactory)
Register a grid type along with a factory function.
typename tree::ValueAccessor< TreeType > AccessorType
static const char *const META_FILE_BBOX_MAX
GridPtrVec::const_iterator GridPtrVecCIter
#define OPENVDB_THROW(exception, message)
static const NonConstTreeType & constTree(NonConstGridType &g)
typename GridType::ConstPtr ConstGridPtrType
static const NonConstTreeType & tree(const NonConstTreeType &t)
const TreeBase & baseTree() const
Return a reference to this grid's tree, which might be shared with other grids.
typename NonConstTreeType::Ptr NonConstTreePtrType
typename _TreeType::Ptr TreePtrType
Index64 activeVoxelCount() const override
Return the number of active voxels.
typename tree::ValueAccessor< NonConstTreeType > NonConstAccessorType
const TreeType & tree() const
Return a reference to this grid's tree, which might be shared with other grids.
static NonConstTreeType & tree(NonConstGridType &g)
void setTree(TreeBase::Ptr) override
Associate the given tree with this grid, in place of its existing tree.