Go to the documentation of this file.
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>
36 inline typename GridType::Ptr
createGrid(
const typename GridType::ValueType& background);
42 template<
typename Gr
idType>
50 template<
typename TreePtrType>
68 template<
typename Gr
idType>
102 #if OPENVDB_ABI_VERSION_NUMBER >= 7
147 template<
typename Gr
idType>
148 bool isType()
const {
return (this->type() == GridType::gridType()); }
153 template<
typename Gr
idType>
157 template<
typename Gr
idType>
159 template<
typename Gr
idType>
160 static typename GridType::ConstPtr constGrid(
const GridBase::Ptr&);
161 template<
typename Gr
idType>
178 #if OPENVDB_ABI_VERSION_NUMBER >= 8
179 virtual bool isTreeUnique()
const = 0;
266 template<
typename Gr
idTypeListT,
typename OpT>
inline bool apply(OpT&)
const;
267 template<
typename Gr
idTypeListT,
typename OpT>
inline bool apply(OpT&);
268 template<
typename Gr
idTypeListT,
typename OpT>
inline bool apply(
const OpT&)
const;
269 template<
typename Gr
idTypeListT,
typename OpT>
inline bool apply(
const OpT&);
479 virtual void print(std::ostream& = std::cout,
int verboseLevel = 1)
const = 0;
486 GridBase(): mTransform(math::Transform::createLinearTransform()) {}
488 #if OPENVDB_ABI_VERSION_NUMBER >= 7
544 template<
typename Gr
idPtrContainerT>
545 inline typename GridPtrContainerT::value_type
548 using GridPtrT =
typename GridPtrContainerT::value_type;
549 typename GridPtrContainerT::const_iterator it =
550 std::find_if(container.begin(), container.end(),
GridNamePred(name));
551 return (it == container.end() ? GridPtrT() : *it);
555 template<
typename KeyT,
typename Gr
idPtrT>
559 using GridPtrMapT = std::map<KeyT, GridPtrT>;
560 for (
typename GridPtrMapT::const_iterator it = container.begin(), end = container.end();
563 const GridPtrT& grid = it->second;
564 if (grid && grid->getName() == name)
return grid;
575 template<
typename _TreeType>
606 template<
typename OtherValueType>
638 template<
typename OtherTreeType>
662 Ptr copyWithNewTree()
const;
678 #if OPENVDB_ABI_VERSION_NUMBER >= 7
717 Name type()
const override {
return this->gridType(); }
733 bool empty()
const override {
return tree().empty(); }
735 void clear()
override { tree().clear(); }
794 void sparseFill(
const CoordBBox& bbox,
const ValueType& value,
bool active =
true);
803 void fill(
const CoordBBox& bbox,
const ValueType& value,
bool active =
true);
811 void denseFill(
const CoordBBox& bbox,
const ValueType& value,
bool active =
true);
814 void pruneGrid(
float tolerance = 0.0)
override;
842 template<
typename OtherTreeType>
857 template<
typename OtherTreeType>
870 template<
typename OtherTreeType>
881 CoordBBox evalActiveVoxelBoundingBox()
const override;
883 Coord evalActiveVoxelDim()
const override;
885 void evalMinMax(ValueType& minVal, ValueType& maxVal)
const;
898 TreePtrType treePtr() {
return mTree; }
905 #if OPENVDB_ABI_VERSION_NUMBER >= 8
908 bool isTreeUnique() const final;
910 bool isTreeUnique()
const;
913 TreeType& tree() {
return *mTree; }
936 void newTree()
override;
946 void readTopology(std::istream&)
override;
949 void writeTopology(std::ostream&)
const override;
952 void readBuffers(std::istream&)
override;
954 void readBuffers(std::istream&,
const CoordBBox&)
override;
960 void readNonresidentBuffers()
const override;
962 void writeBuffers(std::ostream&)
const override;
965 void print(std::ostream& = std::cout,
int verboseLevel = 1)
const override;
972 static inline bool hasMultiPassIO();
986 <<
" might not be threadsafe on this platform");
996 #if OPENVDB_ABI_VERSION_NUMBER >= 7
1018 template<
typename Gr
idType>
1019 inline typename GridType::Ptr
1022 return GridBase::grid<GridType>(grid);
1034 template<
typename Gr
idType>
1035 inline typename GridType::ConstPtr
1038 return GridBase::constGrid<GridType>(grid);
1051 template<
typename Gr
idType>
1052 inline typename GridType::Ptr
1055 if (!grid || !grid->isType<GridType>())
return typename GridType::Ptr();
1056 return gridPtrCast<GridType>(grid->deepCopyGrid());
1060 template<
typename Gr
idType>
1061 inline typename GridType::Ptr
1064 if (!grid.
isType<GridType>())
return typename GridType::Ptr();
1074 template<
typename _TreeType>
1106 template<
typename _TreeType>
1135 template<
typename _TreeType>
1176 template<
typename LeafNodeType>
1178 static const bool value = std::is_base_of<io::MultiPass, LeafNodeType>::value;
1182 template<
typename RootNodeType>
1189 template<
typename TreeType>
1198 #if OPENVDB_ABI_VERSION_NUMBER >= 7
1207 template<
typename Gr
idType>
1208 inline typename GridType::Ptr
1213 if (
grid &&
grid->type() == GridType::gridType()) {
1214 return StaticPtrCast<GridType>(
grid);
1216 return typename GridType::Ptr();
1220 template<
typename Gr
idType>
1221 inline typename GridType::ConstPtr
1224 return ConstPtrCast<const GridType>(
1225 GridBase::grid<GridType>(ConstPtrCast<GridBase>(
grid)));
1229 template<
typename Gr
idType>
1230 inline typename GridType::ConstPtr
1233 return ConstPtrCast<const GridType>(GridBase::grid<GridType>(
grid));
1237 template<
typename Gr
idType>
1238 inline typename GridType::ConstPtr
1241 return ConstPtrCast<const GridType>(
1242 GridBase::grid<GridType>(ConstPtrCast<GridBase>(
grid)));
1264 template<
typename TreeT>
1270 template<
typename TreeT>
1276 template<
typename TreeT>
1283 #if OPENVDB_ABI_VERSION_NUMBER >= 7
1284 template<
typename TreeT>
1294 template<
typename TreeT>
1302 template<
typename TreeT>
1303 template<
typename OtherTreeType>
1306 mTree(new
TreeType(other.constTree()))
1311 template<
typename TreeT>
1319 template<
typename TreeT>
1328 template<
typename TreeT>
1337 template<
typename TreeT>
1341 return Ptr(
new Grid(background));
1346 template<
typename TreeT>
1355 template<
typename TreeT>
1366 template<
typename TreeT>
1374 #if OPENVDB_ABI_VERSION_NUMBER >= 7
1375 template<
typename TreeT>
1380 this->constTransformPtr());
1381 TreePtrType treePtr = ConstPtrCast<TreeT>(this->constTreePtr());
1385 template<
typename TreeT>
1389 return this->copyReplacingMetadataAndTransform(*
this, xform);
1392 template<
typename TreeT>
1397 TreePtrType treePtr = ConstPtrCast<TreeT>(this->constTreePtr());
1403 template<
typename TreeT>
1411 template<
typename TreeT>
1421 template<
typename TreeT>
1425 return this->copy();
1428 template<
typename TreeT>
1432 return this->copy();
1435 #if OPENVDB_ABI_VERSION_NUMBER >= 7
1436 template<
typename TreeT>
1440 return this->copyReplacingMetadata(meta);
1443 template<
typename TreeT>
1447 return this->copyReplacingTransform(xform);
1450 template<
typename TreeT>
1455 return this->copyReplacingMetadataAndTransform(meta, xform);
1459 template<
typename TreeT>
1463 return this->copyWithNewTree();
1470 template<
typename TreeT>
1474 return mTree.use_count() == 1;
1478 template<
typename TreeT>
1483 if (tree->type() != TreeType::treeType()) {
1485 + tree->type() +
" to a grid of type " + this->type());
1487 mTree = StaticPtrCast<TreeType>(tree);
1491 template<
typename TreeT>
1495 mTree.reset(
new TreeType(this->background()));
1502 template<
typename TreeT>
1506 tree().sparseFill(bbox, value, active);
1510 template<
typename TreeT>
1514 this->sparseFill(bbox, value, active);
1517 template<
typename TreeT>
1521 tree().denseFill(bbox, value, active);
1524 template<
typename TreeT>
1528 const auto value =
math::cwiseAdd(zeroVal<ValueType>(), tolerance);
1529 this->tree().prune(
static_cast<ValueType>(value));
1532 template<
typename TreeT>
1539 template<
typename TreeT>
1543 tree().merge(other.
tree(), policy);
1547 template<
typename TreeT>
1548 template<
typename OtherTreeType>
1552 tree().topologyUnion(other.
tree());
1556 template<
typename TreeT>
1557 template<
typename OtherTreeType>
1561 tree().topologyIntersection(other.
tree());
1565 template<
typename TreeT>
1566 template<
typename OtherTreeType>
1570 tree().topologyDifference(other.
tree());
1577 template<
typename TreeT>
1581 tree().evalMinMax(minVal, maxVal);
1585 template<
typename TreeT>
1590 tree().evalActiveVoxelBoundingBox(bbox);
1595 template<
typename TreeT>
1600 const bool nonempty = tree().evalActiveVoxelDim(dim);
1601 return (nonempty ? dim :
Coord());
1611 template<
typename TreeT>
1615 tree().readTopology(is, saveFloatAsHalf());
1619 template<
typename TreeT>
1623 tree().writeTopology(os, saveFloatAsHalf());
1627 template<
typename TreeT>
1632 tree().readBuffers(is, saveFloatAsHalf());
1634 uint16_t numPasses = 1;
1635 is.read(
reinterpret_cast<char*
>(&numPasses),
sizeof(uint16_t));
1638 for (uint16_t passIndex = 0; passIndex < numPasses; ++passIndex) {
1639 uint32_t pass = (uint32_t(numPasses) << 16) | uint32_t(passIndex);
1640 meta->setPass(pass);
1641 tree().readBuffers(is, saveFloatAsHalf());
1649 template<
typename TreeT>
1654 tree().readBuffers(is, bbox, saveFloatAsHalf());
1656 uint16_t numPasses = 1;
1657 is.read(
reinterpret_cast<char*
>(&numPasses),
sizeof(uint16_t));
1660 for (uint16_t passIndex = 0; passIndex < numPasses; ++passIndex) {
1661 uint32_t pass = (uint32_t(numPasses) << 16) | uint32_t(passIndex);
1662 meta->setPass(pass);
1663 tree().readBuffers(is, saveFloatAsHalf());
1672 template<
typename TreeT>
1676 tree().readNonresidentBuffers();
1680 template<
typename TreeT>
1684 if (!hasMultiPassIO()) {
1685 tree().writeBuffers(os, saveFloatAsHalf());
1690 uint16_t numPasses = 1;
1691 meta->setCountingPasses(
true);
1693 tree().writeBuffers(os, saveFloatAsHalf());
1694 numPasses =
static_cast<uint16_t
>(meta->pass());
1695 os.write(
reinterpret_cast<const char*
>(&numPasses),
sizeof(uint16_t));
1696 meta->setCountingPasses(
false);
1699 for (uint16_t passIndex = 0; passIndex < numPasses; ++passIndex) {
1700 uint32_t pass = (uint32_t(numPasses) << 16) | uint32_t(passIndex);
1701 meta->setPass(pass);
1702 tree().writeBuffers(os, saveFloatAsHalf());
1709 template<
typename TreeT>
1717 template<
typename TreeT>
1721 tree().print(os, verboseLevel);
1723 if (metaCount() > 0) {
1724 os <<
"Additional metadata:" << std::endl;
1725 for (ConstMetaIterator it = beginMeta(), end = endMeta(); it != end; ++it) {
1726 os <<
" " << it->first;
1728 const std::string value = it->second->str();
1729 if (!value.empty()) os <<
": " << value;
1735 os <<
"Transform:" << std::endl;
1736 transform().print(os,
" ");
1744 template<
typename Gr
idType>
1745 inline typename GridType::Ptr
1748 return GridType::create(background);
1752 template<
typename Gr
idType>
1753 inline typename GridType::Ptr
1756 return GridType::create();
1760 template<
typename TreePtrType>
1764 using TreeType =
typename TreePtrType::element_type;
1769 template<
typename Gr
idType>
1770 typename GridType::Ptr
1773 using ValueType =
typename GridType::ValueType;
1776 static_assert(std::is_floating_point<ValueType>::value,
1777 "level-set grids must be floating-point-valued");
1779 typename GridType::Ptr grid = GridType::create(
1780 static_cast<ValueType
>(voxelSize * halfWidth));
1790 namespace internal {
1793 template<
typename OpT,
typename GridBaseT,
typename T,
typename ...Ts>
1794 struct GridApplyImpl {
static bool apply(GridBaseT&, OpT&) {
return false; } };
1798 template<
typename OpT,
typename GridBaseT,
typename GridT,
typename ...GridTs>
1799 struct GridApplyImpl<OpT, GridBaseT,
TypeList<GridT, GridTs...>>
1801 static bool apply(GridBaseT& grid, OpT& op)
1803 if (grid.template isType<GridT>()) {
1807 return GridApplyImpl<OpT, GridBaseT,
TypeList<GridTs...>>::apply(grid, op);
1814 template<
typename Gr
idTypeListT,
typename OpT>
1818 return internal::GridApplyImpl<OpT, const GridBase, GridTypeListT>::apply(*
this, op);
1821 template<
typename Gr
idTypeListT,
typename OpT>
1825 return internal::GridApplyImpl<OpT, GridBase, GridTypeListT>::apply(*
this, op);
1828 template<
typename Gr
idTypeListT,
typename OpT>
1832 return internal::GridApplyImpl<const OpT, const GridBase, GridTypeListT>::apply(*
this, op);
1835 template<
typename Gr
idTypeListT,
typename OpT>
1839 return internal::GridApplyImpl<const OpT, GridBase, GridTypeListT>::apply(*
this, op);
1845 #endif // OPENVDB_GRID_HAS_BEEN_INCLUDED
ValueAllIter beginValueAll()
Return an iterator over all of this grid's values (tile and voxel).
Definition: Grid.h:775
virtual Index64 memUsage() const =0
Return the number of bytes of memory used by this grid.
SharedPtr< const GridBase > ConstPtr
Definition: Grid.h:81
Grid & operator=(const Grid &)=delete
Disallow assignment, since it wouldn't be obvious whether the copy is deep or shallow.
static const char *const META_FILE_DELAYED_LOAD
Definition: Grid.h:366
void writeTransform(std::ostream &os) const
Write out the transform for this grid.
Definition: Grid.h:476
ValueOffCIter beginValueOff() const
Return an iterator over all of this grid's inactive values (tile and voxel).
Definition: Grid.h:771
void setTree(TreeBase::Ptr) override
Associate the given tree with this grid, in place of its existing tree.
Definition: Grid.h:1480
static const char *const META_GRID_CREATOR
Definition: Grid.h:356
typename _TreeType::ValueOnCIter ValueOnCIter
Definition: Grid.h:589
typename std::remove_const< TreeType >::type NonConstTreeType
Definition: Grid.h:1110
Consolidated llvm types for most supported types.
Predicate functor that returns true for grids that have a specified name.
Definition: Grid.h:537
tree::TreeBase TreeBase
Definition: Grid.h:26
typename NonConstGridType::Ptr NonConstGridPtrType
Definition: Grid.h:1087
ValueOnCIter beginValueOn() const
Return an iterator over all of this grid's active values (tile and voxel).
Definition: Grid.h:765
typename TreeType::ValueType ValueType
Definition: Grid.h:1089
typename _TreeType::ValueOffIter ValueOffIter
Definition: Grid.h:590
Signed (x, y, z) 32-bit integer coordinates.
Definition: Coord.h:26
virtual GridBase::ConstPtr copyGridReplacingMetadataAndTransform(const MetaMap &meta, math::Transform::Ptr xform) const =0
Return a new grid of the same type as this grid whose tree is shared with this grid and whose transfo...
@ MERGE_ACTIVE_STATES
Definition: openvdb/Types.h:367
~GridBase() override
Definition: Grid.h:86
TreeBase::Ptr baseTreePtr()
Return a pointer to this grid's tree, which might be shared with other grids. The pointer is guarante...
Definition: Grid.h:1247
void clipGrid(const BBoxd &)
Clip this grid to the given world-space bounding box.
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 ...
Definition: Grid.h:1461
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.
Definition: openvdb/Types.h:124
virtual void clip(const CoordBBox &)=0
Clip this grid to the given index-space bounding box.
static const TreeType & tree(const GridType &g)
Definition: Grid.h:1157
typename _TreeType::ValueOnIter ValueOnIter
Definition: Grid.h:588
Index64 memUsage() const override
Definition: Grid.h:889
static std::string vecTypeToString(VecType)
Return the metadata string value for the given type of vector data.
_TreeType TreeType
Definition: Grid.h:1079
static TreeType & tree(AccessorType &a)
Definition: Grid.h:1155
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...
Definition: Grid.h:1377
static void unregisterGrid(const Name &type)
Remove a grid type from the registry.
virtual void print(std::ostream &=std::cout, int verboseLevel=1) const =0
Output a human-readable description of this grid.
typename TreeType::ConstPtr ConstTreePtrType
Definition: Grid.h:1141
typename _TreeType::ValueAllCIter ValueAllCIter
Definition: Grid.h:593
Tag dispatch class that distinguishes shallow copy constructors from deep copy constructors.
Definition: openvdb/Types.h:539
static const TreeType & tree(const TreeType &t)
Definition: Grid.h:1096
typename GridType::ConstPtr ConstGridPtrType
Definition: Grid.h:1088
typename TreeType::ConstPtr ConstTreePtrType
Definition: Grid.h:1112
typename GridType::Ptr GridPtrType
Definition: Grid.h:1086
Index64 activeVoxelCount() const override
Return the number of active voxels.
Definition: Grid.h:879
VecType
Definition: openvdb/Types.h:343
static const TreeType & tree(const GridType &g)
Definition: Grid.h:1127
void clearGridClass()
Remove the setting specifying the class of this grid's volumetric data.
typename tree::ValueAccessor< TreeType > AccessorType
Definition: Grid.h:1149
This adapter allows code that is templated on a Tree type to accept either a Tree type or a Grid type...
Definition: Grid.h:1078
bool apply(OpT &) const
If this grid resolves to one of the listed grid types, invoke the given functor on the resolved grid.
Definition: Grid.h:1816
math::Transform::ConstPtr constTransformPtr() const
Return a pointer to this grid's transform, which might be shared with other grids.
Definition: Grid.h:408
ValueAllCIter beginValueAll() const
Return an iterator over all of this grid's values (tile and voxel).
Definition: Grid.h:777
typename std::remove_const< TreeType >::type NonConstTreeType
Definition: Grid.h:1080
virtual GridBase::ConstPtr copyGridReplacingTransform(math::Transform::Ptr xform) const =0
Return a new grid of the same type as this grid whose tree is shared with this grid,...
virtual void clear()=0
Empty this grid, setting all voxels to the background.
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...
Definition: Grid.h:1438
MergePolicy
Definition: openvdb/Types.h:366
SharedPtr< TreeBase > Ptr
Definition: Tree.h:38
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.
Definition: Grid.h:1771
static const char *const META_FILE_BBOX_MAX
Definition: Grid.h:362
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...
Definition: Grid.h:1452
typename TreeType::Ptr TreePtrType
Definition: Grid.h:1111
Mat3< Type1 > cwiseAdd(const Mat3< Type1 > &m, const Type2 s)
Definition: Mat3.h:820
typename GridType::Ptr GridPtrType
Definition: Grid.h:1145
static const char *const META_SAVE_HALF_FLOAT
Definition: Grid.h:358
virtual GridBase::Ptr deepCopyGrid() const =0
Return a new grid whose metadata, transform and tree are deep copies of this grid's.
static const TreeType & constTree(TreeType &t)
Definition: Grid.h:1128
GridBase()
Initialize with an identity linear transform.
Definition: Grid.h:486
std::string getCreator() const
Return the user-specified description of this grid's creator.
SharedPtr< const TreeBase > ConstPtr
Definition: Tree.h:39
void addStatsMetadata()
Add metadata to this grid comprising the current values of statistics like the active voxel count and...
void print(std::ostream &=std::cout, int verboseLevel=1) const override
Output a human-readable description of this grid.
Definition: Grid.h:1719
typename tree::ValueAccessor< const TreeType > ConstAccessorType
Definition: Grid.h:1150
ValueConverter<T>::Type is the type of a grid having the same hierarchy as this grid but a different ...
Definition: Grid.h:607
void merge(Grid &other, MergePolicy policy=MERGE_ACTIVE_STATES)
Efficiently merge another grid into this grid using one of several schemes.
Definition: Grid.h:1541
virtual void setTree(TreeBase::Ptr)=0
Associate the given tree with this grid, in place of its existing tree.
typename TreeType::ValueType ValueType
Definition: Grid.h:1148
typename std::remove_const< TreeType >::type NonConstTreeType
Definition: Grid.h:1139
OPENVDB_API uint32_t getFormatVersion(std::ios_base &)
Return the file format version number associated with the given input stream.
virtual bool empty() const =0
Return true if this grid contains only background voxels.
GridBase(GridBase &other, ShallowCopy)
Copy another grid's metadata but share its transform.
Definition: Grid.h:498
static const char *const META_GRID_NAME
Definition: Grid.h:357
GridPtrT findGridByName(const std::map< KeyT, GridPtrT > &container, const Name &name)
Return the first grid in the given map whose name is name.
Definition: Grid.h:557
void clearVectorType()
Remove the setting specifying the type of vector data stored in this grid.
math::Transform::ConstPtr transformPtr() const
Return a pointer to this grid's transform, which might be shared with other grids.
Definition: Grid.h:407
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...
Definition: Grid.h:1550
static const char *const META_FILE_VOXEL_COUNT
Definition: Grid.h:365
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...
Definition: Grid.h:1394
const TreeBase & baseTree() const
Return a reference to this grid's tree, which might be shared with other grids.
Definition: Grid.h:192
typename _TreeType::BuildType BuildType
Definition: Grid.h:586
static const TreeType & constTree(const GridType &g)
Definition: Grid.h:1131
typename _TreeType::ValueAllIter ValueAllIter
Definition: Grid.h:592
static const char *const META_FILE_BBOX_MIN
Definition: Grid.h:361
ConstTreePtrType treePtr() const
Return a pointer to this grid's tree, which might be shared with other grids. The pointer is guarante...
Definition: Grid.h:901
typename TreeType::Ptr TreePtrType
Definition: Grid.h:1081
typename _TreeType::ValueOffCIter ValueOffCIter
Definition: Grid.h:591
Grid()
Construct a new grid with background value zero.
Definition: Grid.h:1265
std::set< GridBase::Ptr > GridPtrSet
Definition: Grid.h:524
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...
Definition: Grid.h:1519
const math::Transform & constTransform() const
Return a pointer to this grid's transform, which might be shared with other grids.
Definition: Grid.h:417
GridCPtrSet::const_iterator GridCPtrSetCIter
Definition: Grid.h:531
VecType getVectorType() const
Return the type of vector data (invariant, covariant, etc.) stored in this grid, assuming that this g...
static TreeType & tree(GridType &g)
Definition: Grid.h:1125
#define OPENVDB_THROW(exception, message)
Definition: openvdb/Exceptions.h:74
TreeBase::ConstPtr constBaseTreePtr() const override
Return a pointer to this grid's tree, which might be shared with other grids. The pointer is guarante...
Definition: Grid.h:903
std::set< GridBase::ConstPtr > GridCPtrSet
Definition: Grid.h:529
typename GridType::ConstPtr ConstGridPtrType
Definition: Grid.h:1118
virtual GridBase::Ptr copyGridWithNewTree() const =0
Return a new grid of the same type as this grid whose metadata and transform are deep copies of this ...
void evalMinMax(ValueType &minVal, ValueType &maxVal) const
Return the minimum and maximum active values in this grid.
Definition: Grid.h:1579
ValueAllCIter cbeginValueAll() const
Return an iterator over all of this grid's values (tile and voxel).
Definition: Grid.h:779
ValueOffCIter cbeginValueOff() const
Return an iterator over all of this grid's inactive values (tile and voxel).
Definition: Grid.h:773
SharedPtr< GridPtrSet > GridPtrSetPtr
Definition: Grid.h:527
Abstract base class for typed grids.
Definition: Grid.h:78
typename TreeType::ValueType ValueType
Definition: Grid.h:1119
Accessor getAccessor()
Return an accessor that provides random read and write access to this grid's voxels.
Definition: Grid.h:740
virtual Coord evalActiveVoxelDim() const =0
Return the dimensions of the axis-aligned bounding box of all active voxels.
Vec3d voxelSize() const
Return the size of this grid's voxels.
Definition: Grid.h:434
const ValueType & background() const
Return this grid's background value.
Definition: Grid.h:730
virtual GridBase::ConstPtr copyGrid() const =0
Return a new grid of the same type as this grid whose metadata is a deep copy of this grid's and whos...
static void clearRegistry()
Clear the grid type registry.
static Ptr createGrid(const Name &type)
Create a new grid of the given (registered) type.
openvdb::GridBase Grid
Definition: openvdb_houdini/openvdb_houdini/Utils.h:33
A list of types (not necessarily unique)
Definition: TypeList.h:366
Vec3d worldToIndex(const Vec3d &xyz) const
Apply the inverse of this grid's transform to the given coordinates.
Definition: Grid.h:445
static TreeType & tree(GridType &g)
Definition: Grid.h:1095
@ GRID_LEVEL_SET
Definition: openvdb/Types.h:315
Name valueType() const override
Return the name of the type of a voxel's value (e.g., "float" or "vec3d").
Definition: Grid.h:722
Definition: openvdb/Exceptions.h:64
typename tree::ValueAccessor< _TreeType, true > Accessor
Definition: Grid.h:595
TreeType & tree()
Return a reference to this grid's tree, which might be shared with other grids.
Definition: Grid.h:917
static const char *const META_GRID_CLASS
Definition: Grid.h:355
void setGridClass(GridClass)
Specify the class of volumetric data (level set, fog volume, etc.) that is stored in this grid.
static const char *const META_FILE_COMPRESSION
Definition: Grid.h:363
typename tree::ValueAccessor< const _TreeType, false > ConstUnsafeAccessor
Definition: Grid.h:598
Ptr deepCopy() const
Return a new grid whose metadata, transform and tree are deep copies of this grid's.
Definition: Grid.h:709
static bool isRegistered()
Return true if this grid type is registered.
Definition: Grid.h:979
void setVectorType(VecType)
Specify the type of vector data (invariant, covariant, etc.) stored in this grid, assuming that this ...
SharedPtr< GridPtrVec > GridPtrVecPtr
Definition: Grid.h:517
static std::string vecTypeExamples(VecType)
static const char *const META_IS_LOCAL_SPACE
Definition: Grid.h:359
virtual Name type() const =0
Return the name of this grid's type.
std::vector< GridBase::ConstPtr > GridCPtrVec
Definition: Grid.h:519
typename tree::ValueAccessor< const _TreeType, true > ConstAccessor
Definition: Grid.h:596
static const TreeType & constTree(const TreeType &t)
Definition: Grid.h:1130
_TreeType TreeType
Definition: Grid.h:1109
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,...
Definition: Grid.h:1387
TreeBase::ConstPtr baseTreePtr() const
Return a pointer to this grid's tree, which might be shared with other grids. The pointer is guarante...
Definition: Grid.h:173
static const TreeType & tree(const GridType &g)
Definition: Grid.h:1097
ValueOffIter beginValueOff()
Return an iterator over all of this grid's inactive values (tile and voxel).
Definition: Grid.h:769
void newTree() override
Associate a new, empty tree with this grid, in place of its existing tree.
Definition: Grid.h:1493
bool empty() const override
Return true if this grid contains only inactive background voxels.
Definition: Grid.h:733
static std::string gridClassToString(GridClass)
Return the metadata string value for the given class of volumetric data.
static const TreeType & constTree(GridType &g)
Definition: Grid.h:1129
virtual void readBuffers(std::istream &, const CoordBBox &)=0
Read all of this grid's data buffers that intersect the given index-space bounding box.
typename _TreeType::ValueType ValueType
Definition: Grid.h:585
TreeBase & baseTree()
Return a reference to this grid's tree, which might be shared with other grids.
Definition: Grid.h:187
bool isTreeUnique() const final
Return true if tree is not shared with another grid.
Definition: Grid.h:1472
static bool hasMultiPassIO()
Return true if grids of this type require multiple I/O passes to read and write data buffers.
Definition: Grid.h:1711
GridBase(const GridBase &other)
Deep copy another grid's metadata and transform.
Definition: Grid.h:495
void setName(const std::string &)
Specify a name for this grid.
void topologyDifference(const Grid< OtherTreeType > &other)
Difference this grid's set of active values with the active values of the other grid,...
Definition: Grid.h:1568
ConstAccessor getAccessor() const
Return an accessor that provides random read-only access to this grid's voxels.
Definition: Grid.h:750
static const TreeType & constTree(const GridType &g)
Definition: Grid.h:1162
GridType::Ptr createGrid(const typename GridType::ValueType &background)
Create a new grid of type GridType with a given background value.
Definition: Grid.h:1746
static const TreeType & constTree(GridType &g)
Definition: Grid.h:1160
std::string getName() const
Return this grid's user-specified name.
SharedPtr< GridCPtrVec > GridCPtrVecPtr
Definition: Grid.h:522
const TreeType & tree() const
Return a pointer to this grid's tree, which might be shared with other grids. The pointer is guarante...
Definition: Grid.h:918
Vec3d indexToWorld(const Coord &ijk) const
Apply this grid's transform to the given coordinates.
Definition: Grid.h:443
_TreeType TreeType
Definition: Grid.h:582
const TreeBase & constBaseTree() const
Return a reference to this grid's tree, which might be shared with other grids.
Definition: Grid.h:197
SharedPtr< GridCPtrSet > GridCPtrSetPtr
Definition: Grid.h:532
GridType::ConstPtr gridConstPtrCast(const GridBase::ConstPtr &grid)
Cast a generic const grid pointer to a const pointer to a grid of a concrete class.
Definition: Grid.h:1036
void clear() override
Empty this grid, so that all voxels become inactive background voxels.
Definition: Grid.h:735
static GridClass stringToGridClass(const std::string &)
Return the class of volumetric data specified by the given string.
static std::string vecTypeDescription(VecType)
Return a string describing how the given type of vector data is affected by transformations (e....
SharedPtr< GridBase > Ptr
Definition: Grid.h:80
virtual void pruneGrid(float tolerance=0.0)=0
Reduce the memory footprint of this grid by increasing its sparseness either losslessly (tolerance = ...
static const TreeType & constTree(const TreeType &t)
Definition: Grid.h:1161
Definition: openvdb/Exceptions.h:65
std::shared_ptr< T > SharedPtr
Definition: openvdb/Types.h:92
GridPtrSet::const_iterator GridPtrSetCIter
Definition: Grid.h:526
static const TreeType & constTree(const TreeType &t)
Definition: Grid.h:1100
GridPtrSet::iterator GridPtrSetIter
Definition: Grid.h:525
double Real
Definition: openvdb/Types.h:38
GridNamePred(const Name &_name)
Definition: Grid.h:538
typename tree::ValueAccessor< NonConstTreeType > NonConstAccessorType
Definition: Grid.h:1151
static const TreeType & constTree(const GridType &g)
Definition: Grid.h:1101
typename _TreeType::ConstPtr ConstTreePtrType
Definition: Grid.h:584
Ptr copyWithNewTree() const
Return a new grid of the same type as this grid whose metadata and transform are deep copies of this ...
Definition: Grid.h:1413
Metafunction that specifies whether a given leaf node, tree, or grid type requires multiple passes to...
Definition: Grid.h:1177
Vec3d voxelSize(const Vec3d &xyz) const
Return the size of this grid's voxel at position (x, y, z).
Definition: Grid.h:437
ValueOnIter beginValueOn()
Return an iterator over all of this grid's active values (tile and voxel).
Definition: Grid.h:763
virtual Index64 activeVoxelCount() const =0
Return the number of active voxels.
void readBuffers(std::istream &) override
Read all data buffers for this grid.
Definition: Grid.h:1629
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,...
Definition: Grid.h:1445
static const Real LEVEL_SET_HALF_WIDTH
Definition: openvdb/Types.h:321
typename tree::ValueAccessor< NonConstTreeType > NonConstAccessorType
Definition: Grid.h:1092
static const TreeType & constTree(TreeType &t)
Definition: Grid.h:1098
virtual void readBuffers(std::istream &)=0
Read all data buffers for this grid.
static void registerGrid(const Name &type, GridFactory)
Register a grid type along with a factory function.
bool operator()(const GridBase::ConstPtr &g) const
Definition: Grid.h:539
SharedPtr< const Grid > ConstPtr
Definition: Grid.h:580
static TreeType & tree(TreeType &t)
Definition: Grid.h:1124
GridType::Ptr gridPtrCast(const GridBase::Ptr &grid)
Cast a generic grid pointer to a pointer to a grid of a concrete class.
Definition: Grid.h:1020
static const TreeType & constTree(GridType &g)
Definition: Grid.h:1099
void fill(const CoordBBox &bbox, const ValueType &value, bool active=true)
Set all voxels within a given axis-aligned box to a constant value.
Definition: Grid.h:1512
static const TreeType & tree(const TreeType &t)
Definition: Grid.h:1126
typename tree::ValueAccessor< TreeType > AccessorType
Definition: Grid.h:1090
GridCPtrSet::iterator GridCPtrSetIter
Definition: Grid.h:530
virtual void readNonresidentBuffers() const =0
Read all of this grid's data buffers that are not yet resident in memory (because delayed loading is ...
Base class for typed trees.
Definition: Tree.h:36
void readTopology(std::istream &) override
Read the grid topology from a stream. This will read only the grid structure, not the actual data buf...
Definition: Grid.h:1613
ConstTreePtrType constTreePtr() const
Return a pointer to this grid's tree, which might be shared with other grids. The pointer is guarante...
Definition: Grid.h:902
std::vector< GridBase::Ptr > GridPtrVec
Definition: Grid.h:514
static TreeType & tree(TreeType &t)
Definition: Grid.h:1153
static const TreeType & constTree(TreeType &t)
Definition: Grid.h:1159
virtual GridBase::Ptr copyGrid()=0
Return a new grid of the same type as this grid whose metadata is a deep copy of this grid's and whos...
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...
#define OPENVDB_USE_VERSION_NAMESPACE
Definition: version.h:153
GridCPtrVec::const_iterator GridCPtrVecCIter
Definition: Grid.h:521
Grid< typename TreePtrType::element_type >::Ptr createGrid(TreePtrType)
Create a new grid of the appropriate type that wraps the given tree.
Definition: Grid.h:1762
Vec3< double > Vec3d
Definition: Vec3.h:668
typename NonConstTreeType::Ptr NonConstTreePtrType
Definition: Grid.h:1113
bool isType() const
Return true if this grid is of the same type as the template parameter.
Definition: Grid.h:148
SharedPtr< Grid > Ptr
Definition: Grid.h:579
static Ptr create()
Return a new grid with background value zero.
Definition: Grid.h:1330
GridCPtrVec::iterator GridCPtrVecIter
Definition: Grid.h:520
_TreeType TreeType
Definition: Grid.h:1138
typename TreeType::Ptr TreePtrType
Definition: Grid.h:1140
void setSaveFloatAsHalf(bool)
Return this grid's user-specified name.
static bool isRegistered(const Name &type)
Return true if the given grid type name is registered.
static const char *const META_VECTOR_TYPE
Definition: Grid.h:360
GridClass
Definition: openvdb/Types.h:313
virtual CoordBBox evalActiveVoxelBoundingBox() const =0
void topologyIntersection(const Grid< OtherTreeType > &other)
Intersect this grid's set of active values with the active values of the other grid,...
Definition: Grid.h:1559
typename NonConstTreeType::Ptr NonConstTreePtrType
Definition: Grid.h:1142
virtual Name valueType() const =0
Return the name of the type of a voxel's value (e.g., "float" or "vec3d").
Ptr(*)() GridFactory
Definition: Grid.h:83
GridClass getGridClass() const
Return the class of volumetric data (level set, fog volume, etc.) that is stored in this grid.
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...
Definition: Grid.h:1621
void readTransform(std::istream &is)
Read in the transform for this grid.
Definition: Grid.h:474
typename tree::ValueAccessor< const TreeType > ConstAccessorType
Definition: Grid.h:1091
GridBase::Ptr deepCopyGrid() const override
Return a new grid whose metadata, transform and tree are deep copies of this grid's.
Definition: Grid.h:711
Vec3d indexToWorld(const Vec3d &xyz) const
Apply this grid's transform to the given coordinates.
Definition: Grid.h:441
MetaMap::Ptr getStatsMetadata() const
Return a new MetaMap containing just the metadata that was added to this grid with addStatsMetadata.
OPENVDB_API SharedPtr< StreamMetadata > getStreamMetadataPtr(std::ios_base &)
Return a shared pointer to an object that stores metadata (file format, compression scheme,...
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...
Definition: Grid.h:1423
static GridType::Ptr grid(const GridBase::Ptr &)
Return the result of downcasting a GridBase pointer to a Grid pointer of the specified type,...
Definition: Grid.h:1209
void clip(const CoordBBox &) override
Clip this grid to the given index-space bounding box.
Definition: Grid.h:1534
typename GridType::Ptr GridPtrType
Definition: Grid.h:1116
bool isInWorldSpace() const
typename NonConstTreeType::Ptr NonConstTreePtrType
Definition: Grid.h:1083
typename NonConstGridType::Ptr NonConstGridPtrType
Definition: Grid.h:1146
static TreeType & tree(TreeType &t)
Definition: Grid.h:1094
UnsafeAccessor getUnsafeAccessor()
Return an unsafe accessor that provides random read and write access to this grid's voxels.
Definition: Grid.h:748
ConstAccessor getConstAccessor() const
Return an accessor that provides random read-only access to this grid's voxels.
Definition: Grid.h:752
static TreeType & tree(GridType &g)
Definition: Grid.h:1154
GridPtrVec::iterator GridPtrVecIter
Definition: Grid.h:515
uint64_t Index64
Definition: openvdb/Types.h:31
#define OPENVDB_VERSION_NAME
The version namespace name for this library version.
Definition: version.h:101
static const TreeType & tree(const TreeType &t)
Definition: Grid.h:1156
Ptr copy()
Return a new grid of the same type as this grid whose metadata and transform are deep copies of this ...
Definition: Grid.h:1405
Name name
Definition: Grid.h:540
CoordBBox evalActiveVoxelBoundingBox() const override
Return the axis-aligned bounding box of all active voxels.
Definition: Grid.h:1587
typename NonConstGridType::Ptr NonConstGridPtrType
Definition: Grid.h:1117
Axis-aligned bounding box of signed integer coordinates.
Definition: Coord.h:249
virtual void newTree()=0
Set a new tree with the same background value as the previous tree.
void setTransform(math::Transform::Ptr)
Associate the given transform with this grid, in place of its existing transform.
Definition: Grid.h:1254
void setIsInWorldSpace(bool)
Specify whether this grid's voxel values are in world space or in local space.
static Name gridType()
Return the name of this type of grid.
Definition: Grid.h:719
void readNonresidentBuffers() const override
Read all of this grid's data buffers that are not yet resident in memory (because delayed loading is ...
Definition: Grid.h:1674
virtual void writeBuffers(std::ostream &) const =0
Write out all data buffers for this grid.
const TreeType & constTree() const
Return a pointer to this grid's tree, which might be shared with other grids. The pointer is guarante...
Definition: Grid.h:919
Name type() const override
Return the name of this grid's type.
Definition: Grid.h:717
bool saveFloatAsHalf() const
Return true if this grid should be written out with floating-point voxel values (including components...
typename tree::ValueAccessor< NonConstTreeType > NonConstAccessorType
Definition: Grid.h:1122
void pruneGrid(float tolerance=0.0) override
Reduce the memory footprint of this grid by increasing its sparseness.
Definition: Grid.h:1526
typename tree::ValueAccessor< TreeType > AccessorType
Definition: Grid.h:1120
bool hasUniformVoxels() const
Return true if the voxels in world space are uniformly sized cubes.
Definition: Grid.h:439
void sparseFill(const CoordBBox &bbox, const ValueType &value, bool active=true)
Set all voxels within a given axis-aligned box to a constant value.
Definition: Grid.h:1504
Definition: openvdb/Exceptions.h:13
static GridType::ConstPtr constGrid(const GridBase::Ptr &)
Definition: Grid.h:1231
typename tree::ValueAccessor< const TreeType > ConstAccessorType
Definition: Grid.h:1121
static const TreeType & tree(const AccessorType &a)
Definition: Grid.h:1158
static void registerGrid()
Register this grid type along with a factory function.
Definition: Grid.h:981
Definition: ValueAccessor.h:183
ConstUnsafeAccessor getConstUnsafeAccessor() const
Return an unsafe accessor that provides random read-only access to this grid's voxels.
Definition: Grid.h:760
static VecType stringToVecType(const std::string &)
static void unregisterGrid()
Remove this grid type from the registry.
Definition: Grid.h:990
const math::Transform & transform() const
Return a pointer to this grid's transform, which might be shared with other grids.
Definition: Grid.h:416
GridType::Ptr deepCopyTypedGrid(const GridBase &grid)
Return a pointer to a deep copy of the given grid, provided that the grid's concrete type is GridType...
Definition: Grid.h:1062
static const char *const META_FILE_MEM_BYTES
Definition: Grid.h:364
Definition: LeafBuffer.h:41
ValueOnCIter cbeginValueOn() const
Return an iterator over all of this grid's active values (tile and voxel).
Definition: Grid.h:767
~Grid() override
Definition: Grid.h:646
void setCreator(const std::string &)
Provide a description of this grid's creator.
Container class that associates a tree with a transform and metadata.
Definition: Grid.h:577
typename TreeType::ConstPtr ConstTreePtrType
Definition: Grid.h:1082
typename std::remove_const< ToType >::type Type
Definition: openvdb/Types.h:299
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 buf...
GridPtrVec::const_iterator GridPtrVecCIter
Definition: Grid.h:516
static std::string gridClassToMenuName(GridClass)
Return a formatted string version of the grid class.
void writeBuffers(std::ostream &) const override
Write out all data buffers for this grid.
Definition: Grid.h:1682
std::string Name
Definition: Name.h:17
Coord evalActiveVoxelDim() const override
Return the dimensions of the axis-aligned bounding box of all active voxels.
Definition: Grid.h:1597
typename tree::ValueAccessor< _TreeType, false > UnsafeAccessor
Definition: Grid.h:597
virtual void readTopology(std::istream &)=0
Read the grid topology from a stream. This will read only the grid structure, not the actual data buf...
void print(const ast::Node &node, const bool numberStatements=true, std::ostream &os=std::cout, const char *indent=" ")
Writes a descriptive printout of a Node hierarchy into a target stream.
@ OPENVDB_FILE_VERSION_MULTIPASS_IO
Definition: version.h:197
typename _TreeType::Ptr TreePtrType
Definition: Grid.h:583
#define OPENVDB_LOG_WARN(message)
Log a warning message of the form 'someVar << "some text" << ...'.
Definition: logging.h:253
typename GridType::ConstPtr ConstGridPtrType
Definition: Grid.h:1147